Commit aa113da2 authored by Herbert Xu's avatar Herbert Xu

crypto: picoxcell - Forbid 2-key 3DES in FIPS mode

This patch forbids the use of 2-key 3DES (K1 == K3) in FIPS mode.

It also removes an unnecessary key length checks that are already
performed by the crypto API.
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 7f88c4d7
...@@ -753,11 +753,6 @@ static int spacc_des_setkey(struct crypto_ablkcipher *cipher, const u8 *key, ...@@ -753,11 +753,6 @@ static int spacc_des_setkey(struct crypto_ablkcipher *cipher, const u8 *key,
struct spacc_ablk_ctx *ctx = crypto_tfm_ctx(tfm); struct spacc_ablk_ctx *ctx = crypto_tfm_ctx(tfm);
u32 tmp[DES_EXPKEY_WORDS]; u32 tmp[DES_EXPKEY_WORDS];
if (len > DES3_EDE_KEY_SIZE) {
crypto_ablkcipher_set_flags(cipher, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL;
}
if (unlikely(!des_ekey(tmp, key)) && if (unlikely(!des_ekey(tmp, key)) &&
(crypto_ablkcipher_get_flags(cipher) & (crypto_ablkcipher_get_flags(cipher) &
CRYPTO_TFM_REQ_FORBID_WEAK_KEYS)) { CRYPTO_TFM_REQ_FORBID_WEAK_KEYS)) {
...@@ -771,6 +766,30 @@ static int spacc_des_setkey(struct crypto_ablkcipher *cipher, const u8 *key, ...@@ -771,6 +766,30 @@ static int spacc_des_setkey(struct crypto_ablkcipher *cipher, const u8 *key,
return 0; return 0;
} }
/*
* Set the 3DES key for a block cipher transform. This also performs weak key
* checking if the transform has requested it.
*/
static int spacc_des3_setkey(struct crypto_ablkcipher *cipher, const u8 *key,
unsigned int len)
{
struct spacc_ablk_ctx *ctx = crypto_ablkcipher_ctx(cipher);
u32 flags;
int err;
flags = crypto_ablkcipher_get_flags(cipher);
err = __des3_verify_key(&flags, key);
if (unlikely(err)) {
crypto_ablkcipher_set_flags(cipher, flags);
return err;
}
memcpy(ctx->key, key, len);
ctx->key_len = len;
return 0;
}
/* /*
* Set the key for an AES block cipher. Some key lengths are not supported in * Set the key for an AES block cipher. Some key lengths are not supported in
* hardware so this must also check whether a fallback is needed. * hardware so this must also check whether a fallback is needed.
...@@ -1353,7 +1372,7 @@ static struct spacc_alg ipsec_engine_algs[] = { ...@@ -1353,7 +1372,7 @@ static struct spacc_alg ipsec_engine_algs[] = {
.cra_type = &crypto_ablkcipher_type, .cra_type = &crypto_ablkcipher_type,
.cra_module = THIS_MODULE, .cra_module = THIS_MODULE,
.cra_ablkcipher = { .cra_ablkcipher = {
.setkey = spacc_des_setkey, .setkey = spacc_des3_setkey,
.encrypt = spacc_ablk_encrypt, .encrypt = spacc_ablk_encrypt,
.decrypt = spacc_ablk_decrypt, .decrypt = spacc_ablk_decrypt,
.min_keysize = DES3_EDE_KEY_SIZE, .min_keysize = DES3_EDE_KEY_SIZE,
...@@ -1380,7 +1399,7 @@ static struct spacc_alg ipsec_engine_algs[] = { ...@@ -1380,7 +1399,7 @@ static struct spacc_alg ipsec_engine_algs[] = {
.cra_type = &crypto_ablkcipher_type, .cra_type = &crypto_ablkcipher_type,
.cra_module = THIS_MODULE, .cra_module = THIS_MODULE,
.cra_ablkcipher = { .cra_ablkcipher = {
.setkey = spacc_des_setkey, .setkey = spacc_des3_setkey,
.encrypt = spacc_ablk_encrypt, .encrypt = spacc_ablk_encrypt,
.decrypt = spacc_ablk_decrypt, .decrypt = spacc_ablk_decrypt,
.min_keysize = DES3_EDE_KEY_SIZE, .min_keysize = DES3_EDE_KEY_SIZE,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment