| 432 | */ |
| 433 | |
| 434 | srtp_err_status_t cipher_array_alloc_init(srtp_cipher_t ***ca, |
| 435 | int num_ciphers, |
| 436 | srtp_cipher_type_t *ctype, |
| 437 | int klen) |
| 438 | { |
| 439 | int i, j; |
| 440 | srtp_err_status_t status; |
| 441 | uint8_t *key = NULL; |
| 442 | srtp_cipher_t **cipher_array; |
| 443 | /* pad klen allocation, to handle aes_icm reading 16 bytes for the |
| 444 | 14-byte salt */ |
| 445 | int klen_pad = ((klen + 15) >> 4) << 4; |
| 446 | |
| 447 | /* allocate array of pointers to ciphers */ |
| 448 | cipher_array = (srtp_cipher_t **)srtp_crypto_alloc(sizeof(srtp_cipher_t *) * |
| 449 | num_ciphers); |
| 450 | if (cipher_array == NULL) |
| 451 | return srtp_err_status_alloc_fail; |
| 452 | |
| 453 | /* set ca to location of cipher_array */ |
| 454 | *ca = cipher_array; |
| 455 | |
| 456 | /* allocate key , allow zero key for example null cipher */ |
| 457 | if (klen_pad > 0) { |
| 458 | key = srtp_crypto_alloc(klen_pad); |
| 459 | if (key == NULL) { |
| 460 | srtp_crypto_free(cipher_array); |
| 461 | return srtp_err_status_alloc_fail; |
| 462 | } |
| 463 | } |
| 464 | |
| 465 | /* allocate and initialize an array of ciphers */ |
| 466 | for (i = 0; i < num_ciphers; i++) { |
| 467 | /* allocate cipher */ |
| 468 | status = srtp_cipher_type_alloc(ctype, cipher_array, klen, 16); |
| 469 | if (status) |
| 470 | return status; |
| 471 | |
| 472 | /* generate random key and initialize cipher */ |
| 473 | srtp_cipher_rand_for_tests(key, klen); |
| 474 | for (j = klen; j < klen_pad; j++) |
| 475 | key[j] = 0; |
| 476 | status = srtp_cipher_init(*cipher_array, key); |
| 477 | if (status) |
| 478 | return status; |
| 479 | |
| 480 | /* printf("%dth cipher is at %p\n", i, *cipher_array); */ |
| 481 | /* printf("%dth cipher description: %s\n", i, */ |
| 482 | /* (*cipher_array)->type->description); */ |
| 483 | |
| 484 | /* advance cipher array pointer */ |
| 485 | cipher_array++; |
| 486 | } |
| 487 | |
| 488 | srtp_crypto_free(key); |
| 489 | |
| 490 | return srtp_err_status_ok; |
| 491 | } |
no test coverage detected