]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
crypto: sha256 - Make lib/crypto/sha256.c suitable for generic use
authorHans de Goede <hdegoede@redhat.com>
Sat, 17 Aug 2019 14:24:33 +0000 (16:24 +0200)
committerHerbert Xu <herbert@gondor.apana.org.au>
Thu, 22 Aug 2019 04:57:35 +0000 (14:57 +1000)
Before this commit lib/crypto/sha256.c has only been used in the s390 and
x86 purgatory code, make it suitable for generic use:

* Export interesting symbols
* Add  -D__DISABLE_EXPORTS to CFLAGS_sha256.o for purgatory builds to
  avoid the exports for the purgatory builds
* Add to lib/crypto/Makefile and crypto/Kconfig

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
arch/s390/purgatory/Makefile
arch/x86/purgatory/Makefile
crypto/Kconfig
include/crypto/sha256.h
lib/crypto/Makefile
lib/crypto/sha256.c

index 85b05c9e40f54687e6cbe0b8fbbe2fa0aff25e96..bc0d7a0d039453d28464432c2d74994b827b4c1d 100644 (file)
@@ -10,6 +10,8 @@ PURGATORY_OBJS = $(addprefix $(obj)/,$(purgatory-y))
 $(obj)/sha256.o: $(srctree)/lib/crypto/sha256.c FORCE
        $(call if_changed_rule,cc_o_c)
 
+CFLAGS_sha256.o := -D__DISABLE_EXPORTS
+
 $(obj)/mem.o: $(srctree)/arch/s390/lib/mem.S FORCE
        $(call if_changed_rule,as_o_S)
 
index 026fa0006f0bf9ad59bdff10ba6e8d10ae0a1c29..ea86982aba270fe2461b7ab091e4a2a789c7ca9f 100644 (file)
@@ -9,6 +9,8 @@ PURGATORY_OBJS = $(addprefix $(obj)/,$(purgatory-y))
 $(obj)/sha256.o: $(srctree)/lib/crypto/sha256.c FORCE
        $(call if_changed_rule,cc_o_c)
 
+CFLAGS_sha256.o := -D__DISABLE_EXPORTS
+
 LDFLAGS_purgatory.ro := -e purgatory_start -r --no-undefined -nostdlib -z nodefaultlib
 targets += purgatory.ro
 
index 42a17fe977034171851bf96d25d5a31cab3f71b2..e96b321b51af11dc68113cc27a457971d9ccd619 100644 (file)
@@ -849,6 +849,9 @@ config CRYPTO_SHA1_PPC_SPE
          SHA-1 secure hash standard (DFIPS 180-4) implemented
          using powerpc SPE SIMD instruction set.
 
+config CRYPTO_LIB_SHA256
+       tristate
+
 config CRYPTO_SHA256
        tristate "SHA224 and SHA256 digest algorithm"
        select CRYPTO_HASH
index b1f9c6781082c920351810dfc3918033f6c9dfbf..9cbb3589b8b366e3bdcc7142b50921232e73bc8a 100644 (file)
@@ -14,8 +14,9 @@
 /*
  * Stand-alone implementation of the SHA256 algorithm. It is designed to
  * have as little dependencies as possible so it can be used in the
- * kexec_file purgatory. In other cases you should use the implementation in
- * crypto/.
+ * kexec_file purgatory. In other cases you should generally use the
+ * hash APIs from include/crypto/hash.h. Especially when hashing large
+ * amounts of data as those APIs may be hw-accelerated.
  *
  * For details see lib/crypto/sha256.c
  */
index 101a321b8a99e26d9d75b5a6dd122e5ecd37c4b2..cbe0b6a6450d7536a942c9343b808a1665129886 100644 (file)
@@ -8,3 +8,6 @@ libarc4-y := arc4.o
 
 obj-$(CONFIG_CRYPTO_LIB_DES) += libdes.o
 libdes-y := des.o
+
+obj-$(CONFIG_CRYPTO_LIB_SHA256) += libsha256.o
+libsha256-y := sha256.o
index 1458a20d53a583a4d360bad58075965fa56fc96f..f2ed75ae691009ad1af00f43ad77e2d31b853c8e 100644 (file)
@@ -12,6 +12,7 @@
  */
 
 #include <linux/bitops.h>
+#include <linux/export.h>
 #include <linux/string.h>
 #include <crypto/sha256.h>
 #include <asm/unaligned.h>
@@ -218,6 +219,7 @@ int sha256_init(struct sha256_state *sctx)
 
        return 0;
 }
+EXPORT_SYMBOL(sha256_init);
 
 int sha256_update(struct sha256_state *sctx, const u8 *data, unsigned int len)
 {
@@ -248,6 +250,7 @@ int sha256_update(struct sha256_state *sctx, const u8 *data, unsigned int len)
 
        return 0;
 }
+EXPORT_SYMBOL(sha256_update);
 
 int sha256_final(struct sha256_state *sctx, u8 *out)
 {
@@ -277,3 +280,4 @@ int sha256_final(struct sha256_state *sctx, u8 *out)
 
        return 0;
 }
+EXPORT_SYMBOL(sha256_final);