Skip to content

Commit

Permalink
Merge pull request #614 from bifurcation/get-tag
Browse files Browse the repository at this point in the history
Call `set_aad` and `get_tag` in AEAD performance tests
  • Loading branch information
pabuhler committed Nov 8, 2022
2 parents 9db866d + e1cb78c commit 004b7bb
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion crypto/cipher/cipher.c
Original file line number Diff line number Diff line change
Expand Up @@ -632,24 +632,47 @@ uint64_t srtp_cipher_bits_per_second(srtp_cipher_t *c,
clock_t timer;
unsigned char *enc_buf;
unsigned int len = octets_in_buffer;
uint32_t tag_len = SRTP_MAX_TAG_LEN;
unsigned char aad[4] = { 0, 0, 0, 0 };
uint32_t aad_len = 4;

enc_buf = (unsigned char *)srtp_crypto_alloc(octets_in_buffer);
enc_buf = (unsigned char *)srtp_crypto_alloc(octets_in_buffer + tag_len);
if (enc_buf == NULL) {
return 0; /* indicate bad parameters by returning null */
}
/* time repeated trials */
v128_set_to_zero(&nonce);
timer = clock();
for (i = 0; i < num_trials; i++, nonce.v32[3] = i) {
// Set IV
if (srtp_cipher_set_iv(c, (uint8_t *)&nonce, srtp_direction_encrypt) !=
srtp_err_status_ok) {
srtp_crypto_free(enc_buf);
return 0;
}

// Set (empty) AAD if supported by the cipher
if (c->type->set_aad) {
if (srtp_cipher_set_aad(c, aad, aad_len) != srtp_err_status_ok) {
srtp_crypto_free(enc_buf);
return 0;
}
}

// Encrypt the buffer
if (srtp_cipher_encrypt(c, enc_buf, &len) != srtp_err_status_ok) {
srtp_crypto_free(enc_buf);
return 0;
}

// Get tag if supported by the cipher
if (c->type->get_tag) {
if (srtp_cipher_get_tag(c, (uint8_t *)(enc_buf + len), &tag_len) !=
srtp_err_status_ok) {
srtp_crypto_free(enc_buf);
return 0;
}
}
}
timer = clock() - timer;

Expand Down

0 comments on commit 004b7bb

Please sign in to comment.