diff --git a/Makefile b/Makefile index 28d3603..622ce38 100644 --- a/Makefile +++ b/Makefile @@ -68,7 +68,7 @@ TESTCOMPONENTS=build/test.o build/test_scalarmul.o build/test_sha512.o \ BENCHCOMPONENTS=build/bench.o -BATNAME=build/ed448-goldilocks +BATNAME=build/ed448goldilocks all: lib build/test build/bench @@ -128,6 +128,7 @@ $(BATNAME): include/* src/* src/*/* mkdir -p $@/`basename $$arch`; \ cp include/* src/*.c src/include/* $$arch/* $@/`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 echo 'Mike Hamburg' > $@/designers echo 'Ed448-Goldilocks sign and dh' > $@/description diff --git a/src/include/api.h b/src/include/api.h index cc20246..7ee5e1e 100644 --- a/src/include/api.h +++ b/src/include/api.h @@ -8,6 +8,7 @@ */ #include +#include #include "goldilocks.h" #define PUBLICKEY_BYTES GOLDI_PUBLIC_KEY_BYTES @@ -15,18 +16,24 @@ #define SIGNATURE_BYTES GOLDI_SIGNATURE_BYTES #define SHAREDSECRET_BYTES GOLDI_SHARED_SECRET_BYTES -#define crypto_dh_PUBLICKEYBYTES PUBLICKEY_BYTES -#define crypto_dh_SECRETKEYBYTES SECRETKEY_BYTES +#define crypto_dh_SYSNAME_PUBLICKEYBYTES PUBLICKEY_BYTES +#define crypto_dh_SYSNAME_SECRETKEYBYTES SECRETKEY_BYTES #define PRIVATEKEY_BYTES SECRETKEY_BYTES -#define crypto_dh_BYTES SHAREDSECRET_BYTES -#define crypto_dh_IMPLEMENTATION "AMD64" -#define crypto_dh_VERSION "2014-07-11" - -#define crypto_sign_PUBLICKEYBYTES PUBLICKEY_BYTES -#define crypto_sign_SECRETKEYBYTES SECRETKEY_BYTES -#define crypto_sign_IMPLEMENTATION "AMD64" -#define crypto_sign_VERSION "2014-07-11" -#define crypto_sign_BYTES SIGNATURE_BYTES +#define crypto_dh_SYSNAME_BYTES SHAREDSECRET_BYTES +#define crypto_dh_SYSNAME_IMPLEMENTATION "AMD64" +#define crypto_dh_SYSNAME_VERSION "2014-07-11" + +#define crypto_sign_SYSNAME_PUBLICKEYBYTES PUBLICKEY_BYTES +#define crypto_sign_SYSNAME_SECRETKEYBYTES SECRETKEY_BYTES +#define crypto_sign_SYSNAME_IMPLEMENTATION "AMD64" +#define crypto_sign_SYSNAME_VERSION "2014-07-11" +#define crypto_sign_SYSNAME_BYTES SIGNATURE_BYTES + +#define crypto_dh_SYSNAME_keypair crypto_dh_keypair +#define crypto_dh_SYSNAME crypto_dh +#define crypto_sign_SYSNAME_keypair crypto_dh_keypair +#define crypto_sign_SYSNAME crypto_sign +#define crypto_sign_SYSNAME_open crypto_sign_open #define CRYPTO_DETERMINISTIC 1 @@ -44,7 +51,6 @@ static inline int patentclaims() { return 20; } -#define crypto_sign_keypair crypto_dh_keypair static inline int crypto_dh_keypair ( unsigned char pk[SECRETKEY_BYTES], unsigned char sk[PUBLICKEY_BYTES] @@ -60,25 +66,6 @@ static inline int crypto_dh_keypair ( return ret; } -static inline void keypair ( - unsigned char sk[SECRETKEY_BYTES], - unsigned long long *sklen, - unsigned char pk[PUBLICKEY_BYTES], - unsigned long long *pklen -) { - int ret = goldilocks_init(); - if (ret) abort(); - - ret = goldilocks_keygen( - (struct goldilocks_private_key_t *)sk, - (struct goldilocks_public_key_t *)pk - ); - if (ret) abort(); - - *sklen = SECRETKEY_BYTES; - *pklen = PUBLICKEY_BYTES; -} - static inline int crypto_sign ( unsigned char *sm, unsigned long long *smlen, @@ -86,37 +73,17 @@ static inline int crypto_sign ( unsigned long long mlen, const unsigned char sk[SECRETKEY_BYTES] ) { + unsigned char sig[SIGNATURE_BYTES]; int ret = goldilocks_sign( - sm, m, mlen, - (const struct goldilocks_private_key_t *)sk - ); - if (ret) abort(); - - memcpy(sm + SIGNATURE_BYTES, m, mlen); - - *smlen = mlen + SIGNATURE_BYTES; - return 0; -} - -static inline void signmessage ( - unsigned char *sm, - unsigned long long *smlen, - const unsigned char *m, - unsigned long long mlen, - const unsigned char sk[SECRETKEY_BYTES], - unsigned long long sklen -) { - if (sklen != PRIVATEKEY_BYTES) abort(); - - int ret = goldilocks_sign( - sm, m, mlen, + sig, m, mlen, (const struct goldilocks_private_key_t *)sk ); - if (ret) abort(); - - memcpy(sm + SIGNATURE_BYTES, m, mlen); - - *smlen = mlen + SIGNATURE_BYTES; + if (!ret) { + memmove(sm + SIGNATURE_BYTES, m, mlen); + memcpy(sm, sig, SIGNATURE_BYTES); + *smlen = mlen + SIGNATURE_BYTES; + } + return ret ? -1 : 0; } static inline int crypto_sign_open ( @@ -132,33 +99,15 @@ static inline int crypto_sign_open ( ); if (!ret) { *mlen = smlen - SIGNATURE_BYTES; - memcpy(m, sm + SIGNATURE_BYTES, *mlen); + memmove(m, sm + SIGNATURE_BYTES, *mlen); } return ret ? -1 : 0; } -static inline int verification ( - const unsigned char *m, - unsigned long long mlen, - const unsigned char *sm, - unsigned long long smlen, - const unsigned char pk[PUBLICKEY_BYTES], - unsigned long long pklen -) { - if (pklen != PUBLICKEY_BYTES) abort(); - - int ret = goldilocks_verify( - sm, m, mlen, - (const struct goldilocks_public_key_t *)pk - ); - return ret ? -1 : 0; -} - - static inline int crypto_dh ( unsigned char s[SHAREDSECRET_BYTES], - const unsigned char sk[SECRETKEY_BYTES], - const unsigned char pk[PUBLICKEY_BYTES] + const unsigned char pk[PUBLICKEY_BYTES], + const unsigned char sk[SECRETKEY_BYTES] ) { return goldilocks_shared_secret ( s, @@ -167,24 +116,3 @@ static inline int crypto_dh ( ); } -static inline int sharedsecret ( - unsigned char s[SHAREDSECRET_BYTES], - unsigned long long *slen, - const unsigned char sk[SECRETKEY_BYTES], - unsigned long long sklen, - const unsigned char pk[PUBLICKEY_BYTES], - unsigned long long pklen -) { - if (pklen != PUBLICKEY_BYTES) abort(); - if (sklen != SECRETKEY_BYTES) abort(); - - int ret = goldilocks_shared_secret ( - s, - (const struct goldilocks_private_key_t *)sk, - (const struct goldilocks_public_key_t *)pk - ); - if (ret) return -1; - *slen = SHAREDSECRET_BYTES; - return 0; -} - diff --git a/src/include/word.h b/src/include/word.h index 26123bc..2826ee7 100644 --- a/src/include/word.h +++ b/src/include/word.h @@ -9,7 +9,9 @@ #define _XOPEN_SOURCE 600 #ifndef __APPLE__ -#define _BSD_SOURCE +#ifndef _BSD_SOURCE +#define _BSD_SOURCE 1 +#endif #include #endif diff --git a/src/scalarmul.c b/src/scalarmul.c index 49bd242..7427e18 100644 --- a/src/scalarmul.c +++ b/src/scalarmul.c @@ -752,6 +752,7 @@ prepare_wnaf_table( struct tw_extensible_t *working, unsigned int tbits ) { + int i; convert_tw_extensible_to_tw_pniels(&output[0], working); if (tbits == 0) return; @@ -763,7 +764,7 @@ prepare_wnaf_table( add_tw_pniels_to_tw_extensible(working, &output[0]); convert_tw_extensible_to_tw_pniels(&output[1], working); - for (int i=2; i < 1<