File Index
Files and directories
Sign in
FILE

cast6_avx_glue.c

File preview with syntax highlighting.

linux-6.19.14/arch/x86/crypto/cast6_avx_glue.c C
  1// SPDX-License-Identifier: GPL-2.0-or-later
  2/*
  3 * Glue Code for the AVX assembler implementation of the Cast6 Cipher
  4 *
  5 * Copyright (C) 2012 Johannes Goetzfried
  6 *     <Johannes.Goetzfried@informatik.stud.uni-erlangen.de>
  7 *
  8 * Copyright © 2013 Jussi Kivilinna <jussi.kivilinna@iki.fi>
  9 */
 10
 11#include <linux/module.h>
 12#include <linux/types.h>
 13#include <linux/crypto.h>
 14#include <linux/err.h>
 15#include <crypto/algapi.h>
 16#include <crypto/cast6.h>
 17
 18#include "ecb_cbc_helpers.h"
 19
 20#define CAST6_PARALLEL_BLOCKS 8
 21
 22asmlinkage void cast6_ecb_enc_8way(const void *ctx, u8 *dst, const u8 *src);
 23asmlinkage void cast6_ecb_dec_8way(const void *ctx, u8 *dst, const u8 *src);
 24
 25asmlinkage void cast6_cbc_dec_8way(const void *ctx, u8 *dst, const u8 *src);
 26
 27static int cast6_setkey_skcipher(struct crypto_skcipher *tfm,
 28				 const u8 *key, unsigned int keylen)
 29{
 30	return cast6_setkey(&tfm->base, key, keylen);
 31}
 32
 33static int ecb_encrypt(struct skcipher_request *req)
 34{
 35	ECB_WALK_START(req, CAST6_BLOCK_SIZE, CAST6_PARALLEL_BLOCKS);
 36	ECB_BLOCK(CAST6_PARALLEL_BLOCKS, cast6_ecb_enc_8way);
 37	ECB_BLOCK(1, __cast6_encrypt);
 38	ECB_WALK_END();
 39}
 40
 41static int ecb_decrypt(struct skcipher_request *req)
 42{
 43	ECB_WALK_START(req, CAST6_BLOCK_SIZE, CAST6_PARALLEL_BLOCKS);
 44	ECB_BLOCK(CAST6_PARALLEL_BLOCKS, cast6_ecb_dec_8way);
 45	ECB_BLOCK(1, __cast6_decrypt);
 46	ECB_WALK_END();
 47}
 48
 49static int cbc_encrypt(struct skcipher_request *req)
 50{
 51	CBC_WALK_START(req, CAST6_BLOCK_SIZE, -1);
 52	CBC_ENC_BLOCK(__cast6_encrypt);
 53	CBC_WALK_END();
 54}
 55
 56static int cbc_decrypt(struct skcipher_request *req)
 57{
 58	CBC_WALK_START(req, CAST6_BLOCK_SIZE, CAST6_PARALLEL_BLOCKS);
 59	CBC_DEC_BLOCK(CAST6_PARALLEL_BLOCKS, cast6_cbc_dec_8way);
 60	CBC_DEC_BLOCK(1, __cast6_decrypt);
 61	CBC_WALK_END();
 62}
 63
 64static struct skcipher_alg cast6_algs[] = {
 65	{
 66		.base.cra_name		= "ecb(cast6)",
 67		.base.cra_driver_name	= "ecb-cast6-avx",
 68		.base.cra_priority	= 200,
 69		.base.cra_blocksize	= CAST6_BLOCK_SIZE,
 70		.base.cra_ctxsize	= sizeof(struct cast6_ctx),
 71		.base.cra_module	= THIS_MODULE,
 72		.min_keysize		= CAST6_MIN_KEY_SIZE,
 73		.max_keysize		= CAST6_MAX_KEY_SIZE,
 74		.setkey			= cast6_setkey_skcipher,
 75		.encrypt		= ecb_encrypt,
 76		.decrypt		= ecb_decrypt,
 77	}, {
 78		.base.cra_name		= "cbc(cast6)",
 79		.base.cra_driver_name	= "cbc-cast6-avx",
 80		.base.cra_priority	= 200,
 81		.base.cra_blocksize	= CAST6_BLOCK_SIZE,
 82		.base.cra_ctxsize	= sizeof(struct cast6_ctx),
 83		.base.cra_module	= THIS_MODULE,
 84		.min_keysize		= CAST6_MIN_KEY_SIZE,
 85		.max_keysize		= CAST6_MAX_KEY_SIZE,
 86		.ivsize			= CAST6_BLOCK_SIZE,
 87		.setkey			= cast6_setkey_skcipher,
 88		.encrypt		= cbc_encrypt,
 89		.decrypt		= cbc_decrypt,
 90	},
 91};
 92
 93static int __init cast6_init(void)
 94{
 95	const char *feature_name;
 96
 97	if (!cpu_has_xfeatures(XFEATURE_MASK_SSE | XFEATURE_MASK_YMM,
 98				&feature_name)) {
 99		pr_info("CPU feature '%s' is not supported.\n", feature_name);
100		return -ENODEV;
101	}
102
103	return crypto_register_skciphers(cast6_algs, ARRAY_SIZE(cast6_algs));
104}
105
106static void __exit cast6_exit(void)
107{
108	crypto_unregister_skciphers(cast6_algs, ARRAY_SIZE(cast6_algs));
109}
110
111module_init(cast6_init);
112module_exit(cast6_exit);
113
114MODULE_DESCRIPTION("Cast6 Cipher Algorithm, AVX optimized");
115MODULE_LICENSE("GPL");
116MODULE_ALIAS_CRYPTO("cast6");
~/ Read-only file preview.