X-Git-Url: https://www.bearssl.org/gitweb//home/git/?p=BearSSL;a=blobdiff_plain;f=test%2Ftest_speed.c;h=3ea9b99107b78bc699df042fcb3c411c65b13e50;hp=d7dfaadedc27ab0cb7ad7b1b24ac849fad74c800;hb=c1e540575c63e09e6ab25c0c7826601d77b18d97;hpb=5f045c759957fdff8c85716e6af99e10901fdac0 diff --git a/test/test_speed.c b/test/test_speed.c index d7dfaad..3ea9b99 100644 --- a/test/test_speed.c +++ b/test/test_speed.c @@ -175,17 +175,24 @@ test_speed_ ## fname(void) \ static void \ test_speed_ ## fname(void) \ { \ + br_chacha20_run bc; \ unsigned char key[32]; \ unsigned char buf[8192]; \ unsigned char iv[12]; \ int i; \ long num; \ \ + bc = br_ ## fname ## _get(); \ + if (bc == 0) { \ + printf("%-30s UNAVAILABLE\n", #Name); \ + fflush(stdout); \ + return; \ + } \ memset(key, 'T', sizeof key); \ memset(buf, 'P', sizeof buf); \ memset(iv, 'X', sizeof iv); \ for (i = 0; i < 10; i ++) { \ - br_ ## fname ## _run(key, iv, i, buf, sizeof buf); \ + bc(key, iv, i, buf, sizeof buf); \ } \ num = 10; \ for (;;) { \ @@ -195,8 +202,7 @@ test_speed_ ## fname(void) \ \ begin = clock(); \ for (k = num; k > 0; k --) { \ - br_ ## fname ## _run(key, iv, \ - (uint32_t)k, buf, sizeof buf); \ + bc(key, iv, (uint32_t)k, buf, sizeof buf); \ } \ end = clock(); \ tt = (double)(end - begin) / CLOCKS_PER_SEC; \ @@ -223,15 +229,20 @@ SPEED_HASH(SHA-512, sha512) #define br_aes_big_cbcenc_get_vtable() (&br_aes_big_cbcenc_vtable) #define br_aes_big_cbcdec_get_vtable() (&br_aes_big_cbcdec_vtable) #define br_aes_big_ctr_get_vtable() (&br_aes_big_ctr_vtable) +#define br_aes_big_ctrcbc_get_vtable() (&br_aes_big_ctrcbc_vtable) #define br_aes_small_cbcenc_get_vtable() (&br_aes_small_cbcenc_vtable) #define br_aes_small_cbcdec_get_vtable() (&br_aes_small_cbcdec_vtable) #define br_aes_small_ctr_get_vtable() (&br_aes_small_ctr_vtable) +#define br_aes_small_ctrcbc_get_vtable() (&br_aes_small_ctrcbc_vtable) #define br_aes_ct_cbcenc_get_vtable() (&br_aes_ct_cbcenc_vtable) #define br_aes_ct_cbcdec_get_vtable() (&br_aes_ct_cbcdec_vtable) #define br_aes_ct_ctr_get_vtable() (&br_aes_ct_ctr_vtable) +#define br_aes_ct_ctrcbc_get_vtable() (&br_aes_ct_ctrcbc_vtable) #define br_aes_ct64_cbcenc_get_vtable() (&br_aes_ct64_cbcenc_vtable) #define br_aes_ct64_cbcdec_get_vtable() (&br_aes_ct64_cbcdec_vtable) #define br_aes_ct64_ctr_get_vtable() (&br_aes_ct64_ctr_vtable) +#define br_aes_ct64_ctrcbc_get_vtable() (&br_aes_ct64_ctrcbc_vtable) +#define br_chacha20_ct_get() (&br_chacha20_ct_run) #define SPEED_AES(iname) \ SPEED_BLOCKCIPHER_CBC(AES-128 CBC encrypt (iname), aes128_ ## iname ## _cbcenc, aes_ ## iname, 16, enc) \ @@ -249,6 +260,7 @@ SPEED_AES(small) SPEED_AES(ct) SPEED_AES(ct64) SPEED_AES(x86ni) +SPEED_AES(pwr8) #define br_des_tab_cbcenc_get_vtable() (&br_des_tab_cbcenc_vtable) #define br_des_tab_cbcdec_get_vtable() (&br_des_tab_cbcdec_vtable) @@ -264,7 +276,8 @@ SPEED_BLOCKCIPHER_CBC(3DES CBC decrypt (iname), 3des_ ## iname ## _cbcdec, des_ SPEED_DES(tab) SPEED_DES(ct) -SPEED_CHACHA20(ChaCha20, chacha20_ct) +SPEED_CHACHA20(ChaCha20 (ct), chacha20_ct) +SPEED_CHACHA20(ChaCha20 (sse2), chacha20_sse2) static void test_speed_ghash_inner(char *name, br_ghash gh) @@ -334,6 +347,20 @@ test_speed_ghash_pclmul(void) } } +static void +test_speed_ghash_pwr8(void) +{ + br_ghash gh; + + gh = br_ghash_pwr8_get(); + if (gh == 0) { + printf("%-30s UNAVAILABLE\n", "GHASH (pwr8)"); + fflush(stdout); + } else { + test_speed_ghash_inner("GHASH (pwr8)", gh); + } +} + static uint32_t fake_chacha20(const void *key, const void *iv, uint32_t cc, void *data, size_t len) @@ -401,12 +428,107 @@ test_speed_poly1305_ctmul32(void) &br_poly1305_ctmul32_run); } +static void +test_speed_poly1305_ctmulq(void) +{ + br_poly1305_run bp; + + bp = br_poly1305_ctmulq_get(); + if (bp == 0) { + printf("%-30s UNAVAILABLE\n", "Poly1305 (ctmulq)"); + } else { + test_speed_poly1305_inner("Poly1305 (ctmulq)", bp); + } +} + static void test_speed_poly1305_i15(void) { test_speed_poly1305_inner("Poly1305 (i15)", &br_poly1305_i15_run); } +static void +test_speed_eax_inner(char *name, + const br_block_ctrcbc_class *vt, size_t key_len) +{ + unsigned char buf[8192], key[32], nonce[16], aad[16], tag[16]; + int i; + long num; + br_aes_gen_ctrcbc_keys ac; + br_eax_context ec; + + if (vt == NULL) { + printf("%-30s UNAVAILABLE\n", name); + fflush(stdout); + return; + } + memset(key, 'K', key_len); + memset(nonce, 'N', sizeof nonce); + memset(aad, 'A', sizeof aad); + memset(buf, 'T', sizeof buf); + for (i = 0; i < 10; i ++) { + vt->init(&ac.vtable, key, key_len); + br_eax_init(&ec, &ac.vtable); + br_eax_reset(&ec, nonce, sizeof nonce); + br_eax_aad_inject(&ec, aad, sizeof aad); + br_eax_flip(&ec); + br_eax_run(&ec, 1, buf, sizeof buf); + br_eax_get_tag(&ec, tag); + } + num = 10; + for (;;) { + clock_t begin, end; + double tt; + long k; + + begin = clock(); + for (k = num; k > 0; k --) { + vt->init(&ac.vtable, key, key_len); + br_eax_init(&ec, &ac.vtable); + br_eax_reset(&ec, nonce, sizeof nonce); + br_eax_aad_inject(&ec, aad, sizeof aad); + br_eax_flip(&ec); + br_eax_run(&ec, 1, buf, sizeof buf); + br_eax_get_tag(&ec, tag); + } + end = clock(); + tt = (double)(end - begin) / CLOCKS_PER_SEC; + if (tt >= 2.0) { + printf("%-30s %8.2f MB/s\n", name, + ((double)sizeof buf) * (double)num + / (tt * 1000000.0)); + fflush(stdout); + return; + } + num <<= 1; + } +} + +#define SPEED_EAX(Algo, algo, keysize, impl) \ +static void \ +test_speed_eax_ ## algo ## keysize ## _ ## impl(void) \ +{ \ + test_speed_eax_inner("EAX " #Algo "-" #keysize "(" #impl ")", \ + br_ ## algo ## _ ## impl ## _ctrcbc_get_vtable() \ + , (keysize) >> 3); \ +} + +SPEED_EAX(AES, aes, 128, big) +SPEED_EAX(AES, aes, 128, small) +SPEED_EAX(AES, aes, 128, ct) +SPEED_EAX(AES, aes, 128, ct64) +SPEED_EAX(AES, aes, 128, x86ni) +SPEED_EAX(AES, aes, 192, big) +SPEED_EAX(AES, aes, 192, small) +SPEED_EAX(AES, aes, 192, ct) +SPEED_EAX(AES, aes, 192, ct64) +SPEED_EAX(AES, aes, 192, x86ni) +SPEED_EAX(AES, aes, 256, big) +SPEED_EAX(AES, aes, 256, small) +SPEED_EAX(AES, aes, 256, ct) +SPEED_EAX(AES, aes, 256, ct64) +SPEED_EAX(AES, aes, 256, x86ni) + static const unsigned char RSA_N[] = { 0xE9, 0xF2, 0x4A, 0x2F, 0x96, 0xDF, 0x0A, 0x23, 0x01, 0x85, 0xF1, 0x2C, 0xB2, 0xA8, 0xEF, 0x23, @@ -638,6 +760,21 @@ test_speed_rsa_i32(void) &br_rsa_i32_public, &br_rsa_i32_private); } +static void +test_speed_rsa_i62(void) +{ + br_rsa_public pub; + br_rsa_private priv; + + pub = br_rsa_i62_public_get(); + priv = br_rsa_i62_private_get(); + if (pub) { + test_speed_rsa_inner("RSA i62", pub, priv); + } else { + printf("%-30s UNAVAILABLE\n", "RSA i62"); + } +} + static void test_speed_ec_inner_1(const char *name, const br_ec_impl *impl, const br_ec_curve_def *cd) @@ -1215,6 +1352,16 @@ static const struct { STU(aes192_x86ni_ctr), STU(aes256_x86ni_ctr), + STU(aes128_pwr8_cbcenc), + STU(aes128_pwr8_cbcdec), + STU(aes192_pwr8_cbcenc), + STU(aes192_pwr8_cbcdec), + STU(aes256_pwr8_cbcenc), + STU(aes256_pwr8_cbcdec), + STU(aes128_pwr8_ctr), + STU(aes192_pwr8_ctr), + STU(aes256_pwr8_ctr), + STU(des_tab_cbcenc), STU(des_tab_cbcdec), STU(3des_tab_cbcenc), @@ -1226,19 +1373,39 @@ static const struct { STU(3des_ct_cbcdec), STU(chacha20_ct), + STU(chacha20_sse2), STU(ghash_ctmul), STU(ghash_ctmul32), STU(ghash_ctmul64), STU(ghash_pclmul), + STU(ghash_pwr8), STU(poly1305_ctmul), STU(poly1305_ctmul32), + STU(poly1305_ctmulq), STU(poly1305_i15), + STU(eax_aes128_big), + STU(eax_aes192_big), + STU(eax_aes256_big), + STU(eax_aes128_small), + STU(eax_aes192_small), + STU(eax_aes256_small), + STU(eax_aes128_ct), + STU(eax_aes192_ct), + STU(eax_aes256_ct), + STU(eax_aes128_ct64), + STU(eax_aes192_ct64), + STU(eax_aes256_ct64), + STU(eax_aes128_x86ni), + STU(eax_aes192_x86ni), + STU(eax_aes256_x86ni), + STU(rsa_i15), STU(rsa_i31), STU(rsa_i32), + STU(rsa_i62), STU(ec_prime_i15), STU(ec_prime_i31), STU(ec_p256_m15),