Small fix on sample server code (displaying of IPv6 addresses).
[BearSSL] / test / test_speed.c
index 0d440ff..a09aa04 100644 (file)
@@ -88,7 +88,12 @@ test_speed_ ## fname(void) \
        memset(key, 'T', sizeof key); \
        memset(buf, 'P', sizeof buf); \
        memset(iv, 'X', sizeof iv); \
-       vt = &br_ ## cname ## _cbc ## dir ## _vtable; \
+       vt = br_ ## cname ## _cbc ## dir ## _get_vtable(); \
+       if (vt == NULL) { \
+               printf("%-30s UNAVAILABLE\n", #Name); \
+               fflush(stdout); \
+               return; \
+       } \
        for (i = 0; i < 10; i ++) { \
                vt->init(&ec.vtable, key, sizeof key); \
                vt->run(&ec.vtable, iv, buf, sizeof buf); \
@@ -132,7 +137,12 @@ test_speed_ ## fname(void) \
        memset(key, 'T', sizeof key); \
        memset(buf, 'P', sizeof buf); \
        memset(iv, 'X', sizeof iv); \
-       vt = &br_ ## cname ## _ctr_vtable; \
+       vt = br_ ## cname ## _ctr_get_vtable(); \
+       if (vt == NULL) { \
+               printf("%-30s UNAVAILABLE\n", #Name); \
+               fflush(stdout); \
+               return; \
+       } \
        for (i = 0; i < 10; i ++) { \
                vt->init(&ec.vtable, key, sizeof key); \
                vt->run(&ec.vtable, iv, 1, buf, sizeof buf); \
@@ -206,6 +216,23 @@ SPEED_HASH(SHA-1, sha1)
 SPEED_HASH(SHA-256, sha256)
 SPEED_HASH(SHA-512, sha512)
 
+/*
+ * There are no vtable selection functions for the portable implementations,
+ * so we define some custom macros.
+ */
+#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_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_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_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 SPEED_AES(iname) \
 SPEED_BLOCKCIPHER_CBC(AES-128 CBC encrypt (iname), aes128_ ## iname ## _cbcenc, aes_ ## iname, 16, enc) \
 SPEED_BLOCKCIPHER_CBC(AES-128 CBC decrypt (iname), aes128_ ## iname ## _cbcdec, aes_ ## iname, 16, dec) \
@@ -221,6 +248,13 @@ SPEED_AES(big)
 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)
+#define br_des_ct_cbcenc_get_vtable()      (&br_des_ct_cbcenc_vtable)
+#define br_des_ct_cbcdec_get_vtable()      (&br_des_ct_cbcdec_vtable)
 
 #define SPEED_DES(iname) \
 SPEED_BLOCKCIPHER_CBC(DES CBC encrypt (iname), des_ ## iname ## _cbcenc, des_ ## iname, 8, enc) \
@@ -287,6 +321,34 @@ test_speed_ghash_ctmul64(void)
        test_speed_ghash_inner("GHASH (ctmul64)", &br_ghash_ctmul64);
 }
 
+static void
+test_speed_ghash_pclmul(void)
+{
+       br_ghash gh;
+
+       gh = br_ghash_pclmul_get();
+       if (gh == 0) {
+               printf("%-30s UNAVAILABLE\n", "GHASH (pclmul)");
+               fflush(stdout);
+       } else {
+               test_speed_ghash_inner("GHASH (pclmul)", gh);
+       }
+}
+
+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)
@@ -354,6 +416,19 @@ 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)
 {
@@ -591,6 +666,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)
@@ -1158,6 +1248,26 @@ static const struct {
        STU(aes192_ct64_ctr),
        STU(aes256_ct64_ctr),
 
+       STU(aes128_x86ni_cbcenc),
+       STU(aes128_x86ni_cbcdec),
+       STU(aes192_x86ni_cbcenc),
+       STU(aes192_x86ni_cbcdec),
+       STU(aes256_x86ni_cbcenc),
+       STU(aes256_x86ni_cbcdec),
+       STU(aes128_x86ni_ctr),
+       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),
@@ -1173,14 +1283,18 @@ static const struct {
        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(rsa_i15),
        STU(rsa_i31),
        STU(rsa_i32),
+       STU(rsa_i62),
        STU(ec_prime_i15),
        STU(ec_prime_i31),
        STU(ec_p256_m15),