crypto: x86/camellia - convert to skcipher interface
Convert the x86 asm implementation of Camellia from the (deprecated) blkcipher interface over to the skcipher interface. Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
parent
451cc49324
commit
1af6d03710
2 changed files with 80 additions and 84 deletions
|
@ -23,7 +23,6 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <asm/processor.h>
|
|
||||||
#include <asm/unaligned.h>
|
#include <asm/unaligned.h>
|
||||||
#include <linux/crypto.h>
|
#include <linux/crypto.h>
|
||||||
#include <linux/init.h>
|
#include <linux/init.h>
|
||||||
|
@ -1270,13 +1269,19 @@ int __camellia_setkey(struct camellia_ctx *cctx, const unsigned char *key,
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(__camellia_setkey);
|
EXPORT_SYMBOL_GPL(__camellia_setkey);
|
||||||
|
|
||||||
static int camellia_setkey(struct crypto_tfm *tfm, const u8 *in_key,
|
static int camellia_setkey(struct crypto_tfm *tfm, const u8 *key,
|
||||||
unsigned int key_len)
|
unsigned int key_len)
|
||||||
{
|
{
|
||||||
return __camellia_setkey(crypto_tfm_ctx(tfm), in_key, key_len,
|
return __camellia_setkey(crypto_tfm_ctx(tfm), key, key_len,
|
||||||
&tfm->crt_flags);
|
&tfm->crt_flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int camellia_setkey_skcipher(struct crypto_skcipher *tfm, const u8 *key,
|
||||||
|
unsigned int key_len)
|
||||||
|
{
|
||||||
|
return camellia_setkey(&tfm->base, key, key_len);
|
||||||
|
}
|
||||||
|
|
||||||
void camellia_decrypt_cbc_2way(void *ctx, u128 *dst, const u128 *src)
|
void camellia_decrypt_cbc_2way(void *ctx, u128 *dst, const u128 *src)
|
||||||
{
|
{
|
||||||
u128 iv = *src;
|
u128 iv = *src;
|
||||||
|
@ -1371,39 +1376,33 @@ static const struct common_glue_ctx camellia_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(&camellia_enc, desc, dst, src, nbytes);
|
return glue_ecb_req_128bit(&camellia_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(&camellia_dec, desc, dst, src, nbytes);
|
return glue_ecb_req_128bit(&camellia_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(camellia_enc_blk), desc,
|
return glue_cbc_encrypt_req_128bit(GLUE_FUNC_CAST(camellia_enc_blk),
|
||||||
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(&camellia_dec_cbc, desc, dst, src,
|
return glue_cbc_decrypt_req_128bit(&camellia_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(&camellia_ctr, desc, dst, src, nbytes);
|
return glue_ctr_req_128bit(&camellia_ctr, req);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct crypto_alg camellia_algs[] = { {
|
static struct crypto_alg camellia_cipher_alg = {
|
||||||
.cra_name = "camellia",
|
.cra_name = "camellia",
|
||||||
.cra_driver_name = "camellia-asm",
|
.cra_driver_name = "camellia-asm",
|
||||||
.cra_priority = 200,
|
.cra_priority = 200,
|
||||||
|
@ -1421,66 +1420,50 @@ static struct crypto_alg camellia_algs[] = { {
|
||||||
.cia_decrypt = camellia_decrypt
|
.cia_decrypt = camellia_decrypt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, {
|
};
|
||||||
.cra_name = "ecb(camellia)",
|
|
||||||
.cra_driver_name = "ecb-camellia-asm",
|
static struct skcipher_alg camellia_skcipher_algs[] = {
|
||||||
.cra_priority = 300,
|
{
|
||||||
.cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER,
|
.base.cra_name = "ecb(camellia)",
|
||||||
.cra_blocksize = CAMELLIA_BLOCK_SIZE,
|
.base.cra_driver_name = "ecb-camellia-asm",
|
||||||
.cra_ctxsize = sizeof(struct camellia_ctx),
|
.base.cra_priority = 300,
|
||||||
.cra_alignmask = 0,
|
.base.cra_blocksize = CAMELLIA_BLOCK_SIZE,
|
||||||
.cra_type = &crypto_blkcipher_type,
|
.base.cra_ctxsize = sizeof(struct camellia_ctx),
|
||||||
.cra_module = THIS_MODULE,
|
.base.cra_module = THIS_MODULE,
|
||||||
.cra_u = {
|
.min_keysize = CAMELLIA_MIN_KEY_SIZE,
|
||||||
.blkcipher = {
|
.max_keysize = CAMELLIA_MAX_KEY_SIZE,
|
||||||
.min_keysize = CAMELLIA_MIN_KEY_SIZE,
|
.setkey = camellia_setkey_skcipher,
|
||||||
.max_keysize = CAMELLIA_MAX_KEY_SIZE,
|
.encrypt = ecb_encrypt,
|
||||||
.setkey = camellia_setkey,
|
.decrypt = ecb_decrypt,
|
||||||
.encrypt = ecb_encrypt,
|
}, {
|
||||||
.decrypt = ecb_decrypt,
|
.base.cra_name = "cbc(camellia)",
|
||||||
},
|
.base.cra_driver_name = "cbc-camellia-asm",
|
||||||
},
|
.base.cra_priority = 300,
|
||||||
}, {
|
.base.cra_blocksize = CAMELLIA_BLOCK_SIZE,
|
||||||
.cra_name = "cbc(camellia)",
|
.base.cra_ctxsize = sizeof(struct camellia_ctx),
|
||||||
.cra_driver_name = "cbc-camellia-asm",
|
.base.cra_module = THIS_MODULE,
|
||||||
.cra_priority = 300,
|
.min_keysize = CAMELLIA_MIN_KEY_SIZE,
|
||||||
.cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER,
|
.max_keysize = CAMELLIA_MAX_KEY_SIZE,
|
||||||
.cra_blocksize = CAMELLIA_BLOCK_SIZE,
|
.ivsize = CAMELLIA_BLOCK_SIZE,
|
||||||
.cra_ctxsize = sizeof(struct camellia_ctx),
|
.setkey = camellia_setkey_skcipher,
|
||||||
.cra_alignmask = 0,
|
.encrypt = cbc_encrypt,
|
||||||
.cra_type = &crypto_blkcipher_type,
|
.decrypt = cbc_decrypt,
|
||||||
.cra_module = THIS_MODULE,
|
}, {
|
||||||
.cra_u = {
|
.base.cra_name = "ctr(camellia)",
|
||||||
.blkcipher = {
|
.base.cra_driver_name = "ctr-camellia-asm",
|
||||||
.min_keysize = CAMELLIA_MIN_KEY_SIZE,
|
.base.cra_priority = 300,
|
||||||
.max_keysize = CAMELLIA_MAX_KEY_SIZE,
|
.base.cra_blocksize = 1,
|
||||||
.ivsize = CAMELLIA_BLOCK_SIZE,
|
.base.cra_ctxsize = sizeof(struct camellia_ctx),
|
||||||
.setkey = camellia_setkey,
|
.base.cra_module = THIS_MODULE,
|
||||||
.encrypt = cbc_encrypt,
|
.min_keysize = CAMELLIA_MIN_KEY_SIZE,
|
||||||
.decrypt = cbc_decrypt,
|
.max_keysize = CAMELLIA_MAX_KEY_SIZE,
|
||||||
},
|
.ivsize = CAMELLIA_BLOCK_SIZE,
|
||||||
},
|
.chunksize = CAMELLIA_BLOCK_SIZE,
|
||||||
}, {
|
.setkey = camellia_setkey_skcipher,
|
||||||
.cra_name = "ctr(camellia)",
|
.encrypt = ctr_crypt,
|
||||||
.cra_driver_name = "ctr-camellia-asm",
|
.decrypt = ctr_crypt,
|
||||||
.cra_priority = 300,
|
}
|
||||||
.cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER,
|
};
|
||||||
.cra_blocksize = 1,
|
|
||||||
.cra_ctxsize = sizeof(struct camellia_ctx),
|
|
||||||
.cra_alignmask = 0,
|
|
||||||
.cra_type = &crypto_blkcipher_type,
|
|
||||||
.cra_module = THIS_MODULE,
|
|
||||||
.cra_u = {
|
|
||||||
.blkcipher = {
|
|
||||||
.min_keysize = CAMELLIA_MIN_KEY_SIZE,
|
|
||||||
.max_keysize = CAMELLIA_MAX_KEY_SIZE,
|
|
||||||
.ivsize = CAMELLIA_BLOCK_SIZE,
|
|
||||||
.setkey = camellia_setkey,
|
|
||||||
.encrypt = ctr_crypt,
|
|
||||||
.decrypt = ctr_crypt,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
} };
|
|
||||||
|
|
||||||
static bool is_blacklisted_cpu(void)
|
static bool is_blacklisted_cpu(void)
|
||||||
{
|
{
|
||||||
|
@ -1506,6 +1489,8 @@ MODULE_PARM_DESC(force, "Force module load, ignore CPU blacklist");
|
||||||
|
|
||||||
static int __init init(void)
|
static int __init init(void)
|
||||||
{
|
{
|
||||||
|
int err;
|
||||||
|
|
||||||
if (!force && is_blacklisted_cpu()) {
|
if (!force && is_blacklisted_cpu()) {
|
||||||
printk(KERN_INFO
|
printk(KERN_INFO
|
||||||
"camellia-x86_64: performance on this CPU "
|
"camellia-x86_64: performance on this CPU "
|
||||||
|
@ -1514,12 +1499,23 @@ static int __init init(void)
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
|
|
||||||
return crypto_register_algs(camellia_algs, ARRAY_SIZE(camellia_algs));
|
err = crypto_register_alg(&camellia_cipher_alg);
|
||||||
|
if (err)
|
||||||
|
return err;
|
||||||
|
|
||||||
|
err = crypto_register_skciphers(camellia_skcipher_algs,
|
||||||
|
ARRAY_SIZE(camellia_skcipher_algs));
|
||||||
|
if (err)
|
||||||
|
crypto_unregister_alg(&camellia_cipher_alg);
|
||||||
|
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __exit fini(void)
|
static void __exit fini(void)
|
||||||
{
|
{
|
||||||
crypto_unregister_algs(camellia_algs, ARRAY_SIZE(camellia_algs));
|
crypto_unregister_alg(&camellia_cipher_alg);
|
||||||
|
crypto_unregister_skciphers(camellia_skcipher_algs,
|
||||||
|
ARRAY_SIZE(camellia_skcipher_algs));
|
||||||
}
|
}
|
||||||
|
|
||||||
module_init(init);
|
module_init(init);
|
||||||
|
|
|
@ -1145,7 +1145,7 @@ config CRYPTO_CAMELLIA_X86_64
|
||||||
tristate "Camellia cipher algorithm (x86_64)"
|
tristate "Camellia cipher algorithm (x86_64)"
|
||||||
depends on X86 && 64BIT
|
depends on X86 && 64BIT
|
||||||
depends on CRYPTO
|
depends on CRYPTO
|
||||||
select CRYPTO_ALGAPI
|
select CRYPTO_BLKCIPHER
|
||||||
select CRYPTO_GLUE_HELPER_X86
|
select CRYPTO_GLUE_HELPER_X86
|
||||||
help
|
help
|
||||||
Camellia cipher algorithm module (x86_64).
|
Camellia cipher algorithm module (x86_64).
|
||||||
|
|
Loading…
Add table
Reference in a new issue