Blame view

crypto/sha1_generic.c 2.34 KB
2874c5fd2   Thomas Gleixner   treewide: Replace...
1
  // SPDX-License-Identifier: GPL-2.0-or-later
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2
3
4
5
6
7
8
9
10
11
12
  /*
   * Cryptographic API.
   *
   * SHA1 Secure Hash Algorithm.
   *
   * Derived from cryptoapi implementation, adapted for in-place
   * scatterlist interface.
   *
   * Copyright (c) Alan Smithee.
   * Copyright (c) Andrew McDonald <andrew@mcdonald.org.uk>
   * Copyright (c) Jean-Francois Dive <jef@linuxbe.org>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
13
   */
54ccb3677   Adrian-Ken Rueegsegger   crypto: sha1 - Sw...
14
  #include <crypto/internal/hash.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
15
16
17
  #include <linux/init.h>
  #include <linux/module.h>
  #include <linux/mm.h>
06ace7a9b   Herbert Xu   [CRYPTO] Use stan...
18
  #include <linux/types.h>
5265eeb2b   Jan Glauber   [CRYPTO] sha: Add...
19
  #include <crypto/sha.h>
7c71f0f76   Ard Biesheuvel   crypto: sha1-gene...
20
  #include <crypto/sha1_base.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
21
  #include <asm/byteorder.h>
0c4c78de0   LABBE Corentin   crypto: hash - ad...
22
23
24
25
26
27
  const u8 sha1_zero_message_hash[SHA1_DIGEST_SIZE] = {
  	0xda, 0x39, 0xa3, 0xee, 0x5e, 0x6b, 0x4b, 0x0d,
  	0x32, 0x55, 0xbf, 0xef, 0x95, 0x60, 0x18, 0x90,
  	0xaf, 0xd8, 0x07, 0x09
  };
  EXPORT_SYMBOL_GPL(sha1_zero_message_hash);
7c71f0f76   Ard Biesheuvel   crypto: sha1-gene...
28
29
  static void sha1_generic_block_fn(struct sha1_state *sst, u8 const *src,
  				  int blocks)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
30
  {
6b0b0fa2b   Eric Biggers   crypto: lib/sha1 ...
31
  	u32 temp[SHA1_WORKSPACE_WORDS];
54ccb3677   Adrian-Ken Rueegsegger   crypto: sha1 - Sw...
32

7c71f0f76   Ard Biesheuvel   crypto: sha1-gene...
33
  	while (blocks--) {
6b0b0fa2b   Eric Biggers   crypto: lib/sha1 ...
34
  		sha1_transform(sst->state, src, temp);
7c71f0f76   Ard Biesheuvel   crypto: sha1-gene...
35
36
37
  		src += SHA1_BLOCK_SIZE;
  	}
  	memzero_explicit(temp, sizeof(temp));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
38
  }
7c390170b   Mathias Krause   crypto: sha1 - ex...
39
  int crypto_sha1_update(struct shash_desc *desc, const u8 *data,
7c71f0f76   Ard Biesheuvel   crypto: sha1-gene...
40
  		       unsigned int len)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
41
  {
7c71f0f76   Ard Biesheuvel   crypto: sha1-gene...
42
  	return sha1_base_do_update(desc, data, len, sha1_generic_block_fn);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
43
  }
7c390170b   Mathias Krause   crypto: sha1 - ex...
44
  EXPORT_SYMBOL(crypto_sha1_update);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
45

54ccb3677   Adrian-Ken Rueegsegger   crypto: sha1 - Sw...
46
  static int sha1_final(struct shash_desc *desc, u8 *out)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
47
  {
7c71f0f76   Ard Biesheuvel   crypto: sha1-gene...
48
49
  	sha1_base_do_finalize(desc, sha1_generic_block_fn);
  	return sha1_base_finish(desc, out);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
50
  }
7c71f0f76   Ard Biesheuvel   crypto: sha1-gene...
51
52
  int crypto_sha1_finup(struct shash_desc *desc, const u8 *data,
  		      unsigned int len, u8 *out)
e2a7ce4e1   Herbert Xu   crypto: sha1_gene...
53
  {
7c71f0f76   Ard Biesheuvel   crypto: sha1-gene...
54
55
  	sha1_base_do_update(desc, data, len, sha1_generic_block_fn);
  	return sha1_final(desc, out);
e2a7ce4e1   Herbert Xu   crypto: sha1_gene...
56
  }
7c71f0f76   Ard Biesheuvel   crypto: sha1-gene...
57
  EXPORT_SYMBOL(crypto_sha1_finup);
e2a7ce4e1   Herbert Xu   crypto: sha1_gene...
58

54ccb3677   Adrian-Ken Rueegsegger   crypto: sha1 - Sw...
59
60
  static struct shash_alg alg = {
  	.digestsize	=	SHA1_DIGEST_SIZE,
7c71f0f76   Ard Biesheuvel   crypto: sha1-gene...
61
  	.init		=	sha1_base_init,
7c390170b   Mathias Krause   crypto: sha1 - ex...
62
  	.update		=	crypto_sha1_update,
54ccb3677   Adrian-Ken Rueegsegger   crypto: sha1 - Sw...
63
  	.final		=	sha1_final,
7c71f0f76   Ard Biesheuvel   crypto: sha1-gene...
64
  	.finup		=	crypto_sha1_finup,
e2a7ce4e1   Herbert Xu   crypto: sha1_gene...
65
  	.descsize	=	sizeof(struct sha1_state),
54ccb3677   Adrian-Ken Rueegsegger   crypto: sha1 - Sw...
66
67
68
  	.base		=	{
  		.cra_name	=	"sha1",
  		.cra_driver_name=	"sha1-generic",
90ef3e483   Eric Biggers   crypto: sha1_gene...
69
  		.cra_priority	=	100,
54ccb3677   Adrian-Ken Rueegsegger   crypto: sha1 - Sw...
70
71
72
  		.cra_blocksize	=	SHA1_BLOCK_SIZE,
  		.cra_module	=	THIS_MODULE,
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
73
  };
3af5b90bd   Kamalesh Babulal   [CRYPTO] all: Cle...
74
  static int __init sha1_generic_mod_init(void)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
75
  {
54ccb3677   Adrian-Ken Rueegsegger   crypto: sha1 - Sw...
76
  	return crypto_register_shash(&alg);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
77
  }
3af5b90bd   Kamalesh Babulal   [CRYPTO] all: Cle...
78
  static void __exit sha1_generic_mod_fini(void)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
79
  {
54ccb3677   Adrian-Ken Rueegsegger   crypto: sha1 - Sw...
80
  	crypto_unregister_shash(&alg);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
81
  }
c4741b230   Eric Biggers   crypto: run initc...
82
  subsys_initcall(sha1_generic_mod_init);
3af5b90bd   Kamalesh Babulal   [CRYPTO] all: Cle...
83
  module_exit(sha1_generic_mod_fini);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
84
85
86
  
  MODULE_LICENSE("GPL");
  MODULE_DESCRIPTION("SHA1 Secure Hash Algorithm");
b3be9a6d9   Michal Ludvig   [CRYPTO] sha: Add...
87

5d26a105b   Kees Cook   crypto: prefix mo...
88
  MODULE_ALIAS_CRYPTO("sha1");
3e14dcf7c   Mathias Krause   crypto: add missi...
89
  MODULE_ALIAS_CRYPTO("sha1-generic");