From ad0f9349ae74976f054fc0aba35c0ec82c2837c8 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Wed, 13 Jun 2018 08:17:40 +0000 Subject: Added more conditionals to CRY driver. Removed conditionals from high level functions, those functions are not meant to be excluded. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@12092 110e8d01-0319-4d1e-a829-52ad28d1bb01 --- os/hal/include/hal_crypto.h | 6 +- os/hal/ports/STM32/LLD/CRYPv1/hal_crypto_lld.c | 98 +++++++++++++++++++++++++- os/hal/ports/STM32/LLD/CRYPv1/hal_crypto_lld.h | 32 +++++++-- os/hal/src/hal_crypto.c | 72 +++++++++++++++++-- os/hal/templates/hal_crypto_lld.c | 98 ++++++++++++++++++++++++++ os/hal/templates/hal_crypto_lld.h | 30 ++++++++ 6 files changed, 319 insertions(+), 17 deletions(-) diff --git a/os/hal/include/hal_crypto.h b/os/hal/include/hal_crypto.h index 4152aeb2b..a31dbcd8c 100644 --- a/os/hal/include/hal_crypto.h +++ b/os/hal/include/hal_crypto.h @@ -99,7 +99,7 @@ typedef enum { CRY_ERR_INV_KEY_SIZE = 2, /**< Invalid key size. */ CRY_ERR_INV_KEY_TYPE = 3, /**< Invalid key type. */ CRY_ERR_INV_KEY_ID = 4, /**< Invalid key identifier. */ - CRY_ERR_OPERATION_FAILURE = 5 /**< Requested operation failed.*/ + CRY_ERR_OP_FAILURE = 5 /**< Requested operation failed.*/ } cryerror_t; /** @@ -342,7 +342,6 @@ extern "C" { size_t size, const uint8_t *in); cryerror_t crySHA512Final(CRYDriver *cryp, SHA512Context *sha512ctxp, uint8_t *out); -#if (CRY_LLD_SUPPORTS_HMAC_SHA256 == TRUE) || defined(__DOXYGEN__) cryerror_t cryHMACSHA256Init(CRYDriver *cryp, HMACSHA256Context *hmacsha256ctxp); cryerror_t cryHMACSHA256Update(CRYDriver *cryp, @@ -352,8 +351,6 @@ extern "C" { cryerror_t cryHMACSHA256Final(CRYDriver *cryp, HMACSHA256Context *hmacsha256ctxp, uint8_t *out); -#endif /* CRY_LLD_SUPPORTS_HMAC_SHA256 */ -#if (CRY_LLD_SUPPORTS_HMAC_SHA512 == TRUE) || defined(__DOXYGEN__) cryerror_t cryHMACSHA512Init(CRYDriver *cryp, HMACSHA512Context *hmacsha512ctxp); cryerror_t cryHMACSHA512Update(CRYDriver *cryp, @@ -363,7 +360,6 @@ extern "C" { cryerror_t cryHMACSHA512Final(CRYDriver *cryp, HMACSHA512Context *hmacsha512ctxp, uint8_t *out); -#endif /* CRY_LLD_SUPPORTS_HMAC_SHA512 */ cryerror_t cryTRNG(CRYDriver *cryp, uint8_t *out); #ifdef __cplusplus } 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 6978ecd6f..b32596814 100644 --- a/os/hal/ports/STM32/LLD/CRYPv1/hal_crypto_lld.c +++ b/os/hal/ports/STM32/LLD/CRYPv1/hal_crypto_lld.c @@ -120,6 +120,7 @@ cryerror_t cry_lld_loadkey(CRYDriver *cryp, return CRY_NOERROR; } +#if (CRY_LLD_SUPPORTS_AES == TRUE) || defined(__DOXYGEN__) /** * @brief Encryption of a single block using AES. * @note The implementation of this function must guarantee that it can @@ -138,6 +139,8 @@ cryerror_t cry_lld_loadkey(CRYDriver *cryp, * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid * or refers to an empty key slot. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -172,6 +175,8 @@ cryerror_t cry_lld_encrypt_AES(CRYDriver *cryp, * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid * or refers to an empty key slot. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -187,7 +192,9 @@ cryerror_t cry_lld_decrypt_AES(CRYDriver *cryp, return CRY_ERR_INV_ALGO; } +#endif +#if (CRY_LLD_SUPPORTS_AES_ECB == TRUE) || defined(__DOXYGEN__) /** * @brief Encryption operation using AES-ECB. * @note The function operates on data buffers whose lenght is a multiple @@ -209,6 +216,8 @@ cryerror_t cry_lld_decrypt_AES(CRYDriver *cryp, * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid * or refers to an empty key slot. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -248,6 +257,8 @@ cryerror_t cry_lld_encrypt_AES_ECB(CRYDriver *cryp, * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid * or refers to an empty key slot. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -265,7 +276,9 @@ cryerror_t cry_lld_decrypt_AES_ECB(CRYDriver *cryp, return CRY_ERR_INV_ALGO; } +#endif +#if (CRY_LLD_SUPPORTS_AES_CBC == TRUE) || defined(__DOXYGEN__) /** * @brief Encryption operation using AES-CBC. * @note The function operates on data buffers whose lenght is a multiple @@ -288,6 +301,8 @@ cryerror_t cry_lld_decrypt_AES_ECB(CRYDriver *cryp, * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid * or refers to an empty key slot. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -330,6 +345,8 @@ cryerror_t cry_lld_encrypt_AES_CBC(CRYDriver *cryp, * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid * or refers to an empty key slot. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -349,7 +366,9 @@ cryerror_t cry_lld_decrypt_AES_CBC(CRYDriver *cryp, return CRY_ERR_INV_ALGO; } +#endif +#if (CRY_LLD_SUPPORTS_AES_CFB == TRUE) || defined(__DOXYGEN__) /** * @brief Encryption operation using AES-CFB. * @note The function operates on data buffers whose lenght is a multiple @@ -372,6 +391,8 @@ cryerror_t cry_lld_decrypt_AES_CBC(CRYDriver *cryp, * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid * or refers to an empty key slot. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -414,6 +435,8 @@ cryerror_t cry_lld_encrypt_AES_CFB(CRYDriver *cryp, * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid * or refers to an empty key slot. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -433,7 +456,9 @@ cryerror_t cry_lld_decrypt_AES_CFB(CRYDriver *cryp, return CRY_ERR_INV_ALGO; } +#endif +#if (CRY_LLD_SUPPORTS_AES_CTR == TRUE) || defined(__DOXYGEN__) /** * @brief Encryption operation using AES-CTR. * @note The function operates on data buffers whose lenght is a multiple @@ -457,6 +482,8 @@ cryerror_t cry_lld_decrypt_AES_CFB(CRYDriver *cryp, * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid * or refers to an empty key slot. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -500,6 +527,8 @@ cryerror_t cry_lld_encrypt_AES_CTR(CRYDriver *cryp, * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid * or refers to an empty key slot. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -519,7 +548,9 @@ cryerror_t cry_lld_decrypt_AES_CTR(CRYDriver *cryp, return CRY_ERR_INV_ALGO; } +#endif +#if (CRY_LLD_SUPPORTS_AES_GCM == TRUE) || defined(__DOXYGEN__) /** * @brief Encryption operation using AES-GCM. * @note The function operates on data buffers whose lenght is a multiple @@ -548,6 +579,8 @@ cryerror_t cry_lld_decrypt_AES_CTR(CRYDriver *cryp, * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid * or refers to an empty key slot. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -602,6 +635,8 @@ cryerror_t cry_lld_encrypt_AES_GCM(CRYDriver *cryp, * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid * or refers to an empty key slot. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -627,7 +662,9 @@ cryerror_t cry_lld_decrypt_AES_GCM(CRYDriver *cryp, return CRY_ERR_INV_ALGO; } +#endif +#if (CRY_LLD_SUPPORTS_DES == TRUE) || defined(__DOXYGEN__) /** * @brief Encryption of a single block using (T)DES. * @note The implementation of this function must guarantee that it can @@ -646,6 +683,8 @@ cryerror_t cry_lld_decrypt_AES_GCM(CRYDriver *cryp, * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid * or refers to an empty key slot. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -681,6 +720,8 @@ cryerror_t cry_lld_encrypt_DES(CRYDriver *cryp, * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid * or refers to an empty key slot. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -696,7 +737,9 @@ cryerror_t cry_lld_decrypt_DES(CRYDriver *cryp, return CRY_ERR_INV_ALGO; } +#endif +#if (CRY_LLD_SUPPORTS_DES_ECB == TRUE) || defined(__DOXYGEN__) /** * @brief Encryption operation using (T)DES-ECB. * @note The function operates on data buffers whose length is a multiple @@ -718,6 +761,8 @@ cryerror_t cry_lld_decrypt_DES(CRYDriver *cryp, * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid * or refers to an empty key slot. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -757,6 +802,8 @@ cryerror_t cry_lld_encrypt_DES_ECB(CRYDriver *cryp, * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid * or refers to an empty key slot. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -774,7 +821,9 @@ cryerror_t cry_lld_decrypt_DES_ECB(CRYDriver *cryp, return CRY_ERR_INV_ALGO; } +#endif +#if (CRY_LLD_SUPPORTS_DES_CBC == TRUE) || defined(__DOXYGEN__) /** * @brief Encryption operation using (T)DES-CBC. * @note The function operates on data buffers whose length is a multiple @@ -797,6 +846,8 @@ cryerror_t cry_lld_decrypt_DES_ECB(CRYDriver *cryp, * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid * or refers to an empty key slot. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -839,6 +890,8 @@ cryerror_t cry_lld_encrypt_DES_CBC(CRYDriver *cryp, * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid * or refers to an empty key slot. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -858,7 +911,9 @@ cryerror_t cry_lld_decrypt_DES_CBC(CRYDriver *cryp, return CRY_ERR_INV_ALGO; } +#endif +#if (CRY_LLD_SUPPORTS_SHA1 == TRUE) || defined(__DOXYGEN__) /** * @brief Hash initialization using SHA1. * @note Use of this algorithm is not recommended because proven weak. @@ -868,6 +923,8 @@ cryerror_t cry_lld_decrypt_DES_CBC(CRYDriver *cryp, * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -891,6 +948,8 @@ cryerror_t cry_lld_SHA1_init(CRYDriver *cryp, SHA1Context *sha1ctxp) { * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -916,6 +975,8 @@ cryerror_t cry_lld_SHA1_update(CRYDriver *cryp, SHA1Context *sha1ctxp, * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -928,7 +989,9 @@ cryerror_t cry_lld_SHA1_final(CRYDriver *cryp, SHA1Context *sha1ctxp, return CRY_ERR_INV_ALGO; } +#endif +#if (CRY_LLD_SUPPORTS_SHA256 == TRUE) || defined(__DOXYGEN__) /** * @brief Hash initialization using SHA256. * @@ -937,6 +1000,8 @@ cryerror_t cry_lld_SHA1_final(CRYDriver *cryp, SHA1Context *sha1ctxp, * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -959,6 +1024,8 @@ cryerror_t cry_lld_SHA256_init(CRYDriver *cryp, SHA256Context *sha256ctxp) { * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -983,6 +1050,8 @@ cryerror_t cry_lld_SHA256_update(CRYDriver *cryp, SHA256Context *sha256ctxp, * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -995,7 +1064,9 @@ cryerror_t cry_lld_SHA256_final(CRYDriver *cryp, SHA256Context *sha256ctxp, return CRY_ERR_INV_ALGO; } +#endif +#if (CRY_LLD_SUPPORTS_SHA512 == TRUE) || defined(__DOXYGEN__) /** * @brief Hash initialization using SHA512. * @@ -1004,6 +1075,8 @@ cryerror_t cry_lld_SHA256_final(CRYDriver *cryp, SHA256Context *sha256ctxp, * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -1026,6 +1099,8 @@ cryerror_t cry_lld_SHA512_init(CRYDriver *cryp, SHA512Context *sha512ctxp) { * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -1050,6 +1125,8 @@ cryerror_t cry_lld_SHA512_update(CRYDriver *cryp, SHA512Context *sha512ctxp, * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -1062,6 +1139,7 @@ cryerror_t cry_lld_SHA512_final(CRYDriver *cryp, SHA512Context *sha512ctxp, return CRY_ERR_INV_ALGO; } +#endif #if (CRY_LLD_SUPPORTS_HMAC_SHA256 == TRUE) || defined(__DOXYGEN__) /** @@ -1075,6 +1153,8 @@ cryerror_t cry_lld_SHA512_final(CRYDriver *cryp, SHA512Context *sha512ctxp, * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -1099,6 +1179,8 @@ cryerror_t cry_lld_HMACSHA256_init(CRYDriver *cryp, * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -1126,6 +1208,8 @@ cryerror_t cry_lld_HMACSHA256_update(CRYDriver *cryp, * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -1139,7 +1223,7 @@ cryerror_t cry_lld_HMACSHA256_final(CRYDriver *cryp, return CRY_ERR_INV_ALGO; } -#endif /* CRY_LLD_SUPPORTS_HMAC_SHA256 */ +#endif #if (CRY_LLD_SUPPORTS_HMAC_SHA512 == TRUE) || defined(__DOXYGEN__) /** @@ -1153,6 +1237,8 @@ cryerror_t cry_lld_HMACSHA256_final(CRYDriver *cryp, * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -1177,6 +1263,8 @@ cryerror_t cry_lld_HMACSHA512_init(CRYDriver *cryp, * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -1204,6 +1292,8 @@ cryerror_t cry_lld_HMACSHA512_update(CRYDriver *cryp, * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -1217,8 +1307,9 @@ cryerror_t cry_lld_HMACSHA512_final(CRYDriver *cryp, return CRY_ERR_INV_ALGO; } -#endif /* CRY_LLD_SUPPORTS_HMAC_SHA512 */ +#endif +#if (CRY_LLD_SUPPORTS_TRNG == TRUE) || defined(__DOXYGEN__) /** * @brief True random numbers generator. * @@ -1228,6 +1319,8 @@ cryerror_t cry_lld_HMACSHA512_final(CRYDriver *cryp, * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -1238,6 +1331,7 @@ cryerror_t cry_lld_TRNG(CRYDriver *cryp, uint8_t *out) { return CRY_ERR_INV_ALGO; } +#endif #endif /* HAL_USE_CRY == TRUE */ 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 eba045390..641e3913a 100644 --- a/os/hal/ports/STM32/LLD/CRYPv1/hal_crypto_lld.h +++ b/os/hal/ports/STM32/LLD/CRYPv1/hal_crypto_lld.h @@ -50,7 +50,7 @@ #define CRY_LLD_SUPPORTS_HMAC_SHA256 TRUE #define CRY_LLD_SUPPORTS_HMAC_SHA512 TRUE #define CRY_LLD_SUPPORTS_TRNG TRUE -/** @{ */ +/** @} */ /*===========================================================================*/ /* Driver pre-compile time settings. */ @@ -195,6 +195,7 @@ extern "C" { cryalgorithm_t algorithm, size_t size, const uint8_t *keyp); +#if (CRY_LLD_SUPPORTS_AES == TRUE) || defined(__DOXYGEN__) cryerror_t cry_lld_encrypt_AES(CRYDriver *cryp, crykey_t key_id, const uint8_t *in, @@ -203,6 +204,8 @@ extern "C" { crykey_t key_id, const uint8_t *in, uint8_t *out); +#endif +#if (CRY_LLD_SUPPORTS_AES_ECB == TRUE) || defined(__DOXYGEN__) cryerror_t cry_lld_encrypt_AES_ECB(CRYDriver *cryp, crykey_t key_id, size_t size, @@ -213,6 +216,8 @@ extern "C" { size_t size, const uint8_t *in, uint8_t *out); +#endif +#if (CRY_LLD_SUPPORTS_AES_CBC == TRUE) || defined(__DOXYGEN__) cryerror_t cry_lld_encrypt_AES_CBC(CRYDriver *cryp, crykey_t key_id, size_t size, @@ -225,6 +230,8 @@ extern "C" { const uint8_t *in, uint8_t *out, const uint8_t *iv); +#endif +#if (CRY_LLD_SUPPORTS_AES_CFB == TRUE) || defined(__DOXYGEN__) cryerror_t cry_lld_encrypt_AES_CFB(CRYDriver *cryp, crykey_t key_id, size_t size, @@ -237,6 +244,8 @@ extern "C" { const uint8_t *in, uint8_t *out, const uint8_t *iv); +#endif +#if (CRY_LLD_SUPPORTS_AES_CTR == TRUE) || defined(__DOXYGEN__) cryerror_t cry_lld_encrypt_AES_CTR(CRYDriver *cryp, crykey_t key_id, size_t size, @@ -249,6 +258,8 @@ extern "C" { const uint8_t *in, uint8_t *out, const uint8_t *iv); +#endif +#if (CRY_LLD_SUPPORTS_AES_GCM == TRUE) || defined(__DOXYGEN__) cryerror_t cry_lld_encrypt_AES_GCM(CRYDriver *cryp, crykey_t key_id, size_t size, @@ -267,6 +278,8 @@ extern "C" { size_t aadsize, const uint8_t *aad, uint8_t *authtag); +#endif +#if (CRY_LLD_SUPPORTS_DES == TRUE) || defined(__DOXYGEN__) cryerror_t cry_lld_encrypt_DES(CRYDriver *cryp, crykey_t key_id, const uint8_t *in, @@ -275,6 +288,8 @@ extern "C" { crykey_t key_id, const uint8_t *in, uint8_t *out); +#endif +#if (CRY_LLD_SUPPORTS_DES_ECB == TRUE) || defined(__DOXYGEN__) cryerror_t cry_lld_encrypt_DES_ECB(CRYDriver *cryp, crykey_t key_id, size_t size, @@ -285,6 +300,8 @@ extern "C" { size_t size, const uint8_t *in, uint8_t *out); +#endif +#if (CRY_LLD_SUPPORTS_DES_CBC == TRUE) || defined(__DOXYGEN__) cryerror_t cry_lld_encrypt_DES_CBC(CRYDriver *cryp, crykey_t key_id, size_t size, @@ -297,27 +314,28 @@ extern "C" { const uint8_t *in, uint8_t *out, const uint8_t *iv); +#endif #if (CRY_LLD_SUPPORTS_SHA1 == TRUE) || defined(__DOXYGEN__) cryerror_t cry_lld_SHA1_init(CRYDriver *cryp, SHA1Context *sha1ctxp); cryerror_t cry_lld_SHA1_update(CRYDriver *cryp, SHA1Context *sha1ctxp, size_t size, const uint8_t *in); cryerror_t cry_lld_SHA1_final(CRYDriver *cryp, SHA1Context *sha1ctxp, uint8_t *out); -#endif /* CRY_LLD_SUPPORTS_SHA1 */ +#endif #if (CRY_LLD_SUPPORTS_SHA256 == TRUE) || defined(__DOXYGEN__) cryerror_t cry_lld_SHA256_init(CRYDriver *cryp, SHA256Context *sha256ctxp); cryerror_t cry_lld_SHA256_update(CRYDriver *cryp, SHA256Context *sha256ctxp, size_t size, const uint8_t *in); cryerror_t cry_lld_SHA256_final(CRYDriver *cryp, SHA256Context *sha256ctxp, uint8_t *out); -#endif /* CRY_LLD_SUPPORTS_SHA256 */ +#endif #if (CRY_LLD_SUPPORTS_SHA512 == TRUE) || defined(__DOXYGEN__) cryerror_t cry_lld_SHA512_init(CRYDriver *cryp, SHA512Context *sha512ctxp); cryerror_t cry_lld_SHA512_update(CRYDriver *cryp, SHA512Context *sha512ctxp, size_t size, const uint8_t *in); cryerror_t cry_lld_SHA512_final(CRYDriver *cryp, SHA512Context *sha512ctxp, uint8_t *out); -#endif /* CRY_LLD_SUPPORTS_SHA512 */ +#endif #if (CRY_LLD_SUPPORTS_HMAC_SHA256 == TRUE) || defined(__DOXYGEN__) cryerror_t cry_lld_HMACSHA256_init(CRYDriver *cryp, HMACSHA256Context *hmacsha256ctxp); @@ -327,7 +345,7 @@ extern "C" { cryerror_t cry_lld_HMACSHA256_final(CRYDriver *cryp, HMACSHA256Context *hmacsha256ctxp, uint8_t *out); -#endif /* CRY_LLD_SUPPORTS_HMAC_SHA256 */ +#endif #if (CRY_LLD_SUPPORTS_HMAC_SHA512 == TRUE) || defined(__DOXYGEN__) cryerror_t cry_lld_HMACSHA512_init(CRYDriver *cryp, HMACSHA512Context *hmacsha512ctxp); @@ -337,8 +355,10 @@ extern "C" { cryerror_t cry_lld_HMACSHA512_final(CRYDriver *cryp, HMACSHA512Context *hmacsha512ctxp, uint8_t *out); -#endif /* CRY_LLD_SUPPORTS_HMAC_SHA512 */ +#endif +#if (CRY_LLD_SUPPORTS_TRNG == TRUE) || defined(__DOXYGEN__) cryerror_t cry_lld_TRNG(CRYDriver *cryp, uint8_t *out); +#endif #ifdef __cplusplus } #endif diff --git a/os/hal/src/hal_crypto.c b/os/hal/src/hal_crypto.c index 25e3aa553..f49987878 100644 --- a/os/hal/src/hal_crypto.c +++ b/os/hal/src/hal_crypto.c @@ -193,6 +193,8 @@ cryerror_t cryLoadTransientKey(CRYDriver *cryp, * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid * or refers to an empty key slot. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @special */ @@ -237,6 +239,8 @@ cryerror_t cryEncryptAES(CRYDriver *cryp, * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid * or refers to an empty key slot. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @special */ @@ -284,6 +288,8 @@ cryerror_t cryDecryptAES(CRYDriver *cryp, * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid * or refers to an empty key slot. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @api */ @@ -334,6 +340,8 @@ cryerror_t cryEncryptAES_ECB(CRYDriver *cryp, * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid * or refers to an empty key slot. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @api */ @@ -385,6 +393,8 @@ cryerror_t cryDecryptAES_ECB(CRYDriver *cryp, * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid * or refers to an empty key slot. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @api */ @@ -438,6 +448,8 @@ cryerror_t cryEncryptAES_CBC(CRYDriver *cryp, * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid * or refers to an empty key slot. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @api */ @@ -491,6 +503,8 @@ cryerror_t cryDecryptAES_CBC(CRYDriver *cryp, * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid * or refers to an empty key slot. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @api */ @@ -544,6 +558,8 @@ cryerror_t cryEncryptAES_CFB(CRYDriver *cryp, * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid * or refers to an empty key slot. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @api */ @@ -598,6 +614,8 @@ cryerror_t cryDecryptAES_CFB(CRYDriver *cryp, * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid * or refers to an empty key slot. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @api */ @@ -652,6 +670,8 @@ cryerror_t cryEncryptAES_CTR(CRYDriver *cryp, * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid * or refers to an empty key slot. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @api */ @@ -711,6 +731,8 @@ cryerror_t cryDecryptAES_CTR(CRYDriver *cryp, * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid * or refers to an empty key slot. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @api */ @@ -780,6 +802,8 @@ cryerror_t cryEncryptAES_GCM(CRYDriver *cryp, * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid * or refers to an empty key slot. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @api */ @@ -839,6 +863,8 @@ cryerror_t cryDecryptAES_GCM(CRYDriver *cryp, * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid * or refers to an empty key slot. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @special */ @@ -884,6 +910,8 @@ cryerror_t cryEncryptDES(CRYDriver *cryp, * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid * or refers to an empty key slot. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @special */ @@ -931,6 +959,8 @@ cryerror_t cryDecryptDES(CRYDriver *cryp, * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid * or refers to an empty key slot. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @api */ @@ -981,6 +1011,8 @@ cryerror_t cryEncryptDES_ECB(CRYDriver *cryp, * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid * or refers to an empty key slot. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @api */ @@ -1032,6 +1064,8 @@ cryerror_t cryDecryptDES_ECB(CRYDriver *cryp, * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid * or refers to an empty key slot. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @api */ @@ -1085,6 +1119,8 @@ cryerror_t cryEncryptDES_CBC(CRYDriver *cryp, * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid * or refers to an empty key slot. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @api */ @@ -1126,6 +1162,8 @@ cryerror_t cryDecryptDES_CBC(CRYDriver *cryp, * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @api */ @@ -1159,6 +1197,8 @@ cryerror_t crySHA1Init(CRYDriver *cryp, SHA1Context *sha1ctxp) { * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @api */ @@ -1194,6 +1234,8 @@ cryerror_t crySHA1Update(CRYDriver *cryp, SHA1Context *sha1ctxp, * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @api */ @@ -1226,6 +1268,8 @@ cryerror_t crySHA1Final(CRYDriver *cryp, SHA1Context *sha1ctxp, uint8_t *out) { * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @api */ @@ -1259,6 +1303,8 @@ cryerror_t crySHA256Init(CRYDriver *cryp, SHA256Context *sha256ctxp) { * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @api */ @@ -1294,6 +1340,8 @@ cryerror_t crySHA256Update(CRYDriver *cryp, SHA256Context *sha256ctxp, * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @api */ @@ -1327,6 +1375,8 @@ cryerror_t crySHA256Final(CRYDriver *cryp, SHA256Context *sha256ctxp, * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @api */ @@ -1360,6 +1410,8 @@ cryerror_t crySHA512Init(CRYDriver *cryp, SHA512Context *sha512ctxp) { * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @api */ @@ -1395,6 +1447,8 @@ cryerror_t crySHA512Update(CRYDriver *cryp, SHA512Context *sha512ctxp, * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @api */ @@ -1418,7 +1472,6 @@ cryerror_t crySHA512Final(CRYDriver *cryp, SHA512Context *sha512ctxp, #endif } -#if (CRY_LLD_SUPPORTS_HMAC_SHA256 == TRUE) || defined(__DOXYGEN__) /** * @brief Hash initialization using HMAC_SHA256. * @note Use of this algorithm is not recommended because proven weak. @@ -1430,6 +1483,8 @@ cryerror_t crySHA512Final(CRYDriver *cryp, SHA512Context *sha512ctxp, * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @api */ @@ -1464,6 +1519,8 @@ cryerror_t cryHMACSHA256Init(CRYDriver *cryp, * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @api */ @@ -1501,6 +1558,8 @@ cryerror_t cryHMACSHA256Update(CRYDriver *cryp, * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @api */ @@ -1524,9 +1583,7 @@ cryerror_t cryHMACSHA256Final(CRYDriver *cryp, return CRY_ERR_INV_ALGO; #endif } -#endif /* CRY_LLD_SUPPORTS_HMAC_SHA256 */ -#if (CRY_LLD_SUPPORTS_HMAC_SHA256 == TRUE) || defined(__DOXYGEN__) /** * @brief Hash initialization using HMAC_SHA512. * @note Use of this algorithm is not recommended because proven weak. @@ -1538,6 +1595,8 @@ cryerror_t cryHMACSHA256Final(CRYDriver *cryp, * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @api */ @@ -1572,6 +1631,8 @@ cryerror_t cryHMACSHA512Init(CRYDriver *cryp, * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @api */ @@ -1609,6 +1670,8 @@ cryerror_t cryHMACSHA512Update(CRYDriver *cryp, * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @api */ @@ -1632,7 +1695,6 @@ cryerror_t cryHMACSHA512Final(CRYDriver *cryp, return CRY_ERR_INV_ALGO; #endif } -#endif /* CRY_LLD_SUPPORTS_HMAC_SHA256 */ /** * @brief True random numbers generator. @@ -1643,6 +1705,8 @@ cryerror_t cryHMACSHA512Final(CRYDriver *cryp, * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @api */ diff --git a/os/hal/templates/hal_crypto_lld.c b/os/hal/templates/hal_crypto_lld.c index 5aea1aa7e..5b08cacd1 100644 --- a/os/hal/templates/hal_crypto_lld.c +++ b/os/hal/templates/hal_crypto_lld.c @@ -120,6 +120,7 @@ cryerror_t cry_lld_loadkey(CRYDriver *cryp, return CRY_NOERROR; } +#if (CRY_LLD_SUPPORTS_AES == TRUE) || defined(__DOXYGEN__) /** * @brief Encryption of a single block using AES. * @note The implementation of this function must guarantee that it can @@ -138,6 +139,8 @@ cryerror_t cry_lld_loadkey(CRYDriver *cryp, * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid * or refers to an empty key slot. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -172,6 +175,8 @@ cryerror_t cry_lld_encrypt_AES(CRYDriver *cryp, * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid * or refers to an empty key slot. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -187,7 +192,9 @@ cryerror_t cry_lld_decrypt_AES(CRYDriver *cryp, return CRY_ERR_INV_ALGO; } +#endif +#if (CRY_LLD_SUPPORTS_AES_ECB == TRUE) || defined(__DOXYGEN__) /** * @brief Encryption operation using AES-ECB. * @note The function operates on data buffers whose lenght is a multiple @@ -209,6 +216,8 @@ cryerror_t cry_lld_decrypt_AES(CRYDriver *cryp, * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid * or refers to an empty key slot. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -248,6 +257,8 @@ cryerror_t cry_lld_encrypt_AES_ECB(CRYDriver *cryp, * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid * or refers to an empty key slot. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -265,7 +276,9 @@ cryerror_t cry_lld_decrypt_AES_ECB(CRYDriver *cryp, return CRY_ERR_INV_ALGO; } +#endif +#if (CRY_LLD_SUPPORTS_AES_CBC == TRUE) || defined(__DOXYGEN__) /** * @brief Encryption operation using AES-CBC. * @note The function operates on data buffers whose lenght is a multiple @@ -288,6 +301,8 @@ cryerror_t cry_lld_decrypt_AES_ECB(CRYDriver *cryp, * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid * or refers to an empty key slot. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -330,6 +345,8 @@ cryerror_t cry_lld_encrypt_AES_CBC(CRYDriver *cryp, * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid * or refers to an empty key slot. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -349,7 +366,9 @@ cryerror_t cry_lld_decrypt_AES_CBC(CRYDriver *cryp, return CRY_ERR_INV_ALGO; } +#endif +#if (CRY_LLD_SUPPORTS_AES_CFB == TRUE) || defined(__DOXYGEN__) /** * @brief Encryption operation using AES-CFB. * @note The function operates on data buffers whose lenght is a multiple @@ -372,6 +391,8 @@ cryerror_t cry_lld_decrypt_AES_CBC(CRYDriver *cryp, * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid * or refers to an empty key slot. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -414,6 +435,8 @@ cryerror_t cry_lld_encrypt_AES_CFB(CRYDriver *cryp, * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid * or refers to an empty key slot. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -433,7 +456,9 @@ cryerror_t cry_lld_decrypt_AES_CFB(CRYDriver *cryp, return CRY_ERR_INV_ALGO; } +#endif +#if (CRY_LLD_SUPPORTS_AES_CTR == TRUE) || defined(__DOXYGEN__) /** * @brief Encryption operation using AES-CTR. * @note The function operates on data buffers whose lenght is a multiple @@ -457,6 +482,8 @@ cryerror_t cry_lld_decrypt_AES_CFB(CRYDriver *cryp, * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid * or refers to an empty key slot. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -500,6 +527,8 @@ cryerror_t cry_lld_encrypt_AES_CTR(CRYDriver *cryp, * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid * or refers to an empty key slot. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -519,7 +548,9 @@ cryerror_t cry_lld_decrypt_AES_CTR(CRYDriver *cryp, return CRY_ERR_INV_ALGO; } +#endif +#if (CRY_LLD_SUPPORTS_AES_GCM == TRUE) || defined(__DOXYGEN__) /** * @brief Encryption operation using AES-GCM. * @note The function operates on data buffers whose lenght is a multiple @@ -548,6 +579,8 @@ cryerror_t cry_lld_decrypt_AES_CTR(CRYDriver *cryp, * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid * or refers to an empty key slot. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -602,6 +635,8 @@ cryerror_t cry_lld_encrypt_AES_GCM(CRYDriver *cryp, * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid * or refers to an empty key slot. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -627,7 +662,9 @@ cryerror_t cry_lld_decrypt_AES_GCM(CRYDriver *cryp, return CRY_ERR_INV_ALGO; } +#endif +#if (CRY_LLD_SUPPORTS_DES == TRUE) || defined(__DOXYGEN__) /** * @brief Encryption of a single block using (T)DES. * @note The implementation of this function must guarantee that it can @@ -646,6 +683,8 @@ cryerror_t cry_lld_decrypt_AES_GCM(CRYDriver *cryp, * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid * or refers to an empty key slot. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -681,6 +720,8 @@ cryerror_t cry_lld_encrypt_DES(CRYDriver *cryp, * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid * or refers to an empty key slot. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -696,7 +737,9 @@ cryerror_t cry_lld_decrypt_DES(CRYDriver *cryp, return CRY_ERR_INV_ALGO; } +#endif +#if (CRY_LLD_SUPPORTS_DES_ECB == TRUE) || defined(__DOXYGEN__) /** * @brief Encryption operation using (T)DES-ECB. * @note The function operates on data buffers whose length is a multiple @@ -718,6 +761,8 @@ cryerror_t cry_lld_decrypt_DES(CRYDriver *cryp, * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid * or refers to an empty key slot. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -757,6 +802,8 @@ cryerror_t cry_lld_encrypt_DES_ECB(CRYDriver *cryp, * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid * or refers to an empty key slot. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -774,7 +821,9 @@ cryerror_t cry_lld_decrypt_DES_ECB(CRYDriver *cryp, return CRY_ERR_INV_ALGO; } +#endif +#if (CRY_LLD_SUPPORTS_DES_CBC == TRUE) || defined(__DOXYGEN__) /** * @brief Encryption operation using (T)DES-CBC. * @note The function operates on data buffers whose length is a multiple @@ -797,6 +846,8 @@ cryerror_t cry_lld_decrypt_DES_ECB(CRYDriver *cryp, * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid * or refers to an empty key slot. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -839,6 +890,8 @@ cryerror_t cry_lld_encrypt_DES_CBC(CRYDriver *cryp, * @retval CRY_ERR_INV_KEY_TYPE the selected key is invalid for this operation. * @retval CRY_ERR_INV_KEY_ID if the specified key identifier is invalid * or refers to an empty key slot. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -858,7 +911,9 @@ cryerror_t cry_lld_decrypt_DES_CBC(CRYDriver *cryp, return CRY_ERR_INV_ALGO; } +#endif +#if (CRY_LLD_SUPPORTS_SHA1 == TRUE) || defined(__DOXYGEN__) /** * @brief Hash initialization using SHA1. * @note Use of this algorithm is not recommended because proven weak. @@ -868,6 +923,8 @@ cryerror_t cry_lld_decrypt_DES_CBC(CRYDriver *cryp, * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -891,6 +948,8 @@ cryerror_t cry_lld_SHA1_init(CRYDriver *cryp, SHA1Context *sha1ctxp) { * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -916,6 +975,8 @@ cryerror_t cry_lld_SHA1_update(CRYDriver *cryp, SHA1Context *sha1ctxp, * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -928,7 +989,9 @@ cryerror_t cry_lld_SHA1_final(CRYDriver *cryp, SHA1Context *sha1ctxp, return CRY_ERR_INV_ALGO; } +#endif +#if (CRY_LLD_SUPPORTS_SHA256 == TRUE) || defined(__DOXYGEN__) /** * @brief Hash initialization using SHA256. * @@ -937,6 +1000,8 @@ cryerror_t cry_lld_SHA1_final(CRYDriver *cryp, SHA1Context *sha1ctxp, * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -959,6 +1024,8 @@ cryerror_t cry_lld_SHA256_init(CRYDriver *cryp, SHA256Context *sha256ctxp) { * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -983,6 +1050,8 @@ cryerror_t cry_lld_SHA256_update(CRYDriver *cryp, SHA256Context *sha256ctxp, * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -995,7 +1064,9 @@ cryerror_t cry_lld_SHA256_final(CRYDriver *cryp, SHA256Context *sha256ctxp, return CRY_ERR_INV_ALGO; } +#endif +#if (CRY_LLD_SUPPORTS_SHA512 == TRUE) || defined(__DOXYGEN__) /** * @brief Hash initialization using SHA512. * @@ -1004,6 +1075,8 @@ cryerror_t cry_lld_SHA256_final(CRYDriver *cryp, SHA256Context *sha256ctxp, * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -1026,6 +1099,8 @@ cryerror_t cry_lld_SHA512_init(CRYDriver *cryp, SHA512Context *sha512ctxp) { * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -1050,6 +1125,8 @@ cryerror_t cry_lld_SHA512_update(CRYDriver *cryp, SHA512Context *sha512ctxp, * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -1062,7 +1139,9 @@ cryerror_t cry_lld_SHA512_final(CRYDriver *cryp, SHA512Context *sha512ctxp, return CRY_ERR_INV_ALGO; } +#endif +#if (CRY_LLD_SUPPORTS_HMAC_SHA256 == TRUE) || defined(__DOXYGEN__) /** * @brief Hash initialization using HMAC_SHA256. * @note Use of this algorithm is not recommended because proven weak. @@ -1074,6 +1153,8 @@ cryerror_t cry_lld_SHA512_final(CRYDriver *cryp, SHA512Context *sha512ctxp, * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -1098,6 +1179,8 @@ cryerror_t cry_lld_HMACSHA256_init(CRYDriver *cryp, * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -1125,6 +1208,8 @@ cryerror_t cry_lld_HMACSHA256_update(CRYDriver *cryp, * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -1138,7 +1223,9 @@ cryerror_t cry_lld_HMACSHA256_final(CRYDriver *cryp, return CRY_ERR_INV_ALGO; } +#endif +#if (CRY_LLD_SUPPORTS_HMAC_SHA512 == TRUE) || defined(__DOXYGEN__) /** * @brief Hash initialization using HMAC_SHA512. * @note Use of this algorithm is not recommended because proven weak. @@ -1150,6 +1237,8 @@ cryerror_t cry_lld_HMACSHA256_final(CRYDriver *cryp, * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -1174,6 +1263,8 @@ cryerror_t cry_lld_HMACSHA512_init(CRYDriver *cryp, * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -1201,6 +1292,8 @@ cryerror_t cry_lld_HMACSHA512_update(CRYDriver *cryp, * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -1214,7 +1307,9 @@ cryerror_t cry_lld_HMACSHA512_final(CRYDriver *cryp, return CRY_ERR_INV_ALGO; } +#endif +#if (CRY_LLD_SUPPORTS_TRNG == TRUE) || defined(__DOXYGEN__) /** * @brief True random numbers generator. * @@ -1224,6 +1319,8 @@ cryerror_t cry_lld_HMACSHA512_final(CRYDriver *cryp, * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. + * @retval CRY_ERR_OP_FAILURE if the operation failed, implementation + * dependent. * * @notapi */ @@ -1234,6 +1331,7 @@ cryerror_t cry_lld_TRNG(CRYDriver *cryp, uint8_t *out) { return CRY_ERR_INV_ALGO; } +#endif #endif /* HAL_USE_CRY == TRUE */ diff --git a/os/hal/templates/hal_crypto_lld.h b/os/hal/templates/hal_crypto_lld.h index 96f567da7..d3def1e53 100644 --- a/os/hal/templates/hal_crypto_lld.h +++ b/os/hal/templates/hal_crypto_lld.h @@ -195,6 +195,7 @@ extern "C" { cryalgorithm_t algorithm, size_t size, const uint8_t *keyp); +#if (CRY_LLD_SUPPORTS_AES == TRUE) || defined(__DOXYGEN__) cryerror_t cry_lld_encrypt_AES(CRYDriver *cryp, crykey_t key_id, const uint8_t *in, @@ -203,6 +204,8 @@ extern "C" { crykey_t key_id, const uint8_t *in, uint8_t *out); +#endif +#if (CRY_LLD_SUPPORTS_AES_ECB == TRUE) || defined(__DOXYGEN__) cryerror_t cry_lld_encrypt_AES_ECB(CRYDriver *cryp, crykey_t key_id, size_t size, @@ -213,6 +216,8 @@ extern "C" { size_t size, const uint8_t *in, uint8_t *out); +#endif +#if (CRY_LLD_SUPPORTS_AES_CBC == TRUE) || defined(__DOXYGEN__) cryerror_t cry_lld_encrypt_AES_CBC(CRYDriver *cryp, crykey_t key_id, size_t size, @@ -225,6 +230,8 @@ extern "C" { const uint8_t *in, uint8_t *out, const uint8_t *iv); +#endif +#if (CRY_LLD_SUPPORTS_AES_CFB == TRUE) || defined(__DOXYGEN__) cryerror_t cry_lld_encrypt_AES_CFB(CRYDriver *cryp, crykey_t key_id, size_t size, @@ -237,6 +244,8 @@ extern "C" { const uint8_t *in, uint8_t *out, const uint8_t *iv); +#endif +#if (CRY_LLD_SUPPORTS_AES_CTR == TRUE) || defined(__DOXYGEN__) cryerror_t cry_lld_encrypt_AES_CTR(CRYDriver *cryp, crykey_t key_id, size_t size, @@ -249,6 +258,8 @@ extern "C" { const uint8_t *in, uint8_t *out, const uint8_t *iv); +#endif +#if (CRY_LLD_SUPPORTS_AES_GCM == TRUE) || defined(__DOXYGEN__) cryerror_t cry_lld_encrypt_AES_GCM(CRYDriver *cryp, crykey_t key_id, size_t size, @@ -267,6 +278,8 @@ extern "C" { size_t aadsize, const uint8_t *aad, uint8_t *authtag); +#endif +#if (CRY_LLD_SUPPORTS_DES == TRUE) || defined(__DOXYGEN__) cryerror_t cry_lld_encrypt_DES(CRYDriver *cryp, crykey_t key_id, const uint8_t *in, @@ -275,6 +288,8 @@ extern "C" { crykey_t key_id, const uint8_t *in, uint8_t *out); +#endif +#if (CRY_LLD_SUPPORTS_DES_ECB == TRUE) || defined(__DOXYGEN__) cryerror_t cry_lld_encrypt_DES_ECB(CRYDriver *cryp, crykey_t key_id, size_t size, @@ -285,6 +300,8 @@ extern "C" { size_t size, const uint8_t *in, uint8_t *out); +#endif +#if (CRY_LLD_SUPPORTS_DES_CBC == TRUE) || defined(__DOXYGEN__) cryerror_t cry_lld_encrypt_DES_CBC(CRYDriver *cryp, crykey_t key_id, size_t size, @@ -297,21 +314,29 @@ extern "C" { const uint8_t *in, uint8_t *out, const uint8_t *iv); +#endif +#if (CRY_LLD_SUPPORTS_SHA1 == TRUE) || defined(__DOXYGEN__) cryerror_t cry_lld_SHA1_init(CRYDriver *cryp, SHA1Context *sha1ctxp); cryerror_t cry_lld_SHA1_update(CRYDriver *cryp, SHA1Context *sha1ctxp, size_t size, const uint8_t *in); cryerror_t cry_lld_SHA1_final(CRYDriver *cryp, SHA1Context *sha1ctxp, uint8_t *out); +#endif +#if (CRY_LLD_SUPPORTS_SHA256 == TRUE) || defined(__DOXYGEN__) cryerror_t cry_lld_SHA256_init(CRYDriver *cryp, SHA256Context *sha256ctxp); cryerror_t cry_lld_SHA256_update(CRYDriver *cryp, SHA256Context *sha256ctxp, size_t size, const uint8_t *in); cryerror_t cry_lld_SHA256_final(CRYDriver *cryp, SHA256Context *sha256ctxp, uint8_t *out); +#endif +#if (CRY_LLD_SUPPORTS_SHA512 == TRUE) || defined(__DOXYGEN__) cryerror_t cry_lld_SHA512_init(CRYDriver *cryp, SHA512Context *sha512ctxp); cryerror_t cry_lld_SHA512_update(CRYDriver *cryp, SHA512Context *sha512ctxp, size_t size, const uint8_t *in); cryerror_t cry_lld_SHA512_final(CRYDriver *cryp, SHA512Context *sha512ctxp, uint8_t *out); +#endif +#if (CRY_LLD_SUPPORTS_HMAC_SHA256 == TRUE) || defined(__DOXYGEN__) cryerror_t cry_lld_HMACSHA256_init(CRYDriver *cryp, HMACSHA256Context *hmacsha256ctxp); cryerror_t cry_lld_HMACSHA256_update(CRYDriver *cryp, @@ -320,6 +345,8 @@ extern "C" { cryerror_t cry_lld_HMACSHA256_final(CRYDriver *cryp, HMACSHA256Context *hmacsha256ctxp, uint8_t *out); +#endif +#if (CRY_LLD_SUPPORTS_HMAC_SHA512 == TRUE) || defined(__DOXYGEN__) cryerror_t cry_lld_HMACSHA512_init(CRYDriver *cryp, HMACSHA512Context *hmacsha512ctxp); cryerror_t cry_lld_HMACSHA512_update(CRYDriver *cryp, @@ -328,7 +355,10 @@ extern "C" { cryerror_t cry_lld_HMACSHA512_final(CRYDriver *cryp, HMACSHA512Context *hmacsha512ctxp, uint8_t *out); +#endif +#if (CRY_LLD_SUPPORTS_TRNG == TRUE) || defined(__DOXYGEN__) cryerror_t cry_lld_TRNG(CRYDriver *cryp, uint8_t *out); +#endif #ifdef __cplusplus } #endif -- cgit v1.2.3