Skip to content

Commit 0ee4336

Browse files
nefigtutherbertx
authored andcommitted
crypto: xts - drop xts_check_key()
xts_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. Signed-off-by: Vladis Dronov <[email protected]> Reviewed-by: Eric Biggers <[email protected]> Reviewed-by: Nicolai Stange <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 1c4428b commit 0ee4336

File tree

9 files changed

+16
-34
lines changed

9 files changed

+16
-34
lines changed

arch/s390/crypto/paes_s390.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ static int xts_paes_set_key(struct crypto_skcipher *tfm, const u8 *in_key,
474474
return rc;
475475

476476
/*
477-
* xts_check_key verifies the key length is not odd and makes
477+
* xts_verify_key verifies the key length is not odd and makes
478478
* sure that the two keys are not the same. This can be done
479479
* on the two protected keys as well
480480
*/

drivers/crypto/atmel-aes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1879,7 +1879,7 @@ static int atmel_aes_xts_setkey(struct crypto_skcipher *tfm, const u8 *key,
18791879
struct atmel_aes_xts_ctx *ctx = crypto_skcipher_ctx(tfm);
18801880
int err;
18811881

1882-
err = xts_check_key(crypto_skcipher_tfm(tfm), key, keylen);
1882+
err = xts_verify_key(tfm, key, keylen);
18831883
if (err)
18841884
return err;
18851885

drivers/crypto/axis/artpec6_crypto.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1621,7 +1621,7 @@ artpec6_crypto_xts_set_key(struct crypto_skcipher *cipher, const u8 *key,
16211621
crypto_skcipher_ctx(cipher);
16221622
int ret;
16231623

1624-
ret = xts_check_key(&cipher->base, key, keylen);
1624+
ret = xts_verify_key(cipher, key, keylen);
16251625
if (ret)
16261626
return ret;
16271627

drivers/crypto/cavium/cpt/cptvf_algs.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,13 +232,12 @@ static int cvm_decrypt(struct skcipher_request *req)
232232
static int cvm_xts_setkey(struct crypto_skcipher *cipher, const u8 *key,
233233
u32 keylen)
234234
{
235-
struct crypto_tfm *tfm = crypto_skcipher_tfm(cipher);
236-
struct cvm_enc_ctx *ctx = crypto_tfm_ctx(tfm);
235+
struct cvm_enc_ctx *ctx = crypto_skcipher_ctx(cipher);
237236
int err;
238237
const u8 *key1 = key;
239238
const u8 *key2 = key + (keylen / 2);
240239

241-
err = xts_check_key(tfm, key, keylen);
240+
err = xts_verify_key(cipher, key, keylen);
242241
if (err)
243242
return err;
244243
ctx->key_len = keylen;
@@ -289,8 +288,7 @@ static int cvm_validate_keylen(struct cvm_enc_ctx *ctx, u32 keylen)
289288
static int cvm_setkey(struct crypto_skcipher *cipher, const u8 *key,
290289
u32 keylen, u8 cipher_type)
291290
{
292-
struct crypto_tfm *tfm = crypto_skcipher_tfm(cipher);
293-
struct cvm_enc_ctx *ctx = crypto_tfm_ctx(tfm);
291+
struct cvm_enc_ctx *ctx = crypto_skcipher_ctx(cipher);
294292

295293
ctx->cipher_type = cipher_type;
296294
if (!cvm_validate_keylen(ctx, keylen)) {

drivers/crypto/cavium/nitrox/nitrox_skcipher.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -337,12 +337,11 @@ static int nitrox_3des_decrypt(struct skcipher_request *skreq)
337337
static int nitrox_aes_xts_setkey(struct crypto_skcipher *cipher,
338338
const u8 *key, unsigned int keylen)
339339
{
340-
struct crypto_tfm *tfm = crypto_skcipher_tfm(cipher);
341-
struct nitrox_crypto_ctx *nctx = crypto_tfm_ctx(tfm);
340+
struct nitrox_crypto_ctx *nctx = crypto_skcipher_ctx(cipher);
342341
struct flexi_crypto_context *fctx;
343342
int aes_keylen, ret;
344343

345-
ret = xts_check_key(tfm, key, keylen);
344+
ret = xts_verify_key(cipher, key, keylen);
346345
if (ret)
347346
return ret;
348347

@@ -362,8 +361,7 @@ static int nitrox_aes_xts_setkey(struct crypto_skcipher *cipher,
362361
static int nitrox_aes_ctr_rfc3686_setkey(struct crypto_skcipher *cipher,
363362
const u8 *key, unsigned int keylen)
364363
{
365-
struct crypto_tfm *tfm = crypto_skcipher_tfm(cipher);
366-
struct nitrox_crypto_ctx *nctx = crypto_tfm_ctx(tfm);
364+
struct nitrox_crypto_ctx *nctx = crypto_skcipher_ctx(cipher);
367365
struct flexi_crypto_context *fctx;
368366
int aes_keylen;
369367

drivers/crypto/ccree/cc_cipher.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ static int cc_cipher_setkey(struct crypto_skcipher *sktfm, const u8 *key,
460460
}
461461

462462
if (ctx_p->cipher_mode == DRV_CIPHER_XTS &&
463-
xts_check_key(tfm, key, keylen)) {
463+
xts_verify_key(sktfm, key, keylen)) {
464464
dev_dbg(dev, "weak XTS key");
465465
return -EINVAL;
466466
}

drivers/crypto/marvell/octeontx/otx_cptvf_algs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ static int otx_cpt_skcipher_xts_setkey(struct crypto_skcipher *tfm,
398398
const u8 *key1 = key;
399399
int ret;
400400

401-
ret = xts_check_key(crypto_skcipher_tfm(tfm), key, keylen);
401+
ret = xts_verify_key(tfm, key, keylen);
402402
if (ret)
403403
return ret;
404404
ctx->key_len = keylen;

drivers/crypto/marvell/octeontx2/otx2_cptvf_algs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ static int otx2_cpt_skcipher_xts_setkey(struct crypto_skcipher *tfm,
412412
const u8 *key1 = key;
413413
int ret;
414414

415-
ret = xts_check_key(crypto_skcipher_tfm(tfm), key, keylen);
415+
ret = xts_verify_key(tfm, key, keylen);
416416
if (ret)
417417
return ret;
418418
ctx->key_len = keylen;

include/crypto/xts.h

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,6 @@
88

99
#define XTS_BLOCK_SIZE 16
1010

11-
static inline int xts_check_key(struct crypto_tfm *tfm,
12-
const u8 *key, unsigned int keylen)
13-
{
14-
/*
15-
* key consists of keys of equal size concatenated, therefore
16-
* the length must be even.
17-
*/
18-
if (keylen % 2)
19-
return -EINVAL;
20-
21-
/* ensure that the AES and tweak key are not identical */
22-
if (fips_enabled && !crypto_memneq(key, key + (keylen / 2), keylen / 2))
23-
return -EINVAL;
24-
25-
return 0;
26-
}
27-
2811
static inline int xts_verify_key(struct crypto_skcipher *tfm,
2912
const u8 *key, unsigned int keylen)
3013
{
@@ -42,7 +25,10 @@ static inline int xts_verify_key(struct crypto_skcipher *tfm,
4225
if (fips_enabled && keylen != 32 && keylen != 64)
4326
return -EINVAL;
4427

45-
/* ensure that the AES and tweak key are not identical */
28+
/*
29+
* Ensure that the AES and tweak key are not identical when
30+
* in FIPS mode or the FORBID_WEAK_KEYS flag is set.
31+
*/
4632
if ((fips_enabled || (crypto_skcipher_get_flags(tfm) &
4733
CRYPTO_TFM_REQ_FORBID_WEAK_KEYS)) &&
4834
!crypto_memneq(key, key + (keylen / 2), keylen / 2))

0 commit comments

Comments
 (0)