77#include <linux/interrupt.h>
88#include <linux/types.h>
99#include <crypto/aes.h>
10- #include <crypto/des.h>
10+ #include <crypto/internal/ des.h>
1111#include <crypto/internal/skcipher.h>
1212
1313#include "cipher.h"
@@ -154,27 +154,17 @@ static int qce_ablkcipher_setkey(struct crypto_ablkcipher *ablk, const u8 *key,
154154{
155155 struct crypto_tfm * tfm = crypto_ablkcipher_tfm (ablk );
156156 struct qce_cipher_ctx * ctx = crypto_tfm_ctx (tfm );
157- unsigned long flags = to_cipher_tmpl (tfm )-> alg_flags ;
158157 int ret ;
159158
160159 if (!key || !keylen )
161160 return - EINVAL ;
162161
163- if (IS_AES (flags )) {
164- switch (keylen ) {
165- case AES_KEYSIZE_128 :
166- case AES_KEYSIZE_256 :
167- break ;
168- default :
169- goto fallback ;
170- }
171- } else if (IS_DES (flags )) {
172- u32 tmp [DES_EXPKEY_WORDS ];
173-
174- ret = des_ekey (tmp , key );
175- if (!ret && (crypto_ablkcipher_get_flags (ablk ) &
176- CRYPTO_TFM_REQ_FORBID_WEAK_KEYS ))
177- goto weakkey ;
162+ switch (keylen ) {
163+ case AES_KEYSIZE_128 :
164+ case AES_KEYSIZE_256 :
165+ break ;
166+ default :
167+ goto fallback ;
178168 }
179169
180170 ctx -> enc_keylen = keylen ;
@@ -185,24 +175,32 @@ static int qce_ablkcipher_setkey(struct crypto_ablkcipher *ablk, const u8 *key,
185175 if (!ret )
186176 ctx -> enc_keylen = keylen ;
187177 return ret ;
188- weakkey :
189- crypto_ablkcipher_set_flags (ablk , CRYPTO_TFM_RES_WEAK_KEY );
190- return - EINVAL ;
178+ }
179+
180+ static int qce_des_setkey (struct crypto_ablkcipher * ablk , const u8 * key ,
181+ unsigned int keylen )
182+ {
183+ struct qce_cipher_ctx * ctx = crypto_ablkcipher_ctx (ablk );
184+ int err ;
185+
186+ err = verify_ablkcipher_des_key (ablk , key );
187+ if (err )
188+ return err ;
189+
190+ ctx -> enc_keylen = keylen ;
191+ memcpy (ctx -> enc_key , key , keylen );
192+ return 0 ;
191193}
192194
193195static int qce_des3_setkey (struct crypto_ablkcipher * ablk , const u8 * key ,
194196 unsigned int keylen )
195197{
196198 struct qce_cipher_ctx * ctx = crypto_ablkcipher_ctx (ablk );
197- u32 flags ;
198199 int err ;
199200
200- flags = crypto_ablkcipher_get_flags (ablk );
201- err = __des3_verify_key (& flags , key );
202- if (unlikely (err )) {
203- crypto_ablkcipher_set_flags (ablk , flags );
201+ err = verify_ablkcipher_des3_key (ablk , key );
202+ if (err )
204203 return err ;
205- }
206204
207205 ctx -> enc_keylen = keylen ;
208206 memcpy (ctx -> enc_key , key , keylen );
@@ -374,8 +372,9 @@ static int qce_ablkcipher_register_one(const struct qce_ablkcipher_def *def,
374372 alg -> cra_ablkcipher .ivsize = def -> ivsize ;
375373 alg -> cra_ablkcipher .min_keysize = def -> min_keysize ;
376374 alg -> cra_ablkcipher .max_keysize = def -> max_keysize ;
377- alg -> cra_ablkcipher .setkey = IS_3DES (def -> flags ) ?
378- qce_des3_setkey : qce_ablkcipher_setkey ;
375+ alg -> cra_ablkcipher .setkey = IS_3DES (def -> flags ) ? qce_des3_setkey :
376+ IS_DES (def -> flags ) ? qce_des_setkey :
377+ qce_ablkcipher_setkey ;
379378 alg -> cra_ablkcipher .encrypt = qce_ablkcipher_encrypt ;
380379 alg -> cra_ablkcipher .decrypt = qce_ablkcipher_decrypt ;
381380
0 commit comments