Skip to content

Commit 004b7bb

Browse files
authored
Merge pull request #614 from bifurcation/get-tag
Call `set_aad` and `get_tag` in AEAD performance tests
2 parents 9db866d + e1cb78c commit 004b7bb

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

crypto/cipher/cipher.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,24 +632,47 @@ uint64_t srtp_cipher_bits_per_second(srtp_cipher_t *c,
632632
clock_t timer;
633633
unsigned char *enc_buf;
634634
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;
635638

636-
enc_buf = (unsigned char *)srtp_crypto_alloc(octets_in_buffer);
639+
enc_buf = (unsigned char *)srtp_crypto_alloc(octets_in_buffer + tag_len);
637640
if (enc_buf == NULL) {
638641
return 0; /* indicate bad parameters by returning null */
639642
}
640643
/* time repeated trials */
641644
v128_set_to_zero(&nonce);
642645
timer = clock();
643646
for (i = 0; i < num_trials; i++, nonce.v32[3] = i) {
647+
// Set IV
644648
if (srtp_cipher_set_iv(c, (uint8_t *)&nonce, srtp_direction_encrypt) !=
645649
srtp_err_status_ok) {
646650
srtp_crypto_free(enc_buf);
647651
return 0;
648652
}
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
649663
if (srtp_cipher_encrypt(c, enc_buf, &len) != srtp_err_status_ok) {
650664
srtp_crypto_free(enc_buf);
651665
return 0;
652666
}
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+
}
653676
}
654677
timer = clock() - timer;
655678

0 commit comments

Comments
 (0)