From 0b1cba4c2e057efcbd652a4026c6bc10527cac41 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Fri, 9 Mar 2018 11:37:12 +0000 Subject: Crypto SHA reworked. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@11663 110e8d01-0319-4d1e-a829-52ad28d1bb01 --- os/hal/ports/STM32/LLD/CRYPv1/hal_crypto_lld.c | 558 +++++++++++++++---------- os/hal/ports/STM32/LLD/CRYPv1/hal_crypto_lld.h | 48 ++- 2 files changed, 387 insertions(+), 219 deletions(-) (limited to 'os/hal/ports/STM32/LLD/CRYPv1') 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 d9d7c377d..bdbebe47d 100644 --- a/os/hal/ports/STM32/LLD/CRYPv1/hal_crypto_lld.c +++ b/os/hal/ports/STM32/LLD/CRYPv1/hal_crypto_lld.c @@ -67,7 +67,7 @@ void cry_lld_init(void) { /** * @brief Configures and activates the crypto peripheral. * - * @param[in] cryp pointer to the @p CRYDriver object + * @param[in] cryp pointer to the @p CRYDriver object * * @notapi */ @@ -81,7 +81,7 @@ void cry_lld_start(CRYDriver *cryp) { /** * @brief Deactivates the crypto peripheral. * - * @param[in] cryp pointer to the @p CRYDriver object + * @param[in] cryp pointer to the @p CRYDriver object * * @notapi */ @@ -95,9 +95,11 @@ 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. + * @param[in] cryp pointer to the @p CRYDriver object + * @param[in] algorithm the algorithm identifier + * @param[in] size key size in bytes + * @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. @@ -123,13 +125,13 @@ cryerror_t cry_lld_loadkey(CRYDriver *cryp, * @note The implementation of this function must guarantee that it can * be called from any context. * - * @param[in] cryp pointer to the @p CRYDriver object - * @param[in] key_id the key to be used for the operation, zero is the - * transient key, other values are keys stored in an - * unspecified way - * @param[in] in buffer containing the input plaintext - * @param[out] out buffer for the output cyphertext - * @return The operation status. + * @param[in] cryp pointer to the @p CRYDriver object + * @param[in] key_id the key to be used for the operation, zero is + * the transient key, other values are keys stored + * in an unspecified way + * @param[in] in buffer containing the input plaintext + * @param[out] out buffer for the output cyphertext + * @return The operation status. * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. @@ -157,13 +159,13 @@ cryerror_t cry_lld_encrypt_AES(CRYDriver *cryp, * @note The implementation of this function must guarantee that it can * be called from any context. * - * @param[in] cryp pointer to the @p CRYDriver object - * @param[in] key_id the key to be used for the operation, zero is the - * transient key, other values are keys stored in an - * unspecified way - * @param[in] in buffer containing the input cyphertext - * @param[out] out buffer for the output plaintext - * @return The operation status. + * @param[in] cryp pointer to the @p CRYDriver object + * @param[in] key_id the key to be used for the operation, zero is + * the transient key, other values are keys stored + * in an unspecified way + * @param[in] in buffer containing the input cyphertext + * @param[out] out buffer for the output plaintext + * @return The operation status. * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. @@ -192,15 +194,15 @@ cryerror_t cry_lld_decrypt_AES(CRYDriver *cryp, * of an AES block, this means that padding must be done by the * caller. * - * @param[in] cryp pointer to the @p CRYDriver object - * @param[in] key_id the key to be used for the operation, zero is the - * transient key, other values are keys stored in an - * unspecified way - * @param[in] size size of the plaintext buffer, this number must be a - * multiple of the selected key size - * @param[in] in buffer containing the input plaintext - * @param[out] out buffer for the output cyphertext - * @return The operation status. + * @param[in] cryp pointer to the @p CRYDriver object + * @param[in] key_id the key to be used for the operation, zero is + * the transient key, other values are keys stored + * in an unspecified way + * @param[in] size size of the plaintext buffer, this number must + * be a multiple of the selected key size + * @param[in] in buffer containing the input plaintext + * @param[out] out buffer for the output cyphertext + * @return The operation status. * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. @@ -231,15 +233,15 @@ cryerror_t cry_lld_encrypt_AES_ECB(CRYDriver *cryp, * of an AES block, this means that padding must be done by the * caller. * - * @param[in] cryp pointer to the @p CRYDriver object - * @param[in] key_id the key to be used for the operation, zero is the - * transient key, other values are keys stored in an - * unspecified way - * @param[in] size size of the plaintext buffer, this number must be a - * multiple of the selected key size - * @param[in] in buffer containing the input plaintext - * @param[out] out buffer for the output cyphertext - * @return The operation status. + * @param[in] cryp pointer to the @p CRYDriver object + * @param[in] key_id the key to be used for the operation, zero is + * the transient key, other values are keys stored + * in an unspecified way + * @param[in] size size of the plaintext buffer, this number must + * be a multiple of the selected key size + * @param[in] in buffer containing the input plaintext + * @param[out] out buffer for the output cyphertext + * @return The operation status. * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. @@ -270,16 +272,16 @@ cryerror_t cry_lld_decrypt_AES_ECB(CRYDriver *cryp, * of an AES block, this means that padding must be done by the * caller. * - * @param[in] cryp pointer to the @p CRYDriver object - * @param[in] key_id the key to be used for the operation, zero is the - * transient key, other values are keys stored in an - * unspecified way - * @param[in] size size of the plaintext buffer, this number must be a - * multiple of the selected key size - * @param[in] in buffer containing the input plaintext - * @param[out] out buffer for the output cyphertext - * @param[in] iv 128 bits initial vector - * @return The operation status. + * @param[in] cryp pointer to the @p CRYDriver object + * @param[in] key_id the key to be used for the operation, zero is + * the transient key, other values are keys stored + * in an unspecified way + * @param[in] size size of the plaintext buffer, this number must + * be a multiple of the selected key size + * @param[in] in buffer containing the input plaintext + * @param[out] out buffer for the output cyphertext + * @param[in] iv 128 bits initial vector + * @return The operation status. * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. @@ -312,16 +314,16 @@ cryerror_t cry_lld_encrypt_AES_CBC(CRYDriver *cryp, * of an AES block, this means that padding must be done by the * caller. * - * @param[in] cryp pointer to the @p CRYDriver object - * @param[in] key_id the key to be used for the operation, zero is the - * transient key, other values are keys stored in an - * unspecified way - * @param[in] size size of the plaintext buffer, this number must be a - * multiple of the selected key size - * @param[in] in buffer containing the input plaintext - * @param[out] out buffer for the output cyphertext - * @param[in] iv 128 bits initial vector - * @return The operation status. + * @param[in] cryp pointer to the @p CRYDriver object + * @param[in] key_id the key to be used for the operation, zero is + * the transient key, other values are keys stored + * in an unspecified way + * @param[in] size size of the plaintext buffer, this number must + * be a multiple of the selected key size + * @param[in] in buffer containing the input plaintext + * @param[out] out buffer for the output cyphertext + * @param[in] iv 128 bits initial vector + * @return The operation status. * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. @@ -354,16 +356,16 @@ cryerror_t cry_lld_decrypt_AES_CBC(CRYDriver *cryp, * of an AES block, this means that padding must be done by the * caller. * - * @param[in] cryp pointer to the @p CRYDriver object - * @param[in] key_id the key to be used for the operation, zero is the - * transient key, other values are keys stored in an - * unspecified way - * @param[in] size size of the plaintext buffer, this number must be a - * multiple of the selected key size - * @param[in] in buffer containing the input plaintext - * @param[out] out buffer for the output cyphertext - * @param[in] iv 128 bits initial vector - * @return The operation status. + * @param[in] cryp pointer to the @p CRYDriver object + * @param[in] key_id the key to be used for the operation, zero is + * the transient key, other values are keys stored + * in an unspecified way + * @param[in] size size of the plaintext buffer, this number must + * be a multiple of the selected key size + * @param[in] in buffer containing the input plaintext + * @param[out] out buffer for the output cyphertext + * @param[in] iv 128 bits initial vector + * @return The operation status. * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. @@ -396,16 +398,16 @@ cryerror_t cry_lld_encrypt_AES_CFB(CRYDriver *cryp, * of an AES block, this means that padding must be done by the * caller. * - * @param[in] cryp pointer to the @p CRYDriver object - * @param[in] key_id the key to be used for the operation, zero is the - * transient key, other values are keys stored in an - * unspecified way - * @param[in] size size of the plaintext buffer, this number must be a - * multiple of the selected key size - * @param[in] in buffer containing the input plaintext - * @param[out] out buffer for the output cyphertext - * @param[in] iv 128 bits initial vector - * @return The operation status. + * @param[in] cryp pointer to the @p CRYDriver object + * @param[in] key_id the key to be used for the operation, zero is + * the transient key, other values are keys stored + * in an unspecified way + * @param[in] size size of the plaintext buffer, this number must + * be a multiple of the selected key size + * @param[in] in buffer containing the input plaintext + * @param[out] out buffer for the output cyphertext + * @param[in] iv 128 bits initial vector + * @return The operation status. * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. @@ -438,17 +440,17 @@ cryerror_t cry_lld_decrypt_AES_CFB(CRYDriver *cryp, * of an AES block, this means that padding must be done by the * caller. * - * @param[in] cryp pointer to the @p CRYDriver object - * @param[in] key_id the key to be used for the operation, zero is the - * transient key, other values are keys stored in an - * unspecified way - * @param[in] size size of the plaintext buffer, this number must be a - * multiple of 16 - * @param[in] in buffer containing the input plaintext - * @param[out] out buffer for the output cyphertext - * @param[in] iv 128 bits initial vector + counter, it contains - * a 96 bits IV and a 32 bits counter - * @return The operation status. + * @param[in] cryp pointer to the @p CRYDriver object + * @param[in] key_id the key to be used for the operation, zero is + * the transient key, other values are keys stored + * in an unspecified way + * @param[in] size size of the plaintext buffer, this number must + * be a multiple of 16 + * @param[in] in buffer containing the input plaintext + * @param[out] out buffer for the output cyphertext + * @param[in] iv 128 bits initial vector + counter, it contains + * a 96 bits IV and a 32 bits counter + * @return The operation status. * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. @@ -481,17 +483,17 @@ cryerror_t cry_lld_encrypt_AES_CTR(CRYDriver *cryp, * of an AES block, this means that padding must be done by the * caller. * - * @param[in] cryp pointer to the @p CRYDriver object - * @param[in] key_id the key to be used for the operation, zero is the - * transient key, other values are keys stored in an - * unspecified way - * @param[in] size size of the plaintext buffer, this number must be a - * multiple of 16 - * @param[in] in buffer containing the input cyphertext - * @param[out] out buffer for the output plaintext - * @param[in] iv 128 bits initial vector + counter, it contains - * a 96 bits IV and a 32 bits counter - * @return The operation status. + * @param[in] cryp pointer to the @p CRYDriver object + * @param[in] key_id the key to be used for the operation, zero is + * the transient key, other values are keys stored + * in an unspecified way + * @param[in] size size of the plaintext buffer, this number must + * be a multiple of 16 + * @param[in] in buffer containing the input cyphertext + * @param[out] out buffer for the output plaintext + * @param[in] iv 128 bits initial vector + counter, it contains + * a 96 bits IV and a 32 bits counter + * @return The operation status. * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. @@ -524,21 +526,22 @@ cryerror_t cry_lld_decrypt_AES_CTR(CRYDriver *cryp, * of an AES block, this means that padding must be done by the * caller. * - * @param[in] cryp pointer to the @p CRYDriver object - * @param[in] key_id the key to be used for the operation, zero is the - * transient key, other values are keys stored in an - * unspecified way - * @param[in] size size of the text buffers, this number must be a - * multiple of 16 - * @param[in] in buffer containing the input plaintext - * @param[out] out buffer for the output cyphertext - * @param[in] iv 128 bits initial vector + counter, it contains - * a 96 bits IV and a 32 bits counter - * @param[in] aadsize size of the authentication data, this number must be a - * multiple of 16 - * @param[in] aad buffer containing the authentication data - * @param[in] authtag 128 bits buffer for the generated authentication tag - * @return The operation status. + * @param[in] cryp pointer to the @p CRYDriver object + * @param[in] key_id the key to be used for the operation, zero is + * the transient key, other values are keys stored + * in an unspecified way + * @param[in] size size of the text buffers, this number must be a + * multiple of 16 + * @param[in] in buffer containing the input plaintext + * @param[out] out buffer for the output cyphertext + * @param[in] iv 128 bits initial vector + counter, it contains + * a 96 bits IV and a 32 bits counter + * @param[in] aadsize size of the authentication data, this number + * must be a multiple of 16 + * @param[in] aad buffer containing the authentication data + * @param[in] authtag 128 bits buffer for the generated authentication + * tag + * @return The operation status. * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. @@ -577,21 +580,22 @@ cryerror_t cry_lld_encrypt_AES_GCM(CRYDriver *cryp, * of an AES block, this means that padding must be done by the * caller. * - * @param[in] cryp pointer to the @p CRYDriver object - * @param[in] key_id the key to be used for the operation, zero is the - * transient key, other values are keys stored in an - * unspecified way - * @param[in] size size of the text buffers, this number must be a - * multiple of 16 - * @param[in] in buffer for the output cyphertext - * @param[out] out buffer containing the input plaintext - * @param[in] iv 128 bits initial vector + counter, it contains - * a 96 bits IV and a 32 bits counter - * @param[in] aadsize size of the authentication data, this number must be a - * multiple of 16 - * @param[in] aad buffer containing the authentication data - * @param[in] authtag 128 bits buffer for the generated authentication tag - * @return The operation status. + * @param[in] cryp pointer to the @p CRYDriver object + * @param[in] key_id the key to be used for the operation, zero is + * the transient key, other values are keys stored + * in an unspecified way + * @param[in] size size of the text buffers, this number must be a + * multiple of 16 + * @param[in] in buffer for the output cyphertext + * @param[out] out buffer containing the input plaintext + * @param[in] iv 128 bits initial vector + counter, it contains + * a 96 bits IV and a 32 bits counter + * @param[in] aadsize size of the authentication data, this number + * must be a multiple of 16 + * @param[in] aad buffer containing the authentication data + * @param[in] authtag 128 bits buffer for the generated authentication + * tag + * @return The operation status. * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. @@ -629,13 +633,13 @@ cryerror_t cry_lld_decrypt_AES_GCM(CRYDriver *cryp, * @note The implementation of this function must guarantee that it can * be called from any context. * - * @param[in] cryp pointer to the @p CRYDriver object - * @param[in] key_id the key to be used for the operation, zero is the - * transient key, other values are keys stored in an - * unspecified way - * @param[in] in buffer containing the input plaintext - * @param[out] out buffer for the output cyphertext - * @return The operation status. + * @param[in] cryp pointer to the @p CRYDriver object + * @param[in] key_id the key to be used for the operation, zero is + * the transient key, other values are keys stored + * in an unspecified way + * @param[in] in buffer containing the input plaintext + * @param[out] out buffer for the output cyphertext + * @return The operation status. * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. @@ -664,13 +668,13 @@ cryerror_t cry_lld_encrypt_DES(CRYDriver *cryp, * be called from any context. * * - * @param[in] cryp pointer to the @p CRYDriver object - * @param[in] key_id the key to be used for the operation, zero is the - * transient key, other values are keys stored in an - * unspecified way - * @param[in] in buffer containing the input cyphertext - * @param[out] out buffer for the output plaintext - * @return The operation status. + * @param[in] cryp pointer to the @p CRYDriver object + * @param[in] key_id the key to be used for the operation, zero is + * the transient key, other values are keys stored + * in an unspecified way + * @param[in] in buffer containing the input cyphertext + * @param[out] out buffer for the output plaintext + * @return The operation status. * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. @@ -699,15 +703,15 @@ cryerror_t cry_lld_decrypt_DES(CRYDriver *cryp, * of an DES block, this means that padding must be done by the * caller. * - * @param[in] cryp pointer to the @p CRYDriver object - * @param[in] key_id the key to be used for the operation, zero is the - * transient key, other values are keys stored in an - * unspecified way - * @param[in] size size of the plaintext buffer, this number must be a - * multiple of 8 - * @param[in] in buffer containing the input plaintext - * @param[out] out buffer for the output cyphertext - * @return The operation status. + * @param[in] cryp pointer to the @p CRYDriver object + * @param[in] key_id the key to be used for the operation, zero is + * the transient key, other values are keys stored + * in an unspecified way + * @param[in] size size of the plaintext buffer, this number must + * be a multiple of 8 + * @param[in] in buffer containing the input plaintext + * @param[out] out buffer for the output cyphertext + * @return The operation status. * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. @@ -738,15 +742,15 @@ cryerror_t cry_lld_encrypt_DES_ECB(CRYDriver *cryp, * of an DES block, this means that padding must be done by the * caller. * - * @param[in] cryp pointer to the @p CRYDriver object - * @param[in] key_id the key to be used for the operation, zero is the - * transient key, other values are keys stored in an - * unspecified way - * @param[in] size size of the plaintext buffer, this number must be a - * multiple of 8 - * @param[in] in buffer containing the input cyphertext - * @param[out] out buffer for the output plaintext - * @return The operation status. + * @param[in] cryp pointer to the @p CRYDriver object + * @param[in] key_id the key to be used for the operation, zero is + * the transient key, other values are keys stored + * in an unspecified way + * @param[in] size size of the plaintext buffer, this number must + * be a multiple of 8 + * @param[in] in buffer containing the input cyphertext + * @param[out] out buffer for the output plaintext + * @return T he operation status. * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. @@ -777,16 +781,16 @@ cryerror_t cry_lld_decrypt_DES_ECB(CRYDriver *cryp, * of an DES block, this means that padding must be done by the * caller. * - * @param[in] cryp pointer to the @p CRYDriver object - * @param[in] key_id the key to be used for the operation, zero is the - * transient key, other values are keys stored in an - * unspecified way - * @param[in] size size of the plaintext buffer, this number must be a - * multiple of 8 - * @param[in] in buffer containing the input plaintext - * @param[out] out buffer for the output cyphertext - * @param[in] iv 64 bits input vector - * @return The operation status. + * @param[in] cryp pointer to the @p CRYDriver object + * @param[in] key_id the key to be used for the operation, zero is + * the transient key, other values are keys stored + * in an unspecified way + * @param[in] size size of the plaintext buffer, this number must + * be a multiple of 8 + * @param[in] in buffer containing the input plaintext + * @param[out] out buffer for the output cyphertext + * @param[in] iv 64 bits input vector + * @return The operation status. * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. @@ -819,16 +823,16 @@ cryerror_t cry_lld_encrypt_DES_CBC(CRYDriver *cryp, * of an DES block, this means that padding must be done by the * caller. * - * @param[in] cryp pointer to the @p CRYDriver object - * @param[in] key_id the key to be used for the operation, zero is the - * transient key, other values are keys stored in an - * unspecified way - * @param[in] size size of the plaintext buffer, this number must be a - * multiple of 8 - * @param[in] in buffer containing the input cyphertext - * @param[out] out buffer for the output plaintext - * @param[in] iv 64 bits input vector - * @return The operation status. + * @param[in] cryp pointer to the @p CRYDriver object + * @param[in] key_id the key to be used for the operation, zero is + * the transient key, other values are keys stored + * in an unspecified way + * @param[in] size size of the plaintext buffer, this number must + * be a multiple of 8 + * @param[in] in buffer containing the input cyphertext + * @param[out] out buffer for the output plaintext + * @param[in] iv 64 bits input vector + * @return The operation status. * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. @@ -856,76 +860,204 @@ cryerror_t cry_lld_decrypt_DES_CBC(CRYDriver *cryp, } /** - * @brief Hash using SHA1. - * @NOTE Use of this algorithm is not recommended because proven weak. + * @brief Hash initialization using SHA1. + * @note Use of this algorithm is not recommended because proven weak. * - * @param[in] cryp pointer to the @p CRYDriver object - * @param[in] size size of input buffer - * @param[in] in buffer containing the input text - * @param[out] out 160 bits output buffer - * @return The operation status. + * @param[in] cryp pointer to the @p CRYDriver object + * @param[out] sha1ctxp pointer to a SHA1 context to be initialized * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. * - * @api + * @notapi + */ +cryerror_t cry_lld_SHA1_init(CRYDriver *cryp, SHA1Context *sha1ctxp) { + + (void)cryp; + (void)sha1ctxp; + + return CRY_ERR_INV_ALGO; +} + +/** + * @brief Hash update using SHA1. + * @note Use of this algorithm is not recommended because proven weak. + * + * @param[in] cryp pointer to the @p CRYDriver object + * @param[in] sha1ctxp pointer to a SHA1 context + * @param[in] size size of input buffer + * @param[in] in buffer containing the input text + * @return The operation status. + * @retval CRY_NOERROR if the operation succeeded. + * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this + * device instance. + * + * @notapi */ -cryerror_t cry_lld_SHA1(CRYDriver *cryp, size_t size, - const uint8_t *in, uint8_t *out) { +cryerror_t cry_lld_SHA1_update(CRYDriver *cryp, SHA1Context *sha1ctxp, + size_t size, const uint8_t *in) { (void)cryp; + (void)sha1ctxp; (void)size; (void)in; + + return CRY_ERR_INV_ALGO; +} + +/** + * @brief Hash finalization using SHA1. + * @note Use of this algorithm is not recommended because proven weak. + * + * @param[in] cryp pointer to the @p CRYDriver object + * @param[in] sha1ctxp pointer to a SHA1 context + * @param[out] out 160 bits output buffer + * @return The operation status. + * @retval CRY_NOERROR if the operation succeeded. + * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this + * device instance. + * + * @notapi + */ +cryerror_t cry_lld_SHA1_final(CRYDriver *cryp, SHA1Context *sha1ctxp, + uint8_t *out) { + + (void)cryp; + (void)sha1ctxp; (void)out; return CRY_ERR_INV_ALGO; } /** - * @brief Hash using SHA256. + * @brief Hash initialization using SHA256. + * + * @param[in] cryp pointer to the @p CRYDriver object + * @param[out] sha256ctxp pointer to a SHA256 context to be initialized + * @retval CRY_NOERROR if the operation succeeded. + * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this + * device instance. + * + * @notapi + */ +cryerror_t cry_lld_SHA256_init(CRYDriver *cryp, SHA256Context *sha256ctxp) { + + (void)cryp; + (void)sha256ctxp; + + return CRY_ERR_INV_ALGO; +} + +/** + * @brief Hash update using SHA256. * - * @param[in] cryp pointer to the @p CRYDriver object - * @param[in] size size of input buffer - * @param[in] in buffer containing the input text - * @param[out] out 256 bits output buffer - * @return The operation status. + * @param[in] cryp pointer to the @p CRYDriver object + * @param[in] sha256ctxp pointer to a SHA256 context + * @param[in] size size of input buffer + * @param[in] in buffer containing the input text + * @return The operation status. * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. * - * @api + * @notapi */ -cryerror_t cry_lld_SHA256(CRYDriver *cryp, size_t size, - const uint8_t *in, uint8_t *out) { +cryerror_t cry_lld_SHA256_update(CRYDriver *cryp, SHA256Context *sha256ctxp, + size_t size, const uint8_t *in) { (void)cryp; + (void)sha256ctxp; (void)size; (void)in; + + return CRY_ERR_INV_ALGO; +} + +/** + * @brief Hash finalization using SHA256. + * + * @param[in] cryp pointer to the @p CRYDriver object + * @param[in] sha256ctxp pointer to a SHA256 context + * @param[out] out 256 bits output buffer + * @return The operation status. + * @retval CRY_NOERROR if the operation succeeded. + * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this + * device instance. + * + * @notapi + */ +cryerror_t cry_lld_SHA256_final(CRYDriver *cryp, SHA256Context *sha256ctxp, + uint8_t *out) { + + (void)cryp; + (void)sha256ctxp; (void)out; return CRY_ERR_INV_ALGO; } /** - * @brief Hash using SHA512. + * @brief Hash initialization using SHA512. + * + * @param[in] cryp pointer to the @p CRYDriver object + * @param[out] sha512ctxp pointer to a SHA512 context to be initialized + * @retval CRY_NOERROR if the operation succeeded. + * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this + * device instance. + * + * @notapi + */ +cryerror_t cry_lld_SHA512_init(CRYDriver *cryp, SHA512Context *sha512ctxp) { + + (void)cryp; + (void)sha512ctxp; + + return CRY_ERR_INV_ALGO; +} + +/** + * @brief Hash update using SHA512. * - * @param[in] cryp pointer to the @p CRYDriver object - * @param[in] size size of input buffer - * @param[in] in buffer containing the input text - * @param[out] out 512 bits output buffer - * @return The operation status. + * @param[in] cryp pointer to the @p CRYDriver object + * @param[in] sha512ctxp pointer to a SHA512 context + * @param[in] size size of input buffer + * @param[in] in buffer containing the input text + * @return The operation status. * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. * - * @api + * @notapi */ -cryerror_t cry_lld_SHA512(CRYDriver *cryp, size_t size, - const uint8_t *in, uint8_t *out) { +cryerror_t cry_lld_SHA512_update(CRYDriver *cryp, SHA512Context *sha512ctxp, + size_t size, const uint8_t *in) { (void)cryp; + (void)sha512ctxp; (void)size; (void)in; + + return CRY_ERR_INV_ALGO; +} + +/** + * @brief Hash finalization using SHA512. + * + * @param[in] cryp pointer to the @p CRYDriver object + * @param[in] sha512ctxp pointer to a SHA512 context + * @param[out] out 512 bits output buffer + * @return The operation status. + * @retval CRY_NOERROR if the operation succeeded. + * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this + * device instance. + * + * @notapi + */ +cryerror_t cry_lld_SHA512_final(CRYDriver *cryp, SHA512Context *sha512ctxp, + uint8_t *out) { + + (void)cryp; + (void)sha512ctxp; (void)out; return CRY_ERR_INV_ALGO; @@ -934,14 +1066,14 @@ cryerror_t cry_lld_SHA512(CRYDriver *cryp, size_t size, /** * @brief True random numbers generator. * - * @param[in] cryp pointer to the @p CRYDriver object - * @param[out] out 128 bits output buffer - * @return The operation status. + * @param[in] cryp pointer to the @p CRYDriver object + * @param[out] out 128 bits output buffer + * @return The operation status. * @retval CRY_NOERROR if the operation succeeded. * @retval CRY_ERR_INV_ALGO if the operation is unsupported on this * device instance. * - * @api + * @notapi */ cryerror_t cry_lld_TRNG(CRYDriver *cryp, uint8_t *out) { 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 7a5980451..e2ba05f01 100644 --- a/os/hal/ports/STM32/LLD/CRYPv1/hal_crypto_lld.h +++ b/os/hal/ports/STM32/LLD/CRYPv1/hal_crypto_lld.h @@ -126,6 +126,33 @@ struct CRYDriver { /* End of the mandatory fields.*/ }; +#if (CRY_LLD_SUPPORTS_SHA1 == TRUE) || defined(__DOXYGEN__) +/** + * @brief Type of a SHA1 context. + */ +typedef struct { + uint32_t dummy; +} SHA1Context; +#endif + +#if (CRY_LLD_SUPPORTS_SHA256 == TRUE) || defined(__DOXYGEN__) +/** + * @brief Type of a SHA256 context. + */ +typedef struct { + uint32_t dummy; +} SHA256Context; +#endif + +#if (CRY_LLD_SUPPORTS_SHA512 == TRUE) || defined(__DOXYGEN__) +/** + * @brief Type of a SHA512 context. + */ +typedef struct { + uint32_t dummy; +} SHA512Context; +#endif + /*===========================================================================*/ /* Driver macros. */ /*===========================================================================*/ @@ -250,12 +277,21 @@ extern "C" { const uint8_t *in, uint8_t *out, const uint8_t *iv); - cryerror_t cry_lld_SHA1(CRYDriver *cryp, size_t size, - const uint8_t *in, uint8_t *out); - cryerror_t cry_lld_SHA256(CRYDriver *cryp, size_t size, - const uint8_t *in, uint8_t *out); - cryerror_t cry_lld_SHA512(CRYDriver *cryp, size_t size, - const uint8_t *in, uint8_t *out); + 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); + 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); + 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); cryerror_t cry_lld_TRNG(CRYDriver *cryp, uint8_t *out); #ifdef __cplusplus } -- cgit v1.2.3