mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
sys/crypto: Add unit test for CCM mode with AAD length > 24
This commit is contained in:
parent
6fe6f8f6ca
commit
c817bc9a11
@ -823,6 +823,47 @@ static const uint8_t TEST_NIST_3_EXPECTED[] = {
|
||||
};
|
||||
static const size_t TEST_NIST_3_EXPECTED_LEN = 52;
|
||||
|
||||
/* Tests from Project Wycheproof */
|
||||
/* See https://github.com/google/wycheproof/blob/master/testvectors/aes_ccm_test.json */
|
||||
|
||||
static const uint8_t TEST_WYCHEPROOF_28_KEY[] = {
|
||||
0x20, 0xbb, 0xf7, 0x4c, 0x1e, 0x63, 0x98, 0x2c,
|
||||
0x47, 0x2c, 0x47, 0x43, 0x56, 0x9e, 0x4c, 0x84,
|
||||
};
|
||||
static const size_t TEST_WYCHEPROOF_28_KEY_LEN = 16;
|
||||
static const uint8_t TEST_WYCHEPROOF_28_NONCE[] = {
|
||||
0x45, 0x9f, 0xc7, 0xc0, 0x04, 0xbf, 0x46, 0x32,
|
||||
0x3a, 0x02, 0xd8, 0x46,
|
||||
};
|
||||
static const size_t TEST_WYCHEPROOF_28_NONCE_LEN = 12;
|
||||
static const size_t TEST_WYCHEPROOF_28_MAC_LEN = 16;
|
||||
static const uint8_t TEST_WYCHEPROOF_28_INPUT[] = {
|
||||
/* AAD */
|
||||
0x4f, 0x22, 0x85, 0xce, 0x3d, 0xaf, 0xa5, 0x28,
|
||||
0xc6, 0x94, 0xa5, 0x27, 0x2d, 0x3b, 0x7b, 0x92,
|
||||
0x90, 0x97, 0xdb, 0x39, 0x87, 0x72, 0x65, 0x3b,
|
||||
0xd9, 0xbb, 0xbd, 0xb3, 0xb2, 0xc8, 0xe1,
|
||||
/* PLAINTEXT */
|
||||
0x6d, 0xb5, 0x09, 0x92, 0xe8, 0xfb, 0xbe, 0xe1,
|
||||
0x5d, 0x49, 0x79, 0xd3, 0xe3, 0x22, 0xda, 0xcd,
|
||||
};
|
||||
static const size_t TEST_WYCHEPROOF_28_INPUT_LEN = 16;
|
||||
static const size_t TEST_WYCHEPROOF_28_ADATA_LEN = 31;
|
||||
static const uint8_t TEST_WYCHEPROOF_28_EXPECTED[] = {
|
||||
/* AAD */
|
||||
0x4f, 0x22, 0x85, 0xce, 0x3d, 0xaf, 0xa5, 0x28,
|
||||
0xc6, 0x94, 0xa5, 0x27, 0x2d, 0x3b, 0x7b, 0x92,
|
||||
0x90, 0x97, 0xdb, 0x39, 0x87, 0x72, 0x65, 0x3b,
|
||||
0xd9, 0xbb, 0xbd, 0xb3, 0xb2, 0xc8, 0xe1,
|
||||
/* CIPHERTEXT */
|
||||
0x87, 0x03, 0xe4, 0x46, 0x97, 0x13, 0x8c, 0x58,
|
||||
0x53, 0x2d, 0x97, 0xee, 0x99, 0x23, 0x1d, 0x94,
|
||||
/* MAC */
|
||||
0xf1, 0x4c, 0x2f, 0x39, 0xa4, 0x87, 0x1a, 0x4a,
|
||||
0x16, 0xc4, 0x2f, 0x6f, 0xe8, 0x78, 0xde, 0xef,
|
||||
};
|
||||
static const size_t TEST_WYCHEPROOF_28_EXPECTED_LEN = 63;
|
||||
|
||||
/* Share test buffer output */
|
||||
static uint8_t data[60];
|
||||
|
||||
@ -852,7 +893,6 @@ static void test_encrypt_op(const uint8_t *key, uint8_t key_len,
|
||||
TEST_ASSERT_EQUAL_INT(output_expected_len, len);
|
||||
cmp = compare(output_expected, data, len);
|
||||
TEST_ASSERT_MESSAGE(1 == cmp, "wrong ciphertext");
|
||||
|
||||
}
|
||||
|
||||
static void test_decrypt_op(const uint8_t *key, uint8_t key_len,
|
||||
@ -930,6 +970,8 @@ static void test_crypto_modes_ccm_encrypt(void)
|
||||
do_test_encrypt_op(NIST_1);
|
||||
do_test_encrypt_op(NIST_2);
|
||||
do_test_encrypt_op(NIST_3);
|
||||
|
||||
do_test_encrypt_op(WYCHEPROOF_28);
|
||||
}
|
||||
|
||||
#define do_test_decrypt_op(name) do { \
|
||||
@ -977,6 +1019,8 @@ static void test_crypto_modes_ccm_decrypt(void)
|
||||
do_test_decrypt_op(NIST_1);
|
||||
do_test_decrypt_op(NIST_2);
|
||||
do_test_decrypt_op(NIST_3);
|
||||
|
||||
do_test_decrypt_op(WYCHEPROOF_28);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user