Skip to content

Commit

Permalink
Merge pull request #8333 from yanrayw/2.28_aes_benchmark_cfb
Browse files Browse the repository at this point in the history
Backport 2.28: Benchmark: add AES_CFB128 and AES_CFB8
  • Loading branch information
tom-cosgrove-arm authored Oct 11, 2023
2 parents e0be6bf + c55060d commit 44af436
Showing 1 changed file with 60 additions and 7 deletions.
67 changes: 60 additions & 7 deletions programs/test/benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@ int main(void)
#define HEADER_FORMAT " %-24s : "
#define TITLE_LEN 25

#define OPTIONS \
"md4, md5, ripemd160, sha1, sha256, sha512,\n" \
"arc4, des3, des, camellia, blowfish, chacha20,\n" \
"aes_cbc, aes_gcm, aes_ccm, aes_xts, chachapoly,\n" \
"aes_cmac, des3_cmac, poly1305\n" \
"havege, ctr_drbg, hmac_drbg\n" \
#define OPTIONS \
"md4, md5, ripemd160, sha1, sha256, sha512,\n" \
"arc4, des3, des, camellia, blowfish, chacha20,\n" \
"aes_cbc, aes_cfb128, aes_cfb8, aes_gcm, aes_ccm, aes_xts, chachapoly,\n" \
"aes_cmac, des3_cmac, poly1305\n" \
"havege, ctr_drbg, hmac_drbg\n" \
"rsa, dhm, ecdsa, ecdh.\n"

#if defined(MBEDTLS_ERROR_C)
Expand Down Expand Up @@ -280,7 +280,7 @@ unsigned char buf[BUFSIZE];
typedef struct {
char md4, md5, ripemd160, sha1, sha256, sha512,
arc4, des3, des,
aes_cbc, aes_gcm, aes_ccm, aes_xts, chachapoly,
aes_cbc, aes_cfb128, aes_cfb8, aes_gcm, aes_ccm, aes_xts, chachapoly,
aes_cmac, des3_cmac,
aria, camellia, blowfish, chacha20,
poly1305,
Expand Down Expand Up @@ -336,6 +336,10 @@ int main(int argc, char *argv[])
todo.des = 1;
} else if (strcmp(argv[i], "aes_cbc") == 0) {
todo.aes_cbc = 1;
} else if (strcmp(argv[i], "aes_cfb128") == 0) {
todo.aes_cfb128 = 1;
} else if (strcmp(argv[i], "aes_cfb8") == 0) {
todo.aes_cfb8 = 1;
} else if (strcmp(argv[i], "aes_xts") == 0) {
todo.aes_xts = 1;
} else if (strcmp(argv[i], "aes_gcm") == 0) {
Expand Down Expand Up @@ -432,6 +436,7 @@ int main(int argc, char *argv[])
#if defined(MBEDTLS_ARC4_C)
if (todo.arc4) {
mbedtls_arc4_context arc4;

mbedtls_arc4_init(&arc4);
mbedtls_arc4_setup(&arc4, tmp, 32);
TIME_AND_TSC("ARC4", mbedtls_arc4_crypt(&arc4, BUFSIZE, buf, buf));
Expand All @@ -443,6 +448,7 @@ int main(int argc, char *argv[])
#if defined(MBEDTLS_CIPHER_MODE_CBC)
if (todo.des3) {
mbedtls_des3_context des3;

mbedtls_des3_init(&des3);
if (mbedtls_des3_set3key_enc(&des3, tmp) != 0) {
mbedtls_exit(1);
Expand All @@ -454,6 +460,7 @@ int main(int argc, char *argv[])

if (todo.des) {
mbedtls_des_context des;

mbedtls_des_init(&des);
if (mbedtls_des_setkey_enc(&des, tmp) != 0) {
mbedtls_exit(1);
Expand Down Expand Up @@ -486,6 +493,7 @@ int main(int argc, char *argv[])
if (todo.aes_cbc) {
int keysize;
mbedtls_aes_context aes;

mbedtls_aes_init(&aes);
for (keysize = 128; keysize <= 256; keysize += 64) {
mbedtls_snprintf(title, sizeof(title), "AES-CBC-%d", keysize);
Expand All @@ -500,6 +508,44 @@ int main(int argc, char *argv[])
mbedtls_aes_free(&aes);
}
#endif
#if defined(MBEDTLS_CIPHER_MODE_CFB)
if (todo.aes_cfb128) {
int keysize;
size_t iv_off = 0;
mbedtls_aes_context aes;

mbedtls_aes_init(&aes);
for (keysize = 128; keysize <= 256; keysize += 64) {
mbedtls_snprintf(title, sizeof(title), "AES-CFB128-%d", keysize);

memset(buf, 0, sizeof(buf));
memset(tmp, 0, sizeof(tmp));
CHECK_AND_CONTINUE(mbedtls_aes_setkey_enc(&aes, tmp, keysize));

TIME_AND_TSC(title,
mbedtls_aes_crypt_cfb128(&aes, MBEDTLS_AES_ENCRYPT, BUFSIZE,
&iv_off, tmp, buf, buf));
}
mbedtls_aes_free(&aes);
}
if (todo.aes_cfb8) {
int keysize;
mbedtls_aes_context aes;

mbedtls_aes_init(&aes);
for (keysize = 128; keysize <= 256; keysize += 64) {
mbedtls_snprintf(title, sizeof(title), "AES-CFB8-%d", keysize);

memset(buf, 0, sizeof(buf));
memset(tmp, 0, sizeof(tmp));
CHECK_AND_CONTINUE(mbedtls_aes_setkey_enc(&aes, tmp, keysize));

TIME_AND_TSC(title,
mbedtls_aes_crypt_cfb8(&aes, MBEDTLS_AES_ENCRYPT, BUFSIZE, tmp, buf, buf));
}
mbedtls_aes_free(&aes);
}
#endif
#if defined(MBEDTLS_CIPHER_MODE_XTS)
if (todo.aes_xts) {
int keysize;
Expand Down Expand Up @@ -617,6 +663,7 @@ int main(int argc, char *argv[])
if (todo.aria) {
int keysize;
mbedtls_aria_context aria;

mbedtls_aria_init(&aria);
for (keysize = 128; keysize <= 256; keysize += 64) {
mbedtls_snprintf(title, sizeof(title), "ARIA-CBC-%d", keysize);
Expand All @@ -637,6 +684,7 @@ int main(int argc, char *argv[])
if (todo.camellia) {
int keysize;
mbedtls_camellia_context camellia;

mbedtls_camellia_init(&camellia);
for (keysize = 128; keysize <= 256; keysize += 64) {
mbedtls_snprintf(title, sizeof(title), "CAMELLIA-CBC-%d", keysize);
Expand Down Expand Up @@ -669,6 +717,7 @@ int main(int argc, char *argv[])
if (todo.blowfish) {
int keysize;
mbedtls_blowfish_context blowfish;

mbedtls_blowfish_init(&blowfish);

for (keysize = 128; keysize <= 256; keysize += 64) {
Expand All @@ -690,6 +739,7 @@ int main(int argc, char *argv[])
#if defined(MBEDTLS_HAVEGE_C)
if (todo.havege) {
mbedtls_havege_state hs;

mbedtls_havege_init(&hs);
TIME_AND_TSC("HAVEGE", mbedtls_havege_random(&hs, buf, BUFSIZE));
mbedtls_havege_free(&hs);
Expand Down Expand Up @@ -774,6 +824,7 @@ int main(int argc, char *argv[])
if (todo.rsa) {
int keysize;
mbedtls_rsa_context rsa;

for (keysize = 2048; keysize <= 4096; keysize *= 2) {
mbedtls_snprintf(title, sizeof(title), "RSA-%d", keysize);

Expand Down Expand Up @@ -815,6 +866,7 @@ int main(int argc, char *argv[])

mbedtls_dhm_context dhm;
size_t olen;

for (i = 0; (size_t) i < sizeof(dhm_sizes) / sizeof(dhm_sizes[0]); i++) {
mbedtls_dhm_init(&dhm);

Expand Down Expand Up @@ -928,6 +980,7 @@ int main(int argc, char *argv[])

if (curve_list == (const mbedtls_ecp_curve_info *) &single_curve) {
mbedtls_ecp_group grp;

mbedtls_ecp_group_init(&grp);
if (mbedtls_ecp_group_load(&grp, curve_list->grp_id) != 0) {
mbedtls_exit(1);
Expand Down

0 comments on commit 44af436

Please sign in to comment.