Merge pull request #1443 from bthebaudeau/cc2538-new-aes-modes

cc2538: Complete support of hardware AES modes of operation
This commit is contained in:
Benoît Thébaudeau 2016-01-07 23:27:06 +01:00
commit 0eab95ec4c
17 changed files with 3007 additions and 5 deletions

View file

@ -53,7 +53,8 @@ CONTIKI_CPU_DIRS += ../cc253x/usb/common ../cc253x/usb/common/cdc-acm
### CPU-dependent source files
CONTIKI_CPU_SOURCEFILES += clock.c rtimer-arch.c uart.c watchdog.c
CONTIKI_CPU_SOURCEFILES += nvic.c cpu.c sys-ctrl.c gpio.c ioc.c spi.c adc.c
CONTIKI_CPU_SOURCEFILES += crypto.c aes.c ecb.c ccm.c sha256.c
CONTIKI_CPU_SOURCEFILES += crypto.c aes.c ecb.c cbc.c ctr.c cbc-mac.c gcm.c
CONTIKI_CPU_SOURCEFILES += ccm.c sha256.c
CONTIKI_CPU_SOURCEFILES += cc2538-aes-128.c cc2538-ccm-star.c
CONTIKI_CPU_SOURCEFILES += cc2538-rf.c udma.c lpm.c
CONTIKI_CPU_SOURCEFILES += pka.c bignum-driver.c ecc-driver.c ecc-algorithm.c

91
cpu/cc2538/dev/cbc-mac.c Normal file
View file

@ -0,0 +1,91 @@
/*
* Copyright (c) 2016, Benoît Thébaudeau <benoit.thebaudeau.dev@gmail.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* \addtogroup cc2538-cbc-mac
* @{
*
* \file
* Implementation of the cc2538 AES-CBC-MAC driver
*/
#include "contiki.h"
#include "dev/rom-util.h"
#include "dev/cbc-mac.h"
#include <stdbool.h>
#include <stdint.h>
/*---------------------------------------------------------------------------*/
uint8_t
cbc_mac_auth_start(uint8_t key_area, const void *mdata, uint16_t mdata_len,
struct process *process)
{
uint32_t ctrl;
uint32_t iv[AES_IV_LEN / sizeof(uint32_t)];
/* Program AES-CBC-MAC authentication operation */
ctrl = AES_AES_CTRL_SAVE_CONTEXT | /* Save context */
AES_AES_CTRL_CBC_MAC | /* CBC-MAC */
AES_AES_CTRL_DIRECTION_ENCRYPT; /* Encryption */
/* Prepare the crypto initialization vector
* Set initialization vector to 0 */
rom_util_memset(iv, 0, AES_IV_LEN);
return aes_auth_crypt_start(ctrl, key_area, iv, NULL, 0,
mdata, NULL, mdata_len, process);
}
/*---------------------------------------------------------------------------*/
uint8_t
cbc_mac_auth_get_result(const void *mac_in, void *mac_out)
{
uint32_t tag[AES_TAG_LEN / sizeof(uint32_t)];
uint8_t ret;
ret = aes_auth_crypt_get_result(NULL, tag);
if(ret != CRYPTO_SUCCESS) {
return ret;
}
if(mac_in != NULL) {
/* Check MAC */
if(rom_util_memcmp(tag, mac_in, CBC_MAC_MAC_LEN)) {
ret = AES_AUTHENTICATION_FAILED;
}
}
if(mac_out != NULL) {
/* Copy tag to MAC */
rom_util_memcpy(mac_out, tag, CBC_MAC_MAC_LEN);
}
return ret;
}
/** @} */

98
cpu/cc2538/dev/cbc-mac.h Normal file
View file

@ -0,0 +1,98 @@
/*
* Copyright (c) 2016, Benoît Thébaudeau <benoit.thebaudeau.dev@gmail.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* \addtogroup cc2538-aes
* @{
*
* \defgroup cc2538-cbc-mac cc2538 AES-CBC-MAC
*
* Driver for the cc2538 AES-CBC-MAC mode of the security core
* @{
*
* \file
* Header file for the cc2538 AES-CBC-MAC driver
*/
#ifndef CBC_MAC_H_
#define CBC_MAC_H_
#include "contiki.h"
#include "dev/aes.h"
#include <stdbool.h>
#include <stdint.h>
/*---------------------------------------------------------------------------*/
/** \name AES-CBC-MAC constants
* @{
*/
#define CBC_MAC_MAC_LEN AES_TAG_LEN
/** @} */
/*---------------------------------------------------------------------------*/
/** \name AES-CBC-MAC functions
* @{
*/
/** \brief Starts a CBC-MAC authentication operation
* \param key_area Area in Key RAM where the key is stored (0 to
* \c AES_KEY_AREAS - 1)
* \param mdata Pointer to message to authenticate in SRAM
* \param mdata_len Length of message to authenticate in octets
* \param process Process to be polled upon completion of the operation, or
* \c NULL
* \return \c CRYPTO_SUCCESS if successful, or CRYPTO/AES/CBC-MAC error code
* \warning CBC-MAC is not secure for variable-length messages. There are a few
* workarounds that can be implemented by the caller, like prepending the
* message length to the first block of the message before passing it.
*/
uint8_t cbc_mac_auth_start(uint8_t key_area, const void *mdata,
uint16_t mdata_len, struct process *process);
/** \brief Checks the status of the CBC-MAC authentication operation
* \retval false Result not yet available, and no error occurred
* \retval true Result available, or error occurred
*/
#define cbc_mac_auth_check_status aes_auth_crypt_check_status
/** \brief Gets the result of the CBC-MAC authentication operation
* \param mac_in Pointer to 128-bit input MAC, or \c NULL
* \param mac_out Pointer to 128-bit output MAC, or \c NULL
* \return \c CRYPTO_SUCCESS if successful, or CRYPTO/AES/CBC-MAC error code
* \note This function must be called only after \c cbc_mac_auth_start().
*/
uint8_t cbc_mac_auth_get_result(const void *mac_in, void *mac_out);
/** @} */
#endif /* CBC_MAC_H_ */
/**
* @}
* @}
*/

66
cpu/cc2538/dev/cbc.c Normal file
View file

@ -0,0 +1,66 @@
/*
* Copyright (c) 2015, Benoît Thébaudeau <benoit.thebaudeau.dev@gmail.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* \addtogroup cc2538-cbc
* @{
*
* \file
* Implementation of the cc2538 AES-CBC driver
*/
#include "contiki.h"
#include "dev/cbc.h"
#include <stdbool.h>
#include <stdint.h>
/*---------------------------------------------------------------------------*/
uint8_t
cbc_crypt_start(uint8_t encrypt, uint8_t key_area, const void *iv,
const void *mdata_in, void *mdata_out, uint16_t mdata_len,
struct process *process)
{
uint32_t ctrl;
/* Program AES-CBC crypto operation */
ctrl = AES_AES_CTRL_CBC | /* CBC */
(encrypt ? AES_AES_CTRL_DIRECTION_ENCRYPT : 0); /* En/decryption */
return aes_auth_crypt_start(ctrl, key_area, iv, NULL, 0,
mdata_in, mdata_out, mdata_len, process);
}
/*---------------------------------------------------------------------------*/
int8_t
cbc_crypt_check_status(void)
{
return aes_auth_crypt_check_status() ? aes_auth_crypt_get_result(NULL, NULL) :
CRYPTO_PENDING;
}
/** @} */

92
cpu/cc2538/dev/cbc.h Normal file
View file

@ -0,0 +1,92 @@
/*
* Copyright (c) 2015, Benoît Thébaudeau <benoit.thebaudeau.dev@gmail.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* \addtogroup cc2538-aes
* @{
*
* \defgroup cc2538-cbc cc2538 AES-CBC
*
* Driver for the cc2538 AES-CBC mode of the security core
* @{
*
* \file
* Header file for the cc2538 AES-CBC driver
*/
#ifndef CBC_H_
#define CBC_H_
#include "contiki.h"
#include "dev/aes.h"
#include <stdbool.h>
#include <stdint.h>
/*---------------------------------------------------------------------------*/
/** \name AES-CBC constants
* @{
*/
#define CBC_IV_LEN AES_IV_LEN
/** @} */
/*---------------------------------------------------------------------------*/
/** \name AES-CBC functions
* @{
*/
/** \brief Starts a CBC crypto operation
* \param encrypt \c true to encrypt, or \c false to decrypt
* \param key_area Area in Key RAM where the key is stored (0 to
* \c AES_KEY_AREAS - 1)
* \param iv Pointer to 128-bit initialization vector
* \param mdata_in Pointer to input message in SRAM
* \param mdata_out Pointer to output message in SRAM (may be \p mdata_in)
* \param mdata_len Length of message in octets
* \param process Process to be polled upon completion of the operation, or
* \c NULL
* \return \c CRYPTO_SUCCESS if successful, or CRYPTO/AES/CBC error code
*/
uint8_t cbc_crypt_start(uint8_t encrypt, uint8_t key_area, const void *iv,
const void *mdata_in, void *mdata_out,
uint16_t mdata_len, struct process *process);
/** \brief Checks the status of the CBC crypto operation
* \return \c CRYPTO_PENDING if operation still pending, \c CRYPTO_SUCCESS if
* successful, or CRYPTO/AES/CBC error code
* \note This function must be called only after \c cbc_crypt_start().
*/
int8_t cbc_crypt_check_status(void);
/** @} */
#endif /* CBC_H_ */
/**
* @}
* @}
*/

View file

@ -54,7 +54,7 @@
#include <stdbool.h>
#include <stdint.h>
/*---------------------------------------------------------------------------*/
/** \name CCM constants
/** \name AES-CCM constants
* @{
*/
#define CCM_FLAGS_LEN 1

77
cpu/cc2538/dev/ctr.c Normal file
View file

@ -0,0 +1,77 @@
/*
* Copyright (c) 2015, Benoît Thébaudeau <benoit.thebaudeau.dev@gmail.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* \addtogroup cc2538-ctr
* @{
*
* \file
* Implementation of the cc2538 AES-CTR driver
*/
#include "contiki.h"
#include "dev/rom-util.h"
#include "dev/ctr.h"
#include <stdbool.h>
#include <stdint.h>
/*---------------------------------------------------------------------------*/
uint8_t
ctr_crypt_start(uint8_t encrypt, uint8_t key_area, const void *nonce,
const void *ictr, uint8_t ctr_len, const void *mdata_in,
void *mdata_out, uint16_t mdata_len, struct process *process)
{
uint32_t ctrl;
uint32_t iv[AES_IV_LEN / sizeof(uint32_t)];
uint8_t nonce_len;
/* Program AES-CTR crypto operation */
ctrl = (((ctr_len >> 2) - 1) << AES_AES_CTRL_CTR_WIDTH_S) | /* CTR width */
AES_AES_CTRL_CTR | /* CTR */
(encrypt ? AES_AES_CTRL_DIRECTION_ENCRYPT : 0); /* En/decryption */
/* Prepare the crypto initialization vector */
nonce_len = AES_IV_LEN - ctr_len;
/* Nonce */
rom_util_memcpy(&((uint8_t *)iv)[0], nonce, nonce_len);
/* Initial counter */
rom_util_memcpy(&((uint8_t *)iv)[nonce_len], ictr, ctr_len);
return aes_auth_crypt_start(ctrl, key_area, iv, NULL, 0,
mdata_in, mdata_out, mdata_len, process);
}
/*---------------------------------------------------------------------------*/
int8_t
ctr_crypt_check_status(void)
{
return aes_auth_crypt_check_status() ? aes_auth_crypt_get_result(NULL, NULL) :
CRYPTO_PENDING;
}
/** @} */

89
cpu/cc2538/dev/ctr.h Normal file
View file

@ -0,0 +1,89 @@
/*
* Copyright (c) 2015, Benoît Thébaudeau <benoit.thebaudeau.dev@gmail.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* \addtogroup cc2538-aes
* @{
*
* \defgroup cc2538-ctr cc2538 AES-CTR
*
* Driver for the cc2538 AES-CTR mode of the security core
* @{
*
* \file
* Header file for the cc2538 AES-CTR driver
*/
#ifndef CTR_H_
#define CTR_H_
#include "contiki.h"
#include "dev/aes.h"
#include <stdbool.h>
#include <stdint.h>
/*---------------------------------------------------------------------------*/
/** \name AES-CTR functions
* @{
*/
/** \brief Starts a CTR crypto operation
* \param encrypt \c true to encrypt, or \c false to decrypt
* \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 AES_IV_LEN - \p ctr_len octets), or \c NULL
* \param ictr Pointer to initial counter
* \param ctr_len Length of counter in octets (4, 8, 12, or 16)
* \param mdata_in Pointer to input message in SRAM
* \param mdata_out Pointer to output message in SRAM (may be \p mdata_in)
* \param mdata_len Length of message in octets
* \param process Process to be polled upon completion of the operation, or
* \c NULL
* \return \c CRYPTO_SUCCESS if successful, or CRYPTO/AES/CTR error code
*/
uint8_t ctr_crypt_start(uint8_t encrypt, uint8_t key_area, const void *nonce,
const void *ictr, uint8_t ctr_len, const void *mdata_in,
void *mdata_out, uint16_t mdata_len,
struct process *process);
/** \brief Checks the status of the CTR crypto operation
* \return \c CRYPTO_PENDING if operation still pending, \c CRYPTO_SUCCESS if
* successful, or CRYPTO/AES/CTR error code
* \note This function must be called only after \c ctr_crypt_start().
*/
int8_t ctr_crypt_check_status(void);
/** @} */
#endif /* CTR_H_ */
/**
* @}
* @}
*/

125
cpu/cc2538/dev/gcm.c Normal file
View file

@ -0,0 +1,125 @@
/*
* Copyright (c) 2015, Benoît Thébaudeau <benoit.thebaudeau.dev@gmail.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* \addtogroup cc2538-gcm
* @{
*
* \file
* Implementation of the cc2538 AES-GCM driver
*/
#include "contiki.h"
#include "dev/rom-util.h"
#include "dev/gcm.h"
#include <stdbool.h>
#include <stdint.h>
/*---------------------------------------------------------------------------*/
static uint8_t
gcm_auth_crypt_start(uint8_t encrypt, uint8_t key_area, const void *iv,
const void *adata, uint16_t adata_len,
const void *data_in, void *data_out, uint16_t data_len,
struct process *process)
{
uint32_t ctrl;
uint32_t aes_iv[AES_IV_LEN / sizeof(uint32_t)];
/* Program AES-GCM authentication/crypto operation */
ctrl = AES_AES_CTRL_SAVE_CONTEXT | /* Save context */
AES_AES_CTRL_GCM | /* GCM */
AES_AES_CTRL_CTR_WIDTH_32 | /* CTR width 32 */
AES_AES_CTRL_CTR | /* CTR */
(encrypt ? AES_AES_CTRL_DIRECTION_ENCRYPT : 0); /* En/decryption */
/* Prepare the crypto initialization vector
* Initialization vector */
rom_util_memcpy(aes_iv, iv, GCM_IV_LEN);
/* Initialize counter to 1 */
aes_iv[GCM_IV_LEN / sizeof(aes_iv[0])] = 0x01000000;
return aes_auth_crypt_start(ctrl, key_area, aes_iv, adata, adata_len,
data_in, data_out, data_len, process);
}
/*---------------------------------------------------------------------------*/
static uint8_t
gcm_auth_crypt_get_result(const void *tag_in, void *tag_out)
{
uint32_t tag[AES_TAG_LEN / sizeof(uint32_t)];
uint8_t ret;
ret = aes_auth_crypt_get_result(NULL, tag);
if(ret != CRYPTO_SUCCESS) {
return ret;
}
if(tag_in != NULL) {
/* Check tag */
if(rom_util_memcmp(tag, tag_in, GCM_TAG_LEN)) {
ret = AES_AUTHENTICATION_FAILED;
}
}
if(tag_out != NULL) {
/* Copy tag */
rom_util_memcpy(tag_out, tag, GCM_TAG_LEN);
}
return ret;
}
/*---------------------------------------------------------------------------*/
uint8_t
gcm_auth_encrypt_start(uint8_t key_area, const void *iv, const void *adata,
uint16_t adata_len, const void *pdata,
uint16_t pdata_len, void *cdata, struct process *process)
{
return gcm_auth_crypt_start(true, key_area, iv, adata, adata_len,
pdata, cdata, pdata_len, process);
}
/*---------------------------------------------------------------------------*/
uint8_t
gcm_auth_encrypt_get_result(void *tag)
{
return gcm_auth_crypt_get_result(NULL, tag);
}
/*---------------------------------------------------------------------------*/
uint8_t
gcm_auth_decrypt_start(uint8_t key_area, const void *iv, const void *adata,
uint16_t adata_len, const void *cdata,
uint16_t cdata_len, void *pdata, struct process *process)
{
return gcm_auth_crypt_start(false, key_area, iv, adata, adata_len,
cdata, pdata, cdata_len, process);
}
/*---------------------------------------------------------------------------*/
uint8_t
gcm_auth_decrypt_get_result(const void *tag_in, void *tag_out)
__attribute__ ((alias("gcm_auth_crypt_get_result")));
/** @} */

139
cpu/cc2538/dev/gcm.h Normal file
View file

@ -0,0 +1,139 @@
/*
* Copyright (c) 2015, Benoît Thébaudeau <benoit.thebaudeau.dev@gmail.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* \addtogroup cc2538-aes
* @{
*
* \defgroup cc2538-gcm cc2538 AES-GCM
*
* Driver for the cc2538 AES-GCM mode of the security core
* @{
*
* \file
* Header file for the cc2538 AES-GCM driver
*/
#ifndef GCM_H_
#define GCM_H_
#include "contiki.h"
#include "dev/aes.h"
#include <stdbool.h>
#include <stdint.h>
/*---------------------------------------------------------------------------*/
/** \name AES-GCM constants
* @{
*/
#define GCM_IV_LEN (96 / 8)
#define GCM_TAG_LEN AES_TAG_LEN
/** @} */
/*---------------------------------------------------------------------------*/
/** \name AES-GCM functions
* @{
*/
/** \brief Starts a GCM authentication and encryption operation
* \param key_area Area in Key RAM where the key is stored (0 to
* \c AES_KEY_AREAS - 1)
* \param iv Pointer to 96-bit initialization vector
* \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 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 process Process to be polled upon completion of the operation, or
* \c NULL
* \return \c CRYPTO_SUCCESS if successful, or CRYPTO/AES/GCM error code
*/
uint8_t gcm_auth_encrypt_start(uint8_t key_area, const void *iv,
const void *adata, uint16_t adata_len,
const void *pdata, uint16_t pdata_len,
void *cdata, struct process *process);
/** \brief Checks the status of the GCM authentication and encryption operation
* \retval false Result not yet available, and no error occurred
* \retval true Result available, or error occurred
*/
#define gcm_auth_encrypt_check_status aes_auth_crypt_check_status
/** \brief Gets the result of the GCM authentication and encryption operation
* \param tag Pointer to 128-bit authentication tag, or \c NULL
* \return \c CRYPTO_SUCCESS if successful, or CRYPTO/AES/GCM error code
* \note This function must be called only after \c gcm_auth_encrypt_start().
*/
uint8_t gcm_auth_encrypt_get_result(void *tag);
/** \brief Starts a GCM authentication checking and decryption operation
* \param key_area Area in Key RAM where the key is stored (0 to
* \c AES_KEY_AREAS - 1)
* \param iv Pointer to 96-bit initialization vector
* \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 message in SRAM, or \c NULL
* \param cdata_len Length of encrypted message in octets, or \c 0
* \param pdata Pointer to decrypted message in SRAM (may be \p cdata), or
* \c NULL
* \param process Process to be polled upon completion of the operation, or
* \c NULL
* \return \c CRYPTO_SUCCESS if successful, or CRYPTO/AES/GCM error code
*/
uint8_t gcm_auth_decrypt_start(uint8_t key_area, const void *iv,
const void *adata, uint16_t adata_len,
const void *cdata, uint16_t cdata_len,
void *pdata, struct process *process);
/** \brief Checks the status of the GCM authentication checking and decryption
* operation
* \retval false Result not yet available, and no error occurred
* \retval true Result available, or error occurred
*/
#define gcm_auth_decrypt_check_status aes_auth_crypt_check_status
/** \brief Gets the result of the GCM authentication checking and decryption
* operation
* \param tag_in Pointer to 128-bit input authentication tag, or \c NULL
* \param tag_out Pointer to 128-bit output authentication tag, or \c NULL
* \return \c CRYPTO_SUCCESS if successful, or CRYPTO/AES/GCM error code
* \note This function must be called only after \c gcm_auth_decrypt_start().
*/
uint8_t gcm_auth_decrypt_get_result(const void *tag_in, void *tag_out);
/** @} */
#endif /* GCM_H_ */
/**
* @}
* @}
*/

View file

@ -1,4 +1,5 @@
CONTIKI_PROJECT = ecb-test ccm-test sha256-test
CONTIKI_PROJECT = ecb-test cbc-test ctr-test cbc-mac-test gcm-test ccm-test
CONTIKI_PROJECT += sha256-test
all: $(CONTIKI_PROJECT)

View file

@ -0,0 +1,506 @@
/*
* Copyright (c) 2016, Benoît Thébaudeau <benoit.thebaudeau.dev@gmail.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* \addtogroup cc2538-examples
* @{
*
* \defgroup cc2538-cbc-mac-test cc2538dk AES-CBC-MAC Test Project
*
* AES-CBC-MAC access example for CC2538 on SmartRF06EB.
*
* This example shows how AES-CBC-MAC should be used. The example also
* verifies the AES-CBC-MAC functionality.
*
* @{
*
* \file
* Example demonstrating AES-CBC-MAC on the cc2538dk platform
*/
#include "contiki.h"
#include "sys/rtimer.h"
#include "dev/rom-util.h"
#include "dev/cbc-mac.h"
#include <stdbool.h>
#include <stdio.h>
#include <stdint.h>
/*---------------------------------------------------------------------------*/
#define MDATA_MAX_LEN 160
/*---------------------------------------------------------------------------*/
PROCESS(cbc_mac_test_process, "cbc_mac test process");
AUTOSTART_PROCESSES(&cbc_mac_test_process);
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(cbc_mac_test_process, ev, data)
{
static const char *const str_res[] = {
"success",
"invalid param",
"NULL error",
"resource in use",
"DMA bus error",
"keystore read error",
"keystore write error",
"authentication failed"
};
static const uint8_t keys128[][128 / 8] = {
{ 0x1f, 0x8e, 0x49, 0x73, 0x95, 0x3f, 0x3f, 0xb0,
0xbd, 0x6b, 0x16, 0x66, 0x2e, 0x9a, 0x3c, 0x17 },
{ 0xb7, 0xf3, 0xc9, 0x57, 0x6e, 0x12, 0xdd, 0x0d,
0xb6, 0x3e, 0x8f, 0x8f, 0xac, 0x2b, 0x9a, 0x39 },
{ 0x89, 0xa5, 0x53, 0x73, 0x04, 0x33, 0xf7, 0xe6,
0xd6, 0x7d, 0x16, 0xd3, 0x73, 0xbd, 0x53, 0x60 },
{ 0x2c, 0x14, 0x41, 0x37, 0x51, 0xc3, 0x1e, 0x27,
0x30, 0x57, 0x0b, 0xa3, 0x36, 0x1c, 0x78, 0x6b },
{ 0x6a, 0x70, 0x82, 0xcf, 0x8c, 0xda, 0x13, 0xef,
0xf4, 0x8c, 0x81, 0x58, 0xdd, 0xa2, 0x06, 0xae },
{ 0x7b, 0x1a, 0xb9, 0x14, 0x4b, 0x02, 0x39, 0x31,
0x5c, 0xd5, 0xee, 0xc6, 0xc7, 0x56, 0x63, 0xbd },
{ 0xba, 0xb0, 0xcc, 0xed, 0xdc, 0x0a, 0xbd, 0x63,
0xe3, 0xf8, 0x2e, 0x9f, 0xbf, 0xf7, 0xb8, 0xaa },
{ 0x97, 0xa1, 0x02, 0x55, 0x29, 0xb9, 0x92, 0x5e,
0x25, 0xbb, 0xe7, 0x87, 0x70, 0xca, 0x2f, 0x99 }
};
static const uint8_t keys192[][192 / 8] = {
{ 0xba, 0x75, 0xf4, 0xd1, 0xd9, 0xd7, 0xcf, 0x7f,
0x55, 0x14, 0x45, 0xd5, 0x6c, 0xc1, 0xa8, 0xab,
0x2a, 0x07, 0x8e, 0x15, 0xe0, 0x49, 0xdc, 0x2c },
{ 0x16, 0x2a, 0xd5, 0x0e, 0xe6, 0x4a, 0x07, 0x02,
0xaa, 0x55, 0x1f, 0x57, 0x1d, 0xed, 0xc1, 0x6b,
0x2c, 0x1b, 0x6a, 0x1e, 0x4d, 0x4b, 0x5e, 0xee },
{ 0x8e, 0x27, 0x40, 0xfb, 0xa1, 0x57, 0xae, 0xf2,
0x42, 0x2e, 0x44, 0x23, 0x12, 0xd1, 0x5c, 0x14,
0xd3, 0x12, 0x55, 0x36, 0x84, 0xfc, 0xdc, 0x15 },
{ 0x50, 0x9b, 0xaf, 0x46, 0xfb, 0x9d, 0xe3, 0x42,
0x81, 0xda, 0xfc, 0xc3, 0xdb, 0x79, 0x59, 0x3b,
0xff, 0xa8, 0x42, 0x69, 0x04, 0x30, 0x26, 0x88 }
};
static const uint8_t keys256[][256 / 8] = {
{ 0x6e, 0xd7, 0x6d, 0x2d, 0x97, 0xc6, 0x9f, 0xd1,
0x33, 0x95, 0x89, 0x52, 0x39, 0x31, 0xf2, 0xa6,
0xcf, 0xf5, 0x54, 0xb1, 0x5f, 0x73, 0x8f, 0x21,
0xec, 0x72, 0xdd, 0x97, 0xa7, 0x33, 0x09, 0x07 },
{ 0x48, 0xbe, 0x59, 0x7e, 0x63, 0x2c, 0x16, 0x77,
0x23, 0x24, 0xc8, 0xd3, 0xfa, 0x1d, 0x9c, 0x5a,
0x9e, 0xcd, 0x01, 0x0f, 0x14, 0xec, 0x5d, 0x11,
0x0d, 0x3b, 0xfe, 0xc3, 0x76, 0xc5, 0x53, 0x2b },
{ 0x43, 0xe9, 0x53, 0xb2, 0xae, 0xa0, 0x8a, 0x3a,
0xd5, 0x2d, 0x18, 0x2f, 0x58, 0xc7, 0x2b, 0x9c,
0x60, 0xfb, 0xe4, 0xa9, 0xca, 0x46, 0xa3, 0xcb,
0x89, 0xe3, 0x86, 0x38, 0x45, 0xe2, 0x2c, 0x9e },
{ 0x87, 0x72, 0x5b, 0xd4, 0x3a, 0x45, 0x60, 0x88,
0x14, 0x18, 0x07, 0x73, 0xf0, 0xe7, 0xab, 0x95,
0xa3, 0xc8, 0x59, 0xd8, 0x3a, 0x21, 0x30, 0xe8,
0x84, 0x19, 0x0e, 0x44, 0xd1, 0x4c, 0x69, 0x96 }
};
static const struct {
const void *keys;
uint8_t key_size;
uint8_t count;
} keys[] = {
{ keys128, AES_KEY_STORE_SIZE_KEY_SIZE_128,
sizeof(keys128) / sizeof(keys128[0]) },
{ keys192, AES_KEY_STORE_SIZE_KEY_SIZE_192,
sizeof(keys192) / sizeof(keys192[0]) },
{ keys256, AES_KEY_STORE_SIZE_KEY_SIZE_256,
sizeof(keys256) / sizeof(keys256[0]) }
};
static const struct {
uint8_t key_size_index;
uint8_t key_area;
uint8_t mdata[MDATA_MAX_LEN];
uint16_t mdata_len;
uint8_t mac[CBC_MAC_MAC_LEN];
} vectors[] = {
{
0, /* key_size_index */
0, /* key_area */
{ 0x45, 0xcf, 0x12, 0x96, 0x4f, 0xc8, 0x24, 0xab,
0x76, 0x61, 0x6a, 0xe2, 0xf4, 0xbf, 0x08, 0x22 }, /* mdata */
16, /* mdata_len */
{ 0x97, 0x67, 0x0c, 0x83, 0x99, 0x24, 0xa4, 0xc6,
0x15, 0xb0, 0xf6, 0x14, 0xae, 0x75, 0xa8, 0x69 } /* mac */
}, {
0, /* key_size_index */
1, /* key_area */
{ 0x9a, 0xc1, 0x99, 0x54, 0xce, 0x13, 0x19, 0xb3,
0x54, 0xd3, 0x22, 0x04, 0x60, 0xf7, 0x1c, 0x1e,
0x37, 0x3f, 0x1c, 0xd3, 0x36, 0x24, 0x08, 0x81,
0x16, 0x0c, 0xfd, 0xe4, 0x6e, 0xbf, 0xed, 0x2e,
0x79, 0x1e, 0x8d, 0x5a, 0x1a, 0x13, 0x6e, 0xbd,
0x1d, 0xc4, 0x69, 0xde, 0xc0, 0x0c, 0x41, 0x87,
0x72, 0x2b, 0x84, 0x1c, 0xda, 0xbc, 0xb2, 0x2c,
0x1b, 0xe8, 0xa1, 0x46, 0x57, 0xda, 0x20, 0x0e }, /* mdata */
64, /* mdata_len */
{ 0x9d, 0x15, 0xb9, 0xfb, 0xff, 0xe2, 0x32, 0x97,
0x56, 0x36, 0x36, 0x6d, 0x13, 0x65, 0x78, 0xb5 } /* mac */
}, {
0, /* key_size_index */
2, /* key_area */
{ 0x80, 0x7b, 0xc4, 0xea, 0x68, 0x4e, 0xed, 0xcf,
0xdc, 0xca, 0x30, 0x18, 0x06, 0x80, 0xb0, 0xf1,
0xae, 0x28, 0x14, 0xf3, 0x5f, 0x36, 0xd0, 0x53,
0xc5, 0xae, 0xa6, 0x59, 0x5a, 0x38, 0x6c, 0x14,
0x42, 0x77, 0x0f, 0x4d, 0x72, 0x97, 0xd8, 0xb9,
0x18, 0x25, 0xee, 0x72, 0x37, 0x24, 0x1d, 0xa8,
0x92, 0x5d, 0xd5, 0x94, 0xcc, 0xf6, 0x76, 0xae,
0xcd, 0x46, 0xca, 0x20, 0x68, 0xe8, 0xd3, 0x7a,
0x3a, 0x0e, 0xc8, 0xa7, 0xd5, 0x18, 0x5a, 0x20,
0x1e, 0x66, 0x3b, 0x5f, 0xf3, 0x6a, 0xe1, 0x97,
0x11, 0x01, 0x88, 0xa2, 0x35, 0x03, 0x76, 0x3b,
0x82, 0x18, 0x82, 0x6d, 0x23, 0xce, 0xd7, 0x4b,
0x31, 0xe9, 0xf6, 0xe2, 0xd7, 0xfb, 0xfa, 0x6c,
0xb4, 0x34, 0x20, 0xc7, 0x80, 0x7a, 0x86, 0x25 }, /* mdata */
112, /* mdata_len */
{ 0x5f, 0x4f, 0x06, 0xe0, 0x62, 0x65, 0xf2, 0xeb,
0x16, 0x1c, 0xda, 0x9f, 0x30, 0xe9, 0x79, 0x53 } /* mac */
}, {
0, /* key_size_index */
3, /* key_area */
{ 0x40, 0xd9, 0x30, 0xf9, 0xa0, 0x53, 0x34, 0xd9,
0x81, 0x6f, 0xe2, 0x04, 0x99, 0x9c, 0x3f, 0x82,
0xa0, 0x3f, 0x6a, 0x04, 0x57, 0xa8, 0xc4, 0x75,
0xc9, 0x45, 0x53, 0xd1, 0xd1, 0x16, 0x69, 0x3a,
0xdc, 0x61, 0x80, 0x49, 0xf0, 0xa7, 0x69, 0xa2,
0xee, 0xd6, 0xa6, 0xcb, 0x14, 0xc0, 0x14, 0x3e,
0xc5, 0xcc, 0xcd, 0xbc, 0x8d, 0xec, 0x4c, 0xe5,
0x60, 0xcf, 0xd2, 0x06, 0x22, 0x57, 0x09, 0x32,
0x6d, 0x4d, 0xe7, 0x94, 0x8e, 0x54, 0xd6, 0x03,
0xd0, 0x1b, 0x12, 0xd7, 0xfe, 0xd7, 0x52, 0xfb,
0x23, 0xf1, 0xaa, 0x44, 0x94, 0xfb, 0xb0, 0x01,
0x30, 0xe9, 0xde, 0xd4, 0xe7, 0x7e, 0x37, 0xc0,
0x79, 0x04, 0x2d, 0x82, 0x80, 0x40, 0xc3, 0x25,
0xb1, 0xa5, 0xef, 0xd1, 0x5f, 0xc8, 0x42, 0xe4,
0x40, 0x14, 0xca, 0x43, 0x74, 0xbf, 0x38, 0xf3,
0xc3, 0xfc, 0x3e, 0xe3, 0x27, 0x73, 0x3b, 0x0c,
0x8a, 0xee, 0x1a, 0xbc, 0xd0, 0x55, 0x77, 0x2f,
0x18, 0xdc, 0x04, 0x60, 0x3f, 0x7b, 0x2c, 0x1e,
0xa6, 0x9f, 0xf6, 0x62, 0x36, 0x1f, 0x2b, 0xe0,
0xa1, 0x71, 0xbb, 0xdc, 0xea, 0x1e, 0x5d, 0x3f }, /* mdata */
160, /* mdata_len */
{ 0xda, 0x15, 0x2d, 0xf1, 0xf5, 0x6a, 0x44, 0x0e,
0x1c, 0x7e, 0x27, 0x80, 0xed, 0x87, 0xd9, 0x3d } /* mac */
}, {
0, /* key_size_index */
4, /* key_area */
{ 0xf8, 0xeb, 0x31, 0xb3, 0x1e, 0x37, 0x4e, 0x96,
0x00, 0x30, 0xcd, 0x1c, 0xad, 0xb0, 0xef, 0x0c }, /* mdata */
16, /* mdata_len */
{ 0x11, 0x0b, 0x18, 0xdb, 0xe0, 0x97, 0x56, 0x39,
0xf7, 0x1d, 0x87, 0x7d, 0x6d, 0x07, 0x27, 0x55 } /* mac */
}, {
0, /* key_size_index */
5, /* key_area */
{ 0xd3, 0xf8, 0x9b, 0x71, 0xe0, 0x33, 0x07, 0x0f,
0x9d, 0x75, 0x16, 0xa6, 0xcb, 0x4e, 0xa5, 0xef,
0x51, 0xd6, 0xfb, 0x63, 0xd4, 0xf0, 0xfe, 0xa0,
0x89, 0xd0, 0xa6, 0x0e, 0x47, 0xbb, 0xb3, 0xc2,
0xe1, 0x0e, 0x9b, 0xa3, 0xb2, 0x82, 0xc7, 0xcb,
0x79, 0xae, 0xfe, 0x30, 0x68, 0xce, 0x22, 0x83,
0x77, 0xc2, 0x1a, 0x58, 0xfe, 0x5a, 0x0f, 0x88,
0x83, 0xd0, 0xdb, 0xd3, 0xd0, 0x96, 0xbe, 0xca }, /* mdata */
64, /* mdata_len */
{ 0x6d, 0x91, 0x75, 0x52, 0x10, 0xcc, 0x69, 0x4a,
0xde, 0x6c, 0xf6, 0xa0, 0xcd, 0x2d, 0x51, 0x8e } /* mac */
}, {
0, /* key_size_index */
6, /* key_area */
{ 0xc6, 0x5b, 0x94, 0xb1, 0xf2, 0x91, 0xfa, 0x9f,
0x06, 0x00, 0xf2, 0x2c, 0x3c, 0x04, 0x32, 0xc8,
0x95, 0xad, 0x5d, 0x17, 0x7b, 0xcc, 0xcc, 0x9e,
0xa4, 0x4e, 0x8e, 0xc3, 0x39, 0xc9, 0xad, 0xf4,
0x38, 0x55, 0xb3, 0x26, 0x17, 0x9d, 0x6d, 0x81,
0xaa, 0x36, 0xef, 0x59, 0x46, 0x2f, 0xd8, 0x61,
0x27, 0xe9, 0xd8, 0x1b, 0x0f, 0x28, 0x6f, 0x93,
0x30, 0x6b, 0xf7, 0x4d, 0x4c, 0x79, 0xe4, 0x7c,
0x1b, 0x3d, 0x4b, 0x74, 0xed, 0xd3, 0xa1, 0x62,
0x90, 0xe3, 0xc6, 0x3b, 0x74, 0x2e, 0x41, 0xf2,
0x0d, 0x66, 0xce, 0xee, 0x79, 0x43, 0x16, 0xbb,
0x63, 0xd3, 0xbd, 0x00, 0x27, 0x12, 0xa1, 0xb1,
0x36, 0xba, 0x61, 0x85, 0xbd, 0x5c, 0x1d, 0xab,
0x81, 0xb0, 0x7d, 0xb9, 0x0d, 0x2a, 0xf5, 0xe5 }, /* mdata */
112, /* mdata_len */
{ 0x47, 0x12, 0x32, 0xdc, 0x47, 0xca, 0x7e, 0xe2,
0xd8, 0xd6, 0x43, 0x6c, 0xe5, 0x75, 0x03, 0xb9 } /* mac */
}, {
0, /* key_size_index */
7, /* key_area */
{ 0x22, 0xcd, 0xc3, 0x30, 0x6f, 0xcd, 0x4d, 0x31,
0xcc, 0xd3, 0x27, 0x20, 0xcb, 0xb6, 0x1b, 0xad,
0x28, 0xd8, 0x55, 0x67, 0x06, 0x57, 0xc4, 0x8c,
0x7b, 0x88, 0xc3, 0x1f, 0x4f, 0xa1, 0xf9, 0x3c,
0x01, 0xb5, 0x7d, 0xa9, 0x0b, 0xe6, 0x3e, 0xad,
0x67, 0xd6, 0xa3, 0x25, 0x52, 0x5e, 0x6e, 0xd4,
0x50, 0x83, 0xe6, 0xfb, 0x70, 0xa5, 0x35, 0x29,
0xd1, 0xfa, 0x0f, 0x55, 0x65, 0x3b, 0x94, 0x2a,
0xf5, 0x9d, 0x78, 0xa2, 0x66, 0x03, 0x61, 0xd6,
0x3a, 0x72, 0x90, 0x15, 0x5a, 0xc5, 0xc4, 0x33,
0x12, 0xa2, 0x5b, 0x23, 0x5d, 0xac, 0xbb, 0xc8,
0x63, 0xfa, 0xf0, 0x09, 0x40, 0xc9, 0x96, 0x24,
0x07, 0x6d, 0xfa, 0x44, 0x06, 0x8e, 0x7c, 0x55,
0x4c, 0x90, 0x38, 0x17, 0x69, 0x53, 0xe5, 0x71,
0x75, 0x1d, 0xfc, 0x09, 0x54, 0xd4, 0x1d, 0x11,
0x37, 0x71, 0xb0, 0x64, 0x66, 0xb1, 0xc8, 0xd1,
0x3e, 0x0d, 0x4c, 0xb6, 0x75, 0xed, 0x58, 0xd1,
0xa6, 0x19, 0xe1, 0x54, 0x09, 0x70, 0x98, 0x37,
0x81, 0xdc, 0x11, 0xd2, 0xdd, 0x85, 0x25, 0xab,
0x57, 0x45, 0x95, 0x8d, 0x61, 0x5d, 0xef, 0xda }, /* mdata */
160, /* mdata_len */
{ 0xe9, 0xae, 0x7e, 0x63, 0x54, 0x23, 0xc3, 0x66,
0xd5, 0x23, 0xf9, 0x7c, 0x0e, 0xdb, 0x18, 0xb0 } /* mac */
}, {
1, /* key_size_index */
0, /* key_area */
{ 0xc5, 0x1f, 0xc2, 0x76, 0x77, 0x4d, 0xad, 0x94,
0xbc, 0xdc, 0x1d, 0x28, 0x91, 0xec, 0x86, 0x68 }, /* mdata */
16, /* mdata_len */
{ 0x40, 0xd1, 0x7f, 0x9a, 0x6f, 0x5b, 0xc6, 0xaf,
0x34, 0x1e, 0x6a, 0xc5, 0xe4, 0x9e, 0x71, 0xad } /* mac */
}, {
1, /* key_size_index */
2, /* key_area */
{ 0xbe, 0x8a, 0xbf, 0x00, 0x90, 0x13, 0x63, 0x98,
0x7a, 0x82, 0xcc, 0x77, 0xd0, 0xec, 0x91, 0x69,
0x7b, 0xa3, 0x85, 0x7f, 0x9e, 0x4f, 0x84, 0xbd,
0x79, 0x40, 0x6c, 0x13, 0x8d, 0x02, 0x69, 0x8f,
0x00, 0x32, 0x76, 0xd0, 0x44, 0x91, 0x20, 0xbe,
0xf4, 0x57, 0x8d, 0x78, 0xfe, 0xca, 0xbe, 0x8e,
0x07, 0x0e, 0x11, 0x71, 0x0b, 0x3f, 0x0a, 0x27,
0x44, 0xbd, 0x52, 0x43, 0x4e, 0xc7, 0x00, 0x15,
0x88, 0x4c, 0x18, 0x1e, 0xbd, 0xfd, 0x51, 0xc6,
0x04, 0xa7, 0x1c, 0x52, 0xe4, 0xc0, 0xe1, 0x10,
0xbc, 0x40, 0x8c, 0xd4, 0x62, 0xb2, 0x48, 0xa8,
0x0b, 0x8a, 0x8a, 0xc0, 0x6b, 0xb9, 0x52, 0xac,
0x1d, 0x7f, 0xae, 0xd1, 0x44, 0x80, 0x7f, 0x1a,
0x73, 0x1b, 0x7f, 0xeb, 0xca, 0xf7, 0x83, 0x57,
0x62, 0xde, 0xfe, 0x92, 0xec, 0xcf, 0xc7, 0xa9,
0x94, 0x4e, 0x1c, 0x70, 0x2c, 0xff, 0xe6, 0xbc,
0x86, 0x73, 0x3e, 0xd3, 0x21, 0x42, 0x31, 0x21,
0x08, 0x5a, 0xc0, 0x2d, 0xf8, 0x96, 0x2b, 0xcb,
0xc1, 0x93, 0x70, 0x92, 0xee, 0xbf, 0x0e, 0x90,
0xa8, 0xb2, 0x0e, 0x3d, 0xd8, 0xc2, 0x44, 0xae }, /* mdata */
160, /* mdata_len */
{ 0xea, 0x57, 0x08, 0xb7, 0x8b, 0xf0, 0x51, 0xd6,
0x94, 0xeb, 0x37, 0x01, 0xca, 0x6b, 0xd5, 0x7b } /* mac */
}, {
1, /* key_size_index */
4, /* key_area */
{ 0x39, 0xa9, 0xb4, 0x2d, 0xe1, 0x9e, 0x51, 0x2a,
0xb7, 0xf3, 0x04, 0x35, 0x64, 0xc3, 0x51, 0x5a }, /* mdata */
16, /* mdata_len */
{ 0xa8, 0xd9, 0x3d, 0x9e, 0x1c, 0x14, 0xe4, 0x1e,
0xa3, 0xf0, 0xaa, 0x50, 0xa4, 0xa3, 0x26, 0x09 } /* mac */
}, {
1, /* key_size_index */
6, /* key_area */
{ 0x69, 0x28, 0x29, 0x9c, 0x52, 0xb4, 0xf0, 0x47,
0x92, 0x6f, 0x8a, 0x54, 0x15, 0x29, 0xda, 0x2d,
0x6b, 0xba, 0xa3, 0x99, 0x14, 0x3c, 0xed, 0x8e,
0xfb, 0x77, 0xab, 0x47, 0x40, 0x9d, 0x9a, 0x95,
0x3a, 0x38, 0x6c, 0x7a, 0xbd, 0x60, 0x26, 0xf4,
0x98, 0x31, 0xc7, 0x17, 0x62, 0x7c, 0x2a, 0x5e,
0x77, 0xbd, 0x2d, 0x43, 0x3d, 0x4d, 0x13, 0x0d,
0xac, 0xd9, 0x27, 0xea, 0x0d, 0x13, 0xa2, 0x3d,
0x01, 0xa7, 0xcf, 0x39, 0xc6, 0x71, 0x6d, 0xaf,
0xb6, 0xed, 0x55, 0x24, 0x10, 0xef, 0x5d, 0x27,
0xfb, 0x94, 0x7b, 0xe2, 0xc8, 0x78, 0x2e, 0xee,
0x78, 0x29, 0x19, 0x6c, 0x7e, 0xdc, 0xf1, 0x51,
0xc6, 0x5f, 0x9a, 0x01, 0xf5, 0x4f, 0x8d, 0x20,
0xf3, 0x8b, 0x7d, 0xa4, 0xa7, 0xe8, 0x3a, 0x2f,
0x01, 0x27, 0xd5, 0x9d, 0x3e, 0x24, 0x05, 0xd8,
0x67, 0x4f, 0xc9, 0xf4, 0x1b, 0x60, 0x4f, 0x78,
0x8f, 0x47, 0x15, 0xf9, 0xd3, 0x62, 0x4e, 0xee,
0x57, 0xf3, 0x87, 0xbf, 0xad, 0xd1, 0x8a, 0x1f,
0x90, 0x5e, 0x83, 0x9c, 0x26, 0xb8, 0x61, 0x74,
0x82, 0x34, 0x7f, 0xab, 0x6d, 0x08, 0x84, 0x5a }, /* mdata */
160, /* mdata_len */
{ 0x69, 0x27, 0xe7, 0xfb, 0x4c, 0xb9, 0x9d, 0x9c,
0x54, 0xe2, 0x7f, 0x1c, 0x76, 0x20, 0xa0, 0x07 } /* mac */
}, {
2, /* key_size_index */
0, /* key_area */
{ 0x62, 0x82, 0xb8, 0xc0, 0x5c, 0x5c, 0x15, 0x30,
0xb9, 0x7d, 0x48, 0x16, 0xca, 0x43, 0x47, 0x62 }, /* mdata */
16, /* mdata_len */
{ 0xa1, 0x07, 0x61, 0x82, 0xc1, 0xf4, 0x33, 0xc3,
0xda, 0xfb, 0xe1, 0x1d, 0x3e, 0x71, 0xdd, 0x8a } /* mac */
}, {
2, /* key_size_index */
2, /* key_area */
{ 0x0c, 0x63, 0xd4, 0x13, 0xd3, 0x86, 0x45, 0x70,
0xe7, 0x0b, 0xb6, 0x61, 0x8b, 0xf8, 0xa4, 0xb9,
0x58, 0x55, 0x86, 0x68, 0x8c, 0x32, 0xbb, 0xa0,
0xa5, 0xec, 0xc1, 0x36, 0x2f, 0xad, 0xa7, 0x4a,
0xda, 0x32, 0xc5, 0x2a, 0xcf, 0xd1, 0xaa, 0x74,
0x44, 0xba, 0x56, 0x7b, 0x4e, 0x7d, 0xaa, 0xec,
0xf7, 0xcc, 0x1c, 0xb2, 0x91, 0x82, 0xaf, 0x16,
0x4a, 0xe5, 0x23, 0x2b, 0x00, 0x28, 0x68, 0x69,
0x56, 0x35, 0x59, 0x98, 0x07, 0xa9, 0xa7, 0xf0,
0x7a, 0x1f, 0x13, 0x7e, 0x97, 0xb1, 0xe1, 0xc9,
0xda, 0xbc, 0x89, 0xb6, 0xa5, 0xe4, 0xaf, 0xa9,
0xdb, 0x58, 0x55, 0xed, 0xaa, 0x57, 0x50, 0x56,
0xa8, 0xf4, 0xf8, 0x24, 0x22, 0x16, 0x24, 0x2b,
0xb0, 0xc2, 0x56, 0x31, 0x0d, 0x9d, 0x32, 0x98,
0x26, 0xac, 0x35, 0x3d, 0x71, 0x5f, 0xa3, 0x9f,
0x80, 0xce, 0xc1, 0x44, 0xd6, 0x42, 0x45, 0x58,
0xf9, 0xf7, 0x0b, 0x98, 0xc9, 0x20, 0x09, 0x6e,
0x0f, 0x2c, 0x85, 0x5d, 0x59, 0x48, 0x85, 0xa0,
0x06, 0x25, 0x88, 0x0e, 0x9d, 0xfb, 0x73, 0x41,
0x63, 0xce, 0xce, 0xf7, 0x2c, 0xf0, 0x30, 0xb8 }, /* mdata */
160, /* mdata_len */
{ 0xf2, 0xb7, 0x45, 0x13, 0xd6, 0xcf, 0x2d, 0x80,
0xe6, 0x72, 0xb8, 0x37, 0x45, 0xfa, 0xdc, 0x0f } /* mac */
}, {
2, /* key_size_index */
4, /* key_area */
{ 0xd5, 0x1d, 0x19, 0xde, 0xd5, 0xca, 0x4a, 0xe1,
0x4b, 0x2b, 0x20, 0xb0, 0x27, 0xff, 0xb0, 0x20 }, /* mdata */
16, /* mdata_len */
{ 0xb0, 0x52, 0xa1, 0xdf, 0xe6, 0xa4, 0x8e, 0x63,
0x43, 0x23, 0xdc, 0xaa, 0x85, 0xfa, 0xda, 0x3c } /* mac */
}, {
2, /* key_size_index */
6, /* key_area */
{ 0x5b, 0x97, 0xa9, 0xd4, 0x23, 0xf4, 0xb9, 0x74,
0x13, 0xf3, 0x88, 0xd9, 0xa3, 0x41, 0xe7, 0x27,
0xbb, 0x33, 0x9f, 0x8e, 0x18, 0xa3, 0xfa, 0xc2,
0xf2, 0xfb, 0x85, 0xab, 0xdc, 0x8f, 0x13, 0x5d,
0xeb, 0x30, 0x05, 0x4a, 0x1a, 0xfd, 0xc9, 0xb6,
0xed, 0x7d, 0xa1, 0x6c, 0x55, 0xeb, 0xa6, 0xb0,
0xd4, 0xd1, 0x0c, 0x74, 0xe1, 0xd9, 0xa7, 0xcf,
0x8e, 0xdf, 0xae, 0xaa, 0x68, 0x4a, 0xc0, 0xbd,
0x9f, 0x9d, 0x24, 0xba, 0x67, 0x49, 0x55, 0xc7,
0x9d, 0xc6, 0xbe, 0x32, 0xae, 0xe1, 0xc2, 0x60,
0xb5, 0x58, 0xff, 0x07, 0xe3, 0xa4, 0xd4, 0x9d,
0x24, 0x16, 0x20, 0x11, 0xff, 0x25, 0x4d, 0xb8,
0xbe, 0x07, 0x8e, 0x8a, 0xd0, 0x7e, 0x64, 0x8e,
0x6b, 0xf5, 0x67, 0x93, 0x76, 0xcb, 0x43, 0x21,
0xa5, 0xef, 0x01, 0xaf, 0xe6, 0xad, 0x88, 0x16,
0xfc, 0xc7, 0x63, 0x46, 0x69, 0xc8, 0xc4, 0x38,
0x92, 0x95, 0xc9, 0x24, 0x1e, 0x45, 0xff, 0xf3,
0x9f, 0x32, 0x25, 0xf7, 0x74, 0x50, 0x32, 0xda,
0xee, 0xbe, 0x99, 0xd4, 0xb1, 0x9b, 0xcb, 0x21,
0x5d, 0x1b, 0xfd, 0xb3, 0x6e, 0xda, 0x2c, 0x24 }, /* mdata */
160, /* mdata_len */
{ 0xc9, 0xa0, 0x14, 0x60, 0xaa, 0x2f, 0x85, 0x25,
0x88, 0x75, 0xa1, 0x76, 0xcc, 0x85, 0x46, 0xf9 } /* mac */
}
};
static uint8_t mdata[MDATA_MAX_LEN];
static uint8_t mac[CBC_MAC_MAC_LEN];
static int i;
static uint8_t key_size_index = -1, ret;
static rtimer_clock_t time, time2, total_time;
PROCESS_BEGIN();
puts("-----------------------------------------\n"
"Initializing cryptoprocessor...");
crypto_init();
for(i = 0; i < sizeof(vectors) / sizeof(vectors[0]); i++) {
if(key_size_index != vectors[i].key_size_index) {
key_size_index = vectors[i].key_size_index;
printf("-----------------------------------------\n"
"Filling %d-bit key store...\n", 128 + (key_size_index << 6));
time = RTIMER_NOW();
ret = aes_load_keys(keys[key_size_index].keys,
keys[key_size_index].key_size, keys[key_size_index].count, 0);
time = RTIMER_NOW() - time;
printf("aes_load_keys(): %s, %lu us\n", str_res[ret],
(uint32_t)((uint64_t)time * 1000000 / RTIMER_SECOND));
PROCESS_PAUSE();
if(ret != CRYPTO_SUCCESS) {
break;
}
}
printf("-----------------------------------------\n"
"Test vector #%d:\n"
"key_area=%d mdata_len=%d\n",
i, vectors[i].key_area, vectors[i].mdata_len);
/* mdata has to be in SRAM. */
rom_util_memcpy(mdata, vectors[i].mdata, vectors[i].mdata_len);
time = RTIMER_NOW();
ret = cbc_mac_auth_start(vectors[i].key_area, mdata, vectors[i].mdata_len,
&cbc_mac_test_process);
time2 = RTIMER_NOW();
time = time2 - time;
total_time = time;
if(ret == CRYPTO_SUCCESS) {
PROCESS_WAIT_EVENT_UNTIL(cbc_mac_auth_check_status());
time2 = RTIMER_NOW() - time2;
total_time += time2;
}
printf("cbc_mac_auth_start(): %s, %lu us\n", str_res[ret],
(uint32_t)((uint64_t)time * 1000000 / RTIMER_SECOND));
if(ret != CRYPTO_SUCCESS) {
PROCESS_PAUSE();
continue;
}
printf("cbc_mac_auth_check_status() wait: %lu us\n",
(uint32_t)((uint64_t)time2 * 1000000 / RTIMER_SECOND));
time = RTIMER_NOW();
ret = cbc_mac_auth_get_result(vectors[i].mac, mac);
time = RTIMER_NOW() - time;
total_time += time;
printf("cbc_mac_auth_get_result(): %s, %lu us\n", str_res[ret],
(uint32_t)((uint64_t)time * 1000000 / RTIMER_SECOND));
PROCESS_PAUSE();
if(ret != CRYPTO_SUCCESS) {
continue;
}
if(rom_util_memcmp(mac, vectors[i].mac, CBC_MAC_MAC_LEN)) {
puts("MAC does not match expected one");
} else {
puts("MAC OK");
}
printf("Total duration: %lu us\n",
(uint32_t)((uint64_t)total_time * 1000000 / RTIMER_SECOND));
}
puts("-----------------------------------------\n"
"Disabling cryptoprocessor...");
crypto_disable();
puts("Done!");
PROCESS_END();
}
/*---------------------------------------------------------------------------*/
/**
* @}
* @}
*/

View file

@ -0,0 +1,696 @@
/*
* Copyright (c) 2015, Benoît Thébaudeau <benoit.thebaudeau.dev@gmail.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* \addtogroup cc2538-examples
* @{
*
* \defgroup cc2538-cbc-test cc2538dk AES-CBC Test Project
*
* AES-CBC access example for CC2538 on SmartRF06EB.
*
* This example shows how AES-CBC should be used. The example also verifies
* the AES-CBC functionality.
*
* @{
*
* \file
* Example demonstrating AES-CBC on the cc2538dk platform
*/
#include "contiki.h"
#include "sys/rtimer.h"
#include "dev/rom-util.h"
#include "dev/cbc.h"
#include <stdbool.h>
#include <stdio.h>
#include <stdint.h>
/*---------------------------------------------------------------------------*/
#define MDATA_MAX_LEN 160
/*---------------------------------------------------------------------------*/
PROCESS(cbc_test_process, "cbc test process");
AUTOSTART_PROCESSES(&cbc_test_process);
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(cbc_test_process, ev, data)
{
static const char *const str_res[] = {
"success",
"invalid param",
"NULL error",
"resource in use",
"DMA bus error",
"keystore read error",
"keystore write error",
"authentication failed"
};
static const uint8_t keys128[][128 / 8] = {
{ 0x1f, 0x8e, 0x49, 0x73, 0x95, 0x3f, 0x3f, 0xb0,
0xbd, 0x6b, 0x16, 0x66, 0x2e, 0x9a, 0x3c, 0x17 },
{ 0xb7, 0xf3, 0xc9, 0x57, 0x6e, 0x12, 0xdd, 0x0d,
0xb6, 0x3e, 0x8f, 0x8f, 0xac, 0x2b, 0x9a, 0x39 },
{ 0x89, 0xa5, 0x53, 0x73, 0x04, 0x33, 0xf7, 0xe6,
0xd6, 0x7d, 0x16, 0xd3, 0x73, 0xbd, 0x53, 0x60 },
{ 0x2c, 0x14, 0x41, 0x37, 0x51, 0xc3, 0x1e, 0x27,
0x30, 0x57, 0x0b, 0xa3, 0x36, 0x1c, 0x78, 0x6b },
{ 0x6a, 0x70, 0x82, 0xcf, 0x8c, 0xda, 0x13, 0xef,
0xf4, 0x8c, 0x81, 0x58, 0xdd, 0xa2, 0x06, 0xae },
{ 0x7b, 0x1a, 0xb9, 0x14, 0x4b, 0x02, 0x39, 0x31,
0x5c, 0xd5, 0xee, 0xc6, 0xc7, 0x56, 0x63, 0xbd },
{ 0xba, 0xb0, 0xcc, 0xed, 0xdc, 0x0a, 0xbd, 0x63,
0xe3, 0xf8, 0x2e, 0x9f, 0xbf, 0xf7, 0xb8, 0xaa },
{ 0x97, 0xa1, 0x02, 0x55, 0x29, 0xb9, 0x92, 0x5e,
0x25, 0xbb, 0xe7, 0x87, 0x70, 0xca, 0x2f, 0x99 }
};
static const uint8_t keys192[][192 / 8] = {
{ 0xba, 0x75, 0xf4, 0xd1, 0xd9, 0xd7, 0xcf, 0x7f,
0x55, 0x14, 0x45, 0xd5, 0x6c, 0xc1, 0xa8, 0xab,
0x2a, 0x07, 0x8e, 0x15, 0xe0, 0x49, 0xdc, 0x2c },
{ 0x16, 0x2a, 0xd5, 0x0e, 0xe6, 0x4a, 0x07, 0x02,
0xaa, 0x55, 0x1f, 0x57, 0x1d, 0xed, 0xc1, 0x6b,
0x2c, 0x1b, 0x6a, 0x1e, 0x4d, 0x4b, 0x5e, 0xee },
{ 0x8e, 0x27, 0x40, 0xfb, 0xa1, 0x57, 0xae, 0xf2,
0x42, 0x2e, 0x44, 0x23, 0x12, 0xd1, 0x5c, 0x14,
0xd3, 0x12, 0x55, 0x36, 0x84, 0xfc, 0xdc, 0x15 },
{ 0x50, 0x9b, 0xaf, 0x46, 0xfb, 0x9d, 0xe3, 0x42,
0x81, 0xda, 0xfc, 0xc3, 0xdb, 0x79, 0x59, 0x3b,
0xff, 0xa8, 0x42, 0x69, 0x04, 0x30, 0x26, 0x88 }
};
static const uint8_t keys256[][256 / 8] = {
{ 0x6e, 0xd7, 0x6d, 0x2d, 0x97, 0xc6, 0x9f, 0xd1,
0x33, 0x95, 0x89, 0x52, 0x39, 0x31, 0xf2, 0xa6,
0xcf, 0xf5, 0x54, 0xb1, 0x5f, 0x73, 0x8f, 0x21,
0xec, 0x72, 0xdd, 0x97, 0xa7, 0x33, 0x09, 0x07 },
{ 0x48, 0xbe, 0x59, 0x7e, 0x63, 0x2c, 0x16, 0x77,
0x23, 0x24, 0xc8, 0xd3, 0xfa, 0x1d, 0x9c, 0x5a,
0x9e, 0xcd, 0x01, 0x0f, 0x14, 0xec, 0x5d, 0x11,
0x0d, 0x3b, 0xfe, 0xc3, 0x76, 0xc5, 0x53, 0x2b },
{ 0x43, 0xe9, 0x53, 0xb2, 0xae, 0xa0, 0x8a, 0x3a,
0xd5, 0x2d, 0x18, 0x2f, 0x58, 0xc7, 0x2b, 0x9c,
0x60, 0xfb, 0xe4, 0xa9, 0xca, 0x46, 0xa3, 0xcb,
0x89, 0xe3, 0x86, 0x38, 0x45, 0xe2, 0x2c, 0x9e },
{ 0x87, 0x72, 0x5b, 0xd4, 0x3a, 0x45, 0x60, 0x88,
0x14, 0x18, 0x07, 0x73, 0xf0, 0xe7, 0xab, 0x95,
0xa3, 0xc8, 0x59, 0xd8, 0x3a, 0x21, 0x30, 0xe8,
0x84, 0x19, 0x0e, 0x44, 0xd1, 0x4c, 0x69, 0x96 }
};
static const struct {
const void *keys;
uint8_t key_size;
uint8_t count;
} keys[] = {
{ keys128, AES_KEY_STORE_SIZE_KEY_SIZE_128,
sizeof(keys128) / sizeof(keys128[0]) },
{ keys192, AES_KEY_STORE_SIZE_KEY_SIZE_192,
sizeof(keys192) / sizeof(keys192[0]) },
{ keys256, AES_KEY_STORE_SIZE_KEY_SIZE_256,
sizeof(keys256) / sizeof(keys256[0]) }
};
static const struct {
bool encrypt;
uint8_t key_size_index;
uint8_t key_area;
uint8_t iv[CBC_IV_LEN];
uint8_t mdata[MDATA_MAX_LEN];
uint16_t mdata_len;
uint8_t expected[MDATA_MAX_LEN];
} vectors[] = {
{
true, /* encrypt */
0, /* key_size_index */
0, /* key_area */
{ 0x2f, 0xe2, 0xb3, 0x33, 0xce, 0xda, 0x8f, 0x98,
0xf4, 0xa9, 0x9b, 0x40, 0xd2, 0xcd, 0x34, 0xa8 }, /* iv */
{ 0x45, 0xcf, 0x12, 0x96, 0x4f, 0xc8, 0x24, 0xab,
0x76, 0x61, 0x6a, 0xe2, 0xf4, 0xbf, 0x08, 0x22 }, /* mdata */
16, /* mdata_len */
{ 0x0f, 0x61, 0xc4, 0xd4, 0x4c, 0x51, 0x47, 0xc0,
0x3c, 0x19, 0x5a, 0xd7, 0xe2, 0xcc, 0x12, 0xb2 } /* expected */
}, {
true, /* encrypt */
0, /* key_size_index */
1, /* key_area */
{ 0xc8, 0x0f, 0x09, 0x5d, 0x8b, 0xb1, 0xa0, 0x60,
0x69, 0x9f, 0x7c, 0x19, 0x97, 0x4a, 0x1a, 0xa0 }, /* iv */
{ 0x9a, 0xc1, 0x99, 0x54, 0xce, 0x13, 0x19, 0xb3,
0x54, 0xd3, 0x22, 0x04, 0x60, 0xf7, 0x1c, 0x1e,
0x37, 0x3f, 0x1c, 0xd3, 0x36, 0x24, 0x08, 0x81,
0x16, 0x0c, 0xfd, 0xe4, 0x6e, 0xbf, 0xed, 0x2e,
0x79, 0x1e, 0x8d, 0x5a, 0x1a, 0x13, 0x6e, 0xbd,
0x1d, 0xc4, 0x69, 0xde, 0xc0, 0x0c, 0x41, 0x87,
0x72, 0x2b, 0x84, 0x1c, 0xda, 0xbc, 0xb2, 0x2c,
0x1b, 0xe8, 0xa1, 0x46, 0x57, 0xda, 0x20, 0x0e }, /* mdata */
64, /* mdata_len */
{ 0x19, 0xb9, 0x60, 0x97, 0x72, 0xc6, 0x3f, 0x33,
0x86, 0x08, 0xbf, 0x6e, 0xb5, 0x2c, 0xa1, 0x0b,
0xe6, 0x50, 0x97, 0xf8, 0x9c, 0x1e, 0x09, 0x05,
0xc4, 0x24, 0x01, 0xfd, 0x47, 0x79, 0x1a, 0xe2,
0xc5, 0x44, 0x0b, 0x2d, 0x47, 0x31, 0x16, 0xca,
0x78, 0xbd, 0x9f, 0xf2, 0xfb, 0x60, 0x15, 0xcf,
0xd3, 0x16, 0x52, 0x4e, 0xae, 0x7d, 0xcb, 0x95,
0xae, 0x73, 0x8e, 0xbe, 0xae, 0x84, 0xa4, 0x67 } /* expected */
}, {
true, /* encrypt */
0, /* key_size_index */
2, /* key_area */
{ 0xf7, 0x24, 0x55, 0x8d, 0xb3, 0x43, 0x3a, 0x52,
0x3f, 0x4e, 0x51, 0xa5, 0xbe, 0xa7, 0x04, 0x97 }, /* iv */
{ 0x80, 0x7b, 0xc4, 0xea, 0x68, 0x4e, 0xed, 0xcf,
0xdc, 0xca, 0x30, 0x18, 0x06, 0x80, 0xb0, 0xf1,
0xae, 0x28, 0x14, 0xf3, 0x5f, 0x36, 0xd0, 0x53,
0xc5, 0xae, 0xa6, 0x59, 0x5a, 0x38, 0x6c, 0x14,
0x42, 0x77, 0x0f, 0x4d, 0x72, 0x97, 0xd8, 0xb9,
0x18, 0x25, 0xee, 0x72, 0x37, 0x24, 0x1d, 0xa8,
0x92, 0x5d, 0xd5, 0x94, 0xcc, 0xf6, 0x76, 0xae,
0xcd, 0x46, 0xca, 0x20, 0x68, 0xe8, 0xd3, 0x7a,
0x3a, 0x0e, 0xc8, 0xa7, 0xd5, 0x18, 0x5a, 0x20,
0x1e, 0x66, 0x3b, 0x5f, 0xf3, 0x6a, 0xe1, 0x97,
0x11, 0x01, 0x88, 0xa2, 0x35, 0x03, 0x76, 0x3b,
0x82, 0x18, 0x82, 0x6d, 0x23, 0xce, 0xd7, 0x4b,
0x31, 0xe9, 0xf6, 0xe2, 0xd7, 0xfb, 0xfa, 0x6c,
0xb4, 0x34, 0x20, 0xc7, 0x80, 0x7a, 0x86, 0x25 }, /* mdata */
112, /* mdata_len */
{ 0x40, 0x6a, 0xf1, 0x42, 0x9a, 0x47, 0x8c, 0x3d,
0x07, 0xe5, 0x55, 0xc5, 0x28, 0x7a, 0x60, 0x50,
0x0d, 0x37, 0xfc, 0x39, 0xb6, 0x8e, 0x5b, 0xbb,
0x9b, 0xaf, 0xd6, 0xdd, 0xb2, 0x23, 0x82, 0x85,
0x61, 0xd6, 0x17, 0x1a, 0x30, 0x8d, 0x5b, 0x1a,
0x45, 0x51, 0xe8, 0xa5, 0xe7, 0xd5, 0x72, 0x91,
0x8d, 0x25, 0xc9, 0x68, 0xd3, 0x87, 0x18, 0x48,
0xd2, 0xf1, 0x66, 0x35, 0xca, 0xa9, 0x84, 0x7f,
0x38, 0x59, 0x0b, 0x1d, 0xf5, 0x8a, 0xb5, 0xef,
0xb9, 0x85, 0xf2, 0xc6, 0x6c, 0xfa, 0xf8, 0x6f,
0x61, 0xb3, 0xf9, 0xc0, 0xaf, 0xad, 0x6c, 0x96,
0x3c, 0x49, 0xce, 0xe9, 0xb8, 0xbc, 0x81, 0xa2,
0xdd, 0xb0, 0x6c, 0x96, 0x7f, 0x32, 0x55, 0x15,
0xa4, 0x84, 0x9e, 0xec, 0x37, 0xce, 0x72, 0x1a } /* expected */
}, {
true, /* encrypt */
0, /* key_size_index */
3, /* key_area */
{ 0x1d, 0xbb, 0xeb, 0x2f, 0x19, 0xab, 0xb4, 0x48,
0xaf, 0x84, 0x97, 0x96, 0x24, 0x4a, 0x19, 0xd7 }, /* iv */
{ 0x40, 0xd9, 0x30, 0xf9, 0xa0, 0x53, 0x34, 0xd9,
0x81, 0x6f, 0xe2, 0x04, 0x99, 0x9c, 0x3f, 0x82,
0xa0, 0x3f, 0x6a, 0x04, 0x57, 0xa8, 0xc4, 0x75,
0xc9, 0x45, 0x53, 0xd1, 0xd1, 0x16, 0x69, 0x3a,
0xdc, 0x61, 0x80, 0x49, 0xf0, 0xa7, 0x69, 0xa2,
0xee, 0xd6, 0xa6, 0xcb, 0x14, 0xc0, 0x14, 0x3e,
0xc5, 0xcc, 0xcd, 0xbc, 0x8d, 0xec, 0x4c, 0xe5,
0x60, 0xcf, 0xd2, 0x06, 0x22, 0x57, 0x09, 0x32,
0x6d, 0x4d, 0xe7, 0x94, 0x8e, 0x54, 0xd6, 0x03,
0xd0, 0x1b, 0x12, 0xd7, 0xfe, 0xd7, 0x52, 0xfb,
0x23, 0xf1, 0xaa, 0x44, 0x94, 0xfb, 0xb0, 0x01,
0x30, 0xe9, 0xde, 0xd4, 0xe7, 0x7e, 0x37, 0xc0,
0x79, 0x04, 0x2d, 0x82, 0x80, 0x40, 0xc3, 0x25,
0xb1, 0xa5, 0xef, 0xd1, 0x5f, 0xc8, 0x42, 0xe4,
0x40, 0x14, 0xca, 0x43, 0x74, 0xbf, 0x38, 0xf3,
0xc3, 0xfc, 0x3e, 0xe3, 0x27, 0x73, 0x3b, 0x0c,
0x8a, 0xee, 0x1a, 0xbc, 0xd0, 0x55, 0x77, 0x2f,
0x18, 0xdc, 0x04, 0x60, 0x3f, 0x7b, 0x2c, 0x1e,
0xa6, 0x9f, 0xf6, 0x62, 0x36, 0x1f, 0x2b, 0xe0,
0xa1, 0x71, 0xbb, 0xdc, 0xea, 0x1e, 0x5d, 0x3f }, /* mdata */
160, /* mdata_len */
{ 0x6b, 0xe8, 0xa1, 0x28, 0x00, 0x45, 0x5a, 0x32,
0x05, 0x38, 0x85, 0x3e, 0x0c, 0xba, 0x31, 0xbd,
0x2d, 0x80, 0xea, 0x0c, 0x85, 0x16, 0x4a, 0x4c,
0x5c, 0x26, 0x1a, 0xe4, 0x85, 0x41, 0x7d, 0x93,
0xef, 0xfe, 0x2e, 0xbc, 0x0d, 0x0a, 0x0b, 0x51,
0xd6, 0xea, 0x18, 0x63, 0x3d, 0x21, 0x0c, 0xf6,
0x3c, 0x0c, 0x4d, 0xdb, 0xc2, 0x76, 0x07, 0xf2,
0xe8, 0x1e, 0xd9, 0x11, 0x31, 0x91, 0xef, 0x86,
0xd5, 0x6f, 0x3b, 0x99, 0xbe, 0x6c, 0x41, 0x5a,
0x41, 0x50, 0x29, 0x9f, 0xb8, 0x46, 0xce, 0x71,
0x60, 0xb4, 0x0b, 0x63, 0xba, 0xf1, 0x17, 0x9d,
0x19, 0x27, 0x5a, 0x2e, 0x83, 0x69, 0x83, 0x76,
0xd2, 0x8b, 0x92, 0x54, 0x8c, 0x68, 0xe0, 0x6e,
0x6d, 0x99, 0x4e, 0x2c, 0x15, 0x01, 0xed, 0x29,
0x70, 0x14, 0xe7, 0x02, 0xcd, 0xef, 0xee, 0x2f,
0x65, 0x64, 0x47, 0x70, 0x60, 0x09, 0x61, 0x4d,
0x80, 0x1d, 0xe1, 0xca, 0xaf, 0x73, 0xf8, 0xb7,
0xfa, 0x56, 0xcf, 0x1b, 0xa9, 0x4b, 0x63, 0x19,
0x33, 0xbb, 0xe5, 0x77, 0x62, 0x43, 0x80, 0x85,
0x0f, 0x11, 0x74, 0x35, 0xa0, 0x35, 0x5b, 0x2b } /* expected */
}, {
false, /* encrypt */
0, /* key_size_index */
4, /* key_area */
{ 0xbd, 0x41, 0x72, 0x93, 0x40, 0x78, 0xc2, 0x01,
0x1c, 0xb1, 0xf3, 0x1c, 0xff, 0xaf, 0x48, 0x6e }, /* iv */
{ 0xf8, 0xeb, 0x31, 0xb3, 0x1e, 0x37, 0x4e, 0x96,
0x00, 0x30, 0xcd, 0x1c, 0xad, 0xb0, 0xef, 0x0c }, /* mdata */
16, /* mdata_len */
{ 0x94, 0x0b, 0xc7, 0x6d, 0x61, 0xe2, 0xc4, 0x9d,
0xdd, 0xd5, 0xdf, 0x7f, 0x37, 0xfc, 0xf1, 0x05 } /* expected */
}, {
false, /* encrypt */
0, /* key_size_index */
5, /* key_area */
{ 0x0b, 0x1e, 0x74, 0xf4, 0x5c, 0x17, 0xff, 0x30,
0x4d, 0x99, 0xc0, 0x59, 0xce, 0x5c, 0xde, 0x09 }, /* iv */
{ 0xd3, 0xf8, 0x9b, 0x71, 0xe0, 0x33, 0x07, 0x0f,
0x9d, 0x75, 0x16, 0xa6, 0xcb, 0x4e, 0xa5, 0xef,
0x51, 0xd6, 0xfb, 0x63, 0xd4, 0xf0, 0xfe, 0xa0,
0x89, 0xd0, 0xa6, 0x0e, 0x47, 0xbb, 0xb3, 0xc2,
0xe1, 0x0e, 0x9b, 0xa3, 0xb2, 0x82, 0xc7, 0xcb,
0x79, 0xae, 0xfe, 0x30, 0x68, 0xce, 0x22, 0x83,
0x77, 0xc2, 0x1a, 0x58, 0xfe, 0x5a, 0x0f, 0x88,
0x83, 0xd0, 0xdb, 0xd3, 0xd0, 0x96, 0xbe, 0xca }, /* mdata */
64, /* mdata_len */
{ 0xb9, 0x68, 0xae, 0xb1, 0x99, 0xad, 0x6b, 0x3c,
0x8e, 0x01, 0xf2, 0x6c, 0x2e, 0xda, 0xd4, 0x44,
0x53, 0x8c, 0x78, 0xbf, 0xa3, 0x6e, 0xd6, 0x8c,
0xa7, 0x61, 0x23, 0xb8, 0xcd, 0xce, 0x61, 0x5a,
0x01, 0xf6, 0x11, 0x2b, 0xb8, 0x0b, 0xfc, 0x3f,
0x17, 0x49, 0x05, 0x78, 0xfb, 0x1f, 0x90, 0x9a,
0x52, 0xe1, 0x62, 0x63, 0x7b, 0x06, 0x2d, 0xb0,
0x4e, 0xfe, 0xe2, 0x91, 0xa1, 0xf1, 0xaf, 0x60 } /* expected */
}, {
false, /* encrypt */
0, /* key_size_index */
6, /* key_area */
{ 0x68, 0xb9, 0x14, 0x0f, 0x30, 0x04, 0x90, 0xc5,
0xc9, 0x42, 0xf6, 0x6e, 0x77, 0x7e, 0xb8, 0x06 }, /* iv */
{ 0xc6, 0x5b, 0x94, 0xb1, 0xf2, 0x91, 0xfa, 0x9f,
0x06, 0x00, 0xf2, 0x2c, 0x3c, 0x04, 0x32, 0xc8,
0x95, 0xad, 0x5d, 0x17, 0x7b, 0xcc, 0xcc, 0x9e,
0xa4, 0x4e, 0x8e, 0xc3, 0x39, 0xc9, 0xad, 0xf4,
0x38, 0x55, 0xb3, 0x26, 0x17, 0x9d, 0x6d, 0x81,
0xaa, 0x36, 0xef, 0x59, 0x46, 0x2f, 0xd8, 0x61,
0x27, 0xe9, 0xd8, 0x1b, 0x0f, 0x28, 0x6f, 0x93,
0x30, 0x6b, 0xf7, 0x4d, 0x4c, 0x79, 0xe4, 0x7c,
0x1b, 0x3d, 0x4b, 0x74, 0xed, 0xd3, 0xa1, 0x62,
0x90, 0xe3, 0xc6, 0x3b, 0x74, 0x2e, 0x41, 0xf2,
0x0d, 0x66, 0xce, 0xee, 0x79, 0x43, 0x16, 0xbb,
0x63, 0xd3, 0xbd, 0x00, 0x27, 0x12, 0xa1, 0xb1,
0x36, 0xba, 0x61, 0x85, 0xbd, 0x5c, 0x1d, 0xab,
0x81, 0xb0, 0x7d, 0xb9, 0x0d, 0x2a, 0xf5, 0xe5 }, /* mdata */
112, /* mdata_len */
{ 0xc5, 0x58, 0x5f, 0xf2, 0x15, 0xbb, 0xb7, 0x3b,
0xa5, 0x39, 0x34, 0x40, 0x85, 0x2f, 0xb1, 0x99,
0x43, 0x6d, 0xe0, 0xd1, 0x5e, 0x55, 0xc6, 0x31,
0xf8, 0x77, 0x67, 0x0a, 0xa3, 0xed, 0xa9, 0xf6,
0x72, 0xeb, 0x1f, 0x87, 0x6f, 0x09, 0x54, 0x4e,
0x63, 0x55, 0x84, 0x36, 0xb8, 0x92, 0x80, 0x00,
0xdb, 0x2f, 0x02, 0xa5, 0xad, 0x90, 0xf9, 0x5b,
0x05, 0xac, 0x4c, 0xf4, 0x9e, 0x19, 0x8e, 0x61,
0x7e, 0x76, 0x78, 0x48, 0x0f, 0xdf, 0x0e, 0xfa,
0xcc, 0x6a, 0xae, 0x69, 0x12, 0x71, 0xe6, 0xcd,
0xd3, 0x54, 0x1e, 0xbf, 0x71, 0x9a, 0x1c, 0xca,
0xed, 0xb2, 0x4e, 0x2f, 0x80, 0xf9, 0x24, 0x55,
0xdd, 0x59, 0x10, 0xcb, 0x50, 0x86, 0xb0, 0x96,
0x0a, 0x39, 0x42, 0xec, 0x18, 0x2d, 0xcb, 0xd7 } /* expected */
}, {
false, /* encrypt */
0, /* key_size_index */
7, /* key_area */
{ 0xd4, 0xb4, 0xea, 0xb9, 0x2a, 0xa9, 0x63, 0x7e,
0x87, 0xd3, 0x66, 0x38, 0x4e, 0xd6, 0x91, 0x5c }, /* iv */
{ 0x22, 0xcd, 0xc3, 0x30, 0x6f, 0xcd, 0x4d, 0x31,
0xcc, 0xd3, 0x27, 0x20, 0xcb, 0xb6, 0x1b, 0xad,
0x28, 0xd8, 0x55, 0x67, 0x06, 0x57, 0xc4, 0x8c,
0x7b, 0x88, 0xc3, 0x1f, 0x4f, 0xa1, 0xf9, 0x3c,
0x01, 0xb5, 0x7d, 0xa9, 0x0b, 0xe6, 0x3e, 0xad,
0x67, 0xd6, 0xa3, 0x25, 0x52, 0x5e, 0x6e, 0xd4,
0x50, 0x83, 0xe6, 0xfb, 0x70, 0xa5, 0x35, 0x29,
0xd1, 0xfa, 0x0f, 0x55, 0x65, 0x3b, 0x94, 0x2a,
0xf5, 0x9d, 0x78, 0xa2, 0x66, 0x03, 0x61, 0xd6,
0x3a, 0x72, 0x90, 0x15, 0x5a, 0xc5, 0xc4, 0x33,
0x12, 0xa2, 0x5b, 0x23, 0x5d, 0xac, 0xbb, 0xc8,
0x63, 0xfa, 0xf0, 0x09, 0x40, 0xc9, 0x96, 0x24,
0x07, 0x6d, 0xfa, 0x44, 0x06, 0x8e, 0x7c, 0x55,
0x4c, 0x90, 0x38, 0x17, 0x69, 0x53, 0xe5, 0x71,
0x75, 0x1d, 0xfc, 0x09, 0x54, 0xd4, 0x1d, 0x11,
0x37, 0x71, 0xb0, 0x64, 0x66, 0xb1, 0xc8, 0xd1,
0x3e, 0x0d, 0x4c, 0xb6, 0x75, 0xed, 0x58, 0xd1,
0xa6, 0x19, 0xe1, 0x54, 0x09, 0x70, 0x98, 0x37,
0x81, 0xdc, 0x11, 0xd2, 0xdd, 0x85, 0x25, 0xab,
0x57, 0x45, 0x95, 0x8d, 0x61, 0x5d, 0xef, 0xda }, /* mdata */
160, /* mdata_len */
{ 0xe8, 0xb8, 0x91, 0x50, 0xd8, 0x43, 0x8b, 0xf5,
0xb1, 0x74, 0x49, 0xd6, 0xed, 0x26, 0xbd, 0x72,
0x12, 0x7e, 0x10, 0xe4, 0xaa, 0x57, 0xca, 0xd8,
0x52, 0x83, 0xe8, 0x35, 0x9e, 0x08, 0x92, 0x08,
0xe8, 0x49, 0x21, 0x64, 0x9f, 0x5b, 0x60, 0xea,
0x21, 0xf7, 0x86, 0x7c, 0xbc, 0x96, 0x20, 0x56,
0x0c, 0x4c, 0x62, 0x38, 0xdb, 0x02, 0x12, 0x16,
0xdb, 0x45, 0x3c, 0x99, 0x43, 0xf1, 0xf1, 0xa6,
0x05, 0x46, 0x17, 0x3d, 0xae, 0xf2, 0x55, 0x7c,
0x3c, 0xdd, 0x85, 0x50, 0x31, 0xb3, 0x53, 0xd4,
0xbf, 0x17, 0x6f, 0x28, 0x43, 0x9e, 0x48, 0x78,
0x5c, 0x37, 0xd3, 0x8f, 0x27, 0x0a, 0xa4, 0xa6,
0xfa, 0xad, 0x2b, 0xaa, 0xbc, 0xb0, 0xc0, 0xb2,
0xd1, 0xdd, 0x53, 0x22, 0x93, 0x74, 0x98, 0xce,
0x80, 0x3b, 0xa1, 0x14, 0x84, 0x40, 0xa5, 0x2e,
0x22, 0x7d, 0xdb, 0xa4, 0x87, 0x2f, 0xe4, 0xd8,
0x1d, 0x2d, 0x76, 0xa9, 0x39, 0xd2, 0x47, 0x55,
0xad, 0xb8, 0xa7, 0xb8, 0x45, 0x2c, 0xee, 0xd2,
0xd1, 0x79, 0xe1, 0xa5, 0x84, 0x8f, 0x31, 0x6f,
0x5c, 0x01, 0x63, 0x00, 0xa3, 0x90, 0xbf, 0xa7 } /* expected */
}, {
true, /* encrypt */
1, /* key_size_index */
0, /* key_area */
{ 0x53, 0x1c, 0xe7, 0x81, 0x76, 0x40, 0x16, 0x66,
0xaa, 0x30, 0xdb, 0x94, 0xec, 0x4a, 0x30, 0xeb }, /* iv */
{ 0xc5, 0x1f, 0xc2, 0x76, 0x77, 0x4d, 0xad, 0x94,
0xbc, 0xdc, 0x1d, 0x28, 0x91, 0xec, 0x86, 0x68 }, /* mdata */
16, /* mdata_len */
{ 0x70, 0xdd, 0x95, 0xa1, 0x4e, 0xe9, 0x75, 0xe2,
0x39, 0xdf, 0x36, 0xff, 0x4a, 0xee, 0x1d, 0x5d } /* expected */
}, {
true, /* encrypt */
1, /* key_size_index */
2, /* key_area */
{ 0x24, 0x40, 0x80, 0x38, 0x16, 0x1a, 0x2c, 0xca,
0xe0, 0x7b, 0x02, 0x9b, 0xb6, 0x63, 0x55, 0xc1 }, /* iv */
{ 0xbe, 0x8a, 0xbf, 0x00, 0x90, 0x13, 0x63, 0x98,
0x7a, 0x82, 0xcc, 0x77, 0xd0, 0xec, 0x91, 0x69,
0x7b, 0xa3, 0x85, 0x7f, 0x9e, 0x4f, 0x84, 0xbd,
0x79, 0x40, 0x6c, 0x13, 0x8d, 0x02, 0x69, 0x8f,
0x00, 0x32, 0x76, 0xd0, 0x44, 0x91, 0x20, 0xbe,
0xf4, 0x57, 0x8d, 0x78, 0xfe, 0xca, 0xbe, 0x8e,
0x07, 0x0e, 0x11, 0x71, 0x0b, 0x3f, 0x0a, 0x27,
0x44, 0xbd, 0x52, 0x43, 0x4e, 0xc7, 0x00, 0x15,
0x88, 0x4c, 0x18, 0x1e, 0xbd, 0xfd, 0x51, 0xc6,
0x04, 0xa7, 0x1c, 0x52, 0xe4, 0xc0, 0xe1, 0x10,
0xbc, 0x40, 0x8c, 0xd4, 0x62, 0xb2, 0x48, 0xa8,
0x0b, 0x8a, 0x8a, 0xc0, 0x6b, 0xb9, 0x52, 0xac,
0x1d, 0x7f, 0xae, 0xd1, 0x44, 0x80, 0x7f, 0x1a,
0x73, 0x1b, 0x7f, 0xeb, 0xca, 0xf7, 0x83, 0x57,
0x62, 0xde, 0xfe, 0x92, 0xec, 0xcf, 0xc7, 0xa9,
0x94, 0x4e, 0x1c, 0x70, 0x2c, 0xff, 0xe6, 0xbc,
0x86, 0x73, 0x3e, 0xd3, 0x21, 0x42, 0x31, 0x21,
0x08, 0x5a, 0xc0, 0x2d, 0xf8, 0x96, 0x2b, 0xcb,
0xc1, 0x93, 0x70, 0x92, 0xee, 0xbf, 0x0e, 0x90,
0xa8, 0xb2, 0x0e, 0x3d, 0xd8, 0xc2, 0x44, 0xae }, /* mdata */
160, /* mdata_len */
{ 0xc8, 0x2c, 0xf2, 0xc4, 0x76, 0xde, 0xa8, 0xcb,
0x6a, 0x6e, 0x60, 0x7a, 0x40, 0xd2, 0xf0, 0x39,
0x1b, 0xe8, 0x2e, 0xa9, 0xec, 0x84, 0xa5, 0x37,
0xa6, 0x82, 0x0f, 0x9a, 0xfb, 0x99, 0x7b, 0x76,
0x39, 0x7d, 0x00, 0x54, 0x24, 0xfa, 0xa6, 0xa7,
0x4d, 0xc4, 0xe8, 0xc7, 0xaa, 0x4a, 0x89, 0x00,
0x69, 0x0f, 0x89, 0x4b, 0x6d, 0x1d, 0xca, 0x80,
0x67, 0x53, 0x93, 0xd2, 0x24, 0x3a, 0xda, 0xc7,
0x62, 0xf1, 0x59, 0x30, 0x1e, 0x35, 0x7e, 0x98,
0xb7, 0x24, 0x76, 0x23, 0x10, 0xcd, 0x5a, 0x7b,
0xaf, 0xe1, 0xc2, 0xa0, 0x30, 0xdb, 0xa4, 0x6f,
0xd9, 0x3a, 0x9f, 0xdb, 0x89, 0xcc, 0x13, 0x2c,
0xa9, 0xc1, 0x7d, 0xc7, 0x20, 0x31, 0xec, 0x68,
0x22, 0xee, 0x5a, 0x9d, 0x99, 0xdb, 0xca, 0x66,
0xc7, 0x84, 0xc0, 0x1b, 0x08, 0x85, 0xcb, 0xb6,
0x2e, 0x29, 0xd9, 0x78, 0x01, 0x92, 0x7e, 0xc4,
0x15, 0xa5, 0xd2, 0x15, 0x15, 0x8d, 0x32, 0x5f,
0x9e, 0xe6, 0x89, 0x43, 0x7a, 0xd1, 0xb7, 0x68,
0x4a, 0xd3, 0x3c, 0x0d, 0x92, 0x73, 0x94, 0x51,
0xac, 0x87, 0xf3, 0x9f, 0xf8, 0xc3, 0x1b, 0x84 } /* expected */
}, {
false, /* encrypt */
1, /* key_size_index */
4, /* key_area */
{ 0x32, 0x40, 0x15, 0x87, 0x8c, 0xdc, 0x82, 0xbf,
0xae, 0x59, 0xa2, 0xdc, 0x1f, 0xf3, 0x4e, 0xa6 }, /* iv */
{ 0x39, 0xa9, 0xb4, 0x2d, 0xe1, 0x9e, 0x51, 0x2a,
0xb7, 0xf3, 0x04, 0x35, 0x64, 0xc3, 0x51, 0x5a }, /* mdata */
16, /* mdata_len */
{ 0xaa, 0x41, 0x17, 0x9d, 0x88, 0x0e, 0x6f, 0xe3,
0xb1, 0x48, 0x18, 0xd6, 0xe4, 0xa6, 0x2e, 0xb5 } /* expected */
}, {
false, /* encrypt */
1, /* key_size_index */
6, /* key_area */
{ 0xd6, 0xd8, 0x6e, 0x0c, 0x82, 0xdd, 0x87, 0x88,
0xf4, 0x14, 0x7a, 0x26, 0xf9, 0xa7, 0x1c, 0x74 }, /* iv */
{ 0x69, 0x28, 0x29, 0x9c, 0x52, 0xb4, 0xf0, 0x47,
0x92, 0x6f, 0x8a, 0x54, 0x15, 0x29, 0xda, 0x2d,
0x6b, 0xba, 0xa3, 0x99, 0x14, 0x3c, 0xed, 0x8e,
0xfb, 0x77, 0xab, 0x47, 0x40, 0x9d, 0x9a, 0x95,
0x3a, 0x38, 0x6c, 0x7a, 0xbd, 0x60, 0x26, 0xf4,
0x98, 0x31, 0xc7, 0x17, 0x62, 0x7c, 0x2a, 0x5e,
0x77, 0xbd, 0x2d, 0x43, 0x3d, 0x4d, 0x13, 0x0d,
0xac, 0xd9, 0x27, 0xea, 0x0d, 0x13, 0xa2, 0x3d,
0x01, 0xa7, 0xcf, 0x39, 0xc6, 0x71, 0x6d, 0xaf,
0xb6, 0xed, 0x55, 0x24, 0x10, 0xef, 0x5d, 0x27,
0xfb, 0x94, 0x7b, 0xe2, 0xc8, 0x78, 0x2e, 0xee,
0x78, 0x29, 0x19, 0x6c, 0x7e, 0xdc, 0xf1, 0x51,
0xc6, 0x5f, 0x9a, 0x01, 0xf5, 0x4f, 0x8d, 0x20,
0xf3, 0x8b, 0x7d, 0xa4, 0xa7, 0xe8, 0x3a, 0x2f,
0x01, 0x27, 0xd5, 0x9d, 0x3e, 0x24, 0x05, 0xd8,
0x67, 0x4f, 0xc9, 0xf4, 0x1b, 0x60, 0x4f, 0x78,
0x8f, 0x47, 0x15, 0xf9, 0xd3, 0x62, 0x4e, 0xee,
0x57, 0xf3, 0x87, 0xbf, 0xad, 0xd1, 0x8a, 0x1f,
0x90, 0x5e, 0x83, 0x9c, 0x26, 0xb8, 0x61, 0x74,
0x82, 0x34, 0x7f, 0xab, 0x6d, 0x08, 0x84, 0x5a }, /* mdata */
160, /* mdata_len */
{ 0x67, 0xd2, 0xdd, 0xa6, 0xda, 0x26, 0xe2, 0x13,
0x07, 0x97, 0x34, 0x00, 0x60, 0x07, 0x25, 0x72,
0x7a, 0xe8, 0x14, 0x15, 0x51, 0x17, 0x72, 0xf4,
0xa0, 0x9a, 0xd9, 0x90, 0x3b, 0xcf, 0x90, 0xcc,
0x2c, 0x0d, 0xac, 0x58, 0xba, 0x55, 0x9a, 0x01,
0x09, 0xc5, 0x4a, 0x9d, 0x61, 0x17, 0xb1, 0x5b,
0xb5, 0x74, 0xca, 0x47, 0x3e, 0x84, 0x80, 0x47,
0xe9, 0xa5, 0x4e, 0xe4, 0xab, 0xde, 0x76, 0xaf,
0xf9, 0x84, 0x9c, 0x44, 0x10, 0x9d, 0x16, 0x1f,
0x46, 0x44, 0x2e, 0x16, 0x10, 0xd8, 0xb0, 0x15,
0xcf, 0x36, 0xa0, 0x10, 0xed, 0x8e, 0xfa, 0x32,
0x07, 0xfd, 0xfc, 0x8f, 0xcc, 0x54, 0x8f, 0x14,
0x5c, 0x02, 0x7e, 0x44, 0xc5, 0xb0, 0xec, 0x35,
0xc9, 0x88, 0x6f, 0x4b, 0x9d, 0x65, 0x13, 0xa5,
0xbc, 0x10, 0xd0, 0xea, 0x6b, 0xbb, 0xc2, 0x6f,
0x54, 0xb1, 0x83, 0xbc, 0xae, 0x27, 0xfb, 0x79,
0x9d, 0x88, 0x72, 0xff, 0x74, 0x8f, 0xc4, 0x59,
0xd5, 0x5c, 0xfa, 0x25, 0x5a, 0xae, 0x29, 0xd7,
0x1b, 0x07, 0x6d, 0x9b, 0x44, 0xc1, 0x4d, 0x5c,
0xeb, 0xa9, 0x33, 0x2a, 0x76, 0x3d, 0x9c, 0x94 } /* expected */
}, {
true, /* encrypt */
2, /* key_size_index */
0, /* key_area */
{ 0x85, 0x1e, 0x87, 0x64, 0x77, 0x6e, 0x67, 0x96,
0xaa, 0xb7, 0x22, 0xdb, 0xb6, 0x44, 0xac, 0xe8 }, /* iv */
{ 0x62, 0x82, 0xb8, 0xc0, 0x5c, 0x5c, 0x15, 0x30,
0xb9, 0x7d, 0x48, 0x16, 0xca, 0x43, 0x47, 0x62 }, /* mdata */
16, /* mdata_len */
{ 0x6a, 0xcc, 0x04, 0x14, 0x2e, 0x10, 0x0a, 0x65,
0xf5, 0x1b, 0x97, 0xad, 0xf5, 0x17, 0x2c, 0x41 } /* expected */
}, {
true, /* encrypt */
2, /* key_size_index */
2, /* key_area */
{ 0xd6, 0xd5, 0x81, 0xb8, 0xcf, 0x04, 0xeb, 0xd3,
0xb6, 0xea, 0xa1, 0xb5, 0x3f, 0x04, 0x7e, 0xe1 }, /* iv */
{ 0x0c, 0x63, 0xd4, 0x13, 0xd3, 0x86, 0x45, 0x70,
0xe7, 0x0b, 0xb6, 0x61, 0x8b, 0xf8, 0xa4, 0xb9,
0x58, 0x55, 0x86, 0x68, 0x8c, 0x32, 0xbb, 0xa0,
0xa5, 0xec, 0xc1, 0x36, 0x2f, 0xad, 0xa7, 0x4a,
0xda, 0x32, 0xc5, 0x2a, 0xcf, 0xd1, 0xaa, 0x74,
0x44, 0xba, 0x56, 0x7b, 0x4e, 0x7d, 0xaa, 0xec,
0xf7, 0xcc, 0x1c, 0xb2, 0x91, 0x82, 0xaf, 0x16,
0x4a, 0xe5, 0x23, 0x2b, 0x00, 0x28, 0x68, 0x69,
0x56, 0x35, 0x59, 0x98, 0x07, 0xa9, 0xa7, 0xf0,
0x7a, 0x1f, 0x13, 0x7e, 0x97, 0xb1, 0xe1, 0xc9,
0xda, 0xbc, 0x89, 0xb6, 0xa5, 0xe4, 0xaf, 0xa9,
0xdb, 0x58, 0x55, 0xed, 0xaa, 0x57, 0x50, 0x56,
0xa8, 0xf4, 0xf8, 0x24, 0x22, 0x16, 0x24, 0x2b,
0xb0, 0xc2, 0x56, 0x31, 0x0d, 0x9d, 0x32, 0x98,
0x26, 0xac, 0x35, 0x3d, 0x71, 0x5f, 0xa3, 0x9f,
0x80, 0xce, 0xc1, 0x44, 0xd6, 0x42, 0x45, 0x58,
0xf9, 0xf7, 0x0b, 0x98, 0xc9, 0x20, 0x09, 0x6e,
0x0f, 0x2c, 0x85, 0x5d, 0x59, 0x48, 0x85, 0xa0,
0x06, 0x25, 0x88, 0x0e, 0x9d, 0xfb, 0x73, 0x41,
0x63, 0xce, 0xce, 0xf7, 0x2c, 0xf0, 0x30, 0xb8 }, /* mdata */
160, /* mdata_len */
{ 0xfc, 0x58, 0x73, 0xe5, 0x0d, 0xe8, 0xfa, 0xf4,
0xc6, 0xb8, 0x4b, 0xa7, 0x07, 0xb0, 0x85, 0x4e,
0x9d, 0xb9, 0xab, 0x2e, 0x9f, 0x7d, 0x70, 0x7f,
0xbb, 0xa3, 0x38, 0xc6, 0x84, 0x3a, 0x18, 0xfc,
0x6f, 0xac, 0xeb, 0xaf, 0x66, 0x3d, 0x26, 0x29,
0x6f, 0xb3, 0x29, 0xb4, 0xd2, 0x6f, 0x18, 0x49,
0x4c, 0x79, 0xe0, 0x9e, 0x77, 0x96, 0x47, 0xf9,
0xba, 0xfa, 0x87, 0x48, 0x96, 0x30, 0xd7, 0x9f,
0x43, 0x01, 0x61, 0x0c, 0x23, 0x00, 0xc1, 0x9d,
0xbf, 0x31, 0x48, 0xb7, 0xca, 0xc8, 0xc4, 0xf4,
0x94, 0x41, 0x02, 0x75, 0x4f, 0x33, 0x2e, 0x92,
0xb6, 0xf7, 0xc5, 0xe7, 0x5b, 0xc6, 0x17, 0x9e,
0xb8, 0x77, 0xa0, 0x78, 0xd4, 0x71, 0x90, 0x09,
0x02, 0x17, 0x44, 0xc1, 0x4f, 0x13, 0xfd, 0x2a,
0x55, 0xa2, 0xb9, 0xc4, 0x4d, 0x18, 0x00, 0x06,
0x85, 0xa8, 0x45, 0xa4, 0xf6, 0x32, 0xc7, 0xc5,
0x6a, 0x77, 0x30, 0x6e, 0xfa, 0x66, 0xa2, 0x4d,
0x05, 0xd0, 0x88, 0xdc, 0xd7, 0xc1, 0x3f, 0xe2,
0x4f, 0xc4, 0x47, 0x27, 0x59, 0x65, 0xdb, 0x9e,
0x4d, 0x37, 0xfb, 0xc9, 0x30, 0x44, 0x48, 0xcd } /* expected */
}, {
false, /* encrypt */
2, /* key_size_index */
4, /* key_area */
{ 0xdd, 0xbb, 0xb0, 0x17, 0x3f, 0x1e, 0x2d, 0xeb,
0x23, 0x94, 0xa6, 0x2a, 0xa2, 0xa0, 0x24, 0x0e }, /* iv */
{ 0xd5, 0x1d, 0x19, 0xde, 0xd5, 0xca, 0x4a, 0xe1,
0x4b, 0x2b, 0x20, 0xb0, 0x27, 0xff, 0xb0, 0x20 }, /* mdata */
16, /* mdata_len */
{ 0x07, 0x27, 0x0d, 0x0e, 0x63, 0xaa, 0x36, 0xda,
0xed, 0x8c, 0x6a, 0xde, 0x13, 0xac, 0x1a, 0xf1 } /* expected */
}, {
false, /* encrypt */
2, /* key_size_index */
6, /* key_area */
{ 0xe4, 0x96, 0x51, 0x98, 0x8e, 0xbb, 0xb7, 0x2e,
0xb8, 0xbb, 0x80, 0xbb, 0x9a, 0xbb, 0xca, 0x34 }, /* iv */
{ 0x5b, 0x97, 0xa9, 0xd4, 0x23, 0xf4, 0xb9, 0x74,
0x13, 0xf3, 0x88, 0xd9, 0xa3, 0x41, 0xe7, 0x27,
0xbb, 0x33, 0x9f, 0x8e, 0x18, 0xa3, 0xfa, 0xc2,
0xf2, 0xfb, 0x85, 0xab, 0xdc, 0x8f, 0x13, 0x5d,
0xeb, 0x30, 0x05, 0x4a, 0x1a, 0xfd, 0xc9, 0xb6,
0xed, 0x7d, 0xa1, 0x6c, 0x55, 0xeb, 0xa6, 0xb0,
0xd4, 0xd1, 0x0c, 0x74, 0xe1, 0xd9, 0xa7, 0xcf,
0x8e, 0xdf, 0xae, 0xaa, 0x68, 0x4a, 0xc0, 0xbd,
0x9f, 0x9d, 0x24, 0xba, 0x67, 0x49, 0x55, 0xc7,
0x9d, 0xc6, 0xbe, 0x32, 0xae, 0xe1, 0xc2, 0x60,
0xb5, 0x58, 0xff, 0x07, 0xe3, 0xa4, 0xd4, 0x9d,
0x24, 0x16, 0x20, 0x11, 0xff, 0x25, 0x4d, 0xb8,
0xbe, 0x07, 0x8e, 0x8a, 0xd0, 0x7e, 0x64, 0x8e,
0x6b, 0xf5, 0x67, 0x93, 0x76, 0xcb, 0x43, 0x21,
0xa5, 0xef, 0x01, 0xaf, 0xe6, 0xad, 0x88, 0x16,
0xfc, 0xc7, 0x63, 0x46, 0x69, 0xc8, 0xc4, 0x38,
0x92, 0x95, 0xc9, 0x24, 0x1e, 0x45, 0xff, 0xf3,
0x9f, 0x32, 0x25, 0xf7, 0x74, 0x50, 0x32, 0xda,
0xee, 0xbe, 0x99, 0xd4, 0xb1, 0x9b, 0xcb, 0x21,
0x5d, 0x1b, 0xfd, 0xb3, 0x6e, 0xda, 0x2c, 0x24 }, /* mdata */
160, /* mdata_len */
{ 0xbf, 0xe5, 0xc6, 0x35, 0x4b, 0x7a, 0x3f, 0xf3,
0xe1, 0x92, 0xe0, 0x57, 0x75, 0xb9, 0xb7, 0x58,
0x07, 0xde, 0x12, 0xe3, 0x8a, 0x62, 0x6b, 0x8b,
0xf0, 0xe1, 0x2d, 0x5f, 0xff, 0x78, 0xe4, 0xf1,
0x77, 0x5a, 0xa7, 0xd7, 0x92, 0xd8, 0x85, 0x16,
0x2e, 0x66, 0xd8, 0x89, 0x30, 0xf9, 0xc3, 0xb2,
0xcd, 0xf8, 0x65, 0x4f, 0x56, 0x97, 0x25, 0x04,
0x80, 0x31, 0x90, 0x38, 0x62, 0x70, 0xf0, 0xaa,
0x43, 0x64, 0x5d, 0xb1, 0x87, 0xaf, 0x41, 0xfc,
0xea, 0x63, 0x9b, 0x1f, 0x80, 0x26, 0xcc, 0xdd,
0x0c, 0x23, 0xe0, 0xde, 0x37, 0x09, 0x4a, 0x8b,
0x94, 0x1e, 0xcb, 0x76, 0x02, 0x99, 0x8a, 0x4b,
0x26, 0x04, 0xe6, 0x9f, 0xc0, 0x42, 0x19, 0x58,
0x5d, 0x85, 0x46, 0x00, 0xe0, 0xad, 0x6f, 0x99,
0xa5, 0x3b, 0x25, 0x04, 0x04, 0x3c, 0x08, 0xb1,
0xc3, 0xe2, 0x14, 0xd1, 0x7c, 0xde, 0x05, 0x3c,
0xbd, 0xf9, 0x1d, 0xaa, 0x99, 0x9e, 0xd5, 0xb4,
0x7c, 0x37, 0x98, 0x3b, 0xa3, 0xee, 0x25, 0x4b,
0xc5, 0xc7, 0x93, 0x83, 0x7d, 0xaa, 0xa8, 0xc8,
0x5c, 0xfc, 0x12, 0xf7, 0xf5, 0x4f, 0x69, 0x9f } /* expected */
}
};
static uint8_t mdata[MDATA_MAX_LEN];
static int i;
static uint8_t key_size_index = -1, ret;
static int8_t res;
static rtimer_clock_t time, time2, total_time;
PROCESS_BEGIN();
puts("-----------------------------------------\n"
"Initializing cryptoprocessor...");
crypto_init();
for(i = 0; i < sizeof(vectors) / sizeof(vectors[0]); i++) {
if(key_size_index != vectors[i].key_size_index) {
key_size_index = vectors[i].key_size_index;
printf("-----------------------------------------\n"
"Filling %d-bit key store...\n", 128 + (key_size_index << 6));
time = RTIMER_NOW();
ret = aes_load_keys(keys[key_size_index].keys,
keys[key_size_index].key_size, keys[key_size_index].count, 0);
time = RTIMER_NOW() - time;
printf("aes_load_keys(): %s, %lu us\n", str_res[ret],
(uint32_t)((uint64_t)time * 1000000 / RTIMER_SECOND));
PROCESS_PAUSE();
if(ret != CRYPTO_SUCCESS) {
break;
}
}
printf("-----------------------------------------\n"
"Test vector #%d: %s\n"
"key_area=%d mdata_len=%d\n",
i, vectors[i].encrypt ? "encrypt" : "decrypt",
vectors[i].key_area, vectors[i].mdata_len);
/* mdata has to be in SRAM. */
rom_util_memcpy(mdata, vectors[i].mdata, vectors[i].mdata_len);
time = RTIMER_NOW();
ret = cbc_crypt_start(vectors[i].encrypt, vectors[i].key_area,
vectors[i].iv, mdata, mdata, vectors[i].mdata_len,
&cbc_test_process);
time2 = RTIMER_NOW();
time = time2 - time;
total_time = time;
if(ret == CRYPTO_SUCCESS) {
PROCESS_WAIT_EVENT_UNTIL((res = cbc_crypt_check_status()) !=
CRYPTO_PENDING);
time2 = RTIMER_NOW() - time2;
total_time += time2;
}
printf("cbc_crypt_start(): %s, %lu us\n", str_res[ret],
(uint32_t)((uint64_t)time * 1000000 / RTIMER_SECOND));
if(ret != CRYPTO_SUCCESS) {
PROCESS_PAUSE();
continue;
}
printf("cbc_crypt_check_status() wait: %s, %lu us\n", str_res[res],
(uint32_t)((uint64_t)time2 * 1000000 / RTIMER_SECOND));
PROCESS_PAUSE();
if(res != CRYPTO_SUCCESS) {
continue;
}
if(rom_util_memcmp(mdata, vectors[i].expected, vectors[i].mdata_len)) {
puts("Output message does not match expected one");
} else {
puts("Output message OK");
}
printf("Total duration: %lu us\n",
(uint32_t)((uint64_t)total_time * 1000000 / RTIMER_SECOND));
}
puts("-----------------------------------------\n"
"Disabling cryptoprocessor...");
crypto_disable();
puts("Done!");
PROCESS_END();
}
/*---------------------------------------------------------------------------*/
/**
* @}
* @}
*/

View file

@ -0,0 +1,352 @@
/*
* Copyright (c) 2015, Benoît Thébaudeau <benoit.thebaudeau.dev@gmail.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* \addtogroup cc2538-examples
* @{
*
* \defgroup cc2538-ctr-test cc2538dk AES-CTR Test Project
*
* AES-CTR access example for CC2538 on SmartRF06EB.
*
* This example shows how AES-CTR should be used. The example also verifies
* the AES-CTR functionality.
*
* @{
*
* \file
* Example demonstrating AES-CTR on the cc2538dk platform
*/
#include "contiki.h"
#include "sys/rtimer.h"
#include "dev/rom-util.h"
#include "dev/ctr.h"
#include <stdbool.h>
#include <stdio.h>
#include <stdint.h>
/*---------------------------------------------------------------------------*/
#define NONCE_MAX_LEN 0
#define ICTR_MAX_LEN 16
#define MDATA_MAX_LEN 64
/*---------------------------------------------------------------------------*/
PROCESS(ctr_test_process, "ctr test process");
AUTOSTART_PROCESSES(&ctr_test_process);
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(ctr_test_process, ev, data)
{
static const char *const str_res[] = {
"success",
"invalid param",
"NULL error",
"resource in use",
"DMA bus error",
"keystore read error",
"keystore write error",
"authentication failed"
};
static const uint8_t keys128[][128 / 8] = {
{ 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c }
};
static const uint8_t keys192[][192 / 8] = {
{ 0x8e, 0x73, 0xb0, 0xf7, 0xda, 0x0e, 0x64, 0x52,
0xc8, 0x10, 0xf3, 0x2b, 0x80, 0x90, 0x79, 0xe5,
0x62, 0xf8, 0xea, 0xd2, 0x52, 0x2c, 0x6b, 0x7b }
};
static const uint8_t keys256[][256 / 8] = {
{ 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe,
0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81,
0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7,
0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4 }
};
static const struct {
const void *keys;
uint8_t key_size;
uint8_t count;
} keys[] = {
{ keys128, AES_KEY_STORE_SIZE_KEY_SIZE_128,
sizeof(keys128) / sizeof(keys128[0]) },
{ keys192, AES_KEY_STORE_SIZE_KEY_SIZE_192,
sizeof(keys192) / sizeof(keys192[0]) },
{ keys256, AES_KEY_STORE_SIZE_KEY_SIZE_256,
sizeof(keys256) / sizeof(keys256[0]) }
};
static const struct {
bool encrypt;
uint8_t key_size_index;
uint8_t key_area;
uint8_t nonce[NONCE_MAX_LEN];
uint8_t ictr[ICTR_MAX_LEN];
uint8_t ctr_len;
uint8_t mdata[MDATA_MAX_LEN];
uint16_t mdata_len;
uint8_t expected[MDATA_MAX_LEN];
} vectors[] = {
{
true, /* encrypt */
0, /* key_size_index */
0, /* key_area */
{}, /* nonce */
{ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff }, /* ictr */
16, /* ctr_len */
{ 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11,
0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17,
0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10 }, /* mdata */
64, /* mdata_len */
{ 0x87, 0x4d, 0x61, 0x91, 0xb6, 0x20, 0xe3, 0x26,
0x1b, 0xef, 0x68, 0x64, 0x99, 0x0d, 0xb6, 0xce,
0x98, 0x06, 0xf6, 0x6b, 0x79, 0x70, 0xfd, 0xff,
0x86, 0x17, 0x18, 0x7b, 0xb9, 0xff, 0xfd, 0xff,
0x5a, 0xe4, 0xdf, 0x3e, 0xdb, 0xd5, 0xd3, 0x5e,
0x5b, 0x4f, 0x09, 0x02, 0x0d, 0xb0, 0x3e, 0xab,
0x1e, 0x03, 0x1d, 0xda, 0x2f, 0xbe, 0x03, 0xd1,
0x79, 0x21, 0x70, 0xa0, 0xf3, 0x00, 0x9c, 0xee } /* expected */
}, {
false, /* encrypt */
0, /* key_size_index */
0, /* key_area */
{}, /* nonce */
{ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff }, /* ictr */
16, /* ctr_len */
{ 0x87, 0x4d, 0x61, 0x91, 0xb6, 0x20, 0xe3, 0x26,
0x1b, 0xef, 0x68, 0x64, 0x99, 0x0d, 0xb6, 0xce,
0x98, 0x06, 0xf6, 0x6b, 0x79, 0x70, 0xfd, 0xff,
0x86, 0x17, 0x18, 0x7b, 0xb9, 0xff, 0xfd, 0xff,
0x5a, 0xe4, 0xdf, 0x3e, 0xdb, 0xd5, 0xd3, 0x5e,
0x5b, 0x4f, 0x09, 0x02, 0x0d, 0xb0, 0x3e, 0xab,
0x1e, 0x03, 0x1d, 0xda, 0x2f, 0xbe, 0x03, 0xd1,
0x79, 0x21, 0x70, 0xa0, 0xf3, 0x00, 0x9c, 0xee }, /* mdata */
64, /* mdata_len */
{ 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11,
0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17,
0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10 } /* expected */
}, {
true, /* encrypt */
1, /* key_size_index */
0, /* key_area */
{}, /* nonce */
{ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff }, /* ictr */
16, /* ctr_len */
{ 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11,
0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17,
0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10 }, /* mdata */
64, /* mdata_len */
{ 0x1a, 0xbc, 0x93, 0x24, 0x17, 0x52, 0x1c, 0xa2,
0x4f, 0x2b, 0x04, 0x59, 0xfe, 0x7e, 0x6e, 0x0b,
0x09, 0x03, 0x39, 0xec, 0x0a, 0xa6, 0xfa, 0xef,
0xd5, 0xcc, 0xc2, 0xc6, 0xf4, 0xce, 0x8e, 0x94,
0x1e, 0x36, 0xb2, 0x6b, 0xd1, 0xeb, 0xc6, 0x70,
0xd1, 0xbd, 0x1d, 0x66, 0x56, 0x20, 0xab, 0xf7,
0x4f, 0x78, 0xa7, 0xf6, 0xd2, 0x98, 0x09, 0x58,
0x5a, 0x97, 0xda, 0xec, 0x58, 0xc6, 0xb0, 0x50 } /* expected */
}, {
false, /* encrypt */
1, /* key_size_index */
0, /* key_area */
{}, /* nonce */
{ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff }, /* ictr */
16, /* ctr_len */
{ 0x1a, 0xbc, 0x93, 0x24, 0x17, 0x52, 0x1c, 0xa2,
0x4f, 0x2b, 0x04, 0x59, 0xfe, 0x7e, 0x6e, 0x0b,
0x09, 0x03, 0x39, 0xec, 0x0a, 0xa6, 0xfa, 0xef,
0xd5, 0xcc, 0xc2, 0xc6, 0xf4, 0xce, 0x8e, 0x94,
0x1e, 0x36, 0xb2, 0x6b, 0xd1, 0xeb, 0xc6, 0x70,
0xd1, 0xbd, 0x1d, 0x66, 0x56, 0x20, 0xab, 0xf7,
0x4f, 0x78, 0xa7, 0xf6, 0xd2, 0x98, 0x09, 0x58,
0x5a, 0x97, 0xda, 0xec, 0x58, 0xc6, 0xb0, 0x50 }, /* mdata */
64, /* mdata_len */
{ 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11,
0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17,
0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10 } /* expected */
}, {
true, /* encrypt */
2, /* key_size_index */
0, /* key_area */
{}, /* nonce */
{ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff }, /* ictr */
16, /* ctr_len */
{ 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11,
0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17,
0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10 }, /* mdata */
64, /* mdata_len */
{ 0x60, 0x1e, 0xc3, 0x13, 0x77, 0x57, 0x89, 0xa5,
0xb7, 0xa7, 0xf5, 0x04, 0xbb, 0xf3, 0xd2, 0x28,
0xf4, 0x43, 0xe3, 0xca, 0x4d, 0x62, 0xb5, 0x9a,
0xca, 0x84, 0xe9, 0x90, 0xca, 0xca, 0xf5, 0xc5,
0x2b, 0x09, 0x30, 0xda, 0xa2, 0x3d, 0xe9, 0x4c,
0xe8, 0x70, 0x17, 0xba, 0x2d, 0x84, 0x98, 0x8d,
0xdf, 0xc9, 0xc5, 0x8d, 0xb6, 0x7a, 0xad, 0xa6,
0x13, 0xc2, 0xdd, 0x08, 0x45, 0x79, 0x41, 0xa6 } /* expected */
}, {
false, /* encrypt */
2, /* key_size_index */
0, /* key_area */
{}, /* nonce */
{ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff }, /* ictr */
16, /* ctr_len */
{ 0x60, 0x1e, 0xc3, 0x13, 0x77, 0x57, 0x89, 0xa5,
0xb7, 0xa7, 0xf5, 0x04, 0xbb, 0xf3, 0xd2, 0x28,
0xf4, 0x43, 0xe3, 0xca, 0x4d, 0x62, 0xb5, 0x9a,
0xca, 0x84, 0xe9, 0x90, 0xca, 0xca, 0xf5, 0xc5,
0x2b, 0x09, 0x30, 0xda, 0xa2, 0x3d, 0xe9, 0x4c,
0xe8, 0x70, 0x17, 0xba, 0x2d, 0x84, 0x98, 0x8d,
0xdf, 0xc9, 0xc5, 0x8d, 0xb6, 0x7a, 0xad, 0xa6,
0x13, 0xc2, 0xdd, 0x08, 0x45, 0x79, 0x41, 0xa6 }, /* mdata */
64, /* mdata_len */
{ 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11,
0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17,
0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10 } /* expected */
}
};
static uint8_t mdata[MDATA_MAX_LEN];
static int i;
static uint8_t key_size_index = -1, ret;
static int8_t res;
static rtimer_clock_t time, time2, total_time;
PROCESS_BEGIN();
puts("-----------------------------------------\n"
"Initializing cryptoprocessor...");
crypto_init();
for(i = 0; i < sizeof(vectors) / sizeof(vectors[0]); i++) {
if(key_size_index != vectors[i].key_size_index) {
key_size_index = vectors[i].key_size_index;
printf("-----------------------------------------\n"
"Filling %d-bit key store...\n", 128 + (key_size_index << 6));
time = RTIMER_NOW();
ret = aes_load_keys(keys[key_size_index].keys,
keys[key_size_index].key_size, keys[key_size_index].count, 0);
time = RTIMER_NOW() - time;
printf("aes_load_keys(): %s, %lu us\n", str_res[ret],
(uint32_t)((uint64_t)time * 1000000 / RTIMER_SECOND));
PROCESS_PAUSE();
if(ret != CRYPTO_SUCCESS) {
break;
}
}
printf("-----------------------------------------\n"
"Test vector #%d: %s\n"
"key_area=%d ctr_len=%d mdata_len=%d\n",
i, vectors[i].encrypt ? "encrypt" : "decrypt",
vectors[i].key_area, vectors[i].ctr_len, vectors[i].mdata_len);
/* mdata has to be in SRAM. */
rom_util_memcpy(mdata, vectors[i].mdata, vectors[i].mdata_len);
time = RTIMER_NOW();
ret = ctr_crypt_start(vectors[i].encrypt, vectors[i].key_area,
vectors[i].nonce, vectors[i].ictr, vectors[i].ctr_len,
mdata, mdata, vectors[i].mdata_len,
&ctr_test_process);
time2 = RTIMER_NOW();
time = time2 - time;
total_time = time;
if(ret == CRYPTO_SUCCESS) {
PROCESS_WAIT_EVENT_UNTIL((res = ctr_crypt_check_status()) !=
CRYPTO_PENDING);
time2 = RTIMER_NOW() - time2;
total_time += time2;
}
printf("ctr_crypt_start(): %s, %lu us\n", str_res[ret],
(uint32_t)((uint64_t)time * 1000000 / RTIMER_SECOND));
if(ret != CRYPTO_SUCCESS) {
PROCESS_PAUSE();
continue;
}
printf("ctr_crypt_check_status() wait: %s, %lu us\n", str_res[res],
(uint32_t)((uint64_t)time2 * 1000000 / RTIMER_SECOND));
PROCESS_PAUSE();
if(res != CRYPTO_SUCCESS) {
continue;
}
if(rom_util_memcmp(mdata, vectors[i].expected, vectors[i].mdata_len)) {
puts("Output message does not match expected one");
} else {
puts("Output message OK");
}
printf("Total duration: %lu us\n",
(uint32_t)((uint64_t)total_time * 1000000 / RTIMER_SECOND));
}
puts("-----------------------------------------\n"
"Disabling cryptoprocessor...");
crypto_disable();
puts("Done!");
PROCESS_END();
}
/*---------------------------------------------------------------------------*/
/**
* @}
* @}
*/

View file

@ -0,0 +1,669 @@
/*
* Copyright (c) 2015, Benoît Thébaudeau <benoit.thebaudeau.dev@gmail.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* \addtogroup cc2538-examples
* @{
*
* \defgroup cc2538-gcm-test cc2538dk AES-GCM Test Project
*
* AES-GCM access example for CC2538 on SmartRF06EB.
*
* This example shows how AES-GCM should be used. The example also verifies
* the AES-GCM functionality.
*
* @{
*
* \file
* Example demonstrating AES-GCM on the cc2538dk platform
*/
#include "contiki.h"
#include "sys/rtimer.h"
#include "dev/rom-util.h"
#include "dev/gcm.h"
#include <stdbool.h>
#include <stdio.h>
#include <stdint.h>
/*---------------------------------------------------------------------------*/
#define ADATA_MAX_LEN 90
#define MDATA_MAX_LEN 51
/*---------------------------------------------------------------------------*/
PROCESS(gcm_test_process, "gcm test process");
AUTOSTART_PROCESSES(&gcm_test_process);
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(gcm_test_process, ev, data)
{
static const char *const str_res[] = {
"success",
"invalid param",
"NULL error",
"resource in use",
"DMA bus error",
"keystore read error",
"keystore write error",
"authentication failed"
};
static const uint8_t keys128[][128 / 8] = {
{ 0x2f, 0xb4, 0x5e, 0x5b, 0x8f, 0x99, 0x3a, 0x2b,
0xfe, 0xbc, 0x4b, 0x15, 0xb5, 0x33, 0xe0, 0xb4 },
{ 0xc9, 0x39, 0xcc, 0x13, 0x39, 0x7c, 0x1d, 0x37,
0xde, 0x6a, 0xe0, 0xe1, 0xcb, 0x7c, 0x42, 0x3c },
{ 0xfe, 0x01, 0x21, 0xf4, 0x2e, 0x59, 0x9f, 0x88,
0xff, 0x02, 0xa9, 0x85, 0x40, 0x3e, 0x19, 0xbb },
{ 0x99, 0x71, 0x07, 0x10, 0x59, 0xab, 0xc0, 0x09,
0xe4, 0xf2, 0xbd, 0x69, 0x86, 0x9d, 0xb3, 0x38 },
{ 0x76, 0x2d, 0xa5, 0x8b, 0xb0, 0x00, 0xf5, 0xd4,
0x99, 0x81, 0x8b, 0xc8, 0x59, 0x98, 0x9a, 0x30 },
{ 0x30, 0x0b, 0x8f, 0xfa, 0xb4, 0x36, 0x8c, 0xc9,
0x0f, 0x6d, 0x40, 0x63, 0xe4, 0x27, 0x9f, 0x2a },
{ 0xef, 0x1d, 0xa9, 0xdd, 0x79, 0x42, 0x19, 0xeb,
0xf8, 0xf7, 0x17, 0xd5, 0xa9, 0x8a, 0xb0, 0xaf },
{ 0x93, 0xae, 0x11, 0x40, 0x52, 0xb7, 0x98, 0x5d,
0x40, 0x9a, 0x39, 0xa4, 0x0d, 0xf8, 0xc7, 0xee }
};
static const uint8_t keys192[][192 / 8] = {
{ 0x5d, 0xaa, 0x89, 0x10, 0xd9, 0xdc, 0x50, 0x68,
0xf2, 0xf5, 0x5c, 0x16, 0x39, 0x86, 0xd0, 0x71,
0x45, 0x23, 0x44, 0xa5, 0xea, 0xc5, 0xa8, 0x05 },
{ 0x1b, 0x8f, 0xef, 0x01, 0xcf, 0x6e, 0xfa, 0xbc,
0x2c, 0x7c, 0xff, 0x16, 0xff, 0x67, 0xa3, 0x30,
0x13, 0xf0, 0x62, 0x9a, 0x0a, 0xd9, 0x36, 0x95 },
{ 0x51, 0x9d, 0xdb, 0xcf, 0xb3, 0x41, 0x1c, 0x75,
0x39, 0xdf, 0x0b, 0x61, 0xff, 0x2b, 0x3e, 0x3d,
0x2b, 0x6a, 0xd8, 0xf0, 0x30, 0xcd, 0xdc, 0xc2 },
{ 0x9b, 0x37, 0xbf, 0x6b, 0x0a, 0xa8, 0xff, 0x75,
0xf3, 0x04, 0xed, 0xa7, 0xa9, 0x51, 0x2d, 0xba,
0x7c, 0x9f, 0x80, 0xd6, 0x1e, 0x29, 0x5e, 0x85 }
};
static const uint8_t keys256[][256 / 8] = {
{ 0xdc, 0x77, 0x6f, 0x01, 0x56, 0xc1, 0x5d, 0x03,
0x26, 0x23, 0x85, 0x4b, 0x62, 0x5c, 0x61, 0x86,
0x8e, 0x5d, 0xb8, 0x4b, 0x7b, 0x6f, 0x9f, 0xbd,
0x36, 0x72, 0xf1, 0x2f, 0x00, 0x25, 0xe0, 0xf6 },
{ 0x14, 0x85, 0x79, 0xa3, 0xcb, 0xca, 0x86, 0xd5,
0x52, 0x0d, 0x66, 0xc0, 0xec, 0x71, 0xca, 0x5f,
0x7e, 0x41, 0xba, 0x78, 0xe5, 0x6d, 0xc6, 0xee,
0xbd, 0x56, 0x6f, 0xed, 0x54, 0x7f, 0xe6, 0x91 },
{ 0x42, 0xf6, 0xc2, 0x51, 0x59, 0xb8, 0x65, 0x53,
0x80, 0xf0, 0x52, 0xdd, 0x5d, 0xad, 0x18, 0x0e,
0x76, 0x81, 0x3b, 0x60, 0xeb, 0x81, 0x36, 0x65,
0xc5, 0x01, 0x5f, 0x26, 0xcf, 0x32, 0xe8, 0xf1 },
{ 0x5f, 0x72, 0x04, 0x62, 0x45, 0xd3, 0xf4, 0xa0,
0x87, 0x7e, 0x50, 0xa8, 0x65, 0x54, 0xbf, 0xd5,
0x7d, 0x1c, 0x5e, 0x07, 0x3d, 0x1e, 0xd3, 0xb5,
0x45, 0x1f, 0x6d, 0x0f, 0xc2, 0xa8, 0x50, 0x7a }
};
static const struct {
const void *keys;
uint8_t key_size;
uint8_t count;
} keys[] = {
{ keys128, AES_KEY_STORE_SIZE_KEY_SIZE_128,
sizeof(keys128) / sizeof(keys128[0]) },
{ keys192, AES_KEY_STORE_SIZE_KEY_SIZE_192,
sizeof(keys192) / sizeof(keys192[0]) },
{ keys256, AES_KEY_STORE_SIZE_KEY_SIZE_256,
sizeof(keys256) / sizeof(keys256[0]) }
};
static const struct {
bool encrypt;
uint8_t key_size_index;
uint8_t key_area;
uint8_t iv[GCM_IV_LEN];
uint8_t adata[ADATA_MAX_LEN];
uint16_t adata_len;
uint8_t mdata[MDATA_MAX_LEN];
uint16_t mdata_len;
uint8_t tag[GCM_TAG_LEN];
uint8_t expected[MDATA_MAX_LEN];
} vectors[] = {
{
true, /* encrypt */
0, /* key_size_index */
0, /* key_area */
{ 0x5b, 0x05, 0x75, 0x5f, 0x98, 0x4d, 0x2b, 0x90,
0xf9, 0x4b, 0x80, 0x27 }, /* iv */
{ 0xe8, 0x54, 0x91, 0xb2, 0x20, 0x2c, 0xaf, 0x1d,
0x7d, 0xce, 0x03, 0xb9, 0x7e, 0x09, 0x33, 0x1c,
0x32, 0x47, 0x39, 0x41 }, /* adata */
20, /* adata_len */
{}, /* mdata */
0, /* mdata_len */
{ 0xc7, 0x5b, 0x78, 0x32, 0xb2, 0xa2, 0xd9, 0xbd,
0x82, 0x74, 0x12, 0xb6, 0xef, 0x57, 0x69, 0xdb }, /* tag */
{} /* expected */
}, {
true, /* encrypt */
0, /* key_size_index */
1, /* key_area */
{ 0xb3, 0xd8, 0xcc, 0x01, 0x7c, 0xbb, 0x89, 0xb3,
0x9e, 0x0f, 0x67, 0xe2 }, /* iv */
{ 0x24, 0x82, 0x56, 0x02, 0xbd, 0x12, 0xa9, 0x84,
0xe0, 0x09, 0x2d, 0x3e, 0x44, 0x8e, 0xda, 0x5f }, /* adata */
16, /* adata_len */
{ 0xc3, 0xb3, 0xc4, 0x1f, 0x11, 0x3a, 0x31, 0xb7,
0x3d, 0x9a, 0x5c, 0xd4, 0x32, 0x10, 0x30, 0x69 }, /* mdata */
16, /* mdata_len */
{ 0x00, 0x32, 0xa1, 0xdc, 0x85, 0xf1, 0xc9, 0x78,
0x69, 0x25, 0xa2, 0xe7, 0x1d, 0x82, 0x72, 0xdd }, /* tag */
{ 0x93, 0xfe, 0x7d, 0x9e, 0x9b, 0xfd, 0x10, 0x34,
0x8a, 0x56, 0x06, 0xe5, 0xca, 0xfa, 0x73, 0x54 } /* expected */
}, {
true, /* encrypt */
0, /* key_size_index */
2, /* key_area */
{ 0x3b, 0xb9, 0xeb, 0x77, 0x24, 0xcb, 0xe1, 0x94,
0x3d, 0x43, 0xde, 0x21 }, /* iv */
{ 0x26, 0x62, 0xd8, 0x95, 0x03, 0x5b, 0x65, 0x19,
0xf3, 0x51, 0x0e, 0xae, 0x0f, 0xaa, 0x39, 0x00,
0xad, 0x23, 0xcf, 0xdf }, /* adata */
20, /* adata_len */
{ 0xfd, 0x33, 0x1c, 0xa8, 0x64, 0x60, 0x91, 0xc2,
0x9f, 0x21, 0xe5, 0xf0, 0xa1 }, /* mdata */
13, /* mdata_len */
{ 0xd2, 0x4c, 0x3e, 0x9c, 0x1c, 0x73, 0xc0, 0xaf,
0x10, 0x97, 0xe2, 0x60, 0x61, 0xc8, 0x57, 0xde }, /* tag */
{ 0x59, 0xfe, 0x29, 0xb0, 0x7b, 0x0d, 0xe8, 0xd8,
0x69, 0xef, 0xbb, 0xd9, 0xb4 } /* expected */
}, {
true, /* encrypt */
0, /* key_size_index */
3, /* key_area */
{ 0x07, 0xa9, 0xa9, 0x5e, 0xa3, 0x82, 0x1e, 0x9c,
0x13, 0xc6, 0x32, 0x51 }, /* iv */
{}, /* adata */
0, /* adata_len */
{ 0xf5, 0x4b, 0xc3, 0x50, 0x1f, 0xed, 0x4f, 0x6f,
0x6d, 0xfb, 0x5e, 0xa8, 0x01, 0x06, 0xdf, 0x0b,
0xd8, 0x36, 0xe6, 0x82, 0x62, 0x25, 0xb7, 0x5c,
0x02, 0x22, 0xf6, 0xe8, 0x59, 0xb3, 0x59, 0x83 }, /* mdata */
32, /* mdata_len */
{ 0x78, 0x70, 0xd9, 0x11, 0x7f, 0x54, 0x81, 0x1a,
0x34, 0x69, 0x70, 0xf1, 0xde, 0x09, 0x0c, 0x41 }, /* tag */
{ 0x05, 0x56, 0xc1, 0x59, 0xf8, 0x4e, 0xf3, 0x6c,
0xb1, 0x60, 0x2b, 0x45, 0x26, 0xb1, 0x20, 0x09,
0xc7, 0x75, 0x61, 0x1b, 0xff, 0xb6, 0x4d, 0xc0,
0xd9, 0xca, 0x92, 0x97, 0xcd, 0x2c, 0x6a, 0x01 } /* expected */
}, {
false, /* encrypt */
0, /* key_size_index */
4, /* key_area */
{ 0x58, 0x4c, 0x29, 0x1f, 0xf1, 0xaa, 0x38, 0x8a,
0x51, 0x12, 0x52, 0x1e }, /* iv */
{ 0x91, 0xf9, 0x2e, 0x8b, 0xbd, 0xa7, 0xb5, 0xec,
0x96, 0x7a, 0xde, 0x76, 0x6f, 0x4f, 0x26, 0xe9,
0x18, 0x9e, 0xaa, 0xfa, 0xd4, 0x16, 0xf3, 0x7b,
0x48, 0x91, 0xd3, 0xe3, 0x7d, 0x70, 0xcb, 0x9a,
0x26, 0x7a, 0xa8, 0x43, 0xdd, 0x20, 0x28, 0x58,
0xad, 0xe0, 0x20, 0x26, 0x12, 0x23, 0xdf, 0xce }, /* adata */
48, /* adata_len */
{}, /* mdata */
0, /* mdata_len */
{ 0x9a, 0xc7, 0xeb, 0x2d, 0x76, 0x2f, 0xac, 0xae,
0x06, 0x08, 0x6c, 0x95, 0x79, 0x59, 0x88, 0x0e }, /* tag */
{} /* expected */
}, {
false, /* encrypt */
0, /* key_size_index */
5, /* key_area */
{ 0x8e, 0x69, 0xfa, 0x64, 0xe8, 0x71, 0xd0, 0xe9,
0x8a, 0x18, 0x3a, 0x49 }, /* iv */
{ 0x51, 0x66, 0x30, 0x9e, 0x15, 0x34, 0x47, 0xb2,
0x7c, 0x67, 0x05, 0x14, 0x53, 0xab, 0xf4, 0x41,
0xde, 0x3f, 0x4a, 0x7f, 0x6b, 0x63, 0x3e, 0xc6,
0x12, 0x2f, 0xf8, 0x2d, 0xc1, 0x32, 0xcf, 0xb4,
0x22, 0xd3, 0x6c, 0x5e, 0xc6, 0xe7, 0xcc, 0x90,
0xa9, 0xad, 0x55, 0xca, 0xa1, 0xcc, 0xdc, 0xb8,
0x2d, 0xc5, 0x02, 0x2a, 0x20, 0x06, 0x2a, 0x9c,
0x6e, 0x92, 0x38, 0xf3, 0x4d, 0x08, 0x5b, 0x1f,
0x55, 0x4b, 0x5e, 0xac, 0x05, 0xef, 0xf2, 0x5b,
0x5a, 0x5c, 0xb6, 0xe1, 0x8e, 0x78, 0x27, 0xd7,
0x01, 0x75, 0xdc, 0x06, 0x62, 0xd7, 0x70, 0x33,
0xd1, 0x18 }, /* adata */
90, /* adata_len */
{ 0x2d, 0x22, 0x92, 0xda, 0x61, 0xc2, 0x80, 0xaf,
0xf8, 0x67, 0x67, 0xd2, 0x5b, 0x75, 0xe8, 0x14 }, /* mdata */
16, /* mdata_len */
{ 0x63, 0x3e, 0xe6, 0x57, 0xa8, 0x98, 0x1a, 0x76,
0x82, 0xf8, 0x75, 0x05, 0x59, 0x4c, 0x95, 0xad }, /* tag */
{ 0x49, 0x53, 0xb5, 0x48, 0x59, 0x87, 0x06, 0x31,
0xe8, 0x18, 0xda, 0x71, 0xfc, 0x69, 0xc9, 0x81 } /* expected */
}, {
false, /* encrypt */
0, /* key_size_index */
6, /* key_area */
{ 0x3f, 0x39, 0x83, 0xdc, 0x63, 0x98, 0x6e, 0x33,
0xd1, 0xb6, 0xbf, 0xfc }, /* iv */
{ 0x5a, 0xbd, 0x0c, 0x1c, 0x52, 0xb6, 0x87, 0xe9,
0xa1, 0x67, 0x3b, 0x69, 0x13, 0x78, 0x95, 0xe5,
0x02, 0x5c, 0x2b, 0xd1, 0x8c, 0xbe, 0xac, 0xdb,
0x94, 0x72, 0xe9, 0x18, 0xfe, 0x15, 0x87, 0xda,
0x55, 0x8c, 0x49, 0x2c, 0xc7, 0x08, 0xd2, 0x70,
0xfd, 0x10, 0x57, 0x2e, 0xea, 0x83, 0xd2, 0xde }, /* adata */
48, /* adata_len */
{ 0x95, 0xea, 0x05, 0x70, 0x14, 0x81, 0xe9, 0x15,
0xc7, 0x24, 0x46, 0xc8, 0x76 }, /* mdata */
13, /* mdata_len */
{ 0x5c, 0x86, 0x69, 0x92, 0x66, 0x20, 0x05, 0xca,
0x88, 0x86, 0x81, 0x0e, 0x27, 0x8c, 0x8a, 0xb4 }, /* tag */
{ 0x55, 0x11, 0x87, 0x29, 0x05, 0x43, 0x6c, 0x7d,
0xe3, 0x8e, 0x95, 0x01, 0xe7 } /* expected */
}, {
false, /* encrypt */
0, /* key_size_index */
7, /* key_area */
{ 0x8a, 0xd7, 0x33, 0xa4, 0xa9, 0xb8, 0x33, 0x06,
0x90, 0x23, 0x8c, 0x42 }, /* iv */
{}, /* adata */
0, /* adata_len */
{ 0xbb, 0xb5, 0xb6, 0x72, 0xa4, 0x79, 0xaf, 0xca,
0x2b, 0x11, 0xad, 0xb0, 0xa4, 0xc7, 0x62, 0xb6,
0x98, 0xdd, 0x56, 0x59, 0x08, 0xfe, 0xe1, 0xd1,
0x01, 0xf6, 0xa0, 0x1d, 0x63, 0x33, 0x2c, 0x91,
0xb8, 0x5d, 0x7f, 0x03, 0xac, 0x48, 0xa4, 0x77,
0x89, 0x7d, 0x51, 0x2b, 0x45, 0x72, 0xf9, 0x04,
0x2c, 0xb7, 0xea }, /* mdata */
51, /* mdata_len */
{ 0x4d, 0x78, 0xbd, 0xcb, 0x13, 0x66, 0xfc, 0xba,
0x02, 0xfd, 0xcc, 0xee, 0x57, 0xe1, 0xff, 0x44 }, /* tag */
{ 0x3f, 0x3b, 0xb0, 0x64, 0x4e, 0xac, 0x87, 0x8b,
0x97, 0xd9, 0x90, 0xd2, 0x57, 0xf5, 0xb3, 0x6e,
0x17, 0x93, 0x49, 0x0d, 0xbc, 0x13, 0xfe, 0xa4,
0xef, 0xe9, 0x82, 0x2c, 0xeb, 0xba, 0x74, 0x44,
0xcc, 0xe4, 0xde, 0xe5, 0xa7, 0xf5, 0xdf, 0xdf,
0x28, 0x5f, 0x96, 0x78, 0x57, 0x92, 0x81, 0x22,
0x00, 0xc2, 0x79 } /* expected */
}, {
true, /* encrypt */
1, /* key_size_index */
0, /* key_area */
{ 0x8f, 0x88, 0xd7, 0x0e, 0x25, 0x0d, 0xbf, 0x12,
0x82, 0x41, 0x3f, 0xd7 }, /* iv */
{ 0x3b, 0x3b, 0xbb, 0x2c, 0xcd, 0x76, 0x23, 0x6f,
0x07, 0x4e, 0xec, 0xc1, 0x9f, 0x34, 0x10, 0x57 }, /* adata */
16, /* adata_len */
{ 0x42, 0x35, 0xe4, 0x2f, 0x32, 0xcf, 0xf4, 0x4a,
0x50, 0x7d, 0xd8, 0xa3, 0x66 }, /* mdata */
13, /* mdata_len */
{ 0x4c, 0xdd, 0xdb, 0x4a, 0x95, 0x46, 0xa8, 0xd7,
0x3a, 0xfc, 0x9f, 0x5e, 0x46, 0xa9, 0x26, 0xf3 }, /* tag */
{ 0xe9, 0x2d, 0xf9, 0xd2, 0xfd, 0x43, 0x6e, 0xd2,
0x54, 0xfa, 0x92, 0x78, 0x9c } /* expected */
}, {
true, /* encrypt */
1, /* key_size_index */
2, /* key_area */
{ 0xe9, 0x5e, 0xbb, 0x1e, 0x8d, 0x31, 0xd1, 0xac,
0x41, 0x4a, 0xd5, 0xf1 }, /* iv */
{ 0x9c, 0x1a, 0x35, 0x60, 0x40, 0xa1, 0x87, 0xb7,
0xd8, 0x5c, 0x7b, 0xbd, 0xc2, 0x3d, 0x3e, 0x9c,
0x63, 0x8f, 0x01, 0x4b, 0xd5, 0x62, 0x90, 0x88,
0x75, 0x7b, 0x57, 0x05, 0xb4, 0xf2, 0x78, 0x33,
0xb0, 0xa2, 0xb3, 0xfa, 0x4c, 0x9c, 0x43, 0xa7,
0x7c, 0x69, 0xa3, 0xa2, 0x0a, 0xff, 0xd2, 0xac,
0x4a, 0xa6, 0xfd, 0xf2, 0xe0, 0x7c, 0x0a, 0x8d,
0xaf, 0x1a, 0x19, 0xc4, 0x9a, 0x6a, 0x69, 0xfb,
0xf4, 0x25, 0x1b, 0x77, 0x98, 0x17, 0x31, 0x82,
0xa5, 0x28, 0xe6, 0xeb, 0x94, 0x19, 0x28, 0xaf,
0x99, 0x53, 0xbf, 0x59, 0x5b, 0xfb, 0x7b, 0xdf,
0x5c, 0x3a }, /* adata */
90, /* adata_len */
{ 0xc0, 0xc9, 0x22, 0x56, 0x03, 0x2e, 0xd3, 0x11,
0x3a, 0x79, 0x41, 0x0a, 0x8b, 0x0e, 0x25, 0x0e,
0x9a, 0x97, 0xfb, 0x47, 0x29, 0x8d, 0x12, 0x29,
0x32, 0xff, 0x94, 0xd8, 0xf9, 0x40, 0xbc, 0xf8 }, /* mdata */
32, /* mdata_len */
{ 0x6b, 0xce, 0x3a, 0xbe, 0xe7, 0xb7, 0xa6, 0x56,
0x3a, 0xb7, 0x9f, 0x68, 0xa4, 0x19, 0x72, 0xf4 }, /* tag */
{ 0x2c, 0x04, 0x3e, 0xc6, 0x9c, 0x25, 0x5c, 0x7e,
0xaf, 0x7b, 0xef, 0x47, 0x9b, 0x74, 0x67, 0x4f,
0xf2, 0x0c, 0x18, 0x5b, 0xcc, 0x6f, 0x94, 0x24,
0x22, 0xc7, 0xb5, 0xbe, 0x19, 0x99, 0x68, 0x37 } /* expected */
}, {
false, /* encrypt */
1, /* key_size_index */
4, /* key_area */
{ 0x78, 0xec, 0x38, 0x73, 0xbd, 0x88, 0x46, 0xac,
0x42, 0xff, 0x3a, 0x9b }, /* iv */
{ 0x7b, 0x4d, 0x41, 0x23, 0x02, 0xf3, 0x31, 0x96,
0x53, 0xcc, 0xed, 0x7d, 0xc6, 0xd7, 0xd8, 0x45,
0xcf, 0x10, 0x71, 0xd3, 0x80, 0x2c, 0xf0, 0x9b,
0xcd, 0x2b, 0xf3, 0x07, 0x76, 0x09, 0xa1, 0xda,
0xe1, 0xbf, 0x64, 0xe7, 0x88, 0x20, 0xf3, 0x68,
0x86, 0x2b, 0x2c, 0x0d, 0xaa, 0x17, 0xff, 0x9b,
0x33, 0xd1, 0xa7, 0xe4, 0xf6, 0x27, 0x50, 0x7c,
0x5a, 0x91, 0x6a, 0x80, 0x0e, 0x6d, 0x34, 0x9f,
0x72, 0xa4, 0x5f, 0x8f, 0x76, 0xb0, 0x1e, 0x63,
0xdf, 0xcb, 0x44, 0xf0, 0x0a, 0x22, 0x57, 0x41,
0xd1, 0x72, 0x37, 0x1e, 0xb9, 0x6f, 0x96, 0x49,
0x87, 0xeb }, /* adata */
90, /* adata_len */
{ 0xf1, 0xfb, 0x8d, 0xf2, 0x8f, 0x5a, 0x86, 0x49,
0xd9, 0x30, 0xb4, 0x77, 0xe6 }, /* mdata */
13, /* mdata_len */
{ 0xf7, 0x1b, 0x01, 0x98, 0xae, 0xe9, 0x70, 0xe0,
0xcb, 0x9f, 0x83, 0x5b, 0x4e, 0xe9, 0xf4, 0x33 }, /* tag */
{ 0x16, 0xea, 0xad, 0xec, 0x26, 0x20, 0x4a, 0x64,
0x4e, 0x2f, 0x24, 0xb1, 0xee } /* expected */
}, {
false, /* encrypt */
1, /* key_size_index */
6, /* key_area */
{ 0x2e, 0x8e, 0xf3, 0x3d, 0x26, 0x5d, 0x48, 0x19,
0xb6, 0x3c, 0xfd, 0xfc }, /* iv */
{ 0xf2, 0x16, 0xc7, 0xde, 0xf5, 0x5c, 0x8f, 0xf3,
0x25, 0x93, 0x35, 0x40, 0x96, 0x35, 0x62, 0xef,
0xe9, 0x6a, 0xe3, 0xf4, 0xb5, 0x4e, 0x6e, 0xc9,
0x5b, 0x25, 0x19, 0x42, 0x64, 0x67, 0x11, 0xd1,
0x7e, 0x4e, 0x39, 0xf2, 0x0f, 0xfb, 0x35, 0xd0,
0x33, 0x4c, 0x9c, 0x03, 0x83, 0x0d, 0x00, 0xc3 }, /* adata */
48, /* adata_len */
{ 0x66, 0xd3, 0xe6, 0x06, 0x6c, 0x51, 0xf3, 0x74,
0xc8, 0xde, 0xf9, 0x1d, 0xdd, 0xd7, 0x76, 0xeb,
0xc3, 0xbd, 0x9c, 0x96, 0x19, 0xeb, 0xc6, 0x81,
0x3c, 0x63, 0xd6, 0x9a, 0xac, 0x51, 0xb9, 0x77,
0x5a, 0x47, 0x19, 0x6e, 0x48, 0x83, 0xce, 0x5e,
0x32, 0x33, 0x2c, 0xe0, 0x09, 0xe0, 0x27, 0xec,
0x62, 0x2a, 0xe3 }, /* mdata */
51, /* mdata_len */
{ 0xcc, 0xef, 0x02, 0x7c, 0x0a, 0xe1, 0x90, 0x87,
0xe1, 0x8b, 0x13, 0xab, 0x5e, 0x1c, 0x89, 0xa6 }, /* tag */
{ 0x44, 0x8e, 0x59, 0xef, 0x95, 0x88, 0x67, 0xd6,
0x99, 0xfa, 0xf7, 0x4a, 0xa0, 0x46, 0x28, 0x1d,
0xb5, 0x1c, 0x44, 0xbd, 0x7a, 0xac, 0xb0, 0x52,
0x21, 0xcf, 0x3c, 0x7f, 0x1e, 0xfd, 0x47, 0x04,
0xf9, 0xb4, 0x79, 0x67, 0xb7, 0x05, 0x16, 0x8b,
0x5e, 0xd2, 0x52, 0x38, 0x64, 0x48, 0x29, 0xb7,
0x54, 0xdc, 0x75 } /* expected */
}, {
true, /* encrypt */
2, /* key_size_index */
0, /* key_area */
{ 0x67, 0x13, 0x09, 0x51, 0xc4, 0xa5, 0x7f, 0x6a,
0xe7, 0xf1, 0x32, 0x41 }, /* iv */
{ 0xfd, 0x09, 0x20, 0xfa, 0xeb, 0x7b, 0x21, 0x29,
0x32, 0x28, 0x0a, 0x00, 0x9b, 0xac, 0x96, 0x91,
0x45, 0xe5, 0xc3, 0x16, 0xcf, 0x39, 0x22, 0x62,
0x2c, 0x37, 0x05, 0xc3, 0x45, 0x7c, 0x4e, 0x9f,
0x12, 0x4b, 0x20, 0x76, 0x99, 0x43, 0x23, 0xfb,
0xcf, 0xb5, 0x23, 0xf8, 0xed, 0x16, 0xd2, 0x41 }, /* adata */
48, /* adata_len */
{ 0x93, 0x78, 0xa7, 0x27, 0xa5, 0x11, 0x95, 0x95,
0xad, 0x63, 0x1b, 0x12, 0xa5, 0xa6, 0xbc, 0x8a,
0x91, 0x75, 0x6e, 0xf0, 0x9c, 0x8d, 0x6e, 0xaa,
0x2b, 0x71, 0x8f, 0xe8, 0x68, 0x76, 0xda, 0x20 }, /* mdata */
32, /* mdata_len */
{ 0xb8, 0x76, 0x83, 0x1b, 0x4e, 0xcd, 0x72, 0x42,
0x96, 0x3b, 0x04, 0x0a, 0xa4, 0x5c, 0x41, 0x14 }, /* tag */
{ 0x6d, 0x95, 0x8c, 0x20, 0x87, 0x0d, 0x40, 0x1a,
0x3c, 0x1f, 0x7a, 0x0a, 0xc0, 0x92, 0xc9, 0x77,
0x74, 0xd4, 0x51, 0xc0, 0x9f, 0x7a, 0xae, 0x99,
0x2a, 0x88, 0x41, 0xff, 0x0a, 0xb9, 0xd6, 0x0d } /* expected */
}, {
true, /* encrypt */
2, /* key_size_index */
2, /* key_area */
{ 0xb0, 0x8a, 0x5e, 0xa1, 0x92, 0x74, 0x99, 0xc6,
0xec, 0xbf, 0xd4, 0xe0 }, /* iv */
{ 0xe4, 0xf9, 0x63, 0xf0, 0x15, 0xff, 0xbb, 0x99,
0xee, 0x33, 0x49, 0xbb, 0xaf, 0x7e, 0x8e, 0x8e,
0x6c, 0x2a, 0x71, 0xc2, 0x30, 0xa4, 0x8f, 0x9d,
0x59, 0x86, 0x0a, 0x29, 0x09, 0x1d, 0x27, 0x47,
0xe0, 0x1a, 0x5c, 0xa5, 0x72, 0x34, 0x7e, 0x24,
0x7d, 0x25, 0xf5, 0x6b, 0xa7, 0xae, 0x8e, 0x05,
0xcd, 0xe2, 0xbe, 0x3c, 0x97, 0x93, 0x12, 0x92,
0xc0, 0x23, 0x70, 0x20, 0x8e, 0xcd, 0x09, 0x7e,
0xf6, 0x92, 0x68, 0x7f, 0xec, 0xf2, 0xf4, 0x19,
0xd3, 0x20, 0x01, 0x62, 0xa6, 0x48, 0x0a, 0x57,
0xda, 0xd4, 0x08, 0xa0, 0xdf, 0xeb, 0x49, 0x2e,
0x2c, 0x5d }, /* adata */
90, /* adata_len */
{ 0x9d, 0x0b, 0x15, 0xfd, 0xf1, 0xbd, 0x59, 0x5f,
0x91, 0xf8, 0xb3, 0xab, 0xc0, 0xf7, 0xde, 0xc9,
0x27, 0xdf, 0xd4, 0x79, 0x99, 0x35, 0xa1, 0x79,
0x5d, 0x9c, 0xe0, 0x0c, 0x9b, 0x87, 0x94, 0x34,
0x42, 0x0f, 0xe4, 0x2c, 0x27, 0x5a, 0x7c, 0xd7,
0xb3, 0x9d, 0x63, 0x8f, 0xb8, 0x1c, 0xa5, 0x2b,
0x49, 0xdc, 0x41 }, /* mdata */
51, /* mdata_len */
{ 0xad, 0xbe, 0xcd, 0xb0, 0xd5, 0xc2, 0x22, 0x4d,
0x80, 0x4d, 0x28, 0x86, 0xff, 0x9a, 0x57, 0x60 }, /* tag */
{ 0x20, 0x97, 0xe3, 0x72, 0x95, 0x0a, 0x5e, 0x93,
0x83, 0xc6, 0x75, 0xe8, 0x9e, 0xea, 0x1c, 0x31,
0x4f, 0x99, 0x91, 0x59, 0xf5, 0x61, 0x13, 0x44,
0xb2, 0x98, 0xcd, 0xa4, 0x5e, 0x62, 0x84, 0x37,
0x16, 0xf2, 0x15, 0xf8, 0x2e, 0xe6, 0x63, 0x91,
0x9c, 0x64, 0x00, 0x2a, 0x5c, 0x19, 0x8d, 0x78,
0x78, 0xfd, 0x3f } /* expected */
}, {
false, /* encrypt */
2, /* key_size_index */
4, /* key_area */
{ 0x72, 0x48, 0xa5, 0xed, 0x48, 0xf4, 0xf1, 0xb4,
0xa9, 0xdb, 0x38, 0x26 }, /* iv */
{ 0x8e, 0x3c, 0x74, 0xf1, 0x27, 0xdb, 0xfe, 0x29,
0xac, 0x4d, 0xe0, 0xa7, 0xc3, 0x24, 0x0e, 0xe8,
0xaa, 0x8d, 0x38, 0xa8, 0x2f, 0x38, 0xad, 0x6b,
0x48, 0x02, 0x36, 0xc8, 0xcd, 0x42, 0x32, 0x05,
0x7a, 0x55, 0x02, 0xe9, 0x36, 0xbf, 0xe2, 0x22,
0x25, 0x83, 0x0f, 0xa1, 0x95, 0xa8, 0xaf, 0xce }, /* adata */
48, /* adata_len */
{ 0x26, 0x32, 0x5c, 0x34, 0x63, 0x81, 0x3a, 0x7d,
0x59, 0xd1, 0x84, 0xa3, 0x30, 0xef, 0x80, 0x95,
0x96, 0x37, 0xfa, 0x6d, 0xb4, 0xf5, 0xdb, 0x30,
0x62, 0xd3, 0xd2, 0xec, 0x7e, 0x32, 0xd8, 0x2a }, /* mdata */
32, /* mdata_len */
{ 0x4f, 0x39, 0xc6, 0x3d, 0x4f, 0x21, 0x5d, 0x5b,
0x39, 0xa5, 0x88, 0x53, 0xd3, 0x84, 0x21, 0x75 }, /* tag */
{ 0x9a, 0x32, 0x9c, 0xb4, 0x5b, 0x00, 0x93, 0xe9,
0xc0, 0x06, 0x15, 0x13, 0x7d, 0xd7, 0xdb, 0xd1,
0xf8, 0xb5, 0x25, 0x99, 0x9a, 0xf3, 0xbf, 0xc2,
0x22, 0x31, 0x5f, 0x41, 0x81, 0x77, 0x17, 0xa7 } /* expected */
}, {
false, /* encrypt */
2, /* key_size_index */
6, /* key_area */
{ 0xea, 0x6f, 0x5b, 0x39, 0x1e, 0x44, 0xb7, 0x51,
0xb2, 0x6b, 0xce, 0x6f }, /* iv */
{ 0x9b, 0x3a, 0x68, 0xc9, 0x41, 0xd4, 0x27, 0x44,
0x67, 0x3f, 0xb6, 0x0f, 0xea, 0x49, 0x07, 0x5e,
0xae, 0x77, 0x32, 0x2e, 0x7e, 0x70, 0xe3, 0x45,
0x02, 0xc1, 0x15, 0xb6, 0x49, 0x5e, 0xbf, 0xc7,
0x96, 0xd6, 0x29, 0x08, 0x07, 0x65, 0x3c, 0x6b,
0x53, 0xcd, 0x84, 0x28, 0x1b, 0xd0, 0x31, 0x16,
0x56, 0xd0, 0x01, 0x3f, 0x44, 0x61, 0x9d, 0x27,
0x48, 0x17, 0x7e, 0x99, 0xe8, 0xf8, 0x34, 0x7c,
0x98, 0x9a, 0x7b, 0x59, 0xf9, 0xd8, 0xdc, 0xf0,
0x0f, 0x31, 0xdb, 0x06, 0x84, 0xa4, 0xa8, 0x3e,
0x03, 0x7e, 0x87, 0x77, 0xba, 0xe5, 0x5f, 0x79,
0x9b, 0x0d }, /* adata */
90, /* adata_len */
{ 0x0e, 0x6e, 0x0b, 0x21, 0x14, 0xc4, 0x07, 0x69,
0xc1, 0x59, 0x58, 0xd9, 0x65, 0xa1, 0x4d, 0xcf,
0x50, 0xb6, 0x80, 0xe0, 0x18, 0x5a, 0x44, 0x09,
0xd7, 0x7d, 0x89, 0x4c, 0xa1, 0x5b, 0x1e, 0x69,
0x8d, 0xd8, 0x3b, 0x35, 0x36, 0xb1, 0x8c, 0x05,
0xd8, 0xcd, 0x08, 0x73, 0xd1, 0xed, 0xce, 0x81,
0x50, 0xec, 0xb5 }, /* mdata */
51, /* mdata_len */
{ 0xfd, 0xaa, 0xff, 0x86, 0xce, 0xb9, 0x37, 0x50,
0x2c, 0xd9, 0x01, 0x2d, 0x03, 0x58, 0x58, 0x00 }, /* tag */
{ 0xb0, 0xa8, 0x81, 0xb7, 0x51, 0xcc, 0x1e, 0xb0,
0xc9, 0x12, 0xa4, 0xcf, 0x9b, 0xd9, 0x71, 0x98,
0x37, 0x07, 0xdb, 0xd2, 0x41, 0x17, 0x25, 0x66,
0x45, 0x03, 0x45, 0x5c, 0x55, 0xdb, 0x25, 0xcd,
0xb1, 0x9b, 0xc6, 0x69, 0xc2, 0x65, 0x4a, 0x3a,
0x80, 0x11, 0xde, 0x6b, 0xf7, 0xef, 0xf3, 0xf9,
0xf0, 0x78, 0x34 } /* expected */
}
};
static uint8_t adata[ADATA_MAX_LEN];
static uint8_t mdata[MDATA_MAX_LEN];
static uint8_t tag[GCM_TAG_LEN];
static int i;
static uint8_t key_size_index = -1, ret;
static rtimer_clock_t time, time2, total_time;
PROCESS_BEGIN();
puts("-----------------------------------------\n"
"Initializing cryptoprocessor...");
crypto_init();
for(i = 0; i < sizeof(vectors) / sizeof(vectors[0]); i++) {
if(key_size_index != vectors[i].key_size_index) {
key_size_index = vectors[i].key_size_index;
printf("-----------------------------------------\n"
"Filling %d-bit key store...\n", 128 + (key_size_index << 6));
time = RTIMER_NOW();
ret = aes_load_keys(keys[key_size_index].keys,
keys[key_size_index].key_size, keys[key_size_index].count, 0);
time = RTIMER_NOW() - time;
printf("aes_load_keys(): %s, %lu us\n", str_res[ret],
(uint32_t)((uint64_t)time * 1000000 / RTIMER_SECOND));
PROCESS_PAUSE();
if(ret != CRYPTO_SUCCESS) {
break;
}
}
printf("-----------------------------------------\n"
"Test vector #%d: %s\n"
"key_area=%d adata_len=%d mdata_len=%d\n",
i, vectors[i].encrypt ? "encrypt" : "decrypt",
vectors[i].key_area, vectors[i].adata_len, vectors[i].mdata_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 = gcm_auth_encrypt_start(vectors[i].key_area, vectors[i].iv, adata,
vectors[i].adata_len, mdata,
vectors[i].mdata_len, mdata,
&gcm_test_process);
time2 = RTIMER_NOW();
time = time2 - time;
total_time = time;
if(ret == CRYPTO_SUCCESS) {
PROCESS_WAIT_EVENT_UNTIL(gcm_auth_encrypt_check_status());
time2 = RTIMER_NOW() - time2;
total_time += time2;
}
printf("gcm_auth_encrypt_start(): %s, %lu us\n", str_res[ret],
(uint32_t)((uint64_t)time * 1000000 / RTIMER_SECOND));
if(ret != CRYPTO_SUCCESS) {
PROCESS_PAUSE();
continue;
}
printf("gcm_auth_encrypt_check_status() wait: %lu us\n",
(uint32_t)((uint64_t)time2 * 1000000 / RTIMER_SECOND));
time = RTIMER_NOW();
ret = gcm_auth_encrypt_get_result(tag);
time = RTIMER_NOW() - time;
total_time += time;
printf("gcm_auth_encrypt_get_result(): %s, %lu us\n", str_res[ret],
(uint32_t)((uint64_t)time * 1000000 / RTIMER_SECOND));
PROCESS_PAUSE();
if(ret != CRYPTO_SUCCESS) {
continue;
}
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(tag, vectors[i].tag, GCM_TAG_LEN)) {
puts("Tag does not match expected one");
} else {
puts("Tag OK");
}
} else {
ret = gcm_auth_decrypt_start(vectors[i].key_area, vectors[i].iv, adata,
vectors[i].adata_len, mdata,
vectors[i].mdata_len, mdata,
&gcm_test_process);
time2 = RTIMER_NOW();
time = time2 - time;
total_time = time;
if(ret == CRYPTO_SUCCESS) {
PROCESS_WAIT_EVENT_UNTIL(gcm_auth_decrypt_check_status());
time2 = RTIMER_NOW() - time2;
total_time += time2;
}
printf("gcm_auth_decrypt_start(): %s, %lu us\n", str_res[ret],
(uint32_t)((uint64_t)time * 1000000 / RTIMER_SECOND));
if(ret != CRYPTO_SUCCESS) {
PROCESS_PAUSE();
continue;
}
printf("gcm_auth_decrypt_check_status() wait: %lu us\n",
(uint32_t)((uint64_t)time2 * 1000000 / RTIMER_SECOND));
time = RTIMER_NOW();
ret = gcm_auth_decrypt_get_result(vectors[i].tag, tag);
time = RTIMER_NOW() - time;
total_time += time;
printf("gcm_auth_decrypt_get_result(): %s, %lu us\n", str_res[ret],
(uint32_t)((uint64_t)time * 1000000 / RTIMER_SECOND));
PROCESS_PAUSE();
if(ret != CRYPTO_SUCCESS) {
continue;
}
if(rom_util_memcmp(mdata, vectors[i].expected, vectors[i].mdata_len)) {
puts("Decrypted message does not match expected one");
} else {
puts("Decrypted message OK");
}
}
printf("Total duration: %lu us\n",
(uint32_t)((uint64_t)total_time * 1000000 / RTIMER_SECOND));
}
puts("-----------------------------------------\n"
"Disabling cryptoprocessor...");
crypto_disable();
puts("Done!");
PROCESS_END();
}
/*---------------------------------------------------------------------------*/
/**
* @}
* @}
*/

View file

@ -30,7 +30,7 @@ In terms of hardware support, the following drivers have been implemented:
* General-Purpose Timers. NB: GPT0 is in use by the platform code, the remaining GPTs are available for application development.
* ADC
* PWM
* Cryptoprocessor (AES-ECB/CCM-128/192/256, SHA-256)
* Cryptoprocessor (AES-ECB/CBC/CTR/CBC-MAC/GCM/CCM-128/192/256, SHA-256)
* Public Key Accelerator (ECDH, ECDSA)
* Flash-based port of Coffee
* SmartRF06 EB and BB peripherals

View file

@ -51,7 +51,7 @@ In terms of hardware support, the following drivers have been implemented for th
* Low Power Modes
* General-Purpose Timers. NB: GPT0 is in use by the platform code, the remaining GPTs are available for application development.
* ADC
* Cryptoprocessor (AES-ECB/CCM-128/192/256, SHA-256)
* Cryptoprocessor (AES-ECB/CBC/CTR/CBC-MAC/GCM/CCM-128/192/256, SHA-256)
* Public Key Accelerator (ECDH, ECDSA)
* Flash-based port of Coffee
* PWM