implement worker_batch_pass
[mkp224o.git] / worker_fast_pass.inc.h
blob8b698efc764d0196d859ed3678e094cfdbbe004e
2 #ifdef PASSPHRASE
3 void *worker_fast_pass(void *task)
5 union pubonionunion pubonion;
6 u8 * const pk = &pubonion.raw[PKPREFIX_SIZE];
7 u8 secret[SKPREFIX_SIZE + SECRET_LEN];
8 u8 * const sk = &secret[SKPREFIX_SIZE];
9 u8 seed[SEED_LEN];
10 u8 hashsrc[checksumstrlen + PUBLIC_LEN + 1];
11 u8 wpk[PUBLIC_LEN + 1];
12 ge_p3 ge_public;
13 char *sname;
15 size_t counter,oldcounter;
16 size_t i;
18 #ifdef STATISTICS
19 struct statstruct *st = (struct statstruct *)task;
20 #else
21 (void) task;
22 #endif
24 PREFILTER
26 memcpy(secret,skprefix,SKPREFIX_SIZE);
27 wpk[PUBLIC_LEN] = 0;
28 memset(&pubonion,0,sizeof(pubonion));
29 memcpy(pubonion.raw,pkprefix,PKPREFIX_SIZE);
30 // write version later as it will be overwritten by hash
31 memcpy(hashsrc,checksumstr,checksumstrlen);
32 hashsrc[checksumstrlen + PUBLIC_LEN] = 0x03; // version
34 sname = makesname();
36 initseed:
37 #ifdef STATISTICS
38 ++st->numrestart.v;
39 #endif
41 pthread_mutex_lock(&determseed_mutex);
42 for (int i = 0; i < SEED_LEN; i++)
43 if (++determseed[i])
44 break;
45 memcpy(seed, determseed, SEED_LEN);
46 pthread_mutex_unlock(&determseed_mutex);
48 ed25519_seckey_expand(sk,seed);
50 ge_scalarmult_base(&ge_public,sk);
51 ge_p3_tobytes(pk,&ge_public);
53 for (counter = oldcounter = 0;counter < DETERMINISTIC_LOOP_COUNT;counter += 8) {
54 ge_p1p1 sum;
56 if (unlikely(endwork))
57 goto end;
59 DOFILTER(i,pk,{
60 if (numwords > 1) {
61 shiftpk(wpk,pk,filter_len(i));
62 size_t j;
63 for (int w = 1;;) {
64 DOFILTER(j,wpk,goto secondfind);
65 goto next;
66 secondfind:
67 if (++w >= numwords)
68 break;
69 shiftpk(wpk,wpk,filter_len(j));
72 // found!
73 // update secret key with delta since last hit (if any)
74 addsztoscalar32(sk,counter-oldcounter);
75 oldcounter = counter;
76 // sanity check
77 if ((sk[0] & 248) != sk[0] || ((sk[31] & 63) | 64) != sk[31])
78 goto initseed;
80 // reseed right half of key to avoid reuse, it won't change public key anyway
81 reseedright(sk);
83 ADDNUMSUCCESS;
85 // calc checksum
86 memcpy(&hashsrc[checksumstrlen],pk,PUBLIC_LEN);
87 FIPS202_SHA3_256(hashsrc,sizeof(hashsrc),&pk[PUBLIC_LEN]);
88 // version byte
89 pk[PUBLIC_LEN + 2] = 0x03;
90 // full name
91 strcpy(base32_to(&sname[direndpos],pk,PUBONION_LEN),".onion");
92 onionready(sname,secret,pubonion.raw);
93 pk[PUBLIC_LEN] = 0; // what is this for?
94 });
95 next:
96 ge_add(&sum, &ge_public,&ge_eightpoint);
97 ge_p1p1_to_p3(&ge_public,&sum);
98 ge_p3_tobytes(pk,&ge_public);
99 #ifdef STATISTICS
100 ++st->numcalc.v;
101 #endif
103 goto initseed;
105 end:
106 free(sname);
107 POSTFILTER
108 sodium_memzero(secret,sizeof(secret));
109 sodium_memzero(seed,sizeof(seed));
110 return 0;
112 #endif // PASSPHRASE