Example #1
0
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;
}
Example #2
0
/*
 * srtp_cipher_type_self_test(ct) performs srtp_cipher_type_test on ct's internal
 * list of test data.
 */
srtp_err_status_t srtp_cipher_type_self_test (const srtp_cipher_type_t *ct)
{
    return srtp_cipher_type_test(ct, ct->test_data);
}