Index: .fossil-settings/ignore-glob ================================================================== --- .fossil-settings/ignore-glob +++ .fossil-settings/ignore-glob @@ -10,8 +10,9 @@ configure install-sh config.log config.status blake2b/blake2b.o +blake2b/blake2b-ref-nacl.c tweetnacl/tweetnacl.c tweetnacl/tweetnacl.h tweetnacl/tweetnacl.o Index: Makefile.in ================================================================== --- Makefile.in +++ Makefile.in @@ -1,8 +1,8 @@ CC := @CC@ CFLAGS := @CFLAGS@ @SHOBJFLAGS@ -CPPFLAGS := -I. -I@srcdir@/tweetnacl/ -I@srcdir@/blake2b/ -DSUPERCOP=1 @CPPFLAGS@ @SHOBJCPPFLAGS@ @DEFS@ +CPPFLAGS := -I. -I@srcdir@/tweetnacl/ -I@srcdir@/blake2b/ -DNACL_ED25519_BLAKE2B=1 @CPPFLAGS@ @SHOBJCPPFLAGS@ @DEFS@ LDFLAGS := @LDFLAGS@ LIBS := @LIBS@ SHOBJLDFLAGS := @SHOBJLDFLAGS@ srcdir := @srcdir@ export CC CFLAGS CPPFLAGS Index: blake2b/Makefile ================================================================== --- blake2b/Makefile +++ blake2b/Makefile @@ -1,9 +1,14 @@ -blake2b.o: blake2b-ref.c blake2-impl.h blake2.h - $(CC) $(CPPFLAGS) $(CFLAGS) -DSUPERCOP=1 -o blake2b.o -c blake2b-ref.c +blake2b.o: blake2b-ref-nacl.c blake2-impl.h blake2.h + $(CC) $(CPPFLAGS) $(CFLAGS) -o blake2b.o -c blake2b-ref-nacl.c + +blake2b-ref-nacl.c: blake2b-ref.c blake2-nacl.c + rm -f blake2b-ref-nacl.c + cat blake2b-ref.c blake2-nacl.c > blake2b-ref-nacl.c clean: + rm -f blake2b-ref-nacl.c rm -f blake2b.o distclean: clean .PHONY: clean distclean ADDED blake2b/blake2-nacl.c Index: blake2b/blake2-nacl.c ================================================================== --- /dev/null +++ blake2b/blake2-nacl.c @@ -0,0 +1,6 @@ +#if defined(NACL_ED25519_BLAKE2B) +int crypto_hash_blake2b( unsigned char *out, unsigned char *in, unsigned long long inlen ) +{ + return blake2b( out, BLAKE2B_OUTBYTES, in, inlen, NULL, 0 ); +} +#endif ADDED blake2b/blake2-nacl.h Index: blake2b/blake2-nacl.h ================================================================== --- /dev/null +++ blake2b/blake2-nacl.h @@ -0,0 +1,9 @@ +#define crypto_hash_PRIMITIVE "blake2b" +#define crypto_hash_BYTES crypto_hash_blake2b_BYTES +#define crypto_hash_IMPLEMENTATION crypto_hash_blake2b_IMPLEMENTATION +#define crypto_hash_VERSION crypto_hash_blake2b_VERSION +#define crypto_hash_blake2b_BYTES 64 +extern int crypto_hash_blake2b(unsigned char *,const unsigned char *,unsigned long long); +#define crypto_hash_blake2b_VERSION "-" +#define crypto_hash_blake2b_IMPLEMENTATION "blake2b-ref" +#define crypto_hash crypto_hash_blake2b DELETED blake2b/blake2-supercop.h Index: blake2b/blake2-supercop.h ================================================================== --- blake2b/blake2-supercop.h +++ /dev/null @@ -1,8 +0,0 @@ -#define crypto_hash_PRIMITIVE "blake2b" -#define crypto_hash_BYTES crypto_hash_blake2b_BYTES -#define crypto_hash_IMPLEMENTATION crypto_hash_blake2b_IMPLEMENTATION -#define crypto_hash_VERSION crypto_hash_blake2b_VERSION -#define crypto_hash_blake2b_BYTES 64 -extern int crypto_hash(unsigned char *,const unsigned char *,unsigned long long); -#define crypto_hash_blake2b_VERSION "-" -#define crypto_hash_blake2b_IMPLEMENTATION "blake2b-ref" Index: nano.c ================================================================== --- nano.c +++ nano.c @@ -4,11 +4,11 @@ #include #include #include #include "tweetnacl.h" -#include "blake2-supercop.h" +#include "blake2-nacl.h" #define NANO_SECRET_KEY_LENGTH (crypto_sign_SECRETKEYBYTES - crypto_sign_PUBLICKEYBYTES) #define NANO_PUBLIC_KEY_LENGTH (crypto_sign_PUBLICKEYBYTES) #define TclNano_AttemptAlloc(x) ((void *) Tcl_AttemptAlloc(x)) #define TclNano_Free(x) Tcl_Free((char *) x) Index: tweetnacl/Makefile ================================================================== --- tweetnacl/Makefile +++ tweetnacl/Makefile @@ -6,22 +6,22 @@ tweetnacl.c.new: src/tweetnacl.c rm -f tweetnacl.c.new tweetnacl.c cp src/tweetnacl.c tweetnacl.c.new -tweetnacl.c: tweetnacl.c.new tweetnacl.h.new patches/tweetnacl-supercop.diff patches/tweetnacl-derivepubkey.diff +tweetnacl.c: tweetnacl.c.new tweetnacl.h.new patches/tweetnacl-ed25519blake2b.diff patches/tweetnacl-derivepubkey.diff rm -f tweetnacl.c tweetnacl.h - patch -p1 < patches/tweetnacl-supercop.diff || ( rm -f tweetnacl.c.new tweetnacl.h.new; exit 1 ) + patch -p1 < patches/tweetnacl-ed25519blake2b.diff || ( rm -f tweetnacl.c.new tweetnacl.h.new; exit 1 ) patch -p1 < patches/tweetnacl-derivepubkey.diff || ( rm -f tweetnacl.c.new tweetnacl.h.new; exit 1 ) rm -f tweetnacl.c.new.orig tweetnacl.h.new.orig mv tweetnacl.h.new tweetnacl.h mv tweetnacl.c.new tweetnacl.c tweetnacl.h: tweetnacl.c tweetnacl.o: tweetnacl.c tweetnacl.h - $(CC) $(CPPFLAGS) $(CFLAGS) -DSUPERCOP=1 -I../blake2b/ -o tweetnacl.o -c tweetnacl.c + $(CC) $(CPPFLAGS) $(CFLAGS) -I../blake2b/ -o tweetnacl.o -c tweetnacl.c clean: rm -f tweetnacl.c.new.orig tweetnacl.h.new.orig rm -f tweetnacl.h.new tweetnacl.h rm -f tweetnacl.c.new tweetnacl.c ADDED tweetnacl/patches/tweetnacl-ed25519blake2b.diff Index: tweetnacl/patches/tweetnacl-ed25519blake2b.diff ================================================================== --- /dev/null +++ tweetnacl/patches/tweetnacl-ed25519blake2b.diff @@ -0,0 +1,65 @@ +--- a/tweetnacl.c.new ++++ b/tweetnacl.c.new +@@ -32,12 +32,14 @@ + return (u<<8)|x[0]; + } + ++#ifndef NACL_ED25519_BLAKE2B + static u64 dl64(const u8 *x) + { + u64 i,u=0; + FOR(i,8) u=(u<<8)|x[i]; + return u; + } ++#endif + + sv st32(u8 *x,u32 u) + { +@@ -45,11 +47,13 @@ + FOR(i,4) { x[i] = u; u >>= 8; } + } + ++#ifndef NACL_ED25519_BLAKE2B + sv ts64(u8 *x,u64 u) + { + int i; + for (i = 7;i >= 0;--i) { x[i] = u; u >>= 8; } + } ++#endif + + static int vn(const u8 *x,const u8 *y,int n) + { +@@ -484,6 +488,7 @@ + return crypto_box_open_afternm(m,c,d,n,k); + } + ++#ifndef NACL_ED25519_BLAKE2B + static u64 R(u64 x,int c) { return (x >> c) | (x << (64 - c)); } + static u64 Ch(u64 x,u64 y,u64 z) { return (x & y) ^ (~x & z); } + static u64 Maj(u64 x,u64 y,u64 z) { return (x & y) ^ (x & z) ^ (y & z); } +@@ -584,6 +589,7 @@ + + return 0; + } ++#endif + + sv add(gf p[4],gf q[4]) + { +--- a/tweetnacl.h.new ++++ b/tweetnacl.h.new +@@ -118,11 +118,15 @@ + #define crypto_hashblocks_sha256_BLOCKBYTES crypto_hashblocks_sha256_tweet_BLOCKBYTES + #define crypto_hashblocks_sha256_VERSION crypto_hashblocks_sha256_tweet_VERSION + #define crypto_hashblocks_sha256_IMPLEMENTATION "crypto_hashblocks/sha256/tweet" ++#ifndef NACL_ED25519_BLAKE2B + #define crypto_hash_PRIMITIVE "sha512" + #define crypto_hash crypto_hash_sha512 + #define crypto_hash_BYTES crypto_hash_sha512_BYTES + #define crypto_hash_IMPLEMENTATION crypto_hash_sha512_IMPLEMENTATION + #define crypto_hash_VERSION crypto_hash_sha512_VERSION ++#else ++#include "blake2-nacl.h" ++#endif + #define crypto_hash_sha512_tweet_BYTES 64 + extern int crypto_hash_sha512_tweet(unsigned char *,const unsigned char *,unsigned long long); + #define crypto_hash_sha512_tweet_VERSION "-" DELETED tweetnacl/patches/tweetnacl-supercop.diff Index: tweetnacl/patches/tweetnacl-supercop.diff ================================================================== --- tweetnacl/patches/tweetnacl-supercop.diff +++ /dev/null @@ -1,65 +0,0 @@ ---- a/tweetnacl.c.new -+++ b/tweetnacl.c.new -@@ -32,12 +32,14 @@ - return (u<<8)|x[0]; - } - -+#ifndef SUPERCOP - static u64 dl64(const u8 *x) - { - u64 i,u=0; - FOR(i,8) u=(u<<8)|x[i]; - return u; - } -+#endif - - sv st32(u8 *x,u32 u) - { -@@ -45,11 +47,13 @@ - FOR(i,4) { x[i] = u; u >>= 8; } - } - -+#ifndef SUPERCOP - sv ts64(u8 *x,u64 u) - { - int i; - for (i = 7;i >= 0;--i) { x[i] = u; u >>= 8; } - } -+#endif - - static int vn(const u8 *x,const u8 *y,int n) - { -@@ -484,6 +488,7 @@ - return crypto_box_open_afternm(m,c,d,n,k); - } - -+#ifndef SUPERCOP - static u64 R(u64 x,int c) { return (x >> c) | (x << (64 - c)); } - static u64 Ch(u64 x,u64 y,u64 z) { return (x & y) ^ (~x & z); } - static u64 Maj(u64 x,u64 y,u64 z) { return (x & y) ^ (x & z) ^ (y & z); } -@@ -584,6 +589,7 @@ - - return 0; - } -+#endif - - sv add(gf p[4],gf q[4]) - { ---- a/tweetnacl.h.new -+++ b/tweetnacl.h.new -@@ -118,11 +118,15 @@ - #define crypto_hashblocks_sha256_BLOCKBYTES crypto_hashblocks_sha256_tweet_BLOCKBYTES - #define crypto_hashblocks_sha256_VERSION crypto_hashblocks_sha256_tweet_VERSION - #define crypto_hashblocks_sha256_IMPLEMENTATION "crypto_hashblocks/sha256/tweet" -+#ifndef SUPERCOP - #define crypto_hash_PRIMITIVE "sha512" - #define crypto_hash crypto_hash_sha512 - #define crypto_hash_BYTES crypto_hash_sha512_BYTES - #define crypto_hash_IMPLEMENTATION crypto_hash_sha512_IMPLEMENTATION - #define crypto_hash_VERSION crypto_hash_sha512_VERSION -+#else -+#include "blake2-supercop.h" -+#endif - #define crypto_hash_sha512_tweet_BYTES 64 - extern int crypto_hash_sha512_tweet(unsigned char *,const unsigned char *,unsigned long long); - #define crypto_hash_sha512_tweet_VERSION "-"