null_auth.c (5690B)
1 /* 2 * null_auth.c 3 * 4 * implements the do-nothing auth algorithm 5 * 6 * David A. McGrew 7 * Cisco Systems, Inc. 8 * 9 */ 10 11 /* 12 * 13 * Copyright (c) 2001-2017, 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 "null_auth.h" 52 #include "err.h" /* for srtp_debug */ 53 #include "alloc.h" 54 #include "cipher_types.h" 55 56 static srtp_err_status_t srtp_null_auth_alloc(srtp_auth_t **a, 57 int key_len, 58 int out_len) 59 { 60 extern const srtp_auth_type_t srtp_null_auth; 61 uint8_t *pointer; 62 63 debug_print(srtp_mod_auth, "allocating auth func with key length %d", 64 key_len); 65 debug_print(srtp_mod_auth, " tag length %d", 66 out_len); 67 68 /* allocate memory for auth and srtp_null_auth_ctx_t structures */ 69 pointer = (uint8_t *)srtp_crypto_alloc(sizeof(srtp_null_auth_ctx_t) + 70 sizeof(srtp_auth_t)); 71 if (pointer == NULL) { 72 return srtp_err_status_alloc_fail; 73 } 74 75 /* set pointers */ 76 *a = (srtp_auth_t *)pointer; 77 (*a)->type = &srtp_null_auth; 78 (*a)->state = pointer + sizeof(srtp_auth_t); 79 (*a)->out_len = out_len; 80 (*a)->prefix_len = out_len; 81 (*a)->key_len = key_len; 82 83 return srtp_err_status_ok; 84 } 85 86 static srtp_err_status_t srtp_null_auth_dealloc(srtp_auth_t *a) 87 { 88 extern const srtp_auth_type_t srtp_null_auth; 89 90 /* zeroize entire state*/ 91 octet_string_set_to_zero(a, sizeof(srtp_null_auth_ctx_t) + 92 sizeof(srtp_auth_t)); 93 94 /* free memory */ 95 srtp_crypto_free(a); 96 97 return srtp_err_status_ok; 98 } 99 100 static srtp_err_status_t srtp_null_auth_init(void *statev, 101 const uint8_t *key, 102 int key_len) 103 { 104 /* srtp_null_auth_ctx_t *state = (srtp_null_auth_ctx_t *)statev; */ 105 (void)statev; 106 (void)key; 107 (void)key_len; 108 109 /* accept any length of key, and do nothing */ 110 111 return srtp_err_status_ok; 112 } 113 114 static srtp_err_status_t srtp_null_auth_compute(void *statev, 115 const uint8_t *message, 116 int msg_octets, 117 int tag_len, 118 uint8_t *result) 119 { 120 /* srtp_null_auth_ctx_t *state = (srtp_null_auth_ctx_t *)statev; */ 121 (void)statev; 122 (void)message; 123 (void)msg_octets; 124 (void)tag_len; 125 (void)result; 126 127 return srtp_err_status_ok; 128 } 129 130 static srtp_err_status_t srtp_null_auth_update(void *statev, 131 const uint8_t *message, 132 int msg_octets) 133 { 134 /* srtp_null_auth_ctx_t *state = (srtp_null_auth_ctx_t *)statev; */ 135 (void)statev; 136 (void)message; 137 (void)msg_octets; 138 139 return srtp_err_status_ok; 140 } 141 142 static srtp_err_status_t srtp_null_auth_start(void *statev) 143 { 144 /* srtp_null_auth_ctx_t *state = (srtp_null_auth_ctx_t *)statev; */ 145 (void)statev; 146 147 return srtp_err_status_ok; 148 } 149 150 /* 151 * srtp_auth_type_t - defines description, test case, and null_auth 152 * metaobject 153 */ 154 155 /* begin test case 0 */ 156 157 static const srtp_auth_test_case_t srtp_null_auth_test_case_0 = { 158 0, /* octets in key */ 159 NULL, /* key */ 160 0, /* octets in data */ 161 NULL, /* data */ 162 0, /* octets in tag */ 163 NULL, /* tag */ 164 NULL /* pointer to next testcase */ 165 }; 166 167 /* end test case 0 */ 168 169 static const char srtp_null_auth_description[] = "null authentication function"; 170 171 const srtp_auth_type_t srtp_null_auth = { 172 srtp_null_auth_alloc, /* */ 173 srtp_null_auth_dealloc, /* */ 174 srtp_null_auth_init, /* */ 175 srtp_null_auth_compute, /* */ 176 srtp_null_auth_update, /* */ 177 srtp_null_auth_start, /* */ 178 srtp_null_auth_description, /* */ 179 &srtp_null_auth_test_case_0, /* */ 180 SRTP_NULL_AUTH /* */ 181 };