diff --git a/buffer.c b/buffer.c
index 869e6a3..b82ea3c 100644
--- a/buffer.c
+++ b/buffer.c
@@ -85,9 +85,13 @@ void
 nettle_buffer_clear(struct nettle_buffer *buffer)
 {
   if (buffer->realloc)
-    buffer->realloc(buffer->realloc_ctx, buffer->contents, 0);
+    buffer->contents = buffer->realloc(buffer->realloc_ctx, buffer->contents, 0);
 
-  buffer->contents = NULL;
+  if (buffer->contents)
+    {
+      free(buffer->contents);
+      buffer->contents = NULL;
+    }
   buffer->alloc = 0;
   buffer->size = 0;
 }
diff --git a/examples/rsa-encrypt.c b/examples/rsa-encrypt.c
index 70d1503..ca1a8cd 100644
--- a/examples/rsa-encrypt.c
+++ b/examples/rsa-encrypt.c
@@ -253,7 +253,9 @@ main(int argc, char **argv)
     }
 
   write_bignum(stdout, x);
-  
+
+  mpz_clear(x);
+
   if (!process_file(&ctx,
 		    stdin, stdout))
     return EXIT_FAILURE;
diff --git a/examples/rsa-keygen.c b/examples/rsa-keygen.c
index 0ca39b4..165e6f4 100644
--- a/examples/rsa-keygen.c
+++ b/examples/rsa-keygen.c
@@ -160,5 +160,12 @@ main(int argc, char **argv)
       return EXIT_FAILURE;
     }
 
+  nettle_buffer_clear(&pub_buffer);
+  nettle_buffer_clear(&priv_buffer);
+  rsa_private_key_clear(&priv);
+  rsa_public_key_clear(&pub);
+  free(pub_name);
+
+
   return EXIT_SUCCESS;
 }
diff --git a/testsuite/aes-test.c b/testsuite/aes-test.c
index 87be806..aa9bf59 100644
--- a/testsuite/aes-test.c
+++ b/testsuite/aes-test.c
@@ -2,10 +2,16 @@
 #include "aes.h"
 
 static void
-test_invert(unsigned key_length, const uint8_t *key,
-	    unsigned length, const uint8_t *cleartext,
-	    const uint8_t *ciphertext)
+test_invert(const uint8_t *key_hex,
+	    const uint8_t *cleartext_hex,
+	    const uint8_t *ciphertext_hex)
 {
+  unsigned key_length = decode_hex_length(key_hex);
+  const uint8_t *key = decode_hex_dup(key_hex);
+  unsigned length = decode_hex_length(cleartext_hex);
+  const uint8_t *cleartext = decode_hex_dup(cleartext_hex);
+  const uint8_t *ciphertext = decode_hex_dup(ciphertext_hex);
+
   struct aes_ctx encrypt;
   struct aes_ctx decrypt;
   uint8_t *data = xalloc(length);
@@ -39,61 +45,65 @@ test_invert(unsigned key_length, const uint8_t *key,
       fprintf(stderr, "\n");
       FAIL();
     }
+
   free (data);
+  free((void *)ciphertext);
+  free((void *)cleartext);
+  free((void *)key);
 }
 
 int
 test_main(void)
 {
   /* 128 bit keys */
-  test_cipher(&nettle_aes128, 
-	      HL("0001020305060708 0A0B0C0D0F101112"),
-	      HL("506812A45F08C889 B97F5980038B8359"),
-	      H("D8F532538289EF7D 06B506A4FD5BE9C9"));
+  test_cipher(&nettle_aes128,
+	      "0001020305060708 0A0B0C0D0F101112",
+	      "506812A45F08C889 B97F5980038B8359",
+	      "D8F532538289EF7D 06B506A4FD5BE9C9");
   
   test_cipher(&nettle_aes128, 
-	      HL("14151617191A1B1C 1E1F202123242526"),
-	      HL("5C6D71CA30DE8B8B 00549984D2EC7D4B"),
-	      H("59AB30F4D4EE6E4F F9907EF65B1FB68C"));
+	      "14151617191A1B1C 1E1F202123242526",
+	      "5C6D71CA30DE8B8B 00549984D2EC7D4B",
+	      "59AB30F4D4EE6E4F F9907EF65B1FB68C");
 
   test_cipher(&nettle_aes128, 
-	      HL("28292A2B2D2E2F30 323334353738393A"),
-	      HL("53F3F4C64F8616E4 E7C56199F48F21F6"),
-	      H("BF1ED2FCB2AF3FD4 1443B56D85025CB1"));
+	      "28292A2B2D2E2F30 323334353738393A",
+	      "53F3F4C64F8616E4 E7C56199F48F21F6",
+	      "BF1ED2FCB2AF3FD4 1443B56D85025CB1");
   
   test_cipher(&nettle_aes128, 
-	      HL("A0A1A2A3A5A6A7A8 AAABACADAFB0B1B2"),
-	      HL("F5F4F7F684878689 A6A7A0A1D2CDCCCF"),
-	      H("CE52AF650D088CA5 59425223F4D32694"));
+	      "A0A1A2A3A5A6A7A8 AAABACADAFB0B1B2",
+	      "F5F4F7F684878689 A6A7A0A1D2CDCCCF",
+	      "CE52AF650D088CA5 59425223F4D32694");
 
   /* 192 bit keys */
   
   test_cipher(&nettle_aes192, 
-	      HL("0001020305060708 0A0B0C0D0F101112"
-		"14151617191A1B1C"),
-	      HL("2D33EEF2C0430A8A 9EBF45E809C40BB6"),
-	      H("DFF4945E0336DF4C 1C56BC700EFF837F"));
+	      "0001020305060708 0A0B0C0D0F101112"
+		"14151617191A1B1C",
+	      "2D33EEF2C0430A8A 9EBF45E809C40BB6",
+	      "DFF4945E0336DF4C 1C56BC700EFF837F");
 
   /* 256 bit keys */
   
   test_cipher(&nettle_aes256,
-	      HL("0001020305060708 0A0B0C0D0F101112"
-		"14151617191A1B1C 1E1F202123242526"),
-	      HL("834EADFCCAC7E1B30664B1ABA44815AB"),
-	      H("1946DABF6A03A2A2 C3D0B05080AED6FC"));
+	      "0001020305060708 0A0B0C0D0F101112"
+		"14151617191A1B1C 1E1F202123242526",
+	      "834EADFCCAC7E1B30664B1ABA44815AB",
+	      "1946DABF6A03A2A2 C3D0B05080AED6FC");
 
   
   /* This test case has been problematic with the CBC test case */
   test_cipher(&nettle_aes256,
-	      HL("8d ae 93 ff fc 78 c9 44"
+	      "8d ae 93 ff fc 78 c9 44"
 		"2a bd 0c 1e 68 bc a6 c7"
 		"05 c7 84 e3 5a a9 11 8b"
-		"d3 16 aa 54 9b 44 08 9e"),
-	      HL("a5 ce 55 d4 21 15 a1 c6 4a a4 0c b2 ca a6 d1 37"),
+		"d3 16 aa 54 9b 44 08 9e",
+	      "a5 ce 55 d4 21 15 a1 c6 4a a4 0c b2 ca a6 d1 37",
 	      /* In the cbc test, I once got the bad value
 	       *   "b2 a0 6c d2 2f df 7d 2c  26 d2 42 88 8f 20 74 a2" */
-	      H("1f 94 fc 85 f2 36 21 06"
-		"4a ea e3 c9 cc 38 01 0e"));
+	      "1f 94 fc 85 f2 36 21 06"
+		"4a ea e3 c9 cc 38 01 0e");
   
   /* From draft NIST spec on AES modes.
    *
@@ -102,54 +112,54 @@ test_main(void)
    */
 
   test_cipher(&nettle_aes128,
-	      HL("2b7e151628aed2a6abf7158809cf4f3c"),
-	      HL("6bc1bee22e409f96e93d7e117393172a"
+	      "2b7e151628aed2a6abf7158809cf4f3c",
+	      "6bc1bee22e409f96e93d7e117393172a"
 		"ae2d8a571e03ac9c9eb76fac45af8e51"
 		"30c81c46a35ce411e5fbc1191a0a52ef"
-		"f69f2445df4f9b17ad2b417be66c3710"),
-	      H("3ad77bb40d7a3660a89ecaf32466ef97"
+		"f69f2445df4f9b17ad2b417be66c3710",
+	      "3ad77bb40d7a3660a89ecaf32466ef97"
 		"f5d3d58503b9699de785895a96fdbaaf"
 		"43b1cd7f598ece23881b00e3ed030688"
-		"7b0c785e27e8ad3f8223207104725dd4"));
+		"7b0c785e27e8ad3f8223207104725dd4");
 
   /* F.1.3 ECB-AES192-Encrypt */
 
   test_cipher(&nettle_aes192,
-	      HL("8e73b0f7da0e6452c810f32b809079e5 62f8ead2522c6b7b"),
-	      HL("6bc1bee22e409f96e93d7e117393172a"
+	      "8e73b0f7da0e6452c810f32b809079e5 62f8ead2522c6b7b",
+	      "6bc1bee22e409f96e93d7e117393172a"
 		"ae2d8a571e03ac9c9eb76fac45af8e51"
 		"30c81c46a35ce411e5fbc1191a0a52ef"
-		"f69f2445df4f9b17ad2b417be66c3710"),
-	      H("bd334f1d6e45f25ff712a214571fa5cc"
+		"f69f2445df4f9b17ad2b417be66c3710",
+	      "bd334f1d6e45f25ff712a214571fa5cc"
 		"974104846d0ad3ad7734ecb3ecee4eef"
 		"ef7afd2270e2e60adce0ba2face6444e"
-		"9a4b41ba738d6c72fb16691603c18e0e"));
+		"9a4b41ba738d6c72fb16691603c18e0e");
 
   /* F.1.5 ECB-AES256-Encrypt */
   test_cipher(&nettle_aes256,
-	      HL("603deb1015ca71be2b73aef0857d7781"
-		"1f352c073b6108d72d9810a30914dff4"),
-	      HL("6bc1bee22e409f96e93d7e117393172a"
+	      "603deb1015ca71be2b73aef0857d7781"
+		"1f352c073b6108d72d9810a30914dff4",
+	      "6bc1bee22e409f96e93d7e117393172a"
 		"ae2d8a571e03ac9c9eb76fac45af8e51" 
 		"30c81c46a35ce411e5fbc1191a0a52ef"
-		"f69f2445df4f9b17ad2b417be66c3710"),
-	      H("f3eed1bdb5d2a03c064b5a7e3db181f8"
+		"f69f2445df4f9b17ad2b417be66c3710",
+	      "f3eed1bdb5d2a03c064b5a7e3db181f8"
 		"591ccb10d410ed26dc5ba74a31362870"
 		"b6ed21b99ca6f4f9f153e7b1beafed1d"
-		"23304b7a39f9f3ff067d8d8f9e24ecc7"));
+		"23304b7a39f9f3ff067d8d8f9e24ecc7");
 
   /* Test aes_invert_key with src != dst */
-  test_invert(HL("0001020305060708 0A0B0C0D0F101112"),
-	      HL("506812A45F08C889 B97F5980038B8359"),
-	      H("D8F532538289EF7D 06B506A4FD5BE9C9"));
-  test_invert(HL("0001020305060708 0A0B0C0D0F101112"
-		"14151617191A1B1C"),
-	      HL("2D33EEF2C0430A8A 9EBF45E809C40BB6"),
-	      H("DFF4945E0336DF4C 1C56BC700EFF837F"));
-  test_invert(HL("0001020305060708 0A0B0C0D0F101112"
-		"14151617191A1B1C 1E1F202123242526"),
-	      HL("834EADFCCAC7E1B30664B1ABA44815AB"),
-	      H("1946DABF6A03A2A2 C3D0B05080AED6FC"));
+  test_invert("0001020305060708 0A0B0C0D0F101112",
+	      "506812A45F08C889 B97F5980038B8359",
+	      "D8F532538289EF7D 06B506A4FD5BE9C9");
+  test_invert("0001020305060708 0A0B0C0D0F101112"
+		"14151617191A1B1C",
+	      "2D33EEF2C0430A8A 9EBF45E809C40BB6",
+	      "DFF4945E0336DF4C 1C56BC700EFF837F");
+  test_invert("0001020305060708 0A0B0C0D0F101112"
+		"14151617191A1B1C 1E1F202123242526",
+	      "834EADFCCAC7E1B30664B1ABA44815AB",
+	      "1946DABF6A03A2A2 C3D0B05080AED6FC");
 
   SUCCESS();
 }
diff --git a/testsuite/arcfour-test.c b/testsuite/arcfour-test.c
index 6027c54..99a42bb 100644
--- a/testsuite/arcfour-test.c
+++ b/testsuite/arcfour-test.c
@@ -5,16 +5,16 @@ int
 test_main(void)
 {
   test_cipher_stream(&nettle_arcfour128,
-		     HL("01234567 89ABCDEF 00000000 00000000"),
-		     HL("01234567 89ABCDEF"),
-		     H("69723659 1B5242B1"));
+		     "01234567 89ABCDEF 00000000 00000000",
+		     "01234567 89ABCDEF",
+		     "69723659 1B5242B1");
 
   /* More data. This ensures that we get some collisions between the S
      accesses at index i,j and the access at si + sj. I.e. the cases
      where the ordering of loads and stores matter. */
   test_cipher_stream(&nettle_arcfour128,
-		     HL("aaaaaaaa bbbbbbbb cccccccc dddddddd"),
-		     HL("00000000 00000000 00000000 00000000"
+		     "aaaaaaaa bbbbbbbb cccccccc dddddddd",
+		     "00000000 00000000 00000000 00000000"
 			"00000000 00000000 00000000 00000000"
 			"00000000 00000000 00000000 00000000"
 			"00000000 00000000 00000000 00000000"
@@ -52,8 +52,8 @@ test_main(void)
 			"00000000 00000000 00000000 00000000"
 			"00000000 00000000 00000000 00000000"
 			"00000000 00000000 00000000 00000000"
-			"00000000 00000000 00000000 00000000"),
-		     H("a2b35dc7 bf95ae1e 1c432d15 f4fb8c1c"
+			"00000000 00000000 00000000 00000000",
+		     "a2b35dc7 bf95ae1e 1c432d15 f4fb8c1c"
 		       "f264e1d0 bd090831 6caa7d17 5401ae67"
 		       "3cfbd140 fd3dee42 1012d674 2fb69fa3"
 		       "6522631e bb3d4703 535de1ce 4a81ddce"
@@ -91,7 +91,7 @@ test_main(void)
 		       "613e3067 92cada3e 0e07f599 2f4794f3"
 		       "af01f15a 491732fb 22aa09a3 d2e1e408"
 		       "fe94bdb4 993c68b1 1bb79eb1 bb7ec446"
-		       "760ef7bf 2caa8713 479760e5 a6e143cd"));
+		       "760ef7bf 2caa8713 479760e5 a6e143cd");
   
   SUCCESS();
 }
diff --git a/testsuite/arctwo-test.c b/testsuite/arctwo-test.c
index 4fedfad..cf52d1b 100644
--- a/testsuite/arctwo-test.c
+++ b/testsuite/arctwo-test.c
@@ -25,12 +25,16 @@
 /* For tests with obscure values of ebk. */
 static void
 test_arctwo(unsigned ekb,
-	    unsigned key_length,
-	    const uint8_t *key,
-	    unsigned length,
-	    const uint8_t *cleartext,
-	    const uint8_t *ciphertext)
+	    const uint8_t *key_hex,
+	    const uint8_t *cleartext_hex,
+	    const uint8_t *ciphertext_hex)
 {
+  unsigned key_length = decode_hex_length(key_hex);
+  const uint8_t *key = decode_hex_dup(key_hex);
+  unsigned length = decode_hex_length(cleartext_hex);
+  const uint8_t *cleartext = decode_hex_dup(cleartext_hex);
+  const uint8_t *ciphertext = decode_hex_dup(ciphertext_hex);
+
   struct arctwo_ctx ctx;
   uint8_t *data = xalloc(length);
 
@@ -46,6 +50,9 @@ test_arctwo(unsigned ekb,
     FAIL();
 
   free(data);
+  free((void *)ciphertext);
+  free((void *)cleartext);
+  free((void *)key);
 }
 
 int
@@ -53,63 +60,63 @@ test_main(void)
 {
   /* Test vectors from Peter Gutmann's paper. */
   test_cipher(&nettle_arctwo_gutmann128,
-	      HL("00000000 00000000 00000000 00000000"),
-	      HL("00000000 00000000"),
-	      H ("1c198a83 8df028b7"));
+	      "00000000 00000000 00000000 00000000",
+	      "00000000 00000000",
+	      "1c198a83 8df028b7");
 
   test_cipher(&nettle_arctwo_gutmann128,
-	      HL("00010203 04050607 08090a0b 0c0d0e0f"),
-	      HL("00000000 00000000"),
-	      H ("50dc0162 bd757f31"));
+	      "00010203 04050607 08090a0b 0c0d0e0f",
+	      "00000000 00000000",
+	      "50dc0162 bd757f31");
 
   /* This one was checked against libmcrypt's RFC2268. */
   test_cipher(&nettle_arctwo_gutmann128,
-	      HL("30000000 00000000 00000000 00000000"),
-	      HL("10000000 00000000"),
-	      H ("8fd10389 336bf95e"));
+	      "30000000 00000000 00000000 00000000",
+	      "10000000 00000000",
+	      "8fd10389 336bf95e");
 
   /* Test vectors from RFC 2268. */
   test_cipher(&nettle_arctwo64,
-	      HL("ffffffff ffffffff"),
-	      HL("ffffffff ffffffff"),
-	      H ("278b27e4 2e2f0d49"));
+	      "ffffffff ffffffff",
+	      "ffffffff ffffffff",
+	      "278b27e4 2e2f0d49");
 
   test_cipher(&nettle_arctwo64,
-	      HL("30000000 00000000"),
-	      HL("10000000 00000001"),
-	      H ("30649edf 9be7d2c2"));
+	      "30000000 00000000",
+	      "10000000 00000001",
+	      "30649edf 9be7d2c2");
 
   test_cipher(&nettle_arctwo128,
-	      HL("88bca90e 90875a7f 0f79c384 627bafb2"),
-	      HL("00000000 00000000"),
-	      H ("2269552a b0f85ca6"));
+	      "88bca90e 90875a7f 0f79c384 627bafb2",
+	      "00000000 00000000",
+	      "2269552a b0f85ca6");
 
   /* More obscure tests from RFC 2286 */
   test_arctwo(63,
-	      HL("00000000 00000000"),
-	      HL("00000000 00000000"),
-	      H ("ebb773f9 93278eff"));
+	      "00000000 00000000",
+	      "00000000 00000000",
+	      "ebb773f9 93278eff");
 
   test_arctwo(64,
-	      HL("88"),
-	      HL("00000000 00000000"),
-	      H ("61a8a244 adacccf0"));
+	      "88",
+	      "00000000 00000000",
+	      "61a8a244 adacccf0");
 
   test_arctwo(64,
-	      HL("88bca90e 90875a"),
-	      HL("00000000 00000000"),
-	      H ("6ccf4308 974c267f"));
+	      "88bca90e 90875a",
+	      "00000000 00000000",
+	      "6ccf4308 974c267f");
 
   test_arctwo(64,
-	      HL("88bca90e 90875a7f 0f79c384 627bafb2"),
-	      HL("00000000 00000000"),
-	      H ("1a807d27 2bbe5db1"));
+	      "88bca90e 90875a7f 0f79c384 627bafb2",
+	      "00000000 00000000",
+	      "1a807d27 2bbe5db1");
 
   test_arctwo(129,
-	      HL("88bca90e 90875a7f 0f79c384 627bafb2"
-		 "16f80a6f 85920584 c42fceb0 be255daf 1e"),
-	      HL("00000000 00000000"),
-	      H ("5b78d3a4 3dfff1f1"));
+	      "88bca90e 90875a7f 0f79c384 627bafb2"
+		 "16f80a6f 85920584 c42fceb0 be255daf 1e",
+	      "00000000 00000000",
+	      "5b78d3a4 3dfff1f1");
 
   SUCCESS ();
 }
diff --git a/testsuite/bignum-test.c b/testsuite/bignum-test.c
index 84e0483..91afa9e 100644
--- a/testsuite/bignum-test.c
+++ b/testsuite/bignum-test.c
@@ -11,8 +11,10 @@
 #include "bignum.h"
 
 static void
-test_bignum(const char *hex, unsigned length, const uint8_t *base256)
+test_bignum(const char *hex, const uint8_t *base256_hex)
 {
+  unsigned length = decode_hex_length(base256_hex);
+  const uint8_t *base256 = decode_hex_dup(base256_hex);
   mpz_t a;
   mpz_t b;
   uint8_t *buf;
@@ -35,6 +37,7 @@ test_bignum(const char *hex, unsigned length, const uint8_t *base256)
 
   mpz_clear(a); mpz_clear(b);
   free(buf);
+  free((void *)base256);
 }
 
 static void
@@ -78,17 +81,17 @@ test_main(void)
   test_size(- 0x8000, 2); /*   8000 */
   test_size(- 0x8001, 3); /* ff7fff */
 
-  test_bignum("0", HL("00"));
-  test_bignum("010203040506", HL("010203040506"));
-  test_bignum("80010203040506", HL("0080010203040506"));
-
-  test_bignum(   "-1", HL(    "ff"));
-  test_bignum(  "-7f", HL(    "81"));
-  test_bignum(  "-80", HL(    "80"));
-  test_bignum(  "-81", HL(  "ff7f"));
-  test_bignum("-7fff", HL(  "8001"));
-  test_bignum("-8000", HL(  "8000"));
-  test_bignum("-8001", HL("ff7fff"));
+  test_bignum("0", "00");
+  test_bignum("010203040506", "010203040506");
+  test_bignum("80010203040506", "0080010203040506");
+
+  test_bignum(   "-1",     "ff");
+  test_bignum(  "-7f",     "81");
+  test_bignum(  "-80",     "80");
+  test_bignum(  "-81",   "ff7f");
+  test_bignum("-7fff",   "8001");
+  test_bignum("-8000",   "8000");
+  test_bignum("-8001", "ff7fff");
   
   SUCCESS();
 #else /* !HAVE_LIBGMP */
diff --git a/testsuite/blowfish-test.c b/testsuite/blowfish-test.c
index c4311bb..560f914 100644
--- a/testsuite/blowfish-test.c
+++ b/testsuite/blowfish-test.c
@@ -2,14 +2,22 @@
 #include "nettle-internal.h"
 #include "blowfish.h"
 
+#define STR_TO_HEX(a) encode_hex_dup(a, strlen(a))
+
 int
 test_main(void)
 {
+  const uint8_t *key_hex = STR_TO_HEX("abcdefghijklmnopqrstuvwxyz");
+  const uint8_t *cleartext_hex = STR_TO_HEX("BLOWFISH");
+
   /* 208 bit key. Test from GNUPG. */
   test_cipher(&nettle_blowfish128,
-	      26, "abcdefghijklmnopqrstuvwxyz",
-	      BLOWFISH_BLOCK_SIZE, "BLOWFISH",
-	      H("32 4E D0 FE F4 13 A2 03"));
+	      key_hex,
+	      cleartext_hex,
+	      "32 4E D0 FE F4 13 A2 03");
+
+  free((void *)cleartext_hex);
+  free((void *)key_hex);
 
   SUCCESS();
 }
diff --git a/testsuite/camellia-test.c b/testsuite/camellia-test.c
index 4f1d118..8e245a4 100644
--- a/testsuite/camellia-test.c
+++ b/testsuite/camellia-test.c
@@ -2,10 +2,16 @@
 #include "camellia.h"
 
 static void
-test_invert(unsigned key_length, const uint8_t *key,
-	    unsigned length, const uint8_t *cleartext,
-	    const uint8_t *ciphertext)
+test_invert(const uint8_t *key_hex,
+	    const uint8_t *cleartext_hex,
+	    const uint8_t *ciphertext_hex)
 {
+  unsigned key_length = decode_hex_length(key_hex);
+  const uint8_t *key = decode_hex_dup(key_hex);
+  unsigned length = decode_hex_length(cleartext_hex);
+  const uint8_t *cleartext = decode_hex_dup(cleartext_hex);
+  const uint8_t *ciphertext = decode_hex_dup(ciphertext_hex);
+
   struct camellia_ctx encrypt;
   struct camellia_ctx decrypt;
   uint8_t *data = xalloc(length);
@@ -39,7 +45,11 @@ test_invert(unsigned key_length, const uint8_t *key,
       fprintf(stderr, "\n");
       FAIL();
     }
+
   free (data);
+  free((void *)ciphertext);
+  free((void *)cleartext);
+  free((void *)key);
 }
 
 int
@@ -48,37 +58,37 @@ test_main(void)
   /* Test vectors from RFC 3713 */
   /* 128 bit keys */
   test_cipher(&nettle_camellia128,
-	      HL("01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10"),
-	      HL("01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10"),
-	      H("67 67 31 38 54 96 69 73 08 57 06 56 48 ea be 43"));
+	      "01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10",
+	      "01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10",
+	      "67 67 31 38 54 96 69 73 08 57 06 56 48 ea be 43");
 
   /* 192 bit keys */
   test_cipher(&nettle_camellia192, 
-	      HL("01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10"
-                 "00 11 22 33 44 55 66 77"),
-	      HL("01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10"),
-	      H("b4 99 34 01 b3 e9 96 f8 4e e5 ce e7 d7 9b 09 b9"));
+	      "01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10"
+                 "00 11 22 33 44 55 66 77",
+	      "01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10",
+	      "b4 99 34 01 b3 e9 96 f8 4e e5 ce e7 d7 9b 09 b9");
 
   /* 256 bit keys */
   test_cipher(&nettle_camellia256, 
-	      HL("01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10"
-                 "00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff"),
-	      HL("01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10"),
-	      H("9a cc 23 7d ff 16 d7 6c 20 ef 7c 91 9e 3a 75 09"));
+	      "01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10"
+                 "00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff",
+	      "01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10",
+	      "9a cc 23 7d ff 16 d7 6c 20 ef 7c 91 9e 3a 75 09");
 
   /* Test camellia_invert_key with src != dst */
-  test_invert(HL("01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10"),
-	      HL("01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10"),
-	      H("67 67 31 38 54 96 69 73 08 57 06 56 48 ea be 43"));
+  test_invert("01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10",
+	      "01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10",
+	      "67 67 31 38 54 96 69 73 08 57 06 56 48 ea be 43");
   
-  test_invert(HL("01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10"
-                 "00 11 22 33 44 55 66 77"),
-	      HL("01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10"),
-	      H("b4 99 34 01 b3 e9 96 f8 4e e5 ce e7 d7 9b 09 b9"));
+  test_invert("01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10"
+                 "00 11 22 33 44 55 66 77",
+	      "01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10",
+	      "b4 99 34 01 b3 e9 96 f8 4e e5 ce e7 d7 9b 09 b9");
 
-  test_invert(HL("01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10"
-                 "00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff"),
-	      HL("01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10"),
-	      H("9a cc 23 7d ff 16 d7 6c 20 ef 7c 91 9e 3a 75 09"));
+  test_invert("01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10"
+                 "00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff",
+	      "01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10",
+	      "9a cc 23 7d ff 16 d7 6c 20 ef 7c 91 9e 3a 75 09");
   SUCCESS();
 }
diff --git a/testsuite/cast128-test.c b/testsuite/cast128-test.c
index e4b7830..e9d8fae 100644
--- a/testsuite/cast128-test.c
+++ b/testsuite/cast128-test.c
@@ -9,22 +9,22 @@ test_main(void)
 
   /* 128 bit key */
   test_cipher(&nettle_cast128,
-	      HL("01 23 45 67 12 34 56 78"
-		 "23 45 67 89 34 56 78 9A"),
-	      HL("01 23 45 67 89 AB CD EF"),
-	      H("23 8B 4F E5 84 7E 44 B2"));
+	      "01 23 45 67 12 34 56 78"
+		 "23 45 67 89 34 56 78 9A",
+	      "01 23 45 67 89 AB CD EF",
+	      "23 8B 4F E5 84 7E 44 B2");
   
   /* 80 bit key */
   test_cipher(&nettle_cast128,
-	      HL("01 23 45 67 12 34 56 78 23 45"),
-	      HL("01 23 45 67 89 AB CD EF"),
-	      H("EB 6A 71 1A 2C 02 27 1B"));
+	      "01 23 45 67 12 34 56 78 23 45",
+	      "01 23 45 67 89 AB CD EF",
+	      "EB 6A 71 1A 2C 02 27 1B");
 
   /* 40 bit key */
   test_cipher(&nettle_cast128,
-	      HL("01 23 45 67 12"),
-	      HL("01 23 45 67 89 AB CD EF"),
-	      H("7A C8 16 D1 6E 9B 30 2E"));
+	      "01 23 45 67 12",
+	      "01 23 45 67 89 AB CD EF",
+	      "7A C8 16 D1 6E 9B 30 2E");
 
   SUCCESS();
 }
diff --git a/testsuite/cbc-test.c b/testsuite/cbc-test.c
index b7bd2dd..d877775 100644
--- a/testsuite/cbc-test.c
+++ b/testsuite/cbc-test.c
@@ -68,13 +68,19 @@ test_cbc_bulk(void)
 
   if (!MEMEQ(CBC_BULK_DATA, clear, cipher))
     FAIL();
+
+  free((void *)end_iv);
+  free((void *)start_iv);
+  free((void *)key);
 }
 
 int
 test_main(void)
 {
   static const uint8_t msg[2 * AES_BLOCK_SIZE] = "Listen, I'll say this only once!";
-  
+
+  const uint8_t *msg_hex = encode_hex_dup(msg, sizeof(msg));
+
   /* Intermediate values:
    *   iv XOR first message block:
    *       "a5 ce 55 d4 21 15 a1 c6 4a a4 0c b2 ca a6 d1 37"
@@ -87,16 +93,18 @@ test_main(void)
    */
 
   test_cipher_cbc(&nettle_aes256,
-		  HL("8d ae 93 ff fc 78 c9 44"
+		  "8d ae 93 ff fc 78 c9 44"
 		     "2a bd 0c 1e 68 bc a6 c7"
 		     "05 c7 84 e3 5a a9 11 8b"
-		     "d3 16 aa 54 9b 44 08 9e"),
-		  2 * AES_BLOCK_SIZE, msg,
-		  H("1f 94 fc 85 f2 36 21 06"
+		     "d3 16 aa 54 9b 44 08 9e",
+		  msg_hex,
+		  "1f 94 fc 85 f2 36 21 06"
 		    "4a ea e3 c9 cc 38 01 0e"
 		    "7b f6 5f c5 02 59 2e 71"
-		    "af bf 34 87 c0 36 2a 16"),
-		  H("e9 a7 26 a0 44 7b 8d e6  03 83 60 de ea d5 b0 4e"));
+		    "af bf 34 87 c0 36 2a 16",
+		  "e9 a7 26 a0 44 7b 8d e6  03 83 60 de ea d5 b0 4e");
+
+  free((void *)msg_hex);
 
   /* From NIST spec 800-38a on AES modes.
    *
@@ -112,16 +120,16 @@ test_main(void)
    *   8521f2fd3c8eef2cdc3da7e5c44ea206 
    */
   test_cipher_cbc(&nettle_aes128,
-		  HL("2b7e151628aed2a6abf7158809cf4f3c"),
-		  HL("6bc1bee22e409f96e93d7e117393172a"
+		  "2b7e151628aed2a6abf7158809cf4f3c",
+		  "6bc1bee22e409f96e93d7e117393172a"
 		     "ae2d8a571e03ac9c9eb76fac45af8e51"
 		     "30c81c46a35ce411e5fbc1191a0a52ef"
-		     "f69f2445df4f9b17ad2b417be66c3710"),
-		  H("7649abac8119b246cee98e9b12e9197d"
+		     "f69f2445df4f9b17ad2b417be66c3710",
+		  "7649abac8119b246cee98e9b12e9197d"
 		    "5086cb9b507219ee95db113a917678b2"
 		    "73bed6b8e3c1743b7116e69e22229516"
-		    "3ff1caa1681fac09120eca307586e1a7"),
-		  H("000102030405060708090a0b0c0d0e0f"));
+		    "3ff1caa1681fac09120eca307586e1a7",
+		  "000102030405060708090a0b0c0d0e0f");
   
   /* F.2.3 CBC-AES192.Encrypt */
   
@@ -134,17 +142,17 @@ test_main(void)
    */
 
   test_cipher_cbc(&nettle_aes192,
-		  HL("8e73b0f7da0e6452c810f32b809079e5"
-		     "62f8ead2522c6b7b"),
-		  HL("6bc1bee22e409f96e93d7e117393172a"
+		  "8e73b0f7da0e6452c810f32b809079e5"
+		     "62f8ead2522c6b7b",
+		  "6bc1bee22e409f96e93d7e117393172a"
 		     "ae2d8a571e03ac9c9eb76fac45af8e51"
 		     "30c81c46a35ce411e5fbc1191a0a52ef"
-		     "f69f2445df4f9b17ad2b417be66c3710"),
-		  H("4f021db243bc633d7178183a9fa071e8"
+		     "f69f2445df4f9b17ad2b417be66c3710",
+		  "4f021db243bc633d7178183a9fa071e8"
 		    "b4d9ada9ad7dedf4e5e738763f69145a"
 		    "571b242012fb7ae07fa9baac3df102e0"
-		    "08b0e27988598881d920a9e64f5615cd"),
-		  H("000102030405060708090a0b0c0d0e0f"));
+		    "08b0e27988598881d920a9e64f5615cd",
+		  "000102030405060708090a0b0c0d0e0f");
    
   /* F.2.5 CBC-AES256.Encrypt */
 
@@ -157,17 +165,17 @@ test_main(void)
    */
 
   test_cipher_cbc(&nettle_aes256,
-		  HL("603deb1015ca71be2b73aef0857d7781"
-		     "1f352c073b6108d72d9810a30914dff4"),
-		  HL("6bc1bee22e409f96e93d7e117393172a"
+		  "603deb1015ca71be2b73aef0857d7781"
+		     "1f352c073b6108d72d9810a30914dff4",
+		  "6bc1bee22e409f96e93d7e117393172a"
 		     "ae2d8a571e03ac9c9eb76fac45af8e51"
 		     "30c81c46a35ce411e5fbc1191a0a52ef"
-		     "f69f2445df4f9b17ad2b417be66c3710"),
-		  H("f58c4c04d6e5f1ba779eabfb5f7bfbd6"
+		     "f69f2445df4f9b17ad2b417be66c3710",
+		  "f58c4c04d6e5f1ba779eabfb5f7bfbd6"
 		    "9cfc4e967edb808d679f777bc6702c7d"
 		    "39f23369a9d9bacfa530e26304231461"
-		    "b2eb05e2c39be9fcda6c19078c6a9d1b"),
-		  H("000102030405060708090a0b0c0d0e0f"));
+		    "b2eb05e2c39be9fcda6c19078c6a9d1b",
+		  "000102030405060708090a0b0c0d0e0f");
 
   test_cbc_bulk();
    
diff --git a/testsuite/ctr-test.c b/testsuite/ctr-test.c
index 15c74d5..6b3c3fa 100644
--- a/testsuite/ctr-test.c
+++ b/testsuite/ctr-test.c
@@ -14,43 +14,43 @@ test_main(void)
 
   /* F.5.1  CTR-AES128.Encrypt */
   test_cipher_ctr(&nettle_aes128,
-		  HL("2b7e151628aed2a6abf7158809cf4f3c"),
-		  HL("6bc1bee22e409f96e93d7e117393172a"
+		  "2b7e151628aed2a6abf7158809cf4f3c",
+		  "6bc1bee22e409f96e93d7e117393172a"
 		     "ae2d8a571e03ac9c9eb76fac45af8e51"
 		     "30c81c46a35ce411e5fbc1191a0a52ef"
-		     "f69f2445df4f9b17ad2b417be66c3710"),
-		  H("874d6191b620e3261bef6864990db6ce"
+		     "f69f2445df4f9b17ad2b417be66c3710",
+		  "874d6191b620e3261bef6864990db6ce"
 		    "9806f66b7970fdff8617187bb9fffdff"
 		    "5ae4df3edbd5d35e5b4f09020db03eab"
-		    "1e031dda2fbe03d1792170a0f3009cee"),
-		  H("f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff"));
+		    "1e031dda2fbe03d1792170a0f3009cee",
+		  "f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff");
 
   /* F.5.3  CTR-AES192.Encrypt */
   test_cipher_ctr(&nettle_aes192,
-		  HL("8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b"),
-		  HL("6bc1bee22e409f96e93d7e117393172a"
+		  "8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b",
+		  "6bc1bee22e409f96e93d7e117393172a"
 		     "ae2d8a571e03ac9c9eb76fac45af8e51"
 		     "30c81c46a35ce411e5fbc1191a0a52ef"
-		     "f69f2445df4f9b17ad2b417be66c3710"),
-		  H("1abc932417521ca24f2b0459fe7e6e0b"
+		     "f69f2445df4f9b17ad2b417be66c3710",
+		  "1abc932417521ca24f2b0459fe7e6e0b"
 		     "090339ec0aa6faefd5ccc2c6f4ce8e94"
 		     "1e36b26bd1ebc670d1bd1d665620abf7"
-		     "4f78a7f6d29809585a97daec58c6b050"),
-		  H("f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff"));
+		     "4f78a7f6d29809585a97daec58c6b050",
+		  "f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff");
 
   /* F.5.5  CTR-AES256.Encrypt */
   test_cipher_ctr(&nettle_aes256,
-		  HL("603deb1015ca71be2b73aef0857d7781"
-		     "1f352c073b6108d72d9810a30914dff4"),
-		  HL("6bc1bee22e409f96e93d7e117393172a"
+		  "603deb1015ca71be2b73aef0857d7781"
+		     "1f352c073b6108d72d9810a30914dff4",
+		  "6bc1bee22e409f96e93d7e117393172a"
 		     "ae2d8a571e03ac9c9eb76fac45af8e51"
 		     "30c81c46a35ce411e5fbc1191a0a52ef"
-		     "f69f2445df4f9b17ad2b417be66c3710"),
-		  H("601ec313775789a5b7a7f504bbf3d228"
+		     "f69f2445df4f9b17ad2b417be66c3710",
+		  "601ec313775789a5b7a7f504bbf3d228"
 		     "f443e3ca4d62b59aca84e990cacaf5c5"
 		     "2b0930daa23de94ce87017ba2d84988d"
-		     "dfc9c58db67aada613c2dd08457941a6"),
-		  H("f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff"));
+		     "dfc9c58db67aada613c2dd08457941a6",
+		  "f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff");
 
   SUCCESS();
 }
diff --git a/testsuite/cxx-test.cxx b/testsuite/cxx-test.cxx
index b5635fb..4411956 100644
--- a/testsuite/cxx-test.cxx
+++ b/testsuite/cxx-test.cxx
@@ -10,15 +10,18 @@ test_main(void)
 {
   struct md5_ctx md5;
   uint8_t digest[MD5_DIGEST_SIZE];
+  const uint8_t *result;
 
   md5_init (&md5);
   md5_update (&md5, 14, reinterpret_cast<const uint8_t *> ("message digest"));
   md5_digest (&md5, MD5_DIGEST_SIZE, digest);
 
-  if (!MEMEQH (MD5_DIGEST_SIZE, digest,
-	       "F96B697D7CB7938D 525A2F31AAF161D0"))
+  result = decode_hex_dup("F96B697D7CB7938D 525A2F31AAF161D0");
+  if (!MEMEQ (MD5_DIGEST_SIZE, digest, result))
     FAIL();
 
+  free((void *)result);
+
 #if WITH_PUBLIC_KEY
 
   struct rsa_public_key pub;
diff --git a/testsuite/des-test.c b/testsuite/des-test.c
index 244e5aa..4d1ce64 100644
--- a/testsuite/des-test.c
+++ b/testsuite/des-test.c
@@ -2,12 +2,18 @@
 #include "nettle-internal.h"
 #include "des.h"
 
+#define STR_TO_HEX(a) encode_hex_dup(a, strlen(a))
+
 static void
-test_des(const uint8_t *key, int expected_parity,
-	 unsigned length,
-	 const uint8_t *cleartext,
-	 const uint8_t *ciphertext)
+test_des(const uint8_t *key_hex, int expected_parity,
+	 const uint8_t *cleartext_hex,
+	 const uint8_t *ciphertext_hex)
 {
+  const uint8_t *key = decode_hex_dup(key_hex);
+  unsigned length = decode_hex_length(cleartext_hex);
+  const uint8_t *cleartext = decode_hex_dup(cleartext_hex);
+  const uint8_t *ciphertext = decode_hex_dup(ciphertext_hex);
+
   struct des_ctx ctx;
   uint8_t *data = xalloc(length);
 
@@ -46,77 +52,98 @@ test_des(const uint8_t *key, int expected_parity,
     }
 
   free(data);
+  free((void *)ciphertext);
+  free((void *)cleartext);
+  free((void *)key);
+}
+
+static int
+test_des_check_parity(const uint8_t *key_hex)
+{
+  unsigned length = decode_hex_length(key_hex);
+  const uint8_t *key = decode_hex_dup(key_hex);
+  int rc = des_check_parity(8, key);
+
+  free((void *)key);
+  return rc;
 }
 
 static void
-test_weak(const uint8_t *key)
+test_weak(const uint8_t *key_hex)
 {
   struct des_ctx ctx;
+  const uint8_t *key = decode_hex_dup(key_hex);
 
   if (des_set_key(&ctx, key))
     FAIL();
+
+  free((void *)key);
 }
 
 int
 test_main(void)
 {
+  const uint8_t *cleartext_hex = STR_TO_HEX("Now is t");
+
   /* From Applied Cryptography */
-  test_des(H("01234567 89ABCDEF"), 1,
-	   HL("01234567 89ABCDE7"),
-	   H("C9574425 6A5ED31D"));
+  test_des("01234567 89ABCDEF", 1,
+	   "01234567 89ABCDE7",
+	   "C9574425 6A5ED31D");
 
-  test_des(H("01 01 01 01 01 01 01 80"), 1,
-	   HL("00 00 00 00 00 00 00 00"),
-	   H("9C C6 2D F4 3B 6E ED 74"));
+  test_des("01 01 01 01 01 01 01 80", 1,
+	   "00 00 00 00 00 00 00 00",
+	   "9C C6 2D F4 3B 6E ED 74");
 
-  test_des(H("80 01 01 01 01 01 01 01"), 1,
-	   HL("00 00 00 00 00 00 00 40"),
-	   H("A3 80 E0 2A 6B E5 46 96"));
+  test_des("80 01 01 01 01 01 01 01", 1,
+	   "00 00 00 00 00 00 00 40",
+	   "A3 80 E0 2A 6B E5 46 96");
 
-  test_des(H("08 19 2A 3B 4C 5D 6E 7F"), 1,
-	   HL("00 00 00 00 00 00 00 00"),
-	   H("25 DD AC 3E 96 17 64 67"));
+  test_des("08 19 2A 3B 4C 5D 6E 7F", 1,
+	   "00 00 00 00 00 00 00 00",
+	   "25 DD AC 3E 96 17 64 67");
 
-  test_des(H("01 23 45 67 89 AB CD EF"), 1,
-	   DES_BLOCK_SIZE, "Now is t",
-	   H("3F A4 0E 8A 98 4D 48 15"));
+  test_des("01 23 45 67 89 AB CD EF", 1,
+	   cleartext_hex,
+	   "3F A4 0E 8A 98 4D 48 15");
 
   /* Same key, but with one bad parity bit, */
-  test_des(H("01 23 45 66 89 AB CD EF"), 0,
-	   DES_BLOCK_SIZE, "Now is t",
-	   H("3F A4 0E 8A 98 4D 48 15"));
+  test_des("01 23 45 66 89 AB CD EF", 0,
+	   cleartext_hex,
+	   "3F A4 0E 8A 98 4D 48 15");
 
   /* Parity check */
-  if (des_check_parity(HL("01 01 01 01 01 01 01 00")))
+  if (test_des_check_parity("01 01 01 01 01 01 01 00"))
     FAIL();
 
   /* The four weak keys */
-  test_weak(H("01 01 01 01 01 01 01 01"));  
-  test_weak(H("FE FE FE FE FE FE FE FE"));
-  test_weak(H("1F 1F 1F 1F 0E 0E 0E 0E"));
-  test_weak(H("E0 E0 E0 E0 F1 F1 F1 F1"));
+  test_weak("01 01 01 01 01 01 01 01");  
+  test_weak("FE FE FE FE FE FE FE FE");
+  test_weak("1F 1F 1F 1F 0E 0E 0E 0E");
+  test_weak("E0 E0 E0 E0 F1 F1 F1 F1");
 
   /* Same weak key, but different parity. */
-  test_weak(H("E0 E0 E0 E0 F0 F1 F1 F1"));
+  test_weak("E0 E0 E0 E0 F0 F1 F1 F1");
 
   /* The six pairs of semiweak keys */
-  test_weak(H("01 FE 01 FE 01 FE 01 FE"));
-  test_weak(H("FE 01 FE 01 FE 01 FE 01"));
+  test_weak("01 FE 01 FE 01 FE 01 FE");
+  test_weak("FE 01 FE 01 FE 01 FE 01");
+
+  test_weak("1F E0 1F E0 0E F1 0E F1");
+  test_weak("E0 1F E0 1F F1 0E F1 0E");
 
-  test_weak(H("1F E0 1F E0 0E F1 0E F1"));
-  test_weak(H("E0 1F E0 1F F1 0E F1 0E"));
+  test_weak("01 E0 01 E0 01 F1 01 F1");
+  test_weak("E0 01 E0 01 F1 01 F1 01");
 
-  test_weak(H("01 E0 01 E0 01 F1 01 F1"));
-  test_weak(H("E0 01 E0 01 F1 01 F1 01"));
+  test_weak("1F FE 1F FE 0E FE 0E FE");
+  test_weak("FE 1F FE 1F FE 0E FE 0E");
 
-  test_weak(H("1F FE 1F FE 0E FE 0E FE"));
-  test_weak(H("FE 1F FE 1F FE 0E FE 0E"));
+  test_weak("01 1F 01 1F 01 0E 01 0E");
+  test_weak("1F 01 1F 01 0E 01 0E 01");
 
-  test_weak(H("01 1F 01 1F 01 0E 01 0E"));
-  test_weak(H("1F 01 1F 01 0E 01 0E 01"));
+  test_weak("E0 FE E0 FE F1 FE F1 FE");
+  test_weak("FE E0 FE E0 FE F1 FE F1");
 
-  test_weak(H("E0 FE E0 FE F1 FE F1 FE"));
-  test_weak(H("FE E0 FE E0 FE F1 FE F1"));
+  free((void *)cleartext_hex);
 
   SUCCESS();
 }
diff --git a/testsuite/des3-test.c b/testsuite/des3-test.c
index 678a235..796e776 100644
--- a/testsuite/des3-test.c
+++ b/testsuite/des3-test.c
@@ -2,20 +2,26 @@
 #include "nettle-internal.h"
 #include "des.h"
 
+#define STR_TO_HEX(a) encode_hex_dup(a, strlen(a))
+
 int
 test_main(void)
 {
+  const uint8_t *cleartext_hex = STR_TO_HEX("Now is t");
+
   /* Intermediate values:
    *   After first DES encryption:  "cd ea 2a 20 c2 e0 9e 48"
    *   After second DES decryption: "69 52 6e 95 8b ea 49 bd"
    */
 
   test_cipher(&nettle_des3,
-	      HL("3e 0b 10 b0 5d 49 c2 54"
+	      "3e 0b 10 b0 5d 49 c2 54"
 		 "6b 46 e0 75 8a 91 61 85"
-		 "cb 04 07 d3 20 16 cb a2"),
-	      DES_BLOCK_SIZE, "Now is t",
-	      H("0a 5d b5 2d 85 74 d1 c9"));
+		 "cb 04 07 d3 20 16 cb a2",
+	      cleartext_hex,
+	      "0a 5d b5 2d 85 74 d1 c9");
+
+  free((void *)cleartext_hex);
 
   SUCCESS();
 }
diff --git a/testsuite/gcm-test.c b/testsuite/gcm-test.c
index a1cf964..ef82f39 100644
--- a/testsuite/gcm-test.c
+++ b/testsuite/gcm-test.c
@@ -12,267 +12,267 @@ test_main(void)
 
   /* Test case 1 */
   test_aead(&nettle_gcm_aes128,
-	    /* key */HL("00000000000000000000000000000000"),
-	    /* auth data */ HL(""),
-	    /* plaintext */HL(""),
-	    /* ciphertext*/H(""),
-	    /* IV */HL("000000000000000000000000"),
-	    /* tag */H("58e2fccefa7e3061367f1d57a4e7455a"));
+	    /* key */"00000000000000000000000000000000",
+	    /* auth data */ "",
+	    /* plaintext */"",
+	    /* ciphertext*/"",
+	    /* IV */"000000000000000000000000",
+	    /* tag */"58e2fccefa7e3061367f1d57a4e7455a");
 
   /* Test case 2 */
   test_aead(&nettle_gcm_aes128,
-	    HL("00000000000000000000000000000000"),
-	    HL(""),
-	    HL("00000000000000000000000000000000"),
-	    H("0388dace60b6a392f328c2b971b2fe78"),
-	    HL("000000000000000000000000"),
-	    H("ab6e47d42cec13bdf53a67b21257bddf"));
+	    "00000000000000000000000000000000",
+	    "",
+	    "00000000000000000000000000000000",
+	    "0388dace60b6a392f328c2b971b2fe78",
+	    "000000000000000000000000",
+	    "ab6e47d42cec13bdf53a67b21257bddf");
 
   /* Test case 3 */
   test_aead(&nettle_gcm_aes128,
-	    HL("feffe9928665731c6d6a8f9467308308"),
-	    HL(""),
-	    HL("d9313225f88406e5a55909c5aff5269a"
+	    "feffe9928665731c6d6a8f9467308308",
+	    "",
+	    "d9313225f88406e5a55909c5aff5269a"
 	       "86a7a9531534f7da2e4c303d8a318a72"
 	       "1c3c0c95956809532fcf0e2449a6b525"
-	       "b16aedf5aa0de657ba637b391aafd255"),
-	    H("42831ec2217774244b7221b784d0d49c"
+	       "b16aedf5aa0de657ba637b391aafd255",
+	    "42831ec2217774244b7221b784d0d49c"
 	      "e3aa212f2c02a4e035c17e2329aca12e"
 	      "21d514b25466931c7d8f6a5aac84aa05"
-	      "1ba30b396a0aac973d58e091473f5985"),
-	    HL("cafebabefacedbaddecaf888"),
-	    H("4d5c2af327cd64a62cf35abd2ba6fab4"));
+	      "1ba30b396a0aac973d58e091473f5985",
+	    "cafebabefacedbaddecaf888",
+	    "4d5c2af327cd64a62cf35abd2ba6fab4");
 
   /* Test case 4 */
   test_aead(&nettle_gcm_aes128,
-	    HL("feffe9928665731c6d6a8f9467308308"),
-	    HL("feedfacedeadbeeffeedfacedeadbeef"
-	       "abaddad2"),
-	    HL("d9313225f88406e5a55909c5aff5269a"
+	    "feffe9928665731c6d6a8f9467308308",
+	    "feedfacedeadbeeffeedfacedeadbeef"
+	       "abaddad2",
+	    "d9313225f88406e5a55909c5aff5269a"
 	       "86a7a9531534f7da2e4c303d8a318a72"
 	       "1c3c0c95956809532fcf0e2449a6b525"
-	       "b16aedf5aa0de657ba637b39"),
-	    H("42831ec2217774244b7221b784d0d49c"
+	       "b16aedf5aa0de657ba637b39",
+	    "42831ec2217774244b7221b784d0d49c"
 	      "e3aa212f2c02a4e035c17e2329aca12e"
 	      "21d514b25466931c7d8f6a5aac84aa05"
-	      "1ba30b396a0aac973d58e091"),
-	    HL("cafebabefacedbaddecaf888"),
-	    H("5bc94fbc3221a5db94fae95ae7121a47"));
+	      "1ba30b396a0aac973d58e091",
+	    "cafebabefacedbaddecaf888",
+	    "5bc94fbc3221a5db94fae95ae7121a47");
 
   /* Test case 5 */
   test_aead(&nettle_gcm_aes128,
-	    HL("feffe9928665731c6d6a8f9467308308"),
-	    HL("feedfacedeadbeeffeedfacedeadbeef"
-	       "abaddad2"),
-	    HL("d9313225f88406e5a55909c5aff5269a"
+	    "feffe9928665731c6d6a8f9467308308",
+	    "feedfacedeadbeeffeedfacedeadbeef"
+	       "abaddad2",
+	    "d9313225f88406e5a55909c5aff5269a"
 	       "86a7a9531534f7da2e4c303d8a318a72"
 	       "1c3c0c95956809532fcf0e2449a6b525"
-	       "b16aedf5aa0de657ba637b39"),
-	    H("61353b4c2806934a777ff51fa22a4755"
+	       "b16aedf5aa0de657ba637b39",
+	    "61353b4c2806934a777ff51fa22a4755"
 	      "699b2a714fcdc6f83766e5f97b6c7423"
 	      "73806900e49f24b22b097544d4896b42"
-	      "4989b5e1ebac0f07c23f4598"),
-	    HL("cafebabefacedbad"),
-	    H("3612d2e79e3b0785561be14aaca2fccb"));
+	      "4989b5e1ebac0f07c23f4598",
+	    "cafebabefacedbad",
+	    "3612d2e79e3b0785561be14aaca2fccb");
 
   /* Test case 6 */
   test_aead(&nettle_gcm_aes128,
-	    HL("feffe9928665731c6d6a8f9467308308"),
-	    HL("feedfacedeadbeeffeedfacedeadbeef"
-	       "abaddad2"),
-	    HL("d9313225f88406e5a55909c5aff5269a"
+	    "feffe9928665731c6d6a8f9467308308",
+	    "feedfacedeadbeeffeedfacedeadbeef"
+	       "abaddad2",
+	    "d9313225f88406e5a55909c5aff5269a"
 	       "86a7a9531534f7da2e4c303d8a318a72"
 	       "1c3c0c95956809532fcf0e2449a6b525"
-	       "b16aedf5aa0de657ba637b39"),
-	    H("8ce24998625615b603a033aca13fb894"
+	       "b16aedf5aa0de657ba637b39",
+	    "8ce24998625615b603a033aca13fb894"
 	      "be9112a5c3a211a8ba262a3cca7e2ca7"
 	      "01e4a9a4fba43c90ccdcb281d48c7c6f"
-	      "d62875d2aca417034c34aee5"),
-	    HL("9313225df88406e555909c5aff5269aa"
+	      "d62875d2aca417034c34aee5",
+	    "9313225df88406e555909c5aff5269aa"
 	       "6a7a9538534f7da1e4c303d2a318a728"
 	       "c3c0c95156809539fcf0e2429a6b5254"
-	       "16aedbf5a0de6a57a637b39b"),
-	    H("619cc5aefffe0bfa462af43c1699d050"));
+	       "16aedbf5a0de6a57a637b39b",
+	    "619cc5aefffe0bfa462af43c1699d050");
   
   /* Test case 7 */
   test_aead(&nettle_gcm_aes128,
-	    HL("00000000000000000000000000000000"
-	       "0000000000000000"),
-	    HL(""),
-	    HL(""),
-	    H(""),
-	    HL("000000000000000000000000"),
-	    H("cd33b28ac773f74ba00ed1f312572435"));
+	    "00000000000000000000000000000000"
+	       "0000000000000000",
+	    "",
+	    "",
+	    "",
+	    "000000000000000000000000",
+	    "cd33b28ac773f74ba00ed1f312572435");
 
   /* Test case 8 */
   test_aead(&nettle_gcm_aes128,
-	    HL("00000000000000000000000000000000"
-	       "0000000000000000"),
-	    HL(""),
-	    HL("00000000000000000000000000000000"),
-	    H("98e7247c07f0fe411c267e4384b0f600"),
-	    HL("000000000000000000000000"),
-	    H("2ff58d80033927ab8ef4d4587514f0fb"));
+	    "00000000000000000000000000000000"
+	       "0000000000000000",
+	    "",
+	    "00000000000000000000000000000000",
+	    "98e7247c07f0fe411c267e4384b0f600",
+	    "000000000000000000000000",
+	    "2ff58d80033927ab8ef4d4587514f0fb");
 
   /* Test case 9 */
   test_aead(&nettle_gcm_aes128,
-	    HL("feffe9928665731c6d6a8f9467308308"
-	       "feffe9928665731c"),
-	    HL(""),
-	    HL("d9313225f88406e5a55909c5aff5269a"
+	    "feffe9928665731c6d6a8f9467308308"
+	       "feffe9928665731c",
+	    "",
+	    "d9313225f88406e5a55909c5aff5269a"
 	       "86a7a9531534f7da2e4c303d8a318a72"
 	       "1c3c0c95956809532fcf0e2449a6b525"
-	       "b16aedf5aa0de657ba637b391aafd255"),
-	    H("3980ca0b3c00e841eb06fac4872a2757"
+	       "b16aedf5aa0de657ba637b391aafd255",
+	    "3980ca0b3c00e841eb06fac4872a2757"
 	      "859e1ceaa6efd984628593b40ca1e19c"
 	      "7d773d00c144c525ac619d18c84a3f47"
-	      "18e2448b2fe324d9ccda2710acade256"),
-	    HL("cafebabefacedbaddecaf888"),
-	    H("9924a7c8587336bfb118024db8674a14"));
+	      "18e2448b2fe324d9ccda2710acade256",
+	    "cafebabefacedbaddecaf888",
+	    "9924a7c8587336bfb118024db8674a14");
 
   /* Test case 10 */
   test_aead(&nettle_gcm_aes128,
-	    HL("feffe9928665731c6d6a8f9467308308"
-	       "feffe9928665731c"),
-	    HL("feedfacedeadbeeffeedfacedeadbeef"
-	       "abaddad2"),
-	    HL("d9313225f88406e5a55909c5aff5269a"
+	    "feffe9928665731c6d6a8f9467308308"
+	       "feffe9928665731c",
+	    "feedfacedeadbeeffeedfacedeadbeef"
+	       "abaddad2",
+	    "d9313225f88406e5a55909c5aff5269a"
 	       "86a7a9531534f7da2e4c303d8a318a72"
 	       "1c3c0c95956809532fcf0e2449a6b525"
-	       "b16aedf5aa0de657ba637b39"),
-	    H("3980ca0b3c00e841eb06fac4872a2757"
+	       "b16aedf5aa0de657ba637b39",
+	    "3980ca0b3c00e841eb06fac4872a2757"
 	      "859e1ceaa6efd984628593b40ca1e19c"
 	      "7d773d00c144c525ac619d18c84a3f47"
-	      "18e2448b2fe324d9ccda2710"),
-	    HL("cafebabefacedbaddecaf888"),
-	    H("2519498e80f1478f37ba55bd6d27618c"));
+	      "18e2448b2fe324d9ccda2710",
+	    "cafebabefacedbaddecaf888",
+	    "2519498e80f1478f37ba55bd6d27618c");
 
   /* Test case 11 */
   test_aead(&nettle_gcm_aes128,
-	    HL("feffe9928665731c6d6a8f9467308308"
-	       "feffe9928665731c"),
-	    HL("feedfacedeadbeeffeedfacedeadbeef"
-	       "abaddad2"),
-	    HL("d9313225f88406e5a55909c5aff5269a"
+	    "feffe9928665731c6d6a8f9467308308"
+	       "feffe9928665731c",
+	    "feedfacedeadbeeffeedfacedeadbeef"
+	       "abaddad2",
+	    "d9313225f88406e5a55909c5aff5269a"
 	       "86a7a9531534f7da2e4c303d8a318a72"
 	       "1c3c0c95956809532fcf0e2449a6b525"
-	       "b16aedf5aa0de657ba637b39"),
-	    H("0f10f599ae14a154ed24b36e25324db8"
+	       "b16aedf5aa0de657ba637b39",
+	    "0f10f599ae14a154ed24b36e25324db8"
 	      "c566632ef2bbb34f8347280fc4507057"
 	      "fddc29df9a471f75c66541d4d4dad1c9"
-	      "e93a19a58e8b473fa0f062f7"),
-	    HL("cafebabefacedbad"),
-	    H("65dcc57fcf623a24094fcca40d3533f8"));
+	      "e93a19a58e8b473fa0f062f7",
+	    "cafebabefacedbad",
+	    "65dcc57fcf623a24094fcca40d3533f8");
 
   /* Test case 12 */
   test_aead(&nettle_gcm_aes128,
-	    HL("feffe9928665731c6d6a8f9467308308"
-	       "feffe9928665731c"),
-	    HL("feedfacedeadbeeffeedfacedeadbeef"
-	       "abaddad2"),
-	    HL("d9313225f88406e5a55909c5aff5269a"
+	    "feffe9928665731c6d6a8f9467308308"
+	       "feffe9928665731c",
+	    "feedfacedeadbeeffeedfacedeadbeef"
+	       "abaddad2",
+	    "d9313225f88406e5a55909c5aff5269a"
 	       "86a7a9531534f7da2e4c303d8a318a72"
 	       "1c3c0c95956809532fcf0e2449a6b525"
-	       "b16aedf5aa0de657ba637b39"),
-	    H("d27e88681ce3243c4830165a8fdcf9ff"
+	       "b16aedf5aa0de657ba637b39",
+	    "d27e88681ce3243c4830165a8fdcf9ff"
 	      "1de9a1d8e6b447ef6ef7b79828666e45"
 	      "81e79012af34ddd9e2f037589b292db3"
-	      "e67c036745fa22e7e9b7373b"),
-	    HL("9313225df88406e555909c5aff5269aa"
+	      "e67c036745fa22e7e9b7373b",
+	    "9313225df88406e555909c5aff5269aa"
 	       "6a7a9538534f7da1e4c303d2a318a728"
 	       "c3c0c95156809539fcf0e2429a6b5254"
-	       "16aedbf5a0de6a57a637b39b"),
-	    H("dcf566ff291c25bbb8568fc3d376a6d9"));
+	       "16aedbf5a0de6a57a637b39b",
+	    "dcf566ff291c25bbb8568fc3d376a6d9");
 
   /* Test case 13 */
   test_aead(&nettle_gcm_aes128,
-	    HL("00000000000000000000000000000000"
-	       "00000000000000000000000000000000"),
-	    HL(""),
-	    HL(""),
-	    H(""),
-	    HL("000000000000000000000000"),
-	    H("530f8afbc74536b9a963b4f1c4cb738b"));
+	    "00000000000000000000000000000000"
+	       "00000000000000000000000000000000",
+	    "",
+	    "",
+	    "",
+	    "000000000000000000000000",
+	    "530f8afbc74536b9a963b4f1c4cb738b");
 
   /* Test case 14 */
   test_aead(&nettle_gcm_aes128,
-	    HL("00000000000000000000000000000000"
-	       "00000000000000000000000000000000"),
-	    HL(""),
-	    HL("00000000000000000000000000000000"),
-	    H("cea7403d4d606b6e074ec5d3baf39d18"),
-	    HL("000000000000000000000000"),
-	    H("d0d1c8a799996bf0265b98b5d48ab919"));
+	    "00000000000000000000000000000000"
+	       "00000000000000000000000000000000",
+	    "",
+	    "00000000000000000000000000000000",
+	    "cea7403d4d606b6e074ec5d3baf39d18",
+	    "000000000000000000000000",
+	    "d0d1c8a799996bf0265b98b5d48ab919");
 
   /* Test case 15 */
   test_aead(&nettle_gcm_aes128,
-	    HL("feffe9928665731c6d6a8f9467308308"
-	       "feffe9928665731c6d6a8f9467308308"),
-	    HL(""),
-	    HL("d9313225f88406e5a55909c5aff5269a"
+	    "feffe9928665731c6d6a8f9467308308"
+	       "feffe9928665731c6d6a8f9467308308",
+	    "",
+	    "d9313225f88406e5a55909c5aff5269a"
 	       "86a7a9531534f7da2e4c303d8a318a72"
 	       "1c3c0c95956809532fcf0e2449a6b525"
-	       "b16aedf5aa0de657ba637b391aafd255"),
-	    H("522dc1f099567d07f47f37a32a84427d"
+	       "b16aedf5aa0de657ba637b391aafd255",
+	    "522dc1f099567d07f47f37a32a84427d"
 	      "643a8cdcbfe5c0c97598a2bd2555d1aa"
 	      "8cb08e48590dbb3da7b08b1056828838"
-	      "c5f61e6393ba7a0abcc9f662898015ad"),
-	    HL("cafebabefacedbaddecaf888"),
-	    H("b094dac5d93471bdec1a502270e3cc6c"));
+	      "c5f61e6393ba7a0abcc9f662898015ad",
+	    "cafebabefacedbaddecaf888",
+	    "b094dac5d93471bdec1a502270e3cc6c");
 
   /* Test case 16 */
   test_aead(&nettle_gcm_aes128,
-	    HL("feffe9928665731c6d6a8f9467308308"
-	       "feffe9928665731c6d6a8f9467308308"),
-	    HL("feedfacedeadbeeffeedfacedeadbeef"
-	       "abaddad2"),
-	    HL("d9313225f88406e5a55909c5aff5269a"
+	    "feffe9928665731c6d6a8f9467308308"
+	       "feffe9928665731c6d6a8f9467308308",
+	    "feedfacedeadbeeffeedfacedeadbeef"
+	       "abaddad2",
+	    "d9313225f88406e5a55909c5aff5269a"
 	       "86a7a9531534f7da2e4c303d8a318a72"
 	       "1c3c0c95956809532fcf0e2449a6b525"
-	       "b16aedf5aa0de657ba637b39"),
-	    H("522dc1f099567d07f47f37a32a84427d"
+	       "b16aedf5aa0de657ba637b39",
+	    "522dc1f099567d07f47f37a32a84427d"
 	      "643a8cdcbfe5c0c97598a2bd2555d1aa"
 	      "8cb08e48590dbb3da7b08b1056828838"
-	      "c5f61e6393ba7a0abcc9f662"),
-	    HL("cafebabefacedbaddecaf888"),
-	    H("76fc6ece0f4e1768cddf8853bb2d551b"));
+	      "c5f61e6393ba7a0abcc9f662",
+	    "cafebabefacedbaddecaf888",
+	    "76fc6ece0f4e1768cddf8853bb2d551b");
 
   /* Test case 17 */
   test_aead(&nettle_gcm_aes128,
-	    HL("feffe9928665731c6d6a8f9467308308"
-	       "feffe9928665731c6d6a8f9467308308"),
-	    HL("feedfacedeadbeeffeedfacedeadbeef"
-	       "abaddad2"),
-	    HL("d9313225f88406e5a55909c5aff5269a"
+	    "feffe9928665731c6d6a8f9467308308"
+	       "feffe9928665731c6d6a8f9467308308",
+	    "feedfacedeadbeeffeedfacedeadbeef"
+	       "abaddad2",
+	    "d9313225f88406e5a55909c5aff5269a"
 	       "86a7a9531534f7da2e4c303d8a318a72"
 	       "1c3c0c95956809532fcf0e2449a6b525"
-	       "b16aedf5aa0de657ba637b39"),
-	    H("c3762df1ca787d32ae47c13bf19844cb"
+	       "b16aedf5aa0de657ba637b39",
+	    "c3762df1ca787d32ae47c13bf19844cb"
 	      "af1ae14d0b976afac52ff7d79bba9de0"
 	      "feb582d33934a4f0954cc2363bc73f78"
-	      "62ac430e64abe499f47c9b1f"),
-	    HL("cafebabefacedbad"),
-	    H("3a337dbf46a792c45e454913fe2ea8f2"));
+	      "62ac430e64abe499f47c9b1f",
+	    "cafebabefacedbad",
+	    "3a337dbf46a792c45e454913fe2ea8f2");
 
   /* Test case 18 */
   test_aead(&nettle_gcm_aes128,
-	    HL("feffe9928665731c6d6a8f9467308308"
-	       "feffe9928665731c6d6a8f9467308308"),
-	    HL("feedfacedeadbeeffeedfacedeadbeef"
-	       "abaddad2"),
-	    HL("d9313225f88406e5a55909c5aff5269a"
+	    "feffe9928665731c6d6a8f9467308308"
+	       "feffe9928665731c6d6a8f9467308308",
+	    "feedfacedeadbeeffeedfacedeadbeef"
+	       "abaddad2",
+	    "d9313225f88406e5a55909c5aff5269a"
 	       "86a7a9531534f7da2e4c303d8a318a72"
 	       "1c3c0c95956809532fcf0e2449a6b525"
-	       "b16aedf5aa0de657ba637b39"),
-	    H("5a8def2f0c9e53f1f75d7853659e2a20"
+	       "b16aedf5aa0de657ba637b39",
+	    "5a8def2f0c9e53f1f75d7853659e2a20"
 	      "eeb2b22aafde6419a058ab4f6f746bf4"
 	      "0fc0c3b780f244452da3ebf1c5d82cde"
-	      "a2418997200ef82e44ae7e3f"),
-	    HL("9313225df88406e555909c5aff5269aa"
+	      "a2418997200ef82e44ae7e3f",
+	    "9313225df88406e555909c5aff5269aa"
 	       "6a7a9538534f7da1e4c303d2a318a728"
 	       "c3c0c95156809539fcf0e2429a6b5254"
-	       "16aedbf5a0de6a57a637b39b"),
-	    H("a44a8266ee1c8eb0c8b5d4cf5ae9f19a"));
+	       "16aedbf5a0de6a57a637b39b",
+	    "a44a8266ee1c8eb0c8b5d4cf5ae9f19a");
 
   SUCCESS();
 }
diff --git a/testsuite/hmac-test.c b/testsuite/hmac-test.c
index 0f14934..0356cf5 100644
--- a/testsuite/hmac-test.c
+++ b/testsuite/hmac-test.c
@@ -1,349 +1,435 @@
 #include "testutils.h"
 #include "hmac.h"
 
-/* KEY and MSG are supposed to expand to length, data */ 
-#define HMAC_TEST(alg, length, key, msg, mac) do {		\
-  hmac_##alg##_set_key(&alg, key);				\
-  hmac_##alg##_update(&alg, msg);				\
-  digest[length] = 17;						\
-  hmac_##alg##_digest(&alg, length, digest);			\
-  ASSERT(MEMEQ (length, digest, mac));				\
-  ASSERT(digest[length] == 17);					\
-} while (0)
+#define HEX_NONE 0
+#define HEX_KEY  1
+#define HEX_MSG   2
+
+enum {
+  alg_md5,
+  alg_ripemd160,
+  alg_sha1,
+  alg_sha224,
+  alg_sha256,
+  alg_sha384,
+  alg_sha512
+};
+
+static struct hmac_md5_ctx md5;
+static struct hmac_ripemd160_ctx ripemd160;
+static struct hmac_sha1_ctx sha1;
+static struct hmac_sha224_ctx sha224;
+static struct hmac_sha256_ctx sha256;
+static struct hmac_sha384_ctx sha384;
+static struct hmac_sha512_ctx sha512;
+
+/* sha512's digests are longest */
+static uint8_t digest[SHA512_DIGEST_SIZE+1];
+
+static void
+hmac_test(int alg,
+          unsigned digest_length,
+          int flags,
+          const uint8_t *key_hex,
+          const uint8_t *msg_hex,
+          const uint8_t *mac_hex)
+{
+  const uint8_t *key, *msg, *mac = decode_hex_dup(mac_hex);                                \
+  unsigned key_length, msg_length;
+
+  if (flags & HEX_KEY)
+    {
+      key_length = decode_hex_length(key_hex);
+      key = decode_hex_dup(key_hex);
+    }
+  else
+    {
+      key_length = strlen(key_hex);
+      key = key_hex;
+    }
+
+  if (flags & HEX_MSG)
+    {
+      msg_length = decode_hex_length(msg_hex);
+      msg = decode_hex_dup(msg_hex);
+    }
+  else
+    {
+      msg_length = strlen(msg_hex);
+      msg = msg_hex;
+    }
+
+  digest[digest_length] = 17;
+
+  switch (alg)
+    {
+    case alg_md5:
+        hmac_md5_set_key(&md5, key_length, key);
+        hmac_md5_update(&md5, msg_length, msg);
+        hmac_md5_digest(&md5, digest_length, digest);
+        break;
+    case alg_ripemd160:
+        hmac_ripemd160_set_key(&ripemd160, key_length, key);
+        hmac_ripemd160_update(&ripemd160, msg_length, msg);
+        hmac_ripemd160_digest(&ripemd160, digest_length, digest);
+        break;
+    case alg_sha1:
+        hmac_sha1_set_key(&sha1, key_length, key);
+        hmac_sha1_update(&sha1, msg_length, msg);
+        hmac_sha1_digest(&sha1, digest_length, digest);
+        break;
+    case alg_sha224:
+        hmac_sha224_set_key(&sha224, key_length, key);
+        hmac_sha224_update(&sha224, msg_length, msg);
+        hmac_sha224_digest(&sha224, digest_length, digest);
+        break;
+    case alg_sha256:
+        hmac_sha256_set_key(&sha256, key_length, key);
+        hmac_sha256_update(&sha256, msg_length, msg);
+        hmac_sha256_digest(&sha256, digest_length, digest);
+        break;
+    case alg_sha384:
+        hmac_sha384_set_key(&sha384, key_length, key);
+        hmac_sha384_update(&sha384, msg_length, msg);
+        hmac_sha384_digest(&sha384, digest_length, digest);
+        break;
+    case alg_sha512:
+        hmac_sha512_set_key(&sha512, key_length, key);
+        hmac_sha512_update(&sha512, msg_length, msg);
+        hmac_sha512_digest(&sha512, digest_length, digest);
+        break;
+    }
+
+  ASSERT(MEMEQ(digest_length, digest, mac));
+  ASSERT(digest[digest_length] == 17);
+
+  free((void *)mac);
+  if (flags & HEX_MSG)
+    free((void *)msg);
+  if (flags & HEX_KEY)
+    free((void *)key);
+}
 
 int
 test_main(void)
 {
-  struct hmac_md5_ctx md5;
-  struct hmac_sha1_ctx sha1;
-  struct hmac_ripemd160_ctx ripemd160;
-  struct hmac_sha224_ctx sha224;
-  struct hmac_sha256_ctx sha256;
-  struct hmac_sha384_ctx sha384;
-  struct hmac_sha512_ctx sha512;
-
-  /* sha512's digests are longest */
-  uint8_t digest[SHA512_DIGEST_SIZE+1];
-
-  memset(digest, 0, sizeof(digest));
-
   /* Test vectors for md5, from RFC-2202 */
 
   /* md5 - 1 */
-  HMAC_TEST(md5, MD5_DIGEST_SIZE,
-	    HL("0b0b0b0b0b0b0b0b 0b0b0b0b0b0b0b0b"),
-	    LDATA("Hi There"),
-	    H("9294727a3638bb1c 13f48ef8158bfc9d"));
+  hmac_test(alg_md5, MD5_DIGEST_SIZE, HEX_KEY,
+	    "0b0b0b0b0b0b0b0b 0b0b0b0b0b0b0b0b",
+	    "Hi There",
+	    "9294727a3638bb1c 13f48ef8158bfc9d");
 
 
   /* md5 - 2 */
-  HMAC_TEST(md5, MD5_DIGEST_SIZE,
-	    LDATA("Jefe"),
-	    LDATA("what do ya want for nothing?"),
-	    H("750c783e6ab0b503 eaa86e310a5db738"));	    
+  hmac_test(alg_md5, MD5_DIGEST_SIZE, HEX_NONE,
+	    "Jefe",
+	    "what do ya want for nothing?",
+	    "750c783e6ab0b503 eaa86e310a5db738");
 
   /* md5 - 3 */
-  HMAC_TEST(md5, MD5_DIGEST_SIZE,
-	    HL("aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"),
-	    HL("dddddddddddddddd dddddddddddddddd"
+  hmac_test(alg_md5, MD5_DIGEST_SIZE, (HEX_KEY|HEX_MSG),
+	    "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa",
+	    "dddddddddddddddd dddddddddddddddd"
 	       "dddddddddddddddd dddddddddddddddd"
 	       "dddddddddddddddd dddddddddddddddd"
-	       "dddd"),
-	    H("56be34521d144c88 dbb8c733f0e8b3f6"));
+	       "dddd",
+	    "56be34521d144c88 dbb8c733f0e8b3f6");
   
   /* md5 - 4 */
-  HMAC_TEST(md5, MD5_DIGEST_SIZE,
-	    HL("0102030405060708 090a0b0c0d0e0f10" 
-	       "1112131415161718 19"),
-	    HL("cdcdcdcdcdcdcdcd cdcdcdcdcdcdcdcd"
+  hmac_test(alg_md5, MD5_DIGEST_SIZE, (HEX_KEY|HEX_MSG),
+	    "0102030405060708 090a0b0c0d0e0f10" 
+	       "1112131415161718 19",
+	    "cdcdcdcdcdcdcdcd cdcdcdcdcdcdcdcd"
 	       "cdcdcdcdcdcdcdcd cdcdcdcdcdcdcdcd"
 	       "cdcdcdcdcdcdcdcd cdcdcdcdcdcdcdcd"
-	       "cdcd"),
-	    H("697eaf0aca3a3aea 3a75164746ffaa79"));
+	       "cdcd",
+	    "697eaf0aca3a3aea 3a75164746ffaa79");
 
   /* md5 - 5 */
-  HMAC_TEST(md5, 12,
-	    HL("0c0c0c0c0c0c0c0c 0c0c0c0c0c0c0c0c"),
-	    LDATA("Test With Truncation"),
-	    H("56461ef2342edc00 f9bab995"));
+  hmac_test(alg_md5, 12, HEX_KEY,
+	    "0c0c0c0c0c0c0c0c 0c0c0c0c0c0c0c0c",
+	    "Test With Truncation",
+	    "56461ef2342edc00 f9bab995");
 
   /* md5 - 6 */
-  HMAC_TEST(md5, MD5_DIGEST_SIZE,
-	    HL("aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
+  hmac_test(alg_md5, MD5_DIGEST_SIZE, HEX_KEY,
+	    "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
 	       "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
 	       "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
 	       "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
-	       "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"),
-	    LDATA("Test Using Larger Than Block-Size Key - Hash Key First"),
-	    H("6b1ab7fe4bd7bf8f 0b62e6ce61b9d0cd"));
+	       "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa",
+	    "Test Using Larger Than Block-Size Key - Hash Key First",
+	    "6b1ab7fe4bd7bf8f 0b62e6ce61b9d0cd");
 
   /* md5 - 7 */
-  HMAC_TEST(md5, MD5_DIGEST_SIZE,
-	    HL("aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
+  hmac_test(alg_md5, MD5_DIGEST_SIZE, HEX_KEY,
+	    "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
 	       "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
 	       "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
 	       "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
-	       "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"),
-	    LDATA("Test Using Larger Than Block-Size Key and Larger "
-		  "Than One Block-Size Data"),
-	    H("6f630fad67cda0ee 1fb1f562db3aa53e"));
+	       "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa",
+	    "Test Using Larger Than Block-Size Key and Larger "
+		  "Than One Block-Size Data",
+	    "6f630fad67cda0ee 1fb1f562db3aa53e");
 
   /* Additional test vectors, from Daniel Kahn Gillmor */
-  HMAC_TEST(md5, MD5_DIGEST_SIZE,
-	    LDATA("monkey monkey monkey monkey"),
-	    LDATA(""),
-	    H("e84db42a188813f30a15e611d64c7869"));
+  hmac_test(alg_md5, MD5_DIGEST_SIZE, HEX_NONE,
+	    "monkey monkey monkey monkey",
+	    "",
+	    "e84db42a188813f30a15e611d64c7869");
   
-  HMAC_TEST(md5, MD5_DIGEST_SIZE,
-	    LDATA("monkey monkey monkey monkey"),
-	    LDATA("a"),
-	    H("123662062e67c2aab371cc49db0df134"));
+  hmac_test(alg_md5, MD5_DIGEST_SIZE, HEX_NONE,
+	    "monkey monkey monkey monkey",
+	    "a",
+	    "123662062e67c2aab371cc49db0df134");
   
-  HMAC_TEST(md5, MD5_DIGEST_SIZE,
-	    LDATA("monkey monkey monkey monkey"),
-	    LDATA("38"),
-	    H("0a46cc10a49d4b7025c040c597bf5d76"));
+  hmac_test(alg_md5, MD5_DIGEST_SIZE, HEX_NONE,
+	    "monkey monkey monkey monkey",
+	    "38",
+	    "0a46cc10a49d4b7025c040c597bf5d76");
   
-  HMAC_TEST(md5, MD5_DIGEST_SIZE,
-	    LDATA("monkey monkey monkey monkey"),
-	    LDATA("abc"),
-	    H("d1f4d89f0e8b2b6ed0623c99ec298310"));
+  hmac_test(alg_md5, MD5_DIGEST_SIZE, HEX_NONE,
+	    "monkey monkey monkey monkey",
+	    "abc",
+	    "d1f4d89f0e8b2b6ed0623c99ec298310");
   
-  HMAC_TEST(md5, MD5_DIGEST_SIZE,
-	    LDATA("monkey monkey monkey monkey"),
-	    LDATA("message digest"),
-	    H("1627207b9bed5009a4f6e9ca8d2ca01e"));
+  hmac_test(alg_md5, MD5_DIGEST_SIZE, HEX_NONE,
+	    "monkey monkey monkey monkey",
+	    "message digest",
+	    "1627207b9bed5009a4f6e9ca8d2ca01e");
   
-  HMAC_TEST(md5, MD5_DIGEST_SIZE,
-	    LDATA("monkey monkey monkey monkey"),
-	    LDATA("abcdefghijklmnopqrstuvwxyz"),
-	    H("922aae6ab3b3a29202e21ce5f916ae9a"));
+  hmac_test(alg_md5, MD5_DIGEST_SIZE, HEX_NONE,
+	    "monkey monkey monkey monkey",
+	    "abcdefghijklmnopqrstuvwxyz",
+	    "922aae6ab3b3a29202e21ce5f916ae9a");
 
-  HMAC_TEST(md5, MD5_DIGEST_SIZE,
-	    LDATA("monkey monkey monkey monkey"),
-	    LDATA("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"),
-	    H("ede9cb83679ba82d88fbeae865b3f8fc"));
+  hmac_test(alg_md5, MD5_DIGEST_SIZE, HEX_NONE,
+	    "monkey monkey monkey monkey",
+	    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
+	    "ede9cb83679ba82d88fbeae865b3f8fc");
 
-  HMAC_TEST(md5, MD5_DIGEST_SIZE,
-	    LDATA("monkey monkey monkey monkey"),
-	    LDATA("12345678901234567890123456789012345678901234567890123456789012345678901234567890"),
-	    H("939dd45512ee3a594b6654f6b8de27f7"));
+  hmac_test(alg_md5, MD5_DIGEST_SIZE, HEX_NONE,
+	    "monkey monkey monkey monkey",
+	    "12345678901234567890123456789012345678901234567890123456789012345678901234567890",
+	    "939dd45512ee3a594b6654f6b8de27f7");
 
   /* Test vectors for ripemd160, from
      http://homes.esat.kuleuven.be/~bosselae/ripemd160.html */
-  HMAC_TEST(ripemd160, RIPEMD160_DIGEST_SIZE,
-	    HL("00112233445566778899aabbccddeeff01234567"),
-	    LDATA(""),
-	    H("cf387677bfda8483e63b57e06c3b5ecd8b7fc055"));
-
-  HMAC_TEST(ripemd160, RIPEMD160_DIGEST_SIZE,
-	    HL("00112233445566778899aabbccddeeff01234567"),
-	    LDATA("a"),
-	    H("0d351d71b78e36dbb7391c810a0d2b6240ddbafc"));
-
-  HMAC_TEST(ripemd160, RIPEMD160_DIGEST_SIZE,
-	    HL("00112233445566778899aabbccddeeff01234567"),
-	    LDATA("abc"),
-	    H("f7ef288cb1bbcc6160d76507e0a3bbf712fb67d6"));
-
-  HMAC_TEST(ripemd160, RIPEMD160_DIGEST_SIZE,
-	    HL("00112233445566778899aabbccddeeff01234567"),
-	    LDATA("message digest"),
-	    H("f83662cc8d339c227e600fcd636c57d2571b1c34"));
-
-  HMAC_TEST(ripemd160, RIPEMD160_DIGEST_SIZE,
-	    HL("00112233445566778899aabbccddeeff01234567"),
-	    LDATA("abcdefghijklmnopqrstuvwxyz"),
-	    H("843d1c4eb880ac8ac0c9c95696507957d0155ddb"));
-
-  HMAC_TEST(ripemd160, RIPEMD160_DIGEST_SIZE,
-	    HL("00112233445566778899aabbccddeeff01234567"),
-	    LDATA("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"),
-	    H("60f5ef198a2dd5745545c1f0c47aa3fb5776f881"));
-
-  HMAC_TEST(ripemd160, RIPEMD160_DIGEST_SIZE,
-	    HL("00112233445566778899aabbccddeeff01234567"),
-	    LDATA("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"),
-	    H("e49c136a9e5627e0681b808a3b97e6a6e661ae79"));
+  hmac_test(alg_ripemd160, RIPEMD160_DIGEST_SIZE, HEX_KEY,
+	    "00112233445566778899aabbccddeeff01234567",
+	    "",
+	    "cf387677bfda8483e63b57e06c3b5ecd8b7fc055");
+
+  hmac_test(alg_ripemd160, RIPEMD160_DIGEST_SIZE, HEX_KEY,
+	    "00112233445566778899aabbccddeeff01234567",
+	    "a",
+	    "0d351d71b78e36dbb7391c810a0d2b6240ddbafc");
+
+  hmac_test(alg_ripemd160, RIPEMD160_DIGEST_SIZE, HEX_KEY,
+	    "00112233445566778899aabbccddeeff01234567",
+	    "abc",
+	    "f7ef288cb1bbcc6160d76507e0a3bbf712fb67d6");
+
+  hmac_test(alg_ripemd160, RIPEMD160_DIGEST_SIZE, HEX_KEY,
+	    "00112233445566778899aabbccddeeff01234567",
+	    "message digest",
+	    "f83662cc8d339c227e600fcd636c57d2571b1c34");
+
+  hmac_test(alg_ripemd160, RIPEMD160_DIGEST_SIZE, HEX_KEY,
+	    "00112233445566778899aabbccddeeff01234567",
+	    "abcdefghijklmnopqrstuvwxyz",
+	    "843d1c4eb880ac8ac0c9c95696507957d0155ddb");
+
+  hmac_test(alg_ripemd160, RIPEMD160_DIGEST_SIZE, HEX_KEY,
+	    "00112233445566778899aabbccddeeff01234567",
+	    "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
+	    "60f5ef198a2dd5745545c1f0c47aa3fb5776f881");
+
+  hmac_test(alg_ripemd160, RIPEMD160_DIGEST_SIZE, HEX_KEY,
+	    "00112233445566778899aabbccddeeff01234567",
+	    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
+	    "e49c136a9e5627e0681b808a3b97e6a6e661ae79");
 
   /* Other key */
-  HMAC_TEST(ripemd160, RIPEMD160_DIGEST_SIZE,
-	    HL("0123456789abcdeffedcba987654321000112233"),
-	    LDATA(""),
-	    H("fe69a66c7423eea9c8fa2eff8d9dafb4f17a62f5"));
-
-  HMAC_TEST(ripemd160, RIPEMD160_DIGEST_SIZE,
-	    HL("0123456789abcdeffedcba987654321000112233"),
-	    LDATA("a"),
-	    H("85743e899bc82dbfa36faaa7a25b7cfd372432cd"));
-
-  HMAC_TEST(ripemd160, RIPEMD160_DIGEST_SIZE,
-	    HL("0123456789abcdeffedcba987654321000112233"),
-	    LDATA("abc"),
-	    H("6e4afd501fa6b4a1823ca3b10bd9aa0ba97ba182"));
-
-  HMAC_TEST(ripemd160, RIPEMD160_DIGEST_SIZE,
-	    HL("0123456789abcdeffedcba987654321000112233"),
-	    LDATA("message digest"),
-	    H("2e066e624badb76a184c8f90fba053330e650e92"));
-
-  HMAC_TEST(ripemd160, RIPEMD160_DIGEST_SIZE,
-	    HL("0123456789abcdeffedcba987654321000112233"),
-	    LDATA("abcdefghijklmnopqrstuvwxyz"),
-	    H("07e942aa4e3cd7c04dedc1d46e2e8cc4c741b3d9"));
-
-  HMAC_TEST(ripemd160, RIPEMD160_DIGEST_SIZE,
-	    HL("0123456789abcdeffedcba987654321000112233"),
-	    LDATA("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"),
-	    H("b6582318ddcfb67a53a67d676b8ad869aded629a"));
-
-  HMAC_TEST(ripemd160, RIPEMD160_DIGEST_SIZE,
-	    HL("0123456789abcdeffedcba987654321000112233"),
-	    LDATA("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"),
-	    H("f1be3ee877703140d34f97ea1ab3a07c141333e2"));
+  hmac_test(alg_ripemd160, RIPEMD160_DIGEST_SIZE, HEX_KEY,
+	    "0123456789abcdeffedcba987654321000112233",
+	    "",
+	    "fe69a66c7423eea9c8fa2eff8d9dafb4f17a62f5");
+
+  hmac_test(alg_ripemd160, RIPEMD160_DIGEST_SIZE, HEX_KEY,
+	    "0123456789abcdeffedcba987654321000112233",
+	    "a",
+	    "85743e899bc82dbfa36faaa7a25b7cfd372432cd");
+
+  hmac_test(alg_ripemd160, RIPEMD160_DIGEST_SIZE, HEX_KEY,
+	    "0123456789abcdeffedcba987654321000112233",
+	    "abc",
+	    "6e4afd501fa6b4a1823ca3b10bd9aa0ba97ba182");
+
+  hmac_test(alg_ripemd160, RIPEMD160_DIGEST_SIZE, HEX_KEY,
+	    "0123456789abcdeffedcba987654321000112233",
+	    "message digest",
+	    "2e066e624badb76a184c8f90fba053330e650e92");
+
+  hmac_test(alg_ripemd160, RIPEMD160_DIGEST_SIZE, HEX_KEY,
+	    "0123456789abcdeffedcba987654321000112233",
+	    "abcdefghijklmnopqrstuvwxyz",
+	    "07e942aa4e3cd7c04dedc1d46e2e8cc4c741b3d9");
+
+  hmac_test(alg_ripemd160, RIPEMD160_DIGEST_SIZE, HEX_KEY,
+	    "0123456789abcdeffedcba987654321000112233",
+	    "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
+	    "b6582318ddcfb67a53a67d676b8ad869aded629a");
+
+  hmac_test(alg_ripemd160, RIPEMD160_DIGEST_SIZE, HEX_KEY,
+	    "0123456789abcdeffedcba987654321000112233",
+	    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
+	    "f1be3ee877703140d34f97ea1ab3a07c141333e2");
 
   /* Test vectors for sha1, from RFC-2202 */
 
   /* sha1 - 1 */
-  HMAC_TEST(sha1, SHA1_DIGEST_SIZE,
-	    HL("0b0b0b0b0b0b0b0b 0b0b0b0b0b0b0b0b 0b0b0b0b"),
-	    LDATA("Hi There"),
-	    H("b617318655057264 e28bc0b6fb378c8e f146be00"));
+  hmac_test(alg_sha1, SHA1_DIGEST_SIZE, HEX_KEY,
+	    "0b0b0b0b0b0b0b0b 0b0b0b0b0b0b0b0b 0b0b0b0b",
+	    "Hi There",
+	    "b617318655057264 e28bc0b6fb378c8e f146be00");
 
   /* sha1 - 2 */
-  HMAC_TEST(sha1, SHA1_DIGEST_SIZE,
-	    LDATA("Jefe"),
-	    LDATA("what do ya want for nothing?"),
-	    H("effcdf6ae5eb2fa2 d27416d5f184df9c 259a7c79"));
+  hmac_test(alg_sha1, SHA1_DIGEST_SIZE, HEX_NONE,
+	    "Jefe",
+	    "what do ya want for nothing?",
+	    "effcdf6ae5eb2fa2 d27416d5f184df9c 259a7c79");
 
   /* sha1 - 3 */
-  HMAC_TEST(sha1, SHA1_DIGEST_SIZE,
-	    HL("aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa aaaaaaaa"),
-	    HL("dddddddddddddddd dddddddddddddddd"
+  hmac_test(alg_sha1, SHA1_DIGEST_SIZE, (HEX_KEY|HEX_MSG),
+	    "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa aaaaaaaa",
+	    "dddddddddddddddd dddddddddddddddd"
 	       "dddddddddddddddd dddddddddddddddd"
 	       "dddddddddddddddd dddddddddddddddd"
-	       "dddd"),
-	    H("125d7342b9ac11cd 91a39af48aa17b4f 63f175d3"));
+	       "dddd",
+	    "125d7342b9ac11cd 91a39af48aa17b4f 63f175d3");
 
   /* sha1 - 4 */
-  HMAC_TEST(sha1, SHA1_DIGEST_SIZE,
-	    HL("0102030405060708 090a0b0c0d0e0f10" 
-	       "1112131415161718 19"),
-	    HL("cdcdcdcdcdcdcdcd cdcdcdcdcdcdcdcd"
+  hmac_test(alg_sha1, SHA1_DIGEST_SIZE, (HEX_KEY|HEX_MSG),
+	    "0102030405060708 090a0b0c0d0e0f10" 
+	       "1112131415161718 19",
+	    "cdcdcdcdcdcdcdcd cdcdcdcdcdcdcdcd"
 	       "cdcdcdcdcdcdcdcd cdcdcdcdcdcdcdcd"
 	       "cdcdcdcdcdcdcdcd cdcdcdcdcdcdcdcd"
-	       "cdcd"),
-	    H("4c9007f4026250c6 bc8414f9bf50c86c 2d7235da"));
+	       "cdcd",
+	    "4c9007f4026250c6 bc8414f9bf50c86c 2d7235da");
 
   /* sha1 - 5 */
-  HMAC_TEST(sha1, 12,
-	    HL("0c0c0c0c0c0c0c0c 0c0c0c0c0c0c0c0c 0c0c0c0c"),
-	    LDATA("Test With Truncation"),
-	    H("4c1a03424b55e07f e7f27be1"));
+  hmac_test(alg_sha1, 12, HEX_KEY,
+	    "0c0c0c0c0c0c0c0c 0c0c0c0c0c0c0c0c 0c0c0c0c",
+	    "Test With Truncation",
+	    "4c1a03424b55e07f e7f27be1");
 
   /* sha1 - 6 */
-  HMAC_TEST(sha1, SHA1_DIGEST_SIZE,
-	    HL("aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
+  hmac_test(alg_sha1, SHA1_DIGEST_SIZE, HEX_KEY,
+	    "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
 	       "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
 	       "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
 	       "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
-	       "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"),
-	    LDATA("Test Using Larger Than Block-Size Key - Hash Key First"),
-	    H("aa4ae5e15272d00e 95705637ce8a3b55 ed402112"));
+	       "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa",
+	    "Test Using Larger Than Block-Size Key - Hash Key First",
+	    "aa4ae5e15272d00e 95705637ce8a3b55 ed402112");
 
   /* sha1 - 7 */
-  HMAC_TEST(sha1, SHA1_DIGEST_SIZE,
-	    HL("aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
+  hmac_test(alg_sha1, SHA1_DIGEST_SIZE, HEX_KEY,
+	    "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
 	       "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
 	       "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
 	       "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
-	       "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"),
-	    LDATA("Test Using Larger Than Block-Size Key and Larger "
-		  "Than One Block-Size Data"),
-	    H("e8e99d0f45237d78 6d6bbaa7965c7808 bbff1a91"));
+	       "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa",
+	    "Test Using Larger Than Block-Size Key and Larger "
+		  "Than One Block-Size Data",
+	    "e8e99d0f45237d78 6d6bbaa7965c7808 bbff1a91");
 
   /* Additional test vectors, from Daniel Kahn Gillmor */
-  HMAC_TEST(md5, MD5_DIGEST_SIZE,
-	    LDATA("monkey monkey monkey monkey"),
-	    LDATA(""),
-	    H("e84db42a188813f30a15e611d64c7869"));
+  hmac_test(alg_md5, MD5_DIGEST_SIZE, HEX_NONE,
+	    "monkey monkey monkey monkey",
+	    "",
+	    "e84db42a188813f30a15e611d64c7869");
   
-  HMAC_TEST(md5, MD5_DIGEST_SIZE,
-	    LDATA("monkey monkey monkey monkey"),
-	    LDATA("a"),
-	    H("123662062e67c2aab371cc49db0df134"));
+  hmac_test(alg_md5, MD5_DIGEST_SIZE, HEX_NONE,
+	    "monkey monkey monkey monkey",
+	    "a",
+	    "123662062e67c2aab371cc49db0df134");
   
-  HMAC_TEST(md5, MD5_DIGEST_SIZE,
-	    LDATA("monkey monkey monkey monkey"),
-	    LDATA("38"),
-	    H("0a46cc10a49d4b7025c040c597bf5d76"));
+  hmac_test(alg_md5, MD5_DIGEST_SIZE, HEX_NONE,
+	    "monkey monkey monkey monkey",
+	    "38",
+	    "0a46cc10a49d4b7025c040c597bf5d76");
   
-  HMAC_TEST(md5, MD5_DIGEST_SIZE,
-	    LDATA("monkey monkey monkey monkey"),
-	    LDATA("abc"),
-	    H("d1f4d89f0e8b2b6ed0623c99ec298310"));
+  hmac_test(alg_md5, MD5_DIGEST_SIZE, HEX_NONE,
+	    "monkey monkey monkey monkey",
+	    "abc",
+	    "d1f4d89f0e8b2b6ed0623c99ec298310");
   
-  HMAC_TEST(md5, MD5_DIGEST_SIZE,
-	    LDATA("monkey monkey monkey monkey"),
-	    LDATA("message digest"),
-	    H("1627207b9bed5009a4f6e9ca8d2ca01e"));
+  hmac_test(alg_md5, MD5_DIGEST_SIZE, HEX_NONE,
+	    "monkey monkey monkey monkey",
+	    "message digest",
+	    "1627207b9bed5009a4f6e9ca8d2ca01e");
   
-  HMAC_TEST(md5, MD5_DIGEST_SIZE,
-	    LDATA("monkey monkey monkey monkey"),
-	    LDATA("abcdefghijklmnopqrstuvwxyz"),
-	    H("922aae6ab3b3a29202e21ce5f916ae9a"));
+  hmac_test(alg_md5, MD5_DIGEST_SIZE, HEX_NONE,
+	    "monkey monkey monkey monkey",
+	    "abcdefghijklmnopqrstuvwxyz",
+	    "922aae6ab3b3a29202e21ce5f916ae9a");
 
-  HMAC_TEST(md5, MD5_DIGEST_SIZE,
-	    LDATA("monkey monkey monkey monkey"),
-	    LDATA("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"),
-	    H("ede9cb83679ba82d88fbeae865b3f8fc"));
+  hmac_test(alg_md5, MD5_DIGEST_SIZE, HEX_NONE,
+	    "monkey monkey monkey monkey",
+	    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
+	    "ede9cb83679ba82d88fbeae865b3f8fc");
 
-  HMAC_TEST(md5, MD5_DIGEST_SIZE,
-	    LDATA("monkey monkey monkey monkey"),
-	    LDATA("12345678901234567890123456789012345678901234567890123456789012345678901234567890"),
-	    H("939dd45512ee3a594b6654f6b8de27f7"));
+  hmac_test(alg_md5, MD5_DIGEST_SIZE, HEX_NONE,
+	    "monkey monkey monkey monkey",
+	    "12345678901234567890123456789012345678901234567890123456789012345678901234567890",
+	    "939dd45512ee3a594b6654f6b8de27f7");
 
   /* Test vectors for sha224, from RFC 4231 */
-  HMAC_TEST(sha224, SHA224_DIGEST_SIZE,
-	    HL("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b"
-	       "0b0b0b0b"),
-	    LDATA("Hi There"),
-	    H("896fb1128abbdf196832107cd49df33f"
-	      "47b4b1169912ba4f53684b22"));
-
-  HMAC_TEST(sha224, SHA224_DIGEST_SIZE,
-	    LDATA("Jefe"),
-	    LDATA("what do ya want for nothing?"),
-	    H("a30e01098bc6dbbf45690f3a7e9e6d0f"
-	      "8bbea2a39e6148008fd05e44"));
-
-  HMAC_TEST(sha224, SHA224_DIGEST_SIZE,
-	    HL("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
-	       "aaaaaaaa"),
-	    HL("dddddddddddddddddddddddddddddddd"
+  hmac_test(alg_sha224, SHA224_DIGEST_SIZE, HEX_KEY,
+	    "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b"
+	       "0b0b0b0b",
+	    "Hi There",
+	    "896fb1128abbdf196832107cd49df33f"
+	      "47b4b1169912ba4f53684b22");
+
+  hmac_test(alg_sha224, SHA224_DIGEST_SIZE, HEX_NONE,
+	    "Jefe",
+	    "what do ya want for nothing?",
+	    "a30e01098bc6dbbf45690f3a7e9e6d0f"
+	      "8bbea2a39e6148008fd05e44");
+
+  hmac_test(alg_sha224, SHA224_DIGEST_SIZE, (HEX_KEY|HEX_MSG),
+	    "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+	       "aaaaaaaa",
+	    "dddddddddddddddddddddddddddddddd"
 	       "dddddddddddddddddddddddddddddddd"
 	       "dddddddddddddddddddddddddddddddd"
-	       "dddd"),
-	    H("7fb3cb3588c6c1f6ffa9694d7d6ad264"
-	      "9365b0c1f65d69d1ec8333ea"));
-
-  HMAC_TEST(sha224, SHA224_DIGEST_SIZE,
-	    HL("0102030405060708090a0b0c0d0e0f10"
-	       "111213141516171819"),
-	    HL("cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd"
+	       "dddd",
+	    "7fb3cb3588c6c1f6ffa9694d7d6ad264"
+	      "9365b0c1f65d69d1ec8333ea");
+
+  hmac_test(alg_sha224, SHA224_DIGEST_SIZE, (HEX_KEY|HEX_MSG),
+	    "0102030405060708090a0b0c0d0e0f10"
+	       "111213141516171819",
+	    "cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd"
 	       "cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd"
 	       "cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd"
-	       "cdcd"),
-	    H("6c11506874013cac6a2abc1bb382627c"
-	      "ec6a90d86efc012de7afec5a"));
+	       "cdcd",
+	    "6c11506874013cac6a2abc1bb382627c"
+	      "ec6a90d86efc012de7afec5a");
 
-  HMAC_TEST(sha224, 16,
-	    HL("0c0c0c0c0c0c0c0c 0c0c0c0c0c0c0c0c 0c0c0c0c"),
-	    LDATA("Test With Truncation"),
-	    H("0e2aea68a90c8d37c988bcdb9fca6fa8"));
+  hmac_test(alg_sha224, 16, HEX_KEY,
+	    "0c0c0c0c0c0c0c0c 0c0c0c0c0c0c0c0c 0c0c0c0c",
+	    "Test With Truncation",
+	    "0e2aea68a90c8d37c988bcdb9fca6fa8");
 
-  HMAC_TEST(sha224, SHA224_DIGEST_SIZE,
-	    HL("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+  hmac_test(alg_sha224, SHA224_DIGEST_SIZE, HEX_KEY,
+	    "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
 	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
 	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
 	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
@@ -351,13 +437,13 @@ test_main(void)
 	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
 	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
 	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
-	       "aaaaaa"),
-	    LDATA("Test Using Larger Than Block-Size Key - Hash Key First"),
-	    H("95e9a0db962095adaebe9b2d6f0dbce2"
-	      "d499f112f2d2b7273fa6870e"));
+	       "aaaaaa",
+	    "Test Using Larger Than Block-Size Key - Hash Key First",
+	    "95e9a0db962095adaebe9b2d6f0dbce2"
+	      "d499f112f2d2b7273fa6870e");
 
-  HMAC_TEST(sha224, SHA224_DIGEST_SIZE,
-	    HL("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+  hmac_test(alg_sha224, SHA224_DIGEST_SIZE, HEX_KEY,
+	    "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
 	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
 	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
 	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
@@ -365,104 +451,104 @@ test_main(void)
 	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
 	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
 	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
-	       "aaaaaa"),
-	    LDATA("This is a test using a larger than block-size ke"
+	       "aaaaaa",
+	    "This is a test using a larger than block-size ke"
 		  "y and a larger than block-size data. The key nee"
 		  "ds to be hashed before being used by the HMAC al"
-		  "gorithm."),
-	    H("3a854166ac5d9f023f54d517d0b39dbd"
-	      "946770db9c2b95c9f6f565d1"));
+		  "gorithm.",
+	    "3a854166ac5d9f023f54d517d0b39dbd"
+	      "946770db9c2b95c9f6f565d1");
 
   /* Additional test vectors, from Daniel Kahn Gillmor */
-  HMAC_TEST(sha224, SHA224_DIGEST_SIZE,
-	    LDATA("monkey monkey monkey monkey"),
-	    LDATA(""),
-	    H("d12a49ae38177ffeaa548b2148bb5238"
-	      "60849772d9391e675b103d89"));
+  hmac_test(alg_sha224, SHA224_DIGEST_SIZE, HEX_NONE,
+	    "monkey monkey monkey monkey",
+	    "",
+	    "d12a49ae38177ffeaa548b2148bb5238"
+	      "60849772d9391e675b103d89");
   
-  HMAC_TEST(sha224, SHA224_DIGEST_SIZE,
-	    LDATA("monkey monkey monkey monkey"),
-	    LDATA("a"),
-	    H("b04ff8522f904f553970bfa8ad3f0086"
-	      "bce1e8580affd8a12c94e31a"));
+  hmac_test(alg_sha224, SHA224_DIGEST_SIZE, HEX_NONE,
+	    "monkey monkey monkey monkey",
+	    "a",
+	    "b04ff8522f904f553970bfa8ad3f0086"
+	      "bce1e8580affd8a12c94e31a");
   
-  HMAC_TEST(sha224, SHA224_DIGEST_SIZE,
-	    LDATA("monkey monkey monkey monkey"),
-	    LDATA("38"),
-	    H("afcfb5511f710334f9350f57faec3c08"
-	      "764b4bd126a6840f4347f116"));
+  hmac_test(alg_sha224, SHA224_DIGEST_SIZE, HEX_NONE,
+	    "monkey monkey monkey monkey",
+	    "38",
+	    "afcfb5511f710334f9350f57faec3c08"
+	      "764b4bd126a6840f4347f116");
   
-  HMAC_TEST(sha224, SHA224_DIGEST_SIZE,
-	    LDATA("monkey monkey monkey monkey"),
-	    LDATA("abc"),
-	    H("9df9907af127900c909376893565c6cf"
-	      "2d7db244fdc4277da1e0b679"));
+  hmac_test(alg_sha224, SHA224_DIGEST_SIZE, HEX_NONE,
+	    "monkey monkey monkey monkey",
+	    "abc",
+	    "9df9907af127900c909376893565c6cf"
+	      "2d7db244fdc4277da1e0b679");
   
-  HMAC_TEST(sha224, SHA224_DIGEST_SIZE,
-	    LDATA("monkey monkey monkey monkey"),
-	    LDATA("message digest"),
-	    H("254ebf6b8ddd7a3271b3d9aca1699b0c"
-	      "0bfb7df61e8a114922c88d27"));
+  hmac_test(alg_sha224, SHA224_DIGEST_SIZE, HEX_NONE,
+	    "monkey monkey monkey monkey",
+	    "message digest",
+	    "254ebf6b8ddd7a3271b3d9aca1699b0c"
+	      "0bfb7df61e8a114922c88d27");
   
-  HMAC_TEST(sha224, SHA224_DIGEST_SIZE,
-	    LDATA("monkey monkey monkey monkey"),
-	    LDATA("abcdefghijklmnopqrstuvwxyz"),
-	    H("6ec5bffba5880c3234a6cf257816e4d5"
-	      "35ab178a7f12929769e378fb"));
-
-  HMAC_TEST(sha224, SHA224_DIGEST_SIZE,
-	    LDATA("monkey monkey monkey monkey"),
-	    LDATA("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"),
-	    H("5f768179dbb29ca722875d0f461a2e2f"
-	      "597d0210340a84df1a8e9c63"));
-
-  HMAC_TEST(sha224, SHA224_DIGEST_SIZE,
-	    LDATA("monkey monkey monkey monkey"),
-	    LDATA("12345678901234567890123456789012345678901234567890123456789012345678901234567890"),
-	    H("c7667b0d7e56b2b4f6fcc1d8da9e22da"
-	      "a1556f44c47132a87303c6a2"));
+  hmac_test(alg_sha224, SHA224_DIGEST_SIZE, HEX_NONE,
+	    "monkey monkey monkey monkey",
+	    "abcdefghijklmnopqrstuvwxyz",
+	    "6ec5bffba5880c3234a6cf257816e4d5"
+	      "35ab178a7f12929769e378fb");
+
+  hmac_test(alg_sha224, SHA224_DIGEST_SIZE, HEX_NONE,
+	    "monkey monkey monkey monkey",
+	    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
+	    "5f768179dbb29ca722875d0f461a2e2f"
+	      "597d0210340a84df1a8e9c63");
+
+  hmac_test(alg_sha224, SHA224_DIGEST_SIZE, HEX_NONE,
+	    "monkey monkey monkey monkey",
+	    "12345678901234567890123456789012345678901234567890123456789012345678901234567890",
+	    "c7667b0d7e56b2b4f6fcc1d8da9e22da"
+	      "a1556f44c47132a87303c6a2");
 
   /* Test vectors for sha256, from RFC 4231 */
-  HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
-	    HL("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b"
-	       "0b0b0b0b"),
-	    LDATA("Hi There"),
-	    H("b0344c61d8db38535ca8afceaf0bf12b"
-	      "881dc200c9833da726e9376c2e32cff7"));
-
-  HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
-	    LDATA("Jefe"),
-	    LDATA("what do ya want for nothing?"),
-	    H("5bdcc146bf60754e6a042426089575c7"
-	      "5a003f089d2739839dec58b964ec3843"));
-
-  HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
-	    HL("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
-	       "aaaaaaaa"),
-	    HL("dddddddddddddddddddddddddddddddd"
+  hmac_test(alg_sha256, SHA256_DIGEST_SIZE, HEX_KEY,
+	    "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b"
+	       "0b0b0b0b",
+	    "Hi There",
+	    "b0344c61d8db38535ca8afceaf0bf12b"
+	      "881dc200c9833da726e9376c2e32cff7");
+
+  hmac_test(alg_sha256, SHA256_DIGEST_SIZE, HEX_NONE,
+	    "Jefe",
+	    "what do ya want for nothing?",
+	    "5bdcc146bf60754e6a042426089575c7"
+	      "5a003f089d2739839dec58b964ec3843");
+
+  hmac_test(alg_sha256, SHA256_DIGEST_SIZE, (HEX_KEY|HEX_MSG),
+	    "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+	       "aaaaaaaa",
+	    "dddddddddddddddddddddddddddddddd"
 	       "dddddddddddddddddddddddddddddddd"
 	       "dddddddddddddddddddddddddddddddd"
-	       "dddd"),
-	    H("773ea91e36800e46854db8ebd09181a7"
-	      "2959098b3ef8c122d9635514ced565fe"));
-
-  HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
-	    HL("0102030405060708090a0b0c0d0e0f10"
-	       "111213141516171819"),
-	    HL("cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd"
+	       "dddd",
+	    "773ea91e36800e46854db8ebd09181a7"
+	      "2959098b3ef8c122d9635514ced565fe");
+
+  hmac_test(alg_sha256, SHA256_DIGEST_SIZE, (HEX_KEY|HEX_MSG),
+	    "0102030405060708090a0b0c0d0e0f10"
+	       "111213141516171819",
+	    "cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd"
 	       "cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd"
 	       "cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd"
-	       "cdcd"),
-	    H("82558a389a443c0ea4cc819899f2083a"
-	      "85f0faa3e578f8077a2e3ff46729665b"));
+	       "cdcd",
+	    "82558a389a443c0ea4cc819899f2083a"
+	      "85f0faa3e578f8077a2e3ff46729665b");
 
-  HMAC_TEST(sha256, 16,
-	    HL("0c0c0c0c0c0c0c0c 0c0c0c0c0c0c0c0c 0c0c0c0c"),
-	    LDATA("Test With Truncation"),
-	    H("a3b6167473100ee06e0c796c2955552b"));
+  hmac_test(alg_sha256, 16, HEX_KEY,
+	    "0c0c0c0c0c0c0c0c 0c0c0c0c0c0c0c0c 0c0c0c0c",
+	    "Test With Truncation",
+	    "a3b6167473100ee06e0c796c2955552b");
 
-  HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
-	    HL("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+  hmac_test(alg_sha256, SHA256_DIGEST_SIZE, HEX_KEY,
+	    "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
 	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
 	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
 	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
@@ -470,13 +556,13 @@ test_main(void)
 	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
 	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
 	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
-	       "aaaaaa"),
-	    LDATA("Test Using Larger Than Block-Size Key - Hash Key First"),
-	    H("60e431591ee0b67f0d8a26aacbf5b77f"
-	      "8e0bc6213728c5140546040f0ee37f54"));
+	       "aaaaaa",
+	    "Test Using Larger Than Block-Size Key - Hash Key First",
+	    "60e431591ee0b67f0d8a26aacbf5b77f"
+	      "8e0bc6213728c5140546040f0ee37f54");
 
-  HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
-	    HL("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+  hmac_test(alg_sha256, SHA256_DIGEST_SIZE, HEX_KEY,
+	    "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
 	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
 	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
 	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
@@ -484,201 +570,201 @@ test_main(void)
 	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
 	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
 	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
-	       "aaaaaa"),
-	    LDATA("This is a test using a larger than block-size ke"
+	       "aaaaaa",
+	    "This is a test using a larger than block-size ke"
 		  "y and a larger than block-size data. The key nee"
 		  "ds to be hashed before being used by the HMAC al"
-		  "gorithm."),
-	    H("9b09ffa71b942fcb27635fbcd5b0e944"
-	      "bfdc63644f0713938a7f51535c3a35e2"));
+		  "gorithm.",
+	    "9b09ffa71b942fcb27635fbcd5b0e944"
+	      "bfdc63644f0713938a7f51535c3a35e2");
 
   /* Additional test vectors for sha256, from
      draft-ietf-ipsec-ciph-sha-256-01.txt */
 
   /* Test Case #1: HMAC-SHA-256 with 3-byte input and 32-byte key */
-  HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
-	    HL("0102030405060708 090a0b0c0d0e0f10"
-	       "1112131415161718 191a1b1c1d1e1f20"),
-	    LDATA("abc"),
-	    H("a21b1f5d4cf4f73a 4dd939750f7a066a"
-		 "7f98cc131cb16a66 92759021cfab8181"));
+  hmac_test(alg_sha256, SHA256_DIGEST_SIZE, HEX_KEY,
+	    "0102030405060708 090a0b0c0d0e0f10"
+	       "1112131415161718 191a1b1c1d1e1f20",
+	    "abc",
+	    "a21b1f5d4cf4f73a 4dd939750f7a066a"
+		 "7f98cc131cb16a66 92759021cfab8181");
 
   /* Test Case #2: HMAC-SHA-256 with 56-byte input and 32-byte key */
-  HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
-	    HL("0102030405060708 090a0b0c0d0e0f10"
-	       "1112131415161718 191a1b1c1d1e1f20"),
-	    LDATA("abcdbcdecdefdefgefghfghighijhijk"
-		  "ijkljklmklmnlmnomnopnopq"),
-	    H("104fdc1257328f08 184ba73131c53cae"
-		 "e698e36119421149 ea8c712456697d30"));
+  hmac_test(alg_sha256, SHA256_DIGEST_SIZE, HEX_KEY,
+	    "0102030405060708 090a0b0c0d0e0f10"
+	       "1112131415161718 191a1b1c1d1e1f20",
+	    "abcdbcdecdefdefgefghfghighijhijk"
+		  "ijkljklmklmnlmnomnopnopq",
+	    "104fdc1257328f08 184ba73131c53cae"
+		 "e698e36119421149 ea8c712456697d30");
 
   /* Test Case #3: HMAC-SHA-256 with 112-byte (multi-block) input
      and 32-byte key */
-  HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
-	    HL("0102030405060708 090a0b0c0d0e0f10"
-	       "1112131415161718 191a1b1c1d1e1f20"),
-	    LDATA("abcdbcdecdefdefgefghfghighijhijk"
+  hmac_test(alg_sha256, SHA256_DIGEST_SIZE, HEX_KEY,
+	    "0102030405060708 090a0b0c0d0e0f10"
+	       "1112131415161718 191a1b1c1d1e1f20",
+	    "abcdbcdecdefdefgefghfghighijhijk"
 		  "ijkljklmklmnlmnomnopnopqabcdbcde"
 		  "cdefdefgefghfghighijhijkijkljklm"
-		  "klmnlmnomnopnopq"),
-	    H("470305fc7e40fe34 d3eeb3e773d95aab"
-	      "73acf0fd060447a5 eb4595bf33a9d1a3"));
+		  "klmnlmnomnopnopq",
+	    "470305fc7e40fe34 d3eeb3e773d95aab"
+	      "73acf0fd060447a5 eb4595bf33a9d1a3");
 
   /* Test Case #4:  HMAC-SHA-256 with 8-byte input and 32-byte key */
-  HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
-	    HL("0b0b0b0b0b0b0b0b 0b0b0b0b0b0b0b0b"
-	       "0b0b0b0b0b0b0b0b 0b0b0b0b0b0b0b0b"),
-	    LDATA("Hi There"),
-	    H("198a607eb44bfbc6 9903a0f1cf2bbdc5"
-	      "ba0aa3f3d9ae3c1c 7a3b1696a0b68cf7"));
+  hmac_test(alg_sha256, SHA256_DIGEST_SIZE, HEX_KEY,
+	    "0b0b0b0b0b0b0b0b 0b0b0b0b0b0b0b0b"
+	       "0b0b0b0b0b0b0b0b 0b0b0b0b0b0b0b0b",
+	    "Hi There",
+	    "198a607eb44bfbc6 9903a0f1cf2bbdc5"
+	      "ba0aa3f3d9ae3c1c 7a3b1696a0b68cf7");
 
   /* Test Case #6: HMAC-SHA-256 with 50-byte input and 32-byte key */
-  HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
-	    HL("aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
-	       "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"),
-	    HL("dddddddddddddddd dddddddddddddddd"
+  hmac_test(alg_sha256, SHA256_DIGEST_SIZE, (HEX_KEY|HEX_MSG),
+	    "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
+	       "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa",
+	    "dddddddddddddddd dddddddddddddddd"
 	       "dddddddddddddddd dddddddddddddddd"
 	       "dddddddddddddddd dddddddddddddddd"
-	       "dddd"),
-	    H("cdcb1220d1ecccea 91e53aba3092f962"
-	      "e549fe6ce9ed7fdc 43191fbde45c30b0"));
+	       "dddd",
+	    "cdcb1220d1ecccea 91e53aba3092f962"
+	      "e549fe6ce9ed7fdc 43191fbde45c30b0");
 
   /* Test Case #7: HMAC-SHA-256 with 50-byte input and 37-byte key */
-  HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
-	    HL("0102030405060708 090a0b0c0d0e0f10"
+  hmac_test(alg_sha256, SHA256_DIGEST_SIZE, (HEX_KEY|HEX_MSG),
+	    "0102030405060708 090a0b0c0d0e0f10"
 	       "1112131415161718 191a1b1c1d1e1f20"
-	       "2122232425"),
-	    HL("cdcdcdcdcdcdcdcd cdcdcdcdcdcdcdcd"
+	       "2122232425",
+	    "cdcdcdcdcdcdcdcd cdcdcdcdcdcdcdcd"
 	       "cdcdcdcdcdcdcdcd cdcdcdcdcdcdcdcd"
 	       "cdcdcdcdcdcdcdcd cdcdcdcdcdcdcdcd"
-	       "cdcd"),
-	    H("d4633c17f6fb8d74 4c66dee0f8f07455"
-	      "6ec4af55ef079985 41468eb49bd2e917"));
+	       "cdcd",
+	    "d4633c17f6fb8d74 4c66dee0f8f07455"
+	      "6ec4af55ef079985 41468eb49bd2e917");
 
   /* Test Case #8: HMAC-SHA-256 with 20-byte input and 32-byte key */
-  HMAC_TEST(sha256, 16,
-	    HL("0c0c0c0c0c0c0c0c 0c0c0c0c0c0c0c0c"
-	       "0c0c0c0c0c0c0c0c 0c0c0c0c0c0c0c0c"),
-	    LDATA("Test With Truncation"),
-	    H("7546af01841fc09b 1ab9c3749a5f1c17"));
+  hmac_test(alg_sha256, 16, HEX_KEY,
+	    "0c0c0c0c0c0c0c0c 0c0c0c0c0c0c0c0c"
+	       "0c0c0c0c0c0c0c0c 0c0c0c0c0c0c0c0c",
+	    "Test With Truncation",
+	    "7546af01841fc09b 1ab9c3749a5f1c17");
 
   /* Test Case #9: HMAC-SHA-256 with 54-byte input and 80-byte key */
-  HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
-	    HL("aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
+  hmac_test(alg_sha256, SHA256_DIGEST_SIZE, HEX_KEY,
+	    "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
 	       "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
 	       "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
 	       "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
-	       "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"),
-	    LDATA("Test Using Larger Than Block-Size Key - Hash Key First"),
-	    H("6953025ed96f0c09 f80a96f78e6538db"
-	      "e2e7b820e3dd970e 7ddd39091b32352f"));
+	       "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa",
+	    "Test Using Larger Than Block-Size Key - Hash Key First",
+	    "6953025ed96f0c09 f80a96f78e6538db"
+	      "e2e7b820e3dd970e 7ddd39091b32352f");
 
   /* Test Case #10: HMAC-SHA-256 with 73-byte (multi-block) input
      and 80-byte key */
-  HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
-	    HL("aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
+  hmac_test(alg_sha256, SHA256_DIGEST_SIZE, HEX_KEY,
+	    "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
 	       "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
 	       "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
 	       "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
-	       "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"),
-	    LDATA("Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data"),
-	    H("6355ac22e890d0a3 c8481a5ca4825bc8"
-	      "84d3e7a1ff98a2fc 2ac7d8e064c3b2e6"));
+	       "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa",
+	    "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data",
+	    "6355ac22e890d0a3 c8481a5ca4825bc8"
+	      "84d3e7a1ff98a2fc 2ac7d8e064c3b2e6");
 
   /* Additional test vectors, from Daniel Kahn Gillmor */
-  HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
-	    LDATA("monkey monkey monkey monkey"),
-	    LDATA(""),
-	    H("5c780648c90d121c50091c3a0c3afc1f"
-	      "4ab847528005d99d9821ad3f341b651a"));
+  hmac_test(alg_sha256, SHA256_DIGEST_SIZE, HEX_NONE,
+	    "monkey monkey monkey monkey",
+	    "",
+	    "5c780648c90d121c50091c3a0c3afc1f"
+	      "4ab847528005d99d9821ad3f341b651a");
   
-  HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
-	    LDATA("monkey monkey monkey monkey"),
-	    LDATA("a"),
-	    H("6142364c0646b0cfe426866f21d613e0"
-	      "55a136a7d9b45d85685e080a09cec463"));
+  hmac_test(alg_sha256, SHA256_DIGEST_SIZE, HEX_NONE,
+	    "monkey monkey monkey monkey",
+	    "a",
+	    "6142364c0646b0cfe426866f21d613e0"
+	      "55a136a7d9b45d85685e080a09cec463");
   
-  HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
-	    LDATA("monkey monkey monkey monkey"),
-	    LDATA("38"),
-	    H("e49aa7839977e130ad87b63da9d4eb7b"
-	      "263cd5a27c54a7604b6044eb35901171"));
+  hmac_test(alg_sha256, SHA256_DIGEST_SIZE, HEX_NONE,
+	    "monkey monkey monkey monkey",
+	    "38",
+	    "e49aa7839977e130ad87b63da9d4eb7b"
+	      "263cd5a27c54a7604b6044eb35901171");
   
-  HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
-	    LDATA("monkey monkey monkey monkey"),
-	    LDATA("abc"),
-	    H("e5ef49f545c7af933a9d18c7c562bc91"
-	      "08583fd5cf00d9e0db351d6d8f8e41bc"));
+  hmac_test(alg_sha256, SHA256_DIGEST_SIZE, HEX_NONE,
+	    "monkey monkey monkey monkey",
+	    "abc",
+	    "e5ef49f545c7af933a9d18c7c562bc91"
+	      "08583fd5cf00d9e0db351d6d8f8e41bc");
   
-  HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
-	    LDATA("monkey monkey monkey monkey"),
-	    LDATA("message digest"),
-	    H("373b04877180fea27a41a8fb8f88201c"
-	      "a6268411ee3c80b01a424483eb9156e1"));
+  hmac_test(alg_sha256, SHA256_DIGEST_SIZE, HEX_NONE,
+	    "monkey monkey monkey monkey",
+	    "message digest",
+	    "373b04877180fea27a41a8fb8f88201c"
+	      "a6268411ee3c80b01a424483eb9156e1");
   
-  HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
-	    LDATA("monkey monkey monkey monkey"),
-	    LDATA("abcdefghijklmnopqrstuvwxyz"),
-	    H("eb5945d56eefbdb41602946ea6448d53"
-	      "86b08d7d801a87f439fab52f8bb9736e"));
-
-  HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
-	    LDATA("monkey monkey monkey monkey"),
-	    LDATA("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"),
-	    H("3798f363c57afa6edaffe39016ca7bad"
-	      "efd1e670afb0e3987194307dec3197db"));
-
-  HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
-	    LDATA("monkey monkey monkey monkey"),
-	    LDATA("12345678901234567890123456789012345678901234567890123456789012345678901234567890"),
-	    H("c89a7039a62985ff813fe4509b918a43"
-	      "6d7b1ffd8778e2c24dec464849fb6128"));
+  hmac_test(alg_sha256, SHA256_DIGEST_SIZE, HEX_NONE,
+	    "monkey monkey monkey monkey",
+	    "abcdefghijklmnopqrstuvwxyz",
+	    "eb5945d56eefbdb41602946ea6448d53"
+	      "86b08d7d801a87f439fab52f8bb9736e");
+
+  hmac_test(alg_sha256, SHA256_DIGEST_SIZE, HEX_NONE,
+	    "monkey monkey monkey monkey",
+	    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
+	    "3798f363c57afa6edaffe39016ca7bad"
+	      "efd1e670afb0e3987194307dec3197db");
+
+  hmac_test(alg_sha256, SHA256_DIGEST_SIZE, HEX_NONE,
+	    "monkey monkey monkey monkey",
+	    "12345678901234567890123456789012345678901234567890123456789012345678901234567890",
+	    "c89a7039a62985ff813fe4509b918a43"
+	      "6d7b1ffd8778e2c24dec464849fb6128");
 
   /* Test vectors for sha384, from RFC 4231 */
-  HMAC_TEST(sha384, SHA384_DIGEST_SIZE,
-	    HL("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b"
-	       "0b0b0b0b"),
-	    LDATA("Hi There"),
-	    H("afd03944d84895626b0825f4ab46907f"
+  hmac_test(alg_sha384, SHA384_DIGEST_SIZE, HEX_KEY,
+	    "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b"
+	       "0b0b0b0b",
+	    "Hi There",
+	    "afd03944d84895626b0825f4ab46907f"
 	      "15f9dadbe4101ec682aa034c7cebc59c"
-	      "faea9ea9076ede7f4af152e8b2fa9cb6"));
+	      "faea9ea9076ede7f4af152e8b2fa9cb6");
 
-  HMAC_TEST(sha384, SHA384_DIGEST_SIZE,
-	    LDATA("Jefe"),
-	    LDATA("what do ya want for nothing?"),
-	    H("af45d2e376484031617f78d2b58a6b1b"
+  hmac_test(alg_sha384, SHA384_DIGEST_SIZE, HEX_NONE,
+	    "Jefe",
+	    "what do ya want for nothing?",
+	    "af45d2e376484031617f78d2b58a6b1b"
 	      "9c7ef464f5a01b47e42ec3736322445e"
-	      "8e2240ca5e69e2c78b3239ecfab21649"));
+	      "8e2240ca5e69e2c78b3239ecfab21649");
 
-  HMAC_TEST(sha384, SHA384_DIGEST_SIZE,
-	    HL("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
-	       "aaaaaaaa"),
-	    HL("dddddddddddddddddddddddddddddddd"
+  hmac_test(alg_sha384, SHA384_DIGEST_SIZE, (HEX_KEY|HEX_MSG),
+	    "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+	       "aaaaaaaa",
+	    "dddddddddddddddddddddddddddddddd"
 	       "dddddddddddddddddddddddddddddddd"
 	       "dddddddddddddddddddddddddddddddd"
-	       "dddd"),
-	    H("88062608d3e6ad8a0aa2ace014c8a86f"
+	       "dddd",
+	    "88062608d3e6ad8a0aa2ace014c8a86f"
 	      "0aa635d947ac9febe83ef4e55966144b"
-	      "2a5ab39dc13814b94e3ab6e101a34f27"));
+	      "2a5ab39dc13814b94e3ab6e101a34f27");
 
-  HMAC_TEST(sha384, SHA384_DIGEST_SIZE,
-	    HL("0102030405060708090a0b0c0d0e0f10"
-	       "111213141516171819"),
-	    HL("cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd"
+  hmac_test(alg_sha384, SHA384_DIGEST_SIZE, (HEX_KEY|HEX_MSG),
+	    "0102030405060708090a0b0c0d0e0f10"
+	       "111213141516171819",
+	    "cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd"
 	       "cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd"
 	       "cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd"
-	       "cdcd"),
-	    H("3e8a69b7783c25851933ab6290af6ca7"
+	       "cdcd",
+	    "3e8a69b7783c25851933ab6290af6ca7"
 	      "7a9981480850009cc5577c6e1f573b4e"
-	      "6801dd23c4a7d679ccf8a386c674cffb"));
+	      "6801dd23c4a7d679ccf8a386c674cffb");
 
-  HMAC_TEST(sha384, 16,
-	    HL("0c0c0c0c0c0c0c0c 0c0c0c0c0c0c0c0c 0c0c0c0c"),
-	    LDATA("Test With Truncation"),
-	    H("3abf34c3503b2a23a46efc619baef897"));
+  hmac_test(alg_sha384, 16, HEX_KEY,
+	    "0c0c0c0c0c0c0c0c 0c0c0c0c0c0c0c0c 0c0c0c0c",
+	    "Test With Truncation",
+	    "3abf34c3503b2a23a46efc619baef897");
 
-  HMAC_TEST(sha384, SHA384_DIGEST_SIZE,
-	    HL("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+  hmac_test(alg_sha384, SHA384_DIGEST_SIZE, HEX_KEY,
+	    "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
 	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
 	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
 	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
@@ -686,14 +772,14 @@ test_main(void)
 	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
 	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
 	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
-	       "aaaaaa"),
-	    LDATA("Test Using Larger Than Block-Size Key - Hash Key First"),
-	    H("4ece084485813e9088d2c63a041bc5b4"
+	       "aaaaaa",
+	    "Test Using Larger Than Block-Size Key - Hash Key First",
+	    "4ece084485813e9088d2c63a041bc5b4"
 	      "4f9ef1012a2b588f3cd11f05033ac4c6"
-	      "0c2ef6ab4030fe8296248df163f44952"));
+	      "0c2ef6ab4030fe8296248df163f44952");
 
-  HMAC_TEST(sha384, SHA384_DIGEST_SIZE,
-	    HL("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+  hmac_test(alg_sha384, SHA384_DIGEST_SIZE, HEX_KEY,
+	    "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
 	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
 	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
 	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
@@ -701,64 +787,64 @@ test_main(void)
 	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
 	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
 	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
-	       "aaaaaa"),
-	    LDATA("This is a test using a larger than block-size ke"
+	       "aaaaaa",
+	    "This is a test using a larger than block-size ke"
 		  "y and a larger than block-size data. The key nee"
 		  "ds to be hashed before being used by the HMAC al"
-		  "gorithm."),
-	    H("6617178e941f020d351e2f254e8fd32c"
+		  "gorithm.",
+	    "6617178e941f020d351e2f254e8fd32c"
 	      "602420feb0b8fb9adccebb82461e99c5"
-	      "a678cc31e799176d3860e6110c46523e"));
+	      "a678cc31e799176d3860e6110c46523e");
 
   /* Test vectors for sha512, from RFC 4231 */
-  HMAC_TEST(sha512, SHA512_DIGEST_SIZE,
-	    HL("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b"
-	       "0b0b0b0b"),
-	    LDATA("Hi There"),
-	    H("87aa7cdea5ef619d4ff0b4241a1d6cb0"
+  hmac_test(alg_sha512, SHA512_DIGEST_SIZE, HEX_KEY,
+	    "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b"
+	       "0b0b0b0b",
+	    "Hi There",
+	    "87aa7cdea5ef619d4ff0b4241a1d6cb0"
 	      "2379f4e2ce4ec2787ad0b30545e17cde"
 	      "daa833b7d6b8a702038b274eaea3f4e4"
-	      "be9d914eeb61f1702e696c203a126854"));
+	      "be9d914eeb61f1702e696c203a126854");
 
-  HMAC_TEST(sha512, SHA512_DIGEST_SIZE,
-	    LDATA("Jefe"),
-	    LDATA("what do ya want for nothing?"),
-	    H("164b7a7bfcf819e2e395fbe73b56e0a3"
+  hmac_test(alg_sha512, SHA512_DIGEST_SIZE, HEX_NONE,
+	    "Jefe",
+	    "what do ya want for nothing?",
+	    "164b7a7bfcf819e2e395fbe73b56e0a3"
 	      "87bd64222e831fd610270cd7ea250554"
 	      "9758bf75c05a994a6d034f65f8f0e6fd"
-	      "caeab1a34d4a6b4b636e070a38bce737"));
+	      "caeab1a34d4a6b4b636e070a38bce737");
 
-  HMAC_TEST(sha512, SHA512_DIGEST_SIZE,
-	    HL("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
-	       "aaaaaaaa"),
-	    HL("dddddddddddddddddddddddddddddddd"
+  hmac_test(alg_sha512, SHA512_DIGEST_SIZE, (HEX_KEY|HEX_MSG),
+	    "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+	       "aaaaaaaa",
+	    "dddddddddddddddddddddddddddddddd"
 	       "dddddddddddddddddddddddddddddddd"
 	       "dddddddddddddddddddddddddddddddd"
-	       "dddd"),
-	    H("fa73b0089d56a284efb0f0756c890be9"
+	       "dddd",
+	    "fa73b0089d56a284efb0f0756c890be9"
 	      "b1b5dbdd8ee81a3655f83e33b2279d39"
 	      "bf3e848279a722c806b485a47e67c807"
-	      "b946a337bee8942674278859e13292fb"));
+	      "b946a337bee8942674278859e13292fb");
 
-  HMAC_TEST(sha512, SHA512_DIGEST_SIZE,
-	    HL("0102030405060708090a0b0c0d0e0f10"
-	       "111213141516171819"),
-	    HL("cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd"
+  hmac_test(alg_sha512, SHA512_DIGEST_SIZE, (HEX_KEY|HEX_MSG),
+	    "0102030405060708090a0b0c0d0e0f10"
+	       "111213141516171819",
+	    "cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd"
 	       "cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd"
 	       "cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd"
-	       "cdcd"),
-	    H("b0ba465637458c6990e5a8c5f61d4af7"
+	       "cdcd",
+	    "b0ba465637458c6990e5a8c5f61d4af7"
 	      "e576d97ff94b872de76f8050361ee3db"
 	      "a91ca5c11aa25eb4d679275cc5788063"
-	      "a5f19741120c4f2de2adebeb10a298dd"));
+	      "a5f19741120c4f2de2adebeb10a298dd");
 
-  HMAC_TEST(sha512, 16,
-	    HL("0c0c0c0c0c0c0c0c 0c0c0c0c0c0c0c0c 0c0c0c0c"),
-	    LDATA("Test With Truncation"),
-	    H("415fad6271580a531d4179bc891d87a6"));
+  hmac_test(alg_sha512, 16, HEX_KEY,
+	    "0c0c0c0c0c0c0c0c 0c0c0c0c0c0c0c0c 0c0c0c0c",
+	    "Test With Truncation",
+	    "415fad6271580a531d4179bc891d87a6");
 
-  HMAC_TEST(sha512, SHA512_DIGEST_SIZE,
-	    HL("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+  hmac_test(alg_sha512, SHA512_DIGEST_SIZE, HEX_KEY,
+	    "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
 	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
 	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
 	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
@@ -766,15 +852,15 @@ test_main(void)
 	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
 	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
 	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
-	       "aaaaaa"),
-	    LDATA("Test Using Larger Than Block-Size Key - Hash Key First"),
-	    H("80b24263c7c1a3ebb71493c1dd7be8b4"
+	       "aaaaaa",
+	    "Test Using Larger Than Block-Size Key - Hash Key First",
+	    "80b24263c7c1a3ebb71493c1dd7be8b4"
 	      "9b46d1f41b4aeec1121b013783f8f352"
 	      "6b56d037e05f2598bd0fd2215d6a1e52"
-	      "95e64f73f63f0aec8b915a985d786598"));
+	      "95e64f73f63f0aec8b915a985d786598");
 
-  HMAC_TEST(sha512, SHA512_DIGEST_SIZE,
-	    HL("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+  hmac_test(alg_sha512, SHA512_DIGEST_SIZE, HEX_KEY,
+	    "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
 	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
 	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
 	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
@@ -782,122 +868,122 @@ test_main(void)
 	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
 	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
 	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
-	       "aaaaaa"),
-	    LDATA("This is a test using a larger than block-size ke"
+	       "aaaaaa",
+	    "This is a test using a larger than block-size ke"
 		  "y and a larger than block-size data. The key nee"
 		  "ds to be hashed before being used by the HMAC al"
-		  "gorithm."),
-	    H("e37b6a775dc87dbaa4dfa9f96e5e3ffd"
+		  "gorithm.",
+	    "e37b6a775dc87dbaa4dfa9f96e5e3ffd"
 	      "debd71f8867289865df5a32d20cdc944"
 	      "b6022cac3c4982b10d5eeb55c3e4de15"
-	      "134676fb6de0446065c97440fa8c6a58"));
+	      "134676fb6de0446065c97440fa8c6a58");
 
   /* Additional test vectors, from Daniel Kahn Gillmor */
-  HMAC_TEST(sha512, SHA512_DIGEST_SIZE,
-	    LDATA("monkey monkey monkey monkey"),
-	    LDATA(""),
-	    H("34316413c2d6940572d0bbbf099d529d"
+  hmac_test(alg_sha512, SHA512_DIGEST_SIZE, HEX_NONE,
+	    "monkey monkey monkey monkey",
+	    "",
+	    "34316413c2d6940572d0bbbf099d529d"
 	      "148b424533cf562bc1b365f530e21a31"
 	      "799fc51cef78060cc6f448a8e5d780c2"
-	      "6cdf20d4c3e6f27fe5ef576bbd05e855"));
+	      "6cdf20d4c3e6f27fe5ef576bbd05e855");
   
-  HMAC_TEST(sha512, SHA512_DIGEST_SIZE,
-	    LDATA("monkey monkey monkey monkey"),
-	    LDATA("a"),
-	    H("cf1948507378bc3ab58cb6ec87f4d456"
+  hmac_test(alg_sha512, SHA512_DIGEST_SIZE, HEX_NONE,
+	    "monkey monkey monkey monkey",
+	    "a",
+	    "cf1948507378bc3ab58cb6ec87f4d456"
 	      "b90d3298395c29873f1ded1e111b50fe"
 	      "c336ed24684bf19716efc309212f37aa"
-	      "715cfb9ecccf3af13691ded167b4b336"));
+	      "715cfb9ecccf3af13691ded167b4b336");
   
-  HMAC_TEST(sha512, SHA512_DIGEST_SIZE,
-	    LDATA("monkey monkey monkey monkey"),
-	    LDATA("38"),
-	    H("b8201784216ce01b83cdd282616c6e89"
+  hmac_test(alg_sha512, SHA512_DIGEST_SIZE, HEX_NONE,
+	    "monkey monkey monkey monkey",
+	    "38",
+	    "b8201784216ce01b83cdd282616c6e89"
 	      "644c6dfd1269ed8580bbc39b92add364"
 	      "c2b2a2018cffb1915e8625e473b67d0f"
-	      "e54a50e475dfa0e2b1a97bac1383792c"));
+	      "e54a50e475dfa0e2b1a97bac1383792c");
   
-  HMAC_TEST(sha512, SHA512_DIGEST_SIZE,
-	    LDATA("monkey monkey monkey monkey"),
-	    LDATA("abc"),
-	    H("f097ee08b8c44e847a384f9fd645e35e"
+  hmac_test(alg_sha512, SHA512_DIGEST_SIZE, HEX_NONE,
+	    "monkey monkey monkey monkey",
+	    "abc",
+	    "f097ee08b8c44e847a384f9fd645e35e"
 	      "4816baa9791ba39d3dc611210500b044"
 	      "873ee296bf1047dc06daa201a5767192"
-	      "5b73b4ea59c60114881c8287d0699c83"));
+	      "5b73b4ea59c60114881c8287d0699c83");
   
-  HMAC_TEST(sha512, SHA512_DIGEST_SIZE,
-	    LDATA("monkey monkey monkey monkey"),
-	    LDATA("message digest"),
-	    H("921a441a884b83c76a8526da8e60d60d"
+  hmac_test(alg_sha512, SHA512_DIGEST_SIZE, HEX_NONE,
+	    "monkey monkey monkey monkey",
+	    "message digest",
+	    "921a441a884b83c76a8526da8e60d60d"
 	      "17ded4eee5c29375e0d93717669a4c3e"
 	      "eba7473e95f7c1a2a85afc24a0adbc4d"
-	      "6c2bdd6ca6cab8b18d19f82d4a6c51bc"));
+	      "6c2bdd6ca6cab8b18d19f82d4a6c51bc");
   
-  HMAC_TEST(sha512, SHA512_DIGEST_SIZE,
-	    LDATA("monkey monkey monkey monkey"),
-	    LDATA("abcdefghijklmnopqrstuvwxyz"),
-	    H("640054c96f35815095617d0a8c956066"
+  hmac_test(alg_sha512, SHA512_DIGEST_SIZE, HEX_NONE,
+	    "monkey monkey monkey monkey",
+	    "abcdefghijklmnopqrstuvwxyz",
+	    "640054c96f35815095617d0a8c956066"
 	      "1a6ff46bfb39110333b2c52c8866abfb"
 	      "59d9152c9b0948c1ed65c3fd72a8fb82"
-	      "190acc8830770afe5b0c5b6414c75a77"));
+	      "190acc8830770afe5b0c5b6414c75a77");
 
-  HMAC_TEST(sha512, SHA512_DIGEST_SIZE,
-	    LDATA("monkey monkey monkey monkey"),
-	    LDATA("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"),
-	    H("835a4f5b3750b4c1fccfa88da2f746a4"
+  hmac_test(alg_sha512, SHA512_DIGEST_SIZE, HEX_NONE,
+	    "monkey monkey monkey monkey",
+	    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
+	    "835a4f5b3750b4c1fccfa88da2f746a4"
 	      "900160c9f18964309bb736c13b59491b"
 	      "8e32d37b724cc5aebb0f554c6338a3b5"
-	      "94c4ba26862b2dadb59b7ede1d08d53e"));
+	      "94c4ba26862b2dadb59b7ede1d08d53e");
 
-  HMAC_TEST(sha512, SHA512_DIGEST_SIZE,
-	    LDATA("monkey monkey monkey monkey"),
-	    LDATA("12345678901234567890123456789012345678901234567890123456789012345678901234567890"),
-	    H("fdf83dc879e3476c8e8aceff2bf6fece"
+  hmac_test(alg_sha512, SHA512_DIGEST_SIZE, HEX_NONE,
+	    "monkey monkey monkey monkey",
+	    "12345678901234567890123456789012345678901234567890123456789012345678901234567890",
+	    "fdf83dc879e3476c8e8aceff2bf6fece"
 	      "2e4f39c7e1a167845465bb549dfa5ffe"
 	      "997e6c7cf3720eae51ed2b00ad2a8225"
-	      "375092290edfa9d48ec7e4bc8e276088"));
+	      "375092290edfa9d48ec7e4bc8e276088");
 
   /* Additional test vectors, from
      draft-kelly-ipsec-ciph-sha2-01.txt */
 
   /* Test case AUTH512-1: */
-  HMAC_TEST(sha512, SHA512_DIGEST_SIZE,
-	    HL("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b"
+  hmac_test(alg_sha512, SHA512_DIGEST_SIZE, HEX_KEY,
+	    "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b"
 	       "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b"
 	       "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b"
-	       "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b"),
-	    LDATA("Hi There"),
-	    H("637edc6e01dce7e6742a99451aae82df"
+	       "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b",
+	    "Hi There",
+	    "637edc6e01dce7e6742a99451aae82df"
 	      "23da3e92439e590e43e761b33e910fb8"
 	      "ac2878ebd5803f6f0b61dbce5e251ff8"
-	      "789a4722c1be65aea45fd464e89f8f5b"));
+	      "789a4722c1be65aea45fd464e89f8f5b");
 
   /* Test case AUTH512-2: */
-  HMAC_TEST(sha512, SHA512_DIGEST_SIZE,
-	    LDATA("JefeJefeJefeJefe"
+  hmac_test(alg_sha512, SHA512_DIGEST_SIZE, HEX_NONE,
+	    "JefeJefeJefeJefe"
 		  "JefeJefeJefeJefe"
 		  "JefeJefeJefeJefe"
-		  "JefeJefeJefeJefe"),	    
-	    LDATA("what do ya want for nothing?"),
-	    H("cb370917ae8a7ce28cfd1d8f4705d614"
+		  "JefeJefeJefeJefe",
+	    "what do ya want for nothing?",
+	    "cb370917ae8a7ce28cfd1d8f4705d614"
 	      "1c173b2a9362c15df235dfb251b15454"
 	      "6aa334ae9fb9afc2184932d8695e397b"
-	      "fa0ffb93466cfcceaae38c833b7dba38"));
+	      "fa0ffb93466cfcceaae38c833b7dba38");
 
   /* Test case AUTH512-3: */
-  HMAC_TEST(sha512, SHA512_DIGEST_SIZE,
-	    HL("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+  hmac_test(alg_sha512, SHA512_DIGEST_SIZE, (HEX_KEY|HEX_MSG),
+	    "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
 	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
 	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
-	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"),
-	    HL("dddddddddddddddddddddddddddddddd"
+	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
+	    "dddddddddddddddddddddddddddddddd"
 	       "dddddddddddddddddddddddddddddddd"
 	       "dddddddddddddddddddddddddddddddd"
-	       "dddd"),
-	    H("2ee7acd783624ca9398710f3ee05ae41"
+	       "dddd",
+	    "2ee7acd783624ca9398710f3ee05ae41"
 	      "b9f9b0510c87e49e586cc9bf961733d8"
 	      "623c7b55cebefccf02d5581acc1c9d5f"
-	      "b1ff68a1de45509fbe4da9a433922655"));
+	      "b1ff68a1de45509fbe4da9a433922655");
 
   /* Test case AUTH512-3 from same document seems broken. */
   
diff --git a/testsuite/md2-test.c b/testsuite/md2-test.c
index 8ab45c1..3d4a064 100644
--- a/testsuite/md2-test.c
+++ b/testsuite/md2-test.c
@@ -5,23 +5,23 @@ int
 test_main(void)
 {
   /* Testcases from RFC 1319 */
-  test_hash(&nettle_md2, 0, "",
-	    H("8350e5a3e24c153df2275c9f80692773"));
-  test_hash(&nettle_md2, LDATA("a"),
-	    H("32ec01ec4a6dac72c0ab96fb34c0b5d1"));
-  test_hash(&nettle_md2, LDATA("abc"),
-	    H("da853b0d3f88d99b30283a69e6ded6bb"));
-  test_hash(&nettle_md2, LDATA("message digest"),
-	    H("ab4f496bfb2a530b219ff33031fe06b0"));
-  test_hash(&nettle_md2, LDATA("abcdefghijklmnopqrstuvwxyz"),
-	    H("4e8ddff3650292ab5a4108c3aa47940b"));
+  test_hash(&nettle_md2, "",
+	    "8350e5a3e24c153df2275c9f80692773");
+  test_hash(&nettle_md2, "a",
+	    "32ec01ec4a6dac72c0ab96fb34c0b5d1");
+  test_hash(&nettle_md2, "abc",
+	    "da853b0d3f88d99b30283a69e6ded6bb");
+  test_hash(&nettle_md2, "message digest",
+	    "ab4f496bfb2a530b219ff33031fe06b0");
+  test_hash(&nettle_md2, "abcdefghijklmnopqrstuvwxyz",
+	    "4e8ddff3650292ab5a4108c3aa47940b");
   test_hash(&nettle_md2,
-	    LDATA("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
-		  "0123456789"),
-	    H("da33def2a42df13975352846c30338cd"));
-  test_hash(&nettle_md2, LDATA("1234567890123456789012345678901234567890"
-			       "1234567890123456789012345678901234567890"),
-	    H("d5976f79d83d3a0dc9806c3c66f3efd8"));
+	    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
+		  "0123456789",
+	    "da33def2a42df13975352846c30338cd");
+  test_hash(&nettle_md2, "1234567890123456789012345678901234567890"
+			       "1234567890123456789012345678901234567890",
+	    "d5976f79d83d3a0dc9806c3c66f3efd8");
 
   SUCCESS();
 }
diff --git a/testsuite/md4-test.c b/testsuite/md4-test.c
index 208456d..188c9d1 100644
--- a/testsuite/md4-test.c
+++ b/testsuite/md4-test.c
@@ -4,35 +4,36 @@
 int
 test_main(void)
 {
+// #define x) (sizeof(x) - 1), x
   /* Testcases from RFC 1320 */
-  test_hash(&nettle_md4, LDATA(""),
-	    H("31d6cfe0d16ae931b73c59d7e0c089c0"));
-  test_hash(&nettle_md4, LDATA("a"),
-	    H("bde52cb31de33e46245e05fbdbd6fb24"));
-  test_hash(&nettle_md4, LDATA("abc"),
-	    H("a448017aaf21d8525fc10ae87aa6729d"));
-  test_hash(&nettle_md4, LDATA("message digest"),
-	    H("d9130a8164549fe818874806e1c7014b"));
-  test_hash(&nettle_md4, LDATA("abcdefghijklmnopqrstuvwxyz"),
-	    H("d79e1c308aa5bbcdeea8ed63df412da9"));
+  test_hash(&nettle_md4, "",
+	    "31d6cfe0d16ae931b73c59d7e0c089c0");
+  test_hash(&nettle_md4, "a",
+	    "bde52cb31de33e46245e05fbdbd6fb24");
+  test_hash(&nettle_md4, "abc",
+	    "a448017aaf21d8525fc10ae87aa6729d");
+  test_hash(&nettle_md4, "message digest",
+	    "d9130a8164549fe818874806e1c7014b");
+  test_hash(&nettle_md4, "abcdefghijklmnopqrstuvwxyz",
+	    "d79e1c308aa5bbcdeea8ed63df412da9");
   test_hash(&nettle_md4,
-	    LDATA("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
-		  "0123456789"),
-	    H("043f8582f241db351ce627e153e7f0e4"));
+	    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
+		  "0123456789",
+	    "043f8582f241db351ce627e153e7f0e4");
   test_hash(&nettle_md4,
-	    LDATA("12345678901234567890123456789012345678901234567890"
-		  "123456789012345678901234567890"),
-	    H("e33b4ddc9c38f2199c3e7b164fcc0536"));
+	    "12345678901234567890123456789012345678901234567890"
+		  "123456789012345678901234567890",
+	    "e33b4ddc9c38f2199c3e7b164fcc0536");
 
   /* Additional test vectors, from Daniel Kahn Gillmor */
-  test_hash(&nettle_md4, LDATA("38"),
-	    H("ae9c7ebfb68ea795483d270f5934b71d"));
-  test_hash(&nettle_md4, LDATA("abc"),
-	    H("a448017aaf21d8525fc10ae87aa6729d"));
-  test_hash(&nettle_md4, LDATA("message digest"),
-	    H("d9130a8164549fe818874806e1c7014b"));
-  test_hash(&nettle_md4, LDATA("abcdefghijklmnopqrstuvwxyz"),
-	    H("d79e1c308aa5bbcdeea8ed63df412da9"));
+  test_hash(&nettle_md4, "38",
+	    "ae9c7ebfb68ea795483d270f5934b71d");
+  test_hash(&nettle_md4, "abc",
+	    "a448017aaf21d8525fc10ae87aa6729d");
+  test_hash(&nettle_md4, "message digest",
+	    "d9130a8164549fe818874806e1c7014b");
+  test_hash(&nettle_md4, "abcdefghijklmnopqrstuvwxyz",
+	    "d79e1c308aa5bbcdeea8ed63df412da9");
 
   SUCCESS();
 }
diff --git a/testsuite/md5-compat-test.c b/testsuite/md5-compat-test.c
index bffb623..0b5e6d1 100644
--- a/testsuite/md5-compat-test.c
+++ b/testsuite/md5-compat-test.c
@@ -1,60 +1,53 @@
 #include "testutils.h"
 #include "md5-compat.h"
 
-int
-test_main(void)
+static void
+test_md5_compat(const uint8_t *data, const uint8_t *result_hex)
 {
+  const uint8_t *result = decode_hex_dup(result_hex);
+
   MD5_CTX ctx;
   unsigned char digest[MD5_DIGEST_SIZE];
 
   MD5Init(&ctx);
-  MD5Final(digest, &ctx);
-  if (!MEMEQ(MD5_DIGEST_SIZE, digest, H("D41D8CD98F00B204 E9800998ECF8427E")))
-    FAIL();
-
-  MD5Init(&ctx);
-  MD5Update(&ctx, "a", 1);
+  MD5Update(&ctx, data, strlen(data));
   MD5Final(digest, &ctx);
 
-  if (!MEMEQ(MD5_DIGEST_SIZE, digest, H("0CC175B9C0F1B6A8 31C399E269772661")))
+  if (!MEMEQ(MD5_DIGEST_SIZE, digest, result))
     FAIL();
 
-  MD5Init(&ctx);
-  MD5Update(&ctx, "abc", 3);
-  MD5Final(digest, &ctx);
-
-  if (!MEMEQ(MD5_DIGEST_SIZE, digest, H("900150983cd24fb0 D6963F7D28E17F72")))
-    FAIL();
+  free((void *)result);
+}
 
-  MD5Init(&ctx);
-  MD5Update(&ctx, "message digest", 14);
-  MD5Final(digest, &ctx);
+int test_main(void)
+{
+  test_md5_compat("",
+	    "D41D8CD98F00B204 E9800998ECF8427E");
 
-  if (!MEMEQ(MD5_DIGEST_SIZE, digest, H("F96B697D7CB7938D 525A2F31AAF161D0")))
-    FAIL();
+  test_md5_compat("a",
+	    "0CC175B9C0F1B6A8 31C399E269772661");
 
-  MD5Init(&ctx);
-  MD5Update(&ctx, "abcdefghijklmnopqrstuvwxyz", 26);
-  MD5Final(digest, &ctx);
+  test_md5_compat("abc",
+	    "900150983cd24fb0 D6963F7D28E17F72");
 
-  if (!MEMEQ(MD5_DIGEST_SIZE, digest, H("C3FCD3D76192E400 7DFB496CCA67E13B")))
-    FAIL();
+  test_md5_compat("message digest",
+	    "F96B697D7CB7938D 525A2F31AAF161D0");
 
-  MD5Init(&ctx);
-  MD5Update(&ctx, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", 62);
-  MD5Final(digest, &ctx);
+  test_md5_compat("abcdefghijklmnopqrstuvwxyz",
+	    "C3FCD3D76192E400 7DFB496CCA67E13B");
 
-  if (!MEMEQ(MD5_DIGEST_SIZE, digest, H("D174AB98D277D9F5 A5611C2C9F419D9F")))
-    FAIL();
+  test_md5_compat("ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+	    "abcdefghijklmnopqrstuvwxyz"
+	    "0123456789",
+	    "D174AB98D277D9F5 A5611C2C9F419D9F");
 
-  MD5Init(&ctx);
-  MD5Update(&ctx, "1234567890123456789012345678901234567890"
+  test_md5_compat("1234567890123456789012345678901234567890"
 	    "1234567890123456789012345678901234567890",
-	    80);
-  MD5Final(digest, &ctx);
+	    "57EDF4A22BE3C955 AC49DA2E2107B67A");
 
-  if (!MEMEQ(MD5_DIGEST_SIZE, digest, H("57EDF4A22BE3C955 AC49DA2E2107B67A")))
-    FAIL();
+  /* Additional test vector, from Daniel Kahn Gillmor */
+  test_md5_compat("38",
+	    "a5771bce93e200c3 6f7cd9dfd0e5deaa");
 
   SUCCESS();
 }
diff --git a/testsuite/md5-test.c b/testsuite/md5-test.c
index 995f304..51ad024 100644
--- a/testsuite/md5-test.c
+++ b/testsuite/md5-test.c
@@ -4,35 +4,35 @@
 int
 test_main(void)
 {
-  test_hash(&nettle_md5, 0, "",
-	    H("D41D8CD98F00B204 E9800998ECF8427E"));
+  test_hash(&nettle_md5, "",
+	    "D41D8CD98F00B204 E9800998ECF8427E");
 
-  test_hash(&nettle_md5, 1, "a",
-	    H("0CC175B9C0F1B6A8 31C399E269772661"));
+  test_hash(&nettle_md5, "a",
+	    "0CC175B9C0F1B6A8 31C399E269772661");
 	    
-  test_hash(&nettle_md5, 3, "abc",
-	    H("900150983cd24fb0 D6963F7D28E17F72"));
+  test_hash(&nettle_md5, "abc",
+	    "900150983cd24fb0 D6963F7D28E17F72");
 
-  test_hash(&nettle_md5, 14, "message digest",
-	    H("F96B697D7CB7938D 525A2F31AAF161D0"));
+  test_hash(&nettle_md5, "message digest",
+	    "F96B697D7CB7938D 525A2F31AAF161D0");
   
-  test_hash(&nettle_md5, 26, "abcdefghijklmnopqrstuvwxyz",
-	    H("C3FCD3D76192E400 7DFB496CCA67E13B"));
+  test_hash(&nettle_md5, "abcdefghijklmnopqrstuvwxyz",
+	    "C3FCD3D76192E400 7DFB496CCA67E13B");
   
-  test_hash(&nettle_md5, 62,
+  test_hash(&nettle_md5,
 	    "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
 	    "abcdefghijklmnopqrstuvwxyz"
 	    "0123456789",
-	    H("D174AB98D277D9F5 A5611C2C9F419D9F"));
+	    "D174AB98D277D9F5 A5611C2C9F419D9F");
 
-  test_hash(&nettle_md5, 80,
+  test_hash(&nettle_md5,
 	    "1234567890123456789012345678901234567890"
 	    "1234567890123456789012345678901234567890",
-	    H("57EDF4A22BE3C955 AC49DA2E2107B67A"));
+	    "57EDF4A22BE3C955 AC49DA2E2107B67A");
 
   /* Additional test vector, from Daniel Kahn Gillmor */
-  test_hash(&nettle_md5, LDATA("38"),
-	    H("a5771bce93e200c3 6f7cd9dfd0e5deaa"));
+  test_hash(&nettle_md5, "38",
+	    "a5771bce93e200c3 6f7cd9dfd0e5deaa");
 
   /* Collisions, reported by Xiaoyun Wang1, Dengguo Feng2, Xuejia
      Lai3, Hongbo Yu1, http://eprint.iacr.org/2004/199. */
@@ -82,17 +82,17 @@ test_main(void)
   
 #define H1 "79054025 255fb1a2 6e4bc422 aef54eb4"
   
-  test_hash(&nettle_md5,
-	    HL(M0 N0), H(H0));
+  test_hash_hex(&nettle_md5,
+	    M0 N0, H0);
 
-  test_hash(&nettle_md5,
-	    HL(M1 N1), H(H0));
+  test_hash_hex(&nettle_md5,
+	    M1 N1, H0);
 
-  test_hash(&nettle_md5,
-	    HL(M0 N2), H(H1));
+  test_hash_hex(&nettle_md5,
+	    M0 N2, H1);
 
-  test_hash(&nettle_md5,
-	    HL(M1 N3), H(H1));
+  test_hash_hex(&nettle_md5,
+	    M1 N3, H1);
 
   SUCCESS();
 }
diff --git a/testsuite/memxor-test.c b/testsuite/memxor-test.c
index 8c191f3..8c4388d 100644
--- a/testsuite/memxor-test.c
+++ b/testsuite/memxor-test.c
@@ -145,5 +145,9 @@ test_main(void)
 	    test_memxor3 (a, b, c, size[i], align_dst, align_a, align_b);
 	}
 
+  free((void *)c);
+  free((void *)b);
+  free((void *)a);
+
   SUCCESS();
 }
diff --git a/testsuite/random-prime-test.c b/testsuite/random-prime-test.c
index 6fdb449..ac37576 100644
--- a/testsuite/random-prime-test.c
+++ b/testsuite/random-prime-test.c
@@ -23,6 +23,7 @@ test_main(void)
       ASSERT (mpz_sizeinbase (p, 2) == bits);
       ASSERT (mpz_probab_prime_p(p, 25));
     }
+  mpz_clear(p);
 
   SUCCESS();
 }
diff --git a/testsuite/ripemd160-test.c b/testsuite/ripemd160-test.c
index 1237b70..4d30612 100644
--- a/testsuite/ripemd160-test.c
+++ b/testsuite/ripemd160-test.c
@@ -4,34 +4,34 @@
 int
 test_main(void)
 {
-  test_hash(&nettle_ripemd160, 0, "",
-      H("9c1185a5c5e9fc54612808977ee8f548b2258d31"));
+  test_hash(&nettle_ripemd160, "",
+      "9c1185a5c5e9fc54612808977ee8f548b2258d31");
 
-  test_hash(&nettle_ripemd160, 1, "a",
-      H("0bdc9d2d256b3ee9daae347be6f4dc835a467ffe"));
+  test_hash(&nettle_ripemd160, "a",
+      "0bdc9d2d256b3ee9daae347be6f4dc835a467ffe");
 
-  test_hash(&nettle_ripemd160, 3, "abc",
-      H("8eb208f7e05d987a9b044a8e98c6b087f15a0bfc"));
+  test_hash(&nettle_ripemd160, "abc",
+      "8eb208f7e05d987a9b044a8e98c6b087f15a0bfc");
 
-  test_hash(&nettle_ripemd160, 26, "abcdefghijklmnopqrstuvwxyz",
-      H("f71c27109c692c1b56bbdceb5b9d2865b3708dbc"));
+  test_hash(&nettle_ripemd160, "abcdefghijklmnopqrstuvwxyz",
+      "f71c27109c692c1b56bbdceb5b9d2865b3708dbc");
 
-  test_hash(&nettle_ripemd160, 14, "message digest",
-      H("5d0689ef49d2fae572b881b123a85ffa21595f36"));
+  test_hash(&nettle_ripemd160, "message digest",
+      "5d0689ef49d2fae572b881b123a85ffa21595f36");
 
-  test_hash(&nettle_ripemd160, 62,
+  test_hash(&nettle_ripemd160,
       "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
       "abcdefghijklmnopqrstuvwxyz0123456789",
-      H("b0e20b6e3116640286ed3a87a5713079b21f5189"));
+      "b0e20b6e3116640286ed3a87a5713079b21f5189");
 
-  test_hash(&nettle_ripemd160,  80,
+  test_hash(&nettle_ripemd160,
       "1234567890123456789012345678901234567890"
       "1234567890123456789012345678901234567890",
-      H("9b752e45573d4b39f4dbd3323cab82bf63326bfb"));
+      "9b752e45573d4b39f4dbd3323cab82bf63326bfb");
 
   /* Additional test vector, from Daniel Kahn Gillmor */
-  test_hash(&nettle_ripemd160, LDATA("38"),
-      H("6b2d075b1cd34cd1c3e43a995f110c55649dad0e"));
+  test_hash(&nettle_ripemd160, "38",
+      "6b2d075b1cd34cd1c3e43a995f110c55649dad0e");
 
   SUCCESS();
 }
diff --git a/testsuite/rsa2sexp-test.c b/testsuite/rsa2sexp-test.c
index 596a978..00cfb8d 100644
--- a/testsuite/rsa2sexp-test.c
+++ b/testsuite/rsa2sexp-test.c
@@ -57,7 +57,7 @@ test_main(void)
       print_hex(buffer.size, buffer.contents);  
     }
   
-  ASSERT(MEMEQH(buffer.size, buffer.contents,
+  ASSERT(memeq_hex(buffer.size, buffer.contents,
 		"2831313a707269766174652d6b657928"
 		"333a72736128313a6e36333a085c3408"
 		"989acae4faec3cbbad91c90d34c1d259"
@@ -91,7 +91,8 @@ test_main(void)
       printf("public:");
       print_hex(buffer.size, buffer.contents);  
     }
-  ASSERT(MEMEQH(buffer.size, buffer.contents,
+
+  ASSERT(memeq_hex(buffer.size, buffer.contents,
 		"2831303a7075626c69632d6b65792839"
 		"3a7273612d706b63733128313a6e3633"
 		"3a085c3408989acae4faec3cbbad91c9"
@@ -103,5 +104,7 @@ test_main(void)
   rsa_public_key_clear(&pub);
   rsa_private_key_clear(&priv);
   
+  nettle_buffer_clear(&buffer);
+
   SUCCESS();
 }
diff --git a/testsuite/salsa20-test.c b/testsuite/salsa20-test.c
index 7a246b9..af61dc9 100644
--- a/testsuite/salsa20-test.c
+++ b/testsuite/salsa20-test.c
@@ -13,18 +13,23 @@ memzero_p (const uint8_t *p, size_t n)
   return 1;
 }
 
-/* The ecrypt testcases encrypt 512 zero bytes (8 blocks), then give
-   the xor of all blocks, and the data for block 0 (0-43), 3,4
-   (192-319), 7 (448-511) */
+/* The ecrypt testcases encrypt 512 zero bytes (8 blocks, then give
+   the xor of all blocks, and the data for block 0 (0-43, 3,4
+   (192-319, 7 (448-511) */
 
 #define STREAM_LENGTH 512
 static void
-test_salsa20_stream(unsigned key_length,
-		    const uint8_t *key,
-		    const uint8_t *iv,
-		    const uint8_t *ciphertext,
-		    const uint8_t *xor_ref)
+test_salsa20_stream(const uint8_t *key_hex,
+		    const uint8_t *iv_hex,
+		    const uint8_t *ciphertext_hex,
+		    const uint8_t *xor_ref_hex)
 {
+  unsigned key_length = decode_hex_length(key_hex);
+  const uint8_t *key = decode_hex_dup(key_hex);
+  const uint8_t *iv = decode_hex_dup(iv_hex);
+  const uint8_t *ciphertext = decode_hex_dup(ciphertext_hex);
+  const uint8_t *xor_ref = decode_hex_dup(xor_ref_hex);
+
   struct salsa20_ctx ctx;
   uint8_t data[STREAM_LENGTH + 1];
   uint8_t stream[STREAM_LENGTH + 1];
@@ -111,16 +116,26 @@ test_salsa20_stream(unsigned key_length,
 	  FAIL();
 	}
     }
+
+  free((void *)xor_ref);
+  free((void *)ciphertext);
+  free((void *)iv);
+  free((void *)key);
 }
 
 static void
-test_salsa20(unsigned key_length,
-	     const uint8_t *key,
-	     const uint8_t *iv,
-	     unsigned length,
-	     const uint8_t *cleartext,
-	     const uint8_t *ciphertext)
+test_salsa20(const uint8_t *key_hex,
+	     const uint8_t *iv_hex,
+	     const uint8_t *cleartext_hex,
+	     const uint8_t *ciphertext_hex)
 {
+  unsigned key_length = decode_hex_length(key_hex);
+  const uint8_t *key = decode_hex_dup(key_hex);
+  const uint8_t *iv = decode_hex_dup(iv_hex);
+  unsigned length = decode_hex_length(cleartext_hex);
+  const uint8_t *cleartext = decode_hex_dup(cleartext_hex);
+  const uint8_t *ciphertext = decode_hex_dup(ciphertext_hex);
+
   struct salsa20_ctx ctx;
   uint8_t *data = xalloc(length + 1);
 
@@ -163,6 +178,10 @@ test_salsa20(unsigned key_length,
     }
 
   free(data);
+  free((void *)ciphertext);
+  free((void *)cleartext);
+  free((void *)iv);
+  free((void *)key);
 }
   
 int
@@ -170,42 +189,42 @@ test_main(void)
 {
   /* http://www.ecrypt.eu.org/stream/svn/viewcvs.cgi/ecrypt/trunk/submissions/salsa20/full/verified.test-vectors?logsort=rev&rev=210&view=markup */
 
-  test_salsa20(HL("80000000 00000000 00000000 00000000"),
-	       H("00000000 00000000"),
-	       HL("00000000 00000000"),
-	       H("4DFA5E48 1DA23EA0"));
-
-  test_salsa20(HL("00000000 00000000 00000000 00000000"),
-	       H("80000000 00000000"),
-	       HL("00000000 00000000"),
-	       H("B66C1E44 46DD9557"));
-
-  test_salsa20(HL("0053A6F94C9FF24598EB3E91E4378ADD"),
-	       H("0D74DB42A91077DE"),
-	       HL("00000000 00000000"),
-	       H("05E1E7BE B697D999"));
-
-  test_salsa20(HL("80000000 00000000 00000000 00000000"
-		  "00000000 00000000 00000000 00000000"),
-	       H("00000000 00000000"),
-	       HL("00000000 00000000"),
-	       H("E3BE8FDD 8BECA2E3"));
-
-  test_salsa20(HL("00000000 00000000 00000000 00000000"
-		  "00000000 00000000 00000000 00000000"),
-	       H("80000000 00000000"),
-	       HL("00000000 00000000"),
-	       H("2ABA3DC45B494700"));
-
-  test_salsa20(HL("0053A6F94C9FF24598EB3E91E4378ADD"
-		  "3083D6297CCF2275C81B6EC11467BA0D"),
-	       H("0D74DB42A91077DE"),
-	       HL("00000000 00000000"),
-	       H("F5FAD53F 79F9DF58"));
-
-  test_salsa20_stream(HL("80000000000000000000000000000000"),
-		      H("00000000 00000000"),
-		      H("4DFA5E481DA23EA09A31022050859936"
+  test_salsa20("80000000 00000000 00000000 00000000",
+	       "00000000 00000000",
+	       "00000000 00000000",
+	       "4DFA5E48 1DA23EA0");
+
+  test_salsa20("00000000 00000000 00000000 00000000",
+	       "80000000 00000000",
+	       "00000000 00000000",
+	       "B66C1E44 46DD9557");
+
+  test_salsa20("0053A6F94C9FF24598EB3E91E4378ADD",
+	       "0D74DB42A91077DE",
+	       "00000000 00000000",
+	       "05E1E7BE B697D999");
+
+  test_salsa20("80000000 00000000 00000000 00000000"
+		  "00000000 00000000 00000000 00000000",
+	       "00000000 00000000",
+	       "00000000 00000000",
+	       "E3BE8FDD 8BECA2E3");
+
+  test_salsa20("00000000 00000000 00000000 00000000"
+		  "00000000 00000000 00000000 00000000",
+	       "80000000 00000000",
+	       "00000000 00000000",
+	       "2ABA3DC45B494700");
+
+  test_salsa20("0053A6F94C9FF24598EB3E91E4378ADD"
+		  "3083D6297CCF2275C81B6EC11467BA0D",
+	       "0D74DB42A91077DE",
+	       "00000000 00000000",
+	       "F5FAD53F 79F9DF58");
+
+  test_salsa20_stream("80000000000000000000000000000000",
+		      "00000000 00000000",
+		      "4DFA5E481DA23EA09A31022050859936"
 			"DA52FCEE218005164F267CB65F5CFD7F"
 			"2B4F97E0FF16924A52DF269515110A07"
 			"F9E460BC65EF95DA58F740B7D1DBB0AA"
@@ -220,16 +239,16 @@ test_main(void)
 			"B375703739DACED4DD4059FD71C3C47F"
 			"C2F9939670FAD4A46066ADCC6A564578"
 			"3308B90FFB72BE04A6B147CBE38CC0C3"
-			"B9267C296A92A7C69873F9F263BE9703"),
-		      H("F7A274D268316790A67EC058F45C0F2A"
+			"B9267C296A92A7C69873F9F263BE9703",
+		      "F7A274D268316790A67EC058F45C0F2A"
 			"067A99FCDE6236C0CEF8E056349FE54C"
 			"5F13AC74D2539570FD34FEAB06C57205"
-			"3949B59585742181A5A760223AFA22D4"));
+			"3949B59585742181A5A760223AFA22D4");
 
-  test_salsa20_stream(HL("48494A4B4C4D4E4F5051525354555657"
-			 "58595A5B5C5D5E5F6061626364656667"),
-		      H("0000000000000000"),
-		      H("53AD3698A011F779AD71030F3EFBEBA0"
+  test_salsa20_stream("48494A4B4C4D4E4F5051525354555657"
+			 "58595A5B5C5D5E5F6061626364656667",
+		      "0000000000000000",
+		      "53AD3698A011F779AD71030F3EFBEBA0"
 			"A7EE3C55789681B1591EF33A7BE521ED"
 			"68FC36E58F53FFD6E1369B00E390E973"
 			"F656ACB097E0D603BE59A0B8F7975B98"
@@ -244,11 +263,11 @@ test_main(void)
 			"B505D41E2C207FA1C0A0E93413DDCFFC"
 			"9BECA8030AFFAC2466E56482DA0EF428"
 			"E63880B5021D3051F18679505A2B9D4F"
-			"9B2C5A2D271D276DE3F51DBEBA934436"),
-		      H("7849651A820B1CDFE36D5D6632716534"
+			"9B2C5A2D271D276DE3F51DBEBA934436",
+		      "7849651A820B1CDFE36D5D6632716534"
 			"E0635EDEFD538122D80870B60FB055DB"
 			"637C7CA2B78B116F83AFF46E40F8F71D"
-			"4CD6D2E1B750D5E011D1DF2E80F7210A"));
+			"4CD6D2E1B750D5E011D1DF2E80F7210A");
 
   SUCCESS();
 }
diff --git a/testsuite/serpent-test.c b/testsuite/serpent-test.c
index d9e193b..715482c 100644
--- a/testsuite/serpent-test.c
+++ b/testsuite/serpent-test.c
@@ -19,31 +19,55 @@ decode_hex_reverse (const char *hex)
   return p;
 }
 
-#define RH(x) decode_hex_reverse(x)
-#define RHL(x) decode_hex_length(x), decode_hex_reverse(x)
+void
+test_cipher_reverse(const struct nettle_cipher *cipher,
+	    const uint8_t *key_hex,
+	    const uint8_t *cleartext_hex,
+	    const uint8_t *ciphertext_hex)
+{
+  unsigned key_length = decode_hex_length(key_hex);
+  const uint8_t *key = decode_hex_reverse(key_hex);
+  unsigned cleartext_length = decode_hex_length(cleartext_hex);
+  const uint8_t *cleartext = decode_hex_reverse(cleartext_hex);
+  unsigned ciphertext_length = decode_hex_length(ciphertext_hex);
+  const uint8_t *ciphertext = decode_hex_reverse(ciphertext_hex);
+
+  key_hex = encode_hex_dup(key, key_length);
+  cleartext_hex = encode_hex_dup(cleartext, cleartext_length);
+  ciphertext_hex = encode_hex_dup(ciphertext, ciphertext_length);
+
+  test_cipher(cipher, key_hex, cleartext_hex, ciphertext_hex);
+
+  free((void *)ciphertext_hex);
+  free((void *)cleartext_hex);
+  free((void *)key_hex);
+  free((void *)ciphertext);
+  free((void *)cleartext);
+  free((void *)key);
+}
 
 int
 test_main(void)
 {
   /* From libgcrypt */
   test_cipher(&nettle_serpent128,
-	      HL("0000000000000000 0000000000000000"),
-	      HL("D29D576FCEA3A3A7 ED9099F29273D78E"),
-	      H("B2288B968AE8B086 48D1CE9606FD992D"));
+	      "0000000000000000 0000000000000000",
+	      "D29D576FCEA3A3A7 ED9099F29273D78E",
+	      "B2288B968AE8B086 48D1CE9606FD992D");
   test_cipher(&nettle_serpent192,
-	      HL("0000000000000000 0000000000000000 0000000000000000"),
-	      HL("D29D576FCEABA3A7 ED9899F2927BD78E"),
-	      H("130E353E1037C224 05E8FAEFB2C3C3E9"));
+	      "0000000000000000 0000000000000000 0000000000000000",
+	      "D29D576FCEABA3A7 ED9899F2927BD78E",
+	      "130E353E1037C224 05E8FAEFB2C3C3E9");
   test_cipher(&nettle_serpent256,
-	      HL("0000000000000000 0000000000000000"
-		 "0000000000000000 0000000000000000"),
-	      HL("D095576FCEA3E3A7 ED98D9F29073D78E"),
-	      H("B90EE5862DE69168 F2BDD5125B45472B"));
+	      "0000000000000000 0000000000000000"
+		 "0000000000000000 0000000000000000",
+	      "D095576FCEA3E3A7 ED98D9F29073D78E",
+	      "B90EE5862DE69168 F2BDD5125B45472B");
   test_cipher(&nettle_serpent256,
-	      HL("0000000000000000 0000000000000000"
-		 "0000000000000000 0000000000000000"),
-	      HL("0000000001000000 0200000003000000"),
-	      H("2061A42782BD52EC 691EC383B03BA77C"));
+	      "0000000000000000 0000000000000000"
+		 "0000000000000000 0000000000000000",
+	      "0000000001000000 0200000003000000",
+	      "2061A42782BD52EC 691EC383B03BA77C");
 
   /* The first test for each key size from the ecb_vk.txt and ecb_vt.txt
    * files in the serpent package. */
@@ -53,48 +77,48 @@ test_main(void)
   /* 128 bit key */
 
   /* vk, 1 */
-  test_cipher(&nettle_serpent128,
-	      RHL("8000000000000000 0000000000000000"),
-	      RHL("0000000000000000 0000000000000000"),
-	      RH("49AFBFAD9D5A3405 2CD8FFA5986BD2DD"));
+  test_cipher_reverse(&nettle_serpent128,
+	      "8000000000000000 0000000000000000",
+	      "0000000000000000 0000000000000000",
+	      "49AFBFAD9D5A3405 2CD8FFA5986BD2DD");
 
   /* vt, 1 */
-  test_cipher(&nettle_serpent128,
-	      RHL("0000000000000000 0000000000000000"),
-	      RHL("8000000000000000 0000000000000000"),
-	      RH("10B5FFB720B8CB90 02A1142B0BA2E94A"));
+  test_cipher_reverse(&nettle_serpent128,
+	      "0000000000000000 0000000000000000",
+	      "8000000000000000 0000000000000000",
+	      "10B5FFB720B8CB90 02A1142B0BA2E94A");
 
   /* 192 bit key */
 
   /* vk, 1 */
-  test_cipher(&nettle_serpent192,
-	      RHL("8000000000000000 0000000000000000"
-		 "0000000000000000"),
-	      RHL("0000000000000000 0000000000000000"),
-	      RH("E78E5402C7195568 AC3678F7A3F60C66"));
+  test_cipher_reverse(&nettle_serpent192,
+	      "8000000000000000 0000000000000000"
+		 "0000000000000000",
+	      "0000000000000000 0000000000000000",
+	      "E78E5402C7195568 AC3678F7A3F60C66");
 
   /* vt, 1 */
-  test_cipher(&nettle_serpent192,
-	      RHL("0000000000000000 0000000000000000"
-		 "0000000000000000"),
-	      RHL("8000000000000000 0000000000000000"),
-	      RH("B10B271BA25257E1 294F2B51F076D0D9"));
+  test_cipher_reverse(&nettle_serpent192,
+	      "0000000000000000 0000000000000000"
+		 "0000000000000000",
+	      "8000000000000000 0000000000000000",
+	      "B10B271BA25257E1 294F2B51F076D0D9");
 
   /* 256 bit key */
 
   /* vk, 1 */
-  test_cipher(&nettle_serpent256,
-	      RHL("8000000000000000 0000000000000000"
-		 "0000000000000000 0000000000000000"),
-	      RHL("0000000000000000 0000000000000000"),
-	      RH("ABED96E766BF28CB C0EBD21A82EF0819"));
+  test_cipher_reverse(&nettle_serpent256,
+	      "8000000000000000 0000000000000000"
+		 "0000000000000000 0000000000000000",
+	      "0000000000000000 0000000000000000",
+	      "ABED96E766BF28CB C0EBD21A82EF0819");
 
   /* vt, 1 */
-  test_cipher(&nettle_serpent256,
-	      RHL("0000000000000000 0000000000000000"
-		 "0000000000000000 0000000000000000"),
-	      RHL("8000000000000000 0000000000000000"),
-	      RH("DA5A7992B1B4AE6F 8C004BC8A7DE5520"));
+  test_cipher_reverse(&nettle_serpent256,
+	      "0000000000000000 0000000000000000"
+		 "0000000000000000 0000000000000000",
+	      "8000000000000000 0000000000000000",
+	      "DA5A7992B1B4AE6F 8C004BC8A7DE5520");
 
   /* Test vectors from
      http://www.cs.technion.ac.il/~biham/Reports/Serpent/ */
@@ -102,190 +126,190 @@ test_main(void)
   /* serpent128 */
   /* Set 4, vector#  0 */
   test_cipher(&nettle_serpent128,
-	      HL("000102030405060708090A0B0C0D0E0F"),
-	      HL("00112233445566778899AABBCCDDEEFF"),
-	      H("563E2CF8740A27C164804560391E9B27"));
+	      "000102030405060708090A0B0C0D0E0F",
+	      "00112233445566778899AABBCCDDEEFF",
+	      "563E2CF8740A27C164804560391E9B27");
 
   /* Set 4, vector#  1 */
   test_cipher(&nettle_serpent128,
-	      HL("2BD6459F82C5B300952C49104881FF48"),
-	      HL("EA024714AD5C4D84EA024714AD5C4D84"),
-	      H("92D7F8EF2C36C53409F275902F06539F"));
+	      "2BD6459F82C5B300952C49104881FF48",
+	      "EA024714AD5C4D84EA024714AD5C4D84",
+	      "92D7F8EF2C36C53409F275902F06539F");
 
   /* serpent192 */
   /* Set 4, vector#  0 */
   test_cipher(&nettle_serpent192,
-	      HL("000102030405060708090A0B0C0D0E0F1011121314151617"),
-	      HL("00112233445566778899AABBCCDDEEFF"),
-	      H("6AB816C82DE53B93005008AFA2246A02"));
+	      "000102030405060708090A0B0C0D0E0F1011121314151617",
+	      "00112233445566778899AABBCCDDEEFF",
+	      "6AB816C82DE53B93005008AFA2246A02");
 
   /* Set 4, vector#  1 */
   test_cipher(&nettle_serpent192,
-	      HL("2BD6459F82C5B300952C49104881FF482BD6459F82C5B300"),
-	      HL("EA024714AD5C4D84EA024714AD5C4D84"),
-	      H("827B18C2678A239DFC5512842000E204"));
+	      "2BD6459F82C5B300952C49104881FF482BD6459F82C5B300",
+	      "EA024714AD5C4D84EA024714AD5C4D84",
+	      "827B18C2678A239DFC5512842000E204");
 
   /* serpent256 */
   /* Set 4, vector#  0 */
   test_cipher(&nettle_serpent256,
-	      HL("000102030405060708090A0B0C0D0E0F"
-		 "101112131415161718191A1B1C1D1E1F"),
-	      HL("00112233445566778899AABBCCDDEEFF"),
-	      H("2868B7A2D28ECD5E4FDEFAC3C4330074"));
+	      "000102030405060708090A0B0C0D0E0F"
+		 "101112131415161718191A1B1C1D1E1F",
+	      "00112233445566778899AABBCCDDEEFF",
+	      "2868B7A2D28ECD5E4FDEFAC3C4330074");
 
   /* Set 4, vector#  1 */
   test_cipher(&nettle_serpent256,
-	      HL("2BD6459F82C5B300952C49104881FF48"
-		 "2BD6459F82C5B300952C49104881FF48"),
-	      HL("EA024714AD5C4D84EA024714AD5C4D84"),
-	      H("3E507730776B93FDEA661235E1DD99F0"));
+	      "2BD6459F82C5B300952C49104881FF48"
+		 "2BD6459F82C5B300952C49104881FF48",
+	      "EA024714AD5C4D84EA024714AD5C4D84",
+	      "3E507730776B93FDEA661235E1DD99F0");
 
   /* Test key padding. We use nettle_serpent256, which actually works
      also with key sizes smaller than 32 bytes. */
   test_cipher(&nettle_serpent256,
-	      HL("00112233440100000000000000000000"
-		 "00000000000000000000000000000000"),
-	      HL("0000000001000000 0200000003000000"),
-	      H("C1415AC653FD7C7F D917482EE8EBFE25"));
+	      "00112233440100000000000000000000"
+		 "00000000000000000000000000000000",
+	      "0000000001000000 0200000003000000",
+	      "C1415AC653FD7C7F D917482EE8EBFE25");
 
   /* Currrently, key sizes smaller than SERPENT_MIN_KEY_SIZE bytes
      (128 bits) are not supported. */
   test_cipher(&nettle_serpent256,
-	      HL("0011223344"),
-	      HL("0000000001000000 0200000003000000"),
-	      H("C1415AC653FD7C7F D917482EE8EBFE25"));
+	      "0011223344",
+	      "0000000001000000 0200000003000000",
+	      "C1415AC653FD7C7F D917482EE8EBFE25");
 
   test_cipher(&nettle_serpent256,
-	      HL("00112233445566778899aabbccddeeff"
-		 "00010000000000000000000000000000"),
-	      HL("0000000001000000 0200000003000000"),
-	      H("8EB9C958EAFFDF42 009755D7B6458838"));
+	      "00112233445566778899aabbccddeeff"
+		 "00010000000000000000000000000000",
+	      "0000000001000000 0200000003000000",
+	      "8EB9C958EAFFDF42 009755D7B6458838");
 
   test_cipher(&nettle_serpent256,
-	      HL("00112233445566778899aabbccddeeff"
-		 "00"),
-	      HL("0000000001000000 0200000003000000"),
-	      H("8EB9C958EAFFDF42 009755D7B6458838"));
+	      "00112233445566778899aabbccddeeff"
+		 "00",
+	      "0000000001000000 0200000003000000",
+	      "8EB9C958EAFFDF42 009755D7B6458838");
 
   test_cipher(&nettle_serpent256,
-	      HL("00112233445566778899aabbccddeeff"
-		 "00112201000000000000000000000000"),
-	      HL("0000000001000000 0200000003000000"),
-	      H("C8A078D8212AC96D 9060E30EC5CBB5C7"));
+	      "00112233445566778899aabbccddeeff"
+		 "00112201000000000000000000000000",
+	      "0000000001000000 0200000003000000",
+	      "C8A078D8212AC96D 9060E30EC5CBB5C7");
 
   test_cipher(&nettle_serpent256,
-	      HL("00112233445566778899aabbccddeeff"
-		 "001122"),
-	      HL("0000000001000000 0200000003000000"),
-	      H("C8A078D8212AC96D 9060E30EC5CBB5C7"));
+	      "00112233445566778899aabbccddeeff"
+		 "001122",
+	      "0000000001000000 0200000003000000",
+	      "C8A078D8212AC96D 9060E30EC5CBB5C7");
 
   /* Test with multiple blocks. */
   test_cipher(&nettle_serpent128,
-	      HL("e87450aa0fd87293fd0371483a459bd2"),
-	      HL("a78a7a8d392f629d bd13674c8dce6fa2"),
-	      H("b3d488986c80dea7 c5ebdab4907871c9"));
+	      "e87450aa0fd87293fd0371483a459bd2",
+	      "a78a7a8d392f629d bd13674c8dce6fa2",
+	      "b3d488986c80dea7 c5ebdab4907871c9");
 
   test_cipher(&nettle_serpent128,
-	      HL("e87450aa0fd87293fd0371483a459bd2"),
-	      HL("a78a7a8d392f629d bd13674c8dce6fa2"
-		 "930c74dec02a11d8 c80d90b5e5c887a7"),
-	      H("b3d488986c80dea7 c5ebdab4907871c9"
-		"a4b92b13b79afb37 5518b01bfd706a37"));
+	      "e87450aa0fd87293fd0371483a459bd2",
+	      "a78a7a8d392f629d bd13674c8dce6fa2"
+		 "930c74dec02a11d8 c80d90b5e5c887a7",
+	      "b3d488986c80dea7 c5ebdab4907871c9"
+		"a4b92b13b79afb37 5518b01bfd706a37");
 
   test_cipher(&nettle_serpent128,
-	      HL("e87450aa0fd87293fd0371483a459bd2"),
-	      HL("a78a7a8d392f629d bd13674c8dce6fa2"
+	      "e87450aa0fd87293fd0371483a459bd2",
+	      "a78a7a8d392f629d bd13674c8dce6fa2"
 		 "930c74dec02a11d8 c80d90b5e5c887a7"
-		 "83c92a921b5b2028 d9cb313a5f07ab09"),
-	      H("b3d488986c80dea7 c5ebdab4907871c9"
+		 "83c92a921b5b2028 d9cb313a5f07ab09",
+	      "b3d488986c80dea7 c5ebdab4907871c9"
 		"a4b92b13b79afb37 5518b01bfd706a37"
-		"8e44c2d463df4531 165461699edbad03"));
+		"8e44c2d463df4531 165461699edbad03");
 
   test_cipher(&nettle_serpent128,
-	      HL("91c8e949e12f0e38 7b2473238a3df1b6"),
-	      HL("00000000 00000001 00000002 00000003"
+	      "91c8e949e12f0e38 7b2473238a3df1b6",
+	      "00000000 00000001 00000002 00000003"
 		 "00000004 00000005 00000006 00000007"
 		 "00000008 00000009 0000000a 0000000b"
-		 "0000000c 0000000d 0000000e 0000000f"),
-	      H("2db9f0a39d4f31a4 b1a83cd1032fe1bd"
+		 "0000000c 0000000d 0000000e 0000000f",
+	      "2db9f0a39d4f31a4 b1a83cd1032fe1bd"
 		"3606caa84a220b1b f6f43ff80a831203"
 		"8c6c8d2793dc10b3 904d30e194f086a6"
-		"b2f3e932b9b3f8d1 d4d074f7bd1ff7a3"));
+		"b2f3e932b9b3f8d1 d4d074f7bd1ff7a3");
 	      
   test_cipher(&nettle_serpent128,
-	      HL("e87450aa0fd87293fd0371483a459bd2"),
-	      HL("a78a7a8d392f629d bd13674c8dce6fa2"
+	      "e87450aa0fd87293fd0371483a459bd2",
+	      "a78a7a8d392f629d bd13674c8dce6fa2"
 		 "930c74dec02a11d8 c80d90b5e5c887a7"
 		 "83c92a921b5b2028 d9cb313a5f07ab09"
-		 "672eadf1624a2ed0 c42d1b08b076f75a"),
-	      H("b3d488986c80dea7 c5ebdab4907871c9"
+		 "672eadf1624a2ed0 c42d1b08b076f75a",
+	      "b3d488986c80dea7 c5ebdab4907871c9"
 		"a4b92b13b79afb37 5518b01bfd706a37"
 		"8e44c2d463df4531 165461699edbad03"
-		"30ac8c52697102ae 3b725dba79ceb250"));
+		"30ac8c52697102ae 3b725dba79ceb250");
 
   test_cipher(&nettle_serpent128,
-	      HL("e87450aa0fd87293fd0371483a459bd2"),
-	      HL("a78a7a8d392f629d bd13674c8dce6fa2"
+	      "e87450aa0fd87293fd0371483a459bd2",
+	      "a78a7a8d392f629d bd13674c8dce6fa2"
 		 "930c74dec02a11d8 c80d90b5e5c887a7"
 		 "83c92a921b5b2028 d9cb313a5f07ab09"
 		 "672eadf1624a2ed0 c42d1b08b076f75a"
-		 "7378272aa57ad7c8 803e326689541266"),
-	      H("b3d488986c80dea7 c5ebdab4907871c9"
+		 "7378272aa57ad7c8 803e326689541266",
+	      "b3d488986c80dea7 c5ebdab4907871c9"
 		"a4b92b13b79afb37 5518b01bfd706a37"
 		"8e44c2d463df4531 165461699edbad03"
 		"30ac8c52697102ae 3b725dba79ceb250"
-		"d308b83478e86dbb 629f18736cca042f"));
+		"d308b83478e86dbb 629f18736cca042f");
 
   test_cipher(&nettle_serpent128,
-	      HL("e87450aa0fd87293fd0371483a459bd2"),
-	      HL("a78a7a8d392f629d bd13674c8dce6fa2"
+	      "e87450aa0fd87293fd0371483a459bd2",
+	      "a78a7a8d392f629d bd13674c8dce6fa2"
 		 "930c74dec02a11d8 c80d90b5e5c887a7"
 		 "83c92a921b5b2028 d9cb313a5f07ab09"
 		 "672eadf1624a2ed0 c42d1b08b076f75a"
 		 "7378272aa57ad7c8 803e326689541266"
-		 "b7a2efda5721776f 4113d63a702ac3ae"),
-	      H("b3d488986c80dea7 c5ebdab4907871c9"
+		 "b7a2efda5721776f 4113d63a702ac3ae",
+	      "b3d488986c80dea7 c5ebdab4907871c9"
 		"a4b92b13b79afb37 5518b01bfd706a37"
 		"8e44c2d463df4531 165461699edbad03"
 		"30ac8c52697102ae 3b725dba79ceb250"
 		"d308b83478e86dbb 629f18736cca042f"
-		"006b89e494469adf 0ee78c60684dff86"));
+		"006b89e494469adf 0ee78c60684dff86");
     
   test_cipher(&nettle_serpent128,
-	      HL("e87450aa0fd87293fd0371483a459bd2"),
-	      HL("a78a7a8d392f629d bd13674c8dce6fa2"
+	      "e87450aa0fd87293fd0371483a459bd2",
+	      "a78a7a8d392f629d bd13674c8dce6fa2"
 		 "930c74dec02a11d8 c80d90b5e5c887a7"
 		 "83c92a921b5b2028 d9cb313a5f07ab09"
 		 "672eadf1624a2ed0 c42d1b08b076f75a"
 		 "7378272aa57ad7c8 803e326689541266"
 		 "b7a2efda5721776f 4113d63a702ac3ae"
-		 "cd1be7bbfad74819 644617f8656e9e5b"),
-	      H("b3d488986c80dea7 c5ebdab4907871c9"
+		 "cd1be7bbfad74819 644617f8656e9e5b",
+	      "b3d488986c80dea7 c5ebdab4907871c9"
 		"a4b92b13b79afb37 5518b01bfd706a37"
 		"8e44c2d463df4531 165461699edbad03"
 		"30ac8c52697102ae 3b725dba79ceb250"
 		"d308b83478e86dbb 629f18736cca042f"
 		"006b89e494469adf 0ee78c60684dff86"
-		"5f2c99908ee77ffe aea3d30cb78a1ce1"));
+		"5f2c99908ee77ffe aea3d30cb78a1ce1");
 
   test_cipher(&nettle_serpent128,
-	      HL("e87450aa0fd87293fd0371483a459bd2"),
-	      HL("a78a7a8d392f629d bd13674c8dce6fa2"
+	      "e87450aa0fd87293fd0371483a459bd2",
+	      "a78a7a8d392f629d bd13674c8dce6fa2"
 		 "930c74dec02a11d8 c80d90b5e5c887a7"
 		 "83c92a921b5b2028 d9cb313a5f07ab09"
 		 "672eadf1624a2ed0 c42d1b08b076f75a"
 		 "7378272aa57ad7c8 803e326689541266"
 		 "b7a2efda5721776f 4113d63a702ac3ae"
 		 "cd1be7bbfad74819 644617f8656e9e5b"
-		 "34d449409c1f850a 4cb6700d6ef3405f"),
-	      H("b3d488986c80dea7 c5ebdab4907871c9"
+		 "34d449409c1f850a 4cb6700d6ef3405f",
+	      "b3d488986c80dea7 c5ebdab4907871c9"
 		"a4b92b13b79afb37 5518b01bfd706a37"
 		"8e44c2d463df4531 165461699edbad03"
 		"30ac8c52697102ae 3b725dba79ceb250"
 		"d308b83478e86dbb 629f18736cca042f"
 		"006b89e494469adf 0ee78c60684dff86"
 		"5f2c99908ee77ffe aea3d30cb78a1ce1"
-		"ebe855dd51532477 4d2d55969e032e6c"));
+		"ebe855dd51532477 4d2d55969e032e6c");
 
   SUCCESS();
 }
diff --git a/testsuite/sexp-format-test.c b/testsuite/sexp-format-test.c
index 33c585f..4136693 100644
--- a/testsuite/sexp-format-test.c
+++ b/testsuite/sexp-format-test.c
@@ -26,6 +26,7 @@ test_main(void)
     
     ASSERT(buffer.size == strlen(e));
     ASSERT(MEMEQ(buffer.size, buffer.contents, e));
+    nettle_buffer_clear(&buffer);
   }
   {
     const uint8_t e[] = "{KDM6Zm9vKDM6YmFyMTc6eHh4eHh4eHh4eHh4eHh4eHgpKQ==}";
@@ -41,6 +42,7 @@ test_main(void)
     
     ASSERT(buffer.size == strlen(e));
     ASSERT(MEMEQ(buffer.size, buffer.contents, e));
+    nettle_buffer_clear(&buffer);
   }
   {
     const uint8_t e[] = "1:\0""1:a2:bc3:def4:ghij5:\x00\xDE\xAD\xBE\xEF";
@@ -52,6 +54,7 @@ test_main(void)
     
     ASSERT(buffer.size == LLENGTH(e));
     ASSERT(MEMEQ(buffer.size, buffer.contents, e));
+    nettle_buffer_clear(&buffer);
   }
 
   {
@@ -64,6 +67,8 @@ test_main(void)
     
     ASSERT(buffer.size == strlen(e));
     ASSERT(MEMEQ(buffer.size, buffer.contents, e));
+
+    nettle_buffer_clear(&buffer);
   }
 
   {
@@ -75,6 +80,7 @@ test_main(void)
 	   == strlen(e));
 
     ASSERT(MEMEQ(buffer.size, buffer.contents, e));
+    nettle_buffer_clear(&buffer);
   }
 
   /* Try literals */
@@ -92,6 +98,7 @@ test_main(void)
     
     ASSERT(buffer.size == strlen(e));
     ASSERT(MEMEQ(buffer.size, buffer.contents, e));
+    nettle_buffer_clear(&buffer);
   }
   {
     const uint8_t e[] = "(3:foo(3:bar17:xxxxxxxxxxxxxxxxx))";
@@ -107,6 +114,7 @@ test_main(void)
     
     ASSERT(buffer.size == strlen(e));
     ASSERT(MEMEQ(buffer.size, buffer.contents, e));
+    nettle_buffer_clear(&buffer);
   }
 
   /* Literal parenthesis */
@@ -122,6 +130,7 @@ test_main(void)
     
     ASSERT(buffer.size == strlen(e));
     ASSERT(MEMEQ(buffer.size, buffer.contents, e));
+    nettle_buffer_clear(&buffer);
   }
   
 #if HAVE_LIBGMP
@@ -133,7 +142,7 @@ test_main(void)
     const uint8_t e[] =
       "(3:foo(3:bar1:\xff""11:abcdefghijk13:\0\x81""abcdefghijk))";
 
-    nettle_buffer_clear(&buffer);
+//    nettle_buffer_clear(&buffer);
 
     mpz_init_set_si(x, -1);
     nettle_mpz_init_set_str_256_u(y, 11, "abcdefghijk");
@@ -153,6 +162,8 @@ test_main(void)
 
     nettle_buffer_clear(&buffer);
     mpz_clear(x);
+    mpz_clear(y);
+    mpz_clear(z);
   }
 #endif /* HAVE_LIBGMP */
 
diff --git a/testsuite/sexp-test.c b/testsuite/sexp-test.c
index 4e68f56..0fdec10 100644
--- a/testsuite/sexp-test.c
+++ b/testsuite/sexp-test.c
@@ -1,12 +1,15 @@
 #include "testutils.h"
 #include "sexp.h"
 
+#define INPUT "{Mzpmb28=} {MDo=} {WzM6YmFyXTEyOnh4eHh4eHh4eHh4eA==}"
+
 int
 test_main(void)
 {
   struct sexp_iterator i;
   uint32_t x;
-  
+  uint8_t *p;
+
   ASSERT(sexp_iterator_first(&i, LDATA("")));
   ASSERT(i.type == SEXP_END);
 
@@ -49,9 +52,9 @@ test_main(void)
 	 && sexp_iterator_next(&i) && i.type == SEXP_END);
   
   /* Same data, transport encoded. */
-  
+
   ASSERT(sexp_transport_iterator_first
-	 (&i, LDUP("{Mzpmb28=} {MDo=} {WzM6YmFyXTEyOnh4eHh4eHh4eHh4eA==}")));
+	 (&i, sizeof(INPUT) - 1, p=strdup(INPUT)));
   ASSERT(i.type == SEXP_ATOM
 	 && !i.display_length && !i.display
 	 && i.atom_length == 3 && MEMEQ(3, "foo", i.atom)
@@ -95,5 +98,7 @@ test_main(void)
 	   && !sexp_iterator_assoc(&i, 2, keys, v));    
   }
 
+  free((void *)p);
+
   SUCCESS();
 }
diff --git a/testsuite/sexp2rsa-test.c b/testsuite/sexp2rsa-test.c
index 2e7cd91..3555e1e 100644
--- a/testsuite/sexp2rsa-test.c
+++ b/testsuite/sexp2rsa-test.c
@@ -3,15 +3,8 @@
 int
 test_main(void)
 {
-  struct rsa_public_key pub;
-  struct rsa_private_key priv;
-  
-  rsa_public_key_init(&pub);
-  rsa_private_key_init(&priv);
-
-  ASSERT(rsa_keypair_from_sexp
-	 (&pub, &priv, 0,
-	  HL("2831313a707269766174652d6b657928"
+  static const uint8_t *expr_hex =
+	  "2831313a707269766174652d6b657928"
 	     "333a72736128313a6e36333a085c3408"
 	     "989acae4faec3cbbad91c90d34c1d259"
 	     "cd74121a36f38b0b51424a9b2be514a0"
@@ -34,12 +27,24 @@ test_main(void)
 	     "1d068e2ce9f565c5528c4a7473292831"
 	     "3a6333323a00f8a458ea73a018dc6fa5"
 	     "6863e3bc6de405f364f77dee6f096267"
-	     "9ea1a8282e292929")));
+	     "9ea1a8282e292929";
+  unsigned expr_length = decode_hex_length(expr_hex);
+  const uint8_t *expr = decode_hex_dup(expr_hex);
+  struct rsa_public_key pub;
+  struct rsa_private_key priv;
+  
+  rsa_public_key_init(&pub);
+  rsa_private_key_init(&priv);
+
+  ASSERT(rsa_keypair_from_sexp
+	 (&pub, &priv, 0, expr_length, expr));
 
   test_rsa_key(&pub, &priv);
 
   rsa_public_key_clear(&pub);
   rsa_private_key_clear(&priv);
+
+  free((void *)expr);
   
   SUCCESS();
 }
diff --git a/testsuite/sha1-test.c b/testsuite/sha1-test.c
index 8319086..7b6439a 100644
--- a/testsuite/sha1-test.c
+++ b/testsuite/sha1-test.c
@@ -4,34 +4,34 @@
 int
 test_main(void)
 {
-  test_hash(&nettle_sha1, 0, "",
-	    H("DA39A3EE5E6B4B0D 3255BFEF95601890 AFD80709")); 
+  test_hash(&nettle_sha1, "",
+	    "DA39A3EE5E6B4B0D 3255BFEF95601890 AFD80709"); 
 
-  test_hash(&nettle_sha1, 1, "a",
-	    H("86F7E437FAA5A7FC E15D1DDCB9EAEAEA 377667B8")); 
+  test_hash(&nettle_sha1, "a",
+	    "86F7E437FAA5A7FC E15D1DDCB9EAEAEA 377667B8"); 
 
-  test_hash(&nettle_sha1, 3, "abc",
-	    H("A9993E364706816A BA3E25717850C26C 9CD0D89D"));
+  test_hash(&nettle_sha1, "abc",
+	    "A9993E364706816A BA3E25717850C26C 9CD0D89D");
   
-  test_hash(&nettle_sha1, 26, "abcdefghijklmnopqrstuvwxyz",
-	    H("32D10C7B8CF96570 CA04CE37F2A19D84 240D3A89"));
+  test_hash(&nettle_sha1, "abcdefghijklmnopqrstuvwxyz",
+	    "32D10C7B8CF96570 CA04CE37F2A19D84 240D3A89");
   
-  test_hash(&nettle_sha1, 14, "message digest",
-	    H("C12252CEDA8BE899 4D5FA0290A47231C 1D16AAE3")); 
+  test_hash(&nettle_sha1, "message digest",
+	    "C12252CEDA8BE899 4D5FA0290A47231C 1D16AAE3"); 
 
-  test_hash(&nettle_sha1, 62,
+  test_hash(&nettle_sha1,
 	    "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
 	    "abcdefghijklmnopqrstuvwxyz0123456789",
-	    H("761C457BF73B14D2 7E9E9265C46F4B4D DA11F940"));
+	    "761C457BF73B14D2 7E9E9265C46F4B4D DA11F940");
   
-  test_hash(&nettle_sha1,  80,
+  test_hash(&nettle_sha1,
 	    "1234567890123456789012345678901234567890"
 	    "1234567890123456789012345678901234567890",
-	    H("50ABF5706A150990 A08B2C5EA40FA0E5 85554732"));
+	    "50ABF5706A150990 A08B2C5EA40FA0E5 85554732");
 
   /* Additional test vector, from Daniel Kahn Gillmor */
-  test_hash(&nettle_sha1, LDATA("38"),
-	    H("5b384ce32d8cdef02bc3a139d4cac0a22bb029e8"));
+  test_hash(&nettle_sha1, "38",
+	    "5b384ce32d8cdef02bc3a139d4cac0a22bb029e8");
 
   SUCCESS();
 }
diff --git a/testsuite/sha224-test.c b/testsuite/sha224-test.c
index cef82af..fef7d47 100644
--- a/testsuite/sha224-test.c
+++ b/testsuite/sha224-test.c
@@ -6,43 +6,43 @@ test_main(void)
 {
   /* From FIPS180-2 addendum
      (http://csrc.nist.gov/publications/fips/fips180-2/fips180-2withchangenotice.pdf) */
-  test_hash(&nettle_sha224, 3, "abc",
-	    H("23097d22 3405d822 8642a477 bda255b3"
-	      "2aadbce4 bda0b3f7 e36c9da7"));
+  test_hash(&nettle_sha224, "abc",
+	    "23097d22 3405d822 8642a477 bda255b3"
+	      "2aadbce4 bda0b3f7 e36c9da7");
 
-  test_hash(&nettle_sha224, 56,
+  test_hash(&nettle_sha224,
 	    "abcdbcdecdefdefgefghfghighij"
 	    "hijkijkljklmklmnlmnomnopnopq",
-	    H("75388b16 512776cc 5dba5da1 fd890150"
-	      "b0c6455c b4f58b19 52522525"));
+	    "75388b16 512776cc 5dba5da1 fd890150"
+	      "b0c6455c b4f58b19 52522525");
 
   /* Additional test vectors, from Daniel Kahn Gillmor */
-  test_hash(&nettle_sha224, LDATA(""),
-	    H("d14a028c2a3a2bc9 476102bb288234c4"
-	      "15a2b01f828ea62a c5b3e42f"));
-  test_hash(&nettle_sha224, LDATA("a"),
-	    H("abd37534c7d9a2ef b9465de931cd7055"
-	      "ffdb8879563ae980 78d6d6d5"));
-  test_hash(&nettle_sha224, LDATA("38"),
-	    H("4cfca6da32da6471 98225460722b7ea1"
-	      "284f98c4b179e8db ae3f93d5"));
-  test_hash(&nettle_sha224, LDATA("message digest"),
-	    H("2cb21c83ae2f004d e7e81c3c7019cbcb"
-	      "65b71ab656b22d6d 0c39b8eb"));
-  test_hash(&nettle_sha224, LDATA("abcdefghijklmnopqrstuvwxyz"),
-	    H("45a5f72c39c5cff2 522eb3429799e49e"
-	      "5f44b356ef926bcf 390dccc2"));
+  test_hash(&nettle_sha224, "",
+	    "d14a028c2a3a2bc9 476102bb288234c4"
+	      "15a2b01f828ea62a c5b3e42f");
+  test_hash(&nettle_sha224, "a",
+	    "abd37534c7d9a2ef b9465de931cd7055"
+	      "ffdb8879563ae980 78d6d6d5");
+  test_hash(&nettle_sha224, "38",
+	    "4cfca6da32da6471 98225460722b7ea1"
+	      "284f98c4b179e8db ae3f93d5");
+  test_hash(&nettle_sha224, "message digest",
+	    "2cb21c83ae2f004d e7e81c3c7019cbcb"
+	      "65b71ab656b22d6d 0c39b8eb");
+  test_hash(&nettle_sha224, "abcdefghijklmnopqrstuvwxyz",
+	    "45a5f72c39c5cff2 522eb3429799e49e"
+	      "5f44b356ef926bcf 390dccc2");
   test_hash(&nettle_sha224,
-	    LDATA("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef"
-		  "ghijklmnopqrstuvwxyz0123456789"),
-	    H("bff72b4fcb7d75e5 632900ac5f90d219"
-	      "e05e97a7bde72e74 0db393d9"));
+	    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef"
+		  "ghijklmnopqrstuvwxyz0123456789",
+	    "bff72b4fcb7d75e5 632900ac5f90d219"
+	      "e05e97a7bde72e74 0db393d9");
   test_hash(&nettle_sha224,
-	    LDATA("12345678901234567890123456789012"
+	    "12345678901234567890123456789012"
 		  "34567890123456789012345678901234"
-		  "5678901234567890"),
-	    H("b50aecbe4e9bb0b5 7bc5f3ae760a8e01"
-	      "db24f203fb3cdcd1 3148046e"));
+		  "5678901234567890",
+	    "b50aecbe4e9bb0b5 7bc5f3ae760a8e01"
+	      "db24f203fb3cdcd1 3148046e");
 
   SUCCESS();
 }
diff --git a/testsuite/sha256-test.c b/testsuite/sha256-test.c
index 7499521..b113419 100644
--- a/testsuite/sha256-test.c
+++ b/testsuite/sha256-test.c
@@ -5,51 +5,51 @@ int
 test_main(void)
 {
   /* From FIPS180-2 */
-  test_hash(&nettle_sha256, 3, "abc",
-	    H("ba7816bf8f01cfea 414140de5dae2223"
-	      "b00361a396177a9c b410ff61f20015ad"));
+  test_hash(&nettle_sha256, "abc",
+	    "ba7816bf8f01cfea 414140de5dae2223"
+	      "b00361a396177a9c b410ff61f20015ad");
 
-  test_hash(&nettle_sha256, 56,
+  test_hash(&nettle_sha256,
 	    "abcdbcdecdefdefgefghfghighij"
 	    "hijkijkljklmklmnlmnomnopnopq",
-	    H("248d6a61d20638b8 e5c026930c3e6039"
-	      "a33ce45964ff2167 f6ecedd419db06c1"));
+	    "248d6a61d20638b8 e5c026930c3e6039"
+	      "a33ce45964ff2167 f6ecedd419db06c1");
 
-  test_hash(&nettle_sha256, 112,
+  test_hash(&nettle_sha256,
 	    "abcdefghbcdefghicdefghijdefg"
 	    "hijkefghijklfghijklmghijklmn"
 	    "hijklmnoijklmnopjklmnopqklmn"
 	    "opqrlmnopqrsmnopqrstnopqrstu",
-	    H("cf5b16a778af8380 036ce59e7b049237"
-	      "0b249b11e8f07a51 afac45037afee9d1"));
+	    "cf5b16a778af8380 036ce59e7b049237"
+	      "0b249b11e8f07a51 afac45037afee9d1");
 
   /* Additional test vectors, from Daniel Kahn Gillmor */
-  test_hash(&nettle_sha256, LDATA(""),
-	    H("e3b0c44298fc1c14 9afbf4c8996fb924"
-	      "27ae41e4649b934c a495991b7852b855"));
-  test_hash(&nettle_sha256, LDATA("a"),
-	    H("ca978112ca1bbdca fac231b39a23dc4d"
-	      "a786eff8147c4e72 b9807785afee48bb"));
-  test_hash(&nettle_sha256, LDATA("38"),
-	    H("aea92132c4cbeb26 3e6ac2bf6c183b5d"
-	      "81737f179f21efdc 5863739672f0f470"));
-  test_hash(&nettle_sha256, LDATA("message digest"),
-	    H("f7846f55cf23e14e ebeab5b4e1550cad"
-	      "5b509e3348fbc4ef a3a1413d393cb650"));
-  test_hash(&nettle_sha256, LDATA("abcdefghijklmnopqrstuvwxyz"),
-	    H("71c480df93d6ae2f 1efad1447c66c952"
-	      "5e316218cf51fc8d 9ed832f2daf18b73"));
+  test_hash(&nettle_sha256, "",
+	    "e3b0c44298fc1c14 9afbf4c8996fb924"
+	      "27ae41e4649b934c a495991b7852b855");
+  test_hash(&nettle_sha256, "a",
+	    "ca978112ca1bbdca fac231b39a23dc4d"
+	      "a786eff8147c4e72 b9807785afee48bb");
+  test_hash(&nettle_sha256, "38",
+	    "aea92132c4cbeb26 3e6ac2bf6c183b5d"
+	      "81737f179f21efdc 5863739672f0f470");
+  test_hash(&nettle_sha256, "message digest",
+	    "f7846f55cf23e14e ebeab5b4e1550cad"
+	      "5b509e3348fbc4ef a3a1413d393cb650");
+  test_hash(&nettle_sha256, "abcdefghijklmnopqrstuvwxyz",
+	    "71c480df93d6ae2f 1efad1447c66c952"
+	      "5e316218cf51fc8d 9ed832f2daf18b73");
   test_hash(&nettle_sha256,
-	    LDATA("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef"
-		  "ghijklmnopqrstuvwxyz0123456789"),
-	    H("db4bfcbd4da0cd85 a60c3c37d3fbd880"
-	      "5c77f15fc6b1fdfe 614ee0a7c8fdb4c0"));
+	    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef"
+		  "ghijklmnopqrstuvwxyz0123456789",
+	    "db4bfcbd4da0cd85 a60c3c37d3fbd880"
+	      "5c77f15fc6b1fdfe 614ee0a7c8fdb4c0");
   test_hash(&nettle_sha256,
-	    LDATA("12345678901234567890123456789012"
+	    "12345678901234567890123456789012"
 		  "34567890123456789012345678901234"
-		  "5678901234567890"),
-	    H("f371bc4a311f2b00 9eef952dd83ca80e"
-	      "2b60026c8e935592 d0f9c308453c813e"));
+		  "5678901234567890",
+	    "f371bc4a311f2b00 9eef952dd83ca80e"
+	      "2b60026c8e935592 d0f9c308453c813e");
 
   SUCCESS();
 }
diff --git a/testsuite/sha384-test.c b/testsuite/sha384-test.c
index 086e115..702e73b 100644
--- a/testsuite/sha384-test.c
+++ b/testsuite/sha384-test.c
@@ -4,54 +4,54 @@
 int
 test_main(void)
 {
-  test_hash(&nettle_sha384, 3, "abc",
-	    H("cb00753f45a35e8b b5a03d699ac65007"
+  test_hash(&nettle_sha384, "abc",
+	    "cb00753f45a35e8b b5a03d699ac65007"
 	      "272c32ab0eded163 1a8b605a43ff5bed"
-	      "8086072ba1e7cc23 58baeca134c825a7"));
+	      "8086072ba1e7cc23 58baeca134c825a7");
   
-  test_hash(&nettle_sha384, 112,
+  test_hash(&nettle_sha384,
 	    "abcdefghbcdefghicdefghijdefg"
 	    "hijkefghijklfghijklmghijklmn"
 	    "hijklmnoijklmnopjklmnopqklmn"
 	    "opqrlmnopqrsmnopqrstnopqrstu",
-	    H("09330c33f71147e8 3d192fc782cd1b47"
+	    "09330c33f71147e8 3d192fc782cd1b47"
 	      "53111b173b3b05d2 2fa08086e3b0f712"
-	      "fcc7c71a557e2db9 66c3e9fa91746039"));
+	      "fcc7c71a557e2db9 66c3e9fa91746039");
 
   /* Additional test vectors, from Daniel Kahn Gillmor */
-  test_hash(&nettle_sha384, LDATA(""),
-	    H("38b060a751ac9638 4cd9327eb1b1e36a"
+  test_hash(&nettle_sha384, "",
+	    "38b060a751ac9638 4cd9327eb1b1e36a"
 	      "21fdb71114be0743 4c0cc7bf63f6e1da"
-	      "274edebfe76f65fb d51ad2f14898b95b"));
-  test_hash(&nettle_sha384, LDATA("a"),
-	    H("54a59b9f22b0b808 80d8427e548b7c23"
+	      "274edebfe76f65fb d51ad2f14898b95b");
+  test_hash(&nettle_sha384, "a",
+	    "54a59b9f22b0b808 80d8427e548b7c23"
 	      "abd873486e1f035d ce9cd697e8517503"
-	      "3caa88e6d57bc35e fae0b5afd3145f31"));
-  test_hash(&nettle_sha384, LDATA("38"),
-	    H("c071d202ad950b6a 04a5f15c24596a99"
+	      "3caa88e6d57bc35e fae0b5afd3145f31");
+  test_hash(&nettle_sha384, "38",
+	    "c071d202ad950b6a 04a5f15c24596a99"
 	      "3af8b212467958d5 70a3ffd478006063"
-	      "8e3a3d06637691d3 012bd31122071b2c"));
-  test_hash(&nettle_sha384, LDATA("message digest"),
-	    H("473ed35167ec1f5d 8e550368a3db39be"
+	      "8e3a3d06637691d3 012bd31122071b2c");
+  test_hash(&nettle_sha384, "message digest",
+	    "473ed35167ec1f5d 8e550368a3db39be"
 	      "54639f828868e945 4c239fc8b52e3c61"
-	      "dbd0d8b4de1390c2 56dcbb5d5fd99cd5"));
-  test_hash(&nettle_sha384, LDATA("abcdefghijklmnopqrstuvwxyz"),
-	    H("feb67349df3db6f5 924815d6c3dc133f"
+	      "dbd0d8b4de1390c2 56dcbb5d5fd99cd5");
+  test_hash(&nettle_sha384, "abcdefghijklmnopqrstuvwxyz",
+	    "feb67349df3db6f5 924815d6c3dc133f"
 	      "091809213731fe5c 7b5f4999e463479f"
-	      "f2877f5f2936fa63 bb43784b12f3ebb4"));
+	      "f2877f5f2936fa63 bb43784b12f3ebb4");
   test_hash(&nettle_sha384,
-	    LDATA("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef"
-		  "ghijklmnopqrstuvwxyz0123456789"),
-	    H("1761336e3f7cbfe5 1deb137f026f89e0"
+	    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef"
+		  "ghijklmnopqrstuvwxyz0123456789",
+	    "1761336e3f7cbfe5 1deb137f026f89e0"
 	      "1a448e3b1fafa640 39c1464ee8732f11"
-	      "a5341a6f41e0c202 294736ed64db1a84"));
+	      "a5341a6f41e0c202 294736ed64db1a84");
   test_hash(&nettle_sha384,
-	    LDATA("12345678901234567890123456789012"
+	    "12345678901234567890123456789012"
 		  "34567890123456789012345678901234"
-		  "5678901234567890"),
-	    H("b12932b0627d1c06 0942f54477641556"
+		  "5678901234567890",
+	    "b12932b0627d1c06 0942f54477641556"
 	      "55bd4da0c9afa6dd 9b9ef53129af1b8f"
-	      "b0195996d2de9ca0 df9d821ffee67026"));
+	      "b0195996d2de9ca0 df9d821ffee67026");
 
   SUCCESS();
 }
diff --git a/testsuite/sha512-test.c b/testsuite/sha512-test.c
index 97bde53..d97b384 100644
--- a/testsuite/sha512-test.c
+++ b/testsuite/sha512-test.c
@@ -4,63 +4,63 @@
 int
 test_main(void)
 {
-  test_hash(&nettle_sha512, 3, "abc",
-	    H("ddaf35a193617aba cc417349ae204131"
+  test_hash(&nettle_sha512, "abc",
+	    "ddaf35a193617aba cc417349ae204131"
 	      "12e6fa4e89a97ea2 0a9eeee64b55d39a"
 	      "2192992a274fc1a8 36ba3c23a3feebbd"
-	      "454d4423643ce80e 2a9ac94fa54ca49f"));
+	      "454d4423643ce80e 2a9ac94fa54ca49f");
   
-  test_hash(&nettle_sha512, 112,
+  test_hash(&nettle_sha512,
 	    "abcdefghbcdefghicdefghijdefg"
 	    "hijkefghijklfghijklmghijklmn"
 	    "hijklmnoijklmnopjklmnopqklmn"
 	    "opqrlmnopqrsmnopqrstnopqrstu",
-	    H("8e959b75dae313da 8cf4f72814fc143f"
+	    "8e959b75dae313da 8cf4f72814fc143f"
 	      "8f7779c6eb9f7fa1 7299aeadb6889018"
 	      "501d289e4900f7e4 331b99dec4b5433a"
-	      "c7d329eeb6dd2654 5e96e55b874be909"));
+	      "c7d329eeb6dd2654 5e96e55b874be909");
 
   /* Additional test vectors, from Daniel Kahn Gillmor */
-  test_hash(&nettle_sha512, LDATA(""),
-	    H("cf83e1357eefb8bd f1542850d66d8007"
+  test_hash(&nettle_sha512, "",
+	    "cf83e1357eefb8bd f1542850d66d8007"
 	      "d620e4050b5715dc 83f4a921d36ce9ce"
 	      "47d0d13c5d85f2b0 ff8318d2877eec2f"
-	      "63b931bd47417a81 a538327af927da3e"));
-  test_hash(&nettle_sha512, LDATA("a"),
-	    H("1f40fc92da241694 750979ee6cf582f2"
+	      "63b931bd47417a81 a538327af927da3e");
+  test_hash(&nettle_sha512, "a",
+	    "1f40fc92da241694 750979ee6cf582f2"
 	      "d5d7d28e18335de0 5abc54d0560e0f53"
 	      "02860c652bf08d56 0252aa5e74210546"
-	      "f369fbbbce8c12cf c7957b2652fe9a75"));
-  test_hash(&nettle_sha512, LDATA("38"),
-	    H("caae34a5e8103126 8bcdaf6f1d8c04d3"
+	      "f369fbbbce8c12cf c7957b2652fe9a75");
+  test_hash(&nettle_sha512, "38",
+	    "caae34a5e8103126 8bcdaf6f1d8c04d3"
 	      "7b7f2c349afb705b 575966f63e2ebf0f"
 	      "d910c3b05160ba08 7ab7af35d40b7c71"
-	      "9c53cd8b947c9611 1f64105fd45cc1b2"));
-  test_hash(&nettle_sha512, LDATA("message digest"),
-	    H("107dbf389d9e9f71 a3a95f6c055b9251"
+	      "9c53cd8b947c9611 1f64105fd45cc1b2");
+  test_hash(&nettle_sha512, "message digest",
+	    "107dbf389d9e9f71 a3a95f6c055b9251"
 	      "bc5268c2be16d6c1 3492ea45b0199f33"
 	      "09e16455ab1e9611 8e8a905d5597b720"
-	      "38ddb372a8982604 6de66687bb420e7c"));
-  test_hash(&nettle_sha512, LDATA("abcdefghijklmnopqrstuvwxyz"),
-	    H("4dbff86cc2ca1bae 1e16468a05cb9881"
+	      "38ddb372a8982604 6de66687bb420e7c");
+  test_hash(&nettle_sha512, "abcdefghijklmnopqrstuvwxyz",
+	    "4dbff86cc2ca1bae 1e16468a05cb9881"
 	      "c97f1753bce36190 34898faa1aabe429"
 	      "955a1bf8ec483d74 21fe3c1646613a59"
-	      "ed5441fb0f321389 f77f48a879c7b1f1"));
+	      "ed5441fb0f321389 f77f48a879c7b1f1");
   test_hash(&nettle_sha512,
-	    LDATA("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef"
-		  "ghijklmnopqrstuvwxyz0123456789"),
-	    H("1e07be23c26a86ea 37ea810c8ec78093"
+	    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef"
+		  "ghijklmnopqrstuvwxyz0123456789",
+	    "1e07be23c26a86ea 37ea810c8ec78093"
 	      "52515a970e9253c2 6f536cfc7a9996c4"
 	      "5c8370583e0a78fa 4a90041d71a4ceab"
-	      "7423f19c71b9d5a3 e01249f0bebd5894"));
+	      "7423f19c71b9d5a3 e01249f0bebd5894");
   test_hash(&nettle_sha512,
-	    LDATA("12345678901234567890123456789012"
+	    "12345678901234567890123456789012"
 		  "34567890123456789012345678901234"
-		  "5678901234567890"),
-	    H("72ec1ef1124a45b0 47e8b7c75a932195"
+		  "5678901234567890",
+	    "72ec1ef1124a45b0 47e8b7c75a932195"
 	      "135bb61de24ec0d1 914042246e0aec3a"
 	      "2354e093d76f3048 b456764346900cb1"
-	      "30d2a4fd5dd16abb 5e30bcb850dee843"));
+	      "30d2a4fd5dd16abb 5e30bcb850dee843");
 
   SUCCESS();
 }
diff --git a/testsuite/testutils.c b/testsuite/testutils.c
index 1b0fd88..47c7693 100644
--- a/testsuite/testutils.c
+++ b/testsuite/testutils.c
@@ -46,6 +46,33 @@ xalloc(size_t size)
   return p;
 }
 
+int
+memeq_hex(unsigned length, const uint8_t *s1, const uint8_t *s2_hex)
+{
+  unsigned s2_length = decode_hex_length(s2_hex);
+  const uint8_t *s2 = decode_hex_dup(s2_hex);
+  int result = (length == s2_length) && !memcmp(s1, s2, length);
+
+  free((void *)s2);
+  return result;
+}
+
+const uint8_t *
+encode_hex_dup(const uint8_t *data, unsigned length)
+{
+  unsigned i;
+  uint8_t *hex = xalloc(length * 2 + 1);
+
+  *hex = 0;
+
+  for (i = 0; i < length; i++)
+    {
+      sprintf(&hex[i*2], "%02x", data[i]);
+    }
+
+  return hex;
+}
+
 unsigned
 decode_hex_length(const char *h)
 {
@@ -163,12 +190,16 @@ main(int argc, char **argv)
 
 void
 test_cipher(const struct nettle_cipher *cipher,
-	    unsigned key_length,
-	    const uint8_t *key,
-	    unsigned length,
-	    const uint8_t *cleartext,
-	    const uint8_t *ciphertext)
+	    const uint8_t *key_hex,
+	    const uint8_t *cleartext_hex,
+	    const uint8_t *ciphertext_hex)
 {
+  unsigned key_length = decode_hex_length(key_hex);
+  const uint8_t *key = decode_hex_dup(key_hex);
+  unsigned length = decode_hex_length(cleartext_hex);
+  const uint8_t *cleartext = decode_hex_dup(cleartext_hex);
+  const uint8_t *ciphertext = decode_hex_dup(ciphertext_hex);
+
   void *ctx = xalloc(cipher->context_size);
   uint8_t *data = xalloc(length);
 
@@ -201,19 +232,27 @@ test_cipher(const struct nettle_cipher *cipher,
       FAIL();
     }
 
-  free(ctx);
   free(data);
+  free(ctx);
+  free((void *)ciphertext);
+  free((void *)cleartext);
+  free((void *)key);
 }
 
 void
 test_cipher_cbc(const struct nettle_cipher *cipher,
-		unsigned key_length,
-		const uint8_t *key,
-		unsigned length,
-		const uint8_t *cleartext,
-		const uint8_t *ciphertext,
-		const uint8_t *iiv)
+		const uint8_t *key_hex,
+		const uint8_t *cleartext_hex,
+		const uint8_t *ciphertext_hex,
+		const uint8_t *iiv_hex)
 {
+  unsigned key_length = decode_hex_length(key_hex);
+  const uint8_t *key = decode_hex_dup(key_hex);
+  unsigned length = decode_hex_length(cleartext_hex);
+  const uint8_t *cleartext = decode_hex_dup(cleartext_hex);
+  const uint8_t *ciphertext = decode_hex_dup(ciphertext_hex);
+  const uint8_t *iiv = decode_hex_dup(iiv_hex);
+
   void *ctx = xalloc(cipher->context_size);
   uint8_t *data = xalloc(length);
   uint8_t *iv = xalloc(cipher->block_size);
@@ -254,20 +293,30 @@ test_cipher_cbc(const struct nettle_cipher *cipher,
       fprintf(stderr, "\n");
       FAIL();
     }
-  free(ctx);
-  free(data);
+
   free(iv);
+  free(data);
+  free(ctx);
+  free((void *)iiv);
+  free((void *)ciphertext);
+  free((void *)cleartext);
+  free((void *)key);
 }
 
 void
 test_cipher_ctr(const struct nettle_cipher *cipher,
-		unsigned key_length,
-		const uint8_t *key,
-		unsigned length,
-		const uint8_t *cleartext,
-		const uint8_t *ciphertext,
-		const uint8_t *ictr)
+		const uint8_t *key_hex,
+		const uint8_t *cleartext_hex,
+		const uint8_t *ciphertext_hex,
+		const uint8_t *ictr_hex)
 {
+  unsigned key_length = decode_hex_length(key_hex);
+  const uint8_t *key = decode_hex_dup(key_hex);
+  unsigned length = decode_hex_length(cleartext_hex);
+  const uint8_t *cleartext = decode_hex_dup(cleartext_hex);
+  const uint8_t *ciphertext = decode_hex_dup(ciphertext_hex);
+  const uint8_t *ictr = decode_hex_dup(ictr_hex);
+
   void *ctx = xalloc(cipher->context_size);
   uint8_t *data = xalloc(length);
   uint8_t *ctr = xalloc(cipher->block_size);
@@ -309,21 +358,29 @@ test_cipher_ctr(const struct nettle_cipher *cipher,
       FAIL();
     }
 
-  free(ctx);
-  free(data);
   free(ctr);
+  free(data);
+  free(ctx);
+  free((void *)ictr);
+  free((void *)ciphertext);
+  free((void *)cleartext);
+  free((void *)key);
 }
 
 void
 test_cipher_stream(const struct nettle_cipher *cipher,
-		   unsigned key_length,
-		   const uint8_t *key,
-		   unsigned length,
-		   const uint8_t *cleartext,
-		   const uint8_t *ciphertext)
+		   const uint8_t *key_hex,
+		   const uint8_t *cleartext_hex,
+		   const uint8_t *ciphertext_hex)
 {
+  unsigned key_length = decode_hex_length(key_hex);
+  const uint8_t *key = decode_hex_dup(key_hex);
+  unsigned length = decode_hex_length(cleartext_hex);
+  const uint8_t *cleartext = decode_hex_dup(cleartext_hex);
+  const uint8_t *ciphertext = decode_hex_dup(ciphertext_hex);
+
   unsigned block;
-  
+
   void *ctx = xalloc(cipher->context_size);
   uint8_t *data = xalloc(length + 1);
   
@@ -376,23 +433,33 @@ test_cipher_stream(const struct nettle_cipher *cipher,
       FAIL();	    
     }
 
-  free(ctx);
   free(data);
+  free(ctx);
+  free((void *)ciphertext);
+  free((void *)cleartext);
+  free((void *)key);
 }
 
 void
 test_aead(const struct nettle_aead *aead,
-	  unsigned key_length,
-	  const uint8_t *key,
-	  unsigned auth_length,
-	  const uint8_t *authtext,
-	  unsigned length,
-	  const uint8_t *cleartext,
-	  const uint8_t *ciphertext,
-	  unsigned iv_length,
-	  const uint8_t *iv,
-	  const uint8_t *digest)
+	  const uint8_t *key_hex,
+	  const uint8_t *authtext_hex,
+	  const uint8_t *cleartext_hex,
+	  const uint8_t *ciphertext_hex,
+	  const uint8_t *iv_hex,
+	  const uint8_t *digest_hex)
 {
+  unsigned key_length = decode_hex_length(key_hex);
+  const uint8_t *key = decode_hex_dup(key_hex);
+  unsigned auth_length = decode_hex_length(authtext_hex);
+  const uint8_t *authtext = decode_hex_dup(authtext_hex);
+  unsigned length = decode_hex_length(cleartext_hex);
+  const uint8_t *cleartext = decode_hex_dup(cleartext_hex);
+  const uint8_t *ciphertext = decode_hex_dup(ciphertext_hex);
+  unsigned iv_length = decode_hex_length(iv_hex);
+  const uint8_t *iv = decode_hex_dup(iv_hex);
+  const uint8_t *digest = decode_hex_dup(digest_hex);
+
   void *ctx = xalloc(aead->context_size);
   uint8_t *data = xalloc(length);
   uint8_t *buffer = xalloc(aead->block_size);
@@ -438,14 +505,22 @@ test_aead(const struct nettle_aead *aead,
   free(ctx);
   free(data);
   free(buffer);
+  free((void *)digest);
+  free((void *)iv);
+  free((void *)ciphertext);
+  free((void *)cleartext);
+  free((void *)authtext);
+  free((void *)key);
 }
 
 void
-test_hash(const struct nettle_hash *hash,
-	  unsigned length,
+test_hash_mem(const struct nettle_hash *hash,
+          unsigned length,
 	  const uint8_t *data,
-	  const uint8_t *digest)
+	  const uint8_t *digest_hex)
 {
+  const uint8_t *digest = decode_hex_dup(digest_hex);
+
   void *ctx = xalloc(hash->context_size);
   uint8_t *buffer = xalloc(hash->digest_size);
 
@@ -468,8 +543,32 @@ test_hash(const struct nettle_hash *hash,
   if (buffer[hash->digest_size - 1])
     FAIL();
 
-  free(ctx);
   free(buffer);
+  free(ctx);
+  free((void *)digest);
+}
+
+void
+test_hash(const struct nettle_hash *hash,
+	  const uint8_t *data,
+	  const uint8_t *digest_hex)
+{
+  unsigned length = strlen(data);
+
+  test_hash_mem(hash, length, data, digest_hex);
+}
+
+void
+test_hash_hex(const struct nettle_hash *hash,
+	  const uint8_t *data_hex,
+	  const uint8_t *digest_hex)
+{
+  unsigned length = decode_hex_length(data_hex);
+  const uint8_t *data = decode_hex_dup(data_hex);
+
+  test_hash_mem(hash, length, data, digest_hex);
+
+  free((void *)data);
 }
 
 void
@@ -1069,6 +1168,8 @@ test_dsa_key(struct dsa_public_key *pub,
   
   mpz_powm(t, pub->g, key->x, pub->p);
   ASSERT(0 == mpz_cmp(t, pub->y));
+
+  mpz_clear(t);
 }
 
 #endif /* WITH_HOGWEED */
diff --git a/testsuite/testutils.h b/testsuite/testutils.h
index d7ced9a..8b35160 100644
--- a/testsuite/testutils.h
+++ b/testsuite/testutils.h
@@ -32,6 +32,12 @@ extern "C" {
 void *
 xalloc(size_t size);
 
+int
+memeq_hex(unsigned length, const uint8_t *s1, const uint8_t *s2_hex);
+
+const uint8_t *
+encode_hex_dup(const uint8_t *data, unsigned length);
+
 /* Decodes a NUL-terminated hex string. */
 
 unsigned
@@ -84,56 +90,54 @@ struct nettle_mac
  
 void
 test_cipher(const struct nettle_cipher *cipher,
-	    unsigned key_length,
-	    const uint8_t *key,
-	    unsigned length,
-	    const uint8_t *cleartext,
-	    const uint8_t *ciphertext);
+	    const uint8_t *key_hex,
+	    const uint8_t *cleartext_hex,
+	    const uint8_t *ciphertext_hex);
 
 void
 test_cipher_cbc(const struct nettle_cipher *cipher,
-		unsigned key_length,
 		const uint8_t *key,
-		unsigned length,
 		const uint8_t *cleartext,
 		const uint8_t *ciphertext,
 		const uint8_t *iv);
 
 void
 test_cipher_ctr(const struct nettle_cipher *cipher,
-		unsigned key_length,
-		const uint8_t *key,
-		unsigned length,
-		const uint8_t *cleartext,
-		const uint8_t *ciphertext,
-		const uint8_t *iv);
+		const uint8_t *key_hex,
+		const uint8_t *cleartext_hex,
+		const uint8_t *ciphertext_hex,
+		const uint8_t *iv_hex);
 
 void
 test_cipher_stream(const struct nettle_cipher *cipher,
-		   unsigned key_length,
-		   const uint8_t *key,
-		   unsigned length,
-		   const uint8_t *cleartext,
-		   const uint8_t *ciphertext);
+		   const uint8_t *key_hex,
+		   const uint8_t *cleartext_hex,
+		   const uint8_t *ciphertext_hex);
 
 void
 test_aead(const struct nettle_aead *aead,
-	  unsigned key_length,
-	  const uint8_t *key,
-	  unsigned auth_length,
-	  const uint8_t *authtext,
+	  const uint8_t *key_hex,
+	  const uint8_t *authtext_hex,
+	  const uint8_t *cleartext_hex,
+	  const uint8_t *ciphertext_hex,
+	  const uint8_t *iv_hex,
+	  const uint8_t *digest_hex);
+
+void
+test_hash_mem(const struct nettle_hash *hash,
 	  unsigned length,
-	  const uint8_t *cleartext,
-	  const uint8_t *ciphertext,
-	  unsigned iv_length,
-	  const uint8_t *iv,
-	  const uint8_t *digest);
+	  const uint8_t *data,
+	  const uint8_t *digest_hex);
 
 void
 test_hash(const struct nettle_hash *hash,
-	  unsigned length,
 	  const uint8_t *data,
-	  const uint8_t *digest);
+	  const uint8_t *digest_hex);
+
+void
+test_hash_hex(const struct nettle_hash *hash,
+	  const uint8_t *data_hex,
+	  const uint8_t *digest_hex);
 
 void
 test_hash_large(const struct nettle_hash *hash,
@@ -203,19 +207,13 @@ test_dsa_key(struct dsa_public_key *pub,
 }
 #endif
 
-#define H2(d, s) decode_hex((d), (s))
 #define H(x) decode_hex_dup(x)
-#define HL(x) decode_hex_length(x), decode_hex_dup(x)
 
 /* LDATA needs to handle NUL characters. */
 #define LLENGTH(x) (sizeof(x) - 1)
 #define LDATA(x) (sizeof(x) - 1), x
-#define LDUP(x) strlen(x), strdup(x)
 
 #define MEMEQ(length, a, b) (!memcmp((a), (b), (length)))
-#define MEMEQH(length, a, b) \
-((length) == decode_hex_length((b)) \
- && !memcmp((a), decode_hex_dup((b)), (length)))
 
 #define FAIL() abort()
 #define SKIP() exit(77)
diff --git a/testsuite/twofish-test.c b/testsuite/twofish-test.c
index 65558d3..5a50a99 100644
--- a/testsuite/twofish-test.c
+++ b/testsuite/twofish-test.c
@@ -6,23 +6,23 @@ test_main(void)
 {
   /* 128 bit key */
   test_cipher(&nettle_twofish128,
-	      HL("0000000000000000 0000000000000000"),
-	      HL("0000000000000000 0000000000000000"),
-	      H("9F589F5CF6122C32 B6BFEC2F2AE8C35A"));
+	      "0000000000000000 0000000000000000",
+	      "0000000000000000 0000000000000000",
+	      "9F589F5CF6122C32 B6BFEC2F2AE8C35A");
 
   /* 192 bit key */
   test_cipher(&nettle_twofish192,
-	      HL("0123456789ABCDEF FEDCBA9876543210"
-		 "0011223344556677"),
-	      HL("0000000000000000 0000000000000000"),
-	      H("CFD1D2E5A9BE9CDF 501F13B892BD2248"));
+	      "0123456789ABCDEF FEDCBA9876543210"
+		 "0011223344556677",
+	      "0000000000000000 0000000000000000",
+	      "CFD1D2E5A9BE9CDF 501F13B892BD2248");
 
   /* 256 bit key */
   test_cipher(&nettle_twofish256,
-	      HL("0123456789ABCDEF FEDCBA9876543210"
-		 "0011223344556677 8899AABBCCDDEEFF"),
-	      HL("0000000000000000 0000000000000000"),
-	      H("37527BE0052334B8 9F0CFCCAE87CFA20"));
+	      "0123456789ABCDEF FEDCBA9876543210"
+		 "0011223344556677 8899AABBCCDDEEFF",
+	      "0000000000000000 0000000000000000",
+	      "37527BE0052334B8 9F0CFCCAE87CFA20");
 
   SUCCESS();
 }
diff --git a/testsuite/yarrow-test.c b/testsuite/yarrow-test.c
index 5f01e76..007a650 100644
--- a/testsuite/yarrow-test.c
+++ b/testsuite/yarrow-test.c
@@ -39,6 +39,8 @@ get_event(FILE *f, struct sha256_ctx *hash,
 static FILE *
 open_file(const char *name)
 {
+  FILE *fp;
+
   /* Tries opening the file in $srcdir, if set, otherwise the current
    * working directory */
 
@@ -48,11 +50,17 @@ open_file(const char *name)
       /* Leaks this name, but that doesn't matter. */
       char *buf = xalloc(strlen(name) + strlen(srcdir) + 10);
       sprintf(buf, "%s/%s", srcdir, name);
-      name = buf;
+      /* Opens the file in text mode. */
+      fp = fopen(buf, "r");
+      free(buf);
+    }
+  else
+    {
+      /* Opens the file in text mode. */
+      fp = fopen(name, "r");
     }
 
-  /* Opens the file in text mode. */
-  return fopen(name, "r");
+  return fp;
 }
 
 int
@@ -216,6 +224,11 @@ test_main(void)
       fprintf(stderr, "Failed.\n");
       return EXIT_FAILURE;
     }
-  
+
+  fclose(input);
+  free((void *)expected_seed_file);
+  free((void *)expected_input);
+  free((void *)expected_output);
+
   return EXIT_SUCCESS;
 }
diff --git a/tools/pkcs1-conv.c b/tools/pkcs1-conv.c
index 40420c4..042b203 100644
--- a/tools/pkcs1-conv.c
+++ b/tools/pkcs1-conv.c
@@ -438,6 +438,8 @@ convert_public_key(struct nettle_buffer *buffer, unsigned length, const uint8_t
 		      nettle_buffer_reset(buffer);
 		      res = rsa_keypair_to_sexp(buffer, NULL, &pub, NULL) > 0;
 		    }
+
+		  rsa_public_key_clear(&pub);
 		}
 	      if (!res)
 		werror("SubjectPublicKeyInfo: Invalid RSA key.\n");
@@ -656,5 +658,8 @@ main(int argc, char **argv)
 	  fclose(f);
 	}
     }
+
+  nettle_buffer_clear(&buffer);
+
   return EXIT_SUCCESS;
 }
