mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2025-03-04 18:59:44 +00:00
Zeroize internal buffers and variables in PKCS and SHA
Zeroising of local buffers and variables which are used for calculations in mbedtls_pkcs5_pbkdf2_hmac() and mbedtls_internal_sha*_process() functions to erase sensitive data from memory. Checked all function for possible missing zeroisation in PKCS and SHA. Signed-off-by: gabor-mezei-arm <gabor.mezei@arm.com>
This commit is contained in:
parent
d4c464ff22
commit
461c5a89df
|
@ -0,0 +1,5 @@
|
||||||
|
Security
|
||||||
|
* Zeroising of local buffers and variables which are used for calculations
|
||||||
|
in mbedtls_pkcs5_pbkdf2_hmac() and mbedtls_internal_sha*_process()
|
||||||
|
functions to erase sensitive data from memory. Reported by
|
||||||
|
Johan Malmgren and Johan Uppman Bruce from Sectra.
|
|
@ -79,6 +79,11 @@
|
||||||
#define mbedtls_printf printf
|
#define mbedtls_printf printf
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Implementation that should never be optimized out by the compiler */
|
||||||
|
static void mbedtls_zeroize( void *v, size_t n ) {
|
||||||
|
volatile unsigned char *p = (unsigned char*)v; while( n-- ) *p++ = 0;
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(MBEDTLS_ASN1_PARSE_C)
|
#if defined(MBEDTLS_ASN1_PARSE_C)
|
||||||
static int pkcs5_parse_pbkdf2_params( const mbedtls_asn1_buf *params,
|
static int pkcs5_parse_pbkdf2_params( const mbedtls_asn1_buf *params,
|
||||||
mbedtls_asn1_buf *salt, int *iterations,
|
mbedtls_asn1_buf *salt, int *iterations,
|
||||||
|
@ -312,6 +317,10 @@ int mbedtls_pkcs5_pbkdf2_hmac( mbedtls_md_context_t *ctx, const unsigned char *p
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Zeroise buffers to clear sensitive data from memory. */
|
||||||
|
mbedtls_zeroize( work, MBEDTLS_MD_MAX_SIZE );
|
||||||
|
mbedtls_zeroize( md1, MBEDTLS_MD_MAX_SIZE );
|
||||||
|
|
||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -300,6 +300,15 @@ int mbedtls_internal_sha1_process( mbedtls_sha1_context *ctx,
|
||||||
ctx->state[3] += D;
|
ctx->state[3] += D;
|
||||||
ctx->state[4] += E;
|
ctx->state[4] += E;
|
||||||
|
|
||||||
|
/* Zeroise buffers and variables to clear sensitive data from memory. */
|
||||||
|
mbedtls_zeroize( &A, sizeof( A ) );
|
||||||
|
mbedtls_zeroize( &B, sizeof( B ) );
|
||||||
|
mbedtls_zeroize( &C, sizeof( C ) );
|
||||||
|
mbedtls_zeroize( &D, sizeof( D ) );
|
||||||
|
mbedtls_zeroize( &E, sizeof( E ) );
|
||||||
|
mbedtls_zeroize( &W, sizeof( W ) );
|
||||||
|
mbedtls_zeroize( &temp, sizeof( temp ) );
|
||||||
|
|
||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -269,6 +269,12 @@ int mbedtls_internal_sha256_process( mbedtls_sha256_context *ctx,
|
||||||
for( i = 0; i < 8; i++ )
|
for( i = 0; i < 8; i++ )
|
||||||
ctx->state[i] += A[i];
|
ctx->state[i] += A[i];
|
||||||
|
|
||||||
|
/* Zeroise buffers and variables to clear sensitive data from memory. */
|
||||||
|
mbedtls_zeroize( &A, sizeof( A ) );
|
||||||
|
mbedtls_zeroize( &W, sizeof( W ) );
|
||||||
|
mbedtls_zeroize( &temp1, sizeof( temp1 ) );
|
||||||
|
mbedtls_zeroize( &temp2, sizeof( temp2 ) );
|
||||||
|
|
||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -300,6 +300,19 @@ int mbedtls_internal_sha512_process( mbedtls_sha512_context *ctx,
|
||||||
ctx->state[6] += G;
|
ctx->state[6] += G;
|
||||||
ctx->state[7] += H;
|
ctx->state[7] += H;
|
||||||
|
|
||||||
|
/* Zeroise buffers and variables to clear sensitive data from memory. */
|
||||||
|
mbedtls_zeroize( &A, sizeof( A ) );
|
||||||
|
mbedtls_zeroize( &B, sizeof( B ) );
|
||||||
|
mbedtls_zeroize( &C, sizeof( C ) );
|
||||||
|
mbedtls_zeroize( &D, sizeof( D ) );
|
||||||
|
mbedtls_zeroize( &E, sizeof( E ) );
|
||||||
|
mbedtls_zeroize( &F, sizeof( F ) );
|
||||||
|
mbedtls_zeroize( &G, sizeof( G ) );
|
||||||
|
mbedtls_zeroize( &H, sizeof( H ) );
|
||||||
|
mbedtls_zeroize( &W, sizeof( W ) );
|
||||||
|
mbedtls_zeroize( &temp1, sizeof( temp1 ) );
|
||||||
|
mbedtls_zeroize( &temp2, sizeof( temp2 ) );
|
||||||
|
|
||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue