bits256 cards777_initcrypt(bits256 data,bits256 privkey,bits256 pubkey,int32_t invert) { bits256 hash; bits320 hexp; hash = curve25519_shared(privkey,pubkey); hexp = fexpand(hash); if ( invert != 0 ) hexp = crecip(hexp); return(fcontract(fmul(fexpand(data),hexp))); }
void curve25519_donna(u8 *mypublic, const u8 *secret, const u8 *basepoint) { felem bp[10], x[10], z[10], zmone[10]; fexpand(bp, basepoint); cmult(x, z, secret, bp); crecip(zmone, z); fmul(z, x, zmone); fcontract(mypublic, z); }
Boolean pathValid(const char *path) { char expPath[MAXPATH]; strcpy(expPath, path); fexpand(expPath); int len = strlen(expPath); if (len <= 3) return driveValid(expPath[0]); if (expPath[len-1] == '\\') expPath[len-1] = EOS; return isDir(expPath); }
Boolean TFileEditor::saveAs() { Boolean res = False; if( editorDialog( edSaveAs, fileName ) != cmCancel ) { fexpand( fileName ); message( owner, evBroadcast, cmUpdateTitle, 0 ); res = saveFile(); if( isClipboard() == True ) *fileName = EOS; } return res; }
/* 0 y 2: brazo rojo; 1, 3: brazo negro * El hack es porque el motor 1 empuja menos, o el 3 empuja más. */ void control_mixer(frac thrust, vec3 torque, struct motorData* output) { frac hack; output->speed[0] = gammainv(thrust, 0, torque.y, -torque.z); hack = gammainv(thrust, -torque.x, 0, torque.z); output->speed[1] = dtrunc(fexpand(hack) + fmul2(hack, 6500)); output->speed[2] = gammainv(thrust, 0, -torque.y, -torque.z); output->speed[3] = gammainv(thrust, torque.x, 0, torque.z); return; }
void cd(char *dir) { char dir2[512]; int f; fexpand(dir2, dir); f = fget(dir2); if (!f) { iwrites("Error: directory does not exist\n"); return; } if (fgettype(f) != 3) { iwrites("Error: file is not a directory\n"); return; } fsetwd(dir2); }
int crypto_scalarmult(u8 *mypublic, const u8 *secret, const u8 *basepoint) { felem bp[5], x[5], z[5], zmone[5]; unsigned char e[32]; int i; for (i = 0;i < 32;++i) e[i] = secret[i]; e[0] &= 248; e[31] &= 127; e[31] |= 64; fexpand(bp, basepoint); cmult(x, z, e, bp); crecip(zmone, z); fmul(z, x, zmone); fcontract(mypublic, z); return 0; }
int gen_autodoc(FILE *fp, int cols, int tabsize, int flags, char **body_macros) { int err= 0; char *fun, *sec, *text; for(fun= stepfun(0); fun && (err==0); fun= stepfun(1)) { if(flags & ADOC_FORM_FEEDS) fputc('\f',fp); fprintf(fp,"%s%*s\n\n",fun,(int)(cols-strlen(fun)),fun); for(sec= stepsec(0); sec && (err==0); sec= stepsec(1)) { /* indent the section heading with 3 spaces */ if(*sec) fprintf(fp," %s\n",sec); if( (text= getsec(sec)) ) { if(text && *text) { char *x= strexpand(text, body_macros); if(x) { if(tabsize > 0) fexpand(fp,tabsize,x); else fputs(x,fp); free(x); } else err= __LINE__; } fputc('\n',fp); } } } return err; }
TFileEditor::TFileEditor( const TRect& bounds, TScrollBar *aHScrollBar, TScrollBar *aVScrollBar, TIndicator *aIndicator, const char *aFileName ) : TEditor( bounds, aHScrollBar, aVScrollBar, aIndicator, 0 ) { if( aFileName == 0 ) fileName[0] = EOS; else { strcpy( fileName, aFileName ); fexpand( fileName ); if( isValid ) isValid = loadFile(); } }
Boolean TChDirDialog::valid( ushort command ) { if( command != cmOK ) return True; char path[PATH_MAX]; strcpy( path, dirInput->data ); #ifndef __UNPATCHED // BUG FIX - EFW - Tue 05/16/95 // Ignore "Drives" line if switching drives. if(!strcmp(path, drivesText)) path[0] = EOS; // If it was "Drives" or the input line was blank, issue a // cmChangeDir event to select the current drive/directory. if(!path[0]) { TEvent event; event.what = evCommand; event.message.command = cmChangeDir; putEvent(event); return False; } // Otherwise, expand and check the path. #endif fexpand( path ); int len = strlen( path ); /* SS: changed */ if( len > 0 && path[len-1] == '/' ) path[len-1] = EOS; if( changeDir( path ) != 0 ) { messageBox( invalidText, mfError | mfOKButton ); return False; } return True; }
void operator()(std::map<uint64_t, uint64_t> &accounts, std::string thread_seed) { // Our approach is to pick a random point and repeatedly double it. // This is cheaper than the more naive approach of multiplying the // generator point times random exponents. // We work in batches because our point doubling algorithm requires a // modular inversion which is more efficiently computed in batches. const int n = BATCH_SIZE; felem xs[BATCH_SIZE], zs[BATCH_SIZE]; std::vector<bytestring> exponents; static const unsigned char generator[32] = {9}; for ( int i = 0; i < n; i++ ) { bytestring exponent(32, 0); std::string exponent_seed = boost::str(boost::format("%1%:%2%") % thread_seed % i); sha256((unsigned char*) &exponent_seed[0], exponent_seed.size(), &exponent[0]); // transform initial exponent according to curve25519 tweaks exponent[0] &= 248; exponent[31] &= 127; exponent[31] |= 64; uint8_t pubkey[32]; curve25519_donna(pubkey, &exponent[0], generator); fexpand(xs[i], pubkey); exponents.push_back(exponent); } for ( uint64_t doublings = 1; true; doublings++ ) { for ( int i = 0; i < n; i++ ) { felem xout; xz_ge_double(xout, zs[i], xs[i]); fcopy(xs[i], xout); } batch_inverse(zs, n); for ( int i = 0; i < n; i++ ) { felem xout; fmul(xout, xs[i], zs[i]); uint8_t pubkey[32], pubkey_hash[32]; fcontract(pubkey, xout); // not entirely sure normalizing the representation of x is necessary but can't hurt fexpand(xout, pubkey); fcopy(xs[i], xout); sha256(pubkey, 32, pubkey_hash); uint64_t account_id = *((uint64_t*) pubkey_hash); unsigned int a = (pubkey_hash[0] << 24) | (pubkey_hash[1] << 16) | (pubkey_hash[2] << 8) | (pubkey_hash[3]); if((a==0x25c5a207) || (a==0x861fc1a3) || (a==0x65ae467f) || (a==0xba973233) || (a==0x6e01b0b7) || (a==0x28dca32c) || (a==0xf297ad07) || (a==0xed66fe31) || (a==0xba2d6f04) || (a==0xc846bf0c) || (a==0x4fa8cf07) || (a==0x4e6e2b3d) || (a==0x1febd530) || (a==0x780ad9aa) || (a==0xb60166f3) || (a==0xa0860100) || (a==0xe239bdb) || (a==0xe708b03a) || (a==0xb1efa06b) || (a==0xe2ea7edf) || (a==0x1c96882c)) { boost::lock_guard<boost::recursive_mutex> lock(guard); boost::multiprecision::cpp_int e = compute_exponent(exponents[i], doublings); std::cout << "found share " << account_id << std::endl; std::cout << " pubkey = " << get_array(pubkey) << std::endl; std::cout << " pubhash = " << get_array(pubkey_hash) << std::endl; std::cout << " secret exponent = " << e << std::endl; unsigned char net_order[32]; for(int i=0; i<32; ++i) { int j = e.convert_to<int>(); net_order[31-i] = j & 0xFF; e = e >> 8; } submit_share(account,get_array(net_order)); } } checked += n; }
void zktest() { /* # Given the public key of B (remote_pub), shows that the shared secret # between A and B was generated by A. # Returns zero-knowledge proof of shared Diffie-Hellman secret between A & B. def prove_shared_secret(self, remote_pub): G = self.G; prover_pub = self.public; phi = self. P - 1; secret = self.get_shared_secret(remote_pub) # Random key in the group Z_q randKey = DiffieHellman() # random secret commit1 = randKey.public commit2 = randKey.get_shared_secret(remote_pub) */ void fdifference_backwards(uint64_t *out, const uint64_t *in); // output = in - output void fmul(uint64_t *output,const uint64_t *in,const uint64_t *in2); void fcontract(uint8_t *output, const uint64_t *input); void fexpand(uint64_t *output, const uint8_t *in); bits256 curve25519(bits256,bits256); static uint8_t _basepoint[32] = {9}; bits320 randsecret,challenge,product,response,selfsecret,secret; bits256 remote_pub,basepoint,remote_secret,randkey,commit1,commit2,_secret,tmp,buf[8]; int32_t n = 0; tmp = GENESIS_PRIVKEY; _secret = curve25519(tmp,remote_pub); fexpand(secret.ulongs,_secret.bytes); randombytes(randkey.bytes,sizeof(randkey)), randkey.bytes[0] &= 248, randkey.bytes[31] &= 127, randkey.bytes[31] |= 64; randombytes(remote_secret.bytes,sizeof(remote_secret)), remote_secret.bytes[0] &= 248, remote_secret.bytes[31] &= 127, remote_secret.bytes[31] |= 64; memcpy(basepoint.bytes,_basepoint,sizeof(basepoint)); remote_pub = curve25519(remote_secret,basepoint); fexpand(randsecret.ulongs,randkey.bytes); curve25519_donna(commit1.bytes,randkey.bytes,_basepoint); commit2 = curve25519(randkey,remote_pub); /* # shift and hash concat = str(G) + str(prover_pub) + str(remote_pub) + str(secret) + str(commit1) + str(commit2) h = hashlib.md5() h.update(concat.encode("utf-8")) challenge = int(h.hexdigest(), 16) product = (self.secret * challenge) % phi response = (randKey.secret - product) % phi return (secret, challenge, response)*/ buf[n++] = GENESIS_PRIVKEY, buf[n++] = GENESIS_PUBKEY; buf[n++] = remote_pub, buf[n++] = _secret, buf[n++] = commit1, buf[n++] = commit2; memset(challenge.bytes,0,sizeof(challenge)); calc_sha256(0,tmp.bytes,buf[0].bytes,n*sizeof(buf[0])); fexpand(challenge.ulongs,tmp.bytes); tmp = GENESIS_PRIVKEY; fexpand(selfsecret.ulongs,tmp.bytes); fmul(product.ulongs,selfsecret.ulongs,challenge.ulongs); response = product; fdifference_backwards(product.ulongs,randsecret.ulongs); /* # Verifies proof generated above. Verifier c is showing that # shared secret between A and B was generated by A. # returns 0 if if verification fails; returns shared secret otherwise def verify_shared_secret(self, prover_pub, remote_pub, secret, challenge, response): P = self.P; G = self.G ; public = self.public # g^r * (a's public key)^challenge commit1 = (pow(G, response, P) * pow(public, challenge, P)) % P # (b's public key)^response * (secret)^challenge commit2 = (pow(remote_pub, response, P) * pow(secret, challenge, P)) % P */ bits256 _commit1b,_commit2b,_tmp2,_challenge,_response; bits320 Tmp,Tmp2,commit2b; fcontract(_challenge.bytes,challenge.ulongs); fcontract(_response.bytes,response.ulongs); tmp = curve25519(_secret,_challenge); _tmp2 = curve25519(remote_pub,_response); fexpand(Tmp.ulongs,tmp.bytes); fexpand(Tmp2.ulongs,_tmp2.bytes); fmul(commit2b.ulongs,Tmp.ulongs,Tmp2.ulongs); fcontract(_commit2b.bytes,commit2b.ulongs); printf("commits %llx %llx vs %llx %llx\n",commit1.txid,commit2.txid,_commit1b.txid,_commit2b.txid); /* # Shift and hash hasher = hashlib.md5() concat = str(G) + str(prover_pub) + str(remote_pub) + str(secret) + str(commit1) + str(commit2) hasher.update(concat.encode("utf-8")) check = int(hasher.hexdigest(), 16) if challenge == check: return secret else: return 0 def main(): a = DiffieHellman() b = DiffieHellman() results = a.prove_shared_secret(b.public) assert a.verify_shared_secret(a.public, b.public, results[0], \ results[1], results[2]) */ }
/* * Execute a multicharacter command. */ static void exec_mca(void) { char *cbuf; cmd_exec(); cbuf = get_cmdbuf(); switch (mca) { case A_F_SEARCH: case A_B_SEARCH: multi_search(cbuf, (int)number); break; case A_FILTER: search_type ^= SRCH_NO_MATCH; set_filter_pattern(cbuf, search_type); break; case A_FIRSTCMD: /* * Skip leading spaces or + signs in the string. */ while (*cbuf == '+' || *cbuf == ' ') cbuf++; if (every_first_cmd != NULL) free(every_first_cmd); if (*cbuf == '\0') every_first_cmd = NULL; else every_first_cmd = save(cbuf); break; case A_OPT_TOGGLE: toggle_option(curropt, opt_lower, cbuf, optflag); curropt = NULL; break; case A_F_BRACKET: match_brac(cbuf[0], cbuf[1], 1, (int)number); break; case A_B_BRACKET: match_brac(cbuf[1], cbuf[0], 0, (int)number); break; case A_EXAMINE: if (secure) break; /* POSIX behavior, but possibly generally useful */ if (strlen(cbuf) == 0) { reopen_curr_ifile(); jump_back(1); break; } /* POSIX behavior - probably not generally useful */ if (less_is_more && (strcmp(cbuf, "#") == 0)) { if (ntags()) { error("No previous file", NULL_PARG); break; } if (edit_prev(1)) { error("No previous file", NULL_PARG); } else { jump_back(1); } break; } edit_list(cbuf); /* If tag structure is loaded then clean it up. */ cleantags(); break; case A_SHELL: /* * !! just uses whatever is in shellcmd. * Otherwise, copy cmdbuf to shellcmd, * expanding any special characters ("%" or "#"). */ if (*cbuf != '!') { if (shellcmd != NULL) free(shellcmd); shellcmd = fexpand(cbuf); } if (secure) break; if (shellcmd == NULL) lsystem("", "!done"); else lsystem(shellcmd, "!done"); break; case A_PIPE: if (secure) break; (void) pipe_mark(pipec, cbuf); error("|done", NULL_PARG); break; } }