crypto: remove CRYPTO_TFM_RES_BAD_KEY_LEN

The CRYPTO_TFM_RES_BAD_KEY_LEN flag was apparently meant as a way to
make the ->setkey() functions provide more information about errors.

However, no one actually checks for this flag, which makes it pointless.

Also, many algorithms fail to set this flag when given a bad length key.
Reviewing just the generic implementations, this is the case for
aes-fixed-time, cbcmac, echainiv, nhpoly1305, pcrypt, rfc3686, rfc4309,
rfc7539, rfc7539esp, salsa20, seqiv, and xcbc.  But there are probably
many more in arch/*/crypto/ and drivers/crypto/.

Some algorithms can even set this flag when the key is the correct
length.  For example, authenc and authencesn set it when the key payload
is malformed in any way (not just a bad length), the atmel-sha and ccree
drivers can set it if a memory allocation fails, and the chelsio driver
sets it for bad auth tag lengths, not just bad key lengths.

So even if someone actually wanted to start checking this flag (which
seems unlikely, since it's been unused for a long time), there would be
a lot of work needed to get it working correctly.  But it would probably
be much better to go back to the drawing board and just define different
return values, like -EINVAL if the key is invalid for the algorithm vs.
-EKEYREJECTED if the key was rejected by a policy like "no weak keys".
That would be much simpler, less error-prone, and easier to test.

So just remove this flag.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Reviewed-by: Horia Geantă <horia.geanta@nxp.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
Eric Biggers 2019-12-30 21:19:36 -06:00 committed by Herbert Xu
parent 5c925e8b10
commit 674f368a95
93 changed files with 167 additions and 561 deletions

View File

@ -138,14 +138,8 @@ static int ce_aes_setkey(struct crypto_skcipher *tfm, const u8 *in_key,
unsigned int key_len) unsigned int key_len)
{ {
struct crypto_aes_ctx *ctx = crypto_skcipher_ctx(tfm); struct crypto_aes_ctx *ctx = crypto_skcipher_ctx(tfm);
int ret;
ret = ce_aes_expandkey(ctx, in_key, key_len); return ce_aes_expandkey(ctx, in_key, key_len);
if (!ret)
return 0;
crypto_skcipher_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL;
} }
struct crypto_aes_xts_ctx { struct crypto_aes_xts_ctx {
@ -167,11 +161,7 @@ static int xts_set_key(struct crypto_skcipher *tfm, const u8 *in_key,
if (!ret) if (!ret)
ret = ce_aes_expandkey(&ctx->key2, &in_key[key_len / 2], ret = ce_aes_expandkey(&ctx->key2, &in_key[key_len / 2],
key_len / 2); key_len / 2);
if (!ret) return ret;
return 0;
crypto_skcipher_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL;
} }
static int ecb_encrypt(struct skcipher_request *req) static int ecb_encrypt(struct skcipher_request *req)

View File

@ -54,10 +54,8 @@ static int crc32_setkey(struct crypto_shash *hash, const u8 *key,
{ {
u32 *mctx = crypto_shash_ctx(hash); u32 *mctx = crypto_shash_ctx(hash);
if (keylen != sizeof(u32)) { if (keylen != sizeof(u32))
crypto_shash_set_flags(hash, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
}
*mctx = le32_to_cpup((__le32 *)key); *mctx = le32_to_cpup((__le32 *)key);
return 0; return 0;
} }

View File

@ -163,10 +163,8 @@ static int ghash_setkey(struct crypto_shash *tfm,
struct ghash_key *key = crypto_shash_ctx(tfm); struct ghash_key *key = crypto_shash_ctx(tfm);
be128 h; be128 h;
if (keylen != GHASH_BLOCK_SIZE) { if (keylen != GHASH_BLOCK_SIZE)
crypto_shash_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
}
/* needed for the fallback */ /* needed for the fallback */
memcpy(&key->k, inkey, GHASH_BLOCK_SIZE); memcpy(&key->k, inkey, GHASH_BLOCK_SIZE);

View File

@ -47,14 +47,8 @@ static int ccm_setkey(struct crypto_aead *tfm, const u8 *in_key,
unsigned int key_len) unsigned int key_len)
{ {
struct crypto_aes_ctx *ctx = crypto_aead_ctx(tfm); struct crypto_aes_ctx *ctx = crypto_aead_ctx(tfm);
int ret;
ret = ce_aes_expandkey(ctx, in_key, key_len); return ce_aes_expandkey(ctx, in_key, key_len);
if (!ret)
return 0;
tfm->base.crt_flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
return -EINVAL;
} }
static int ccm_setauthsize(struct crypto_aead *tfm, unsigned int authsize) static int ccm_setauthsize(struct crypto_aead *tfm, unsigned int authsize)

View File

@ -143,14 +143,8 @@ int ce_aes_setkey(struct crypto_tfm *tfm, const u8 *in_key,
unsigned int key_len) unsigned int key_len)
{ {
struct crypto_aes_ctx *ctx = crypto_tfm_ctx(tfm); struct crypto_aes_ctx *ctx = crypto_tfm_ctx(tfm);
int ret;
ret = ce_aes_expandkey(ctx, in_key, key_len); return ce_aes_expandkey(ctx, in_key, key_len);
if (!ret)
return 0;
tfm->crt_flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
return -EINVAL;
} }
EXPORT_SYMBOL(ce_aes_setkey); EXPORT_SYMBOL(ce_aes_setkey);

View File

@ -132,13 +132,8 @@ static int skcipher_aes_setkey(struct crypto_skcipher *tfm, const u8 *in_key,
unsigned int key_len) unsigned int key_len)
{ {
struct crypto_aes_ctx *ctx = crypto_skcipher_ctx(tfm); struct crypto_aes_ctx *ctx = crypto_skcipher_ctx(tfm);
int ret;
ret = aes_expandkey(ctx, in_key, key_len); return aes_expandkey(ctx, in_key, key_len);
if (ret)
crypto_skcipher_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return ret;
} }
static int __maybe_unused xts_set_key(struct crypto_skcipher *tfm, static int __maybe_unused xts_set_key(struct crypto_skcipher *tfm,
@ -155,11 +150,7 @@ static int __maybe_unused xts_set_key(struct crypto_skcipher *tfm,
if (!ret) if (!ret)
ret = aes_expandkey(&ctx->key2, &in_key[key_len / 2], ret = aes_expandkey(&ctx->key2, &in_key[key_len / 2],
key_len / 2); key_len / 2);
if (!ret) return ret;
return 0;
crypto_skcipher_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL;
} }
static int __maybe_unused essiv_cbc_set_key(struct crypto_skcipher *tfm, static int __maybe_unused essiv_cbc_set_key(struct crypto_skcipher *tfm,
@ -173,19 +164,12 @@ static int __maybe_unused essiv_cbc_set_key(struct crypto_skcipher *tfm,
ret = aes_expandkey(&ctx->key1, in_key, key_len); ret = aes_expandkey(&ctx->key1, in_key, key_len);
if (ret) if (ret)
goto out; return ret;
desc->tfm = ctx->hash; desc->tfm = ctx->hash;
crypto_shash_digest(desc, in_key, key_len, digest); crypto_shash_digest(desc, in_key, key_len, digest);
ret = aes_expandkey(&ctx->key2, digest, sizeof(digest)); return aes_expandkey(&ctx->key2, digest, sizeof(digest));
if (ret)
goto out;
return 0;
out:
crypto_skcipher_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL;
} }
static int __maybe_unused ecb_encrypt(struct skcipher_request *req) static int __maybe_unused ecb_encrypt(struct skcipher_request *req)
@ -791,13 +775,8 @@ static int cbcmac_setkey(struct crypto_shash *tfm, const u8 *in_key,
unsigned int key_len) unsigned int key_len)
{ {
struct mac_tfm_ctx *ctx = crypto_shash_ctx(tfm); struct mac_tfm_ctx *ctx = crypto_shash_ctx(tfm);
int err;
err = aes_expandkey(&ctx->key, in_key, key_len); return aes_expandkey(&ctx->key, in_key, key_len);
if (err)
crypto_shash_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return err;
} }
static void cmac_gf128_mul_by_x(be128 *y, const be128 *x) static void cmac_gf128_mul_by_x(be128 *y, const be128 *x)

View File

@ -248,10 +248,8 @@ static int ghash_setkey(struct crypto_shash *tfm,
{ {
struct ghash_key *key = crypto_shash_ctx(tfm); struct ghash_key *key = crypto_shash_ctx(tfm);
if (keylen != GHASH_BLOCK_SIZE) { if (keylen != GHASH_BLOCK_SIZE)
crypto_shash_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
}
return __ghash_setkey(key, inkey, keylen); return __ghash_setkey(key, inkey, keylen);
} }
@ -306,10 +304,8 @@ static int gcm_setkey(struct crypto_aead *tfm, const u8 *inkey,
int ret; int ret;
ret = aes_expandkey(&ctx->aes_key, inkey, keylen); ret = aes_expandkey(&ctx->aes_key, inkey, keylen);
if (ret) { if (ret)
tfm->base.crt_flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
return -EINVAL; return -EINVAL;
}
aes_encrypt(&ctx->aes_key, key, (u8[AES_BLOCK_SIZE]){}); aes_encrypt(&ctx->aes_key, key, (u8[AES_BLOCK_SIZE]){});

View File

@ -177,10 +177,8 @@ static int chksum_setkey(struct crypto_shash *tfm, const u8 *key,
{ {
struct chksum_ctx *mctx = crypto_shash_ctx(tfm); struct chksum_ctx *mctx = crypto_shash_ctx(tfm);
if (keylen != sizeof(mctx->key)) { if (keylen != sizeof(mctx->key))
crypto_shash_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
}
mctx->key = get_unaligned_le32(key); mctx->key = get_unaligned_le32(key);
return 0; return 0;
} }

View File

@ -94,13 +94,6 @@ static int ppc_aes_setkey(struct crypto_tfm *tfm, const u8 *in_key,
{ {
struct ppc_aes_ctx *ctx = crypto_tfm_ctx(tfm); struct ppc_aes_ctx *ctx = crypto_tfm_ctx(tfm);
if (key_len != AES_KEYSIZE_128 &&
key_len != AES_KEYSIZE_192 &&
key_len != AES_KEYSIZE_256) {
tfm->crt_flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
return -EINVAL;
}
switch (key_len) { switch (key_len) {
case AES_KEYSIZE_128: case AES_KEYSIZE_128:
ctx->rounds = 4; ctx->rounds = 4;
@ -114,6 +107,8 @@ static int ppc_aes_setkey(struct crypto_tfm *tfm, const u8 *in_key,
ctx->rounds = 6; ctx->rounds = 6;
ppc_expand_key_256(ctx->key_enc, in_key); ppc_expand_key_256(ctx->key_enc, in_key);
break; break;
default:
return -EINVAL;
} }
ppc_generate_decrypt_key(ctx->key_dec, ctx->key_enc, key_len); ppc_generate_decrypt_key(ctx->key_dec, ctx->key_enc, key_len);
@ -139,13 +134,6 @@ static int ppc_xts_setkey(struct crypto_skcipher *tfm, const u8 *in_key,
key_len >>= 1; key_len >>= 1;
if (key_len != AES_KEYSIZE_128 &&
key_len != AES_KEYSIZE_192 &&
key_len != AES_KEYSIZE_256) {
crypto_skcipher_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL;
}
switch (key_len) { switch (key_len) {
case AES_KEYSIZE_128: case AES_KEYSIZE_128:
ctx->rounds = 4; ctx->rounds = 4;
@ -162,6 +150,8 @@ static int ppc_xts_setkey(struct crypto_skcipher *tfm, const u8 *in_key,
ppc_expand_key_256(ctx->key_enc, in_key); ppc_expand_key_256(ctx->key_enc, in_key);
ppc_expand_key_256(ctx->key_twk, in_key + AES_KEYSIZE_256); ppc_expand_key_256(ctx->key_twk, in_key + AES_KEYSIZE_256);
break; break;
default:
return -EINVAL;
} }
ppc_generate_decrypt_key(ctx->key_dec, ctx->key_enc, key_len); ppc_generate_decrypt_key(ctx->key_dec, ctx->key_enc, key_len);

View File

@ -73,10 +73,8 @@ static int crc32c_vpmsum_setkey(struct crypto_shash *hash, const u8 *key,
{ {
u32 *mctx = crypto_shash_ctx(hash); u32 *mctx = crypto_shash_ctx(hash);
if (keylen != sizeof(u32)) { if (keylen != sizeof(u32))
crypto_shash_set_flags(hash, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
}
*mctx = le32_to_cpup((__le32 *)key); *mctx = le32_to_cpup((__le32 *)key);
return 0; return 0;
} }

View File

@ -414,10 +414,8 @@ static int xts_aes_set_key(struct crypto_skcipher *tfm, const u8 *in_key,
return err; return err;
/* In fips mode only 128 bit or 256 bit keys are valid */ /* In fips mode only 128 bit or 256 bit keys are valid */
if (fips_enabled && key_len != 32 && key_len != 64) { if (fips_enabled && key_len != 32 && key_len != 64)
crypto_skcipher_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
}
/* Pick the correct function code based on the key length */ /* Pick the correct function code based on the key length */
fc = (key_len == 32) ? CPACF_KM_XTS_128 : fc = (key_len == 32) ? CPACF_KM_XTS_128 :

View File

@ -111,10 +111,8 @@ static int crc32_vx_setkey(struct crypto_shash *tfm, const u8 *newkey,
{ {
struct crc_ctx *mctx = crypto_shash_ctx(tfm); struct crc_ctx *mctx = crypto_shash_ctx(tfm);
if (newkeylen != sizeof(mctx->key)) { if (newkeylen != sizeof(mctx->key))
crypto_shash_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
}
mctx->key = le32_to_cpu(*(__le32 *)newkey); mctx->key = le32_to_cpu(*(__le32 *)newkey);
return 0; return 0;
} }
@ -124,10 +122,8 @@ static int crc32be_vx_setkey(struct crypto_shash *tfm, const u8 *newkey,
{ {
struct crc_ctx *mctx = crypto_shash_ctx(tfm); struct crc_ctx *mctx = crypto_shash_ctx(tfm);
if (newkeylen != sizeof(mctx->key)) { if (newkeylen != sizeof(mctx->key))
crypto_shash_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
}
mctx->key = be32_to_cpu(*(__be32 *)newkey); mctx->key = be32_to_cpu(*(__be32 *)newkey);
return 0; return 0;
} }

View File

@ -43,10 +43,8 @@ static int ghash_setkey(struct crypto_shash *tfm,
{ {
struct ghash_ctx *ctx = crypto_shash_ctx(tfm); struct ghash_ctx *ctx = crypto_shash_ctx(tfm);
if (keylen != GHASH_BLOCK_SIZE) { if (keylen != GHASH_BLOCK_SIZE)
crypto_shash_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
}
memcpy(ctx->key, key, GHASH_BLOCK_SIZE); memcpy(ctx->key, key, GHASH_BLOCK_SIZE);

View File

@ -151,11 +151,7 @@ static int ecb_paes_set_key(struct crypto_skcipher *tfm, const u8 *in_key,
if (rc) if (rc)
return rc; return rc;
if (__paes_set_key(ctx)) { return __paes_set_key(ctx);
crypto_skcipher_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL;
}
return 0;
} }
static int ecb_paes_crypt(struct skcipher_request *req, unsigned long modifier) static int ecb_paes_crypt(struct skcipher_request *req, unsigned long modifier)
@ -254,11 +250,7 @@ static int cbc_paes_set_key(struct crypto_skcipher *tfm, const u8 *in_key,
if (rc) if (rc)
return rc; return rc;
if (__cbc_paes_set_key(ctx)) { return __cbc_paes_set_key(ctx);
crypto_skcipher_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL;
}
return 0;
} }
static int cbc_paes_crypt(struct skcipher_request *req, unsigned long modifier) static int cbc_paes_crypt(struct skcipher_request *req, unsigned long modifier)
@ -386,10 +378,9 @@ static int xts_paes_set_key(struct crypto_skcipher *tfm, const u8 *in_key,
if (rc) if (rc)
return rc; return rc;
if (__xts_paes_set_key(ctx)) { rc = __xts_paes_set_key(ctx);
crypto_skcipher_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN); if (rc)
return -EINVAL; return rc;
}
/* /*
* xts_check_key verifies the key length is not odd and makes * xts_check_key verifies the key length is not odd and makes
@ -526,11 +517,7 @@ static int ctr_paes_set_key(struct crypto_skcipher *tfm, const u8 *in_key,
if (rc) if (rc)
return rc; return rc;
if (__ctr_paes_set_key(ctx)) { return __ctr_paes_set_key(ctx);
crypto_skcipher_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL;
}
return 0;
} }
static unsigned int __ctrblk_init(u8 *ctrptr, u8 *iv, unsigned int nbytes) static unsigned int __ctrblk_init(u8 *ctrptr, u8 *iv, unsigned int nbytes)

View File

@ -169,7 +169,6 @@ static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
unsigned int key_len) unsigned int key_len)
{ {
struct crypto_sparc64_aes_ctx *ctx = crypto_tfm_ctx(tfm); struct crypto_sparc64_aes_ctx *ctx = crypto_tfm_ctx(tfm);
u32 *flags = &tfm->crt_flags;
switch (key_len) { switch (key_len) {
case AES_KEYSIZE_128: case AES_KEYSIZE_128:
@ -188,7 +187,6 @@ static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
break; break;
default: default:
*flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
return -EINVAL; return -EINVAL;
} }

View File

@ -39,12 +39,9 @@ static int camellia_set_key(struct crypto_tfm *tfm, const u8 *_in_key,
{ {
struct camellia_sparc64_ctx *ctx = crypto_tfm_ctx(tfm); struct camellia_sparc64_ctx *ctx = crypto_tfm_ctx(tfm);
const u32 *in_key = (const u32 *) _in_key; const u32 *in_key = (const u32 *) _in_key;
u32 *flags = &tfm->crt_flags;
if (key_len != 16 && key_len != 24 && key_len != 32) { if (key_len != 16 && key_len != 24 && key_len != 32)
*flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
return -EINVAL; return -EINVAL;
}
ctx->key_len = key_len; ctx->key_len = key_len;

View File

@ -33,10 +33,8 @@ static int crc32c_sparc64_setkey(struct crypto_shash *hash, const u8 *key,
{ {
u32 *mctx = crypto_shash_ctx(hash); u32 *mctx = crypto_shash_ctx(hash);
if (keylen != sizeof(u32)) { if (keylen != sizeof(u32))
crypto_shash_set_flags(hash, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
}
*(__le32 *)mctx = le32_to_cpup((__le32 *)key); *(__le32 *)mctx = le32_to_cpup((__le32 *)key);
return 0; return 0;
} }

View File

@ -144,10 +144,8 @@ static int crypto_aegis128_aesni_setkey(struct crypto_aead *aead, const u8 *key,
{ {
struct aegis_ctx *ctx = crypto_aegis128_aesni_ctx(aead); struct aegis_ctx *ctx = crypto_aegis128_aesni_ctx(aead);
if (keylen != AEGIS128_KEY_SIZE) { if (keylen != AEGIS128_KEY_SIZE)
crypto_aead_set_flags(aead, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
}
memcpy(ctx->key.bytes, key, AEGIS128_KEY_SIZE); memcpy(ctx->key.bytes, key, AEGIS128_KEY_SIZE);

View File

@ -316,14 +316,11 @@ static int aes_set_key_common(struct crypto_tfm *tfm, void *raw_ctx,
const u8 *in_key, unsigned int key_len) const u8 *in_key, unsigned int key_len)
{ {
struct crypto_aes_ctx *ctx = aes_ctx(raw_ctx); struct crypto_aes_ctx *ctx = aes_ctx(raw_ctx);
u32 *flags = &tfm->crt_flags;
int err; int err;
if (key_len != AES_KEYSIZE_128 && key_len != AES_KEYSIZE_192 && if (key_len != AES_KEYSIZE_128 && key_len != AES_KEYSIZE_192 &&
key_len != AES_KEYSIZE_256) { key_len != AES_KEYSIZE_256)
*flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
return -EINVAL; return -EINVAL;
}
if (!crypto_simd_usable()) if (!crypto_simd_usable())
err = aes_expandkey(ctx, in_key, key_len); err = aes_expandkey(ctx, in_key, key_len);
@ -641,10 +638,9 @@ static int common_rfc4106_set_key(struct crypto_aead *aead, const u8 *key,
{ {
struct aesni_rfc4106_gcm_ctx *ctx = aesni_rfc4106_gcm_ctx_get(aead); struct aesni_rfc4106_gcm_ctx *ctx = aesni_rfc4106_gcm_ctx_get(aead);
if (key_len < 4) { if (key_len < 4)
crypto_aead_set_flags(aead, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
}
/*Account for 4 byte nonce at the end.*/ /*Account for 4 byte nonce at the end.*/
key_len -= 4; key_len -= 4;

View File

@ -64,10 +64,8 @@ static int crypto_blake2s_setkey(struct crypto_shash *tfm, const u8 *key,
{ {
struct blake2s_tfm_ctx *tctx = crypto_shash_ctx(tfm); struct blake2s_tfm_ctx *tctx = crypto_shash_ctx(tfm);
if (keylen == 0 || keylen > BLAKE2S_KEY_SIZE) { if (keylen == 0 || keylen > BLAKE2S_KEY_SIZE)
crypto_shash_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
}
memcpy(tctx->key, key, keylen); memcpy(tctx->key, key, keylen);
tctx->keylen = keylen; tctx->keylen = keylen;

View File

@ -142,8 +142,7 @@ static const struct common_glue_ctx camellia_dec_xts = {
static int camellia_setkey(struct crypto_skcipher *tfm, const u8 *key, static int camellia_setkey(struct crypto_skcipher *tfm, const u8 *key,
unsigned int keylen) unsigned int keylen)
{ {
return __camellia_setkey(crypto_skcipher_ctx(tfm), key, keylen, return __camellia_setkey(crypto_skcipher_ctx(tfm), key, keylen);
&tfm->base.crt_flags);
} }
static int ecb_encrypt(struct skcipher_request *req) static int ecb_encrypt(struct skcipher_request *req)

View File

@ -144,8 +144,7 @@ static const struct common_glue_ctx camellia_dec_xts = {
static int camellia_setkey(struct crypto_skcipher *tfm, const u8 *key, static int camellia_setkey(struct crypto_skcipher *tfm, const u8 *key,
unsigned int keylen) unsigned int keylen)
{ {
return __camellia_setkey(crypto_skcipher_ctx(tfm), key, keylen, return __camellia_setkey(crypto_skcipher_ctx(tfm), key, keylen);
&tfm->base.crt_flags);
} }
static int ecb_encrypt(struct skcipher_request *req) static int ecb_encrypt(struct skcipher_request *req)
@ -177,7 +176,6 @@ int xts_camellia_setkey(struct crypto_skcipher *tfm, const u8 *key,
unsigned int keylen) unsigned int keylen)
{ {
struct camellia_xts_ctx *ctx = crypto_skcipher_ctx(tfm); struct camellia_xts_ctx *ctx = crypto_skcipher_ctx(tfm);
u32 *flags = &tfm->base.crt_flags;
int err; int err;
err = xts_verify_key(tfm, key, keylen); err = xts_verify_key(tfm, key, keylen);
@ -185,13 +183,12 @@ int xts_camellia_setkey(struct crypto_skcipher *tfm, const u8 *key,
return err; return err;
/* first half of xts-key is for crypt */ /* first half of xts-key is for crypt */
err = __camellia_setkey(&ctx->crypt_ctx, key, keylen / 2, flags); err = __camellia_setkey(&ctx->crypt_ctx, key, keylen / 2);
if (err) if (err)
return err; return err;
/* second half of xts-key is for tweak */ /* second half of xts-key is for tweak */
return __camellia_setkey(&ctx->tweak_ctx, key + keylen / 2, keylen / 2, return __camellia_setkey(&ctx->tweak_ctx, key + keylen / 2, keylen / 2);
flags);
} }
EXPORT_SYMBOL_GPL(xts_camellia_setkey); EXPORT_SYMBOL_GPL(xts_camellia_setkey);

View File

@ -1227,12 +1227,10 @@ static void camellia_setup192(const unsigned char *key, u64 *subkey)
} }
int __camellia_setkey(struct camellia_ctx *cctx, const unsigned char *key, int __camellia_setkey(struct camellia_ctx *cctx, const unsigned char *key,
unsigned int key_len, u32 *flags) unsigned int key_len)
{ {
if (key_len != 16 && key_len != 24 && key_len != 32) { if (key_len != 16 && key_len != 24 && key_len != 32)
*flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
return -EINVAL; return -EINVAL;
}
cctx->key_length = key_len; cctx->key_length = key_len;
@ -1255,8 +1253,7 @@ EXPORT_SYMBOL_GPL(__camellia_setkey);
static int camellia_setkey(struct crypto_tfm *tfm, const u8 *key, static int camellia_setkey(struct crypto_tfm *tfm, const u8 *key,
unsigned int key_len) unsigned int key_len)
{ {
return __camellia_setkey(crypto_tfm_ctx(tfm), key, key_len, return __camellia_setkey(crypto_tfm_ctx(tfm), key, key_len);
&tfm->crt_flags);
} }
static int camellia_setkey_skcipher(struct crypto_skcipher *tfm, const u8 *key, static int camellia_setkey_skcipher(struct crypto_skcipher *tfm, const u8 *key,

View File

@ -173,7 +173,6 @@ static int xts_cast6_setkey(struct crypto_skcipher *tfm, const u8 *key,
unsigned int keylen) unsigned int keylen)
{ {
struct cast6_xts_ctx *ctx = crypto_skcipher_ctx(tfm); struct cast6_xts_ctx *ctx = crypto_skcipher_ctx(tfm);
u32 *flags = &tfm->base.crt_flags;
int err; int err;
err = xts_verify_key(tfm, key, keylen); err = xts_verify_key(tfm, key, keylen);
@ -181,13 +180,12 @@ static int xts_cast6_setkey(struct crypto_skcipher *tfm, const u8 *key,
return err; return err;
/* first half of xts-key is for crypt */ /* first half of xts-key is for crypt */
err = __cast6_setkey(&ctx->crypt_ctx, key, keylen / 2, flags); err = __cast6_setkey(&ctx->crypt_ctx, key, keylen / 2);
if (err) if (err)
return err; return err;
/* second half of xts-key is for tweak */ /* second half of xts-key is for tweak */
return __cast6_setkey(&ctx->tweak_ctx, key + keylen / 2, keylen / 2, return __cast6_setkey(&ctx->tweak_ctx, key + keylen / 2, keylen / 2);
flags);
} }
static int xts_encrypt(struct skcipher_request *req) static int xts_encrypt(struct skcipher_request *req)

View File

@ -94,10 +94,8 @@ static int crc32_pclmul_setkey(struct crypto_shash *hash, const u8 *key,
{ {
u32 *mctx = crypto_shash_ctx(hash); u32 *mctx = crypto_shash_ctx(hash);
if (keylen != sizeof(u32)) { if (keylen != sizeof(u32))
crypto_shash_set_flags(hash, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
}
*mctx = le32_to_cpup((__le32 *)key); *mctx = le32_to_cpup((__le32 *)key);
return 0; return 0;
} }

View File

@ -91,10 +91,8 @@ static int crc32c_intel_setkey(struct crypto_shash *hash, const u8 *key,
{ {
u32 *mctx = crypto_shash_ctx(hash); u32 *mctx = crypto_shash_ctx(hash);
if (keylen != sizeof(u32)) { if (keylen != sizeof(u32))
crypto_shash_set_flags(hash, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
}
*mctx = le32_to_cpup((__le32 *)key); *mctx = le32_to_cpup((__le32 *)key);
return 0; return 0;
} }

View File

@ -57,10 +57,8 @@ static int ghash_setkey(struct crypto_shash *tfm,
be128 *x = (be128 *)key; be128 *x = (be128 *)key;
u64 a, b; u64 a, b;
if (keylen != GHASH_BLOCK_SIZE) { if (keylen != GHASH_BLOCK_SIZE)
crypto_shash_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
}
/* perform multiplication by 'x' in GF(2^128) */ /* perform multiplication by 'x' in GF(2^128) */
a = be64_to_cpu(x->a); a = be64_to_cpu(x->a);

View File

@ -64,7 +64,6 @@ static int xts_twofish_setkey(struct crypto_skcipher *tfm, const u8 *key,
unsigned int keylen) unsigned int keylen)
{ {
struct twofish_xts_ctx *ctx = crypto_skcipher_ctx(tfm); struct twofish_xts_ctx *ctx = crypto_skcipher_ctx(tfm);
u32 *flags = &tfm->base.crt_flags;
int err; int err;
err = xts_verify_key(tfm, key, keylen); err = xts_verify_key(tfm, key, keylen);
@ -72,13 +71,12 @@ static int xts_twofish_setkey(struct crypto_skcipher *tfm, const u8 *key,
return err; return err;
/* first half of xts-key is for crypt */ /* first half of xts-key is for crypt */
err = __twofish_setkey(&ctx->crypt_ctx, key, keylen / 2, flags); err = __twofish_setkey(&ctx->crypt_ctx, key, keylen / 2);
if (err) if (err)
return err; return err;
/* second half of xts-key is for tweak */ /* second half of xts-key is for tweak */
return __twofish_setkey(&ctx->tweak_ctx, key + keylen / 2, keylen / 2, return __twofish_setkey(&ctx->tweak_ctx, key + keylen / 2, keylen / 2);
flags);
} }
static const struct common_glue_ctx twofish_enc = { static const struct common_glue_ctx twofish_enc = {

View File

@ -26,7 +26,7 @@ struct camellia_xts_ctx {
extern int __camellia_setkey(struct camellia_ctx *cctx, extern int __camellia_setkey(struct camellia_ctx *cctx,
const unsigned char *key, const unsigned char *key,
unsigned int key_len, u32 *flags); unsigned int key_len);
extern int xts_camellia_setkey(struct crypto_skcipher *tfm, const u8 *key, extern int xts_camellia_setkey(struct crypto_skcipher *tfm, const u8 *key,
unsigned int keylen); unsigned int keylen);

View File

@ -372,10 +372,8 @@ static int crypto_aegis128_setkey(struct crypto_aead *aead, const u8 *key,
{ {
struct aegis_ctx *ctx = crypto_aead_ctx(aead); struct aegis_ctx *ctx = crypto_aead_ctx(aead);
if (keylen != AEGIS128_KEY_SIZE) { if (keylen != AEGIS128_KEY_SIZE)
crypto_aead_set_flags(aead, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
}
memcpy(ctx->key.bytes, key, AEGIS128_KEY_SIZE); memcpy(ctx->key.bytes, key, AEGIS128_KEY_SIZE);
return 0; return 0;

View File

@ -1127,24 +1127,18 @@ EXPORT_SYMBOL_GPL(crypto_it_tab);
* @in_key: The input key. * @in_key: The input key.
* @key_len: The size of the key. * @key_len: The size of the key.
* *
* Returns 0 on success, on failure the %CRYPTO_TFM_RES_BAD_KEY_LEN flag in tfm * This function uses aes_expand_key() to expand the key. &crypto_aes_ctx
* is set. The function uses aes_expand_key() to expand the key. * _must_ be the private data embedded in @tfm which is retrieved with
* &crypto_aes_ctx _must_ be the private data embedded in @tfm which is * crypto_tfm_ctx().
* retrieved with crypto_tfm_ctx(). *
* Return: 0 on success; -EINVAL on failure (only happens for bad key lengths)
*/ */
int crypto_aes_set_key(struct crypto_tfm *tfm, const u8 *in_key, int crypto_aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
unsigned int key_len) unsigned int key_len)
{ {
struct crypto_aes_ctx *ctx = crypto_tfm_ctx(tfm); struct crypto_aes_ctx *ctx = crypto_tfm_ctx(tfm);
u32 *flags = &tfm->crt_flags;
int ret;
ret = aes_expandkey(ctx, in_key, key_len); return aes_expandkey(ctx, in_key, key_len);
if (!ret)
return 0;
*flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
return -EINVAL;
} }
EXPORT_SYMBOL_GPL(crypto_aes_set_key); EXPORT_SYMBOL_GPL(crypto_aes_set_key);

View File

@ -464,7 +464,6 @@ static int anubis_setkey(struct crypto_tfm *tfm, const u8 *in_key,
{ {
struct anubis_ctx *ctx = crypto_tfm_ctx(tfm); struct anubis_ctx *ctx = crypto_tfm_ctx(tfm);
const __be32 *key = (const __be32 *)in_key; const __be32 *key = (const __be32 *)in_key;
u32 *flags = &tfm->crt_flags;
int N, R, i, r; int N, R, i, r;
u32 kappa[ANUBIS_MAX_N]; u32 kappa[ANUBIS_MAX_N];
u32 inter[ANUBIS_MAX_N]; u32 inter[ANUBIS_MAX_N];
@ -474,7 +473,6 @@ static int anubis_setkey(struct crypto_tfm *tfm, const u8 *in_key,
case 32: case 36: case 40: case 32: case 36: case 40:
break; break;
default: default:
*flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
return -EINVAL; return -EINVAL;
} }

View File

@ -91,7 +91,7 @@ static int crypto_authenc_setkey(struct crypto_aead *authenc, const u8 *key,
int err = -EINVAL; int err = -EINVAL;
if (crypto_authenc_extractkeys(&keys, key, keylen) != 0) if (crypto_authenc_extractkeys(&keys, key, keylen) != 0)
goto badkey; goto out;
crypto_ahash_clear_flags(auth, CRYPTO_TFM_REQ_MASK); crypto_ahash_clear_flags(auth, CRYPTO_TFM_REQ_MASK);
crypto_ahash_set_flags(auth, crypto_aead_get_flags(authenc) & crypto_ahash_set_flags(auth, crypto_aead_get_flags(authenc) &
@ -113,10 +113,6 @@ static int crypto_authenc_setkey(struct crypto_aead *authenc, const u8 *key,
out: out:
memzero_explicit(&keys, sizeof(keys)); memzero_explicit(&keys, sizeof(keys));
return err; return err;
badkey:
crypto_aead_set_flags(authenc, CRYPTO_TFM_RES_BAD_KEY_LEN);
goto out;
} }
static void authenc_geniv_ahash_done(struct crypto_async_request *areq, int err) static void authenc_geniv_ahash_done(struct crypto_async_request *areq, int err)

View File

@ -65,7 +65,7 @@ static int crypto_authenc_esn_setkey(struct crypto_aead *authenc_esn, const u8 *
int err = -EINVAL; int err = -EINVAL;
if (crypto_authenc_extractkeys(&keys, key, keylen) != 0) if (crypto_authenc_extractkeys(&keys, key, keylen) != 0)
goto badkey; goto out;
crypto_ahash_clear_flags(auth, CRYPTO_TFM_REQ_MASK); crypto_ahash_clear_flags(auth, CRYPTO_TFM_REQ_MASK);
crypto_ahash_set_flags(auth, crypto_aead_get_flags(authenc_esn) & crypto_ahash_set_flags(auth, crypto_aead_get_flags(authenc_esn) &
@ -87,10 +87,6 @@ static int crypto_authenc_esn_setkey(struct crypto_aead *authenc_esn, const u8 *
out: out:
memzero_explicit(&keys, sizeof(keys)); memzero_explicit(&keys, sizeof(keys));
return err; return err;
badkey:
crypto_aead_set_flags(authenc_esn, CRYPTO_TFM_RES_BAD_KEY_LEN);
goto out;
} }
static int crypto_authenc_esn_genicv_tail(struct aead_request *req, static int crypto_authenc_esn_genicv_tail(struct aead_request *req,

View File

@ -147,10 +147,8 @@ static int blake2b_setkey(struct crypto_shash *tfm, const u8 *key,
{ {
struct blake2b_tfm_ctx *tctx = crypto_shash_ctx(tfm); struct blake2b_tfm_ctx *tctx = crypto_shash_ctx(tfm);
if (keylen == 0 || keylen > BLAKE2B_KEYBYTES) { if (keylen == 0 || keylen > BLAKE2B_KEYBYTES)
crypto_shash_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
}
memcpy(tctx->key, key, keylen); memcpy(tctx->key, key, keylen);
tctx->keylen = keylen; tctx->keylen = keylen;

View File

@ -17,10 +17,8 @@ static int crypto_blake2s_setkey(struct crypto_shash *tfm, const u8 *key,
{ {
struct blake2s_tfm_ctx *tctx = crypto_shash_ctx(tfm); struct blake2s_tfm_ctx *tctx = crypto_shash_ctx(tfm);
if (keylen == 0 || keylen > BLAKE2S_KEY_SIZE) { if (keylen == 0 || keylen > BLAKE2S_KEY_SIZE)
crypto_shash_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
}
memcpy(tctx->key, key, keylen); memcpy(tctx->key, key, keylen);
tctx->keylen = keylen; tctx->keylen = keylen;

View File

@ -970,12 +970,9 @@ camellia_set_key(struct crypto_tfm *tfm, const u8 *in_key,
{ {
struct camellia_ctx *cctx = crypto_tfm_ctx(tfm); struct camellia_ctx *cctx = crypto_tfm_ctx(tfm);
const unsigned char *key = (const unsigned char *)in_key; const unsigned char *key = (const unsigned char *)in_key;
u32 *flags = &tfm->crt_flags;
if (key_len != 16 && key_len != 24 && key_len != 32) { if (key_len != 16 && key_len != 24 && key_len != 32)
*flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
return -EINVAL; return -EINVAL;
}
cctx->key_length = key_len; cctx->key_length = key_len;

View File

@ -103,17 +103,14 @@ static inline void W(u32 *key, unsigned int i)
key[7] ^= F2(key[0], Tr[i % 4][7], Tm[i][7]); key[7] ^= F2(key[0], Tr[i % 4][7], Tm[i][7]);
} }
int __cast6_setkey(struct cast6_ctx *c, const u8 *in_key, int __cast6_setkey(struct cast6_ctx *c, const u8 *in_key, unsigned int key_len)
unsigned key_len, u32 *flags)
{ {
int i; int i;
u32 key[8]; u32 key[8];
__be32 p_key[8]; /* padded key */ __be32 p_key[8]; /* padded key */
if (key_len % 4 != 0) { if (key_len % 4 != 0)
*flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
return -EINVAL; return -EINVAL;
}
memset(p_key, 0, 32); memset(p_key, 0, 32);
memcpy(p_key, in_key, key_len); memcpy(p_key, in_key, key_len);
@ -148,8 +145,7 @@ EXPORT_SYMBOL_GPL(__cast6_setkey);
int cast6_setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen) int cast6_setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen)
{ {
return __cast6_setkey(crypto_tfm_ctx(tfm), key, keylen, return __cast6_setkey(crypto_tfm_ctx(tfm), key, keylen);
&tfm->crt_flags);
} }
EXPORT_SYMBOL_GPL(cast6_setkey); EXPORT_SYMBOL_GPL(cast6_setkey);

View File

@ -46,10 +46,8 @@ int crypto_cipher_setkey(struct crypto_cipher *tfm,
unsigned long alignmask = crypto_cipher_alignmask(tfm); unsigned long alignmask = crypto_cipher_alignmask(tfm);
crypto_cipher_clear_flags(tfm, CRYPTO_TFM_RES_MASK); crypto_cipher_clear_flags(tfm, CRYPTO_TFM_RES_MASK);
if (keylen < cia->cia_min_keysize || keylen > cia->cia_max_keysize) { if (keylen < cia->cia_min_keysize || keylen > cia->cia_max_keysize)
crypto_cipher_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
}
if ((unsigned long)key & alignmask) if ((unsigned long)key & alignmask)
return setkey_unaligned(tfm, key, keylen); return setkey_unaligned(tfm, key, keylen);

View File

@ -60,10 +60,8 @@ static int crc32_setkey(struct crypto_shash *hash, const u8 *key,
{ {
u32 *mctx = crypto_shash_ctx(hash); u32 *mctx = crypto_shash_ctx(hash);
if (keylen != sizeof(u32)) { if (keylen != sizeof(u32))
crypto_shash_set_flags(hash, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
}
*mctx = get_unaligned_le32(key); *mctx = get_unaligned_le32(key);
return 0; return 0;
} }

View File

@ -74,10 +74,8 @@ static int chksum_setkey(struct crypto_shash *tfm, const u8 *key,
{ {
struct chksum_ctx *mctx = crypto_shash_ctx(tfm); struct chksum_ctx *mctx = crypto_shash_ctx(tfm);
if (keylen != sizeof(mctx->key)) { if (keylen != sizeof(mctx->key))
crypto_shash_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
}
mctx->key = get_unaligned_le32(key); mctx->key = get_unaligned_le32(key);
return 0; return 0;
} }

View File

@ -117,10 +117,8 @@ static int essiv_aead_setkey(struct crypto_aead *tfm, const u8 *key,
if (err) if (err)
return err; return err;
if (crypto_authenc_extractkeys(&keys, key, keylen) != 0) { if (crypto_authenc_extractkeys(&keys, key, keylen) != 0)
crypto_aead_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
}
desc->tfm = tctx->hash; desc->tfm = tctx->hash;
err = crypto_shash_init(desc) ?: err = crypto_shash_init(desc) ?:

View File

@ -58,10 +58,8 @@ static int ghash_setkey(struct crypto_shash *tfm,
struct ghash_ctx *ctx = crypto_shash_ctx(tfm); struct ghash_ctx *ctx = crypto_shash_ctx(tfm);
be128 k; be128 k;
if (keylen != GHASH_BLOCK_SIZE) { if (keylen != GHASH_BLOCK_SIZE)
crypto_shash_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
}
if (ctx->gf128) if (ctx->gf128)
gf128mul_free_4k(ctx->gf128); gf128mul_free_4k(ctx->gf128);

View File

@ -137,10 +137,8 @@ static int michael_setkey(struct crypto_shash *tfm, const u8 *key,
const __le32 *data = (const __le32 *)key; const __le32 *data = (const __le32 *)key;
if (keylen != 8) { if (keylen != 8)
crypto_shash_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
}
mctx->l = le32_to_cpu(data[0]); mctx->l = le32_to_cpu(data[0]);
mctx->r = le32_to_cpu(data[1]); mctx->r = le32_to_cpu(data[1]);

View File

@ -603,10 +603,8 @@ int crypto_skcipher_setkey(struct crypto_skcipher *tfm, const u8 *key,
unsigned long alignmask = crypto_skcipher_alignmask(tfm); unsigned long alignmask = crypto_skcipher_alignmask(tfm);
int err; int err;
if (keylen < cipher->min_keysize || keylen > cipher->max_keysize) { if (keylen < cipher->min_keysize || keylen > cipher->max_keysize)
crypto_skcipher_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
}
if ((unsigned long)key & alignmask) if ((unsigned long)key & alignmask)
err = skcipher_setkey_unaligned(tfm, key, keylen); err = skcipher_setkey_unaligned(tfm, key, keylen);

View File

@ -143,29 +143,23 @@ int crypto_sm4_expand_key(struct crypto_sm4_ctx *ctx, const u8 *in_key,
EXPORT_SYMBOL_GPL(crypto_sm4_expand_key); EXPORT_SYMBOL_GPL(crypto_sm4_expand_key);
/** /**
* crypto_sm4_set_key - Set the AES key. * crypto_sm4_set_key - Set the SM4 key.
* @tfm: The %crypto_tfm that is used in the context. * @tfm: The %crypto_tfm that is used in the context.
* @in_key: The input key. * @in_key: The input key.
* @key_len: The size of the key. * @key_len: The size of the key.
* *
* Returns 0 on success, on failure the %CRYPTO_TFM_RES_BAD_KEY_LEN flag in tfm * This function uses crypto_sm4_expand_key() to expand the key.
* is set. The function uses crypto_sm4_expand_key() to expand the key.
* &crypto_sm4_ctx _must_ be the private data embedded in @tfm which is * &crypto_sm4_ctx _must_ be the private data embedded in @tfm which is
* retrieved with crypto_tfm_ctx(). * retrieved with crypto_tfm_ctx().
*
* Return: 0 on success; -EINVAL on failure (only happens for bad key lengths)
*/ */
int crypto_sm4_set_key(struct crypto_tfm *tfm, const u8 *in_key, int crypto_sm4_set_key(struct crypto_tfm *tfm, const u8 *in_key,
unsigned int key_len) unsigned int key_len)
{ {
struct crypto_sm4_ctx *ctx = crypto_tfm_ctx(tfm); struct crypto_sm4_ctx *ctx = crypto_tfm_ctx(tfm);
u32 *flags = &tfm->crt_flags;
int ret;
ret = crypto_sm4_expand_key(ctx, in_key, key_len); return crypto_sm4_expand_key(ctx, in_key, key_len);
if (!ret)
return 0;
*flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
return -EINVAL;
} }
EXPORT_SYMBOL_GPL(crypto_sm4_set_key); EXPORT_SYMBOL_GPL(crypto_sm4_set_key);

View File

@ -567,7 +567,7 @@ static const u8 calc_sb_tbl[512] = {
/* Perform the key setup. */ /* Perform the key setup. */
int __twofish_setkey(struct twofish_ctx *ctx, const u8 *key, int __twofish_setkey(struct twofish_ctx *ctx, const u8 *key,
unsigned int key_len, u32 *flags) unsigned int key_len)
{ {
int i, j, k; int i, j, k;
@ -584,10 +584,7 @@ int __twofish_setkey(struct twofish_ctx *ctx, const u8 *key,
/* Check key length. */ /* Check key length. */
if (key_len % 8) if (key_len % 8)
{
*flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
return -EINVAL; /* unsupported key length */ return -EINVAL; /* unsupported key length */
}
/* Compute the first two words of the S vector. The magic numbers are /* Compute the first two words of the S vector. The magic numbers are
* the entries of the RS matrix, preprocessed through poly_to_exp. The * the entries of the RS matrix, preprocessed through poly_to_exp. The
@ -688,8 +685,7 @@ EXPORT_SYMBOL_GPL(__twofish_setkey);
int twofish_setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int key_len) int twofish_setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int key_len)
{ {
return __twofish_setkey(crypto_tfm_ctx(tfm), key, key_len, return __twofish_setkey(crypto_tfm_ctx(tfm), key, key_len);
&tfm->crt_flags);
} }
EXPORT_SYMBOL_GPL(twofish_setkey); EXPORT_SYMBOL_GPL(twofish_setkey);

View File

@ -435,10 +435,8 @@ static int vmac_setkey(struct crypto_shash *tfm,
unsigned int i; unsigned int i;
int err; int err;
if (keylen != VMAC_KEY_LEN) { if (keylen != VMAC_KEY_LEN)
crypto_shash_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
}
err = crypto_cipher_setkey(tctx->cipher, key, keylen); err = crypto_cipher_setkey(tctx->cipher, key, keylen);
if (err) if (err)

View File

@ -22,10 +22,8 @@ static int xxhash64_setkey(struct crypto_shash *tfm, const u8 *key,
{ {
struct xxhash64_tfm_ctx *tctx = crypto_shash_ctx(tfm); struct xxhash64_tfm_ctx *tctx = crypto_shash_ctx(tfm);
if (keylen != sizeof(tctx->seed)) { if (keylen != sizeof(tctx->seed))
crypto_shash_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
}
tctx->seed = get_unaligned_le64(key); tctx->seed = get_unaligned_le64(key);
return 0; return 0;
} }

View File

@ -541,7 +541,6 @@ int sun4i_ss_aes_setkey(struct crypto_skcipher *tfm, const u8 *key,
break; break;
default: default:
dev_dbg(ss->dev, "ERROR: Invalid keylen %u\n", keylen); dev_dbg(ss->dev, "ERROR: Invalid keylen %u\n", keylen);
crypto_skcipher_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
} }
op->keylen = keylen; op->keylen = keylen;

View File

@ -394,7 +394,6 @@ int sun8i_ce_aes_setkey(struct crypto_skcipher *tfm, const u8 *key,
break; break;
default: default:
dev_dbg(ce->dev, "ERROR: Invalid keylen %u\n", keylen); dev_dbg(ce->dev, "ERROR: Invalid keylen %u\n", keylen);
crypto_skcipher_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
} }
if (op->key) { if (op->key) {

View File

@ -390,7 +390,6 @@ int sun8i_ss_aes_setkey(struct crypto_skcipher *tfm, const u8 *key,
break; break;
default: default:
dev_dbg(ss->dev, "ERROR: Invalid keylen %u\n", keylen); dev_dbg(ss->dev, "ERROR: Invalid keylen %u\n", keylen);
crypto_skcipher_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
} }
if (op->key) { if (op->key) {
@ -416,7 +415,6 @@ int sun8i_ss_des3_setkey(struct crypto_skcipher *tfm, const u8 *key,
if (unlikely(keylen != 3 * DES_KEY_SIZE)) { if (unlikely(keylen != 3 * DES_KEY_SIZE)) {
dev_dbg(ss->dev, "Invalid keylen %u\n", keylen); dev_dbg(ss->dev, "Invalid keylen %u\n", keylen);
crypto_skcipher_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
} }

View File

@ -128,12 +128,9 @@ static int crypto4xx_setkey_aes(struct crypto_skcipher *cipher,
struct dynamic_sa_ctl *sa; struct dynamic_sa_ctl *sa;
int rc; int rc;
if (keylen != AES_KEYSIZE_256 && if (keylen != AES_KEYSIZE_256 && keylen != AES_KEYSIZE_192 &&
keylen != AES_KEYSIZE_192 && keylen != AES_KEYSIZE_128) { keylen != AES_KEYSIZE_128)
crypto_skcipher_set_flags(cipher,
CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
}
/* Create SA */ /* Create SA */
if (ctx->sa_in || ctx->sa_out) if (ctx->sa_in || ctx->sa_out)
@ -551,10 +548,8 @@ int crypto4xx_setkey_aes_gcm(struct crypto_aead *cipher,
struct dynamic_sa_ctl *sa; struct dynamic_sa_ctl *sa;
int rc = 0; int rc = 0;
if (crypto4xx_aes_gcm_validate_keylen(keylen) != 0) { if (crypto4xx_aes_gcm_validate_keylen(keylen) != 0)
crypto_aead_set_flags(cipher, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
}
rc = crypto4xx_aead_setup_fallback(ctx, cipher, key, keylen); rc = crypto4xx_aead_setup_fallback(ctx, cipher, key, keylen);
if (rc) if (rc)

View File

@ -366,7 +366,6 @@ int meson_aes_setkey(struct crypto_skcipher *tfm, const u8 *key,
break; break;
default: default:
dev_dbg(mc->dev, "ERROR: Invalid keylen %u\n", keylen); dev_dbg(mc->dev, "ERROR: Invalid keylen %u\n", keylen);
crypto_skcipher_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
} }
if (op->key) { if (op->key) {

View File

@ -1140,10 +1140,8 @@ static int atmel_aes_setkey(struct crypto_skcipher *tfm, const u8 *key,
if (keylen != AES_KEYSIZE_128 && if (keylen != AES_KEYSIZE_128 &&
keylen != AES_KEYSIZE_192 && keylen != AES_KEYSIZE_192 &&
keylen != AES_KEYSIZE_256) { keylen != AES_KEYSIZE_256)
crypto_skcipher_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
}
memcpy(ctx->key, key, keylen); memcpy(ctx->key, key, keylen);
ctx->keylen = keylen; ctx->keylen = keylen;
@ -1716,10 +1714,8 @@ static int atmel_aes_gcm_setkey(struct crypto_aead *tfm, const u8 *key,
if (keylen != AES_KEYSIZE_256 && if (keylen != AES_KEYSIZE_256 &&
keylen != AES_KEYSIZE_192 && keylen != AES_KEYSIZE_192 &&
keylen != AES_KEYSIZE_128) { keylen != AES_KEYSIZE_128)
crypto_aead_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
}
memcpy(ctx->key, key, keylen); memcpy(ctx->key, key, keylen);
ctx->keylen = keylen; ctx->keylen = keylen;
@ -2073,7 +2069,6 @@ static int atmel_aes_authenc_setkey(struct crypto_aead *tfm, const u8 *key,
return 0; return 0;
badkey: badkey:
crypto_aead_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
memzero_explicit(&keys, sizeof(keys)); memzero_explicit(&keys, sizeof(keys));
return -EINVAL; return -EINVAL;
} }

View File

@ -1249,10 +1249,8 @@ static int artpec6_crypto_aead_set_key(struct crypto_aead *tfm, const u8 *key,
{ {
struct artpec6_cryptotfm_context *ctx = crypto_tfm_ctx(&tfm->base); struct artpec6_cryptotfm_context *ctx = crypto_tfm_ctx(&tfm->base);
if (len != 16 && len != 24 && len != 32) { if (len != 16 && len != 24 && len != 32)
crypto_aead_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
}
ctx->key_length = len; ctx->key_length = len;
@ -1606,8 +1604,6 @@ artpec6_crypto_cipher_set_key(struct crypto_skcipher *cipher, const u8 *key,
case 32: case 32:
break; break;
default: default:
crypto_skcipher_set_flags(cipher,
CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
} }
@ -1634,8 +1630,6 @@ artpec6_crypto_xts_set_key(struct crypto_skcipher *cipher, const u8 *key,
case 64: case 64:
break; break;
default: default:
crypto_skcipher_set_flags(cipher,
CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
} }

View File

@ -1846,7 +1846,6 @@ static int aes_setkey(struct crypto_skcipher *cipher, const u8 *key,
ctx->cipher_type = CIPHER_TYPE_AES256; ctx->cipher_type = CIPHER_TYPE_AES256;
break; break;
default: default:
crypto_skcipher_set_flags(cipher, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
} }
WARN_ON((ctx->max_payload != SPU_MAX_PAYLOAD_INF) && WARN_ON((ctx->max_payload != SPU_MAX_PAYLOAD_INF) &&
@ -2916,7 +2915,6 @@ static int aead_authenc_setkey(struct crypto_aead *cipher,
ctx->authkeylen = 0; ctx->authkeylen = 0;
ctx->digestsize = 0; ctx->digestsize = 0;
crypto_aead_set_flags(cipher, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
} }
@ -2992,7 +2990,6 @@ static int aead_gcm_ccm_setkey(struct crypto_aead *cipher,
ctx->authkeylen = 0; ctx->authkeylen = 0;
ctx->digestsize = 0; ctx->digestsize = 0;
crypto_aead_set_flags(cipher, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
} }

View File

@ -548,10 +548,8 @@ static int chachapoly_setkey(struct crypto_aead *aead, const u8 *key,
unsigned int ivsize = crypto_aead_ivsize(aead); unsigned int ivsize = crypto_aead_ivsize(aead);
unsigned int saltlen = CHACHAPOLY_IV_SIZE - ivsize; unsigned int saltlen = CHACHAPOLY_IV_SIZE - ivsize;
if (keylen != CHACHA_KEY_SIZE + saltlen) { if (keylen != CHACHA_KEY_SIZE + saltlen)
crypto_aead_set_flags(aead, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
}
ctx->cdata.key_virt = key; ctx->cdata.key_virt = key;
ctx->cdata.keylen = keylen - saltlen; ctx->cdata.keylen = keylen - saltlen;
@ -619,7 +617,6 @@ static int aead_setkey(struct crypto_aead *aead,
memzero_explicit(&keys, sizeof(keys)); memzero_explicit(&keys, sizeof(keys));
return aead_set_sh_desc(aead); return aead_set_sh_desc(aead);
badkey: badkey:
crypto_aead_set_flags(aead, CRYPTO_TFM_RES_BAD_KEY_LEN);
memzero_explicit(&keys, sizeof(keys)); memzero_explicit(&keys, sizeof(keys));
return -EINVAL; return -EINVAL;
} }
@ -649,10 +646,8 @@ static int gcm_setkey(struct crypto_aead *aead,
int err; int err;
err = aes_check_keylen(keylen); err = aes_check_keylen(keylen);
if (err) { if (err)
crypto_aead_set_flags(aead, CRYPTO_TFM_RES_BAD_KEY_LEN);
return err; return err;
}
print_hex_dump_debug("key in @"__stringify(__LINE__)": ", print_hex_dump_debug("key in @"__stringify(__LINE__)": ",
DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1); DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
@ -672,10 +667,8 @@ static int rfc4106_setkey(struct crypto_aead *aead,
int err; int err;
err = aes_check_keylen(keylen - 4); err = aes_check_keylen(keylen - 4);
if (err) { if (err)
crypto_aead_set_flags(aead, CRYPTO_TFM_RES_BAD_KEY_LEN);
return err; return err;
}
print_hex_dump_debug("key in @"__stringify(__LINE__)": ", print_hex_dump_debug("key in @"__stringify(__LINE__)": ",
DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1); DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
@ -700,10 +693,8 @@ static int rfc4543_setkey(struct crypto_aead *aead,
int err; int err;
err = aes_check_keylen(keylen - 4); err = aes_check_keylen(keylen - 4);
if (err) { if (err)
crypto_aead_set_flags(aead, CRYPTO_TFM_RES_BAD_KEY_LEN);
return err; return err;
}
print_hex_dump_debug("key in @"__stringify(__LINE__)": ", print_hex_dump_debug("key in @"__stringify(__LINE__)": ",
DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1); DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
@ -762,11 +753,8 @@ static int aes_skcipher_setkey(struct crypto_skcipher *skcipher,
int err; int err;
err = aes_check_keylen(keylen); err = aes_check_keylen(keylen);
if (err) { if (err)
crypto_skcipher_set_flags(skcipher,
CRYPTO_TFM_RES_BAD_KEY_LEN);
return err; return err;
}
return skcipher_setkey(skcipher, key, keylen, 0); return skcipher_setkey(skcipher, key, keylen, 0);
} }
@ -786,11 +774,8 @@ static int rfc3686_skcipher_setkey(struct crypto_skcipher *skcipher,
keylen -= CTR_RFC3686_NONCE_SIZE; keylen -= CTR_RFC3686_NONCE_SIZE;
err = aes_check_keylen(keylen); err = aes_check_keylen(keylen);
if (err) { if (err)
crypto_skcipher_set_flags(skcipher,
CRYPTO_TFM_RES_BAD_KEY_LEN);
return err; return err;
}
return skcipher_setkey(skcipher, key, keylen, ctx1_iv_off); return skcipher_setkey(skcipher, key, keylen, ctx1_iv_off);
} }
@ -809,11 +794,8 @@ static int ctr_skcipher_setkey(struct crypto_skcipher *skcipher,
ctx1_iv_off = 16; ctx1_iv_off = 16;
err = aes_check_keylen(keylen); err = aes_check_keylen(keylen);
if (err) { if (err)
crypto_skcipher_set_flags(skcipher,
CRYPTO_TFM_RES_BAD_KEY_LEN);
return err; return err;
}
return skcipher_setkey(skcipher, key, keylen, ctx1_iv_off); return skcipher_setkey(skcipher, key, keylen, ctx1_iv_off);
} }
@ -846,7 +828,6 @@ static int xts_skcipher_setkey(struct crypto_skcipher *skcipher, const u8 *key,
u32 *desc; u32 *desc;
if (keylen != 2 * AES_MIN_KEY_SIZE && keylen != 2 * AES_MAX_KEY_SIZE) { if (keylen != 2 * AES_MIN_KEY_SIZE && keylen != 2 * AES_MAX_KEY_SIZE) {
crypto_skcipher_set_flags(skcipher, CRYPTO_TFM_RES_BAD_KEY_LEN);
dev_err(jrdev, "key size mismatch\n"); dev_err(jrdev, "key size mismatch\n");
return -EINVAL; return -EINVAL;
} }

View File

@ -268,7 +268,6 @@ static int aead_setkey(struct crypto_aead *aead, const u8 *key,
memzero_explicit(&keys, sizeof(keys)); memzero_explicit(&keys, sizeof(keys));
return ret; return ret;
badkey: badkey:
crypto_aead_set_flags(aead, CRYPTO_TFM_RES_BAD_KEY_LEN);
memzero_explicit(&keys, sizeof(keys)); memzero_explicit(&keys, sizeof(keys));
return -EINVAL; return -EINVAL;
} }
@ -356,10 +355,8 @@ static int gcm_setkey(struct crypto_aead *aead,
int ret; int ret;
ret = aes_check_keylen(keylen); ret = aes_check_keylen(keylen);
if (ret) { if (ret)
crypto_aead_set_flags(aead, CRYPTO_TFM_RES_BAD_KEY_LEN);
return ret; return ret;
}
print_hex_dump_debug("key in @" __stringify(__LINE__)": ", print_hex_dump_debug("key in @" __stringify(__LINE__)": ",
DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1); DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
@ -462,10 +459,8 @@ static int rfc4106_setkey(struct crypto_aead *aead,
int ret; int ret;
ret = aes_check_keylen(keylen - 4); ret = aes_check_keylen(keylen - 4);
if (ret) { if (ret)
crypto_aead_set_flags(aead, CRYPTO_TFM_RES_BAD_KEY_LEN);
return ret; return ret;
}
print_hex_dump_debug("key in @" __stringify(__LINE__)": ", print_hex_dump_debug("key in @" __stringify(__LINE__)": ",
DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1); DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
@ -570,10 +565,8 @@ static int rfc4543_setkey(struct crypto_aead *aead,
int ret; int ret;
ret = aes_check_keylen(keylen - 4); ret = aes_check_keylen(keylen - 4);
if (ret) { if (ret)
crypto_aead_set_flags(aead, CRYPTO_TFM_RES_BAD_KEY_LEN);
return ret; return ret;
}
print_hex_dump_debug("key in @" __stringify(__LINE__)": ", print_hex_dump_debug("key in @" __stringify(__LINE__)": ",
DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1); DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
@ -644,7 +637,7 @@ static int skcipher_setkey(struct crypto_skcipher *skcipher, const u8 *key,
ctx->sh_desc_enc); ctx->sh_desc_enc);
if (ret) { if (ret) {
dev_err(jrdev, "driver enc context update failed\n"); dev_err(jrdev, "driver enc context update failed\n");
goto badkey; return -EINVAL;
} }
} }
@ -653,14 +646,11 @@ static int skcipher_setkey(struct crypto_skcipher *skcipher, const u8 *key,
ctx->sh_desc_dec); ctx->sh_desc_dec);
if (ret) { if (ret) {
dev_err(jrdev, "driver dec context update failed\n"); dev_err(jrdev, "driver dec context update failed\n");
goto badkey; return -EINVAL;
} }
} }
return ret; return ret;
badkey:
crypto_skcipher_set_flags(skcipher, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL;
} }
static int aes_skcipher_setkey(struct crypto_skcipher *skcipher, static int aes_skcipher_setkey(struct crypto_skcipher *skcipher,
@ -669,11 +659,8 @@ static int aes_skcipher_setkey(struct crypto_skcipher *skcipher,
int err; int err;
err = aes_check_keylen(keylen); err = aes_check_keylen(keylen);
if (err) { if (err)
crypto_skcipher_set_flags(skcipher,
CRYPTO_TFM_RES_BAD_KEY_LEN);
return err; return err;
}
return skcipher_setkey(skcipher, key, keylen, 0); return skcipher_setkey(skcipher, key, keylen, 0);
} }
@ -693,11 +680,8 @@ static int rfc3686_skcipher_setkey(struct crypto_skcipher *skcipher,
keylen -= CTR_RFC3686_NONCE_SIZE; keylen -= CTR_RFC3686_NONCE_SIZE;
err = aes_check_keylen(keylen); err = aes_check_keylen(keylen);
if (err) { if (err)
crypto_skcipher_set_flags(skcipher,
CRYPTO_TFM_RES_BAD_KEY_LEN);
return err; return err;
}
return skcipher_setkey(skcipher, key, keylen, ctx1_iv_off); return skcipher_setkey(skcipher, key, keylen, ctx1_iv_off);
} }
@ -716,11 +700,8 @@ static int ctr_skcipher_setkey(struct crypto_skcipher *skcipher,
ctx1_iv_off = 16; ctx1_iv_off = 16;
err = aes_check_keylen(keylen); err = aes_check_keylen(keylen);
if (err) { if (err)
crypto_skcipher_set_flags(skcipher,
CRYPTO_TFM_RES_BAD_KEY_LEN);
return err; return err;
}
return skcipher_setkey(skcipher, key, keylen, ctx1_iv_off); return skcipher_setkey(skcipher, key, keylen, ctx1_iv_off);
} }
@ -748,7 +729,7 @@ static int xts_skcipher_setkey(struct crypto_skcipher *skcipher, const u8 *key,
if (keylen != 2 * AES_MIN_KEY_SIZE && keylen != 2 * AES_MAX_KEY_SIZE) { if (keylen != 2 * AES_MIN_KEY_SIZE && keylen != 2 * AES_MAX_KEY_SIZE) {
dev_err(jrdev, "key size mismatch\n"); dev_err(jrdev, "key size mismatch\n");
goto badkey; return -EINVAL;
} }
ctx->cdata.keylen = keylen; ctx->cdata.keylen = keylen;
@ -765,7 +746,7 @@ static int xts_skcipher_setkey(struct crypto_skcipher *skcipher, const u8 *key,
ctx->sh_desc_enc); ctx->sh_desc_enc);
if (ret) { if (ret) {
dev_err(jrdev, "driver enc context update failed\n"); dev_err(jrdev, "driver enc context update failed\n");
goto badkey; return -EINVAL;
} }
} }
@ -774,14 +755,11 @@ static int xts_skcipher_setkey(struct crypto_skcipher *skcipher, const u8 *key,
ctx->sh_desc_dec); ctx->sh_desc_dec);
if (ret) { if (ret) {
dev_err(jrdev, "driver dec context update failed\n"); dev_err(jrdev, "driver dec context update failed\n");
goto badkey; return -EINVAL;
} }
} }
return ret; return ret;
badkey:
crypto_skcipher_set_flags(skcipher, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL;
} }
/* /*

View File

@ -313,7 +313,6 @@ static int aead_setkey(struct crypto_aead *aead, const u8 *key,
memzero_explicit(&keys, sizeof(keys)); memzero_explicit(&keys, sizeof(keys));
return aead_set_sh_desc(aead); return aead_set_sh_desc(aead);
badkey: badkey:
crypto_aead_set_flags(aead, CRYPTO_TFM_RES_BAD_KEY_LEN);
memzero_explicit(&keys, sizeof(keys)); memzero_explicit(&keys, sizeof(keys));
return -EINVAL; return -EINVAL;
} }
@ -326,11 +325,11 @@ static int des3_aead_setkey(struct crypto_aead *aead, const u8 *key,
err = crypto_authenc_extractkeys(&keys, key, keylen); err = crypto_authenc_extractkeys(&keys, key, keylen);
if (unlikely(err)) if (unlikely(err))
goto badkey; goto out;
err = -EINVAL; err = -EINVAL;
if (keys.enckeylen != DES3_EDE_KEY_SIZE) if (keys.enckeylen != DES3_EDE_KEY_SIZE)
goto badkey; goto out;
err = crypto_des3_ede_verify_key(crypto_aead_tfm(aead), keys.enckey) ?: err = crypto_des3_ede_verify_key(crypto_aead_tfm(aead), keys.enckey) ?:
aead_setkey(aead, key, keylen); aead_setkey(aead, key, keylen);
@ -338,10 +337,6 @@ static int des3_aead_setkey(struct crypto_aead *aead, const u8 *key,
out: out:
memzero_explicit(&keys, sizeof(keys)); memzero_explicit(&keys, sizeof(keys));
return err; return err;
badkey:
crypto_aead_set_flags(aead, CRYPTO_TFM_RES_BAD_KEY_LEN);
goto out;
} }
static struct aead_edesc *aead_edesc_alloc(struct aead_request *req, static struct aead_edesc *aead_edesc_alloc(struct aead_request *req,
@ -634,10 +629,8 @@ static int chachapoly_setkey(struct crypto_aead *aead, const u8 *key,
unsigned int ivsize = crypto_aead_ivsize(aead); unsigned int ivsize = crypto_aead_ivsize(aead);
unsigned int saltlen = CHACHAPOLY_IV_SIZE - ivsize; unsigned int saltlen = CHACHAPOLY_IV_SIZE - ivsize;
if (keylen != CHACHA_KEY_SIZE + saltlen) { if (keylen != CHACHA_KEY_SIZE + saltlen)
crypto_aead_set_flags(aead, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
}
ctx->cdata.key_virt = key; ctx->cdata.key_virt = key;
ctx->cdata.keylen = keylen - saltlen; ctx->cdata.keylen = keylen - saltlen;
@ -725,10 +718,8 @@ static int gcm_setkey(struct crypto_aead *aead,
int ret; int ret;
ret = aes_check_keylen(keylen); ret = aes_check_keylen(keylen);
if (ret) { if (ret)
crypto_aead_set_flags(aead, CRYPTO_TFM_RES_BAD_KEY_LEN);
return ret; return ret;
}
print_hex_dump_debug("key in @" __stringify(__LINE__)": ", print_hex_dump_debug("key in @" __stringify(__LINE__)": ",
DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1); DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
@ -822,10 +813,8 @@ static int rfc4106_setkey(struct crypto_aead *aead,
int ret; int ret;
ret = aes_check_keylen(keylen - 4); ret = aes_check_keylen(keylen - 4);
if (ret) { if (ret)
crypto_aead_set_flags(aead, CRYPTO_TFM_RES_BAD_KEY_LEN);
return ret; return ret;
}
print_hex_dump_debug("key in @" __stringify(__LINE__)": ", print_hex_dump_debug("key in @" __stringify(__LINE__)": ",
DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1); DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
@ -923,10 +912,8 @@ static int rfc4543_setkey(struct crypto_aead *aead,
int ret; int ret;
ret = aes_check_keylen(keylen - 4); ret = aes_check_keylen(keylen - 4);
if (ret) { if (ret)
crypto_aead_set_flags(aead, CRYPTO_TFM_RES_BAD_KEY_LEN);
return ret; return ret;
}
print_hex_dump_debug("key in @" __stringify(__LINE__)": ", print_hex_dump_debug("key in @" __stringify(__LINE__)": ",
DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1); DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
@ -992,11 +979,8 @@ static int aes_skcipher_setkey(struct crypto_skcipher *skcipher,
int err; int err;
err = aes_check_keylen(keylen); err = aes_check_keylen(keylen);
if (err) { if (err)
crypto_skcipher_set_flags(skcipher,
CRYPTO_TFM_RES_BAD_KEY_LEN);
return err; return err;
}
return skcipher_setkey(skcipher, key, keylen, 0); return skcipher_setkey(skcipher, key, keylen, 0);
} }
@ -1016,11 +1000,8 @@ static int rfc3686_skcipher_setkey(struct crypto_skcipher *skcipher,
keylen -= CTR_RFC3686_NONCE_SIZE; keylen -= CTR_RFC3686_NONCE_SIZE;
err = aes_check_keylen(keylen); err = aes_check_keylen(keylen);
if (err) { if (err)
crypto_skcipher_set_flags(skcipher,
CRYPTO_TFM_RES_BAD_KEY_LEN);
return err; return err;
}
return skcipher_setkey(skcipher, key, keylen, ctx1_iv_off); return skcipher_setkey(skcipher, key, keylen, ctx1_iv_off);
} }
@ -1039,11 +1020,8 @@ static int ctr_skcipher_setkey(struct crypto_skcipher *skcipher,
ctx1_iv_off = 16; ctx1_iv_off = 16;
err = aes_check_keylen(keylen); err = aes_check_keylen(keylen);
if (err) { if (err)
crypto_skcipher_set_flags(skcipher,
CRYPTO_TFM_RES_BAD_KEY_LEN);
return err; return err;
}
return skcipher_setkey(skcipher, key, keylen, ctx1_iv_off); return skcipher_setkey(skcipher, key, keylen, ctx1_iv_off);
} }
@ -1051,11 +1029,8 @@ static int ctr_skcipher_setkey(struct crypto_skcipher *skcipher,
static int chacha20_skcipher_setkey(struct crypto_skcipher *skcipher, static int chacha20_skcipher_setkey(struct crypto_skcipher *skcipher,
const u8 *key, unsigned int keylen) const u8 *key, unsigned int keylen)
{ {
if (keylen != CHACHA_KEY_SIZE) { if (keylen != CHACHA_KEY_SIZE)
crypto_skcipher_set_flags(skcipher,
CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
}
return skcipher_setkey(skcipher, key, keylen, 0); return skcipher_setkey(skcipher, key, keylen, 0);
} }
@ -1084,7 +1059,6 @@ static int xts_skcipher_setkey(struct crypto_skcipher *skcipher, const u8 *key,
if (keylen != 2 * AES_MIN_KEY_SIZE && keylen != 2 * AES_MAX_KEY_SIZE) { if (keylen != 2 * AES_MIN_KEY_SIZE && keylen != 2 * AES_MAX_KEY_SIZE) {
dev_err(dev, "key size mismatch\n"); dev_err(dev, "key size mismatch\n");
crypto_skcipher_set_flags(skcipher, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
} }
@ -3277,7 +3251,6 @@ static int ahash_setkey(struct crypto_ahash *ahash, const u8 *key,
return ret; return ret;
bad_free_key: bad_free_key:
kfree(hashed_key); kfree(hashed_key);
crypto_ahash_set_flags(ahash, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
} }

View File

@ -473,7 +473,6 @@ static int ahash_setkey(struct crypto_ahash *ahash,
return ahash_set_sh_desc(ahash); return ahash_set_sh_desc(ahash);
bad_free_key: bad_free_key:
kfree(hashed_key); kfree(hashed_key);
crypto_ahash_set_flags(ahash, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
} }
@ -483,10 +482,8 @@ static int axcbc_setkey(struct crypto_ahash *ahash, const u8 *key,
struct caam_hash_ctx *ctx = crypto_ahash_ctx(ahash); struct caam_hash_ctx *ctx = crypto_ahash_ctx(ahash);
struct device *jrdev = ctx->jrdev; struct device *jrdev = ctx->jrdev;
if (keylen != AES_KEYSIZE_128) { if (keylen != AES_KEYSIZE_128)
crypto_ahash_set_flags(ahash, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
}
memcpy(ctx->key, key, keylen); memcpy(ctx->key, key, keylen);
dma_sync_single_for_device(jrdev, ctx->adata.key_dma, keylen, dma_sync_single_for_device(jrdev, ctx->adata.key_dma, keylen,
@ -506,10 +503,8 @@ static int acmac_setkey(struct crypto_ahash *ahash, const u8 *key,
int err; int err;
err = aes_check_keylen(keylen); err = aes_check_keylen(keylen);
if (err) { if (err)
crypto_ahash_set_flags(ahash, CRYPTO_TFM_RES_BAD_KEY_LEN);
return err; return err;
}
/* key is immediate data for all cmac shared descriptors */ /* key is immediate data for all cmac shared descriptors */
ctx->adata.key_virt = key; ctx->adata.key_virt = key;

View File

@ -295,8 +295,6 @@ static int cvm_setkey(struct crypto_skcipher *cipher, const u8 *key,
memcpy(ctx->enc_key, key, keylen); memcpy(ctx->enc_key, key, keylen);
return 0; return 0;
} else { } else {
crypto_skcipher_set_flags(cipher,
CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
} }
} }

View File

@ -40,10 +40,8 @@ static int nitrox_aes_gcm_setkey(struct crypto_aead *aead, const u8 *key,
union fc_ctx_flags flags; union fc_ctx_flags flags;
aes_keylen = flexi_aes_keylen(keylen); aes_keylen = flexi_aes_keylen(keylen);
if (aes_keylen < 0) { if (aes_keylen < 0)
crypto_aead_set_flags(aead, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
}
/* fill crypto context */ /* fill crypto context */
fctx = nctx->u.fctx; fctx = nctx->u.fctx;

View File

@ -200,10 +200,8 @@ static int nitrox_aes_setkey(struct crypto_skcipher *cipher, const u8 *key,
int aes_keylen; int aes_keylen;
aes_keylen = flexi_aes_keylen(keylen); aes_keylen = flexi_aes_keylen(keylen);
if (aes_keylen < 0) { if (aes_keylen < 0)
crypto_skcipher_set_flags(cipher, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
}
return nitrox_skcipher_setkey(cipher, aes_keylen, key, keylen); return nitrox_skcipher_setkey(cipher, aes_keylen, key, keylen);
} }
@ -351,10 +349,8 @@ static int nitrox_aes_xts_setkey(struct crypto_skcipher *cipher,
keylen /= 2; keylen /= 2;
aes_keylen = flexi_aes_keylen(keylen); aes_keylen = flexi_aes_keylen(keylen);
if (aes_keylen < 0) { if (aes_keylen < 0)
crypto_skcipher_set_flags(cipher, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
}
fctx = nctx->u.fctx; fctx = nctx->u.fctx;
/* copy KEY2 */ /* copy KEY2 */
@ -382,10 +378,8 @@ static int nitrox_aes_ctr_rfc3686_setkey(struct crypto_skcipher *cipher,
keylen -= CTR_RFC3686_NONCE_SIZE; keylen -= CTR_RFC3686_NONCE_SIZE;
aes_keylen = flexi_aes_keylen(keylen); aes_keylen = flexi_aes_keylen(keylen);
if (aes_keylen < 0) { if (aes_keylen < 0)
crypto_skcipher_set_flags(cipher, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
}
return nitrox_skcipher_setkey(cipher, aes_keylen, key, keylen); return nitrox_skcipher_setkey(cipher, aes_keylen, key, keylen);
} }

View File

@ -276,7 +276,6 @@ static int ccp_aes_cmac_setkey(struct crypto_ahash *tfm, const u8 *key,
ctx->u.aes.type = CCP_AES_TYPE_256; ctx->u.aes.type = CCP_AES_TYPE_256;
break; break;
default: default:
crypto_ahash_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
} }
ctx->u.aes.mode = alg->mode; ctx->u.aes.mode = alg->mode;

View File

@ -42,7 +42,6 @@ static int ccp_aes_gcm_setkey(struct crypto_aead *tfm, const u8 *key,
ctx->u.aes.type = CCP_AES_TYPE_256; ctx->u.aes.type = CCP_AES_TYPE_256;
break; break;
default: default:
crypto_aead_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
} }

View File

@ -51,7 +51,6 @@ static int ccp_aes_setkey(struct crypto_skcipher *tfm, const u8 *key,
ctx->u.aes.type = CCP_AES_TYPE_256; ctx->u.aes.type = CCP_AES_TYPE_256;
break; break;
default: default:
crypto_skcipher_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
} }
ctx->u.aes.mode = alg->mode; ctx->u.aes.mode = alg->mode;

View File

@ -293,10 +293,8 @@ static int ccp_sha_setkey(struct crypto_ahash *tfm, const u8 *key,
ret = crypto_shash_digest(sdesc, key, key_len, ret = crypto_shash_digest(sdesc, key, key_len,
ctx->u.sha.key); ctx->u.sha.key);
if (ret) { if (ret)
crypto_ahash_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
}
key_len = digest_size; key_len = digest_size;
} else { } else {

View File

@ -562,7 +562,7 @@ static int cc_aead_setkey(struct crypto_aead *tfm, const u8 *key,
rc = crypto_authenc_extractkeys(&keys, key, keylen); rc = crypto_authenc_extractkeys(&keys, key, keylen);
if (rc) if (rc)
goto badkey; return rc;
enckey = keys.enckey; enckey = keys.enckey;
authkey = keys.authkey; authkey = keys.authkey;
ctx->enc_keylen = keys.enckeylen; ctx->enc_keylen = keys.enckeylen;
@ -570,10 +570,9 @@ static int cc_aead_setkey(struct crypto_aead *tfm, const u8 *key,
if (ctx->cipher_mode == DRV_CIPHER_CTR) { if (ctx->cipher_mode == DRV_CIPHER_CTR) {
/* the nonce is stored in bytes at end of key */ /* the nonce is stored in bytes at end of key */
rc = -EINVAL;
if (ctx->enc_keylen < if (ctx->enc_keylen <
(AES_MIN_KEY_SIZE + CTR_RFC3686_NONCE_SIZE)) (AES_MIN_KEY_SIZE + CTR_RFC3686_NONCE_SIZE))
goto badkey; return -EINVAL;
/* Copy nonce from last 4 bytes in CTR key to /* Copy nonce from last 4 bytes in CTR key to
* first 4 bytes in CTR IV * first 4 bytes in CTR IV
*/ */
@ -591,7 +590,7 @@ static int cc_aead_setkey(struct crypto_aead *tfm, const u8 *key,
rc = validate_keys_sizes(ctx); rc = validate_keys_sizes(ctx);
if (rc) if (rc)
goto badkey; return rc;
/* STAT_PHASE_1: Copy key to ctx */ /* STAT_PHASE_1: Copy key to ctx */
@ -605,7 +604,7 @@ static int cc_aead_setkey(struct crypto_aead *tfm, const u8 *key,
} else if (ctx->auth_mode != DRV_HASH_NULL) { /* HMAC */ } else if (ctx->auth_mode != DRV_HASH_NULL) { /* HMAC */
rc = cc_get_plain_hmac_key(tfm, authkey, ctx->auth_keylen); rc = cc_get_plain_hmac_key(tfm, authkey, ctx->auth_keylen);
if (rc) if (rc)
goto badkey; return rc;
} }
/* STAT_PHASE_2: Create sequence */ /* STAT_PHASE_2: Create sequence */
@ -622,8 +621,7 @@ static int cc_aead_setkey(struct crypto_aead *tfm, const u8 *key,
break; /* No auth. key setup */ break; /* No auth. key setup */
default: default:
dev_err(dev, "Unsupported authenc (%d)\n", ctx->auth_mode); dev_err(dev, "Unsupported authenc (%d)\n", ctx->auth_mode);
rc = -ENOTSUPP; return -ENOTSUPP;
goto badkey;
} }
/* STAT_PHASE_3: Submit sequence to HW */ /* STAT_PHASE_3: Submit sequence to HW */
@ -632,18 +630,12 @@ static int cc_aead_setkey(struct crypto_aead *tfm, const u8 *key,
rc = cc_send_sync_request(ctx->drvdata, &cc_req, desc, seq_len); rc = cc_send_sync_request(ctx->drvdata, &cc_req, desc, seq_len);
if (rc) { if (rc) {
dev_err(dev, "send_request() failed (rc=%d)\n", rc); dev_err(dev, "send_request() failed (rc=%d)\n", rc);
goto setkey_error; return rc;
} }
} }
/* Update STAT_PHASE_3 */ /* Update STAT_PHASE_3 */
return rc; return rc;
badkey:
crypto_aead_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
setkey_error:
return rc;
} }
static int cc_des3_aead_setkey(struct crypto_aead *aead, const u8 *key, static int cc_des3_aead_setkey(struct crypto_aead *aead, const u8 *key,

View File

@ -291,7 +291,6 @@ static int cc_cipher_sethkey(struct crypto_skcipher *sktfm, const u8 *key,
/* This check the size of the protected key token */ /* This check the size of the protected key token */
if (keylen != sizeof(hki)) { if (keylen != sizeof(hki)) {
dev_err(dev, "Unsupported protected key size %d.\n", keylen); dev_err(dev, "Unsupported protected key size %d.\n", keylen);
crypto_tfm_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
} }
@ -304,7 +303,6 @@ static int cc_cipher_sethkey(struct crypto_skcipher *sktfm, const u8 *key,
if (validate_keys_sizes(ctx_p, keylen)) { if (validate_keys_sizes(ctx_p, keylen)) {
dev_err(dev, "Unsupported key size %d.\n", keylen); dev_err(dev, "Unsupported key size %d.\n", keylen);
crypto_tfm_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
} }
@ -395,7 +393,6 @@ static int cc_cipher_setkey(struct crypto_skcipher *sktfm, const u8 *key,
if (validate_keys_sizes(ctx_p, keylen)) { if (validate_keys_sizes(ctx_p, keylen)) {
dev_err(dev, "Unsupported key size %d.\n", keylen); dev_err(dev, "Unsupported key size %d.\n", keylen);
crypto_tfm_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
} }

View File

@ -899,9 +899,6 @@ static int cc_hash_setkey(struct crypto_ahash *ahash, const u8 *key,
rc = cc_send_sync_request(ctx->drvdata, &cc_req, desc, idx); rc = cc_send_sync_request(ctx->drvdata, &cc_req, desc, idx);
out: out:
if (rc)
crypto_ahash_set_flags(ahash, CRYPTO_TFM_RES_BAD_KEY_LEN);
if (ctx->key_params.key_dma_addr) { if (ctx->key_params.key_dma_addr) {
dma_unmap_single(dev, ctx->key_params.key_dma_addr, dma_unmap_single(dev, ctx->key_params.key_dma_addr,
ctx->key_params.keylen, DMA_TO_DEVICE); ctx->key_params.keylen, DMA_TO_DEVICE);
@ -990,9 +987,6 @@ static int cc_xcbc_setkey(struct crypto_ahash *ahash,
rc = cc_send_sync_request(ctx->drvdata, &cc_req, desc, idx); rc = cc_send_sync_request(ctx->drvdata, &cc_req, desc, idx);
if (rc)
crypto_ahash_set_flags(ahash, CRYPTO_TFM_RES_BAD_KEY_LEN);
dma_unmap_single(dev, ctx->key_params.key_dma_addr, dma_unmap_single(dev, ctx->key_params.key_dma_addr,
ctx->key_params.keylen, DMA_TO_DEVICE); ctx->key_params.keylen, DMA_TO_DEVICE);
dev_dbg(dev, "Unmapped key-buffer: key_dma_addr=%pad keylen=%u\n", dev_dbg(dev, "Unmapped key-buffer: key_dma_addr=%pad keylen=%u\n",

View File

@ -912,7 +912,6 @@ static int chcr_aes_cbc_setkey(struct crypto_skcipher *cipher,
ablkctx->ciph_mode = CHCR_SCMD_CIPHER_MODE_AES_CBC; ablkctx->ciph_mode = CHCR_SCMD_CIPHER_MODE_AES_CBC;
return 0; return 0;
badkey_err: badkey_err:
crypto_skcipher_set_flags(cipher, CRYPTO_TFM_RES_BAD_KEY_LEN);
ablkctx->enckey_len = 0; ablkctx->enckey_len = 0;
return err; return err;
@ -943,7 +942,6 @@ static int chcr_aes_ctr_setkey(struct crypto_skcipher *cipher,
return 0; return 0;
badkey_err: badkey_err:
crypto_skcipher_set_flags(cipher, CRYPTO_TFM_RES_BAD_KEY_LEN);
ablkctx->enckey_len = 0; ablkctx->enckey_len = 0;
return err; return err;
@ -981,7 +979,6 @@ static int chcr_aes_rfc3686_setkey(struct crypto_skcipher *cipher,
return 0; return 0;
badkey_err: badkey_err:
crypto_skcipher_set_flags(cipher, CRYPTO_TFM_RES_BAD_KEY_LEN);
ablkctx->enckey_len = 0; ablkctx->enckey_len = 0;
return err; return err;
@ -2174,7 +2171,6 @@ static int chcr_aes_xts_setkey(struct crypto_skcipher *cipher, const u8 *key,
ablkctx->ciph_mode = CHCR_SCMD_CIPHER_MODE_AES_XTS; ablkctx->ciph_mode = CHCR_SCMD_CIPHER_MODE_AES_XTS;
return 0; return 0;
badkey_err: badkey_err:
crypto_skcipher_set_flags(cipher, CRYPTO_TFM_RES_BAD_KEY_LEN);
ablkctx->enckey_len = 0; ablkctx->enckey_len = 0;
return err; return err;
@ -3284,7 +3280,6 @@ static int chcr_ccm_common_setkey(struct crypto_aead *aead,
ck_size = CHCR_KEYCTX_CIPHER_KEY_SIZE_256; ck_size = CHCR_KEYCTX_CIPHER_KEY_SIZE_256;
mk_size = CHCR_KEYCTX_MAC_KEY_SIZE_256; mk_size = CHCR_KEYCTX_MAC_KEY_SIZE_256;
} else { } else {
crypto_aead_set_flags(aead, CRYPTO_TFM_RES_BAD_KEY_LEN);
aeadctx->enckey_len = 0; aeadctx->enckey_len = 0;
return -EINVAL; return -EINVAL;
} }
@ -3322,7 +3317,6 @@ static int chcr_aead_rfc4309_setkey(struct crypto_aead *aead, const u8 *key,
int error; int error;
if (keylen < 3) { if (keylen < 3) {
crypto_aead_set_flags(aead, CRYPTO_TFM_RES_BAD_KEY_LEN);
aeadctx->enckey_len = 0; aeadctx->enckey_len = 0;
return -EINVAL; return -EINVAL;
} }
@ -3372,7 +3366,6 @@ static int chcr_gcm_setkey(struct crypto_aead *aead, const u8 *key,
} else if (keylen == AES_KEYSIZE_256) { } else if (keylen == AES_KEYSIZE_256) {
ck_size = CHCR_KEYCTX_CIPHER_KEY_SIZE_256; ck_size = CHCR_KEYCTX_CIPHER_KEY_SIZE_256;
} else { } else {
crypto_aead_set_flags(aead, CRYPTO_TFM_RES_BAD_KEY_LEN);
pr_err("GCM: Invalid key length %d\n", keylen); pr_err("GCM: Invalid key length %d\n", keylen);
ret = -EINVAL; ret = -EINVAL;
goto out; goto out;
@ -3429,10 +3422,8 @@ static int chcr_authenc_setkey(struct crypto_aead *authenc, const u8 *key,
if (err) if (err)
goto out; goto out;
if (crypto_authenc_extractkeys(&keys, key, keylen) != 0) { if (crypto_authenc_extractkeys(&keys, key, keylen) != 0)
crypto_aead_set_flags(authenc, CRYPTO_TFM_RES_BAD_KEY_LEN);
goto out; goto out;
}
if (get_alg_config(&param, max_authsize)) { if (get_alg_config(&param, max_authsize)) {
pr_err("chcr : Unsupported digest size\n"); pr_err("chcr : Unsupported digest size\n");
@ -3559,10 +3550,9 @@ static int chcr_aead_digest_null_setkey(struct crypto_aead *authenc,
if (err) if (err)
goto out; goto out;
if (crypto_authenc_extractkeys(&keys, key, keylen) != 0) { if (crypto_authenc_extractkeys(&keys, key, keylen) != 0)
crypto_aead_set_flags(authenc, CRYPTO_TFM_RES_BAD_KEY_LEN);
goto out; goto out;
}
subtype = get_aead_subtype(authenc); subtype = get_aead_subtype(authenc);
if (subtype == CRYPTO_ALG_SUB_TYPE_CTR_SHA || if (subtype == CRYPTO_ALG_SUB_TYPE_CTR_SHA ||
subtype == CRYPTO_ALG_SUB_TYPE_CTR_NULL) { subtype == CRYPTO_ALG_SUB_TYPE_CTR_NULL) {

View File

@ -119,11 +119,9 @@ static int geode_setkey_cip(struct crypto_tfm *tfm, const u8 *key,
return 0; return 0;
} }
if (len != AES_KEYSIZE_192 && len != AES_KEYSIZE_256) { if (len != AES_KEYSIZE_192 && len != AES_KEYSIZE_256)
/* not supported at all */ /* not supported at all */
tfm->crt_flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
return -EINVAL; return -EINVAL;
}
/* /*
* The requested key size is not supported by HW, do a fallback * The requested key size is not supported by HW, do a fallback
@ -154,11 +152,9 @@ static int geode_setkey_skcipher(struct crypto_skcipher *tfm, const u8 *key,
return 0; return 0;
} }
if (len != AES_KEYSIZE_192 && len != AES_KEYSIZE_256) { if (len != AES_KEYSIZE_192 && len != AES_KEYSIZE_256)
/* not supported at all */ /* not supported at all */
crypto_skcipher_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
}
/* /*
* The requested key size is not supported by HW, do a fallback * The requested key size is not supported by HW, do a fallback

View File

@ -380,10 +380,8 @@ static int safexcel_skcipher_aes_setkey(struct crypto_skcipher *ctfm,
int ret, i; int ret, i;
ret = aes_expandkey(&aes, key, len); ret = aes_expandkey(&aes, key, len);
if (ret) { if (ret)
crypto_skcipher_set_flags(ctfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return ret; return ret;
}
if (priv->flags & EIP197_TRC_CACHE && ctx->base.ctxr_dma) { if (priv->flags & EIP197_TRC_CACHE && ctx->base.ctxr_dma) {
for (i = 0; i < len / sizeof(u32); i++) { for (i = 0; i < len / sizeof(u32); i++) {
@ -433,12 +431,12 @@ static int safexcel_aead_setkey(struct crypto_aead *ctfm, const u8 *key,
case SAFEXCEL_DES: case SAFEXCEL_DES:
err = verify_aead_des_key(ctfm, keys.enckey, keys.enckeylen); err = verify_aead_des_key(ctfm, keys.enckey, keys.enckeylen);
if (unlikely(err)) if (unlikely(err))
goto badkey_expflags; goto badkey;
break; break;
case SAFEXCEL_3DES: case SAFEXCEL_3DES:
err = verify_aead_des3_key(ctfm, keys.enckey, keys.enckeylen); err = verify_aead_des3_key(ctfm, keys.enckey, keys.enckeylen);
if (unlikely(err)) if (unlikely(err))
goto badkey_expflags; goto badkey;
break; break;
case SAFEXCEL_AES: case SAFEXCEL_AES:
err = aes_expandkey(&aes, keys.enckey, keys.enckeylen); err = aes_expandkey(&aes, keys.enckey, keys.enckeylen);
@ -521,8 +519,6 @@ static int safexcel_aead_setkey(struct crypto_aead *ctfm, const u8 *key,
return 0; return 0;
badkey: badkey:
crypto_aead_set_flags(ctfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
badkey_expflags:
memzero_explicit(&keys, sizeof(keys)); memzero_explicit(&keys, sizeof(keys));
return err; return err;
} }
@ -1444,10 +1440,8 @@ static int safexcel_skcipher_aesctr_setkey(struct crypto_skcipher *ctfm,
/* exclude the nonce here */ /* exclude the nonce here */
keylen = len - CTR_RFC3686_NONCE_SIZE; keylen = len - CTR_RFC3686_NONCE_SIZE;
ret = aes_expandkey(&aes, key, keylen); ret = aes_expandkey(&aes, key, keylen);
if (ret) { if (ret)
crypto_skcipher_set_flags(ctfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return ret; return ret;
}
if (priv->flags & EIP197_TRC_CACHE && ctx->base.ctxr_dma) { if (priv->flags & EIP197_TRC_CACHE && ctx->base.ctxr_dma) {
for (i = 0; i < keylen / sizeof(u32); i++) { for (i = 0; i < keylen / sizeof(u32); i++) {
@ -2459,10 +2453,8 @@ static int safexcel_skcipher_aesxts_setkey(struct crypto_skcipher *ctfm,
/* Only half of the key data is cipher key */ /* Only half of the key data is cipher key */
keylen = (len >> 1); keylen = (len >> 1);
ret = aes_expandkey(&aes, key, keylen); ret = aes_expandkey(&aes, key, keylen);
if (ret) { if (ret)
crypto_skcipher_set_flags(ctfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return ret; return ret;
}
if (priv->flags & EIP197_TRC_CACHE && ctx->base.ctxr_dma) { if (priv->flags & EIP197_TRC_CACHE && ctx->base.ctxr_dma) {
for (i = 0; i < keylen / sizeof(u32); i++) { for (i = 0; i < keylen / sizeof(u32); i++) {
@ -2478,10 +2470,8 @@ static int safexcel_skcipher_aesxts_setkey(struct crypto_skcipher *ctfm,
/* The other half is the tweak key */ /* The other half is the tweak key */
ret = aes_expandkey(&aes, (u8 *)(key + keylen), keylen); ret = aes_expandkey(&aes, (u8 *)(key + keylen), keylen);
if (ret) { if (ret)
crypto_skcipher_set_flags(ctfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return ret; return ret;
}
if (priv->flags & EIP197_TRC_CACHE && ctx->base.ctxr_dma) { if (priv->flags & EIP197_TRC_CACHE && ctx->base.ctxr_dma) {
for (i = 0; i < keylen / sizeof(u32); i++) { for (i = 0; i < keylen / sizeof(u32); i++) {
@ -2570,7 +2560,6 @@ static int safexcel_aead_gcm_setkey(struct crypto_aead *ctfm, const u8 *key,
ret = aes_expandkey(&aes, key, len); ret = aes_expandkey(&aes, key, len);
if (ret) { if (ret) {
crypto_aead_set_flags(ctfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
memzero_explicit(&aes, sizeof(aes)); memzero_explicit(&aes, sizeof(aes));
return ret; return ret;
} }
@ -2684,7 +2673,6 @@ static int safexcel_aead_ccm_setkey(struct crypto_aead *ctfm, const u8 *key,
ret = aes_expandkey(&aes, key, len); ret = aes_expandkey(&aes, key, len);
if (ret) { if (ret) {
crypto_aead_set_flags(ctfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
memzero_explicit(&aes, sizeof(aes)); memzero_explicit(&aes, sizeof(aes));
return ret; return ret;
} }
@ -2815,10 +2803,9 @@ static int safexcel_skcipher_chacha20_setkey(struct crypto_skcipher *ctfm,
{ {
struct safexcel_cipher_ctx *ctx = crypto_skcipher_ctx(ctfm); struct safexcel_cipher_ctx *ctx = crypto_skcipher_ctx(ctfm);
if (len != CHACHA_KEY_SIZE) { if (len != CHACHA_KEY_SIZE)
crypto_skcipher_set_flags(ctfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
}
safexcel_chacha20_setkey(ctx, key); safexcel_chacha20_setkey(ctx, key);
return 0; return 0;
@ -2872,10 +2859,9 @@ static int safexcel_aead_chachapoly_setkey(struct crypto_aead *ctfm,
len -= EIP197_AEAD_IPSEC_NONCE_SIZE; len -= EIP197_AEAD_IPSEC_NONCE_SIZE;
ctx->nonce = *(u32 *)(key + len); ctx->nonce = *(u32 *)(key + len);
} }
if (len != CHACHA_KEY_SIZE) { if (len != CHACHA_KEY_SIZE)
crypto_aead_set_flags(ctfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
}
safexcel_chacha20_setkey(ctx, key); safexcel_chacha20_setkey(ctx, key);
return 0; return 0;
@ -3070,10 +3056,8 @@ static int safexcel_skcipher_sm4_setkey(struct crypto_skcipher *ctfm,
struct safexcel_cipher_ctx *ctx = crypto_tfm_ctx(tfm); struct safexcel_cipher_ctx *ctx = crypto_tfm_ctx(tfm);
struct safexcel_crypto_priv *priv = ctx->priv; struct safexcel_crypto_priv *priv = ctx->priv;
if (len != SM4_KEY_SIZE) { if (len != SM4_KEY_SIZE)
crypto_skcipher_set_flags(ctfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
}
if (priv->flags & EIP197_TRC_CACHE && ctx->base.ctxr_dma) if (priv->flags & EIP197_TRC_CACHE && ctx->base.ctxr_dma)
if (memcmp(ctx->key, key, SM4_KEY_SIZE)) if (memcmp(ctx->key, key, SM4_KEY_SIZE))

View File

@ -1919,10 +1919,8 @@ static int safexcel_crc32_setkey(struct crypto_ahash *tfm, const u8 *key,
{ {
struct safexcel_ahash_ctx *ctx = crypto_tfm_ctx(crypto_ahash_tfm(tfm)); struct safexcel_ahash_ctx *ctx = crypto_tfm_ctx(crypto_ahash_tfm(tfm));
if (keylen != sizeof(u32)) { if (keylen != sizeof(u32))
crypto_ahash_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
}
memcpy(ctx->ipad, key, sizeof(u32)); memcpy(ctx->ipad, key, sizeof(u32));
return 0; return 0;
@ -1995,10 +1993,8 @@ static int safexcel_cbcmac_setkey(struct crypto_ahash *tfm, const u8 *key,
int ret, i; int ret, i;
ret = aes_expandkey(&aes, key, len); ret = aes_expandkey(&aes, key, len);
if (ret) { if (ret)
crypto_ahash_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return ret; return ret;
}
memset(ctx->ipad, 0, 2 * AES_BLOCK_SIZE); memset(ctx->ipad, 0, 2 * AES_BLOCK_SIZE);
for (i = 0; i < len / sizeof(u32); i++) for (i = 0; i < len / sizeof(u32); i++)
@ -2065,10 +2061,8 @@ static int safexcel_xcbcmac_setkey(struct crypto_ahash *tfm, const u8 *key,
int ret, i; int ret, i;
ret = aes_expandkey(&aes, key, len); ret = aes_expandkey(&aes, key, len);
if (ret) { if (ret)
crypto_ahash_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return ret; return ret;
}
/* precompute the XCBC key material */ /* precompute the XCBC key material */
crypto_cipher_clear_flags(ctx->kaes, CRYPTO_TFM_REQ_MASK); crypto_cipher_clear_flags(ctx->kaes, CRYPTO_TFM_REQ_MASK);
@ -2168,10 +2162,8 @@ static int safexcel_cmac_setkey(struct crypto_ahash *tfm, const u8 *key,
int ret, i; int ret, i;
ret = aes_expandkey(&aes, key, len); ret = aes_expandkey(&aes, key, len);
if (ret) { if (ret)
crypto_ahash_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return ret; return ret;
}
for (i = 0; i < len / sizeof(u32); i++) for (i = 0; i < len / sizeof(u32); i++)
ctx->ipad[i + 8] = ctx->ipad[i + 8] =

View File

@ -740,7 +740,6 @@ static int setup_cipher(struct crypto_tfm *tfm, int encrypt,
u32 keylen_cfg = 0; u32 keylen_cfg = 0;
struct ix_sa_dir *dir; struct ix_sa_dir *dir;
struct ixp_ctx *ctx = crypto_tfm_ctx(tfm); struct ixp_ctx *ctx = crypto_tfm_ctx(tfm);
u32 *flags = &tfm->crt_flags;
dir = encrypt ? &ctx->encrypt : &ctx->decrypt; dir = encrypt ? &ctx->encrypt : &ctx->decrypt;
cinfo = dir->npe_ctx; cinfo = dir->npe_ctx;
@ -757,7 +756,6 @@ static int setup_cipher(struct crypto_tfm *tfm, int encrypt,
case 24: keylen_cfg = MOD_AES192; break; case 24: keylen_cfg = MOD_AES192; break;
case 32: keylen_cfg = MOD_AES256; break; case 32: keylen_cfg = MOD_AES256; break;
default: default:
*flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
return -EINVAL; return -EINVAL;
} }
cipher_cfg |= keylen_cfg; cipher_cfg |= keylen_cfg;
@ -1169,7 +1167,6 @@ static int aead_setkey(struct crypto_aead *tfm, const u8 *key,
memzero_explicit(&keys, sizeof(keys)); memzero_explicit(&keys, sizeof(keys));
return aead_setup(tfm, crypto_aead_authsize(tfm)); return aead_setup(tfm, crypto_aead_authsize(tfm));
badkey: badkey:
crypto_aead_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
memzero_explicit(&keys, sizeof(keys)); memzero_explicit(&keys, sizeof(keys));
return -EINVAL; return -EINVAL;
} }

View File

@ -255,10 +255,8 @@ static int mv_cesa_aes_setkey(struct crypto_skcipher *cipher, const u8 *key,
int i; int i;
ret = aes_expandkey(&ctx->aes, key, len); ret = aes_expandkey(&ctx->aes, key, len);
if (ret) { if (ret)
crypto_skcipher_set_flags(cipher, CRYPTO_TFM_RES_BAD_KEY_LEN);
return ret; return ret;
}
remaining = (ctx->aes.key_length - 16) / 4; remaining = (ctx->aes.key_length - 16) / 4;
offset = ctx->aes.key_length + 24 - remaining; offset = ctx->aes.key_length + 24 - remaining;

View File

@ -652,7 +652,6 @@ static int mtk_aes_setkey(struct crypto_skcipher *tfm,
break; break;
default: default:
crypto_skcipher_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
} }
@ -1022,7 +1021,6 @@ static int mtk_aes_gcm_setkey(struct crypto_aead *aead, const u8 *key,
break; break;
default: default:
crypto_aead_set_flags(aead, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
} }

View File

@ -746,7 +746,6 @@ static int n2_aes_setkey(struct crypto_skcipher *skcipher, const u8 *key,
ctx->enc_type |= ENC_TYPE_ALG_AES256; ctx->enc_type |= ENC_TYPE_ALG_AES256;
break; break;
default: default:
crypto_skcipher_set_flags(skcipher, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
} }

View File

@ -108,14 +108,11 @@ static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
{ {
struct aes_ctx *ctx = aes_ctx(tfm); struct aes_ctx *ctx = aes_ctx(tfm);
const __le32 *key = (const __le32 *)in_key; const __le32 *key = (const __le32 *)in_key;
u32 *flags = &tfm->crt_flags;
struct crypto_aes_ctx gen_aes; struct crypto_aes_ctx gen_aes;
int cpu; int cpu;
if (key_len % 8) { if (key_len % 8)
*flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
return -EINVAL; return -EINVAL;
}
/* /*
* If the hardware is capable of generating the extended key * If the hardware is capable of generating the extended key
@ -146,10 +143,8 @@ static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
ctx->cword.encrypt.keygen = 1; ctx->cword.encrypt.keygen = 1;
ctx->cword.decrypt.keygen = 1; ctx->cword.decrypt.keygen = 1;
if (aes_expandkey(&gen_aes, in_key, key_len)) { if (aes_expandkey(&gen_aes, in_key, key_len))
*flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
return -EINVAL; return -EINVAL;
}
memcpy(ctx->E, gen_aes.key_enc, AES_MAX_KEYLENGTH); memcpy(ctx->E, gen_aes.key_enc, AES_MAX_KEYLENGTH);
memcpy(ctx->D, gen_aes.key_dec, AES_MAX_KEYLENGTH); memcpy(ctx->D, gen_aes.key_dec, AES_MAX_KEYLENGTH);

View File

@ -490,7 +490,6 @@ static int spacc_aead_setkey(struct crypto_aead *tfm, const u8 *key,
return 0; return 0;
badkey: badkey:
crypto_aead_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
memzero_explicit(&keys, sizeof(keys)); memzero_explicit(&keys, sizeof(keys));
return -EINVAL; return -EINVAL;
} }
@ -780,10 +779,8 @@ static int spacc_aes_setkey(struct crypto_skcipher *cipher, const u8 *key,
struct spacc_ablk_ctx *ctx = crypto_tfm_ctx(tfm); struct spacc_ablk_ctx *ctx = crypto_tfm_ctx(tfm);
int err = 0; int err = 0;
if (len > AES_MAX_KEY_SIZE) { if (len > AES_MAX_KEY_SIZE)
crypto_skcipher_set_flags(cipher, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
}
/* /*
* IPSec engine only supports 128 and 256 bit AES keys. If we get a * IPSec engine only supports 128 and 256 bit AES keys. If we get a
@ -830,7 +827,6 @@ static int spacc_kasumi_f8_setkey(struct crypto_skcipher *cipher,
int err = 0; int err = 0;
if (len > AES_MAX_KEY_SIZE) { if (len > AES_MAX_KEY_SIZE) {
crypto_skcipher_set_flags(cipher, CRYPTO_TFM_RES_BAD_KEY_LEN);
err = -EINVAL; err = -EINVAL;
goto out; goto out;
} }

View File

@ -570,7 +570,6 @@ static int qat_alg_aead_init_sessions(struct crypto_aead *tfm, const u8 *key,
memzero_explicit(&keys, sizeof(keys)); memzero_explicit(&keys, sizeof(keys));
return 0; return 0;
bad_key: bad_key:
crypto_aead_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
memzero_explicit(&keys, sizeof(keys)); memzero_explicit(&keys, sizeof(keys));
return -EINVAL; return -EINVAL;
error: error:
@ -586,14 +585,11 @@ static int qat_alg_skcipher_init_sessions(struct qat_alg_skcipher_ctx *ctx,
int alg; int alg;
if (qat_alg_validate_key(keylen, &alg, mode)) if (qat_alg_validate_key(keylen, &alg, mode))
goto bad_key; return -EINVAL;
qat_alg_skcipher_init_enc(ctx, alg, key, keylen, mode); qat_alg_skcipher_init_enc(ctx, alg, key, keylen, mode);
qat_alg_skcipher_init_dec(ctx, alg, key, keylen, mode); qat_alg_skcipher_init_dec(ctx, alg, key, keylen, mode);
return 0; return 0;
bad_key:
crypto_skcipher_set_flags(ctx->tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL;
} }
static int qat_alg_aead_rekey(struct crypto_aead *tfm, const uint8_t *key, static int qat_alg_aead_rekey(struct crypto_aead *tfm, const uint8_t *key,

View File

@ -396,8 +396,6 @@ static int qce_ahash_hmac_setkey(struct crypto_ahash *tfm, const u8 *key,
ahash_request_set_crypt(req, &sg, ctx->authkey, keylen); ahash_request_set_crypt(req, &sg, ctx->authkey, keylen);
ret = crypto_wait_req(crypto_ahash_digest(req), &wait); ret = crypto_wait_req(crypto_ahash_digest(req), &wait);
if (ret)
crypto_ahash_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
kfree(buf); kfree(buf);
err_free_req: err_free_req:

View File

@ -34,10 +34,8 @@ static int rk_aes_setkey(struct crypto_skcipher *cipher,
struct rk_cipher_ctx *ctx = crypto_tfm_ctx(tfm); struct rk_cipher_ctx *ctx = crypto_tfm_ctx(tfm);
if (keylen != AES_KEYSIZE_128 && keylen != AES_KEYSIZE_192 && if (keylen != AES_KEYSIZE_128 && keylen != AES_KEYSIZE_192 &&
keylen != AES_KEYSIZE_256) { keylen != AES_KEYSIZE_256)
crypto_skcipher_set_flags(cipher, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
}
ctx->keylen = keylen; ctx->keylen = keylen;
memcpy_toio(ctx->dev->reg + RK_CRYPTO_AES_KEY_0, key, keylen); memcpy_toio(ctx->dev->reg + RK_CRYPTO_AES_KEY_0, key, keylen);
return 0; return 0;

View File

@ -85,10 +85,8 @@ static int stm32_crc_setkey(struct crypto_shash *tfm, const u8 *key,
{ {
struct stm32_crc_ctx *mctx = crypto_shash_ctx(tfm); struct stm32_crc_ctx *mctx = crypto_shash_ctx(tfm);
if (keylen != sizeof(u32)) { if (keylen != sizeof(u32))
crypto_shash_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
}
mctx->key = get_unaligned_le32(key); mctx->key = get_unaligned_le32(key);
return 0; return 0;

View File

@ -914,7 +914,6 @@ static int aead_setkey(struct crypto_aead *authenc,
return 0; return 0;
badkey: badkey:
crypto_aead_set_flags(authenc, CRYPTO_TFM_RES_BAD_KEY_LEN);
memzero_explicit(&keys, sizeof(keys)); memzero_explicit(&keys, sizeof(keys));
return -EINVAL; return -EINVAL;
} }
@ -929,11 +928,11 @@ static int aead_des3_setkey(struct crypto_aead *authenc,
err = crypto_authenc_extractkeys(&keys, key, keylen); err = crypto_authenc_extractkeys(&keys, key, keylen);
if (unlikely(err)) if (unlikely(err))
goto badkey; goto out;
err = -EINVAL; err = -EINVAL;
if (keys.authkeylen + keys.enckeylen > TALITOS_MAX_KEY_SIZE) if (keys.authkeylen + keys.enckeylen > TALITOS_MAX_KEY_SIZE)
goto badkey; goto out;
err = verify_aead_des3_key(authenc, keys.enckey, keys.enckeylen); err = verify_aead_des3_key(authenc, keys.enckey, keys.enckeylen);
if (err) if (err)
@ -954,10 +953,6 @@ static int aead_des3_setkey(struct crypto_aead *authenc,
out: out:
memzero_explicit(&keys, sizeof(keys)); memzero_explicit(&keys, sizeof(keys));
return err; return err;
badkey:
crypto_aead_set_flags(authenc, CRYPTO_TFM_RES_BAD_KEY_LEN);
goto out;
} }
static void talitos_sg_unmap(struct device *dev, static void talitos_sg_unmap(struct device *dev,
@ -1528,8 +1523,6 @@ static int skcipher_aes_setkey(struct crypto_skcipher *cipher,
keylen == AES_KEYSIZE_256) keylen == AES_KEYSIZE_256)
return skcipher_setkey(cipher, key, keylen); return skcipher_setkey(cipher, key, keylen);
crypto_skcipher_set_flags(cipher, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
} }
@ -2234,10 +2227,8 @@ static int ahash_setkey(struct crypto_ahash *tfm, const u8 *key,
/* Must get the hash of the long key */ /* Must get the hash of the long key */
ret = keyhash(tfm, key, keylen, hash); ret = keyhash(tfm, key, keylen, hash);
if (ret) { if (ret)
crypto_ahash_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
}
keysize = digestsize; keysize = digestsize;
memcpy(ctx->key, hash, digestsize); memcpy(ctx->key, hash, digestsize);

View File

@ -951,7 +951,6 @@ static int aes_skcipher_setkey(struct crypto_skcipher *cipher,
const u8 *key, unsigned int keylen) const u8 *key, unsigned int keylen)
{ {
struct cryp_ctx *ctx = crypto_skcipher_ctx(cipher); struct cryp_ctx *ctx = crypto_skcipher_ctx(cipher);
u32 *flags = &cipher->base.crt_flags;
pr_debug(DEV_DBG_NAME " [%s]", __func__); pr_debug(DEV_DBG_NAME " [%s]", __func__);
@ -970,7 +969,6 @@ static int aes_skcipher_setkey(struct crypto_skcipher *cipher,
default: default:
pr_err(DEV_DBG_NAME "[%s]: Unknown keylen!", __func__); pr_err(DEV_DBG_NAME "[%s]: Unknown keylen!", __func__);
*flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
return -EINVAL; return -EINVAL;
} }

View File

@ -272,11 +272,11 @@ static int virtio_crypto_alg_skcipher_init_sessions(
if (keylen > vcrypto->max_cipher_key_len) { if (keylen > vcrypto->max_cipher_key_len) {
pr_err("virtio_crypto: the key is too long\n"); pr_err("virtio_crypto: the key is too long\n");
goto bad_key; return -EINVAL;
} }
if (virtio_crypto_alg_validate_key(keylen, &alg)) if (virtio_crypto_alg_validate_key(keylen, &alg))
goto bad_key; return -EINVAL;
/* Create encryption session */ /* Create encryption session */
ret = virtio_crypto_alg_skcipher_init_session(ctx, ret = virtio_crypto_alg_skcipher_init_session(ctx,
@ -291,10 +291,6 @@ static int virtio_crypto_alg_skcipher_init_sessions(
return ret; return ret;
} }
return 0; return 0;
bad_key:
crypto_skcipher_set_flags(ctx->tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL;
} }
/* Note: kernel crypto API realization */ /* Note: kernel crypto API realization */

View File

@ -15,8 +15,7 @@ struct cast6_ctx {
u8 Kr[12][4]; u8 Kr[12][4];
}; };
int __cast6_setkey(struct cast6_ctx *ctx, const u8 *key, int __cast6_setkey(struct cast6_ctx *ctx, const u8 *key, unsigned int keylen);
unsigned int keylen, u32 *flags);
int cast6_setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen); int cast6_setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen);
void __cast6_encrypt(const void *ctx, u8 *dst, const u8 *src); void __cast6_encrypt(const void *ctx, u8 *dst, const u8 *src);

View File

@ -120,20 +120,16 @@ static inline int verify_skcipher_des3_key(struct crypto_skcipher *tfm,
static inline int verify_aead_des_key(struct crypto_aead *tfm, const u8 *key, static inline int verify_aead_des_key(struct crypto_aead *tfm, const u8 *key,
int keylen) int keylen)
{ {
if (keylen != DES_KEY_SIZE) { if (keylen != DES_KEY_SIZE)
crypto_aead_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
}
return crypto_des_verify_key(crypto_aead_tfm(tfm), key); return crypto_des_verify_key(crypto_aead_tfm(tfm), key);
} }
static inline int verify_aead_des3_key(struct crypto_aead *tfm, const u8 *key, static inline int verify_aead_des3_key(struct crypto_aead *tfm, const u8 *key,
int keylen) int keylen)
{ {
if (keylen != DES3_EDE_KEY_SIZE) { if (keylen != DES3_EDE_KEY_SIZE)
crypto_aead_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
}
return crypto_des3_ede_verify_key(crypto_aead_tfm(tfm), key); return crypto_des3_ede_verify_key(crypto_aead_tfm(tfm), key);
} }

View File

@ -19,7 +19,7 @@ struct twofish_ctx {
}; };
int __twofish_setkey(struct twofish_ctx *ctx, const u8 *key, int __twofish_setkey(struct twofish_ctx *ctx, const u8 *key,
unsigned int key_len, u32 *flags); unsigned int key_len);
int twofish_setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int key_len); int twofish_setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int key_len);
#endif #endif

View File

@ -17,10 +17,8 @@ static inline int xts_check_key(struct crypto_tfm *tfm,
* key consists of keys of equal size concatenated, therefore * key consists of keys of equal size concatenated, therefore
* the length must be even. * the length must be even.
*/ */
if (keylen % 2) { if (keylen % 2)
*flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
return -EINVAL; return -EINVAL;
}
/* ensure that the AES and tweak key are not identical */ /* ensure that the AES and tweak key are not identical */
if (fips_enabled && if (fips_enabled &&
@ -39,10 +37,8 @@ static inline int xts_verify_key(struct crypto_skcipher *tfm,
* key consists of keys of equal size concatenated, therefore * key consists of keys of equal size concatenated, therefore
* the length must be even. * the length must be even.
*/ */
if (keylen % 2) { if (keylen % 2)
crypto_skcipher_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
}
/* ensure that the AES and tweak key are not identical */ /* ensure that the AES and tweak key are not identical */
if ((fips_enabled || (crypto_skcipher_get_flags(tfm) & if ((fips_enabled || (crypto_skcipher_get_flags(tfm) &

View File

@ -113,7 +113,6 @@
#define CRYPTO_TFM_REQ_MAY_SLEEP 0x00000200 #define CRYPTO_TFM_REQ_MAY_SLEEP 0x00000200
#define CRYPTO_TFM_REQ_MAY_BACKLOG 0x00000400 #define CRYPTO_TFM_REQ_MAY_BACKLOG 0x00000400
#define CRYPTO_TFM_RES_WEAK_KEY 0x00100000 #define CRYPTO_TFM_RES_WEAK_KEY 0x00100000
#define CRYPTO_TFM_RES_BAD_KEY_LEN 0x00200000
/* /*
* Miscellaneous stuff. * Miscellaneous stuff.