int main(int argc,char **argv) { if(argc != 5) { fprintf(stderr,"%s <bank public info> <private coin request> <signed coin request> <coin>\n", argv[0]); exit(1); } const char *szBankFile=argv[1]; const char *szPrivateRequestFile=argv[2]; const char *szSignatureFile=argv[3]; const char *szCoinFile=argv[4]; SetDumper(stderr); BIO *bioBank=BIO_new_file(szBankFile,"r"); BIO *bioPrivateRequest=BIO_new_file(szPrivateRequestFile,"r"); BIO *bioSignature=BIO_new_file(szSignatureFile,"r"); BIO *bioCoin=BIO_new_file(szCoinFile,"w"); PublicBank bank(bioBank); CoinRequest req(bioPrivateRequest); ReadNumber(bioSignature,"request="); BIGNUM *bnSignature=ReadNumber(bioSignature,"signature="); DumpNumber("signature=",bnSignature); Coin coin; req.ProcessResponse(&coin,bank,bnSignature); coin.WriteBIO(bioCoin); }
static void DumpConstants(const ktap_proto *f, DumpState *D) { int i, n = f->sizek; DumpInt(n, D); for (i = 0; i < n; i++) { const ktap_value* o=&f->k[i]; DumpChar(ttypenv(o), D); switch (ttypenv(o)) { case KTAP_TNIL: break; case KTAP_TBOOLEAN: DumpChar(bvalue(o), D); break; case KTAP_TNUMBER: DumpNumber(nvalue(o), D); break; case KTAP_TSTRING: DumpString(rawtsvalue(o), D); break; default: printf("ktap: DumpConstants with unknown vaule type %d\n", ttypenv(o)); ktap_assert(0); } } n = f->sizep; DumpInt(n, D); for (i = 0; i < n; i++) DumpFunction(f->p[i], D); }
static void DumpConstants (const Proto *f, DumpState *D) { int i; int n = f->sp->sizek; DumpInt(n, D); for (i = 0; i < n; i++) { const TValue *o = &f->k[i]; DumpByte(ttype(o), D); switch (ttype(o)) { case LUA_TNIL: break; case LUA_TBOOLEAN: DumpByte(bvalue(o), D); break; case LUA_TNUMFLT: DumpNumber(fltvalue(o), D); break; case LUA_TNUMINT: DumpInteger(ivalue(o), D); break; case LUA_TSHRSTR: case LUA_TLNGSTR: DumpString(tsvalue(o), D); break; default: lua_assert(0); } } }
static void DumpConstants(const Proto* f, DumpState* D) { int i,n; DumpInt(n=f->sizek,D); for (i=0; i<n; i++) { const TObject* o=&f->k[i]; DumpByte(ttype(o),D); switch (ttype(o)) { case LUA_TNUMBER: DumpNumber(nvalue(o),D); break; case LUA_TSTRING: DumpString(tsvalue(o),D); break; case LUA_TNIL: break; default: lua_assert(0); /* cannot happen */ break; } } DumpInt(n=f->sizep,D); for (i=0; i<n; i++) DumpFunction(f->p[i],f->source,D); }
static void DumpConstants(const Proto* f, DumpState* D) { int i,n=f->sizek; DumpInt(n,D); for (i=0; i<n; i++) { const TValue* o=&f->k[i]; DumpChar(ttype(o),D); switch (ttype(o)) { case LUA_TNIL: break; case LUA_TBOOLEAN: DumpChar(bvalue(o),D); break; case LUA_TNUMBER: DumpNumber(nvalue(o),D); break; case LUA_TSTRING: DumpString(rawtsvalue(o),D); break; default: lua_assert(0); /* cannot happen */ break; } } n=f->sizep; DumpInt(n,D); for (i=0; i<n; i++) DumpFunction(f->p[i],f->source,D); }
static void DumpConstants(TProtoFunc* tf, FILE* D) { int i,n; n = tf->nconsts; DumpWord(n,D); for (i=0; i<n; i++) { TObject* o=tf->consts+i; switch (ttype(o)) { case LUA_T_NUMBER: fputc('N',D); DumpNumber(nvalue(o),D); break; case LUA_T_STRING: fputc('S',D); DumpTString(tsvalue(o),D); break; case LUA_T_PROTO: fputc('F',D); break; case LUA_T_NIL: fputc(-ttype(o),D); break; default: /* cannot happen */ luaL_verror("cannot dump constant #%d: type=%d [%s]", i,ttype(o),luaO_typename(o)); break; } } }
static void DumpConstants(const killa_Proto* f, DumpState* D) { int i,n=f->sizek; DumpInt(n,D); for (i=0; i<n; i++) { const killa_TValue* o=&f->k[i]; DumpChar(killa_ttype(o),D); switch (killa_ttype(o)) { case KILLA_TNULL: break; case KILLA_TBOOLEAN: DumpChar(killa_bvalue(o),D); break; case KILLA_TNUMBER: DumpNumber(killa_nvalue(o),D); break; case KILLA_TSTRING: DumpString(killa_rawtsvalue(o),D); break; } } n=f->sizep; DumpInt(n,D); for (i=0; i<n; i++) DumpFunction(f->p[i],D); }
/*const*/ BIGNUM *Bank::SignRequest(PublicCoinRequest &req) { InitCTX(); BIGNUM *BtoA=BN_new(); BN_mod_exp(BtoA,req.Request(),priv_key(),p(),m_ctx); DumpNumber("B->A= ",BtoA); return BtoA; }
static void DumpHeader (DumpState *D) { DumpLiteral(LUA_SIGNATURE, D); DumpByte(LUAC_VERSION, D); DumpByte(LUAC_FORMAT, D); DumpLiteral(LUAC_DATA, D); DumpByte(sizeof(int), D); DumpByte(sizeof(size_t), D); DumpByte(sizeof(Instruction), D); DumpByte(sizeof(lua_Integer), D); DumpByte(sizeof(lua_Number), D); DumpInteger(LUAC_INT, D); DumpNumber(LUAC_NUM, D); }
static void DumpHeader(void* D) { DumpByte(ID_CHUNK,D); DumpSig(SIGNATURE, D); DumpByte(VERSION,D); DumpByte(luaU_endianess(),D); DumpByte(sizeof(int),D); DumpByte(sizeof(size_t),D); DumpByte(sizeof(Instruction),D); DumpByte(SIZE_INSTRUCTION,D); DumpByte(SIZE_OP,D); DumpByte(SIZE_B,D); DumpByte(sizeof(Number),D); DumpNumber(TEST_NUMBER,D); }
static void DumpHeader(DumpState* D) { DumpLiteral(LUA_SIGNATURE,D); DumpByte(VERSION,D); DumpByte(luaU_endianness(),D); DumpByte(sizeof(int),D); DumpByte(sizeof(size_t),D); DumpByte(sizeof(Instruction),D); DumpByte(SIZE_OP,D); DumpByte(SIZE_A,D); DumpByte(SIZE_B,D); DumpByte(SIZE_C,D); DumpByte(sizeof(lua_Number),D); DumpNumber(TEST_NUMBER,D); }
LAURIE_BOOLEAN Bank::Verify(Coin &coin) { InitCTX(); BIGNUM *t=BN_new(); if(!coin.GenerateCoinNumber(t,*this)) return false; BN_mod_exp(t,t,priv_key(),p(),m_ctx); DumpNumber("y^k= ",t); BN_sub(t,t,coin.Signature()); LAURIE_BOOLEAN bRet=BN_is_zero(t); BN_free(t); return bRet; }
static void DumpConstants(const LuaProto* f, DumpState* D) { int n = (int)f->constants.size(); DumpInt(n,D); for(int i=0; i < n; i++) { LuaValue v = f->constants[i]; DumpChar(v.type(),D); if(v.isBool()) { DumpChar(v.getBool() ? 1 : 0,D); } else if(v.isNumber()) { DumpNumber(v.getNumber(),D); } else if(v.isString()) { DumpString(v.getString(),D); } } n = (int)f->subprotos_.size(); DumpInt(n,D); for (int i=0; i < n; i++) { DumpFunction(f->subprotos_[i],D); } }
void PublicCoinRequest::WriteBIO(BIO *bio) { DumpNumber(bio,"request=",m_bnCoinRequest); }
void DumpNumber(const char *szTitle,const BIGNUM *bn,const char *szTrailer) { DumpNumber(dout,szTitle,bn,szTrailer); }
void Bank::WriteBIO(BIO *bio) { PublicBank::WriteBIO(bio); DumpNumber(bio,"private=",priv_key()); }
// Lucre step 3: the mint signs the token // bool OTMint_Lucre::SignToken(OTPseudonym & theNotary, OTToken & theToken, OTString & theOutput, int32_t nTokenIndex) { bool bReturnValue = false; //OTLog::Error("%s <bank file> <coin request> <coin signature> [<signature repeats>]\n", _OT_Lucre_Dumper setDumper; // OTLog::vError("OTMint::SignToken!!\nnTokenIndex: %d\n Denomination: %lld\n", nTokenIndex, theToken.GetDenomination()); OpenSSL_BIO bioBank = BIO_new(BIO_s_mem()); // input OpenSSL_BIO bioRequest = BIO_new(BIO_s_mem()); // input OpenSSL_BIO bioSignature = BIO_new(BIO_s_mem()); // output OTASCIIArmor thePrivate; GetPrivate(thePrivate, theToken.GetDenomination()); // The Mint private info is encrypted in m_mapPrivates[theToken.GetDenomination()]. // So I need to extract that first before I can use it. OTEnvelope theEnvelope(thePrivate); OTString strContents; // output from opening the envelope. // Decrypt the Envelope into strContents if (!theEnvelope.Open(theNotary, strContents)) return false; // copy strContents to a BIO BIO_puts(bioBank, strContents.Get()); // OTLog::vError("BANK CONTENTS:\n%s--------------------------------------\n", strContents.Get()); // Instantiate the Bank with its private key Bank bank(bioBank); // OTLog::vError("BANK INSTANTIATED.--------------------------------------\n"); // I need the request. the prototoken. OTASCIIArmor ascPrototoken; bool bFoundToken = theToken.GetPrototoken(ascPrototoken, nTokenIndex); if (bFoundToken) { // base64-Decode the prototoken OTString strPrototoken(ascPrototoken); // OTLog::vError("\n--------------------------------------\nDEBUG: PROTOTOKEN CONTENTS:\n" // "-----------------%s---------------------\n", strPrototoken.Get() ); // copy strPrototoken to a BIO BIO_puts(bioRequest, strPrototoken.Get()); // Load up the coin request from the bio (the prototoken) PublicCoinRequest req(bioRequest); // OTLog::Error("PROTOTOKEN INSTANTIATED.--------------------------------------\n"); // Sign it with the bank we previously instantiated. // results will be in bnSignature (BIGNUM) BIGNUM * bnSignature = bank.SignRequest(req); if (NULL == bnSignature) { OTLog::Error("MAJOR ERROR!: Bank.SignRequest failed in OTMint_Lucre::SignToken\n"); } else { // OTLog::Error("BANK.SIGNREQUEST SUCCESSFUL.--------------------------------------\n"); // Write the request contents, followed by the signature contents, // to the Signature bio. Then free the BIGNUM. req.WriteBIO(bioSignature); // the original request contents DumpNumber(bioSignature,"signature=", bnSignature); // the new signature contents BN_free(bnSignature); // Read the signature bio into a C-style buffer... char sig_buf[1024]; // todo stop hardcoding these string lengths // memset(sig_buf, 0, 1024); // zero it out. (I had this commented out, but the size was 2048, so maybe it's safe now at 1024.) int32_t sig_len = BIO_read(bioSignature, sig_buf, 1000); // cutting it a little short on purpose, with the buffer. Just makes me feel more comfortable for some reason. // Add the null terminator by hand (just in case.) sig_buf[sig_len] = '\0'; if (sig_len) { // *********************************************** // OTLog::vError("\n--------------------------------------\n" // "*** Siglen is %d. sig_str_len is %d.\nsig buf:\n------------%s------------\nLAST " // "CHARACTER IS '%c' SECOND TO LAST CHARACTER IS '%c'\n", // sig_len, sig_str_len, sig_buf, sig_buf[sig_str_len-1], sig_buf[sig_str_len-2]); // Copy the original coin request into the spendable field of the token object. // (It won't actually be spendable until the client processes it, though.) theToken.SetSpendable(ascPrototoken); // OTLog::vError("*** SPENDABLE:\n-----------%s---------------------\n", ascPrototoken.Get()); // Base64-encode the signature contents into theToken.m_Signature. OTString strSignature(sig_buf); // strSignature.Set(sig_buf, sig_len-1); // sig_len includes null terminator, whereas Set() adds 1 for it. // OTLog::vError("SIGNATURE:\n--------------------%s" // "------------------\n", strSignature.Get()); // Here we pass the signature back to the caller. // He will probably set it onto the token. theOutput.Set(sig_buf, sig_len); bReturnValue = true; // This is also where we set the expiration date on the token. // The client should have already done this, but we are explicitly // setting the values here to prevent any funny business. theToken.SetSeriesAndExpiration(m_nSeries, m_VALID_FROM, m_VALID_TO); } } } return bReturnValue; }
void PublicBank::WriteBIO(BIO *bio) { DumpNumber(bio,"g=",g()); DumpNumber(bio,"p=",p()); DumpNumber(bio,"public=",pub_key()); }
void UnsignedCoin::WriteBIO(BIO *bio) { DumpNumber(bio,"id=",m_bnCoinID); }
void CoinRequest::WriteBIO(BIO *bio) { PublicCoinRequest::WriteBIO(bio); m_coin.WriteBIO(bio); DumpNumber(bio,"blinding=",m_bnBlindingFactor); }
void Coin::WriteBIO(BIO *bio) { UnsignedCoin::WriteBIO(bio); DumpNumber(bio,"signature=",m_bnCoinSignature); }