netwerk/srtp/src/crypto/cipher/null_cipher.c

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /*
michael@0 2 * null_cipher.c
michael@0 3 *
michael@0 4 * A null cipher implementation. This cipher leaves the plaintext
michael@0 5 * unchanged.
michael@0 6 *
michael@0 7 * David A. McGrew
michael@0 8 * Cisco Systems, Inc.
michael@0 9 */
michael@0 10
michael@0 11 /*
michael@0 12 *
michael@0 13 * Copyright (c) 2001-2006, Cisco Systems, Inc.
michael@0 14 * All rights reserved.
michael@0 15 *
michael@0 16 * Redistribution and use in source and binary forms, with or without
michael@0 17 * modification, are permitted provided that the following conditions
michael@0 18 * are met:
michael@0 19 *
michael@0 20 * Redistributions of source code must retain the above copyright
michael@0 21 * notice, this list of conditions and the following disclaimer.
michael@0 22 *
michael@0 23 * Redistributions in binary form must reproduce the above
michael@0 24 * copyright notice, this list of conditions and the following
michael@0 25 * disclaimer in the documentation and/or other materials provided
michael@0 26 * with the distribution.
michael@0 27 *
michael@0 28 * Neither the name of the Cisco Systems, Inc. nor the names of its
michael@0 29 * contributors may be used to endorse or promote products derived
michael@0 30 * from this software without specific prior written permission.
michael@0 31 *
michael@0 32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
michael@0 33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
michael@0 34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
michael@0 35 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
michael@0 36 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
michael@0 37 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
michael@0 38 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
michael@0 39 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
michael@0 40 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
michael@0 41 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
michael@0 42 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
michael@0 43 * OF THE POSSIBILITY OF SUCH DAMAGE.
michael@0 44 *
michael@0 45 */
michael@0 46
michael@0 47 #include "datatypes.h"
michael@0 48 #include "null_cipher.h"
michael@0 49 #include "alloc.h"
michael@0 50
michael@0 51 /* the null_cipher uses the cipher debug module */
michael@0 52
michael@0 53 extern debug_module_t mod_cipher;
michael@0 54
michael@0 55 err_status_t
michael@0 56 null_cipher_alloc(cipher_t **c, int key_len) {
michael@0 57 extern cipher_type_t null_cipher;
michael@0 58 uint8_t *pointer;
michael@0 59
michael@0 60 debug_print(mod_cipher,
michael@0 61 "allocating cipher with key length %d", key_len);
michael@0 62
michael@0 63 /* allocate memory a cipher of type null_cipher */
michael@0 64 pointer = (uint8_t*)crypto_alloc(sizeof(null_cipher_ctx_t) + sizeof(cipher_t));
michael@0 65 if (pointer == NULL)
michael@0 66 return err_status_alloc_fail;
michael@0 67
michael@0 68 /* set pointers */
michael@0 69 *c = (cipher_t *)pointer;
michael@0 70 (*c)->type = &null_cipher;
michael@0 71 (*c)->state = pointer + sizeof(cipher_t);
michael@0 72
michael@0 73 /* set key size */
michael@0 74 (*c)->key_len = key_len;
michael@0 75
michael@0 76 /* increment ref_count */
michael@0 77 null_cipher.ref_count++;
michael@0 78
michael@0 79 return err_status_ok;
michael@0 80
michael@0 81 }
michael@0 82
michael@0 83 err_status_t
michael@0 84 null_cipher_dealloc(cipher_t *c) {
michael@0 85 extern cipher_type_t null_cipher;
michael@0 86
michael@0 87 /* zeroize entire state*/
michael@0 88 octet_string_set_to_zero((uint8_t *)c,
michael@0 89 sizeof(null_cipher_ctx_t) + sizeof(cipher_t));
michael@0 90
michael@0 91 /* free memory of type null_cipher */
michael@0 92 crypto_free(c);
michael@0 93
michael@0 94 /* decrement reference count */
michael@0 95 null_cipher.ref_count--;
michael@0 96
michael@0 97 return err_status_ok;
michael@0 98
michael@0 99 }
michael@0 100
michael@0 101 err_status_t
michael@0 102 null_cipher_init(null_cipher_ctx_t *ctx, const uint8_t *key, int key_len) {
michael@0 103
michael@0 104 debug_print(mod_cipher, "initializing null cipher", NULL);
michael@0 105
michael@0 106 return err_status_ok;
michael@0 107 }
michael@0 108
michael@0 109 err_status_t
michael@0 110 null_cipher_set_iv(null_cipher_ctx_t *c, void *iv) {
michael@0 111 return err_status_ok;
michael@0 112 }
michael@0 113
michael@0 114 err_status_t
michael@0 115 null_cipher_encrypt(null_cipher_ctx_t *c,
michael@0 116 unsigned char *buf, unsigned int *bytes_to_encr) {
michael@0 117 return err_status_ok;
michael@0 118 }
michael@0 119
michael@0 120 char
michael@0 121 null_cipher_description[] = "null cipher";
michael@0 122
michael@0 123 cipher_test_case_t
michael@0 124 null_cipher_test_0 = {
michael@0 125 0, /* octets in key */
michael@0 126 NULL, /* key */
michael@0 127 0, /* packet index */
michael@0 128 0, /* octets in plaintext */
michael@0 129 NULL, /* plaintext */
michael@0 130 0, /* octets in plaintext */
michael@0 131 NULL, /* ciphertext */
michael@0 132 NULL /* pointer to next testcase */
michael@0 133 };
michael@0 134
michael@0 135
michael@0 136 /*
michael@0 137 * note: the decrypt function is idential to the encrypt function
michael@0 138 */
michael@0 139
michael@0 140 cipher_type_t null_cipher = {
michael@0 141 (cipher_alloc_func_t) null_cipher_alloc,
michael@0 142 (cipher_dealloc_func_t) null_cipher_dealloc,
michael@0 143 (cipher_init_func_t) null_cipher_init,
michael@0 144 (cipher_encrypt_func_t) null_cipher_encrypt,
michael@0 145 (cipher_decrypt_func_t) null_cipher_encrypt,
michael@0 146 (cipher_set_iv_func_t) null_cipher_set_iv,
michael@0 147 (char *) null_cipher_description,
michael@0 148 (int) 0,
michael@0 149 (cipher_test_case_t *) &null_cipher_test_0,
michael@0 150 (debug_module_t *) NULL,
michael@0 151 (cipher_type_id_t) NULL_CIPHER
michael@0 152 };
michael@0 153

mercurial