Add _init() and _free() for hash modules
diff --git a/library/ssl_tls.c b/library/ssl_tls.c
index 28ca14aa..963f02b 100644
--- a/library/ssl_tls.c
+++ b/library/ssl_tls.c
@@ -156,6 +156,9 @@
unsigned char sha1sum[20];
((void)label);
+ md5_init( &md5 );
+ sha1_init( &sha1 );
+
/*
* SSLv3:
* block =
@@ -180,8 +183,8 @@
md5_finish( &md5, dstbuf + i * 16 );
}
- polarssl_zeroize( &md5, sizeof( md5 ) );
- polarssl_zeroize( &sha1, sizeof( sha1 ) );
+ md5_free( &md5 );
+ sha1_free( &sha1 );
polarssl_zeroize( padding, sizeof( padding ) );
polarssl_zeroize( sha1sum, sizeof( sha1sum ) );
@@ -805,6 +808,9 @@
SSL_DEBUG_BUF( 3, "calculated verify result", hash, 36 );
SSL_DEBUG_MSG( 2, ( "<= calc verify" ) );
+ md5_free( &md5 );
+ sha1_free( &sha1 );
+
return;
}
#endif /* POLARSSL_SSL_PROTO_SSL3 */
@@ -826,6 +832,9 @@
SSL_DEBUG_BUF( 3, "calculated verify result", hash, 36 );
SSL_DEBUG_MSG( 2, ( "<= calc verify" ) );
+ md5_free( &md5 );
+ sha1_free( &sha1 );
+
return;
}
#endif /* POLARSSL_SSL_PROTO_TLS1 || POLARSSL_SSL_PROTO_TLS1_1 */
@@ -844,6 +853,8 @@
SSL_DEBUG_BUF( 3, "calculated verify result", hash, 32 );
SSL_DEBUG_MSG( 2, ( "<= calc verify" ) );
+ sha256_free( &sha256 );
+
return;
}
#endif /* POLARSSL_SHA256_C */
@@ -861,6 +872,8 @@
SSL_DEBUG_BUF( 3, "calculated verify result", hash, 48 );
SSL_DEBUG_MSG( 2, ( "<= calc verify" ) );
+ sha512_free( &sha512 );
+
return;
}
#endif /* POLARSSL_SHA512_C */
@@ -2878,8 +2891,8 @@
SSL_DEBUG_BUF( 3, "calc finished result", buf, 36 );
- polarssl_zeroize( &md5, sizeof( md5_context ) );
- polarssl_zeroize( &sha1, sizeof( sha1_context ) );
+ md5_free( &md5 );
+ sha1_free( &sha1 );
polarssl_zeroize( padbuf, sizeof( padbuf ) );
polarssl_zeroize( md5sum, sizeof( md5sum ) );
@@ -2936,8 +2949,8 @@
SSL_DEBUG_BUF( 3, "calc finished result", buf, len );
- polarssl_zeroize( &md5, sizeof( md5_context ) );
- polarssl_zeroize( &sha1, sizeof( sha1_context ) );
+ md5_free( &md5 );
+ sha1_free( &sha1 );
polarssl_zeroize( padbuf, sizeof( padbuf ) );
@@ -2985,7 +2998,7 @@
SSL_DEBUG_BUF( 3, "calc finished result", buf, len );
- polarssl_zeroize( &sha256, sizeof( sha256_context ) );
+ sha256_free( &sha256 );
polarssl_zeroize( padbuf, sizeof( padbuf ) );
@@ -3032,7 +3045,7 @@
SSL_DEBUG_BUF( 3, "calc finished result", buf, len );
- polarssl_zeroize( &sha512, sizeof( sha512_context ) );
+ sha512_free( &sha512 );
polarssl_zeroize( padbuf, sizeof( padbuf ) );
@@ -3302,14 +3315,18 @@
#if defined(POLARSSL_SSL_PROTO_SSL3) || defined(POLARSSL_SSL_PROTO_TLS1) || \
defined(POLARSSL_SSL_PROTO_TLS1_1)
- md5_starts( &ssl->handshake->fin_md5 );
+ md5_init( &ssl->handshake->fin_md5 );
+ sha1_init( &ssl->handshake->fin_sha1 );
+ md5_starts( &ssl->handshake->fin_md5 );
sha1_starts( &ssl->handshake->fin_sha1 );
#endif
#if defined(POLARSSL_SSL_PROTO_TLS1_2)
#if defined(POLARSSL_SHA256_C)
+ sha256_init( &ssl->handshake->fin_sha256 );
sha256_starts( &ssl->handshake->fin_sha256, 0 );
#endif
#if defined(POLARSSL_SHA512_C)
+ sha512_init( &ssl->handshake->fin_sha512 );
sha512_starts( &ssl->handshake->fin_sha512, 1 );
#endif
#endif /* POLARSSL_SSL_PROTO_TLS1_2 */