@@ -632,24 +632,47 @@ uint64_t srtp_cipher_bits_per_second(srtp_cipher_t *c,
632
632
clock_t timer ;
633
633
unsigned char * enc_buf ;
634
634
unsigned int len = octets_in_buffer ;
635
+ uint32_t tag_len = SRTP_MAX_TAG_LEN ;
636
+ unsigned char aad [4 ] = { 0 , 0 , 0 , 0 };
637
+ uint32_t aad_len = 4 ;
635
638
636
- enc_buf = (unsigned char * )srtp_crypto_alloc (octets_in_buffer );
639
+ enc_buf = (unsigned char * )srtp_crypto_alloc (octets_in_buffer + tag_len );
637
640
if (enc_buf == NULL ) {
638
641
return 0 ; /* indicate bad parameters by returning null */
639
642
}
640
643
/* time repeated trials */
641
644
v128_set_to_zero (& nonce );
642
645
timer = clock ();
643
646
for (i = 0 ; i < num_trials ; i ++ , nonce .v32 [3 ] = i ) {
647
+ // Set IV
644
648
if (srtp_cipher_set_iv (c , (uint8_t * )& nonce , srtp_direction_encrypt ) !=
645
649
srtp_err_status_ok ) {
646
650
srtp_crypto_free (enc_buf );
647
651
return 0 ;
648
652
}
653
+
654
+ // Set (empty) AAD if supported by the cipher
655
+ if (c -> type -> set_aad ) {
656
+ if (srtp_cipher_set_aad (c , aad , aad_len ) != srtp_err_status_ok ) {
657
+ srtp_crypto_free (enc_buf );
658
+ return 0 ;
659
+ }
660
+ }
661
+
662
+ // Encrypt the buffer
649
663
if (srtp_cipher_encrypt (c , enc_buf , & len ) != srtp_err_status_ok ) {
650
664
srtp_crypto_free (enc_buf );
651
665
return 0 ;
652
666
}
667
+
668
+ // Get tag if supported by the cipher
669
+ if (c -> type -> get_tag ) {
670
+ if (srtp_cipher_get_tag (c , (uint8_t * )(enc_buf + len ), & tag_len ) !=
671
+ srtp_err_status_ok ) {
672
+ srtp_crypto_free (enc_buf );
673
+ return 0 ;
674
+ }
675
+ }
653
676
}
654
677
timer = clock () - timer ;
655
678
0 commit comments