From: Jonathan L. <jon...@us...> - 2010-05-20 23:53:23
|
Update of /cvsroot/srtp/srtp/crypto/kernel In directory sfp-cvsdas-3.v30.ch3.sourceforge.com:/tmp/cvs-serv30240/kernel Modified Files: crypto_kernel.c Log Message: Add crypto_kernel_replace_cipher_type and crypto_kernel_replace_auth_type functions, allowing users to plug-in their own implementations of ciphers and auth types. Index: crypto_kernel.c =================================================================== RCS file: /cvsroot/srtp/srtp/crypto/kernel/crypto_kernel.c,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** crypto_kernel.c 20 May 2010 22:09:12 -0000 1.9 --- crypto_kernel.c 20 May 2010 23:53:15 -0000 1.10 *************** *** 298,303 **** } ! err_status_t ! crypto_kernel_load_cipher_type(cipher_type_t *new_ct, cipher_type_id_t id) { kernel_cipher_type_t *ctype, *new_ctype; err_status_t status; --- 298,304 ---- } ! inline err_status_t ! crypto_kernel_do_load_cipher_type(cipher_type_t *new_ct, cipher_type_id_t id, ! int replace) { kernel_cipher_type_t *ctype, *new_ctype; err_status_t status; *************** *** 319,340 **** ctype = crypto_kernel.cipher_type_list; while (ctype != NULL) { ! if ((new_ct == ctype->cipher_type) || (id == ctype->id)) return err_status_bad_param; ctype = ctype->next; } ! /* put new_ct at the head of the list */ /* allocate memory */ ! new_ctype = (kernel_cipher_type_t *) crypto_alloc(sizeof(kernel_cipher_type_t)); ! if (new_ctype == NULL) ! return err_status_alloc_fail; /* set fields */ new_ctype->cipher_type = new_ct; new_ctype->id = id; - new_ctype->next = crypto_kernel.cipher_type_list; - - /* set head of list to new cipher type */ - crypto_kernel.cipher_type_list = new_ctype; /* load debug module, if there is one present */ --- 320,352 ---- ctype = crypto_kernel.cipher_type_list; while (ctype != NULL) { ! if (id == ctype->id) { ! if (!replace) ! return err_status_bad_param; ! status = cipher_type_test(new_ct, ctype->cipher_type->test_data); ! if (status) ! return status; ! new_ctype = ctype; ! break; ! } ! else if (new_ct == ctype->cipher_type) return err_status_bad_param; ctype = ctype->next; } ! /* if not found, put new_ct at the head of the list */ ! if (ctype == NULL) { /* allocate memory */ ! new_ctype = (kernel_cipher_type_t *) crypto_alloc(sizeof(kernel_cipher_type_t)); ! if (new_ctype == NULL) ! return err_status_alloc_fail; ! new_ctype->next = crypto_kernel.cipher_type_list; ! ! /* set head of list to new cipher type */ ! crypto_kernel.cipher_type_list = new_ctype; ! } /* set fields */ new_ctype->cipher_type = new_ct; new_ctype->id = id; /* load debug module, if there is one present */ *************** *** 347,351 **** err_status_t ! crypto_kernel_load_auth_type(auth_type_t *new_at, auth_type_id_t id) { kernel_auth_type_t *atype, *new_atype; err_status_t status; --- 359,374 ---- err_status_t ! crypto_kernel_load_cipher_type(cipher_type_t *new_ct, cipher_type_id_t id) { ! return crypto_kernel_do_load_cipher_type(new_ct, id, 0); ! } ! ! err_status_t ! crypto_kernel_replace_cipher_type(cipher_type_t *new_ct, cipher_type_id_t id) { ! return crypto_kernel_do_load_cipher_type(new_ct, id, 1); ! } ! ! err_status_t ! crypto_kernel_do_load_auth_type(auth_type_t *new_at, auth_type_id_t id, ! int replace) { kernel_auth_type_t *atype, *new_atype; err_status_t status; *************** *** 367,388 **** atype = crypto_kernel.auth_type_list; while (atype != NULL) { ! if ((new_at == atype->auth_type) || (id == atype->id)) return err_status_bad_param; atype = atype->next; } ! /* put new_at at the head of the list */ ! /* allocate memory */ ! new_atype = (kernel_auth_type_t *)crypto_alloc(sizeof(kernel_auth_type_t)); ! if (new_atype == NULL) ! return err_status_alloc_fail; /* set fields */ new_atype->auth_type = new_at; new_atype->id = id; - new_atype->next = crypto_kernel.auth_type_list; - - /* set head of list to new auth type */ - crypto_kernel.auth_type_list = new_atype; /* load debug module, if there is one present */ --- 390,422 ---- atype = crypto_kernel.auth_type_list; while (atype != NULL) { ! if (id == atype->id) { ! if (!replace) ! return err_status_bad_param; ! status = auth_type_test(new_at, atype->auth_type->test_data); ! if (status) ! return status; ! new_atype = atype; ! break; ! } ! else if (new_at == atype->auth_type) return err_status_bad_param; atype = atype->next; } ! /* if not found, put new_at at the head of the list */ ! if (atype == NULL) { ! /* allocate memory */ ! new_atype = (kernel_auth_type_t *)crypto_alloc(sizeof(kernel_auth_type_t)); ! if (new_atype == NULL) ! return err_status_alloc_fail; ! ! new_atype->next = crypto_kernel.auth_type_list; ! /* set head of list to new auth type */ ! crypto_kernel.auth_type_list = new_atype; ! } /* set fields */ new_atype->auth_type = new_at; new_atype->id = id; /* load debug module, if there is one present */ *************** *** 395,398 **** --- 429,442 ---- } + err_status_t + crypto_kernel_load_auth_type(auth_type_t *new_at, auth_type_id_t id) { + return crypto_kernel_do_load_auth_type(new_at, id, 0); + } + + err_status_t + crypto_kernel_replace_auth_type(auth_type_t *new_at, auth_type_id_t id) { + return crypto_kernel_do_load_auth_type(new_at, id, 1); + } + cipher_type_t * |