From 9972a833a8f47248618c06ba6116897a551a659b Mon Sep 17 00:00:00 2001 From: cathugger Date: Sun, 20 Jan 2019 01:29:02 +0200 Subject: [PATCH] finish porting to amd64-64-24k --- ed25519/amd64-64-24k/ge25519.h | 3 ++ ed25519/ed25519.h | 53 +++++++++++++++++++++++++--------- main.c | 4 +-- 3 files changed, 44 insertions(+), 16 deletions(-) diff --git a/ed25519/amd64-64-24k/ge25519.h b/ed25519/amd64-64-24k/ge25519.h index 491ef80..69af5d7 100644 --- a/ed25519/amd64-64-24k/ge25519.h +++ b/ed25519/amd64-64-24k/ge25519.h @@ -81,6 +81,9 @@ extern int ge25519_unpackneg_vartime(ge25519 *r, const unsigned char p[32]); extern void ge25519_pack(unsigned char r[32], const ge25519 *p); +extern void ge25519_batchpack_destructive_1(bytes32 out[], ge25519_p3 in[], fe25519 *inz[], fe25519 tmp[], size_t num); +extern void ge25519_batchpack_destructive_finish(bytes32 out, ge25519_p3 *unf); + extern int ge25519_isneutral_vartime(const ge25519 *p); extern void ge25519_add(ge25519 *r, const ge25519 *p, const ge25519 *q); diff --git a/ed25519/ed25519.h b/ed25519/ed25519.h index a3388f8..9f527ea 100644 --- a/ed25519/ed25519.h +++ b/ed25519/ed25519.h @@ -2,6 +2,7 @@ #define ED25519_SECRETKEYBYTES 64 #define ED25519_PUBLICKEYBYTES 32 + #ifdef ED25519_ref10 #include "ref10/ed25519.h" #define ed25519_seckey ed25519_ref10_seckey @@ -10,6 +11,8 @@ #define ed25519_keygen ed25519_ref10_keygen #include "ref10/ge.h" +#define GEZ(x) ((x).Z) + /* The basepoint multiplied by 8. */ static const ge_cached ge_eightpoint = { /* YplusX */ @@ -36,13 +39,38 @@ static const ge_cached ge_eightpoint = { inline static void ge_initeightpoint() {} #endif + +#ifdef ED25519_amd64_51_30k +#define ED25519_amd64_common +#else +#ifdef ED25519_amd64_64_24k +#define ED25519_amd64_common +#endif +#endif + + #ifdef ED25519_amd64_51_30k #include "amd64-51-30k/ed25519.h" +#include "amd64-51-30k/ge25519.h" #define ed25519_seckey ed25519_amd64_51_30k_seckey #define ed25519_seckey_expand ed25519_amd64_51_30k_seckey_expand #define ed25519_pubkey ed25519_amd64_51_30k_pubkey #define ed25519_keygen ed25519_amd64_51_30k_keygen -#include "amd64-51-30k/ge25519.h" +#endif + +#ifdef ED25519_amd64_64_24k +#include "amd64-64-24k/ed25519.h" +#include "amd64-64-24k/ge25519.h" +#define ed25519_seckey ed25519_amd64_64_seckey +#define ed25519_seckey_expand ed25519_amd64_64_seckey_expand +#define ed25519_pubkey ed25519_amd64_64_pubkey +#define ed25519_keygen ed25519_amd64_64_keygen +#endif + + +// common +#ifdef ED25519_amd64_common +#define fe fe25519 #define ge_p1p1 ge25519_p1p1 #define ge_p3 ge25519_p3 #define ge_cached ge25519_pniels @@ -50,6 +78,14 @@ inline static void ge_initeightpoint() {} #define ge_p3_tobytes ge25519_pack #define ge_add ge25519_pnielsadd_p1p1 +#define ge_p3_batchtobytes_destructive_1 ge25519_batchpack_destructive_1 +#define ge_p3_batchtobytes_destructive_finish ge25519_batchpack_destructive_finish + +#define GEZ(x) ((x).z) +#endif + + +#ifdef ED25519_amd64_51_30k static inline void ge_scalarmult_base(ge_p3 *gepk,const unsigned char *sk) { sc25519 scsk; @@ -72,20 +108,8 @@ static const ge25519_pniels ge_eightpoint = { inline static void ge_initeightpoint() {} #endif -#ifdef ED25519_amd64_64_24k -#include "amd64-64-24k/ed25519.h" -#define ed25519_seckey ed25519_amd64_64_seckey -#define ed25519_seckey_expand ed25519_amd64_64_seckey_expand -#define ed25519_pubkey ed25519_amd64_64_pubkey -#define ed25519_keygen ed25519_amd64_64_keygen -#include "amd64-64-24k/ge25519.h" -#define ge_p1p1 ge25519_p1p1 -#define ge_p3 ge25519_p3 -#define ge_cached ge25519_pniels -#define ge_p1p1_to_p3 ge25519_p1p1_to_p3 -#define ge_p3_tobytes ge25519_pack -#define ge_add ge25519_pnielsadd_p1p1 +#ifdef ED25519_amd64_64_24k static inline void ge_scalarmult_base(ge_p3 *gepk,const unsigned char *sk) { sc25519 scsk; @@ -108,6 +132,7 @@ static const ge25519_pniels ge_eightpoint = { inline static void ge_initeightpoint() {} #endif + #ifdef ED25519_donna #define ED25519_CUSTOMRANDOM #define ED25519_CUSTOMHASH diff --git a/main.c b/main.c index 472d6b4..b374930 100644 --- a/main.c +++ b/main.c @@ -520,7 +520,7 @@ end: #ifdef BATCHKEYGEN #ifndef BATCHNUM -#define BATCHNUM 64 +#define BATCHNUM 256 #endif static void *dobatchwork(void *task) @@ -547,7 +547,7 @@ static void *dobatchwork(void *task) #endif for (size_t b = 0;b < BATCHNUM;++b) - batchgez[b] = &ge_batch[b].Z; + batchgez[b] = &GEZ(ge_batch[b]); PREFILTER