Allow mining without --basekey again.

This commit is contained in:
dzwdz 2023-05-31 09:50:08 +00:00
parent 476d135747
commit 532b61e4f9
4 changed files with 18 additions and 21 deletions

5
main.c
View file

@ -682,11 +682,6 @@ int main(int argc,char **argv)
exit(1); exit(1);
} }
if (basekeys == 0) {
fprintf(stderr, "This build requires using --basekey.\n");
exit(1);
}
if (yamlinput && yamloutput) { if (yamlinput && yamloutput) {
fprintf(stderr,"both -y and -Y does not make sense\n"); fprintf(stderr,"both -y and -Y does not make sense\n");
exit(1); exit(1);

View file

@ -211,7 +211,7 @@ static void reseedright(u8 sk[SECRET_LEN])
#include "ed25519/ed25519_impl_pre.h" #include "ed25519/ed25519_impl_pre.h"
ge_p3 ALIGN(16) PUBKEY_BASE; ge_p3 ALIGN(16) PUBKEY_BASE;
int pubkey_base_initialized; int pubkey_base_initialized = 0;
#include "worker_impl.inc.h" // uses those globals #include "worker_impl.inc.h" // uses those globals
@ -219,14 +219,18 @@ void ed25519_pubkey_addbase(const u8 base_pk[32])
{ {
ge_p3 ALIGN(16) A; ge_p3 ALIGN(16) A;
u8 tmp_pk[32]; u8 tmp_pk[32];
ge_frombytes_negate_vartime(&A, base_pk); ge_frombytes_negate_vartime(&A, base_pk);
// dumb hack: unpack flips the point. to get the original point // dumb hack: The only available frombytes function flips the point.
// back, i just pack and unpack it again // To get the original point back, I can just pack and unpack it again.
ge_p3_tobytes(tmp_pk, &A); ge_p3_tobytes(tmp_pk, &A);
ge_frombytes_negate_vartime(&A, tmp_pk); ge_frombytes_negate_vartime(&A, tmp_pk);
if (!pubkey_base_initialized) { if (!pubkey_base_initialized) {
// note: PUBKEY_BASE could be initialized to the point at infinity
// to remove the need for pubkey_base_initialized.
pubkey_base_initialized = 1; pubkey_base_initialized = 1;
PUBKEY_BASE = A; // TODO use a proper cpy fn if any PUBKEY_BASE = A;
} else { } else {
ge25519_add(&PUBKEY_BASE, &PUBKEY_BASE, &A); ge25519_add(&PUBKEY_BASE, &PUBKEY_BASE, &A);
} }
@ -235,14 +239,11 @@ void ed25519_pubkey_addbase(const u8 base_pk[32])
static int ed25519_pubkey_onbase(u8 *pk,const u8 *sk) static int ed25519_pubkey_onbase(u8 *pk,const u8 *sk)
{ {
ge_p3 ALIGN(16) A; ge_p3 ALIGN(16) A;
if (unlikely(pubkey_base_initialized == 0))
abort();
ge_scalarmult_base(&A, sk); ge_scalarmult_base(&A, sk);
ge25519_add(&A, &A, &PUBKEY_BASE); if (pubkey_base_initialized) {
ge25519_add(&A, &A, &PUBKEY_BASE);
}
ge_p3_tobytes(pk,&A); ge_p3_tobytes(pk,&A);
return 0; return 0;
} }
@ -251,7 +252,7 @@ static void sanitycheck(const u8 *sk, const u8 *pk) {
u8 testpk[PUBLIC_LEN]; u8 testpk[PUBLIC_LEN];
ed25519_pubkey_onbase(testpk, sk); ed25519_pubkey_onbase(testpk, sk);
if (memcmp(testpk,pk,PUBLIC_LEN) != 0) { if (memcmp(testpk,pk,PUBLIC_LEN) != 0) {
fprintf(stderr, "Sanity check failed. Either I fucked something up, or you're using an unsupported combination of options. Probably both.\n"); fprintf(stderr, "Sanity check failed. Please report this on Github, including the command line parameters you've used.\n");
abort(); abort();
} }
} }

View file

@ -25,9 +25,6 @@ void *CRYPTO_NAMESPACE(worker_batch)(void *task)
(void) task; (void) task;
#endif #endif
if (unlikely(pubkey_base_initialized == 0))
abort();
PREFILTER PREFILTER
memcpy(secret,skprefix,SKPREFIX_SIZE); memcpy(secret,skprefix,SKPREFIX_SIZE);
@ -50,7 +47,9 @@ initseed:
ed25519_seckey_expand(sk,seed); ed25519_seckey_expand(sk,seed);
ge_scalarmult_base(&ge_public,sk); ge_scalarmult_base(&ge_public,sk);
ge25519_add(&ge_public, &ge_public, &PUBKEY_BASE); if (pubkey_base_initialized) {
ge25519_add(&ge_public, &ge_public, &PUBKEY_BASE);
}
for (counter = 0;counter < SIZE_MAX-(8*BATCHNUM);counter += 8*BATCHNUM) { for (counter = 0;counter < SIZE_MAX-(8*BATCHNUM);counter += 8*BATCHNUM) {
ge_p1p1 ALIGN(16) sum; ge_p1p1 ALIGN(16) sum;

View file

@ -42,7 +42,9 @@ initseed:
ed25519_seckey_expand(sk,seed); ed25519_seckey_expand(sk,seed);
ge_scalarmult_base(&ge_public,sk); ge_scalarmult_base(&ge_public,sk);
ge25519_add(&ge_public, &ge_public, &PUBKEY_BASE); if (pubkey_base_initialized) {
ge25519_add(&ge_public, &ge_public, &PUBKEY_BASE);
}
ge_p3_tobytes(pk,&ge_public); ge_p3_tobytes(pk,&ge_public);
for (counter = 0;counter < SIZE_MAX-8;counter += 8) { for (counter = 0;counter < SIZE_MAX-8;counter += 8) {