From 14e8be4d338acd25dc81236997c2c22a232cf38f Mon Sep 17 00:00:00 2001
From: Paul Bakker
Date: Thu, 26 Jun 2014 12:25:06 +0200
Subject: [PATCH] Adapted programs / test suites to _init() and _free()
---
programs/aes/aescrypt2.c | 3 ++-
tests/suites/test_suite_hmac_shax.function | 15 +++++++++++++++
tests/suites/test_suite_mdx.function | 12 ++++++++++++
3 files changed, 29 insertions(+), 1 deletion(-)
diff --git a/programs/aes/aescrypt2.c b/programs/aes/aescrypt2.c
index db7ed325e..40b7fec38 100644
--- a/programs/aes/aescrypt2.c
+++ b/programs/aes/aescrypt2.c
@@ -94,6 +94,7 @@ int main( int argc, char *argv[] )
#endif
aes_init( &aes_ctx );
+ sha256_init( &sha_ctx );
/*
* Parse the command-line arguments.
@@ -429,7 +430,7 @@ exit:
memset( digest, 0, sizeof( digest ) );
aes_free( &aes_ctx );
- memset( &sha_ctx, 0, sizeof( sha256_context ) );
+ sha256_free( &sha_ctx );
return( ret );
}
diff --git a/tests/suites/test_suite_hmac_shax.function b/tests/suites/test_suite_hmac_shax.function
index d65437b0e..10b376f5b 100644
--- a/tests/suites/test_suite_hmac_shax.function
+++ b/tests/suites/test_suite_hmac_shax.function
@@ -17,6 +17,7 @@ void sha1_hmac( int trunc_size, char *hex_key_string, char *hex_src_string,
memset(src_str, 0x00, sizeof src_str);
memset(key_str, 0x00, sizeof key_str);
+ sha1_init( &ctx );
key_len = unhexify( key_str, hex_key_string );
src_len = unhexify( src_str, hex_src_string );
@@ -56,6 +57,8 @@ void sha1_hmac( int trunc_size, char *hex_key_string, char *hex_src_string,
hexify( hash_str, output, sizeof output );
TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
+
+ sha1_free( &ctx );
}
/* END_CASE */
@@ -72,6 +75,7 @@ void sha224_hmac( int trunc_size, char *hex_key_string, char *hex_src_string,
memset(src_str, 0x00, sizeof src_str);
memset(key_str, 0x00, sizeof key_str);
+ sha256_init( &ctx );
key_len = unhexify( key_str, hex_key_string );
src_len = unhexify( src_str, hex_src_string );
@@ -111,6 +115,8 @@ void sha224_hmac( int trunc_size, char *hex_key_string, char *hex_src_string,
hexify( hash_str, output, sizeof output );
TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
+
+ sha256_free( &ctx );
}
/* END_CASE */
@@ -127,6 +133,7 @@ void sha256_hmac( int trunc_size, char *hex_key_string, char *hex_src_string,
memset(src_str, 0x00, sizeof src_str);
memset(key_str, 0x00, sizeof key_str);
+ sha256_init( &ctx );
key_len = unhexify( key_str, hex_key_string );
src_len = unhexify( src_str, hex_src_string );
@@ -166,6 +173,8 @@ void sha256_hmac( int trunc_size, char *hex_key_string, char *hex_src_string,
hexify( hash_str, output, sizeof output );
TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
+
+ sha256_free( &ctx );
}
/* END_CASE */
@@ -182,6 +191,7 @@ void sha384_hmac( int trunc_size, char *hex_key_string, char *hex_src_string,
memset(src_str, 0x00, sizeof src_str);
memset(key_str, 0x00, sizeof key_str);
+ sha512_init( &ctx );
key_len = unhexify( key_str, hex_key_string );
src_len = unhexify( src_str, hex_src_string );
@@ -221,6 +231,8 @@ void sha384_hmac( int trunc_size, char *hex_key_string, char *hex_src_string,
hexify( hash_str, output, sizeof output );
TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
+
+ sha512_free( &ctx );
}
/* END_CASE */
@@ -237,6 +249,7 @@ void sha512_hmac( int trunc_size, char *hex_key_string, char *hex_src_string,
memset(src_str, 0x00, sizeof src_str);
memset(key_str, 0x00, sizeof key_str);
+ sha512_init( &ctx );
key_len = unhexify( key_str, hex_key_string );
src_len = unhexify( src_str, hex_src_string );
@@ -276,5 +289,7 @@ void sha512_hmac( int trunc_size, char *hex_key_string, char *hex_src_string,
hexify( hash_str, output, sizeof output );
TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
+
+ sha512_free( &ctx );
}
/* END_CASE */
diff --git a/tests/suites/test_suite_mdx.function b/tests/suites/test_suite_mdx.function
index 24fb32894..12a5e1b49 100644
--- a/tests/suites/test_suite_mdx.function
+++ b/tests/suites/test_suite_mdx.function
@@ -98,6 +98,7 @@ void md2_hmac( int trunc_size, char *hex_key_string, char *hex_src_string,
memset( src_str, 0x00, sizeof src_str );
memset( key_str, 0x00, sizeof key_str );
+ md2_init( &ctx );
key_len = unhexify( key_str, hex_key_string );
src_len = unhexify( src_str, hex_src_string );
@@ -137,6 +138,8 @@ void md2_hmac( int trunc_size, char *hex_key_string, char *hex_src_string,
hexify( hash_str, output, sizeof output );
TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
+
+ md2_free( &ctx );
}
/* END_CASE */
@@ -153,6 +156,7 @@ void md4_hmac( int trunc_size, char *hex_key_string, char *hex_src_string,
memset( src_str, 0x00, sizeof src_str );
memset( key_str, 0x00, sizeof key_str );
+ md4_init( &ctx );
key_len = unhexify( key_str, hex_key_string );
src_len = unhexify( src_str, hex_src_string );
@@ -192,6 +196,8 @@ void md4_hmac( int trunc_size, char *hex_key_string, char *hex_src_string,
hexify( hash_str, output, sizeof output );
TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
+
+ md4_free( &ctx );
}
/* END_CASE */
@@ -208,6 +214,7 @@ void md5_hmac( int trunc_size, char *hex_key_string, char *hex_src_string,
memset( src_str, 0x00, sizeof src_str );
memset( key_str, 0x00, sizeof key_str );
+ md5_init( &ctx );
key_len = unhexify( key_str, hex_key_string );
src_len = unhexify( src_str, hex_src_string );
@@ -247,6 +254,8 @@ void md5_hmac( int trunc_size, char *hex_key_string, char *hex_src_string,
hexify( hash_str, output, sizeof output );
TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
+
+ md5_free( &ctx );
}
/* END_CASE */
@@ -263,6 +272,7 @@ void ripemd160_hmac( int trunc_size, char *hex_key_string, char *hex_src_string,
memset( src_str, 0x00, sizeof src_str );
memset( key_str, 0x00, sizeof key_str );
+ ripemd160_init( &ctx );
key_len = unhexify( key_str, hex_key_string );
src_len = unhexify( src_str, hex_src_string );
@@ -302,6 +312,8 @@ void ripemd160_hmac( int trunc_size, char *hex_key_string, char *hex_src_string,
hexify( hash_str, output, sizeof output );
TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
+
+ ripemd160_free( &ctx );
}
/* END_CASE */