Skip to content

Commit 545a6b9

Browse files
brglgregkh
authored andcommitted
crypto: qce - Remove unsafe/deprecated algorithms
commit 7e28b0a upstream. Remove algorithms that are either unsafe or deprecated and have no in-kernel users that cannot be served by the ARM CE implementations. AES-ECB reveals plaintext patterns (identical plaintext blocks produce identical ciphertext blocks) and should not be exposed as a hardware- accelerated primitive. DES, Triple DES and HMAC-SHA1 have been deprecated for years. Remove sha1, ecb(aes), ecb(des), cbc(des), ecb(des3_ede), cbc(des3_ede), hmac(sha1) and all AEAD variants built on these primitives as well as authenc(hmac(sha256),cbc(des)). Also clean up the - now dead - code, flags and constants. Cc: stable@vger.kernel.org Acked-by: Eric Biggers <ebiggers@kernel.org> Tested-by: Kuldeep Singh <kuldeep.singh@oss.qualcomm.com> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 182f16a commit 545a6b9

7 files changed

Lines changed: 20 additions & 239 deletions

File tree

drivers/crypto/qce/aead.c

Lines changed: 1 addition & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
#include <crypto/gcm.h>
99
#include <crypto/authenc.h>
1010
#include <crypto/internal/aead.h>
11-
#include <crypto/internal/des.h>
12-
#include <crypto/sha1.h>
1311
#include <crypto/sha2.h>
1412
#include <crypto/scatterwalk.h>
1513
#include "aead.h"
@@ -597,7 +595,6 @@ static int qce_aead_setkey(struct crypto_aead *tfm, const u8 *key, unsigned int
597595
struct qce_aead_ctx *ctx = crypto_aead_ctx(tfm);
598596
struct crypto_authenc_keys authenc_keys;
599597
unsigned long flags = to_aead_tmpl(tfm)->alg_flags;
600-
u32 _key[6];
601598
int err;
602599

603600
err = crypto_authenc_extractkeys(&authenc_keys, key, keylen);
@@ -608,26 +605,7 @@ static int qce_aead_setkey(struct crypto_aead *tfm, const u8 *key, unsigned int
608605
authenc_keys.authkeylen > QCE_MAX_KEY_SIZE)
609606
return -EINVAL;
610607

611-
if (IS_DES(flags)) {
612-
err = verify_aead_des_key(tfm, authenc_keys.enckey, authenc_keys.enckeylen);
613-
if (err)
614-
return err;
615-
} else if (IS_3DES(flags)) {
616-
err = verify_aead_des3_key(tfm, authenc_keys.enckey, authenc_keys.enckeylen);
617-
if (err)
618-
return err;
619-
/*
620-
* The crypto engine does not support any two keys
621-
* being the same for triple des algorithms. The
622-
* verify_skcipher_des3_key does not check for all the
623-
* below conditions. Schedule fallback in this case.
624-
*/
625-
memcpy(_key, authenc_keys.enckey, DES3_EDE_KEY_SIZE);
626-
if (!((_key[0] ^ _key[2]) | (_key[1] ^ _key[3])) ||
627-
!((_key[2] ^ _key[4]) | (_key[3] ^ _key[5])) ||
628-
!((_key[0] ^ _key[4]) | (_key[1] ^ _key[5])))
629-
ctx->need_fallback = true;
630-
} else if (IS_AES(flags)) {
608+
if (IS_AES(flags)) {
631609
/* No random key sizes */
632610
if (authenc_keys.enckeylen != AES_KEYSIZE_128 &&
633611
authenc_keys.enckeylen != AES_KEYSIZE_192 &&
@@ -698,38 +676,6 @@ struct qce_aead_def {
698676
};
699677

700678
static const struct qce_aead_def aead_def[] = {
701-
{
702-
.flags = QCE_ALG_DES | QCE_MODE_CBC | QCE_HASH_SHA1_HMAC,
703-
.name = "authenc(hmac(sha1),cbc(des))",
704-
.drv_name = "authenc-hmac-sha1-cbc-des-qce",
705-
.blocksize = DES_BLOCK_SIZE,
706-
.ivsize = DES_BLOCK_SIZE,
707-
.maxauthsize = SHA1_DIGEST_SIZE,
708-
},
709-
{
710-
.flags = QCE_ALG_3DES | QCE_MODE_CBC | QCE_HASH_SHA1_HMAC,
711-
.name = "authenc(hmac(sha1),cbc(des3_ede))",
712-
.drv_name = "authenc-hmac-sha1-cbc-3des-qce",
713-
.blocksize = DES3_EDE_BLOCK_SIZE,
714-
.ivsize = DES3_EDE_BLOCK_SIZE,
715-
.maxauthsize = SHA1_DIGEST_SIZE,
716-
},
717-
{
718-
.flags = QCE_ALG_DES | QCE_MODE_CBC | QCE_HASH_SHA256_HMAC,
719-
.name = "authenc(hmac(sha256),cbc(des))",
720-
.drv_name = "authenc-hmac-sha256-cbc-des-qce",
721-
.blocksize = DES_BLOCK_SIZE,
722-
.ivsize = DES_BLOCK_SIZE,
723-
.maxauthsize = SHA256_DIGEST_SIZE,
724-
},
725-
{
726-
.flags = QCE_ALG_3DES | QCE_MODE_CBC | QCE_HASH_SHA256_HMAC,
727-
.name = "authenc(hmac(sha256),cbc(des3_ede))",
728-
.drv_name = "authenc-hmac-sha256-cbc-3des-qce",
729-
.blocksize = DES3_EDE_BLOCK_SIZE,
730-
.ivsize = DES3_EDE_BLOCK_SIZE,
731-
.maxauthsize = SHA256_DIGEST_SIZE,
732-
},
733679
{
734680
.flags = QCE_ALG_AES | QCE_MODE_CBC | QCE_HASH_SHA256_HMAC,
735681
.name = "authenc(hmac(sha256),cbc(aes))",

drivers/crypto/qce/common.c

Lines changed: 12 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include <linux/interrupt.h>
99
#include <linux/types.h>
1010
#include <crypto/scatterwalk.h>
11-
#include <crypto/sha1.h>
1211
#include <crypto/sha2.h>
1312

1413
#include "cipher.h"
@@ -115,18 +114,16 @@ static u32 qce_auth_cfg(unsigned long flags, u32 key_size, u32 auth_size)
115114
cfg |= AUTH_KEY_SZ_AES256 << AUTH_KEY_SIZE_SHIFT;
116115
}
117116

118-
if (IS_SHA1(flags) || IS_SHA1_HMAC(flags))
119-
cfg |= AUTH_SIZE_SHA1 << AUTH_SIZE_SHIFT;
120-
else if (IS_SHA256(flags) || IS_SHA256_HMAC(flags))
117+
if (IS_SHA256(flags) || IS_SHA256_HMAC(flags))
121118
cfg |= AUTH_SIZE_SHA256 << AUTH_SIZE_SHIFT;
122119
else if (IS_CMAC(flags))
123120
cfg |= AUTH_SIZE_ENUM_16_BYTES << AUTH_SIZE_SHIFT;
124121
else if (IS_CCM(flags))
125122
cfg |= (auth_size - 1) << AUTH_SIZE_SHIFT;
126123

127-
if (IS_SHA1(flags) || IS_SHA256(flags))
124+
if (IS_SHA256(flags))
128125
cfg |= AUTH_MODE_HASH << AUTH_MODE_SHIFT;
129-
else if (IS_SHA1_HMAC(flags) || IS_SHA256_HMAC(flags))
126+
else if (IS_SHA256_HMAC(flags))
130127
cfg |= AUTH_MODE_HMAC << AUTH_MODE_SHIFT;
131128
else if (IS_CCM(flags))
132129
cfg |= AUTH_MODE_CCM << AUTH_MODE_SHIFT;
@@ -191,7 +188,7 @@ static int qce_setup_regs_ahash(struct crypto_async_request *async_req)
191188
else
192189
qce_cpu_to_be32p_array(auth, rctx->digest, digestsize);
193190

194-
iv_words = (IS_SHA1(rctx->flags) || IS_SHA1_HMAC(rctx->flags)) ? 5 : 8;
191+
iv_words = 8;
195192
qce_write_array(qce, REG_AUTH_IV0, (u32 *)auth, iv_words);
196193

197194
if (rctx->first_blk)
@@ -243,19 +240,8 @@ static u32 qce_encr_cfg(unsigned long flags, u32 aes_key_size)
243240

244241
if (IS_AES(flags))
245242
cfg |= ENCR_ALG_AES << ENCR_ALG_SHIFT;
246-
else if (IS_DES(flags) || IS_3DES(flags))
247-
cfg |= ENCR_ALG_DES << ENCR_ALG_SHIFT;
248-
249-
if (IS_DES(flags))
250-
cfg |= ENCR_KEY_SZ_DES << ENCR_KEY_SZ_SHIFT;
251-
252-
if (IS_3DES(flags))
253-
cfg |= ENCR_KEY_SZ_3DES << ENCR_KEY_SZ_SHIFT;
254243

255244
switch (flags & QCE_MODE_MASK) {
256-
case QCE_MODE_ECB:
257-
cfg |= ENCR_MODE_ECB << ENCR_MODE_SHIFT;
258-
break;
259245
case QCE_MODE_CBC:
260246
cfg |= ENCR_MODE_CBC << ENCR_MODE_SHIFT;
261247
break;
@@ -340,13 +326,7 @@ static int qce_setup_regs_skcipher(struct crypto_async_request *async_req)
340326

341327
encr_cfg = qce_encr_cfg(flags, keylen);
342328

343-
if (IS_DES(flags)) {
344-
enciv_words = 2;
345-
enckey_words = 2;
346-
} else if (IS_3DES(flags)) {
347-
enciv_words = 2;
348-
enckey_words = 6;
349-
} else if (IS_AES(flags)) {
329+
if (IS_AES(flags)) {
350330
if (IS_XTS(flags))
351331
qce_xtskey(qce, ctx->enc_key, ctx->enc_keylen,
352332
rctx->cryptlen);
@@ -357,14 +337,12 @@ static int qce_setup_regs_skcipher(struct crypto_async_request *async_req)
357337

358338
qce_write_array(qce, REG_ENCR_KEY0, (u32 *)enckey, enckey_words);
359339

360-
if (!IS_ECB(flags)) {
361-
if (IS_XTS(flags))
362-
qce_xts_swapiv(enciv, rctx->iv, ivsize);
363-
else
364-
qce_cpu_to_be32p_array(enciv, rctx->iv, ivsize);
340+
if (IS_XTS(flags))
341+
qce_xts_swapiv(enciv, rctx->iv, ivsize);
342+
else
343+
qce_cpu_to_be32p_array(enciv, rctx->iv, ivsize);
365344

366-
qce_write_array(qce, REG_CNTR0_IV0, (u32 *)enciv, enciv_words);
367-
}
345+
qce_write_array(qce, REG_CNTR0_IV0, (u32 *)enciv, enciv_words);
368346

369347
if (IS_ENCRYPT(flags))
370348
encr_cfg |= BIT(ENCODE_SHIFT);
@@ -393,10 +371,6 @@ static int qce_setup_regs_skcipher(struct crypto_async_request *async_req)
393371
#endif
394372

395373
#ifdef CONFIG_CRYPTO_DEV_QCE_AEAD
396-
static const u32 std_iv_sha1[SHA256_DIGEST_SIZE / sizeof(u32)] = {
397-
SHA1_H0, SHA1_H1, SHA1_H2, SHA1_H3, SHA1_H4, 0, 0, 0
398-
};
399-
400374
static const u32 std_iv_sha256[SHA256_DIGEST_SIZE / sizeof(u32)] = {
401375
SHA256_H0, SHA256_H1, SHA256_H2, SHA256_H3,
402376
SHA256_H4, SHA256_H5, SHA256_H6, SHA256_H7
@@ -473,13 +447,8 @@ static int qce_setup_regs_aead(struct crypto_async_request *async_req)
473447
/* Write initial authentication IV only for HMAC algorithms */
474448
if (IS_SHA_HMAC(rctx->flags)) {
475449
/* Write default authentication iv */
476-
if (IS_SHA1_HMAC(rctx->flags)) {
477-
auth_ivsize = SHA1_DIGEST_SIZE;
478-
memcpy(authiv, std_iv_sha1, auth_ivsize);
479-
} else if (IS_SHA256_HMAC(rctx->flags)) {
480-
auth_ivsize = SHA256_DIGEST_SIZE;
481-
memcpy(authiv, std_iv_sha256, auth_ivsize);
482-
}
450+
auth_ivsize = SHA256_DIGEST_SIZE;
451+
memcpy(authiv, std_iv_sha256, auth_ivsize);
483452
authiv_words = auth_ivsize / sizeof(u32);
484453
qce_write_array(qce, REG_AUTH_IV0, (u32 *)authiv, authiv_words);
485454
} else if (IS_CCM(rctx->flags)) {

drivers/crypto/qce/common.h

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
/* IV length in bytes */
2424
#define QCE_AES_IV_LENGTH AES_BLOCK_SIZE
25-
/* max of AES_BLOCK_SIZE, DES3_EDE_BLOCK_SIZE */
25+
/* max of AES_BLOCK_SIZE */
2626
#define QCE_MAX_IV_SIZE AES_BLOCK_SIZE
2727

2828
/* maximum nonce bytes */
@@ -33,14 +33,10 @@
3333
#define QCE_MAX_ALIGN_SIZE 64
3434

3535
/* cipher algorithms */
36-
#define QCE_ALG_DES BIT(0)
37-
#define QCE_ALG_3DES BIT(1)
3836
#define QCE_ALG_AES BIT(2)
3937

4038
/* hash and hmac algorithms */
41-
#define QCE_HASH_SHA1 BIT(3)
4239
#define QCE_HASH_SHA256 BIT(4)
43-
#define QCE_HASH_SHA1_HMAC BIT(5)
4440
#define QCE_HASH_SHA256_HMAC BIT(6)
4541
#define QCE_HASH_AES_CMAC BIT(7)
4642

@@ -58,21 +54,15 @@
5854
#define QCE_ENCRYPT BIT(30)
5955
#define QCE_DECRYPT BIT(31)
6056

61-
#define IS_DES(flags) (flags & QCE_ALG_DES)
62-
#define IS_3DES(flags) (flags & QCE_ALG_3DES)
6357
#define IS_AES(flags) (flags & QCE_ALG_AES)
6458

65-
#define IS_SHA1(flags) (flags & QCE_HASH_SHA1)
6659
#define IS_SHA256(flags) (flags & QCE_HASH_SHA256)
67-
#define IS_SHA1_HMAC(flags) (flags & QCE_HASH_SHA1_HMAC)
6860
#define IS_SHA256_HMAC(flags) (flags & QCE_HASH_SHA256_HMAC)
6961
#define IS_CMAC(flags) (flags & QCE_HASH_AES_CMAC)
70-
#define IS_SHA(flags) (IS_SHA1(flags) || IS_SHA256(flags))
71-
#define IS_SHA_HMAC(flags) \
72-
(IS_SHA1_HMAC(flags) || IS_SHA256_HMAC(flags))
62+
#define IS_SHA(flags) IS_SHA256(flags)
63+
#define IS_SHA_HMAC(flags) IS_SHA256_HMAC(flags)
7364

7465
#define IS_CBC(mode) (mode & QCE_MODE_CBC)
75-
#define IS_ECB(mode) (mode & QCE_MODE_ECB)
7666
#define IS_CTR(mode) (mode & QCE_MODE_CTR)
7767
#define IS_XTS(mode) (mode & QCE_MODE_XTS)
7868
#define IS_CCM(mode) (mode & QCE_MODE_CCM)

drivers/crypto/qce/regs-v5.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@
203203

204204
#define AUTH_SIZE_SHIFT 9
205205
#define AUTH_SIZE_MASK GENMASK(13, 9)
206-
#define AUTH_SIZE_SHA1 0
207206
#define AUTH_SIZE_SHA256 1
208207
#define AUTH_SIZE_ENUM_1_BYTES 0
209208
#define AUTH_SIZE_ENUM_2_BYTES 1
@@ -284,15 +283,12 @@
284283

285284
#define ENCR_KEY_SZ_SHIFT 3
286285
#define ENCR_KEY_SZ_MASK GENMASK(5, 3)
287-
#define ENCR_KEY_SZ_DES 0
288-
#define ENCR_KEY_SZ_3DES 1
289286
#define ENCR_KEY_SZ_AES128 0
290287
#define ENCR_KEY_SZ_AES256 2
291288

292289
#define ENCR_ALG_SHIFT 0
293290
#define ENCR_ALG_MASK GENMASK(2, 0)
294291
#define ENCR_ALG_NONE 0
295-
#define ENCR_ALG_DES 1
296292
#define ENCR_ALG_AES 2
297293
#define ENCR_ALG_KASUMI 4
298294
#define ENCR_ALG_SNOW_3G 5

drivers/crypto/qce/sha.c

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ struct qce_sha_saved_state {
2424

2525
static LIST_HEAD(ahash_algs);
2626

27-
static const u32 std_iv_sha1[SHA256_DIGEST_SIZE / sizeof(u32)] = {
28-
SHA1_H0, SHA1_H1, SHA1_H2, SHA1_H3, SHA1_H4, 0, 0, 0
29-
};
30-
3127
static const u32 std_iv_sha256[SHA256_DIGEST_SIZE / sizeof(u32)] = {
3228
SHA256_H0, SHA256_H1, SHA256_H2, SHA256_H3,
3329
SHA256_H4, SHA256_H5, SHA256_H6, SHA256_H7
@@ -348,9 +344,7 @@ static int qce_ahash_hmac_setkey(struct crypto_ahash *tfm, const u8 *key,
348344
return 0;
349345
}
350346

351-
if (digestsize == SHA1_DIGEST_SIZE)
352-
alg_name = "sha1-qce";
353-
else if (digestsize == SHA256_DIGEST_SIZE)
347+
if (digestsize == SHA256_DIGEST_SIZE)
354348
alg_name = "sha256-qce";
355349
else
356350
return -EINVAL;
@@ -411,15 +405,6 @@ struct qce_ahash_def {
411405
};
412406

413407
static const struct qce_ahash_def ahash_def[] = {
414-
{
415-
.flags = QCE_HASH_SHA1,
416-
.name = "sha1",
417-
.drv_name = "sha1-qce",
418-
.digestsize = SHA1_DIGEST_SIZE,
419-
.blocksize = SHA1_BLOCK_SIZE,
420-
.statesize = sizeof(struct qce_sha_saved_state),
421-
.std_iv = std_iv_sha1,
422-
},
423408
{
424409
.flags = QCE_HASH_SHA256,
425410
.name = "sha256",
@@ -429,15 +414,6 @@ static const struct qce_ahash_def ahash_def[] = {
429414
.statesize = sizeof(struct qce_sha_saved_state),
430415
.std_iv = std_iv_sha256,
431416
},
432-
{
433-
.flags = QCE_HASH_SHA1_HMAC,
434-
.name = "hmac(sha1)",
435-
.drv_name = "hmac-sha1-qce",
436-
.digestsize = SHA1_DIGEST_SIZE,
437-
.blocksize = SHA1_BLOCK_SIZE,
438-
.statesize = sizeof(struct qce_sha_saved_state),
439-
.std_iv = std_iv_sha1,
440-
},
441417
{
442418
.flags = QCE_HASH_SHA256_HMAC,
443419
.name = "hmac(sha256)",
@@ -475,9 +451,7 @@ static int qce_ahash_register_one(const struct qce_ahash_def *def,
475451
alg->halg.digestsize = def->digestsize;
476452
alg->halg.statesize = def->statesize;
477453

478-
if (IS_SHA1(def->flags))
479-
tmpl->hash_zero = sha1_zero_message_hash;
480-
else if (IS_SHA256(def->flags))
454+
if (IS_SHA256(def->flags))
481455
tmpl->hash_zero = sha256_zero_message_hash;
482456

483457
base = &alg->halg.base;

drivers/crypto/qce/sha.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#define _SHA_H_
88

99
#include <crypto/scatterwalk.h>
10-
#include <crypto/sha1.h>
1110
#include <crypto/sha2.h>
1211

1312
#include "common.h"

0 commit comments

Comments
 (0)