OLD | NEW |
(Empty) | |
| 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-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 #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 |
| 55 /* null_auth uses the auth debug module */ |
| 56 |
| 57 extern srtp_debug_module_t srtp_mod_auth; |
| 58 |
| 59 static srtp_err_status_t srtp_null_auth_alloc (srtp_auth_t **a, int key_len, int
out_len) |
| 60 { |
| 61 extern const srtp_auth_type_t srtp_null_auth; |
| 62 uint8_t *pointer; |
| 63 |
| 64 debug_print(srtp_mod_auth, "allocating auth func with key length %d", key_le
n); |
| 65 debug_print(srtp_mod_auth, " tag length %d", out_le
n); |
| 66 |
| 67 /* allocate memory for auth and srtp_null_auth_ctx_t structures */ |
| 68 pointer = (uint8_t*)srtp_crypto_alloc(sizeof(srtp_null_auth_ctx_t) + sizeof(
srtp_auth_t)); |
| 69 if (pointer == NULL) { |
| 70 return srtp_err_status_alloc_fail; |
| 71 } |
| 72 |
| 73 /* set pointers */ |
| 74 *a = (srtp_auth_t*)pointer; |
| 75 (*a)->type = &srtp_null_auth; |
| 76 (*a)->state = pointer + sizeof(srtp_auth_t); |
| 77 (*a)->out_len = out_len; |
| 78 (*a)->prefix_len = out_len; |
| 79 (*a)->key_len = key_len; |
| 80 |
| 81 return srtp_err_status_ok; |
| 82 } |
| 83 |
| 84 static srtp_err_status_t srtp_null_auth_dealloc (srtp_auth_t *a) |
| 85 { |
| 86 extern const srtp_auth_type_t srtp_null_auth; |
| 87 |
| 88 /* zeroize entire state*/ |
| 89 octet_string_set_to_zero((uint8_t*)a, |
| 90 sizeof(srtp_null_auth_ctx_t) + sizeof(srtp_auth_t))
; |
| 91 |
| 92 /* free memory */ |
| 93 srtp_crypto_free(a); |
| 94 |
| 95 return srtp_err_status_ok; |
| 96 } |
| 97 |
| 98 static srtp_err_status_t srtp_null_auth_init (void *statev, const uint8_t *key,
int key_len) |
| 99 { |
| 100 /* srtp_null_auth_ctx_t *state = (srtp_null_auth_ctx_t *)statev; */ |
| 101 /* accept any length of key, and do nothing */ |
| 102 |
| 103 return srtp_err_status_ok; |
| 104 } |
| 105 |
| 106 static srtp_err_status_t srtp_null_auth_compute (void *statev, const uint8_t *me
ssage, |
| 107 int msg_octets, int tag_len, uint8_t *
result) |
| 108 { |
| 109 /* srtp_null_auth_ctx_t *state = (srtp_null_auth_ctx_t *)statev; */ |
| 110 |
| 111 return srtp_err_status_ok; |
| 112 } |
| 113 |
| 114 static srtp_err_status_t srtp_null_auth_update (void *statev, const uint8_t *mes
sage, |
| 115 int msg_octets) |
| 116 { |
| 117 /* srtp_null_auth_ctx_t *state = (srtp_null_auth_ctx_t *)statev; */ |
| 118 |
| 119 return srtp_err_status_ok; |
| 120 } |
| 121 |
| 122 static srtp_err_status_t srtp_null_auth_start (void *statev) |
| 123 { |
| 124 /* srtp_null_auth_ctx_t *state = (srtp_null_auth_ctx_t *)statev; */ |
| 125 |
| 126 return srtp_err_status_ok; |
| 127 } |
| 128 |
| 129 /* |
| 130 * srtp_auth_type_t - defines description, test case, and null_auth |
| 131 * metaobject |
| 132 */ |
| 133 |
| 134 /* begin test case 0 */ |
| 135 |
| 136 static const srtp_auth_test_case_t srtp_null_auth_test_case_0 = { |
| 137 0, /* octets in key */ |
| 138 NULL, /* key */ |
| 139 0, /* octets in data */ |
| 140 NULL, /* data */ |
| 141 0, /* octets in tag */ |
| 142 NULL, /* tag */ |
| 143 NULL /* pointer to next testcase */ |
| 144 }; |
| 145 |
| 146 /* end test case 0 */ |
| 147 |
| 148 static const char srtp_null_auth_description[] = "null authentication function"; |
| 149 |
| 150 const srtp_auth_type_t srtp_null_auth = { |
| 151 srtp_null_auth_alloc, |
| 152 srtp_null_auth_dealloc, |
| 153 srtp_null_auth_init, |
| 154 srtp_null_auth_compute, |
| 155 srtp_null_auth_update, |
| 156 srtp_null_auth_start, |
| 157 srtp_null_auth_description, |
| 158 &srtp_null_auth_test_case_0, |
| 159 SRTP_NULL_AUTH |
| 160 }; |
| 161 |
OLD | NEW |