some tweaks
[mkp224o.git] / worker_slow.inc.h
blob799e4aa2f2e0998384dcfb8770bcd4ec8a643934
2 void *worker_slow(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 char *sname;
13 size_t i;
15 #ifdef STATISTICS
16 struct statstruct *st = (struct statstruct *)task;
17 #else
18 (void) task;
19 #endif
20 PREFILTER
22 memcpy(secret,skprefix,SKPREFIX_SIZE);
23 wpk[PUBLIC_LEN] = 0;
24 memset(&pubonion,0,sizeof(pubonion));
25 memcpy(pubonion.raw,pkprefix,PKPREFIX_SIZE);
26 // write version later as it will be overwritten by hash
27 memcpy(hashsrc,checksumstr,checksumstrlen);
28 hashsrc[checksumstrlen + PUBLIC_LEN] = 0x03; // version
30 sname = makesname();
32 initseed:
33 randombytes(seed,sizeof(seed));
34 ed25519_seckey_expand(sk,seed);
35 #ifdef STATISTICS
36 ++st->numrestart.v;
37 #endif
39 again:
40 if (unlikely(endwork))
41 goto end;
43 ed25519_pubkey(pk,sk);
45 #ifdef STATISTICS
46 ++st->numcalc.v;
47 #endif
49 DOFILTER(i,pk,{
50 if (numwords > 1) {
51 shiftpk(wpk,pk,filter_len(i));
52 size_t j;
53 for (int w = 1;;) {
54 DOFILTER(j,wpk,goto secondfind);
55 goto next;
56 secondfind:
57 if (++w >= numwords)
58 break;
59 shiftpk(wpk,wpk,filter_len(j));
62 // sanity check
63 if ((sk[0] & 248) != sk[0] || ((sk[31] & 63) | 64) != sk[31])
64 goto initseed;
66 ADDNUMSUCCESS;
68 // calc checksum
69 memcpy(&hashsrc[checksumstrlen],pk,PUBLIC_LEN);
70 FIPS202_SHA3_256(hashsrc,sizeof(hashsrc),&pk[PUBLIC_LEN]);
71 // version byte
72 pk[PUBLIC_LEN + 2] = 0x03;
73 // base32
74 strcpy(base32_to(&sname[direndpos],pk,PUBONION_LEN),".onion");
75 onionready(sname,secret,pubonion.raw);
76 pk[PUBLIC_LEN] = 0; // what is this for?
77 goto initseed;
78 });
79 next:
80 addsk32(sk);
81 goto again;
83 end:
84 free(sname);
85 POSTFILTER
86 sodium_memzero(secret,sizeof(secret));
87 sodium_memzero(seed,sizeof(seed));
88 return 0;