mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-05 20:13:44 +02:00
More crypto benchmarks
This commit is contained in:
parent
15e88a8b7e
commit
df99f5e3f3
2 changed files with 86 additions and 11 deletions
|
@ -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 <
|
||||
|
|
|
@ -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<ZT_NUM_C25519_TEST_VECTORS;++t) {
|
||||
C25519::agree(C25519_TEST_VECTORS[t].priv1,C25519_TEST_VECTORS[t].pub2,key);
|
||||
foo = key[0]; // prevent optimization
|
||||
}
|
||||
}
|
||||
int64_t end = now();
|
||||
ZT_T_PRINTF("%.4f μs/agreement" ZT_EOL_S,((double)(end - start) * 1000.0) / (double)(150 * ZT_NUM_C25519_TEST_VECTORS));
|
||||
}
|
||||
|
||||
{
|
||||
uint8_t sig[ZT_C25519_SIGNATURE_LEN];
|
||||
memset(sig,0,sizeof(sig));
|
||||
ZT_T_PRINTF("[crypto] Benchmarking Ed25519 signature... ");
|
||||
int64_t start = now();
|
||||
for(int i=0;i<150;++i) {
|
||||
for (int t=0;t<ZT_NUM_C25519_TEST_VECTORS;++t) {
|
||||
C25519::sign(C25519_TEST_VECTORS[t].priv1,C25519_TEST_VECTORS[t].pub1,sig,sizeof(sig),sig);
|
||||
foo = sig[0];
|
||||
}
|
||||
}
|
||||
int64_t end = now();
|
||||
ZT_T_PRINTF("%.4f μs/signature" ZT_EOL_S,((double)(end - start) * 1000.0) / (double)(150 * ZT_NUM_C25519_TEST_VECTORS));
|
||||
}
|
||||
|
||||
{
|
||||
ZT_T_PRINTF("[crypto] Benchmarking Ed25519 signature verification... ");
|
||||
int64_t start = now();
|
||||
for(int i=0;i<15;++i) {
|
||||
for (int t=0;t<ZT_NUM_C25519_TEST_VECTORS;++t) {
|
||||
if (C25519::verify(C25519_TEST_VECTORS[t].pub1,C25519_TEST_VECTORS[t].agreementSha512,64,C25519_TEST_VECTORS[t].agreementSignedBy1,96))
|
||||
++foo;
|
||||
}
|
||||
}
|
||||
int64_t end = now();
|
||||
ZT_T_PRINTF("%.4f μs/verify" ZT_EOL_S,((double)(end - start) * 1000.0) / (double)(15 * ZT_NUM_C25519_TEST_VECTORS));
|
||||
}
|
||||
|
||||
{
|
||||
uint8_t key[48];
|
||||
ZT_T_PRINTF("[crypto] Benchmarking ECC384 ECDH... ");
|
||||
volatile uint8_t *volatile pub = (volatile uint8_t *)ECC384_TV0_PUBLIC;
|
||||
int64_t start = now();
|
||||
for(int i=0;i<500;++i) {
|
||||
ECC384ECDH((const uint8_t *)pub,ECC384_TV0_PRIVATE,key);
|
||||
foo = key[0];
|
||||
}
|
||||
int64_t end = now();
|
||||
ZT_T_PRINTF("%.4f μs/agreement" ZT_EOL_S,((double)(end - start) * 1000.0) / (double)(500 * ZT_NUM_C25519_TEST_VECTORS));
|
||||
}
|
||||
|
||||
{
|
||||
uint8_t sig[96];
|
||||
ZT_T_PRINTF("[crypto] Benchmarking ECC384 signature... ");
|
||||
int64_t start = now();
|
||||
for(int i=0;i<500;++i) {
|
||||
ECC384ECDSASign(ECC384_TV0_PRIVATE,sig,sig);
|
||||
foo = sig[0];
|
||||
}
|
||||
int64_t end = now();
|
||||
ZT_T_PRINTF("%.4f μs/signature" ZT_EOL_S,((double)(end - start) * 1000.0) / (double)(500 * ZT_NUM_C25519_TEST_VECTORS));
|
||||
ZT_T_PRINTF("[crypto] Benchmarking ECC384 signature verification... ");
|
||||
start = now();
|
||||
for(int i=0;i<500;++i) {
|
||||
if (!ECC384ECDSAVerify(ECC384_TV0_PUBLIC,sig,sig))
|
||||
++foo;
|
||||
}
|
||||
end = now();
|
||||
ZT_T_PRINTF("%.4f μs/verify" ZT_EOL_S,((double)(end - start) * 1000.0) / (double)(500 * ZT_NUM_C25519_TEST_VECTORS));
|
||||
}
|
||||
} catch (std::exception &e) {
|
||||
ZT_T_PRINTF(ZT_EOL_S "[crypto] Unexpected exception: %s" ZT_EOL_S,e.what());
|
||||
|
|
Loading…
Add table
Reference in a new issue