/src/libsrtp/crypto/hash/null_auth.c
Line | Count | Source (jump to first uncovered line) |
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 | 7.55k | { |
60 | 7.55k | extern const srtp_auth_type_t srtp_null_auth; |
61 | 7.55k | uint8_t *pointer; |
62 | | |
63 | 7.55k | debug_print(srtp_mod_auth, "allocating auth func with key length %d", |
64 | 7.55k | key_len); |
65 | 7.55k | debug_print(srtp_mod_auth, " tag length %d", |
66 | 7.55k | out_len); |
67 | | |
68 | | /* allocate memory for auth and srtp_null_auth_ctx_t structures */ |
69 | 7.55k | pointer = (uint8_t *)srtp_crypto_alloc(sizeof(srtp_null_auth_ctx_t) + |
70 | 7.55k | sizeof(srtp_auth_t)); |
71 | 7.55k | if (pointer == NULL) { |
72 | 0 | return srtp_err_status_alloc_fail; |
73 | 0 | } |
74 | | |
75 | | /* set pointers */ |
76 | 7.55k | *a = (srtp_auth_t *)pointer; |
77 | 7.55k | (*a)->type = &srtp_null_auth; |
78 | 7.55k | (*a)->state = pointer + sizeof(srtp_auth_t); |
79 | 7.55k | (*a)->out_len = out_len; |
80 | 7.55k | (*a)->prefix_len = out_len; |
81 | 7.55k | (*a)->key_len = key_len; |
82 | | |
83 | 7.55k | return srtp_err_status_ok; |
84 | 7.55k | } |
85 | | |
86 | | static srtp_err_status_t srtp_null_auth_dealloc(srtp_auth_t *a) |
87 | 7.55k | { |
88 | 7.55k | extern const srtp_auth_type_t srtp_null_auth; |
89 | | |
90 | | /* zeroize entire state*/ |
91 | 7.55k | octet_string_set_to_zero(a, sizeof(srtp_null_auth_ctx_t) + |
92 | 7.55k | sizeof(srtp_auth_t)); |
93 | | |
94 | | /* free memory */ |
95 | 7.55k | srtp_crypto_free(a); |
96 | | |
97 | 7.55k | return srtp_err_status_ok; |
98 | 7.55k | } |
99 | | |
100 | | static srtp_err_status_t srtp_null_auth_init(void *statev, |
101 | | const uint8_t *key, |
102 | | int key_len) |
103 | 7.35k | { |
104 | | /* srtp_null_auth_ctx_t *state = (srtp_null_auth_ctx_t *)statev; */ |
105 | 7.35k | (void)statev; |
106 | 7.35k | (void)key; |
107 | 7.35k | (void)key_len; |
108 | | |
109 | | /* accept any length of key, and do nothing */ |
110 | | |
111 | 7.35k | return srtp_err_status_ok; |
112 | 7.35k | } |
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 | 11.5k | { |
120 | | /* srtp_null_auth_ctx_t *state = (srtp_null_auth_ctx_t *)statev; */ |
121 | 11.5k | (void)statev; |
122 | 11.5k | (void)message; |
123 | 11.5k | (void)msg_octets; |
124 | 11.5k | (void)tag_len; |
125 | 11.5k | (void)result; |
126 | | |
127 | 11.5k | return srtp_err_status_ok; |
128 | 11.5k | } |
129 | | |
130 | | static srtp_err_status_t srtp_null_auth_update(void *statev, |
131 | | const uint8_t *message, |
132 | | int msg_octets) |
133 | 0 | { |
134 | | /* srtp_null_auth_ctx_t *state = (srtp_null_auth_ctx_t *)statev; */ |
135 | 0 | (void)statev; |
136 | 0 | (void)message; |
137 | 0 | (void)msg_octets; |
138 | |
|
139 | 0 | return srtp_err_status_ok; |
140 | 0 | } |
141 | | |
142 | | static srtp_err_status_t srtp_null_auth_start(void *statev) |
143 | 11.5k | { |
144 | | /* srtp_null_auth_ctx_t *state = (srtp_null_auth_ctx_t *)statev; */ |
145 | 11.5k | (void)statev; |
146 | | |
147 | 11.5k | return srtp_err_status_ok; |
148 | 11.5k | } |
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 | | }; |