summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArd Biesheuvel <ard.biesheuvel@linaro.org>2019-08-15 05:00:45 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2019-08-22 00:39:37 -0400
commit8f467cf29f192f9ebd89dcc4a18901e62c17e37a (patch)
tree9feda5aa979613a2b6a2b94cfbd65f91f1a617cc
parent4e2c820897d93a4dbe76865d860087f809963308 (diff)
crypto: sparc/des - switch to new verification routines
Switch to the refactored DES key verification routines. While at it, rename the DES encrypt/decrypt routines so they will not conflict with the DES library later on. Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r--arch/sparc/crypto/des_glue.c37
1 files changed, 16 insertions, 21 deletions
diff --git a/arch/sparc/crypto/des_glue.c b/arch/sparc/crypto/des_glue.c
index 281448f72c90..db6010b4e52e 100644
--- a/arch/sparc/crypto/des_glue.c
+++ b/arch/sparc/crypto/des_glue.c
@@ -12,7 +12,7 @@
12#include <linux/mm.h> 12#include <linux/mm.h>
13#include <linux/types.h> 13#include <linux/types.h>
14#include <crypto/algapi.h> 14#include <crypto/algapi.h>
15#include <crypto/des.h> 15#include <crypto/internal/des.h>
16 16
17#include <asm/fpumacro.h> 17#include <asm/fpumacro.h>
18#include <asm/pstate.h> 18#include <asm/pstate.h>
@@ -45,19 +45,15 @@ static int des_set_key(struct crypto_tfm *tfm, const u8 *key,
45 unsigned int keylen) 45 unsigned int keylen)
46{ 46{
47 struct des_sparc64_ctx *dctx = crypto_tfm_ctx(tfm); 47 struct des_sparc64_ctx *dctx = crypto_tfm_ctx(tfm);
48 u32 *flags = &tfm->crt_flags; 48 int err;
49 u32 tmp[DES_EXPKEY_WORDS];
50 int ret;
51 49
52 /* Even though we have special instructions for key expansion, 50 /* Even though we have special instructions for key expansion,
53 * we call des_ekey() so that we don't have to write our own 51 * we call des_verify_key() so that we don't have to write our own
54 * weak key detection code. 52 * weak key detection code.
55 */ 53 */
56 ret = des_ekey(tmp, key); 54 err = crypto_des_verify_key(tfm, key);
57 if (unlikely(ret == 0) && (*flags & CRYPTO_TFM_REQ_FORBID_WEAK_KEYS)) { 55 if (err)
58 *flags |= CRYPTO_TFM_RES_WEAK_KEY; 56 return err;
59 return -EINVAL;
60 }
61 57
62 des_sparc64_key_expand((const u32 *) key, &dctx->encrypt_expkey[0]); 58 des_sparc64_key_expand((const u32 *) key, &dctx->encrypt_expkey[0]);
63 encrypt_to_decrypt(&dctx->decrypt_expkey[0], &dctx->encrypt_expkey[0]); 59 encrypt_to_decrypt(&dctx->decrypt_expkey[0], &dctx->encrypt_expkey[0]);
@@ -68,7 +64,7 @@ static int des_set_key(struct crypto_tfm *tfm, const u8 *key,
68extern void des_sparc64_crypt(const u64 *key, const u64 *input, 64extern void des_sparc64_crypt(const u64 *key, const u64 *input,
69 u64 *output); 65 u64 *output);
70 66
71static void des_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) 67static void sparc_des_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
72{ 68{
73 struct des_sparc64_ctx *ctx = crypto_tfm_ctx(tfm); 69 struct des_sparc64_ctx *ctx = crypto_tfm_ctx(tfm);
74 const u64 *K = ctx->encrypt_expkey; 70 const u64 *K = ctx->encrypt_expkey;
@@ -76,7 +72,7 @@ static void des_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
76 des_sparc64_crypt(K, (const u64 *) src, (u64 *) dst); 72 des_sparc64_crypt(K, (const u64 *) src, (u64 *) dst);
77} 73}
78 74
79static void des_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) 75static void sparc_des_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
80{ 76{
81 struct des_sparc64_ctx *ctx = crypto_tfm_ctx(tfm); 77 struct des_sparc64_ctx *ctx = crypto_tfm_ctx(tfm);
82 const u64 *K = ctx->decrypt_expkey; 78 const u64 *K = ctx->decrypt_expkey;
@@ -202,14 +198,13 @@ static int des3_ede_set_key(struct crypto_tfm *tfm, const u8 *key,
202 unsigned int keylen) 198 unsigned int keylen)
203{ 199{
204 struct des3_ede_sparc64_ctx *dctx = crypto_tfm_ctx(tfm); 200 struct des3_ede_sparc64_ctx *dctx = crypto_tfm_ctx(tfm);
205 u32 *flags = &tfm->crt_flags;
206 u64 k1[DES_EXPKEY_WORDS / 2]; 201 u64 k1[DES_EXPKEY_WORDS / 2];
207 u64 k2[DES_EXPKEY_WORDS / 2]; 202 u64 k2[DES_EXPKEY_WORDS / 2];
208 u64 k3[DES_EXPKEY_WORDS / 2]; 203 u64 k3[DES_EXPKEY_WORDS / 2];
209 int err; 204 int err;
210 205
211 err = __des3_verify_key(flags, key); 206 err = crypto_des3_ede_verify_key(tfm, key);
212 if (unlikely(err)) 207 if (err)
213 return err; 208 return err;
214 209
215 des_sparc64_key_expand((const u32 *)key, k1); 210 des_sparc64_key_expand((const u32 *)key, k1);
@@ -235,7 +230,7 @@ static int des3_ede_set_key(struct crypto_tfm *tfm, const u8 *key,
235extern void des3_ede_sparc64_crypt(const u64 *key, const u64 *input, 230extern void des3_ede_sparc64_crypt(const u64 *key, const u64 *input,
236 u64 *output); 231 u64 *output);
237 232
238static void des3_ede_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) 233static void sparc_des3_ede_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
239{ 234{
240 struct des3_ede_sparc64_ctx *ctx = crypto_tfm_ctx(tfm); 235 struct des3_ede_sparc64_ctx *ctx = crypto_tfm_ctx(tfm);
241 const u64 *K = ctx->encrypt_expkey; 236 const u64 *K = ctx->encrypt_expkey;
@@ -243,7 +238,7 @@ static void des3_ede_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
243 des3_ede_sparc64_crypt(K, (const u64 *) src, (u64 *) dst); 238 des3_ede_sparc64_crypt(K, (const u64 *) src, (u64 *) dst);
244} 239}
245 240
246static void des3_ede_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) 241static void sparc_des3_ede_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
247{ 242{
248 struct des3_ede_sparc64_ctx *ctx = crypto_tfm_ctx(tfm); 243 struct des3_ede_sparc64_ctx *ctx = crypto_tfm_ctx(tfm);
249 const u64 *K = ctx->decrypt_expkey; 244 const u64 *K = ctx->decrypt_expkey;
@@ -390,8 +385,8 @@ static struct crypto_alg algs[] = { {
390 .cia_min_keysize = DES_KEY_SIZE, 385 .cia_min_keysize = DES_KEY_SIZE,
391 .cia_max_keysize = DES_KEY_SIZE, 386 .cia_max_keysize = DES_KEY_SIZE,
392 .cia_setkey = des_set_key, 387 .cia_setkey = des_set_key,
393 .cia_encrypt = des_encrypt, 388 .cia_encrypt = sparc_des_encrypt,
394 .cia_decrypt = des_decrypt 389 .cia_decrypt = sparc_des_decrypt
395 } 390 }
396 } 391 }
397}, { 392}, {
@@ -447,8 +442,8 @@ static struct crypto_alg algs[] = { {
447 .cia_min_keysize = DES3_EDE_KEY_SIZE, 442 .cia_min_keysize = DES3_EDE_KEY_SIZE,
448 .cia_max_keysize = DES3_EDE_KEY_SIZE, 443 .cia_max_keysize = DES3_EDE_KEY_SIZE,
449 .cia_setkey = des3_ede_set_key, 444 .cia_setkey = des3_ede_set_key,
450 .cia_encrypt = des3_ede_encrypt, 445 .cia_encrypt = sparc_des3_ede_encrypt,
451 .cia_decrypt = des3_ede_decrypt 446 .cia_decrypt = sparc_des3_ede_decrypt
452 } 447 }
453 } 448 }
454}, { 449}, {