Adapt programs / test suites
diff --git a/programs/aes/crypt_and_hash.c b/programs/aes/crypt_and_hash.c
index 3e89ba6..f5484d4 100644
--- a/programs/aes/crypt_and_hash.c
+++ b/programs/aes/crypt_and_hash.c
@@ -95,8 +95,8 @@
       off_t filesize, offset;
 #endif
 
-    memset( &cipher_ctx, 0, sizeof( cipher_context_t ));
-    memset( &md_ctx, 0, sizeof( md_context_t ));
+    cipher_init( &cipher_ctx );
+    md_init( &md_ctx );
 
     /*
      * Parse the command-line arguments.
@@ -533,8 +533,8 @@
     memset( buffer, 0, sizeof( buffer ) );
     memset( digest, 0, sizeof( digest ) );
 
-    cipher_free_ctx( &cipher_ctx );
-    md_free_ctx( &md_ctx );
+    cipher_free( &cipher_ctx );
+    md_free( &md_ctx );
 
     return( ret );
 }
diff --git a/programs/hash/generic_sum.c b/programs/hash/generic_sum.c
index b5de2a1..4d007cf 100644
--- a/programs/hash/generic_sum.c
+++ b/programs/hash/generic_sum.c
@@ -165,7 +165,7 @@
     const md_info_t *md_info;
     md_context_t md_ctx;
 
-    memset( &md_ctx, 0, sizeof( md_context_t ));
+    md_init( &md_ctx );
 
     if( argc == 1 )
     {
@@ -217,7 +217,7 @@
         ret |= generic_print( md_info, argv[i] );
 
 exit:
-    md_free_ctx( &md_ctx );
+    md_free( &md_ctx );
 
     return( ret );
 }
diff --git a/tests/suites/test_suite_cipher.function b/tests/suites/test_suite_cipher.function
index 7c9c76d..3afdff6 100644
--- a/tests/suites/test_suite_cipher.function
+++ b/tests/suites/test_suite_cipher.function
@@ -29,7 +29,7 @@
     unsigned char buf[1] = { 0 };
     size_t olen;
 
-    memset( &ctx, 0, sizeof( cipher_context_t ) );
+    cipher_init( &ctx );
 
     TEST_ASSERT( cipher_get_block_size( NULL ) == 0 );
     TEST_ASSERT( cipher_get_block_size( &ctx ) == 0 );
@@ -111,8 +111,8 @@
     /*
      * Prepare contexts
      */
-    memset( &ctx_dec, 0, sizeof( ctx_dec ) );
-    memset( &ctx_enc, 0, sizeof( ctx_enc ) );
+    cipher_init( &ctx_dec );
+    cipher_init( &ctx_enc );
 
     memset( key, 0x2a, sizeof( key ) );
 
@@ -207,8 +207,8 @@
     /*
      * Done
      */
-    TEST_ASSERT( 0 == cipher_free_ctx( &ctx_dec ) );
-    TEST_ASSERT( 0 == cipher_free_ctx( &ctx_enc ) );
+    cipher_free( &ctx_dec );
+    cipher_free( &ctx_enc );
 }
 /* END_CASE */
 
@@ -231,7 +231,7 @@
     memset( key, 0, 32 );
     memset( iv , 0, 16 );
 
-    memset( &ctx, 0, sizeof( ctx ) );
+    cipher_init( &ctx );
 
     memset( inbuf, 5, 64 );
     memset( encbuf, 0, 64 );
@@ -259,7 +259,7 @@
     TEST_ASSERT( ret == cipher_finish( &ctx, encbuf + outlen, &outlen ) );
 
     /* done */
-    TEST_ASSERT( 0 == cipher_free_ctx( &ctx ) );
+    cipher_free( &ctx );
 }
 /* END_CASE */
 
@@ -279,16 +279,16 @@
 
     memset( key, 0, 32 );
     memset( iv , 0, 16 );
-    
-    memset( &ctx_dec, 0, sizeof( ctx_dec ) );
-    
+
+    cipher_init( &ctx_dec );
+
     memset( encbuf, 0, 64 );
     memset( decbuf, 0, 64 );
 
     /* Initialise context */
     cipher_info = cipher_info_from_type( POLARSSL_CIPHER_AES_128_CBC );
     TEST_ASSERT( NULL != cipher_info);
-    
+
     TEST_ASSERT( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
 
     TEST_ASSERT( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
@@ -308,7 +308,7 @@
                  &ctx_dec, decbuf + outlen, &outlen ) );
     TEST_ASSERT( 0 == outlen );
 
-    TEST_ASSERT( 0 == cipher_free_ctx( &ctx_dec ) );
+    cipher_free( &ctx_dec );
 }
 /* END_CASE */
 
@@ -335,10 +335,10 @@
 
     memset( key, 0, 32 );
     memset( iv , 0, 16 );
-    
-    memset( &ctx_dec, 0, sizeof( ctx_dec ) );
-    memset( &ctx_enc, 0, sizeof( ctx_enc ) );
-        
+
+    cipher_init( &ctx_dec );
+    cipher_init( &ctx_enc );
+
     memset( inbuf, 5, 64 );
     memset( encbuf, 0, 64 );
     memset( decbuf, 0, 64 );
@@ -346,10 +346,10 @@
     /* Initialise enc and dec contexts */
     cipher_info = cipher_info_from_type( cipher_id );
     TEST_ASSERT( NULL != cipher_info);
-    
+
     TEST_ASSERT( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
     TEST_ASSERT( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
-    
+
     TEST_ASSERT( 0 == cipher_setkey( &ctx_dec, key, key_len, POLARSSL_DECRYPT ) );
     TEST_ASSERT( 0 == cipher_setkey( &ctx_enc, key, key_len, POLARSSL_ENCRYPT ) );
 
@@ -397,8 +397,8 @@
 
     TEST_ASSERT( 0 == memcmp(inbuf, decbuf, length) );
 
-    TEST_ASSERT( 0 == cipher_free_ctx( &ctx_dec ) );
-    TEST_ASSERT( 0 == cipher_free_ctx( &ctx_enc ) );
+    cipher_free( &ctx_dec );
+    cipher_free( &ctx_enc );
 }
 /* END_CASE */
 
@@ -423,6 +423,8 @@
     unsigned char output[200];
     size_t outlen, total_len;
 
+    cipher_init( &ctx );
+
     memset( key, 0x00, sizeof( key ) );
     memset( iv, 0x00, sizeof( iv ) );
     memset( cipher, 0x00, sizeof( cipher ) );
@@ -477,7 +479,7 @@
         TEST_ASSERT( 0 == memcmp( output, clear, clear_len ) );
     }
 
-    cipher_free_ctx( &ctx );
+    cipher_free( &ctx );
 }
 /* END_CASE */
 
@@ -499,6 +501,8 @@
     unsigned char output[200];
     size_t outlen;
 
+    cipher_init( &ctx );
+
     memset( key,    0x00, sizeof( key    ) );
     memset( iv,     0x00, sizeof( iv     ) );
     memset( cipher, 0x00, sizeof( cipher ) );
@@ -563,7 +567,7 @@
 
 
 cleanup:
-    cipher_free_ctx( &ctx );
+    cipher_free( &ctx );
 }
 /* END_CASE */
 
@@ -580,6 +584,8 @@
     unsigned char output[32];
     size_t outlen;
 
+    cipher_init( &ctx );
+
     memset( key, 0x00, sizeof( key ) );
     memset( input, 0x00, sizeof( input ) );
     memset( result, 0x00, sizeof( result ) );
@@ -610,7 +616,7 @@
         TEST_ASSERT( 0 == memcmp( output, result,
                                   cipher_get_block_size( &ctx ) ) );
 
-    cipher_free_ctx( &ctx );
+    cipher_free( &ctx );
 }
 /* END_CASE */
 
@@ -620,13 +626,15 @@
     const cipher_info_t *cipher_info;
     cipher_context_t ctx;
 
+    cipher_init( &ctx );
+
     cipher_info = cipher_info_from_type( cipher_id );
     TEST_ASSERT( NULL != cipher_info );
     TEST_ASSERT( 0 == cipher_init_ctx( &ctx, cipher_info ) );
 
     TEST_ASSERT( ret == cipher_set_padding_mode( &ctx, pad_mode ) );
 
-    TEST_ASSERT( 0 == cipher_free_ctx( &ctx ) );
+    cipher_free( &ctx );
 }
 /* END_CASE */
 
@@ -639,7 +647,7 @@
     size_t ilen, dlen;
 
     /* build a fake context just for getting access to get_padding */
-    memset( &ctx, 0, sizeof( ctx ) );
+    cipher_init( &ctx );
     cipher_info.mode = POLARSSL_MODE_CBC;
     ctx.cipher_info = &cipher_info;
 
diff --git a/tests/suites/test_suite_md.function b/tests/suites/test_suite_md.function
index 9f06443..338f8af 100644
--- a/tests/suites/test_suite_md.function
+++ b/tests/suites/test_suite_md.function
@@ -15,7 +15,7 @@
     md_context_t ctx;
     unsigned char buf[150];
 
-    memset( &ctx, 0, sizeof ctx );
+    md_init( &ctx );
 
     /*
      * Very minimal testing of md_process, just make sure the various
@@ -31,7 +31,7 @@
         TEST_ASSERT( info != NULL );
         TEST_ASSERT( md_init_ctx( &ctx, info ) == 0 );
         TEST_ASSERT( md_process( &ctx, buf ) == 0 );
-        TEST_ASSERT( md_free_ctx( &ctx ) == 0 );
+        md_free( &ctx );
     }
 }
 /* END_CASE */
@@ -43,7 +43,7 @@
     const md_info_t *info = md_info_from_type( *( md_list() ) );
     unsigned char buf[1] = { 0 };
 
-    memset( &ctx, 0, sizeof( md_context_t ) );
+    md_init( &ctx );
 
     TEST_ASSERT( md_get_size( NULL ) == 0 );
 
@@ -177,9 +177,11 @@
     unsigned char src_str[1000];
     unsigned char hash_str[1000];
     unsigned char output[100];
-    
+
     const md_info_t *md_info = NULL;
-    md_context_t ctx = MD_CONTEXT_T_INIT;
+    md_context_t ctx;
+
+    md_init( &ctx );
 
     memset(md_name, 0x00, 100);
     memset(src_str, 0x00, 1000);
@@ -196,8 +198,8 @@
     TEST_ASSERT ( ctx.md_ctx != NULL );
     TEST_ASSERT ( 0 == md_update( &ctx, src_str, strlen( (char *) src_str ) ) );
     TEST_ASSERT ( 0 == md_finish( &ctx, output ) );
-    TEST_ASSERT ( 0 == md_free_ctx( &ctx ) );
-    
+    md_free( &ctx );
+
     hexify( hash_str, output, md_get_size(md_info) );
 
     TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
@@ -214,7 +216,9 @@
     unsigned char output[100];
     int src_len;
     const md_info_t *md_info = NULL;
-    md_context_t ctx = MD_CONTEXT_T_INIT;
+    md_context_t ctx;
+
+    md_init( &ctx );
 
     memset(md_name, 0x00, 100);
     memset(src_str, 0x00, 10000);
@@ -227,13 +231,13 @@
     TEST_ASSERT ( 0 == md_init_ctx( &ctx, md_info ) );
 
     src_len = unhexify( src_str, hex_src_string );
-    
+
     TEST_ASSERT ( 0 == md_starts( &ctx ) );
     TEST_ASSERT ( ctx.md_ctx != NULL );
     TEST_ASSERT ( 0 == md_update( &ctx, src_str, src_len ) );
     TEST_ASSERT ( 0 == md_finish( &ctx, output ) );
-    TEST_ASSERT ( 0 == md_free_ctx( &ctx ) );
-    
+    md_free( &ctx );
+
     hexify( hash_str, output, md_get_size(md_info) );
 
     TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
@@ -283,7 +287,9 @@
     unsigned char output[100];
     int key_len, src_len;
     const md_info_t *md_info = NULL;
-    md_context_t ctx = MD_CONTEXT_T_INIT;
+    md_context_t ctx;
+
+    md_init( &ctx );
 
     memset(md_name, 0x00, 100);
     memset(src_str, 0x00, 10000);
@@ -314,7 +320,7 @@
     TEST_ASSERT ( 0 == md_hmac_reset( &ctx ) );
     TEST_ASSERT ( 0 == md_hmac_update( &ctx, src_str, src_len ) );
     TEST_ASSERT ( 0 == md_hmac_finish( &ctx, output ) );
-    TEST_ASSERT ( 0 == md_free_ctx( &ctx ) );
+    md_free( &ctx );
 
     hexify( hash_str, output, md_get_size(md_info) );
     TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
diff --git a/tests/suites/test_suite_pbkdf2.function b/tests/suites/test_suite_pbkdf2.function
index bd52bf9..4b31896 100644
--- a/tests/suites/test_suite_pbkdf2.function
+++ b/tests/suites/test_suite_pbkdf2.function
@@ -17,10 +17,12 @@
 
     md_context_t ctx;
     const md_info_t *info;
-    
+
     int pw_len, salt_len;
     unsigned char key[100];
 
+    md_init( &ctx );
+
     memset(pw_str, 0x00, 100);
     memset(salt_str, 0x00, 100);
     memset(dst_str, 0x00, 100);
@@ -36,7 +38,7 @@
     TEST_ASSERT( md_init_ctx( &ctx, info ) == 0 );
     TEST_ASSERT( pbkdf2_hmac( &ctx, pw_str, pw_len, salt_str, salt_len,
                               it_cnt, key_len, key ) == 0 );
-    TEST_ASSERT( md_free_ctx( &ctx ) == 0 );
+    md_free( &ctx );
 
     hexify( dst_str, key, key_len );
     TEST_ASSERT( strcmp( (char *) dst_str, result_key_string ) == 0 );
diff --git a/tests/suites/test_suite_pkcs5.function b/tests/suites/test_suite_pkcs5.function
index c745571..a86778a 100644
--- a/tests/suites/test_suite_pkcs5.function
+++ b/tests/suites/test_suite_pkcs5.function
@@ -22,6 +22,8 @@
     int pw_len, salt_len;
     unsigned char key[100];
 
+    md_init( &ctx );
+
     memset(pw_str, 0x00, 100);
     memset(salt_str, 0x00, 100);
     memset(dst_str, 0x00, 100);
@@ -37,7 +39,7 @@
     TEST_ASSERT( md_init_ctx( &ctx, info ) == 0 );
     TEST_ASSERT( pkcs5_pbkdf2_hmac( &ctx, pw_str, pw_len, salt_str, salt_len,
                                      it_cnt, key_len, key ) == 0 );
-    TEST_ASSERT( md_free_ctx( &ctx ) == 0 );
+    md_free( &ctx );
 
     hexify( dst_str, key, key_len );
     TEST_ASSERT( strcmp( (char *) dst_str, result_key_string ) == 0 );