FEMessage* FEInitiator::barter(const vector<EncBuffer*>& ctextR, const vector<hash_t>& ptHashR, const vector<hash_t>& ptHashI) { if (ctextR.empty()) throw CashException(CashException::CE_FE_ERROR, "[FEInitiator::barter] No responder ciphertext given"); if (ptHashR.empty()) throw CashException(CashException::CE_FE_ERROR, "[FEInitiator::barter] No initiator plaintext hash given"); ctextB = ctextR; // create contract createContract(); // compute hashes hash_t ptHashMerkleI = Hash::hash(ptHashI, verifiablePK->hashAlg, verifiablePK->hashKey, Hash::TYPE_MERKLE); hash_t ptHashMerkleR = Hash::hash(ptHashR, verifiablePK->hashAlg, verifiablePK->hashKey, Hash::TYPE_MERKLE); hash_t ctHashMerkleI = Hash::hash(ctextA, verifiablePK->hashAlg, verifiablePK->hashKey, Hash::TYPE_MERKLE); hash_t ctHashMerkleR = Hash::hash(ctextB, verifiablePK->hashAlg, verifiablePK->hashKey, Hash::TYPE_MERKLE); // set the contract contract->setPTHashA(ptHashMerkleI); contract->setCTHashA(ctHashMerkleI); contract->setPTHashB(ptHashMerkleR); contract->setCTHashB(ctHashMerkleR); contract->setEncAlgA(ctextA[0]->encAlg); contract->setEncAlgB(ctextB[0]->encAlg); contract->setPTHashBlocksB(ptHashR.size()); contract->setCTHashBlocksB(ctextR.size()); // optimization: if all ciphertexts have the same key, just output one key // shortcut: if two ciphertexts have the same key, assume all have // the same key vector<ZZ> keys; if (ctextA.size() > 1 && ctextA[0]->key == ctextA[1]->key) keys.push_back(ZZFromBytes(ctextA[0]->key)); else { for (unsigned i = 0; i < ctextA.size(); i++) { keys.push_back(ZZFromBytes(ctextA[i]->key)); } } // now set up signature and escrow VEProver prover(regularPK); // label is the multicontract string label = saveString(*contract); vector<ZZ> escrow = prover.encrypt(keys, label, regularPK->hashAlg, stat); // need to sign on the escrow using our signature key string escrowStr = CommonFunctions::vecToString(escrow); /* TODO: When we use RSA enc as escrow, we should also sign the contract */ string sig = Signature::sign(*signKey, escrowStr, regularPK->hashAlg); // now output the escrow, signature, and contract (label) return new FEMessage(escrow, sig, *contract); }
BuyMessage* Buyer::buy(const vector<EncBuffer*>& ct, const vector<hash_t>& ptHash) { if (inProgress) throw CashException(CashException::CE_FE_ERROR, "[Buyer::buy] Buy called on an already working buyer"); if (ct.empty()) throw CashException(CashException::CE_FE_ERROR, "[Buyer::buy] No ciphertext given"); if (ptHash.empty()) throw CashException(CashException::CE_FE_ERROR, "[Buyer::buy] No plaintext hash given"); // store ciphertexts ctext = ct; // compute hashes // XXX temporary fix: use regular hashes (size-1 hashes aren't matching) startTimer(); hash_t ptHashMerkle = Hash::hash(ptHash, pk->hashAlg, pk->hashKey, Hash::TYPE_MERKLE); hash_t ctHashMerkle = Hash::hash(ctext, pk->hashAlg, pk->hashKey, Hash::TYPE_MERKLE); // create contract createContract(); // set up the contract contract->setPTHashB(ptHashMerkle); contract->setCTHashB(ctHashMerkle); contract->setEncAlgB(ctext[0]->encAlg); contract->setPTHashBlocksB(ptHash.size()); contract->setCTHashBlocksB(ctext.size()); printTimer("[Buyer::buy] created contract"); startTimer(); // set up the escrow VECiphertext* escrow = new VECiphertext(makeEscrow()); printTimer("[Buyer::buy] created escrow"); // set inProgress inProgress = true; return new BuyMessage(coin, contract, escrow); }
FEMessage* FEInitiator::buy(const vector</*const*/ EncBuffer*>& ctextR, const vector</*const*/ hash_t>& ptHashR) { if (TYPE_NONE != exchangeType) throw CashException(CashException::CE_FE_ERROR, "[FEInitiator::buy] Buy called on an already working FEInitiator"); if (ctextR.empty()) throw CashException(CashException::CE_FE_ERROR, "[FEInitiator::buy] No ciphertext given"); if (ptHashR.empty()) throw CashException(CashException::CE_FE_ERROR, "[FEInitiator::buy] No plaintext hash given"); // now decide that we are running a buy protocol exchangeType = TYPE_BUY; // store ciphertexts ctextB = ctextR; // compute hashes hash_t ptHashMerkle = Hash::hash(ptHashR, verifiablePK->hashAlg, verifiablePK->hashKey, Hash::TYPE_MERKLE); hash_t ctHashMerkle = Hash::hash(ctextB, verifiablePK->hashAlg, verifiablePK->hashKey, Hash::TYPE_MERKLE); // create contract if (NULL == contract) createContract(); // set up the contract contract->setPTHashB(ptHashMerkle); contract->setCTHashB(ctHashMerkle); contract->setEncAlgB(ctextB[0]->encAlg); contract->setPTHashBlocksB(ptHashR.size()); contract->setCTHashBlocksB(ctextR.size()); string signature = signContract(); return new FEMessage(signature, *contract); }