diff options
| author | jhurst <jhurst@cinecert.com> | 2009-10-08 15:58:16 +0000 |
|---|---|---|
| committer | jhurst <> | 2009-10-08 15:58:16 +0000 |
| commit | 19bd80c074e1dec35404fd85607a2a68c791b2d9 (patch) | |
| tree | b0ca75276663bca2a7beb64bf3bf5ceac01abeea /src/fips-186-rng-test.cpp | |
| parent | 99ff2799c6926419c049d7d307b7f558505283ab (diff) | |
FIPS 186-2 fixes
Diffstat (limited to 'src/fips-186-rng-test.cpp')
| -rwxr-xr-x | src/fips-186-rng-test.cpp | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/src/fips-186-rng-test.cpp b/src/fips-186-rng-test.cpp index b0a677b..08a1665 100755 --- a/src/fips-186-rng-test.cpp +++ b/src/fips-186-rng-test.cpp @@ -39,47 +39,52 @@ using namespace Kumu; int main(int argc, const char** argv) { - if ( argc != 3 ) + if ( argc != 5 ) { - fprintf(stderr, "USAGE: fips-186-test <XKey-hex> <X-hex>\n"); + fprintf(stderr, "USAGE: fips-186-test <rounds> <b> <XKey-hex> <X-hex>\n"); return 2; } - byte_t XKey_buf[SHA_DIGEST_LENGTH]; - byte_t X_test_buf[SHA_DIGEST_LENGTH*2]; - byte_t X_buf[SHA_DIGEST_LENGTH*2]; + ui32_t const X_buf_len = 1024; + byte_t XKey_buf[X_buf_len]; + byte_t X_test_buf[X_buf_len]; ui32_t char_count; - if ( hex2bin(argv[1], XKey_buf, SHA_DIGEST_LENGTH, &char_count) != 0 ) + char* end = 0; + ui32_t rounds = strtol(argv[1], &end, 10); + ui32_t B = strtol(argv[2], &end, 10) / 8; + + if ( hex2bin(argv[3], XKey_buf, X_buf_len, &char_count) != 0 ) { fprintf(stderr, "Error parsing <XKey-hex> value\n"); return 3; } - if ( char_count != SHA_DIGEST_LENGTH ) + if ( char_count != B ) { - fprintf(stderr, "Incorrect length for <XKey-hex> value (expecting 40 hexadecimal characters)\n"); + fprintf(stderr, "Incorrect length for <XKey-hex> value (expecting %d decoded bytes)\n", B); return 3; } - if ( hex2bin(argv[2], X_test_buf, SHA_DIGEST_LENGTH*2, &char_count) != 0 ) + if ( hex2bin(argv[4], X_test_buf, X_buf_len, &char_count) != 0 ) { - fprintf(stderr, "Error parsing <XKey-hex> value\n"); + fprintf(stderr, "Error parsing <X-hex> value\n"); return 3; } - if ( char_count != (SHA_DIGEST_LENGTH * 2) ) - { - fprintf(stderr, "Incorrect length for <X-hex> value (expecting 80 hexadecimal characters)\n"); - return 3; - } + ui32_t const meg = 1024*1024; + ui32_t out_size = char_count; + byte_t X_buf[meg]; + ui32_t fill_size = rounds * 20; + assert(fill_size < meg); + Gen_FIPS_186_Value(XKey_buf, B, X_buf, fill_size); - Gen_FIPS_186_Value(XKey_buf, SHA_DIGEST_LENGTH, X_buf, SHA_DIGEST_LENGTH*2); + byte_t* test_key = &X_buf[fill_size - out_size]; - if ( memcmp(X_buf, X_test_buf, SHA_DIGEST_LENGTH*2) != 0 ) + if ( memcmp(test_key, X_test_buf, char_count) != 0 ) { fprintf(stderr, "Test vector value does not match:\n"); - hexdump(X_buf, SHA_DIGEST_LENGTH*2); + hexdump(test_key, char_count); return 4; } |
