Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

blake2s.c:258:26: error: incompatible types when initializing type ‘uint32_t {aka unsigned int}’ using type ‘BlakeVectorUInt32 {aka __vector(4) unsigned int}’ #40

Open
NickeZ opened this issue Jun 20, 2019 · 2 comments

Comments

@NickeZ
Copy link

NickeZ commented Jun 20, 2019

I'm getting the following compiler error when compiling with gcc 7 or 8.

$ make -C src/protocol
make: Entering directory '/tmp/noise-tmp/src/protocol'
depbase=`echo ../crypto/blake2/blake2s.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`;\
gcc-7 -DPACKAGE_NAME=\"noise-c\" -DPACKAGE_TARNAME=\"noise-c\" -DPACKAGE_VERSION=\"0.0.1\" -DPACKAGE_STRING=\"noise-c\ 0.0.1\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"noise-c\" -DVERSION=\"0.0.1\" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DSIZEOF_VOID_P=8 -DHAVE_LIBRT=1 -DHAVE_POLL=1 -DHAVE_PTHREAD_PRIO_INHERIT=1 -I. -I/home/niklas/projects/external/noise-c/src/protocol  -I/home/niklas/projects/external/noise-c/include -I/home/niklas/projects/external/noise-c/src -I/home/niklas/projects/external/noise-c/src/crypto/goldilocks/src/include -I/home/niklas/projects/external/noise-c/src/crypto/goldilocks/src/p448 -I/home/niklas/projects/external/noise-c/src/crypto/goldilocks/src/p448/arch_x86_64   -DED25519_CUSTOMHASH -DED25519_CUSTOMRANDOM  -Wall   -g -O2 -pthread -MT ../crypto/blake2/blake2s.o -MD -MP -MF $depbase.Tpo -c -o ../crypto/blake2/blake2s.o /home/niklas/projects/external/noise-c/src/protocol/../crypto/blake2/blake2s.c &&\
mv -f $depbase.Tpo $depbase.Po
/home/niklas/projects/external/noise-c/src/protocol/../crypto/blake2/blake2s.c: In function ‘BLAKE2s_finish’:
/home/niklas/projects/external/noise-c/src/protocol/../crypto/blake2/blake2s.c:258:26: error: incompatible types when initializing type ‘uint32_t {aka unsigned int}’ using type ‘BlakeVectorUInt32 {aka __vector(4) unsigned int}’
             uint32_t h = context->h[posn];
                          ^~~~~~~
make: *** [Makefile:794: ../crypto/blake2/blake2s.o] Error 1
make: Leaving directory '/tmp/noise-tmp/src/protocol'

Configured with:

/home/niklas/projects/external/noise-c/configure --with-libsodium=no --with-openssl=no
@NickeZ
Copy link
Author

NickeZ commented Jun 20, 2019

I was trying to add support for the arm gcc toolchain and hit the above bug because of endianess problems. Here is the final diff I applied which works:

From 275be759990bdfaf634df9e7c685430e278a5a9c Mon Sep 17 00:00:00 2001
From: Niklas Claesson <[email protected]>
Date: Wed, 19 Jun 2019 16:12:39 +0200
Subject: [PATCH] use byteorder from compiler

---
 src/crypto/blake2/blake2-endian.h        | 8 +++++++-
 src/crypto/ghash/ghash.c                 | 9 ++++++++-
 src/crypto/goldilocks/src/include/word.h | 7 ++++++-
 3 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/src/crypto/blake2/blake2-endian.h b/src/crypto/blake2/blake2-endian.h
index 10e40ab..25a3239 100644
--- a/src/crypto/blake2/blake2-endian.h
+++ b/src/crypto/blake2/blake2-endian.h
@@ -23,6 +23,12 @@
 #ifndef __BLAKE2_ENDIAN_H__
 #define __BLAKE2_ENDIAN_H__
 
+#if defined(__BYTE_ORDER__)
+#define __BYTE_ORDER __BYTE_ORDER__
+#define __LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__
+#define __BIG_ENDIAN __ORDER_BIG_ENDIAN__
+#endif
+
 #if defined(__WIN32__) || defined(WIN32)
 #ifndef __BIG_ENDIAN
 #define __BIG_ENDIAN 4321
@@ -44,7 +50,7 @@
 #if !defined( __LITTLE_ENDIAN) && defined(__DARWIN_LITTLE_ENDIAN)
 #define __LITTLE_ENDIAN __DARWIN_LITTLE_ENDIAN
 #endif
-#else
+#elif !defined(__BYTE_ORDER)
 #include <endian.h>
 #endif
 
diff --git a/src/crypto/ghash/ghash.c b/src/crypto/ghash/ghash.c
index e2bc5b2..d2c4a69 100644
--- a/src/crypto/ghash/ghash.c
+++ b/src/crypto/ghash/ghash.c
@@ -22,6 +22,13 @@
 
 #include "ghash.h"
 #include <string.h>
+
+#if defined(__BYTE_ORDER__)
+#define __BYTE_ORDER __BYTE_ORDER__
+#define __LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__
+#define __BIG_ENDIAN __ORDER_BIG_ENDIAN__
+#endif
+
 #if defined(__WIN32__) || defined(WIN32)
 #ifndef __BIG_ENDIAN
 #define __BIG_ENDIAN 4321
@@ -43,7 +50,7 @@
 #if !defined( __LITTLE_ENDIAN) && defined(__DARWIN_LITTLE_ENDIAN)
 #define __LITTLE_ENDIAN __DARWIN_LITTLE_ENDIAN
 #endif
-#else
+#elif !defined(__BYTE_ORDER)
 #include <endian.h>
 #endif
 
diff --git a/src/crypto/goldilocks/src/include/word.h b/src/crypto/goldilocks/src/include/word.h
index 9ad01e1..1a3c950 100644
--- a/src/crypto/goldilocks/src/include/word.h
+++ b/src/crypto/goldilocks/src/include/word.h
@@ -10,8 +10,13 @@
 
 #include "arch_config.h"
 
+#if defined(__BYTE_ORDER__)
+#define __BYTE_ORDER __BYTE_ORDER__
+#define __LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__
+#define __BIG_ENDIAN __ORDER_BIG_ENDIAN__
+#endif
 
-#ifndef __APPLE__
+#if !defined(__APPLE__) && !defined(__BYTE_ORDER)
 #if defined(__WIN32__) || defined(WIN32)
 #ifndef __BIG_ENDIAN
 #define __BIG_ENDIAN 4321
-- 
2.20.1

@NickeZ
Copy link
Author

NickeZ commented Jun 20, 2019

In this toolchain endian.h is available in machine/ but I think it is more robust to use the gcc builtin variables.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant