1414 *
1515 */
1616
17- #include <crypto/algapi.h>
1817#include <linux/init.h>
1918#include <linux/module.h>
19+ #include <linux/crypto.h>
20+ #include <crypto/algapi.h>
21+ #include <crypto/des.h>
2022
2123#include "crypt_s390.h"
22- #include "crypto_des.h"
23-
24- #define DES_BLOCK_SIZE 8
25- #define DES_KEY_SIZE 8
2624
2725#define DES3_192_KEY_SIZE (3 * DES_KEY_SIZE)
28- #define DES3_192_BLOCK_SIZE DES_BLOCK_SIZE
2926
3027struct crypt_s390_des_ctx {
3128 u8 iv [DES_BLOCK_SIZE ];
@@ -42,13 +39,16 @@ static int des_setkey(struct crypto_tfm *tfm, const u8 *key,
4239{
4340 struct crypt_s390_des_ctx * dctx = crypto_tfm_ctx (tfm );
4441 u32 * flags = & tfm -> crt_flags ;
45- int ret ;
42+ u32 tmp [ DES_EXPKEY_WORDS ] ;
4643
47- /* test if key is valid (not a weak key) */
48- ret = crypto_des_check_key (key , keylen , flags );
49- if (ret == 0 )
50- memcpy (dctx -> key , key , keylen );
51- return ret ;
44+ /* check for weak keys */
45+ if (!des_ekey (tmp , key ) && (* flags & CRYPTO_TFM_REQ_WEAK_KEY )) {
46+ * flags |= CRYPTO_TFM_RES_WEAK_KEY ;
47+ return - EINVAL ;
48+ }
49+
50+ memcpy (dctx -> key , key , keylen );
51+ return 0 ;
5252}
5353
5454static void des_encrypt (struct crypto_tfm * tfm , u8 * out , const u8 * in )
@@ -238,9 +238,7 @@ static struct crypto_alg cbc_des_alg = {
238238static int des3_192_setkey (struct crypto_tfm * tfm , const u8 * key ,
239239 unsigned int keylen )
240240{
241- int i , ret ;
242241 struct crypt_s390_des3_192_ctx * dctx = crypto_tfm_ctx (tfm );
243- const u8 * temp_key = key ;
244242 u32 * flags = & tfm -> crt_flags ;
245243
246244 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,
250248 * flags |= CRYPTO_TFM_RES_WEAK_KEY ;
251249 return - EINVAL ;
252250 }
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- }
258251 memcpy (dctx -> key , key , keylen );
259252 return 0 ;
260253}
@@ -264,23 +257,23 @@ static void des3_192_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
264257 struct crypt_s390_des3_192_ctx * dctx = crypto_tfm_ctx (tfm );
265258
266259 crypt_s390_km (KM_TDEA_192_ENCRYPT , dctx -> key , dst , (void * )src ,
267- DES3_192_BLOCK_SIZE );
260+ DES_BLOCK_SIZE );
268261}
269262
270263static void des3_192_decrypt (struct crypto_tfm * tfm , u8 * dst , const u8 * src )
271264{
272265 struct crypt_s390_des3_192_ctx * dctx = crypto_tfm_ctx (tfm );
273266
274267 crypt_s390_km (KM_TDEA_192_DECRYPT , dctx -> key , dst , (void * )src ,
275- DES3_192_BLOCK_SIZE );
268+ DES_BLOCK_SIZE );
276269}
277270
278271static struct crypto_alg des3_192_alg = {
279272 .cra_name = "des3_ede" ,
280273 .cra_driver_name = "des3_ede-s390" ,
281274 .cra_priority = CRYPT_S390_PRIORITY ,
282275 .cra_flags = CRYPTO_ALG_TYPE_CIPHER ,
283- .cra_blocksize = DES3_192_BLOCK_SIZE ,
276+ .cra_blocksize = DES_BLOCK_SIZE ,
284277 .cra_ctxsize = sizeof (struct crypt_s390_des3_192_ctx ),
285278 .cra_module = THIS_MODULE ,
286279 .cra_list = LIST_HEAD_INIT (des3_192_alg .cra_list ),
@@ -322,7 +315,7 @@ static struct crypto_alg ecb_des3_192_alg = {
322315 .cra_driver_name = "ecb-des3_ede-s390" ,
323316 .cra_priority = CRYPT_S390_COMPOSITE_PRIORITY ,
324317 .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER ,
325- .cra_blocksize = DES3_192_BLOCK_SIZE ,
318+ .cra_blocksize = DES_BLOCK_SIZE ,
326319 .cra_ctxsize = sizeof (struct crypt_s390_des3_192_ctx ),
327320 .cra_type = & crypto_blkcipher_type ,
328321 .cra_module = THIS_MODULE ,
@@ -366,7 +359,7 @@ static struct crypto_alg cbc_des3_192_alg = {
366359 .cra_driver_name = "cbc-des3_ede-s390" ,
367360 .cra_priority = CRYPT_S390_COMPOSITE_PRIORITY ,
368361 .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER ,
369- .cra_blocksize = DES3_192_BLOCK_SIZE ,
362+ .cra_blocksize = DES_BLOCK_SIZE ,
370363 .cra_ctxsize = sizeof (struct crypt_s390_des3_192_ctx ),
371364 .cra_type = & crypto_blkcipher_type ,
372365 .cra_module = THIS_MODULE ,
@@ -376,7 +369,7 @@ static struct crypto_alg cbc_des3_192_alg = {
376369 .blkcipher = {
377370 .min_keysize = DES3_192_KEY_SIZE ,
378371 .max_keysize = DES3_192_KEY_SIZE ,
379- .ivsize = DES3_192_BLOCK_SIZE ,
372+ .ivsize = DES_BLOCK_SIZE ,
380373 .setkey = des3_192_setkey ,
381374 .encrypt = cbc_des3_192_encrypt ,
382375 .decrypt = cbc_des3_192_decrypt ,
@@ -427,7 +420,7 @@ static int des_s390_init(void)
427420 goto out ;
428421}
429422
430- static void __exit des_s390_fini (void )
423+ static void __exit des_s390_exit (void )
431424{
432425 crypto_unregister_alg (& cbc_des3_192_alg );
433426 crypto_unregister_alg (& ecb_des3_192_alg );
@@ -438,7 +431,7 @@ static void __exit des_s390_fini(void)
438431}
439432
440433module_init (des_s390_init );
441- module_exit (des_s390_fini );
434+ module_exit (des_s390_exit );
442435
443436MODULE_ALIAS ("des" );
444437MODULE_ALIAS ("des3_ede" );
0 commit comments