Commit 15658b9c authored by johan's avatar johan

Add SHA512 wrapper

- based on mbedtls only
- todo: add it for polarssl too
parent 60568157
......@@ -770,9 +770,22 @@ BCTBX_PUBLIC void bctbx_EDDSA_ECDH_publicKeyConversion(const bctbx_EDDSAContext_
/*****************************************************************************/
/***** Hashing *****/
/*****************************************************************************/
/*
* @brief SHA512 wrapper
* @param[in] input Input data buffer
* @param[in] inputLength Input data length in bytes
* @param[in] hashLength Length of output required in bytes, Output is truncated to the hashLength left bytes. 64 bytes maximum
* @param[out] output Output data buffer.
*
*/
BCTBX_PUBLIC void bctbx_sha512(const uint8_t *input,
size_t inputLength,
uint8_t hashLength,
uint8_t *output);
/**
* @brief HMAC-SHA256 wrapper
* @param[in] key HMAC secret key
* @param[in] key HMAC secret key
* @param[in] keyLength HMAC key length in bytes
* @param[in] input Input data buffer
* @param[in] inputLength Input data length in bytes
......
......@@ -1339,11 +1339,35 @@ void bctbx_hmacSha256(const uint8_t *key,
}
}
/*
* @brief SHA512 wrapper
* @param[in] input Input data buffer
* @param[in] inputLength Input data length in bytes
* @param[in] hashLength Length of output required in bytes, Output is truncated to the hashLength left bytes. 64 bytes maximum
* @param[out] output Output data buffer.
*
*/
void bctbx_sha512(const uint8_t *input,
size_t inputLength,
uint8_t hashLength,
uint8_t *output)
{
uint8_t hashOutput[64];
mbedtls_sha512(input, inputLength, hashOutput, 0); /* last param to zero to select SHA512 and not SHA384 */
/* check output length, can't be>64 */
if (hashLength>64) {
memcpy(output, hashOutput, 64);
} else {
memcpy(output, hashOutput, hashLength);
}
}
/*
* @brief SHA256 wrapper
* @param[in] input Input data buffer
* @param[in] inputLength Input data length in bytes
* @param[in] hmacLength Length of output required in bytes, HMAC output is truncated to the hmacLength left bytes. 32 bytes maximum
* @param[in] hashLength Length of output required in bytes, Output is truncated to the hashLength left bytes. 32 bytes maximum
* @param[out] output Output data buffer.
*
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment