| double cpu_speed = 0.0; |
double cpu_speed = 0.0; |
| double test_time = 3.0; |
double test_time = 3.0; |
| |
|
| |
int quiet = 0; |
| int test_packet = 1; |
int test_packet = 1; |
| int test_setup = 1; |
int test_setup = 1; |
| int output_vectors = 0; |
int output_vectors = 0; |
| |
|
| if (errors >= 10) |
if (errors >= 10) |
| { |
{ |
| fprintf(stderr, "Too many errors (%d errors). Aborting test.\n", errors); |
if (!quiet) |
| exit(1); |
fprintf(stderr, |
| |
"Too many errors (%d errors). Aborting test.\n", errors); |
| |
|
| |
exit(3); |
| } |
} |
| |
|
| if (sec > test_time) |
if (sec > test_time) |
| { |
{ |
| fprintf(stderr, "Time out (%.2f seconds). Aborting test.\n", sec); |
if (!quiet) |
| exit(2); |
fprintf(stderr, |
| |
"Time out (%.2f seconds). Aborting test.\n", sec); |
| |
|
| |
exit(1); |
| } |
} |
| } |
} |
| |
|
| fprintf(fd, "Primitive Name: %s\n", ECRYPT_NAME); |
fprintf(fd, "Primitive Name: %s\n", ECRYPT_NAME); |
| fprintf(fd, "================%.*s\n", (int)strlen(ECRYPT_NAME), |
fprintf(fd, "================%.*s\n", (int)strlen(ECRYPT_NAME), |
| "=========================================="); |
"=========================================="); |
| |
fprintf(fd, "Profile: %s\n", ECRYPT_PROFILE); |
| fprintf(fd, "Key size: %d bits\n", keysize); |
fprintf(fd, "Key size: %d bits\n", keysize); |
| fprintf(fd, "IV size: %d bits\n", ivsize); |
fprintf(fd, "IV size: %d bits\n", ivsize); |
| #ifdef ECRYPT_AE |
#ifdef ECRYPT_AE |
| |
|
| CTX ctx; |
CTX ctx; |
| |
|
| u8 key[MAXKEYSIZEB]; |
ALIGN(u8 key[MAXKEYSIZEB]); |
| u8 iv[MAXIVSIZEB]; |
ALIGN(u8 iv[MAXIVSIZEB]); |
| |
|
| u8 plaintext[LONG_TEST_STREAM_SIZEB]; |
ALIGN(u8 plaintext[LONG_TEST_STREAM_SIZEB]); |
| u8 ciphertext[LONG_TEST_STREAM_SIZEB]; |
ALIGN(u8 ciphertext[LONG_TEST_STREAM_SIZEB]); |
| u8 checktext[LONG_TEST_STREAM_SIZEB]; |
ALIGN(u8 checktext[LONG_TEST_STREAM_SIZEB]); |
| |
|
| #ifdef ECRYPT_AE |
#ifdef ECRYPT_AE |
| int macsize; |
int macsize; |
| int aadlen; |
int aadlen; |
| |
|
| u8 aad[TEST_CHUNK]; |
ALIGN(u8 aad[TEST_CHUNK]); |
| u8 mac[MAXMACSIZEB]; |
ALIGN(u8 mac[MAXMACSIZEB]); |
| u8 checkmac[MAXMACSIZEB]; |
ALIGN(u8 checkmac[MAXMACSIZEB]); |
| #endif |
#endif |
| |
|
| u8 xored[TEST_CHUNK]; |
ALIGN(u8 xored[TEST_CHUNK]); |
| |
|
| FILE *fd; |
FILE *fd; |
| |
|
| { |
{ |
| CTX ctx[2]; |
CTX ctx[2]; |
| |
|
| u8 key[2][MAXKEYSIZEB]; |
ALIGN(u8 key[2][MAXKEYSIZEB]); |
| u8 iv[2][MAXIVSIZEB]; |
ALIGN(u8 iv[2][MAXIVSIZEB]); |
| |
|
| u8 plaintext[TEST_CHUNK + ECRYPT_BLOCKLENGTH]; |
ALIGN(u8 plaintext[TEST_CHUNK + ECRYPT_BLOCKLENGTH]); |
| u8 ciphertext[3][TEST_CHUNK + ECRYPT_BLOCKLENGTH]; |
ALIGN(u8 ciphertext[3][TEST_CHUNK + ECRYPT_BLOCKLENGTH]); |
| #ifdef ECRYPT_AE |
#ifdef ECRYPT_AE |
| u8 mac[3][MAXMACSIZEB]; |
ALIGN(u8 mac[3][MAXMACSIZEB]); |
| #endif |
#endif |
| |
|
| int msglen = TEST_CHUNK; |
int msglen = TEST_CHUNK; |
| { |
{ |
| CTX ctx[KEYS_TO_TEST]; |
CTX ctx[KEYS_TO_TEST]; |
| |
|
| u8 key[KEYS_TO_TEST][MAXKEYSIZEB]; |
ALIGN(u8 key[KEYS_TO_TEST][MAXKEYSIZEB]); |
| u8 iv[KEYS_TO_TEST][MAXIVSIZEB]; |
ALIGN(u8 iv[KEYS_TO_TEST][MAXIVSIZEB]); |
| u8 text[2][TEST_BLOCKS * ECRYPT_BLOCKLENGTH]; |
ALIGN(u8 text[2][TEST_BLOCKS * ECRYPT_BLOCKLENGTH]); |
| #ifdef ECRYPT_AE |
#ifdef ECRYPT_AE |
| u8 mac[MAXMACSIZEB]; |
ALIGN(u8 mac[MAXMACSIZEB]); |
| #endif |
#endif |
| |
|
| int tests, tests_per_key, keys_to_test; |
int tests, tests_per_key, keys_to_test; |
| case 's': |
case 's': |
| single_key = 1; |
single_key = 1; |
| break; |
break; |
| |
case 'q': |
| |
quiet = 1; |
| |
break; |
| } |
} |
| |
|
| argc--; |
argc--; |
| " -t SEC limit the duration of the tests (default: 3 seconds)\n" |
" -t SEC limit the duration of the tests (default: 3 seconds)\n" |
| " -p do not test packet encryption speed\n" |
" -p do not test packet encryption speed\n" |
| " -k do not test key and IV setup speed\n" |
" -k do not test key and IV setup speed\n" |
| " -s perform tests for a single key and IV length\n"); |
" -s perform tests for a single key and IV length\n" |
| |
" -q be quiet\n"); |
| |
|
| exit(1); |
exit(2); |
| } |
} |
| |
|
| print_header(stdout); |
print_header(stdout); |
| } |
} |
| } |
} |
| |
|
| |
if (!quiet) |
| |
{ |
| fprintf(stderr, "Elapsed time: %.2f seconds.\n", |
fprintf(stderr, "Elapsed time: %.2f seconds.\n", |
| (double)clock() / (double)CLOCKS_PER_SEC); |
(double)clock() / (double)CLOCKS_PER_SEC); |
| fprintf(stderr, "There were %d errors.\n", errors); |
fprintf(stderr, "There were %d errors.\n", errors); |
| |
} |
| |
|
| if (errors) |
if (errors) |
| return 1; |
return 3; |
| else |
else |
| return 0; |
return 0; |
| } |
} |