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 "err.h" /* for srtp_debug */ |
| 54 #include "alloc.h" |
| 55 |
| 56 /* the null_cipher uses the cipher debug module */ |
| 57 |
| 58 extern srtp_debug_module_t srtp_mod_cipher; |
| 59 |
| 60 static srtp_err_status_t srtp_null_cipher_alloc (srtp_cipher_t **c, int key_len,
int tlen) |
| 61 { |
| 62 extern const srtp_cipher_type_t srtp_null_cipher; |
| 63 |
| 64 debug_print(srtp_mod_cipher, |
| 65 "allocating cipher with key length %d", key_len); |
| 66 |
| 67 /* allocate memory a cipher of type null_cipher */ |
| 68 *c = (srtp_cipher_t *)srtp_crypto_alloc(sizeof(srtp_cipher_t)); |
| 69 if (*c == NULL) { |
| 70 return srtp_err_status_alloc_fail; |
| 71 } |
| 72 memset(*c, 0x0, sizeof(srtp_cipher_t)); |
| 73 |
| 74 /* set pointers */ |
| 75 (*c)->algorithm = SRTP_NULL_CIPHER; |
| 76 (*c)->type = &srtp_null_cipher; |
| 77 (*c)->state = (void *) 0x1; /* The null cipher does not maintain state */ |
| 78 |
| 79 /* set key size */ |
| 80 (*c)->key_len = key_len; |
| 81 |
| 82 return srtp_err_status_ok; |
| 83 |
| 84 } |
| 85 |
| 86 static srtp_err_status_t srtp_null_cipher_dealloc (srtp_cipher_t *c) |
| 87 { |
| 88 extern const srtp_cipher_type_t srtp_null_cipher; |
| 89 |
| 90 /* zeroize entire state*/ |
| 91 octet_string_set_to_zero((uint8_t*)c, sizeof(srtp_cipher_t)); |
| 92 |
| 93 /* free memory of type null_cipher */ |
| 94 srtp_crypto_free(c); |
| 95 |
| 96 return srtp_err_status_ok; |
| 97 |
| 98 } |
| 99 |
| 100 static srtp_err_status_t srtp_null_cipher_init (void *cv, const uint8_t *key) |
| 101 { |
| 102 /* srtp_null_cipher_ctx_t *c = (srtp_null_cipher_ctx_t *)cv; */ |
| 103 |
| 104 debug_print(srtp_mod_cipher, "initializing null cipher", NULL); |
| 105 |
| 106 return srtp_err_status_ok; |
| 107 } |
| 108 |
| 109 static srtp_err_status_t srtp_null_cipher_set_iv (void *cv, uint8_t *iv, srtp_ci
pher_direction_t dir) |
| 110 { |
| 111 /* srtp_null_cipher_ctx_t *c = (srtp_null_cipher_ctx_t *)cv; */ |
| 112 return srtp_err_status_ok; |
| 113 } |
| 114 |
| 115 static srtp_err_status_t srtp_null_cipher_encrypt (void *cv, |
| 116 unsigned char *buf, unsigned int *by
tes_to_encr) |
| 117 { |
| 118 /* srtp_null_cipher_ctx_t *c = (srtp_null_cipher_ctx_t *)cv; */ |
| 119 return srtp_err_status_ok; |
| 120 } |
| 121 |
| 122 static const char srtp_null_cipher_description[] = "null cipher"; |
| 123 |
| 124 static const srtp_cipher_test_case_t srtp_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 0, |
| 133 NULL, |
| 134 0, |
| 135 NULL /* pointer to next testcase */ |
| 136 }; |
| 137 |
| 138 |
| 139 /* |
| 140 * note: the decrypt function is idential to the encrypt function |
| 141 */ |
| 142 |
| 143 const srtp_cipher_type_t srtp_null_cipher = { |
| 144 srtp_null_cipher_alloc, |
| 145 srtp_null_cipher_dealloc, |
| 146 srtp_null_cipher_init, |
| 147 0, /* set_aad */ |
| 148 srtp_null_cipher_encrypt, |
| 149 srtp_null_cipher_encrypt, |
| 150 srtp_null_cipher_set_iv, |
| 151 0, /* get_tag */ |
| 152 srtp_null_cipher_description, |
| 153 &srtp_null_cipher_test_0, |
| 154 SRTP_NULL_CIPHER |
| 155 }; |
| 156 |
OLD | NEW |