Skip to content

Commit 231baec

Browse files
ebiggersherbertx
authored andcommitted
crypto: clarify name of WEAK_KEY request flag
CRYPTO_TFM_REQ_WEAK_KEY confuses newcomers to the crypto API because it sounds like it is requesting a weak key. Actually, it is requesting that weak keys be forbidden (for algorithms that have the notion of "weak keys"; currently only DES and XTS do). Also it is only one letter away from CRYPTO_TFM_RES_WEAK_KEY, with which it can be easily confused. (This in fact happened in the UX500 driver, though just in some debugging messages.) Therefore, make the intent clear by renaming it to CRYPTO_TFM_REQ_FORBID_WEAK_KEYS. Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 37ebfff commit 231baec

25 files changed

Lines changed: 55 additions & 49 deletions

File tree

‎arch/s390/crypto/des_s390.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ static int des_setkey(struct crypto_tfm *tfm, const u8 *key,
3838

3939
/* check for weak keys */
4040
if (!des_ekey(tmp, key) &&
41-
(tfm->crt_flags & CRYPTO_TFM_REQ_WEAK_KEY)) {
41+
(tfm->crt_flags & CRYPTO_TFM_REQ_FORBID_WEAK_KEYS)) {
4242
tfm->crt_flags |= CRYPTO_TFM_RES_WEAK_KEY;
4343
return -EINVAL;
4444
}
@@ -228,7 +228,7 @@ static int des3_setkey(struct crypto_tfm *tfm, const u8 *key,
228228
if (!(crypto_memneq(key, &key[DES_KEY_SIZE], DES_KEY_SIZE) &&
229229
crypto_memneq(&key[DES_KEY_SIZE], &key[DES_KEY_SIZE * 2],
230230
DES_KEY_SIZE)) &&
231-
(tfm->crt_flags & CRYPTO_TFM_REQ_WEAK_KEY)) {
231+
(tfm->crt_flags & CRYPTO_TFM_REQ_FORBID_WEAK_KEYS)) {
232232
tfm->crt_flags |= CRYPTO_TFM_RES_WEAK_KEY;
233233
return -EINVAL;
234234
}

‎arch/sparc/crypto/des_glue.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static int des_set_key(struct crypto_tfm *tfm, const u8 *key,
5353
* weak key detection code.
5454
*/
5555
ret = des_ekey(tmp, key);
56-
if (unlikely(ret == 0) && (*flags & CRYPTO_TFM_REQ_WEAK_KEY)) {
56+
if (unlikely(ret == 0) && (*flags & CRYPTO_TFM_REQ_FORBID_WEAK_KEYS)) {
5757
*flags |= CRYPTO_TFM_RES_WEAK_KEY;
5858
return -EINVAL;
5959
}
@@ -209,7 +209,7 @@ static int des3_ede_set_key(struct crypto_tfm *tfm, const u8 *key,
209209

210210
if (unlikely(!((K[0] ^ K[2]) | (K[1] ^ K[3])) ||
211211
!((K[2] ^ K[4]) | (K[3] ^ K[5]))) &&
212-
(*flags & CRYPTO_TFM_REQ_WEAK_KEY)) {
212+
(*flags & CRYPTO_TFM_REQ_FORBID_WEAK_KEYS)) {
213213
*flags |= CRYPTO_TFM_RES_WEAK_KEY;
214214
return -EINVAL;
215215
}

‎crypto/des_generic.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ static int des_setkey(struct crypto_tfm *tfm, const u8 *key,
789789
/* Expand to tmp */
790790
ret = des_ekey(tmp, key);
791791

792-
if (unlikely(ret == 0) && (*flags & CRYPTO_TFM_REQ_WEAK_KEY)) {
792+
if (unlikely(ret == 0) && (*flags & CRYPTO_TFM_REQ_FORBID_WEAK_KEYS)) {
793793
*flags |= CRYPTO_TFM_RES_WEAK_KEY;
794794
return -EINVAL;
795795
}
@@ -866,7 +866,7 @@ int __des3_ede_setkey(u32 *expkey, u32 *flags, const u8 *key,
866866

867867
if (unlikely(!((K[0] ^ K[2]) | (K[1] ^ K[3])) ||
868868
!((K[2] ^ K[4]) | (K[3] ^ K[5]))) &&
869-
(*flags & CRYPTO_TFM_REQ_WEAK_KEY)) {
869+
(*flags & CRYPTO_TFM_REQ_FORBID_WEAK_KEYS)) {
870870
*flags |= CRYPTO_TFM_RES_WEAK_KEY;
871871
return -EINVAL;
872872
}

‎crypto/testmgr.c‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,8 @@ static int __test_aead(struct crypto_aead *tfm, int enc,
706706

707707
crypto_aead_clear_flags(tfm, ~0);
708708
if (template[i].wk)
709-
crypto_aead_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
709+
crypto_aead_set_flags(tfm,
710+
CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
710711

711712
if (template[i].klen > MAX_KEYLEN) {
712713
pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
@@ -820,7 +821,8 @@ static int __test_aead(struct crypto_aead *tfm, int enc,
820821

821822
crypto_aead_clear_flags(tfm, ~0);
822823
if (template[i].wk)
823-
crypto_aead_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
824+
crypto_aead_set_flags(tfm,
825+
CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
824826
if (template[i].klen > MAX_KEYLEN) {
825827
pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
826828
d, j, algo, template[i].klen, MAX_KEYLEN);
@@ -1078,7 +1080,7 @@ static int test_cipher(struct crypto_cipher *tfm, int enc,
10781080

10791081
crypto_cipher_clear_flags(tfm, ~0);
10801082
if (template[i].wk)
1081-
crypto_cipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
1083+
crypto_cipher_set_flags(tfm, CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
10821084

10831085
ret = crypto_cipher_setkey(tfm, template[i].key,
10841086
template[i].klen);
@@ -1194,8 +1196,7 @@ static int __test_skcipher(struct crypto_skcipher *tfm, int enc,
11941196

11951197
crypto_skcipher_clear_flags(tfm, ~0);
11961198
if (template[i].wk)
1197-
crypto_skcipher_set_flags(tfm,
1198-
CRYPTO_TFM_REQ_WEAK_KEY);
1199+
crypto_skcipher_set_flags(tfm, CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
11991200

12001201
ret = crypto_skcipher_setkey(tfm, template[i].key,
12011202
template[i].klen);
@@ -1265,8 +1266,7 @@ static int __test_skcipher(struct crypto_skcipher *tfm, int enc,
12651266
j++;
12661267
crypto_skcipher_clear_flags(tfm, ~0);
12671268
if (template[i].wk)
1268-
crypto_skcipher_set_flags(tfm,
1269-
CRYPTO_TFM_REQ_WEAK_KEY);
1269+
crypto_skcipher_set_flags(tfm, CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
12701270

12711271
ret = crypto_skcipher_setkey(tfm, template[i].key,
12721272
template[i].klen);

‎crypto/testmgr.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ struct hash_testvec {
5050
* @ctext: Pointer to ciphertext
5151
* @len: Length of @ptext and @ctext in bytes
5252
* @fail: If set to one, the test need to fail
53-
* @wk: Does the test need CRYPTO_TFM_REQ_WEAK_KEY
53+
* @wk: Does the test need CRYPTO_TFM_REQ_FORBID_WEAK_KEYS?
5454
* ( e.g. test needs to fail due to a weak key )
5555
* @np: numbers of SG to distribute data in (from 1 to MAX_TAP)
5656
* @tap: How to distribute data in @np SGs
@@ -91,7 +91,7 @@ struct cipher_testvec {
9191
* @anp: Numbers of SG to distribute assoc data in
9292
* @fail: setkey() failure expected?
9393
* @novrfy: Decryption verification failure expected?
94-
* @wk: Does the test need CRYPTO_TFM_REQ_WEAK_KEY?
94+
* @wk: Does the test need CRYPTO_TFM_REQ_FORBID_WEAK_KEYS?
9595
* (e.g. setkey() needs to fail due to a weak key)
9696
* @klen: Length of @key in bytes
9797
* @plen: Length of @ptext in bytes

‎drivers/crypto/atmel-tdes.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,7 @@ static int atmel_des_setkey(struct crypto_ablkcipher *tfm, const u8 *key,
785785
}
786786

787787
err = des_ekey(tmp, key);
788-
if (err == 0 && (ctfm->crt_flags & CRYPTO_TFM_REQ_WEAK_KEY)) {
788+
if (err == 0 && (ctfm->crt_flags & CRYPTO_TFM_REQ_FORBID_WEAK_KEYS)) {
789789
ctfm->crt_flags |= CRYPTO_TFM_RES_WEAK_KEY;
790790
return -EINVAL;
791791
}

‎drivers/crypto/bcm/cipher.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1818,7 +1818,7 @@ static int des_setkey(struct crypto_ablkcipher *cipher, const u8 *key,
18181818
if (keylen == DES_KEY_SIZE) {
18191819
if (des_ekey(tmp, key) == 0) {
18201820
if (crypto_ablkcipher_get_flags(cipher) &
1821-
CRYPTO_TFM_REQ_WEAK_KEY) {
1821+
CRYPTO_TFM_REQ_FORBID_WEAK_KEYS) {
18221822
u32 flags = CRYPTO_TFM_RES_WEAK_KEY;
18231823

18241824
crypto_ablkcipher_set_flags(cipher, flags);
@@ -2872,7 +2872,7 @@ static int aead_authenc_setkey(struct crypto_aead *cipher,
28722872

28732873
if (des_ekey(tmp, keys.enckey) == 0) {
28742874
if (crypto_aead_get_flags(cipher) &
2875-
CRYPTO_TFM_REQ_WEAK_KEY) {
2875+
CRYPTO_TFM_REQ_FORBID_WEAK_KEYS) {
28762876
crypto_aead_set_flags(cipher, flags);
28772877
return -EINVAL;
28782878
}

‎drivers/crypto/ccp/ccp-crypto-des3.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ static int ccp_des3_setkey(struct crypto_ablkcipher *tfm, const u8 *key,
5757

5858
if (unlikely(!((K[0] ^ K[2]) | (K[1] ^ K[3])) ||
5959
!((K[2] ^ K[4]) | (K[3] ^ K[5]))) &&
60-
(*flags & CRYPTO_TFM_REQ_WEAK_KEY)) {
60+
(*flags & CRYPTO_TFM_REQ_FORBID_WEAK_KEYS)) {
6161
*flags |= CRYPTO_TFM_RES_WEAK_KEY;
6262
return -EINVAL;
6363
}

‎drivers/crypto/ccree/cc_cipher.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,8 @@ static int cc_cipher_setkey(struct crypto_skcipher *sktfm, const u8 *key,
352352
dev_dbg(dev, "weak 3DES key");
353353
return -EINVAL;
354354
} else if (!des_ekey(tmp, key) &&
355-
(crypto_tfm_get_flags(tfm) & CRYPTO_TFM_REQ_WEAK_KEY)) {
355+
(crypto_tfm_get_flags(tfm) &
356+
CRYPTO_TFM_REQ_FORBID_WEAK_KEYS)) {
356357
tfm->crt_flags |= CRYPTO_TFM_RES_WEAK_KEY;
357358
dev_dbg(dev, "weak DES key");
358359
return -EINVAL;

‎drivers/crypto/hifn_795x.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1961,7 +1961,8 @@ static int hifn_setkey(struct crypto_ablkcipher *cipher, const u8 *key,
19611961
u32 tmp[DES_EXPKEY_WORDS];
19621962
int ret = des_ekey(tmp, key);
19631963

1964-
if (unlikely(ret == 0) && (tfm->crt_flags & CRYPTO_TFM_REQ_WEAK_KEY)) {
1964+
if (unlikely(ret == 0) &&
1965+
(tfm->crt_flags & CRYPTO_TFM_REQ_FORBID_WEAK_KEYS)) {
19651966
tfm->crt_flags |= CRYPTO_TFM_RES_WEAK_KEY;
19661967
return -EINVAL;
19671968
}

0 commit comments

Comments
 (0)