2019-05-27 14:55:05 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2012-07-12 01:37:37 +08:00
|
|
|
/*
|
2018-12-03 17:47:34 +08:00
|
|
|
* Glue Code for the AVX assembler implementation of the Cast5 Cipher
|
2012-07-12 01:37:37 +08:00
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Johannes Goetzfried
|
|
|
|
* <Johannes.Goetzfried@informatik.stud.uni-erlangen.de>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <crypto/algapi.h>
|
|
|
|
#include <crypto/cast5.h>
|
2018-02-20 15:48:13 +08:00
|
|
|
#include <crypto/internal/simd.h>
|
|
|
|
#include <linux/crypto.h>
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/types.h>
|
2012-07-12 01:37:37 +08:00
|
|
|
|
2021-01-06 00:48:05 +08:00
|
|
|
#include "ecb_cbc_helpers.h"
|
|
|
|
|
2012-07-12 01:37:37 +08:00
|
|
|
#define CAST5_PARALLEL_BLOCKS 16
|
|
|
|
|
2012-10-20 20:06:56 +08:00
|
|
|
asmlinkage void cast5_ecb_enc_16way(struct cast5_ctx *ctx, u8 *dst,
|
2012-07-12 01:37:37 +08:00
|
|
|
const u8 *src);
|
2012-10-20 20:06:56 +08:00
|
|
|
asmlinkage void cast5_ecb_dec_16way(struct cast5_ctx *ctx, u8 *dst,
|
|
|
|
const u8 *src);
|
|
|
|
asmlinkage void cast5_cbc_dec_16way(struct cast5_ctx *ctx, u8 *dst,
|
|
|
|
const u8 *src);
|
2012-07-12 01:37:37 +08:00
|
|
|
|
2018-02-20 15:48:13 +08:00
|
|
|
static int cast5_setkey_skcipher(struct crypto_skcipher *tfm, const u8 *key,
|
|
|
|
unsigned int keylen)
|
2012-07-12 01:37:37 +08:00
|
|
|
{
|
2018-02-20 15:48:13 +08:00
|
|
|
return cast5_setkey(&tfm->base, key, keylen);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ecb_encrypt(struct skcipher_request *req)
|
2012-07-12 01:37:37 +08:00
|
|
|
{
|
2021-01-06 00:48:05 +08:00
|
|
|
ECB_WALK_START(req, CAST5_BLOCK_SIZE, CAST5_PARALLEL_BLOCKS);
|
|
|
|
ECB_BLOCK(CAST5_PARALLEL_BLOCKS, cast5_ecb_enc_16way);
|
|
|
|
ECB_BLOCK(1, __cast5_encrypt);
|
|
|
|
ECB_WALK_END();
|
2012-07-12 01:37:37 +08:00
|
|
|
}
|
|
|
|
|
2018-02-20 15:48:13 +08:00
|
|
|
static int ecb_decrypt(struct skcipher_request *req)
|
2012-07-12 01:37:37 +08:00
|
|
|
{
|
2021-01-06 00:48:05 +08:00
|
|
|
ECB_WALK_START(req, CAST5_BLOCK_SIZE, CAST5_PARALLEL_BLOCKS);
|
|
|
|
ECB_BLOCK(CAST5_PARALLEL_BLOCKS, cast5_ecb_dec_16way);
|
|
|
|
ECB_BLOCK(1, __cast5_decrypt);
|
|
|
|
ECB_WALK_END();
|
2012-07-12 01:37:37 +08:00
|
|
|
}
|
|
|
|
|
2018-02-20 15:48:13 +08:00
|
|
|
static int cbc_encrypt(struct skcipher_request *req)
|
2012-07-12 01:37:37 +08:00
|
|
|
{
|
2021-01-06 00:48:05 +08:00
|
|
|
CBC_WALK_START(req, CAST5_BLOCK_SIZE, -1);
|
|
|
|
CBC_ENC_BLOCK(__cast5_encrypt);
|
|
|
|
CBC_WALK_END();
|
2012-07-12 01:37:37 +08:00
|
|
|
}
|
|
|
|
|
2018-02-20 15:48:13 +08:00
|
|
|
static int cbc_decrypt(struct skcipher_request *req)
|
2012-07-12 01:37:37 +08:00
|
|
|
{
|
2021-01-06 00:48:05 +08:00
|
|
|
CBC_WALK_START(req, CAST5_BLOCK_SIZE, CAST5_PARALLEL_BLOCKS);
|
|
|
|
CBC_DEC_BLOCK(CAST5_PARALLEL_BLOCKS, cast5_cbc_dec_16way);
|
|
|
|
CBC_DEC_BLOCK(1, __cast5_decrypt);
|
|
|
|
CBC_WALK_END();
|
2012-07-12 01:37:37 +08:00
|
|
|
}
|
|
|
|
|
2018-02-20 15:48:13 +08:00
|
|
|
static struct skcipher_alg cast5_algs[] = {
|
|
|
|
{
|
|
|
|
.base.cra_name = "__ecb(cast5)",
|
|
|
|
.base.cra_driver_name = "__ecb-cast5-avx",
|
|
|
|
.base.cra_priority = 200,
|
|
|
|
.base.cra_flags = CRYPTO_ALG_INTERNAL,
|
|
|
|
.base.cra_blocksize = CAST5_BLOCK_SIZE,
|
|
|
|
.base.cra_ctxsize = sizeof(struct cast5_ctx),
|
|
|
|
.base.cra_module = THIS_MODULE,
|
|
|
|
.min_keysize = CAST5_MIN_KEY_SIZE,
|
|
|
|
.max_keysize = CAST5_MAX_KEY_SIZE,
|
|
|
|
.setkey = cast5_setkey_skcipher,
|
|
|
|
.encrypt = ecb_encrypt,
|
|
|
|
.decrypt = ecb_decrypt,
|
|
|
|
}, {
|
|
|
|
.base.cra_name = "__cbc(cast5)",
|
|
|
|
.base.cra_driver_name = "__cbc-cast5-avx",
|
|
|
|
.base.cra_priority = 200,
|
|
|
|
.base.cra_flags = CRYPTO_ALG_INTERNAL,
|
|
|
|
.base.cra_blocksize = CAST5_BLOCK_SIZE,
|
|
|
|
.base.cra_ctxsize = sizeof(struct cast5_ctx),
|
|
|
|
.base.cra_module = THIS_MODULE,
|
|
|
|
.min_keysize = CAST5_MIN_KEY_SIZE,
|
|
|
|
.max_keysize = CAST5_MAX_KEY_SIZE,
|
|
|
|
.ivsize = CAST5_BLOCK_SIZE,
|
|
|
|
.setkey = cast5_setkey_skcipher,
|
|
|
|
.encrypt = cbc_encrypt,
|
|
|
|
.decrypt = cbc_decrypt,
|
|
|
|
}
|
|
|
|
};
|
2012-07-12 01:37:37 +08:00
|
|
|
|
2018-02-20 15:48:13 +08:00
|
|
|
static struct simd_skcipher_alg *cast5_simd_algs[ARRAY_SIZE(cast5_algs)];
|
2012-07-12 01:37:37 +08:00
|
|
|
|
|
|
|
static int __init cast5_init(void)
|
|
|
|
{
|
2015-04-28 16:11:24 +08:00
|
|
|
const char *feature_name;
|
2012-07-12 01:37:37 +08:00
|
|
|
|
2015-09-03 07:31:26 +08:00
|
|
|
if (!cpu_has_xfeatures(XFEATURE_MASK_SSE | XFEATURE_MASK_YMM,
|
|
|
|
&feature_name)) {
|
2015-04-28 16:11:24 +08:00
|
|
|
pr_info("CPU feature '%s' is not supported.\n", feature_name);
|
2012-07-12 01:37:37 +08:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2018-02-20 15:48:13 +08:00
|
|
|
return simd_register_skciphers_compat(cast5_algs,
|
|
|
|
ARRAY_SIZE(cast5_algs),
|
|
|
|
cast5_simd_algs);
|
2012-07-12 01:37:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit cast5_exit(void)
|
|
|
|
{
|
2018-02-20 15:48:13 +08:00
|
|
|
simd_unregister_skciphers(cast5_algs, ARRAY_SIZE(cast5_algs),
|
|
|
|
cast5_simd_algs);
|
2012-07-12 01:37:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
module_init(cast5_init);
|
|
|
|
module_exit(cast5_exit);
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("Cast5 Cipher Algorithm, AVX optimized");
|
|
|
|
MODULE_LICENSE("GPL");
|
2014-11-21 09:05:53 +08:00
|
|
|
MODULE_ALIAS_CRYPTO("cast5");
|