blob: cc883ec909053a7f1446d1a4fcebdf146020f786 [file] [log] [blame]
Cullen Jennings235513a2005-09-21 22:51:36 +00001/*
2 * crypto_kernel.c
3 *
4 * header for the cryptographic kernel
5 *
6 * David A. McGrew
7 * Cisco Systems, Inc.
8 */
9/*
jfigus92736bc2014-11-21 10:30:54 -050010 *
jfigus7882dd92013-08-02 16:08:23 -040011 * Copyright(c) 2001-2006,2013 Cisco Systems, Inc.
Cullen Jennings235513a2005-09-21 22:51:36 +000012 * All rights reserved.
jfigus92736bc2014-11-21 10:30:54 -050013 *
Cullen Jennings235513a2005-09-21 22:51:36 +000014 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
jfigus92736bc2014-11-21 10:30:54 -050017 *
Cullen Jennings235513a2005-09-21 22:51:36 +000018 * Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
jfigus92736bc2014-11-21 10:30:54 -050020 *
Cullen Jennings235513a2005-09-21 22:51:36 +000021 * Redistributions in binary form must reproduce the above
22 * copyright notice, this list of conditions and the following
23 * disclaimer in the documentation and/or other materials provided
24 * with the distribution.
jfigus92736bc2014-11-21 10:30:54 -050025 *
Cullen Jennings235513a2005-09-21 22:51:36 +000026 * Neither the name of the Cisco Systems, Inc. nor the names of its
27 * contributors may be used to endorse or promote products derived
28 * from this software without specific prior written permission.
jfigus92736bc2014-11-21 10:30:54 -050029 *
Cullen Jennings235513a2005-09-21 22:51:36 +000030 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
33 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
34 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
35 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
36 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
37 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
40 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
41 * OF THE POSSIBILITY OF SUCH DAMAGE.
42 *
43 */
44
45
Teerapap Changwichukarn6cffe242014-09-24 11:24:07 +080046#ifdef HAVE_CONFIG_H
47 #include <config.h>
48#endif
49
Cullen Jennings235513a2005-09-21 22:51:36 +000050#include "alloc.h"
51
52#include "crypto_kernel.h"
53
54/* the debug module for the crypto_kernel */
55
jfigus02d6f032014-11-21 10:56:42 -050056srtp_debug_module_t srtp_mod_crypto_kernel = {
jfigus92736bc2014-11-21 10:30:54 -050057 0, /* debugging is off by default */
58 "crypto kernel" /* printable name for module */
Cullen Jennings235513a2005-09-21 22:51:36 +000059};
60
61/*
62 * other debug modules that can be included in the kernel
63 */
64
jfigus02d6f032014-11-21 10:56:42 -050065extern srtp_debug_module_t srtp_mod_auth;
66extern srtp_debug_module_t srtp_mod_cipher;
67extern srtp_debug_module_t mod_stat;
68extern srtp_debug_module_t mod_alloc;
Cullen Jennings235513a2005-09-21 22:51:36 +000069
jfigus92736bc2014-11-21 10:30:54 -050070/*
Cullen Jennings235513a2005-09-21 22:51:36 +000071 * cipher types that can be included in the kernel
jfigus92736bc2014-11-21 10:30:54 -050072 */
Cullen Jennings235513a2005-09-21 22:51:36 +000073
jfigus9de994f2014-11-20 09:17:19 -050074extern srtp_cipher_type_t srtp_null_cipher;
jfigus9a840432014-11-19 15:48:21 -050075extern srtp_cipher_type_t srtp_aes_icm;
jfigusa3127b82014-11-19 14:46:52 -050076#ifdef OPENSSL
jfigus9a840432014-11-19 15:48:21 -050077extern srtp_cipher_type_t srtp_aes_gcm_128_openssl;
78extern srtp_cipher_type_t srtp_aes_gcm_256_openssl;
jfigus0d3a2682013-04-02 15:42:37 -040079#endif
Cullen Jennings235513a2005-09-21 22:51:36 +000080
81
82/*
83 * auth func types that can be included in the kernel
84 */
85
jfigus9de994f2014-11-20 09:17:19 -050086extern srtp_auth_type_t srtp_null_auth;
jfigusae4f3b12014-11-20 09:34:08 -050087extern srtp_auth_type_t srtp_hmac;
Cullen Jennings235513a2005-09-21 22:51:36 +000088
89/* crypto_kernel is a global variable, the only one of its datatype */
90
jfigus92736bc2014-11-21 10:30:54 -050091srtp_crypto_kernel_t crypto_kernel = {
92 srtp_crypto_kernel_state_insecure, /* start off in insecure state */
93 NULL, /* no cipher types yet */
94 NULL, /* no auth types yet */
95 NULL /* no debug modules yet */
Cullen Jennings235513a2005-09-21 22:51:36 +000096};
97
David McGrewb0ad0702006-03-17 20:51:24 +000098#define MAX_RNG_TRIALS 25
David McGrew026b47c2006-03-17 18:22:41 +000099
jfigus92736bc2014-11-21 10:30:54 -0500100srtp_err_status_t srtp_crypto_kernel_init ()
101{
102 srtp_err_status_t status;
Cullen Jennings235513a2005-09-21 22:51:36 +0000103
jfigus92736bc2014-11-21 10:30:54 -0500104 /* check the security state */
105 if (crypto_kernel.state == srtp_crypto_kernel_state_secure) {
David McGrew98beafa2005-10-07 12:59:57 +0000106
jfigus92736bc2014-11-21 10:30:54 -0500107 /*
108 * we're already in the secure state, but we've been asked to
109 * re-initialize, so we just re-run the self-tests and then return
110 */
111 return srtp_crypto_kernel_status();
112 }
Cullen Jennings235513a2005-09-21 22:51:36 +0000113
jfigus92736bc2014-11-21 10:30:54 -0500114 /* initialize error reporting system */
jfigus02d6f032014-11-21 10:56:42 -0500115 status = srtp_err_reporting_init("crypto");
jfigus92736bc2014-11-21 10:30:54 -0500116 if (status) {
117 return status;
118 }
Cullen Jennings235513a2005-09-21 22:51:36 +0000119
jfigus92736bc2014-11-21 10:30:54 -0500120 /* load debug modules */
121 status = srtp_crypto_kernel_load_debug_module(&srtp_mod_crypto_kernel);
122 if (status) {
123 return status;
124 }
125 status = srtp_crypto_kernel_load_debug_module(&srtp_mod_auth);
126 if (status) {
127 return status;
128 }
129 status = srtp_crypto_kernel_load_debug_module(&srtp_mod_cipher);
130 if (status) {
131 return status;
132 }
133 status = srtp_crypto_kernel_load_debug_module(&mod_stat);
134 if (status) {
135 return status;
136 }
137 status = srtp_crypto_kernel_load_debug_module(&mod_alloc);
138 if (status) {
139 return status;
140 }
Cullen Jennings235513a2005-09-21 22:51:36 +0000141
jfigus92736bc2014-11-21 10:30:54 -0500142 /* initialize random number generator */
143 status = rand_source_init();
144 if (status) {
145 return status;
146 }
147
148 /* run FIPS-140 statistical tests on rand_source */
149 status = stat_test_rand_source_with_repetition(rand_source_get_octet_string, MAX_RNG_TRIALS);
150 if (status) {
151 return status;
152 }
153
154 /* load cipher types */
155 status = srtp_crypto_kernel_load_cipher_type(&srtp_null_cipher, SRTP_NULL_CIPHER);
156 if (status) {
157 return status;
158 }
159 status = srtp_crypto_kernel_load_cipher_type(&srtp_aes_icm, SRTP_AES_ICM);
160 if (status) {
161 return status;
162 }
jfigusa3127b82014-11-19 14:46:52 -0500163#ifdef OPENSSL
jfigus92736bc2014-11-21 10:30:54 -0500164 status = srtp_crypto_kernel_load_cipher_type(&srtp_aes_gcm_128_openssl, SRTP_AES_128_GCM);
165 if (status) {
166 return status;
167 }
168 status = srtp_crypto_kernel_load_cipher_type(&srtp_aes_gcm_256_openssl, SRTP_AES_256_GCM);
169 if (status) {
170 return status;
171 }
jfigus0d3a2682013-04-02 15:42:37 -0400172#endif
Cullen Jennings235513a2005-09-21 22:51:36 +0000173
jfigus92736bc2014-11-21 10:30:54 -0500174 /* load auth func types */
175 status = srtp_crypto_kernel_load_auth_type(&srtp_null_auth, SRTP_NULL_AUTH);
176 if (status) {
177 return status;
178 }
179 status = srtp_crypto_kernel_load_auth_type(&srtp_hmac, SRTP_HMAC_SHA1);
180 if (status) {
181 return status;
182 }
Cullen Jennings235513a2005-09-21 22:51:36 +0000183
jfigus92736bc2014-11-21 10:30:54 -0500184 /* change state to secure */
185 crypto_kernel.state = srtp_crypto_kernel_state_secure;
Cullen Jennings235513a2005-09-21 22:51:36 +0000186
jfigus92736bc2014-11-21 10:30:54 -0500187 return srtp_err_status_ok;
Cullen Jennings235513a2005-09-21 22:51:36 +0000188}
189
jfigus92736bc2014-11-21 10:30:54 -0500190srtp_err_status_t srtp_crypto_kernel_status ()
191{
192 srtp_err_status_t status;
193 srtp_kernel_cipher_type_t *ctype = crypto_kernel.cipher_type_list;
194 srtp_kernel_auth_type_t *atype = crypto_kernel.auth_type_list;
195 srtp_kernel_debug_module_t *dm = crypto_kernel.debug_module_list;
Cullen Jennings235513a2005-09-21 22:51:36 +0000196
jfigus92736bc2014-11-21 10:30:54 -0500197 /* run FIPS-140 statistical tests on rand_source */
198 printf("testing rand_source...");
199 status = stat_test_rand_source_with_repetition(rand_source_get_octet_string, MAX_RNG_TRIALS);
Cullen Jennings235513a2005-09-21 22:51:36 +0000200 if (status) {
jfigus92736bc2014-11-21 10:30:54 -0500201 printf("failed\n");
202 crypto_kernel.state = srtp_crypto_kernel_state_insecure;
203 return status;
Cullen Jennings235513a2005-09-21 22:51:36 +0000204 }
205 printf("passed\n");
jfigus92736bc2014-11-21 10:30:54 -0500206
207 /* for each cipher type, describe and test */
208 while (ctype != NULL) {
209 printf("cipher: %s\n", ctype->cipher_type->description);
210 printf(" self-test: ");
211 status = srtp_cipher_type_self_test(ctype->cipher_type);
212 if (status) {
213 printf("failed with error code %d\n", status);
214 exit(status);
215 }
216 printf("passed\n");
217 ctype = ctype->next;
218 }
219
220 /* for each auth type, describe and test */
221 while (atype != NULL) {
222 printf("auth func: %s\n", atype->auth_type->description);
223 printf(" self-test: ");
224 status = srtp_auth_type_self_test(atype->auth_type);
225 if (status) {
226 printf("failed with error code %d\n", status);
227 exit(status);
228 }
229 printf("passed\n");
230 atype = atype->next;
231 }
232
233 /* describe each debug module */
234 printf("debug modules loaded:\n");
235 while (dm != NULL) {
236 printf(" %s ", dm->mod->name);
237 if (dm->mod->on) {
238 printf("(on)\n");
239 } else{
240 printf("(off)\n");
241 }
242 dm = dm->next;
243 }
244
245 return srtp_err_status_ok;
246}
247
248srtp_err_status_t srtp_crypto_kernel_list_debug_modules ()
249{
250 srtp_kernel_debug_module_t *dm = crypto_kernel.debug_module_list;
251
252 /* describe each debug module */
253 printf("debug modules loaded:\n");
254 while (dm != NULL) {
255 printf(" %s ", dm->mod->name);
256 if (dm->mod->on) {
257 printf("(on)\n");
258 } else{
259 printf("(off)\n");
260 }
261 dm = dm->next;
262 }
263
264 return srtp_err_status_ok;
265}
266
267srtp_err_status_t srtp_crypto_kernel_shutdown ()
268{
269 srtp_err_status_t status;
270
271 /*
272 * free dynamic memory used in crypto_kernel at present
273 */
274
275 /* walk down cipher type list, freeing memory */
276 while (crypto_kernel.cipher_type_list != NULL) {
277 srtp_kernel_cipher_type_t *ctype = crypto_kernel.cipher_type_list;
278 crypto_kernel.cipher_type_list = ctype->next;
279 debug_print(srtp_mod_crypto_kernel,
280 "freeing memory for cipher %s",
281 ctype->cipher_type->description);
282 srtp_crypto_free(ctype);
283 }
284
285 /* walk down authetication module list, freeing memory */
286 while (crypto_kernel.auth_type_list != NULL) {
287 srtp_kernel_auth_type_t *atype = crypto_kernel.auth_type_list;
288 crypto_kernel.auth_type_list = atype->next;
289 debug_print(srtp_mod_crypto_kernel,
290 "freeing memory for authentication %s",
291 atype->auth_type->description);
292 srtp_crypto_free(atype);
293 }
294
295 /* walk down debug module list, freeing memory */
296 while (crypto_kernel.debug_module_list != NULL) {
297 srtp_kernel_debug_module_t *kdm = crypto_kernel.debug_module_list;
298 crypto_kernel.debug_module_list = kdm->next;
299 debug_print(srtp_mod_crypto_kernel,
300 "freeing memory for debug module %s",
301 kdm->mod->name);
302 srtp_crypto_free(kdm);
303 }
304
305 /* de-initialize random number generator */ status = rand_source_deinit();
Cullen Jennings235513a2005-09-21 22:51:36 +0000306 if (status) {
jfigus92736bc2014-11-21 10:30:54 -0500307 return status;
Cullen Jennings235513a2005-09-21 22:51:36 +0000308 }
Cullen Jennings235513a2005-09-21 22:51:36 +0000309
jfigus92736bc2014-11-21 10:30:54 -0500310 /* return to insecure state */
311 crypto_kernel.state = srtp_crypto_kernel_state_insecure;
Cullen Jennings235513a2005-09-21 22:51:36 +0000312
jfigus92736bc2014-11-21 10:30:54 -0500313 return srtp_err_status_ok;
Cullen Jennings235513a2005-09-21 22:51:36 +0000314}
315
jfigus92736bc2014-11-21 10:30:54 -0500316static inline srtp_err_status_t srtp_crypto_kernel_do_load_cipher_type (srtp_cipher_type_t *new_ct, srtp_cipher_type_id_t id, int replace)
317{
318 srtp_kernel_cipher_type_t *ctype, *new_ctype;
319 srtp_err_status_t status;
Cullen Jennings235513a2005-09-21 22:51:36 +0000320
jfigus92736bc2014-11-21 10:30:54 -0500321 /* defensive coding */
322 if (new_ct == NULL) {
323 return srtp_err_status_bad_param;
Jonathan Lennoxdc4d8842010-05-20 23:53:15 +0000324 }
Cullen Jennings235513a2005-09-21 22:51:36 +0000325
jfigus92736bc2014-11-21 10:30:54 -0500326 if (new_ct->id != id) {
327 return srtp_err_status_bad_param;
328 }
329
330 /* check cipher type by running self-test */
331 status = srtp_cipher_type_self_test(new_ct);
332 if (status) {
333 return status;
334 }
335
336 /* walk down list, checking if this type is in the list already */
337 ctype = crypto_kernel.cipher_type_list;
338 while (ctype != NULL) {
339 if (id == ctype->id) {
340 if (!replace) {
341 return srtp_err_status_bad_param;
342 }
343 status = srtp_cipher_type_test(new_ct, ctype->cipher_type->test_data);
344 if (status) {
345 return status;
346 }
347 new_ctype = ctype;
348 break;
349 }else if (new_ct == ctype->cipher_type) {
350 return srtp_err_status_bad_param;
351 }
352 ctype = ctype->next;
353 }
354
355 /* if not found, put new_ct at the head of the list */
356 if (ctype == NULL) {
357 /* allocate memory */
358 new_ctype = (srtp_kernel_cipher_type_t*)srtp_crypto_alloc(sizeof(srtp_kernel_cipher_type_t));
359 if (new_ctype == NULL) {
360 return srtp_err_status_alloc_fail;
361 }
362 new_ctype->next = crypto_kernel.cipher_type_list;
363
364 /* set head of list to new cipher type */
365 crypto_kernel.cipher_type_list = new_ctype;
366 }
367
368 /* set fields */
369 new_ctype->cipher_type = new_ct;
370 new_ctype->id = id;
371
372 /* load debug module, if there is one present */
373 if (new_ct->debug != NULL) {
374 srtp_crypto_kernel_load_debug_module(new_ct->debug);
375 }
376 /* we could check for errors here */
377
378 return srtp_err_status_ok;
379}
380
381srtp_err_status_t srtp_crypto_kernel_load_cipher_type (srtp_cipher_type_t *new_ct, srtp_cipher_type_id_t id)
382{
383 return srtp_crypto_kernel_do_load_cipher_type(new_ct, id, 0);
384}
385
386srtp_err_status_t srtp_crypto_kernel_replace_cipher_type (srtp_cipher_type_t *new_ct, srtp_cipher_type_id_t id)
387{
388 return srtp_crypto_kernel_do_load_cipher_type(new_ct, id, 1);
389}
390
391srtp_err_status_t srtp_crypto_kernel_do_load_auth_type (srtp_auth_type_t *new_at, srtp_auth_type_id_t id, int replace)
392{
393 srtp_kernel_auth_type_t *atype, *new_atype;
394 srtp_err_status_t status;
395
396 /* defensive coding */
397 if (new_at == NULL) {
398 return srtp_err_status_bad_param;
399 }
400
401 if (new_at->id != id) {
402 return srtp_err_status_bad_param;
403 }
404
405 /* check auth type by running self-test */
406 status = srtp_auth_type_self_test(new_at);
407 if (status) {
408 return status;
409 }
410
411 /* walk down list, checking if this type is in the list already */
412 atype = crypto_kernel.auth_type_list;
413 while (atype != NULL) {
414 if (id == atype->id) {
415 if (!replace) {
416 return srtp_err_status_bad_param;
417 }
418 status = srtp_auth_type_test(new_at, atype->auth_type->test_data);
419 if (status) {
420 return status;
421 }
422 new_atype = atype;
423 break;
424 }else if (new_at == atype->auth_type) {
425 return srtp_err_status_bad_param;
426 }
427 atype = atype->next;
428 }
429
430 /* if not found, put new_at at the head of the list */
431 if (atype == NULL) {
432 /* allocate memory */
433 new_atype = (srtp_kernel_auth_type_t*)srtp_crypto_alloc(sizeof(srtp_kernel_auth_type_t));
434 if (new_atype == NULL) {
435 return srtp_err_status_alloc_fail;
436 }
437
438 new_atype->next = crypto_kernel.auth_type_list;
439 /* set head of list to new auth type */
440 crypto_kernel.auth_type_list = new_atype;
441 }
442
443 /* set fields */
444 new_atype->auth_type = new_at;
445 new_atype->id = id;
446
447 /* load debug module, if there is one present */
448 if (new_at->debug != NULL) {
449 srtp_crypto_kernel_load_debug_module(new_at->debug);
450 }
451 /* we could check for errors here */
452
453 return srtp_err_status_ok;
454
455}
456
457srtp_err_status_t srtp_crypto_kernel_load_auth_type (srtp_auth_type_t *new_at, srtp_auth_type_id_t id)
458{
459 return srtp_crypto_kernel_do_load_auth_type(new_at, id, 0);
460}
461
462srtp_err_status_t srtp_crypto_kernel_replace_auth_type (srtp_auth_type_t *new_at, srtp_auth_type_id_t id)
463{
464 return srtp_crypto_kernel_do_load_auth_type(new_at, id, 1);
465}
466
467
468srtp_cipher_type_t * srtp_crypto_kernel_get_cipher_type (srtp_cipher_type_id_t id)
469{
470 srtp_kernel_cipher_type_t *ctype;
471
472 /* walk down list, looking for id */
473 ctype = crypto_kernel.cipher_type_list;
474 while (ctype != NULL) {
475 if (id == ctype->id) {
476 return ctype->cipher_type;
477 }
478 ctype = ctype->next;
479 }
480
481 /* haven't found the right one, indicate failure by returning NULL */
482 return NULL;
483}
484
485
486srtp_err_status_t srtp_crypto_kernel_alloc_cipher (srtp_cipher_type_id_t id, srtp_cipher_pointer_t *cp, int key_len, int tag_len)
487{
488 srtp_cipher_type_t *ct;
489
490 /*
491 * if the crypto_kernel is not yet initialized, we refuse to allocate
492 * any ciphers - this is a bit extra-paranoid
493 */
494 if (crypto_kernel.state != srtp_crypto_kernel_state_secure) {
495 return srtp_err_status_init_fail;
496 }
497
498 ct = srtp_crypto_kernel_get_cipher_type(id);
499 if (!ct) {
500 return srtp_err_status_fail;
501 }
502
503 return ((ct)->alloc(cp, key_len, tag_len));
504}
505
506
507
508srtp_auth_type_t * srtp_crypto_kernel_get_auth_type (srtp_auth_type_id_t id)
509{
510 srtp_kernel_auth_type_t *atype;
511
512 /* walk down list, looking for id */
513 atype = crypto_kernel.auth_type_list;
514 while (atype != NULL) {
515 if (id == atype->id) {
516 return atype->auth_type;
517 }
518 atype = atype->next;
519 }
520
521 /* haven't found the right one, indicate failure by returning NULL */
522 return NULL;
523}
524
525srtp_err_status_t srtp_crypto_kernel_alloc_auth (srtp_auth_type_id_t id, auth_pointer_t *ap, int key_len, int tag_len)
526{
527 srtp_auth_type_t *at;
528
529 /*
530 * if the crypto_kernel is not yet initialized, we refuse to allocate
531 * any auth functions - this is a bit extra-paranoid
532 */
533 if (crypto_kernel.state != srtp_crypto_kernel_state_secure) {
534 return srtp_err_status_init_fail;
535 }
536
537 at = srtp_crypto_kernel_get_auth_type(id);
538 if (!at) {
539 return srtp_err_status_fail;
540 }
541
542 return ((at)->alloc(ap, key_len, tag_len));
543}
544
jfigus02d6f032014-11-21 10:56:42 -0500545srtp_err_status_t srtp_crypto_kernel_load_debug_module (srtp_debug_module_t *new_dm)
jfigus92736bc2014-11-21 10:30:54 -0500546{
547 srtp_kernel_debug_module_t *kdm, *new;
548
549 /* defensive coding */
550 if (new_dm == NULL) {
551 return srtp_err_status_bad_param;
552 }
553
554 /* walk down list, checking if this type is in the list already */
555 kdm = crypto_kernel.debug_module_list;
556 while (kdm != NULL) {
557 if (strncmp(new_dm->name, kdm->mod->name, 64) == 0) {
558 return srtp_err_status_bad_param;
559 }
560 kdm = kdm->next;
561 }
562
563 /* put new_dm at the head of the list */
564 /* allocate memory */
565 new = (srtp_kernel_debug_module_t*)srtp_crypto_alloc(sizeof(srtp_kernel_debug_module_t));
566 if (new == NULL) {
567 return srtp_err_status_alloc_fail;
568 }
569
570 /* set fields */
571 new->mod = new_dm;
572 new->next = crypto_kernel.debug_module_list;
Jonathan Lennoxdc4d8842010-05-20 23:53:15 +0000573
574 /* set head of list to new cipher type */
jfigus92736bc2014-11-21 10:30:54 -0500575 crypto_kernel.debug_module_list = new;
Cullen Jennings235513a2005-09-21 22:51:36 +0000576
jfigus92736bc2014-11-21 10:30:54 -0500577 return srtp_err_status_ok;
Cullen Jennings235513a2005-09-21 22:51:36 +0000578}
579
jfigus92736bc2014-11-21 10:30:54 -0500580srtp_err_status_t srtp_crypto_kernel_set_debug_module (char *name, int on)
581{
582 srtp_kernel_debug_module_t *kdm;
Jonathan Lennoxdc4d8842010-05-20 23:53:15 +0000583
jfigus92736bc2014-11-21 10:30:54 -0500584 /* walk down list, checking if this type is in the list already */
585 kdm = crypto_kernel.debug_module_list;
586 while (kdm != NULL) {
587 if (strncmp(name, kdm->mod->name, 64) == 0) {
588 kdm->mod->on = on;
589 return srtp_err_status_ok;
590 }
591 kdm = kdm->next;
Jonathan Lennoxdc4d8842010-05-20 23:53:15 +0000592 }
Cullen Jennings235513a2005-09-21 22:51:36 +0000593
jfigus857009c2014-11-05 11:17:43 -0500594 return srtp_err_status_fail;
Cullen Jennings235513a2005-09-21 22:51:36 +0000595}