diff --git a/unit/test-crypto.c b/unit/test-crypto.c index c90ae3b3..b8d57a62 100644 --- a/unit/test-crypto.c +++ b/unit/test-crypto.c @@ -335,6 +335,36 @@ static void ptk_test(const void *data) l_free(ptk); } +static void aes_wrap_test(const void *data) +{ + /* RFC3394 section 4.1 test vector */ + static const uint8_t kek[16] = { + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, + }; + static const uint8_t key_data[16] = { + 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, + 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, + }; + static const uint8_t ciphertext[24] = { + 0x1f, 0xa6, 0x8b, 0x0a, 0x81, 0x12, 0xb4, 0x47, + 0xae, 0xf3, 0x4b, 0xd8, 0xfb, 0x5a, 0x7b, 0x82, + 0x9d, 0x3e, 0x86, 0x23, 0x71, 0xd2, 0xcf, 0xe5, + }; + uint8_t out[24]; + + memset(out, 0, 24); + + assert(aes_wrap(kek, key_data, sizeof(key_data), out)); + assert(!memcmp(out, ciphertext, sizeof(ciphertext))); + + out[10] = 10; + assert(!aes_unwrap(kek, out, sizeof(ciphertext), out)); + + assert(aes_unwrap(kek, ciphertext, sizeof(ciphertext), out)); + assert(!memcmp(out, key_data, sizeof(key_data))); +} + int main(int argc, char *argv[]) { l_test_init(&argc, &argv); @@ -360,6 +390,9 @@ int main(int argc, char *argv[]) l_test_add("/PTK Derivation/PTK Test Case 4", ptk_test, &ptk_test_4); + l_test_add("/AES Key-wrap/Wrap & unwrap", + aes_wrap_test, NULL); + done: return l_test_run(); }