Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

crypto: x86/des - switch to library interface

Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Ard Biesheuvel and committed by
Herbert Xu
cc1d24b9 04007b0e

+23 -19
+23 -19
arch/x86/crypto/des3_ede_glue.c
··· 11 11 */ 12 12 13 13 #include <crypto/algapi.h> 14 - #include <crypto/internal/des.h> 14 + #include <crypto/des.h> 15 15 #include <crypto/internal/skcipher.h> 16 16 #include <linux/crypto.h> 17 17 #include <linux/init.h> ··· 19 19 #include <linux/types.h> 20 20 21 21 struct des3_ede_x86_ctx { 22 - u32 enc_expkey[DES3_EDE_EXPKEY_WORDS]; 23 - u32 dec_expkey[DES3_EDE_EXPKEY_WORDS]; 22 + struct des3_ede_ctx enc; 23 + struct des3_ede_ctx dec; 24 24 }; 25 25 26 26 /* regular block cipher functions */ ··· 34 34 static inline void des3_ede_enc_blk(struct des3_ede_x86_ctx *ctx, u8 *dst, 35 35 const u8 *src) 36 36 { 37 - u32 *enc_ctx = ctx->enc_expkey; 37 + u32 *enc_ctx = ctx->enc.expkey; 38 38 39 39 des3_ede_x86_64_crypt_blk(enc_ctx, dst, src); 40 40 } ··· 42 42 static inline void des3_ede_dec_blk(struct des3_ede_x86_ctx *ctx, u8 *dst, 43 43 const u8 *src) 44 44 { 45 - u32 *dec_ctx = ctx->dec_expkey; 45 + u32 *dec_ctx = ctx->dec.expkey; 46 46 47 47 des3_ede_x86_64_crypt_blk(dec_ctx, dst, src); 48 48 } ··· 50 50 static inline void des3_ede_enc_blk_3way(struct des3_ede_x86_ctx *ctx, u8 *dst, 51 51 const u8 *src) 52 52 { 53 - u32 *enc_ctx = ctx->enc_expkey; 53 + u32 *enc_ctx = ctx->enc.expkey; 54 54 55 55 des3_ede_x86_64_crypt_blk_3way(enc_ctx, dst, src); 56 56 } ··· 58 58 static inline void des3_ede_dec_blk_3way(struct des3_ede_x86_ctx *ctx, u8 *dst, 59 59 const u8 *src) 60 60 { 61 - u32 *dec_ctx = ctx->dec_expkey; 61 + u32 *dec_ctx = ctx->dec.expkey; 62 62 63 63 des3_ede_x86_64_crypt_blk_3way(dec_ctx, dst, src); 64 64 } ··· 122 122 struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); 123 123 struct des3_ede_x86_ctx *ctx = crypto_skcipher_ctx(tfm); 124 124 125 - return ecb_crypt(req, ctx->enc_expkey); 125 + return ecb_crypt(req, ctx->enc.expkey); 126 126 } 127 127 128 128 static int ecb_decrypt(struct skcipher_request *req) ··· 130 130 struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); 131 131 struct des3_ede_x86_ctx *ctx = crypto_skcipher_ctx(tfm); 132 132 133 - return ecb_crypt(req, ctx->dec_expkey); 133 + return ecb_crypt(req, ctx->dec.expkey); 134 134 } 135 135 136 136 static unsigned int __cbc_encrypt(struct des3_ede_x86_ctx *ctx, ··· 348 348 u32 i, j, tmp; 349 349 int err; 350 350 351 - err = crypto_des3_ede_verify_key(tfm, key); 352 - if (err) 353 - return err; 351 + err = des3_ede_expand_key(&ctx->enc, key, keylen); 352 + if (err == -ENOKEY) { 353 + if (crypto_tfm_get_flags(tfm) & CRYPTO_TFM_REQ_FORBID_WEAK_KEYS) 354 + err = -EINVAL; 355 + else 356 + err = 0; 357 + } 354 358 355 - /* Generate encryption context using generic implementation. */ 356 - err = __des3_ede_setkey(ctx->enc_expkey, &tfm->crt_flags, key, keylen); 357 - if (err < 0) 359 + if (err) { 360 + memset(ctx, 0, sizeof(*ctx)); 358 361 return err; 362 + } 359 363 360 364 /* Fix encryption context for this implementation and form decryption 361 365 * context. */ 362 366 j = DES3_EDE_EXPKEY_WORDS - 2; 363 367 for (i = 0; i < DES3_EDE_EXPKEY_WORDS; i += 2, j -= 2) { 364 - tmp = ror32(ctx->enc_expkey[i + 1], 4); 365 - ctx->enc_expkey[i + 1] = tmp; 368 + tmp = ror32(ctx->enc.expkey[i + 1], 4); 369 + ctx->enc.expkey[i + 1] = tmp; 366 370 367 - ctx->dec_expkey[j + 0] = ctx->enc_expkey[i + 0]; 368 - ctx->dec_expkey[j + 1] = tmp; 371 + ctx->dec.expkey[j + 0] = ctx->enc.expkey[i + 0]; 372 + ctx->dec.expkey[j + 1] = tmp; 369 373 } 370 374 371 375 return 0;