aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArd Biesheuvel <ard.biesheuvel@linaro.org>2019-08-15 05:00:52 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2019-08-22 00:39:40 -0400
commit00cd6b233fc89463d4f4eddeb9abf1e009cc09c0 (patch)
tree391721d3ed686f7eb605106ba4070871bbc2337e
parentb525041633145828bd6744a4d1b79dbc084315b3 (diff)
crypto: ccree/des - switch to new verification routines
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r--drivers/crypto/ccree/cc_aead.c24
-rw-r--r--drivers/crypto/ccree/cc_cipher.c15
2 files changed, 8 insertions, 31 deletions
diff --git a/drivers/crypto/ccree/cc_aead.c b/drivers/crypto/ccree/cc_aead.c
index a9779a212b18..d3e8faa03f15 100644
--- a/drivers/crypto/ccree/cc_aead.c
+++ b/drivers/crypto/ccree/cc_aead.c
@@ -6,7 +6,7 @@
6#include <crypto/algapi.h> 6#include <crypto/algapi.h>
7#include <crypto/internal/aead.h> 7#include <crypto/internal/aead.h>
8#include <crypto/authenc.h> 8#include <crypto/authenc.h>
9#include <crypto/des.h> 9#include <crypto/internal/des.h>
10#include <linux/rtnetlink.h> 10#include <linux/rtnetlink.h>
11#include "cc_driver.h" 11#include "cc_driver.h"
12#include "cc_buffer_mgr.h" 12#include "cc_buffer_mgr.h"
@@ -649,33 +649,17 @@ static int cc_des3_aead_setkey(struct crypto_aead *aead, const u8 *key,
649 unsigned int keylen) 649 unsigned int keylen)
650{ 650{
651 struct crypto_authenc_keys keys; 651 struct crypto_authenc_keys keys;
652 u32 flags;
653 int err; 652 int err;
654 653
655 err = crypto_authenc_extractkeys(&keys, key, keylen); 654 err = crypto_authenc_extractkeys(&keys, key, keylen);
656 if (unlikely(err)) 655 if (unlikely(err))
657 goto badkey; 656 return err;
658
659 err = -EINVAL;
660 if (keys.enckeylen != DES3_EDE_KEY_SIZE)
661 goto badkey;
662 657
663 flags = crypto_aead_get_flags(aead); 658 err = verify_aead_des3_key(aead, keys.enckey, keys.enckeylen) ?:
664 err = __des3_verify_key(&flags, keys.enckey); 659 cc_aead_setkey(aead, key, keylen);
665 if (unlikely(err)) {
666 crypto_aead_set_flags(aead, flags);
667 goto out;
668 }
669 660
670 err = cc_aead_setkey(aead, key, keylen);
671
672out:
673 memzero_explicit(&keys, sizeof(keys)); 661 memzero_explicit(&keys, sizeof(keys));
674 return err; 662 return err;
675
676badkey:
677 crypto_aead_set_flags(aead, CRYPTO_TFM_RES_BAD_KEY_LEN);
678 goto out;
679} 663}
680 664
681static int cc_rfc4309_ccm_setkey(struct crypto_aead *tfm, const u8 *key, 665static int cc_rfc4309_ccm_setkey(struct crypto_aead *tfm, const u8 *key,
diff --git a/drivers/crypto/ccree/cc_cipher.c b/drivers/crypto/ccree/cc_cipher.c
index 5b58226ea24d..c7ec20e90fc0 100644
--- a/drivers/crypto/ccree/cc_cipher.c
+++ b/drivers/crypto/ccree/cc_cipher.c
@@ -5,7 +5,7 @@
5#include <linux/module.h> 5#include <linux/module.h>
6#include <crypto/algapi.h> 6#include <crypto/algapi.h>
7#include <crypto/internal/skcipher.h> 7#include <crypto/internal/skcipher.h>
8#include <crypto/des.h> 8#include <crypto/internal/des.h>
9#include <crypto/xts.h> 9#include <crypto/xts.h>
10#include <crypto/sm4.h> 10#include <crypto/sm4.h>
11#include <crypto/scatterwalk.h> 11#include <crypto/scatterwalk.h>
@@ -411,16 +411,9 @@ static int cc_cipher_setkey(struct crypto_skcipher *sktfm, const u8 *key,
411 * HW does the expansion on its own. 411 * HW does the expansion on its own.
412 */ 412 */
413 if (ctx_p->flow_mode == S_DIN_to_DES) { 413 if (ctx_p->flow_mode == S_DIN_to_DES) {
414 u32 tmp[DES3_EDE_EXPKEY_WORDS]; 414 if ((keylen == DES3_EDE_KEY_SIZE &&
415 if (keylen == DES3_EDE_KEY_SIZE && 415 verify_skcipher_des3_key(sktfm, key)) ||
416 __des3_ede_setkey(tmp, &tfm->crt_flags, key, 416 verify_skcipher_des_key(sktfm, key)) {
417 DES3_EDE_KEY_SIZE)) {
418 dev_dbg(dev, "weak 3DES key");
419 return -EINVAL;
420 } else if (!des_ekey(tmp, key) &&
421 (crypto_tfm_get_flags(tfm) &
422 CRYPTO_TFM_REQ_FORBID_WEAK_KEYS)) {
423 tfm->crt_flags |= CRYPTO_TFM_RES_WEAK_KEY;
424 dev_dbg(dev, "weak DES key"); 417 dev_dbg(dev, "weak DES key");
425 return -EINVAL; 418 return -EINVAL;
426 } 419 }