Merge pull request #5973 from k-stachowiak/IOTSSL-1727-update-to-new-md-api

Update Mbed TLS HW acceleration partner code to new hashing API
pull/6099/head
Cruz Monrreal 2018-02-14 12:58:08 -06:00 committed by GitHub
commit 06b618447f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 725 additions and 133 deletions

View File

@ -23,6 +23,67 @@
#include "mbedtls/sha256.h"
/**
* \name SECTION: Compatibility code
*
* Depending on whether the alternative (hatdware accelerated) hashing
* functions are provided or not, different API should be used for hashing.
* \{
*/
#if defined(MBEDTLS_SHA256_ALT)
/**
* \brief This function starts a SHA-256 checksum calculation.
*
* \deprecated Superseded by mbedtls_sha256_starts_ret() in 2.7.0.
*
* \param ctx The SHA-256 context to initialize.
* \param is224 Determines which function to use.
* <ul><li>0: Use SHA-256.</li>
* <li>1: Use SHA-224.</li></ul>
*/
void mbedtls_sha256_starts( mbedtls_sha256_context *ctx,
int is224 )
{
mbedtls_sha256_starts_ret( ctx, is224 );
}
/**
* \brief This function feeds an input buffer into an ongoing
* SHA-256 checksum calculation.
*
* \deprecated Superseded by mbedtls_sha256_update_ret() in 2.7.0.
*
* \param ctx The SHA-256 context to initialize.
* \param input The buffer holding the data.
* \param ilen The length of the input data.
*/
void mbedtls_sha256_update( mbedtls_sha256_context *ctx,
const unsigned char *input,
size_t ilen )
{
mbedtls_sha256_update_ret( ctx, input, ilen );
}
/**
* \brief This function finishes the SHA-256 operation, and writes
* the result to the output buffer.
*
* \deprecated Superseded by mbedtls_sha256_finish_ret() in 2.7.0.
*
* \param ctx The SHA-256 context.
* \param output The SHA-224or SHA-256 checksum result.
*/
void mbedtls_sha256_finish( mbedtls_sha256_context *ctx,
unsigned char output[32] )
{
mbedtls_sha256_finish_ret( ctx, output );
}
#endif /* defined(MBEDTLS_SHA256_ALT) */
/* \} name SECTION: Compatibility code */
using namespace utest::v1;

View File

@ -103,37 +103,40 @@ void mbedtls_sha1_clone(mbedtls_sha1_context *dst,
/*
* SHA-1 context setup
*/
void mbedtls_sha1_starts(mbedtls_sha1_context *ctx)
int mbedtls_sha1_starts_ret(mbedtls_sha1_context *ctx)
{
if (ctx->active_ctx == &ctx->hw_ctx) {
mbedtls_sha1_hw_starts(&ctx->hw_ctx);
} else if (ctx->active_ctx == &ctx->sw_ctx) {
mbedtls_sha1_sw_starts(&ctx->sw_ctx);
}
return 0;
}
/*
* SHA-1 process buffer
*/
void mbedtls_sha1_update(mbedtls_sha1_context *ctx, const unsigned char *input, size_t ilen)
int mbedtls_sha1_update_ret(mbedtls_sha1_context *ctx, const unsigned char *input, size_t ilen)
{
if (ctx->active_ctx == &ctx->hw_ctx) {
mbedtls_sha1_hw_update(&ctx->hw_ctx, input, ilen);
} else if (ctx->active_ctx == &ctx->sw_ctx) {
mbedtls_sha1_sw_update(&ctx->sw_ctx, input, ilen);
}
return 0;
}
/*
* SHA-1 final digest
*/
void mbedtls_sha1_finish(mbedtls_sha1_context *ctx, unsigned char output[20])
int mbedtls_sha1_finish_ret(mbedtls_sha1_context *ctx, unsigned char output[20])
{
if (ctx->active_ctx == &ctx->hw_ctx) {
mbedtls_sha1_hw_finish(&ctx->hw_ctx, output);
} else if (ctx->active_ctx == &ctx->sw_ctx) {
mbedtls_sha1_sw_finish(&ctx->sw_ctx, output);
}
return 0;
}
void mbedtls_sha1_process(mbedtls_sha1_context *ctx, const unsigned char data[64])

View File

@ -66,8 +66,10 @@ void mbedtls_sha1_clone( mbedtls_sha1_context *dst,
* \brief SHA-1 context setup
*
* \param ctx context to be initialized
*
* \return 0 if successful
*/
void mbedtls_sha1_starts( mbedtls_sha1_context *ctx );
int mbedtls_sha1_starts_ret( mbedtls_sha1_context *ctx );
/**
* \brief SHA-1 process buffer
@ -75,16 +77,20 @@ void mbedtls_sha1_starts( mbedtls_sha1_context *ctx );
* \param ctx SHA-1 context
* \param input buffer holding the data
* \param ilen length of the input data
*
* \return 0 if successful
*/
void mbedtls_sha1_update( mbedtls_sha1_context *ctx, const unsigned char *input, size_t ilen );
int mbedtls_sha1_update_ret( mbedtls_sha1_context *ctx, const unsigned char *input, size_t ilen );
/**
* \brief SHA-1 final digest
*
* \param ctx SHA-1 context
* \param output SHA-1 checksum result
*
* \return 0 if successful
*/
void mbedtls_sha1_finish( mbedtls_sha1_context *ctx, unsigned char output[20] );
int mbedtls_sha1_finish_ret( mbedtls_sha1_context *ctx, unsigned char output[20] );
/* Internal use */
void mbedtls_sha1_process( mbedtls_sha1_context *ctx, const unsigned char data[64] );

View File

@ -104,37 +104,40 @@ void mbedtls_sha256_clone(mbedtls_sha256_context *dst,
/*
* SHA-256 context setup
*/
void mbedtls_sha256_starts(mbedtls_sha256_context *ctx, int is224)
int mbedtls_sha256_starts_ret(mbedtls_sha256_context *ctx, int is224)
{
if (ctx->active_ctx == &ctx->hw_ctx) {
mbedtls_sha256_hw_starts(&ctx->hw_ctx, is224);
} else if (ctx->active_ctx == &ctx->sw_ctx) {
mbedtls_sha256_sw_starts(&ctx->sw_ctx, is224);
}
return 0;
}
/*
* SHA-256 process buffer
*/
void mbedtls_sha256_update(mbedtls_sha256_context *ctx, const unsigned char *input, size_t ilen)
int mbedtls_sha256_update_ret(mbedtls_sha256_context *ctx, const unsigned char *input, size_t ilen)
{
if (ctx->active_ctx == &ctx->hw_ctx) {
mbedtls_sha256_hw_update(&ctx->hw_ctx, input, ilen);
} else if (ctx->active_ctx == &ctx->sw_ctx) {
mbedtls_sha256_sw_update(&ctx->sw_ctx, input, ilen);
}
return 0;
}
/*
* SHA-256 final digest
*/
void mbedtls_sha256_finish(mbedtls_sha256_context *ctx, unsigned char output[32])
int mbedtls_sha256_finish_ret(mbedtls_sha256_context *ctx, unsigned char output[32])
{
if (ctx->active_ctx == &ctx->hw_ctx) {
mbedtls_sha256_hw_finish(&ctx->hw_ctx, output);
} else if (ctx->active_ctx == &ctx->sw_ctx) {
mbedtls_sha256_sw_finish(&ctx->sw_ctx, output);
}
return 0;
}
void mbedtls_sha256_process(mbedtls_sha256_context *ctx, const unsigned char data[64])

View File

@ -67,8 +67,10 @@ void mbedtls_sha256_clone( mbedtls_sha256_context *dst,
*
* \param ctx context to be initialized
* \param is224 0 = use SHA256, 1 = use SHA224
*
* \return 0 if successful
*/
void mbedtls_sha256_starts( mbedtls_sha256_context *ctx, int is224 );
int mbedtls_sha256_starts_ret( mbedtls_sha256_context *ctx, int is224 );
/**
* \brief SHA-256 process buffer
@ -76,17 +78,21 @@ void mbedtls_sha256_starts( mbedtls_sha256_context *ctx, int is224 );
* \param ctx SHA-256 context
* \param input buffer holding the data
* \param ilen length of the input data
*
* \return 0 if successful
*/
void mbedtls_sha256_update( mbedtls_sha256_context *ctx, const unsigned char *input,
size_t ilen );
int mbedtls_sha256_update_ret( mbedtls_sha256_context *ctx, const unsigned char *input,
size_t ilen );
/**
* \brief SHA-256 final digest
*
* \param ctx SHA-256 context
* \param output SHA-224/256 checksum result
*
* \return 0 if successful
*/
void mbedtls_sha256_finish( mbedtls_sha256_context *ctx, unsigned char output[32] );
int mbedtls_sha256_finish_ret( mbedtls_sha256_context *ctx, unsigned char output[32] );
/* Internal use */
void mbedtls_sha256_process( mbedtls_sha256_context *ctx, const unsigned char data[64] );

View File

@ -105,37 +105,40 @@ void mbedtls_sha512_clone(mbedtls_sha512_context *dst,
/*
* SHA-512 context setup
*/
void mbedtls_sha512_starts(mbedtls_sha512_context *ctx, int is384)
int mbedtls_sha512_starts_ret(mbedtls_sha512_context *ctx, int is384)
{
if (ctx->active_ctx == &ctx->hw_ctx) {
mbedtls_sha512_hw_starts(&ctx->hw_ctx, is384);
} else if (ctx->active_ctx == &ctx->sw_ctx) {
mbedtls_sha512_sw_starts(&ctx->sw_ctx, is384);
}
return 0;
}
/*
* SHA-512 process buffer
*/
void mbedtls_sha512_update(mbedtls_sha512_context *ctx, const unsigned char *input, size_t ilen)
int mbedtls_sha512_update_ret(mbedtls_sha512_context *ctx, const unsigned char *input, size_t ilen)
{
if (ctx->active_ctx == &ctx->hw_ctx) {
mbedtls_sha512_hw_update(&ctx->hw_ctx, input, ilen);
} else if (ctx->active_ctx == &ctx->sw_ctx) {
mbedtls_sha512_sw_update(&ctx->sw_ctx, input, ilen);
}
return 0;
}
/*
* SHA-512 final digest
*/
void mbedtls_sha512_finish(mbedtls_sha512_context *ctx, unsigned char output[64])
int mbedtls_sha512_finish_ret(mbedtls_sha512_context *ctx, unsigned char output[64])
{
if (ctx->active_ctx == &ctx->hw_ctx) {
mbedtls_sha512_hw_finish(&ctx->hw_ctx, output);
} else if (ctx->active_ctx == &ctx->sw_ctx) {
mbedtls_sha512_sw_finish(&ctx->sw_ctx, output);
}
return 0;
}
void mbedtls_sha512_process(mbedtls_sha512_context *ctx, const unsigned char data[128])

View File

@ -67,8 +67,10 @@ void mbedtls_sha512_clone( mbedtls_sha512_context *dst,
*
* \param ctx context to be initialized
* \param is384 0 = use SHA512, 1 = use SHA384
*
* \return 0 if successful
*/
void mbedtls_sha512_starts( mbedtls_sha512_context *ctx, int is384 );
int mbedtls_sha512_starts_ret( mbedtls_sha512_context *ctx, int is384 );
/**
* \brief SHA-512 process buffer
@ -76,17 +78,21 @@ void mbedtls_sha512_starts( mbedtls_sha512_context *ctx, int is384 );
* \param ctx SHA-512 context
* \param input buffer holding the data
* \param ilen length of the input data
*
* \return 0 if successful
*/
void mbedtls_sha512_update( mbedtls_sha512_context *ctx, const unsigned char *input,
size_t ilen );
int mbedtls_sha512_update_ret( mbedtls_sha512_context *ctx, const unsigned char *input,
size_t ilen );
/**
* \brief SHA-512 final digest
*
* \param ctx SHA-512 context
* \param output SHA-384/512 checksum result
*
* \return 0 if successful
*/
void mbedtls_sha512_finish( mbedtls_sha512_context *ctx, unsigned char output[64] );
int mbedtls_sha512_finish_ret( mbedtls_sha512_context *ctx, unsigned char output[64] );
/* Internal use */
void mbedtls_sha512_process( mbedtls_sha512_context *ctx, const unsigned char data[128] );

View File

@ -103,37 +103,40 @@ void mbedtls_sha1_clone(mbedtls_sha1_context *dst,
/*
* SHA-1 context setup
*/
void mbedtls_sha1_starts(mbedtls_sha1_context *ctx)
int mbedtls_sha1_starts_ret(mbedtls_sha1_context *ctx)
{
if (ctx->active_ctx == &ctx->hw_ctx) {
mbedtls_sha1_hw_starts(&ctx->hw_ctx);
} else if (ctx->active_ctx == &ctx->sw_ctx) {
mbedtls_sha1_sw_starts(&ctx->sw_ctx);
}
return 0;
}
/*
* SHA-1 process buffer
*/
void mbedtls_sha1_update(mbedtls_sha1_context *ctx, const unsigned char *input, size_t ilen)
int mbedtls_sha1_update_ret(mbedtls_sha1_context *ctx, const unsigned char *input, size_t ilen)
{
if (ctx->active_ctx == &ctx->hw_ctx) {
mbedtls_sha1_hw_update(&ctx->hw_ctx, input, ilen);
} else if (ctx->active_ctx == &ctx->sw_ctx) {
mbedtls_sha1_sw_update(&ctx->sw_ctx, input, ilen);
}
return 0;
}
/*
* SHA-1 final digest
*/
void mbedtls_sha1_finish(mbedtls_sha1_context *ctx, unsigned char output[20])
int mbedtls_sha1_finish_ret(mbedtls_sha1_context *ctx, unsigned char output[20])
{
if (ctx->active_ctx == &ctx->hw_ctx) {
mbedtls_sha1_hw_finish(&ctx->hw_ctx, output);
} else if (ctx->active_ctx == &ctx->sw_ctx) {
mbedtls_sha1_sw_finish(&ctx->sw_ctx, output);
}
return 0;
}
void mbedtls_sha1_process(mbedtls_sha1_context *ctx, const unsigned char data[64])

View File

@ -66,8 +66,10 @@ void mbedtls_sha1_clone( mbedtls_sha1_context *dst,
* \brief SHA-1 context setup
*
* \param ctx context to be initialized
*
* \return 0 if successful
*/
void mbedtls_sha1_starts( mbedtls_sha1_context *ctx );
int mbedtls_sha1_starts_ret( mbedtls_sha1_context *ctx );
/**
* \brief SHA-1 process buffer
@ -75,16 +77,20 @@ void mbedtls_sha1_starts( mbedtls_sha1_context *ctx );
* \param ctx SHA-1 context
* \param input buffer holding the data
* \param ilen length of the input data
*
* \return 0 if successful
*/
void mbedtls_sha1_update( mbedtls_sha1_context *ctx, const unsigned char *input, size_t ilen );
int mbedtls_sha1_update_ret( mbedtls_sha1_context *ctx, const unsigned char *input, size_t ilen );
/**
* \brief SHA-1 final digest
*
* \param ctx SHA-1 context
* \param output SHA-1 checksum result
*
* \return 0 if successful
*/
void mbedtls_sha1_finish( mbedtls_sha1_context *ctx, unsigned char output[20] );
int mbedtls_sha1_finish_ret( mbedtls_sha1_context *ctx, unsigned char output[20] );
/* Internal use */
void mbedtls_sha1_process( mbedtls_sha1_context *ctx, const unsigned char data[64] );

View File

@ -104,37 +104,40 @@ void mbedtls_sha256_clone(mbedtls_sha256_context *dst,
/*
* SHA-256 context setup
*/
void mbedtls_sha256_starts(mbedtls_sha256_context *ctx, int is224)
int mbedtls_sha256_starts_ret(mbedtls_sha256_context *ctx, int is224)
{
if (ctx->active_ctx == &ctx->hw_ctx) {
mbedtls_sha256_hw_starts(&ctx->hw_ctx, is224);
} else if (ctx->active_ctx == &ctx->sw_ctx) {
mbedtls_sha256_sw_starts(&ctx->sw_ctx, is224);
}
return 0;
}
/*
* SHA-256 process buffer
*/
void mbedtls_sha256_update(mbedtls_sha256_context *ctx, const unsigned char *input, size_t ilen)
int mbedtls_sha256_update_ret(mbedtls_sha256_context *ctx, const unsigned char *input, size_t ilen)
{
if (ctx->active_ctx == &ctx->hw_ctx) {
mbedtls_sha256_hw_update(&ctx->hw_ctx, input, ilen);
} else if (ctx->active_ctx == &ctx->sw_ctx) {
mbedtls_sha256_sw_update(&ctx->sw_ctx, input, ilen);
}
return 0;
}
/*
* SHA-256 final digest
*/
void mbedtls_sha256_finish(mbedtls_sha256_context *ctx, unsigned char output[32])
int mbedtls_sha256_finish_ret(mbedtls_sha256_context *ctx, unsigned char output[32])
{
if (ctx->active_ctx == &ctx->hw_ctx) {
mbedtls_sha256_hw_finish(&ctx->hw_ctx, output);
} else if (ctx->active_ctx == &ctx->sw_ctx) {
mbedtls_sha256_sw_finish(&ctx->sw_ctx, output);
}
return 0;
}
void mbedtls_sha256_process(mbedtls_sha256_context *ctx, const unsigned char data[64])

View File

@ -67,8 +67,10 @@ void mbedtls_sha256_clone( mbedtls_sha256_context *dst,
*
* \param ctx context to be initialized
* \param is224 0 = use SHA256, 1 = use SHA224
*
* \return 0 if successful
*/
void mbedtls_sha256_starts( mbedtls_sha256_context *ctx, int is224 );
int mbedtls_sha256_starts_ret( mbedtls_sha256_context *ctx, int is224 );
/**
* \brief SHA-256 process buffer
@ -76,17 +78,21 @@ void mbedtls_sha256_starts( mbedtls_sha256_context *ctx, int is224 );
* \param ctx SHA-256 context
* \param input buffer holding the data
* \param ilen length of the input data
*
* \return 0 if successful
*/
void mbedtls_sha256_update( mbedtls_sha256_context *ctx, const unsigned char *input,
size_t ilen );
int mbedtls_sha256_update_ret( mbedtls_sha256_context *ctx, const unsigned char *input,
size_t ilen );
/**
* \brief SHA-256 final digest
*
* \param ctx SHA-256 context
* \param output SHA-224/256 checksum result
*
* \return 0 if successful
*/
void mbedtls_sha256_finish( mbedtls_sha256_context *ctx, unsigned char output[32] );
int mbedtls_sha256_finish_ret( mbedtls_sha256_context *ctx, unsigned char output[32] );
/* Internal use */
void mbedtls_sha256_process( mbedtls_sha256_context *ctx, const unsigned char data[64] );

View File

@ -90,12 +90,11 @@ void mbedtls_md5_clone( mbedtls_md5_context *dst,
*dst = *src;
}
void mbedtls_md5_starts( mbedtls_md5_context *ctx )
int mbedtls_md5_starts_ret( mbedtls_md5_context *ctx )
{
/* HASH IP initialization */
if (HAL_HASH_DeInit(&ctx->hhash_md5) != 0) {
// error found to be returned
return;
return MBEDTLS_ERR_MD5_HW_ACCEL_FAILED;
}
/* HASH Configuration */
@ -103,34 +102,37 @@ void mbedtls_md5_starts( mbedtls_md5_context *ctx )
/* clear CR ALGO value */
HASH->CR &= ~HASH_CR_ALGO_Msk;
if (HAL_HASH_Init(&ctx->hhash_md5) != 0) {
// return error code
return;
return MBEDTLS_ERR_MD5_HW_ACCEL_FAILED;
}
if (st_md5_save_hw_context(ctx) != 1) {
return; // return HASH_BUSY timeout Error here
return MBEDTLS_ERR_MD5_HW_ACCEL_FAILED; // Hash busy timeout
}
return 0;
}
void mbedtls_md5_process( mbedtls_md5_context *ctx, const unsigned char data[ST_MD5_BLOCK_SIZE] )
int mbedtls_md5_process( mbedtls_md5_context *ctx, const unsigned char data[ST_MD5_BLOCK_SIZE] )
{
if (st_md5_restore_hw_context(ctx) != 1) {
return; // Return HASH_BUSY timout error here
return MBEDTLS_ERR_MD5_HW_ACCEL_FAILED; // Hash busy timeout
}
if (HAL_HASH_MD5_Accumulate(&ctx->hhash_md5, (uint8_t *)data, ST_MD5_BLOCK_SIZE) != 0) {
return; // Return error code here
return MBEDTLS_ERR_MD5_HW_ACCEL_FAILED;
}
if (st_md5_save_hw_context(ctx) != 1) {
return; // return HASH_BUSY timeout Error here
return MBEDTLS_ERR_MD5_HW_ACCEL_FAILED; // Hash busy timeout
}
return 0;
}
void mbedtls_md5_update( mbedtls_md5_context *ctx, const unsigned char *input, size_t ilen )
int mbedtls_md5_update_ret( mbedtls_md5_context *ctx, const unsigned char *input, size_t ilen )
{
size_t currentlen = ilen;
/* If ilen = 0 : do nothing */
if (currentlen != 0) {
if (st_md5_restore_hw_context(ctx) != 1) {
return; // Return HASH_BUSY timout error here
return MBEDTLS_ERR_MD5_HW_ACCEL_FAILED; // Hash busy timeout
}
// store mechanism to accumulate ST_MD5_BLOCK_SIZE bytes (512 bits) in the HW
@ -147,7 +149,7 @@ void mbedtls_md5_update( mbedtls_md5_context *ctx, const unsigned char *input, s
size_t iter = currentlen / ST_MD5_BLOCK_SIZE;
if (iter !=0) {
if (HAL_HASH_MD5_Accumulate(&ctx->hhash_md5, (uint8_t *)(input + ST_MD5_BLOCK_SIZE - ctx->sbuf_len), (iter * ST_MD5_BLOCK_SIZE)) != 0) {
return; // Return error code here
return MBEDTLS_ERR_MD5_HW_ACCEL_FAILED;
}
}
// sbuf is completely accumulated, now copy up to 63 remaining bytes
@ -158,20 +160,20 @@ void mbedtls_md5_update( mbedtls_md5_context *ctx, const unsigned char *input, s
}
if (st_md5_save_hw_context(ctx) != 1) {
return; // return HASH_BUSY timeout Error here
return MBEDTLS_ERR_MD5_HW_ACCEL_FAILED; // Hash busy timeout
}
}
}
void mbedtls_md5_finish( mbedtls_md5_context *ctx, unsigned char output[16] )
int mbedtls_md5_finish_ret( mbedtls_md5_context *ctx, unsigned char output[16] )
{
if (st_md5_restore_hw_context(ctx) != 1) {
return; // Return HASH_BUSY timout error here
return MBEDTLS_ERR_MD5_HW_ACCEL_FAILED; // Hash busy timeout
}
/* Last accumulation for extra bytes in sbuf_len */
/* This sets HW flags in case mbedtls_md5_update has not been called yet */
if (HAL_HASH_MD5_Accumulate(&ctx->hhash_md5, ctx->sbuf, ctx->sbuf_len) != 0) {
return; // Return error code here
return MBEDTLS_ERR_MD5_HW_ACCEL_FAILED; // Accumulation error
}
mbedtls_zeroize( ctx->sbuf, ST_MD5_BLOCK_SIZE);
@ -179,11 +181,13 @@ void mbedtls_md5_finish( mbedtls_md5_context *ctx, unsigned char output[16] )
__HAL_HASH_START_DIGEST();
if (HAL_HASH_MD5_Finish(&ctx->hhash_md5, output, 10)) {
// error code to be returned
return MBEDTLS_ERR_MD5_HW_ACCEL_FAILED; // Finish error
}
if (st_md5_save_hw_context(ctx) != 1) {
return; // return HASH_BUSY timeout Error here
return MBEDTLS_ERR_MD5_HW_ACCEL_FAILED; // Hash busy timeout
}
return 0;
}
#endif /* MBEDTLS_MD5_ALT */

View File

@ -27,6 +27,19 @@
#include "cmsis.h"
#include <string.h>
/**
* \name SECTION: Temporary compatibility code
*
* This section contains code to be added up stream in Mbed TLS. Once that
* has been provided, this section should be removed as the code will be
* provided elsewhere.
* \{
*/
#define MBEDTLS_ERR_MD5_HW_ACCEL_FAILED -0x002F /**< MD5 hardware accelerator failed */
/* \} name SECTION: Temporary compatibility code */
#ifdef __cplusplus
extern "C" {
#endif
@ -79,8 +92,10 @@ void mbedtls_md5_clone( mbedtls_md5_context *dst,
* \brief MD5 context setup
*
* \param ctx context to be initialized
*
* \return 0 if successful
*/
void mbedtls_md5_starts( mbedtls_md5_context *ctx );
int mbedtls_md5_starts_ret( mbedtls_md5_context *ctx );
/**
* \brief MD5 process buffer
@ -88,19 +103,23 @@ void mbedtls_md5_starts( mbedtls_md5_context *ctx );
* \param ctx MD5 context
* \param input buffer holding the data
* \param ilen length of the input data
*
* \return 0 if successful
*/
void mbedtls_md5_update( mbedtls_md5_context *ctx, const unsigned char *input, size_t ilen );
int mbedtls_md5_update_ret( mbedtls_md5_context *ctx, const unsigned char *input, size_t ilen );
/**
* \brief MD5 final digest
*
* \param ctx MD5 context
* \param output MD5 checksum result
*
* \return 0 if successful
*/
void mbedtls_md5_finish( mbedtls_md5_context *ctx, unsigned char output[16] );
int mbedtls_md5_finish_ret( mbedtls_md5_context *ctx, unsigned char output[16] );
/* Internal use */
void mbedtls_md5_process( mbedtls_md5_context *ctx, const unsigned char data[ST_MD5_BLOCK_SIZE] );
int mbedtls_md5_process( mbedtls_md5_context *ctx, const unsigned char data[ST_MD5_BLOCK_SIZE] );
#ifdef __cplusplus
}

View File

@ -88,12 +88,11 @@ void mbedtls_sha1_clone( mbedtls_sha1_context *dst,
*dst = *src;
}
void mbedtls_sha1_starts( mbedtls_sha1_context *ctx )
int mbedtls_sha1_starts_ret( mbedtls_sha1_context *ctx )
{
/* Deinitializes the HASH peripheral */
if (HAL_HASH_DeInit(&ctx->hhash_sha1) == HAL_ERROR) {
// error found to be returned
return;
return MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED;
}
/* HASH Configuration */
@ -101,33 +100,36 @@ void mbedtls_sha1_starts( mbedtls_sha1_context *ctx )
/* clear CR ALGO value */
HASH->CR &= ~HASH_CR_ALGO_Msk;
if (HAL_HASH_Init(&ctx->hhash_sha1) == HAL_ERROR) {
// error found to be returned
return;
return MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED;
}
if (st_sha1_save_hw_context(ctx) != 1) {
return; // return HASH_BUSY timeout Error here
return MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED; // Hash busy timeout
}
return 0;
}
void mbedtls_sha1_process( mbedtls_sha1_context *ctx, const unsigned char data[ST_SHA1_BLOCK_SIZE] )
int mbedtls_sha1_process( mbedtls_sha1_context *ctx, const unsigned char data[ST_SHA1_BLOCK_SIZE] )
{
if (st_sha1_restore_hw_context(ctx) != 1) {
return; // Return HASH_BUSY timout error here
return MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED; // Hash busy timeout
}
if (HAL_HASH_SHA1_Accumulate(&ctx->hhash_sha1, (uint8_t *) data, ST_SHA1_BLOCK_SIZE) != 0) {
return; // Return error code
return MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED;
}
if (st_sha1_save_hw_context(ctx) != 1) {
return; // return HASH_BUSY timeout Error here
return MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED; // Hash busy timeout
}
return 0;
}
void mbedtls_sha1_update( mbedtls_sha1_context *ctx, const unsigned char *input, size_t ilen )
int mbedtls_sha1_update_ret( mbedtls_sha1_context *ctx, const unsigned char *input, size_t ilen )
{
size_t currentlen = ilen;
if (st_sha1_restore_hw_context(ctx) != 1) {
return; // Return HASH_BUSY timout error here
return MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED; // Hash busy timeout
}
// store mechanism to accumulate ST_SHA1_BLOCK_SIZE bytes (512 bits) in the HW
@ -146,11 +148,14 @@ void mbedtls_sha1_update( mbedtls_sha1_context *ctx, const unsigned char *input,
// fill buffer and process it
memcpy(ctx->sbuf + ctx->sbuf_len, input, (ST_SHA1_BLOCK_SIZE - ctx->sbuf_len));
currentlen -= (ST_SHA1_BLOCK_SIZE - ctx->sbuf_len);
mbedtls_sha1_process(ctx, ctx->sbuf);
if( mbedtls_sha1_process(ctx, ctx->sbuf) != 0 ) {
return MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED;
}
// Process every input as long as it is %64 bytes, ie 512 bits
size_t iter = currentlen / ST_SHA1_BLOCK_SIZE;
if (HAL_HASH_SHA1_Accumulate(&ctx->hhash_sha1, (uint8_t *)(input + ST_SHA1_BLOCK_SIZE - ctx->sbuf_len), (iter * ST_SHA1_BLOCK_SIZE)) != 0) {
return; // Return error code here
return MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED;
}
// sbuf is completely accumulated, now copy up to 63 remaining bytes
ctx->sbuf_len = currentlen % ST_SHA1_BLOCK_SIZE;
@ -159,31 +164,35 @@ void mbedtls_sha1_update( mbedtls_sha1_context *ctx, const unsigned char *input,
}
}
if (st_sha1_save_hw_context(ctx) != 1) {
return; // return HASH_BUSY timeout Error here
return MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED; // Hash busy timeout
}
return 0;
}
void mbedtls_sha1_finish( mbedtls_sha1_context *ctx, unsigned char output[20] )
int mbedtls_sha1_finish_ret( mbedtls_sha1_context *ctx, unsigned char output[20] )
{
if (st_sha1_restore_hw_context(ctx) != 1) {
return; // Return HASH_BUSY timout error here
return MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED; // Hash busy timeout
}
/* Last accumulation for extra bytes in sbuf_len */
/* This allows the HW flags to be in place in case mbedtls_sha256_update has not been called yet */
if (HAL_HASH_SHA1_Accumulate(&ctx->hhash_sha1, ctx->sbuf, ctx->sbuf_len) != 0) {
return; // Return error code here
return MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED;
}
mbedtls_zeroize(ctx->sbuf, ST_SHA1_BLOCK_SIZE);
ctx->sbuf_len = 0;
__HAL_HASH_START_DIGEST();
if (HAL_HASH_SHA1_Finish(&ctx->hhash_sha1, output, 10) != 0){
return; // error code to be returned
return MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED;
}
if (st_sha1_save_hw_context(ctx) != 1) {
return; // return HASH_BUSY timeout Error here
return MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED; // Hash busy timeout
}
return 0;
}
#endif /*MBEDTLS_SHA1_ALT*/

View File

@ -24,6 +24,18 @@
#if defined (MBEDTLS_SHA1_ALT)
/**
* \name SECTION: Temporary compatibility code
*
* This section contains code to be added up stream in Mbed TLS. Once that
* has been provided, this section should be removed as the code will be
* provided elsewhere.
* \{
*/
#define MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED -0x0035 /**< SHA-1 hardware accelerator failed */
/* \} name SECTION: Temporary compatibility code */
#include "cmsis.h"
#include <string.h>
@ -79,8 +91,10 @@ void mbedtls_sha1_clone( mbedtls_sha1_context *dst,
* \brief SHA-1 context setup
*
* \param ctx context to be initialized
*
* \return 0 if successful
*/
void mbedtls_sha1_starts( mbedtls_sha1_context *ctx );
int mbedtls_sha1_starts_ret( mbedtls_sha1_context *ctx );
/**
* \brief SHA-1 process buffer
@ -88,19 +102,23 @@ void mbedtls_sha1_starts( mbedtls_sha1_context *ctx );
* \param ctx SHA-1 context
* \param input buffer holding the data
* \param ilen length of the input data
*
* \return 0 if successful
*/
void mbedtls_sha1_update( mbedtls_sha1_context *ctx, const unsigned char *input, size_t ilen );
int mbedtls_sha1_update_ret( mbedtls_sha1_context *ctx, const unsigned char *input, size_t ilen );
/**
* \brief SHA-1 final digest
*
* \param ctx SHA-1 context
* \param output SHA-1 checksum result
*
* \return 0 if successful
*/
void mbedtls_sha1_finish( mbedtls_sha1_context *ctx, unsigned char output[20] );
int mbedtls_sha1_finish_ret( mbedtls_sha1_context *ctx, unsigned char output[20] );
/* Internal use */
void mbedtls_sha1_process( mbedtls_sha1_context *ctx, const unsigned char data[ST_SHA1_BLOCK_SIZE] );
int mbedtls_sha1_process( mbedtls_sha1_context *ctx, const unsigned char data[ST_SHA1_BLOCK_SIZE] );
#ifdef __cplusplus
}

View File

@ -88,12 +88,11 @@ void mbedtls_sha256_clone( mbedtls_sha256_context *dst,
*dst = *src;
}
void mbedtls_sha256_starts( mbedtls_sha256_context *ctx, int is224 )
int mbedtls_sha256_starts_ret( mbedtls_sha256_context *ctx, int is224 )
{
/* HASH IP initialization */
if (HAL_HASH_DeInit(&ctx->hhash_sha256) == HAL_ERROR) {
// error found to be returned
return;
return MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED;
}
ctx->is224 = is224;
@ -102,39 +101,42 @@ void mbedtls_sha256_starts( mbedtls_sha256_context *ctx, int is224 )
/* clear CR ALGO value */
HASH->CR &= ~HASH_CR_ALGO_Msk;
if (HAL_HASH_Init(&ctx->hhash_sha256) == HAL_ERROR) {
// error found to be returned
return;
return MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED;
}
if (st_sha256_save_hw_context(ctx) != 1) {
return; // return HASH_BUSY timeout Error here
return MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED; // Hash busy timeout
}
return 0;
}
void mbedtls_sha256_process( mbedtls_sha256_context *ctx, const unsigned char data[ST_SHA256_BLOCK_SIZE] )
int mbedtls_sha256_process( mbedtls_sha256_context *ctx, const unsigned char data[ST_SHA256_BLOCK_SIZE] )
{
if (st_sha256_restore_hw_context(ctx) != 1) {
return; // Return HASH_BUSY timout error here
return MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED; // Hash busy timeout
}
if (ctx->is224 == 0) {
if (HAL_HASHEx_SHA256_Accumulate(&ctx->hhash_sha256, (uint8_t *) data, ST_SHA256_BLOCK_SIZE) != 0) {
return; // Return error code
return MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED;
}
} else {
if (HAL_HASHEx_SHA224_Accumulate(&ctx->hhash_sha256, (uint8_t *) data, ST_SHA256_BLOCK_SIZE) != 0) {
return; // Return error code
return MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED;
}
}
if (st_sha256_save_hw_context(ctx) != 1) {
return; // return HASH_BUSY timeout Error here
return MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED; // Hash busy timeout
}
return 0;
}
void mbedtls_sha256_update( mbedtls_sha256_context *ctx, const unsigned char *input, size_t ilen )
int mbedtls_sha256_update_ret( mbedtls_sha256_context *ctx, const unsigned char *input, size_t ilen )
{
size_t currentlen = ilen;
if (st_sha256_restore_hw_context(ctx) != 1) {
return; // Return HASH_BUSY timout error here
return MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED; // Hash busy timeout
}
// store mechanism to accumulate ST_SHA256_BLOCK_SIZE bytes (512 bits) in the HW
@ -157,17 +159,19 @@ void mbedtls_sha256_update( mbedtls_sha256_context *ctx, const unsigned char *in
// fill buffer and process it
memcpy(ctx->sbuf + ctx->sbuf_len, input, (ST_SHA256_BLOCK_SIZE - ctx->sbuf_len));
currentlen -= (ST_SHA256_BLOCK_SIZE - ctx->sbuf_len);
mbedtls_sha256_process(ctx, ctx->sbuf);
if( mbedtls_sha256_process(ctx, ctx->sbuf) != 0) {
return MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED;
}
// Process every input as long as it is %64 bytes, ie 512 bits
size_t iter = currentlen / ST_SHA256_BLOCK_SIZE;
if (iter !=0) {
if (ctx->is224 == 0) {
if (HAL_HASHEx_SHA256_Accumulate(&ctx->hhash_sha256, (uint8_t *)(input + ST_SHA256_BLOCK_SIZE - ctx->sbuf_len), (iter * ST_SHA256_BLOCK_SIZE)) != 0) {
return; // Return error code here
return MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED;
}
} else {
if (HAL_HASHEx_SHA224_Accumulate(&ctx->hhash_sha256, (uint8_t *)(input + ST_SHA256_BLOCK_SIZE - ctx->sbuf_len), (iter * ST_SHA256_BLOCK_SIZE)) != 0) {
return; // Return error code here
return MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED;
}
}
}
@ -178,24 +182,26 @@ void mbedtls_sha256_update( mbedtls_sha256_context *ctx, const unsigned char *in
}
}
if (st_sha256_save_hw_context(ctx) != 1) {
return; // return HASH_BUSY timeout Error here
return MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED; // Hash busy timeout
}
return 0;
}
void mbedtls_sha256_finish( mbedtls_sha256_context *ctx, unsigned char output[32] )
int mbedtls_sha256_finish_ret( mbedtls_sha256_context *ctx, unsigned char output[32] )
{
if (st_sha256_restore_hw_context(ctx) != 1) {
return; // Return HASH_BUSY timout error here
return MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED; // Hash busy timeout
}
/* Last accumulation for extra bytes in sbuf_len */
/* This allows the HW flags to be in place in case mbedtls_sha256_update has not been called yet */
if (ctx->is224 == 0) {
if (HAL_HASHEx_SHA256_Accumulate(&ctx->hhash_sha256, ctx->sbuf, ctx->sbuf_len) != 0) {
return; // Return error code here
return MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED;
}
} else {
if (HAL_HASHEx_SHA224_Accumulate(&ctx->hhash_sha256, ctx->sbuf, ctx->sbuf_len) != 0) {
return; // Return error code here
return MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED;
}
}
@ -205,16 +211,18 @@ void mbedtls_sha256_finish( mbedtls_sha256_context *ctx, unsigned char output[32
if (ctx->is224 == 0) {
if (HAL_HASHEx_SHA256_Finish(&ctx->hhash_sha256, output, 10) != 0) {
return; // Return error code here
return MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED;
}
} else {
if (HAL_HASHEx_SHA224_Finish(&ctx->hhash_sha256, output, 10) != 0) {
return; // Return error code here
return MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED;
}
}
if (st_sha256_save_hw_context(ctx) != 1) {
return; // return HASH_BUSY timeout Error here
return MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED; // Hash busy timeout
}
return 0;
}
#endif /*MBEDTLS_SHA256_ALT*/

View File

@ -27,6 +27,19 @@
#include "cmsis.h"
#include <string.h>
/**
* \name SECTION: Temporary compatibility code
*
* This section contains code to be added up stream in Mbed TLS. Once that
* has been provided, this section should be removed as the code will be
* provided elsewhere.
* \{
*/
#define MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED -0x0037 /**< SHA-256 hardware accelerator failed */
/* \} name SECTION: Temporary compatibility code */
#ifdef __cplusplus
extern "C" {
#endif
@ -80,8 +93,10 @@ void mbedtls_sha256_clone( mbedtls_sha256_context *dst,
*
* \param ctx context to be initialized
* \param is224 0 = use SHA256, 1 = use SHA224
*
* \return 0 if successful
*/
void mbedtls_sha256_starts( mbedtls_sha256_context *ctx, int is224 );
int mbedtls_sha256_starts_ret( mbedtls_sha256_context *ctx, int is224 );
/**
* \brief SHA-256 process buffer
@ -89,8 +104,10 @@ void mbedtls_sha256_starts( mbedtls_sha256_context *ctx, int is224 );
* \param ctx SHA-256 context
* \param input buffer holding the data
* \param ilen length of the input data
*
* \return 0 if successful
*/
void mbedtls_sha256_update( mbedtls_sha256_context *ctx, const unsigned char *input,
int mbedtls_sha256_update_ret( mbedtls_sha256_context *ctx, const unsigned char *input,
size_t ilen );
/**
@ -98,11 +115,13 @@ void mbedtls_sha256_update( mbedtls_sha256_context *ctx, const unsigned char *in
*
* \param ctx SHA-256 context
* \param output SHA-224/256 checksum result
*
* \return 0 if successful
*/
void mbedtls_sha256_finish( mbedtls_sha256_context *ctx, unsigned char output[32] );
int mbedtls_sha256_finish_ret( mbedtls_sha256_context *ctx, unsigned char output[32] );
/* Internal use */
void mbedtls_sha256_process( mbedtls_sha256_context *ctx, const unsigned char data[ST_SHA256_BLOCK_SIZE] );
int mbedtls_sha256_process( mbedtls_sha256_context *ctx, const unsigned char data[ST_SHA256_BLOCK_SIZE] );
#ifdef __cplusplus
}

View File

@ -234,7 +234,7 @@ void mbedtls_sha256_clone( mbedtls_sha256_context *dst,
/*
* SHA-256 context setup
*/
void mbedtls_sha256_starts( mbedtls_sha256_context *ctx, int is224 )
int mbedtls_sha256_starts_ret( mbedtls_sha256_context *ctx, int is224 )
{
ctx->total[0] = 0;
ctx->total[1] = 0;
@ -246,6 +246,8 @@ void mbedtls_sha256_starts( mbedtls_sha256_context *ctx, int is224 )
ctx->is224 = false;
memcpy(ctx->state, init_state_sha256, sizeof(ctx->state));
}
return 0;
}
void mbedtls_sha256_process( mbedtls_sha256_context *ctx,
@ -257,15 +259,15 @@ void mbedtls_sha256_process( mbedtls_sha256_context *ctx,
/*
* SHA-256 process buffer
*/
void mbedtls_sha256_update( mbedtls_sha256_context *ctx,
const unsigned char *input,
size_t ilen )
int mbedtls_sha256_update_ret( mbedtls_sha256_context *ctx,
const unsigned char *input,
size_t ilen )
{
size_t fill;
uint32_t left;
if( ilen == 0 ) {
return;
return 0;
}
left = ctx->total[0] & 0x3F;
@ -296,17 +298,20 @@ void mbedtls_sha256_update( mbedtls_sha256_context *ctx,
if( ilen > 0 ) {
memcpy( (void *) (ctx->buffer + left), input, ilen );
}
return 0;
}
/*
* SHA-256 final digest
*/
void mbedtls_sha256_finish( mbedtls_sha256_context *ctx,
unsigned char output[32] )
int mbedtls_sha256_finish_ret( mbedtls_sha256_context *ctx,
unsigned char output[32] )
{
uint32_t last, padn;
uint32_t high, low;
unsigned char msglen[8];
int err;
high = ( ctx->total[0] >> 29 )
| ( ctx->total[1] << 3 );
@ -318,12 +323,21 @@ void mbedtls_sha256_finish( mbedtls_sha256_context *ctx,
last = ctx->total[0] & 0x3F;
padn = ( last < 56 ) ? ( 56 - last ) : ( 120 - last );
mbedtls_sha256_update( ctx, sha_padding, padn );
mbedtls_sha256_update( ctx, msglen, 8 );
err = mbedtls_sha256_update_ret( ctx, sha_padding, padn );
if( err != 0 ) {
return err;
}
err = mbedtls_sha256_update_ret( ctx, msglen, 8 );
if( err != 0 ) {
return err;
}
for ( size_t i = 0; i < (ctx->is224 ? 28 : 32); i+=4) {
*((uint32_t*)(&output[i])) = __REV(ctx->state[i >> 2]);
}
return 0;
}
#endif /* #if defined(MBEDTLS_SHA256_ALT) && defined(MBEDTLS_SHA256_C) */
@ -366,12 +380,16 @@ void mbedtls_sha1_clone( mbedtls_sha1_context *dst,
* \brief SHA-1 context setup
*
* \param ctx context to be initialized
*
* \return \c 0 if successful
*
*/
void mbedtls_sha1_starts( mbedtls_sha1_context *ctx )
int mbedtls_sha1_starts_ret( mbedtls_sha1_context *ctx )
{
ctx->total[0] = 0;
ctx->total[1] = 0;
memcpy(ctx->state, init_state_sha1, 32);
return 0;
}
/**
@ -380,16 +398,19 @@ void mbedtls_sha1_starts( mbedtls_sha1_context *ctx )
* \param ctx SHA-1 context
* \param input buffer holding the data
* \param ilen length of the input data
*
* \return \c 0 if successful
*
*/
void mbedtls_sha1_update( mbedtls_sha1_context *ctx,
const unsigned char *input,
size_t ilen )
int mbedtls_sha1_update_ret( mbedtls_sha1_context *ctx,
const unsigned char *input,
size_t ilen )
{
size_t fill;
uint32_t left;
if( ilen == 0 ) {
return;
return 0;
}
left = ctx->total[0] & 0x3F;
@ -420,6 +441,8 @@ void mbedtls_sha1_update( mbedtls_sha1_context *ctx,
if( ilen > 0 ) {
memcpy( (void *) (ctx->buffer + left), input, ilen );
}
return 0;
}
/**
@ -427,13 +450,17 @@ void mbedtls_sha1_update( mbedtls_sha1_context *ctx,
*
* \param ctx SHA-1 context
* \param output SHA-1 checksum result
*
* \return \c 0 if successful
*
*/
void mbedtls_sha1_finish( mbedtls_sha1_context *ctx,
unsigned char output[20] )
int mbedtls_sha1_finish_ret( mbedtls_sha1_context *ctx,
unsigned char output[20] )
{
uint32_t last, padn;
uint32_t high, low;
unsigned char msglen[8];
int err;
high = ( ctx->total[0] >> 29 )
| ( ctx->total[1] << 3 );
@ -445,12 +472,21 @@ void mbedtls_sha1_finish( mbedtls_sha1_context *ctx,
last = ctx->total[0] & 0x3F;
padn = ( last < 56 ) ? ( 56 - last ) : ( 120 - last );
mbedtls_sha1_update( ctx, sha_padding, padn );
mbedtls_sha1_update( ctx, msglen, 8 );
err = mbedtls_sha1_update_ret( ctx, sha_padding, padn );
if( err != 0 ) {
return err;
}
err = mbedtls_sha1_update_ret( ctx, msglen, 8 );
if( err != 0 ) {
return err;
}
for ( size_t i = 0; i < 20; i+=4) {
*((uint32_t*)(&output[i])) = __REV(ctx->state[i >> 2]);
}
return 0;
}
/* Internal use */

View File

@ -78,8 +78,11 @@ void mbedtls_sha1_clone( mbedtls_sha1_context *dst,
* \brief SHA-1 context setup
*
* \param ctx context to be initialized
*
* \return \c 0 if successful
*
*/
void mbedtls_sha1_starts( mbedtls_sha1_context *ctx );
int mbedtls_sha1_starts_ret( mbedtls_sha1_context *ctx );
/**
* \brief SHA-1 process buffer
@ -87,16 +90,22 @@ void mbedtls_sha1_starts( mbedtls_sha1_context *ctx );
* \param ctx SHA-1 context
* \param input buffer holding the data
* \param ilen length of the input data
*
* \return \c 0 if successful
*
*/
void mbedtls_sha1_update( mbedtls_sha1_context *ctx, const unsigned char *input, size_t ilen );
int mbedtls_sha1_update_ret( mbedtls_sha1_context *ctx, const unsigned char *input, size_t ilen );
/**
* \brief SHA-1 final digest
*
* \param ctx SHA-1 context
* \param output SHA-1 checksum result
*
* \return \c 0 if successful
*
*/
void mbedtls_sha1_finish( mbedtls_sha1_context *ctx, unsigned char output[20] );
int mbedtls_sha1_finish_ret( mbedtls_sha1_context *ctx, unsigned char output[20] );
/* Internal use */
void mbedtls_sha1_process( mbedtls_sha1_context *ctx, const unsigned char data[64] );

View File

@ -84,8 +84,11 @@ void mbedtls_sha256_clone( mbedtls_sha256_context *dst,
*
* \param ctx context to be initialized
* \param is224 0 = use SHA256, 1 = use SHA224
*
* \return \c 0 if successful
*
*/
void mbedtls_sha256_starts( mbedtls_sha256_context *ctx, int is224 );
int mbedtls_sha256_starts_ret( mbedtls_sha256_context *ctx, int is224 );
/**
* \brief SHA-256 process buffer
@ -93,17 +96,22 @@ void mbedtls_sha256_starts( mbedtls_sha256_context *ctx, int is224 );
* \param ctx SHA-256 context
* \param input buffer holding the data
* \param ilen length of the input data
*
* \return \c 0 if successful
*
*/
void mbedtls_sha256_update( mbedtls_sha256_context *ctx, const unsigned char *input,
size_t ilen );
int mbedtls_sha256_update_ret( mbedtls_sha256_context *ctx, const unsigned char *input, size_t ilen );
/**
* \brief SHA-256 final digest
*
* \param ctx SHA-256 context
* \param output SHA-224/256 checksum result
*
* \return \c 0 if successful
*
*/
void mbedtls_sha256_finish( mbedtls_sha256_context *ctx, unsigned char output[32] );
int mbedtls_sha256_finish_ret( mbedtls_sha256_context *ctx, unsigned char output[32] );
/* Internal use */
void mbedtls_sha256_process( mbedtls_sha256_context *ctx, const unsigned char data[64] );

View File

@ -0,0 +1,356 @@
#include "mbedtls/md2.h"
#include "mbedtls/md4.h"
#include "mbedtls/md5.h"
#include "mbedtls/sha1.h"
#include "mbedtls/sha256.h"
#include "mbedtls/sha512.h"
#if defined(MBEDTLS_MD2_C) && defined(MBEDTLS_MD2_ALT)
/**
* \brief MD2 context setup
*
* \deprecated Superseded by mbedtls_md2_starts_ret() in 2.7.0
*
* \param ctx context to be initialized
*
* \warning MD2 is considered a weak message digest and its use
* constitutes a security risk. We recommend considering
* stronger message digests instead.
*
*/
void mbedtls_md2_starts( mbedtls_md2_context *ctx )
{
mbedtls_md2_starts_ret( ctx );
}
/**
* \brief MD2 process buffer
*
* \deprecated Superseded by mbedtls_md2_update_ret() in 2.7.0
*
* \param ctx MD2 context
* \param input buffer holding the data
* \param ilen length of the input data
*
* \warning MD2 is considered a weak message digest and its use
* constitutes a security risk. We recommend considering
* stronger message digests instead.
*
*/
void mbedtls_md2_update( mbedtls_md2_context *ctx,
const unsigned char *input,
size_t ilen )
{
mbedtls_md2_update_ret( ctx, input, ilen );
}
/**
* \brief MD2 final digest
*
* \deprecated Superseded by mbedtls_md2_finish_ret() in 2.7.0
*
* \param ctx MD2 context
* \param output MD2 checksum result
*
* \warning MD2 is considered a weak message digest and its use
* constitutes a security risk. We recommend considering
* stronger message digests instead.
*
*/
void mbedtls_md2_finish( mbedtls_md2_context *ctx,
unsigned char output[16] )
{
mbedtls_md2_finish_ret( ctx, output );
}
#endif /* defined(MBEDTLS_MD2_ALT) */
#if defined(MBEDTLS_MD4_C) && defined(MBEDTLS_MD4_ALT)
/**
* \brief MD4 context setup
*
* \deprecated Superseded by mbedtls_md4_starts_ret() in 2.7.0
*
* \param ctx context to be initialized
*
* \warning MD4 is considered a weak message digest and its use
* constitutes a security risk. We recommend considering
* stronger message digests instead.
*
*/
void mbedtls_md4_starts( mbedtls_md4_context *ctx )
{
mbedtls_md4_starts_ret( ctx );
}
/**
* \brief MD4 process buffer
*
* \deprecated Superseded by mbedtls_md4_update_ret() in 2.7.0
*
* \param ctx MD4 context
* \param input buffer holding the data
* \param ilen length of the input data
*
* \warning MD4 is considered a weak message digest and its use
* constitutes a security risk. We recommend considering
* stronger message digests instead.
*
*/
void mbedtls_md4_update( mbedtls_md4_context *ctx,
const unsigned char *input,
size_t ilen )
{
mbedtls_md4_update_ret( ctx, input, ilen );
}
/**
* \brief MD4 final digest
*
* \deprecated Superseded by mbedtls_md4_finish_ret() in 2.7.0
*
* \param ctx MD4 context
* \param output MD4 checksum result
*
* \warning MD4 is considered a weak message digest and its use
* constitutes a security risk. We recommend considering
* stronger message digests instead.
*
*/
void mbedtls_md4_finish( mbedtls_md4_context *ctx,
unsigned char output[16] )
{
mbedtls_md4_finish_ret( ctx, output );
}
#endif /* defined(MBEDTLS_MD4_ALT) */
#if defined(MBEDTLS_MD5_C) && defined(MBEDTLS_MD5_ALT)
/**
* \brief MD5 context setup
*
* \deprecated Superseded by mbedtls_md5_starts_ret() in 2.7.0
*
* \param ctx context to be initialized
*
* \warning MD5 is considered a weak message digest and its use
* constitutes a security risk. We recommend considering
* stronger message digests instead.
*
*/
void mbedtls_md5_starts( mbedtls_md5_context *ctx )
{
mbedtls_md5_starts_ret( ctx );
}
/**
* \brief MD5 process buffer
*
* \deprecated Superseded by mbedtls_md5_update_ret() in 2.7.0
*
* \param ctx MD5 context
* \param input buffer holding the data
* \param ilen length of the input data
*
* \warning MD5 is considered a weak message digest and its use
* constitutes a security risk. We recommend considering
* stronger message digests instead.
*
*/
void mbedtls_md5_update( mbedtls_md5_context *ctx,
const unsigned char *input,
size_t ilen )
{
mbedtls_md5_update_ret( ctx, input, ilen );
}
/**
* \brief MD5 final digest
*
* \deprecated Superseded by mbedtls_md5_finish_ret() in 2.7.0
*
* \param ctx MD5 context
* \param output MD5 checksum result
*
* \warning MD5 is considered a weak message digest and its use
* constitutes a security risk. We recommend considering
* stronger message digests instead.
*
*/
void mbedtls_md5_finish( mbedtls_md5_context *ctx,
unsigned char output[16] )
{
mbedtls_md5_finish_ret( ctx, output );
}
#endif /* defined(MBEDTLS_MD5_ALT) */
#if defined(MBEDTLS_SHA1_C) && defined(MBEDTLS_SHA1_ALT)
/**
* \brief SHA-1 context setup
*
* \deprecated Superseded by mbedtls_sha1_starts_ret() in 2.7.0
*
* \param ctx The SHA-1 context to be initialized.
*
* \warning SHA-1 is considered a weak message digest and its use
* constitutes a security risk. We recommend considering
* stronger message digests instead.
*
*/
void mbedtls_sha1_starts( mbedtls_sha1_context *ctx )
{
mbedtls_sha1_starts_ret( ctx );
}
/**
* \brief SHA-1 process buffer
*
* \deprecated Superseded by mbedtls_sha1_update_ret() in 2.7.0
*
* \param ctx The SHA-1 context.
* \param input The buffer holding the input data.
* \param ilen The length of the input data.
*
* \warning SHA-1 is considered a weak message digest and its use
* constitutes a security risk. We recommend considering
* stronger message digests instead.
*
*/
void mbedtls_sha1_update( mbedtls_sha1_context *ctx,
const unsigned char *input,
size_t ilen )
{
mbedtls_sha1_update_ret( ctx, input, ilen );
}
/**
* \brief SHA-1 final digest
*
* \deprecated Superseded by mbedtls_sha1_finish_ret() in 2.7.0
*
* \param ctx The SHA-1 context.
* \param output The SHA-1 checksum result.
*
* \warning SHA-1 is considered a weak message digest and its use
* constitutes a security risk. We recommend considering
* stronger message digests instead.
*
*/
void mbedtls_sha1_finish( mbedtls_sha1_context *ctx,
unsigned char output[20] )
{
mbedtls_sha1_finish_ret( ctx, output );
}
#endif /* defined(MBEDTLS_SHA1_ALT) */
#if defined(MBEDTLS_SHA256_C) && defined(MBEDTLS_SHA256_ALT)
/**
* \brief This function starts a SHA-256 checksum calculation.
*
* \deprecated Superseded by mbedtls_sha256_starts_ret() in 2.7.0.
*
* \param ctx The SHA-256 context to initialize.
* \param is224 Determines which function to use.
* <ul><li>0: Use SHA-256.</li>
* <li>1: Use SHA-224.</li></ul>
*/
void mbedtls_sha256_starts( mbedtls_sha256_context *ctx,
int is224 )
{
mbedtls_sha256_starts_ret( ctx, is224 );
}
/**
* \brief This function feeds an input buffer into an ongoing
* SHA-256 checksum calculation.
*
* \deprecated Superseded by mbedtls_sha256_update_ret() in 2.7.0.
*
* \param ctx The SHA-256 context to initialize.
* \param input The buffer holding the data.
* \param ilen The length of the input data.
*/
void mbedtls_sha256_update( mbedtls_sha256_context *ctx,
const unsigned char *input,
size_t ilen )
{
mbedtls_sha256_update_ret( ctx, input, ilen );
}
/**
* \brief This function finishes the SHA-256 operation, and writes
* the result to the output buffer.
*
* \deprecated Superseded by mbedtls_sha256_finish_ret() in 2.7.0.
*
* \param ctx The SHA-256 context.
* \param output The SHA-224or SHA-256 checksum result.
*/
void mbedtls_sha256_finish( mbedtls_sha256_context *ctx,
unsigned char output[32] )
{
mbedtls_sha256_finish_ret( ctx, output );
}
#endif /* defined(MBEDTLS_SHA256_ALT) */
#if defined(MBEDTLS_SHA512_C) && defined(MBEDTLS_SHA512_ALT)
/**
* \brief This function starts a SHA-384 or SHA-512 checksum
* calculation.
*
* \deprecated Superseded by mbedtls_sha512_starts_ret() in 2.7.0
*
* \param ctx The SHA-512 context to initialize.
* \param is384 Determines which function to use.
* <ul><li>0: Use SHA-512.</li>
* <li>1: Use SHA-384.</li></ul>
*/
void mbedtls_sha512_starts( mbedtls_sha512_context *ctx,
int is384 )
{
mbedtls_sha512_starts_ret( ctx, is384 );
}
/**
* \brief This function feeds an input buffer into an ongoing
* SHA-512 checksum calculation.
*
* \deprecated Superseded by mbedtls_sha512_update_ret() in 2.7.0
*
* \param ctx The SHA-512 context.
* \param input The buffer holding the data.
* \param ilen The length of the input data.
*/
void mbedtls_sha512_update( mbedtls_sha512_context *ctx,
const unsigned char *input,
size_t ilen )
{
mbedtls_sha512_update_ret( ctx, input, ilen );
}
/**
* \brief This function finishes the SHA-512 operation, and writes
* the result to the output buffer.
*
* \deprecated Superseded by mbedtls_sha512_finish_ret() in 2.7.0
*
* \param ctx The SHA-512 context.
* \param output The SHA-384 or SHA-512 checksum result.
*/
void mbedtls_sha512_finish( mbedtls_sha512_context *ctx,
unsigned char output[64] )
{
mbedtls_sha512_finish_ret( ctx, output );
}
#endif /* defined(MBEDTLS_SHA512_ALT) */