mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-04-23 11:42:31 +00:00
- Fixed a potential loop bug
This commit is contained in:
parent
02faf45d8b
commit
23fd5ea667
@ -253,6 +253,7 @@ int ctr_drbg_random_with_add( void *p_rng,
|
|||||||
unsigned char *p = output;
|
unsigned char *p = output;
|
||||||
unsigned char tmp[CTR_DRBG_BLOCKSIZE];
|
unsigned char tmp[CTR_DRBG_BLOCKSIZE];
|
||||||
int cb, i;
|
int cb, i;
|
||||||
|
size_t use_len;
|
||||||
|
|
||||||
if( output_len > CTR_DRBG_MAX_REQUEST )
|
if( output_len > CTR_DRBG_MAX_REQUEST )
|
||||||
return( POLARSSL_ERR_CTR_DRBG_REQUEST_TOO_BIG );
|
return( POLARSSL_ERR_CTR_DRBG_REQUEST_TOO_BIG );
|
||||||
@ -293,12 +294,13 @@ int ctr_drbg_random_with_add( void *p_rng,
|
|||||||
*/
|
*/
|
||||||
aes_crypt_ecb( &ctx->aes_ctx, AES_ENCRYPT, ctx->counter, tmp );
|
aes_crypt_ecb( &ctx->aes_ctx, AES_ENCRYPT, ctx->counter, tmp );
|
||||||
|
|
||||||
|
use_len = (output_len > CTR_DRBG_BLOCKSIZE ) ? CTR_DRBG_BLOCKSIZE : output_len;
|
||||||
/*
|
/*
|
||||||
* Copy random block to destination
|
* Copy random block to destination
|
||||||
*/
|
*/
|
||||||
memcpy( p, tmp, (output_len > CTR_DRBG_BLOCKSIZE ) ? CTR_DRBG_BLOCKSIZE : output_len );
|
memcpy( p, tmp, use_len );
|
||||||
p += CTR_DRBG_BLOCKSIZE;
|
p += use_len;
|
||||||
output_len -= CTR_DRBG_BLOCKSIZE;
|
output_len -= use_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctr_drbg_update( ctx, add_input );
|
ctr_drbg_update( ctx, add_input );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user