From 5d0456c06f23b9afb2a28e3e03398157263d400e Mon Sep 17 00:00:00 2001
From: Nikos Mavrogiannopoulos <nmav@redhat.com>
Date: Tue, 12 Jun 2018 13:32:54 +0200
Subject: [PATCH 3/3] nettle_md5/sha1_compress are now part of API

These were exported for long time and are now part of existing
software.

Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
---
 arm/fat/sha1-compress-2.asm     |  2 +-
 arm/v6/sha1-compress.asm        |  6 +++---
 examples/nettle-benchmark.c     |  2 +-
 fat-arm.c                       |  8 ++++----
 fat-setup.h                     |  3 +++
 fat-x86_64.c                    | 12 ++++++------
 libnettle.map.in                |  4 ++--
 md5-compress.c                  |  2 +-
 md5.c                           |  4 ++--
 md5.h                           |  3 ++-
 sha1-compress.c                 |  6 +++---
 sha1.c                          |  4 ++--
 sha1.h                          |  3 ++-
 testsuite/md5-test.c            |  2 +-
 x86/md5-compress.asm            |  6 +++---
 x86/sha1-compress.asm           |  6 +++---
 x86_64/md5-compress.asm         |  6 +++---
 x86_64/sha1-compress.asm        |  6 +++---
 x86_64/sha_ni/sha1-compress.asm |  6 +++---
 19 files changed, 48 insertions(+), 43 deletions(-)

diff --git a/arm/fat/sha1-compress-2.asm b/arm/fat/sha1-compress-2.asm
index c326befd..b915bb45 100644
--- a/arm/fat/sha1-compress-2.asm
+++ b/arm/fat/sha1-compress-2.asm
@@ -31,7 +31,7 @@ ifelse(<
    not, see http://www.gnu.org/licenses/.
 >)
 
-dnl PROLOGUE(_nettle_sha1_compress) picked up by configure
+dnl PROLOGUE(nettle_sha1_compress) picked up by configure
 
 define(<fat_transform>, <$1_armv6>)
 include_src(<arm/v6/sha1-compress.asm>)
diff --git a/arm/v6/sha1-compress.asm b/arm/v6/sha1-compress.asm
index 8cc22be7..f60b4230 100644
--- a/arm/v6/sha1-compress.asm
+++ b/arm/v6/sha1-compress.asm
@@ -101,7 +101,7 @@ define(<ROUND3>, <
 	ror	$2, $2, #2
 	add	$5, $5, T0
 >)
-	C void _nettle_sha1_compress(uint32_t *state, const uint8_t *input)
+	C void nettle_sha1_compress(uint32_t *state, const uint8_t *input)
 	
 	.text
 	.align 2
@@ -112,7 +112,7 @@ define(<ROUND3>, <
 .LK3:
 	.int	0x8F1BBCDC
 
-PROLOGUE(_nettle_sha1_compress)
+PROLOGUE(nettle_sha1_compress)
 	push	{r4,r5,r6,r7,r8,r10,lr}
 	sub	sp, sp, #64
 
@@ -246,7 +246,7 @@ IF_BE(<	rsb     SHIFT, SHIFT, #32>)
 	add	sp, sp, #64
 	stm	STATE, {SA,SB,SC,SD,SE}
 	pop	{r4,r5,r6,r7,r8,r10,pc}	
-EPILOGUE(_nettle_sha1_compress)
+EPILOGUE(nettle_sha1_compress)
 
 .LK4:
 	.int	0xCA62C1D6
diff --git a/examples/nettle-benchmark.c b/examples/nettle-benchmark.c
index 61f1a7ba..5a88e72d 100644
--- a/examples/nettle-benchmark.c
+++ b/examples/nettle-benchmark.c
@@ -718,7 +718,7 @@ bench_sha1_compress(void)
   uint8_t data[SHA1_BLOCK_SIZE];
   double t;
 
-  TIME_CYCLES (t, _nettle_sha1_compress(state, data));
+  TIME_CYCLES (t, nettle_sha1_compress(state, data));
 
   printf("sha1_compress: %.2f cycles\n", t);  
 }
diff --git a/fat-arm.c b/fat-arm.c
index d52b1439..a0f061a9 100644
--- a/fat-arm.c
+++ b/fat-arm.c
@@ -147,7 +147,7 @@ DECLARE_FAT_FUNC(_nettle_salsa20_core, salsa20_core_func)
 DECLARE_FAT_FUNC_VAR(salsa20_core, salsa20_core_func, c)
 DECLARE_FAT_FUNC_VAR(salsa20_core, salsa20_core_func, neon)
 
-DECLARE_FAT_FUNC(_nettle_sha1_compress, sha1_compress_func)
+DECLARE_FAT_FUNC(nettle_sha1_compress, sha1_compress_func)
 DECLARE_FAT_FUNC_VAR(sha1_compress, sha1_compress_func, c)
 DECLARE_FAT_FUNC_VAR(sha1_compress, sha1_compress_func, armv6)
 
@@ -191,7 +191,7 @@ fat_init (void)
 	fprintf (stderr, "libnettle: enabling armv6 code.\n");
       _nettle_aes_encrypt_vec = _nettle_aes_encrypt_armv6;
       _nettle_aes_decrypt_vec = _nettle_aes_decrypt_armv6;
-      _nettle_sha1_compress_vec = _nettle_sha1_compress_armv6;
+      nettle_sha1_compress_vec = nettle_sha1_compress_armv6;
       _nettle_sha256_compress_vec = _nettle_sha256_compress_armv6;
     }
   else
@@ -200,7 +200,7 @@ fat_init (void)
 	fprintf (stderr, "libnettle: not enabling armv6 code.\n");
       _nettle_aes_encrypt_vec = _nettle_aes_encrypt_arm;
       _nettle_aes_decrypt_vec = _nettle_aes_decrypt_arm;
-      _nettle_sha1_compress_vec = _nettle_sha1_compress_c;
+      nettle_sha1_compress_vec = nettle_sha1_compress_c;
       _nettle_sha256_compress_vec = _nettle_sha256_compress_c;
     }
   if (features.have_neon)
@@ -243,7 +243,7 @@ DEFINE_FAT_FUNC(_nettle_salsa20_core, void,
 		(uint32_t *dst, const uint32_t *src, unsigned rounds),
 		(dst, src, rounds))
 
-DEFINE_FAT_FUNC(_nettle_sha1_compress, void,
+DEFINE_FAT_FUNC(nettle_sha1_compress, void,
 		(uint32_t *state, const uint8_t *input),
 		(state, input))
 
diff --git a/fat-setup.h b/fat-setup.h
index eb7166a7..2b3b14fd 100644
--- a/fat-setup.h
+++ b/fat-setup.h
@@ -152,6 +152,9 @@
 #define DECLARE_FAT_FUNC_VAR(name, type, var)	\
        type _nettle_##name##_##var;
 
+#define DECLARE_FAT_FUNC_VAR_EXP(name, type, var)	\
+       type nettle_##name##_##var;
+
 typedef void void_func (void);
 
 typedef void aes_crypt_internal_func (unsigned rounds, const uint32_t *keys,
diff --git a/fat-x86_64.c b/fat-x86_64.c
index b66d0861..3f5fee52 100644
--- a/fat-x86_64.c
+++ b/fat-x86_64.c
@@ -123,9 +123,9 @@ DECLARE_FAT_FUNC(nettle_memxor, memxor_func)
 DECLARE_FAT_FUNC_VAR(memxor, memxor_func, x86_64)
 DECLARE_FAT_FUNC_VAR(memxor, memxor_func, sse2)
 
-DECLARE_FAT_FUNC(_nettle_sha1_compress, sha1_compress_func)
-DECLARE_FAT_FUNC_VAR(sha1_compress, sha1_compress_func, x86_64)
-DECLARE_FAT_FUNC_VAR(sha1_compress, sha1_compress_func, sha_ni)
+DECLARE_FAT_FUNC(nettle_sha1_compress, sha1_compress_func)
+DECLARE_FAT_FUNC_VAR_EXP(sha1_compress, sha1_compress_func, x86_64)
+DECLARE_FAT_FUNC_VAR_EXP(sha1_compress, sha1_compress_func, sha_ni)
 
 DECLARE_FAT_FUNC(_nettle_sha256_compress, sha256_compress_func)
 DECLARE_FAT_FUNC_VAR(sha256_compress, sha256_compress_func, x86_64)
@@ -175,14 +175,14 @@ fat_init (void)
     {
       if (verbose)
 	fprintf (stderr, "libnettle: using sha_ni instructions.\n");
-      _nettle_sha1_compress_vec = _nettle_sha1_compress_sha_ni;
+      nettle_sha1_compress_vec = nettle_sha1_compress_sha_ni;
       _nettle_sha256_compress_vec = _nettle_sha256_compress_sha_ni;
     }
   else
     {
       if (verbose)
 	fprintf (stderr, "libnettle: not using sha_ni instructions.\n");
-      _nettle_sha1_compress_vec = _nettle_sha1_compress_x86_64;
+      nettle_sha1_compress_vec = nettle_sha1_compress_x86_64;
       _nettle_sha256_compress_vec = _nettle_sha256_compress_x86_64;
     }
   if (features.vendor == X86_INTEL)
@@ -217,7 +217,7 @@ DEFINE_FAT_FUNC(nettle_memxor, void *,
 		(void *dst, const void *src, size_t n),
 		(dst, src, n))
 
-DEFINE_FAT_FUNC(_nettle_sha1_compress, void,
+DEFINE_FAT_FUNC(nettle_sha1_compress, void,
 		(uint32_t *state, const uint8_t *input),
 		(state, input))
 
diff --git a/libnettle.map.in b/libnettle.map.in
index 01902f79..f6537b13 100644
--- a/libnettle.map.in
+++ b/libnettle.map.in
@@ -279,7 +279,7 @@ NETTLE_@LIBNETTLE_MAJOR@
     nettle_md5_digest;
     nettle_md5_init;
     nettle_md5_update;
-    _nettle_md5_compress;
+    nettle_md5_compress;
     nettle_MD5Final;
     nettle_MD5Init;
     nettle_MD5Update;
@@ -316,7 +316,7 @@ NETTLE_@LIBNETTLE_MAJOR@
     nettle_sha1_digest;
     nettle_sha1_init;
     nettle_sha1_update;
-    _nettle_sha1_compress;
+    nettle_sha1_compress;
     nettle_sha1;
     nettle_sha224_digest;
     nettle_sha224_init;
diff --git a/md5-compress.c b/md5-compress.c
index dab33e30..6fe3256e 100644
--- a/md5-compress.c
+++ b/md5-compress.c
@@ -79,7 +79,7 @@
  * (_MD5_DIGEST_LENGTH) words. */
 
 void
-_nettle_md5_compress(uint32_t *digest, const uint8_t *input)
+nettle_md5_compress(uint32_t *digest, const uint8_t *input)
 {
   uint32_t data[MD5_DATA_LENGTH];
   uint32_t a, b, c, d;
diff --git a/md5.c b/md5.c
index 142b112e..cc009b4a 100644
--- a/md5.c
+++ b/md5.c
@@ -61,7 +61,7 @@ md5_init(struct md5_ctx *ctx)
   ctx->index = 0;
 }
 
-#define COMPRESS(ctx, data) (_nettle_md5_compress((ctx)->state, (data)))
+#define COMPRESS(ctx, data) (nettle_md5_compress((ctx)->state, (data)))
 
 void
 md5_update(struct md5_ctx *ctx,
@@ -86,7 +86,7 @@ md5_digest(struct md5_ctx *ctx,
   bit_count = (ctx->count << 9) | (ctx->index << 3);
 
   LE_WRITE_UINT64(ctx->block + (MD5_BLOCK_SIZE - 8), bit_count);
-  _nettle_md5_compress(ctx->state, ctx->block);
+  nettle_md5_compress(ctx->state, ctx->block);
 
   _nettle_write_le32(length, digest, ctx->state);
   md5_init(ctx);
diff --git a/md5.h b/md5.h
index 040cf9de..c7b82810 100644
--- a/md5.h
+++ b/md5.h
@@ -76,8 +76,9 @@ md5_digest(struct md5_ctx *ctx,
 
 /* Internal compression function. STATE points to 4 uint32_t words,
    and DATA points to 64 bytes of input data, possibly unaligned. */
+#define _nettle_md5_compress nettle_md5_compress
 void
-_nettle_md5_compress(uint32_t *state, const uint8_t *data);
+nettle_md5_compress(uint32_t *state, const uint8_t *data);
 
 #ifdef __cplusplus
 }
diff --git a/sha1-compress.c b/sha1-compress.c
index 377b9c1e..dac376d6 100644
--- a/sha1-compress.c
+++ b/sha1-compress.c
@@ -132,8 +132,8 @@
 /* For fat builds */
 #if HAVE_NATIVE_sha1_compress
 void
-_nettle_sha1_compress_c(uint32_t *state, const uint8_t *input);
-#define _nettle_sha1_compress _nettle_sha1_compress_c
+nettle_sha1_compress_c(uint32_t *state, const uint8_t *input);
+#define nettle_sha1_compress nettle_sha1_compress_c
 #endif
 
 /* Perform the SHA transformation.  Note that this code, like MD5, seems to
@@ -142,7 +142,7 @@ _nettle_sha1_compress_c(uint32_t *state, const uint8_t *input);
    sections, e.g. based on the four subrounds. */
 
 void
-_nettle_sha1_compress(uint32_t *state, const uint8_t *input)
+nettle_sha1_compress(uint32_t *state, const uint8_t *input)
 {
   uint32_t data[SHA1_DATA_LENGTH];
   uint32_t A, B, C, D, E;     /* Local vars */
diff --git a/sha1.c b/sha1.c
index a585727e..af73096c 100644
--- a/sha1.c
+++ b/sha1.c
@@ -68,7 +68,7 @@ sha1_init(struct sha1_ctx *ctx)
   ctx->index = 0;
 }
 
-#define COMPRESS(ctx, data) (_nettle_sha1_compress((ctx)->state, data))
+#define COMPRESS(ctx, data) (nettle_sha1_compress((ctx)->state, data))
 
 void
 sha1_update(struct sha1_ctx *ctx,
@@ -93,7 +93,7 @@ sha1_digest(struct sha1_ctx *ctx,
 
   /* append the 64 bit count */
   WRITE_UINT64(ctx->block + (SHA1_BLOCK_SIZE - 8), bit_count);
-  _nettle_sha1_compress(ctx->state, ctx->block);
+  nettle_sha1_compress(ctx->state, ctx->block);
 
   _nettle_write_be32(length, digest, ctx->state);
   sha1_init(ctx);
diff --git a/sha1.h b/sha1.h
index 7500d0c2..410812f5 100644
--- a/sha1.h
+++ b/sha1.h
@@ -78,8 +78,9 @@ sha1_digest(struct sha1_ctx *ctx,
 
 /* Internal compression function. STATE points to 5 uint32_t words,
    and DATA points to 64 bytes of input data, possibly unaligned. */
+#define _nettle_sha1_compress nettle_sha1_compress
 void
-_nettle_sha1_compress(uint32_t *state, const uint8_t *data);
+nettle_sha1_compress(uint32_t *state, const uint8_t *data);
 
 #ifdef __cplusplus
 }
diff --git a/testsuite/md5-test.c b/testsuite/md5-test.c
index 37c2fb15..ebf3e085 100644
--- a/testsuite/md5-test.c
+++ b/testsuite/md5-test.c
@@ -95,7 +95,7 @@ test_main(void)
 	    SHEX(M1 N3), SHEX(H1));
 }
 
-/* Intermediate values for the single _nettle_md5_compress call for
+/* Intermediate values for the single nettle_md5_compress call for
    the first test case. Each row gives the values for a, b, c, d after
    the i:th round. The row i = -1 gives the initial values, and i = 99
    gives the output values.
diff --git a/x86/md5-compress.asm b/x86/md5-compress.asm
index 98814119..c849c082 100644
--- a/x86/md5-compress.asm
+++ b/x86/md5-compress.asm
@@ -78,11 +78,11 @@ define(<ROUND>,<
 
 	.file "md5-compress.asm"
 
-	C _nettle_md5_compress(uint32_t *state, uint8_t *data)
+	C nettle_md5_compress(uint32_t *state, uint8_t *data)
 	
 	.text
 	ALIGN(16)
-PROLOGUE(_nettle_md5_compress)
+PROLOGUE(nettle_md5_compress)
 	C save all registers that need to be saved
 
 				C  24(%esp)  input
@@ -184,4 +184,4 @@ PROLOGUE(_nettle_md5_compress)
 	popl	%ebp
 	popl	%ebx
 	ret
-EPILOGUE(_nettle_md5_compress)
+EPILOGUE(nettle_md5_compress)
diff --git a/x86/sha1-compress.asm b/x86/sha1-compress.asm
index d829de82..03bdcdc9 100644
--- a/x86/sha1-compress.asm
+++ b/x86/sha1-compress.asm
@@ -155,11 +155,11 @@ define(<ROUND_F3>, <
 
 	.file "sha1-compress.asm"
 
-	C _nettle_sha1_compress(uint32_t *state, uint8_t *data)
+	C nettle_sha1_compress(uint32_t *state, uint8_t *data)
 	
 	.text
 
-PROLOGUE(_nettle_sha1_compress)
+PROLOGUE(nettle_sha1_compress)
 	C save all registers that need to be saved
 	C 			   88(%esp)  data
 	C 			   84(%esp)  state
@@ -1540,7 +1540,7 @@ C 	ROUND_F2(SB, SC, SD, SE, SA, 79, K4VALUE)
 	popl	%ebp
 	popl	%ebx
 	ret
-EPILOGUE(_nettle_sha1_compress)
+EPILOGUE(nettle_sha1_compress)
 
 C TODO:
 
diff --git a/x86_64/md5-compress.asm b/x86_64/md5-compress.asm
index 49cc3385..182b8f18 100644
--- a/x86_64/md5-compress.asm
+++ b/x86_64/md5-compress.asm
@@ -79,10 +79,10 @@ define(<ROUND>,<
 
 	.file "md5-compress.asm"
 
-	C _nettle_md5_compress(uint32_t *state, uint8_t *input)
+	C nettle_md5_compress(uint32_t *state, uint8_t *input)
 	.text
 	ALIGN(16)
-PROLOGUE(_nettle_md5_compress)
+PROLOGUE(nettle_md5_compress)
 	W64_ENTRY(2,0)
 	C save all registers that need to be saved
 	push	%rbp
@@ -173,4 +173,4 @@ PROLOGUE(_nettle_md5_compress)
 	W64_EXIT(2,0)
 
 	ret
-EPILOGUE(_nettle_md5_compress)
+EPILOGUE(nettle_md5_compress)
diff --git a/x86_64/sha1-compress.asm b/x86_64/sha1-compress.asm
index e48a13c3..dd48de0e 100644
--- a/x86_64/sha1-compress.asm
+++ b/x86_64/sha1-compress.asm
@@ -171,11 +171,11 @@ define(<ROUND_F3>, <
 
 	.file "sha1-compress.asm"
 
-	C _nettle_sha1_compress(uint32_t *state, uint8_t *input)
+	C nettle_sha1_compress(uint32_t *state, uint8_t *input)
 	
 	.text
 	ALIGN(16)
-PROLOGUE(_nettle_sha1_compress)
+PROLOGUE(nettle_sha1_compress)
 	C save all registers that need to be saved
 	W64_ENTRY(2, 0)
 	
@@ -304,4 +304,4 @@ PROLOGUE(_nettle_sha1_compress)
 	add	$64, %rsp
 	W64_EXIT(2, 0)
 	ret
-EPILOGUE(_nettle_sha1_compress)
+EPILOGUE(nettle_sha1_compress)
diff --git a/x86_64/sha_ni/sha1-compress.asm b/x86_64/sha_ni/sha1-compress.asm
index f0097eef..ab848fdd 100644
--- a/x86_64/sha_ni/sha1-compress.asm
+++ b/x86_64/sha_ni/sha1-compress.asm
@@ -59,13 +59,13 @@ define(<QROUND>, <
 
 	.file "sha1-compress.asm"
 
-	C _nettle_sha1_compress(uint32_t *state, uint8_t *input)
+	C nettle_sha1_compress(uint32_t *state, uint8_t *input)
 
 	.text
 	ALIGN(16)
 .Lswap_mask:
 	.byte 15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0
-PROLOGUE(_nettle_sha1_compress)
+PROLOGUE(nettle_sha1_compress)
 	C save all registers that need to be saved
 	W64_ENTRY(2, 10)
 	movups	(STATE), ABCD
@@ -145,4 +145,4 @@ PROLOGUE(_nettle_sha1_compress)
 
 	W64_EXIT(2, 10)
 	ret
-EPILOGUE(_nettle_sha1_compress)
+EPILOGUE(nettle_sha1_compress)
-- 
2.17.0

