1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-25 06:23:53 +01:00

tests/ccm: add test for input_len check

This commit is contained in:
Gaëtan Harter 2017-11-22 15:05:59 +01:00
parent 89023b3499
commit a47e5e427e
No known key found for this signature in database
GPG Key ID: 76DF6BCF1B1F883B

View File

@ -190,11 +190,51 @@ static void test_crypto_modes_ccm_decrypt(void)
}
typedef int (*func_ccm_t)(cipher_t*, uint8_t*, uint32_t, uint8_t, uint8_t,
uint8_t*, size_t, uint8_t*, size_t, uint8_t*);
static int _test_ccm_len(func_ccm_t func, uint8_t len_encoding,
uint8_t *input, size_t input_len, size_t adata_len)
{
int ret;
cipher_t cipher;
uint8_t mac_length = 8;
uint8_t nonce[15] = {0};
uint8_t key[16] = {0};
uint8_t nonce_len = nonce_and_len_encoding_size - len_encoding;
cipher_init(&cipher, CIPHER_AES_128, key, 16);
ret = func(&cipher, NULL, adata_len, mac_length, len_encoding,
nonce, nonce_len, input, input_len, data);
return ret;
}
/* Test length checking in ccm functions. */
static void test_crypto_modes_ccm_check_len(void)
{
int ret;
/* Just 1 to big to fit */
ret = _test_ccm_len(cipher_encrypt_ccm, 2, NULL, 1 << 16, 0);
TEST_ASSERT_EQUAL_INT(CCM_ERR_INVALID_LENGTH_ENCODING, ret);
ret = _test_ccm_len(cipher_decrypt_ccm, 2, NULL, 1 << 16, 0);
TEST_ASSERT_EQUAL_INT(CCM_ERR_INVALID_LENGTH_ENCODING, ret);
/* adata_len should not change the result (was wrong in previous implem) */
ret = _test_ccm_len(cipher_encrypt_ccm, 2, NULL, 1 << 16, 65535);
TEST_ASSERT_EQUAL_INT(CCM_ERR_INVALID_LENGTH_ENCODING, ret);
ret = _test_ccm_len(cipher_decrypt_ccm, 2, NULL, 1 << 16, 65535);
TEST_ASSERT_EQUAL_INT(CCM_ERR_INVALID_LENGTH_ENCODING, ret);
}
Test* tests_crypto_modes_ccm_tests(void)
{
EMB_UNIT_TESTFIXTURES(fixtures) {
new_TestFixture(test_crypto_modes_ccm_encrypt),
new_TestFixture(test_crypto_modes_ccm_decrypt),
new_TestFixture(test_crypto_modes_ccm_check_len),
};
EMB_UNIT_TESTCALLER(crypto_modes_ccm_tests, NULL, NULL, fixtures);