srtp_err_status_t srtp_crypto_kernel_status () { srtp_err_status_t status; srtp_kernel_cipher_type_t *ctype = crypto_kernel.cipher_type_list; srtp_kernel_auth_type_t *atype = crypto_kernel.auth_type_list; srtp_kernel_debug_module_t *dm = crypto_kernel.debug_module_list; /* for each cipher type, describe and test */ while (ctype != NULL) { printf("cipher: %s\n", ctype->cipher_type->description); printf(" self-test: "); status = srtp_cipher_type_self_test(ctype->cipher_type); if (status) { printf("failed with error code %d\n", status); exit(status); } printf("passed\n"); ctype = ctype->next; } /* for each auth type, describe and test */ while (atype != NULL) { printf("auth func: %s\n", atype->auth_type->description); printf(" self-test: "); status = srtp_auth_type_self_test(atype->auth_type); if (status) { printf("failed with error code %d\n", status); exit(status); } printf("passed\n"); atype = atype->next; } /* describe each debug module */ printf("debug modules loaded:\n"); while (dm != NULL) { printf(" %s ", dm->mod->name); if (dm->mod->on) { printf("(on)\n"); } else { printf("(off)\n"); } dm = dm->next; } return srtp_err_status_ok; }
srtp_err_status_t srtp_crypto_kernel_status() { srtp_err_status_t status; srtp_kernel_cipher_type_t *ctype = crypto_kernel.cipher_type_list; srtp_kernel_auth_type_t *atype = crypto_kernel.auth_type_list; /* for each cipher type, describe and test */ while (ctype != NULL) { srtp_err_report(srtp_err_level_info, "cipher: %s\n", ctype->cipher_type->description); srtp_err_report(srtp_err_level_info, " self-test: "); status = srtp_cipher_type_self_test(ctype->cipher_type); if (status) { srtp_err_report(srtp_err_level_error, "failed with error code %d\n", status); exit(status); } srtp_err_report(srtp_err_level_info, "passed\n"); ctype = ctype->next; } /* for each auth type, describe and test */ while (atype != NULL) { srtp_err_report(srtp_err_level_info, "auth func: %s\n", atype->auth_type->description); srtp_err_report(srtp_err_level_info, " self-test: "); status = srtp_auth_type_self_test(atype->auth_type); if (status) { srtp_err_report(srtp_err_level_error, "failed with error code %d\n", status); exit(status); } srtp_err_report(srtp_err_level_info, "passed\n"); atype = atype->next; } srtp_crypto_kernel_list_debug_modules(); return srtp_err_status_ok; }
static 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) { srtp_kernel_cipher_type_t *ctype, *new_ctype; srtp_err_status_t status; /* defensive coding */ if (new_ct == NULL) { return srtp_err_status_bad_param; } if (new_ct->id != id) { return srtp_err_status_bad_param; } /* check cipher type by running self-test */ status = srtp_cipher_type_self_test(new_ct); if (status) { return status; } /* walk down list, checking if this type is in the list already */ ctype = crypto_kernel.cipher_type_list; while (ctype != NULL) { if (id == ctype->id) { if (!replace) { return srtp_err_status_bad_param; } status = srtp_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 srtp_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 = (srtp_kernel_cipher_type_t*)srtp_crypto_alloc(sizeof(srtp_kernel_cipher_type_t)); if (new_ctype == NULL) { return srtp_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 */ if (new_ct->debug != NULL) { srtp_crypto_kernel_load_debug_module(new_ct->debug); } /* we could check for errors here */ return srtp_err_status_ok; }