remove BATCHNUM limitations
[mkp224o.git] / worker_fast.inc.h
blobdb57b0b25ef2713c77298adb4998be43af04b8af
2 void *worker_fast(void *task)
4 union pubonionunion pubonion;
5 u8 * const pk = &pubonion.raw[PKPREFIX_SIZE];
6 u8 secret[SKPREFIX_SIZE + SECRET_LEN];
7 u8 * const sk = &secret[SKPREFIX_SIZE];
8 u8 seed[SEED_LEN];
9 u8 hashsrc[checksumstrlen + PUBLIC_LEN + 1];
10 u8 wpk[PUBLIC_LEN + 1];
11 ge_p3 ge_public;
12 char *sname;
14 size_t counter;
15 size_t i;
17 #ifdef STATISTICS
18 struct statstruct *st = (struct statstruct *)task;
19 #else
20 (void) task;
21 #endif
23 PREFILTER
25 memcpy(secret,skprefix,SKPREFIX_SIZE);
26 wpk[PUBLIC_LEN] = 0;
27 memset(&pubonion,0,sizeof(pubonion));
28 memcpy(pubonion.raw,pkprefix,PKPREFIX_SIZE);
29 // write version later as it will be overwritten by hash
30 memcpy(hashsrc,checksumstr,checksumstrlen);
31 hashsrc[checksumstrlen + PUBLIC_LEN] = 0x03; // version
33 sname = makesname();
35 initseed:
36 #ifdef STATISTICS
37 ++st->numrestart.v;
38 #endif
40 randombytes(seed,sizeof(seed));
42 ed25519_seckey_expand(sk,seed);
44 ge_scalarmult_base(&ge_public,sk);
45 ge_p3_tobytes(pk,&ge_public);
47 for (counter = 0;counter < SIZE_MAX-8;counter += 8) {
48 ge_p1p1 sum;
50 if (unlikely(endwork))
51 goto end;
53 DOFILTER(i,pk,{
54 if (numwords > 1) {
55 shiftpk(wpk,pk,filter_len(i));
56 size_t j;
57 for (int w = 1;;) {
58 DOFILTER(j,wpk,goto secondfind);
59 goto next;
60 secondfind:
61 if (++w >= numwords)
62 break;
63 shiftpk(wpk,wpk,filter_len(j));
66 // found!
67 // update secret key with counter
68 addsztoscalar32(sk,counter);
69 // sanity check
70 if ((sk[0] & 248) != sk[0] || ((sk[31] & 63) | 64) != sk[31])
71 goto initseed;
73 ADDNUMSUCCESS;
75 // calc checksum
76 memcpy(&hashsrc[checksumstrlen],pk,PUBLIC_LEN);
77 FIPS202_SHA3_256(hashsrc,sizeof(hashsrc),&pk[PUBLIC_LEN]);
78 // version byte
79 pk[PUBLIC_LEN + 2] = 0x03;
80 // full name
81 strcpy(base32_to(&sname[direndpos],pk,PUBONION_LEN),".onion");
82 onionready(sname,secret,pubonion.raw);
83 pk[PUBLIC_LEN] = 0; // what is this for?
84 // don't reuse same seed
85 goto initseed;
86 });
87 next:
88 ge_add(&sum,&ge_public,&ge_eightpoint);
89 ge_p1p1_to_p3(&ge_public,&sum);
90 ge_p3_tobytes(pk,&ge_public);
91 #ifdef STATISTICS
92 ++st->numcalc.v;
93 #endif
95 goto initseed;
97 end:
98 free(sname);
99 POSTFILTER
100 sodium_memzero(secret,sizeof(secret));
101 sodium_memzero(seed,sizeof(seed));
102 return 0;