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