From 4433591cfc3d2fd8f0cad8e4271ddd2377033655 Mon Sep 17 00:00:00 2001 From: Michael Hamburg Date: Mon, 29 Sep 2014 12:59:12 -0700 Subject: [PATCH] Forget yesterday's hack; just add an arch_config.h to each arch which says how many bits it is. Add batarch.map for eBATS architecture renaming. --- HISTORY.txt | 17 +++++++++++++++++ Makefile | 9 +++++---- TODO.txt | 13 ++++++++++++- src/arch_32/arch_config.h | 1 + src/arch_arm_32/arch_config.h | 1 + src/arch_neon/arch_config.h | 1 + src/arch_neon_experimental/arch_config.h | 1 + src/arch_ref64/arch_config.h | 1 + src/arch_x86_64/arch_config.h | 1 + src/include/word.h | 16 +++------------- test/batarch.map | 5 +++++ 11 files changed, 48 insertions(+), 18 deletions(-) create mode 100644 src/arch_32/arch_config.h create mode 100644 src/arch_arm_32/arch_config.h create mode 100644 src/arch_neon/arch_config.h create mode 100644 src/arch_neon_experimental/arch_config.h create mode 100644 src/arch_ref64/arch_config.h create mode 100644 src/arch_x86_64/arch_config.h create mode 100644 test/batarch.map diff --git a/HISTORY.txt b/HISTORY.txt index f5b0e0b..006b2b8 100644 --- a/HISTORY.txt +++ b/HISTORY.txt @@ -1,3 +1,20 @@ +September 29, 2014: + Yesterday I put in some more architecture detection, but it should + really be based on the arch directory, because what's in there really + is a terrible hack. + + I've tweaked the eBAT construction code to rename the architectures + using test/batarch.map. Maybe I should also rename them internally, + but not yet. + + I added some new TODO.txt items. Some folks have been asking for a + more factored library, instead of this combined arithmetic, curve code, + encodings and protocol all-in-one jumble. Likewise the hash and RNG + should be flexible. + + I've also been meaning to put more work in on SPAKE2EE, which would + also mean finalizing the Elligator code. + September 18, 2014: Begin work on a "ref" implementation. Currently this is just the arch_ref64 architecture. The ref implementation always weak_reduces diff --git a/Makefile b/Makefile index 622ce38..6ebc1ed 100644 --- a/Makefile +++ b/Makefile @@ -122,14 +122,15 @@ doc: Doxyfile doc/timestamp src/*.c src/include/*.h src/$(ARCH)/*.c src/$(ARCH)/ bat: $(BATNAME) -$(BATNAME): include/* src/* src/*/* +$(BATNAME): include/* src/* src/*/* test/batarch.map rm -fr $@ - for arch in src/arch*; do \ + (while read arch where; do \ mkdir -p $@/`basename $$arch`; \ - cp include/* src/*.c src/include/* $$arch/* $@/`basename $$arch`; \ + cp include/*.h src/*.c src/include/*.h src/$$where/*.c src/$$where/*.h $@/`basename $$arch`; \ perl -p -i -e 's/.*endif.*GOLDILOCKS_CONFIG_H/#define SUPERCOP_WONT_LET_ME_OPEN_FILES 1\n\n$$&/' $@/`basename $$arch`/config.h; \ perl -p -i -e 's/SYSNAME/'`basename $(BATNAME)`_`basename $$arch`'/g' $@/`basename $$arch`/api.h; \ - done + done \ + ) < test/batarch.map echo 'Mike Hamburg' > $@/designers echo 'Ed448-Goldilocks sign and dh' > $@/description diff --git a/TODO.txt b/TODO.txt index df1a782..827c947 100644 --- a/TODO.txt +++ b/TODO.txt @@ -1,5 +1,16 @@ Important work items for Ed448-Goldilocks: +* Better architecture detection / factoring of arch-related headers. + [PROGRESS] + +* Better factoring of high-level vs low-level library. + +* Factor out hash, crandom from core library? + +* Signed 32-bit NEON implementation to avoid bias/reduce after subtract + + + * Documentation: write high-level API docs, and internal docs to help other implementors. * Partial progress on Doxygenating the code. @@ -59,7 +70,7 @@ Important work items for Ed448-Goldilocks: * Scalarmul with other cofactor modes. * High-level API: - * SPAKE2 Elligator Edition? Maybe write a paper first. + * SHA512 Elligator Edition? Maybe write a paper first. * Elligator. * Need to write Elligator inverse. Might not be Elligator-2S. diff --git a/src/arch_32/arch_config.h b/src/arch_32/arch_config.h new file mode 100644 index 0000000..47bbe3e --- /dev/null +++ b/src/arch_32/arch_config.h @@ -0,0 +1 @@ +#define WORD_BITS 32 diff --git a/src/arch_arm_32/arch_config.h b/src/arch_arm_32/arch_config.h new file mode 100644 index 0000000..47bbe3e --- /dev/null +++ b/src/arch_arm_32/arch_config.h @@ -0,0 +1 @@ +#define WORD_BITS 32 diff --git a/src/arch_neon/arch_config.h b/src/arch_neon/arch_config.h new file mode 100644 index 0000000..47bbe3e --- /dev/null +++ b/src/arch_neon/arch_config.h @@ -0,0 +1 @@ +#define WORD_BITS 32 diff --git a/src/arch_neon_experimental/arch_config.h b/src/arch_neon_experimental/arch_config.h new file mode 100644 index 0000000..47bbe3e --- /dev/null +++ b/src/arch_neon_experimental/arch_config.h @@ -0,0 +1 @@ +#define WORD_BITS 32 diff --git a/src/arch_ref64/arch_config.h b/src/arch_ref64/arch_config.h new file mode 100644 index 0000000..58758cc --- /dev/null +++ b/src/arch_ref64/arch_config.h @@ -0,0 +1 @@ +#define WORD_BITS 64 diff --git a/src/arch_x86_64/arch_config.h b/src/arch_x86_64/arch_config.h new file mode 100644 index 0000000..58758cc --- /dev/null +++ b/src/arch_x86_64/arch_config.h @@ -0,0 +1 @@ +#define WORD_BITS 64 diff --git a/src/include/word.h b/src/include/word.h index 6c60ed8..f493ecc 100644 --- a/src/include/word.h +++ b/src/include/word.h @@ -5,6 +5,8 @@ #ifndef __WORD_H__ #define __WORD_H__ +#include "arch_config.h" + /* for posix_memalign */ #define _XOPEN_SOURCE 600 @@ -26,18 +28,7 @@ #include #endif -#if ((__SIZEOF_INT128__ == 16 \ - || 10*__clang_major__ + __clang_minor__ <= 32) \ - && __SIZEOF_SIZE_T__ == 8 \ - && (__SIZEOF_LONG__==8 || __POINTER_WIDTH__==64) \ - && !defined(GOLDI_FORCE_32_BIT)) -/* It's a 64-bit machine if: - * __uint128_t exists - * size_t is 64 bits - * Either longs are 64-bits (doesn't happen on Windows) - * or pointers are 64-bits (doesn't happen on 32/64 arches) - * FUTURE: validate this hack on more architectures. - */ +#if (WORD_BITS == 64) typedef uint32_t hword_t; typedef uint64_t word_t; typedef __uint128_t dword_t; @@ -67,7 +58,6 @@ typedef int64_t dsword_t; #define GOLDI_BITS 32 #endif -#define WORD_BITS (sizeof(word_t) * 8) #define DIV_CEIL(_x,_y) (((_x) + (_y) - 1)/(_y)) #define ROUND_UP(_x,_y) (DIV_CEIL((_x),(_y))*(_y)) #define WORDS_FOR_BITS(_x) (DIV_CEIL((_x),WORD_BITS)) diff --git a/test/batarch.map b/test/batarch.map new file mode 100644 index 0000000..df54ddf --- /dev/null +++ b/test/batarch.map @@ -0,0 +1,5 @@ +neon arch_neon_experimental +arm32 arch_arm_32 +64 arch_ref64 +32 arch_32 +amd64 arch_x86_64