diff --git a/src/main.c b/src/main.c index c128e5d..46ebc07 100644 --- a/src/main.c +++ b/src/main.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -986,50 +987,74 @@ static int gt_track (uint8_t **db, struct ip_common *ic, uint8_t *data, int rev) return 0; } +static unsigned long long gt_now (void) +{ +#ifdef CLOCK_MONOTONIC + struct timespec tv; + clock_gettime(CLOCK_MONOTONIC, &tv); + return tv.tv_sec*1000000ULL+tv.tv_nsec/1000ULL; +#else + struct timeval tv; + gettimeofday(&tv, NULL); + return tv.tv_sec*1000000ULL+tv.tv_usec; +#endif +} + static void gt_bench (int chacha) { unsigned char npub[crypto_aead_aes256gcm_NPUBBYTES]; memset(npub, 0, sizeof(npub)); unsigned char key[crypto_aead_aes256gcm_KEYBYTES]; - memset(key, 1, sizeof(key)); + memset(key, 1, sizeof(key)); crypto_aead_aes256gcm_state ctx; if (!chacha) crypto_aead_aes256gcm_beforenm(&ctx, key); - int count = 2000000; - size_t size = 8; - gt_print("bench: %s\n", chacha?"chacha20poly1305":"aes256gcm"); _align_(16) unsigned char buf[32*1024+crypto_aead_aes256gcm_ABYTES]; - for (size_t size=8; size<=sizeof(buf); size*=2) { - struct timeval tv1; - gettimeofday(&tv1, NULL); + size_t bs = 8; - for (int i=0; !gt.quit && i