Blame view

arch/arm/crypto/sha1-ce-glue.c 2.17 KB
d2912cb15   Thomas Gleixner   treewide: Replace...
1
  // SPDX-License-Identifier: GPL-2.0-only
864cbeed4   Ard Biesheuvel   crypto: arm - add...
2
3
4
5
  /*
   * sha1-ce-glue.c - SHA-1 secure hash using ARMv8 Crypto Extensions
   *
   * Copyright (C) 2015 Linaro Ltd <ard.biesheuvel@linaro.org>
864cbeed4   Ard Biesheuvel   crypto: arm - add...
6
7
8
   */
  
  #include <crypto/internal/hash.h>
99680c5e9   Eric Biggers   crypto: arm - con...
9
  #include <crypto/internal/simd.h>
864cbeed4   Ard Biesheuvel   crypto: arm - add...
10
  #include <crypto/sha.h>
dde00981e   Ard Biesheuvel   crypto: arm/sha1-...
11
  #include <crypto/sha1_base.h>
bd56f95ea   Ard Biesheuvel   crypto: arm/sha1-...
12
  #include <linux/cpufeature.h>
864cbeed4   Ard Biesheuvel   crypto: arm - add...
13
14
  #include <linux/crypto.h>
  #include <linux/module.h>
864cbeed4   Ard Biesheuvel   crypto: arm - add...
15
16
17
  #include <asm/hwcap.h>
  #include <asm/neon.h>
  #include <asm/simd.h>
864cbeed4   Ard Biesheuvel   crypto: arm - add...
18

90451d6bd   Ard Biesheuvel   crypto: arm/sha1 ...
19
  #include "sha1.h"
864cbeed4   Ard Biesheuvel   crypto: arm - add...
20
21
22
  MODULE_DESCRIPTION("SHA1 secure hash using ARMv8 Crypto Extensions");
  MODULE_AUTHOR("Ard Biesheuvel <ard.biesheuvel@linaro.org>");
  MODULE_LICENSE("GPL v2");
dde00981e   Ard Biesheuvel   crypto: arm/sha1-...
23
24
  asmlinkage void sha1_ce_transform(struct sha1_state *sst, u8 const *src,
  				  int blocks);
864cbeed4   Ard Biesheuvel   crypto: arm - add...
25

dde00981e   Ard Biesheuvel   crypto: arm/sha1-...
26
27
  static int sha1_ce_update(struct shash_desc *desc, const u8 *data,
  			  unsigned int len)
864cbeed4   Ard Biesheuvel   crypto: arm - add...
28
29
  {
  	struct sha1_state *sctx = shash_desc_ctx(desc);
99680c5e9   Eric Biggers   crypto: arm - con...
30
  	if (!crypto_simd_usable() ||
dde00981e   Ard Biesheuvel   crypto: arm/sha1-...
31
  	    (sctx->count % SHA1_BLOCK_SIZE) + len < SHA1_BLOCK_SIZE)
864cbeed4   Ard Biesheuvel   crypto: arm - add...
32
  		return sha1_update_arm(desc, data, len);
dde00981e   Ard Biesheuvel   crypto: arm/sha1-...
33
34
35
  	kernel_neon_begin();
  	sha1_base_do_update(desc, data, len, sha1_ce_transform);
  	kernel_neon_end();
864cbeed4   Ard Biesheuvel   crypto: arm - add...
36

864cbeed4   Ard Biesheuvel   crypto: arm - add...
37
38
  	return 0;
  }
dde00981e   Ard Biesheuvel   crypto: arm/sha1-...
39
40
  static int sha1_ce_finup(struct shash_desc *desc, const u8 *data,
  			 unsigned int len, u8 *out)
864cbeed4   Ard Biesheuvel   crypto: arm - add...
41
  {
99680c5e9   Eric Biggers   crypto: arm - con...
42
  	if (!crypto_simd_usable())
dde00981e   Ard Biesheuvel   crypto: arm/sha1-...
43
  		return sha1_finup_arm(desc, data, len, out);
864cbeed4   Ard Biesheuvel   crypto: arm - add...
44

dde00981e   Ard Biesheuvel   crypto: arm/sha1-...
45
46
47
48
49
  	kernel_neon_begin();
  	if (len)
  		sha1_base_do_update(desc, data, len, sha1_ce_transform);
  	sha1_base_do_finalize(desc, sha1_ce_transform);
  	kernel_neon_end();
864cbeed4   Ard Biesheuvel   crypto: arm - add...
50

dde00981e   Ard Biesheuvel   crypto: arm/sha1-...
51
  	return sha1_base_finish(desc, out);
864cbeed4   Ard Biesheuvel   crypto: arm - add...
52
  }
dde00981e   Ard Biesheuvel   crypto: arm/sha1-...
53
  static int sha1_ce_final(struct shash_desc *desc, u8 *out)
864cbeed4   Ard Biesheuvel   crypto: arm - add...
54
  {
dde00981e   Ard Biesheuvel   crypto: arm/sha1-...
55
  	return sha1_ce_finup(desc, NULL, 0, out);
864cbeed4   Ard Biesheuvel   crypto: arm - add...
56
57
58
  }
  
  static struct shash_alg alg = {
dde00981e   Ard Biesheuvel   crypto: arm/sha1-...
59
60
61
62
  	.init			= sha1_base_init,
  	.update			= sha1_ce_update,
  	.final			= sha1_ce_final,
  	.finup			= sha1_ce_finup,
864cbeed4   Ard Biesheuvel   crypto: arm - add...
63
64
  	.descsize		= sizeof(struct sha1_state),
  	.digestsize		= SHA1_DIGEST_SIZE,
864cbeed4   Ard Biesheuvel   crypto: arm - add...
65
66
67
68
  	.base			= {
  		.cra_name		= "sha1",
  		.cra_driver_name	= "sha1-ce",
  		.cra_priority		= 200,
864cbeed4   Ard Biesheuvel   crypto: arm - add...
69
70
71
72
73
74
75
  		.cra_blocksize		= SHA1_BLOCK_SIZE,
  		.cra_module		= THIS_MODULE,
  	}
  };
  
  static int __init sha1_ce_mod_init(void)
  {
864cbeed4   Ard Biesheuvel   crypto: arm - add...
76
77
78
79
80
81
82
  	return crypto_register_shash(&alg);
  }
  
  static void __exit sha1_ce_mod_fini(void)
  {
  	crypto_unregister_shash(&alg);
  }
bd56f95ea   Ard Biesheuvel   crypto: arm/sha1-...
83
  module_cpu_feature_match(SHA1, sha1_ce_mod_init);
864cbeed4   Ard Biesheuvel   crypto: arm - add...
84
  module_exit(sha1_ce_mod_fini);