| 1 |
/** |
| 2 |
* \file test-kdf-pbkdf2-hmac-sha1.c |
| 3 |
* |
| 4 |
* \brief The PBKDF2 HMAC-SHA-1 unit-tests |
| 5 |
* |
| 6 |
* \warning SHA-1 is considered a weak message digest and its use constitutes |
| 7 |
* a security risk! We recommend considering stronger message digests |
| 8 |
* instead! |
| 9 |
* |
| 10 |
* \copyright 2022 Joseph Benden <[email protected]> |
| 11 |
* |
| 12 |
* \license GPL-2.0-OR-LATER |
| 13 |
*/ |
| 14 |
|
| 15 |
#ifdef HAVE_CONFIG_H |
| 16 |
#include "config.h" |
| 17 |
#endif |
| 18 |
|
| 19 |
#include <stdint.h> |
| 20 |
#include <stdio.h> |
| 21 |
#include <string.h> |
| 22 |
#include <strings.h> |
| 23 |
#include <stdlib.h> |
| 24 |
|
| 25 |
#include "aircrack-ng/crypto/crypto.h" |
| 26 |
#include "tests.h" |
| 27 |
|
| 28 |
// clang-format off |
| 29 |
/* |
| 30 |
* RFC 6070 test vectors |
| 31 |
*/ |
| 32 |
struct { |
| 33 |
uint8_t key[96]; |
| 34 |
size_t key_len; |
| 35 |
uint8_t data[128]; |
| 36 |
size_t data_len; |
| 37 |
size_t iterations; |
| 38 |
uint8_t digest[DIGEST_SHA1_MAC_LEN]; |
| 39 |
} sha1_tests[] = { |
| 40 |
{ |
| 41 |
"password\0", |
| 42 |
8, |
| 43 |
"salt", |
| 44 |
4, |
| 45 |
1, |
| 46 |
{0x0c, 0x60, 0xc8, 0x0f, 0x96, 0x1f, 0x0e, 0x71, |
| 47 |
0xf3, 0xa9, 0xb5, 0x24, 0xaf, 0x60, 0x12, 0x06, |
| 48 |
0x2f, 0xe0, 0x37, 0xa6} |
| 49 |
}, |
| 50 |
{ |
| 51 |
"password\0", |
| 52 |
8, |
| 53 |
"salt", |
| 54 |
4, |
| 55 |
2, |
| 56 |
{0xea, 0x6c, 0x01, 0x4d, 0xc7, 0x2d, 0x6f, 0x8c, |
| 57 |
0xcd, 0x1e, 0xd9, 0x2a, 0xce, 0x1d, 0x41, 0xf0, |
| 58 |
0xd8, 0xde, 0x89, 0x57 } |
| 59 |
#ifdef EXPENSIVE_TESTS |
| 60 |
}, |
| 61 |
{ |
| 62 |
"password\0", |
| 63 |
8, |
| 64 |
"salt", |
| 65 |
4, |
| 66 |
4096, |
| 67 |
{0x4b, 0x00, 0x79, 0x01, 0xb7, 0x65, 0x48, 0x9a, |
| 68 |
0xbe, 0xad, 0x49, 0xd9, 0x26, 0xf7, 0x21, 0xd0, |
| 69 |
0x65, 0xa4, 0x29, 0xc1} |
| 70 |
}, |
| 71 |
{ |
| 72 |
"password\0", |
| 73 |
8, |
| 74 |
"salt", |
| 75 |
4, |
| 76 |
16777216, |
| 77 |
{0xee, 0xfe, 0x3d, 0x61, 0xcd, 0x4d, 0xa4, 0xe4, |
| 78 |
0xe9, 0x94, 0x5b, 0x3d, 0x6b, 0xa2, 0x15, 0x8c, |
| 79 |
0x26, 0x34, 0xe9, 0x84} |
| 80 |
#endif |
| 81 |
} |
| 82 |
}; |
| 83 |
// clang-format on |
| 84 |
|
| 85 |
STATIC_ASSERT(ArrayCount(sha1_tests) >= 2u, ensure_at_least_2_entries); |
| 86 |
|
| 87 |
int main(int argc, char ** argv) |
| 88 |
{ |
| 89 |
size_t i; |
| 90 |
int error = 0; |
| 91 |
uint8_t sha1sum[DIGEST_SHA1_MAC_LEN]; |
| 92 |
|
| 93 |
(void) argc; |
| 94 |
|
| 95 |
for (i = 0; i < ArrayCount(sha1_tests); i++) |
| 96 |
{ |
| 97 |
error |= KDF_PBKDF2_SHA1(sha1_tests[i].key, |
| 98 |
sha1_tests[i].data, |
| 99 |
sha1_tests[i].data_len, |
| 100 |
sha1_tests[i].iterations, |
| 101 |
sha1sum, |
| 102 |
DIGEST_SHA1_MAC_LEN); |
| 103 |
error |= test( |
| 104 |
sha1sum, sha1_tests[i].digest, DIGEST_SHA1_MAC_LEN, argv[0]); |
| 105 |
} |
| 106 |
|
| 107 |
return error; |
| 108 |
} |