Trivial set of FIPS 140-3 related changes
Subsystems (9)
v3 cover Trivial set of FIPS 140-3 related changes
Hi,
This patchset and cover letter was initially composed by Nicolai Stange and sent earlier as:
https://lore.kernel.org/r/[email protected]/
with a subject: [PATCH 0/4] Trivial set of FIPS 140-3 related changes
I'm adding patches 2 and 3 which (I hope) resolve issues spotted by reviewers of previous version of the patchset. This new patchset should ease our future kernel work on the FIPS mode.
I'm quoting Nicolai's cover letter here:
Quoted 10 lines
Hi all,
these four rather unrelated patches are basically a dump of some of the more trivial changes required for working towards FIPS 140-3 conformance.
Please pick as you deem appropriate.
Thanks!
Nicolai
v2: fixed a block comment formatting
v3: "Reviewed-by: Eric Biggers" was copied from the v1 thread:
https://lore.kernel.org/r/[email protected]/
Nicolai Stange (4):
crypto: xts - restrict key lengths to approved values in FIPS mode
crypto: testmgr - disallow plain cbcmac(aes) in FIPS mode
crypto: testmgr - disallow plain ghash in FIPS mode
crypto: testmgr - allow ecdsa-nist-p256 and -p384 in FIPS mode
Vladis Dronov (2):
crypto: xts - drop xts_check_key()
crypto: xts - drop redundant xts key check
arch/s390/crypto/aes_s390.c | 4 --- arch/s390/crypto/paes_s390.c | 2 +- crypto/testmgr.c | 4 +-- drivers/crypto/atmel-aes.c | 2 +- drivers/crypto/axis/artpec6_crypto.c | 2 +- drivers/crypto/cavium/cpt/cptvf_algs.c | 8 +++--- .../crypto/cavium/nitrox/nitrox_skcipher.c | 8 +++--- drivers/crypto/ccree/cc_cipher.c | 2 +- .../crypto/marvell/octeontx/otx_cptvf_algs.c | 2 +- .../marvell/octeontx2/otx2_cptvf_algs.c | 2 +- include/crypto/xts.h | 25 +++++++------------ 11 files changed, 23 insertions(+), 38 deletions(-)
base-commit: b6bb9676f2165d518b35ba3bea5f1fcfc0d969bf
Signature · 1 line
2.38.1
PATCH v3 1/6 crypto: xts - restrict key lengths to approved values in FIPS mode
From: Nicolai Stange <[email protected]>
According to FIPS 140-3 IG C.I., only (total) key lengths of either 256 bits or 512 bits are allowed with xts(aes). Make xts_verify_key() to reject anything else in FIPS mode.
As xts(aes) is the only approved xts() template instantiation in FIPS mode, the new restriction implemented in xts_verify_key() effectively only applies to this particular construction.
--- include/crypto/xts.h | 7 +++++++ 1 file changed, 7 insertions(+)
include/crypto/xts.h +7 -0
@@ -35,6 +35,13 @@ static inline int xts_verify_key(struct crypto_skcipher *tfm,if (keylen %2 )return -EINVAL ; +/* +* In FIPS mode only a combined key length of either 256 or +* 512 bits is allowed, c.f. FIPS 140-3 IG C.I. +*/ +if (fips_enabled && keylen !=32 && keylen !=64 ) +return -EINVAL ; +/* ensure that the AES and tweak key are not identical */ if ((fips_enabled || (crypto_skcipher_get_flags(tfm) & CRYPTO_TFM_REQ_FORBID_WEAK_KEYS)) &&
Signature · 1 line
2.38.1
PATCH v3 2/6 crypto: xts - drop xts_check_key()
In reply to Vladis Dronovxts_check_key() is obsoleted by xts_verify_key(). Over time XTS crypto drivers adopted the newer xts_verify_key() variant, but xts_check_key() is still used by a number of drivers. Switch drivers to use the newer xts_verify_key() and make a couple of cleanups. This allows us to drop xts_check_key() completely and avoid redundancy.
--- arch/s390/crypto/paes_s390.c | 2 +- drivers/crypto/atmel-aes.c | 2 +- drivers/crypto/axis/artpec6_crypto.c | 2 +- drivers/crypto/cavium/cpt/cptvf_algs.c | 8 +++---- .../crypto/cavium/nitrox/nitrox_skcipher.c | 8 +++---- drivers/crypto/ccree/cc_cipher.c | 2 +- .../crypto/marvell/octeontx/otx_cptvf_algs.c | 2 +- .../marvell/octeontx2/otx2_cptvf_algs.c | 2 +- include/crypto/xts.h | 22 ++++--------------- 9 files changed, 16 insertions(+), 34 deletions(-)
arch/s390/crypto/paes_s390.c +1 -1
@@ -474,7 +474,7 @@ static int xts_paes_set_key(struct crypto_skcipher *tfm, const u8 *in_key,return rc;/* -* xts_check_key verifies the key length is not odd and makes +* xts_verify_key verifies the key length is not odd and makes * sure that the two keys are not the same. This can be done * on the two protected keys as well */
drivers/crypto/atmel-aes.c +1 -1
@@ -1879,7 +1879,7 @@ static int atmel_aes_xts_setkey(struct crypto_skcipher *tfm, const u8 *key,struct atmel_aes_xts_ctx *ctx =crypto_skcipher_ctx (tfm);int err; - err =xts_check_key (crypto_skcipher_tfm (tfm), key, keylen); + err =xts_verify_key (tfm, key, keylen);if (err)return err;
drivers/crypto/axis/artpec6_crypto.c +1 -1
@@ -1621,7 +1621,7 @@ artpec6_crypto_xts_set_key(struct crypto_skcipher *cipher, const u8 *key,crypto_skcipher_ctx (cipher);int ret; - ret =xts_check_key (&cipher->base, key, keylen); + ret =xts_verify_key (cipher, key, keylen);if (ret)return ret;
drivers/crypto/cavium/cpt/cptvf_algs.c +3 -5
@@ -232,13 +232,12 @@ static int cvm_decrypt(struct skcipher_request *req)static int cvm_xts_setkey (struct crypto_skcipher *cipher,const u8 *key,u32 keylen) { -struct crypto_tfm *tfm =crypto_skcipher_tfm (cipher); -struct cvm_enc_ctx *ctx =crypto_tfm_ctx (tfm); +struct cvm_enc_ctx *ctx =crypto_skcipher_ctx (cipher);int err;const u8 *key1 = key;const u8 *key2 = key + (keylen /2 ); - err =xts_check_key (tfm, key, keylen); + err =xts_verify_key (cipher, key, keylen);if (err)return err; ctx->key_len = keylen;
@@ -289,8 +288,7 @@ static int cvm_validate_keylen(struct cvm_enc_ctx *ctx, u32 keylen)static int cvm_setkey (struct crypto_skcipher *cipher,const u8 *key,u32 keylen,u8 cipher_type) { -struct crypto_tfm *tfm =crypto_skcipher_tfm (cipher); -struct cvm_enc_ctx *ctx =crypto_tfm_ctx (tfm); +struct cvm_enc_ctx *ctx =crypto_skcipher_ctx (cipher); ctx->cipher_type = cipher_type;if (!cvm_validate_keylen (ctx, keylen)) {
drivers/crypto/cavium/nitrox/nitrox_skcipher.c +3 -5
@@ -337,12 +337,11 @@ static int nitrox_3des_decrypt(struct skcipher_request *skreq)static int nitrox_aes_xts_setkey (struct crypto_skcipher *cipher,const u8 *key,unsigned int keylen) { -struct crypto_tfm *tfm =crypto_skcipher_tfm (cipher); -struct nitrox_crypto_ctx *nctx =crypto_tfm_ctx (tfm); +struct nitrox_crypto_ctx *nctx =crypto_skcipher_ctx (cipher);struct flexi_crypto_context *fctx;int aes_keylen, ret; - ret =xts_check_key (tfm, key, keylen); + ret =xts_verify_key (cipher, key, keylen);if (ret)return ret;
@@ -362,8 +361,7 @@ static int nitrox_aes_xts_setkey(struct crypto_skcipher *cipher,static int nitrox_aes_ctr_rfc3686_setkey (struct crypto_skcipher *cipher,const u8 *key,unsigned int keylen) { -struct crypto_tfm *tfm =crypto_skcipher_tfm (cipher); -struct nitrox_crypto_ctx *nctx =crypto_tfm_ctx (tfm); +struct nitrox_crypto_ctx *nctx =crypto_skcipher_ctx (cipher);struct flexi_crypto_context *fctx;int aes_keylen;
drivers/crypto/ccree/cc_cipher.c +1 -1
@@ -460,7 +460,7 @@ static int cc_cipher_setkey(struct crypto_skcipher *sktfm, const u8 *key, }if (ctx_p->cipher_mode ==DRV_CIPHER_XTS && -xts_check_key (tfm, key, keylen)) { +xts_verify_key (sktfm, key, keylen)) {dev_dbg (dev,"weak XTS key" );return -EINVAL ; }
drivers/crypto/marvell/octeontx/otx_cptvf_algs.c +1 -1
@@ -398,7 +398,7 @@ static int otx_cpt_skcipher_xts_setkey(struct crypto_skcipher *tfm,const u8 *key1 = key;int ret; - ret =xts_check_key (crypto_skcipher_tfm (tfm), key, keylen); + ret =xts_verify_key (tfm, key, keylen);if (ret)return ret; ctx->key_len = keylen;
drivers/crypto/marvell/octeontx2/otx2_cptvf_algs.c +1 -1
@@ -412,7 +412,7 @@ static int otx2_cpt_skcipher_xts_setkey(struct crypto_skcipher *tfm,const u8 *key1 = key;int ret; - ret =xts_check_key (crypto_skcipher_tfm (tfm), key, keylen); + ret =xts_verify_key (tfm, key, keylen);if (ret)return ret; ctx->key_len = keylen;
include/crypto/xts.h +4 -18
@@ -8,23 +8,6 @@#define XTS_BLOCK_SIZE 16 -static inline int xts_check_key (struct crypto_tfm *tfm, -const u8 *key,unsigned int keylen) -{ -/* -* key consists of keys of equal size concatenated, therefore -* the length must be even. -*/ -if (keylen %2 ) -return -EINVAL ; - -/* ensure that the AES and tweak key are not identical */ -if (fips_enabled && !crypto_memneq (key, key + (keylen /2 ), keylen /2 )) -return -EINVAL ; - -return 0 ; -} -static inline int xts_verify_key (struct crypto_skcipher *tfm,const u8 *key,unsigned int keylen) {
@@ -42,7 +25,10 @@ static inline int xts_verify_key(struct crypto_skcipher *tfm,if (fips_enabled && keylen !=32 && keylen !=64 )return -EINVAL ; -/* ensure that the AES and tweak key are not identical */ +/* +* Ensure that the AES and tweak key are not identical when +* in FIPS mode or the FORBID_WEAK_KEYS flag is set. +*/ if ((fips_enabled || (crypto_skcipher_get_flags (tfm) &CRYPTO_TFM_REQ_FORBID_WEAK_KEYS )) && !crypto_memneq (key, key + (keylen /2 ), keylen /2 ))
Signature · 1 line
2.38.1
Re: [PATCH v3 2/6] crypto: xts - drop xts_check_key()
Hi Vladis,
Quoted 5 lines · Vladis Dronov
xts_check_key()is obsoleted byxts_verify_key(). Over time XTS crypto drivers adopted the newerxts_verify_key()variant, butxts_check_key()is still used by a number of drivers. Switch drivers to use the newerxts_verify_key()and make a couple of cleanups. This allows us to dropxts_check_key()completely and avoid redundancy.
nice work, thanks a lot for doing it!
There are two (obviously correct) cleanups which seem unrelated to xts_verify_key(), namely in cvm_setkey() and nitrox_aes_ctr_rfc3686_setkey(), see below.
But the commit message does say "and make a couple of cleanups" and these changes certainly qualify as such. I just wanted to have it mentioned.
Thanks!
Nicolai
Quoted 4 lines
Signed-off-by Vladis Dronov <[email protected]>Reviewed-by Eric Biggers <[email protected]>---
<snip>
Quoted 4 lines
drivers/crypto/cavium/cpt/cptvf_algs.c +0
-0
<snip>
drivers/crypto/cavium/cpt/cptvf_algs.c static int cvm_validate_keylen(struct cvm_enc_ctx *ctx, u32 keylen) · line 294
Quoted 10 lines
drivers/crypto/cavium/cpt/cptvf_algs.c +1
-2@@ -289,8 +288,7 @@ static int cvm_validate_keylen(struct cvm_enc_ctx *ctx, u32 keylen)static int cvm_setkey (struct crypto_skcipher *cipher,const u8 *key,u32 keylen,u8 cipher_type) { -struct crypto_tfm *tfm =crypto_skcipher_tfm (cipher); -struct cvm_enc_ctx *ctx =crypto_tfm_ctx (tfm); +struct cvm_enc_ctx *ctx =crypto_skcipher_ctx (cipher); ctx->cipher_type = cipher_type;if (!cvm_validate_keylen (ctx, keylen)) {
This change here and ...
Quoted 4 lines
drivers/crypto/cavium/nitrox/nitrox_skcipher.c +0
-0
<snip>
drivers/crypto/cavium/nitrox/nitrox_skcipher.c static int nitrox_aes_xts_setkey(struct crypto_skcipher *cipher, · line 367
Quoted 10 lines
drivers/crypto/cavium/nitrox/nitrox_skcipher.c +1
-2@@ -362,8 +361,7 @@ static int nitrox_aes_xts_setkey(struct crypto_skcipher *cipher,static int nitrox_aes_ctr_rfc3686_setkey (struct crypto_skcipher *cipher,const u8 *key,unsigned int keylen) { -struct crypto_tfm *tfm =crypto_skcipher_tfm (cipher); -struct nitrox_crypto_ctx *nctx =crypto_tfm_ctx (tfm); +struct nitrox_crypto_ctx *nctx =crypto_skcipher_ctx (cipher);struct flexi_crypto_context *fctx;int aes_keylen;
this one are not strictly related to xts_verify_key() AFAICS, but it's fine to have them included nonetheless, IMO.
Signature · 3 lines
SUSE Software Solutions Germany GmbH, Frankenstraße 146, 90461 Nürnberg, Germany GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman (HRB 36809, AG Nürnberg)
PATCH v3 3/6 crypto: xts - drop redundant xts key check
In reply to Vladis Dronovxts_fallback_setkey() in xts_aes_set_key() will now enforce key size rule in FIPS mode when setting up the fallback algorithm keys, which makes the check in xts_aes_set_key() redundant or unreachable. So just drop this check.
xts_fallback_setkey() now makes a key size check in xts_verify_key():
xts_fallback_setkey()
crypto_skcipher_setkey() [ skcipher_setkey_unaligned() ]
cipher->setkey() { .setkey = xts_setkey }
xts_setkey()
xts_verify_key()--- arch/s390/crypto/aes_s390.c | 4 ---- 1 file changed, 4 deletions(-)
arch/s390/crypto/aes_s390.c +0 -4
@@ -398,10 +398,6 @@ static int xts_aes_set_key(struct crypto_skcipher *tfm, const u8 *in_key,if (err)return err; -/* In fips mode only 128 bit or 256 bit keys are valid */ -if (fips_enabled && key_len !=32 && key_len !=64 ) -return -EINVAL ; -/* Pick the correct function code based on the key length */ fc = (key_len ==32 ) ?CPACF_KM_XTS_128 : (key_len ==64 ) ?CPACF_KM_XTS_256 :0 ;
Signature · 1 line
2.38.1
Re: [PATCH v3 3/6] crypto: xts - drop redundant xts key check
Hi Vladis,
the patch subject prefix is a bit misleading IMO, it kind of suggests that this patch would apply to the generic crypto/xts.c. How about using a format similar to e.g. the one from commit 7988fb2c03c8 ("crypto:
s390/aes - convert to skcipher API"), i.e.
"crypto: s390/aes - drop redundant xts key check"
?
Quoted 2 lines · Vladis Dronov
xts_fallback_setkey()inxts_aes_set_key()will now enforce key size rule in FIPS mode when setting up the fallback algorithm keys,
I think it would be nice to make it more explicit why/how xts_fallback_setkey() happens to enforce the key size rules now.
Perhaps amend the above sentence by something like
"xts_fallback_setkey() in xts_aes_set_key() will now implictly enforce
the key size rule in FIPS mode by means of invoking the generic xts implementation with its key checks for setting up the fallback algorithm,"
?
Quoted 21 lines
which makes the check in
xts_aes_set_key()redundant or unreachable. So just drop this check.
xts_fallback_setkey()now makes a key size check inxts_verify_key():
xts_fallback_setkey()
crypto_skcipher_setkey()[skcipher_setkey_unaligned()]cipher->setkey() { .setkey = xts_setkey } xts_setkey() xts_verify_key()Signed-off-by Vladis Dronov <[email protected]>--- arch/s390/crypto/aes_s390.c | 4 ---- 1 file changed, 4 deletions(-)arch/s390/crypto/aes_s390.c +0
-0
arch/s390/crypto/aes_s390.c static int xts_aes_set_key(struct crypto_skcipher *tfm, const u8 *in_key, · line 404
Quoted 7 lines
arch/s390/crypto/aes_s390.c +0
-4@@ -398,10 +398,6 @@ static int xts_aes_set_key(struct crypto_skcipher *tfm, const u8 *in_key,if (err)return err; -/* In fips mode only 128 bit or 256 bit keys are valid */ -if (fips_enabled && key_len !=32 && key_len !=64 ) -return -EINVAL ; -
The change itself looks good, but it might be worth adding a comment right at the invocation of xts_fallback_setkey() that this includes an implicit xts_verify_key() check? So that if anybody ever was about to remove the xts_fallback_setkey() for some reason in the future, it would give a clear indication that xts_verify_key() needs to get called directly instead?
Thanks!
Nicolai
Quoted 3 lines
arch/s390/crypto/aes_s390.c +0
-0/* Pick the correct function code based on the key length */ fc = (key_len ==32 ) ?CPACF_KM_XTS_128 : (key_len ==64 ) ?CPACF_KM_XTS_256 :0 ;
Signature · 3 lines
SUSE Software Solutions Germany GmbH, Frankenstraße 146, 90461 Nürnberg, Germany GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman (HRB 36809, AG Nürnberg)
PATCH v3 4/6 crypto: testmgr - disallow plain cbcmac(aes) in FIPS mode
In reply to Vladis DronovFrom: Nicolai Stange <[email protected]>
cbcmac(aes) may be used only as part of the ccm(aes) construction in FIPS mode. Since commit d6097b8d5d55 ("crypto: api - allow algs only in specific constructions in FIPS mode") there's support for using spawns which by itself are marked as non-approved from approved template instantiations. So simply mark plain cbcmac(aes) as non-approved in testmgr to block any attempts of direct instantiations in FIPS mode.
--- crypto/testmgr.c | 1 - 1 file changed, 1 deletion(-)
crypto/testmgr.c +0 -1
@@ -4501,7 +4501,6 @@ static const struct alg_test_desc alg_test_descs[] = { }, {#endif .alg = "cbcmac(aes)", - .fips_allowed = 1, .test = alg_test_hash, .suite = { .hash =__VECS (aes_cbcmac_tv_template)
Signature · 1 line
2.38.1
PATCH v3 5/6 crypto: testmgr - disallow plain ghash in FIPS mode
In reply to Vladis DronovFrom: Nicolai Stange <[email protected]>
ghash may be used only as part of the gcm(aes) construction in FIPS mode. Since commit d6097b8d5d55 ("crypto: api - allow algs only in specific constructions in FIPS mode") there's support for using spawns which by itself are marked as non-approved from approved template instantiations. So simply mark plain ghash as non-approved in testmgr to block any attempts of direct instantiations in FIPS mode.
--- crypto/testmgr.c | 1 - 1 file changed, 1 deletion(-)
crypto/testmgr.c +0 -1
@@ -5125,7 +5125,6 @@ static const struct alg_test_desc alg_test_descs[] = { }, { .alg = "ghash", .test = alg_test_hash, - .fips_allowed = 1, .suite = { .hash = __VECS(ghash_tv_template) }
Signature · 1 line
2.38.1
PATCH v3 6/6 crypto: testmgr - allow ecdsa-nist-p256 and -p384 in FIPS mode
In reply to Vladis DronovFrom: Nicolai Stange <[email protected]>
The kernel provides implementations of the NIST ECDSA signature verification primitives. For key sizes of 256 and 384 bits respectively they are approved and can be enabled in FIPS mode. Do so.
--- crypto/testmgr.c | 2 ++ 1 file changed, 2 insertions(+)
crypto/testmgr.c +2 -0
@@ -5034,12 +5034,14 @@ static const struct alg_test_desc alg_test_descs[] = { }, { .alg = "ecdsa-nist-p256", .test = alg_test_akcipher, + .fips_allowed = 1, .suite = { .akcipher = __VECS(ecdsa_nist_p256_tv_template) } }, { .alg = "ecdsa-nist-p384", .test = alg_test_akcipher, + .fips_allowed = 1, .suite = { .akcipher =__VECS (ecdsa_nist_p384_tv_template) }
Signature · 1 line
2.38.1
Herbert Xu
maintainerQuoted 53 lines · Vladis Dronov
Hi,
This patchset and cover letter was initially composed by Nicolai Stange and sent earlier as:
https://lore.kernel.org/r/[email protected]/
with a subject: [PATCH 0/4] Trivial set of FIPS 140-3 related changesI'm adding patches 2 and 3 which (I hope) resolve issues spotted by reviewers of previous version of the patchset. This new patchset should ease our future kernel work on the FIPS mode.
I'm quoting Nicolai's cover letter here:
Quoted 10 lines
Hi all,
these four rather unrelated patches are basically a dump of some of the more trivial changes required for working towards FIPS 140-3 conformance.
Please pick as you deem appropriate.
Thanks!
Nicolai
v2: fixed a block comment formatting
v3: "Reviewed-by: Eric Biggers" was copied from the v1 thread:
https://lore.kernel.org/r/[email protected]/Nicolai Stange (4):
crypto: xts - restrict key lengths to approved values in FIPS mode
crypto: testmgr - disallow plain cbcmac(aes) in FIPS mode
crypto: testmgr - disallow plain ghash in FIPS mode
crypto: testmgr - allow ecdsa-nist-p256 and -p384 in FIPS modeVladis Dronov (2):
crypto: xts - dropxts_check_key()
crypto: xts - drop redundant xts key checkarch/s390/crypto/aes_s390.c | 4 --- arch/s390/crypto/paes_s390.c | 2 +- crypto/testmgr.c | 4 +-- drivers/crypto/atmel-aes.c | 2 +- drivers/crypto/axis/artpec6_crypto.c | 2 +- drivers/crypto/cavium/cpt/cptvf_algs.c | 8 +++--- .../crypto/cavium/nitrox/nitrox_skcipher.c | 8 +++--- drivers/crypto/ccree/cc_cipher.c | 2 +- .../crypto/marvell/octeontx/otx_cptvf_algs.c | 2 +- .../marvell/octeontx2/otx2_cptvf_algs.c | 2 +- include/crypto/xts.h | 25 +++++++------------ 11 files changed, 23 insertions(+), 38 deletions(-)
Quoted 3 lines
base-commit:
b6bb9676f2165d518b35ba3bea5f1fcfc0d969bfSignature · 1 line
2.38.1
All applied. Thanks.
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt