diff options
| author | Jan Glauber <jang@linux.vnet.ibm.com> | 2010-05-21 08:04:08 -0400 |
|---|---|---|
| committer | Herbert Xu <herbert@gondor.apana.org.au> | 2010-05-21 08:04:08 -0400 |
| commit | 80d663a42127b839e820ed934cead51cff6196d3 (patch) | |
| tree | 8c5d482d47366f7201863967438673d505005f33 /arch/s390/crypto | |
| parent | e954bc91bdd4bb08b8325478c5004b24a23a3522 (diff) | |
crypto: des_s390: remove des3_ede128 mode
des_s390 implements support for 3DES with a 128 bit key. This mode is probably
not used anywhere, less secure than 3DES with a 192 bit key and not
implemented in the generic des version. Removing this mode seems to be low risk
and will ease maintenance of the code.
Signed-off-by: Jan Glauber <jang@linux.vnet.ibm.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'arch/s390/crypto')
| -rw-r--r-- | arch/s390/crypto/des_s390.c | 191 |
1 files changed, 1 insertions, 190 deletions
diff --git a/arch/s390/crypto/des_s390.c b/arch/s390/crypto/des_s390.c index 2bc479ab3a66..a1a18b30309f 100644 --- a/arch/s390/crypto/des_s390.c +++ b/arch/s390/crypto/des_s390.c | |||
| @@ -24,9 +24,6 @@ | |||
| 24 | #define DES_BLOCK_SIZE 8 | 24 | #define DES_BLOCK_SIZE 8 |
| 25 | #define DES_KEY_SIZE 8 | 25 | #define DES_KEY_SIZE 8 |
| 26 | 26 | ||
| 27 | #define DES3_128_KEY_SIZE (2 * DES_KEY_SIZE) | ||
| 28 | #define DES3_128_BLOCK_SIZE DES_BLOCK_SIZE | ||
| 29 | |||
| 30 | #define DES3_192_KEY_SIZE (3 * DES_KEY_SIZE) | 27 | #define DES3_192_KEY_SIZE (3 * DES_KEY_SIZE) |
| 31 | #define DES3_192_BLOCK_SIZE DES_BLOCK_SIZE | 28 | #define DES3_192_BLOCK_SIZE DES_BLOCK_SIZE |
| 32 | 29 | ||
| @@ -35,11 +32,6 @@ struct crypt_s390_des_ctx { | |||
| 35 | u8 key[DES_KEY_SIZE]; | 32 | u8 key[DES_KEY_SIZE]; |
| 36 | }; | 33 | }; |
| 37 | 34 | ||
| 38 | struct crypt_s390_des3_128_ctx { | ||
| 39 | u8 iv[DES_BLOCK_SIZE]; | ||
| 40 | u8 key[DES3_128_KEY_SIZE]; | ||
| 41 | }; | ||
| 42 | |||
| 43 | struct crypt_s390_des3_192_ctx { | 35 | struct crypt_s390_des3_192_ctx { |
| 44 | u8 iv[DES_BLOCK_SIZE]; | 36 | u8 iv[DES_BLOCK_SIZE]; |
| 45 | u8 key[DES3_192_KEY_SIZE]; | 37 | u8 key[DES3_192_KEY_SIZE]; |
| @@ -237,165 +229,6 @@ static struct crypto_alg cbc_des_alg = { | |||
| 237 | * complementation keys. Any weakness is obviated by the use of | 229 | * complementation keys. Any weakness is obviated by the use of |
| 238 | * multiple keys. | 230 | * multiple keys. |
| 239 | * | 231 | * |
| 240 | * However, if the two independent 64-bit keys are equal, | ||
| 241 | * then the DES3 operation is simply the same as DES. | ||
| 242 | * Implementers MUST reject keys that exhibit this property. | ||
| 243 | * | ||
| 244 | */ | ||
| 245 | static int des3_128_setkey(struct crypto_tfm *tfm, const u8 *key, | ||
| 246 | unsigned int keylen) | ||
| 247 | { | ||
| 248 | int i, ret; | ||
| 249 | struct crypt_s390_des3_128_ctx *dctx = crypto_tfm_ctx(tfm); | ||
| 250 | const u8 *temp_key = key; | ||
| 251 | u32 *flags = &tfm->crt_flags; | ||
| 252 | |||
| 253 | if (!(memcmp(key, &key[DES_KEY_SIZE], DES_KEY_SIZE)) && | ||
| 254 | (*flags & CRYPTO_TFM_REQ_WEAK_KEY)) { | ||
| 255 | *flags |= CRYPTO_TFM_RES_WEAK_KEY; | ||
| 256 | return -EINVAL; | ||
| 257 | } | ||
| 258 | for (i = 0; i < 2; i++, temp_key += DES_KEY_SIZE) { | ||
| 259 | ret = crypto_des_check_key(temp_key, DES_KEY_SIZE, flags); | ||
| 260 | if (ret < 0) | ||
| 261 | return ret; | ||
| 262 | } | ||
| 263 | memcpy(dctx->key, key, keylen); | ||
| 264 | return 0; | ||
| 265 | } | ||
| 266 | |||
| 267 | static void des3_128_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) | ||
| 268 | { | ||
| 269 | struct crypt_s390_des3_128_ctx *dctx = crypto_tfm_ctx(tfm); | ||
| 270 | |||
| 271 | crypt_s390_km(KM_TDEA_128_ENCRYPT, dctx->key, dst, (void*)src, | ||
| 272 | DES3_128_BLOCK_SIZE); | ||
| 273 | } | ||
| 274 | |||
| 275 | static void des3_128_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) | ||
| 276 | { | ||
| 277 | struct crypt_s390_des3_128_ctx *dctx = crypto_tfm_ctx(tfm); | ||
| 278 | |||
| 279 | crypt_s390_km(KM_TDEA_128_DECRYPT, dctx->key, dst, (void*)src, | ||
| 280 | DES3_128_BLOCK_SIZE); | ||
| 281 | } | ||
| 282 | |||
| 283 | static struct crypto_alg des3_128_alg = { | ||
| 284 | .cra_name = "des3_ede128", | ||
| 285 | .cra_driver_name = "des3_ede128-s390", | ||
| 286 | .cra_priority = CRYPT_S390_PRIORITY, | ||
| 287 | .cra_flags = CRYPTO_ALG_TYPE_CIPHER, | ||
| 288 | .cra_blocksize = DES3_128_BLOCK_SIZE, | ||
| 289 | .cra_ctxsize = sizeof(struct crypt_s390_des3_128_ctx), | ||
| 290 | .cra_module = THIS_MODULE, | ||
| 291 | .cra_list = LIST_HEAD_INIT(des3_128_alg.cra_list), | ||
| 292 | .cra_u = { | ||
| 293 | .cipher = { | ||
| 294 | .cia_min_keysize = DES3_128_KEY_SIZE, | ||
| 295 | .cia_max_keysize = DES3_128_KEY_SIZE, | ||
| 296 | .cia_setkey = des3_128_setkey, | ||
| 297 | .cia_encrypt = des3_128_encrypt, | ||
| 298 | .cia_decrypt = des3_128_decrypt, | ||
| 299 | } | ||
| 300 | } | ||
| 301 | }; | ||
| 302 | |||
| 303 | static int ecb_des3_128_encrypt(struct blkcipher_desc *desc, | ||
| 304 | struct scatterlist *dst, | ||
| 305 | struct scatterlist *src, unsigned int nbytes) | ||
| 306 | { | ||
| 307 | struct crypt_s390_des3_128_ctx *sctx = crypto_blkcipher_ctx(desc->tfm); | ||
| 308 | struct blkcipher_walk walk; | ||
| 309 | |||
| 310 | blkcipher_walk_init(&walk, dst, src, nbytes); | ||
| 311 | return ecb_desall_crypt(desc, KM_TDEA_128_ENCRYPT, sctx->key, &walk); | ||
| 312 | } | ||
| 313 | |||
| 314 | static int ecb_des3_128_decrypt(struct blkcipher_desc *desc, | ||
| 315 | struct scatterlist *dst, | ||
| 316 | struct scatterlist *src, unsigned int nbytes) | ||
| 317 | { | ||
| 318 | struct crypt_s390_des3_128_ctx *sctx = crypto_blkcipher_ctx(desc->tfm); | ||
| 319 | struct blkcipher_walk walk; | ||
| 320 | |||
| 321 | blkcipher_walk_init(&walk, dst, src, nbytes); | ||
| 322 | return ecb_desall_crypt(desc, KM_TDEA_128_DECRYPT, sctx->key, &walk); | ||
| 323 | } | ||
| 324 | |||
| 325 | static struct crypto_alg ecb_des3_128_alg = { | ||
| 326 | .cra_name = "ecb(des3_ede128)", | ||
| 327 | .cra_driver_name = "ecb-des3_ede128-s390", | ||
| 328 | .cra_priority = CRYPT_S390_COMPOSITE_PRIORITY, | ||
| 329 | .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER, | ||
| 330 | .cra_blocksize = DES3_128_BLOCK_SIZE, | ||
| 331 | .cra_ctxsize = sizeof(struct crypt_s390_des3_128_ctx), | ||
| 332 | .cra_type = &crypto_blkcipher_type, | ||
| 333 | .cra_module = THIS_MODULE, | ||
| 334 | .cra_list = LIST_HEAD_INIT( | ||
| 335 | ecb_des3_128_alg.cra_list), | ||
| 336 | .cra_u = { | ||
| 337 | .blkcipher = { | ||
| 338 | .min_keysize = DES3_128_KEY_SIZE, | ||
| 339 | .max_keysize = DES3_128_KEY_SIZE, | ||
| 340 | .setkey = des3_128_setkey, | ||
| 341 | .encrypt = ecb_des3_128_encrypt, | ||
| 342 | .decrypt = ecb_des3_128_decrypt, | ||
| 343 | } | ||
| 344 | } | ||
| 345 | }; | ||
| 346 | |||
| 347 | static int cbc_des3_128_encrypt(struct blkcipher_desc *desc, | ||
| 348 | struct scatterlist *dst, | ||
| 349 | struct scatterlist *src, unsigned int nbytes) | ||
| 350 | { | ||
| 351 | struct crypt_s390_des3_128_ctx *sctx = crypto_blkcipher_ctx(desc->tfm); | ||
| 352 | struct blkcipher_walk walk; | ||
| 353 | |||
| 354 | blkcipher_walk_init(&walk, dst, src, nbytes); | ||
| 355 | return cbc_desall_crypt(desc, KMC_TDEA_128_ENCRYPT, sctx->iv, &walk); | ||
| 356 | } | ||
| 357 | |||
| 358 | static int cbc_des3_128_decrypt(struct blkcipher_desc *desc, | ||
| 359 | struct scatterlist *dst, | ||
| 360 | struct scatterlist *src, unsigned int nbytes) | ||
| 361 | { | ||
| 362 | struct crypt_s390_des3_128_ctx *sctx = crypto_blkcipher_ctx(desc->tfm); | ||
| 363 | struct blkcipher_walk walk; | ||
| 364 | |||
| 365 | blkcipher_walk_init(&walk, dst, src, nbytes); | ||
| 366 | return cbc_desall_crypt(desc, KMC_TDEA_128_DECRYPT, sctx->iv, &walk); | ||
| 367 | } | ||
| 368 | |||
| 369 | static struct crypto_alg cbc_des3_128_alg = { | ||
| 370 | .cra_name = "cbc(des3_ede128)", | ||
| 371 | .cra_driver_name = "cbc-des3_ede128-s390", | ||
| 372 | .cra_priority = CRYPT_S390_COMPOSITE_PRIORITY, | ||
| 373 | .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER, | ||
| 374 | .cra_blocksize = DES3_128_BLOCK_SIZE, | ||
| 375 | .cra_ctxsize = sizeof(struct crypt_s390_des3_128_ctx), | ||
| 376 | .cra_type = &crypto_blkcipher_type, | ||
| 377 | .cra_module = THIS_MODULE, | ||
| 378 | .cra_list = LIST_HEAD_INIT( | ||
| 379 | cbc_des3_128_alg.cra_list), | ||
| 380 | .cra_u = { | ||
| 381 | .blkcipher = { | ||
| 382 | .min_keysize = DES3_128_KEY_SIZE, | ||
| 383 | .max_keysize = DES3_128_KEY_SIZE, | ||
| 384 | .ivsize = DES3_128_BLOCK_SIZE, | ||
| 385 | .setkey = des3_128_setkey, | ||
| 386 | .encrypt = cbc_des3_128_encrypt, | ||
| 387 | .decrypt = cbc_des3_128_decrypt, | ||
| 388 | } | ||
| 389 | } | ||
| 390 | }; | ||
| 391 | |||
| 392 | /* | ||
| 393 | * RFC2451: | ||
| 394 | * | ||
| 395 | * For DES-EDE3, there is no known need to reject weak or | ||
| 396 | * complementation keys. Any weakness is obviated by the use of | ||
| 397 | * multiple keys. | ||
| 398 | * | ||
| 399 | * However, if the first two or last two independent 64-bit keys are | 232 | * However, if the first two or last two independent 64-bit keys are |
| 400 | * equal (k1 == k2 or k2 == k3), then the DES3 operation is simply the | 233 | * equal (k1 == k2 or k2 == k3), then the DES3 operation is simply the |
| 401 | * same as DES. Implementers MUST reject keys that exhibit this | 234 | * same as DES. Implementers MUST reject keys that exhibit this |
| @@ -553,10 +386,9 @@ static struct crypto_alg cbc_des3_192_alg = { | |||
| 553 | 386 | ||
| 554 | static int des_s390_init(void) | 387 | static int des_s390_init(void) |
| 555 | { | 388 | { |
| 556 | int ret = 0; | 389 | int ret; |
| 557 | 390 | ||
| 558 | if (!crypt_s390_func_available(KM_DEA_ENCRYPT) || | 391 | if (!crypt_s390_func_available(KM_DEA_ENCRYPT) || |
| 559 | !crypt_s390_func_available(KM_TDEA_128_ENCRYPT) || | ||
| 560 | !crypt_s390_func_available(KM_TDEA_192_ENCRYPT)) | 392 | !crypt_s390_func_available(KM_TDEA_192_ENCRYPT)) |
| 561 | return -EOPNOTSUPP; | 393 | return -EOPNOTSUPP; |
| 562 | 394 | ||
| @@ -569,17 +401,6 @@ static int des_s390_init(void) | |||
| 569 | ret = crypto_register_alg(&cbc_des_alg); | 401 | ret = crypto_register_alg(&cbc_des_alg); |
| 570 | if (ret) | 402 | if (ret) |
| 571 | goto cbc_des_err; | 403 | goto cbc_des_err; |
| 572 | |||
| 573 | ret = crypto_register_alg(&des3_128_alg); | ||
| 574 | if (ret) | ||
| 575 | goto des3_128_err; | ||
| 576 | ret = crypto_register_alg(&ecb_des3_128_alg); | ||
| 577 | if (ret) | ||
| 578 | goto ecb_des3_128_err; | ||
| 579 | ret = crypto_register_alg(&cbc_des3_128_alg); | ||
| 580 | if (ret) | ||
| 581 | goto cbc_des3_128_err; | ||
| 582 | |||
| 583 | ret = crypto_register_alg(&des3_192_alg); | 404 | ret = crypto_register_alg(&des3_192_alg); |
| 584 | if (ret) | 405 | if (ret) |
| 585 | goto des3_192_err; | 406 | goto des3_192_err; |
| @@ -589,7 +410,6 @@ static int des_s390_init(void) | |||
| 589 | ret = crypto_register_alg(&cbc_des3_192_alg); | 410 | ret = crypto_register_alg(&cbc_des3_192_alg); |
| 590 | if (ret) | 411 | if (ret) |
| 591 | goto cbc_des3_192_err; | 412 | goto cbc_des3_192_err; |
| 592 | |||
| 593 | out: | 413 | out: |
| 594 | return ret; | 414 | return ret; |
| 595 | 415 | ||
| @@ -598,12 +418,6 @@ cbc_des3_192_err: | |||
| 598 | ecb_des3_192_err: | 418 | ecb_des3_192_err: |
| 599 | crypto_unregister_alg(&des3_192_alg); | 419 | crypto_unregister_alg(&des3_192_alg); |
| 600 | des3_192_err: | 420 | des3_192_err: |
| 601 | crypto_unregister_alg(&cbc_des3_128_alg); | ||
| 602 | cbc_des3_128_err: | ||
| 603 | crypto_unregister_alg(&ecb_des3_128_alg); | ||
| 604 | ecb_des3_128_err: | ||
| 605 | crypto_unregister_alg(&des3_128_alg); | ||
| 606 | des3_128_err: | ||
| 607 | crypto_unregister_alg(&cbc_des_alg); | 421 | crypto_unregister_alg(&cbc_des_alg); |
| 608 | cbc_des_err: | 422 | cbc_des_err: |
| 609 | crypto_unregister_alg(&ecb_des_alg); | 423 | crypto_unregister_alg(&ecb_des_alg); |
| @@ -618,9 +432,6 @@ static void __exit des_s390_fini(void) | |||
| 618 | crypto_unregister_alg(&cbc_des3_192_alg); | 432 | crypto_unregister_alg(&cbc_des3_192_alg); |
| 619 | crypto_unregister_alg(&ecb_des3_192_alg); | 433 | crypto_unregister_alg(&ecb_des3_192_alg); |
| 620 | crypto_unregister_alg(&des3_192_alg); | 434 | crypto_unregister_alg(&des3_192_alg); |
| 621 | crypto_unregister_alg(&cbc_des3_128_alg); | ||
| 622 | crypto_unregister_alg(&ecb_des3_128_alg); | ||
| 623 | crypto_unregister_alg(&des3_128_alg); | ||
| 624 | crypto_unregister_alg(&cbc_des_alg); | 435 | crypto_unregister_alg(&cbc_des_alg); |
| 625 | crypto_unregister_alg(&ecb_des_alg); | 436 | crypto_unregister_alg(&ecb_des_alg); |
| 626 | crypto_unregister_alg(&des_alg); | 437 | crypto_unregister_alg(&des_alg); |
