From cc3c637732392882cac650dbd7c376980bf95774 Mon Sep 17 00:00:00 2001 From: Mike Hamburg Date: Sun, 12 Oct 2014 17:22:10 -0700 Subject: [PATCH] Changes to the eBAT build system, to bring the code and package closer to how DJB expects them. --- Makefile | 29 +++++++---- src/bat/api_dh.h | 24 +++++++++ src/bat/api_sign.h | 24 +++++++++ src/bat/dh.c | 40 +++++++++++++++ src/bat/sign.c | 66 +++++++++++++++++++++++++ src/include/api.h | 118 --------------------------------------------- 6 files changed, 173 insertions(+), 128 deletions(-) create mode 100644 src/bat/api_dh.h create mode 100644 src/bat/api_sign.h create mode 100644 src/bat/dh.c create mode 100644 src/bat/sign.c delete mode 100644 src/include/api.h diff --git a/Makefile b/Makefile index 6ebc1ed..0dc971c 100644 --- a/Makefile +++ b/Makefile @@ -30,6 +30,8 @@ LANGFLAGS = -std=c99 -fno-strict-aliasing GENFLAGS = -ffunction-sections -fdata-sections -fvisibility=hidden -fomit-frame-pointer -fPIC OFLAGS = -O3 +TODAY = $(shell date "+%Y-%m-%d") + ifneq (,$(findstring arm,$(MACHINE))) ifneq (,$(findstring neon,$(ARCH))) ARCHFLAGS += -mfpu=neon @@ -68,7 +70,8 @@ TESTCOMPONENTS=build/test.o build/test_scalarmul.o build/test_sha512.o \ BENCHCOMPONENTS=build/bench.o -BATNAME=build/ed448goldilocks +BATBASE=ed448goldilocks-bats-$(TODAY) +BATNAME=build/$(BATBASE) all: lib build/test build/bench @@ -124,15 +127,21 @@ bat: $(BATNAME) $(BATNAME): include/* src/* src/*/* test/batarch.map rm -fr $@ - (while read arch where; do \ - mkdir -p $@/`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 \ - ) < test/batarch.map - echo 'Mike Hamburg' > $@/designers - echo 'Ed448-Goldilocks sign and dh' > $@/description + for prim in dh sign; do \ + targ="$@/crypto_$$prim/ed448goldilocks"; \ + (while read arch where; do \ + mkdir -p $$targ/`basename $$arch`; \ + cp include/*.h src/*.c src/include/*.h src/bat/$$prim.c src/$$where/*.c src/$$where/*.h $$targ/`basename $$arch`; \ + cp src/bat/api_$$prim.h $$targ/`basename $$arch`/api.h; \ + perl -p -i -e 's/.*endif.*GOLDILOCKS_CONFIG_H/#define SUPERCOP_WONT_LET_ME_OPEN_FILES 1\n\n$$&/' $$targ/`basename $$arch`/config.h; \ + perl -p -i -e 's/SYSNAME/'`basename $(BATNAME)`_`basename $$arch`'/g' $$targ/`basename $$arch`/api.h; \ + perl -p -i -e 's/__TODAY__/'$(TODAY)'/g' $$targ/`basename $$arch`/api.h; \ + done \ + ) < test/batarch.map; \ + echo 'Mike Hamburg' > $$targ/designers; \ + echo 'Ed448-Goldilocks sign and dh' > $$targ/description; \ + done + (cd build && tar czf $(BATBASE).tgz $(BATBASE) ) todo:: diff --git a/src/bat/api_dh.h b/src/bat/api_dh.h new file mode 100644 index 0000000..e266318 --- /dev/null +++ b/src/bat/api_dh.h @@ -0,0 +1,24 @@ +/** + * @file sizes.h + * @copyright + * Copyright (c) 2014 Cryptography Research, Inc. \n + * Released under the MIT License. See LICENSE.txt for license information. + * @author Mike Hamburg + * @brief BATMAN / SUPERCOP glue for benchmarking. + */ + +#include +#include "goldilocks.h" + +#define PUBLICKEY_BYTES GOLDI_PUBLIC_KEY_BYTES +#define SECRETKEY_BYTES GOLDI_PRIVATE_KEY_BYTES +#define SHAREDSECRET_BYTES GOLDI_SHARED_SECRET_BYTES + +#define CRYPTO_PUBLICKEYBYTES PUBLICKEY_BYTES +#define CRYPTO_SECRETKEYBYTES SECRETKEY_BYTES +#define CRYPTO_BYTES SHAREDSECRET_BYTES +#define PRIVATEKEY_BYTES SECRETKEY_BYTES +#define CRYPTO_VERSION "__TODAY__" + +#define CRYPTO_DETERMINISTIC 1 + diff --git a/src/bat/api_sign.h b/src/bat/api_sign.h new file mode 100644 index 0000000..238ebbe --- /dev/null +++ b/src/bat/api_sign.h @@ -0,0 +1,24 @@ +/** + * @file sizes.h + * @copyright + * Copyright (c) 2014 Cryptography Research, Inc. \n + * Released under the MIT License. See LICENSE.txt for license information. + * @author Mike Hamburg + * @brief BATMAN / SUPERCOP glue for benchmarking. + */ + +#include +#include "goldilocks.h" + +#define PUBLICKEY_BYTES GOLDI_PUBLIC_KEY_BYTES +#define SECRETKEY_BYTES GOLDI_PRIVATE_KEY_BYTES +#define SIGNATURE_BYTES GOLDI_SIGNATURE_BYTES + +#define CRYPTO_PUBLICKEYBYTES PUBLICKEY_BYTES +#define CRYPTO_SECRETKEYBYTES SECRETKEY_BYTES +#define CRYPTO_BYTES SIGNATURE_BYTES +#define PRIVATEKEY_BYTES SECRETKEY_BYTES +#define CRYPTO_VERSION "__TODAY__" + +#define CRYPTO_DETERMINISTIC 1 + diff --git a/src/bat/dh.c b/src/bat/dh.c new file mode 100644 index 0000000..51ded53 --- /dev/null +++ b/src/bat/dh.c @@ -0,0 +1,40 @@ +/** + * @file sizes.h + * @copyright + * Copyright (c) 2014 Cryptography Research, Inc. \n + * Released under the MIT License. See LICENSE.txt for license information. + * @author Mike Hamburg + * @brief BATMAN / SUPERCOP glue for benchmarking. + */ + +#include +#include +#include "api.h" +#include "crypto_dh.h" + +int crypto_dh_keypair ( + unsigned char pk[SECRETKEY_BYTES], + unsigned char sk[PUBLICKEY_BYTES] +) { + int ret; + ret = goldilocks_init(); + if (ret && ret != GOLDI_EALREADYINIT) + return ret; + if ((ret = goldilocks_keygen( + (struct goldilocks_private_key_t *)sk, + (struct goldilocks_public_key_t *)pk + ))) abort(); + return ret; +} + +int crypto_dh ( + unsigned char s[SHAREDSECRET_BYTES], + const unsigned char pk[PUBLICKEY_BYTES], + const unsigned char sk[SECRETKEY_BYTES] +) { + return goldilocks_shared_secret ( + s, + (const struct goldilocks_private_key_t *)sk, + (const struct goldilocks_public_key_t *)pk + ); +} diff --git a/src/bat/sign.c b/src/bat/sign.c new file mode 100644 index 0000000..acedc49 --- /dev/null +++ b/src/bat/sign.c @@ -0,0 +1,66 @@ +/** + * @file sizes.h + * @copyright + * Copyright (c) 2014 Cryptography Research, Inc. \n + * Released under the MIT License. See LICENSE.txt for license information. + * @author Mike Hamburg + * @brief BATMAN / SUPERCOP glue for benchmarking. + */ + +#include +#include +#include "api.h" +#include "crypto_sign.h" + +int crypto_sign_keypair ( + unsigned char pk[SECRETKEY_BYTES], + unsigned char sk[PUBLICKEY_BYTES] +) { + int ret; + ret = goldilocks_init(); + if (ret && ret != GOLDI_EALREADYINIT) + return ret; + if ((ret = goldilocks_keygen( + (struct goldilocks_private_key_t *)sk, + (struct goldilocks_public_key_t *)pk + ))) abort(); + return ret; +} + +int crypto_sign ( + unsigned char *sm, + unsigned long long *smlen, + const unsigned char *m, + unsigned long long mlen, + const unsigned char sk[SECRETKEY_BYTES] +) { + unsigned char sig[SIGNATURE_BYTES]; + int ret = goldilocks_sign( + sig, m, mlen, + (const struct goldilocks_private_key_t *)sk + ); + if (!ret) { + memmove(sm + SIGNATURE_BYTES, m, mlen); + memcpy(sm, sig, SIGNATURE_BYTES); + *smlen = mlen + SIGNATURE_BYTES; + } + return ret ? -1 : 0; +} + +int crypto_sign_open ( + unsigned char *m, + unsigned long long *mlen, + const unsigned char *sm, + unsigned long long smlen, + const unsigned char pk[PUBLICKEY_BYTES] +) { + int ret = goldilocks_verify( + sm, sm + SIGNATURE_BYTES, smlen - SIGNATURE_BYTES, + (const struct goldilocks_public_key_t *)pk + ); + if (!ret) { + *mlen = smlen - SIGNATURE_BYTES; + memmove(m, sm + SIGNATURE_BYTES, *mlen); + } + return ret ? -1 : 0; +} diff --git a/src/include/api.h b/src/include/api.h deleted file mode 100644 index 2c8975a..0000000 --- a/src/include/api.h +++ /dev/null @@ -1,118 +0,0 @@ -/** - * @file sizes.h - * @copyright - * Copyright (c) 2014 Cryptography Research, Inc. \n - * Released under the MIT License. See LICENSE.txt for license information. - * @author Mike Hamburg - * @brief BATMAN / SUPERCOP glue for benchmarking. - */ - -#include -#include -#include "goldilocks.h" - -#define PUBLICKEY_BYTES GOLDI_PUBLIC_KEY_BYTES -#define SECRETKEY_BYTES GOLDI_PRIVATE_KEY_BYTES -#define SIGNATURE_BYTES GOLDI_SIGNATURE_BYTES -#define SHAREDSECRET_BYTES GOLDI_SHARED_SECRET_BYTES - -#define crypto_dh_SYSNAME_PUBLICKEYBYTES PUBLICKEY_BYTES -#define crypto_dh_SYSNAME_SECRETKEYBYTES SECRETKEY_BYTES -#define PRIVATEKEY_BYTES SECRETKEY_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 - -/* -#ifndef LOOPS -#define LOOPS 512 -#endif -*/ - -static inline int timingattacks(void) { return 0; } -static inline int copyrightclaims(void) { return 0; } -static inline int patentclaims(void) { - /* Until the end of July 2014, point compression - * is patented. */ - return 20; -} - -static inline int crypto_dh_keypair ( - unsigned char pk[SECRETKEY_BYTES], - unsigned char sk[PUBLICKEY_BYTES] -) { - int ret; - ret = goldilocks_init(); - if (ret && ret != GOLDI_EALREADYINIT) - return ret; - if ((ret = goldilocks_keygen( - (struct goldilocks_private_key_t *)sk, - (struct goldilocks_public_key_t *)pk - ))) abort(); - return ret; -} - -static inline int crypto_sign ( - unsigned char *sm, - unsigned long long *smlen, - const unsigned char *m, - unsigned long long mlen, - const unsigned char sk[SECRETKEY_BYTES] -) { - unsigned char sig[SIGNATURE_BYTES]; - int ret = goldilocks_sign( - sig, m, mlen, - (const struct goldilocks_private_key_t *)sk - ); - 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 ( - unsigned char *m, - unsigned long long *mlen, - const unsigned char *sm, - unsigned long long smlen, - const unsigned char pk[PUBLICKEY_BYTES] -) { - int ret = goldilocks_verify( - sm, sm + SIGNATURE_BYTES, smlen - SIGNATURE_BYTES, - (const struct goldilocks_public_key_t *)pk - ); - if (!ret) { - *mlen = smlen - SIGNATURE_BYTES; - memmove(m, sm + SIGNATURE_BYTES, *mlen); - } - return ret ? -1 : 0; -} - -static inline int crypto_dh ( - unsigned char s[SHAREDSECRET_BYTES], - const unsigned char pk[PUBLICKEY_BYTES], - const unsigned char sk[SECRETKEY_BYTES] -) { - return goldilocks_shared_secret ( - s, - (const struct goldilocks_private_key_t *)sk, - (const struct goldilocks_public_key_t *)pk - ); -} -