From 6438396a33c7b8feabf2d9c02d55742c854b36e1 Mon Sep 17 00:00:00 2001 From: cathugger Date: Thu, 5 May 2022 23:18:41 +0300 Subject: [PATCH] more :> --- ed25519/ed25519_impl_pre.h | 1 + main.c | 10 +++--- worker.c | 63 ++++++++++++++++++++++++++++---------- worker.h | 10 +++--- worker_batch.inc.h | 2 +- worker_batch_pass.inc.h | 2 +- worker_fast.inc.h | 2 +- worker_fast_pass.inc.h | 2 +- worker_impl.inc.h | 16 +++++++++- worker_slow.inc.h | 2 +- 10 files changed, 78 insertions(+), 32 deletions(-) diff --git a/ed25519/ed25519_impl_pre.h b/ed25519/ed25519_impl_pre.h index 375c9b0..bc84ad9 100644 --- a/ed25519/ed25519_impl_pre.h +++ b/ed25519/ed25519_impl_pre.h @@ -1,3 +1,4 @@ + #ifndef ED25519_donna # if defined(_MSC_VER) # define ALIGN(x) __declspec(align(x)) diff --git a/main.c b/main.c index b8aaabb..1943817 100644 --- a/main.c +++ b/main.c @@ -666,16 +666,16 @@ int main(int argc,char **argv) #ifdef PASSPHRASE deterministic ? (wt == WT_BATCH - ? worker_batch_pass - : worker_fast_pass) + ? CRYPTO_NAMESPACE(worker_batch_pass) + : CRYPTO_NAMESPACE(worker_fast_pass)) : #endif wt == WT_BATCH - ? worker_batch + ? CRYPTO_NAMESPACE(worker_batch) : wt == WT_FAST - ? worker_fast - : worker_slow, + ? CRYPTO_NAMESPACE(worker_fast) + : CRYPTO_NAMESPACE(worker_slow), tp ); if (tret) { diff --git a/worker.c b/worker.c index 2a3d2e9..b9a6476 100644 --- a/worker.c +++ b/worker.c @@ -17,8 +17,6 @@ #include "vec.h" #include "base32.h" #include "keccak.h" -#include "ed25519/ed25519.h" -#include "ed25519/ed25519_impl_pre.h" #include "ioutil.h" #include "common.h" #include "yaml.h" @@ -53,10 +51,6 @@ size_t numneedgenerate = 0; char *workdir = 0; size_t workdirlen = 0; -void worker_init(void) -{ - ge_initeightpoint(); -} #ifdef PASSPHRASE // How many times we loop before a reseed @@ -218,20 +212,57 @@ static void reseedright(u8 sk[SECRET_LEN]) #define BATCHNUM 2048 #endif + +#include "ed25519/ed25519.h" + +#include "worker_impl.inc.h" + size_t worker_batch_memuse(void) { - return (sizeof(ge_p3) + sizeof(fe) + sizeof(bytes32)) * BATCHNUM; + size_t s = 0,x; + +#ifdef ED25519_ref10 + x = crypto_sign_ed25519_ref10_worker_batch_memuse(); + if (x > s) + s = x; +#endif + +#ifdef ED25519_amd64_51_30k + x = crypto_sign_ed25519_amd64_51_30k_worker_batch_memuse(); + if (x > s) + s = x; +#endif + +#ifdef ED25519_amd64_64_24k + x = crypto_sign_ed25519_amd64_64_24k_worker_batch_memuse(); + if (x > s) + s = x; +#endif + +#ifdef ED25519_donna + x = crypto_sign_ed25519_donna_worker_batch_memuse(); + if (x > s) + s = x; +#endif + + return s; } -#include "worker_slow.inc.h" +void worker_init(void) +{ +#ifdef ED25519_ref10 + crypto_sign_ed25519_ref10_ge_initeightpoint(); +#endif -#include "worker_fast.inc.h" +#ifdef ED25519_amd64_51_30k + crypto_sign_ed25519_amd64_51_30k_ge_initeightpoint(); +#endif -#include "worker_fast_pass.inc.h" +#ifdef ED25519_amd64_64_24k + crypto_sign_ed25519_amd64_64_24k_ge_initeightpoint(); +#endif -#include "worker_batch.inc.h" - -#include "worker_batch_pass.inc.h" - -// XXX this is useless here, but will end up somewhere like that when i'll modularize stuff -#include "ed25519/ed25519_impl_post.h" +#ifdef ED25519_donna + crypto_sign_ed25519_donna_ge_initeightpoint(); +#endif +} diff --git a/worker.h b/worker.h index 7f50f6f..36912a0 100644 --- a/worker.h +++ b/worker.h @@ -40,10 +40,10 @@ extern void worker_init(void); extern char *makesname(void); extern size_t worker_batch_memuse(void); -extern void *worker_slow(void *task); -extern void *worker_fast(void *task); -extern void *worker_batch(void *task); +extern void *CRYPTO_NAMESPACE(worker_slow)(void *task); +extern void *CRYPTO_NAMESPACE(worker_fast)(void *task); +extern void *CRYPTO_NAMESPACE(worker_batch)(void *task); #ifdef PASSPHRASE -extern void *worker_fast_pass(void *task); -extern void *worker_batch_pass(void *task); +extern void *CRYPTO_NAMESPACE(worker_fast_pass)(void *task); +extern void *CRYPTO_NAMESPACE(worker_batch_pass)(void *task); #endif diff --git a/worker_batch.inc.h b/worker_batch.inc.h index 2e0788f..7eb5cd6 100644 --- a/worker_batch.inc.h +++ b/worker_batch.inc.h @@ -1,5 +1,5 @@ -void *worker_batch(void *task) +void *CRYPTO_NAMESPACE(worker_batch)(void *task) { union pubonionunion pubonion; u8 * const pk = &pubonion.raw[PKPREFIX_SIZE]; diff --git a/worker_batch_pass.inc.h b/worker_batch_pass.inc.h index 44006ff..0fa49ff 100644 --- a/worker_batch_pass.inc.h +++ b/worker_batch_pass.inc.h @@ -1,6 +1,6 @@ #ifdef PASSPHRASE -void *worker_batch_pass(void *task) +void *CRYPTO_NAMESPACE(worker_batch_pass)(void *task) { union pubonionunion pubonion; u8 * const pk = &pubonion.raw[PKPREFIX_SIZE]; diff --git a/worker_fast.inc.h b/worker_fast.inc.h index 1d7443f..b9ec7a0 100644 --- a/worker_fast.inc.h +++ b/worker_fast.inc.h @@ -1,5 +1,5 @@ -void *worker_fast(void *task) +void *CRYPTO_NAMESPACE(worker_fast)(void *task) { union pubonionunion pubonion; u8 * const pk = &pubonion.raw[PKPREFIX_SIZE]; diff --git a/worker_fast_pass.inc.h b/worker_fast_pass.inc.h index 132aed6..793d600 100644 --- a/worker_fast_pass.inc.h +++ b/worker_fast_pass.inc.h @@ -1,6 +1,6 @@ #ifdef PASSPHRASE -void *worker_fast_pass(void *task) +void *CRYPTO_NAMESPACE(worker_fast_pass)(void *task) { union pubonionunion pubonion; u8 * const pk = &pubonion.raw[PKPREFIX_SIZE]; diff --git a/worker_impl.inc.h b/worker_impl.inc.h index 70b786d..fbd7b0f 100644 --- a/worker_impl.inc.h +++ b/worker_impl.inc.h @@ -1 +1,15 @@ -// TODO + +#include "ed25519/ed25519_impl_pre.h" + +static size_t CRYPTO_NAMESPACE(worker_batch_memuse)(void) +{ + return (sizeof(ge_p3) + sizeof(fe) + sizeof(bytes32)) * BATCHNUM; +} + +#include "worker_slow.inc.h" +#include "worker_fast.inc.h" +#include "worker_fast_pass.inc.h" +#include "worker_batch.inc.h" +#include "worker_batch_pass.inc.h" + +#include "ed25519/ed25519_impl_post.h" diff --git a/worker_slow.inc.h b/worker_slow.inc.h index 278b58b..ab75ef2 100644 --- a/worker_slow.inc.h +++ b/worker_slow.inc.h @@ -1,5 +1,5 @@ -void *worker_slow(void *task) +void *CRYPTO_NAMESPACE(worker_slow)(void *task) { union pubonionunion pubonion; u8 * const pk = &pubonion.raw[PKPREFIX_SIZE];