forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
crypto: x86/blowfish - drop CTR mode implementation
Blowfish in counter mode is never used in the kernel, so there is no point in keeping an accelerated implementation around. Acked-by: Eric Biggers <[email protected]> Signed-off-by: Ard Biesheuvel <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
- Loading branch information
1 parent
768db5f
commit c0a6492
Showing
2 changed files
with
1 addition
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,8 +6,6 @@ | |
* | ||
* CBC & ECB parts based on code (crypto/cbc.c,ecb.c) by: | ||
* Copyright (c) 2006 Herbert Xu <[email protected]> | ||
* CTR part based on code (crypto/ctr.c) by: | ||
* (C) Copyright IBM Corp. 2007 - Joy Latten <[email protected]> | ||
*/ | ||
|
||
#include <crypto/algapi.h> | ||
|
@@ -247,97 +245,6 @@ static int cbc_decrypt(struct skcipher_request *req) | |
return err; | ||
} | ||
|
||
static void ctr_crypt_final(struct bf_ctx *ctx, struct skcipher_walk *walk) | ||
{ | ||
u8 *ctrblk = walk->iv; | ||
u8 keystream[BF_BLOCK_SIZE]; | ||
u8 *src = walk->src.virt.addr; | ||
u8 *dst = walk->dst.virt.addr; | ||
unsigned int nbytes = walk->nbytes; | ||
|
||
blowfish_enc_blk(ctx, keystream, ctrblk); | ||
crypto_xor_cpy(dst, keystream, src, nbytes); | ||
|
||
crypto_inc(ctrblk, BF_BLOCK_SIZE); | ||
} | ||
|
||
static unsigned int __ctr_crypt(struct bf_ctx *ctx, struct skcipher_walk *walk) | ||
{ | ||
unsigned int bsize = BF_BLOCK_SIZE; | ||
unsigned int nbytes = walk->nbytes; | ||
u64 *src = (u64 *)walk->src.virt.addr; | ||
u64 *dst = (u64 *)walk->dst.virt.addr; | ||
u64 ctrblk = be64_to_cpu(*(__be64 *)walk->iv); | ||
__be64 ctrblocks[4]; | ||
|
||
/* Process four block batch */ | ||
if (nbytes >= bsize * 4) { | ||
do { | ||
if (dst != src) { | ||
dst[0] = src[0]; | ||
dst[1] = src[1]; | ||
dst[2] = src[2]; | ||
dst[3] = src[3]; | ||
} | ||
|
||
/* create ctrblks for parallel encrypt */ | ||
ctrblocks[0] = cpu_to_be64(ctrblk++); | ||
ctrblocks[1] = cpu_to_be64(ctrblk++); | ||
ctrblocks[2] = cpu_to_be64(ctrblk++); | ||
ctrblocks[3] = cpu_to_be64(ctrblk++); | ||
|
||
blowfish_enc_blk_xor_4way(ctx, (u8 *)dst, | ||
(u8 *)ctrblocks); | ||
|
||
src += 4; | ||
dst += 4; | ||
} while ((nbytes -= bsize * 4) >= bsize * 4); | ||
|
||
if (nbytes < bsize) | ||
goto done; | ||
} | ||
|
||
/* Handle leftovers */ | ||
do { | ||
if (dst != src) | ||
*dst = *src; | ||
|
||
ctrblocks[0] = cpu_to_be64(ctrblk++); | ||
|
||
blowfish_enc_blk_xor(ctx, (u8 *)dst, (u8 *)ctrblocks); | ||
|
||
src += 1; | ||
dst += 1; | ||
} while ((nbytes -= bsize) >= bsize); | ||
|
||
done: | ||
*(__be64 *)walk->iv = cpu_to_be64(ctrblk); | ||
return nbytes; | ||
} | ||
|
||
static int ctr_crypt(struct skcipher_request *req) | ||
{ | ||
struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); | ||
struct bf_ctx *ctx = crypto_skcipher_ctx(tfm); | ||
struct skcipher_walk walk; | ||
unsigned int nbytes; | ||
int err; | ||
|
||
err = skcipher_walk_virt(&walk, req, false); | ||
|
||
while ((nbytes = walk.nbytes) >= BF_BLOCK_SIZE) { | ||
nbytes = __ctr_crypt(ctx, &walk); | ||
err = skcipher_walk_done(&walk, nbytes); | ||
} | ||
|
||
if (nbytes) { | ||
ctr_crypt_final(ctx, &walk); | ||
err = skcipher_walk_done(&walk, 0); | ||
} | ||
|
||
return err; | ||
} | ||
|
||
static struct crypto_alg bf_cipher_alg = { | ||
.cra_name = "blowfish", | ||
.cra_driver_name = "blowfish-asm", | ||
|
@@ -384,20 +291,6 @@ static struct skcipher_alg bf_skcipher_algs[] = { | |
.setkey = blowfish_setkey_skcipher, | ||
.encrypt = cbc_encrypt, | ||
.decrypt = cbc_decrypt, | ||
}, { | ||
.base.cra_name = "ctr(blowfish)", | ||
.base.cra_driver_name = "ctr-blowfish-asm", | ||
.base.cra_priority = 300, | ||
.base.cra_blocksize = 1, | ||
.base.cra_ctxsize = sizeof(struct bf_ctx), | ||
.base.cra_module = THIS_MODULE, | ||
.min_keysize = BF_MIN_KEY_SIZE, | ||
.max_keysize = BF_MAX_KEY_SIZE, | ||
.ivsize = BF_BLOCK_SIZE, | ||
.chunksize = BF_BLOCK_SIZE, | ||
.setkey = blowfish_setkey_skcipher, | ||
.encrypt = ctr_crypt, | ||
.decrypt = ctr_crypt, | ||
}, | ||
}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters