Blame view

crypto/arc4.c 1.81 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
14
  #include <crypto/internal/skcipher.h>
  #include <linux/init.h>
  #include <linux/module.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
15

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

dc51f2575   Ard Biesheuvel   crypto: arc4 - re...
21
  	return arc4_setkey(ctx, in_key, key_len);
ce6dd3689   Jussi Kivilinna   crypto: arc4 - im...
22
  }
611a23c2d   Ard Biesheuvel   crypto: arc4 - re...
23
  static int crypto_arc4_crypt(struct skcipher_request *req)
ce6dd3689   Jussi Kivilinna   crypto: arc4 - im...
24
  {
426bcb508   Eric Biggers   crypto: arc4 - co...
25
26
27
  	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...
28
  	int err;
426bcb508   Eric Biggers   crypto: arc4 - co...
29
  	err = skcipher_walk_virt(&walk, req, false);
ce6dd3689   Jussi Kivilinna   crypto: arc4 - im...
30
31
  
  	while (walk.nbytes > 0) {
426bcb508   Eric Biggers   crypto: arc4 - co...
32
33
34
  		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...
35
36
37
38
  	}
  
  	return err;
  }
611a23c2d   Ard Biesheuvel   crypto: arc4 - re...
39
40
41
42
43
  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...
44
  	.base.cra_name		=	"ecb(arc4)",
d6ebf5286   Eric Biggers   crypto: make all ...
45
  	.base.cra_driver_name	=	"ecb(arc4)-generic",
426bcb508   Eric Biggers   crypto: arc4 - co...
46
47
48
49
50
51
  	.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...
52
53
54
  	.setkey			=	crypto_arc4_setkey,
  	.encrypt		=	crypto_arc4_crypt,
  	.decrypt		=	crypto_arc4_crypt,
426bcb508   Eric Biggers   crypto: arc4 - co...
55
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
56
57
58
  
  static int __init arc4_init(void)
  {
611a23c2d   Ard Biesheuvel   crypto: arc4 - re...
59
  	return crypto_register_skcipher(&arc4_alg);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
60
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
61
62
  static void __exit arc4_exit(void)
  {
611a23c2d   Ard Biesheuvel   crypto: arc4 - re...
63
  	crypto_unregister_skcipher(&arc4_alg);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
64
  }
c4741b230   Eric Biggers   crypto: run initc...
65
  subsys_initcall(arc4_init);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
66
67
68
69
70
  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...
71
  MODULE_ALIAS_CRYPTO("ecb(arc4)");