}
 
 static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
-                      unsigned int key_len, u32 *flags)
+                      unsigned int key_len)
 {
        int i;
        u32 ss[8];
        struct aes_ctx *ctx = crypto_tfm_ctx(tfm);
        const __le32 *key = (const __le32 *)in_key;
+       u32 *flags = &tfm->crt_flags;
 
        /* encryption schedule */
        
 
 };
 
 static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
-                      unsigned int key_len, u32 *flags)
+                      unsigned int key_len)
 {
        struct s390_aes_ctx *sctx = crypto_tfm_ctx(tfm);
+       u32 *flags = &tfm->crt_flags;
 
        switch (key_len) {
        case 16:
 
 };
 
 static int des_setkey(struct crypto_tfm *tfm, const u8 *key,
-                     unsigned int keylen, u32 *flags)
+                     unsigned int keylen)
 {
        struct crypt_s390_des_ctx *dctx = crypto_tfm_ctx(tfm);
+       u32 *flags = &tfm->crt_flags;
        int ret;
 
        /* test if key is valid (not a weak key) */
  *
  */
 static int des3_128_setkey(struct crypto_tfm *tfm, const u8 *key,
-                          unsigned int keylen, u32 *flags)
+                          unsigned int keylen)
 {
        int i, ret;
        struct crypt_s390_des3_128_ctx *dctx = crypto_tfm_ctx(tfm);
-       const u8* temp_key = key;
+       const u8 *temp_key = key;
+       u32 *flags = &tfm->crt_flags;
 
        if (!(memcmp(key, &key[DES_KEY_SIZE], DES_KEY_SIZE))) {
                *flags |= CRYPTO_TFM_RES_BAD_KEY_SCHED;
  *
  */
 static int des3_192_setkey(struct crypto_tfm *tfm, const u8 *key,
-                          unsigned int keylen, u32 *flags)
+                          unsigned int keylen)
 {
        int i, ret;
        struct crypt_s390_des3_192_ctx *dctx = crypto_tfm_ctx(tfm);
-       const u8* temp_key = key;
+       const u8 *temp_key = key;
+       u32 *flags = &tfm->crt_flags;
 
        if (!(memcmp(key, &key[DES_KEY_SIZE], DES_KEY_SIZE) &&
            memcmp(&key[DES_KEY_SIZE], &key[DES_KEY_SIZE * 2],
 
 }
 
 static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
-                      unsigned int key_len, u32 *flags)
+                      unsigned int key_len)
 {
        struct aes_ctx *ctx = crypto_tfm_ctx(tfm);
        const __le32 *key = (const __le32 *)in_key;
+       u32 *flags = &tfm->crt_flags;
        u32 i, j, t, u, v, w;
 
-       if (key_len != 16 && key_len != 24 && key_len != 32) {
+       if (key_len % 8) {
                *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
                return -EINVAL;
        }
 
 }
 
 static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
-                      unsigned int key_len, u32 *flags)
+                      unsigned int key_len)
 {
        struct aes_ctx *ctx = crypto_tfm_ctx(tfm);
        const __le32 *key = (const __le32 *)in_key;
+       u32 *flags = &tfm->crt_flags;
        u32 i, t, u, v, w;
 
-       if (key_len != 16 && key_len != 24 && key_len != 32) {
+       if (key_len % 8) {
                *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
                return -EINVAL;
        }
 
 };
 
 static int anubis_setkey(struct crypto_tfm *tfm, const u8 *in_key,
-                        unsigned int key_len, u32 *flags)
+                        unsigned int key_len)
 {
        struct anubis_ctx *ctx = crypto_tfm_ctx(tfm);
        const __be32 *key = (const __be32 *)in_key;
+       u32 *flags = &tfm->crt_flags;
        int N, R, i, r;
        u32 kappa[ANUBIS_MAX_N];
        u32 inter[ANUBIS_MAX_N];
 
 };
 
 static int arc4_set_key(struct crypto_tfm *tfm, const u8 *in_key,
-                       unsigned int key_len, u32 *flags)
+                       unsigned int key_len)
 {
        struct arc4_ctx *ctx = crypto_tfm_ctx(tfm);
        int i, j = 0, k = 0;
 
 /* 
  * Calculates the blowfish S and P boxes for encryption and decryption.
  */
-static int bf_setkey(struct crypto_tfm *tfm, const u8 *key,
-                    unsigned int keylen, u32 *flags)
+static int bf_setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen)
 {
        struct bf_ctx *ctx = crypto_tfm_ctx(tfm);
        u32 *P = ctx->p;
 
 }
 
 
-static int cast5_setkey(struct crypto_tfm *tfm, const u8 *key,
-                       unsigned key_len, u32 *flags)
+static int cast5_setkey(struct crypto_tfm *tfm, const u8 *key, unsigned key_len)
 {
        struct cast5_ctx *c = crypto_tfm_ctx(tfm);
        int i;
        u32 z[4];
        u32 k[16];
        __be32 p_key[4];
-       
-       if (key_len < 5 || key_len > 16) {
-               *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
-               return -EINVAL;
-       }
 
        c->rr = key_len <= 10 ? 1 : 0;
 
 
 }
 
 static int cast6_setkey(struct crypto_tfm *tfm, const u8 *in_key,
-                       unsigned key_len, u32 *flags)
+                       unsigned key_len)
 {
        int i;
        u32 key[8];
        __be32 p_key[8]; /* padded key */
        struct cast6_ctx *c = crypto_tfm_ctx(tfm);
+       u32 *flags = &tfm->crt_flags;
 
-       if (key_len < 16 || key_len > 32 || key_len % 4 != 0) {
+       if (key_len % 4 != 0) {
                *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
                return -EINVAL;
        }       
 
 {
        struct cipher_alg *cia = &tfm->__crt_alg->cra_cipher;
        
+       tfm->crt_flags &= ~CRYPTO_TFM_RES_MASK;
        if (keylen < cia->cia_min_keysize || keylen > cia->cia_max_keysize) {
                tfm->crt_flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
                return -EINVAL;
        } else
-               return cia->cia_setkey(tfm, key, keylen,
-                                      &tfm->crt_flags);
+               return cia->cia_setkey(tfm, key, keylen);
 }
 
 static int ecb_encrypt(struct crypto_tfm *tfm,
 
  * the seed.
  */
 static int chksum_setkey(struct crypto_tfm *tfm, const u8 *key,
-                        unsigned int keylen, u32 *flags)
+                        unsigned int keylen)
 {
        struct chksum_ctx *mctx = crypto_tfm_ctx(tfm);
 
        if (keylen != sizeof(mctx->crc)) {
-               if (flags)
-                       *flags = CRYPTO_TFM_RES_BAD_KEY_LEN;
+               tfm->crt_flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
                return -EINVAL;
        }
        mctx->key = le32_to_cpu(*(__le32 *)key);
 
 { }
 
 static int null_setkey(struct crypto_tfm *tfm, const u8 *key,
-                      unsigned int keylen, u32 *flags)
+                      unsigned int keylen)
 { return 0; }
 
 static void null_crypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
 
 }
 
 static int des_setkey(struct crypto_tfm *tfm, const u8 *key,
-                     unsigned int keylen, u32 *flags)
+                     unsigned int keylen)
 {
        struct des_ctx *dctx = crypto_tfm_ctx(tfm);
+       u32 *flags = &tfm->crt_flags;
        u32 tmp[DES_EXPKEY_WORDS];
        int ret;
 
  *
  */
 static int des3_ede_setkey(struct crypto_tfm *tfm, const u8 *key,
-                          unsigned int keylen, u32 *flags)
+                          unsigned int keylen)
 {
        const u32 *K = (const u32 *)key;
        struct des3_ede_ctx *dctx = crypto_tfm_ctx(tfm);
        u32 *expkey = dctx->expkey;
+       u32 *flags = &tfm->crt_flags;
 
        if (unlikely(!((K[0] ^ K[2]) | (K[1] ^ K[3])) ||
                     !((K[2] ^ K[4]) | (K[3] ^ K[5]))))
 
                tfm->__crt_alg->cra_digest.dia_final(tfm, out);
 }
 
+static int nosetkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen)
+{
+       tfm->crt_flags &= ~CRYPTO_TFM_RES_MASK;
+       return -ENOSYS;
+}
+
 static int setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen)
 {
-       u32 flags;
-       if (tfm->__crt_alg->cra_digest.dia_setkey == NULL)
-               return -ENOSYS;
-       return tfm->__crt_alg->cra_digest.dia_setkey(tfm, key, keylen, &flags);
+       tfm->crt_flags &= ~CRYPTO_TFM_RES_MASK;
+       return tfm->__crt_alg->cra_digest.dia_setkey(tfm, key, keylen);
 }
 
 static void digest(struct crypto_tfm *tfm,
 int crypto_init_digest_ops(struct crypto_tfm *tfm)
 {
        struct digest_tfm *ops = &tfm->crt_digest;
+       struct digest_alg *dalg = &tfm->__crt_alg->cra_digest;
        
        ops->dit_init   = init;
        ops->dit_update = update;
        ops->dit_final  = final;
        ops->dit_digest = digest;
-       ops->dit_setkey = setkey;
+       ops->dit_setkey = dalg->dia_setkey ? setkey : nosetkey;
        
        return crypto_alloc_hmac_block(tfm);
 }
 
 };
 
 static int khazad_setkey(struct crypto_tfm *tfm, const u8 *in_key,
-                        unsigned int key_len, u32 *flags)
+                        unsigned int key_len)
 {
        struct khazad_ctx *ctx = crypto_tfm_ctx(tfm);
        const __be32 *key = (const __be32 *)in_key;
        int r;
        const u64 *S = T7;
        u64 K2, K1;
-       
-       if (key_len != 16)
-       {
-               *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
-               return -EINVAL;
-       }
 
        /* key is supposed to be 32-bit aligned */
        K2 = ((u64)be32_to_cpu(key[0]) << 32) | be32_to_cpu(key[1]);
 
 
 
 static int michael_setkey(struct crypto_tfm *tfm, const u8 *key,
-                         unsigned int keylen, u32 *flags)
+                         unsigned int keylen)
 {
        struct michael_mic_ctx *mctx = crypto_tfm_ctx(tfm);
        const __le32 *data = (const __le32 *)key;
 
        if (keylen != 8) {
-               if (flags)
-                       *flags = CRYPTO_TFM_RES_BAD_KEY_LEN;
+               tfm->crt_flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
                return -EINVAL;
        }
 
 
 
 
 static int serpent_setkey(struct crypto_tfm *tfm, const u8 *key,
-                         unsigned int keylen, u32 *flags)
+                         unsigned int keylen)
 {
        struct serpent_ctx *ctx = crypto_tfm_ctx(tfm);
        u32 *k = ctx->expkey;
        u32 r0,r1,r2,r3,r4;
        int i;
 
-       if ((keylen < SERPENT_MIN_KEY_SIZE)
-                       || (keylen > SERPENT_MAX_KEY_SIZE))
-       {
-               *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
-               return -EINVAL;
-       }
-
        /* Copy key, add padding */
 
        for (i = 0; i < keylen; ++i)
 };
 
 static int tnepres_setkey(struct crypto_tfm *tfm, const u8 *key,
-                         unsigned int keylen, u32 *flags)
+                         unsigned int keylen)
 {
        u8 rev_key[SERPENT_MAX_KEY_SIZE];
        int i;
 
-       if ((keylen < SERPENT_MIN_KEY_SIZE)
-           || (keylen > SERPENT_MAX_KEY_SIZE)) {
-               *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
-               return -EINVAL;
-       } 
-
        for (i = 0; i < keylen; ++i)
                rev_key[keylen - i - 1] = key[i];
  
-       return serpent_setkey(tfm, rev_key, keylen, flags);
+       return serpent_setkey(tfm, rev_key, keylen);
 }
 
 static void tnepres_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
 
                sg_set_buf(&sg[0], hash_tv[i].plaintext, hash_tv[i].psize);
 
                crypto_digest_init(tfm);
-               if (tfm->crt_u.digest.dit_setkey) {
-                       crypto_digest_setkey(tfm, hash_tv[i].key,
-                                            hash_tv[i].ksize);
-               }
+               crypto_digest_setkey(tfm, hash_tv[i].key, hash_tv[i].ksize);
                crypto_digest_update(tfm, sg, 1);
                crypto_digest_final(tfm, result);
 
 
 };
 
 static int tea_setkey(struct crypto_tfm *tfm, const u8 *in_key,
-                     unsigned int key_len, u32 *flags)
+                     unsigned int key_len)
 {
        struct tea_ctx *ctx = crypto_tfm_ctx(tfm);
        const __le32 *key = (const __le32 *)in_key;
-       
-       if (key_len != 16)
-       {
-               *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
-               return -EINVAL;
-       }
 
        ctx->KEY[0] = le32_to_cpu(key[0]);
        ctx->KEY[1] = le32_to_cpu(key[1]);
 }
 
 static int xtea_setkey(struct crypto_tfm *tfm, const u8 *in_key,
-                      unsigned int key_len, u32 *flags)
+                      unsigned int key_len)
 {
        struct xtea_ctx *ctx = crypto_tfm_ctx(tfm);
        const __le32 *key = (const __le32 *)in_key;
-       
-       if (key_len != 16)
-       {
-               *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
-               return -EINVAL;
-       }
 
        ctx->KEY[0] = le32_to_cpu(key[0]);
        ctx->KEY[1] = le32_to_cpu(key[1]);
 
    ctx->a[(j) + 1] = rol32(y, 9)
 
 /* Perform the key setup. */
-int twofish_setkey(struct crypto_tfm *tfm, const u8 *key,
-                  unsigned int key_len, u32 *flags)
+int twofish_setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int key_len)
 {
 
        struct twofish_ctx *ctx = crypto_tfm_ctx(tfm);
+       u32 *flags = &tfm->crt_flags;
 
        int i, j, k;
 
        u8 tmp;
 
        /* Check key length. */
-       if (key_len != 16 && key_len != 24 && key_len != 32)
+       if (key_len % 8)
        {
                *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
                return -EINVAL; /* unsupported key length */
 
 }
 
 static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
-                      unsigned int key_len, u32 *flags)
+                      unsigned int key_len)
 {
        struct aes_ctx *ctx = aes_ctx(tfm);
        const __le32 *key = (const __le32 *)in_key;
+       u32 *flags = &tfm->crt_flags;
        uint32_t i, t, u, v, w;
        uint32_t P[AES_EXTENDED_KEY_SIZE];
        uint32_t rounds;
 
-       if (key_len != 16 && key_len != 24 && key_len != 32) {
+       if (key_len % 8) {
                *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
                return -EINVAL;
        }
 
        u32 s[4][256], w[8], k[32];
 };
 
-int twofish_setkey(struct crypto_tfm *tfm, const u8 *key,
-                  unsigned int key_len, u32 *flags);
+int twofish_setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int key_len);
 
 #endif
 
        unsigned int cia_min_keysize;
        unsigned int cia_max_keysize;
        int (*cia_setkey)(struct crypto_tfm *tfm, const u8 *key,
-                         unsigned int keylen, u32 *flags);
+                         unsigned int keylen);
        void (*cia_encrypt)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
        void (*cia_decrypt)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
 
                           unsigned int len);
        void (*dia_final)(struct crypto_tfm *tfm, u8 *out);
        int (*dia_setkey)(struct crypto_tfm *tfm, const u8 *key,
-                         unsigned int keylen, u32 *flags);
+                         unsigned int keylen);
 };
 
 struct compress_alg {
                                        const u8 *key, unsigned int keylen)
 {
        BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_DIGEST);
-       if (tfm->crt_digest.dit_setkey == NULL)
-               return -ENOSYS;
        return tfm->crt_digest.dit_setkey(tfm, key, keylen);
 }