From 04890b18996f2c244b770f9adbe06dd24a7fb7bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Th=C3=A9baudeau?= Date: Wed, 23 Dec 2015 01:04:13 +0100 Subject: [PATCH] cc2538: ccm: Allow separate input/output buffers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is supported by the hardware, so give access to this feature in the API. Signed-off-by: Benoît Thébaudeau --- cpu/cc2538/dev/ccm.c | 27 +++++---- cpu/cc2538/dev/ccm.h | 74 +++++++++++++++-------- examples/cc2538dk/crypto/ccm-test.c | 93 +++++++++++------------------ 3 files changed, 97 insertions(+), 97 deletions(-) diff --git a/cpu/cc2538/dev/ccm.c b/cpu/cc2538/dev/ccm.c index 70e3fac34..c0f02ddc1 100644 --- a/cpu/cc2538/dev/ccm.c +++ b/cpu/cc2538/dev/ccm.c @@ -51,11 +51,11 @@ static uint8_t ccm_auth_crypt_start(uint8_t encrypt, uint8_t len_len, uint8_t key_area, const void *nonce, const void *adata, uint16_t adata_len, - void *data, uint16_t data_len, uint8_t mic_len, - struct process *process) + const void *data_in, void *data_out, uint16_t data_len, + uint8_t mic_len, struct process *process) { uint32_t ctrl; - uint32_t iv[4]; + uint32_t iv[AES_IV_LEN / sizeof(uint32_t)]; /* Program AES-CCM authentication/crypto operation */ ctrl = AES_AES_CTRL_SAVE_CONTEXT | /* Save context */ @@ -70,19 +70,20 @@ ccm_auth_crypt_start(uint8_t encrypt, uint8_t len_len, uint8_t key_area, * Flags: L' = L - 1 */ ((uint8_t *)iv)[0] = len_len - 1; /* Nonce */ - rom_util_memcpy(&((uint8_t *)iv)[1], nonce, 15 - len_len); + rom_util_memcpy(&((uint8_t *)iv)[CCM_FLAGS_LEN], nonce, + CCM_NONCE_LEN_LEN - len_len); /* Initialize counter to 0 */ - rom_util_memset(&((uint8_t *)iv)[16 - len_len], 0, len_len); + rom_util_memset(&((uint8_t *)iv)[AES_IV_LEN - len_len], 0, len_len); return aes_auth_crypt_start(ctrl, key_area, iv, adata, adata_len, - data, data, data_len, process); + data_in, data_out, data_len, process); } /*---------------------------------------------------------------------------*/ static uint8_t ccm_auth_crypt_get_result(const void *cdata, uint16_t cdata_len, void *mic, uint8_t mic_len) { - uint32_t tag[4]; + uint32_t tag[AES_TAG_LEN / sizeof(uint32_t)]; uint16_t data_len; uint8_t ret; @@ -107,12 +108,12 @@ ccm_auth_crypt_get_result(const void *cdata, uint16_t cdata_len, /*---------------------------------------------------------------------------*/ uint8_t ccm_auth_encrypt_start(uint8_t len_len, uint8_t key_area, const void *nonce, - const void *adata, uint16_t adata_len, void *pdata, - uint16_t pdata_len, uint8_t mic_len, + const void *adata, uint16_t adata_len, const void *pdata, + uint16_t pdata_len, void *cdata, uint8_t mic_len, struct process *process) { return ccm_auth_crypt_start(true, len_len, key_area, nonce, adata, adata_len, - pdata, pdata_len, mic_len, process); + pdata, cdata, pdata_len, mic_len, process); } /*---------------------------------------------------------------------------*/ uint8_t @@ -123,14 +124,14 @@ ccm_auth_encrypt_get_result(void *mic, uint8_t mic_len) /*---------------------------------------------------------------------------*/ uint8_t ccm_auth_decrypt_start(uint8_t len_len, uint8_t key_area, const void *nonce, - const void *adata, uint16_t adata_len, void *cdata, - uint16_t cdata_len, uint8_t mic_len, + const void *adata, uint16_t adata_len, const void *cdata, + uint16_t cdata_len, void *pdata, uint8_t mic_len, struct process *process) { uint16_t data_len = cdata_len - mic_len; return ccm_auth_crypt_start(false, len_len, key_area, nonce, adata, adata_len, - cdata, data_len, mic_len, process); + cdata, pdata, data_len, mic_len, process); } /*---------------------------------------------------------------------------*/ uint8_t diff --git a/cpu/cc2538/dev/ccm.h b/cpu/cc2538/dev/ccm.h index 0a83c217f..8bb1f533b 100644 --- a/cpu/cc2538/dev/ccm.h +++ b/cpu/cc2538/dev/ccm.h @@ -54,26 +54,41 @@ #include #include /*---------------------------------------------------------------------------*/ +/** \name CCM constants + * @{ + */ +#define CCM_FLAGS_LEN 1 +#define CCM_NONCE_LEN_LEN (AES_IV_LEN - CCM_FLAGS_LEN) +#define CCM_MIC_MAX_LEN AES_TAG_LEN +/** @} */ +/*---------------------------------------------------------------------------*/ /** \name AES-CCM functions * @{ */ -/** \brief Starts the CCM authentication and encryption operation - * \param len_len Number of octets in length field (2, 4 or 8) - * \param key_area Area in Key RAM where the key is stored (0 to 7) - * \param nonce Pointer to nonce (15 - \p len_len octets) - * \param adata Pointer to additional authenticated data, or \c NULL +/** \brief Starts a CCM authentication and encryption operation + * \param len_len Number of octets in length field (2, 4, or 8) + * \param key_area Area in Key RAM where the key is stored (0 to + * \c AES_KEY_AREAS - 1) + * \param nonce Pointer to nonce (\c CCM_NONCE_LEN_LEN - \p len_len octets) + * \param adata Pointer to additional authenticated data in SRAM, or \c NULL * \param adata_len Length of additional authenticated data in octets, or \c 0 - * \param pdata Pointer to message to authenticate and encrypt, or \c NULL - * \param pdata_len Length of message to authenticate and encrypt in octets, or \c 0 - * \param mic_len Number of octets in authentication field (even value between 0 and 16) - * \param process Process to be polled upon completion of the operation, or \c NULL + * \param pdata Pointer to message to authenticate and encrypt in SRAM, or + * \c NULL + * \param pdata_len Length of message to authenticate and encrypt in octets, or + * \c 0 + * \param cdata Pointer to encrypted message in SRAM (may be \p pdata), or + * \c NULL + * \param mic_len Number of octets in authentication field (even value between 0 + * and \c CCM_MIC_MAX_LEN) + * \param process Process to be polled upon completion of the operation, or + * \c NULL * \return \c CRYPTO_SUCCESS if successful, or CRYPTO/AES/CCM error code */ uint8_t ccm_auth_encrypt_start(uint8_t len_len, uint8_t key_area, const void *nonce, const void *adata, - uint16_t adata_len, void *pdata, - uint16_t pdata_len, uint8_t mic_len, + uint16_t adata_len, const void *pdata, + uint16_t pdata_len, void *cdata, uint8_t mic_len, struct process *process); /** \brief Checks the status of the CCM authentication and encryption operation @@ -84,41 +99,50 @@ uint8_t ccm_auth_encrypt_start(uint8_t len_len, uint8_t key_area, /** \brief Gets the result of the CCM authentication and encryption operation * \param mic Pointer to authentication field, or \c NULL - * \param mic_len Number of octets in authentication field (even value between 0 and 16) + * \param mic_len Number of octets in authentication field (even value between 0 + * and \c CCM_MIC_MAX_LEN) * \return \c CRYPTO_SUCCESS if successful, or CRYPTO/AES/CCM error code * \note This function must be called only after \c ccm_auth_encrypt_start(). */ uint8_t ccm_auth_encrypt_get_result(void *mic, uint8_t mic_len); -/** \brief Starts the CCM authentication checking and decryption operation - * \param len_len Number of octets in length field (2, 4 or 8) - * \param key_area Area in Key RAM where the key is stored (0 to 7) - * \param nonce Pointer to nonce (15 - \p len_len octets) - * \param adata Pointer to additional authenticated data, or \c NULL +/** \brief Starts a CCM authentication checking and decryption operation + * \param len_len Number of octets in length field (2, 4, or 8) + * \param key_area Area in Key RAM where the key is stored (0 to + * \c AES_KEY_AREAS - 1) + * \param nonce Pointer to nonce (\c CCM_NONCE_LEN_LEN - \p len_len octets) + * \param adata Pointer to additional authenticated data in SRAM, or \c NULL * \param adata_len Length of additional authenticated data in octets, or \c 0 - * \param cdata Pointer to encrypted and authenticated message + * \param cdata Pointer to encrypted and authenticated message in SRAM * \param cdata_len Length of encrypted and authenticated message in octets - * \param mic_len Number of octets in authentication field (even value between 0 and 16) - * \param process Process to be polled upon completion of the operation, or \c NULL + * \param pdata Pointer to decrypted message in SRAM (may be \p cdata), or + * \c NULL + * \param mic_len Number of octets in authentication field (even value between 0 + * and \c CCM_MIC_MAX_LEN) + * \param process Process to be polled upon completion of the operation, or + * \c NULL * \return \c CRYPTO_SUCCESS if successful, or CRYPTO/AES/CCM error code */ uint8_t ccm_auth_decrypt_start(uint8_t len_len, uint8_t key_area, const void *nonce, const void *adata, - uint16_t adata_len, void *cdata, - uint16_t cdata_len, uint8_t mic_len, + uint16_t adata_len, const void *cdata, + uint16_t cdata_len, void *pdata, uint8_t mic_len, struct process *process); -/** \brief Checks the status of the CCM authentication checking and decryption operation +/** \brief Checks the status of the CCM authentication checking and decryption + * operation * \retval false Result not yet available, and no error occurred * \retval true Result available, or error occurred */ #define ccm_auth_decrypt_check_status aes_auth_crypt_check_status -/** \brief Gets the result of the CCM authentication checking and decryption operation +/** \brief Gets the result of the CCM authentication checking and decryption + * operation * \param cdata Pointer to encrypted and authenticated message * \param cdata_len Length of encrypted and authenticated message in octets * \param mic Pointer to authentication field, or \c NULL - * \param mic_len Number of octets in authentication field (even value between 0 and 16) + * \param mic_len Number of octets in authentication field (even value between 0 + * and \c CCM_MIC_MAX_LEN) * \return \c CRYPTO_SUCCESS if successful, or CRYPTO/AES/CCM error code * \note This function must be called only after \c ccm_auth_decrypt_start(). */ diff --git a/examples/cc2538dk/crypto/ccm-test.c b/examples/cc2538dk/crypto/ccm-test.c index 64c4fcf18..4b7287104 100644 --- a/examples/cc2538dk/crypto/ccm-test.c +++ b/examples/cc2538dk/crypto/ccm-test.c @@ -58,6 +58,11 @@ #include #include /*---------------------------------------------------------------------------*/ +#define NONCE_MAX_LEN 13 +#define ADATA_MAX_LEN 32 +#define MDATA_MAX_LEN 40 +#define MIC_MAX_LEN 16 +/*---------------------------------------------------------------------------*/ PROCESS(ccm_test_process, "ccm test process"); AUTOSTART_PROCESSES(&ccm_test_process); /*---------------------------------------------------------------------------*/ @@ -73,13 +78,13 @@ PROCESS_THREAD(ccm_test_process, ev, data) "keystore write error", "authentication failed" }; - static const uint8_t keys128[][16] = { + static const uint8_t keys128[][128 / 8] = { { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, { 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf } }; - static const uint8_t keys192[][24] = { + static const uint8_t keys192[][192 / 8] = { { 0x26, 0x51, 0x1f, 0xb5, 0x1f, 0xcf, 0xa7, 0x5c, 0xb4, 0xb4, 0x4d, 0xa7, 0x5a, 0x6e, 0x5a, 0x0e, 0xb8, 0xd9, 0xc8, 0xf3, 0xb9, 0x06, 0xf8, 0x86 }, @@ -93,7 +98,7 @@ PROCESS_THREAD(ccm_test_process, ev, data) 0x37, 0x34, 0x1f, 0xec, 0x49, 0x94, 0x7e, 0x8c, 0x70, 0x48, 0x24, 0x94, 0xa8, 0xf0, 0x7f, 0xcc } }; - static const uint8_t keys256[][32] = { + static const uint8_t keys256[][256 / 8] = { { 0x26, 0x51, 0x1f, 0xb5, 0x1f, 0xcf, 0xa7, 0x5c, 0xb4, 0xb4, 0x4d, 0xa7, 0x5a, 0x6e, 0x5a, 0x0e, 0xb8, 0xd9, 0xc8, 0xf3, 0xb9, 0x06, 0xf8, 0x86, @@ -123,19 +128,18 @@ PROCESS_THREAD(ccm_test_process, ev, data) { keys256, AES_KEY_STORE_SIZE_KEY_SIZE_256, sizeof(keys256) / sizeof(keys256[0]) } }; - static struct { + static const struct { bool encrypt; uint8_t len_len; uint8_t key_size_index; uint8_t key_area; - uint8_t nonce[13]; - uint8_t adata[32]; + uint8_t nonce[NONCE_MAX_LEN]; + uint8_t adata[ADATA_MAX_LEN]; uint16_t adata_len; - uint8_t mdata[40]; + uint8_t mdata[MDATA_MAX_LEN]; uint16_t mdata_len; - uint8_t mic[16]; uint8_t mic_len; - uint8_t expected[40]; + uint8_t expected[MDATA_MAX_LEN]; } vectors[] = { { true, /* encrypt */ @@ -150,7 +154,6 @@ PROCESS_THREAD(ccm_test_process, ev, data) 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, /* mdata */ 20, /* mdata_len */ - {}, /* mic */ 0, /* mic_len */ { 0x92, 0xe8, 0xad, 0xca, 0x53, 0x81, 0xbf, 0xd0, 0x5b, 0xdd, 0xf3, 0x61, 0x09, 0x09, 0x82, 0xe6, @@ -169,7 +172,6 @@ PROCESS_THREAD(ccm_test_process, ev, data) 26, /* adata_len */ {}, /* mdata */ 0, /* mdata_len */ - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* mic */ 8, /* mic_len */ { 0x22, 0x3b, 0xc1, 0xec, 0x84, 0x1a, 0xb5, 0x53 } /* expected */ }, { @@ -186,7 +188,6 @@ PROCESS_THREAD(ccm_test_process, ev, data) 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, /* mdata */ 20, /* mdata_len */ - { 0x00, 0x00, 0x00, 0x00 }, /* mic */ 4, /* mic_len */ { 0x92, 0xe8, 0xad, 0xca, 0x53, 0x81, 0xbf, 0xd0, 0x5b, 0xdd, 0xf3, 0x61, 0x09, 0x09, 0x82, 0xe6, @@ -204,7 +205,6 @@ PROCESS_THREAD(ccm_test_process, ev, data) 0x5b, 0xdd, 0xf3, 0x61, 0x09, 0x09, 0x82, 0xe6, 0x2c, 0x61, 0x01, 0x4e }, /* mdata */ 20, /* mdata_len */ - {}, /* mic */ 0, /* mic_len */ { 0x14, 0xaa, 0xbb, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, @@ -223,7 +223,6 @@ PROCESS_THREAD(ccm_test_process, ev, data) 26, /* adata_len */ { 0x22, 0x3b, 0xc1, 0xec, 0x84, 0x1a, 0xb5, 0x53 }, /* mdata */ 8, /* mdata_len */ - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* mic */ 8, /* mic_len */ {} /* expected */ }, { @@ -240,7 +239,6 @@ PROCESS_THREAD(ccm_test_process, ev, data) 0x5b, 0xdd, 0xf3, 0x61, 0x09, 0x09, 0x82, 0xe6, 0x2c, 0x61, 0x01, 0x4e, 0x7b, 0x34, 0x4f, 0x09 }, /* mdata */ 24, /* mdata_len */ - { 0x00, 0x00, 0x00, 0x00 }, /* mic */ 4, /* mic_len */ { 0x14, 0xaa, 0xbb, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, @@ -258,8 +256,6 @@ PROCESS_THREAD(ccm_test_process, ev, data) 0x12, 0x55, 0x06, 0x39, 0xb9, 0x1f, 0xb2, 0x57, 0x3e, 0x39, 0xa8, 0xeb, 0x5d, 0x80, 0x1d, 0xe8 }, /* mdata */ 24, /* mdata_len */ - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* mic */ 16, /* mic_len */ { 0x63, 0x42, 0xb8, 0x70, 0x0e, 0xde, 0xc9, 0x7a, 0x96, 0x0e, 0xb1, 0x6e, 0x7c, 0xb1, 0xeb, 0x44, @@ -280,8 +276,6 @@ PROCESS_THREAD(ccm_test_process, ev, data) 32, /* adata_len */ {}, /* mdata */ 0, /* mdata_len */ - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* mic */ 16, /* mic_len */ { 0x3b, 0xf9, 0xd9, 0x3a, 0xf6, 0xff, 0xac, 0x9a, 0xc8, 0x4c, 0xd3, 0x20, 0x2d, 0x4e, 0x0c, 0xc8 } /* expected */ @@ -300,8 +294,6 @@ PROCESS_THREAD(ccm_test_process, ev, data) 0xe6, 0x9c, 0x2a, 0x1f, 0x58, 0x93, 0x9d, 0xfe, 0x4d, 0x40, 0x37, 0x91, 0xb5, 0xdf, 0x13, 0x10 }, /* mdata */ 24, /* mdata_len */ - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* mic */ 16, /* mic_len */ { 0x8a, 0x0f, 0x3d, 0x82, 0x29, 0xe4, 0x8e, 0x74, 0x87, 0xfd, 0x95, 0xa2, 0x8a, 0xd3, 0x92, 0xc8, @@ -324,7 +316,6 @@ PROCESS_THREAD(ccm_test_process, ev, data) 0xe5, 0xd6, 0x25, 0x49, 0x59, 0xa1, 0x8a, 0xff, 0xc4, 0xfa, 0xf5, 0x9c, 0x8e, 0xf6, 0x34, 0x89 }, /* mdata */ 24, /* mdata_len */ - { 0x00, 0x00, 0x00, 0x00 }, /* mic */ 4, /* mic_len */ { 0x13, 0x7d, 0x9d, 0xa5, 0x9b, 0xaf, 0x5c, 0xbf, 0xd4, 0x66, 0x20, 0xc5, 0xf2, 0x98, 0xfc, 0x76, @@ -345,8 +336,6 @@ PROCESS_THREAD(ccm_test_process, ev, data) 0xb0, 0x90, 0x15, 0x5d, 0x34, 0xa7, 0x6c, 0x83, 0x24, 0xe5, 0x55, 0x0c, 0x3e, 0xf4, 0x26, 0xed }, /* mdata */ 40, /* mdata_len */ - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* mic */ 16, /* mic_len */ { 0x39, 0xf0, 0x8a, 0x2a, 0xf1, 0xd8, 0xda, 0x62, 0x12, 0x55, 0x06, 0x39, 0xb9, 0x1f, 0xb2, 0x57, @@ -366,8 +355,6 @@ PROCESS_THREAD(ccm_test_process, ev, data) { 0x3b, 0xf9, 0xd9, 0x3a, 0xf6, 0xff, 0xac, 0x9a, 0xc8, 0x4c, 0xd3, 0x20, 0x2d, 0x4e, 0x0c, 0xc8 }, /* mdata */ 16, /* mdata_len */ - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* mic */ 16, /* mic_len */ {} /* expected */ }, { @@ -387,8 +374,6 @@ PROCESS_THREAD(ccm_test_process, ev, data) 0x2d, 0xd6, 0xef, 0x1c, 0x45, 0xd4, 0xcc, 0xb7, 0x23, 0xdc, 0x07, 0x44, 0x14, 0xdb, 0x50, 0x6d }, /* mdata */ 40, /* mdata_len */ - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* mic */ 16, /* mic_len */ { 0xc8, 0xd2, 0x75, 0xf9, 0x19, 0xe1, 0x7d, 0x7f, 0xe6, 0x9c, 0x2a, 0x1f, 0x58, 0x93, 0x9d, 0xfe, @@ -410,7 +395,6 @@ PROCESS_THREAD(ccm_test_process, ev, data) 0x6d, 0xe1, 0x0a, 0xc6, 0x8e, 0x77, 0x4e, 0xdf, 0x1f, 0x2c, 0x5b, 0xad }, /* mdata */ 28, /* mdata_len */ - { 0x00, 0x00, 0x00, 0x00 }, /* mic */ 4, /* mic_len */ { 0xee, 0x7e, 0x60, 0x75, 0xba, 0x52, 0x84, 0x6d, 0xe5, 0xd6, 0x25, 0x49, 0x59, 0xa1, 0x8a, 0xff, @@ -428,8 +412,6 @@ PROCESS_THREAD(ccm_test_process, ev, data) 0xe7, 0x91, 0x11, 0x0f, 0xca, 0xea, 0x48, 0xe4, 0x1d, 0xb7, 0xc7, 0xf0, 0x98, 0xa8, 0x10, 0x00 }, /* mdata */ 24, /* mdata_len */ - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* mic */ 16, /* mic_len */ { 0x55, 0xf0, 0x68, 0xc0, 0xbb, 0xba, 0x8b, 0x59, 0x80, 0x13, 0xdd, 0x18, 0x41, 0xfd, 0x74, 0x0f, @@ -450,8 +432,6 @@ PROCESS_THREAD(ccm_test_process, ev, data) 32, /* adata_len */ {}, /* mdata */ 0, /* mdata_len */ - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* mic */ 16, /* mic_len */ { 0xca, 0x48, 0x2c, 0x67, 0x4b, 0x59, 0x90, 0x46, 0xcc, 0x7d, 0x7e, 0xe0, 0xd0, 0x0e, 0xec, 0x1e } /* expected */ @@ -470,8 +450,6 @@ PROCESS_THREAD(ccm_test_process, ev, data) 0x7b, 0x5e, 0x01, 0x5e, 0xea, 0x14, 0x1c, 0xa1, 0xa8, 0x80, 0x20, 0xf2, 0xd5, 0xd6, 0xcc, 0x2c }, /* mdata */ 24, /* mdata_len */ - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* mic */ 16, /* mic_len */ { 0x27, 0xed, 0x90, 0x66, 0x81, 0x74, 0xeb, 0xf8, 0x24, 0x1a, 0x3c, 0x74, 0xb3, 0x5e, 0x12, 0x46, @@ -494,7 +472,6 @@ PROCESS_THREAD(ccm_test_process, ev, data) 0x7e, 0xdb, 0xb6, 0x7f, 0x8a, 0xe4, 0x56, 0xb4, 0xea, 0x06, 0x6a, 0x4b, 0xee, 0xe0, 0x65, 0xf9 }, /* mdata */ 24, /* mdata_len */ - { 0x00, 0x00, 0x00, 0x00 }, /* mic */ 4, /* mic_len */ { 0x9c, 0x8d, 0x5d, 0xd2, 0x27, 0xfd, 0x9f, 0x81, 0x23, 0x76, 0x01, 0x83, 0x0a, 0xfe, 0xe4, 0xf0, @@ -515,8 +492,6 @@ PROCESS_THREAD(ccm_test_process, ev, data) 0x93, 0x57, 0x53, 0xe6, 0x01, 0xb7, 0x9d, 0xb4, 0xae, 0x73, 0x0b, 0x6a, 0xe3, 0x50, 0x07, 0x31 }, /* mdata */ 40, /* mdata_len */ - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* mic */ 16, /* mic_len */ { 0x30, 0xd5, 0x6f, 0xf2, 0xa2, 0x5b, 0x83, 0xfe, 0xe7, 0x91, 0x11, 0x0f, 0xca, 0xea, 0x48, 0xe4, @@ -536,8 +511,6 @@ PROCESS_THREAD(ccm_test_process, ev, data) { 0xca, 0x48, 0x2c, 0x67, 0x4b, 0x59, 0x90, 0x46, 0xcc, 0x7d, 0x7e, 0xe0, 0xd0, 0x0e, 0xec, 0x1e }, /* mdata */ 16, /* mdata_len */ - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* mic */ 16, /* mic_len */ {} /* expected */ }, { @@ -557,8 +530,6 @@ PROCESS_THREAD(ccm_test_process, ev, data) 0x3b, 0xdb, 0x67, 0x06, 0x2a, 0x13, 0xef, 0x4e, 0x98, 0x6f, 0x5b, 0xb3, 0xd0, 0xbb, 0x43, 0x07 }, /* mdata */ 40, /* mdata_len */ - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* mic */ 16, /* mic_len */ { 0x64, 0x4e, 0xb3, 0x4b, 0x9a, 0x12, 0x6e, 0x43, 0x7b, 0x5e, 0x01, 0x5e, 0xea, 0x14, 0x1c, 0xa1, @@ -580,13 +551,15 @@ PROCESS_THREAD(ccm_test_process, ev, data) 0x11, 0x56, 0x36, 0xc8, 0xe5, 0xd5, 0xfd, 0x74, 0x3c, 0xb9, 0xaf, 0xed }, /* mdata */ 28, /* mdata_len */ - { 0x00, 0x00, 0x00, 0x00 }, /* mic */ 4, /* mic_len */ { 0x23, 0x90, 0x29, 0xf1, 0x50, 0xbc, 0xcb, 0xd6, 0x7e, 0xdb, 0xb6, 0x7f, 0x8a, 0xe4, 0x56, 0xb4, 0xea, 0x06, 0x6a, 0x4b, 0xee, 0xe0, 0x65, 0xf9 } /* expected */ } }; + static uint8_t adata[ADATA_MAX_LEN]; + static uint8_t mdata[MDATA_MAX_LEN]; + static uint8_t mic[MIC_MAX_LEN]; static int i; static uint8_t key_size_index = -1, ret; static rtimer_clock_t time, time2, total_time; @@ -622,13 +595,17 @@ PROCESS_THREAD(ccm_test_process, ev, data) vectors[i].len_len, vectors[i].key_area, vectors[i].adata_len, vectors[i].mdata_len, vectors[i].mic_len); + /* adata and mdata have to be in SRAM. */ + rom_util_memcpy(adata, vectors[i].adata, vectors[i].adata_len); + rom_util_memcpy(mdata, vectors[i].mdata, vectors[i].mdata_len); + time = RTIMER_NOW(); if(vectors[i].encrypt) { ret = ccm_auth_encrypt_start(vectors[i].len_len, vectors[i].key_area, - vectors[i].nonce, vectors[i].adata, - vectors[i].adata_len, vectors[i].mdata, - vectors[i].mdata_len, vectors[i].mic_len, - &ccm_test_process); + vectors[i].nonce, adata, + vectors[i].adata_len, mdata, + vectors[i].mdata_len, mdata, + vectors[i].mic_len, &ccm_test_process); time2 = RTIMER_NOW(); time = time2 - time; total_time = time; @@ -647,7 +624,7 @@ PROCESS_THREAD(ccm_test_process, ev, data) (uint32_t)((uint64_t)time2 * 1000000 / RTIMER_SECOND)); time = RTIMER_NOW(); - ret = ccm_auth_encrypt_get_result(vectors[i].mic, vectors[i].mic_len); + ret = ccm_auth_encrypt_get_result(mic, vectors[i].mic_len); time = RTIMER_NOW() - time; total_time += time; printf("ccm_auth_encrypt_get_result(): %s, %lu us\n", str_res[ret], @@ -657,15 +634,13 @@ PROCESS_THREAD(ccm_test_process, ev, data) continue; } - if(rom_util_memcmp(vectors[i].mdata, vectors[i].expected, - vectors[i].mdata_len)) { + if(rom_util_memcmp(mdata, vectors[i].expected, vectors[i].mdata_len)) { puts("Encrypted message does not match expected one"); } else { puts("Encrypted message OK"); } - if(rom_util_memcmp(vectors[i].mic, - vectors[i].expected + vectors[i].mdata_len, + if(rom_util_memcmp(mic, vectors[i].expected + vectors[i].mdata_len, vectors[i].mic_len)) { puts("MIC does not match expected one"); } else { @@ -673,10 +648,10 @@ PROCESS_THREAD(ccm_test_process, ev, data) } } else { ret = ccm_auth_decrypt_start(vectors[i].len_len, vectors[i].key_area, - vectors[i].nonce, vectors[i].adata, - vectors[i].adata_len, vectors[i].mdata, - vectors[i].mdata_len, vectors[i].mic_len, - &ccm_test_process); + vectors[i].nonce, adata, + vectors[i].adata_len, mdata, + vectors[i].mdata_len, mdata, + vectors[i].mic_len, &ccm_test_process); time2 = RTIMER_NOW(); time = time2 - time; total_time = time; @@ -695,8 +670,8 @@ PROCESS_THREAD(ccm_test_process, ev, data) (uint32_t)((uint64_t)time2 * 1000000 / RTIMER_SECOND)); time = RTIMER_NOW(); - ret = ccm_auth_decrypt_get_result(vectors[i].mdata, vectors[i].mdata_len, - vectors[i].mic, vectors[i].mic_len); + ret = ccm_auth_decrypt_get_result(mdata, vectors[i].mdata_len, + mic, vectors[i].mic_len); time = RTIMER_NOW() - time; total_time += time; printf("ccm_auth_decrypt_get_result(): %s, %lu us\n", str_res[ret], @@ -706,7 +681,7 @@ PROCESS_THREAD(ccm_test_process, ev, data) continue; } - if(rom_util_memcmp(vectors[i].mdata, vectors[i].expected, + if(rom_util_memcmp(mdata, vectors[i].expected, vectors[i].mdata_len - vectors[i].mic_len)) { puts("Decrypted message does not match expected one"); } else {