@@ -801,19 +801,16 @@ static int atmel_tdes_setkey(struct crypto_ablkcipher *tfm, const u8 *key,
801801{
802802 struct atmel_tdes_ctx * ctx = crypto_ablkcipher_ctx (tfm );
803803 const char * alg_name ;
804+ u32 flags ;
805+ int err ;
804806
805807 alg_name = crypto_tfm_alg_name (crypto_ablkcipher_tfm (tfm ));
806808
807- /*
808- * HW bug in cfb 3-keys mode.
809- */
810- if (!ctx -> dd -> caps .has_cfb_3keys && strstr (alg_name , "cfb" )
811- && (keylen != 2 * DES_KEY_SIZE )) {
812- crypto_ablkcipher_set_flags (tfm , CRYPTO_TFM_RES_BAD_KEY_LEN );
813- return - EINVAL ;
814- } else if ((keylen != 2 * DES_KEY_SIZE ) && (keylen != 3 * DES_KEY_SIZE )) {
815- crypto_ablkcipher_set_flags (tfm , CRYPTO_TFM_RES_BAD_KEY_LEN );
816- return - EINVAL ;
809+ flags = crypto_ablkcipher_get_flags (tfm );
810+ err = __des3_verify_key (& flags , key );
811+ if (unlikely (err )) {
812+ crypto_ablkcipher_set_flags (tfm , flags );
813+ return err ;
817814 }
818815
819816 memcpy (ctx -> key , key , keylen );
@@ -1060,7 +1057,7 @@ static struct crypto_alg tdes_algs[] = {
10601057 .cra_module = THIS_MODULE ,
10611058 .cra_init = atmel_tdes_cra_init ,
10621059 .cra_u .ablkcipher = {
1063- .min_keysize = 2 * DES_KEY_SIZE ,
1060+ .min_keysize = 3 * DES_KEY_SIZE ,
10641061 .max_keysize = 3 * DES_KEY_SIZE ,
10651062 .setkey = atmel_tdes_setkey ,
10661063 .encrypt = atmel_tdes_ecb_encrypt ,
@@ -1079,94 +1076,14 @@ static struct crypto_alg tdes_algs[] = {
10791076 .cra_module = THIS_MODULE ,
10801077 .cra_init = atmel_tdes_cra_init ,
10811078 .cra_u .ablkcipher = {
1082- .min_keysize = 2 * DES_KEY_SIZE ,
1079+ .min_keysize = 3 * DES_KEY_SIZE ,
10831080 .max_keysize = 3 * DES_KEY_SIZE ,
10841081 .ivsize = DES_BLOCK_SIZE ,
10851082 .setkey = atmel_tdes_setkey ,
10861083 .encrypt = atmel_tdes_cbc_encrypt ,
10871084 .decrypt = atmel_tdes_cbc_decrypt ,
10881085 }
10891086},
1090- {
1091- .cra_name = "cfb(des3_ede)" ,
1092- .cra_driver_name = "atmel-cfb-tdes" ,
1093- .cra_priority = 100 ,
1094- .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC ,
1095- .cra_blocksize = DES_BLOCK_SIZE ,
1096- .cra_ctxsize = sizeof (struct atmel_tdes_ctx ),
1097- .cra_alignmask = 0x7 ,
1098- .cra_type = & crypto_ablkcipher_type ,
1099- .cra_module = THIS_MODULE ,
1100- .cra_init = atmel_tdes_cra_init ,
1101- .cra_u .ablkcipher = {
1102- .min_keysize = 2 * DES_KEY_SIZE ,
1103- .max_keysize = 2 * DES_KEY_SIZE ,
1104- .ivsize = DES_BLOCK_SIZE ,
1105- .setkey = atmel_tdes_setkey ,
1106- .encrypt = atmel_tdes_cfb_encrypt ,
1107- .decrypt = atmel_tdes_cfb_decrypt ,
1108- }
1109- },
1110- {
1111- .cra_name = "cfb8(des3_ede)" ,
1112- .cra_driver_name = "atmel-cfb8-tdes" ,
1113- .cra_priority = 100 ,
1114- .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC ,
1115- .cra_blocksize = CFB8_BLOCK_SIZE ,
1116- .cra_ctxsize = sizeof (struct atmel_tdes_ctx ),
1117- .cra_alignmask = 0 ,
1118- .cra_type = & crypto_ablkcipher_type ,
1119- .cra_module = THIS_MODULE ,
1120- .cra_init = atmel_tdes_cra_init ,
1121- .cra_u .ablkcipher = {
1122- .min_keysize = 2 * DES_KEY_SIZE ,
1123- .max_keysize = 2 * DES_KEY_SIZE ,
1124- .ivsize = DES_BLOCK_SIZE ,
1125- .setkey = atmel_tdes_setkey ,
1126- .encrypt = atmel_tdes_cfb8_encrypt ,
1127- .decrypt = atmel_tdes_cfb8_decrypt ,
1128- }
1129- },
1130- {
1131- .cra_name = "cfb16(des3_ede)" ,
1132- .cra_driver_name = "atmel-cfb16-tdes" ,
1133- .cra_priority = 100 ,
1134- .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC ,
1135- .cra_blocksize = CFB16_BLOCK_SIZE ,
1136- .cra_ctxsize = sizeof (struct atmel_tdes_ctx ),
1137- .cra_alignmask = 0x1 ,
1138- .cra_type = & crypto_ablkcipher_type ,
1139- .cra_module = THIS_MODULE ,
1140- .cra_init = atmel_tdes_cra_init ,
1141- .cra_u .ablkcipher = {
1142- .min_keysize = 2 * DES_KEY_SIZE ,
1143- .max_keysize = 2 * DES_KEY_SIZE ,
1144- .ivsize = DES_BLOCK_SIZE ,
1145- .setkey = atmel_tdes_setkey ,
1146- .encrypt = atmel_tdes_cfb16_encrypt ,
1147- .decrypt = atmel_tdes_cfb16_decrypt ,
1148- }
1149- },
1150- {
1151- .cra_name = "cfb32(des3_ede)" ,
1152- .cra_driver_name = "atmel-cfb32-tdes" ,
1153- .cra_priority = 100 ,
1154- .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC ,
1155- .cra_blocksize = CFB32_BLOCK_SIZE ,
1156- .cra_ctxsize = sizeof (struct atmel_tdes_ctx ),
1157- .cra_alignmask = 0x3 ,
1158- .cra_type = & crypto_ablkcipher_type ,
1159- .cra_module = THIS_MODULE ,
1160- .cra_init = atmel_tdes_cra_init ,
1161- .cra_u .ablkcipher = {
1162- .min_keysize = 2 * DES_KEY_SIZE ,
1163- .max_keysize = 2 * DES_KEY_SIZE ,
1164- .ivsize = DES_BLOCK_SIZE ,
1165- .setkey = atmel_tdes_setkey ,
1166- .encrypt = atmel_tdes_cfb32_encrypt ,
1167- .decrypt = atmel_tdes_cfb32_decrypt ,
1168- }
1169- },
11701087{
11711088 .cra_name = "ofb(des3_ede)" ,
11721089 .cra_driver_name = "atmel-ofb-tdes" ,
@@ -1179,7 +1096,7 @@ static struct crypto_alg tdes_algs[] = {
11791096 .cra_module = THIS_MODULE ,
11801097 .cra_init = atmel_tdes_cra_init ,
11811098 .cra_u .ablkcipher = {
1182- .min_keysize = 2 * DES_KEY_SIZE ,
1099+ .min_keysize = 3 * DES_KEY_SIZE ,
11831100 .max_keysize = 3 * DES_KEY_SIZE ,
11841101 .ivsize = DES_BLOCK_SIZE ,
11851102 .setkey = atmel_tdes_setkey ,
0 commit comments