Implement SHA512_NO_SHA384 in sha512 module
Saves 140 bytes on sha512.o, measured with: arm-none-eabi-gcc -Wall -Wextra -Iinclude -Os -mcpu=cortex-m0plus -mthumb -c library/sha512.c && arm-none-eabi-size sha512.o arm-none-eabi-gcc (GNU Tools for Arm Embedded Processors 7-2018-q2-update) 7.3.1 20180622 (release) [ARM/embedded-7-branch revision 261907] Todo: - fix selftest - fix dependencies in test suites - implement in MD layer
This commit is contained in:
parent
ad6cb11461
commit
3df4e60561
2 changed files with 10 additions and 0 deletions
|
@ -59,8 +59,10 @@ typedef struct mbedtls_sha512_context
|
|||
uint64_t total[2]; /*!< The number of Bytes processed. */
|
||||
uint64_t state[8]; /*!< The intermediate digest state. */
|
||||
unsigned char buffer[128]; /*!< The data block being processed. */
|
||||
#if !defined(MBEDTLS_SHA512_NO_SHA384)
|
||||
int is384; /*!< Determines which function to use:
|
||||
0: Use SHA-512, or 1: Use SHA-384. */
|
||||
#endif
|
||||
}
|
||||
mbedtls_sha512_context;
|
||||
|
||||
|
|
|
@ -151,6 +151,9 @@ int mbedtls_sha512_starts_ret( mbedtls_sha512_context *ctx, int is384 )
|
|||
}
|
||||
else
|
||||
{
|
||||
#if defined(MBEDTLS_SHA512_NO_SHA384)
|
||||
return( MBEDTLS_ERR_SHA512_BAD_INPUT_DATA );
|
||||
#else
|
||||
/* SHA-384 */
|
||||
ctx->state[0] = UL64(0xCBBB9D5DC1059ED8);
|
||||
ctx->state[1] = UL64(0x629A292A367CD507);
|
||||
|
@ -160,9 +163,12 @@ int mbedtls_sha512_starts_ret( mbedtls_sha512_context *ctx, int is384 )
|
|||
ctx->state[5] = UL64(0x8EB44A8768581511);
|
||||
ctx->state[6] = UL64(0xDB0C2E0D64F98FA7);
|
||||
ctx->state[7] = UL64(0x47B5481DBEFA4FA4);
|
||||
#endif /* MBEDTLS_SHA512_NO_SHA384 */
|
||||
}
|
||||
|
||||
#if !defined(MBEDTLS_SHA512_NO_SHA384)
|
||||
ctx->is384 = is384;
|
||||
#endif
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
@ -437,7 +443,9 @@ int mbedtls_sha512_finish_ret( mbedtls_sha512_context *ctx,
|
|||
sha512_put_uint64_be( ctx->state[4], output, 32 );
|
||||
sha512_put_uint64_be( ctx->state[5], output, 40 );
|
||||
|
||||
#if !defined(MBEDTLS_SHA512_NO_SHA384)
|
||||
if( ctx->is384 == 0 )
|
||||
#endif
|
||||
{
|
||||
sha512_put_uint64_be( ctx->state[6], output, 48 );
|
||||
sha512_put_uint64_be( ctx->state[7], output, 56 );
|
||||
|
|
Loading…
Reference in a new issue