mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-02-25 09:41:00 +00:00
Merge pull request #4506 from gilles-peskine-arm/array-parameters-to-pointers-sha512
Change sha256 and sha512 output type from an array to a pointer
This commit is contained in:
commit
0e3ec27598
6
ChangeLog.d/sha512-output-type.txt
Normal file
6
ChangeLog.d/sha512-output-type.txt
Normal file
@ -0,0 +1,6 @@
|
||||
API changes
|
||||
* The output parameter of mbedtls_sha512_finish_ret, mbedtls_sha512_ret,
|
||||
mbedtls_sha256_finish_ret and mbedtls_sha256_ret now has a pointer type
|
||||
rather than array type. This removes spurious warnings in some compilers
|
||||
when outputting a SHA-384 or SHA-224 hash into a buffer of exactly
|
||||
the hash size.
|
8
docs/3.0-migration-guide.d/sha512-output-type.md
Normal file
8
docs/3.0-migration-guide.d/sha512-output-type.md
Normal file
@ -0,0 +1,8 @@
|
||||
SHA-512 and SHA-256 output type change
|
||||
--------------------------
|
||||
|
||||
The output parameter of `mbedtls_sha256_finish_ret()`, `mbedtls_sha256_ret()`, `mbedtls_sha512_finish_ret()`, `mbedtls_sha512_ret()` now has a pointer type rather than array type. This makes no difference in terms of C semantics, but removes spurious warnings in some compilers when outputting a SHA-384 hash into a 48-byte buffer or a SHA-224 hash into a 28-byte buffer.
|
||||
|
||||
This makes no difference to a vast majority of applications. If your code takes a pointer to one of these functions, you may need to change the type of the pointer.
|
||||
|
||||
Alternative implementations of the SHA256 and SHA512 modules must adjust their functions' prototype accordingly.
|
@ -127,13 +127,14 @@ int mbedtls_sha256_update_ret( mbedtls_sha256_context *ctx,
|
||||
* \param ctx The SHA-256 context. This must be initialized
|
||||
* and have a hash operation started.
|
||||
* \param output The SHA-224 or SHA-256 checksum result.
|
||||
* This must be a writable buffer of length \c 32 Bytes.
|
||||
* This must be a writable buffer of length \c 32 bytes
|
||||
* for SHA-256, \c 28 bytes for SHA-224.
|
||||
*
|
||||
* \return \c 0 on success.
|
||||
* \return A negative error code on failure.
|
||||
*/
|
||||
int mbedtls_sha256_finish_ret( mbedtls_sha256_context *ctx,
|
||||
unsigned char output[32] );
|
||||
unsigned char *output );
|
||||
|
||||
/**
|
||||
* \brief This function processes a single data block within
|
||||
@ -163,14 +164,15 @@ int mbedtls_internal_sha256_process( mbedtls_sha256_context *ctx,
|
||||
* \param input The buffer holding the data. This must be a readable
|
||||
* buffer of length \p ilen Bytes.
|
||||
* \param ilen The length of the input data in Bytes.
|
||||
* \param output The SHA-224 or SHA-256 checksum result. This must
|
||||
* be a writable buffer of length \c 32 Bytes.
|
||||
* \param output The SHA-224 or SHA-256 checksum result.
|
||||
* This must be a writable buffer of length \c 32 bytes
|
||||
* for SHA-256, \c 28 bytes for SHA-224.
|
||||
* \param is224 Determines which function to use. This must be
|
||||
* either \c 0 for SHA-256, or \c 1 for SHA-224.
|
||||
*/
|
||||
int mbedtls_sha256_ret( const unsigned char *input,
|
||||
size_t ilen,
|
||||
unsigned char output[32],
|
||||
unsigned char *output,
|
||||
int is224 );
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
|
@ -134,13 +134,14 @@ int mbedtls_sha512_update_ret( mbedtls_sha512_context *ctx,
|
||||
* \param ctx The SHA-512 context. This must be initialized
|
||||
* and have a hash operation started.
|
||||
* \param output The SHA-384 or SHA-512 checksum result.
|
||||
* This must be a writable buffer of length \c 64 Bytes.
|
||||
* This must be a writable buffer of length \c 64 bytes
|
||||
* for SHA-512, \c 48 bytes for SHA-384.
|
||||
*
|
||||
* \return \c 0 on success.
|
||||
* \return A negative error code on failure.
|
||||
*/
|
||||
int mbedtls_sha512_finish_ret( mbedtls_sha512_context *ctx,
|
||||
unsigned char output[64] );
|
||||
unsigned char *output );
|
||||
|
||||
/**
|
||||
* \brief This function processes a single data block within
|
||||
@ -171,7 +172,8 @@ int mbedtls_internal_sha512_process( mbedtls_sha512_context *ctx,
|
||||
* a readable buffer of length \p ilen Bytes.
|
||||
* \param ilen The length of the input data in Bytes.
|
||||
* \param output The SHA-384 or SHA-512 checksum result.
|
||||
* This must be a writable buffer of length \c 64 Bytes.
|
||||
* This must be a writable buffer of length \c 64 bytes
|
||||
* for SHA-512, \c 48 bytes for SHA-384.
|
||||
* \param is384 Determines which function to use. This must be either
|
||||
* \c 0 for SHA-512, or \c 1 for SHA-384.
|
||||
*
|
||||
@ -184,7 +186,7 @@ int mbedtls_internal_sha512_process( mbedtls_sha512_context *ctx,
|
||||
*/
|
||||
int mbedtls_sha512_ret( const unsigned char *input,
|
||||
size_t ilen,
|
||||
unsigned char output[64],
|
||||
unsigned char *output,
|
||||
int is384 );
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
|
@ -332,7 +332,7 @@ int mbedtls_sha256_update_ret( mbedtls_sha256_context *ctx,
|
||||
* SHA-256 final digest
|
||||
*/
|
||||
int mbedtls_sha256_finish_ret( mbedtls_sha256_context *ctx,
|
||||
unsigned char output[32] )
|
||||
unsigned char *output )
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
uint32_t used;
|
||||
@ -401,7 +401,7 @@ int mbedtls_sha256_finish_ret( mbedtls_sha256_context *ctx,
|
||||
*/
|
||||
int mbedtls_sha256_ret( const unsigned char *input,
|
||||
size_t ilen,
|
||||
unsigned char output[32],
|
||||
unsigned char *output,
|
||||
int is224 )
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
|
@ -380,7 +380,7 @@ int mbedtls_sha512_update_ret( mbedtls_sha512_context *ctx,
|
||||
* SHA-512 final digest
|
||||
*/
|
||||
int mbedtls_sha512_finish_ret( mbedtls_sha512_context *ctx,
|
||||
unsigned char output[64] )
|
||||
unsigned char *output )
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
unsigned used;
|
||||
@ -453,7 +453,7 @@ int mbedtls_sha512_finish_ret( mbedtls_sha512_context *ctx,
|
||||
*/
|
||||
int mbedtls_sha512_ret( const unsigned char *input,
|
||||
size_t ilen,
|
||||
unsigned char output[64],
|
||||
unsigned char *output,
|
||||
int is384 )
|
||||
{
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
|
@ -2898,8 +2898,6 @@ static void ssl_calc_finished_tls_sha256(
|
||||
|
||||
#if defined(MBEDTLS_SHA512_C)
|
||||
|
||||
typedef int (*finish_sha384_t)(mbedtls_sha512_context*, unsigned char*);
|
||||
|
||||
static void ssl_calc_finished_tls_sha384(
|
||||
mbedtls_ssl_context *ssl, unsigned char *buf, int from )
|
||||
{
|
||||
@ -2958,13 +2956,7 @@ static void ssl_calc_finished_tls_sha384(
|
||||
MBEDTLS_SSL_DEBUG_BUF( 4, "finished sha512 state", (unsigned char *)
|
||||
sha512.state, sizeof( sha512.state ) );
|
||||
#endif
|
||||
/*
|
||||
* For SHA-384, we can save 16 bytes by keeping padbuf 48 bytes long.
|
||||
* However, to avoid stringop-overflow warning in gcc, we have to cast
|
||||
* mbedtls_sha512_finish_ret().
|
||||
*/
|
||||
finish_sha384_t finish = (finish_sha384_t)mbedtls_sha512_finish_ret;
|
||||
finish( &sha512, padbuf );
|
||||
mbedtls_sha512_finish_ret( &sha512, padbuf );
|
||||
|
||||
mbedtls_sha512_free( &sha512 );
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user