From 5cc019f935243f6548e75e0c106d121d4de4ffc2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Niels=20M=C3=B6ller?= <nisse@lysator.liu.se>
Date: Wed, 24 Apr 2013 23:02:34 +0200
Subject: [PATCH] Changed memxor functions to take void * arguments.

---
 ChangeLog |  8 ++++++++
 memxor.c  | 28 ++++++++++++++++++----------
 memxor.h  |  5 ++---
 3 files changed, 28 insertions(+), 13 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index cd6583a3..15ae2633 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2013-04-24  Niels Möller  <nisse@lysator.liu.se>
 
+	* memxor.h: Updated prototypes. Drop include of nettle-types.h.
+
+	* memxor.c: Include nettle-types.h, for uintptr_t. Replace all
+	internal uses of uint8_t by plain char.
+	(memxor): Use void * rather than uint8_t * for
+	arguments.
+	(memxor3): Likewise.
+
 	* x86_64/memxor.asm: Added nettle_ prefix to symbols.
 	* arm/memxor.asm: Likewise.
 
diff --git a/memxor.c b/memxor.c
index f2feff04..a91ec215 100644
--- a/memxor.c
+++ b/memxor.c
@@ -35,6 +35,9 @@
 
 #include "memxor.h"
 
+/* For uintptr_t */
+#include "nettle-types.h"
+
 typedef unsigned long int word_t;
 
 #if SIZEOF_LONG & (SIZEOF_LONG - 1)
@@ -75,7 +78,7 @@ memxor_common_alignment (word_t *dst, const word_t *src, size_t n)
    words, not bytes. Assumes we can read complete words at the start
    and end of the src operand. */
 static void
-memxor_different_alignment (word_t *dst, const uint8_t *src, size_t n)
+memxor_different_alignment (word_t *dst, const char *src, size_t n)
 {
   size_t i;
   int shl, shr;
@@ -111,10 +114,11 @@ memxor_different_alignment (word_t *dst, const uint8_t *src, size_t n)
 
 /* XOR LEN bytes starting at SRCADDR onto DESTADDR. Result undefined
    if the source overlaps with the destination. Return DESTADDR. */
-uint8_t *
-memxor(uint8_t *dst, const uint8_t *src, size_t n)
+void *
+memxor(void *dst_in, const void *src_in, size_t n)
 {
-  uint8_t *orig_dst = dst;
+  char *dst = dst_in;
+  const char *src = src_in;
 
   if (n >= WORD_T_THRESH)
     {
@@ -137,7 +141,7 @@ memxor(uint8_t *dst, const uint8_t *src, size_t n)
   for (; n > 0; n--)
     *dst++ ^= *src++;
 
-  return orig_dst;
+  return dst_in;
 }
 
 
@@ -153,7 +157,7 @@ memxor3_common_alignment (word_t *dst,
 
 static void
 memxor3_different_alignment_b (word_t *dst,
-			       const word_t *a, const uint8_t *b, unsigned offset, size_t n)
+			       const word_t *a, const char *b, unsigned offset, size_t n)
 {
   int shl, shr;
   const word_t *b_word;
@@ -187,7 +191,7 @@ memxor3_different_alignment_b (word_t *dst,
 
 static void
 memxor3_different_alignment_ab (word_t *dst,
-				const uint8_t *a, const uint8_t *b,
+				const char *a, const char *b,
 				unsigned offset, size_t n)
 {
   int shl, shr;
@@ -224,7 +228,7 @@ memxor3_different_alignment_ab (word_t *dst,
 
 static void
 memxor3_different_alignment_all (word_t *dst,
-				 const uint8_t *a, const uint8_t *b,
+				 const char *a, const char *b,
 				 unsigned a_offset, unsigned b_offset,
 				 size_t n)
 {
@@ -271,9 +275,13 @@ memxor3_different_alignment_all (word_t *dst,
    the start of the destination area. This feature is used only
    internally by cbc decrypt, and it is not advertised or documented
    to nettle users. */
-uint8_t *
-memxor3(uint8_t *dst, const uint8_t *a, const uint8_t *b, size_t n)
+void *
+memxor3(void *dst_in, const void *a_in, const void *b_in, size_t n)
 {
+  char *dst = dst_in;
+  const char *a = a_in;
+  const char *b = b_in;
+
   if (n >= WORD_T_THRESH)
     {
       unsigned i;
diff --git a/memxor.h b/memxor.h
index 2a6545ce..b7bef09e 100644
--- a/memxor.h
+++ b/memxor.h
@@ -6,7 +6,6 @@
 #define NETTLE_MEMXOR_H_INCLUDED
 
 #include <stdlib.h>
-#include "nettle-types.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -16,8 +15,8 @@ extern "C" {
 #define memxor nettle_memxor
 #define memxor3 nettle_memxor3
 
-uint8_t *memxor(uint8_t *dst, const uint8_t *src, size_t n);
-uint8_t *memxor3(uint8_t *dst, const uint8_t *a, const uint8_t *b, size_t n);
+void *memxor(void *dst, const void *src, size_t n);
+void *memxor3(void *dst, const void *a, const void *b, size_t n);
 
 #ifdef __cplusplus
 }
-- 
GitLab