Introduce polarssl_zeroize() instead of memset() for zeroization
diff --git a/library/cipher_wrap.c b/library/cipher_wrap.c
index 9437212..a927e29 100644
--- a/library/cipher_wrap.c
+++ b/library/cipher_wrap.c
@@ -51,6 +51,11 @@
#include <stdlib.h>
+/* Implementation that should never be optimized out by the compiler */
+static void polarssl_zeroize( void *v, size_t n ) {
+ volatile unsigned char *p = v; while( n-- ) *p++ = 0;
+}
+
#if defined(POLARSSL_AES_C)
int aes_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
@@ -114,6 +119,7 @@
static void aes_ctx_free( void *ctx )
{
+ polarssl_zeroize( ctx, sizeof( aes_context ) );
free( ctx );
}
@@ -287,6 +293,7 @@
static void camellia_ctx_free( void *ctx )
{
+ polarssl_zeroize( ctx, sizeof( camellia_context ) );
free( ctx );
}
@@ -495,6 +502,13 @@
static void des_ctx_free( void *ctx )
{
+ polarssl_zeroize( ctx, sizeof( des_context ) );
+ free( ctx );
+}
+
+static void des3_ctx_free( void *ctx )
+{
+ polarssl_zeroize( ctx, sizeof( des3_context ) );
free( ctx );
}
@@ -527,7 +541,7 @@
des3_set2key_enc_wrap,
des3_set2key_dec_wrap,
des3_ctx_alloc,
- des_ctx_free
+ des3_ctx_free
};
const cipher_info_t des_ede_cbc_info = {
@@ -548,7 +562,7 @@
des3_set3key_enc_wrap,
des3_set3key_dec_wrap,
des3_ctx_alloc,
- des_ctx_free
+ des3_ctx_free
};
const cipher_info_t des_ede3_cbc_info = {
@@ -625,6 +639,7 @@
static void blowfish_ctx_free( void *ctx )
{
+ polarssl_zeroize( ctx, sizeof( blowfish_context ) );
free( ctx );
}