Merge git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
authorLinus Torvalds <torvalds@linux-foundation.org>
Fri, 10 Oct 2008 18:20:42 +0000 (11:20 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 10 Oct 2008 18:20:42 +0000 (11:20 -0700)
* git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6:
  crypto: skcipher - Use RNG interface instead of get_random_bytes
  crypto: rng - RNG interface and implementation
  crypto: api - Add fips_enable flag
  crypto: skcipher - Move IV generators into their own modules
  crypto: cryptomgr - Test ciphers using ECB
  crypto: api - Use test infrastructure
  crypto: cryptomgr - Add test infrastructure
  crypto: tcrypt - Add alg_test interface
  crypto: tcrypt - Abort and only log if there is an error
  crypto: crc32c - Use Intel CRC32 instruction
  crypto: tcrypt - Avoid using contiguous pages
  crypto: api - Display larval objects properly
  crypto: api - Export crypto_alg_lookup instead of __crypto_alg_lookup
  crypto: Kconfig - Replace leading spaces with tabs

25 files changed:
arch/x86/crypto/Makefile
arch/x86/crypto/crc32c-intel.c [new file with mode: 0644]
crypto/Kconfig
crypto/Makefile
crypto/algapi.c
crypto/algboss.c [moved from crypto/cryptomgr.c with 69% similarity]
crypto/ansi_cprng.c [new file with mode: 0644]
crypto/api.c
crypto/blkcipher.c
crypto/chainiv.c
crypto/eseqiv.c
crypto/fips.c [new file with mode: 0644]
crypto/internal.h
crypto/krng.c [new file with mode: 0644]
crypto/proc.c
crypto/rng.c [new file with mode: 0644]
crypto/seqiv.c
crypto/tcrypt.c
crypto/tcrypt.h
crypto/testmgr.c [new file with mode: 0644]
crypto/testmgr.h [new file with mode: 0644]
include/crypto/internal/rng.h [new file with mode: 0644]
include/crypto/internal/skcipher.h
include/crypto/rng.h [new file with mode: 0644]
include/linux/crypto.h

index 3874c2de54036e125a7f4772d93f37fa277e5c11..903de4aa509496205cf792980d1b6f57b3d87177 100644 (file)
@@ -10,6 +10,8 @@ obj-$(CONFIG_CRYPTO_AES_X86_64) += aes-x86_64.o
 obj-$(CONFIG_CRYPTO_TWOFISH_X86_64) += twofish-x86_64.o
 obj-$(CONFIG_CRYPTO_SALSA20_X86_64) += salsa20-x86_64.o
 
+obj-$(CONFIG_CRYPTO_CRC32C_INTEL) += crc32c-intel.o
+
 aes-i586-y := aes-i586-asm_32.o aes_glue.o
 twofish-i586-y := twofish-i586-asm_32.o twofish_glue.o
 salsa20-i586-y := salsa20-i586-asm_32.o salsa20_glue.o
diff --git a/arch/x86/crypto/crc32c-intel.c b/arch/x86/crypto/crc32c-intel.c
new file mode 100644 (file)
index 0000000..070afc5
--- /dev/null
@@ -0,0 +1,197 @@
+/*
+ * Using hardware provided CRC32 instruction to accelerate the CRC32 disposal.
+ * CRC32C polynomial:0x1EDC6F41(BE)/0x82F63B78(LE)
+ * CRC32 is a new instruction in Intel SSE4.2, the reference can be found at:
+ * http://www.intel.com/products/processor/manuals/
+ * Intel(R) 64 and IA-32 Architectures Software Developer's Manual
+ * Volume 2A: Instruction Set Reference, A-M
+ *
+ * Copyright (c) 2008 Austin Zhang <austin_zhang@linux.intel.com>
+ * Copyright (c) 2008 Kent Liu <kent.liu@intel.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ */
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/string.h>
+#include <linux/kernel.h>
+#include <crypto/internal/hash.h>
+
+#include <asm/cpufeature.h>
+
+#define CHKSUM_BLOCK_SIZE      1
+#define CHKSUM_DIGEST_SIZE     4
+
+#define SCALE_F        sizeof(unsigned long)
+
+#ifdef CONFIG_X86_64
+#define REX_PRE "0x48, "
+#else
+#define REX_PRE
+#endif
+
+static u32 crc32c_intel_le_hw_byte(u32 crc, unsigned char const *data, size_t length)
+{
+       while (length--) {
+               __asm__ __volatile__(
+                       ".byte 0xf2, 0xf, 0x38, 0xf0, 0xf1"
+                       :"=S"(crc)
+                       :"0"(crc), "c"(*data)
+               );
+               data++;
+       }
+
+       return crc;
+}
+
+static u32 __pure crc32c_intel_le_hw(u32 crc, unsigned char const *p, size_t len)
+{
+       unsigned int iquotient = len / SCALE_F;
+       unsigned int iremainder = len % SCALE_F;
+       unsigned long *ptmp = (unsigned long *)p;
+
+       while (iquotient--) {
+               __asm__ __volatile__(
+                       ".byte 0xf2, " REX_PRE "0xf, 0x38, 0xf1, 0xf1;"
+                       :"=S"(crc)
+                       :"0"(crc), "c"(*ptmp)
+               );
+               ptmp++;
+       }
+
+       if (iremainder)
+               crc = crc32c_intel_le_hw_byte(crc, (unsigned char *)ptmp,
+                                iremainder);
+
+       return crc;
+}
+
+/*
+ * Setting the seed allows arbitrary accumulators and flexible XOR policy
+ * If your algorithm starts with ~0, then XOR with ~0 before you set
+ * the seed.
+ */
+static int crc32c_intel_setkey(struct crypto_ahash *hash, const u8 *key,
+                       unsigned int keylen)
+{
+       u32 *mctx = crypto_ahash_ctx(hash);
+
+       if (keylen != sizeof(u32)) {
+               crypto_ahash_set_flags(hash, CRYPTO_TFM_RES_BAD_KEY_LEN);
+               return -EINVAL;
+       }
+       *mctx = le32_to_cpup((__le32 *)key);
+       return 0;
+}
+
+static int crc32c_intel_init(struct ahash_request *req)
+{
+       u32 *mctx = crypto_ahash_ctx(crypto_ahash_reqtfm(req));
+       u32 *crcp = ahash_request_ctx(req);
+
+       *crcp = *mctx;
+
+       return 0;
+}
+
+static int crc32c_intel_update(struct ahash_request *req)
+{
+       struct crypto_hash_walk walk;
+       u32 *crcp = ahash_request_ctx(req);
+       u32 crc = *crcp;
+       int nbytes;
+
+       for (nbytes = crypto_hash_walk_first(req, &walk); nbytes;
+          nbytes = crypto_hash_walk_done(&walk, 0))
+       crc = crc32c_intel_le_hw(crc, walk.data, nbytes);
+
+       *crcp = crc;
+       return 0;
+}
+
+static int crc32c_intel_final(struct ahash_request *req)
+{
+       u32 *crcp = ahash_request_ctx(req);
+
+       *(__le32 *)req->result = ~cpu_to_le32p(crcp);
+       return 0;
+}
+
+static int crc32c_intel_digest(struct ahash_request *req)
+{
+       struct crypto_hash_walk walk;
+       u32 *mctx = crypto_ahash_ctx(crypto_ahash_reqtfm(req));
+       u32 crc = *mctx;
+       int nbytes;
+
+       for (nbytes = crypto_hash_walk_first(req, &walk); nbytes;
+          nbytes = crypto_hash_walk_done(&walk, 0))
+               crc = crc32c_intel_le_hw(crc, walk.data, nbytes);
+
+       *(__le32 *)req->result = ~cpu_to_le32(crc);
+       return 0;
+}
+
+static int crc32c_intel_cra_init(struct crypto_tfm *tfm)
+{
+       u32 *key = crypto_tfm_ctx(tfm);
+
+       *key = ~0;
+
+       tfm->crt_ahash.reqsize = sizeof(u32);
+
+       return 0;
+}
+
+static struct crypto_alg alg = {
+       .cra_name               =       "crc32c",
+       .cra_driver_name        =       "crc32c-intel",
+       .cra_priority           =       200,
+       .cra_flags              =       CRYPTO_ALG_TYPE_AHASH,
+       .cra_blocksize          =       CHKSUM_BLOCK_SIZE,
+       .cra_alignmask          =       3,
+       .cra_ctxsize            =       sizeof(u32),
+       .cra_module             =       THIS_MODULE,
+       .cra_list               =       LIST_HEAD_INIT(alg.cra_list),
+       .cra_init               =       crc32c_intel_cra_init,
+       .cra_type               =       &crypto_ahash_type,
+       .cra_u                  =       {
+               .ahash = {
+                       .digestsize    =       CHKSUM_DIGEST_SIZE,
+                       .setkey        =       crc32c_intel_setkey,
+                       .init          =       crc32c_intel_init,
+                       .update        =       crc32c_intel_update,
+                       .final         =       crc32c_intel_final,
+                       .digest        =       crc32c_intel_digest,
+               }
+       }
+};
+
+
+static int __init crc32c_intel_mod_init(void)
+{
+       if (cpu_has_xmm4_2)
+               return crypto_register_alg(&alg);
+       else
+               return -ENODEV;
+}
+
+static void __exit crc32c_intel_mod_fini(void)
+{
+       crypto_unregister_alg(&alg);
+}
+
+module_init(crc32c_intel_mod_init);
+module_exit(crc32c_intel_mod_fini);
+
+MODULE_AUTHOR("Austin Zhang <austin.zhang@intel.com>, Kent Liu <kent.liu@intel.com>");
+MODULE_DESCRIPTION("CRC32c (Castagnoli) optimization using Intel Hardware.");
+MODULE_LICENSE("GPL");
+
+MODULE_ALIAS("crc32c");
+MODULE_ALIAS("crc32c-intel");
+
index d83185915eeee034948f30af0ef755de7ed557a8..39dbd8e4dde13c2769a1acb71c8d9937f12b3499 100644 (file)
@@ -21,6 +21,14 @@ if CRYPTO
 
 comment "Crypto core or helper"
 
+config CRYPTO_FIPS
+       bool "FIPS 200 compliance"
+       help
+         This options enables the fips boot option which is
+         required if you want to system to operate in a FIPS 200
+         certification.  You should say no unless you know what
+         this is.
+
 config CRYPTO_ALGAPI
        tristate
        help
@@ -33,14 +41,21 @@ config CRYPTO_AEAD
 config CRYPTO_BLKCIPHER
        tristate
        select CRYPTO_ALGAPI
+       select CRYPTO_RNG
 
 config CRYPTO_HASH
        tristate
        select CRYPTO_ALGAPI
 
+config CRYPTO_RNG
+       tristate
+       select CRYPTO_ALGAPI
+
 config CRYPTO_MANAGER
        tristate "Cryptographic algorithm manager"
-       select CRYPTO_ALGAPI
+       select CRYPTO_AEAD
+       select CRYPTO_HASH
+       select CRYPTO_BLKCIPHER
        help
          Create default cryptographic template instantiations such as
          cbc(aes).
@@ -85,9 +100,7 @@ config CRYPTO_AUTHENC
 config CRYPTO_TEST
        tristate "Testing module"
        depends on m
-       select CRYPTO_ALGAPI
-       select CRYPTO_AEAD
-       select CRYPTO_BLKCIPHER
+       select CRYPTO_MANAGER
        help
          Quick & dirty crypto test module.
 
@@ -113,6 +126,7 @@ config CRYPTO_SEQIV
        tristate "Sequence Number IV Generator"
        select CRYPTO_AEAD
        select CRYPTO_BLKCIPHER
+       select CRYPTO_RNG
        help
          This IV generator generates an IV based on a sequence number by
          xoring it with a salt.  This algorithm is mainly useful for CTR
@@ -219,7 +233,19 @@ config CRYPTO_CRC32C
          Castagnoli, et al Cyclic Redundancy-Check Algorithm.  Used
          by iSCSI for header and data digests and by others.
          See Castagnoli93.  This implementation uses lib/libcrc32c.
-          Module will be crc32c.
+         Module will be crc32c.
+
+config CRYPTO_CRC32C_INTEL
+       tristate "CRC32c INTEL hardware acceleration"
+       depends on X86
+       select CRYPTO_HASH
+       help
+         In Intel processor with SSE4.2 supported, the processor will
+         support CRC32C implementation using hardware accelerated CRC32
+         instruction. This option will create 'crc32c-intel' module,
+         which will enable any routine to use the CRC32 instruction to
+         gain performance compared with software implementation.
+         Module will be crc32c-intel.
 
 config CRYPTO_MD4
        tristate "MD4 digest algorithm"
@@ -243,55 +269,58 @@ config CRYPTO_MICHAEL_MIC
          of the algorithm.
 
 config CRYPTO_RMD128
-  tristate "RIPEMD-128 digest algorithm"
-  select CRYPTO_ALGAPI
-  help
-    RIPEMD-128 (ISO/IEC 10118-3:2004).
+       tristate "RIPEMD-128 digest algorithm"
+       select CRYPTO_ALGAPI
+       help
+         RIPEMD-128 (ISO/IEC 10118-3:2004).
 
-    RIPEMD-128 is a 128-bit cryptographic hash function. It should only
-    to be used as a secure replacement for RIPEMD. For other use cases
-    RIPEMD-160 should be used.
+         RIPEMD-128 is a 128-bit cryptographic hash function. It should only
+         to be used as a secure replacement for RIPEMD. For other use cases
+         RIPEMD-160 should be used.
 
-    Developed by Hans Dobbertin, Antoon Bosselaers and Bart Preneel.
-    See <http://home.esat.kuleuven.be/~bosselae/ripemd160.html>
+         Developed by Hans Dobbertin, Antoon Bosselaers and Bart Preneel.
+         See <http://home.esat.kuleuven.be/~bosselae/ripemd160.html>
 
 config CRYPTO_RMD160
-  tristate "RIPEMD-160 digest algorithm"
-  select CRYPTO_ALGAPI
-  help
-    RIPEMD-160 (ISO/IEC 10118-3:2004).
+       tristate "RIPEMD-160 digest algorithm"
+       select CRYPTO_ALGAPI
+       help
+         RIPEMD-160 (ISO/IEC 10118-3:2004).
 
-    RIPEMD-160 is a 160-bit cryptographic hash function. It is intended
-    to be used as a secure replacement for the 128-bit hash functions
-    MD4, MD5 and it's predecessor RIPEMD (not to be confused with RIPEMD-128).
+         RIPEMD-160 is a 160-bit cryptographic hash function. It is intended
+         to be used as a secure replacement for the 128-bit hash functions
+         MD4, MD5 and it's predecessor RIPEMD
+         (not to be confused with RIPEMD-128).
 
-    It's speed is comparable to SHA1 and there are no known attacks against
-    RIPEMD-160.
+         It's speed is comparable to SHA1 and there are no known attacks
+         against RIPEMD-160.
 
-    Developed by Hans Dobbertin, Antoon Bosselaers and Bart Preneel.
-    See <http://home.esat.kuleuven.be/~bosselae/ripemd160.html>
+         Developed by Hans Dobbertin, Antoon Bosselaers and Bart Preneel.
+         See <http://home.esat.kuleuven.be/~bosselae/ripemd160.html>
 
 config CRYPTO_RMD256
-  tristate "RIPEMD-256 digest algorithm"
-  select CRYPTO_ALGAPI
-  help
-    RIPEMD-256 is an optional extension of RIPEMD-128 with a 256 bit hash.
-    It is intended for applications that require longer hash-results, without
-    needing a larger security level (than RIPEMD-128).
+       tristate "RIPEMD-256 digest algorithm"
+       select CRYPTO_ALGAPI
+       help
+         RIPEMD-256 is an optional extension of RIPEMD-128 with a
+         256 bit hash. It is intended for applications that require
+         longer hash-results, without needing a larger security level
+         (than RIPEMD-128).
 
-    Developed by Hans Dobbertin, Antoon Bosselaers and Bart Preneel.
-    See <http://home.esat.kuleuven.be/~bosselae/ripemd160.html>
+         Developed by Hans Dobbertin, Antoon Bosselaers and Bart Preneel.
+         See <http://home.esat.kuleuven.be/~bosselae/ripemd160.html>
 
 config CRYPTO_RMD320
-  tristate "RIPEMD-320 digest algorithm"
-  select CRYPTO_ALGAPI
-  help
-    RIPEMD-320 is an optional extension of RIPEMD-160 with a 320 bit hash.
-    It is intended for applications that require longer hash-results, without
-    needing a larger security level (than RIPEMD-160).
+       tristate "RIPEMD-320 digest algorithm"
+       select CRYPTO_ALGAPI
+       help
+         RIPEMD-320 is an optional extension of RIPEMD-160 with a
+         320 bit hash. It is intended for applications that require
+         longer hash-results, without needing a larger security level
+         (than RIPEMD-160).
 
-    Developed by Hans Dobbertin, Antoon Bosselaers and Bart Preneel.
-    See <http://home.esat.kuleuven.be/~bosselae/ripemd160.html>
+         Developed by Hans Dobbertin, Antoon Bosselaers and Bart Preneel.
+         See <http://home.esat.kuleuven.be/~bosselae/ripemd160.html>
 
 config CRYPTO_SHA1
        tristate "SHA1 digest algorithm"
@@ -308,8 +337,8 @@ config CRYPTO_SHA256
          This version of SHA implements a 256 bit hash with 128 bits of
          security against collision attacks.
 
-          This code also includes SHA-224, a 224 bit hash with 112 bits
-          of security against collision attacks.
+         This code also includes SHA-224, a 224 bit hash with 112 bits
+         of security against collision attacks.
 
 config CRYPTO_SHA512
        tristate "SHA384 and SHA512 digest algorithms"
@@ -666,6 +695,18 @@ config CRYPTO_LZO
        help
          This is the LZO algorithm.
 
+comment "Random Number Generation"
+
+config CRYPTO_ANSI_CPRNG
+       tristate "Pseudo Random Number Generation for Cryptographic modules"
+       select CRYPTO_AES
+       select CRYPTO_RNG
+       select CRYPTO_FIPS
+       help
+         This option enables the generic pseudo random number generator
+         for cryptographic modules.  Uses the Algorithm specified in
+         ANSI X9.31 A.2.4
+
 source "drivers/crypto/Kconfig"
 
 endif  # if CRYPTO
index d4f3ed857df01bc376aee37a54bb7d2186c529a3..5862b807334e5c0f46fbad14bf01e058fe4e9939 100644 (file)
@@ -5,6 +5,8 @@
 obj-$(CONFIG_CRYPTO) += crypto.o
 crypto-objs := api.o cipher.o digest.o compress.o
 
+obj-$(CONFIG_CRYPTO_FIPS) += fips.o
+
 crypto_algapi-$(CONFIG_PROC_FS) += proc.o
 crypto_algapi-objs := algapi.o scatterwalk.o $(crypto_algapi-y)
 obj-$(CONFIG_CRYPTO_ALGAPI) += crypto_algapi.o
@@ -13,15 +15,17 @@ obj-$(CONFIG_CRYPTO_AEAD) += aead.o
 
 crypto_blkcipher-objs := ablkcipher.o
 crypto_blkcipher-objs += blkcipher.o
-crypto_blkcipher-objs += chainiv.o
-crypto_blkcipher-objs += eseqiv.o
 obj-$(CONFIG_CRYPTO_BLKCIPHER) += crypto_blkcipher.o
+obj-$(CONFIG_CRYPTO_BLKCIPHER) += chainiv.o
+obj-$(CONFIG_CRYPTO_BLKCIPHER) += eseqiv.o
 obj-$(CONFIG_CRYPTO_SEQIV) += seqiv.o
 
 crypto_hash-objs := hash.o
 crypto_hash-objs += ahash.o
 obj-$(CONFIG_CRYPTO_HASH) += crypto_hash.o
 
+cryptomgr-objs := algboss.o testmgr.o
+
 obj-$(CONFIG_CRYPTO_MANAGER) += cryptomgr.o
 obj-$(CONFIG_CRYPTO_HMAC) += hmac.o
 obj-$(CONFIG_CRYPTO_XCBC) += xcbc.o
@@ -69,7 +73,9 @@ obj-$(CONFIG_CRYPTO_MICHAEL_MIC) += michael_mic.o
 obj-$(CONFIG_CRYPTO_CRC32C) += crc32c.o
 obj-$(CONFIG_CRYPTO_AUTHENC) += authenc.o
 obj-$(CONFIG_CRYPTO_LZO) += lzo.o
-
+obj-$(CONFIG_CRYPTO_RNG) += rng.o
+obj-$(CONFIG_CRYPTO_RNG) += krng.o
+obj-$(CONFIG_CRYPTO_ANSI_CPRNG) += ansi_cprng.o
 obj-$(CONFIG_CRYPTO_TEST) += tcrypt.o
 
 #
index e65cb50cf4aff8b739130ba7012e383196ef286a..7c41e7405c41a4392791cc4a01a22cce52f983b0 100644 (file)
 
 #include "internal.h"
 
+static void crypto_remove_final(struct list_head *list);
+
 static LIST_HEAD(crypto_template_list);
 
 void crypto_larval_error(const char *name, u32 type, u32 mask)
 {
        struct crypto_alg *alg;
 
-       down_read(&crypto_alg_sem);
-       alg = __crypto_alg_lookup(name, type, mask);
-       up_read(&crypto_alg_sem);
+       alg = crypto_alg_lookup(name, type, mask);
 
        if (alg) {
                if (crypto_is_larval(alg)) {
@@ -128,23 +128,97 @@ static void crypto_remove_spawns(struct list_head *spawns,
        }
 }
 
-static int __crypto_register_alg(struct crypto_alg *alg,
-                                struct list_head *list)
+static struct crypto_larval *__crypto_register_alg(struct crypto_alg *alg)
 {
        struct crypto_alg *q;
+       struct crypto_larval *larval;
        int ret = -EAGAIN;
 
        if (crypto_is_dead(alg))
-               goto out;
+               goto err;
 
        INIT_LIST_HEAD(&alg->cra_users);
 
+       /* No cheating! */
+       alg->cra_flags &= ~CRYPTO_ALG_TESTED;
+
        ret = -EEXIST;
 
        atomic_set(&alg->cra_refcnt, 1);
        list_for_each_entry(q, &crypto_alg_list, cra_list) {
                if (q == alg)
-                       goto out;
+                       goto err;
+
+               if (crypto_is_larval(q)) {
+                       if (!strcmp(alg->cra_driver_name, q->cra_driver_name))
+                               goto err;
+                       continue;
+               }
+
+               if (!strcmp(q->cra_driver_name, alg->cra_name) ||
+                   !strcmp(q->cra_name, alg->cra_driver_name))
+                       goto err;
+       }
+
+       larval = crypto_larval_alloc(alg->cra_name,
+                                    alg->cra_flags | CRYPTO_ALG_TESTED, 0);
+       if (IS_ERR(larval))
+               goto out;
+
+       ret = -ENOENT;
+       larval->adult = crypto_mod_get(alg);
+       if (!larval->adult)
+               goto free_larval;
+
+       atomic_set(&larval->alg.cra_refcnt, 1);
+       memcpy(larval->alg.cra_driver_name, alg->cra_driver_name,
+              CRYPTO_MAX_ALG_NAME);
+       larval->alg.cra_priority = alg->cra_priority;
+
+       list_add(&alg->cra_list, &crypto_alg_list);
+       list_add(&larval->alg.cra_list, &crypto_alg_list);
+
+out:   
+       return larval;
+
+free_larval:
+       kfree(larval);
+err:
+       larval = ERR_PTR(ret);
+       goto out;
+}
+
+void crypto_alg_tested(const char *name, int err)
+{
+       struct crypto_larval *test;
+       struct crypto_alg *alg;
+       struct crypto_alg *q;
+       LIST_HEAD(list);
+
+       down_write(&crypto_alg_sem);
+       list_for_each_entry(q, &crypto_alg_list, cra_list) {
+               if (!crypto_is_larval(q))
+                       continue;
+
+               test = (struct crypto_larval *)q;
+
+               if (!strcmp(q->cra_driver_name, name))
+                       goto found;
+       }
+
+       printk(KERN_ERR "alg: Unexpected test result for %s: %d\n", name, err);
+       goto unlock;
+
+found:
+       alg = test->adult;
+       if (err || list_empty(&alg->cra_list))
+               goto complete;
+
+       alg->cra_flags |= CRYPTO_ALG_TESTED;
+
+       list_for_each_entry(q, &crypto_alg_list, cra_list) {
+               if (q == alg)
+                       continue;
 
                if (crypto_is_moribund(q))
                        continue;
@@ -180,17 +254,18 @@ static int __crypto_register_alg(struct crypto_alg *alg,
                    q->cra_priority > alg->cra_priority)
                        continue;
 
-               crypto_remove_spawns(&q->cra_users, list, alg->cra_flags);
+               crypto_remove_spawns(&q->cra_users, &list, alg->cra_flags);
        }
-       
-       list_add(&alg->cra_list, &crypto_alg_list);
 
-       crypto_notify(CRYPTO_MSG_ALG_REGISTER, alg);
-       ret = 0;
+complete:
+       complete_all(&test->completion);
 
-out:   
-       return ret;
+unlock:
+       up_write(&crypto_alg_sem);
+
+       crypto_remove_final(&list);
 }
+EXPORT_SYMBOL_GPL(crypto_alg_tested);
 
 static void crypto_remove_final(struct list_head *list)
 {
@@ -203,9 +278,27 @@ static void crypto_remove_final(struct list_head *list)
        }
 }
 
+static void crypto_wait_for_test(struct crypto_larval *larval)
+{
+       int err;
+
+       err = crypto_probing_notify(CRYPTO_MSG_ALG_REGISTER, larval->adult);
+       if (err != NOTIFY_STOP) {
+               if (WARN_ON(err != NOTIFY_DONE))
+                       goto out;
+               crypto_alg_tested(larval->alg.cra_driver_name, 0);
+       }
+
+       err = wait_for_completion_interruptible(&larval->completion);
+       WARN_ON(err);
+
+out:
+       crypto_larval_kill(&larval->alg);
+}
+
 int crypto_register_alg(struct crypto_alg *alg)
 {
-       LIST_HEAD(list);
+       struct crypto_larval *larval;
        int err;
 
        err = crypto_check_alg(alg);
@@ -213,11 +306,14 @@ int crypto_register_alg(struct crypto_alg *alg)
                return err;
 
        down_write(&crypto_alg_sem);
-       err = __crypto_register_alg(alg, &list);
+       larval = __crypto_register_alg(alg);
        up_write(&crypto_alg_sem);
 
-       crypto_remove_final(&list);
-       return err;
+       if (IS_ERR(larval))
+               return PTR_ERR(larval);
+
+       crypto_wait_for_test(larval);
+       return 0;
 }
 EXPORT_SYMBOL_GPL(crypto_register_alg);
 
@@ -335,8 +431,8 @@ EXPORT_SYMBOL_GPL(crypto_lookup_template);
 int crypto_register_instance(struct crypto_template *tmpl,
                             struct crypto_instance *inst)
 {
-       LIST_HEAD(list);
-       int err = -EINVAL;
+       struct crypto_larval *larval;
+       int err;
 
        err = crypto_check_alg(&inst->alg);
        if (err)
@@ -346,8 +442,8 @@ int crypto_register_instance(struct crypto_template *tmpl,
 
        down_write(&crypto_alg_sem);
 
-       err = __crypto_register_alg(&inst->alg, &list);
-       if (err)
+       larval = __crypto_register_alg(&inst->alg);
+       if (IS_ERR(larval))
                goto unlock;
 
        hlist_add_head(&inst->list, &tmpl->instances);
@@ -356,7 +452,12 @@ int crypto_register_instance(struct crypto_template *tmpl,
 unlock:
        up_write(&crypto_alg_sem);
 
-       crypto_remove_final(&list);
+       err = PTR_ERR(larval);
+       if (IS_ERR(larval))
+               goto err;
+
+       crypto_wait_for_test(larval);
+       err = 0;
 
 err:
        return err;
similarity index 69%
rename from crypto/cryptomgr.c
rename to crypto/algboss.c
index e5e3cf848d425ad0c3fa8584e323b51d9135221b..4601e4267c886182d6b037983fe2630fffb5d8dd 100644 (file)
@@ -45,6 +45,15 @@ struct cryptomgr_param {
 
        char larval[CRYPTO_MAX_ALG_NAME];
        char template[CRYPTO_MAX_ALG_NAME];
+
+       u32 otype;
+       u32 omask;
+};
+
+struct crypto_test_param {
+       char driver[CRYPTO_MAX_ALG_NAME];
+       char alg[CRYPTO_MAX_ALG_NAME];
+       u32 type;
 };
 
 static int cryptomgr_probe(void *data)
@@ -76,8 +85,7 @@ out:
        module_put_and_exit(0);
 
 err:
-       crypto_larval_error(param->larval, param->type.data.type,
-                           param->type.data.mask);
+       crypto_larval_error(param->larval, param->otype, param->omask);
        goto out;
 }
 
@@ -169,13 +177,65 @@ static int cryptomgr_schedule_probe(struct crypto_larval *larval)
 
        param->type.attr.rta_len = sizeof(param->type);
        param->type.attr.rta_type = CRYPTOA_TYPE;
-       param->type.data.type = larval->alg.cra_flags;
-       param->type.data.mask = larval->mask;
+       param->type.data.type = larval->alg.cra_flags & ~CRYPTO_ALG_TESTED;
+       param->type.data.mask = larval->mask & ~CRYPTO_ALG_TESTED;
        param->tb[0] = &param->type.attr;
 
+       param->otype = larval->alg.cra_flags;
+       param->omask = larval->mask;
+
        memcpy(param->larval, larval->alg.cra_name, CRYPTO_MAX_ALG_NAME);
 
-       thread = kthread_run(cryptomgr_probe, param, "cryptomgr");
+       thread = kthread_run(cryptomgr_probe, param, "cryptomgr_probe");
+       if (IS_ERR(thread))
+               goto err_free_param;
+
+       return NOTIFY_STOP;
+
+err_free_param:
+       kfree(param);
+err_put_module:
+       module_put(THIS_MODULE);
+err:
+       return NOTIFY_OK;
+}
+
+static int cryptomgr_test(void *data)
+{
+       struct crypto_test_param *param = data;
+       u32 type = param->type;
+       int err = 0;
+
+       if (!((type ^ CRYPTO_ALG_TYPE_BLKCIPHER) &
+             CRYPTO_ALG_TYPE_BLKCIPHER_MASK) && !(type & CRYPTO_ALG_GENIV))
+               goto skiptest;
+
+       err = alg_test(param->driver, param->alg, type, CRYPTO_ALG_TESTED);
+
+skiptest:
+       crypto_alg_tested(param->driver, err);
+
+       kfree(param);
+       module_put_and_exit(0);
+}
+
+static int cryptomgr_schedule_test(struct crypto_alg *alg)
+{
+       struct task_struct *thread;
+       struct crypto_test_param *param;
+
+       if (!try_module_get(THIS_MODULE))
+               goto err;
+
+       param = kzalloc(sizeof(*param), GFP_KERNEL);
+       if (!param)
+               goto err_put_module;
+
+       memcpy(param->driver, alg->cra_driver_name, sizeof(param->driver));
+       memcpy(param->alg, alg->cra_name, sizeof(param->alg));
+       param->type = alg->cra_flags;
+
+       thread = kthread_run(cryptomgr_test, param, "cryptomgr_test");
        if (IS_ERR(thread))
                goto err_free_param;
 
@@ -195,6 +255,8 @@ static int cryptomgr_notify(struct notifier_block *this, unsigned long msg,
        switch (msg) {
        case CRYPTO_MSG_ALG_REQUEST:
                return cryptomgr_schedule_probe(data);
+       case CRYPTO_MSG_ALG_REGISTER:
+               return cryptomgr_schedule_test(data);
        }
 
        return NOTIFY_DONE;
@@ -206,16 +268,32 @@ static struct notifier_block cryptomgr_notifier = {
 
 static int __init cryptomgr_init(void)
 {
-       return crypto_register_notifier(&cryptomgr_notifier);
+       int err;
+
+       err = testmgr_init();
+       if (err)
+               return err;
+
+       err = crypto_register_notifier(&cryptomgr_notifier);
+       if (err)
+               goto free_testmgr;
+
+       return 0;
+
+free_testmgr:
+       testmgr_exit();
+       return err;
 }
 
 static void __exit cryptomgr_exit(void)
 {
        int err = crypto_unregister_notifier(&cryptomgr_notifier);
        BUG_ON(err);
+
+       testmgr_exit();
 }
 
-module_init(cryptomgr_init);
+subsys_initcall(cryptomgr_init);
 module_exit(cryptomgr_exit);
 
 MODULE_LICENSE("GPL");
diff --git a/crypto/ansi_cprng.c b/crypto/ansi_cprng.c
new file mode 100644 (file)
index 0000000..72db0fd
--- /dev/null
@@ -0,0 +1,417 @@
+/*
+ * PRNG: Pseudo Random Number Generator
+ *       Based on NIST Recommended PRNG From ANSI X9.31 Appendix A.2.4 using
+ *       AES 128 cipher
+ *
+ *  (C) Neil Horman <nhorman@tuxdriver.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify it
+ *  under the terms of the GNU General Public License as published by the
+ *  Free Software Foundation; either version 2 of the License, or (at your
+ *  any later version.
+ *
+ *
+ */
+
+#include <crypto/internal/rng.h>
+#include <linux/err.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/string.h>
+
+#include "internal.h"
+
+#define DEFAULT_PRNG_KEY "0123456789abcdef"
+#define DEFAULT_PRNG_KSZ 16
+#define DEFAULT_BLK_SZ 16
+#define DEFAULT_V_SEED "zaybxcwdveuftgsh"
+
+/*
+ * Flags for the prng_context flags field
+ */
+
+#define PRNG_FIXED_SIZE 0x1
+#define PRNG_NEED_RESET 0x2
+
+/*
+ * Note: DT is our counter value
+ *      I is our intermediate value
+ *      V is our seed vector
+ * See http://csrc.nist.gov/groups/STM/cavp/documents/rng/931rngext.pdf
+ * for implementation details
+ */
+
+
+struct prng_context {
+       spinlock_t prng_lock;
+       unsigned char rand_data[DEFAULT_BLK_SZ];
+       unsigned char last_rand_data[DEFAULT_BLK_SZ];
+       unsigned char DT[DEFAULT_BLK_SZ];
+       unsigned char I[DEFAULT_BLK_SZ];
+       unsigned char V[DEFAULT_BLK_SZ];
+       u32 rand_data_valid;
+       struct crypto_cipher *tfm;
+       u32 flags;
+};
+
+static int dbg;
+
+static void hexdump(char *note, unsigned char *buf, unsigned int len)
+{
+       if (dbg) {
+               printk(KERN_CRIT "%s", note);
+               print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET,
+                               16, 1,
+                               buf, len, false);
+       }
+}
+
+#define dbgprint(format, args...) do {\
+if (dbg)\
+       printk(format, ##args);\
+} while (0)
+
+static void xor_vectors(unsigned char *in1, unsigned char *in2,
+                       unsigned char *out, unsigned int size)
+{
+       int i;
+
+       for (i = 0; i < size; i++)
+               out[i] = in1[i] ^ in2[i];
+
+}
+/*
+ * Returns DEFAULT_BLK_SZ bytes of random data per call
+ * returns 0 if generation succeded, <0 if something went wrong
+ */
+static int _get_more_prng_bytes(struct prng_context *ctx)
+{
+       int i;
+       unsigned char tmp[DEFAULT_BLK_SZ];
+       unsigned char *output = NULL;
+
+
+       dbgprint(KERN_CRIT "Calling _get_more_prng_bytes for context %p\n",
+               ctx);
+
+       hexdump("Input DT: ", ctx->DT, DEFAULT_BLK_SZ);
+       hexdump("Input I: ", ctx->I, DEFAULT_BLK_SZ);
+       hexdump("Input V: ", ctx->V, DEFAULT_BLK_SZ);
+
+       /*
+        * This algorithm is a 3 stage state machine
+        */
+       for (i = 0; i < 3; i++) {
+
+               switch (i) {
+               case 0:
+                       /*
+                        * Start by encrypting the counter value
+                        * This gives us an intermediate value I
+                        */
+                       memcpy(tmp, ctx->DT, DEFAULT_BLK_SZ);
+                       output = ctx->I;
+                       hexdump("tmp stage 0: ", tmp, DEFAULT_BLK_SZ);
+                       break;
+               case 1:
+
+                       /*
+                        * Next xor I with our secret vector V
+                        * encrypt that result to obtain our
+                        * pseudo random data which we output
+                        */
+                       xor_vectors(ctx->I, ctx->V, tmp, DEFAULT_BLK_SZ);
+                       hexdump("tmp stage 1: ", tmp, DEFAULT_BLK_SZ);
+                       output = ctx->rand_data;
+                       break;
+               case 2:
+                       /*
+                        * First check that we didn't produce the same
+                        * random data that we did last time around through this
+                        */
+                       if (!memcmp(ctx->rand_data, ctx->last_rand_data,
+                                       DEFAULT_BLK_SZ)) {
+                               printk(KERN_ERR
+                                       "ctx %p Failed repetition check!\n",
+                                       ctx);
+                               ctx->flags |= PRNG_NEED_RESET;
+                               return -EINVAL;
+                       }
+                       memcpy(ctx->last_rand_data, ctx->rand_data,
+                               DEFAULT_BLK_SZ);
+
+                       /*
+                        * Lastly xor the random data with I
+                        * and encrypt that to obtain a new secret vector V
+                        */
+                       xor_vectors(ctx->rand_data, ctx->I, tmp,
+                               DEFAULT_BLK_SZ);
+                       output = ctx->V;
+                       hexdump("tmp stage 2: ", tmp, DEFAULT_BLK_SZ);
+                       break;
+               }
+
+
+               /* do the encryption */
+               crypto_cipher_encrypt_one(ctx->tfm, output, tmp);
+
+       }
+
+       /*
+        * Now update our DT value
+        */
+       for (i = 0; i < DEFAULT_BLK_SZ; i++) {
+               ctx->DT[i] += 1;
+               if (ctx->DT[i] != 0)
+                       break;
+       }
+
+       dbgprint("Returning new block for context %p\n", ctx);
+       ctx->rand_data_valid = 0;
+
+       hexdump("Output DT: ", ctx->DT, DEFAULT_BLK_SZ);
+       hexdump("Output I: ", ctx->I, DEFAULT_BLK_SZ);
+       hexdump("Output V: ", ctx->V, DEFAULT_BLK_SZ);
+       hexdump("New Random Data: ", ctx->rand_data, DEFAULT_BLK_SZ);
+
+       return 0;
+}
+
+/* Our exported functions */
+static int get_prng_bytes(char *buf, size_t nbytes, struct prng_context *ctx)
+{
+       unsigned long flags;
+       unsigned char *ptr = buf;
+       unsigned int byte_count = (unsigned int)nbytes;
+       int err;
+
+
+       if (nbytes < 0)
+               return -EINVAL;
+
+       spin_lock_irqsave(&ctx->prng_lock, flags);
+
+       err = -EINVAL;
+       if (ctx->flags & PRNG_NEED_RESET)
+               goto done;
+
+       /*
+        * If the FIXED_SIZE flag is on, only return whole blocks of
+        * pseudo random data
+        */
+       err = -EINVAL;
+       if (ctx->flags & PRNG_FIXED_SIZE) {
+               if (nbytes < DEFAULT_BLK_SZ)
+                       goto done;
+               byte_count = DEFAULT_BLK_SZ;
+       }
+
+       err = byte_count;
+
+       dbgprint(KERN_CRIT "getting %d random bytes for context %p\n",
+               byte_count, ctx);
+
+
+remainder:
+       if (ctx->rand_data_valid == DEFAULT_BLK_SZ) {
+               if (_get_more_prng_bytes(ctx) < 0) {
+                       memset(buf, 0, nbytes);
+                       err = -EINVAL;
+                       goto done;
+               }
+       }
+
+       /*
+        * Copy up to the next whole block size
+        */
+       if (byte_count < DEFAULT_BLK_SZ) {
+               for (; ctx->rand_data_valid < DEFAULT_BLK_SZ;
+                       ctx->rand_data_valid++) {
+                       *ptr = ctx->rand_data[ctx->rand_data_valid];
+                       ptr++;
+                       byte_count--;
+                       if (byte_count == 0)
+                               goto done;
+               }
+       }
+
+       /*
+        * Now copy whole blocks
+        */
+       for (; byte_count >= DEFAULT_BLK_SZ; byte_count -= DEFAULT_BLK_SZ) {
+               if (_get_more_prng_bytes(ctx) < 0) {
+                       memset(buf, 0, nbytes);
+                       err = -EINVAL;
+                       goto done;
+               }
+               memcpy(ptr, ctx->rand_data, DEFAULT_BLK_SZ);
+               ctx->rand_data_valid += DEFAULT_BLK_SZ;
+               ptr += DEFAULT_BLK_SZ;
+       }
+
+       /*
+        * Now copy any extra partial data
+        */
+       if (byte_count)
+               goto remainder;
+
+done:
+       spin_unlock_irqrestore(&ctx->prng_lock, flags);
+       dbgprint(KERN_CRIT "returning %d from get_prng_bytes in context %p\n",
+               err, ctx);
+       return err;
+}
+
+static void free_prng_context(struct prng_context *ctx)
+{
+       crypto_free_cipher(ctx->tfm);
+}
+
+static int reset_prng_context(struct prng_context *ctx,
+                             unsigned char *key, size_t klen,
+                             unsigned char *V, unsigned char *DT)
+{
+       int ret;
+       int rc = -EINVAL;
+       unsigned char *prng_key;
+
+       spin_lock(&ctx->prng_lock);
+       ctx->flags |= PRNG_NEED_RESET;
+
+       prng_key = (key != NULL) ? key : (unsigned char *)DEFAULT_PRNG_KEY;
+
+       if (!key)
+               klen = DEFAULT_PRNG_KSZ;
+
+       if (V)
+               memcpy(ctx->V, V, DEFAULT_BLK_SZ);
+       else
+               memcpy(ctx->V, DEFAULT_V_SEED, DEFAULT_BLK_SZ);
+
+       if (DT)
+               memcpy(ctx->DT, DT, DEFAULT_BLK_SZ);
+       else
+               memset(ctx->DT, 0, DEFAULT_BLK_SZ);
+
+       memset(ctx->rand_data, 0, DEFAULT_BLK_SZ);
+       memset(ctx->last_rand_data, 0, DEFAULT_BLK_SZ);
+
+       if (ctx->tfm)
+               crypto_free_cipher(ctx->tfm);
+
+       ctx->tfm = crypto_alloc_cipher("aes", 0, 0);
+       if (IS_ERR(ctx->tfm)) {
+               dbgprint(KERN_CRIT "Failed to alloc tfm for context %p\n",
+                       ctx);
+               ctx->tfm = NULL;
+               goto out;
+       }
+
+       ctx->rand_data_valid = DEFAULT_BLK_SZ;
+
+       ret = crypto_cipher_setkey(ctx->tfm, prng_key, klen);
+       if (ret) {
+               dbgprint(KERN_CRIT "PRNG: setkey() failed flags=%x\n",
+                       crypto_cipher_get_flags(ctx->tfm));
+               crypto_free_cipher(ctx->tfm);
+               goto out;
+       }
+
+       rc = 0;
+       ctx->flags &= ~PRNG_NEED_RESET;
+out:
+       spin_unlock(&ctx->prng_lock);
+
+       return rc;
+
+}
+
+static int cprng_init(struct crypto_tfm *tfm)
+{
+       struct prng_context *ctx = crypto_tfm_ctx(tfm);
+
+       spin_lock_init(&ctx->prng_lock);
+
+       return reset_prng_context(ctx, NULL, DEFAULT_PRNG_KSZ, NULL, NULL);
+}
+
+static void cprng_exit(struct crypto_tfm *tfm)
+{
+       free_prng_context(crypto_tfm_ctx(tfm));
+}
+
+static int cprng_get_random(struct crypto_rng *tfm, u8 *rdata,
+                           unsigned int dlen)
+{
+       struct prng_context *prng = crypto_rng_ctx(tfm);
+
+       return get_prng_bytes(rdata, dlen, prng);
+}
+
+static int cprng_reset(struct crypto_rng *tfm, u8 *seed, unsigned int slen)
+{
+       struct prng_context *prng = crypto_rng_ctx(tfm);
+       u8 *key = seed + DEFAULT_PRNG_KSZ;
+
+       if (slen < DEFAULT_PRNG_KSZ + DEFAULT_BLK_SZ)
+               return -EINVAL;
+
+       reset_prng_context(prng, key, DEFAULT_PRNG_KSZ, seed, NULL);
+
+       if (prng->flags & PRNG_NEED_RESET)
+               return -EINVAL;
+       return 0;
+}
+
+static struct crypto_alg rng_alg = {
+       .cra_name               = "stdrng",
+       .cra_driver_name        = "ansi_cprng",
+       .cra_priority           = 100,
+       .cra_flags              = CRYPTO_ALG_TYPE_RNG,
+       .cra_ctxsize            = sizeof(struct prng_context),
+       .cra_type               = &crypto_rng_type,
+       .cra_module             = THIS_MODULE,
+       .cra_list               = LIST_HEAD_INIT(rng_alg.cra_list),
+       .cra_init               = cprng_init,
+       .cra_exit               = cprng_exit,
+       .cra_u                  = {
+               .rng = {
+                       .rng_make_random        = cprng_get_random,
+                       .rng_reset              = cprng_reset,
+                       .seedsize = DEFAULT_PRNG_KSZ + DEFAULT_BLK_SZ,
+               }
+       }
+};
+
+
+/* Module initalization */
+static int __init prng_mod_init(void)
+{
+       int ret = 0;
+
+       if (fips_enabled)
+               rng_alg.cra_priority += 200;
+
+       ret = crypto_register_alg(&rng_alg);
+
+       if (ret)
+               goto out;
+out:
+       return 0;
+}
+
+static void __exit prng_mod_fini(void)
+{
+       crypto_unregister_alg(&rng_alg);
+       return;
+}
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Software Pseudo Random Number Generator");
+MODULE_AUTHOR("Neil Horman <nhorman@tuxdriver.com>");
+module_param(dbg, int, 0);
+MODULE_PARM_DESC(dbg, "Boolean to enable debugging (0/1 == off/on)");
+module_init(prng_mod_init);
+module_exit(prng_mod_fini);
+MODULE_ALIAS("stdrng");
index d06e33270abea8fae3c5ae97354774bca63bf9b3..0444d242e9854dbc1a63a61a37ecc37b94c52df7 100644 (file)
@@ -55,7 +55,13 @@ void crypto_mod_put(struct crypto_alg *alg)
 }
 EXPORT_SYMBOL_GPL(crypto_mod_put);
 
-struct crypto_alg *__crypto_alg_lookup(const char *name, u32 type, u32 mask)
+static inline int crypto_is_test_larval(struct crypto_larval *larval)
+{
+       return larval->alg.cra_driver_name[0];
+}
+
+static struct crypto_alg *__crypto_alg_lookup(const char *name, u32 type,
+                                             u32 mask)
 {
        struct crypto_alg *q, *alg = NULL;
        int best = -2;
@@ -70,6 +76,7 @@ struct crypto_alg *__crypto_alg_lookup(const char *name, u32 type, u32 mask)
                        continue;
 
                if (crypto_is_larval(q) &&
+                   !crypto_is_test_larval((struct crypto_larval *)q) &&
                    ((struct crypto_larval *)q)->mask != mask)
                        continue;
 
@@ -92,7 +99,6 @@ struct crypto_alg *__crypto_alg_lookup(const char *name, u32 type, u32 mask)
 
        return alg;
 }
-EXPORT_SYMBOL_GPL(__crypto_alg_lookup);
 
 static void crypto_larval_destroy(struct crypto_alg *alg)
 {
@@ -104,10 +110,8 @@ static void crypto_larval_destroy(struct crypto_alg *alg)
        kfree(larval);
 }
 
-static struct crypto_alg *crypto_larval_alloc(const char *name, u32 type,
-                                             u32 mask)
+struct crypto_larval *crypto_larval_alloc(const char *name, u32 type, u32 mask)
 {
-       struct crypto_alg *alg;
        struct crypto_larval *larval;
 
        larval = kzalloc(sizeof(*larval), GFP_KERNEL);
@@ -119,10 +123,25 @@ static struct crypto_alg *crypto_larval_alloc(const char *name, u32 type,
        larval->alg.cra_priority = -1;
        larval->alg.cra_destroy = crypto_larval_destroy;
 
-       atomic_set(&larval->alg.cra_refcnt, 2);
        strlcpy(larval->alg.cra_name, name, CRYPTO_MAX_ALG_NAME);
        init_completion(&larval->completion);
 
+       return larval;
+}
+EXPORT_SYMBOL_GPL(crypto_larval_alloc);
+
+static struct crypto_alg *crypto_larval_add(const char *name, u32 type,
+                                           u32 mask)
+{
+       struct crypto_alg *alg;
+       struct crypto_larval *larval;
+
+       larval = crypto_larval_alloc(name, type, mask);
+       if (IS_ERR(larval))
+               return ERR_CAST(larval);
+
+       atomic_set(&larval->alg.cra_refcnt, 2);
+
        down_write(&crypto_alg_sem);
        alg = __crypto_alg_lookup(name, type, mask);
        if (!alg) {
@@ -152,21 +171,29 @@ EXPORT_SYMBOL_GPL(crypto_larval_kill);
 static struct crypto_alg *crypto_larval_wait(struct crypto_alg *alg)
 {
        struct crypto_larval *larval = (void *)alg;
+       long timeout;
+
+       timeout = wait_for_completion_interruptible_timeout(
+               &larval->completion, 60 * HZ);
 
-       wait_for_completion_interruptible_timeout(&larval->completion, 60 * HZ);
        alg = larval->adult;
-       if (alg) {
-               if (!crypto_mod_get(alg))
-                       alg = ERR_PTR(-EAGAIN);
-       } else
+       if (timeout < 0)
+               alg = ERR_PTR(-EINTR);
+       else if (!timeout)
+               alg = ERR_PTR(-ETIMEDOUT);
+       else if (!alg)
                alg = ERR_PTR(-ENOENT);
+       else if (crypto_is_test_larval(larval) &&
+                !(alg->cra_flags & CRYPTO_ALG_TESTED))
+               alg = ERR_PTR(-EAGAIN);
+       else if (!crypto_mod_get(alg))
+               alg = ERR_PTR(-EAGAIN);
        crypto_mod_put(&larval->alg);
 
        return alg;
 }
 
-static struct crypto_alg *crypto_alg_lookup(const char *name, u32 type,
-                                           u32 mask)
+struct crypto_alg *crypto_alg_lookup(const char *name, u32 type, u32 mask)
 {
        struct crypto_alg *alg;
 
@@ -176,6 +203,7 @@ static struct crypto_alg *crypto_alg_lookup(const char *name, u32 type,
 
        return alg;
 }
+EXPORT_SYMBOL_GPL(crypto_alg_lookup);
 
 struct crypto_alg *crypto_larval_lookup(const char *name, u32 type, u32 mask)
 {
@@ -192,25 +220,40 @@ struct crypto_alg *crypto_larval_lookup(const char *name, u32 type, u32 mask)
        if (alg)
                return crypto_is_larval(alg) ? crypto_larval_wait(alg) : alg;
 
-       return crypto_larval_alloc(name, type, mask);
+       return crypto_larval_add(name, type, mask);
 }
 EXPORT_SYMBOL_GPL(crypto_larval_lookup);
 
+int crypto_probing_notify(unsigned long val, void *v)
+{
+       int ok;
+
+       ok = blocking_notifier_call_chain(&crypto_chain, val, v);
+       if (ok == NOTIFY_DONE) {
+               request_module("cryptomgr");
+               ok = blocking_notifier_call_chain(&crypto_chain, val, v);
+       }
+
+       return ok;
+}
+EXPORT_SYMBOL_GPL(crypto_probing_notify);
+
 struct crypto_alg *crypto_alg_mod_lookup(const char *name, u32 type, u32 mask)
 {
        struct crypto_alg *alg;
        struct crypto_alg *larval;
        int ok;
 
+       if (!(mask & CRYPTO_ALG_TESTED)) {
+               type |= CRYPTO_ALG_TESTED;
+               mask |= CRYPTO_ALG_TESTED;
+       }
+
        larval = crypto_larval_lookup(name, type, mask);
        if (IS_ERR(larval) || !crypto_is_larval(larval))
                return larval;
 
-       ok = crypto_notify(CRYPTO_MSG_ALG_REQUEST, larval);
-       if (ok == NOTIFY_DONE) {
-               request_module("cryptomgr");
-               ok = crypto_notify(CRYPTO_MSG_ALG_REQUEST, larval);
-       }
+       ok = crypto_probing_notify(CRYPTO_MSG_ALG_REQUEST, larval);
 
        if (ok == NOTIFY_STOP)
                alg = crypto_larval_wait(larval);
index 185f955fb0d7f79770b7765660bd1a9cbbcfab2e..4a7e65c4df4dc3ac6af007efa1d136e1232be053 100644 (file)
@@ -696,34 +696,5 @@ void skcipher_geniv_exit(struct crypto_tfm *tfm)
 }
 EXPORT_SYMBOL_GPL(skcipher_geniv_exit);
 
-static int __init blkcipher_module_init(void)
-{
-       int err;
-
-       err = chainiv_module_init();
-       if (err)
-               goto out;
-
-       err = eseqiv_module_init();
-       if (err)
-               goto eseqiv_err;
-
-out:
-       return err;
-
-eseqiv_err:
-       chainiv_module_exit();
-       goto out;
-}
-
-static void __exit blkcipher_module_exit(void)
-{
-       eseqiv_module_exit();
-       chainiv_module_exit();
-}
-
-module_init(blkcipher_module_init);
-module_exit(blkcipher_module_exit);
-
 MODULE_LICENSE("GPL");
 MODULE_DESCRIPTION("Generic block chaining cipher type");
index 9affadee32879c5114afab56d4bc82428c01dcf6..7c37a497b860a27733eac07c4f7ff018c0abb4a3 100644 (file)
  */
 
 #include <crypto/internal/skcipher.h>
+#include <crypto/rng.h>
 #include <linux/err.h>
 #include <linux/init.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
-#include <linux/random.h>
 #include <linux/spinlock.h>
 #include <linux/string.h>
 #include <linux/workqueue.h>
@@ -83,6 +83,7 @@ static int chainiv_givencrypt_first(struct skcipher_givcrypt_request *req)
 {
        struct crypto_ablkcipher *geniv = skcipher_givcrypt_reqtfm(req);
        struct chainiv_ctx *ctx = crypto_ablkcipher_ctx(geniv);
+       int err = 0;
 
        spin_lock_bh(&ctx->lock);
        if (crypto_ablkcipher_crt(geniv)->givencrypt !=
@@ -90,11 +91,15 @@ static int chainiv_givencrypt_first(struct skcipher_givcrypt_request *req)
                goto unlock;
 
        crypto_ablkcipher_crt(geniv)->givencrypt = chainiv_givencrypt;
-       get_random_bytes(ctx->iv, crypto_ablkcipher_ivsize(geniv));
+       err = crypto_rng_get_bytes(crypto_default_rng, ctx->iv,
+                                  crypto_ablkcipher_ivsize(geniv));
 
 unlock:
        spin_unlock_bh(&ctx->lock);
 
+       if (err)
+               return err;
+
        return chainiv_givencrypt(req);
 }
 
@@ -203,6 +208,7 @@ static int async_chainiv_givencrypt_first(struct skcipher_givcrypt_request *req)
 {
        struct crypto_ablkcipher *geniv = skcipher_givcrypt_reqtfm(req);
        struct async_chainiv_ctx *ctx = crypto_ablkcipher_ctx(geniv);
+       int err = 0;
 
        if (test_and_set_bit(CHAINIV_STATE_INUSE, &ctx->state))
                goto out;
@@ -212,11 +218,15 @@ static int async_chainiv_givencrypt_first(struct skcipher_givcrypt_request *req)
                goto unlock;
 
        crypto_ablkcipher_crt(geniv)->givencrypt = async_chainiv_givencrypt;
-       get_random_bytes(ctx->iv, crypto_ablkcipher_ivsize(geniv));
+       err = crypto_rng_get_bytes(crypto_default_rng, ctx->iv,
+                                  crypto_ablkcipher_ivsize(geniv));
 
 unlock:
        clear_bit(CHAINIV_STATE_INUSE, &ctx->state);
 
+       if (err)
+               return err;
+
 out:
        return async_chainiv_givencrypt(req);
 }
@@ -284,9 +294,13 @@ static struct crypto_instance *chainiv_alloc(struct rtattr **tb)
        if (IS_ERR(algt))
                return ERR_PTR(err);
 
+       err = crypto_get_default_rng();
+       if (err)
+               return ERR_PTR(err);
+
        inst = skcipher_geniv_alloc(&chainiv_tmpl, tb, 0, 0);
        if (IS_ERR(inst))
-               goto out;
+               goto put_rng;
 
        inst->alg.cra_ablkcipher.givencrypt = chainiv_givencrypt_first;
 
@@ -311,21 +325,37 @@ static struct crypto_instance *chainiv_alloc(struct rtattr **tb)
 
 out:
        return inst;
+
+put_rng:
+       crypto_put_default_rng();
+       goto out;
+}
+
+static void chainiv_free(struct crypto_instance *inst)
+{
+       skcipher_geniv_free(inst);
+       crypto_put_default_rng();
 }
 
 static struct crypto_template chainiv_tmpl = {
        .name = "chainiv",
        .alloc = chainiv_alloc,
-       .free = skcipher_geniv_free,
+       .free = chainiv_free,
        .module = THIS_MODULE,
 };
 
-int __init chainiv_module_init(void)
+static int __init chainiv_module_init(void)
 {
        return crypto_register_template(&chainiv_tmpl);
 }
 
-void chainiv_module_exit(void)
+static void chainiv_module_exit(void)
 {
        crypto_unregister_template(&chainiv_tmpl);
 }
+
+module_init(chainiv_module_init);
+module_exit(chainiv_module_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Chain IV Generator");
index 881d30910434831f528f5be244ab502bd984d0b6..2a342c8e52b385b34f2602b0c8dfb4d465e9b573 100644 (file)
  */
 
 #include <crypto/internal/skcipher.h>
+#include <crypto/rng.h>
 #include <crypto/scatterwalk.h>
 #include <linux/err.h>
 #include <linux/init.h>
 #include <linux/kernel.h>
 #include <linux/mm.h>
 #include <linux/module.h>
-#include <linux/random.h>
 #include <linux/scatterlist.h>
 #include <linux/spinlock.h>
 #include <linux/string.h>
@@ -163,17 +163,22 @@ static int eseqiv_givencrypt_first(struct skcipher_givcrypt_request *req)
 {
        struct crypto_ablkcipher *geniv = skcipher_givcrypt_reqtfm(req);
        struct eseqiv_ctx *ctx = crypto_ablkcipher_ctx(geniv);
+       int err = 0;
 
        spin_lock_bh(&ctx->lock);
        if (crypto_ablkcipher_crt(geniv)->givencrypt != eseqiv_givencrypt_first)
                goto unlock;
 
        crypto_ablkcipher_crt(geniv)->givencrypt = eseqiv_givencrypt;
-       get_random_bytes(ctx->salt, crypto_ablkcipher_ivsize(geniv));
+       err = crypto_rng_get_bytes(crypto_default_rng, ctx->salt,
+                                  crypto_ablkcipher_ivsize(geniv));
 
 unlock:
        spin_unlock_bh(&ctx->lock);
 
+       if (err)
+               return err;
+
        return eseqiv_givencrypt(req);
 }
 
@@ -216,9 +221,13 @@ static struct crypto_instance *eseqiv_alloc(struct rtattr **tb)
        struct crypto_instance *inst;
        int err;
 
+       err = crypto_get_default_rng();
+       if (err)
+               return ERR_PTR(err);
+
        inst = skcipher_geniv_alloc(&eseqiv_tmpl, tb, 0, 0);
        if (IS_ERR(inst))
-               goto out;
+               goto put_rng;
 
        err = -EINVAL;
        if (inst->alg.cra_ablkcipher.ivsize != inst->alg.cra_blocksize)
@@ -238,22 +247,36 @@ out:
 free_inst:
        skcipher_geniv_free(inst);
        inst = ERR_PTR(err);
+put_rng:
+       crypto_put_default_rng();
        goto out;
 }
 
+static void eseqiv_free(struct crypto_instance *inst)
+{
+       skcipher_geniv_free(inst);
+       crypto_put_default_rng();
+}
+
 static struct crypto_template eseqiv_tmpl = {
        .name = "eseqiv",
        .alloc = eseqiv_alloc,
-       .free = skcipher_geniv_free,
+       .free = eseqiv_free,
        .module = THIS_MODULE,
 };
 
-int __init eseqiv_module_init(void)
+static int __init eseqiv_module_init(void)
 {
        return crypto_register_template(&eseqiv_tmpl);
 }
 
-void __exit eseqiv_module_exit(void)
+static void __exit eseqiv_module_exit(void)
 {
        crypto_unregister_template(&eseqiv_tmpl);
 }
+
+module_init(eseqiv_module_init);
+module_exit(eseqiv_module_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Encrypted Sequence Number IV Generator");
diff --git a/crypto/fips.c b/crypto/fips.c
new file mode 100644 (file)
index 0000000..5539700
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * FIPS 200 support.
+ *
+ * Copyright (c) 2008 Neil Horman <nhorman@tuxdriver.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ */
+
+#include "internal.h"
+
+int fips_enabled;
+EXPORT_SYMBOL_GPL(fips_enabled);
+
+/* Process kernel command-line parameter at boot time. fips=0 or fips=1 */
+static int fips_enable(char *str)
+{
+       fips_enabled = !!simple_strtol(str, NULL, 0);
+       printk(KERN_INFO "fips mode: %s\n",
+               fips_enabled ? "enabled" : "disabled");
+       return 1;
+}
+
+__setup("fips=", fips_enable);
index 683fcb2d91f41968e946792e82d6eae3e917913c..8ef72d76092e40227000c3126688f254ffed6978 100644 (file)
 #include <linux/rwsem.h>
 #include <linux/slab.h>
 
+#ifdef CONFIG_CRYPTO_FIPS
+extern int fips_enabled;
+#else
+#define fips_enabled 0
+#endif
+
 /* Crypto notification events. */
 enum {
        CRYPTO_MSG_ALG_REQUEST,
@@ -82,7 +88,7 @@ static inline unsigned int crypto_compress_ctxsize(struct crypto_alg *alg)
 }
 
 struct crypto_alg *crypto_mod_get(struct crypto_alg *alg);
-struct crypto_alg *__crypto_alg_lookup(const char *name, u32 type, u32 mask);
+struct crypto_alg *crypto_alg_lookup(const char *name, u32 type, u32 mask);
 struct crypto_alg *crypto_alg_mod_lookup(const char *name, u32 type, u32 mask);
 
 int crypto_init_digest_ops(struct crypto_tfm *tfm);
@@ -94,9 +100,11 @@ void crypto_exit_digest_ops(struct crypto_tfm *tfm);
 void crypto_exit_cipher_ops(struct crypto_tfm *tfm);
 void crypto_exit_compress_ops(struct crypto_tfm *tfm);
 
+struct crypto_larval *crypto_larval_alloc(const char *name, u32 type, u32 mask);
 void crypto_larval_kill(struct crypto_alg *alg);
 struct crypto_alg *crypto_larval_lookup(const char *name, u32 type, u32 mask);
 void crypto_larval_error(const char *name, u32 type, u32 mask);
+void crypto_alg_tested(const char *name, int err);
 
 void crypto_shoot_alg(struct crypto_alg *alg);
 struct crypto_tfm *__crypto_alloc_tfm(struct crypto_alg *alg, u32 type,
@@ -107,6 +115,10 @@ int crypto_register_instance(struct crypto_template *tmpl,
 
 int crypto_register_notifier(struct notifier_block *nb);
 int crypto_unregister_notifier(struct notifier_block *nb);
+int crypto_probing_notify(unsigned long val, void *v);
+
+int __init testmgr_init(void);
+void testmgr_exit(void);
 
 static inline void crypto_alg_put(struct crypto_alg *alg)
 {
@@ -139,9 +151,9 @@ static inline int crypto_is_moribund(struct crypto_alg *alg)
        return alg->cra_flags & (CRYPTO_ALG_DEAD | CRYPTO_ALG_DYING);
 }
 
-static inline int crypto_notify(unsigned long val, void *v)
+static inline void crypto_notify(unsigned long val, void *v)
 {
-       return blocking_notifier_call_chain(&crypto_chain, val, v);
+       blocking_notifier_call_chain(&crypto_chain, val, v);
 }
 
 #endif /* _CRYPTO_INTERNAL_H */
diff --git a/crypto/krng.c b/crypto/krng.c
new file mode 100644 (file)
index 0000000..4328bb3
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * RNG implementation using standard kernel RNG.
+ *
+ * Copyright (c) 2008 Herbert Xu <herbert@gondor.apana.org.au>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * any later version.
+ *
+ */
+
+#include <crypto/internal/rng.h>
+#include <linux/err.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/random.h>
+
+static int krng_get_random(struct crypto_rng *tfm, u8 *rdata, unsigned int dlen)
+{
+       get_random_bytes(rdata, dlen);
+       return 0;
+}
+
+static int krng_reset(struct crypto_rng *tfm, u8 *seed, unsigned int slen)
+{
+       return 0;
+}
+
+static struct crypto_alg krng_alg = {
+       .cra_name               = "stdrng",
+       .cra_driver_name        = "krng",
+       .cra_priority           = 200,
+       .cra_flags              = CRYPTO_ALG_TYPE_RNG,
+       .cra_ctxsize            = 0,
+       .cra_type               = &crypto_rng_type,
+       .cra_module             = THIS_MODULE,
+       .cra_list               = LIST_HEAD_INIT(krng_alg.cra_list),
+       .cra_u                  = {
+               .rng = {
+                       .rng_make_random        = krng_get_random,
+                       .rng_reset              = krng_reset,
+                       .seedsize               = 0,
+               }
+       }
+};
+
+
+/* Module initalization */
+static int __init krng_mod_init(void)
+{
+       return crypto_register_alg(&krng_alg);
+}
+
+static void __exit krng_mod_fini(void)
+{
+       crypto_unregister_alg(&krng_alg);
+       return;
+}
+
+module_init(krng_mod_init);
+module_exit(krng_mod_fini);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Kernel Random Number Generator");
+MODULE_ALIAS("stdrng");
index 02ff5670c1583e4d454dfc37028b427e92d7d342..37a13d05636d4beaaea521d4538aa711e8bbb627 100644 (file)
 #include <linux/rwsem.h>
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
+#include <linux/sysctl.h>
 #include "internal.h"
 
+#ifdef CONFIG_CRYPTO_FIPS
+static struct ctl_table crypto_sysctl_table[] = {
+       {
+               .ctl_name       = CTL_UNNUMBERED,
+               .procname       = "fips_enabled",
+               .data           = &fips_enabled,
+               .maxlen         = sizeof(int),
+               .mode           = 0444,
+               .proc_handler   = &proc_dointvec
+       },
+       {
+               .ctl_name = 0,
+       },
+};
+
+static struct ctl_table crypto_dir_table[] = {
+       {
+               .ctl_name       = CTL_UNNUMBERED,
+               .procname       = "crypto",
+               .mode           = 0555,
+               .child          = crypto_sysctl_table
+       },
+       {
+               .ctl_name = 0,
+       },
+};
+
+static struct ctl_table_header *crypto_sysctls;
+
+static void crypto_proc_fips_init(void)
+{
+       crypto_sysctls = register_sysctl_table(crypto_dir_table);
+}
+
+static void crypto_proc_fips_exit(void)
+{
+       if (crypto_sysctls)
+               unregister_sysctl_table(crypto_sysctls);
+}
+#else
+#define crypto_proc_fips_init()
+#define crypto_proc_fips_exit()
+#endif
+
 static void *c_start(struct seq_file *m, loff_t *pos)
 {
        down_read(&crypto_alg_sem);
@@ -46,8 +91,11 @@ static int c_show(struct seq_file *m, void *p)
        seq_printf(m, "module       : %s\n", module_name(alg->cra_module));
        seq_printf(m, "priority     : %d\n", alg->cra_priority);
        seq_printf(m, "refcnt       : %d\n", atomic_read(&alg->cra_refcnt));
+       seq_printf(m, "selftest     : %s\n",
+                  (alg->cra_flags & CRYPTO_ALG_TESTED) ?
+                  "passed" : "unknown");
        
-       switch (alg->cra_flags & CRYPTO_ALG_TYPE_MASK) {
+       switch (alg->cra_flags & (CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_LARVAL)) {
        case CRYPTO_ALG_TYPE_CIPHER:
                seq_printf(m, "type         : cipher\n");
                seq_printf(m, "blocksize    : %u\n", alg->cra_blocksize);
@@ -67,7 +115,10 @@ static int c_show(struct seq_file *m, void *p)
                seq_printf(m, "type         : compression\n");
                break;
        default:
-               if (alg->cra_type && alg->cra_type->show)
+               if (alg->cra_flags & CRYPTO_ALG_LARVAL) {
+                       seq_printf(m, "type         : larval\n");
+                       seq_printf(m, "flags        : 0x%x\n", alg->cra_flags);
+               } else if (alg->cra_type && alg->cra_type->show)
                        alg->cra_type->show(m, alg);
                else
                        seq_printf(m, "type         : unknown\n");
@@ -100,9 +151,11 @@ static const struct file_operations proc_crypto_ops = {
 void __init crypto_init_proc(void)
 {
        proc_create("crypto", 0, NULL, &proc_crypto_ops);
+       crypto_proc_fips_init();
 }
 
 void __exit crypto_exit_proc(void)
 {
+       crypto_proc_fips_exit();
        remove_proc_entry("crypto", NULL);
 }
diff --git a/crypto/rng.c b/crypto/rng.c
new file mode 100644 (file)
index 0000000..6e94bc7
--- /dev/null
@@ -0,0 +1,126 @@
+/*
+ * Cryptographic API.
+ *
+ * RNG operations.
+ *
+ * Copyright (c) 2008 Neil Horman <nhorman@tuxdriver.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ */
+
+#include <asm/atomic.h>
+#include <crypto/internal/rng.h>
+#include <linux/err.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/random.h>
+#include <linux/seq_file.h>
+#include <linux/string.h>
+
+static DEFINE_MUTEX(crypto_default_rng_lock);
+struct crypto_rng *crypto_default_rng;
+EXPORT_SYMBOL_GPL(crypto_default_rng);
+static int crypto_default_rng_refcnt;
+
+static int rngapi_reset(struct crypto_rng *tfm, u8 *seed, unsigned int slen)
+{
+       u8 *buf = NULL;
+       int err;
+
+       if (!seed && slen) {
+               buf = kmalloc(slen, GFP_KERNEL);
+               if (!buf)
+                       return -ENOMEM;
+
+               get_random_bytes(buf, slen);
+               seed = buf;
+       }
+
+       err = crypto_rng_alg(tfm)->rng_reset(tfm, seed, slen);
+
+       kfree(buf);
+       return err;
+}
+
+static int crypto_init_rng_ops(struct crypto_tfm *tfm, u32 type, u32 mask)
+{
+       struct rng_alg *alg = &tfm->__crt_alg->cra_rng;
+       struct rng_tfm *ops = &tfm->crt_rng;
+
+       ops->rng_gen_random = alg->rng_make_random;
+       ops->rng_reset = rngapi_reset;
+
+       return 0;
+}
+
+static void crypto_rng_show(struct seq_file *m, struct crypto_alg *alg)
+       __attribute__ ((unused));
+static void crypto_rng_show(struct seq_file *m, struct crypto_alg *alg)
+{
+       seq_printf(m, "type         : rng\n");
+       seq_printf(m, "seedsize     : %u\n", alg->cra_rng.seedsize);
+}
+
+static unsigned int crypto_rng_ctxsize(struct crypto_alg *alg, u32 type,
+                                      u32 mask)
+{
+       return alg->cra_ctxsize;
+}
+
+const struct crypto_type crypto_rng_type = {
+       .ctxsize = crypto_rng_ctxsize,
+       .init = crypto_init_rng_ops,
+#ifdef CONFIG_PROC_FS
+       .show = crypto_rng_show,
+#endif
+};
+EXPORT_SYMBOL_GPL(crypto_rng_type);
+
+int crypto_get_default_rng(void)
+{
+       struct crypto_rng *rng;
+       int err;
+
+       mutex_lock(&crypto_default_rng_lock);
+       if (!crypto_default_rng) {
+               rng = crypto_alloc_rng("stdrng", 0, 0);
+               err = PTR_ERR(rng);
+               if (IS_ERR(rng))
+                       goto unlock;
+
+               err = crypto_rng_reset(rng, NULL, crypto_rng_seedsize(rng));
+               if (err) {
+                       crypto_free_rng(rng);
+                       goto unlock;
+               }
+
+               crypto_default_rng = rng;
+       }
+
+       crypto_default_rng_refcnt++;
+       err = 0;
+
+unlock:
+       mutex_unlock(&crypto_default_rng_lock);
+
+       return err;
+}
+EXPORT_SYMBOL_GPL(crypto_get_default_rng);
+
+void crypto_put_default_rng(void)
+{
+       mutex_lock(&crypto_default_rng_lock);
+       if (!--crypto_default_rng_refcnt) {
+               crypto_free_rng(crypto_default_rng);
+               crypto_default_rng = NULL;
+       }
+       mutex_unlock(&crypto_default_rng_lock);
+}
+EXPORT_SYMBOL_GPL(crypto_put_default_rng);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Random Number Genertor");
index b903aab3157759e0803c818b32c35a52bd39ad44..5a013a8bf87a3ceb1a61036a459d71f3520ba09e 100644 (file)
 
 #include <crypto/internal/aead.h>
 #include <crypto/internal/skcipher.h>
+#include <crypto/rng.h>
 #include <linux/err.h>
 #include <linux/init.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
-#include <linux/random.h>
 #include <linux/spinlock.h>
 #include <linux/string.h>
 
@@ -189,17 +189,22 @@ static int seqiv_givencrypt_first(struct skcipher_givcrypt_request *req)
 {
        struct crypto_ablkcipher *geniv = skcipher_givcrypt_reqtfm(req);
        struct seqiv_ctx *ctx = crypto_ablkcipher_ctx(geniv);
+       int err = 0;
 
        spin_lock_bh(&ctx->lock);
        if (crypto_ablkcipher_crt(geniv)->givencrypt != seqiv_givencrypt_first)
                goto unlock;
 
        crypto_ablkcipher_crt(geniv)->givencrypt = seqiv_givencrypt;
-       get_random_bytes(ctx->salt, crypto_ablkcipher_ivsize(geniv));
+       err = crypto_rng_get_bytes(crypto_default_rng, ctx->salt,
+                                  crypto_ablkcipher_ivsize(geniv));
 
 unlock:
        spin_unlock_bh(&ctx->lock);
 
+       if (err)
+               return err;
+
        return seqiv_givencrypt(req);
 }
 
@@ -207,17 +212,22 @@ static int seqiv_aead_givencrypt_first(struct aead_givcrypt_request *req)
 {
        struct crypto_aead *geniv = aead_givcrypt_reqtfm(req);
        struct seqiv_ctx *ctx = crypto_aead_ctx(geniv);
+       int err = 0;
 
        spin_lock_bh(&ctx->lock);
        if (crypto_aead_crt(geniv)->givencrypt != seqiv_aead_givencrypt_first)
                goto unlock;
 
        crypto_aead_crt(geniv)->givencrypt = seqiv_aead_givencrypt;
-       get_random_bytes(ctx->salt, crypto_aead_ivsize(geniv));
+       err = crypto_rng_get_bytes(crypto_default_rng, ctx->salt,
+                                  crypto_aead_ivsize(geniv));
 
 unlock:
        spin_unlock_bh(&ctx->lock);
 
+       if (err)
+               return err;
+
        return seqiv_aead_givencrypt(req);
 }
 
@@ -298,19 +308,27 @@ static struct crypto_instance *seqiv_alloc(struct rtattr **tb)
        if (IS_ERR(algt))
                return ERR_PTR(err);
 
+       err = crypto_get_default_rng();
+       if (err)
+               return ERR_PTR(err);
+
        if ((algt->type ^ CRYPTO_ALG_TYPE_AEAD) & CRYPTO_ALG_TYPE_MASK)
                inst = seqiv_ablkcipher_alloc(tb);
        else
                inst = seqiv_aead_alloc(tb);
 
        if (IS_ERR(inst))
-               goto out;
+               goto put_rng;
 
        inst->alg.cra_alignmask |= __alignof__(u32) - 1;
        inst->alg.cra_ctxsize += sizeof(struct seqiv_ctx);
 
 out:
        return inst;
+
+put_rng:
+       crypto_put_default_rng();
+       goto out;
 }
 
 static void seqiv_free(struct crypto_instance *inst)
@@ -319,6 +337,7 @@ static void seqiv_free(struct crypto_instance *inst)
                skcipher_geniv_free(inst);
        else
                aead_geniv_free(inst);
+       crypto_put_default_rng();
 }
 
 static struct crypto_template seqiv_tmpl = {
index 66368022e0bf32466fa4a4e0569e9e03303b6b12..28a45a1e6f423603a563ef40c821736a88ef266b 100644 (file)
 #include <linux/err.h>
 #include <linux/init.h>
 #include <linux/module.h>
-#include <linux/mm.h>
 #include <linux/slab.h>
 #include <linux/scatterlist.h>
 #include <linux/string.h>
-#include <linux/crypto.h>
 #include <linux/moduleparam.h>
 #include <linux/jiffies.h>
 #include <linux/timex.h>
 #include "tcrypt.h"
 
 /*
- * Need to kmalloc() memory for testing.
+ * Need slab memory for testing (size in number of pages).
  */
-#define TVMEMSIZE      16384
-#define XBUFSIZE       32768
+#define TVMEMSIZE      4
 
 /*
- * Indexes into the xbuf to simulate cross-page access.
- */
-#define IDX1           32
-#define IDX2           32400
-#define IDX3           1
-#define IDX4           8193
-#define IDX5           22222
-#define IDX6           17101
-#define IDX7           27333
-#define IDX8           3000
-
-/*
-* Used by test_cipher()
+* Used by test_cipher_speed()
 */
 #define ENCRYPT 1
 #define DECRYPT 0
 
-struct tcrypt_result {
-       struct completion completion;
-       int err;
-};
-
-static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 };
-
 /*
  * Used by test_cipher_speed()
  */
 static unsigned int sec;
 
 static int mode;
-static char *xbuf;
-static char *axbuf;
-static char *tvmem;
+static char *tvmem[TVMEMSIZE];
 
 static char *check[] = {
        "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256",
@@ -80,655 +56,13 @@ static char *check[] = {
        "lzo", "cts", NULL
 };
 
-static void hexdump(unsigned char *buf, unsigned int len)
-{
-       print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET,
-                       16, 1,
-                       buf, len, false);
-}
-
-static void tcrypt_complete(struct crypto_async_request *req, int err)
-{
-       struct tcrypt_result *res = req->data;
-
-       if (err == -EINPROGRESS)
-               return;
-
-       res->err = err;
-       complete(&res->completion);
-}
-
-static void test_hash(char *algo, struct hash_testvec *template,
-                     unsigned int tcount)
-{
-       unsigned int i, j, k, temp;
-       struct scatterlist sg[8];
-       char result[64];
-       struct crypto_ahash *tfm;
-       struct ahash_request *req;
-       struct tcrypt_result tresult;
-       int ret;
-       void *hash_buff;
-
-       printk("\ntesting %s\n", algo);
-
-       init_completion(&tresult.completion);
-
-       tfm = crypto_alloc_ahash(algo, 0, 0);
-       if (IS_ERR(tfm)) {
-               printk("failed to load transform for %s: %ld\n", algo,
-                      PTR_ERR(tfm));
-               return;
-       }
-
-       req = ahash_request_alloc(tfm, GFP_KERNEL);
-       if (!req) {
-               printk(KERN_ERR "failed to allocate request for %s\n", algo);
-               goto out_noreq;
-       }
-       ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
-                                  tcrypt_complete, &tresult);
-
-       for (i = 0; i < tcount; i++) {
-               printk("test %u:\n", i + 1);
-               memset(result, 0, 64);
-
-               hash_buff = kzalloc(template[i].psize, GFP_KERNEL);
-               if (!hash_buff)
-                       continue;
-
-               memcpy(hash_buff, template[i].plaintext, template[i].psize);
-               sg_init_one(&sg[0], hash_buff, template[i].psize);
-
-               if (template[i].ksize) {
-                       crypto_ahash_clear_flags(tfm, ~0);
-                       ret = crypto_ahash_setkey(tfm, template[i].key,
-                                                 template[i].ksize);
-                       if (ret) {
-                               printk("setkey() failed ret=%d\n", ret);
-                               kfree(hash_buff);
-                               goto out;
-                       }
-               }
-
-               ahash_request_set_crypt(req, sg, result, template[i].psize);
-               ret = crypto_ahash_digest(req);
-               switch (ret) {
-               case 0:
-                       break;
-               case -EINPROGRESS:
-               case -EBUSY:
-                       ret = wait_for_completion_interruptible(
-                               &tresult.completion);
-                       if (!ret && !(ret = tresult.err)) {
-                               INIT_COMPLETION(tresult.completion);
-                               break;
-                       }
-                       /* fall through */
-               default:
-                       printk("digest () failed ret=%d\n", ret);
-                       kfree(hash_buff);
-                       goto out;
-               }
-
-               hexdump(result, crypto_ahash_digestsize(tfm));
-               printk("%s\n",
-                      memcmp(result, template[i].digest,
-                             crypto_ahash_digestsize(tfm)) ?
-                      "fail" : "pass");
-               kfree(hash_buff);
-       }
-
-       printk("testing %s across pages\n", algo);
-
-       /* setup the dummy buffer first */
-       memset(xbuf, 0, XBUFSIZE);
-
-       j = 0;
-       for (i = 0; i < tcount; i++) {
-               if (template[i].np) {
-                       j++;
-                       printk("test %u:\n", j);
-                       memset(result, 0, 64);
-
-                       temp = 0;
-                       sg_init_table(sg, template[i].np);
-                       for (k = 0; k < template[i].np; k++) {
-                               memcpy(&xbuf[IDX[k]],
-                                      template[i].plaintext + temp,
-                                      template[i].tap[k]);
-                               temp += template[i].tap[k];
-                               sg_set_buf(&sg[k], &xbuf[IDX[k]],
-                                           template[i].tap[k]);
-                       }
-
-                       if (template[i].ksize) {
-                               crypto_ahash_clear_flags(tfm, ~0);
-                               ret = crypto_ahash_setkey(tfm, template[i].key,
-                                                         template[i].ksize);
-
-                               if (ret) {
-                                       printk("setkey() failed ret=%d\n", ret);
-                                       goto out;
-                               }
-                       }
-
-                       ahash_request_set_crypt(req, sg, result,
-                                               template[i].psize);
-                       ret = crypto_ahash_digest(req);
-                       switch (ret) {
-                       case 0:
-                               break;
-                       case -EINPROGRESS:
-                       case -EBUSY:
-                               ret = wait_for_completion_interruptible(
-                                       &tresult.completion);
-                               if (!ret && !(ret = tresult.err)) {
-                                       INIT_COMPLETION(tresult.completion);
-                                       break;
-                               }
-                               /* fall through */
-                       default:
-                               printk("digest () failed ret=%d\n", ret);
-                               goto out;
-                       }
-
-                       hexdump(result, crypto_ahash_digestsize(tfm));
-                       printk("%s\n",
-                              memcmp(result, template[i].digest,
-                                     crypto_ahash_digestsize(tfm)) ?
-                              "fail" : "pass");
-               }
-       }
-
-out:
-       ahash_request_free(req);
-out_noreq:
-       crypto_free_ahash(tfm);
-}
-
-static void test_aead(char *algo, int enc, struct aead_testvec *template,
-                     unsigned int tcount)
-{
-       unsigned int ret, i, j, k, n, temp;
-       char *q;
-       struct crypto_aead *tfm;
-       char *key;
-       struct aead_request *req;
-       struct scatterlist sg[8];
-       struct scatterlist asg[8];
-       const char *e;
-       struct tcrypt_result result;
-       unsigned int authsize;
-       void *input;
-       void *assoc;
-       char iv[MAX_IVLEN];
-
-       if (enc == ENCRYPT)
-               e = "encryption";
-       else
-               e = "decryption";
-
-       printk(KERN_INFO "\ntesting %s %s\n", algo, e);
-
-       init_completion(&result.completion);
-
-       tfm = crypto_alloc_aead(algo, 0, 0);
-
-       if (IS_ERR(tfm)) {
-               printk(KERN_INFO "failed to load transform for %s: %ld\n",
-                      algo, PTR_ERR(tfm));
-               return;
-       }
-
-       req = aead_request_alloc(tfm, GFP_KERNEL);
-       if (!req) {
-               printk(KERN_INFO "failed to allocate request for %s\n", algo);
-               goto out;
-       }
-
-       aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
-                                 tcrypt_complete, &result);
-
-       for (i = 0, j = 0; i < tcount; i++) {
-               if (!template[i].np) {
-                       printk(KERN_INFO "test %u (%d bit key):\n",
-                              ++j, template[i].klen * 8);
-
-                       /* some tepmplates have no input data but they will
-                        * touch input
-                        */
-                       input = kzalloc(template[i].ilen + template[i].rlen, GFP_KERNEL);
-                       if (!input)
-                               continue;
-
-                       assoc = kzalloc(template[i].alen, GFP_KERNEL);
-                       if (!assoc) {
-                               kfree(input);
-                               continue;
-                       }
-
-                       memcpy(input, template[i].input, template[i].ilen);
-                       memcpy(assoc, template[i].assoc, template[i].alen);
-                       if (template[i].iv)
-                               memcpy(iv, template[i].iv, MAX_IVLEN);
-                       else
-                               memset(iv, 0, MAX_IVLEN);
-
-                       crypto_aead_clear_flags(tfm, ~0);
-                       if (template[i].wk)
-                               crypto_aead_set_flags(
-                                       tfm, CRYPTO_TFM_REQ_WEAK_KEY);
-
-                       if (template[i].key)
-                               key = template[i].key;
-                       else
-                               key = kzalloc(template[i].klen, GFP_KERNEL);
-
-                       ret = crypto_aead_setkey(tfm, key,
-                                                template[i].klen);
-                       if (ret) {
-                               printk(KERN_INFO "setkey() failed flags=%x\n",
-                                      crypto_aead_get_flags(tfm));
-
-                               if (!template[i].fail)
-                                       goto next_one;
-                       }
-
-                       authsize = abs(template[i].rlen - template[i].ilen);
-                       ret = crypto_aead_setauthsize(tfm, authsize);
-                       if (ret) {
-                               printk(KERN_INFO
-                                      "failed to set authsize = %u\n",
-                                      authsize);
-                               goto next_one;
-                       }
-
-                       sg_init_one(&sg[0], input,
-                                   template[i].ilen + (enc ? authsize : 0));
-
-                       sg_init_one(&asg[0], assoc, template[i].alen);
-
-                       aead_request_set_crypt(req, sg, sg,
-                                              template[i].ilen, iv);
-
-                       aead_request_set_assoc(req, asg, template[i].alen);
-
-                       ret = enc ?
-                               crypto_aead_encrypt(req) :
-                               crypto_aead_decrypt(req);
-
-                       switch (ret) {
-                       case 0:
-                               break;
-                       case -EINPROGRESS:
-                       case -EBUSY:
-                               ret = wait_for_completion_interruptible(
-                                       &result.completion);
-                               if (!ret && !(ret = result.err)) {
-                                       INIT_COMPLETION(result.completion);
-                                       break;
-                               }
-                               /* fall through */
-                       default:
-                               printk(KERN_INFO "%s () failed err=%d\n",
-                                      e, -ret);
-                               goto next_one;
-                       }
-
-                       q = input;
-                       hexdump(q, template[i].rlen);
-
-                       printk(KERN_INFO "enc/dec: %s\n",
-                              memcmp(q, template[i].result,
-                                     template[i].rlen) ? "fail" : "pass");
-next_one:
-                       if (!template[i].key)
-                               kfree(key);
-                       kfree(assoc);
-                       kfree(input);
-               }
-       }
-
-       printk(KERN_INFO "\ntesting %s %s across pages (chunking)\n", algo, e);
-       memset(axbuf, 0, XBUFSIZE);
-
-       for (i = 0, j = 0; i < tcount; i++) {
-               if (template[i].np) {
-                       printk(KERN_INFO "test %u (%d bit key):\n",
-                              ++j, template[i].klen * 8);
-
-                       if (template[i].iv)
-                               memcpy(iv, template[i].iv, MAX_IVLEN);
-                       else
-                               memset(iv, 0, MAX_IVLEN);
-
-                       crypto_aead_clear_flags(tfm, ~0);
-                       if (template[i].wk)
-                               crypto_aead_set_flags(
-                                       tfm, CRYPTO_TFM_REQ_WEAK_KEY);
-                       key = template[i].key;
-
-                       ret = crypto_aead_setkey(tfm, key, template[i].klen);
-                       if (ret) {
-                               printk(KERN_INFO "setkey() failed flags=%x\n",
-                                      crypto_aead_get_flags(tfm));
-
-                               if (!template[i].fail)
-                                       goto out;
-                       }
-
-                       memset(xbuf, 0, XBUFSIZE);
-                       sg_init_table(sg, template[i].np);
-                       for (k = 0, temp = 0; k < template[i].np; k++) {
-                               memcpy(&xbuf[IDX[k]],
-                                      template[i].input + temp,
-                                      template[i].tap[k]);
-                               temp += template[i].tap[k];
-                               sg_set_buf(&sg[k], &xbuf[IDX[k]],
-                                          template[i].tap[k]);
-                       }
-
-                       authsize = abs(template[i].rlen - template[i].ilen);
-                       ret = crypto_aead_setauthsize(tfm, authsize);
-                       if (ret) {
-                               printk(KERN_INFO
-                                      "failed to set authsize = %u\n",
-                                      authsize);
-                               goto out;
-                       }
-
-                       if (enc)
-                               sg[k - 1].length += authsize;
-
-                       sg_init_table(asg, template[i].anp);
-                       for (k = 0, temp = 0; k < template[i].anp; k++) {
-                               memcpy(&axbuf[IDX[k]],
-                                      template[i].assoc + temp,
-                                      template[i].atap[k]);
-                               temp += template[i].atap[k];
-                               sg_set_buf(&asg[k], &axbuf[IDX[k]],
-                                          template[i].atap[k]);
-                       }
-
-                       aead_request_set_crypt(req, sg, sg,
-                                              template[i].ilen,
-                                              iv);
-
-                       aead_request_set_assoc(req, asg, template[i].alen);
-
-                       ret = enc ?
-                               crypto_aead_encrypt(req) :
-                               crypto_aead_decrypt(req);
-
-                       switch (ret) {
-                       case 0:
-                               break;
-                       case -EINPROGRESS:
-                       case -EBUSY:
-                               ret = wait_for_completion_interruptible(
-                                       &result.completion);
-                               if (!ret && !(ret = result.err)) {
-                                       INIT_COMPLETION(result.completion);
-                                       break;
-                               }
-                               /* fall through */
-                       default:
-                               printk(KERN_INFO "%s () failed err=%d\n",
-                                      e, -ret);
-                               goto out;
-                       }
-
-                       for (k = 0, temp = 0; k < template[i].np; k++) {
-                               printk(KERN_INFO "page %u\n", k);
-                               q = &xbuf[IDX[k]];
-
-                               n = template[i].tap[k];
-                               if (k == template[i].np - 1)
-                                       n += enc ? authsize : -authsize;
-                               hexdump(q, n);
-                               printk(KERN_INFO "%s\n",
-                                      memcmp(q, template[i].result + temp, n) ?
-                                      "fail" : "pass");
-
-                               q += n;
-                               if (k == template[i].np - 1 && !enc) {
-                                       if (memcmp(q, template[i].input +
-                                                     temp + n, authsize))
-                                               n = authsize;
-                                       else
-                                               n = 0;
-                               } else {
-                                       for (n = 0; q[n]; n++)
-                                               ;
-                               }
-                               if (n) {
-                                       printk("Result buffer corruption %u "
-                                              "bytes:\n", n);
-                                       hexdump(q, n);
-                               }
-
-                               temp += template[i].tap[k];
-                       }
-               }
-       }
-
-out:
-       crypto_free_aead(tfm);
-       aead_request_free(req);
-}
-
-static void test_cipher(char *algo, int enc,
-                       struct cipher_testvec *template, unsigned int tcount)
+static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc,
+                              struct scatterlist *sg, int blen, int sec)
 {
-       unsigned int ret, i, j, k, n, temp;
-       char *q;
-       struct crypto_ablkcipher *tfm;
-       struct ablkcipher_request *req;
-       struct scatterlist sg[8];
-       const char *e;
-       struct tcrypt_result result;
-       void *data;
-       char iv[MAX_IVLEN];
-
-       if (enc == ENCRYPT)
-               e = "encryption";
-       else
-               e = "decryption";
-
-       printk("\ntesting %s %s\n", algo, e);
-
-       init_completion(&result.completion);
-       tfm = crypto_alloc_ablkcipher(algo, 0, 0);
-
-       if (IS_ERR(tfm)) {
-               printk("failed to load transform for %s: %ld\n", algo,
-                      PTR_ERR(tfm));
-               return;
-       }
-
-       req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
-       if (!req) {
-               printk("failed to allocate request for %s\n", algo);
-               goto out;
-       }
-
-       ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
-                                       tcrypt_complete, &result);
-
-       j = 0;
-       for (i = 0; i < tcount; i++) {
-
-               data = kzalloc(template[i].ilen, GFP_KERNEL);
-               if (!data)
-                       continue;
-
-               memcpy(data, template[i].input, template[i].ilen);
-               if (template[i].iv)
-                       memcpy(iv, template[i].iv, MAX_IVLEN);
-               else
-                       memset(iv, 0, MAX_IVLEN);
-
-               if (!(template[i].np)) {
-                       j++;
-                       printk("test %u (%d bit key):\n",
-                       j, template[i].klen * 8);
-
-                       crypto_ablkcipher_clear_flags(tfm, ~0);
-                       if (template[i].wk)
-                               crypto_ablkcipher_set_flags(
-                                       tfm, CRYPTO_TFM_REQ_WEAK_KEY);
-
-                       ret = crypto_ablkcipher_setkey(tfm, template[i].key,
-                                                      template[i].klen);
-                       if (ret) {
-                               printk("setkey() failed flags=%x\n",
-                                      crypto_ablkcipher_get_flags(tfm));
-
-                               if (!template[i].fail) {
-                                       kfree(data);
-                                       goto out;
-                               }
-                       }
-
-                       sg_init_one(&sg[0], data, template[i].ilen);
-
-                       ablkcipher_request_set_crypt(req, sg, sg,
-                                                    template[i].ilen, iv);
-                       ret = enc ?
-                               crypto_ablkcipher_encrypt(req) :
-                               crypto_ablkcipher_decrypt(req);
-
-                       switch (ret) {
-                       case 0:
-                               break;
-                       case -EINPROGRESS:
-                       case -EBUSY:
-                               ret = wait_for_completion_interruptible(
-                                       &result.completion);
-                               if (!ret && !((ret = result.err))) {
-                                       INIT_COMPLETION(result.completion);
-                                       break;
-                               }
-                               /* fall through */
-                       default:
-                               printk("%s () failed err=%d\n", e, -ret);
-                               kfree(data);
-                               goto out;
-                       }
-
-                       q = data;
-                       hexdump(q, template[i].rlen);
-
-                       printk("%s\n",
-                              memcmp(q, template[i].result,
-                                     template[i].rlen) ? "fail" : "pass");
-               }
-               kfree(data);
-       }
-
-       printk("\ntesting %s %s across pages (chunking)\n", algo, e);
-
-       j = 0;
-       for (i = 0; i < tcount; i++) {
-
-               if (template[i].iv)
-                       memcpy(iv, template[i].iv, MAX_IVLEN);
-               else
-                       memset(iv, 0, MAX_IVLEN);
-
-               if (template[i].np) {
-                       j++;
-                       printk("test %u (%d bit key):\n",
-                       j, template[i].klen * 8);
-
-                       memset(xbuf, 0, XBUFSIZE);
-                       crypto_ablkcipher_clear_flags(tfm, ~0);
-                       if (template[i].wk)
-                               crypto_ablkcipher_set_flags(
-                                       tfm, CRYPTO_TFM_REQ_WEAK_KEY);
-
-                       ret = crypto_ablkcipher_setkey(tfm, template[i].key,
-                                                      template[i].klen);
-                       if (ret) {
-                               printk("setkey() failed flags=%x\n",
-                                               crypto_ablkcipher_get_flags(tfm));
-
-                               if (!template[i].fail)
-                                       goto out;
-                       }
-
-                       temp = 0;
-                       sg_init_table(sg, template[i].np);
-                       for (k = 0; k < template[i].np; k++) {
-                               memcpy(&xbuf[IDX[k]],
-                                               template[i].input + temp,
-                                               template[i].tap[k]);
-                               temp += template[i].tap[k];
-                               sg_set_buf(&sg[k], &xbuf[IDX[k]],
-                                               template[i].tap[k]);
-                       }
-
-                       ablkcipher_request_set_crypt(req, sg, sg,
-                                       template[i].ilen, iv);
-
-                       ret = enc ?
-                               crypto_ablkcipher_encrypt(req) :
-                               crypto_ablkcipher_decrypt(req);
-
-                       switch (ret) {
-                       case 0:
-                               break;
-                       case -EINPROGRESS:
-                       case -EBUSY:
-                               ret = wait_for_completion_interruptible(
-                                       &result.completion);
-                               if (!ret && !((ret = result.err))) {
-                                       INIT_COMPLETION(result.completion);
-                                       break;
-                               }
-                               /* fall through */
-                       default:
-                               printk("%s () failed err=%d\n", e, -ret);
-                               goto out;
-                       }
-
-                       temp = 0;
-                       for (k = 0; k < template[i].np; k++) {
-                               printk("page %u\n", k);
-                               q = &xbuf[IDX[k]];
-                               hexdump(q, template[i].tap[k]);
-                               printk("%s\n",
-                                       memcmp(q, template[i].result + temp,
-                                               template[i].tap[k]) ? "fail" :
-                                       "pass");
-
-                               for (n = 0; q[template[i].tap[k] + n]; n++)
-                                       ;
-                               if (n) {
-                                       printk("Result buffer corruption %u "
-                                              "bytes:\n", n);
-                                       hexdump(&q[template[i].tap[k]], n);
-                               }
-                               temp += template[i].tap[k];
-                       }
-               }
-       }
-out:
-       crypto_free_ablkcipher(tfm);
-       ablkcipher_request_free(req);
-}
-
-static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc, char *p,
-                              int blen, int sec)
-{
-       struct scatterlist sg[1];
        unsigned long start, end;
        int bcount;
        int ret;
 
-       sg_init_one(sg, p, blen);
-
        for (start = jiffies, end = start + sec * HZ, bcount = 0;
             time_before(jiffies, end); bcount++) {
                if (enc)
@@ -745,16 +79,13 @@ static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc, char *p,
        return 0;
 }
 
-static int test_cipher_cycles(struct blkcipher_desc *desc, int enc, char *p,
-                             int blen)
+static int test_cipher_cycles(struct blkcipher_desc *desc, int enc,
+                             struct scatterlist *sg, int blen)
 {
-       struct scatterlist sg[1];
        unsigned long cycles = 0;
        int ret = 0;
        int i;
 
-       sg_init_one(sg, p, blen);
-
        local_bh_disable();
        local_irq_disable();
 
@@ -799,12 +130,12 @@ out:
 
 static u32 block_sizes[] = { 16, 64, 256, 1024, 8192, 0 };
 
-static void test_cipher_speed(char *algo, int enc, unsigned int sec,
-                             struct cipher_testvec *template,
+static void test_cipher_speed(const char *algo, int enc, unsigned int sec,
+                             struct cipher_speed_template *template,
                              unsigned int tcount, u8 *keysize)
 {
        unsigned int ret, i, j, iv_len;
-       unsigned char *key, *p, iv[128];
+       const char *key, iv[128];
        struct crypto_blkcipher *tfm;
        struct blkcipher_desc desc;
        const char *e;
@@ -832,27 +163,28 @@ static void test_cipher_speed(char *algo, int enc, unsigned int sec,
 
                b_size = block_sizes;
                do {
+                       struct scatterlist sg[TVMEMSIZE];
 
-                       if ((*keysize + *b_size) > TVMEMSIZE) {
-                               printk("template (%u) too big for tvmem (%u)\n",
-                                               *keysize + *b_size, TVMEMSIZE);
+                       if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
+                               printk("template (%u) too big for "
+                                      "tvmem (%lu)\n", *keysize + *b_size,
+                                      TVMEMSIZE * PAGE_SIZE);
                                goto out;
                        }
 
                        printk("test %u (%d bit key, %d byte blocks): ", i,
                                        *keysize * 8, *b_size);
 
-                       memset(tvmem, 0xff, *keysize + *b_size);
+                       memset(tvmem[0], 0xff, PAGE_SIZE);
 
                        /* set key, plain text and IV */
-                       key = (unsigned char *)tvmem;
+                       key = tvmem[0];
                        for (j = 0; j < tcount; j++) {
                                if (template[j].klen == *keysize) {
                                        key = template[j].key;
                                        break;
                                }
                        }
-                       p = (unsigned char *)tvmem + *keysize;
 
                        ret = crypto_blkcipher_setkey(tfm, key, *keysize);
                        if (ret) {
@@ -861,6 +193,14 @@ static void test_cipher_speed(char *algo, int enc, unsigned int sec,
                                goto out;
                        }
 
+                       sg_init_table(sg, TVMEMSIZE);
+                       sg_set_buf(sg, tvmem[0] + *keysize,
+                                  PAGE_SIZE - *keysize);
+                       for (j = 1; j < TVMEMSIZE; j++) {
+                               sg_set_buf(sg + j, tvmem[j], PAGE_SIZE);
+                               memset (tvmem[j], 0xff, PAGE_SIZE);
+                       }
+
                        iv_len = crypto_blkcipher_ivsize(tfm);
                        if (iv_len) {
                                memset(&iv, 0xff, iv_len);
@@ -868,9 +208,11 @@ static void test_cipher_speed(char *algo, int enc, unsigned int sec,
                        }
 
                        if (sec)
-                               ret = test_cipher_jiffies(&desc, enc, p, *b_size, sec);
+                               ret = test_cipher_jiffies(&desc, enc, sg,
+                                                         *b_size, sec);
                        else
-                               ret = test_cipher_cycles(&desc, enc, p, *b_size);
+                               ret = test_cipher_cycles(&desc, enc, sg,
+                                                        *b_size);
 
                        if (ret) {
                                printk("%s() failed flags=%x\n", e, desc.flags);
@@ -886,19 +228,16 @@ out:
        crypto_free_blkcipher(tfm);
 }
 
-static int test_hash_jiffies_digest(struct hash_desc *desc, char *p, int blen,
+static int test_hash_jiffies_digest(struct hash_desc *desc,
+                                   struct scatterlist *sg, int blen,
                                    char *out, int sec)
 {
-       struct scatterlist sg[1];
        unsigned long start, end;
        int bcount;
        int ret;
 
-       sg_init_table(sg, 1);
-
        for (start = jiffies, end = start + sec * HZ, bcount = 0;
             time_before(jiffies, end); bcount++) {
-               sg_set_buf(sg, p, blen);
                ret = crypto_hash_digest(desc, sg, blen, out);
                if (ret)
                        return ret;
@@ -910,18 +249,15 @@ static int test_hash_jiffies_digest(struct hash_desc *desc, char *p, int blen,
        return 0;
 }
 
-static int test_hash_jiffies(struct hash_desc *desc, char *p, int blen,
-                            int plen, char *out, int sec)
+static int test_hash_jiffies(struct hash_desc *desc, struct scatterlist *sg,
+                            int blen, int plen, char *out, int sec)
 {
-       struct scatterlist sg[1];
        unsigned long start, end;
        int bcount, pcount;
        int ret;
 
        if (plen == blen)
-               return test_hash_jiffies_digest(desc, p, blen, out, sec);
-
-       sg_init_table(sg, 1);
+               return test_hash_jiffies_digest(desc, sg, blen, out, sec);
 
        for (start = jiffies, end = start + sec * HZ, bcount = 0;
             time_before(jiffies, end); bcount++) {
@@ -929,7 +265,6 @@ static int test_hash_jiffies(struct hash_desc *desc, char *p, int blen,
                if (ret)
                        return ret;
                for (pcount = 0; pcount < blen; pcount += plen) {
-                       sg_set_buf(sg, p + pcount, plen);
                        ret = crypto_hash_update(desc, sg, plen);
                        if (ret)
                                return ret;
@@ -946,22 +281,18 @@ static int test_hash_jiffies(struct hash_desc *desc, char *p, int blen,
        return 0;
 }
 
-static int test_hash_cycles_digest(struct hash_desc *desc, char *p, int blen,
-                                  char *out)
+static int test_hash_cycles_digest(struct hash_desc *desc,
+                                  struct scatterlist *sg, int blen, char *out)
 {
-       struct scatterlist sg[1];
        unsigned long cycles = 0;
        int i;
        int ret;
 
-       sg_init_table(sg, 1);
-
        local_bh_disable();
        local_irq_disable();
 
        /* Warm-up run. */
        for (i = 0; i < 4; i++) {
-               sg_set_buf(sg, p, blen);
                ret = crypto_hash_digest(desc, sg, blen, out);
                if (ret)
                        goto out;
@@ -973,7 +304,6 @@ static int test_hash_cycles_digest(struct hash_desc *desc, char *p, int blen,
 
                start = get_cycles();
 
-               sg_set_buf(sg, p, blen);
                ret = crypto_hash_digest(desc, sg, blen, out);
                if (ret)
                        goto out;
@@ -996,18 +326,15 @@ out:
        return 0;
 }
 
-static int test_hash_cycles(struct hash_desc *desc, char *p, int blen,
-                           int plen, char *out)
+static int test_hash_cycles(struct hash_desc *desc, struct scatterlist *sg,
+                           int blen, int plen, char *out)
 {
-       struct scatterlist sg[1];
        unsigned long cycles = 0;
        int i, pcount;
        int ret;
 
        if (plen == blen)
-               return test_hash_cycles_digest(desc, p, blen, out);
-
-       sg_init_table(sg, 1);
+               return test_hash_cycles_digest(desc, sg, blen, out);
 
        local_bh_disable();
        local_irq_disable();
@@ -1018,7 +345,6 @@ static int test_hash_cycles(struct hash_desc *desc, char *p, int blen,
                if (ret)
                        goto out;
                for (pcount = 0; pcount < blen; pcount += plen) {
-                       sg_set_buf(sg, p + pcount, plen);
                        ret = crypto_hash_update(desc, sg, plen);
                        if (ret)
                                goto out;
@@ -1038,7 +364,6 @@ static int test_hash_cycles(struct hash_desc *desc, char *p, int blen,
                if (ret)
                        goto out;
                for (pcount = 0; pcount < blen; pcount += plen) {
-                       sg_set_buf(sg, p + pcount, plen);
                        ret = crypto_hash_update(desc, sg, plen);
                        if (ret)
                                goto out;
@@ -1065,9 +390,10 @@ out:
        return 0;
 }
 
-static void test_hash_speed(char *algo, unsigned int sec,
-                             struct hash_speed *speed)
+static void test_hash_speed(const char *algo, unsigned int sec,
+                           struct hash_speed *speed)
 {
+       struct scatterlist sg[TVMEMSIZE];
        struct crypto_hash *tfm;
        struct hash_desc desc;
        char output[1024];
@@ -1093,23 +419,27 @@ static void test_hash_speed(char *algo, unsigned int sec,
                goto out;
        }
 
+       sg_init_table(sg, TVMEMSIZE);
+       for (i = 0; i < TVMEMSIZE; i++) {
+               sg_set_buf(sg + i, tvmem[i], PAGE_SIZE);
+               memset(tvmem[i], 0xff, PAGE_SIZE);
+       }
+
        for (i = 0; speed[i].blen != 0; i++) {
-               if (speed[i].blen > TVMEMSIZE) {
-                       printk("template (%u) too big for tvmem (%u)\n",
-                              speed[i].blen, TVMEMSIZE);
+               if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) {
+                       printk("template (%u) too big for tvmem (%lu)\n",
+                              speed[i].blen, TVMEMSIZE * PAGE_SIZE);
                        goto out;
                }
 
                printk("test%3u (%5u byte blocks,%5u bytes per update,%4u updates): ",
                       i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
 
-               memset(tvmem, 0xff, speed[i].blen);
-
                if (sec)
-                       ret = test_hash_jiffies(&desc, tvmem, speed[i].blen,
+                       ret = test_hash_jiffies(&desc, sg, speed[i].blen,
                                                speed[i].plen, output, sec);
                else
-                       ret = test_hash_cycles(&desc, tvmem, speed[i].blen,
+                       ret = test_hash_cycles(&desc, sg, speed[i].blen,
                                               speed[i].plen, output);
 
                if (ret) {
@@ -1122,73 +452,6 @@ out:
        crypto_free_hash(tfm);
 }
 
-static void test_comp(char *algo, struct comp_testvec *ctemplate,
-                      struct comp_testvec *dtemplate, int ctcount, int dtcount)
-{
-       unsigned int i;
-       char result[COMP_BUF_SIZE];
-       struct crypto_comp *tfm;
-       unsigned int tsize;
-
-       printk("\ntesting %s compression\n", algo);
-
-       tfm = crypto_alloc_comp(algo, 0, CRYPTO_ALG_ASYNC);
-       if (IS_ERR(tfm)) {
-               printk("failed to load transform for %s\n", algo);
-               return;
-       }
-
-       for (i = 0; i < ctcount; i++) {
-               int ilen, ret, dlen = COMP_BUF_SIZE;
-
-               printk("test %u:\n", i + 1);
-               memset(result, 0, sizeof (result));
-
-               ilen = ctemplate[i].inlen;
-               ret = crypto_comp_compress(tfm, ctemplate[i].input,
-                                          ilen, result, &dlen);
-               if (ret) {
-                       printk("fail: ret=%d\n", ret);
-                       continue;
-               }
-               hexdump(result, dlen);
-               printk("%s (ratio %d:%d)\n",
-                      memcmp(result, ctemplate[i].output, dlen) ? "fail" : "pass",
-                      ilen, dlen);
-       }
-
-       printk("\ntesting %s decompression\n", algo);
-
-       tsize = sizeof(struct comp_testvec);
-       tsize *= dtcount;
-       if (tsize > TVMEMSIZE) {
-               printk("template (%u) too big for tvmem (%u)\n", tsize,
-                      TVMEMSIZE);
-               goto out;
-       }
-
-       for (i = 0; i < dtcount; i++) {
-               int ilen, ret, dlen = COMP_BUF_SIZE;
-
-               printk("test %u:\n", i + 1);
-               memset(result, 0, sizeof (result));
-
-               ilen = dtemplate[i].inlen;
-               ret = crypto_comp_decompress(tfm, dtemplate[i].input,
-                                            ilen, result, &dlen);
-               if (ret) {
-                       printk("fail: ret=%d\n", ret);
-                       continue;
-               }
-               hexdump(result, dlen);
-               printk("%s (ratio %d:%d)\n",
-                      memcmp(result, dtemplate[i].output, dlen) ? "fail" : "pass",
-                      ilen, dlen);
-       }
-out:
-       crypto_free_comp(tfm);
-}
-
 static void test_available(void)
 {
        char **name = check;
@@ -1201,549 +464,237 @@ static void test_available(void)
        }
 }
 
-static void do_test(void)
+static inline int tcrypt_test(const char *alg)
 {
-       switch (mode) {
+       return alg_test(alg, alg, 0, 0);
+}
+
+static void do_test(int m)
+{
+       int i;
 
+       switch (m) {
        case 0:
-               test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
-
-               test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
-
-               //DES
-               test_cipher("ecb(des)", ENCRYPT, des_enc_tv_template,
-                           DES_ENC_TEST_VECTORS);
-               test_cipher("ecb(des)", DECRYPT, des_dec_tv_template,
-                           DES_DEC_TEST_VECTORS);
-               test_cipher("cbc(des)", ENCRYPT, des_cbc_enc_tv_template,
-                           DES_CBC_ENC_TEST_VECTORS);
-               test_cipher("cbc(des)", DECRYPT, des_cbc_dec_tv_template,
-                           DES_CBC_DEC_TEST_VECTORS);
-
-               //DES3_EDE
-               test_cipher("ecb(des3_ede)", ENCRYPT, des3_ede_enc_tv_template,
-                           DES3_EDE_ENC_TEST_VECTORS);
-               test_cipher("ecb(des3_ede)", DECRYPT, des3_ede_dec_tv_template,
-                           DES3_EDE_DEC_TEST_VECTORS);
-
-               test_cipher("cbc(des3_ede)", ENCRYPT,
-                           des3_ede_cbc_enc_tv_template,
-                           DES3_EDE_CBC_ENC_TEST_VECTORS);
-
-               test_cipher("cbc(des3_ede)", DECRYPT,
-                           des3_ede_cbc_dec_tv_template,
-                           DES3_EDE_CBC_DEC_TEST_VECTORS);
-
-               test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
-
-               test_hash("sha224", sha224_tv_template, SHA224_TEST_VECTORS);
-
-               test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
-
-               //BLOWFISH
-               test_cipher("ecb(blowfish)", ENCRYPT, bf_enc_tv_template,
-                           BF_ENC_TEST_VECTORS);
-               test_cipher("ecb(blowfish)", DECRYPT, bf_dec_tv_template,
-                           BF_DEC_TEST_VECTORS);
-               test_cipher("cbc(blowfish)", ENCRYPT, bf_cbc_enc_tv_template,
-                           BF_CBC_ENC_TEST_VECTORS);
-               test_cipher("cbc(blowfish)", DECRYPT, bf_cbc_dec_tv_template,
-                           BF_CBC_DEC_TEST_VECTORS);
-
-               //TWOFISH
-               test_cipher("ecb(twofish)", ENCRYPT, tf_enc_tv_template,
-                           TF_ENC_TEST_VECTORS);
-               test_cipher("ecb(twofish)", DECRYPT, tf_dec_tv_template,
-                           TF_DEC_TEST_VECTORS);
-               test_cipher("cbc(twofish)", ENCRYPT, tf_cbc_enc_tv_template,
-                           TF_CBC_ENC_TEST_VECTORS);
-               test_cipher("cbc(twofish)", DECRYPT, tf_cbc_dec_tv_template,
-                           TF_CBC_DEC_TEST_VECTORS);
-
-               //SERPENT
-               test_cipher("ecb(serpent)", ENCRYPT, serpent_enc_tv_template,
-                           SERPENT_ENC_TEST_VECTORS);
-               test_cipher("ecb(serpent)", DECRYPT, serpent_dec_tv_template,
-                           SERPENT_DEC_TEST_VECTORS);
-
-               //TNEPRES
-               test_cipher("ecb(tnepres)", ENCRYPT, tnepres_enc_tv_template,
-                           TNEPRES_ENC_TEST_VECTORS);
-               test_cipher("ecb(tnepres)", DECRYPT, tnepres_dec_tv_template,
-                           TNEPRES_DEC_TEST_VECTORS);
-
-               //AES
-               test_cipher("ecb(aes)", ENCRYPT, aes_enc_tv_template,
-                           AES_ENC_TEST_VECTORS);
-               test_cipher("ecb(aes)", DECRYPT, aes_dec_tv_template,
-                           AES_DEC_TEST_VECTORS);
-               test_cipher("cbc(aes)", ENCRYPT, aes_cbc_enc_tv_template,
-                           AES_CBC_ENC_TEST_VECTORS);
-               test_cipher("cbc(aes)", DECRYPT, aes_cbc_dec_tv_template,
-                           AES_CBC_DEC_TEST_VECTORS);
-               test_cipher("lrw(aes)", ENCRYPT, aes_lrw_enc_tv_template,
-                           AES_LRW_ENC_TEST_VECTORS);
-               test_cipher("lrw(aes)", DECRYPT, aes_lrw_dec_tv_template,
-                           AES_LRW_DEC_TEST_VECTORS);
-               test_cipher("xts(aes)", ENCRYPT, aes_xts_enc_tv_template,
-                           AES_XTS_ENC_TEST_VECTORS);
-               test_cipher("xts(aes)", DECRYPT, aes_xts_dec_tv_template,
-                           AES_XTS_DEC_TEST_VECTORS);
-               test_cipher("rfc3686(ctr(aes))", ENCRYPT, aes_ctr_enc_tv_template,
-                           AES_CTR_ENC_TEST_VECTORS);
-               test_cipher("rfc3686(ctr(aes))", DECRYPT, aes_ctr_dec_tv_template,
-                           AES_CTR_DEC_TEST_VECTORS);
-               test_aead("gcm(aes)", ENCRYPT, aes_gcm_enc_tv_template,
-                         AES_GCM_ENC_TEST_VECTORS);
-               test_aead("gcm(aes)", DECRYPT, aes_gcm_dec_tv_template,
-                         AES_GCM_DEC_TEST_VECTORS);
-               test_aead("ccm(aes)", ENCRYPT, aes_ccm_enc_tv_template,
-                         AES_CCM_ENC_TEST_VECTORS);
-               test_aead("ccm(aes)", DECRYPT, aes_ccm_dec_tv_template,
-                         AES_CCM_DEC_TEST_VECTORS);
-
-               //CAST5
-               test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template,
-                           CAST5_ENC_TEST_VECTORS);
-               test_cipher("ecb(cast5)", DECRYPT, cast5_dec_tv_template,
-                           CAST5_DEC_TEST_VECTORS);
-
-               //CAST6
-               test_cipher("ecb(cast6)", ENCRYPT, cast6_enc_tv_template,
-                           CAST6_ENC_TEST_VECTORS);
-               test_cipher("ecb(cast6)", DECRYPT, cast6_dec_tv_template,
-                           CAST6_DEC_TEST_VECTORS);
-
-               //ARC4
-               test_cipher("ecb(arc4)", ENCRYPT, arc4_enc_tv_template,
-                           ARC4_ENC_TEST_VECTORS);
-               test_cipher("ecb(arc4)", DECRYPT, arc4_dec_tv_template,
-                           ARC4_DEC_TEST_VECTORS);
-
-               //TEA
-               test_cipher("ecb(tea)", ENCRYPT, tea_enc_tv_template,
-                           TEA_ENC_TEST_VECTORS);
-               test_cipher("ecb(tea)", DECRYPT, tea_dec_tv_template,
-                           TEA_DEC_TEST_VECTORS);
-
-
-               //XTEA
-               test_cipher("ecb(xtea)", ENCRYPT, xtea_enc_tv_template,
-                           XTEA_ENC_TEST_VECTORS);
-               test_cipher("ecb(xtea)", DECRYPT, xtea_dec_tv_template,
-                           XTEA_DEC_TEST_VECTORS);
-
-               //KHAZAD
-               test_cipher("ecb(khazad)", ENCRYPT, khazad_enc_tv_template,
-                           KHAZAD_ENC_TEST_VECTORS);
-               test_cipher("ecb(khazad)", DECRYPT, khazad_dec_tv_template,
-                           KHAZAD_DEC_TEST_VECTORS);
-
-               //ANUBIS
-               test_cipher("ecb(anubis)", ENCRYPT, anubis_enc_tv_template,
-                           ANUBIS_ENC_TEST_VECTORS);
-               test_cipher("ecb(anubis)", DECRYPT, anubis_dec_tv_template,
-                           ANUBIS_DEC_TEST_VECTORS);
-               test_cipher("cbc(anubis)", ENCRYPT, anubis_cbc_enc_tv_template,
-                           ANUBIS_CBC_ENC_TEST_VECTORS);
-               test_cipher("cbc(anubis)", DECRYPT, anubis_cbc_dec_tv_template,
-                           ANUBIS_CBC_ENC_TEST_VECTORS);
-
-               //XETA
-               test_cipher("ecb(xeta)", ENCRYPT, xeta_enc_tv_template,
-                           XETA_ENC_TEST_VECTORS);
-               test_cipher("ecb(xeta)", DECRYPT, xeta_dec_tv_template,
-                           XETA_DEC_TEST_VECTORS);
-
-               //FCrypt
-               test_cipher("pcbc(fcrypt)", ENCRYPT, fcrypt_pcbc_enc_tv_template,
-                           FCRYPT_ENC_TEST_VECTORS);
-               test_cipher("pcbc(fcrypt)", DECRYPT, fcrypt_pcbc_dec_tv_template,
-                           FCRYPT_DEC_TEST_VECTORS);
-
-               //CAMELLIA
-               test_cipher("ecb(camellia)", ENCRYPT,
-                           camellia_enc_tv_template,
-                           CAMELLIA_ENC_TEST_VECTORS);
-               test_cipher("ecb(camellia)", DECRYPT,
-                           camellia_dec_tv_template,
-                           CAMELLIA_DEC_TEST_VECTORS);
-               test_cipher("cbc(camellia)", ENCRYPT,
-                           camellia_cbc_enc_tv_template,
-                           CAMELLIA_CBC_ENC_TEST_VECTORS);
-               test_cipher("cbc(camellia)", DECRYPT,
-                           camellia_cbc_dec_tv_template,
-                           CAMELLIA_CBC_DEC_TEST_VECTORS);
-
-               //SEED
-               test_cipher("ecb(seed)", ENCRYPT, seed_enc_tv_template,
-                           SEED_ENC_TEST_VECTORS);
-               test_cipher("ecb(seed)", DECRYPT, seed_dec_tv_template,
-                           SEED_DEC_TEST_VECTORS);
-
-               //CTS
-               test_cipher("cts(cbc(aes))", ENCRYPT, cts_mode_enc_tv_template,
-                           CTS_MODE_ENC_TEST_VECTORS);
-               test_cipher("cts(cbc(aes))", DECRYPT, cts_mode_dec_tv_template,
-                           CTS_MODE_DEC_TEST_VECTORS);
-
-               test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
-               test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
-               test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
-               test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS);
-               test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS);
-               test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS);
-               test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS);
-               test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
-               test_comp("deflate", deflate_comp_tv_template,
-                         deflate_decomp_tv_template, DEFLATE_COMP_TEST_VECTORS,
-                         DEFLATE_DECOMP_TEST_VECTORS);
-               test_comp("lzo", lzo_comp_tv_template, lzo_decomp_tv_template,
-                         LZO_COMP_TEST_VECTORS, LZO_DECOMP_TEST_VECTORS);
-               test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS);
-               test_hash("hmac(md5)", hmac_md5_tv_template,
-                         HMAC_MD5_TEST_VECTORS);
-               test_hash("hmac(sha1)", hmac_sha1_tv_template,
-                         HMAC_SHA1_TEST_VECTORS);
-               test_hash("hmac(sha224)", hmac_sha224_tv_template,
-                         HMAC_SHA224_TEST_VECTORS);
-               test_hash("hmac(sha256)", hmac_sha256_tv_template,
-                         HMAC_SHA256_TEST_VECTORS);
-               test_hash("hmac(sha384)", hmac_sha384_tv_template,
-                         HMAC_SHA384_TEST_VECTORS);
-               test_hash("hmac(sha512)", hmac_sha512_tv_template,
-                         HMAC_SHA512_TEST_VECTORS);
-
-               test_hash("xcbc(aes)", aes_xcbc128_tv_template,
-                         XCBC_AES_TEST_VECTORS);
-
-               test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
+               for (i = 1; i < 200; i++)
+                       do_test(i);
                break;
 
        case 1:
-               test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
+               tcrypt_test("md5");
                break;
 
        case 2:
-               test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
+               tcrypt_test("sha1");
                break;
 
        case 3:
-               test_cipher("ecb(des)", ENCRYPT, des_enc_tv_template,
-                           DES_ENC_TEST_VECTORS);
-               test_cipher("ecb(des)", DECRYPT, des_dec_tv_template,
-                           DES_DEC_TEST_VECTORS);
-               test_cipher("cbc(des)", ENCRYPT, des_cbc_enc_tv_template,
-                           DES_CBC_ENC_TEST_VECTORS);
-               test_cipher("cbc(des)", DECRYPT, des_cbc_dec_tv_template,
-                           DES_CBC_DEC_TEST_VECTORS);
+               tcrypt_test("ecb(des)");
+               tcrypt_test("cbc(des)");
                break;
 
        case 4:
-               test_cipher("ecb(des3_ede)", ENCRYPT, des3_ede_enc_tv_template,
-                           DES3_EDE_ENC_TEST_VECTORS);
-               test_cipher("ecb(des3_ede)", DECRYPT, des3_ede_dec_tv_template,
-                           DES3_EDE_DEC_TEST_VECTORS);
-
-               test_cipher("cbc(des3_ede)", ENCRYPT,
-                           des3_ede_cbc_enc_tv_template,
-                           DES3_EDE_CBC_ENC_TEST_VECTORS);
-
-               test_cipher("cbc(des3_ede)", DECRYPT,
-                           des3_ede_cbc_dec_tv_template,
-                           DES3_EDE_CBC_DEC_TEST_VECTORS);
+               tcrypt_test("ecb(des3_ede)");
+               tcrypt_test("cbc(des3_ede)");
                break;
 
        case 5:
-               test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
+               tcrypt_test("md4");
                break;
 
        case 6:
-               test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
+               tcrypt_test("sha256");
                break;
 
        case 7:
-               test_cipher("ecb(blowfish)", ENCRYPT, bf_enc_tv_template,
-                           BF_ENC_TEST_VECTORS);
-               test_cipher("ecb(blowfish)", DECRYPT, bf_dec_tv_template,
-                           BF_DEC_TEST_VECTORS);
-               test_cipher("cbc(blowfish)", ENCRYPT, bf_cbc_enc_tv_template,
-                           BF_CBC_ENC_TEST_VECTORS);
-               test_cipher("cbc(blowfish)", DECRYPT, bf_cbc_dec_tv_template,
-                           BF_CBC_DEC_TEST_VECTORS);
+               tcrypt_test("ecb(blowfish)");
+               tcrypt_test("cbc(blowfish)");
                break;
 
        case 8:
-               test_cipher("ecb(twofish)", ENCRYPT, tf_enc_tv_template,
-                           TF_ENC_TEST_VECTORS);
-               test_cipher("ecb(twofish)", DECRYPT, tf_dec_tv_template,
-                           TF_DEC_TEST_VECTORS);
-               test_cipher("cbc(twofish)", ENCRYPT, tf_cbc_enc_tv_template,
-                           TF_CBC_ENC_TEST_VECTORS);
-               test_cipher("cbc(twofish)", DECRYPT, tf_cbc_dec_tv_template,
-                           TF_CBC_DEC_TEST_VECTORS);
+               tcrypt_test("ecb(twofish)");
+               tcrypt_test("cbc(twofish)");
                break;
 
        case 9:
-               test_cipher("ecb(serpent)", ENCRYPT, serpent_enc_tv_template,
-                           SERPENT_ENC_TEST_VECTORS);
-               test_cipher("ecb(serpent)", DECRYPT, serpent_dec_tv_template,
-                           SERPENT_DEC_TEST_VECTORS);
+               tcrypt_test("ecb(serpent)");
                break;
 
        case 10:
-               test_cipher("ecb(aes)", ENCRYPT, aes_enc_tv_template,
-                           AES_ENC_TEST_VECTORS);
-               test_cipher("ecb(aes)", DECRYPT, aes_dec_tv_template,
-                           AES_DEC_TEST_VECTORS);
-               test_cipher("cbc(aes)", ENCRYPT, aes_cbc_enc_tv_template,
-                           AES_CBC_ENC_TEST_VECTORS);
-               test_cipher("cbc(aes)", DECRYPT, aes_cbc_dec_tv_template,
-                           AES_CBC_DEC_TEST_VECTORS);
-               test_cipher("lrw(aes)", ENCRYPT, aes_lrw_enc_tv_template,
-                           AES_LRW_ENC_TEST_VECTORS);
-               test_cipher("lrw(aes)", DECRYPT, aes_lrw_dec_tv_template,
-                           AES_LRW_DEC_TEST_VECTORS);
-               test_cipher("xts(aes)", ENCRYPT, aes_xts_enc_tv_template,
-                           AES_XTS_ENC_TEST_VECTORS);
-               test_cipher("xts(aes)", DECRYPT, aes_xts_dec_tv_template,
-                           AES_XTS_DEC_TEST_VECTORS);
-               test_cipher("rfc3686(ctr(aes))", ENCRYPT, aes_ctr_enc_tv_template,
-                           AES_CTR_ENC_TEST_VECTORS);
-               test_cipher("rfc3686(ctr(aes))", DECRYPT, aes_ctr_dec_tv_template,
-                           AES_CTR_DEC_TEST_VECTORS);
+               tcrypt_test("ecb(aes)");
+               tcrypt_test("cbc(aes)");
+               tcrypt_test("lrw(aes)");
+               tcrypt_test("xts(aes)");
+               tcrypt_test("rfc3686(ctr(aes))");
                break;
 
        case 11:
-               test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
+               tcrypt_test("sha384");
                break;
 
        case 12:
-               test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
+               tcrypt_test("sha512");
                break;
 
        case 13:
-               test_comp("deflate", deflate_comp_tv_template,
-                         deflate_decomp_tv_template, DEFLATE_COMP_TEST_VECTORS,
-                         DEFLATE_DECOMP_TEST_VECTORS);
+               tcrypt_test("deflate");
                break;
 
        case 14:
-               test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template,
-                           CAST5_ENC_TEST_VECTORS);
-               test_cipher("ecb(cast5)", DECRYPT, cast5_dec_tv_template,
-                           CAST5_DEC_TEST_VECTORS);
+               tcrypt_test("ecb(cast5)");
                break;
 
        case 15:
-               test_cipher("ecb(cast6)", ENCRYPT, cast6_enc_tv_template,
-                           CAST6_ENC_TEST_VECTORS);
-               test_cipher("ecb(cast6)", DECRYPT, cast6_dec_tv_template,
-                           CAST6_DEC_TEST_VECTORS);
+               tcrypt_test("ecb(cast6)");
                break;
 
        case 16:
-               test_cipher("ecb(arc4)", ENCRYPT, arc4_enc_tv_template,
-                           ARC4_ENC_TEST_VECTORS);
-               test_cipher("ecb(arc4)", DECRYPT, arc4_dec_tv_template,
-                           ARC4_DEC_TEST_VECTORS);
+               tcrypt_test("ecb(arc4)");
                break;
 
        case 17:
-               test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
+               tcrypt_test("michael_mic");
                break;
 
        case 18:
-               test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS);
+               tcrypt_test("crc32c");
                break;
 
        case 19:
-               test_cipher("ecb(tea)", ENCRYPT, tea_enc_tv_template,
-                           TEA_ENC_TEST_VECTORS);
-               test_cipher("ecb(tea)", DECRYPT, tea_dec_tv_template,
-                           TEA_DEC_TEST_VECTORS);
+               tcrypt_test("ecb(tea)");
                break;
 
        case 20:
-               test_cipher("ecb(xtea)", ENCRYPT, xtea_enc_tv_template,
-                           XTEA_ENC_TEST_VECTORS);
-               test_cipher("ecb(xtea)", DECRYPT, xtea_dec_tv_template,
-                           XTEA_DEC_TEST_VECTORS);
+               tcrypt_test("ecb(xtea)");
                break;
 
        case 21:
-               test_cipher("ecb(khazad)", ENCRYPT, khazad_enc_tv_template,
-                           KHAZAD_ENC_TEST_VECTORS);
-               test_cipher("ecb(khazad)", DECRYPT, khazad_dec_tv_template,
-                           KHAZAD_DEC_TEST_VECTORS);
+               tcrypt_test("ecb(khazad)");
                break;
 
        case 22:
-               test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
+               tcrypt_test("wp512");
                break;
 
        case 23:
-               test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS);
+               tcrypt_test("wp384");
                break;
 
        case 24:
-               test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS);
+               tcrypt_test("wp256");
                break;
 
        case 25:
-               test_cipher("ecb(tnepres)", ENCRYPT, tnepres_enc_tv_template,
-                           TNEPRES_ENC_TEST_VECTORS);
-               test_cipher("ecb(tnepres)", DECRYPT, tnepres_dec_tv_template,
-                           TNEPRES_DEC_TEST_VECTORS);
+               tcrypt_test("ecb(tnepres)");
                break;
 
        case 26:
-               test_cipher("ecb(anubis)", ENCRYPT, anubis_enc_tv_template,
-                           ANUBIS_ENC_TEST_VECTORS);
-               test_cipher("ecb(anubis)", DECRYPT, anubis_dec_tv_template,
-                           ANUBIS_DEC_TEST_VECTORS);
-               test_cipher("cbc(anubis)", ENCRYPT, anubis_cbc_enc_tv_template,
-                           ANUBIS_CBC_ENC_TEST_VECTORS);
-               test_cipher("cbc(anubis)", DECRYPT, anubis_cbc_dec_tv_template,
-                           ANUBIS_CBC_ENC_TEST_VECTORS);
+               tcrypt_test("ecb(anubis)");
+               tcrypt_test("cbc(anubis)");
                break;
 
        case 27:
-               test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS);
+               tcrypt_test("tgr192");
                break;
 
        case 28:
 
-               test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS);
+               tcrypt_test("tgr160");
                break;
 
        case 29:
-               test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
+               tcrypt_test("tgr128");
                break;
 
        case 30:
-               test_cipher("ecb(xeta)", ENCRYPT, xeta_enc_tv_template,
-                           XETA_ENC_TEST_VECTORS);
-               test_cipher("ecb(xeta)", DECRYPT, xeta_dec_tv_template,
-                           XETA_DEC_TEST_VECTORS);
+               tcrypt_test("ecb(xeta)");
                break;
 
        case 31:
-               test_cipher("pcbc(fcrypt)", ENCRYPT, fcrypt_pcbc_enc_tv_template,
-                           FCRYPT_ENC_TEST_VECTORS);
-               test_cipher("pcbc(fcrypt)", DECRYPT, fcrypt_pcbc_dec_tv_template,
-                           FCRYPT_DEC_TEST_VECTORS);
+               tcrypt_test("pcbc(fcrypt)");
                break;
 
        case 32:
-               test_cipher("ecb(camellia)", ENCRYPT,
-                           camellia_enc_tv_template,
-                           CAMELLIA_ENC_TEST_VECTORS);
-               test_cipher("ecb(camellia)", DECRYPT,
-                           camellia_dec_tv_template,
-                           CAMELLIA_DEC_TEST_VECTORS);
-               test_cipher("cbc(camellia)", ENCRYPT,
-                           camellia_cbc_enc_tv_template,
-                           CAMELLIA_CBC_ENC_TEST_VECTORS);
-               test_cipher("cbc(camellia)", DECRYPT,
-                           camellia_cbc_dec_tv_template,
-                           CAMELLIA_CBC_DEC_TEST_VECTORS);
+               tcrypt_test("ecb(camellia)");
+               tcrypt_test("cbc(camellia)");
                break;
        case 33:
-               test_hash("sha224", sha224_tv_template, SHA224_TEST_VECTORS);
+               tcrypt_test("sha224");
                break;
 
        case 34:
-               test_cipher("salsa20", ENCRYPT,
-                           salsa20_stream_enc_tv_template,
-                           SALSA20_STREAM_ENC_TEST_VECTORS);
+               tcrypt_test("salsa20");
                break;
 
        case 35:
-               test_aead("gcm(aes)", ENCRYPT, aes_gcm_enc_tv_template,
-                         AES_GCM_ENC_TEST_VECTORS);
-               test_aead("gcm(aes)", DECRYPT, aes_gcm_dec_tv_template,
-                         AES_GCM_DEC_TEST_VECTORS);
+               tcrypt_test("gcm(aes)");
                break;
 
        case 36:
-               test_comp("lzo", lzo_comp_tv_template, lzo_decomp_tv_template,
-                         LZO_COMP_TEST_VECTORS, LZO_DECOMP_TEST_VECTORS);
+               tcrypt_test("lzo");
                break;
 
        case 37:
-               test_aead("ccm(aes)", ENCRYPT, aes_ccm_enc_tv_template,
-                         AES_CCM_ENC_TEST_VECTORS);
-               test_aead("ccm(aes)", DECRYPT, aes_ccm_dec_tv_template,
-                         AES_CCM_DEC_TEST_VECTORS);
+               tcrypt_test("ccm(aes)");
                break;
 
        case 38:
-               test_cipher("cts(cbc(aes))", ENCRYPT, cts_mode_enc_tv_template,
-                           CTS_MODE_ENC_TEST_VECTORS);
-               test_cipher("cts(cbc(aes))", DECRYPT, cts_mode_dec_tv_template,
-                           CTS_MODE_DEC_TEST_VECTORS);
+               tcrypt_test("cts(cbc(aes))");
                break;
 
         case 39:
-               test_hash("rmd128", rmd128_tv_template, RMD128_TEST_VECTORS);
+               tcrypt_test("rmd128");
                break;
 
         case 40:
-               test_hash("rmd160", rmd160_tv_template, RMD160_TEST_VECTORS);
+               tcrypt_test("rmd160");
                break;
 
        case 41:
-               test_hash("rmd256", rmd256_tv_template, RMD256_TEST_VECTORS);
+               tcrypt_test("rmd256");
                break;
 
        case 42:
-               test_hash("rmd320", rmd320_tv_template, RMD320_TEST_VECTORS);
+               tcrypt_test("rmd320");
+               break;
+
+       case 43:
+               tcrypt_test("ecb(seed)");
                break;
 
        case 100:
-               test_hash("hmac(md5)", hmac_md5_tv_template,
-                         HMAC_MD5_TEST_VECTORS);
+               tcrypt_test("hmac(md5)");
                break;
 
        case 101:
-               test_hash("hmac(sha1)", hmac_sha1_tv_template,
-                         HMAC_SHA1_TEST_VECTORS);
+               tcrypt_test("hmac(sha1)");
                break;
 
        case 102:
-               test_hash("hmac(sha256)", hmac_sha256_tv_template,
-                         HMAC_SHA256_TEST_VECTORS);
+               tcrypt_test("hmac(sha256)");
                break;
 
        case 103:
-               test_hash("hmac(sha384)", hmac_sha384_tv_template,
-                         HMAC_SHA384_TEST_VECTORS);
+               tcrypt_test("hmac(sha384)");
                break;
 
        case 104:
-               test_hash("hmac(sha512)", hmac_sha512_tv_template,
-                         HMAC_SHA512_TEST_VECTORS);
+               tcrypt_test("hmac(sha512)");
                break;
 
        case 105:
-               test_hash("hmac(sha224)", hmac_sha224_tv_template,
-                         HMAC_SHA224_TEST_VECTORS);
+               tcrypt_test("hmac(sha224)");
                break;
 
        case 106:
-               test_hash("xcbc(aes)", aes_xcbc128_tv_template,
-                         XCBC_AES_TEST_VECTORS);
+               tcrypt_test("xcbc(aes)");
                break;
 
        case 107:
-               test_hash("hmac(rmd128)", hmac_rmd128_tv_template,
-                         HMAC_RMD128_TEST_VECTORS);
+               tcrypt_test("hmac(rmd128)");
                break;
 
        case 108:
-               test_hash("hmac(rmd160)", hmac_rmd160_tv_template,
-                         HMAC_RMD160_TEST_VECTORS);
+               tcrypt_test("hmac(rmd160)");
                break;
 
        case 200:
@@ -1767,16 +718,16 @@ static void do_test(void)
 
        case 201:
                test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
-                               des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS,
+                               des3_speed_template, DES3_SPEED_VECTORS,
                                speed_template_24);
                test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
-                               des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS,
+                               des3_speed_template, DES3_SPEED_VECTORS,
                                speed_template_24);
                test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
-                               des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS,
+                               des3_speed_template, DES3_SPEED_VECTORS,
                                speed_template_24);
                test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
-                               des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS,
+                               des3_speed_template, DES3_SPEED_VECTORS,
                                speed_template_24);
                break;
 
@@ -1906,31 +857,21 @@ static void do_test(void)
        case 1000:
                test_available();
                break;
-
-       default:
-               /* useful for debugging */
-               printk("not testing anything\n");
-               break;
        }
 }
 
 static int __init tcrypt_mod_init(void)
 {
        int err = -ENOMEM;
+       int i;
 
-       tvmem = kmalloc(TVMEMSIZE, GFP_KERNEL);
-       if (tvmem == NULL)
-               return err;
-
-       xbuf = kmalloc(XBUFSIZE, GFP_KERNEL);
-       if (xbuf == NULL)
-               goto err_free_tv;
-
-       axbuf = kmalloc(XBUFSIZE, GFP_KERNEL);
-       if (axbuf == NULL)
-               goto err_free_xbuf;
+       for (i = 0; i < TVMEMSIZE; i++) {
+               tvmem[i] = (void *)__get_free_page(GFP_KERNEL);
+               if (!tvmem[i])
+                       goto err_free_tv;
+       }
 
-       do_test();
+       do_test(mode);
 
        /* We intentionaly return -EAGAIN to prevent keeping
         * the module. It does all its work from init()
@@ -1940,11 +881,9 @@ static int __init tcrypt_mod_init(void)
         */
        err = -EAGAIN;
 
-       kfree(axbuf);
- err_free_xbuf:
-       kfree(xbuf);
- err_free_tv:
-       kfree(tvmem);
+err_free_tv:
+       for (i = 0; i < TVMEMSIZE && tvmem[i]; i++)
+               free_page((unsigned long)tvmem[i]);
 
        return err;
 }
index 801e0c288862cb3fa2072416b684d959acf0424a..966bbfaf95b15346e00f25f1394ceda3ec96f5d6 100644 (file)
 #ifndef _CRYPTO_TCRYPT_H
 #define _CRYPTO_TCRYPT_H
 
-#define MAX_DIGEST_SIZE                64
-#define MAX_TAP                        8
-
-#define MAX_KEYLEN             56
-#define MAX_IVLEN              32
-
-struct hash_testvec {
-       /* only used with keyed hash algorithms */
-       char *key;
-       char *plaintext;
-       char *digest;
-       unsigned char tap[MAX_TAP];
-       unsigned char psize;
-       unsigned char np;
-       unsigned char ksize;
-};
-
-struct cipher_testvec {
-       char *key;
-       char *iv;
-       char *input;
-       char *result;
-       unsigned char tap[MAX_TAP];
-       int np;
-       unsigned char fail;
-       unsigned char wk; /* weak key flag */
-       unsigned char klen;
-       unsigned short ilen;
-       unsigned short rlen;
-};
-
-struct aead_testvec {
-       char *key;
-       char *iv;
-       char *input;
-       char *assoc;
-       char *result;
-       unsigned char tap[MAX_TAP];
-       unsigned char atap[MAX_TAP];
-       int np;
-       int anp;
-       unsigned char fail;
-       unsigned char wk; /* weak key flag */
-       unsigned char klen;
-       unsigned short ilen;
-       unsigned short alen;
-       unsigned short rlen;
+struct cipher_speed_template {
+       const char *key;
+       unsigned int klen;
 };
 
 struct hash_speed {
@@ -71,8673 +27,20 @@ struct hash_speed {
        unsigned int plen;      /* per-update length */
 };
 
-static char zeroed_string[48];
-
-/*
- * MD4 test vectors from RFC1320
- */
-#define MD4_TEST_VECTORS       7
-
-static struct hash_testvec md4_tv_template [] = {
-       {
-               .plaintext = "",
-               .digest = "\x31\xd6\xcf\xe0\xd1\x6a\xe9\x31"
-                         "\xb7\x3c\x59\xd7\xe0\xc0\x89\xc0",
-       }, {
-               .plaintext = "a",
-               .psize  = 1,
-               .digest = "\xbd\xe5\x2c\xb3\x1d\xe3\x3e\x46"
-                         "\x24\x5e\x05\xfb\xdb\xd6\xfb\x24",
-       }, {
-               .plaintext = "abc",
-               .psize  = 3,
-               .digest = "\xa4\x48\x01\x7a\xaf\x21\xd8\x52"
-                         "\x5f\xc1\x0a\xe8\x7a\xa6\x72\x9d",
-       }, {
-               .plaintext = "message digest",
-               .psize  = 14,
-               .digest = "\xd9\x13\x0a\x81\x64\x54\x9f\xe8"
-                       "\x18\x87\x48\x06\xe1\xc7\x01\x4b",
-       }, {
-               .plaintext = "abcdefghijklmnopqrstuvwxyz",
-               .psize  = 26,
-               .digest = "\xd7\x9e\x1c\x30\x8a\xa5\xbb\xcd"
-                         "\xee\xa8\xed\x63\xdf\x41\x2d\xa9",
-               .np     = 2,
-               .tap    = { 13, 13 },
-       }, {
-               .plaintext = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
-               .psize  = 62,
-               .digest = "\x04\x3f\x85\x82\xf2\x41\xdb\x35"
-                         "\x1c\xe6\x27\xe1\x53\xe7\xf0\xe4",
-       }, {
-               .plaintext = "123456789012345678901234567890123456789012345678901234567890123"
-                          "45678901234567890",
-               .psize  = 80,
-               .digest = "\xe3\x3b\x4d\xdc\x9c\x38\xf2\x19"
-                         "\x9c\x3e\x7b\x16\x4f\xcc\x05\x36",
-       },
-};
-
-/*
- * MD5 test vectors from RFC1321
- */
-#define MD5_TEST_VECTORS       7
-
-static struct hash_testvec md5_tv_template[] = {
-       {
-               .digest = "\xd4\x1d\x8c\xd9\x8f\x00\xb2\x04"
-                         "\xe9\x80\x09\x98\xec\xf8\x42\x7e",
-       }, {
-               .plaintext = "a",
-               .psize  = 1,
-               .digest = "\x0c\xc1\x75\xb9\xc0\xf1\xb6\xa8"
-                         "\x31\xc3\x99\xe2\x69\x77\x26\x61",
-       }, {
-               .plaintext = "abc",
-               .psize  = 3,
-               .digest = "\x90\x01\x50\x98\x3c\xd2\x4f\xb0"
-                         "\xd6\x96\x3f\x7d\x28\xe1\x7f\x72",
-       }, {
-               .plaintext = "message digest",
-               .psize  = 14,
-               .digest = "\xf9\x6b\x69\x7d\x7c\xb7\x93\x8d"
-                         "\x52\x5a\x2f\x31\xaa\xf1\x61\xd0",
-       }, {
-               .plaintext = "abcdefghijklmnopqrstuvwxyz",
-               .psize  = 26,
-               .digest = "\xc3\xfc\xd3\xd7\x61\x92\xe4\x00"
-                         "\x7d\xfb\x49\x6c\xca\x67\xe1\x3b",
-               .np     = 2,
-               .tap    = {13, 13}
-       }, {
-               .plaintext = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
-               .psize  = 62,
-               .digest = "\xd1\x74\xab\x98\xd2\x77\xd9\xf5"
-                         "\xa5\x61\x1c\x2c\x9f\x41\x9d\x9f",
-       }, {
-               .plaintext = "12345678901234567890123456789012345678901234567890123456789012"
-                          "345678901234567890",
-               .psize  = 80,
-               .digest = "\x57\xed\xf4\xa2\x2b\xe3\xc9\x55"
-                         "\xac\x49\xda\x2e\x21\x07\xb6\x7a",
-       }
-
-};
-
-/*
- * RIPEMD-128 test vectors from ISO/IEC 10118-3:2004(E)
- */
-#define RMD128_TEST_VECTORS     10
-
-static struct hash_testvec rmd128_tv_template[] = {
-       {
-               .digest = "\xcd\xf2\x62\x13\xa1\x50\xdc\x3e"
-                         "\xcb\x61\x0f\x18\xf6\xb3\x8b\x46",
-       }, {
-               .plaintext = "a",
-               .psize  = 1,
-               .digest = "\x86\xbe\x7a\xfa\x33\x9d\x0f\xc7"
-                         "\xcf\xc7\x85\xe7\x2f\x57\x8d\x33",
-       }, {
-               .plaintext = "abc",
-               .psize  = 3,
-               .digest = "\xc1\x4a\x12\x19\x9c\x66\xe4\xba"
-                         "\x84\x63\x6b\x0f\x69\x14\x4c\x77",
-       }, {
-               .plaintext = "message digest",
-               .psize  = 14,
-               .digest = "\x9e\x32\x7b\x3d\x6e\x52\x30\x62"
-                         "\xaf\xc1\x13\x2d\x7d\xf9\xd1\xb8",
-       }, {
-               .plaintext = "abcdefghijklmnopqrstuvwxyz",
-               .psize  = 26,
-               .digest = "\xfd\x2a\xa6\x07\xf7\x1d\xc8\xf5"
-                         "\x10\x71\x49\x22\xb3\x71\x83\x4e",
-       }, {
-               .plaintext = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcde"
-                            "fghijklmnopqrstuvwxyz0123456789",
-               .psize  = 62,
-               .digest = "\xd1\xe9\x59\xeb\x17\x9c\x91\x1f"
-                         "\xae\xa4\x62\x4c\x60\xc5\xc7\x02",
-       }, {
-               .plaintext = "1234567890123456789012345678901234567890"
-                            "1234567890123456789012345678901234567890",
-               .psize  = 80,
-               .digest = "\x3f\x45\xef\x19\x47\x32\xc2\xdb"
-                         "\xb2\xc4\xa2\xc7\x69\x79\x5f\xa3",
-        }, {
-               .plaintext = "abcdbcdecdefdefgefghfghighij"
-                            "hijkijkljklmklmnlmnomnopnopq",
-               .psize  = 56,
-               .digest = "\xa1\xaa\x06\x89\xd0\xfa\xfa\x2d"
-                         "\xdc\x22\xe8\x8b\x49\x13\x3a\x06",
-               .np     = 2,
-               .tap    = { 28, 28 },
-       }, {
-               .plaintext = "abcdefghbcdefghicdefghijdefghijkefghijklfghi"
-                            "jklmghijklmnhijklmnoijklmnopjklmnopqklmnopqr"
-                            "lmnopqrsmnopqrstnopqrstu",
-               .psize  = 112,
-               .digest = "\xd4\xec\xc9\x13\xe1\xdf\x77\x6b"
-                         "\xf4\x8d\xe9\xd5\x5b\x1f\x25\x46",
-       }, {
-               .plaintext = "abcdbcdecdefdefgefghfghighijhijk",
-               .psize  = 32,
-               .digest = "\x13\xfc\x13\xe8\xef\xff\x34\x7d"
-                         "\xe1\x93\xff\x46\xdb\xac\xcf\xd4",
-       }
-};
-
-/*
- * RIPEMD-160 test vectors from ISO/IEC 10118-3:2004(E)
- */
-#define RMD160_TEST_VECTORS     10
-
-static struct hash_testvec rmd160_tv_template[] = {
-       {
-               .digest = "\x9c\x11\x85\xa5\xc5\xe9\xfc\x54\x61\x28"
-                         "\x08\x97\x7e\xe8\xf5\x48\xb2\x25\x8d\x31",
-       }, {
-               .plaintext = "a",
-               .psize  = 1,
-               .digest = "\x0b\xdc\x9d\x2d\x25\x6b\x3e\xe9\xda\xae"
-                         "\x34\x7b\xe6\xf4\xdc\x83\x5a\x46\x7f\xfe",
-       }, {
-               .plaintext = "abc",
-               .psize  = 3,
-               .digest = "\x8e\xb2\x08\xf7\xe0\x5d\x98\x7a\x9b\x04"
-                         "\x4a\x8e\x98\xc6\xb0\x87\xf1\x5a\x0b\xfc",
-       }, {
-               .plaintext = "message digest",
-               .psize  = 14,
-               .digest = "\x5d\x06\x89\xef\x49\xd2\xfa\xe5\x72\xb8"
-                         "\x81\xb1\x23\xa8\x5f\xfa\x21\x59\x5f\x36",
-       }, {
-               .plaintext = "abcdefghijklmnopqrstuvwxyz",
-               .psize  = 26,
-               .digest = "\xf7\x1c\x27\x10\x9c\x69\x2c\x1b\x56\xbb"
-                         "\xdc\xeb\x5b\x9d\x28\x65\xb3\x70\x8d\xbc",
-       }, {
-               .plaintext = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcde"
-                            "fghijklmnopqrstuvwxyz0123456789",
-               .psize  = 62,
-               .digest = "\xb0\xe2\x0b\x6e\x31\x16\x64\x02\x86\xed"
-                         "\x3a\x87\xa5\x71\x30\x79\xb2\x1f\x51\x89",
-       }, {
-               .plaintext = "1234567890123456789012345678901234567890"
-                            "1234567890123456789012345678901234567890",
-               .psize  = 80,
-               .digest = "\x9b\x75\x2e\x45\x57\x3d\x4b\x39\xf4\xdb"
-                         "\xd3\x32\x3c\xab\x82\xbf\x63\x32\x6b\xfb",
-        }, {
-               .plaintext = "abcdbcdecdefdefgefghfghighij"
-                            "hijkijkljklmklmnlmnomnopnopq",
-               .psize  = 56,
-               .digest = "\x12\xa0\x53\x38\x4a\x9c\x0c\x88\xe4\x05"
-                         "\xa0\x6c\x27\xdc\xf4\x9a\xda\x62\xeb\x2b",
-               .np     = 2,
-               .tap    = { 28, 28 },
-       }, {
-               .plaintext = "abcdefghbcdefghicdefghijdefghijkefghijklfghi"
-                            "jklmghijklmnhijklmnoijklmnopjklmnopqklmnopqr"
-                            "lmnopqrsmnopqrstnopqrstu",
-               .psize  = 112,
-               .digest = "\x6f\x3f\xa3\x9b\x6b\x50\x3c\x38\x4f\x91"
-                         "\x9a\x49\xa7\xaa\x5c\x2c\x08\xbd\xfb\x45",
-       }, {
-               .plaintext = "abcdbcdecdefdefgefghfghighijhijk",
-               .psize  = 32,
-               .digest = "\x94\xc2\x64\x11\x54\x04\xe6\x33\x79\x0d"
-                         "\xfc\xc8\x7b\x58\x7d\x36\x77\x06\x7d\x9f",
-       }
-};
-
-/*
- * RIPEMD-256 test vectors
- */
-#define RMD256_TEST_VECTORS     8
-
-static struct hash_testvec rmd256_tv_template[] = {
-       {
-               .digest = "\x02\xba\x4c\x4e\x5f\x8e\xcd\x18"
-                         "\x77\xfc\x52\xd6\x4d\x30\xe3\x7a"
-                         "\x2d\x97\x74\xfb\x1e\x5d\x02\x63"
-                         "\x80\xae\x01\x68\xe3\xc5\x52\x2d",
-       }, {
-               .plaintext = "a",
-               .psize  = 1,
-               .digest = "\xf9\x33\x3e\x45\xd8\x57\xf5\xd9"
-                         "\x0a\x91\xba\xb7\x0a\x1e\xba\x0c"
-                         "\xfb\x1b\xe4\xb0\x78\x3c\x9a\xcf"
-                         "\xcd\x88\x3a\x91\x34\x69\x29\x25",
-       }, {
-               .plaintext = "abc",
-               .psize  = 3,
-               .digest = "\xaf\xbd\x6e\x22\x8b\x9d\x8c\xbb"
-                         "\xce\xf5\xca\x2d\x03\xe6\xdb\xa1"
-                         "\x0a\xc0\xbc\x7d\xcb\xe4\x68\x0e"
-                         "\x1e\x42\xd2\xe9\x75\x45\x9b\x65",
-       }, {
-               .plaintext = "message digest",
-               .psize  = 14,
-               .digest = "\x87\xe9\x71\x75\x9a\x1c\xe4\x7a"
-                         "\x51\x4d\x5c\x91\x4c\x39\x2c\x90"
-                         "\x18\xc7\xc4\x6b\xc1\x44\x65\x55"
-                         "\x4a\xfc\xdf\x54\xa5\x07\x0c\x0e",
-       }, {
-               .plaintext = "abcdefghijklmnopqrstuvwxyz",
-               .psize  = 26,
-               .digest = "\x64\x9d\x30\x34\x75\x1e\xa2\x16"
-                         "\x77\x6b\xf9\xa1\x8a\xcc\x81\xbc"
-                         "\x78\x96\x11\x8a\x51\x97\x96\x87"
-                         "\x82\xdd\x1f\xd9\x7d\x8d\x51\x33",
-       }, {
-               .plaintext = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcde"
-                            "fghijklmnopqrstuvwxyz0123456789",
-               .psize  = 62,
-               .digest = "\x57\x40\xa4\x08\xac\x16\xb7\x20"
-                         "\xb8\x44\x24\xae\x93\x1c\xbb\x1f"
-                         "\xe3\x63\xd1\xd0\xbf\x40\x17\xf1"
-                         "\xa8\x9f\x7e\xa6\xde\x77\xa0\xb8",
-       }, {
-               .plaintext = "1234567890123456789012345678901234567890"
-                            "1234567890123456789012345678901234567890",
-               .psize  = 80,
-               .digest = "\x06\xfd\xcc\x7a\x40\x95\x48\xaa"
-                         "\xf9\x13\x68\xc0\x6a\x62\x75\xb5"
-                         "\x53\xe3\xf0\x99\xbf\x0e\xa4\xed"
-                         "\xfd\x67\x78\xdf\x89\xa8\x90\xdd",
-        }, {
-               .plaintext = "abcdbcdecdefdefgefghfghighij"
-                            "hijkijkljklmklmnlmnomnopnopq",
-               .psize  = 56,
-               .digest = "\x38\x43\x04\x55\x83\xaa\xc6\xc8"
-                         "\xc8\xd9\x12\x85\x73\xe7\xa9\x80"
-                         "\x9a\xfb\x2a\x0f\x34\xcc\xc3\x6e"
-                         "\xa9\xe7\x2f\x16\xf6\x36\x8e\x3f",
-               .np     = 2,
-               .tap    = { 28, 28 },
-       }
-};
-
-/*
- * RIPEMD-320 test vectors
- */
-#define RMD320_TEST_VECTORS     8
-
-static struct hash_testvec rmd320_tv_template[] = {
-       {
-               .digest = "\x22\xd6\x5d\x56\x61\x53\x6c\xdc\x75\xc1"
-                         "\xfd\xf5\xc6\xde\x7b\x41\xb9\xf2\x73\x25"
-                         "\xeb\xc6\x1e\x85\x57\x17\x7d\x70\x5a\x0e"
-                         "\xc8\x80\x15\x1c\x3a\x32\xa0\x08\x99\xb8",
-       }, {
-               .plaintext = "a",
-               .psize  = 1,
-               .digest = "\xce\x78\x85\x06\x38\xf9\x26\x58\xa5\xa5"
-                         "\x85\x09\x75\x79\x92\x6d\xda\x66\x7a\x57"
-                         "\x16\x56\x2c\xfc\xf6\xfb\xe7\x7f\x63\x54"
-                         "\x2f\x99\xb0\x47\x05\xd6\x97\x0d\xff\x5d",
-       }, {
-               .plaintext = "abc",
-               .psize  = 3,
-               .digest = "\xde\x4c\x01\xb3\x05\x4f\x89\x30\xa7\x9d"
-                         "\x09\xae\x73\x8e\x92\x30\x1e\x5a\x17\x08"
-                         "\x5b\xef\xfd\xc1\xb8\xd1\x16\x71\x3e\x74"
-                         "\xf8\x2f\xa9\x42\xd6\x4c\xdb\xc4\x68\x2d",
-       }, {
-               .plaintext = "message digest",
-               .psize  = 14,
-               .digest = "\x3a\x8e\x28\x50\x2e\xd4\x5d\x42\x2f\x68"
-                         "\x84\x4f\x9d\xd3\x16\xe7\xb9\x85\x33\xfa"
-                         "\x3f\x2a\x91\xd2\x9f\x84\xd4\x25\xc8\x8d"
-                         "\x6b\x4e\xff\x72\x7d\xf6\x6a\x7c\x01\x97",
-       }, {
-               .plaintext = "abcdefghijklmnopqrstuvwxyz",
-               .psize  = 26,
-               .digest = "\xca\xbd\xb1\x81\x0b\x92\x47\x0a\x20\x93"
-                         "\xaa\x6b\xce\x05\x95\x2c\x28\x34\x8c\xf4"
-                         "\x3f\xf6\x08\x41\x97\x51\x66\xbb\x40\xed"
-                         "\x23\x40\x04\xb8\x82\x44\x63\xe6\xb0\x09",
-       }, {
-               .plaintext = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcde"
-                            "fghijklmnopqrstuvwxyz0123456789",
-               .psize  = 62,
-               .digest = "\xed\x54\x49\x40\xc8\x6d\x67\xf2\x50\xd2"
-                         "\x32\xc3\x0b\x7b\x3e\x57\x70\xe0\xc6\x0c"
-                         "\x8c\xb9\xa4\xca\xfe\x3b\x11\x38\x8a\xf9"
-                         "\x92\x0e\x1b\x99\x23\x0b\x84\x3c\x86\xa4",
-       }, {
-               .plaintext = "1234567890123456789012345678901234567890"
-                            "1234567890123456789012345678901234567890",
-               .psize  = 80,
-               .digest = "\x55\x78\x88\xaf\x5f\x6d\x8e\xd6\x2a\xb6"
-                         "\x69\x45\xc6\xd2\xa0\xa4\x7e\xcd\x53\x41"
-                         "\xe9\x15\xeb\x8f\xea\x1d\x05\x24\x95\x5f"
-                         "\x82\x5d\xc7\x17\xe4\xa0\x08\xab\x2d\x42",
-        }, {
-               .plaintext = "abcdbcdecdefdefgefghfghighij"
-                            "hijkijkljklmklmnlmnomnopnopq",
-               .psize  = 56,
-               .digest = "\xd0\x34\xa7\x95\x0c\xf7\x22\x02\x1b\xa4"
-                         "\xb8\x4d\xf7\x69\xa5\xde\x20\x60\xe2\x59"
-                         "\xdf\x4c\x9b\xb4\xa4\x26\x8c\x0e\x93\x5b"
-                         "\xbc\x74\x70\xa9\x69\xc9\xd0\x72\xa1\xac",
-               .np     = 2,
-               .tap    = { 28, 28 },
-       }
-};
-
-/*
- * SHA1 test vectors  from from FIPS PUB 180-1
- */
-#define SHA1_TEST_VECTORS      2
-
-static struct hash_testvec sha1_tv_template[] = {
-       {
-               .plaintext = "abc",
-               .psize  = 3,
-               .digest = "\xa9\x99\x3e\x36\x47\x06\x81\x6a\xba\x3e"
-                         "\x25\x71\x78\x50\xc2\x6c\x9c\xd0\xd8\x9d",
-       }, {
-               .plaintext = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
-               .psize  = 56,
-               .digest = "\x84\x98\x3e\x44\x1c\x3b\xd2\x6e\xba\xae"
-                         "\x4a\xa1\xf9\x51\x29\xe5\xe5\x46\x70\xf1",
-               .np     = 2,
-               .tap    = { 28, 28 }
-       }
-};
-
-
-/*
- * SHA224 test vectors from from FIPS PUB 180-2
- */
-#define SHA224_TEST_VECTORS     2
-
-static struct hash_testvec sha224_tv_template[] = {
-       {
-               .plaintext = "abc",
-               .psize  = 3,
-               .digest = "\x23\x09\x7D\x22\x34\x05\xD8\x22"
-                         "\x86\x42\xA4\x77\xBD\xA2\x55\xB3"
-                         "\x2A\xAD\xBC\xE4\xBD\xA0\xB3\xF7"
-                         "\xE3\x6C\x9D\xA7",
-       }, {
-               .plaintext =
-               "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
-               .psize  = 56,
-               .digest = "\x75\x38\x8B\x16\x51\x27\x76\xCC"
-                         "\x5D\xBA\x5D\xA1\xFD\x89\x01\x50"
-                         "\xB0\xC6\x45\x5C\xB4\xF5\x8B\x19"
-                         "\x52\x52\x25\x25",
-               .np     = 2,
-               .tap    = { 28, 28 }
-       }
-};
-
-/*
- * SHA256 test vectors from from NIST
- */
-#define SHA256_TEST_VECTORS    2
-
-static struct hash_testvec sha256_tv_template[] = {
-       {
-               .plaintext = "abc",
-               .psize  = 3,
-               .digest = "\xba\x78\x16\xbf\x8f\x01\xcf\xea"
-                         "\x41\x41\x40\xde\x5d\xae\x22\x23"
-                         "\xb0\x03\x61\xa3\x96\x17\x7a\x9c"
-                         "\xb4\x10\xff\x61\xf2\x00\x15\xad",
-       }, {
-               .plaintext = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
-               .psize  = 56,
-               .digest = "\x24\x8d\x6a\x61\xd2\x06\x38\xb8"
-                         "\xe5\xc0\x26\x93\x0c\x3e\x60\x39"
-                         "\xa3\x3c\xe4\x59\x64\xff\x21\x67"
-                         "\xf6\xec\xed\xd4\x19\xdb\x06\xc1",
-               .np     = 2,
-               .tap    = { 28, 28 }
-       },
-};
-
-/*
- * SHA384 test vectors from from NIST and kerneli
- */
-#define SHA384_TEST_VECTORS    4
-
-static struct hash_testvec sha384_tv_template[] = {
-       {
-               .plaintext= "abc",
-               .psize  = 3,
-               .digest = "\xcb\x00\x75\x3f\x45\xa3\x5e\x8b"
-                         "\xb5\xa0\x3d\x69\x9a\xc6\x50\x07"
-                         "\x27\x2c\x32\xab\x0e\xde\xd1\x63"
-                         "\x1a\x8b\x60\x5a\x43\xff\x5b\xed"
-                         "\x80\x86\x07\x2b\xa1\xe7\xcc\x23"
-                         "\x58\xba\xec\xa1\x34\xc8\x25\xa7",
-       }, {
-               .plaintext = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
-               .psize  = 56,
-               .digest = "\x33\x91\xfd\xdd\xfc\x8d\xc7\x39"
-                         "\x37\x07\xa6\x5b\x1b\x47\x09\x39"
-                         "\x7c\xf8\xb1\xd1\x62\xaf\x05\xab"
-                         "\xfe\x8f\x45\x0d\xe5\xf3\x6b\xc6"
-                         "\xb0\x45\x5a\x85\x20\xbc\x4e\x6f"
-                         "\x5f\xe9\x5b\x1f\xe3\xc8\x45\x2b",
-       }, {
-               .plaintext = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn"
-                          "hijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu",
-               .psize  = 112,
-               .digest = "\x09\x33\x0c\x33\xf7\x11\x47\xe8"
-                         "\x3d\x19\x2f\xc7\x82\xcd\x1b\x47"
-                         "\x53\x11\x1b\x17\x3b\x3b\x05\xd2"
-                         "\x2f\xa0\x80\x86\xe3\xb0\xf7\x12"
-                         "\xfc\xc7\xc7\x1a\x55\x7e\x2d\xb9"
-                         "\x66\xc3\xe9\xfa\x91\x74\x60\x39",
-       }, {
-               .plaintext = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcd"
-                          "efghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz",
-               .psize  = 104,
-               .digest = "\x3d\x20\x89\x73\xab\x35\x08\xdb"
-                         "\xbd\x7e\x2c\x28\x62\xba\x29\x0a"
-                         "\xd3\x01\x0e\x49\x78\xc1\x98\xdc"
-                         "\x4d\x8f\xd0\x14\xe5\x82\x82\x3a"
-                         "\x89\xe1\x6f\x9b\x2a\x7b\xbc\x1a"
-                         "\xc9\x38\xe2\xd1\x99\xe8\xbe\xa4",
-               .np     = 4,
-               .tap    = { 26, 26, 26, 26 }
-       },
-};
-
-/*
- * SHA512 test vectors from from NIST and kerneli
- */
-#define SHA512_TEST_VECTORS    4
-
-static struct hash_testvec sha512_tv_template[] = {
-       {
-               .plaintext = "abc",
-               .psize  = 3,
-               .digest = "\xdd\xaf\x35\xa1\x93\x61\x7a\xba"
-                         "\xcc\x41\x73\x49\xae\x20\x41\x31"
-                         "\x12\xe6\xfa\x4e\x89\xa9\x7e\xa2"
-                         "\x0a\x9e\xee\xe6\x4b\x55\xd3\x9a"
-                         "\x21\x92\x99\x2a\x27\x4f\xc1\xa8"
-                         "\x36\xba\x3c\x23\xa3\xfe\xeb\xbd"
-                         "\x45\x4d\x44\x23\x64\x3c\xe8\x0e"
-                         "\x2a\x9a\xc9\x4f\xa5\x4c\xa4\x9f",
-       }, {
-               .plaintext = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
-               .psize  = 56,
-               .digest = "\x20\x4a\x8f\xc6\xdd\xa8\x2f\x0a"
-                         "\x0c\xed\x7b\xeb\x8e\x08\xa4\x16"
-                         "\x57\xc1\x6e\xf4\x68\xb2\x28\xa8"
-                         "\x27\x9b\xe3\x31\xa7\x03\xc3\x35"
-                         "\x96\xfd\x15\xc1\x3b\x1b\x07\xf9"
-                         "\xaa\x1d\x3b\xea\x57\x78\x9c\xa0"
-                         "\x31\xad\x85\xc7\xa7\x1d\xd7\x03"
-                         "\x54\xec\x63\x12\x38\xca\x34\x45",
-       }, {
-               .plaintext = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn"
-                          "hijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu",
-               .psize  = 112,
-               .digest = "\x8e\x95\x9b\x75\xda\xe3\x13\xda"
-                         "\x8c\xf4\xf7\x28\x14\xfc\x14\x3f"
-                         "\x8f\x77\x79\xc6\xeb\x9f\x7f\xa1"
-                         "\x72\x99\xae\xad\xb6\x88\x90\x18"
-                         "\x50\x1d\x28\x9e\x49\x00\xf7\xe4"
-                         "\x33\x1b\x99\xde\xc4\xb5\x43\x3a"
-                         "\xc7\xd3\x29\xee\xb6\xdd\x26\x54"
-                         "\x5e\x96\xe5\x5b\x87\x4b\xe9\x09",
-       }, {
-               .plaintext = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcd"
-                          "efghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz",
-               .psize  = 104,
-               .digest = "\x93\x0d\x0c\xef\xcb\x30\xff\x11"
-                         "\x33\xb6\x89\x81\x21\xf1\xcf\x3d"
-                         "\x27\x57\x8a\xfc\xaf\xe8\x67\x7c"
-                         "\x52\x57\xcf\x06\x99\x11\xf7\x5d"
-                         "\x8f\x58\x31\xb5\x6e\xbf\xda\x67"
-                         "\xb2\x78\xe6\x6d\xff\x8b\x84\xfe"
-                         "\x2b\x28\x70\xf7\x42\xa5\x80\xd8"
-                         "\xed\xb4\x19\x87\x23\x28\x50\xc9",
-               .np     = 4,
-               .tap    = { 26, 26, 26, 26 }
-       },
-};
-
-
-/*
- * WHIRLPOOL test vectors from Whirlpool package
- * by Vincent Rijmen and Paulo S. L. M. Barreto as part of the NESSIE
- * submission
- */
-#define WP512_TEST_VECTORS     8
-
-static struct hash_testvec wp512_tv_template[] = {
-       {
-               .plaintext = "",
-               .psize  = 0,
-               .digest = "\x19\xFA\x61\xD7\x55\x22\xA4\x66"
-                         "\x9B\x44\xE3\x9C\x1D\x2E\x17\x26"
-                         "\xC5\x30\x23\x21\x30\xD4\x07\xF8"
-                         "\x9A\xFE\xE0\x96\x49\x97\xF7\xA7"
-                         "\x3E\x83\xBE\x69\x8B\x28\x8F\xEB"
-                         "\xCF\x88\xE3\xE0\x3C\x4F\x07\x57"
-                         "\xEA\x89\x64\xE5\x9B\x63\xD9\x37"
-                         "\x08\xB1\x38\xCC\x42\xA6\x6E\xB3",
-
-
-       }, {
-               .plaintext = "a",
-               .psize  = 1,
-               .digest = "\x8A\xCA\x26\x02\x79\x2A\xEC\x6F"
-                         "\x11\xA6\x72\x06\x53\x1F\xB7\xD7"
-                         "\xF0\xDF\xF5\x94\x13\x14\x5E\x69"
-                         "\x73\xC4\x50\x01\xD0\x08\x7B\x42"
-                         "\xD1\x1B\xC6\x45\x41\x3A\xEF\xF6"
-                         "\x3A\x42\x39\x1A\x39\x14\x5A\x59"
-                         "\x1A\x92\x20\x0D\x56\x01\x95\xE5"
-                         "\x3B\x47\x85\x84\xFD\xAE\x23\x1A",
-       }, {
-               .plaintext = "abc",
-               .psize  = 3,
-               .digest = "\x4E\x24\x48\xA4\xC6\xF4\x86\xBB"
-                         "\x16\xB6\x56\x2C\x73\xB4\x02\x0B"
-                         "\xF3\x04\x3E\x3A\x73\x1B\xCE\x72"
-                         "\x1A\xE1\xB3\x03\xD9\x7E\x6D\x4C"
-                         "\x71\x81\xEE\xBD\xB6\xC5\x7E\x27"
-                         "\x7D\x0E\x34\x95\x71\x14\xCB\xD6"
-                         "\xC7\x97\xFC\x9D\x95\xD8\xB5\x82"
-                         "\xD2\x25\x29\x20\x76\xD4\xEE\xF5",
-       }, {
-               .plaintext = "message digest",
-               .psize  = 14,
-               .digest = "\x37\x8C\x84\xA4\x12\x6E\x2D\xC6"
-                         "\xE5\x6D\xCC\x74\x58\x37\x7A\xAC"
-                         "\x83\x8D\x00\x03\x22\x30\xF5\x3C"
-                         "\xE1\xF5\x70\x0C\x0F\xFB\x4D\x3B"
-                         "\x84\x21\x55\x76\x59\xEF\x55\xC1"
-                         "\x06\xB4\xB5\x2A\xC5\xA4\xAA\xA6"
-                         "\x92\xED\x92\x00\x52\x83\x8F\x33"
-                         "\x62\xE8\x6D\xBD\x37\xA8\x90\x3E",
-       }, {
-               .plaintext = "abcdefghijklmnopqrstuvwxyz",
-               .psize  = 26,
-               .digest = "\xF1\xD7\x54\x66\x26\x36\xFF\xE9"
-                         "\x2C\x82\xEB\xB9\x21\x2A\x48\x4A"
-                         "\x8D\x38\x63\x1E\xAD\x42\x38\xF5"
-                         "\x44\x2E\xE1\x3B\x80\x54\xE4\x1B"
-                         "\x08\xBF\x2A\x92\x51\xC3\x0B\x6A"
-                         "\x0B\x8A\xAE\x86\x17\x7A\xB4\xA6"
-                         "\xF6\x8F\x67\x3E\x72\x07\x86\x5D"
-                         "\x5D\x98\x19\xA3\xDB\xA4\xEB\x3B",
-       }, {
-               .plaintext = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
-                          "abcdefghijklmnopqrstuvwxyz0123456789",
-               .psize  = 62,
-               .digest = "\xDC\x37\xE0\x08\xCF\x9E\xE6\x9B"
-                         "\xF1\x1F\x00\xED\x9A\xBA\x26\x90"
-                         "\x1D\xD7\xC2\x8C\xDE\xC0\x66\xCC"
-                         "\x6A\xF4\x2E\x40\xF8\x2F\x3A\x1E"
-                         "\x08\xEB\xA2\x66\x29\x12\x9D\x8F"
-                         "\xB7\xCB\x57\x21\x1B\x92\x81\xA6"
-                         "\x55\x17\xCC\x87\x9D\x7B\x96\x21"
-                         "\x42\xC6\x5F\x5A\x7A\xF0\x14\x67",
-       }, {
-               .plaintext = "1234567890123456789012345678901234567890"
-                          "1234567890123456789012345678901234567890",
-               .psize  = 80,
-               .digest = "\x46\x6E\xF1\x8B\xAB\xB0\x15\x4D"
-                         "\x25\xB9\xD3\x8A\x64\x14\xF5\xC0"
-                         "\x87\x84\x37\x2B\xCC\xB2\x04\xD6"
-                         "\x54\x9C\x4A\xFA\xDB\x60\x14\x29"
-                         "\x4D\x5B\xD8\xDF\x2A\x6C\x44\xE5"
-                         "\x38\xCD\x04\x7B\x26\x81\xA5\x1A"
-                         "\x2C\x60\x48\x1E\x88\xC5\xA2\x0B"
-                         "\x2C\x2A\x80\xCF\x3A\x9A\x08\x3B",
-       }, {
-               .plaintext = "abcdbcdecdefdefgefghfghighijhijk",
-               .psize  = 32,
-               .digest = "\x2A\x98\x7E\xA4\x0F\x91\x70\x61"
-                         "\xF5\xD6\xF0\xA0\xE4\x64\x4F\x48"
-                         "\x8A\x7A\x5A\x52\xDE\xEE\x65\x62"
-                         "\x07\xC5\x62\xF9\x88\xE9\x5C\x69"
-                         "\x16\xBD\xC8\x03\x1B\xC5\xBE\x1B"
-                         "\x7B\x94\x76\x39\xFE\x05\x0B\x56"
-                         "\x93\x9B\xAA\xA0\xAD\xFF\x9A\xE6"
-                         "\x74\x5B\x7B\x18\x1C\x3B\xE3\xFD",
-       },
-};
-
-#define WP384_TEST_VECTORS     8
-
-static struct hash_testvec wp384_tv_template[] = {
-       {
-               .plaintext = "",
-               .psize  = 0,
-               .digest = "\x19\xFA\x61\xD7\x55\x22\xA4\x66"
-                         "\x9B\x44\xE3\x9C\x1D\x2E\x17\x26"
-                         "\xC5\x30\x23\x21\x30\xD4\x07\xF8"
-                         "\x9A\xFE\xE0\x96\x49\x97\xF7\xA7"
-                         "\x3E\x83\xBE\x69\x8B\x28\x8F\xEB"
-                         "\xCF\x88\xE3\xE0\x3C\x4F\x07\x57",
-
-
-       }, {
-               .plaintext = "a",
-               .psize  = 1,
-               .digest = "\x8A\xCA\x26\x02\x79\x2A\xEC\x6F"
-                         "\x11\xA6\x72\x06\x53\x1F\xB7\xD7"
-                         "\xF0\xDF\xF5\x94\x13\x14\x5E\x69"
-                         "\x73\xC4\x50\x01\xD0\x08\x7B\x42"
-                         "\xD1\x1B\xC6\x45\x41\x3A\xEF\xF6"
-                         "\x3A\x42\x39\x1A\x39\x14\x5A\x59",
-       }, {
-               .plaintext = "abc",
-               .psize  = 3,
-               .digest = "\x4E\x24\x48\xA4\xC6\xF4\x86\xBB"
-                         "\x16\xB6\x56\x2C\x73\xB4\x02\x0B"
-                         "\xF3\x04\x3E\x3A\x73\x1B\xCE\x72"
-                         "\x1A\xE1\xB3\x03\xD9\x7E\x6D\x4C"
-                         "\x71\x81\xEE\xBD\xB6\xC5\x7E\x27"
-                         "\x7D\x0E\x34\x95\x71\x14\xCB\xD6",
-       }, {
-               .plaintext = "message digest",
-               .psize  = 14,
-               .digest = "\x37\x8C\x84\xA4\x12\x6E\x2D\xC6"
-                         "\xE5\x6D\xCC\x74\x58\x37\x7A\xAC"
-                         "\x83\x8D\x00\x03\x22\x30\xF5\x3C"
-                         "\xE1\xF5\x70\x0C\x0F\xFB\x4D\x3B"
-                         "\x84\x21\x55\x76\x59\xEF\x55\xC1"
-                         "\x06\xB4\xB5\x2A\xC5\xA4\xAA\xA6",
-       }, {
-               .plaintext = "abcdefghijklmnopqrstuvwxyz",
-               .psize  = 26,
-               .digest = "\xF1\xD7\x54\x66\x26\x36\xFF\xE9"
-                         "\x2C\x82\xEB\xB9\x21\x2A\x48\x4A"
-                         "\x8D\x38\x63\x1E\xAD\x42\x38\xF5"
-                         "\x44\x2E\xE1\x3B\x80\x54\xE4\x1B"
-                         "\x08\xBF\x2A\x92\x51\xC3\x0B\x6A"
-                         "\x0B\x8A\xAE\x86\x17\x7A\xB4\xA6",
-       }, {
-               .plaintext = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
-                          "abcdefghijklmnopqrstuvwxyz0123456789",
-               .psize  = 62,
-               .digest = "\xDC\x37\xE0\x08\xCF\x9E\xE6\x9B"
-                         "\xF1\x1F\x00\xED\x9A\xBA\x26\x90"
-                         "\x1D\xD7\xC2\x8C\xDE\xC0\x66\xCC"
-                         "\x6A\xF4\x2E\x40\xF8\x2F\x3A\x1E"
-                         "\x08\xEB\xA2\x66\x29\x12\x9D\x8F"
-                         "\xB7\xCB\x57\x21\x1B\x92\x81\xA6",
-       }, {
-               .plaintext = "1234567890123456789012345678901234567890"
-                          "1234567890123456789012345678901234567890",
-               .psize  = 80,
-               .digest = "\x46\x6E\xF1\x8B\xAB\xB0\x15\x4D"
-                         "\x25\xB9\xD3\x8A\x64\x14\xF5\xC0"
-                         "\x87\x84\x37\x2B\xCC\xB2\x04\xD6"
-                         "\x54\x9C\x4A\xFA\xDB\x60\x14\x29"
-                         "\x4D\x5B\xD8\xDF\x2A\x6C\x44\xE5"
-                         "\x38\xCD\x04\x7B\x26\x81\xA5\x1A",
-       }, {
-               .plaintext = "abcdbcdecdefdefgefghfghighijhijk",
-               .psize  = 32,
-               .digest = "\x2A\x98\x7E\xA4\x0F\x91\x70\x61"
-                         "\xF5\xD6\xF0\xA0\xE4\x64\x4F\x48"
-                         "\x8A\x7A\x5A\x52\xDE\xEE\x65\x62"
-                         "\x07\xC5\x62\xF9\x88\xE9\x5C\x69"
-                         "\x16\xBD\xC8\x03\x1B\xC5\xBE\x1B"
-                         "\x7B\x94\x76\x39\xFE\x05\x0B\x56",
-       },
-};
-
-#define WP256_TEST_VECTORS     8
-
-static struct hash_testvec wp256_tv_template[] = {
-       {
-               .plaintext = "",
-               .psize  = 0,
-               .digest = "\x19\xFA\x61\xD7\x55\x22\xA4\x66"
-                         "\x9B\x44\xE3\x9C\x1D\x2E\x17\x26"
-                         "\xC5\x30\x23\x21\x30\xD4\x07\xF8"
-                         "\x9A\xFE\xE0\x96\x49\x97\xF7\xA7",
-
-
-       }, {
-               .plaintext = "a",
-               .psize  = 1,
-               .digest = "\x8A\xCA\x26\x02\x79\x2A\xEC\x6F"
-                         "\x11\xA6\x72\x06\x53\x1F\xB7\xD7"
-                         "\xF0\xDF\xF5\x94\x13\x14\x5E\x69"
-                         "\x73\xC4\x50\x01\xD0\x08\x7B\x42",
-       }, {
-               .plaintext = "abc",
-               .psize  = 3,
-               .digest = "\x4E\x24\x48\xA4\xC6\xF4\x86\xBB"
-                         "\x16\xB6\x56\x2C\x73\xB4\x02\x0B"
-                         "\xF3\x04\x3E\x3A\x73\x1B\xCE\x72"
-                         "\x1A\xE1\xB3\x03\xD9\x7E\x6D\x4C",
-       }, {
-               .plaintext = "message digest",
-               .psize  = 14,
-               .digest = "\x37\x8C\x84\xA4\x12\x6E\x2D\xC6"
-                         "\xE5\x6D\xCC\x74\x58\x37\x7A\xAC"
-                         "\x83\x8D\x00\x03\x22\x30\xF5\x3C"
-                         "\xE1\xF5\x70\x0C\x0F\xFB\x4D\x3B",
-       }, {
-               .plaintext = "abcdefghijklmnopqrstuvwxyz",
-               .psize  = 26,
-               .digest = "\xF1\xD7\x54\x66\x26\x36\xFF\xE9"
-                         "\x2C\x82\xEB\xB9\x21\x2A\x48\x4A"
-                         "\x8D\x38\x63\x1E\xAD\x42\x38\xF5"
-                         "\x44\x2E\xE1\x3B\x80\x54\xE4\x1B",
-       }, {
-               .plaintext = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
-                          "abcdefghijklmnopqrstuvwxyz0123456789",
-               .psize  = 62,
-               .digest = "\xDC\x37\xE0\x08\xCF\x9E\xE6\x9B"
-                         "\xF1\x1F\x00\xED\x9A\xBA\x26\x90"
-                         "\x1D\xD7\xC2\x8C\xDE\xC0\x66\xCC"
-                         "\x6A\xF4\x2E\x40\xF8\x2F\x3A\x1E",
-       }, {
-               .plaintext = "1234567890123456789012345678901234567890"
-                          "1234567890123456789012345678901234567890",
-               .psize  = 80,
-               .digest = "\x46\x6E\xF1\x8B\xAB\xB0\x15\x4D"
-                         "\x25\xB9\xD3\x8A\x64\x14\xF5\xC0"
-                         "\x87\x84\x37\x2B\xCC\xB2\x04\xD6"
-                         "\x54\x9C\x4A\xFA\xDB\x60\x14\x29",
-       }, {
-               .plaintext = "abcdbcdecdefdefgefghfghighijhijk",
-               .psize  = 32,
-               .digest = "\x2A\x98\x7E\xA4\x0F\x91\x70\x61"
-                         "\xF5\xD6\xF0\xA0\xE4\x64\x4F\x48"
-                         "\x8A\x7A\x5A\x52\xDE\xEE\x65\x62"
-                         "\x07\xC5\x62\xF9\x88\xE9\x5C\x69",
-       },
-};
-
-/*
- * TIGER test vectors from Tiger website
- */
-#define TGR192_TEST_VECTORS    6
-
-static struct hash_testvec tgr192_tv_template[] = {
-       {
-               .plaintext = "",
-               .psize  = 0,
-               .digest = "\x24\xf0\x13\x0c\x63\xac\x93\x32"
-                         "\x16\x16\x6e\x76\xb1\xbb\x92\x5f"
-                         "\xf3\x73\xde\x2d\x49\x58\x4e\x7a",
-       }, {
-               .plaintext = "abc",
-               .psize  = 3,
-               .digest = "\xf2\x58\xc1\xe8\x84\x14\xab\x2a"
-                         "\x52\x7a\xb5\x41\xff\xc5\xb8\xbf"
-                         "\x93\x5f\x7b\x95\x1c\x13\x29\x51",
-       }, {
-               .plaintext = "Tiger",
-               .psize  = 5,
-               .digest = "\x9f\x00\xf5\x99\x07\x23\x00\xdd"
-                         "\x27\x6a\xbb\x38\xc8\xeb\x6d\xec"
-                         "\x37\x79\x0c\x11\x6f\x9d\x2b\xdf",
-       }, {
-               .plaintext = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-",
-               .psize  = 64,
-               .digest = "\x87\xfb\x2a\x90\x83\x85\x1c\xf7"
-                         "\x47\x0d\x2c\xf8\x10\xe6\xdf\x9e"
-                         "\xb5\x86\x44\x50\x34\xa5\xa3\x86",
-       }, {
-               .plaintext = "ABCDEFGHIJKLMNOPQRSTUVWXYZ=abcdefghijklmnopqrstuvwxyz+0123456789",
-               .psize  = 64,
-               .digest = "\x46\x7d\xb8\x08\x63\xeb\xce\x48"
-                         "\x8d\xf1\xcd\x12\x61\x65\x5d\xe9"
-                         "\x57\x89\x65\x65\x97\x5f\x91\x97",
-       }, {
-               .plaintext = "Tiger - A Fast New Hash Function, "
-                          "by Ross Anderson and Eli Biham, "
-                          "proceedings of Fast Software Encryption 3, "
-                          "Cambridge, 1996.",
-               .psize  = 125,
-               .digest = "\x3d\x9a\xeb\x03\xd1\xbd\x1a\x63"
-                         "\x57\xb2\x77\x4d\xfd\x6d\x5b\x24"
-                         "\xdd\x68\x15\x1d\x50\x39\x74\xfc",
-       },
-};
-
-#define TGR160_TEST_VECTORS    6
-
-static struct hash_testvec tgr160_tv_template[] = {
-       {
-               .plaintext = "",
-               .psize  = 0,
-               .digest = "\x24\xf0\x13\x0c\x63\xac\x93\x32"
-                         "\x16\x16\x6e\x76\xb1\xbb\x92\x5f"
-                         "\xf3\x73\xde\x2d",
-       }, {
-               .plaintext = "abc",
-               .psize  = 3,
-               .digest = "\xf2\x58\xc1\xe8\x84\x14\xab\x2a"
-                         "\x52\x7a\xb5\x41\xff\xc5\xb8\xbf"
-                         "\x93\x5f\x7b\x95",
-       }, {
-               .plaintext = "Tiger",
-               .psize  = 5,
-               .digest = "\x9f\x00\xf5\x99\x07\x23\x00\xdd"
-                         "\x27\x6a\xbb\x38\xc8\xeb\x6d\xec"
-                         "\x37\x79\x0c\x11",
-       }, {
-               .plaintext = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-",
-               .psize  = 64,
-               .digest = "\x87\xfb\x2a\x90\x83\x85\x1c\xf7"
-                         "\x47\x0d\x2c\xf8\x10\xe6\xdf\x9e"
-                         "\xb5\x86\x44\x50",
-       }, {
-               .plaintext = "ABCDEFGHIJKLMNOPQRSTUVWXYZ=abcdefghijklmnopqrstuvwxyz+0123456789",
-               .psize  = 64,
-               .digest = "\x46\x7d\xb8\x08\x63\xeb\xce\x48"
-                         "\x8d\xf1\xcd\x12\x61\x65\x5d\xe9"
-                         "\x57\x89\x65\x65",
-       }, {
-               .plaintext = "Tiger - A Fast New Hash Function, "
-                          "by Ross Anderson and Eli Biham, "
-                          "proceedings of Fast Software Encryption 3, "
-                          "Cambridge, 1996.",
-               .psize  = 125,
-               .digest = "\x3d\x9a\xeb\x03\xd1\xbd\x1a\x63"
-                         "\x57\xb2\x77\x4d\xfd\x6d\x5b\x24"
-                         "\xdd\x68\x15\x1d",
-       },
-};
-
-#define TGR128_TEST_VECTORS    6
-
-static struct hash_testvec tgr128_tv_template[] = {
-       {
-               .plaintext = "",
-               .psize  = 0,
-               .digest = "\x24\xf0\x13\x0c\x63\xac\x93\x32"
-                         "\x16\x16\x6e\x76\xb1\xbb\x92\x5f",
-       }, {
-               .plaintext = "abc",
-               .psize  = 3,
-               .digest = "\xf2\x58\xc1\xe8\x84\x14\xab\x2a"
-                         "\x52\x7a\xb5\x41\xff\xc5\xb8\xbf",
-       }, {
-               .plaintext = "Tiger",
-               .psize  = 5,
-               .digest = "\x9f\x00\xf5\x99\x07\x23\x00\xdd"
-                         "\x27\x6a\xbb\x38\xc8\xeb\x6d\xec",
-       }, {
-               .plaintext = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-",
-               .psize  = 64,
-               .digest = "\x87\xfb\x2a\x90\x83\x85\x1c\xf7"
-                         "\x47\x0d\x2c\xf8\x10\xe6\xdf\x9e",
-       }, {
-               .plaintext = "ABCDEFGHIJKLMNOPQRSTUVWXYZ=abcdefghijklmnopqrstuvwxyz+0123456789",
-               .psize  = 64,
-               .digest = "\x46\x7d\xb8\x08\x63\xeb\xce\x48"
-                         "\x8d\xf1\xcd\x12\x61\x65\x5d\xe9",
-       }, {
-               .plaintext = "Tiger - A Fast New Hash Function, "
-                          "by Ross Anderson and Eli Biham, "
-                          "proceedings of Fast Software Encryption 3, "
-                          "Cambridge, 1996.",
-               .psize  = 125,
-               .digest = "\x3d\x9a\xeb\x03\xd1\xbd\x1a\x63"
-                         "\x57\xb2\x77\x4d\xfd\x6d\x5b\x24",
-       },
-};
-
-/*
- * HMAC-MD5 test vectors from RFC2202
- * (These need to be fixed to not use strlen).
- */
-#define HMAC_MD5_TEST_VECTORS  7
-
-static struct hash_testvec hmac_md5_tv_template[] =
-{
-       {
-               .key    = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",
-               .ksize  = 16,
-               .plaintext = "Hi There",
-               .psize  = 8,
-               .digest = "\x92\x94\x72\x7a\x36\x38\xbb\x1c"
-                         "\x13\xf4\x8e\xf8\x15\x8b\xfc\x9d",
-       }, {
-               .key    = "Jefe",
-               .ksize  = 4,
-               .plaintext = "what do ya want for nothing?",
-               .psize  = 28,
-               .digest = "\x75\x0c\x78\x3e\x6a\xb0\xb5\x03"
-                         "\xea\xa8\x6e\x31\x0a\x5d\xb7\x38",
-               .np     = 2,
-               .tap    = {14, 14}
-       }, {
-               .key    = "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa",
-               .ksize  = 16,
-               .plaintext = "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
-                       "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
-                       "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
-                       "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd",
-               .psize  = 50,
-               .digest = "\x56\xbe\x34\x52\x1d\x14\x4c\x88"
-                         "\xdb\xb8\xc7\x33\xf0\xe8\xb3\xf6",
-       }, {
-               .key    = "\x01\x02\x03\x04\x05\x06\x07\x08"
-                         "\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10"
-                         "\x11\x12\x13\x14\x15\x16\x17\x18\x19",
-               .ksize  = 25,
-               .plaintext = "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
-                       "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
-                       "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
-                       "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd",
-               .psize  = 50,
-               .digest = "\x69\x7e\xaf\x0a\xca\x3a\x3a\xea"
-                         "\x3a\x75\x16\x47\x46\xff\xaa\x79",
-       }, {
-               .key    = "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c",
-               .ksize  = 16,
-               .plaintext = "Test With Truncation",
-               .psize  = 20,
-               .digest = "\x56\x46\x1e\xf2\x34\x2e\xdc\x00"
-                         "\xf9\xba\xb9\x95\x69\x0e\xfd\x4c",
-       }, {
-               .key    = "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa",
-               .ksize  = 80,
-               .plaintext = "Test Using Larger Than Block-Size Key - Hash Key First",
-               .psize  = 54,
-               .digest = "\x6b\x1a\xb7\xfe\x4b\xd7\xbf\x8f"
-                         "\x0b\x62\xe6\xce\x61\xb9\xd0\xcd",
-       }, {
-               .key    = "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa",
-               .ksize  = 80,
-               .plaintext = "Test Using Larger Than Block-Size Key and Larger Than One "
-                          "Block-Size Data",
-               .psize  = 73,
-               .digest = "\x6f\x63\x0f\xad\x67\xcd\xa0\xee"
-                         "\x1f\xb1\xf5\x62\xdb\x3a\xa5\x3e",
-       },
-};
-
-/*
- * HMAC-RIPEMD128 test vectors from RFC2286
- */
-#define HMAC_RMD128_TEST_VECTORS       7
-
-static struct hash_testvec hmac_rmd128_tv_template[] = {
-       {
-               .key    = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",
-               .ksize  = 16,
-               .plaintext = "Hi There",
-               .psize  = 8,
-               .digest = "\xfb\xf6\x1f\x94\x92\xaa\x4b\xbf"
-                         "\x81\xc1\x72\xe8\x4e\x07\x34\xdb",
-       }, {
-               .key    = "Jefe",
-               .ksize  = 4,
-               .plaintext = "what do ya want for nothing?",
-               .psize  = 28,
-               .digest = "\x87\x5f\x82\x88\x62\xb6\xb3\x34"
-                         "\xb4\x27\xc5\x5f\x9f\x7f\xf0\x9b",
-               .np     = 2,
-               .tap    = { 14, 14 },
-       }, {
-               .key    = "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa",
-               .ksize  = 16,
-               .plaintext = "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
-                       "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
-                       "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
-                       "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd",
-               .psize  = 50,
-               .digest = "\x09\xf0\xb2\x84\x6d\x2f\x54\x3d"
-                         "\xa3\x63\xcb\xec\x8d\x62\xa3\x8d",
-       }, {
-               .key    = "\x01\x02\x03\x04\x05\x06\x07\x08"
-                         "\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10"
-                         "\x11\x12\x13\x14\x15\x16\x17\x18\x19",
-               .ksize  = 25,
-               .plaintext = "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
-                       "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
-                       "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
-                       "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd",
-               .psize  = 50,
-               .digest = "\xbd\xbb\xd7\xcf\x03\xe4\x4b\x5a"
-                         "\xa6\x0a\xf8\x15\xbe\x4d\x22\x94",
-       }, {
-               .key    = "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c",
-               .ksize  = 16,
-               .plaintext = "Test With Truncation",
-               .psize  = 20,
-               .digest = "\xe7\x98\x08\xf2\x4b\x25\xfd\x03"
-                         "\x1c\x15\x5f\x0d\x55\x1d\x9a\x3a",
-       }, {
-               .key    = "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa",
-               .ksize  = 80,
-               .plaintext = "Test Using Larger Than Block-Size Key - Hash Key First",
-               .psize  = 54,
-               .digest = "\xdc\x73\x29\x28\xde\x98\x10\x4a"
-                         "\x1f\x59\xd3\x73\xc1\x50\xac\xbb",
-       }, {
-               .key    = "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa",
-               .ksize  = 80,
-               .plaintext = "Test Using Larger Than Block-Size Key and Larger Than One "
-                          "Block-Size Data",
-               .psize  = 73,
-               .digest = "\x5c\x6b\xec\x96\x79\x3e\x16\xd4"
-                         "\x06\x90\xc2\x37\x63\x5f\x30\xc5",
-       },
-};
-
-/*
- * HMAC-RIPEMD160 test vectors from RFC2286
- */
-#define HMAC_RMD160_TEST_VECTORS       7
-
-static struct hash_testvec hmac_rmd160_tv_template[] = {
-       {
-               .key    = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",
-               .ksize  = 20,
-               .plaintext = "Hi There",
-               .psize  = 8,
-               .digest = "\x24\xcb\x4b\xd6\x7d\x20\xfc\x1a\x5d\x2e"
-                         "\xd7\x73\x2d\xcc\x39\x37\x7f\x0a\x56\x68",
-       }, {
-               .key    = "Jefe",
-               .ksize  = 4,
-               .plaintext = "what do ya want for nothing?",
-               .psize  = 28,
-               .digest = "\xdd\xa6\xc0\x21\x3a\x48\x5a\x9e\x24\xf4"
-                         "\x74\x20\x64\xa7\xf0\x33\xb4\x3c\x40\x69",
-               .np     = 2,
-               .tap    = { 14, 14 },
-       }, {
-               .key    = "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa",
-               .ksize  = 20,
-               .plaintext = "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
-                       "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
-                       "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
-                       "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd",
-               .psize  = 50,
-               .digest = "\xb0\xb1\x05\x36\x0d\xe7\x59\x96\x0a\xb4"
-                         "\xf3\x52\x98\xe1\x16\xe2\x95\xd8\xe7\xc1",
-       }, {
-               .key    = "\x01\x02\x03\x04\x05\x06\x07\x08"
-                         "\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10"
-                         "\x11\x12\x13\x14\x15\x16\x17\x18\x19",
-               .ksize  = 25,
-               .plaintext = "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
-                       "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
-                       "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
-                       "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd",
-               .psize  = 50,
-               .digest = "\xd5\xca\x86\x2f\x4d\x21\xd5\xe6\x10\xe1"
-                         "\x8b\x4c\xf1\xbe\xb9\x7a\x43\x65\xec\xf4",
-       }, {
-               .key    = "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c",
-               .ksize  = 20,
-               .plaintext = "Test With Truncation",
-               .psize  = 20,
-               .digest = "\x76\x19\x69\x39\x78\xf9\x1d\x90\x53\x9a"
-                         "\xe7\x86\x50\x0f\xf3\xd8\xe0\x51\x8e\x39",
-       }, {
-               .key    = "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa",
-               .ksize  = 80,
-               .plaintext = "Test Using Larger Than Block-Size Key - Hash Key First",
-               .psize  = 54,
-               .digest = "\x64\x66\xca\x07\xac\x5e\xac\x29\xe1\xbd"
-                         "\x52\x3e\x5a\xda\x76\x05\xb7\x91\xfd\x8b",
-       }, {
-               .key    = "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa",
-               .ksize  = 80,
-               .plaintext = "Test Using Larger Than Block-Size Key and Larger Than One "
-                          "Block-Size Data",
-               .psize  = 73,
-               .digest = "\x69\xea\x60\x79\x8d\x71\x61\x6c\xce\x5f"
-                         "\xd0\x87\x1e\x23\x75\x4c\xd7\x5d\x5a\x0a",
-       },
-};
-
-/*
- * HMAC-SHA1 test vectors from RFC2202
- */
-#define HMAC_SHA1_TEST_VECTORS 7
-
-static struct hash_testvec hmac_sha1_tv_template[] = {
-       {
-               .key    = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",
-               .ksize  = 20,
-               .plaintext = "Hi There",
-               .psize  = 8,
-               .digest = "\xb6\x17\x31\x86\x55\x05\x72\x64"
-                         "\xe2\x8b\xc0\xb6\xfb\x37\x8c\x8e\xf1"
-                         "\x46\xbe",
-       }, {
-               .key    = "Jefe",
-               .ksize  = 4,
-               .plaintext = "what do ya want for nothing?",
-               .psize  = 28,
-               .digest = "\xef\xfc\xdf\x6a\xe5\xeb\x2f\xa2\xd2\x74"
-                         "\x16\xd5\xf1\x84\xdf\x9c\x25\x9a\x7c\x79",
-               .np     = 2,
-               .tap    = { 14, 14 }
-       }, {
-               .key    = "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa",
-               .ksize  = 20,
-               .plaintext = "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
-                       "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
-                       "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
-                       "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd",
-               .psize  = 50,
-               .digest = "\x12\x5d\x73\x42\xb9\xac\x11\xcd\x91\xa3"
-                         "\x9a\xf4\x8a\xa1\x7b\x4f\x63\xf1\x75\xd3",
-       }, {
-               .key    = "\x01\x02\x03\x04\x05\x06\x07\x08"
-                         "\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10"
-                         "\x11\x12\x13\x14\x15\x16\x17\x18\x19",
-               .ksize  = 25,
-               .plaintext = "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
-                       "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
-                       "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
-                       "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd",
-               .psize  = 50,
-               .digest = "\x4c\x90\x07\xf4\x02\x62\x50\xc6\xbc\x84"
-                         "\x14\xf9\xbf\x50\xc8\x6c\x2d\x72\x35\xda",
-       }, {
-               .key    = "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c",
-               .ksize  = 20,
-               .plaintext = "Test With Truncation",
-               .psize  = 20,
-               .digest = "\x4c\x1a\x03\x42\x4b\x55\xe0\x7f\xe7\xf2"
-                         "\x7b\xe1\xd5\x8b\xb9\x32\x4a\x9a\x5a\x04",
-       }, {
-               .key    = "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa",
-               .ksize  = 80,
-               .plaintext = "Test Using Larger Than Block-Size Key - Hash Key First",
-               .psize  = 54,
-               .digest = "\xaa\x4a\xe5\xe1\x52\x72\xd0\x0e\x95\x70"
-                         "\x56\x37\xce\x8a\x3b\x55\xed\x40\x21\x12",
-       }, {
-               .key    = "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa",
-               .ksize  = 80,
-               .plaintext = "Test Using Larger Than Block-Size Key and Larger Than One "
-                          "Block-Size Data",
-               .psize  = 73,
-               .digest = "\xe8\xe9\x9d\x0f\x45\x23\x7d\x78\x6d\x6b"
-                         "\xba\xa7\x96\x5c\x78\x08\xbb\xff\x1a\x91",
-       },
-};
-
-
-/*
- * SHA224 HMAC test vectors from RFC4231
- */
-#define HMAC_SHA224_TEST_VECTORS    4
-
-static struct hash_testvec hmac_sha224_tv_template[] = {
-       {
-               .key    = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
-                       "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
-                       "\x0b\x0b\x0b\x0b",
-               .ksize  = 20,
-               /*  ("Hi There") */
-               .plaintext = "\x48\x69\x20\x54\x68\x65\x72\x65",
-               .psize  = 8,
-               .digest = "\x89\x6f\xb1\x12\x8a\xbb\xdf\x19"
-                       "\x68\x32\x10\x7c\xd4\x9d\xf3\x3f"
-                       "\x47\xb4\xb1\x16\x99\x12\xba\x4f"
-                       "\x53\x68\x4b\x22",
-       }, {
-               .key    = "Jefe",
-               .ksize  = 4,
-               /* ("what do ya want for nothing?") */
-               .plaintext = "\x77\x68\x61\x74\x20\x64\x6f\x20"
-                       "\x79\x61\x20\x77\x61\x6e\x74\x20"
-                       "\x66\x6f\x72\x20\x6e\x6f\x74\x68"
-                       "\x69\x6e\x67\x3f",
-               .psize  = 28,
-               .digest = "\xa3\x0e\x01\x09\x8b\xc6\xdb\xbf"
-                       "\x45\x69\x0f\x3a\x7e\x9e\x6d\x0f"
-                       "\x8b\xbe\xa2\xa3\x9e\x61\x48\x00"
-                       "\x8f\xd0\x5e\x44",
-               .np = 4,
-               .tap    = { 7, 7, 7, 7 }
-       }, {
-               .key    = "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa",
-               .ksize  = 131,
-               /* ("Test Using Larger Than Block-Size Key - Hash Key First") */
-               .plaintext = "\x54\x65\x73\x74\x20\x55\x73\x69"
-                       "\x6e\x67\x20\x4c\x61\x72\x67\x65"
-                       "\x72\x20\x54\x68\x61\x6e\x20\x42"
-                       "\x6c\x6f\x63\x6b\x2d\x53\x69\x7a"
-                       "\x65\x20\x4b\x65\x79\x20\x2d\x20"
-                       "\x48\x61\x73\x68\x20\x4b\x65\x79"
-                       "\x20\x46\x69\x72\x73\x74",
-               .psize  = 54,
-               .digest = "\x95\xe9\xa0\xdb\x96\x20\x95\xad"
-                       "\xae\xbe\x9b\x2d\x6f\x0d\xbc\xe2"
-                       "\xd4\x99\xf1\x12\xf2\xd2\xb7\x27"
-                       "\x3f\xa6\x87\x0e",
-       }, {
-               .key    = "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa",
-               .ksize  = 131,
-               /* ("This is a test using a larger than block-size key and a")
-               (" larger than block-size data. The key needs to be")
-                       (" hashed before being used by the HMAC algorithm.") */
-               .plaintext = "\x54\x68\x69\x73\x20\x69\x73\x20"
-                       "\x61\x20\x74\x65\x73\x74\x20\x75"
-                       "\x73\x69\x6e\x67\x20\x61\x20\x6c"
-                       "\x61\x72\x67\x65\x72\x20\x74\x68"
-                       "\x61\x6e\x20\x62\x6c\x6f\x63\x6b"
-                       "\x2d\x73\x69\x7a\x65\x20\x6b\x65"
-                       "\x79\x20\x61\x6e\x64\x20\x61\x20"
-                       "\x6c\x61\x72\x67\x65\x72\x20\x74"
-                       "\x68\x61\x6e\x20\x62\x6c\x6f\x63"
-                       "\x6b\x2d\x73\x69\x7a\x65\x20\x64"
-                       "\x61\x74\x61\x2e\x20\x54\x68\x65"
-                       "\x20\x6b\x65\x79\x20\x6e\x65\x65"
-                       "\x64\x73\x20\x74\x6f\x20\x62\x65"
-                       "\x20\x68\x61\x73\x68\x65\x64\x20"
-                       "\x62\x65\x66\x6f\x72\x65\x20\x62"
-                       "\x65\x69\x6e\x67\x20\x75\x73\x65"
-                       "\x64\x20\x62\x79\x20\x74\x68\x65"
-                       "\x20\x48\x4d\x41\x43\x20\x61\x6c"
-                       "\x67\x6f\x72\x69\x74\x68\x6d\x2e",
-               .psize  = 152,
-               .digest = "\x3a\x85\x41\x66\xac\x5d\x9f\x02"
-                       "\x3f\x54\xd5\x17\xd0\xb3\x9d\xbd"
-                       "\x94\x67\x70\xdb\x9c\x2b\x95\xc9"
-                       "\xf6\xf5\x65\xd1",
-       },
-};
-
-/*
- * HMAC-SHA256 test vectors from
- * draft-ietf-ipsec-ciph-sha-256-01.txt
- */
-#define HMAC_SHA256_TEST_VECTORS       10
-
-static struct hash_testvec hmac_sha256_tv_template[] = {
-       {
-               .key    = "\x01\x02\x03\x04\x05\x06\x07\x08"
-                         "\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10"
-                         "\x11\x12\x13\x14\x15\x16\x17\x18"
-                         "\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20",
-               .ksize  = 32,
-               .plaintext = "abc",
-               .psize  = 3,
-               .digest = "\xa2\x1b\x1f\x5d\x4c\xf4\xf7\x3a"
-                         "\x4d\xd9\x39\x75\x0f\x7a\x06\x6a"
-                         "\x7f\x98\xcc\x13\x1c\xb1\x6a\x66"
-                         "\x92\x75\x90\x21\xcf\xab\x81\x81",
-       }, {
-               .key    = "\x01\x02\x03\x04\x05\x06\x07\x08"
-                         "\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10"
-                         "\x11\x12\x13\x14\x15\x16\x17\x18"
-                         "\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20",
-               .ksize  = 32,
-               .plaintext = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
-               .psize  = 56,
-               .digest = "\x10\x4f\xdc\x12\x57\x32\x8f\x08"
-                         "\x18\x4b\xa7\x31\x31\xc5\x3c\xae"
-                         "\xe6\x98\xe3\x61\x19\x42\x11\x49"
-                         "\xea\x8c\x71\x24\x56\x69\x7d\x30",
-       }, {
-               .key    = "\x01\x02\x03\x04\x05\x06\x07\x08"
-                         "\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10"
-                         "\x11\x12\x13\x14\x15\x16\x17\x18"
-                         "\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20",
-               .ksize  = 32,
-               .plaintext = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
-                          "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
-               .psize  = 112,
-               .digest = "\x47\x03\x05\xfc\x7e\x40\xfe\x34"
-                         "\xd3\xee\xb3\xe7\x73\xd9\x5a\xab"
-                         "\x73\xac\xf0\xfd\x06\x04\x47\xa5"
-                         "\xeb\x45\x95\xbf\x33\xa9\xd1\xa3",
-       }, {
-               .key    = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
-                       "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
-                       "\x0b\x0b\x0b\x0b\x0b\x0b",
-               .ksize  = 32,
-               .plaintext = "Hi There",
-               .psize  = 8,
-               .digest = "\x19\x8a\x60\x7e\xb4\x4b\xfb\xc6"
-                         "\x99\x03\xa0\xf1\xcf\x2b\xbd\xc5"
-                         "\xba\x0a\xa3\xf3\xd9\xae\x3c\x1c"
-                         "\x7a\x3b\x16\x96\xa0\xb6\x8c\xf7",
-       }, {
-               .key    = "Jefe",
-               .ksize  = 4,
-               .plaintext = "what do ya want for nothing?",
-               .psize  = 28,
-               .digest = "\x5b\xdc\xc1\x46\xbf\x60\x75\x4e"
-                         "\x6a\x04\x24\x26\x08\x95\x75\xc7"
-                         "\x5a\x00\x3f\x08\x9d\x27\x39\x83"
-                         "\x9d\xec\x58\xb9\x64\xec\x38\x43",
-               .np     = 2,
-               .tap    = { 14, 14 }
-       }, {
-               .key    = "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa",
-               .ksize  = 32,
-               .plaintext = "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
-                       "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
-                       "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
-                       "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd",
-               .psize  = 50,
-               .digest = "\xcd\xcb\x12\x20\xd1\xec\xcc\xea"
-                         "\x91\xe5\x3a\xba\x30\x92\xf9\x62"
-                         "\xe5\x49\xfe\x6c\xe9\xed\x7f\xdc"
-                         "\x43\x19\x1f\xbd\xe4\x5c\x30\xb0",
-       }, {
-               .key    = "\x01\x02\x03\x04\x05\x06\x07\x08"
-                         "\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10"
-                         "\x11\x12\x13\x14\x15\x16\x17\x18"
-                         "\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20"
-                         "\x21\x22\x23\x24\x25",
-               .ksize  = 37,
-               .plaintext = "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
-                       "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
-                       "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
-                       "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd",
-               .psize  = 50,
-               .digest = "\xd4\x63\x3c\x17\xf6\xfb\x8d\x74"
-                         "\x4c\x66\xde\xe0\xf8\xf0\x74\x55"
-                         "\x6e\xc4\xaf\x55\xef\x07\x99\x85"
-                         "\x41\x46\x8e\xb4\x9b\xd2\xe9\x17",
-       }, {
-               .key    = "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c"
-                       "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c"
-                       "\x0c\x0c\x0c\x0c\x0c\x0c",
-               .ksize  = 32,
-               .plaintext = "Test With Truncation",
-               .psize  = 20,
-               .digest = "\x75\x46\xaf\x01\x84\x1f\xc0\x9b"
-                         "\x1a\xb9\xc3\x74\x9a\x5f\x1c\x17"
-                         "\xd4\xf5\x89\x66\x8a\x58\x7b\x27"
-                         "\x00\xa9\xc9\x7c\x11\x93\xcf\x42",
-       }, {
-               .key    = "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa",
-               .ksize  = 80,
-               .plaintext = "Test Using Larger Than Block-Size Key - Hash Key First",
-               .psize  = 54,
-               .digest = "\x69\x53\x02\x5e\xd9\x6f\x0c\x09"
-                         "\xf8\x0a\x96\xf7\x8e\x65\x38\xdb"
-                         "\xe2\xe7\xb8\x20\xe3\xdd\x97\x0e"
-                         "\x7d\xdd\x39\x09\x1b\x32\x35\x2f",
-       }, {
-               .key    = "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa",
-               .ksize  = 80,
-               .plaintext = "Test Using Larger Than Block-Size Key and Larger Than "
-                          "One Block-Size Data",
-               .psize  = 73,
-               .digest = "\x63\x55\xac\x22\xe8\x90\xd0\xa3"
-                         "\xc8\x48\x1a\x5c\xa4\x82\x5b\xc8"
-                         "\x84\xd3\xe7\xa1\xff\x98\xa2\xfc"
-                         "\x2a\xc7\xd8\xe0\x64\xc3\xb2\xe6",
-       },
-};
-
-#define XCBC_AES_TEST_VECTORS 6
-
-static struct hash_testvec aes_xcbc128_tv_template[] = {
-       {
-               .key    = "\x00\x01\x02\x03\x04\x05\x06\x07"
-                         "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",
-               .plaintext = zeroed_string,
-               .digest = "\x75\xf0\x25\x1d\x52\x8a\xc0\x1c"
-                         "\x45\x73\xdf\xd5\x84\xd7\x9f\x29",
-               .psize  = 0,
-               .ksize  = 16,
-       }, {
-               .key    = "\x00\x01\x02\x03\x04\x05\x06\x07"
-                         "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",
-               .plaintext = "\x00\x01\x02",
-               .digest = "\x5b\x37\x65\x80\xae\x2f\x19\xaf"
-                         "\xe7\x21\x9c\xee\xf1\x72\x75\x6f",
-               .psize  = 3,
-               .ksize  = 16,
-       } , {
-               .key    = "\x00\x01\x02\x03\x04\x05\x06\x07"
-                         "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",
-               .plaintext = "\x00\x01\x02\x03\x04\x05\x06\x07"
-                            "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",
-               .digest = "\xd2\xa2\x46\xfa\x34\x9b\x68\xa7"
-                         "\x99\x98\xa4\x39\x4f\xf7\xa2\x63",
-               .psize  = 16,
-               .ksize  = 16,
-       }, {
-               .key    = "\x00\x01\x02\x03\x04\x05\x06\x07"
-                         "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",
-               .plaintext = "\x00\x01\x02\x03\x04\x05\x06\x07"
-                            "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
-                            "\x10\x11\x12\x13",
-               .digest = "\x47\xf5\x1b\x45\x64\x96\x62\x15"
-                         "\xb8\x98\x5c\x63\x05\x5e\xd3\x08",
-               .tap    = { 10, 10 },
-               .psize  = 20,
-               .np     = 2,
-               .ksize  = 16,
-       }, {
-               .key    = "\x00\x01\x02\x03\x04\x05\x06\x07"
-                         "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",
-               .plaintext = "\x00\x01\x02\x03\x04\x05\x06\x07"
-                            "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
-                            "\x10\x11\x12\x13\x14\x15\x16\x17"
-                            "\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f",
-               .digest = "\xf5\x4f\x0e\xc8\xd2\xb9\xf3\xd3"
-                         "\x68\x07\x73\x4b\xd5\x28\x3f\xd4",
-               .psize  = 32,
-               .ksize  = 16,
-       }, {
-               .key    = "\x00\x01\x02\x03\x04\x05\x06\x07"
-                         "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",
-               .plaintext = "\x00\x01\x02\x03\x04\x05\x06\x07"
-                            "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
-                            "\x10\x11\x12\x13\x14\x15\x16\x17"
-                            "\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"
-                            "\x20\x21",
-               .digest = "\xbe\xcb\xb3\xbc\xcd\xb5\x18\xa3"
-                         "\x06\x77\xd5\x48\x1f\xb6\xb4\xd8",
-               .tap    = { 17, 17 },
-               .psize  = 34,
-               .np     = 2,
-               .ksize  = 16,
-       }
-};
-
-/*
- * SHA384 HMAC test vectors from RFC4231
- */
-
-#define HMAC_SHA384_TEST_VECTORS       4
-
-static struct hash_testvec hmac_sha384_tv_template[] = {
-       {
-               .key    = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
-                         "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
-                         "\x0b\x0b\x0b\x0b",
-               .ksize  = 20,
-               .plaintext = "Hi There",
-               .psize  = 8,
-               .digest = "\xaf\xd0\x39\x44\xd8\x48\x95\x62"
-                         "\x6b\x08\x25\xf4\xab\x46\x90\x7f"
-                         "\x15\xf9\xda\xdb\xe4\x10\x1e\xc6"
-                         "\x82\xaa\x03\x4c\x7c\xeb\xc5\x9c"
-                         "\xfa\xea\x9e\xa9\x07\x6e\xde\x7f"
-                         "\x4a\xf1\x52\xe8\xb2\xfa\x9c\xb6",
-       }, {
-               .key    = "Jefe",
-               .ksize  = 4,
-               .plaintext = "what do ya want for nothing?",
-               .psize  = 28,
-               .digest = "\xaf\x45\xd2\xe3\x76\x48\x40\x31"
-                         "\x61\x7f\x78\xd2\xb5\x8a\x6b\x1b"
-                         "\x9c\x7e\xf4\x64\xf5\xa0\x1b\x47"
-                         "\xe4\x2e\xc3\x73\x63\x22\x44\x5e"
-                         "\x8e\x22\x40\xca\x5e\x69\xe2\xc7"
-                         "\x8b\x32\x39\xec\xfa\xb2\x16\x49",
-               .np     = 4,
-               .tap    = { 7, 7, 7, 7 }
-       }, {
-               .key    = "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                         "\xaa\xaa\xaa",
-               .ksize  = 131,
-               .plaintext = "Test Using Larger Than Block-Siz"
-                          "e Key - Hash Key First",
-               .psize  = 54,
-               .digest = "\x4e\xce\x08\x44\x85\x81\x3e\x90"
-                         "\x88\xd2\xc6\x3a\x04\x1b\xc5\xb4"
-                         "\x4f\x9e\xf1\x01\x2a\x2b\x58\x8f"
-                         "\x3c\xd1\x1f\x05\x03\x3a\xc4\xc6"
-                         "\x0c\x2e\xf6\xab\x40\x30\xfe\x82"
-                         "\x96\x24\x8d\xf1\x63\xf4\x49\x52",
-       }, {
-               .key    = "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                         "\xaa\xaa\xaa",
-               .ksize  = 131,
-               .plaintext = "This is a test u"
-                          "sing a larger th"
-                          "an block-size ke"
-                          "y and a larger t"
-                          "han block-size d"
-                          "ata. The key nee"
-                          "ds to be hashed "
-                          "before being use"
-                          "d by the HMAC al"
-                          "gorithm.",
-               .psize  = 152,
-               .digest = "\x66\x17\x17\x8e\x94\x1f\x02\x0d"
-                         "\x35\x1e\x2f\x25\x4e\x8f\xd3\x2c"
-                         "\x60\x24\x20\xfe\xb0\xb8\xfb\x9a"
-                         "\xdc\xce\xbb\x82\x46\x1e\x99\xc5"
-                         "\xa6\x78\xcc\x31\xe7\x99\x17\x6d"
-                         "\x38\x60\xe6\x11\x0c\x46\x52\x3e",
-       },
-};
-
-/*
- * SHA512 HMAC test vectors from RFC4231
- */
-
-#define HMAC_SHA512_TEST_VECTORS       4
-
-static struct hash_testvec hmac_sha512_tv_template[] = {
-       {
-               .key    = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
-                         "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
-                         "\x0b\x0b\x0b\x0b",
-               .ksize  = 20,
-               .plaintext = "Hi There",
-               .psize  = 8,
-               .digest = "\x87\xaa\x7c\xde\xa5\xef\x61\x9d"
-                         "\x4f\xf0\xb4\x24\x1a\x1d\x6c\xb0"
-                         "\x23\x79\xf4\xe2\xce\x4e\xc2\x78"
-                         "\x7a\xd0\xb3\x05\x45\xe1\x7c\xde"
-                         "\xda\xa8\x33\xb7\xd6\xb8\xa7\x02"
-                         "\x03\x8b\x27\x4e\xae\xa3\xf4\xe4"
-                         "\xbe\x9d\x91\x4e\xeb\x61\xf1\x70"
-                         "\x2e\x69\x6c\x20\x3a\x12\x68\x54",
-       }, {
-               .key    = "Jefe",
-               .ksize  = 4,
-               .plaintext = "what do ya want for nothing?",
-               .psize  = 28,
-               .digest = "\x16\x4b\x7a\x7b\xfc\xf8\x19\xe2"
-                         "\xe3\x95\xfb\xe7\x3b\x56\xe0\xa3"
-                         "\x87\xbd\x64\x22\x2e\x83\x1f\xd6"
-                         "\x10\x27\x0c\xd7\xea\x25\x05\x54"
-                         "\x97\x58\xbf\x75\xc0\x5a\x99\x4a"
-                         "\x6d\x03\x4f\x65\xf8\xf0\xe6\xfd"
-                         "\xca\xea\xb1\xa3\x4d\x4a\x6b\x4b"
-                         "\x63\x6e\x07\x0a\x38\xbc\xe7\x37",
-               .np     = 4,
-               .tap    = { 7, 7, 7, 7 }
-       }, {
-               .key    = "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                         "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                         "\xaa\xaa\xaa",
-               .ksize  = 131,
-               .plaintext = "Test Using Large"
-                          "r Than Block-Siz"
-                          "e Key - Hash Key"
-                          " First",
-               .psize  = 54,
-               .digest = "\x80\xb2\x42\x63\xc7\xc1\xa3\xeb"
-                       "\xb7\x14\x93\xc1\xdd\x7b\xe8\xb4"
-                       "\x9b\x46\xd1\xf4\x1b\x4a\xee\xc1"
-                       "\x12\x1b\x01\x37\x83\xf8\xf3\x52"
-                       "\x6b\x56\xd0\x37\xe0\x5f\x25\x98"
-                       "\xbd\x0f\xd2\x21\x5d\x6a\x1e\x52"
-                       "\x95\xe6\x4f\x73\xf6\x3f\x0a\xec"
-                       "\x8b\x91\x5a\x98\x5d\x78\x65\x98",
-       }, {
-               .key    = "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
-                       "\xaa\xaa\xaa",
-               .ksize  = 131,
-               .plaintext =
-                         "This is a test u"
-                         "sing a larger th"
-                         "an block-size ke"
-                         "y and a larger t"
-                         "han block-size d"
-                         "ata. The key nee"
-                         "ds to be hashed "
-                         "before being use"
-                         "d by the HMAC al"
-                         "gorithm.",
-               .psize  = 152,
-               .digest = "\xe3\x7b\x6a\x77\x5d\xc8\x7d\xba"
-                       "\xa4\xdf\xa9\xf9\x6e\x5e\x3f\xfd"
-                       "\xde\xbd\x71\xf8\x86\x72\x89\x86"
-                       "\x5d\xf5\xa3\x2d\x20\xcd\xc9\x44"
-                       "\xb6\x02\x2c\xac\x3c\x49\x82\xb1"
-                       "\x0d\x5e\xeb\x55\xc3\xe4\xde\x15"
-                       "\x13\x46\x76\xfb\x6d\xe0\x44\x60"
-                       "\x65\xc9\x74\x40\xfa\x8c\x6a\x58",
-       },
-};
-
 /*
  * DES test vectors.
  */
-#define DES_ENC_TEST_VECTORS           10
-#define DES_DEC_TEST_VECTORS           4
-#define DES_CBC_ENC_TEST_VECTORS       5
-#define DES_CBC_DEC_TEST_VECTORS       4
-#define DES3_EDE_ENC_TEST_VECTORS      3
-#define DES3_EDE_DEC_TEST_VECTORS      3
-#define DES3_EDE_CBC_ENC_TEST_VECTORS  1
-#define DES3_EDE_CBC_DEC_TEST_VECTORS  1
-
-static struct cipher_testvec des_enc_tv_template[] = {
-       { /* From Applied Cryptography */
-               .key    = "\x01\x23\x45\x67\x89\xab\xcd\xef",
-               .klen   = 8,
-               .input  = "\x01\x23\x45\x67\x89\xab\xcd\xe7",
-               .ilen   = 8,
-               .result = "\xc9\x57\x44\x25\x6a\x5e\xd3\x1d",
-               .rlen   = 8,
-       }, { /* Same key, different plaintext block */
-               .key    = "\x01\x23\x45\x67\x89\xab\xcd\xef",
-               .klen   = 8,
-               .input  = "\x22\x33\x44\x55\x66\x77\x88\x99",
-               .ilen   = 8,
-               .result = "\xf7\x9c\x89\x2a\x33\x8f\x4a\x8b",
-               .rlen   = 8,
-       }, { /* Sbox test from NBS */
-               .key    = "\x7c\xa1\x10\x45\x4a\x1a\x6e\x57",
-               .klen   = 8,
-               .input  = "\x01\xa1\xd6\xd0\x39\x77\x67\x42",
-               .ilen   = 8,
-               .result = "\x69\x0f\x5b\x0d\x9a\x26\x93\x9b",
-               .rlen   = 8,
-       }, { /* Three blocks */
-               .key    = "\x01\x23\x45\x67\x89\xab\xcd\xef",
-               .klen   = 8,
-               .input  = "\x01\x23\x45\x67\x89\xab\xcd\xe7"
-                         "\x22\x33\x44\x55\x66\x77\x88\x99"
-                         "\xca\xfe\xba\xbe\xfe\xed\xbe\xef",
-               .ilen   = 24,
-               .result = "\xc9\x57\x44\x25\x6a\x5e\xd3\x1d"
-                         "\xf7\x9c\x89\x2a\x33\x8f\x4a\x8b"
-                         "\xb4\x99\x26\xf7\x1f\xe1\xd4\x90",
-               .rlen   = 24,
-       }, { /* Weak key */
-               .fail   = 1,
-               .wk     = 1,
-               .key    = "\x01\x01\x01\x01\x01\x01\x01\x01",
-               .klen   = 8,
-               .input  = "\x01\x23\x45\x67\x89\xab\xcd\xe7",
-               .ilen   = 8,
-               .result = "\xc9\x57\x44\x25\x6a\x5e\xd3\x1d",
-               .rlen   = 8,
-       }, { /* Two blocks -- for testing encryption across pages */
-               .key    = "\x01\x23\x45\x67\x89\xab\xcd\xef",
-               .klen   = 8,
-               .input  = "\x01\x23\x45\x67\x89\xab\xcd\xe7"
-                         "\x22\x33\x44\x55\x66\x77\x88\x99",
-               .ilen   = 16,
-               .result = "\xc9\x57\x44\x25\x6a\x5e\xd3\x1d"
-                         "\xf7\x9c\x89\x2a\x33\x8f\x4a\x8b",
-               .rlen   = 16,
-               .np     = 2,
-               .tap    = { 8, 8 }
-       }, { /* Four blocks -- for testing encryption with chunking */
-               .key    = "\x01\x23\x45\x67\x89\xab\xcd\xef",
-               .klen   = 8,
-               .input  = "\x01\x23\x45\x67\x89\xab\xcd\xe7"
-                         "\x22\x33\x44\x55\x66\x77\x88\x99"
-                         "\xca\xfe\xba\xbe\xfe\xed\xbe\xef"
-                         "\x22\x33\x44\x55\x66\x77\x88\x99",
-               .ilen   = 32,
-               .result = "\xc9\x57\x44\x25\x6a\x5e\xd3\x1d"
-                         "\xf7\x9c\x89\x2a\x33\x8f\x4a\x8b"
-                         "\xb4\x99\x26\xf7\x1f\xe1\xd4\x90"
-                         "\xf7\x9c\x89\x2a\x33\x8f\x4a\x8b",
-               .rlen   = 32,
-               .np     = 3,
-               .tap    = { 14, 10, 8 }
-       }, {
-               .key    = "\x01\x23\x45\x67\x89\xab\xcd\xef",
-               .klen   = 8,
-               .input  = "\x01\x23\x45\x67\x89\xab\xcd\xe7"
-                         "\x22\x33\x44\x55\x66\x77\x88\x99"
-                         "\xca\xfe\xba\xbe\xfe\xed\xbe\xef",
-               .ilen   = 24,
-               .result = "\xc9\x57\x44\x25\x6a\x5e\xd3\x1d"
-                         "\xf7\x9c\x89\x2a\x33\x8f\x4a\x8b"
-                         "\xb4\x99\x26\xf7\x1f\xe1\xd4\x90",
-               .rlen   = 24,
-               .np     = 4,
-               .tap    = { 2, 1, 3, 18 }
-       }, {
-               .key    = "\x01\x23\x45\x67\x89\xab\xcd\xef",
-               .klen   = 8,
-               .input  = "\x01\x23\x45\x67\x89\xab\xcd\xe7"
-                         "\x22\x33\x44\x55\x66\x77\x88\x99",
-               .ilen   = 16,
-               .result = "\xc9\x57\x44\x25\x6a\x5e\xd3\x1d"
-                         "\xf7\x9c\x89\x2a\x33\x8f\x4a\x8b",
-               .rlen   = 16,
-               .np     = 5,
-               .tap    = { 2, 2, 2, 2, 8 }
-       }, {
-               .key    = "\x01\x23\x45\x67\x89\xab\xcd\xef",
-               .klen   = 8,
-               .input  = "\x01\x23\x45\x67\x89\xab\xcd\xe7",
-               .ilen   = 8,
-               .result = "\xc9\x57\x44\x25\x6a\x5e\xd3\x1d",
-               .rlen   = 8,
-               .np     = 8,
-               .tap    = { 1, 1, 1, 1, 1, 1, 1, 1 }
-       },
-};
-
-static struct cipher_testvec des_dec_tv_template[] = {
-       { /* From Applied Cryptography */
-               .key    = "\x01\x23\x45\x67\x89\xab\xcd\xef",
-               .klen   = 8,
-               .input  = "\xc9\x57\x44\x25\x6a\x5e\xd3\x1d",
-               .ilen   = 8,
-               .result = "\x01\x23\x45\x67\x89\xab\xcd\xe7",
-               .rlen   = 8,
-       }, { /* Sbox test from NBS */
-               .key    = "\x7c\xa1\x10\x45\x4a\x1a\x6e\x57",
-               .klen   = 8,
-               .input  = "\x69\x0f\x5b\x0d\x9a\x26\x93\x9b",
-               .ilen   = 8,
-               .result = "\x01\xa1\xd6\xd0\x39\x77\x67\x42",
-               .rlen   = 8,
-       }, { /* Two blocks, for chunking test */
-               .key    = "\x01\x23\x45\x67\x89\xab\xcd\xef",
-               .klen   = 8,
-               .input  = "\xc9\x57\x44\x25\x6a\x5e\xd3\x1d"
-                         "\x69\x0f\x5b\x0d\x9a\x26\x93\x9b",
-               .ilen   = 16,
-               .result = "\x01\x23\x45\x67\x89\xab\xcd\xe7"
-                         "\xa3\x99\x7b\xca\xaf\x69\xa0\xf5",
-               .rlen   = 16,
-               .np     = 2,
-               .tap    = { 8, 8 }
-       }, {
-               .key    = "\x01\x23\x45\x67\x89\xab\xcd\xef",
-               .klen   = 8,
-               .input  = "\xc9\x57\x44\x25\x6a\x5e\xd3\x1d"
-                         "\x69\x0f\x5b\x0d\x9a\x26\x93\x9b",
-               .ilen   = 16,
-               .result = "\x01\x23\x45\x67\x89\xab\xcd\xe7"
-                         "\xa3\x99\x7b\xca\xaf\x69\xa0\xf5",
-               .rlen   = 16,
-               .np     = 3,
-               .tap    = { 3, 12, 1 }
-       },
-};
-
-static struct cipher_testvec des_cbc_enc_tv_template[] = {
-       { /* From OpenSSL */
-               .key    = "\x01\x23\x45\x67\x89\xab\xcd\xef",
-               .klen   = 8,
-               .iv     = "\xfe\xdc\xba\x98\x76\x54\x32\x10",
-               .input  = "\x37\x36\x35\x34\x33\x32\x31\x20"
-                         "\x4e\x6f\x77\x20\x69\x73\x20\x74"
-                         "\x68\x65\x20\x74\x69\x6d\x65\x20",
-               .ilen   = 24,
-               .result = "\xcc\xd1\x73\xff\xab\x20\x39\xf4"
-                         "\xac\xd8\xae\xfd\xdf\xd8\xa1\xeb"
-                         "\x46\x8e\x91\x15\x78\x88\xba\x68",
-               .rlen   = 24,
-       }, { /* FIPS Pub 81 */
-               .key    = "\x01\x23\x45\x67\x89\xab\xcd\xef",
-               .klen   = 8,
-               .iv     = "\x12\x34\x56\x78\x90\xab\xcd\xef",
-               .input  = "\x4e\x6f\x77\x20\x69\x73\x20\x74",
-               .ilen   = 8,
-               .result = "\xe5\xc7\xcd\xde\x87\x2b\xf2\x7c",
-               .rlen   = 8,
-       }, {
-               .key    = "\x01\x23\x45\x67\x89\xab\xcd\xef",
-               .klen   = 8,
-               .iv     = "\xe5\xc7\xcd\xde\x87\x2b\xf2\x7c",
-               .input  = "\x68\x65\x20\x74\x69\x6d\x65\x20",
-               .ilen   = 8,
-               .result = "\x43\xe9\x34\x00\x8c\x38\x9c\x0f",
-               .rlen   = 8,
-       }, {
-               .key    = "\x01\x23\x45\x67\x89\xab\xcd\xef",
-               .klen   = 8,
-               .iv     = "\x43\xe9\x34\x00\x8c\x38\x9c\x0f",
-               .input  = "\x66\x6f\x72\x20\x61\x6c\x6c\x20",
-               .ilen   = 8,
-               .result = "\x68\x37\x88\x49\x9a\x7c\x05\xf6",
-               .rlen   = 8,
-       }, { /* Copy of openssl vector for chunk testing */
-            /* From OpenSSL */
-               .key    = "\x01\x23\x45\x67\x89\xab\xcd\xef",
-               .klen   = 8,
-               .iv     = "\xfe\xdc\xba\x98\x76\x54\x32\x10",
-               .input  = "\x37\x36\x35\x34\x33\x32\x31\x20"
-                         "\x4e\x6f\x77\x20\x69\x73\x20\x74"
-                         "\x68\x65\x20\x74\x69\x6d\x65\x20",
-               .ilen   = 24,
-               .result = "\xcc\xd1\x73\xff\xab\x20\x39\xf4"
-                         "\xac\xd8\xae\xfd\xdf\xd8\xa1\xeb"
-                         "\x46\x8e\x91\x15\x78\x88\xba\x68",
-               .rlen   = 24,
-               .np     = 2,
-               .tap    = { 13, 11 }
-       },
-};
-
-static struct cipher_testvec des_cbc_dec_tv_template[] = {
-       { /* FIPS Pub 81 */
-               .key    = "\x01\x23\x45\x67\x89\xab\xcd\xef",
-               .klen   = 8,
-               .iv     = "\x12\x34\x56\x78\x90\xab\xcd\xef",
-               .input  = "\xe5\xc7\xcd\xde\x87\x2b\xf2\x7c",
-               .ilen   = 8,
-               .result = "\x4e\x6f\x77\x20\x69\x73\x20\x74",
-               .rlen   = 8,
-       }, {
-               .key    = "\x01\x23\x45\x67\x89\xab\xcd\xef",
-               .klen   = 8,
-               .iv     = "\xe5\xc7\xcd\xde\x87\x2b\xf2\x7c",
-               .input  = "\x43\xe9\x34\x00\x8c\x38\x9c\x0f",
-               .ilen   = 8,
-               .result = "\x68\x65\x20\x74\x69\x6d\x65\x20",
-               .rlen   = 8,
-       }, {
-               .key    = "\x01\x23\x45\x67\x89\xab\xcd\xef",
-               .klen   = 8,
-               .iv     = "\x43\xe9\x34\x00\x8c\x38\x9c\x0f",
-               .input  = "\x68\x37\x88\x49\x9a\x7c\x05\xf6",
-               .ilen   = 8,
-               .result = "\x66\x6f\x72\x20\x61\x6c\x6c\x20",
-               .rlen   = 8,
-       }, { /* Copy of above, for chunk testing */
-               .key    = "\x01\x23\x45\x67\x89\xab\xcd\xef",
-               .klen   = 8,
-               .iv     = "\x43\xe9\x34\x00\x8c\x38\x9c\x0f",
-               .input  = "\x68\x37\x88\x49\x9a\x7c\x05\xf6",
-               .ilen   = 8,
-               .result = "\x66\x6f\x72\x20\x61\x6c\x6c\x20",
-               .rlen   = 8,
-               .np     = 2,
-               .tap    = { 4, 4 }
-       },
-};
-
-static struct cipher_testvec des3_ede_enc_tv_template[] = {
-       { /* These are from openssl */
-               .key    = "\x01\x23\x45\x67\x89\xab\xcd\xef"
-                         "\x55\x55\x55\x55\x55\x55\x55\x55"
-                         "\xfe\xdc\xba\x98\x76\x54\x32\x10",
-               .klen   = 24,
-               .input  = "\x73\x6f\x6d\x65\x64\x61\x74\x61",
-               .ilen   = 8,
-               .result = "\x18\xd7\x48\xe5\x63\x62\x05\x72",
-               .rlen   = 8,
-       }, {
-               .key    = "\x03\x52\x02\x07\x67\x20\x82\x17"
-                         "\x86\x02\x87\x66\x59\x08\x21\x98"
-                         "\x64\x05\x6a\xbd\xfe\xa9\x34\x57",
-               .klen   = 24,
-               .input  = "\x73\x71\x75\x69\x67\x67\x6c\x65",
-               .ilen   = 8,
-               .result = "\xc0\x7d\x2a\x0f\xa5\x66\xfa\x30",
-               .rlen   = 8,
-       }, {
-               .key    = "\x10\x46\x10\x34\x89\x98\x80\x20"
-                         "\x91\x07\xd0\x15\x89\x19\x01\x01"
-                         "\x19\x07\x92\x10\x98\x1a\x01\x01",
-               .klen   = 24,
-               .input  = "\x00\x00\x00\x00\x00\x00\x00\x00",
-               .ilen   = 8,
-               .result = "\xe1\xef\x62\xc3\x32\xfe\x82\x5b",
-               .rlen   = 8,
-       },
-};
-
-static struct cipher_testvec des3_ede_dec_tv_template[] = {
-       { /* These are from openssl */
-               .key    = "\x01\x23\x45\x67\x89\xab\xcd\xef"
-                         "\x55\x55\x55\x55\x55\x55\x55\x55"
-                         "\xfe\xdc\xba\x98\x76\x54\x32\x10",
-               .klen   = 24,
-               .input  = "\x18\xd7\x48\xe5\x63\x62\x05\x72",
-               .ilen   = 8,
-               .result = "\x73\x6f\x6d\x65\x64\x61\x74\x61",
-               .rlen   = 8,
-       }, {
-               .key    = "\x03\x52\x02\x07\x67\x20\x82\x17"
-                         "\x86\x02\x87\x66\x59\x08\x21\x98"
-                         "\x64\x05\x6a\xbd\xfe\xa9\x34\x57",
-               .klen   = 24,
-               .input  = "\xc0\x7d\x2a\x0f\xa5\x66\xfa\x30",
-               .ilen   = 8,
-               .result = "\x73\x71\x75\x69\x67\x67\x6c\x65",
-               .rlen   = 8,
-       }, {
-               .key    = "\x10\x46\x10\x34\x89\x98\x80\x20"
-                         "\x91\x07\xd0\x15\x89\x19\x01\x01"
-                         "\x19\x07\x92\x10\x98\x1a\x01\x01",
-               .klen   = 24,
-               .input  = "\xe1\xef\x62\xc3\x32\xfe\x82\x5b",
-               .ilen   = 8,
-               .result = "\x00\x00\x00\x00\x00\x00\x00\x00",
-               .rlen   = 8,
-       },
-};
-
-static struct cipher_testvec des3_ede_cbc_enc_tv_template[] = {
-       { /* Generated from openssl */
-               .key    = "\xE9\xC0\xFF\x2E\x76\x0B\x64\x24"
-                         "\x44\x4D\x99\x5A\x12\xD6\x40\xC0"
-                         "\xEA\xC2\x84\xE8\x14\x95\xDB\xE8",
-               .klen   = 24,
-               .iv     = "\x7D\x33\x88\x93\x0F\x93\xB2\x42",
-               .input  = "\x6f\x54\x20\x6f\x61\x4d\x79\x6e"
-                         "\x53\x20\x63\x65\x65\x72\x73\x74"
-                         "\x54\x20\x6f\x6f\x4d\x20\x6e\x61"
-                         "\x20\x79\x65\x53\x72\x63\x74\x65"
-                         "\x20\x73\x6f\x54\x20\x6f\x61\x4d"
-                         "\x79\x6e\x53\x20\x63\x65\x65\x72"
-                         "\x73\x74\x54\x20\x6f\x6f\x4d\x20"
-                         "\x6e\x61\x20\x79\x65\x53\x72\x63"
-                         "\x74\x65\x20\x73\x6f\x54\x20\x6f"
-                         "\x61\x4d\x79\x6e\x53\x20\x63\x65"
-                         "\x65\x72\x73\x74\x54\x20\x6f\x6f"
-                         "\x4d\x20\x6e\x61\x20\x79\x65\x53"
-                         "\x72\x63\x74\x65\x20\x73\x6f\x54"
-                         "\x20\x6f\x61\x4d\x79\x6e\x53\x20"
-                         "\x63\x65\x65\x72\x73\x74\x54\x20"
-                         "\x6f\x6f\x4d\x20\x6e\x61\x0a\x79",
-               .ilen   = 128,
-               .result = "\x0e\x2d\xb6\x97\x3c\x56\x33\xf4"
-                         "\x67\x17\x21\xc7\x6e\x8a\xd5\x49"
-                         "\x74\xb3\x49\x05\xc5\x1c\xd0\xed"
-                         "\x12\x56\x5c\x53\x96\xb6\x00\x7d"
-                         "\x90\x48\xfc\xf5\x8d\x29\x39\xcc"
-                         "\x8a\xd5\x35\x18\x36\x23\x4e\xd7"
-                         "\x76\xd1\xda\x0c\x94\x67\xbb\x04"
-                         "\x8b\xf2\x03\x6c\xa8\xcf\xb6\xea"
-                         "\x22\x64\x47\xaa\x8f\x75\x13\xbf"
-                         "\x9f\xc2\xc3\xf0\xc9\x56\xc5\x7a"
-                         "\x71\x63\x2e\x89\x7b\x1e\x12\xca"
-                         "\xe2\x5f\xaf\xd8\xa4\xf8\xc9\x7a"
-                         "\xd6\xf9\x21\x31\x62\x44\x45\xa6"
-                         "\xd6\xbc\x5a\xd3\x2d\x54\x43\xcc"
-                         "\x9d\xde\xa5\x70\xe9\x42\x45\x8a"
-                         "\x6b\xfa\xb1\x91\x13\xb0\xd9\x19",
-               .rlen   = 128,
-       },
-};
-
-static struct cipher_testvec des3_ede_cbc_dec_tv_template[] = {
-       { /* Generated from openssl */
-               .key    = "\xE9\xC0\xFF\x2E\x76\x0B\x64\x24"
-                         "\x44\x4D\x99\x5A\x12\xD6\x40\xC0"
-                         "\xEA\xC2\x84\xE8\x14\x95\xDB\xE8",
-               .klen   = 24,
-               .iv     = "\x7D\x33\x88\x93\x0F\x93\xB2\x42",
-               .input  = "\x0e\x2d\xb6\x97\x3c\x56\x33\xf4"
-                         "\x67\x17\x21\xc7\x6e\x8a\xd5\x49"
-                         "\x74\xb3\x49\x05\xc5\x1c\xd0\xed"
-                         "\x12\x56\x5c\x53\x96\xb6\x00\x7d"
-                         "\x90\x48\xfc\xf5\x8d\x29\x39\xcc"
-                         "\x8a\xd5\x35\x18\x36\x23\x4e\xd7"
-                         "\x76\xd1\xda\x0c\x94\x67\xbb\x04"
-                         "\x8b\xf2\x03\x6c\xa8\xcf\xb6\xea"
-                         "\x22\x64\x47\xaa\x8f\x75\x13\xbf"
-                         "\x9f\xc2\xc3\xf0\xc9\x56\xc5\x7a"
-                         "\x71\x63\x2e\x89\x7b\x1e\x12\xca"
-                         "\xe2\x5f\xaf\xd8\xa4\xf8\xc9\x7a"
-                         "\xd6\xf9\x21\x31\x62\x44\x45\xa6"
-                         "\xd6\xbc\x5a\xd3\x2d\x54\x43\xcc"
-                         "\x9d\xde\xa5\x70\xe9\x42\x45\x8a"
-                         "\x6b\xfa\xb1\x91\x13\xb0\xd9\x19",
-               .ilen   = 128,
-               .result = "\x6f\x54\x20\x6f\x61\x4d\x79\x6e"
-                         "\x53\x20\x63\x65\x65\x72\x73\x74"
-                         "\x54\x20\x6f\x6f\x4d\x20\x6e\x61"
-                         "\x20\x79\x65\x53\x72\x63\x74\x65"
-                         "\x20\x73\x6f\x54\x20\x6f\x61\x4d"
-                         "\x79\x6e\x53\x20\x63\x65\x65\x72"
-                         "\x73\x74\x54\x20\x6f\x6f\x4d\x20"
-                         "\x6e\x61\x20\x79\x65\x53\x72\x63"
-                         "\x74\x65\x20\x73\x6f\x54\x20\x6f"
-                         "\x61\x4d\x79\x6e\x53\x20\x63\x65"
-                         "\x65\x72\x73\x74\x54\x20\x6f\x6f"
-                         "\x4d\x20\x6e\x61\x20\x79\x65\x53"
-                         "\x72\x63\x74\x65\x20\x73\x6f\x54"
-                         "\x20\x6f\x61\x4d\x79\x6e\x53\x20"
-                         "\x63\x65\x65\x72\x73\x74\x54\x20"
-                         "\x6f\x6f\x4d\x20\x6e\x61\x0a\x79",
-               .rlen   = 128,
-       },
-};
-
-/*
- * Blowfish test vectors.
- */
-#define BF_ENC_TEST_VECTORS    6
-#define BF_DEC_TEST_VECTORS    6
-#define BF_CBC_ENC_TEST_VECTORS        1
-#define BF_CBC_DEC_TEST_VECTORS        1
-
-static struct cipher_testvec bf_enc_tv_template[] = {
-       { /* DES test vectors from OpenSSL */
-               .key    = "\x00\x00\x00\x00\x00\x00\x00\x00",
-               .klen   = 8,
-               .input  = "\x00\x00\x00\x00\x00\x00\x00\x00",
-               .ilen   = 8,
-               .result = "\x4e\xf9\x97\x45\x61\x98\xdd\x78",
-               .rlen   = 8,
-       }, {
-               .key    = "\x1f\x1f\x1f\x1f\x0e\x0e\x0e\x0e",
-               .klen   = 8,
-               .input  = "\x01\x23\x45\x67\x89\xab\xcd\xef",
-               .ilen   = 8,
-               .result = "\xa7\x90\x79\x51\x08\xea\x3c\xae",
-               .rlen   = 8,
-       }, {
-               .key    = "\xf0\xe1\xd2\xc3\xb4\xa5\x96\x87",
-               .klen   = 8,
-               .input  = "\xfe\xdc\xba\x98\x76\x54\x32\x10",
-               .ilen   = 8,
-               .result = "\xe8\x7a\x24\x4e\x2c\xc8\x5e\x82",
-               .rlen   = 8,
-       }, { /* Vary the keylength... */
-               .key    = "\xf0\xe1\xd2\xc3\xb4\xa5\x96\x87"
-                         "\x78\x69\x5a\x4b\x3c\x2d\x1e\x0f",
-               .klen   = 16,
-               .input  = "\xfe\xdc\xba\x98\x76\x54\x32\x10",
-               .ilen   = 8,
-               .result = "\x93\x14\x28\x87\xee\x3b\xe1\x5c",
-               .rlen   = 8,
-       }, {
-               .key    = "\xf0\xe1\xd2\xc3\xb4\xa5\x96\x87"
-                         "\x78\x69\x5a\x4b\x3c\x2d\x1e\x0f"
-                         "\x00\x11\x22\x33\x44",
-               .klen   = 21,
-               .input  = "\xfe\xdc\xba\x98\x76\x54\x32\x10",
-               .ilen   = 8,
-               .result = "\xe6\xf5\x1e\xd7\x9b\x9d\xb2\x1f",
-               .rlen   = 8,
-       }, { /* Generated with bf488 */
-               .key    = "\xf0\xe1\xd2\xc3\xb4\xa5\x96\x87"
-                         "\x78\x69\x5a\x4b\x3c\x2d\x1e\x0f"
-                         "\x00\x11\x22\x33\x44\x55\x66\x77"
-                         "\x04\x68\x91\x04\xc2\xfd\x3b\x2f"
-                         "\x58\x40\x23\x64\x1a\xba\x61\x76"
-                         "\x1f\x1f\x1f\x1f\x0e\x0e\x0e\x0e"
-                         "\xff\xff\xff\xff\xff\xff\xff\xff",
-               .klen   = 56,
-               .input  = "\xfe\xdc\xba\x98\x76\x54\x32\x10",
-               .ilen   = 8,
-               .result = "\xc0\x45\x04\x01\x2e\x4e\x1f\x53",
-               .rlen   = 8,
-       },
-};
-
-static struct cipher_testvec bf_dec_tv_template[] = {
-       { /* DES test vectors from OpenSSL */
-               .key    = "\x00\x00\x00\x00\x00\x00\x00\x00",
-               .klen   = 8,
-               .input  = "\x4e\xf9\x97\x45\x61\x98\xdd\x78",
-               .ilen   = 8,
-               .result = "\x00\x00\x00\x00\x00\x00\x00\x00",
-               .rlen   = 8,
-       }, {
-               .key    = "\x1f\x1f\x1f\x1f\x0e\x0e\x0e\x0e",
-               .klen   = 8,
-               .input  = "\xa7\x90\x79\x51\x08\xea\x3c\xae",
-               .ilen   = 8,
-               .result = "\x01\x23\x45\x67\x89\xab\xcd\xef",
-               .rlen   = 8,
-       }, {
-               .key    = "\xf0\xe1\xd2\xc3\xb4\xa5\x96\x87",
-               .klen   = 8,
-               .input  = "\xe8\x7a\x24\x4e\x2c\xc8\x5e\x82",
-               .ilen   = 8,
-               .result = "\xfe\xdc\xba\x98\x76\x54\x32\x10",
-               .rlen   = 8,
-       }, { /* Vary the keylength... */
-               .key    = "\xf0\xe1\xd2\xc3\xb4\xa5\x96\x87"
-                         "\x78\x69\x5a\x4b\x3c\x2d\x1e\x0f",
-               .klen   = 16,
-               .input  = "\x93\x14\x28\x87\xee\x3b\xe1\x5c",
-               .ilen   = 8,
-               .result = "\xfe\xdc\xba\x98\x76\x54\x32\x10",
-               .rlen   = 8,
-       }, {
-               .key    = "\xf0\xe1\xd2\xc3\xb4\xa5\x96\x87"
-                         "\x78\x69\x5a\x4b\x3c\x2d\x1e\x0f"
-                         "\x00\x11\x22\x33\x44",
-               .klen   = 21,
-               .input  = "\xe6\xf5\x1e\xd7\x9b\x9d\xb2\x1f",
-               .ilen   = 8,
-               .result = "\xfe\xdc\xba\x98\x76\x54\x32\x10",
-               .rlen   = 8,
-       }, { /* Generated with bf488, using OpenSSL, Libgcrypt and Nettle */
-               .key    = "\xf0\xe1\xd2\xc3\xb4\xa5\x96\x87"
-                         "\x78\x69\x5a\x4b\x3c\x2d\x1e\x0f"
-                         "\x00\x11\x22\x33\x44\x55\x66\x77"
-                         "\x04\x68\x91\x04\xc2\xfd\x3b\x2f"
-                         "\x58\x40\x23\x64\x1a\xba\x61\x76"
-                         "\x1f\x1f\x1f\x1f\x0e\x0e\x0e\x0e"
-                         "\xff\xff\xff\xff\xff\xff\xff\xff",
-               .klen   = 56,
-               .input  = "\xc0\x45\x04\x01\x2e\x4e\x1f\x53",
-               .ilen   = 8,
-               .result = "\xfe\xdc\xba\x98\x76\x54\x32\x10",
-               .rlen   = 8,
-       },
-};
-
-static struct cipher_testvec bf_cbc_enc_tv_template[] = {
-       { /* From OpenSSL */
-               .key    = "\x01\x23\x45\x67\x89\xab\xcd\xef"
-                         "\xf0\xe1\xd2\xc3\xb4\xa5\x96\x87",
-               .klen   = 16,
-               .iv     = "\xfe\xdc\xba\x98\x76\x54\x32\x10",
-               .input  = "\x37\x36\x35\x34\x33\x32\x31\x20"
-                         "\x4e\x6f\x77\x20\x69\x73\x20\x74"
-                         "\x68\x65\x20\x74\x69\x6d\x65\x20"
-                         "\x66\x6f\x72\x20\x00\x00\x00\x00",
-               .ilen   = 32,
-               .result = "\x6b\x77\xb4\xd6\x30\x06\xde\xe6"
-                         "\x05\xb1\x56\xe2\x74\x03\x97\x93"
-                         "\x58\xde\xb9\xe7\x15\x46\x16\xd9"
-                         "\x59\xf1\x65\x2b\xd5\xff\x92\xcc",
-               .rlen   = 32,
-       },
-};
-
-static struct cipher_testvec bf_cbc_dec_tv_template[] = {
-       { /* From OpenSSL */
-               .key    = "\x01\x23\x45\x67\x89\xab\xcd\xef"
-                         "\xf0\xe1\xd2\xc3\xb4\xa5\x96\x87",
-               .klen   = 16,
-               .iv     = "\xfe\xdc\xba\x98\x76\x54\x32\x10",
-               .input  = "\x6b\x77\xb4\xd6\x30\x06\xde\xe6"
-                         "\x05\xb1\x56\xe2\x74\x03\x97\x93"
-                         "\x58\xde\xb9\xe7\x15\x46\x16\xd9"
-                         "\x59\xf1\x65\x2b\xd5\xff\x92\xcc",
-               .ilen   = 32,
-               .result = "\x37\x36\x35\x34\x33\x32\x31\x20"
-                         "\x4e\x6f\x77\x20\x69\x73\x20\x74"
-                         "\x68\x65\x20\x74\x69\x6d\x65\x20"
-                         "\x66\x6f\x72\x20\x00\x00\x00\x00",
-               .rlen   = 32,
-       },
-};
-
-/*
- * Twofish test vectors.
- */
-#define TF_ENC_TEST_VECTORS            3
-#define TF_DEC_TEST_VECTORS            3
-#define TF_CBC_ENC_TEST_VECTORS                4
-#define TF_CBC_DEC_TEST_VECTORS                4
-
-static struct cipher_testvec tf_enc_tv_template[] = {
-       {
-               .key    = zeroed_string,
-               .klen   = 16,
-               .input  = zeroed_string,
-               .ilen   = 16,
-               .result = "\x9f\x58\x9f\x5c\xf6\x12\x2c\x32"
-                         "\xb6\xbf\xec\x2f\x2a\xe8\xc3\x5a",
-               .rlen   = 16,
-       }, {
-               .key    = "\x01\x23\x45\x67\x89\xab\xcd\xef"
-                         "\xfe\xdc\xba\x98\x76\x54\x32\x10"
-                         "\x00\x11\x22\x33\x44\x55\x66\x77",
-               .klen   = 24,
-               .input  = zeroed_string,
-               .ilen   = 16,
-               .result = "\xcf\xd1\xd2\xe5\xa9\xbe\x9c\xdf"
-                         "\x50\x1f\x13\xb8\x92\xbd\x22\x48",
-               .rlen   = 16,
-       }, {
-               .key    = "\x01\x23\x45\x67\x89\xab\xcd\xef"
-                         "\xfe\xdc\xba\x98\x76\x54\x32\x10"
-                         "\x00\x11\x22\x33\x44\x55\x66\x77"
-                         "\x88\x99\xaa\xbb\xcc\xdd\xee\xff",
-               .klen   = 32,
-               .input  = zeroed_string,
-               .ilen   = 16,
-               .result = "\x37\x52\x7b\xe0\x05\x23\x34\xb8"
-                         "\x9f\x0c\xfc\xca\xe8\x7c\xfa\x20",
-               .rlen   = 16,
-       },
-};
+#define DES3_SPEED_VECTORS     1
 
-static struct cipher_testvec tf_dec_tv_template[] = {
+static struct cipher_speed_template des3_speed_template[] = {
        {
-               .key    = zeroed_string,
-               .klen   = 16,
-               .input  = "\x9f\x58\x9f\x5c\xf6\x12\x2c\x32"
-                         "\xb6\xbf\xec\x2f\x2a\xe8\xc3\x5a",
-               .ilen   = 16,
-               .result = zeroed_string,
-               .rlen   = 16,
-       }, {
                .key    = "\x01\x23\x45\x67\x89\xab\xcd\xef"
-                         "\xfe\xdc\xba\x98\x76\x54\x32\x10"
-                         "\x00\x11\x22\x33\x44\x55\x66\x77",
-               .klen   = 24,
-               .input  = "\xcf\xd1\xd2\xe5\xa9\xbe\x9c\xdf"
-                         "\x50\x1f\x13\xb8\x92\xbd\x22\x48",
-               .ilen   = 16,
-               .result = zeroed_string,
-               .rlen   = 16,
-       }, {
-               .key    = "\x01\x23\x45\x67\x89\xab\xcd\xef"
-                         "\xfe\xdc\xba\x98\x76\x54\x32\x10"
-                         "\x00\x11\x22\x33\x44\x55\x66\x77"
-                         "\x88\x99\xaa\xbb\xcc\xdd\xee\xff",
-               .klen   = 32,
-               .input  = "\x37\x52\x7b\xe0\x05\x23\x34\xb8"
-                         "\x9f\x0c\xfc\xca\xe8\x7c\xfa\x20",
-               .ilen   = 16,
-               .result = zeroed_string,
-               .rlen   = 16,
-       },
-};
-
-static struct cipher_testvec tf_cbc_enc_tv_template[] = {
-       { /* Generated with Nettle */
-               .key    = zeroed_string,
-               .klen   = 16,
-               .iv     = zeroed_string,
-               .input  = zeroed_string,
-               .ilen   = 16,
-               .result = "\x9f\x58\x9f\x5c\xf6\x12\x2c\x32"
-                         "\xb6\xbf\xec\x2f\x2a\xe8\xc3\x5a",
-               .rlen   = 16,
-       }, {
-               .key    = zeroed_string,
-               .klen   = 16,
-               .iv     = "\x9f\x58\x9f\x5c\xf6\x12\x2c\x32"
-                         "\xb6\xbf\xec\x2f\x2a\xe8\xc3\x5a",
-               .input  = zeroed_string,
-               .ilen   = 16,
-               .result = "\xd4\x91\xdb\x16\xe7\xb1\xc3\x9e"
-                         "\x86\xcb\x08\x6b\x78\x9f\x54\x19",
-               .rlen   = 16,
-       }, {
-               .key    = zeroed_string,
-               .klen   = 16,
-               .iv     = "\xd4\x91\xdb\x16\xe7\xb1\xc3\x9e"
-                         "\x86\xcb\x08\x6b\x78\x9f\x54\x19",
-               .input  = zeroed_string,
-               .ilen   = 16,
-               .result = "\x05\xef\x8c\x61\xa8\x11\x58\x26"
-                         "\x34\xba\x5c\xb7\x10\x6a\xa6\x41",
-               .rlen   = 16,
-       }, {
-               .key    = zeroed_string,
-               .klen   = 16,
-               .iv     = zeroed_string,
-               .input  = zeroed_string,
-               .ilen   = 48,
-               .result = "\x9f\x58\x9f\x5c\xf6\x12\x2c\x32"
-                         "\xb6\xbf\xec\x2f\x2a\xe8\xc3\x5a"
-                         "\xd4\x91\xdb\x16\xe7\xb1\xc3\x9e"
-                         "\x86\xcb\x08\x6b\x78\x9f\x54\x19"
-                         "\x05\xef\x8c\x61\xa8\x11\x58\x26"
-                         "\x34\xba\x5c\xb7\x10\x6a\xa6\x41",
-               .rlen   = 48,
-       },
-};
-
-static struct cipher_testvec tf_cbc_dec_tv_template[] = {
-       { /* Reverse of the first four above */
-               .key    = zeroed_string,
-               .klen   = 16,
-               .iv     = zeroed_string,
-               .input  = "\x9f\x58\x9f\x5c\xf6\x12\x2c\x32"
-                         "\xb6\xbf\xec\x2f\x2a\xe8\xc3\x5a",
-               .ilen   = 16,
-               .result = zeroed_string,
-               .rlen   = 16,
-       }, {
-               .key    = zeroed_string,
-               .klen   = 16,
-               .iv     = "\x9f\x58\x9f\x5c\xf6\x12\x2c\x32"
-                         "\xb6\xbf\xec\x2f\x2a\xe8\xc3\x5a",
-               .input  = "\xd4\x91\xdb\x16\xe7\xb1\xc3\x9e"
-                         "\x86\xcb\x08\x6b\x78\x9f\x54\x19",
-               .ilen   = 16,
-               .result = zeroed_string,
-               .rlen   = 16,
-       }, {
-               .key    = zeroed_string,
-               .klen   = 16,
-               .iv     = "\xd4\x91\xdb\x16\xe7\xb1\xc3\x9e"
-                         "\x86\xcb\x08\x6b\x78\x9f\x54\x19",
-               .input  = "\x05\xef\x8c\x61\xa8\x11\x58\x26"
-                         "\x34\xba\x5c\xb7\x10\x6a\xa6\x41",
-               .ilen   = 16,
-               .result = zeroed_string,
-               .rlen   = 16,
-       }, {
-               .key    = zeroed_string,
-               .klen   = 16,
-               .iv     = zeroed_string,
-               .input  = "\x9f\x58\x9f\x5c\xf6\x12\x2c\x32"
-                         "\xb6\xbf\xec\x2f\x2a\xe8\xc3\x5a"
-                         "\xd4\x91\xdb\x16\xe7\xb1\xc3\x9e"
-                         "\x86\xcb\x08\x6b\x78\x9f\x54\x19"
-                         "\x05\xef\x8c\x61\xa8\x11\x58\x26"
-                         "\x34\xba\x5c\xb7\x10\x6a\xa6\x41",
-               .ilen   = 48,
-               .result = zeroed_string,
-               .rlen   = 48,
-       },
-};
-
-/*
- * Serpent test vectors.  These are backwards because Serpent writes
- * octet sequences in right-to-left mode.
- */
-#define SERPENT_ENC_TEST_VECTORS       4
-#define SERPENT_DEC_TEST_VECTORS       4
-
-#define TNEPRES_ENC_TEST_VECTORS       4
-#define TNEPRES_DEC_TEST_VECTORS       4
-
-static struct cipher_testvec serpent_enc_tv_template[] = {
-       {
-               .input  = "\x00\x01\x02\x03\x04\x05\x06\x07"
-                         "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",
-               .ilen   = 16,
-               .result = "\x12\x07\xfc\xce\x9b\xd0\xd6\x47"
-                         "\x6a\xe9\x8f\xbe\xd1\x43\xa0\xe2",
-               .rlen   = 16,
-       }, {
-               .key    = "\x00\x01\x02\x03\x04\x05\x06\x07"
-                         "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",
-               .klen   = 16,
-               .input  = "\x00\x01\x02\x03\x04\x05\x06\x07"
-                         "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",
-               .ilen   = 16,
-               .result = "\x4c\x7d\x8a\x32\x80\x72\xa2\x2c"
-                         "\x82\x3e\x4a\x1f\x3a\xcd\xa1\x6d",
-               .rlen   = 16,
-       }, {
-               .key    = "\x00\x01\x02\x03\x04\x05\x06\x07"
-                         "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
-                         "\x10\x11\x12\x13\x14\x15\x16\x17"
-                         "\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f",
-               .klen   = 32,
-               .input  = "\x00\x01\x02\x03\x04\x05\x06\x07"
-                         "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",
-               .ilen   = 16,
-               .result = "\xde\x26\x9f\xf8\x33\xe4\x32\xb8"
-                         "\x5b\x2e\x88\xd2\x70\x1c\xe7\x5c",
-               .rlen   = 16,
-       }, {
-               .key    = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80",
-               .klen   = 16,
-               .input  = zeroed_string,
-               .ilen   = 16,
-               .result = "\xdd\xd2\x6b\x98\xa5\xff\xd8\x2c"
-                         "\x05\x34\x5a\x9d\xad\xbf\xaf\x49",
-               .rlen   = 16,
-       },
-};
-
-static struct cipher_testvec tnepres_enc_tv_template[] = {
-       { /* KeySize=128, PT=0, I=1 */
-               .input  = "\x00\x00\x00\x00\x00\x00\x00\x00"
-                         "\x00\x00\x00\x00\x00\x00\x00\x00",
-               .key    = "\x80\x00\x00\x00\x00\x00\x00\x00"
-                         "\x00\x00\x00\x00\x00\x00\x00\x00",
-               .klen   = 16,
-               .ilen   = 16,
-               .result = "\x49\xaf\xbf\xad\x9d\x5a\x34\x05"
-                         "\x2c\xd8\xff\xa5\x98\x6b\xd2\xdd",
-               .rlen   = 16,
-       }, { /* KeySize=192, PT=0, I=1 */
-               .key    = "\x80\x00\x00\x00\x00\x00\x00\x00"
-                         "\x00\x00\x00\x00\x00\x00\x00\x00"
-                         "\x00\x00\x00\x00\x00\x00\x00\x00",
-               .klen   = 24,
-               .input  = "\x00\x00\x00\x00\x00\x00\x00\x00"
-                         "\x00\x00\x00\x00\x00\x00\x00\x00",
-               .ilen   = 16,
-               .result = "\xe7\x8e\x54\x02\xc7\x19\x55\x68"
-                         "\xac\x36\x78\xf7\xa3\xf6\x0c\x66",
-               .rlen   = 16,
-       }, { /* KeySize=256, PT=0, I=1 */
-               .key    = "\x80\x00\x00\x00\x00\x00\x00\x00"
-                         "\x00\x00\x00\x00\x00\x00\x00\x00"
-                         "\x00\x00\x00\x00\x00\x00\x00\x00"
-                         "\x00\x00\x00\x00\x00\x00\x00\x00",
-               .klen   = 32,
-               .input  = "\x00\x00\x00\x00\x00\x00\x00\x00"
-                         "\x00\x00\x00\x00\x00\x00\x00\x00",
-               .ilen   = 16,
-               .result = "\xab\xed\x96\xe7\x66\xbf\x28\xcb"
-                         "\xc0\xeb\xd2\x1a\x82\xef\x08\x19",
-               .rlen   = 16,
-       }, { /* KeySize=256, I=257 */
-               .key    = "\x1f\x1e\x1d\x1c\x1b\x1a\x19\x18"
-                         "\x17\x16\x15\x14\x13\x12\x11\x10"
-                         "\x0f\x0e\x0d\x0c\x0b\x0a\x09\x08"
-                         "\x07\x06\x05\x04\x03\x02\x01\x00",
-               .klen   = 32,
-               .input  = "\x0f\x0e\x0d\x0c\x0b\x0a\x09\x08"
-                         "\x07\x06\x05\x04\x03\x02\x01\x00",
-               .ilen   = 16,
-               .result = "\x5c\xe7\x1c\x70\xd2\x88\x2e\x5b"
-                         "\xb8\x32\xe4\x33\xf8\x9f\x26\xde",
-               .rlen   = 16,
-       },
-};
-
-
-static struct cipher_testvec serpent_dec_tv_template[] = {
-       {
-               .input  = "\x12\x07\xfc\xce\x9b\xd0\xd6\x47"
-                         "\x6a\xe9\x8f\xbe\xd1\x43\xa0\xe2",
-               .ilen   = 16,
-               .result = "\x00\x01\x02\x03\x04\x05\x06\x07"
-                         "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",
-               .rlen   = 16,
-       }, {
-               .key    = "\x00\x01\x02\x03\x04\x05\x06\x07"
-                         "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",
-               .klen   = 16,
-               .input  = "\x4c\x7d\x8a\x32\x80\x72\xa2\x2c"
-                         "\x82\x3e\x4a\x1f\x3a\xcd\xa1\x6d",
-               .ilen   = 16,
-               .result = "\x00\x01\x02\x03\x04\x05\x06\x07"
-                         "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",
-               .rlen   = 16,
-       }, {
-               .key    = "\x00\x01\x02\x03\x04\x05\x06\x07"
-                         "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
-                         "\x10\x11\x12\x13\x14\x15\x16\x17"
-                         "\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f",
-               .klen   = 32,
-               .input  = "\xde\x26\x9f\xf8\x33\xe4\x32\xb8"
-                         "\x5b\x2e\x88\xd2\x70\x1c\xe7\x5c",
-               .ilen   = 16,
-               .result = "\x00\x01\x02\x03\x04\x05\x06\x07"
-                         "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",
-               .rlen   = 16,
-       }, {
-               .key    = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80",
-               .klen   = 16,
-               .input  = "\xdd\xd2\x6b\x98\xa5\xff\xd8\x2c"
-                         "\x05\x34\x5a\x9d\xad\xbf\xaf\x49",
-               .ilen   = 16,
-               .result = zeroed_string,
-               .rlen   = 16,
-       },
-};
-
-static struct cipher_testvec tnepres_dec_tv_template[] = {
-       {
-               .input  = "\x41\xcc\x6b\x31\x59\x31\x45\x97"
-                         "\x6d\x6f\xbb\x38\x4b\x37\x21\x28",
-               .ilen   = 16,
-               .result = "\x00\x01\x02\x03\x04\x05\x06\x07"
-                         "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",
-               .rlen   = 16,
-       }, {
-               .key    = "\x00\x01\x02\x03\x04\x05\x06\x07"
-                         "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",
-               .klen   = 16,
-               .input  = "\xea\xf4\xd7\xfc\xd8\x01\x34\x47"
-                         "\x81\x45\x0b\xfa\x0c\xd6\xad\x6e",
-               .ilen   = 16,
-               .result = "\x00\x01\x02\x03\x04\x05\x06\x07"
-                         "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",
-               .rlen   = 16,
-       }, {
-               .key    = "\x00\x01\x02\x03\x04\x05\x06\x07"
-                         "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
-                         "\x10\x11\x12\x13\x14\x15\x16\x17"
-                         "\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f",
-               .klen   = 32,
-               .input  = "\x64\xa9\x1a\x37\xed\x9f\xe7\x49"
-                         "\xa8\x4e\x76\xd6\xf5\x0d\x78\xee",
-               .ilen   = 16,
-               .result = "\x00\x01\x02\x03\x04\x05\x06\x07"
-                         "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",
-               .rlen   = 16,
-       }, { /* KeySize=128, I=121 */
-               .key    = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80",
-               .klen   = 16,
-               .input  = "\x3d\xda\xbf\xc0\x06\xda\xab\x06"
-                         "\x46\x2a\xf4\xef\x81\x54\x4e\x26",
-               .ilen   = 16,
-               .result = zeroed_string,
-               .rlen   = 16,
-       },
-};
-
-
-/* Cast6 test vectors from RFC 2612 */
-#define CAST6_ENC_TEST_VECTORS 3
-#define CAST6_DEC_TEST_VECTORS  3
-
-static struct cipher_testvec cast6_enc_tv_template[] = {
-       {
-               .key    = "\x23\x42\xbb\x9e\xfa\x38\x54\x2c"
-                         "\x0a\xf7\x56\x47\xf2\x9f\x61\x5d",
-               .klen   = 16,
-               .input  = zeroed_string,
-               .ilen   = 16,
-               .result = "\xc8\x42\xa0\x89\x72\xb4\x3d\x20"
-                         "\x83\x6c\x91\xd1\xb7\x53\x0f\x6b",
-               .rlen   = 16,
-       }, {
-               .key    = "\x23\x42\xbb\x9e\xfa\x38\x54\x2c"
-                         "\xbe\xd0\xac\x83\x94\x0a\xc2\x98"
-                         "\xba\xc7\x7a\x77\x17\x94\x28\x63",
-               .klen   = 24,
-               .input  = zeroed_string,
-               .ilen   = 16,
-               .result = "\x1b\x38\x6c\x02\x10\xdc\xad\xcb"
-                         "\xdd\x0e\x41\xaa\x08\xa7\xa7\xe8",
-               .rlen   = 16,
-       }, {
-               .key    = "\x23\x42\xbb\x9e\xfa\x38\x54\x2c"
-                         "\xbe\xd0\xac\x83\x94\x0a\xc2\x98"
-                         "\x8d\x7c\x47\xce\x26\x49\x08\x46"
-                         "\x1c\xc1\xb5\x13\x7a\xe6\xb6\x04",
-               .klen   = 32,
-               .input  = zeroed_string,
-               .ilen   = 16,
-               .result = "\x4f\x6a\x20\x38\x28\x68\x97\xb9"
-                         "\xc9\x87\x01\x36\x55\x33\x17\xfa",
-               .rlen   = 16,
-       },
-};
-
-static struct cipher_testvec cast6_dec_tv_template[] = {
-       {
-               .key    = "\x23\x42\xbb\x9e\xfa\x38\x54\x2c"
-                         "\x0a\xf7\x56\x47\xf2\x9f\x61\x5d",
-               .klen   = 16,
-               .input  = "\xc8\x42\xa0\x89\x72\xb4\x3d\x20"
-                         "\x83\x6c\x91\xd1\xb7\x53\x0f\x6b",
-               .ilen   = 16,
-               .result = zeroed_string,
-               .rlen   = 16,
-       }, {
-               .key    = "\x23\x42\xbb\x9e\xfa\x38\x54\x2c"
-                         "\xbe\xd0\xac\x83\x94\x0a\xc2\x98"
-                         "\xba\xc7\x7a\x77\x17\x94\x28\x63",
-               .klen   = 24,
-               .input  = "\x1b\x38\x6c\x02\x10\xdc\xad\xcb"
-                         "\xdd\x0e\x41\xaa\x08\xa7\xa7\xe8",
-               .ilen   = 16,
-               .result = zeroed_string,
-               .rlen   = 16,
-       }, {
-               .key    = "\x23\x42\xbb\x9e\xfa\x38\x54\x2c"
-                         "\xbe\xd0\xac\x83\x94\x0a\xc2\x98"
-                         "\x8d\x7c\x47\xce\x26\x49\x08\x46"
-                         "\x1c\xc1\xb5\x13\x7a\xe6\xb6\x04",
-               .klen   = 32,
-               .input  = "\x4f\x6a\x20\x38\x28\x68\x97\xb9"
-                         "\xc9\x87\x01\x36\x55\x33\x17\xfa",
-               .ilen   = 16,
-               .result = zeroed_string,
-               .rlen   = 16,
-       },
-};
-
-
-/*
- * AES test vectors.
- */
-#define AES_ENC_TEST_VECTORS 3
-#define AES_DEC_TEST_VECTORS 3
-#define AES_CBC_ENC_TEST_VECTORS 4
-#define AES_CBC_DEC_TEST_VECTORS 4
-#define AES_LRW_ENC_TEST_VECTORS 8
-#define AES_LRW_DEC_TEST_VECTORS 8
-#define AES_XTS_ENC_TEST_VECTORS 4
-#define AES_XTS_DEC_TEST_VECTORS 4
-#define AES_CTR_ENC_TEST_VECTORS 7
-#define AES_CTR_DEC_TEST_VECTORS 6
-#define AES_GCM_ENC_TEST_VECTORS 9
-#define AES_GCM_DEC_TEST_VECTORS 8
-#define AES_CCM_ENC_TEST_VECTORS 7
-#define AES_CCM_DEC_TEST_VECTORS 7
-
-static struct cipher_testvec aes_enc_tv_template[] = {
-       { /* From FIPS-197 */
-               .key    = "\x00\x01\x02\x03\x04\x05\x06\x07"
-                         "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",
-               .klen   = 16,
-               .input  = "\x00\x11\x22\x33\x44\x55\x66\x77"
-                         "\x88\x99\xaa\xbb\xcc\xdd\xee\xff",
-               .ilen   = 16,
-               .result = "\x69\xc4\xe0\xd8\x6a\x7b\x04\x30"
-                         "\xd8\xcd\xb7\x80\x70\xb4\xc5\x5a",
-               .rlen   = 16,
-       }, {
-               .key    = "\x00\x01\x02\x03\x04\x05\x06\x07"
-                         "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
-                         "\x10\x11\x12\x13\x14\x15\x16\x17",
-               .klen   = 24,
-               .input  = "\x00\x11\x22\x33\x44\x55\x66\x77"
-                         "\x88\x99\xaa\xbb\xcc\xdd\xee\xff",
-               .ilen   = 16,
-               .result = "\xdd\xa9\x7c\xa4\x86\x4c\xdf\xe0"
-                         "\x6e\xaf\x70\xa0\xec\x0d\x71\x91",
-               .rlen   = 16,
-       }, {
-               .key    = "\x00\x01\x02\x03\x04\x05\x06\x07"
-                         "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
-                         "\x10\x11\x12\x13\x14\x15\x16\x17"
-                         "\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f",
-               .klen   = 32,
-               .input  = "\x00\x11\x22\x33\x44\x55\x66\x77"
-                         "\x88\x99\xaa\xbb\xcc\xdd\xee\xff",
-               .ilen   = 16,
-               .result = "\x8e\xa2\xb7\xca\x51\x67\x45\xbf"
-                         "\xea\xfc\x49\x90\x4b\x49\x60\x89",
-               .rlen   = 16,
-       },
-};
-
-static struct cipher_testvec aes_dec_tv_template[] = {
-       { /* From FIPS-197 */
-               .key    = "\x00\x01\x02\x03\x04\x05\x06\x07"
-                         "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",
-               .klen   = 16,
-               .input  = "\x69\xc4\xe0\xd8\x6a\x7b\x04\x30"
-                         "\xd8\xcd\xb7\x80\x70\xb4\xc5\x5a",
-               .ilen   = 16,
-               .result = "\x00\x11\x22\x33\x44\x55\x66\x77"
-                         "\x88\x99\xaa\xbb\xcc\xdd\xee\xff",
-               .rlen   = 16,
-       }, {
-               .key    = "\x00\x01\x02\x03\x04\x05\x06\x07"
-                   &n