Commit e0f409dc authored by Eric Biggers's avatar Eric Biggers Committed by Herbert Xu

crypto: x86/serpent-sse2 - convert to skcipher interface

Convert the SSE2 implementation of Serpent from the (deprecated)
ablkcipher and blkcipher interfaces over to the skcipher interface.
Note that this includes replacing the use of ablk_helper with
crypto_simd.
Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 8bab4e3c
...@@ -30,19 +30,22 @@ ...@@ -30,19 +30,22 @@
*/ */
#include <linux/module.h> #include <linux/module.h>
#include <linux/hardirq.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/crypto.h> #include <linux/crypto.h>
#include <linux/err.h> #include <linux/err.h>
#include <crypto/ablk_helper.h>
#include <crypto/algapi.h> #include <crypto/algapi.h>
#include <crypto/serpent.h>
#include <crypto/cryptd.h>
#include <crypto/b128ops.h> #include <crypto/b128ops.h>
#include <crypto/ctr.h> #include <crypto/internal/simd.h>
#include <crypto/serpent.h>
#include <asm/crypto/serpent-sse2.h> #include <asm/crypto/serpent-sse2.h>
#include <asm/crypto/glue_helper.h> #include <asm/crypto/glue_helper.h>
static int serpent_setkey_skcipher(struct crypto_skcipher *tfm,
const u8 *key, unsigned int keylen)
{
return __serpent_setkey(crypto_skcipher_ctx(tfm), key, keylen);
}
static void serpent_decrypt_cbc_xway(void *ctx, u128 *dst, const u128 *src) static void serpent_decrypt_cbc_xway(void *ctx, u128 *dst, const u128 *src)
{ {
u128 ivs[SERPENT_PARALLEL_BLOCKS - 1]; u128 ivs[SERPENT_PARALLEL_BLOCKS - 1];
...@@ -137,166 +140,79 @@ static const struct common_glue_ctx serpent_dec_cbc = { ...@@ -137,166 +140,79 @@ static const struct common_glue_ctx serpent_dec_cbc = {
} } } }
}; };
static int ecb_encrypt(struct blkcipher_desc *desc, struct scatterlist *dst, static int ecb_encrypt(struct skcipher_request *req)
struct scatterlist *src, unsigned int nbytes)
{ {
return glue_ecb_crypt_128bit(&serpent_enc, desc, dst, src, nbytes); return glue_ecb_req_128bit(&serpent_enc, req);
} }
static int ecb_decrypt(struct blkcipher_desc *desc, struct scatterlist *dst, static int ecb_decrypt(struct skcipher_request *req)
struct scatterlist *src, unsigned int nbytes)
{ {
return glue_ecb_crypt_128bit(&serpent_dec, desc, dst, src, nbytes); return glue_ecb_req_128bit(&serpent_dec, req);
} }
static int cbc_encrypt(struct blkcipher_desc *desc, struct scatterlist *dst, static int cbc_encrypt(struct skcipher_request *req)
struct scatterlist *src, unsigned int nbytes)
{ {
return glue_cbc_encrypt_128bit(GLUE_FUNC_CAST(__serpent_encrypt), desc, return glue_cbc_encrypt_req_128bit(GLUE_FUNC_CAST(__serpent_encrypt),
dst, src, nbytes); req);
} }
static int cbc_decrypt(struct blkcipher_desc *desc, struct scatterlist *dst, static int cbc_decrypt(struct skcipher_request *req)
struct scatterlist *src, unsigned int nbytes)
{ {
return glue_cbc_decrypt_128bit(&serpent_dec_cbc, desc, dst, src, return glue_cbc_decrypt_req_128bit(&serpent_dec_cbc, req);
nbytes);
} }
static int ctr_crypt(struct blkcipher_desc *desc, struct scatterlist *dst, static int ctr_crypt(struct skcipher_request *req)
struct scatterlist *src, unsigned int nbytes)
{ {
return glue_ctr_crypt_128bit(&serpent_ctr, desc, dst, src, nbytes); return glue_ctr_req_128bit(&serpent_ctr, req);
} }
static struct crypto_alg serpent_algs[] = { { static struct skcipher_alg serpent_algs[] = {
.cra_name = "__ecb-serpent-sse2", {
.cra_driver_name = "__driver-ecb-serpent-sse2", .base.cra_name = "__ecb(serpent)",
.cra_priority = 0, .base.cra_driver_name = "__ecb-serpent-sse2",
.cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER | .base.cra_priority = 400,
CRYPTO_ALG_INTERNAL, .base.cra_flags = CRYPTO_ALG_INTERNAL,
.cra_blocksize = SERPENT_BLOCK_SIZE, .base.cra_blocksize = SERPENT_BLOCK_SIZE,
.cra_ctxsize = sizeof(struct serpent_ctx), .base.cra_ctxsize = sizeof(struct serpent_ctx),
.cra_alignmask = 0, .base.cra_module = THIS_MODULE,
.cra_type = &crypto_blkcipher_type,
.cra_module = THIS_MODULE,
.cra_u = {
.blkcipher = {
.min_keysize = SERPENT_MIN_KEY_SIZE, .min_keysize = SERPENT_MIN_KEY_SIZE,
.max_keysize = SERPENT_MAX_KEY_SIZE, .max_keysize = SERPENT_MAX_KEY_SIZE,
.setkey = serpent_setkey, .setkey = serpent_setkey_skcipher,
.encrypt = ecb_encrypt, .encrypt = ecb_encrypt,
.decrypt = ecb_decrypt, .decrypt = ecb_decrypt,
}, }, {
}, .base.cra_name = "__cbc(serpent)",
}, { .base.cra_driver_name = "__cbc-serpent-sse2",
.cra_name = "__cbc-serpent-sse2", .base.cra_priority = 400,
.cra_driver_name = "__driver-cbc-serpent-sse2", .base.cra_flags = CRYPTO_ALG_INTERNAL,
.cra_priority = 0, .base.cra_blocksize = SERPENT_BLOCK_SIZE,
.cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER | .base.cra_ctxsize = sizeof(struct serpent_ctx),
CRYPTO_ALG_INTERNAL, .base.cra_module = THIS_MODULE,
.cra_blocksize = SERPENT_BLOCK_SIZE,
.cra_ctxsize = sizeof(struct serpent_ctx),
.cra_alignmask = 0,
.cra_type = &crypto_blkcipher_type,
.cra_module = THIS_MODULE,
.cra_u = {
.blkcipher = {
.min_keysize = SERPENT_MIN_KEY_SIZE, .min_keysize = SERPENT_MIN_KEY_SIZE,
.max_keysize = SERPENT_MAX_KEY_SIZE, .max_keysize = SERPENT_MAX_KEY_SIZE,
.setkey = serpent_setkey, .ivsize = SERPENT_BLOCK_SIZE,
.setkey = serpent_setkey_skcipher,
.encrypt = cbc_encrypt, .encrypt = cbc_encrypt,
.decrypt = cbc_decrypt, .decrypt = cbc_decrypt,
}, }, {
}, .base.cra_name = "__ctr(serpent)",
}, { .base.cra_driver_name = "__ctr-serpent-sse2",
.cra_name = "__ctr-serpent-sse2", .base.cra_priority = 400,
.cra_driver_name = "__driver-ctr-serpent-sse2", .base.cra_flags = CRYPTO_ALG_INTERNAL,
.cra_priority = 0, .base.cra_blocksize = 1,
.cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER | .base.cra_ctxsize = sizeof(struct serpent_ctx),
CRYPTO_ALG_INTERNAL, .base.cra_module = THIS_MODULE,
.cra_blocksize = 1,
.cra_ctxsize = sizeof(struct serpent_ctx),
.cra_alignmask = 0,
.cra_type = &crypto_blkcipher_type,
.cra_module = THIS_MODULE,
.cra_u = {
.blkcipher = {
.min_keysize = SERPENT_MIN_KEY_SIZE, .min_keysize = SERPENT_MIN_KEY_SIZE,
.max_keysize = SERPENT_MAX_KEY_SIZE, .max_keysize = SERPENT_MAX_KEY_SIZE,
.ivsize = SERPENT_BLOCK_SIZE, .ivsize = SERPENT_BLOCK_SIZE,
.setkey = serpent_setkey, .chunksize = SERPENT_BLOCK_SIZE,
.setkey = serpent_setkey_skcipher,
.encrypt = ctr_crypt, .encrypt = ctr_crypt,
.decrypt = ctr_crypt, .decrypt = ctr_crypt,
}, },
}, };
}, {
.cra_name = "ecb(serpent)", static struct simd_skcipher_alg *serpent_simd_algs[ARRAY_SIZE(serpent_algs)];
.cra_driver_name = "ecb-serpent-sse2",
.cra_priority = 400,
.cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC,
.cra_blocksize = SERPENT_BLOCK_SIZE,
.cra_ctxsize = sizeof(struct async_helper_ctx),
.cra_alignmask = 0,
.cra_type = &crypto_ablkcipher_type,
.cra_module = THIS_MODULE,
.cra_init = ablk_init,
.cra_exit = ablk_exit,
.cra_u = {
.ablkcipher = {
.min_keysize = SERPENT_MIN_KEY_SIZE,
.max_keysize = SERPENT_MAX_KEY_SIZE,
.setkey = ablk_set_key,
.encrypt = ablk_encrypt,
.decrypt = ablk_decrypt,
},
},
}, {
.cra_name = "cbc(serpent)",
.cra_driver_name = "cbc-serpent-sse2",
.cra_priority = 400,
.cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC,
.cra_blocksize = SERPENT_BLOCK_SIZE,
.cra_ctxsize = sizeof(struct async_helper_ctx),
.cra_alignmask = 0,
.cra_type = &crypto_ablkcipher_type,
.cra_module = THIS_MODULE,
.cra_init = ablk_init,
.cra_exit = ablk_exit,
.cra_u = {
.ablkcipher = {
.min_keysize = SERPENT_MIN_KEY_SIZE,
.max_keysize = SERPENT_MAX_KEY_SIZE,
.ivsize = SERPENT_BLOCK_SIZE,
.setkey = ablk_set_key,
.encrypt = __ablk_encrypt,
.decrypt = ablk_decrypt,
},
},
}, {
.cra_name = "ctr(serpent)",
.cra_driver_name = "ctr-serpent-sse2",
.cra_priority = 400,
.cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC,
.cra_blocksize = 1,
.cra_ctxsize = sizeof(struct async_helper_ctx),
.cra_alignmask = 0,
.cra_type = &crypto_ablkcipher_type,
.cra_module = THIS_MODULE,
.cra_init = ablk_init,
.cra_exit = ablk_exit,
.cra_u = {
.ablkcipher = {
.min_keysize = SERPENT_MIN_KEY_SIZE,
.max_keysize = SERPENT_MAX_KEY_SIZE,
.ivsize = SERPENT_BLOCK_SIZE,
.setkey = ablk_set_key,
.encrypt = ablk_encrypt,
.decrypt = ablk_encrypt,
.geniv = "chainiv",
},
},
} };
static int __init serpent_sse2_init(void) static int __init serpent_sse2_init(void)
{ {
...@@ -305,12 +221,15 @@ static int __init serpent_sse2_init(void) ...@@ -305,12 +221,15 @@ static int __init serpent_sse2_init(void)
return -ENODEV; return -ENODEV;
} }
return crypto_register_algs(serpent_algs, ARRAY_SIZE(serpent_algs)); return simd_register_skciphers_compat(serpent_algs,
ARRAY_SIZE(serpent_algs),
serpent_simd_algs);
} }
static void __exit serpent_sse2_exit(void) static void __exit serpent_sse2_exit(void)
{ {
crypto_unregister_algs(serpent_algs, ARRAY_SIZE(serpent_algs)); simd_unregister_skciphers(serpent_algs, ARRAY_SIZE(serpent_algs),
serpent_simd_algs);
} }
module_init(serpent_sse2_init); module_init(serpent_sse2_init);
......
...@@ -1422,11 +1422,10 @@ config CRYPTO_SERPENT ...@@ -1422,11 +1422,10 @@ config CRYPTO_SERPENT
config CRYPTO_SERPENT_SSE2_X86_64 config CRYPTO_SERPENT_SSE2_X86_64
tristate "Serpent cipher algorithm (x86_64/SSE2)" tristate "Serpent cipher algorithm (x86_64/SSE2)"
depends on X86 && 64BIT depends on X86 && 64BIT
select CRYPTO_ALGAPI select CRYPTO_BLKCIPHER
select CRYPTO_CRYPTD
select CRYPTO_ABLK_HELPER
select CRYPTO_GLUE_HELPER_X86 select CRYPTO_GLUE_HELPER_X86
select CRYPTO_SERPENT select CRYPTO_SERPENT
select CRYPTO_SIMD
help help
Serpent cipher algorithm, by Anderson, Biham & Knudsen. Serpent cipher algorithm, by Anderson, Biham & Knudsen.
...@@ -1442,11 +1441,10 @@ config CRYPTO_SERPENT_SSE2_X86_64 ...@@ -1442,11 +1441,10 @@ config CRYPTO_SERPENT_SSE2_X86_64
config CRYPTO_SERPENT_SSE2_586 config CRYPTO_SERPENT_SSE2_586
tristate "Serpent cipher algorithm (i586/SSE2)" tristate "Serpent cipher algorithm (i586/SSE2)"
depends on X86 && !64BIT depends on X86 && !64BIT
select CRYPTO_ALGAPI select CRYPTO_BLKCIPHER
select CRYPTO_CRYPTD
select CRYPTO_ABLK_HELPER
select CRYPTO_GLUE_HELPER_X86 select CRYPTO_GLUE_HELPER_X86
select CRYPTO_SERPENT select CRYPTO_SERPENT
select CRYPTO_SIMD
help help
Serpent cipher algorithm, by Anderson, Biham & Knudsen. Serpent cipher algorithm, by Anderson, Biham & Knudsen.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment