Files

83 lines
2.0 KiB
C
Raw Permalink Normal View History

// SPDX-License-Identifier: GPL-2.0-or-later
2011-06-08 21:26:00 +08:00
/*
2005-04-16 15:20:36 -07:00
* Cryptographic API
*
* ARC4 Cipher Algorithm
*
* Jon Oberheide <jon@oberheide.org>
*/
2019-02-08 15:50:08 +02:00
#include <crypto/arc4.h>
2019-01-03 20:16:23 -08:00
#include <crypto/internal/skcipher.h>
#include <linux/init.h>
#include <linux/kernel.h>
2019-01-03 20:16:23 -08:00
#include <linux/module.h>
#include <linux/sched.h>
2005-04-16 15:20:36 -07:00
2023-11-28 14:52:57 +08:00
#define ARC4_ALIGN __alignof__(struct arc4_ctx)
static int crypto_arc4_setkey(struct crypto_lskcipher *tfm, const u8 *in_key,
2019-06-12 18:19:57 +02:00
unsigned int key_len)
2005-04-16 15:20:36 -07:00
{
struct arc4_ctx *ctx = crypto_lskcipher_ctx(tfm);
2005-04-16 15:20:36 -07:00
return arc4_setkey(ctx, in_key, key_len);
2005-04-16 15:20:36 -07:00
}
static int crypto_arc4_crypt(struct crypto_lskcipher *tfm, const u8 *src,
2023-11-28 14:52:57 +08:00
u8 *dst, unsigned nbytes, u8 *siv, u32 flags)
{
struct arc4_ctx *ctx = crypto_lskcipher_ctx(tfm);
2023-11-28 14:52:57 +08:00
if (!(flags & CRYPTO_LSKCIPHER_FLAG_CONT))
memcpy(siv, ctx, sizeof(*ctx));
ctx = (struct arc4_ctx *)siv;
arc4_crypt(ctx, dst, src, nbytes);
return 0;
}
static int crypto_arc4_init(struct crypto_lskcipher *tfm)
{
pr_warn_ratelimited("\"%s\" (%ld) uses obsolete ecb(arc4) skcipher\n",
current->comm, (unsigned long)current->pid);
return 0;
}
static struct lskcipher_alg arc4_alg = {
.co.base.cra_name = "arc4",
.co.base.cra_driver_name = "arc4-generic",
.co.base.cra_priority = 100,
.co.base.cra_blocksize = ARC4_BLOCK_SIZE,
.co.base.cra_ctxsize = sizeof(struct arc4_ctx),
2023-11-28 14:52:57 +08:00
.co.base.cra_alignmask = ARC4_ALIGN - 1,
.co.base.cra_module = THIS_MODULE,
.co.min_keysize = ARC4_MIN_KEY_SIZE,
.co.max_keysize = ARC4_MAX_KEY_SIZE,
2023-11-28 14:52:57 +08:00
.co.statesize = sizeof(struct arc4_ctx),
.setkey = crypto_arc4_setkey,
.encrypt = crypto_arc4_crypt,
.decrypt = crypto_arc4_crypt,
.init = crypto_arc4_init,
2019-01-03 20:16:23 -08:00
};
2005-04-16 15:20:36 -07:00
static int __init arc4_init(void)
{
return crypto_register_lskcipher(&arc4_alg);
2005-04-16 15:20:36 -07:00
}
static void __exit arc4_exit(void)
{
crypto_unregister_lskcipher(&arc4_alg);
2005-04-16 15:20:36 -07:00
}
module_init(arc4_init);
2005-04-16 15:20:36 -07:00
module_exit(arc4_exit);
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("ARC4 Cipher Algorithm");
MODULE_AUTHOR("Jon Oberheide <jon@oberheide.org>");
2019-06-12 18:19:57 +02:00
MODULE_ALIAS_CRYPTO("ecb(arc4)");