diff options
author | Ard Biesheuvel <ard.biesheuvel@linaro.org> | 2019-08-15 05:01:01 -0400 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2019-08-22 00:57:32 -0400 |
commit | f96c897c855cfbde74d92f5cd65dc1108799bd8a (patch) | |
tree | a7047a71e65eea03b52c34382bd0e6c24e51822b /drivers/crypto | |
parent | 0157fb268893cddeb79c3cb6fc05d13a132aa66c (diff) |
crypto: qce/des - switch to new verification routines
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'drivers/crypto')
-rw-r--r-- | drivers/crypto/qce/ablkcipher.c | 55 |
1 files changed, 27 insertions, 28 deletions
diff --git a/drivers/crypto/qce/ablkcipher.c b/drivers/crypto/qce/ablkcipher.c index a976210ba41c..7a98bf5cc967 100644 --- a/drivers/crypto/qce/ablkcipher.c +++ b/drivers/crypto/qce/ablkcipher.c | |||
@@ -7,7 +7,7 @@ | |||
7 | #include <linux/interrupt.h> | 7 | #include <linux/interrupt.h> |
8 | #include <linux/types.h> | 8 | #include <linux/types.h> |
9 | #include <crypto/aes.h> | 9 | #include <crypto/aes.h> |
10 | #include <crypto/des.h> | 10 | #include <crypto/internal/des.h> |
11 | #include <crypto/internal/skcipher.h> | 11 | #include <crypto/internal/skcipher.h> |
12 | 12 | ||
13 | #include "cipher.h" | 13 | #include "cipher.h" |
@@ -154,27 +154,17 @@ static int qce_ablkcipher_setkey(struct crypto_ablkcipher *ablk, const u8 *key, | |||
154 | { | 154 | { |
155 | struct crypto_tfm *tfm = crypto_ablkcipher_tfm(ablk); | 155 | struct crypto_tfm *tfm = crypto_ablkcipher_tfm(ablk); |
156 | struct qce_cipher_ctx *ctx = crypto_tfm_ctx(tfm); | 156 | struct qce_cipher_ctx *ctx = crypto_tfm_ctx(tfm); |
157 | unsigned long flags = to_cipher_tmpl(tfm)->alg_flags; | ||
158 | int ret; | 157 | int ret; |
159 | 158 | ||
160 | if (!key || !keylen) | 159 | if (!key || !keylen) |
161 | return -EINVAL; | 160 | return -EINVAL; |
162 | 161 | ||
163 | if (IS_AES(flags)) { | 162 | switch (keylen) { |
164 | switch (keylen) { | 163 | case AES_KEYSIZE_128: |
165 | case AES_KEYSIZE_128: | 164 | case AES_KEYSIZE_256: |
166 | case AES_KEYSIZE_256: | 165 | break; |
167 | break; | 166 | default: |
168 | default: | 167 | goto fallback; |
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; | ||
178 | } | 168 | } |
179 | 169 | ||
180 | ctx->enc_keylen = keylen; | 170 | ctx->enc_keylen = keylen; |
@@ -185,24 +175,32 @@ fallback: | |||
185 | if (!ret) | 175 | if (!ret) |
186 | ctx->enc_keylen = keylen; | 176 | ctx->enc_keylen = keylen; |
187 | return ret; | 177 | return ret; |
188 | weakkey: | 178 | } |
189 | crypto_ablkcipher_set_flags(ablk, CRYPTO_TFM_RES_WEAK_KEY); | 179 | |
190 | return -EINVAL; | 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; | ||
191 | } | 193 | } |
192 | 194 | ||
193 | static int qce_des3_setkey(struct crypto_ablkcipher *ablk, const u8 *key, | 195 | static int qce_des3_setkey(struct crypto_ablkcipher *ablk, const u8 *key, |
194 | unsigned int keylen) | 196 | unsigned int keylen) |
195 | { | 197 | { |
196 | struct qce_cipher_ctx *ctx = crypto_ablkcipher_ctx(ablk); | 198 | struct qce_cipher_ctx *ctx = crypto_ablkcipher_ctx(ablk); |
197 | u32 flags; | ||
198 | int err; | 199 | int err; |
199 | 200 | ||
200 | flags = crypto_ablkcipher_get_flags(ablk); | 201 | err = verify_ablkcipher_des3_key(ablk, key); |
201 | err = __des3_verify_key(&flags, key); | 202 | if (err) |
202 | if (unlikely(err)) { | ||
203 | crypto_ablkcipher_set_flags(ablk, flags); | ||
204 | return err; | 203 | return err; |
205 | } | ||
206 | 204 | ||
207 | ctx->enc_keylen = keylen; | 205 | ctx->enc_keylen = keylen; |
208 | memcpy(ctx->enc_key, key, keylen); | 206 | memcpy(ctx->enc_key, key, keylen); |
@@ -374,8 +372,9 @@ static int qce_ablkcipher_register_one(const struct qce_ablkcipher_def *def, | |||
374 | alg->cra_ablkcipher.ivsize = def->ivsize; | 372 | alg->cra_ablkcipher.ivsize = def->ivsize; |
375 | alg->cra_ablkcipher.min_keysize = def->min_keysize; | 373 | alg->cra_ablkcipher.min_keysize = def->min_keysize; |
376 | alg->cra_ablkcipher.max_keysize = def->max_keysize; | 374 | alg->cra_ablkcipher.max_keysize = def->max_keysize; |
377 | alg->cra_ablkcipher.setkey = IS_3DES(def->flags) ? | 375 | alg->cra_ablkcipher.setkey = IS_3DES(def->flags) ? qce_des3_setkey : |
378 | qce_des3_setkey : qce_ablkcipher_setkey; | 376 | IS_DES(def->flags) ? qce_des_setkey : |
377 | qce_ablkcipher_setkey; | ||
379 | alg->cra_ablkcipher.encrypt = qce_ablkcipher_encrypt; | 378 | alg->cra_ablkcipher.encrypt = qce_ablkcipher_encrypt; |
380 | alg->cra_ablkcipher.decrypt = qce_ablkcipher_decrypt; | 379 | alg->cra_ablkcipher.decrypt = qce_ablkcipher_decrypt; |
381 | 380 | ||