OLD | NEW |
| (Empty) |
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,2013 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 #ifdef HAVE_CONFIG_H | |
48 #include <config.h> | |
49 #endif | |
50 | |
51 #include "datatypes.h" | |
52 #include "null_cipher.h" | |
53 #include "alloc.h" | |
54 | |
55 /* the null_cipher uses the cipher debug module */ | |
56 | |
57 extern debug_module_t mod_cipher; | |
58 | |
59 err_status_t | |
60 null_cipher_alloc(cipher_t **c, int key_len, int tlen) { | |
61 extern cipher_type_t null_cipher; | |
62 uint8_t *pointer; | |
63 | |
64 debug_print(mod_cipher, | |
65 "allocating cipher with key length %d", key_len); | |
66 | |
67 /* allocate memory a cipher of type null_cipher */ | |
68 pointer = (uint8_t*)crypto_alloc(sizeof(null_cipher_ctx_t) + sizeof(cipher_t))
; | |
69 if (pointer == NULL) | |
70 return err_status_alloc_fail; | |
71 | |
72 /* set pointers */ | |
73 *c = (cipher_t *)pointer; | |
74 (*c)->algorithm = NULL_CIPHER; | |
75 (*c)->type = &null_cipher; | |
76 (*c)->state = pointer + sizeof(cipher_t); | |
77 | |
78 /* set key size */ | |
79 (*c)->key_len = key_len; | |
80 | |
81 /* increment ref_count */ | |
82 null_cipher.ref_count++; | |
83 | |
84 return err_status_ok; | |
85 | |
86 } | |
87 | |
88 err_status_t | |
89 null_cipher_dealloc(cipher_t *c) { | |
90 extern cipher_type_t null_cipher; | |
91 | |
92 /* zeroize entire state*/ | |
93 octet_string_set_to_zero((uint8_t *)c, | |
94 sizeof(null_cipher_ctx_t) + sizeof(cipher_t)); | |
95 | |
96 /* free memory of type null_cipher */ | |
97 crypto_free(c); | |
98 | |
99 /* decrement reference count */ | |
100 null_cipher.ref_count--; | |
101 | |
102 return err_status_ok; | |
103 | |
104 } | |
105 | |
106 err_status_t | |
107 null_cipher_init(null_cipher_ctx_t *ctx, const uint8_t *key, int key_len) { | |
108 | |
109 debug_print(mod_cipher, "initializing null cipher", NULL); | |
110 | |
111 return err_status_ok; | |
112 } | |
113 | |
114 err_status_t | |
115 null_cipher_set_iv(null_cipher_ctx_t *c, void *iv) { | |
116 return err_status_ok; | |
117 } | |
118 | |
119 err_status_t | |
120 null_cipher_encrypt(null_cipher_ctx_t *c, | |
121 unsigned char *buf, unsigned int *bytes_to_encr) { | |
122 return err_status_ok; | |
123 } | |
124 | |
125 char | |
126 null_cipher_description[] = "null cipher"; | |
127 | |
128 cipher_test_case_t | |
129 null_cipher_test_0 = { | |
130 0, /* octets in key */ | |
131 NULL, /* key */ | |
132 0, /* packet index */ | |
133 0, /* octets in plaintext */ | |
134 NULL, /* plaintext */ | |
135 0, /* octets in plaintext */ | |
136 NULL, /* ciphertext */ | |
137 0, | |
138 NULL, | |
139 0, | |
140 NULL /* pointer to next testcase */ | |
141 }; | |
142 | |
143 | |
144 /* | |
145 * note: the decrypt function is idential to the encrypt function | |
146 */ | |
147 | |
148 cipher_type_t null_cipher = { | |
149 (cipher_alloc_func_t) null_cipher_alloc, | |
150 (cipher_dealloc_func_t) null_cipher_dealloc, | |
151 (cipher_init_func_t) null_cipher_init, | |
152 (cipher_set_aad_func_t) 0, | |
153 (cipher_encrypt_func_t) null_cipher_encrypt, | |
154 (cipher_decrypt_func_t) null_cipher_encrypt, | |
155 (cipher_set_iv_func_t) null_cipher_set_iv, | |
156 (cipher_get_tag_func_t) 0, | |
157 (char *) null_cipher_description, | |
158 (int) 0, | |
159 (cipher_test_case_t *) &null_cipher_test_0, | |
160 (debug_module_t *) NULL, | |
161 (cipher_type_id_t) NULL_CIPHER | |
162 }; | |
163 | |
OLD | NEW |