void bench_blake2(void) { Blake2b b2b; byte digest[64]; double start, total, persec; int i; InitBlake2b(&b2b, 64); start = current_time(1); for(i = 0; i < numBlocks; i++) Blake2bUpdate(&b2b, plain, sizeof(plain)); Blake2bFinal(&b2b, digest, 64); total = current_time(0) - start; persec = 1 / total * numBlocks; #ifdef BENCH_EMBEDDED /* since using kB, convert to MB/s */ persec = persec / 1024; #endif printf("BLAKE2b %d %s took %5.3f seconds, %6.2f MB/s\n", numBlocks, blockType, total, persec); }
static int InitHmac(Hmac* hmac, int type) { int ret = 0; hmac->innerHashKeyed = 0; hmac->macType = (byte)type; if (!(type == MD5 || type == SHA || type == SHA256 || type == SHA384 || type == SHA512 || type == BLAKE2B_ID)) return BAD_FUNC_ARG; switch (type) { #ifndef NO_MD5 case MD5: InitMd5(&hmac->hash.md5); break; #endif #ifndef NO_SHA case SHA: ret = InitSha(&hmac->hash.sha); break; #endif #ifndef NO_SHA256 case SHA256: ret = InitSha256(&hmac->hash.sha256); break; #endif #ifdef CYASSL_SHA384 case SHA384: ret = InitSha384(&hmac->hash.sha384); break; #endif #ifdef CYASSL_SHA512 case SHA512: ret = InitSha512(&hmac->hash.sha512); break; #endif #ifdef HAVE_BLAKE2 case BLAKE2B_ID: ret = InitBlake2b(&hmac->hash.blake2b, BLAKE2B_256); break; #endif default: return BAD_FUNC_ARG; } return ret; }
void bench_blake2(void) { Blake2b b2b; byte digest[64]; double start, total, persec; int i, ret; ret = InitBlake2b(&b2b, 64); if (ret != 0) { printf("InitBlake2b failed, ret = %d\n", ret); return; } start = current_time(1); for(i = 0; i < numBlocks; i++) { ret = Blake2bUpdate(&b2b, plain, sizeof(plain)); if (ret != 0) { printf("Blake2bUpdate failed, ret = %d\n", ret); return; } } ret = Blake2bFinal(&b2b, digest, 64); if (ret != 0) { printf("Blake2bFinal failed, ret = %d\n", ret); return; } total = current_time(0) - start; persec = 1 / total * numBlocks; #ifdef BENCH_EMBEDDED /* since using kB, convert to MB/s */ persec = persec / 1024; #endif printf("BLAKE2b %d %s took %5.3f seconds, %7.3f MB/s\n", numBlocks, blockType, total, persec); }