diff options
author | Jan Glauber <jang@linux.vnet.ibm.com> | 2010-05-21 08:04:46 -0400 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2010-05-21 08:04:46 -0400 |
commit | 1efbd15c3bc2b79d33e033e898211109c32159fa (patch) | |
tree | e64b3b66f138ebad2b128ca86c544bfa24af3353 /arch | |
parent | 80d663a42127b839e820ed934cead51cff6196d3 (diff) |
crypto: des_s390: use generic weak key check
Get rid of the des_s390 specific key check module and use the generic DES
weak key check instead. Also use the generic DES header and remove the
weak key check in 3DES mode, as RFC2451 mentions that the DES weak keys
are not relevant for 3DES.
Signed-off-by: Jan Glauber <jang@linux.vnet.ibm.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'arch')
-rw-r--r-- | arch/s390/crypto/Makefile | 2 | ||||
-rw-r--r-- | arch/s390/crypto/des_s390.c | 47 |
2 files changed, 21 insertions, 28 deletions
diff --git a/arch/s390/crypto/Makefile b/arch/s390/crypto/Makefile index 6a1157fa4f98..1cf81d77c5a5 100644 --- a/arch/s390/crypto/Makefile +++ b/arch/s390/crypto/Makefile | |||
@@ -5,6 +5,6 @@ | |||
5 | obj-$(CONFIG_CRYPTO_SHA1_S390) += sha1_s390.o sha_common.o | 5 | obj-$(CONFIG_CRYPTO_SHA1_S390) += sha1_s390.o sha_common.o |
6 | obj-$(CONFIG_CRYPTO_SHA256_S390) += sha256_s390.o sha_common.o | 6 | obj-$(CONFIG_CRYPTO_SHA256_S390) += sha256_s390.o sha_common.o |
7 | obj-$(CONFIG_CRYPTO_SHA512_S390) += sha512_s390.o sha_common.o | 7 | obj-$(CONFIG_CRYPTO_SHA512_S390) += sha512_s390.o sha_common.o |
8 | obj-$(CONFIG_CRYPTO_DES_S390) += des_s390.o des_check_key.o | 8 | obj-$(CONFIG_CRYPTO_DES_S390) += des_s390.o |
9 | obj-$(CONFIG_CRYPTO_AES_S390) += aes_s390.o | 9 | obj-$(CONFIG_CRYPTO_AES_S390) += aes_s390.o |
10 | obj-$(CONFIG_S390_PRNG) += prng.o | 10 | obj-$(CONFIG_S390_PRNG) += prng.o |
diff --git a/arch/s390/crypto/des_s390.c b/arch/s390/crypto/des_s390.c index a1a18b30309f..cc5420118393 100644 --- a/arch/s390/crypto/des_s390.c +++ b/arch/s390/crypto/des_s390.c | |||
@@ -14,18 +14,15 @@ | |||
14 | * | 14 | * |
15 | */ | 15 | */ |
16 | 16 | ||
17 | #include <crypto/algapi.h> | ||
18 | #include <linux/init.h> | 17 | #include <linux/init.h> |
19 | #include <linux/module.h> | 18 | #include <linux/module.h> |
19 | #include <linux/crypto.h> | ||
20 | #include <crypto/algapi.h> | ||
21 | #include <crypto/des.h> | ||
20 | 22 | ||
21 | #include "crypt_s390.h" | 23 | #include "crypt_s390.h" |
22 | #include "crypto_des.h" | ||
23 | |||
24 | #define DES_BLOCK_SIZE 8 | ||
25 | #define DES_KEY_SIZE 8 | ||
26 | 24 | ||
27 | #define DES3_192_KEY_SIZE (3 * DES_KEY_SIZE) | 25 | #define DES3_192_KEY_SIZE (3 * DES_KEY_SIZE) |
28 | #define DES3_192_BLOCK_SIZE DES_BLOCK_SIZE | ||
29 | 26 | ||
30 | struct crypt_s390_des_ctx { | 27 | struct crypt_s390_des_ctx { |
31 | u8 iv[DES_BLOCK_SIZE]; | 28 | u8 iv[DES_BLOCK_SIZE]; |
@@ -42,13 +39,16 @@ static int des_setkey(struct crypto_tfm *tfm, const u8 *key, | |||
42 | { | 39 | { |
43 | struct crypt_s390_des_ctx *dctx = crypto_tfm_ctx(tfm); | 40 | struct crypt_s390_des_ctx *dctx = crypto_tfm_ctx(tfm); |
44 | u32 *flags = &tfm->crt_flags; | 41 | u32 *flags = &tfm->crt_flags; |
45 | int ret; | 42 | u32 tmp[DES_EXPKEY_WORDS]; |
46 | 43 | ||
47 | /* test if key is valid (not a weak key) */ | 44 | /* check for weak keys */ |
48 | ret = crypto_des_check_key(key, keylen, flags); | 45 | if (!des_ekey(tmp, key) && (*flags & CRYPTO_TFM_REQ_WEAK_KEY)) { |
49 | if (ret == 0) | 46 | *flags |= CRYPTO_TFM_RES_WEAK_KEY; |
50 | memcpy(dctx->key, key, keylen); | 47 | return -EINVAL; |
51 | return ret; | 48 | } |
49 | |||
50 | memcpy(dctx->key, key, keylen); | ||
51 | return 0; | ||
52 | } | 52 | } |
53 | 53 | ||
54 | static void des_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in) | 54 | static void des_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in) |
@@ -238,9 +238,7 @@ static struct crypto_alg cbc_des_alg = { | |||
238 | static int des3_192_setkey(struct crypto_tfm *tfm, const u8 *key, | 238 | static int des3_192_setkey(struct crypto_tfm *tfm, const u8 *key, |
239 | unsigned int keylen) | 239 | unsigned int keylen) |
240 | { | 240 | { |
241 | int i, ret; | ||
242 | struct crypt_s390_des3_192_ctx *dctx = crypto_tfm_ctx(tfm); | 241 | struct crypt_s390_des3_192_ctx *dctx = crypto_tfm_ctx(tfm); |
243 | const u8 *temp_key = key; | ||
244 | u32 *flags = &tfm->crt_flags; | 242 | u32 *flags = &tfm->crt_flags; |
245 | 243 | ||
246 | if (!(memcmp(key, &key[DES_KEY_SIZE], DES_KEY_SIZE) && | 244 | if (!(memcmp(key, &key[DES_KEY_SIZE], DES_KEY_SIZE) && |
@@ -250,11 +248,6 @@ static int des3_192_setkey(struct crypto_tfm *tfm, const u8 *key, | |||
250 | *flags |= CRYPTO_TFM_RES_WEAK_KEY; | 248 | *flags |= CRYPTO_TFM_RES_WEAK_KEY; |
251 | return -EINVAL; | 249 | return -EINVAL; |
252 | } | 250 | } |
253 | for (i = 0; i < 3; i++, temp_key += DES_KEY_SIZE) { | ||
254 | ret = crypto_des_check_key(temp_key, DES_KEY_SIZE, flags); | ||
255 | if (ret < 0) | ||
256 | return ret; | ||
257 | } | ||
258 | memcpy(dctx->key, key, keylen); | 251 | memcpy(dctx->key, key, keylen); |
259 | return 0; | 252 | return 0; |
260 | } | 253 | } |
@@ -264,7 +257,7 @@ static void des3_192_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) | |||
264 | struct crypt_s390_des3_192_ctx *dctx = crypto_tfm_ctx(tfm); | 257 | struct crypt_s390_des3_192_ctx *dctx = crypto_tfm_ctx(tfm); |
265 | 258 | ||
266 | crypt_s390_km(KM_TDEA_192_ENCRYPT, dctx->key, dst, (void*)src, | 259 | crypt_s390_km(KM_TDEA_192_ENCRYPT, dctx->key, dst, (void*)src, |
267 | DES3_192_BLOCK_SIZE); | 260 | DES_BLOCK_SIZE); |
268 | } | 261 | } |
269 | 262 | ||
270 | static void des3_192_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) | 263 | static void des3_192_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) |
@@ -272,7 +265,7 @@ static void des3_192_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) | |||
272 | struct crypt_s390_des3_192_ctx *dctx = crypto_tfm_ctx(tfm); | 265 | struct crypt_s390_des3_192_ctx *dctx = crypto_tfm_ctx(tfm); |
273 | 266 | ||
274 | crypt_s390_km(KM_TDEA_192_DECRYPT, dctx->key, dst, (void*)src, | 267 | crypt_s390_km(KM_TDEA_192_DECRYPT, dctx->key, dst, (void*)src, |
275 | DES3_192_BLOCK_SIZE); | 268 | DES_BLOCK_SIZE); |
276 | } | 269 | } |
277 | 270 | ||
278 | static struct crypto_alg des3_192_alg = { | 271 | static struct crypto_alg des3_192_alg = { |
@@ -280,7 +273,7 @@ static struct crypto_alg des3_192_alg = { | |||
280 | .cra_driver_name = "des3_ede-s390", | 273 | .cra_driver_name = "des3_ede-s390", |
281 | .cra_priority = CRYPT_S390_PRIORITY, | 274 | .cra_priority = CRYPT_S390_PRIORITY, |
282 | .cra_flags = CRYPTO_ALG_TYPE_CIPHER, | 275 | .cra_flags = CRYPTO_ALG_TYPE_CIPHER, |
283 | .cra_blocksize = DES3_192_BLOCK_SIZE, | 276 | .cra_blocksize = DES_BLOCK_SIZE, |
284 | .cra_ctxsize = sizeof(struct crypt_s390_des3_192_ctx), | 277 | .cra_ctxsize = sizeof(struct crypt_s390_des3_192_ctx), |
285 | .cra_module = THIS_MODULE, | 278 | .cra_module = THIS_MODULE, |
286 | .cra_list = LIST_HEAD_INIT(des3_192_alg.cra_list), | 279 | .cra_list = LIST_HEAD_INIT(des3_192_alg.cra_list), |
@@ -322,7 +315,7 @@ static struct crypto_alg ecb_des3_192_alg = { | |||
322 | .cra_driver_name = "ecb-des3_ede-s390", | 315 | .cra_driver_name = "ecb-des3_ede-s390", |
323 | .cra_priority = CRYPT_S390_COMPOSITE_PRIORITY, | 316 | .cra_priority = CRYPT_S390_COMPOSITE_PRIORITY, |
324 | .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER, | 317 | .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER, |
325 | .cra_blocksize = DES3_192_BLOCK_SIZE, | 318 | .cra_blocksize = DES_BLOCK_SIZE, |
326 | .cra_ctxsize = sizeof(struct crypt_s390_des3_192_ctx), | 319 | .cra_ctxsize = sizeof(struct crypt_s390_des3_192_ctx), |
327 | .cra_type = &crypto_blkcipher_type, | 320 | .cra_type = &crypto_blkcipher_type, |
328 | .cra_module = THIS_MODULE, | 321 | .cra_module = THIS_MODULE, |
@@ -366,7 +359,7 @@ static struct crypto_alg cbc_des3_192_alg = { | |||
366 | .cra_driver_name = "cbc-des3_ede-s390", | 359 | .cra_driver_name = "cbc-des3_ede-s390", |
367 | .cra_priority = CRYPT_S390_COMPOSITE_PRIORITY, | 360 | .cra_priority = CRYPT_S390_COMPOSITE_PRIORITY, |
368 | .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER, | 361 | .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER, |
369 | .cra_blocksize = DES3_192_BLOCK_SIZE, | 362 | .cra_blocksize = DES_BLOCK_SIZE, |
370 | .cra_ctxsize = sizeof(struct crypt_s390_des3_192_ctx), | 363 | .cra_ctxsize = sizeof(struct crypt_s390_des3_192_ctx), |
371 | .cra_type = &crypto_blkcipher_type, | 364 | .cra_type = &crypto_blkcipher_type, |
372 | .cra_module = THIS_MODULE, | 365 | .cra_module = THIS_MODULE, |
@@ -376,7 +369,7 @@ static struct crypto_alg cbc_des3_192_alg = { | |||
376 | .blkcipher = { | 369 | .blkcipher = { |
377 | .min_keysize = DES3_192_KEY_SIZE, | 370 | .min_keysize = DES3_192_KEY_SIZE, |
378 | .max_keysize = DES3_192_KEY_SIZE, | 371 | .max_keysize = DES3_192_KEY_SIZE, |
379 | .ivsize = DES3_192_BLOCK_SIZE, | 372 | .ivsize = DES_BLOCK_SIZE, |
380 | .setkey = des3_192_setkey, | 373 | .setkey = des3_192_setkey, |
381 | .encrypt = cbc_des3_192_encrypt, | 374 | .encrypt = cbc_des3_192_encrypt, |
382 | .decrypt = cbc_des3_192_decrypt, | 375 | .decrypt = cbc_des3_192_decrypt, |
@@ -427,7 +420,7 @@ des_err: | |||
427 | goto out; | 420 | goto out; |
428 | } | 421 | } |
429 | 422 | ||
430 | static void __exit des_s390_fini(void) | 423 | static void __exit des_s390_exit(void) |
431 | { | 424 | { |
432 | crypto_unregister_alg(&cbc_des3_192_alg); | 425 | crypto_unregister_alg(&cbc_des3_192_alg); |
433 | crypto_unregister_alg(&ecb_des3_192_alg); | 426 | crypto_unregister_alg(&ecb_des3_192_alg); |
@@ -438,7 +431,7 @@ static void __exit des_s390_fini(void) | |||
438 | } | 431 | } |
439 | 432 | ||
440 | module_init(des_s390_init); | 433 | module_init(des_s390_init); |
441 | module_exit(des_s390_fini); | 434 | module_exit(des_s390_exit); |
442 | 435 | ||
443 | MODULE_ALIAS("des"); | 436 | MODULE_ALIAS("des"); |
444 | MODULE_ALIAS("des3_ede"); | 437 | MODULE_ALIAS("des3_ede"); |