Blame view

crypto/arc4.c 2.09 KB
2874c5fd2   Thomas Gleixner   treewide: Replace...
1
  // SPDX-License-Identifier: GPL-2.0-or-later
cfa2b54ec   Mati Vait   crypto: arc4 - Fi...
2
  /*
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3
4
5
6
7
   * Cryptographic API
   *
   * ARC4 Cipher Algorithm
   *
   * Jon Oberheide <jon@oberheide.org>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
8
   */
ce6dd3689   Jussi Kivilinna   crypto: arc4 - im...
9

ce6dd3689   Jussi Kivilinna   crypto: arc4 - im...
10
  #include <crypto/algapi.h>
bd30cf533   Iuliana Prodan   crypto: export ar...
11
  #include <crypto/arc4.h>
426bcb508   Eric Biggers   crypto: arc4 - co...
12
13
  #include <crypto/internal/skcipher.h>
  #include <linux/init.h>
9ace67718   Ard Biesheuvel   crypto: arc4 - ma...
14
  #include <linux/kernel.h>
426bcb508   Eric Biggers   crypto: arc4 - co...
15
  #include <linux/module.h>
9ace67718   Ard Biesheuvel   crypto: arc4 - ma...
16
  #include <linux/sched.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
17

611a23c2d   Ard Biesheuvel   crypto: arc4 - re...
18
19
  static int crypto_arc4_setkey(struct crypto_skcipher *tfm, const u8 *in_key,
  			      unsigned int key_len)
426bcb508   Eric Biggers   crypto: arc4 - co...
20
  {
611a23c2d   Ard Biesheuvel   crypto: arc4 - re...
21
  	struct arc4_ctx *ctx = crypto_skcipher_ctx(tfm);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
22

dc51f2575   Ard Biesheuvel   crypto: arc4 - re...
23
  	return arc4_setkey(ctx, in_key, key_len);
ce6dd3689   Jussi Kivilinna   crypto: arc4 - im...
24
  }
611a23c2d   Ard Biesheuvel   crypto: arc4 - re...
25
  static int crypto_arc4_crypt(struct skcipher_request *req)
ce6dd3689   Jussi Kivilinna   crypto: arc4 - im...
26
  {
426bcb508   Eric Biggers   crypto: arc4 - co...
27
28
29
  	struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
  	struct arc4_ctx *ctx = crypto_skcipher_ctx(tfm);
  	struct skcipher_walk walk;
ce6dd3689   Jussi Kivilinna   crypto: arc4 - im...
30
  	int err;
426bcb508   Eric Biggers   crypto: arc4 - co...
31
  	err = skcipher_walk_virt(&walk, req, false);
ce6dd3689   Jussi Kivilinna   crypto: arc4 - im...
32
33
  
  	while (walk.nbytes > 0) {
426bcb508   Eric Biggers   crypto: arc4 - co...
34
35
36
  		arc4_crypt(ctx, walk.dst.virt.addr, walk.src.virt.addr,
  			   walk.nbytes);
  		err = skcipher_walk_done(&walk, 0);
ce6dd3689   Jussi Kivilinna   crypto: arc4 - im...
37
38
39
40
  	}
  
  	return err;
  }
9ace67718   Ard Biesheuvel   crypto: arc4 - ma...
41
42
43
44
45
46
47
48
  static int crypto_arc4_init(struct crypto_skcipher *tfm)
  {
  	pr_warn_ratelimited("\"%s\" (%ld) uses obsolete ecb(arc4) skcipher
  ",
  			    current->comm, (unsigned long)current->pid);
  
  	return 0;
  }
611a23c2d   Ard Biesheuvel   crypto: arc4 - re...
49
50
51
52
53
  static struct skcipher_alg arc4_alg = {
  	/*
  	 * For legacy reasons, this is named "ecb(arc4)", not "arc4".
  	 * Nevertheless it's actually a stream cipher, not a block cipher.
  	 */
426bcb508   Eric Biggers   crypto: arc4 - co...
54
  	.base.cra_name		=	"ecb(arc4)",
d6ebf5286   Eric Biggers   crypto: make all ...
55
  	.base.cra_driver_name	=	"ecb(arc4)-generic",
426bcb508   Eric Biggers   crypto: arc4 - co...
56
57
58
59
60
61
  	.base.cra_priority	=	100,
  	.base.cra_blocksize	=	ARC4_BLOCK_SIZE,
  	.base.cra_ctxsize	=	sizeof(struct arc4_ctx),
  	.base.cra_module	=	THIS_MODULE,
  	.min_keysize		=	ARC4_MIN_KEY_SIZE,
  	.max_keysize		=	ARC4_MAX_KEY_SIZE,
611a23c2d   Ard Biesheuvel   crypto: arc4 - re...
62
63
64
  	.setkey			=	crypto_arc4_setkey,
  	.encrypt		=	crypto_arc4_crypt,
  	.decrypt		=	crypto_arc4_crypt,
9ace67718   Ard Biesheuvel   crypto: arc4 - ma...
65
  	.init			=	crypto_arc4_init,
426bcb508   Eric Biggers   crypto: arc4 - co...
66
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
67
68
69
  
  static int __init arc4_init(void)
  {
611a23c2d   Ard Biesheuvel   crypto: arc4 - re...
70
  	return crypto_register_skcipher(&arc4_alg);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
71
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
72
73
  static void __exit arc4_exit(void)
  {
611a23c2d   Ard Biesheuvel   crypto: arc4 - re...
74
  	crypto_unregister_skcipher(&arc4_alg);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
75
  }
c4741b230   Eric Biggers   crypto: run initc...
76
  subsys_initcall(arc4_init);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
77
78
79
80
81
  module_exit(arc4_exit);
  
  MODULE_LICENSE("GPL");
  MODULE_DESCRIPTION("ARC4 Cipher Algorithm");
  MODULE_AUTHOR("Jon Oberheide <jon@oberheide.org>");
611a23c2d   Ard Biesheuvel   crypto: arc4 - re...
82
  MODULE_ALIAS_CRYPTO("ecb(arc4)");