explicit void params declarations, add warnings to keep it correct
[mkp224o.git] / worker_fast.inc.h
blob31726568116d2d661162d8ce86bf9531f2fd0e77
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
39 randombytes(seed,sizeof(seed));
40 ed25519_seckey_expand(sk,seed);
42 ge_scalarmult_base(&ge_public,sk);
43 ge_p3_tobytes(pk,&ge_public);
45 for (counter = 0;counter < SIZE_MAX-8;counter += 8) {
46 ge_p1p1 sum;
48 if (unlikely(endwork))
49 goto end;
51 DOFILTER(i,pk,{
52 if (numwords > 1) {
53 shiftpk(wpk,pk,filter_len(i));
54 size_t j;
55 for (int w = 1;;) {
56 DOFILTER(j,wpk,goto secondfind);
57 goto next;
58 secondfind:
59 if (++w >= numwords)
60 break;
61 shiftpk(wpk,wpk,filter_len(j));
64 // found!
65 // update secret key with counter
66 addsztoscalar32(sk,counter);
67 // sanity check
68 if ((sk[0] & 248) != sk[0] || ((sk[31] & 63) | 64) != sk[31])
69 goto initseed;
71 ADDNUMSUCCESS;
73 // calc checksum
74 memcpy(&hashsrc[checksumstrlen],pk,PUBLIC_LEN);
75 FIPS202_SHA3_256(hashsrc,sizeof(hashsrc),&pk[PUBLIC_LEN]);
76 // version byte
77 pk[PUBLIC_LEN + 2] = 0x03;
78 // full name
79 strcpy(base32_to(&sname[direndpos],pk,PUBONION_LEN),".onion");
80 onionready(sname,secret,pubonion.raw);
81 pk[PUBLIC_LEN] = 0; // what is this for?
82 // don't reuse same seed
83 goto initseed;
84 });
85 next:
86 ge_add(&sum,&ge_public,&ge_eightpoint);
87 ge_p1p1_to_p3(&ge_public,&sum);
88 ge_p3_tobytes(pk,&ge_public);
89 #ifdef STATISTICS
90 ++st->numcalc.v;
91 #endif
93 goto initseed;
95 end:
96 free(sname);
97 POSTFILTER
98 sodium_memzero(secret,sizeof(secret));
99 sodium_memzero(seed,sizeof(seed));
100 return 0;