From 695dbad0846781728a1c0d95343ea64a39f4eaa3 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Sun, 22 Oct 2017 09:34:37 +0000 Subject: More crypto code, still unfinished. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@10870 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/ports/STM32/LLD/CRYPv1/hal_crypto_lld.c | 29 ++++++++++- os/hal/ports/STM32/LLD/CRYPv1/hal_crypto_lld.h | 66 ++++++++++++++++++++++---- 2 files changed, 85 insertions(+), 10 deletions(-) (limited to 'os/hal/ports') diff --git a/os/hal/ports/STM32/LLD/CRYPv1/hal_crypto_lld.c b/os/hal/ports/STM32/LLD/CRYPv1/hal_crypto_lld.c index 37cdb2a71..a843ddd44 100644 --- a/os/hal/ports/STM32/LLD/CRYPv1/hal_crypto_lld.c +++ b/os/hal/ports/STM32/LLD/CRYPv1/hal_crypto_lld.c @@ -34,8 +34,8 @@ /* Driver exported variables. */ /*===========================================================================*/ -/** @brief CRYP1 driver identifier.*/ -#if STM32_CRY_USE_CRYP1 || defined(__DOXYGEN__) +/** @brief CRY1 driver identifier.*/ +#if PLATFORM_CRY_USE_CRY1 || defined(__DOXYGEN__) CRYDriver CRYD1; #endif @@ -92,6 +92,31 @@ void cry_lld_stop(CRYDriver *cryp) { } } +/** + * @brief Initializes the transient key for a specific algorithm. + * + * @param[in] cryp pointer to the @p CRYDriver object + * @param[in] keyp pointer to the key data + * @return The operation status. + * @retval CRY_NOERROR if the operation succeeded. + * @retval CRY_ERR_INV_ALGO if the specified algorithm is unknown or + * unsupported. + * @retval CRY_ERR_INV_KEY_SIZE if the specified key size is invalid. + * + * @notapi + */ +cryerror_t cry_lld_loadkey(CRYDriver *cryp, + cryalgorithm_t algorithm, + size_t size, + const uint8_t *keyp) { + + (void)cryp; + (void)algorithm; + (void)size; + (void)keyp; + + return CRY_NOERROR; +} #endif /* HAL_USE_CRY */ /** @} */ diff --git a/os/hal/ports/STM32/LLD/CRYPv1/hal_crypto_lld.h b/os/hal/ports/STM32/LLD/CRYPv1/hal_crypto_lld.h index e7279728b..2bc94b31d 100644 --- a/os/hal/ports/STM32/LLD/CRYPv1/hal_crypto_lld.h +++ b/os/hal/ports/STM32/LLD/CRYPv1/hal_crypto_lld.h @@ -107,23 +107,21 @@ typedef struct { */ struct CRYDriver { /** - * @brief Driver state. + * @brief Driver state. */ crystate_t state; /** - * @brief Current configuration data. + * @brief Current configuration data. */ const CRYConfig *config; /** - * @brief Waiting thread. + * @brief Algorithm type of transient key. */ - thread_reference_t thread; -#if (CRY_USE_MUTUAL_EXCLUSION == TRUE) || defined(__DOXYGEN__) + cryalgorithm_t key0_type; /** - * @brief Mutex protecting the peripheral. + * @brief Size of transient key. */ - mutex_t mutex; -#endif + size_t key0_size; #if defined(CRY_DRIVER_EXT_FIELDS) CRY_DRIVER_EXT_FIELDS #endif @@ -148,6 +146,58 @@ extern "C" { void cry_lld_init(void); void cry_lld_start(CRYDriver *cryp); void cry_lld_stop(CRYDriver *cryp); + cryerror_t cry_lld_loadkey(CRYDriver *cryp, + cryalgorithm_t algorithm, + size_t size, + const uint8_t *keyp); + cryerror_t cry_lld_encrypt_AES_ECB(CRYDriver *cryp, + crykey_t key_id, + size_t size, + const uint8_t *in, + uint8_t *out); + cryerror_t cry_lld_decrypt_AES_ECB(CRYDriver *cryp, + crykey_t key_id, + size_t size, + const uint8_t *in, + uint8_t *out); + cryerror_t cry_lld_encrypt_AES_CBC(CRYDriver *cryp, + crykey_t key_id, + size_t size, + const uint8_t *in, + uint8_t *out, + const uint8_t *iv); + cryerror_t cry_lld_decrypt_AES_CBC(CRYDriver *cryp, + crykey_t key_id, + size_t size, + const uint8_t *in, + uint8_t *out, + const uint8_t *iv); + cryerror_t cry_lld_encrypt_AES_CFB(CRYDriver *cryp, + crykey_t key_id, + size_t size, + const uint8_t *in, + uint8_t *out, + const uint8_t *iv); + cryerror_t cry_lld_decrypt_AES_CFB(CRYDriver *cryp, + crykey_t key_id, + size_t size, + const uint8_t *in, + uint8_t *out, + const uint8_t *iv); + cryerror_t cry_lld_encrypt_AES_CTR(CRYDriver *cryp, + crykey_t key_id, + size_t size, + const uint8_t *in, + uint8_t *out, + const uint8_t *nonce, + uint8_t *cnt); + cryerror_t cry_lld_decrypt_AES_CTR(CRYDriver *cryp, + crykey_t key_id, + size_t size, + const uint8_t *in, + uint8_t *out, + const uint8_t *nonce, + uint8_t *cnt); #ifdef __cplusplus } #endif -- cgit v1.2.3