| 1 |
#ifdef HAVE_CONFIG_H |
| 2 |
#include "config.h" |
| 3 |
#endif |
| 4 |
|
| 5 |
#include <stdarg.h> |
| 6 |
#include <stddef.h> |
| 7 |
#include <setjmp.h> |
| 8 |
#include <cmocka.h> |
| 9 |
|
| 10 |
#include <assert.h> |
| 11 |
#include <stdio.h> |
| 12 |
#include <stdlib.h> |
| 13 |
|
| 14 |
#include "aircrack-ng/ce-wpa/crypto_engine.h" |
| 15 |
#include "aircrack-ng/crypto/crypto.h" |
| 16 |
|
| 17 |
static void test_calc_one_pmk(void ** state) |
| 18 |
{ |
| 19 |
(void) state; |
| 20 |
|
| 21 |
uint8_t essid[] = "linksys"; |
| 22 |
uint8_t key[] = "password"; |
| 23 |
uint8_t pmk[PMK_LEN] = {0}; |
| 24 |
uint8_t expected[PMK_LEN] |
| 25 |
= {0xec, 0xc9, 0x99, 0x1e, 0x3c, 0xfb, 0x1b, 0x11, 0x7b, 0xdb, |
| 26 |
0xbd, 0x0, 0xde, 0xb4, 0x7, 0xf0, 0x23, 0x29, 0x44, 0xb5, |
| 27 |
0x68, 0x21, 0x64, 0x7e, 0x23, 0x49, 0x13, 0x9d, 0x2, 0xfd, |
| 28 |
0x2b, 0xfb}; |
| 29 |
|
| 30 |
memset(pmk, 0, sizeof(pmk)); |
| 31 |
ac_crypto_engine_calc_one_pmk(key, essid, strlen((char *) essid), pmk); |
| 32 |
|
| 33 |
assert_int_equal(sizeof(pmk), sizeof(expected)); |
| 34 |
assert_memory_equal(pmk, expected, sizeof(expected)); |
| 35 |
} |
| 36 |
|
| 37 |
static void test_calc_pmk(void ** state) |
| 38 |
{ |
| 39 |
(void) state; |
| 40 |
|
| 41 |
uint8_t essid[33] = "linksys"; |
| 42 |
wpapsk_password key[MAX_KEYS_PER_CRYPT_SUPPORTED]; |
| 43 |
ac_crypto_engine_t engine; |
| 44 |
|
| 45 |
memset(&engine, 0, sizeof(engine)); |
| 46 |
ac_crypto_engine_init(&engine); |
| 47 |
ac_crypto_engine_set_essid(&engine, &essid[0]); |
| 48 |
ac_crypto_engine_thread_init(&engine, 1); |
| 49 |
|
| 50 |
memset(key, 0, sizeof(key)); |
| 51 |
|
| 52 |
strcpy((char *) (key[0].v), "password"); |
| 53 |
key[0].length = 8; |
| 54 |
|
| 55 |
ac_crypto_engine_calc_pmk(&engine, key, 1, 1); |
| 56 |
|
| 57 |
uint8_t expected[PMK_LEN] |
| 58 |
= {0xec, 0xc9, 0x99, 0x1e, 0x3c, 0xfb, 0x1b, 0x11, 0x7b, 0xdb, |
| 59 |
0xbd, 0x0, 0xde, 0xb4, 0x7, 0xf0, 0x23, 0x29, 0x44, 0xb5, |
| 60 |
0x68, 0x21, 0x64, 0x7e, 0x23, 0x49, 0x13, 0x9d, 0x2, 0xfd, |
| 61 |
0x2b, 0xfb}; |
| 62 |
|
| 63 |
assert_memory_equal((unsigned char *) (engine.thread_data[1]->pmk), |
| 64 |
expected, |
| 65 |
sizeof(expected)); |
| 66 |
|
| 67 |
ac_crypto_engine_thread_destroy(&engine, 1); |
| 68 |
ac_crypto_engine_destroy(&engine); |
| 69 |
} |
| 70 |
|
| 71 |
int main(int argc, char * argv[]) |
| 72 |
{ |
| 73 |
(void) argc; |
| 74 |
(void) argv; |
| 75 |
|
| 76 |
const struct CMUnitTest tests[] = { |
| 77 |
cmocka_unit_test(test_calc_one_pmk), cmocka_unit_test(test_calc_pmk), |
| 78 |
}; |
| 79 |
return cmocka_run_group_tests(tests, NULL, NULL); |
| 80 |
} |