MCPcopy Create free account
hub / github.com/cisco/libsrtp / cipher_array_bits_per_second

Function cipher_array_bits_per_second

crypto/test/cipher_driver.c:519–563  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

517 */
518
519uint64_t cipher_array_bits_per_second(srtp_cipher_t *cipher_array[],
520 int num_cipher,
521 unsigned octets_in_buffer,
522 int num_trials)
523{
524 int i;
525 v128_t nonce;
526 clock_t timer;
527 unsigned char *enc_buf;
528 int cipher_index = srtp_cipher_rand_u32_for_tests() % num_cipher;
529
530 /* Over-alloc, for NIST CBC padding */
531 enc_buf = srtp_crypto_alloc(octets_in_buffer + 17);
532 if (enc_buf == NULL)
533 return 0; /* indicate bad parameters by returning null */
534
535 /* time repeated trials */
536 v128_set_to_zero(&nonce);
537 timer = clock();
538 for (i = 0; i < num_trials; i++, nonce.v32[3] = i) {
539 /* length parameter to srtp_cipher_encrypt is in/out -- out is total,
540 * padded
541 * length -- so reset it each time. */
542 unsigned octets_to_encrypt = octets_in_buffer;
543
544 /* encrypt buffer with cipher */
545 srtp_cipher_set_iv(cipher_array[cipher_index], (uint8_t *)&nonce,
546 srtp_direction_encrypt);
547 srtp_cipher_encrypt(cipher_array[cipher_index], enc_buf,
548 &octets_to_encrypt);
549
550 /* choose a cipher at random from the array*/
551 cipher_index = (*((uint32_t *)enc_buf)) % num_cipher;
552 }
553 timer = clock() - timer;
554
555 srtp_crypto_free(enc_buf);
556
557 if (timer == 0) {
558 /* Too fast! */
559 return 0;
560 }
561
562 return (uint64_t)CLOCKS_PER_SEC * num_trials * 8 * octets_in_buffer / timer;
563}
564
565void cipher_array_test_throughput(srtp_cipher_t *ca[], int num_cipher)
566{

Callers 1

Calls 5

srtp_crypto_allocFunction · 0.85
srtp_cipher_set_ivFunction · 0.85
srtp_cipher_encryptFunction · 0.85
srtp_crypto_freeFunction · 0.85

Tested by

no test coverage detected