drm/panthor: Don't add write fences to the shared BOs
[drm/drm-misc.git] / crypto / arc4.c
blob1a4825c97c5ae19e4092c2df63730edafdadbf0c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Cryptographic API
5 * ARC4 Cipher Algorithm
7 * Jon Oberheide <jon@oberheide.org>
8 */
10 #include <crypto/arc4.h>
11 #include <crypto/internal/skcipher.h>
12 #include <linux/init.h>
13 #include <linux/kernel.h>
14 #include <linux/module.h>
15 #include <linux/sched.h>
17 #define ARC4_ALIGN __alignof__(struct arc4_ctx)
19 static int crypto_arc4_setkey(struct crypto_lskcipher *tfm, const u8 *in_key,
20 unsigned int key_len)
22 struct arc4_ctx *ctx = crypto_lskcipher_ctx(tfm);
24 return arc4_setkey(ctx, in_key, key_len);
27 static int crypto_arc4_crypt(struct crypto_lskcipher *tfm, const u8 *src,
28 u8 *dst, unsigned nbytes, u8 *siv, u32 flags)
30 struct arc4_ctx *ctx = crypto_lskcipher_ctx(tfm);
32 if (!(flags & CRYPTO_LSKCIPHER_FLAG_CONT))
33 memcpy(siv, ctx, sizeof(*ctx));
35 ctx = (struct arc4_ctx *)siv;
37 arc4_crypt(ctx, dst, src, nbytes);
38 return 0;
41 static int crypto_arc4_init(struct crypto_lskcipher *tfm)
43 pr_warn_ratelimited("\"%s\" (%ld) uses obsolete ecb(arc4) skcipher\n",
44 current->comm, (unsigned long)current->pid);
46 return 0;
49 static struct lskcipher_alg arc4_alg = {
50 .co.base.cra_name = "arc4",
51 .co.base.cra_driver_name = "arc4-generic",
52 .co.base.cra_priority = 100,
53 .co.base.cra_blocksize = ARC4_BLOCK_SIZE,
54 .co.base.cra_ctxsize = sizeof(struct arc4_ctx),
55 .co.base.cra_alignmask = ARC4_ALIGN - 1,
56 .co.base.cra_module = THIS_MODULE,
57 .co.min_keysize = ARC4_MIN_KEY_SIZE,
58 .co.max_keysize = ARC4_MAX_KEY_SIZE,
59 .co.statesize = sizeof(struct arc4_ctx),
60 .setkey = crypto_arc4_setkey,
61 .encrypt = crypto_arc4_crypt,
62 .decrypt = crypto_arc4_crypt,
63 .init = crypto_arc4_init,
66 static int __init arc4_init(void)
68 return crypto_register_lskcipher(&arc4_alg);
71 static void __exit arc4_exit(void)
73 crypto_unregister_lskcipher(&arc4_alg);
76 subsys_initcall(arc4_init);
77 module_exit(arc4_exit);
79 MODULE_LICENSE("GPL");
80 MODULE_DESCRIPTION("ARC4 Cipher Algorithm");
81 MODULE_AUTHOR("Jon Oberheide <jon@oberheide.org>");
82 MODULE_ALIAS_CRYPTO("ecb(arc4)");