Last active
August 29, 2015 14:03
-
-
Save rblaze/fe469a8cca74697353d8 to your computer and use it in GitHub Desktop.
AES perf test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define CHECK(x) \ | |
do { \ | |
NTSTATUS __l_status = (x); \ | |
if (! BCRYPT_SUCCESS(__l_status)) { \ | |
printf("ERROR: `%s` returned %x\n", #x, __l_status); \ | |
return 1; \ | |
} \ | |
} while (0) | |
UCHAR masterSecret[128]; | |
int BulkTest() | |
{ | |
BCRYPT_ALG_HANDLE encAlgHandle; | |
BCRYPT_KEY_HANDLE keyHandle; | |
LARGE_INTEGER start, end, rate; | |
UCHAR iv[16]; | |
QueryPerformanceFrequency(&rate); | |
CHECK(BCryptOpenAlgorithmProvider(&encAlgHandle, BCRYPT_AES_ALGORITHM, NULL, 0)); | |
CHECK(BCryptGenerateSymmetricKey(encAlgHandle, &keyHandle, NULL, 0, masterSecret, 16, 0)); | |
ULONG ciphertextsize; | |
LONG size = 128*1024*1024; | |
UCHAR *pt = (UCHAR *)malloc(size); | |
UCHAR *ct = (UCHAR *)malloc(size); | |
memset(iv, 0, sizeof(iv)); | |
QueryPerformanceCounter(&start); | |
CHECK(BCryptEncrypt(keyHandle, pt, size, NULL, iv, sizeof(iv), ct, size, &ciphertextsize, 0)); | |
QueryPerformanceCounter(&end); | |
printf("encryption %d bytes time %I64d ticks, %I64d bps\n", ciphertextsize, end.QuadPart - start.QuadPart, rate.QuadPart * size / (end.QuadPart - start.QuadPart)); | |
memset(iv, 0, sizeof(iv)); | |
QueryPerformanceCounter(&start); | |
CHECK(BCryptDecrypt(keyHandle, ct, ciphertextsize, NULL, iv, sizeof(iv), pt, size, &ciphertextsize, 0)); | |
QueryPerformanceCounter(&end); | |
printf("decryption %d bytes time %I64d ticks, %I64d bps\n", ciphertextsize, end.QuadPart - start.QuadPart, rate.QuadPart * size / (end.QuadPart - start.QuadPart)); | |
free(pt); | |
free(ct); | |
CHECK(BCryptDestroyKey(keyHandle)); | |
CHECK(BCryptCloseAlgorithmProvider(encAlgHandle, 0)); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment