Revert "Update Mbed TLS HW acceleration partner code to new hashing API"

pull/6163/head
Martin Kojtal 2018-02-22 11:20:35 +00:00 committed by GitHub
parent c32b822bb2
commit 414b2d971d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 133 additions and 725 deletions

View File

@ -23,67 +23,6 @@
#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,40 +103,37 @@ void mbedtls_sha1_clone(mbedtls_sha1_context *dst,
/*
* SHA-1 context setup
*/
int mbedtls_sha1_starts_ret(mbedtls_sha1_context *ctx)
void mbedtls_sha1_starts(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
*/
int mbedtls_sha1_update_ret(mbedtls_sha1_context *ctx, const unsigned char *input, size_t ilen)
void mbedtls_sha1_update(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
*/
int mbedtls_sha1_finish_ret(mbedtls_sha1_context *ctx, unsigned char output[20])
void mbedtls_sha1_finish(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,10 +66,8 @@ void mbedtls_sha1_clone( mbedtls_sha1_context *dst,
* \brief SHA-1 context setup
*
* \param ctx context to be initialized
*
* \return 0 if successful
*/
int mbedtls_sha1_starts_ret( mbedtls_sha1_context *ctx );
void mbedtls_sha1_starts( mbedtls_sha1_context *ctx );
/**
* \brief SHA-1 process buffer
@ -77,20 +75,16 @@ int mbedtls_sha1_starts_ret( 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
*/
int mbedtls_sha1_update_ret( mbedtls_sha1_context *ctx, const unsigned char *input, size_t ilen );
void mbedtls_sha1_update( 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
*/
int mbedtls_sha1_finish_ret( mbedtls_sha1_context *ctx, unsigned char output[20] );
void mbedtls_sha1_finish( 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,40 +104,37 @@ void mbedtls_sha256_clone(mbedtls_sha256_context *dst,
/*
* SHA-256 context setup
*/
int mbedtls_sha256_starts_ret(mbedtls_sha256_context *ctx, int is224)
void mbedtls_sha256_starts(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
*/
int mbedtls_sha256_update_ret(mbedtls_sha256_context *ctx, const unsigned char *input, size_t ilen)
void mbedtls_sha256_update(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
*/
int mbedtls_sha256_finish_ret(mbedtls_sha256_context *ctx, unsigned char output[32])
void mbedtls_sha256_finish(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,10 +67,8 @@ 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
*/
int mbedtls_sha256_starts_ret( mbedtls_sha256_context *ctx, int is224 );
void mbedtls_sha256_starts( mbedtls_sha256_context *ctx, int is224 );
/**
* \brief SHA-256 process buffer
@ -78,21 +76,17 @@ int mbedtls_sha256_starts_ret( 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
*/
int mbedtls_sha256_update_ret( mbedtls_sha256_context *ctx, const unsigned char *input,
size_t ilen );
void mbedtls_sha256_update( 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
*/
int mbedtls_sha256_finish_ret( mbedtls_sha256_context *ctx, unsigned char output[32] );
void mbedtls_sha256_finish( 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,40 +105,37 @@ void mbedtls_sha512_clone(mbedtls_sha512_context *dst,
/*
* SHA-512 context setup
*/
int mbedtls_sha512_starts_ret(mbedtls_sha512_context *ctx, int is384)
void mbedtls_sha512_starts(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
*/
int mbedtls_sha512_update_ret(mbedtls_sha512_context *ctx, const unsigned char *input, size_t ilen)
void mbedtls_sha512_update(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
*/
int mbedtls_sha512_finish_ret(mbedtls_sha512_context *ctx, unsigned char output[64])
void mbedtls_sha512_finish(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,10 +67,8 @@ 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
*/
int mbedtls_sha512_starts_ret( mbedtls_sha512_context *ctx, int is384 );
void mbedtls_sha512_starts( mbedtls_sha512_context *ctx, int is384 );
/**
* \brief SHA-512 process buffer
@ -78,21 +76,17 @@ int mbedtls_sha512_starts_ret( 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
*/
int mbedtls_sha512_update_ret( mbedtls_sha512_context *ctx, const unsigned char *input,
size_t ilen );
void mbedtls_sha512_update( 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
*/
int mbedtls_sha512_finish_ret( mbedtls_sha512_context *ctx, unsigned char output[64] );
void mbedtls_sha512_finish( 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,40 +103,37 @@ void mbedtls_sha1_clone(mbedtls_sha1_context *dst,
/*
* SHA-1 context setup
*/
int mbedtls_sha1_starts_ret(mbedtls_sha1_context *ctx)
void mbedtls_sha1_starts(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
*/
int mbedtls_sha1_update_ret(mbedtls_sha1_context *ctx, const unsigned char *input, size_t ilen)
void mbedtls_sha1_update(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
*/
int mbedtls_sha1_finish_ret(mbedtls_sha1_context *ctx, unsigned char output[20])
void mbedtls_sha1_finish(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,10 +66,8 @@ void mbedtls_sha1_clone( mbedtls_sha1_context *dst,
* \brief SHA-1 context setup
*
* \param ctx context to be initialized
*
* \return 0 if successful
*/
int mbedtls_sha1_starts_ret( mbedtls_sha1_context *ctx );
void mbedtls_sha1_starts( mbedtls_sha1_context *ctx );
/**
* \brief SHA-1 process buffer
@ -77,20 +75,16 @@ int mbedtls_sha1_starts_ret( 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
*/
int mbedtls_sha1_update_ret( mbedtls_sha1_context *ctx, const unsigned char *input, size_t ilen );
void mbedtls_sha1_update( 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
*/
int mbedtls_sha1_finish_ret( mbedtls_sha1_context *ctx, unsigned char output[20] );
void mbedtls_sha1_finish( 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,40 +104,37 @@ void mbedtls_sha256_clone(mbedtls_sha256_context *dst,
/*
* SHA-256 context setup
*/
int mbedtls_sha256_starts_ret(mbedtls_sha256_context *ctx, int is224)
void mbedtls_sha256_starts(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
*/
int mbedtls_sha256_update_ret(mbedtls_sha256_context *ctx, const unsigned char *input, size_t ilen)
void mbedtls_sha256_update(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
*/
int mbedtls_sha256_finish_ret(mbedtls_sha256_context *ctx, unsigned char output[32])
void mbedtls_sha256_finish(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,10 +67,8 @@ 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
*/
int mbedtls_sha256_starts_ret( mbedtls_sha256_context *ctx, int is224 );
void mbedtls_sha256_starts( mbedtls_sha256_context *ctx, int is224 );
/**
* \brief SHA-256 process buffer
@ -78,21 +76,17 @@ int mbedtls_sha256_starts_ret( 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
*/
int mbedtls_sha256_update_ret( mbedtls_sha256_context *ctx, const unsigned char *input,
size_t ilen );
void mbedtls_sha256_update( 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
*/
int mbedtls_sha256_finish_ret( mbedtls_sha256_context *ctx, unsigned char output[32] );
void mbedtls_sha256_finish( 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,11 +90,12 @@ void mbedtls_md5_clone( mbedtls_md5_context *dst,
*dst = *src;
}
int mbedtls_md5_starts_ret( mbedtls_md5_context *ctx )
void mbedtls_md5_starts( mbedtls_md5_context *ctx )
{
/* HASH IP initialization */
if (HAL_HASH_DeInit(&ctx->hhash_md5) != 0) {
return MBEDTLS_ERR_MD5_HW_ACCEL_FAILED;
// error found to be returned
return;
}
/* HASH Configuration */
@ -102,37 +103,34 @@ int mbedtls_md5_starts_ret( mbedtls_md5_context *ctx )
/* clear CR ALGO value */
HASH->CR &= ~HASH_CR_ALGO_Msk;
if (HAL_HASH_Init(&ctx->hhash_md5) != 0) {
return MBEDTLS_ERR_MD5_HW_ACCEL_FAILED;
// return error code
return;
}
if (st_md5_save_hw_context(ctx) != 1) {
return MBEDTLS_ERR_MD5_HW_ACCEL_FAILED; // Hash busy timeout
return; // return HASH_BUSY timeout Error here
}
return 0;
}
int mbedtls_md5_process( mbedtls_md5_context *ctx, const unsigned char data[ST_MD5_BLOCK_SIZE] )
void mbedtls_md5_process( mbedtls_md5_context *ctx, const unsigned char data[ST_MD5_BLOCK_SIZE] )
{
if (st_md5_restore_hw_context(ctx) != 1) {
return MBEDTLS_ERR_MD5_HW_ACCEL_FAILED; // Hash busy timeout
return; // Return HASH_BUSY timout error here
}
if (HAL_HASH_MD5_Accumulate(&ctx->hhash_md5, (uint8_t *)data, ST_MD5_BLOCK_SIZE) != 0) {
return MBEDTLS_ERR_MD5_HW_ACCEL_FAILED;
return; // Return error code here
}
if (st_md5_save_hw_context(ctx) != 1) {
return MBEDTLS_ERR_MD5_HW_ACCEL_FAILED; // Hash busy timeout
return; // return HASH_BUSY timeout Error here
}
return 0;
}
int mbedtls_md5_update_ret( mbedtls_md5_context *ctx, const unsigned char *input, size_t ilen )
void mbedtls_md5_update( 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 MBEDTLS_ERR_MD5_HW_ACCEL_FAILED; // Hash busy timeout
return; // Return HASH_BUSY timout error here
}
// store mechanism to accumulate ST_MD5_BLOCK_SIZE bytes (512 bits) in the HW
@ -149,7 +147,7 @@ int mbedtls_md5_update_ret( mbedtls_md5_context *ctx, const unsigned char *input
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 MBEDTLS_ERR_MD5_HW_ACCEL_FAILED;
return; // Return error code here
}
}
// sbuf is completely accumulated, now copy up to 63 remaining bytes
@ -160,20 +158,20 @@ int mbedtls_md5_update_ret( mbedtls_md5_context *ctx, const unsigned char *input
}
if (st_md5_save_hw_context(ctx) != 1) {
return MBEDTLS_ERR_MD5_HW_ACCEL_FAILED; // Hash busy timeout
return; // return HASH_BUSY timeout Error here
}
}
}
int mbedtls_md5_finish_ret( mbedtls_md5_context *ctx, unsigned char output[16] )
void mbedtls_md5_finish( mbedtls_md5_context *ctx, unsigned char output[16] )
{
if (st_md5_restore_hw_context(ctx) != 1) {
return MBEDTLS_ERR_MD5_HW_ACCEL_FAILED; // Hash busy timeout
return; // Return HASH_BUSY timout error here
}
/* 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 MBEDTLS_ERR_MD5_HW_ACCEL_FAILED; // Accumulation error
return; // Return error code here
}
mbedtls_zeroize( ctx->sbuf, ST_MD5_BLOCK_SIZE);
@ -181,13 +179,11 @@ int mbedtls_md5_finish_ret( mbedtls_md5_context *ctx, unsigned char output[16] )
__HAL_HASH_START_DIGEST();
if (HAL_HASH_MD5_Finish(&ctx->hhash_md5, output, 10)) {
return MBEDTLS_ERR_MD5_HW_ACCEL_FAILED; // Finish error
// error code to be returned
}
if (st_md5_save_hw_context(ctx) != 1) {
return MBEDTLS_ERR_MD5_HW_ACCEL_FAILED; // Hash busy timeout
return; // return HASH_BUSY timeout Error here
}
return 0;
}
#endif /* MBEDTLS_MD5_ALT */

View File

@ -27,19 +27,6 @@
#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
@ -92,10 +79,8 @@ void mbedtls_md5_clone( mbedtls_md5_context *dst,
* \brief MD5 context setup
*
* \param ctx context to be initialized
*
* \return 0 if successful
*/
int mbedtls_md5_starts_ret( mbedtls_md5_context *ctx );
void mbedtls_md5_starts( mbedtls_md5_context *ctx );
/**
* \brief MD5 process buffer
@ -103,23 +88,19 @@ int mbedtls_md5_starts_ret( 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
*/
int mbedtls_md5_update_ret( mbedtls_md5_context *ctx, const unsigned char *input, size_t ilen );
void mbedtls_md5_update( 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
*/
int mbedtls_md5_finish_ret( mbedtls_md5_context *ctx, unsigned char output[16] );
void mbedtls_md5_finish( mbedtls_md5_context *ctx, unsigned char output[16] );
/* Internal use */
int mbedtls_md5_process( mbedtls_md5_context *ctx, const unsigned char data[ST_MD5_BLOCK_SIZE] );
void mbedtls_md5_process( mbedtls_md5_context *ctx, const unsigned char data[ST_MD5_BLOCK_SIZE] );
#ifdef __cplusplus
}

View File

@ -88,11 +88,12 @@ void mbedtls_sha1_clone( mbedtls_sha1_context *dst,
*dst = *src;
}
int mbedtls_sha1_starts_ret( mbedtls_sha1_context *ctx )
void mbedtls_sha1_starts( mbedtls_sha1_context *ctx )
{
/* Deinitializes the HASH peripheral */
if (HAL_HASH_DeInit(&ctx->hhash_sha1) == HAL_ERROR) {
return MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED;
// error found to be returned
return;
}
/* HASH Configuration */
@ -100,36 +101,33 @@ int mbedtls_sha1_starts_ret( mbedtls_sha1_context *ctx )
/* clear CR ALGO value */
HASH->CR &= ~HASH_CR_ALGO_Msk;
if (HAL_HASH_Init(&ctx->hhash_sha1) == HAL_ERROR) {
return MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED;
// error found to be returned
return;
}
if (st_sha1_save_hw_context(ctx) != 1) {
return MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED; // Hash busy timeout
return; // return HASH_BUSY timeout Error here
}
return 0;
}
int mbedtls_sha1_process( mbedtls_sha1_context *ctx, const unsigned char data[ST_SHA1_BLOCK_SIZE] )
void mbedtls_sha1_process( mbedtls_sha1_context *ctx, const unsigned char data[ST_SHA1_BLOCK_SIZE] )
{
if (st_sha1_restore_hw_context(ctx) != 1) {
return MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED; // Hash busy timeout
return; // Return HASH_BUSY timout error here
}
if (HAL_HASH_SHA1_Accumulate(&ctx->hhash_sha1, (uint8_t *) data, ST_SHA1_BLOCK_SIZE) != 0) {
return MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED;
return; // Return error code
}
if (st_sha1_save_hw_context(ctx) != 1) {
return MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED; // Hash busy timeout
return; // return HASH_BUSY timeout Error here
}
return 0;
}
int mbedtls_sha1_update_ret( mbedtls_sha1_context *ctx, const unsigned char *input, size_t ilen )
void mbedtls_sha1_update( mbedtls_sha1_context *ctx, const unsigned char *input, size_t ilen )
{
size_t currentlen = ilen;
if (st_sha1_restore_hw_context(ctx) != 1) {
return MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED; // Hash busy timeout
return; // Return HASH_BUSY timout error here
}
// store mechanism to accumulate ST_SHA1_BLOCK_SIZE bytes (512 bits) in the HW
@ -148,14 +146,11 @@ int mbedtls_sha1_update_ret( mbedtls_sha1_context *ctx, const unsigned char *inp
// 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);
if( mbedtls_sha1_process(ctx, ctx->sbuf) != 0 ) {
return MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED;
}
mbedtls_sha1_process(ctx, ctx->sbuf);
// 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 MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED;
return; // Return error code here
}
// sbuf is completely accumulated, now copy up to 63 remaining bytes
ctx->sbuf_len = currentlen % ST_SHA1_BLOCK_SIZE;
@ -164,35 +159,31 @@ int mbedtls_sha1_update_ret( mbedtls_sha1_context *ctx, const unsigned char *inp
}
}
if (st_sha1_save_hw_context(ctx) != 1) {
return MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED; // Hash busy timeout
return; // return HASH_BUSY timeout Error here
}
return 0;
}
int mbedtls_sha1_finish_ret( mbedtls_sha1_context *ctx, unsigned char output[20] )
void mbedtls_sha1_finish( mbedtls_sha1_context *ctx, unsigned char output[20] )
{
if (st_sha1_restore_hw_context(ctx) != 1) {
return MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED; // Hash busy timeout
return; // Return HASH_BUSY timout error here
}
/* 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 MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED;
return; // Return error code here
}
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 MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED;
return; // error code to be returned
}
if (st_sha1_save_hw_context(ctx) != 1) {
return MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED; // Hash busy timeout
return; // return HASH_BUSY timeout Error here
}
return 0;
}
#endif /*MBEDTLS_SHA1_ALT*/

View File

@ -24,18 +24,6 @@
#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>
@ -91,10 +79,8 @@ void mbedtls_sha1_clone( mbedtls_sha1_context *dst,
* \brief SHA-1 context setup
*
* \param ctx context to be initialized
*
* \return 0 if successful
*/
int mbedtls_sha1_starts_ret( mbedtls_sha1_context *ctx );
void mbedtls_sha1_starts( mbedtls_sha1_context *ctx );
/**
* \brief SHA-1 process buffer
@ -102,23 +88,19 @@ int mbedtls_sha1_starts_ret( 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
*/
int mbedtls_sha1_update_ret( mbedtls_sha1_context *ctx, const unsigned char *input, size_t ilen );
void mbedtls_sha1_update( 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
*/
int mbedtls_sha1_finish_ret( mbedtls_sha1_context *ctx, unsigned char output[20] );
void mbedtls_sha1_finish( mbedtls_sha1_context *ctx, unsigned char output[20] );
/* Internal use */
int mbedtls_sha1_process( mbedtls_sha1_context *ctx, const unsigned char data[ST_SHA1_BLOCK_SIZE] );
void mbedtls_sha1_process( mbedtls_sha1_context *ctx, const unsigned char data[ST_SHA1_BLOCK_SIZE] );
#ifdef __cplusplus
}

View File

@ -88,11 +88,12 @@ void mbedtls_sha256_clone( mbedtls_sha256_context *dst,
*dst = *src;
}
int mbedtls_sha256_starts_ret( mbedtls_sha256_context *ctx, int is224 )
void mbedtls_sha256_starts( mbedtls_sha256_context *ctx, int is224 )
{
/* HASH IP initialization */
if (HAL_HASH_DeInit(&ctx->hhash_sha256) == HAL_ERROR) {
return MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED;
// error found to be returned
return;
}
ctx->is224 = is224;
@ -101,42 +102,39 @@ int mbedtls_sha256_starts_ret( 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) {
return MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED;
// error found to be returned
return;
}
if (st_sha256_save_hw_context(ctx) != 1) {
return MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED; // Hash busy timeout
return; // return HASH_BUSY timeout Error here
}
return 0;
}
int mbedtls_sha256_process( mbedtls_sha256_context *ctx, const unsigned char data[ST_SHA256_BLOCK_SIZE] )
void mbedtls_sha256_process( mbedtls_sha256_context *ctx, const unsigned char data[ST_SHA256_BLOCK_SIZE] )
{
if (st_sha256_restore_hw_context(ctx) != 1) {
return MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED; // Hash busy timeout
return; // Return HASH_BUSY timout error here
}
if (ctx->is224 == 0) {
if (HAL_HASHEx_SHA256_Accumulate(&ctx->hhash_sha256, (uint8_t *) data, ST_SHA256_BLOCK_SIZE) != 0) {
return MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED;
return; // Return error code
}
} else {
if (HAL_HASHEx_SHA224_Accumulate(&ctx->hhash_sha256, (uint8_t *) data, ST_SHA256_BLOCK_SIZE) != 0) {
return MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED;
return; // Return error code
}
}
if (st_sha256_save_hw_context(ctx) != 1) {
return MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED; // Hash busy timeout
return; // return HASH_BUSY timeout Error here
}
return 0;
}
int mbedtls_sha256_update_ret( mbedtls_sha256_context *ctx, const unsigned char *input, size_t ilen )
void mbedtls_sha256_update( mbedtls_sha256_context *ctx, const unsigned char *input, size_t ilen )
{
size_t currentlen = ilen;
if (st_sha256_restore_hw_context(ctx) != 1) {
return MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED; // Hash busy timeout
return; // Return HASH_BUSY timout error here
}
// store mechanism to accumulate ST_SHA256_BLOCK_SIZE bytes (512 bits) in the HW
@ -159,19 +157,17 @@ int mbedtls_sha256_update_ret( mbedtls_sha256_context *ctx, const unsigned char
// 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);
if( mbedtls_sha256_process(ctx, ctx->sbuf) != 0) {
return MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED;
}
mbedtls_sha256_process(ctx, ctx->sbuf);
// 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 MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED;
return; // Return error code here
}
} 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 MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED;
return; // Return error code here
}
}
}
@ -182,26 +178,24 @@ int mbedtls_sha256_update_ret( mbedtls_sha256_context *ctx, const unsigned char
}
}
if (st_sha256_save_hw_context(ctx) != 1) {
return MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED; // Hash busy timeout
return; // return HASH_BUSY timeout Error here
}
return 0;
}
int mbedtls_sha256_finish_ret( mbedtls_sha256_context *ctx, unsigned char output[32] )
void mbedtls_sha256_finish( mbedtls_sha256_context *ctx, unsigned char output[32] )
{
if (st_sha256_restore_hw_context(ctx) != 1) {
return MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED; // Hash busy timeout
return; // Return HASH_BUSY timout error here
}
/* 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 MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED;
return; // Return error code here
}
} else {
if (HAL_HASHEx_SHA224_Accumulate(&ctx->hhash_sha256, ctx->sbuf, ctx->sbuf_len) != 0) {
return MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED;
return; // Return error code here
}
}
@ -211,18 +205,16 @@ int mbedtls_sha256_finish_ret( mbedtls_sha256_context *ctx, unsigned char output
if (ctx->is224 == 0) {
if (HAL_HASHEx_SHA256_Finish(&ctx->hhash_sha256, output, 10) != 0) {
return MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED;
return; // Return error code here
}
} else {
if (HAL_HASHEx_SHA224_Finish(&ctx->hhash_sha256, output, 10) != 0) {
return MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED;
return; // Return error code here
}
}
if (st_sha256_save_hw_context(ctx) != 1) {
return MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED; // Hash busy timeout
return; // return HASH_BUSY timeout Error here
}
return 0;
}
#endif /*MBEDTLS_SHA256_ALT*/

View File

@ -27,19 +27,6 @@
#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
@ -93,10 +80,8 @@ 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
*/
int mbedtls_sha256_starts_ret( mbedtls_sha256_context *ctx, int is224 );
void mbedtls_sha256_starts( mbedtls_sha256_context *ctx, int is224 );
/**
* \brief SHA-256 process buffer
@ -104,10 +89,8 @@ int mbedtls_sha256_starts_ret( 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
*/
int mbedtls_sha256_update_ret( mbedtls_sha256_context *ctx, const unsigned char *input,
void mbedtls_sha256_update( mbedtls_sha256_context *ctx, const unsigned char *input,
size_t ilen );
/**
@ -115,13 +98,11 @@ int mbedtls_sha256_update_ret( mbedtls_sha256_context *ctx, const unsigned char
*
* \param ctx SHA-256 context
* \param output SHA-224/256 checksum result
*
* \return 0 if successful
*/
int mbedtls_sha256_finish_ret( mbedtls_sha256_context *ctx, unsigned char output[32] );
void mbedtls_sha256_finish( mbedtls_sha256_context *ctx, unsigned char output[32] );
/* Internal use */
int mbedtls_sha256_process( mbedtls_sha256_context *ctx, const unsigned char data[ST_SHA256_BLOCK_SIZE] );
void 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
*/
int mbedtls_sha256_starts_ret( mbedtls_sha256_context *ctx, int is224 )
void mbedtls_sha256_starts( mbedtls_sha256_context *ctx, int is224 )
{
ctx->total[0] = 0;
ctx->total[1] = 0;
@ -246,8 +246,6 @@ int mbedtls_sha256_starts_ret( 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,
@ -259,15 +257,15 @@ void mbedtls_sha256_process( mbedtls_sha256_context *ctx,
/*
* SHA-256 process buffer
*/
int mbedtls_sha256_update_ret( mbedtls_sha256_context *ctx,
const unsigned char *input,
size_t ilen )
void mbedtls_sha256_update( mbedtls_sha256_context *ctx,
const unsigned char *input,
size_t ilen )
{
size_t fill;
uint32_t left;
if( ilen == 0 ) {
return 0;
return;
}
left = ctx->total[0] & 0x3F;
@ -298,20 +296,17 @@ int mbedtls_sha256_update_ret( mbedtls_sha256_context *ctx,
if( ilen > 0 ) {
memcpy( (void *) (ctx->buffer + left), input, ilen );
}
return 0;
}
/*
* SHA-256 final digest
*/
int mbedtls_sha256_finish_ret( mbedtls_sha256_context *ctx,
unsigned char output[32] )
void mbedtls_sha256_finish( 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 );
@ -323,21 +318,12 @@ int mbedtls_sha256_finish_ret( mbedtls_sha256_context *ctx,
last = ctx->total[0] & 0x3F;
padn = ( last < 56 ) ? ( 56 - last ) : ( 120 - last );
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;
}
mbedtls_sha256_update( ctx, sha_padding, padn );
mbedtls_sha256_update( ctx, msglen, 8 );
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) */
@ -380,16 +366,12 @@ void mbedtls_sha1_clone( mbedtls_sha1_context *dst,
* \brief SHA-1 context setup
*
* \param ctx context to be initialized
*
* \return \c 0 if successful
*
*/
int mbedtls_sha1_starts_ret( mbedtls_sha1_context *ctx )
void mbedtls_sha1_starts( mbedtls_sha1_context *ctx )
{
ctx->total[0] = 0;
ctx->total[1] = 0;
memcpy(ctx->state, init_state_sha1, 32);
return 0;
}
/**
@ -398,19 +380,16 @@ int mbedtls_sha1_starts_ret( 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
*
*/
int mbedtls_sha1_update_ret( mbedtls_sha1_context *ctx,
const unsigned char *input,
size_t ilen )
void mbedtls_sha1_update( mbedtls_sha1_context *ctx,
const unsigned char *input,
size_t ilen )
{
size_t fill;
uint32_t left;
if( ilen == 0 ) {
return 0;
return;
}
left = ctx->total[0] & 0x3F;
@ -441,8 +420,6 @@ int mbedtls_sha1_update_ret( mbedtls_sha1_context *ctx,
if( ilen > 0 ) {
memcpy( (void *) (ctx->buffer + left), input, ilen );
}
return 0;
}
/**
@ -450,17 +427,13 @@ int mbedtls_sha1_update_ret( mbedtls_sha1_context *ctx,
*
* \param ctx SHA-1 context
* \param output SHA-1 checksum result
*
* \return \c 0 if successful
*
*/
int mbedtls_sha1_finish_ret( mbedtls_sha1_context *ctx,
unsigned char output[20] )
void mbedtls_sha1_finish( 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 );
@ -472,21 +445,12 @@ int mbedtls_sha1_finish_ret( mbedtls_sha1_context *ctx,
last = ctx->total[0] & 0x3F;
padn = ( last < 56 ) ? ( 56 - last ) : ( 120 - last );
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;
}
mbedtls_sha1_update( ctx, sha_padding, padn );
mbedtls_sha1_update( ctx, msglen, 8 );
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,11 +78,8 @@ void mbedtls_sha1_clone( mbedtls_sha1_context *dst,
* \brief SHA-1 context setup
*
* \param ctx context to be initialized
*
* \return \c 0 if successful
*
*/
int mbedtls_sha1_starts_ret( mbedtls_sha1_context *ctx );
void mbedtls_sha1_starts( mbedtls_sha1_context *ctx );
/**
* \brief SHA-1 process buffer
@ -90,22 +87,16 @@ int mbedtls_sha1_starts_ret( 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
*
*/
int mbedtls_sha1_update_ret( mbedtls_sha1_context *ctx, const unsigned char *input, size_t ilen );
void mbedtls_sha1_update( 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
*
*/
int mbedtls_sha1_finish_ret( mbedtls_sha1_context *ctx, unsigned char output[20] );
void mbedtls_sha1_finish( 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,11 +84,8 @@ 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
*
*/
int mbedtls_sha256_starts_ret( mbedtls_sha256_context *ctx, int is224 );
void mbedtls_sha256_starts( mbedtls_sha256_context *ctx, int is224 );
/**
* \brief SHA-256 process buffer
@ -96,22 +93,17 @@ int mbedtls_sha256_starts_ret( 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
*
*/
int mbedtls_sha256_update_ret( mbedtls_sha256_context *ctx, const unsigned char *input, size_t ilen );
void mbedtls_sha256_update( 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
*
*/
int mbedtls_sha256_finish_ret( mbedtls_sha256_context *ctx, unsigned char output[32] );
void mbedtls_sha256_finish( 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

@ -1,356 +0,0 @@
#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) */