diff options
| -rw-r--r-- | arch/x86/crypto/twofish_avx_glue.c | 25 | ||||
| -rw-r--r-- | arch/x86/crypto/twofish_glue_3way.c | 109 | ||||
| -rw-r--r-- | arch/x86/include/asm/crypto/twofish.h | 8 | ||||
| -rw-r--r-- | crypto/Kconfig | 1 |
4 files changed, 25 insertions, 118 deletions
diff --git a/arch/x86/crypto/twofish_avx_glue.c b/arch/x86/crypto/twofish_avx_glue.c index 3358e23f9ffb..3750b2cd3019 100644 --- a/arch/x86/crypto/twofish_avx_glue.c +++ b/arch/x86/crypto/twofish_avx_glue.c | |||
| @@ -79,6 +79,31 @@ static void twofish_xts_dec(void *ctx, u128 *dst, const u128 *src, le128 *iv) | |||
| 79 | GLUE_FUNC_CAST(twofish_dec_blk)); | 79 | GLUE_FUNC_CAST(twofish_dec_blk)); |
| 80 | } | 80 | } |
| 81 | 81 | ||
| 82 | struct twofish_xts_ctx { | ||
| 83 | struct twofish_ctx tweak_ctx; | ||
| 84 | struct twofish_ctx crypt_ctx; | ||
| 85 | }; | ||
| 86 | |||
| 87 | static int xts_twofish_setkey(struct crypto_tfm *tfm, const u8 *key, | ||
| 88 | unsigned int keylen) | ||
| 89 | { | ||
| 90 | struct twofish_xts_ctx *ctx = crypto_tfm_ctx(tfm); | ||
| 91 | u32 *flags = &tfm->crt_flags; | ||
| 92 | int err; | ||
| 93 | |||
| 94 | err = xts_check_key(tfm, key, keylen); | ||
| 95 | if (err) | ||
| 96 | return err; | ||
| 97 | |||
| 98 | /* first half of xts-key is for crypt */ | ||
| 99 | err = __twofish_setkey(&ctx->crypt_ctx, key, keylen / 2, flags); | ||
| 100 | if (err) | ||
| 101 | return err; | ||
| 102 | |||
| 103 | /* second half of xts-key is for tweak */ | ||
| 104 | return __twofish_setkey(&ctx->tweak_ctx, key + keylen / 2, keylen / 2, | ||
| 105 | flags); | ||
| 106 | } | ||
| 82 | 107 | ||
| 83 | static const struct common_glue_ctx twofish_enc = { | 108 | static const struct common_glue_ctx twofish_enc = { |
| 84 | .num_funcs = 3, | 109 | .num_funcs = 3, |
diff --git a/arch/x86/crypto/twofish_glue_3way.c b/arch/x86/crypto/twofish_glue_3way.c index 2d6dc5d7f0aa..bdbd2f6ab9d7 100644 --- a/arch/x86/crypto/twofish_glue_3way.c +++ b/arch/x86/crypto/twofish_glue_3way.c | |||
| @@ -30,7 +30,6 @@ | |||
| 30 | #include <crypto/b128ops.h> | 30 | #include <crypto/b128ops.h> |
| 31 | #include <asm/crypto/twofish.h> | 31 | #include <asm/crypto/twofish.h> |
| 32 | #include <asm/crypto/glue_helper.h> | 32 | #include <asm/crypto/glue_helper.h> |
| 33 | #include <crypto/xts.h> | ||
| 34 | 33 | ||
| 35 | EXPORT_SYMBOL_GPL(__twofish_enc_blk_3way); | 34 | EXPORT_SYMBOL_GPL(__twofish_enc_blk_3way); |
| 36 | EXPORT_SYMBOL_GPL(twofish_dec_blk_3way); | 35 | EXPORT_SYMBOL_GPL(twofish_dec_blk_3way); |
| @@ -182,94 +181,6 @@ static int ctr_crypt(struct blkcipher_desc *desc, struct scatterlist *dst, | |||
| 182 | return glue_ctr_crypt_128bit(&twofish_ctr, desc, dst, src, nbytes); | 181 | return glue_ctr_crypt_128bit(&twofish_ctr, desc, dst, src, nbytes); |
| 183 | } | 182 | } |
| 184 | 183 | ||
| 185 | static void encrypt_callback(void *priv, u8 *srcdst, unsigned int nbytes) | ||
| 186 | { | ||
| 187 | const unsigned int bsize = TF_BLOCK_SIZE; | ||
| 188 | struct twofish_ctx *ctx = priv; | ||
| 189 | int i; | ||
| 190 | |||
| 191 | if (nbytes == 3 * bsize) { | ||
| 192 | twofish_enc_blk_3way(ctx, srcdst, srcdst); | ||
| 193 | return; | ||
| 194 | } | ||
| 195 | |||
| 196 | for (i = 0; i < nbytes / bsize; i++, srcdst += bsize) | ||
| 197 | twofish_enc_blk(ctx, srcdst, srcdst); | ||
| 198 | } | ||
| 199 | |||
| 200 | static void decrypt_callback(void *priv, u8 *srcdst, unsigned int nbytes) | ||
| 201 | { | ||
| 202 | const unsigned int bsize = TF_BLOCK_SIZE; | ||
| 203 | struct twofish_ctx *ctx = priv; | ||
| 204 | int i; | ||
| 205 | |||
| 206 | if (nbytes == 3 * bsize) { | ||
| 207 | twofish_dec_blk_3way(ctx, srcdst, srcdst); | ||
| 208 | return; | ||
| 209 | } | ||
| 210 | |||
| 211 | for (i = 0; i < nbytes / bsize; i++, srcdst += bsize) | ||
| 212 | twofish_dec_blk(ctx, srcdst, srcdst); | ||
| 213 | } | ||
| 214 | |||
| 215 | int xts_twofish_setkey(struct crypto_tfm *tfm, const u8 *key, | ||
| 216 | unsigned int keylen) | ||
| 217 | { | ||
| 218 | struct twofish_xts_ctx *ctx = crypto_tfm_ctx(tfm); | ||
| 219 | u32 *flags = &tfm->crt_flags; | ||
| 220 | int err; | ||
| 221 | |||
| 222 | err = xts_check_key(tfm, key, keylen); | ||
| 223 | if (err) | ||
| 224 | return err; | ||
| 225 | |||
| 226 | /* first half of xts-key is for crypt */ | ||
| 227 | err = __twofish_setkey(&ctx->crypt_ctx, key, keylen / 2, flags); | ||
| 228 | if (err) | ||
| 229 | return err; | ||
| 230 | |||
| 231 | /* second half of xts-key is for tweak */ | ||
| 232 | return __twofish_setkey(&ctx->tweak_ctx, key + keylen / 2, keylen / 2, | ||
| 233 | flags); | ||
| 234 | } | ||
| 235 | EXPORT_SYMBOL_GPL(xts_twofish_setkey); | ||
| 236 | |||
| 237 | static int xts_encrypt(struct blkcipher_desc *desc, struct scatterlist *dst, | ||
| 238 | struct scatterlist *src, unsigned int nbytes) | ||
| 239 | { | ||
| 240 | struct twofish_xts_ctx *ctx = crypto_blkcipher_ctx(desc->tfm); | ||
| 241 | le128 buf[3]; | ||
| 242 | struct xts_crypt_req req = { | ||
| 243 | .tbuf = buf, | ||
| 244 | .tbuflen = sizeof(buf), | ||
| 245 | |||
| 246 | .tweak_ctx = &ctx->tweak_ctx, | ||
| 247 | .tweak_fn = XTS_TWEAK_CAST(twofish_enc_blk), | ||
| 248 | .crypt_ctx = &ctx->crypt_ctx, | ||
| 249 | .crypt_fn = encrypt_callback, | ||
| 250 | }; | ||
| 251 | |||
| 252 | return xts_crypt(desc, dst, src, nbytes, &req); | ||
| 253 | } | ||
| 254 | |||
| 255 | static int xts_decrypt(struct blkcipher_desc *desc, struct scatterlist *dst, | ||
| 256 | struct scatterlist *src, unsigned int nbytes) | ||
| 257 | { | ||
| 258 | struct twofish_xts_ctx *ctx = crypto_blkcipher_ctx(desc->tfm); | ||
| 259 | le128 buf[3]; | ||
| 260 | struct xts_crypt_req req = { | ||
| 261 | .tbuf = buf, | ||
| 262 | .tbuflen = sizeof(buf), | ||
| 263 | |||
| 264 | .tweak_ctx = &ctx->tweak_ctx, | ||
| 265 | .tweak_fn = XTS_TWEAK_CAST(twofish_enc_blk), | ||
| 266 | .crypt_ctx = &ctx->crypt_ctx, | ||
| 267 | .crypt_fn = decrypt_callback, | ||
| 268 | }; | ||
| 269 | |||
| 270 | return xts_crypt(desc, dst, src, nbytes, &req); | ||
| 271 | } | ||
| 272 | |||
| 273 | static struct crypto_alg tf_algs[] = { { | 184 | static struct crypto_alg tf_algs[] = { { |
| 274 | .cra_name = "ecb(twofish)", | 185 | .cra_name = "ecb(twofish)", |
| 275 | .cra_driver_name = "ecb-twofish-3way", | 186 | .cra_driver_name = "ecb-twofish-3way", |
| @@ -329,26 +240,6 @@ static struct crypto_alg tf_algs[] = { { | |||
| 329 | .decrypt = ctr_crypt, | 240 | .decrypt = ctr_crypt, |
| 330 | }, | 241 | }, |
| 331 | }, | 242 | }, |
| 332 | }, { | ||
| 333 | .cra_name = "xts(twofish)", | ||
| 334 | .cra_driver_name = "xts-twofish-3way", | ||
| 335 | .cra_priority = 300, | ||
| 336 | .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER, | ||
| 337 | .cra_blocksize = TF_BLOCK_SIZE, | ||
| 338 | .cra_ctxsize = sizeof(struct twofish_xts_ctx), | ||
| 339 | .cra_alignmask = 0, | ||
| 340 | .cra_type = &crypto_blkcipher_type, | ||
| 341 | .cra_module = THIS_MODULE, | ||
| 342 | .cra_u = { | ||
| 343 | .blkcipher = { | ||
| 344 | .min_keysize = TF_MIN_KEY_SIZE * 2, | ||
| 345 | .max_keysize = TF_MAX_KEY_SIZE * 2, | ||
| 346 | .ivsize = TF_BLOCK_SIZE, | ||
| 347 | .setkey = xts_twofish_setkey, | ||
| 348 | .encrypt = xts_encrypt, | ||
| 349 | .decrypt = xts_decrypt, | ||
| 350 | }, | ||
| 351 | }, | ||
| 352 | } }; | 243 | } }; |
| 353 | 244 | ||
| 354 | static bool is_blacklisted_cpu(void) | 245 | static bool is_blacklisted_cpu(void) |
diff --git a/arch/x86/include/asm/crypto/twofish.h b/arch/x86/include/asm/crypto/twofish.h index 3c904116ee00..f618bf272b90 100644 --- a/arch/x86/include/asm/crypto/twofish.h +++ b/arch/x86/include/asm/crypto/twofish.h | |||
| @@ -6,11 +6,6 @@ | |||
| 6 | #include <crypto/twofish.h> | 6 | #include <crypto/twofish.h> |
| 7 | #include <crypto/b128ops.h> | 7 | #include <crypto/b128ops.h> |
| 8 | 8 | ||
| 9 | struct twofish_xts_ctx { | ||
| 10 | struct twofish_ctx tweak_ctx; | ||
| 11 | struct twofish_ctx crypt_ctx; | ||
| 12 | }; | ||
| 13 | |||
| 14 | /* regular block cipher functions from twofish_x86_64 module */ | 9 | /* regular block cipher functions from twofish_x86_64 module */ |
| 15 | asmlinkage void twofish_enc_blk(struct twofish_ctx *ctx, u8 *dst, | 10 | asmlinkage void twofish_enc_blk(struct twofish_ctx *ctx, u8 *dst, |
| 16 | const u8 *src); | 11 | const u8 *src); |
| @@ -30,7 +25,4 @@ extern void twofish_enc_blk_ctr(void *ctx, u128 *dst, const u128 *src, | |||
| 30 | extern void twofish_enc_blk_ctr_3way(void *ctx, u128 *dst, const u128 *src, | 25 | extern void twofish_enc_blk_ctr_3way(void *ctx, u128 *dst, const u128 *src, |
| 31 | le128 *iv); | 26 | le128 *iv); |
| 32 | 27 | ||
| 33 | extern int xts_twofish_setkey(struct crypto_tfm *tfm, const u8 *key, | ||
| 34 | unsigned int keylen); | ||
| 35 | |||
| 36 | #endif /* ASM_X86_TWOFISH_H */ | 28 | #endif /* ASM_X86_TWOFISH_H */ |
diff --git a/crypto/Kconfig b/crypto/Kconfig index eba78fa85147..6a18aa26bbc7 100644 --- a/crypto/Kconfig +++ b/crypto/Kconfig | |||
| @@ -1584,7 +1584,6 @@ config CRYPTO_TWOFISH_X86_64_3WAY | |||
| 1584 | select CRYPTO_TWOFISH_COMMON | 1584 | select CRYPTO_TWOFISH_COMMON |
| 1585 | select CRYPTO_TWOFISH_X86_64 | 1585 | select CRYPTO_TWOFISH_X86_64 |
| 1586 | select CRYPTO_GLUE_HELPER_X86 | 1586 | select CRYPTO_GLUE_HELPER_X86 |
| 1587 | select CRYPTO_XTS | ||
| 1588 | help | 1587 | help |
| 1589 | Twofish cipher algorithm (x86_64, 3-way parallel). | 1588 | Twofish cipher algorithm (x86_64, 3-way parallel). |
| 1590 | 1589 | ||
