mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-02-09 12:40:57 +00:00
Use const size buffer for local output in CCM decryption.
Signed-off-by: Mateusz Starzyk <mateusz.starzyk@mobica.com>
This commit is contained in:
parent
c562788068
commit
f337850738
@ -61,8 +61,6 @@
|
|||||||
#define MBEDTLS_ERR_CCM_BAD_INPUT -0x000D
|
#define MBEDTLS_ERR_CCM_BAD_INPUT -0x000D
|
||||||
/** Authenticated decryption failed. */
|
/** Authenticated decryption failed. */
|
||||||
#define MBEDTLS_ERR_CCM_AUTH_FAILED -0x000F
|
#define MBEDTLS_ERR_CCM_AUTH_FAILED -0x000F
|
||||||
/** Memory allocation failed */
|
|
||||||
#define MBEDTLS_ERR_CCM_ALLOC_FAILED -0x0011
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -43,9 +43,6 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#define mbedtls_printf printf
|
#define mbedtls_printf printf
|
||||||
#endif /* MBEDTLS_SELF_TEST && MBEDTLS_AES_C */
|
#endif /* MBEDTLS_SELF_TEST && MBEDTLS_AES_C */
|
||||||
#include <stdlib.h>
|
|
||||||
#define mbedtls_calloc calloc
|
|
||||||
#define mbedtls_free free
|
|
||||||
#endif /* MBEDTLS_PLATFORM_C */
|
#endif /* MBEDTLS_PLATFORM_C */
|
||||||
|
|
||||||
#if !defined(MBEDTLS_CCM_ALT)
|
#if !defined(MBEDTLS_CCM_ALT)
|
||||||
@ -337,8 +334,7 @@ int mbedtls_ccm_update( mbedtls_ccm_context *ctx,
|
|||||||
unsigned char i;
|
unsigned char i;
|
||||||
size_t use_len, offset, olen;
|
size_t use_len, offset, olen;
|
||||||
|
|
||||||
const size_t local_output_len = input_len;
|
unsigned char local_output[16];
|
||||||
unsigned char* local_output = NULL;
|
|
||||||
|
|
||||||
if( ctx->state & CCM_STATE__ERROR )
|
if( ctx->state & CCM_STATE__ERROR )
|
||||||
{
|
{
|
||||||
@ -350,19 +346,6 @@ int mbedtls_ccm_update( mbedtls_ccm_context *ctx,
|
|||||||
return MBEDTLS_ERR_CCM_BAD_INPUT;
|
return MBEDTLS_ERR_CCM_BAD_INPUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Local output is used for decryption only. */
|
|
||||||
if( local_output_len > 0 && \
|
|
||||||
( ctx->mode == MBEDTLS_CCM_DECRYPT || \
|
|
||||||
ctx->mode == MBEDTLS_CCM_STAR_DECRYPT ) )
|
|
||||||
{
|
|
||||||
local_output = mbedtls_calloc( local_output_len, sizeof( *local_output) );
|
|
||||||
if( local_output == NULL )
|
|
||||||
{
|
|
||||||
ctx->state |= CCM_STATE__ERROR;
|
|
||||||
return MBEDTLS_ERR_CCM_ALLOC_FAILED;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if( output_size < input_len )
|
if( output_size < input_len )
|
||||||
return( MBEDTLS_ERR_CCM_BAD_INPUT );
|
return( MBEDTLS_ERR_CCM_BAD_INPUT );
|
||||||
*output_len = input_len;
|
*output_len = input_len;
|
||||||
@ -414,7 +397,7 @@ int mbedtls_ccm_update( mbedtls_ccm_context *ctx,
|
|||||||
ctx->y[i + offset] ^= local_output[i];
|
ctx->y[i + offset] ^= local_output[i];
|
||||||
|
|
||||||
memcpy( output, local_output, use_len );
|
memcpy( output, local_output, use_len );
|
||||||
mbedtls_platform_zeroize( local_output, local_output_len );
|
mbedtls_platform_zeroize( local_output, 16 );
|
||||||
|
|
||||||
if( use_len + offset == 16 || ctx->processed == ctx->plaintext_len )
|
if( use_len + offset == 16 || ctx->processed == ctx->plaintext_len )
|
||||||
{
|
{
|
||||||
@ -439,12 +422,7 @@ int mbedtls_ccm_update( mbedtls_ccm_context *ctx,
|
|||||||
}
|
}
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
if( ctx->mode == MBEDTLS_CCM_DECRYPT || \
|
mbedtls_platform_zeroize( local_output, 16 );
|
||||||
ctx->mode == MBEDTLS_CCM_STAR_DECRYPT )
|
|
||||||
{
|
|
||||||
mbedtls_platform_zeroize( local_output, local_output_len );
|
|
||||||
mbedtls_free( local_output );
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user