1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/srtp/src/crypto/hash/null_auth.c Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,162 @@ 1.4 +/* 1.5 + * null_auth.c 1.6 + * 1.7 + * implements the do-nothing auth algorithm 1.8 + * 1.9 + * David A. McGrew 1.10 + * Cisco Systems, Inc. 1.11 + * 1.12 + */ 1.13 + 1.14 +/* 1.15 + * 1.16 + * Copyright (c) 2001-2006, Cisco Systems, Inc. 1.17 + * All rights reserved. 1.18 + * 1.19 + * Redistribution and use in source and binary forms, with or without 1.20 + * modification, are permitted provided that the following conditions 1.21 + * are met: 1.22 + * 1.23 + * Redistributions of source code must retain the above copyright 1.24 + * notice, this list of conditions and the following disclaimer. 1.25 + * 1.26 + * Redistributions in binary form must reproduce the above 1.27 + * copyright notice, this list of conditions and the following 1.28 + * disclaimer in the documentation and/or other materials provided 1.29 + * with the distribution. 1.30 + * 1.31 + * Neither the name of the Cisco Systems, Inc. nor the names of its 1.32 + * contributors may be used to endorse or promote products derived 1.33 + * from this software without specific prior written permission. 1.34 + * 1.35 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1.36 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1.37 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 1.38 + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 1.39 + * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 1.40 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 1.41 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 1.42 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 1.43 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 1.44 + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 1.45 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 1.46 + * OF THE POSSIBILITY OF SUCH DAMAGE. 1.47 + * 1.48 + */ 1.49 + 1.50 + 1.51 +#include "null_auth.h" 1.52 +#include "alloc.h" 1.53 + 1.54 +/* null_auth uses the auth debug module */ 1.55 + 1.56 +extern debug_module_t mod_auth; 1.57 + 1.58 +err_status_t 1.59 +null_auth_alloc(auth_t **a, int key_len, int out_len) { 1.60 + extern auth_type_t null_auth; 1.61 + uint8_t *pointer; 1.62 + 1.63 + debug_print(mod_auth, "allocating auth func with key length %d", key_len); 1.64 + debug_print(mod_auth, " tag length %d", out_len); 1.65 + 1.66 + /* allocate memory for auth and null_auth_ctx_t structures */ 1.67 + pointer = (uint8_t*)crypto_alloc(sizeof(null_auth_ctx_t) + sizeof(auth_t)); 1.68 + if (pointer == NULL) 1.69 + return err_status_alloc_fail; 1.70 + 1.71 + /* set pointers */ 1.72 + *a = (auth_t *)pointer; 1.73 + (*a)->type = &null_auth; 1.74 + (*a)->state = pointer + sizeof (auth_t); 1.75 + (*a)->out_len = out_len; 1.76 + (*a)->prefix_len = out_len; 1.77 + (*a)->key_len = key_len; 1.78 + 1.79 + /* increment global count of all null_auth uses */ 1.80 + null_auth.ref_count++; 1.81 + 1.82 + return err_status_ok; 1.83 +} 1.84 + 1.85 +err_status_t 1.86 +null_auth_dealloc(auth_t *a) { 1.87 + extern auth_type_t null_auth; 1.88 + 1.89 + /* zeroize entire state*/ 1.90 + octet_string_set_to_zero((uint8_t *)a, 1.91 + sizeof(null_auth_ctx_t) + sizeof(auth_t)); 1.92 + 1.93 + /* free memory */ 1.94 + crypto_free(a); 1.95 + 1.96 + /* decrement global count of all null_auth uses */ 1.97 + null_auth.ref_count--; 1.98 + 1.99 + return err_status_ok; 1.100 +} 1.101 + 1.102 +err_status_t 1.103 +null_auth_init(null_auth_ctx_t *state, const uint8_t *key, int key_len) { 1.104 + 1.105 + /* accept any length of key, and do nothing */ 1.106 + 1.107 + return err_status_ok; 1.108 +} 1.109 + 1.110 +err_status_t 1.111 +null_auth_compute(null_auth_ctx_t *state, uint8_t *message, 1.112 + int msg_octets, int tag_len, uint8_t *result) { 1.113 + 1.114 + return err_status_ok; 1.115 +} 1.116 + 1.117 +err_status_t 1.118 +null_auth_update(null_auth_ctx_t *state, uint8_t *message, 1.119 + int msg_octets) { 1.120 + 1.121 + return err_status_ok; 1.122 +} 1.123 + 1.124 +err_status_t 1.125 +null_auth_start(null_auth_ctx_t *state) { 1.126 + return err_status_ok; 1.127 +} 1.128 + 1.129 +/* 1.130 + * auth_type_t - defines description, test case, and null_auth 1.131 + * metaobject 1.132 + */ 1.133 + 1.134 +/* begin test case 0 */ 1.135 + 1.136 +auth_test_case_t 1.137 +null_auth_test_case_0 = { 1.138 + 0, /* octets in key */ 1.139 + NULL, /* key */ 1.140 + 0, /* octets in data */ 1.141 + NULL, /* data */ 1.142 + 0, /* octets in tag */ 1.143 + NULL, /* tag */ 1.144 + NULL /* pointer to next testcase */ 1.145 +}; 1.146 + 1.147 +/* end test case 0 */ 1.148 + 1.149 +char null_auth_description[] = "null authentication function"; 1.150 + 1.151 +auth_type_t 1.152 +null_auth = { 1.153 + (auth_alloc_func) null_auth_alloc, 1.154 + (auth_dealloc_func) null_auth_dealloc, 1.155 + (auth_init_func) null_auth_init, 1.156 + (auth_compute_func) null_auth_compute, 1.157 + (auth_update_func) null_auth_update, 1.158 + (auth_start_func) null_auth_start, 1.159 + (char *) null_auth_description, 1.160 + (int) 0, /* instance count */ 1.161 + (auth_test_case_t *) &null_auth_test_case_0, 1.162 + (debug_module_t *) NULL, 1.163 + (auth_type_id_t) NULL_AUTH 1.164 +}; 1.165 +