CTR_DRBG: clean stack buffers
Wipe stack buffers that may contain sensitive data (data that
contributes to the DRBG state.
diff --git a/library/ctr_drbg.c b/library/ctr_drbg.c
index e8fdd9b..c023c69 100644
--- a/library/ctr_drbg.c
+++ b/library/ctr_drbg.c
@@ -264,6 +264,7 @@
mbedtls_aes_setkey_enc( &ctx->aes_ctx, tmp, MBEDTLS_CTR_DRBG_KEYBITS );
memcpy( ctx->counter, tmp + MBEDTLS_CTR_DRBG_KEYSIZE, MBEDTLS_CTR_DRBG_BLOCKSIZE );
+ mbedtls_zeroize( tmp, sizeof( tmp ) );
return( 0 );
}
@@ -281,6 +282,7 @@
block_cipher_df( add_input, additional, add_len );
ctr_drbg_update_internal( ctx, add_input );
+ mbedtls_zeroize( add_input, sizeof( add_input ) );
}
}
@@ -327,6 +329,7 @@
ctr_drbg_update_internal( ctx, seed );
ctx->reseed_counter = 1;
+ mbedtls_zeroize( seed, sizeof( seed ) );
return( 0 );
}
@@ -393,6 +396,8 @@
ctx->reseed_counter++;
+ mbedtls_zeroize( add_input, sizeof( add_input ) );
+ mbedtls_zeroize( tmp, sizeof( tmp ) );
return( 0 );
}