diff --git a/node/C25519.cpp b/node/C25519.cpp index b36c7b8c2..3c7ff0d1e 100644 --- a/node/C25519.cpp +++ b/node/C25519.cpp @@ -53,7 +53,7 @@ ZT_ALWAYS_INLINE void fscalar_product(limb *output, const limb *in, const limb s } } -void fproduct(limb *output, const limb *in2, const limb *in) { +ZT_ALWAYS_INLINE void fproduct(limb *output, const limb *in2, const limb *in) { output[0] = ((limb) ((s32) in2[0])) * ((s32) in[0]); output[1] = ((limb) ((s32) in2[0])) * ((s32) in[1]) + ((limb) ((s32) in2[1])) * ((s32) in[0]); @@ -267,7 +267,7 @@ ZT_ALWAYS_INLINE void fmul(limb *output, const limb *in, const limb *in2) { memcpy(output, t, sizeof(limb) * 10); } -ZT_ALWAYS_INLINE void fsquare_inner(limb *output, const limb *in) { +void fsquare_inner(limb *output, const limb *in) { output[0] = ((limb) ((s32) in[0])) * ((s32) in[0]); output[1] = 2 * ((limb) ((s32) in[0])) * ((s32) in[1]); output[2] = 2 * (((limb) ((s32) in[1])) * ((s32) in[1]) + @@ -325,7 +325,7 @@ ZT_ALWAYS_INLINE void fsquare_inner(limb *output, const limb *in) { output[18] = 2 * ((limb) ((s32) in[9])) * ((s32) in[9]); } -void fsquare(limb *output, const limb *in) { +ZT_ALWAYS_INLINE void fsquare(limb *output, const limb *in) { limb t[19]; fsquare_inner(t, in); /* |t[i]| < 14*2^54 because the largest product of two limbs will be < diff --git a/node/Tests.cpp b/node/Tests.cpp index 9eb2517ab..d7ebc8512 100644 --- a/node/Tests.cpp +++ b/node/Tests.cpp @@ -687,47 +687,122 @@ extern "C" const char *ZTT_benchmarkCrypto() AES aes(AES_CTR_TEST_VECTOR_0_KEY); AES::CTR ctr(aes); int64_t start = now(); - for(long i=0;i<500000;++i) { + for(long i=0;i<350000;++i) { ctr.init(AES_CTR_TEST_VECTOR_0_IV,tmp); ctr.crypt(tmp,sizeof(tmp)); ctr.finish(); } int64_t end = now(); foo = tmp[0]; // prevent optimization - ZT_T_PRINTF("%.8f MiB/sec" ZT_EOL_S,((16384.0 * 500000.0) / 1048576.0) / ((double)(end - start) / 1000.0)); + ZT_T_PRINTF("%.4f MiB/sec" ZT_EOL_S,((16384.0 * 350000.0) / 1048576.0) / ((double)(end - start) / 1000.0)); ZT_T_PRINTF("[crypto] Benchmarking AES-GMAC... "); AES::GMAC gmac(aes); start = now(); - for(long i=0;i<500000;++i) { + for(long i=0;i<350000;++i) { gmac.init(tag); gmac.update(tmp,sizeof(tmp)); gmac.finish(tag); } end = now(); foo = tag[0]; // prevent optimization - ZT_T_PRINTF("%.8f MiB/sec" ZT_EOL_S,((16384.0 * 500000.0) / 1048576.0) / ((double)(end - start) / 1000.0)); + ZT_T_PRINTF("%.4f MiB/sec" ZT_EOL_S,((16384.0 * 350000.0) / 1048576.0) / ((double)(end - start) / 1000.0)); } { ZT_T_PRINTF("[crypto] Benchmarking Poly1305... "); int64_t start = now(); - for(long i=0;i<500000;++i) + for(long i=0;i<150000;++i) poly1305(tag,tmp,sizeof(tmp),tag); int64_t end = now(); foo = tag[0]; // prevent optimization - ZT_T_PRINTF("%.8f MiB/sec" ZT_EOL_S,((16384.0 * 500000.0) / 1048576.0) / ((double)(end - start) / 1000.0)); + ZT_T_PRINTF("%.4f MiB/sec" ZT_EOL_S,((16384.0 * 150000.0) / 1048576.0) / ((double)(end - start) / 1000.0)); } { ZT_T_PRINTF("[crypto] Benchmarking Salsa20/12 (using vector acceleration: %s)... ",Salsa20::accelerated() ? "yes" : "no"); Salsa20 s20(tmp,tag); int64_t start = now(); - for(long i=0;i<250000;++i) + for(long i=0;i<150000;++i) s20.crypt12(tmp,tmp,sizeof(tmp)); int64_t end = now(); foo = tmp[0]; // prevent optimization - ZT_T_PRINTF("%.8f MiB/sec" ZT_EOL_S,((16384.0 * 250000.0) / 1048576.0) / ((double)(end - start) / 1000.0)); + ZT_T_PRINTF("%.4f MiB/sec" ZT_EOL_S,((16384.0 * 150000.0) / 1048576.0) / ((double)(end - start) / 1000.0)); + } + + { + uint8_t key[ZT_C25519_SHARED_KEY_LEN]; + ZT_T_PRINTF("[crypto] Benchmarking Curve25519 ECDH... "); + int64_t start = now(); + for(int i=0;i<150;++i) { + for (int t=0;t