crypto: remove CRYPTO_TFM_RES_BAD_KEY_LEN
authorEric Biggers <ebiggers@google.com>
Tue, 31 Dec 2019 03:19:36 +0000 (21:19 -0600)
committerHerbert Xu <herbert@gondor.apana.org.au>
Thu, 9 Jan 2020 03:30:53 +0000 (11:30 +0800)
commit674f368a952c48ede71784935a799a5205b92b6c
treee8610dafbeb92ae5f91d53579e071e8ff58303e4
parent5c925e8b10a5f43f220755aceb9d5f14b2f4e2c5
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>
93 files changed:
arch/arm/crypto/aes-ce-glue.c
arch/arm/crypto/crc32-ce-glue.c
arch/arm/crypto/ghash-ce-glue.c
arch/arm64/crypto/aes-ce-ccm-glue.c
arch/arm64/crypto/aes-ce-glue.c
arch/arm64/crypto/aes-glue.c
arch/arm64/crypto/ghash-ce-glue.c
arch/mips/crypto/crc32-mips.c
arch/powerpc/crypto/aes-spe-glue.c
arch/powerpc/crypto/crc32c-vpmsum_glue.c
arch/s390/crypto/aes_s390.c
arch/s390/crypto/crc32-vx.c
arch/s390/crypto/ghash_s390.c
arch/s390/crypto/paes_s390.c
arch/sparc/crypto/aes_glue.c
arch/sparc/crypto/camellia_glue.c
arch/sparc/crypto/crc32c_glue.c
arch/x86/crypto/aegis128-aesni-glue.c
arch/x86/crypto/aesni-intel_glue.c
arch/x86/crypto/blake2s-glue.c
arch/x86/crypto/camellia_aesni_avx2_glue.c
arch/x86/crypto/camellia_aesni_avx_glue.c
arch/x86/crypto/camellia_glue.c
arch/x86/crypto/cast6_avx_glue.c
arch/x86/crypto/crc32-pclmul_glue.c
arch/x86/crypto/crc32c-intel_glue.c
arch/x86/crypto/ghash-clmulni-intel_glue.c
arch/x86/crypto/twofish_avx_glue.c
arch/x86/include/asm/crypto/camellia.h
crypto/aegis128-core.c
crypto/aes_generic.c
crypto/anubis.c
crypto/authenc.c
crypto/authencesn.c
crypto/blake2b_generic.c
crypto/blake2s_generic.c
crypto/camellia_generic.c
crypto/cast6_generic.c
crypto/cipher.c
crypto/crc32_generic.c
crypto/crc32c_generic.c
crypto/essiv.c
crypto/ghash-generic.c
crypto/michael_mic.c
crypto/skcipher.c
crypto/sm4_generic.c
crypto/twofish_common.c
crypto/vmac.c
crypto/xxhash_generic.c
drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c
drivers/crypto/allwinner/sun8i-ss/sun8i-ss-cipher.c
drivers/crypto/amcc/crypto4xx_alg.c
drivers/crypto/amlogic/amlogic-gxl-cipher.c
drivers/crypto/atmel-aes.c
drivers/crypto/axis/artpec6_crypto.c
drivers/crypto/bcm/cipher.c
drivers/crypto/caam/caamalg.c
drivers/crypto/caam/caamalg_qi.c
drivers/crypto/caam/caamalg_qi2.c
drivers/crypto/caam/caamhash.c
drivers/crypto/cavium/cpt/cptvf_algs.c
drivers/crypto/cavium/nitrox/nitrox_aead.c
drivers/crypto/cavium/nitrox/nitrox_skcipher.c
drivers/crypto/ccp/ccp-crypto-aes-cmac.c
drivers/crypto/ccp/ccp-crypto-aes-galois.c
drivers/crypto/ccp/ccp-crypto-aes.c
drivers/crypto/ccp/ccp-crypto-sha.c
drivers/crypto/ccree/cc_aead.c
drivers/crypto/ccree/cc_cipher.c
drivers/crypto/ccree/cc_hash.c
drivers/crypto/chelsio/chcr_algo.c
drivers/crypto/geode-aes.c
drivers/crypto/inside-secure/safexcel_cipher.c
drivers/crypto/inside-secure/safexcel_hash.c
drivers/crypto/ixp4xx_crypto.c
drivers/crypto/marvell/cipher.c
drivers/crypto/mediatek/mtk-aes.c
drivers/crypto/n2_core.c
drivers/crypto/padlock-aes.c
drivers/crypto/picoxcell_crypto.c
drivers/crypto/qat/qat_common/qat_algs.c
drivers/crypto/qce/sha.c
drivers/crypto/rockchip/rk3288_crypto_skcipher.c
drivers/crypto/stm32/stm32-crc32.c
drivers/crypto/talitos.c
drivers/crypto/ux500/cryp/cryp_core.c
drivers/crypto/virtio/virtio_crypto_algs.c
include/crypto/cast6.h
include/crypto/internal/des.h
include/crypto/twofish.h
include/crypto/xts.h
include/linux/crypto.h