Make low-level poly1305 functions that were marked as "internal" in
public header file really internal. Change their prefix from nettle to
_nettle.

Signed-off-by: Dmitry Baryshkov <[email protected]>
---
 chacha-poly1305.c            |  5 +--
 poly1305-aes.c               |  5 +--
 poly1305-internal.c          |  5 +--
 poly1305-internal.h          | 66 ++++++++++++++++++++++++++++++++++++
 poly1305.h                   | 14 --------
 x86_64/poly1305-internal.asm | 12 +++----
 6 files changed, 81 insertions(+), 26 deletions(-)
 create mode 100644 poly1305-internal.h

diff --git a/chacha-poly1305.c b/chacha-poly1305.c
index a15fef0cd742..47ca86bb360d 100644
--- a/chacha-poly1305.c
+++ b/chacha-poly1305.c
@@ -54,6 +54,7 @@
 
 #include "chacha-internal.h"
 #include "chacha-poly1305.h"
+#include "poly1305-internal.h"
 
 #include "macros.h"
 
@@ -80,7 +81,7 @@ chacha_poly1305_set_nonce (struct chacha_poly1305_ctx *ctx,
   chacha_set_nonce96 (&ctx->chacha, nonce);
   /* Generate authentication key */
   _chacha_core (u.x, ctx->chacha.state, CHACHA_ROUNDS);
-  poly1305_set_key (&ctx->poly1305, u.subkey);  
+  _poly1305_set_key (&ctx->poly1305, u.subkey);
   /* For final poly1305 processing */
   memcpy (ctx->s.b, u.subkey + 16, 16);
   /* Increment block count */
@@ -162,6 +163,6 @@ chacha_poly1305_digest (struct chacha_poly1305_ctx *ctx,
 
   _poly1305_block (&ctx->poly1305, buf, 1);
 
-  poly1305_digest (&ctx->poly1305, &ctx->s);
+  _poly1305_digest (&ctx->poly1305, &ctx->s);
   memcpy (digest, &ctx->s.b, length);
 }
diff --git a/poly1305-aes.c b/poly1305-aes.c
index 1a27b1d85523..85a6d2ae138b 100644
--- a/poly1305-aes.c
+++ b/poly1305-aes.c
@@ -38,13 +38,14 @@
 #include <string.h>
 
 #include "poly1305.h"
+#include "poly1305-internal.h"
 #include "macros.h"
 
 void
 poly1305_aes_set_key (struct poly1305_aes_ctx *ctx, const uint8_t * key)
 {
   aes128_set_encrypt_key(&ctx->aes, (key));
-  poly1305_set_key(&ctx->pctx, (key+16));
+  _poly1305_set_key(&ctx->pctx, (key+16));
   ctx->index = 0;
 }
 
@@ -82,7 +83,7 @@ poly1305_aes_digest (struct poly1305_aes_ctx *ctx,
     }
   aes128_encrypt(&ctx->aes, POLY1305_BLOCK_SIZE, s.b, ctx->nonce);
   
-  poly1305_digest (&ctx->pctx, &s);
+  _poly1305_digest (&ctx->pctx, &s);
   memcpy (digest, s.b, length);
 
   INCREMENT (16, ctx->nonce);
diff --git a/poly1305-internal.c b/poly1305-internal.c
index 2ee16807c514..8713fcb68894 100644
--- a/poly1305-internal.c
+++ b/poly1305-internal.c
@@ -63,6 +63,7 @@
 #include <string.h>
 
 #include "poly1305.h"
+#include "poly1305-internal.h"
 
 #include "macros.h"
 
@@ -85,7 +86,7 @@
 #define h4 hh
 
 void
-poly1305_set_key(struct poly1305_ctx *ctx, const uint8_t key[16])
+_poly1305_set_key(struct poly1305_ctx *ctx, const uint8_t key[16])
 {
   uint32_t t0,t1,t2,t3;
 
@@ -148,7 +149,7 @@ _poly1305_block (struct poly1305_ctx *ctx, const uint8_t 
*m, unsigned t4)
 
 /* Adds digest to the nonce */
 void
-poly1305_digest (struct poly1305_ctx *ctx, union nettle_block16 *s)
+_poly1305_digest (struct poly1305_ctx *ctx, union nettle_block16 *s)
 {
   uint32_t b, nb;
   uint64_t f0,f1,f2,f3;
diff --git a/poly1305-internal.h b/poly1305-internal.h
new file mode 100644
index 000000000000..edb80f7fa011
--- /dev/null
+++ b/poly1305-internal.h
@@ -0,0 +1,66 @@
+/* poly1305.h
+
+   Poly1305 message authentication code.
+
+   Copyright (C) 2013 Nikos Mavrogiannopoulos
+   Copyright (C) 2013, 2014 Niels Möller
+
+   This file is part of GNU Nettle.
+
+   GNU Nettle is free software: you can redistribute it and/or
+   modify it under the terms of either:
+
+     * the GNU Lesser General Public License as published by the Free
+       Software Foundation; either version 3 of the License, or (at your
+       option) any later version.
+
+   or
+
+     * the GNU General Public License as published by the Free
+       Software Foundation; either version 2 of the License, or (at your
+       option) any later version.
+
+   or both in parallel, as here.
+
+   GNU Nettle is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received copies of the GNU General Public License and
+   the GNU Lesser General Public License along with this program.  If
+   not, see http://www.gnu.org/licenses/.
+*/
+
+#ifndef NETTLE_POLY1305_INTERNAL_H_INCLUDED
+#define NETTLE_POLY1305_INTERNAL_H_INCLUDED
+
+#include "aes.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Name mangling */
+#define _poly1305_set_key _nettle_poly1305_set_key
+#define _poly1305_digest _nettle_poly1305_digest
+#define _poly1305_block _nettle_poly1305_block
+
+/* Low level functions/macros for the poly1305 construction. */
+
+#define POLY1305_DIGEST_SIZE 16
+#define POLY1305_KEY_SIZE 16
+
+/* Low-level internal interface. */
+void _poly1305_set_key(struct poly1305_ctx *ctx, const uint8_t 
key[POLY1305_KEY_SIZE]);
+/* Extracts digest, and adds it to s, the encrypted nonce. */
+void _poly1305_digest (struct poly1305_ctx *ctx, union nettle_block16 *s);
+/* Internal function. Process one block. */
+void _poly1305_block (struct poly1305_ctx *ctx, const uint8_t *m,
+                     unsigned high);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* NETTLE_POLY1305_INTERNAL_H_INCLUDED */
diff --git a/poly1305.h b/poly1305.h
index eadc4057fe89..99c63c8a8288 100644
--- a/poly1305.h
+++ b/poly1305.h
@@ -42,10 +42,6 @@ extern "C" {
 #endif
 
 /* Name mangling */
-#define poly1305_set_key nettle_poly1305_set_key
-#define poly1305_digest nettle_poly1305_digest
-#define _poly1305_block _nettle_poly1305_block
-
 #define poly1305_aes_set_key nettle_poly1305_aes_set_key
 #define poly1305_aes_set_nonce nettle_poly1305_aes_set_nonce
 #define poly1305_aes_update nettle_poly1305_aes_update
@@ -53,9 +49,7 @@ extern "C" {
 
 /* Low level functions/macros for the poly1305 construction. */
 
-#define POLY1305_DIGEST_SIZE 16
 #define POLY1305_BLOCK_SIZE 16
-#define POLY1305_KEY_SIZE 16
 
 struct poly1305_ctx {
   /* Key, 128-bit value and some cached multiples. */
@@ -76,14 +70,6 @@ struct poly1305_ctx {
   } h;
 };
 
-/* Low-level internal interface. */
-void poly1305_set_key(struct poly1305_ctx *ctx, const uint8_t 
key[POLY1305_KEY_SIZE]);
-/* Extracts digest, and adds it to s, the encrypted nonce. */
-void poly1305_digest (struct poly1305_ctx *ctx, union nettle_block16 *s);
-/* Internal function. Process one block. */
-void _poly1305_block (struct poly1305_ctx *ctx, const uint8_t *m,
-                     unsigned high);
-
 /* poly1305-aes */
 
 #define POLY1305_AES_KEY_SIZE 32
diff --git a/x86_64/poly1305-internal.asm b/x86_64/poly1305-internal.asm
index 98159ad391ec..8012e49f3781 100644
--- a/x86_64/poly1305-internal.asm
+++ b/x86_64/poly1305-internal.asm
@@ -41,14 +41,14 @@ define(<H0>, <%r9>)
 define(<H1>, <%r10>)
 define(<H2>, <%r11>)
        
-       C poly1305_set_key(struct poly1305_ctx *ctx, const uint8_t key[16])
+       C _poly1305_set_key(struct poly1305_ctx *ctx, const uint8_t key[16])
        .text
        C Registers:
        C  %rdi: ctx
        C  %rsi: key
        C  %r8: mask
        ALIGN(16)
-PROLOGUE(nettle_poly1305_set_key)
+PROLOGUE(_nettle_poly1305_set_key)
        W64_ENTRY(2,0)
        mov     $0x0ffffffc0fffffff, %r8
        mov     (%rsi), %rax
@@ -69,7 +69,7 @@ PROLOGUE(nettle_poly1305_set_key)
        W64_EXIT(2,0)
        ret
 
-EPILOGUE(nettle_poly1305_set_key)
+EPILOGUE(_nettle_poly1305_set_key)
 
 C 64-bit multiplication mod 2^130 - 5
 C
@@ -142,12 +142,12 @@ PROLOGUE(_nettle_poly1305_block)
        ret
 EPILOGUE(_nettle_poly1305_block)
 
-       C poly1305_digest (struct poly1305_ctx *ctx, uint8_t *s)
+       C _poly1305_digest (struct poly1305_ctx *ctx, uint8_t *s)
        C Registers:
        C   %rdi: ctx
        C   %rsi: s
        
-PROLOGUE(nettle_poly1305_digest)
+PROLOGUE(_nettle_poly1305_digest)
        W64_ENTRY(2, 0)
 
        mov     P1305_H0 (CTX), H0
@@ -182,5 +182,5 @@ define(<T1>, <%rax>)
        mov     XREG(%rax), P1305_H2 (CTX)
        W64_EXIT(2, 0)
        ret
-EPILOGUE(nettle_poly1305_digest)
+EPILOGUE(_nettle_poly1305_digest)
 
-- 
2.25.1

_______________________________________________
nettle-bugs mailing list
[email protected]
http://lists.lysator.liu.se/mailman/listinfo/nettle-bugs

Reply via email to