Esempio n. 1
0
      std::shared_ptr<model::Query> PbQueryFactory::deserialize(
           const protocol::Query &pb_query) {
        std::shared_ptr<model::Query> val;

        if (pb_query.has_get_account()) {
          // Convert to get Account
          auto pb_cast = pb_query.get_account();
          auto account_query = GetAccount();
          account_query.account_id = pb_cast.account_id();
          val = std::make_shared<model::GetAccount>(account_query);
        }

        if (pb_query.has_get_account_assets()) {
          // Convert to get Account Asset
          auto pb_cast = pb_query.get_account_assets();
          auto query = GetAccountAssets();
          query.account_id = pb_cast.account_id();
          query.asset_id = pb_cast.asset_id();
          val = std::make_shared<model::GetAccountAssets>(query);
        }
        if (pb_query.has_get_account_signatories()) {
          // Convert to get Signatories
          auto pb_cast = pb_query.get_account_signatories();
          auto query = GetSignatories();
          query.account_id = pb_cast.account_id();
          val = std::make_shared<model::GetSignatories>(query);
        }

        if (pb_query.has_get_account_transactions()) {
          // Convert to get Signatories
          auto pb_cast = pb_query.get_account_transactions();
          auto query = GetAccountTransactions();
          query.account_id = pb_cast.account_id();
          val = std::make_shared<model::GetAccountTransactions>(query);
        }
        if (!val) {
          // Query not implemented
          return nullptr;
        }
        Signature sign;
        auto pb_sign = pb_query.header().signature();
        std::copy(pb_sign.pubkey().begin(), pb_sign.pubkey().end(),
                  sign.pubkey.begin());

        std::copy(pb_sign.signature().begin(), pb_sign.signature().end(),
                  sign.signature.begin());
        val->query_counter = pb_query.query_counter();
        val->signature = sign;
        val->created_ts = pb_query.header().created_time();
        val->creator_account_id = pb_query.creator_account_id();
        model::HashProviderImpl hashProvider; // TODO: get rid off unnecessary object initialization
        val->query_hash = hashProvider.get_hash(val);
        return val;
      }
Esempio n. 2
0
static void do_recover_pubkey_uncomp(int keypos) {
	std::vector<unsigned char> pubkey(64);
	if(buffill - keypos < 64) {
		fprintf(stderr, "Not enough data in buffer to recover key!\n");
		return;
	}
	memcpy(&pubkey[0], buf+keypos, 64);

	key_info* kinfo;
	keymap_iter iter = pubkey_map.find(pubkey);
	if(iter != pubkey_map.end()) {
		kinfo = iter->second;
		if(kinfo->found_pub) {
			//printf("Duplicate potential public key, skipping\n");
			num_dups++;
			show_progress();
			return;
		}
	} else {
		kinfo = new key_info();
		kinfo->pubkey = pubkey;
		pubkey_map[pubkey] = kinfo;
	}

	kinfo->found_pub = 1;
	kinfo->pubkey = pubkey;
	num_pend_pub++;

	//printf("Found potential pubkey: ");
	//dump_hex(&pubkey[0], 64);
	try_recover_key(kinfo);
}
Esempio n. 3
0
Test::Result
PK_Signature_Generation_Test::run_one_test(const std::string&, const VarMap& vars)
   {
   const std::vector<uint8_t> message   = get_req_bin(vars, "Msg");
   const std::vector<uint8_t> signature = get_req_bin(vars, "Signature");
   const std::string padding = get_opt_str(vars, "Padding", default_padding(vars));

   std::unique_ptr<Botan::RandomNumberGenerator> rng;
   if(vars.count("Nonce"))
      {
      rng.reset(new Fixed_Output_RNG(get_req_bin(vars, "Nonce")));
      }

   Test::Result result(algo_name() + "/" + padding + " signature generation");

   std::unique_ptr<Botan::Private_Key> privkey = load_private_key(vars);
   std::unique_ptr<Botan::Public_Key> pubkey(Botan::X509::load_key(Botan::X509::BER_encode(*privkey)));

   Botan::PK_Signer signer(*privkey, padding);
   Botan::PK_Verifier verifier(*pubkey, padding);

   const std::vector<uint8_t> generated_signature = signer.sign_message(message, rng ? *rng : Test::rng());
   result.test_eq("generated signature matches KAT", generated_signature, signature);

   result.test_eq("generated signature valid", verifier.verify_message(message, generated_signature), true);
   check_invalid_signatures(result, verifier, message, signature);
   result.test_eq("correct signature valid", verifier.verify_message(message, signature), true);

   return result;
   }
Esempio n. 4
0
	void endecryptFor1024bitKeyTest()
	{
		MPInteger encryptExponent("00010001");
		MPInteger modulus(
			"7ef57a896736682c97adea5669df5ce8764c05e3f00f5e5b882d1"
			"1955e68ba46d61e65f97fac21df965e933157f269139a7a38078c"
			"3c2e595a7ee17fa23cb562c00b9336dbea41555dc8a577d193106"
			"4d4eff76e93dc5bdd4c531ac0603125d61cd7d91017adb97fc777"
			"741f7680206e65a648875a3e93ff12ad26781d0e56d1");

		MPInteger decryptExponent(
			"0cae5448f928340b9032ecdf28c008b5a76b3c8361ed070db9725"
			"6f9466ecb7c5bd2b978cc49d3305402aa4d196dbb151c2eecfdc4"
			"0216d711f4ee6d23355120a1e59074a2408f457b216b8d90dd809"
			"1947684d57ebff65c55bc2af13d7d84396de565c40513f02dce13"
			"5e075a26835acc0f367dd2e58c5e2f9e370584e02481");

		MPInteger plaintext = "abffe123f875b1f45da2b2ca";

		PublicKey pubkey(encryptExponent, modulus);
		PrivateKey privkey(decryptExponent, modulus);

		RSA cipher(pubkey);
		MPInteger ciphertext = cipher.encrypt(plaintext);

		CPPUNIT_ASSERT(plaintext != ciphertext);

		RSA decrypter(privkey);
		MPInteger decrypttext = decrypter.decrypt(ciphertext);
		
		CPPUNIT_ASSERT(plaintext == decrypttext);

	}
Esempio n. 5
0
bool SignatureExtractorChecker::CheckSig(const std::vector<unsigned char>& scriptSig, const std::vector<unsigned char>& vchPubKey, const CScript& scriptCode, SigVersion sigversion) const
{
    if (checker.CheckSig(scriptSig, vchPubKey, scriptCode, sigversion)) {
        CPubKey pubkey(vchPubKey);
        sigdata.signatures.emplace(pubkey.GetID(), SigPair(pubkey, scriptSig));
        return true;
    }
    return false;
}
		data_chunk elliptic_curve_key::public_key() const
		{
			// same as get_private_key
			int length = i2o_ECPublicKey(key_, NULL);
			if (!length)
				return data_chunk();
			data_chunk pubkey(length, 0);
			uint8_t* pubkey_begin = pubkey.data();
			if (i2o_ECPublicKey(key_, &pubkey_begin) != length)
				return data_chunk();
			return pubkey;
		}
Esempio n. 7
0
bool CScriptCompressor::Decompress(unsigned int nSize, const std::vector<unsigned char> &in)
{
    switch (nSize)
    {
        case 0x00:
            script.resize(25);
            script[0] = OP_DUP;
            script[1] = OP_HASH160;
            script[2] = 20;
            memcpy(&script[3], in.data(), 20);
            script[23] = OP_EQUALVERIFY;
            script[24] = OP_CHECKSIG;
            return true;
        case 0x01:
            script.resize(23);
            script[0] = OP_HASH160;
            script[1] = 20;
            memcpy(&script[2], in.data(), 20);
            script[22] = OP_EQUAL;
            return true;
        case 0x02:
        case 0x03:
            script.resize(35);
            script[0] = 33;
            script[1] = nSize;
            memcpy(&script[2], in.data(), 32);
            script[34] = OP_CHECKSIG;
            return true;
        case 0x04:
        case 0x05:
            unsigned char vch[33] = {};
            vch[0] = nSize - 2;
            memcpy(&vch[1], in.data(), 32);
            CPubKey pubkey(&vch[0], &vch[33]);
            if (!pubkey.Decompress())
                return false;
            assert(pubkey.size() == 65);
            script.resize(67);
            script[0] = 65;
            memcpy(&script[1], pubkey.begin(), 65);
            script[66] = OP_CHECKSIG;
            return true;
    }
    return false;
}
Esempio n. 8
0
static void MutateTxAddOutPubKey(CMutableTransaction& tx, const std::string& strInput)
{
    // Separate into VALUE:PUBKEY[:FLAGS]
    std::vector<std::string> vStrInputParts;
    boost::split(vStrInputParts, strInput, boost::is_any_of(":"));

    if (vStrInputParts.size() < 2 || vStrInputParts.size() > 3)
        throw std::runtime_error("TX output missing or too many separators");

    // Extract and validate VALUE
    CAmount value = ExtractAndValidateValue(vStrInputParts[0]);

    // Extract and validate PUBKEY
    CPubKey pubkey(ParseHex(vStrInputParts[1]));
    if (!pubkey.IsFullyValid())
        throw std::runtime_error("invalid TX output pubkey");
    CScript scriptPubKey = GetScriptForRawPubKey(pubkey);

    // Extract and validate FLAGS
    bool bSegWit = false;
    bool bScriptHash = false;
    if (vStrInputParts.size() == 3) {
        std::string flags = vStrInputParts[2];
        bSegWit = (flags.find('W') != std::string::npos);
        bScriptHash = (flags.find('S') != std::string::npos);
    }

    if (bSegWit) {
        if (!pubkey.IsCompressed()) {
            throw std::runtime_error("Uncompressed pubkeys are not useable for SegWit outputs");
        }
        // Call GetScriptForWitness() to build a P2WSH scriptPubKey
        scriptPubKey = GetScriptForWitness(scriptPubKey);
    }
    if (bScriptHash) {
        // Get the ID for the script, and then construct a P2SH destination for it.
        scriptPubKey = GetScriptForDestination(CScriptID(scriptPubKey));
    }

    // construct TxOut, append to transaction output list
    CTxOut txout(value, scriptPubKey);
    tx.vout.push_back(txout);
}
Esempio n. 9
0
// nasty hack to try and recover BitcoinJ public+private keys
// probably quite unreliable
static void do_recover_pubkey_j() {
	std::vector<unsigned char> pubkey(64);
	if(buffill - bufpos < 64 || bufpos < 64) {
		fprintf(stderr, "Not enough data in buffer to recover potential BitcoinJ key!\n");
		return;
	}

	int bufpos_priv = -1;
	for(int i = bufpos-64; i < bufpos-37; i++) {
		if(memcmp(buf+i, "\x00\x00\x00\x20", 4) == 0) {
			bufpos_priv = i+4; break;
		}
	}
	if(bufpos_priv < 0)
		return;

	do_recover_pubkey_uncomp(bufpos);
	do_recover_privkey(bufpos_priv);
}
Esempio n. 10
0
PaymentCode::PaymentCode(
    const uint32_t nym,
    const bool bitmessage,
    const uint8_t bitmessageVersion,
    const uint8_t bitmessageStream)
        : hasBitmessage_(bitmessage)
        , bitmessage_version_(bitmessageVersion)
        , bitmessage_stream_(bitmessageStream)
{
    serializedAsymmetricKey privatekey =
        App::Me().Crypto().BIP32().GetPaymentCode(nym);

    chain_code_.Assign(
        privatekey->chaincode().c_str(),
        privatekey->chaincode().size());

    serializedAsymmetricKey key =
        App::Me().Crypto().BIP32().PrivateToPublic(*privatekey);

    OTData pubkey(key->key().c_str(), key->key().size());

    ConstructKey(pubkey, chain_code_);
}
Esempio n. 11
0
Test::Result
PK_Signature_Generation_Test::run_one_test(const std::string& pad_hdr, const VarMap& vars)
   {
   const std::vector<uint8_t> message   = get_req_bin(vars, "Msg");
   const std::vector<uint8_t> signature = get_req_bin(vars, "Signature");
   const std::string padding = choose_padding(vars, pad_hdr);

   Test::Result result(algo_name() + "/" + padding + " signature generation");

   std::unique_ptr<Botan::Private_Key> privkey;
   try
      {
      privkey = load_private_key(vars);
      }
   catch(Botan::Lookup_Error& e)
      {
      result.note_missing(e.what());
      return result;
      }

   std::unique_ptr<Botan::Public_Key> pubkey(Botan::X509::load_key(Botan::X509::BER_encode(*privkey)));

   std::vector<std::unique_ptr<Botan::PK_Verifier>> verifiers;

   for(auto const& verify_provider : possible_providers(algo_name()))
      {
      std::unique_ptr<Botan::PK_Verifier> verifier;

      try
         {
         verifier.reset(new Botan::PK_Verifier(*pubkey, padding, Botan::IEEE_1363, verify_provider));
         }
      catch(Botan::Lookup_Error&)
         {
         //result.test_note("Skipping verifying with " + verify_provider);
         continue;
         }

      result.test_eq("KAT signature valid", verifier->verify_message(message, signature), true);

      check_invalid_signatures(result, *verifier, message, signature);
      verifiers.push_back(std::move(verifier));
      }

   for(auto const& sign_provider : possible_providers(algo_name()))
      {
      std::unique_ptr<Botan::RandomNumberGenerator> rng;
      if(vars.count("Nonce"))
         {
         rng.reset(test_rng(get_req_bin(vars, "Nonce")));
         }

      std::unique_ptr<Botan::PK_Signer> signer;

      std::vector<uint8_t> generated_signature;

      try
         {
         signer.reset(new Botan::PK_Signer(*privkey, Test::rng(), padding, Botan::IEEE_1363, sign_provider));

         generated_signature = signer->sign_message(message, rng ? *rng : Test::rng());
         }
      catch(Botan::Lookup_Error&)
         {
         //result.test_note("Skipping signing with " + sign_provider);
         continue;
         }

      if(sign_provider == "base")
         {
         result.test_eq("generated signature matches KAT", generated_signature, signature);
         }
      else if(generated_signature != signature)
         {
         for(std::unique_ptr<Botan::PK_Verifier>& verifier : verifiers)
            {
            if(!result.test_eq("generated signature valid",
                               verifier->verify_message(message, generated_signature), true))
               {
               result.test_failure("generated signature", generated_signature);
               }
            }
         }
      }

   return result;
   }
Esempio n. 12
0
Test::Result
PK_Signature_Generation_Test::run_one_test(const std::string&, const VarMap& vars)
   {
   const std::vector<uint8_t> message   = get_req_bin(vars, "Msg");
   const std::vector<uint8_t> signature = get_req_bin(vars, "Signature");
   const std::string padding = get_opt_str(vars, "Padding", default_padding(vars));

   Test::Result result(algo_name() + "/" + padding + " signature generation");

   std::unique_ptr<Botan::Private_Key> privkey = load_private_key(vars);
   std::unique_ptr<Botan::Public_Key> pubkey(Botan::X509::load_key(Botan::X509::BER_encode(*privkey)));

   for(auto&& sign_provider : possible_pk_providers())
      {
      std::unique_ptr<Botan::PK_Signer> signer;

      try
         {
         signer.reset(new Botan::PK_Signer(*privkey, padding, Botan::IEEE_1363, sign_provider));
         }
      catch(Botan::Lookup_Error&)
         {
         //result.test_note("Skipping signing with " + sign_provider);
         continue;
         }

      std::unique_ptr<Botan::RandomNumberGenerator> rng;
      if(vars.count("Nonce"))
         {
         rng.reset(new Fixed_Output_RNG(get_req_bin(vars, "Nonce")));
         }

      const std::vector<uint8_t> generated_signature =
         signer->sign_message(message, rng ? *rng : Test::rng());

      if(sign_provider == "base")
         {
         result.test_eq("generated signature matches KAT", generated_signature, signature);
         }

      for(auto&& verify_provider : possible_pk_providers())
         {
         std::unique_ptr<Botan::PK_Verifier> verifier;

         try
            {
            verifier.reset(new Botan::PK_Verifier(*pubkey, padding, Botan::IEEE_1363, verify_provider));
            }
         catch(Botan::Lookup_Error&)
            {
            //result.test_note("Skipping verifying with " + verify_provider);
            continue;
            }

         if(!result.test_eq("generated signature valid",
                            verifier->verify_message(message, generated_signature), true))
            {
            result.test_failure("generated signature", generated_signature);
            }

         check_invalid_signatures(result, *verifier, message, signature);
         result.test_eq("KAT signature valid", verifier->verify_message(message, signature), true);
         }
      }

   return result;
   }
void SignVerifyMessageDialog::on_verifyMessageButton_VM_clicked()
{
    CBitcoinAddress addr(ui->addressIn_VM->text().toStdString());
    if (!addr.IsValid())
    {
        ui->addressIn_VM->setValid(false);
        ui->statusLabel_VM->setStyleSheet("QLabel { color: red; }");
        ui->statusLabel_VM->setText(tr("The entered address is invalid.") + QString(" ") + tr("Please check the address and try again."));
        return;
    }
    CKeyID keyID;
    if (!addr.GetKeyID(keyID))
    {
        ui->addressIn_VM->setValid(false);
        ui->statusLabel_VM->setStyleSheet("QLabel { color: red; }");
        ui->statusLabel_VM->setText(tr("The entered address does not refer to a key.") + QString(" ") + tr("Please check the address and try again."));
        return;
    }

    bool fInvalid = false;
    std::vector<unsigned char> vchSig = DecodeBase64(ui->signatureIn_VM->text().toStdString().c_str(), &fInvalid);

    if (fInvalid)
    {
        ui->signatureIn_VM->setValid(false);
        ui->statusLabel_VM->setStyleSheet("QLabel { color: red; }");
        ui->statusLabel_VM->setText(tr("The signature could not be decoded.") + QString(" ") + tr("Please check the signature and try again."));
        return;
    }

    CDataStream ss(SER_GETHASH, 0);
    ss << strMessageMagic;
    ss << ui->messageIn_VM->document()->toPlainText().toStdString();

    // get the public key from UI
    fInvalid = false;
    std::vector<unsigned char> vchPubKey = DecodeBase64(ui->pubkeyIn_VM->text().toStdString().c_str(), &fInvalid);

    if (fInvalid)
    {
        ui->pubkeyIn_VM->setValid(false);
        ui->statusLabel_VM->setStyleSheet("QLabel { color: red; }");
        ui->statusLabel_VM->setText(tr("The public key could not be decoded.") + QString(" ") + tr("Please check it and try again."));
        return;
    }

    CPubKey pubkey(vchPubKey);
    if (!pubkey.IsValid())
    {
        ui->pubkeyIn_VM->setValid(false);
        ui->statusLabel_VM->setStyleSheet("QLabel { color: red; }");
        ui->statusLabel_VM->setText(tr("The public key is not valid.") + QString(" ") + tr("Please check it and try again."));
        return;    
    }

    CKey key;
    if (!key.SetPubKey(pubkey))
    {
        ui->pubkeyIn_VM->setValid(false);
        ui->statusLabel_VM->setStyleSheet("QLabel { color: red; }");
        ui->statusLabel_VM->setText(tr("The public key cannot be added.") + QString(" ") + tr("Please check it and try again."));
        return;
    }

    if (!key.Verify(HashKeccak(ss.begin(), ss.end()), vchSig))
    {
        ui->signatureIn_VM->setValid(false);
        ui->statusLabel_VM->setStyleSheet("QLabel { color: red; }");
        ui->statusLabel_VM->setText(tr("The signature did not match the message digest.") + QString(" ") + tr("Please check the signature and try again."));
        return;
    }

    // TODO
    // add the public key
    //key.SetPubKey();

    if (!(CBitcoinAddress(key.GetPubKey().GetID()) == addr))
    {
        ui->statusLabel_VM->setStyleSheet("QLabel { color: red; }");
        ui->statusLabel_VM->setText(QString("<nobr>") + tr("Message verification failed.") + QString("</nobr>"));
        return;
    }

    ui->statusLabel_VM->setStyleSheet("QLabel { color: green; }");
    ui->statusLabel_VM->setText(QString("<nobr>") + tr("Message verified.") + QString("</nobr>"));
}
Esempio n. 14
0
int main(int argc, char **argv)
{
  QxtCommandOptions options;

  options.add(CL_HELP, "display this help message",
      QxtCommandOptions::NoValue);
  options.add(CL_NKEYS, "number of keys to generate",
      QxtCommandOptions::ValueRequired);
  options.add(CL_PUBDIR, "directory in which to put public keys (default=./keys/pub)",
      QxtCommandOptions::ValueRequired);
  options.add(CL_PRIVDIR, "directory in which to put private keys (default=./keys/priv)",
      QxtCommandOptions::ValueRequired);
  options.add(CL_KEYTYPE, "specify the key type (default=dsa, options=dsa|rsa)",
      QxtCommandOptions::ValueRequired);
  options.add(CL_LIB, "specify the library (default=cryptopp, options=cryptopp)",
      QxtCommandOptions::ValueRequired);
  options.add(CL_RAND, "specify the base properties for the key (default=NULL)",
      QxtCommandOptions::ValueRequired);
  options.add(CL_DEBUG, "enable debugging",
      QxtCommandOptions::NoValue);

  options.parse(argc, argv);

  if(options.count(CL_HELP) || options.showUnrecognizedWarning()) {
    options.showUsage();
    return -1;
  }

  QMultiHash<QString, QVariant> params = options.parameters();

  int key_count = params.value(CL_NKEYS, 1).toInt();
  if(key_count < 1) {
    ExitWithWarning(options, "Invalid nkeys");
  }

  QString pubdir_path = params.value(CL_PUBDIR, DEFAULT_PUBDIR).toString();
  QDir pubdir(pubdir_path);
  if(!pubdir.exists()) {
    pubdir.mkpath(".");
  }

  if(!pubdir.exists()) {
    ExitWithWarning(options, "Unable to create pubdir");
  }

  QString privdir_path = params.value(CL_PRIVDIR, DEFAULT_PRIVDIR).toString();
  QDir privdir(privdir_path);
  if(!privdir.exists()) {
    privdir.mkpath(".");
  }

  if(!privdir.exists()) {
    ExitWithWarning(options, "Unable to create privdir");
  }

  if(params.contains(CL_DEBUG)) {
    Logging::UseStderr();
  }

  QString lib_name = params.value(CL_LIB, "cryptopp").toString();
  QString key = params.value(CL_KEYTYPE, "dsa").toString();

  CryptoFactory &cf = CryptoFactory::GetInstance();
  QSharedPointer<CreateKey> ck(new CreateKey());
  if(lib_name == "cryptopp") {
    if(key == "dsa") {
      cf.SetLibrary(CryptoFactory::CryptoPPDsa);
      if(params.contains(CL_RAND)) {
        ck = QSharedPointer<CreateKey>(
            new CreateSeededDsaKey(params.value(CL_RAND).toString()));
      }
    } else if (key == "rsa") {
      cf.SetLibrary(CryptoFactory::CryptoPP);
    } else {
      ExitWithWarning(options, "Invalid key type");
    }
  } else {
    ExitWithWarning(options, "Invalid library");
  }

  Library *lib = cf.GetLibrary();
  QSharedPointer<Hash> hash(lib->GetHashAlgorithm());

  int count = 0;
  while(count < key_count) {
    QSharedPointer<AsymmetricKey> key((*ck)());
    QSharedPointer<AsymmetricKey> pubkey(key->GetPublicKey());
    QByteArray hvalue = hash->ComputeHash(pubkey->GetByteArray());
    QString id = Integer(hvalue).ToString();

    if(!key->Save(privdir_path + QDir::separator() + id)) {
      qFatal("Could not save private key");
    }

    if(!pubkey->Save(pubdir_path + QDir::separator() + id + ".pub")) {
      qFatal("Could not save private key");
    }

    count++;
  }

  return 0;
}
Esempio n. 15
0
static void MutateTxAddOutMultiSig(CMutableTransaction& tx, const std::string& strInput)
{
    // Separate into VALUE:REQUIRED:NUMKEYS:PUBKEY1:PUBKEY2:....[:FLAGS]
    std::vector<std::string> vStrInputParts;
    boost::split(vStrInputParts, strInput, boost::is_any_of(":"));

    // Check that there are enough parameters
    if (vStrInputParts.size()<3)
        throw std::runtime_error("Not enough multisig parameters");

    // Extract and validate VALUE
    CAmount value = ExtractAndValidateValue(vStrInputParts[0]);

    // Extract REQUIRED
    uint32_t required = stoul(vStrInputParts[1]);

    // Extract NUMKEYS
    uint32_t numkeys = stoul(vStrInputParts[2]);

    // Validate there are the correct number of pubkeys
    if (vStrInputParts.size() < numkeys + 3)
        throw std::runtime_error("incorrect number of multisig pubkeys");

    if (required < 1 || required > 20 || numkeys < 1 || numkeys > 20 || numkeys < required)
        throw std::runtime_error("multisig parameter mismatch. Required " \
                            + std::to_string(required) + " of " + std::to_string(numkeys) + "signatures.");

    // extract and validate PUBKEYs
    std::vector<CPubKey> pubkeys;
    for(int pos = 1; pos <= int(numkeys); pos++) {
        CPubKey pubkey(ParseHex(vStrInputParts[pos + 2]));
        if (!pubkey.IsFullyValid())
            throw std::runtime_error("invalid TX output pubkey");
        pubkeys.push_back(pubkey);
    }

    // Extract FLAGS
    bool bSegWit = false;
    bool bScriptHash = false;
    if (vStrInputParts.size() == numkeys + 4) {
        std::string flags = vStrInputParts.back();
        bSegWit = (flags.find('W') != std::string::npos);
        bScriptHash = (flags.find('S') != std::string::npos);
    }
    else if (vStrInputParts.size() > numkeys + 4) {
        // Validate that there were no more parameters passed
        throw std::runtime_error("Too many parameters");
    }

    CScript scriptPubKey = GetScriptForMultisig(required, pubkeys);

    if (bSegWit) {
        for (CPubKey& pubkey : pubkeys) {
            if (!pubkey.IsCompressed()) {
                throw std::runtime_error("Uncompressed pubkeys are not useable for SegWit outputs");
            }
        }
        // Call GetScriptForWitness() to build a P2WSH scriptPubKey
        scriptPubKey = GetScriptForWitness(scriptPubKey);
    }
    if (bScriptHash) {
        if (scriptPubKey.size() > MAX_SCRIPT_ELEMENT_SIZE) {
            throw std::runtime_error(strprintf(
                        "redeemScript exceeds size limit: %d > %d", scriptPubKey.size(), MAX_SCRIPT_ELEMENT_SIZE));
        }
        // Get the ID for the script, and then construct a P2SH destination for it.
        scriptPubKey = GetScriptForDestination(CScriptID(scriptPubKey));
    }

    // construct TxOut, append to transaction output list
    CTxOut txout(value, scriptPubKey);
    tx.vout.push_back(txout);
}
Esempio n. 16
0
void prove_tests::test_proofs_irma_testvec()
{
	////////////////////////////////////////////////////////////////////
	// Issuer public key
	////////////////////////////////////////////////////////////////////
	
	mpz_class n("0x88CC7BD5EAA39006A63D1DBA18BDAF00130725597A0A46F0BACCEF163952833BCBDD4070281CC042B4255488D0E260B4D48A31D94BCA67C854737D37890C7B21184A053CD579176681093AB0EF0B8DB94AFD1812A78E1E62AE942651BB909E6F5E5A2CEF6004946CCA3F66EC21CB9AC01FF9D3E88F19AC27FC77B1903F141049");
	mpz_class Z("0x3F7BAA7B26D110054A2F427939E61AC4E844139CEEBEA24E5C6FB417FFEB8F38272FBFEEC203DB43A2A498C49B7746B809461B3D1F514308EEB31F163C5B6FD5E41FFF1EB2C5987A79496161A56E595BC9271AAA65D2F6B72F561A78DD6115F5B706D92D276B95B1C90C49981FE79C23A19A2105032F9F621848BC57352AB2AC");
	mpz_class S("0x617DB25740673217DF74BDDC8D8AC1345B54B9AEA903451EC2C6EFBE994301F9CABB254D14E4A9FD2CD3FCC2C0EFC87803F0959C9550B2D2A2EE869BCD6C5DF7B9E1E24C18E0D2809812B056CE420A75494F9C09C3405B4550FD97D57B4930F75CD9C9CE0A820733CB7E6FC1EEAF299C3844C1C9077AC705B774D7A20E77BA30");
	std::vector<mpz_class> R;
	
	R.push_back(mpz_class("0x6B4D9D7D654E4B1285D4689E12D635D4AF85167460A3B47DB9E7B80A4D476DBEEC0B8960A4ACAECF25E18477B953F028BD71C6628DD2F047D9C0A6EE8F2BC7A8B34821C14B269DBD8A95DCCD5620B60F64B132E09643CFCE900A3045331207F794D4F7B4B0513486CB04F76D62D8B14B5F031A8AD9FFF3FAB8A68E74593C5D8B"));
	R.push_back(mpz_class("0x177CB93935BB62C52557A8DD43075AA6DCDD02E2A004C56A81153595849A476C515A1FAE9E596C22BE960D3E963ECFAC68F638EBF89642798CCAE946F2F179D30ABE0EDA9A44E15E9CD24B522F6134B06AC09F72F04614D42FDBDB36B09F60F7F8B1A570789D861B7DBD40427254F0336D0923E1876527525A09CDAB261EA7EE"));
	R.push_back(mpz_class("0x12ED9D5D9C9960BACE45B7471ED93572EA0B82C611120127701E4EF22A591CDC173136A468926103736A56713FEF3111FDE19E67CE632AB140A6FF6E09245AC3D6E022CD44A7CC36BCBE6B2189960D3D47513AB2610F27D272924A84154646027B73893D3EE8554767318942A8403F0CD2A41264814388BE4DF345E479EF52A8"));
	R.push_back(mpz_class("0x7AF1083437CDAC568FF1727D9C8AC4768A15912B03A8814839CF053C85696DF3A5681558F06BAD593F8A09C4B9C3805464935E0372CBD235B18686B540963EB9310F9907077E36EED0251D2CF1D2DDD6836CF793ED23D266080BF43C31CF3D304E2055EF44D454F477354664E1025B3F134ACE59272F07D0FD4995BDAACCDC0B"));
	R.push_back(mpz_class("0x614BF5243C26D62E8C7C9B0FAE9C57F44B05714894C3DCF583D9797C423C1635F2E4F1697E92771EB98CF36999448CEFC20CB6E10931DED3927DB0DFF56E18BD3A6096F2FF1BFF1A703F3CCE6F37D589B5626354DF0DB277EF73DA8A2C7347689B79130559FB94B6260C13D8DC7D264BA26953B906488B87CDC9DFD0BC69C551"));
	R.push_back(mpz_class("0x5CAE46A432BE9DB72F3B106E2104B68F361A9B3E7B06BBE3E52E60E69832618B941C952AA2C6EEFFC222311EBBAB922F7020D609D1435A8F3F941F4373E408BE5FEBAF471D05C1B91030789F7FEA450F61D6CB9A4DD8642253327E7EBF49C1600C2A075EC9B9DEC196DDBDC373C29D1AF5CEAD34FA6993B8CDD739D04EA0D253"));
	R.push_back(mpz_class("0x52E49FE8B12BFE9F12300EF5FBDE1800D4611A587E9F4763C11E3476BBA671BFD2E868436C9E8066F96958C897DD6D291567C0C490329793F35E925B77B304249EA6B30241F5D014E1C533EAC27AA9D9FCA7049D3A8D89058969FC2CD4DC63DF38740701D5E2B7299C49EC6F190DA19F4F6BC3834EC1AE145AF51AFEBA027EAA"));
	R.push_back(mpz_class("0x05AA7EE2AD981BEE4E3D4DF8F86414797A8A38706C84C9376D324070C908724BB89B224CB5ADE8CDDB0F65EBE9965F5C710C59704C88607E3C527D57A548E24904F4991383E5028535AE21D11D5BF87C3C5178E638DDF16E666EA31F286D6D1B3251E0B1470E621BEE94CDFA1D2E47A86FD2F900D5DDCB42080DAB583CBEEEDF"));
	R.push_back(mpz_class("0x73D3AB9008DC2BD65161A0D7BFC6C29669C975B54A1339D8385BC7D5DEC88C6D4BD482BFBC7A7DE44B016646B378B6A85FBC1219D351FE475DC178F90DF4961CA980EB4F157B764EC3ECF19604FEDE0551AA42FB12B7F19667AC9F2C46D1185E66072EA709CC0D9689CE721A47D54C028D7B0B01AEEC1C4C9A03979BE9080C21"));
	R.push_back(mpz_class("0x33F10AB2D18B94D870C684B5436B38AC419C08FB065A2C608C4E2E2060FE436945A15F8D80F373B35C3230654A92F99B1A1C8D5BB10B83646A112506022AF7D4D09F7403EC5AECDB077DA945FE0BE661BAFEDDDDC5E43A4C5D1A0B28AE2AA838C6C8A7AE3DF150DBD0A207891F1D6C4001B88D1D91CF380EE15E4E632F33BD02"));
	
	silvia_pub_key pubkey(n, S, Z, R);
	
	////////////////////////////////////////////////////////////////////
	// Test attributes
	////////////////////////////////////////////////////////////////////
	
	silvia_integer_attribute m1(1313);
	silvia_integer_attribute m2(1314);
	silvia_integer_attribute m3(1315);
	silvia_integer_attribute m4(1316);
	
	std::vector<silvia_attribute*> attributes;
	attributes.push_back(&m1);
	attributes.push_back(&m2);
	attributes.push_back(&m3);
	attributes.push_back(&m4);
	
	////////////////////////////////////////////////////////////////////
	// Test credential
	////////////////////////////////////////////////////////////////////
	
	silvia_integer_attribute s(mpz_class("0xB1173E9CFA91149B60B6A3A5822B49FAF79A6EED971469FCABEA79BC82AF36E0"));
	
	mpz_class A("0x37FB456B3D4D38F890F5DECDBE8147DD476A8F951E325EB3E860ABD2CCD4F52A1EF46594ED2D450869328DFFF6ACBD049BB8DD7AE4E256EB501B79BC17E1D68AB224D9CC310EB73CC218C43E860346942D690BBCEE7A3ED392D3933BB8CE6D4539A4D08475738A84B0FFB7D1A0CF25644E6EABC97A52C62BBC507E6885D16373");
	mpz_class e("0x8000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006D093A6A327D0392ED2787DA24BB7D");
	mpz_class v("0x0B2067BB63FEF96D093A81CB7BD270188E5F47AEEA74A350C3848114E353E0E2654205BAD43B632DDDC23CA357780544A63AA4ACCE35C6D9123C34CD31ABD202469CA72461E10DF2A29E7E134760C8C0CAAEC78709119C673665FC5009309CAC9A4BB5361B0494B129D03A9ED84A7AD87DE4B16BDB69F37E09B1F3FE56550F456E04FB78CBE52A577B1A2429A9FB29F41C4716A9F3FCD2C6BBE38925E9E4B088573530901628491F96EAB564C8EC0488BAECB6667E4B48DE715436C8116428766E6F3877DE982AAF48");
	
	silvia_credential testcredential(s, attributes, A, e, v);
	
	////////////////////////////////////////////////////////////////////
	// Initialise prover
	////////////////////////////////////////////////////////////////////
	
	silvia_prover prover(&pubkey, &testcredential);
	
	////////////////////////////////////////////////////////////////////
	// Proof #1:
	// Hide: 1, 2, 3
	// Reveal: 4
	////////////////////////////////////////////////////////////////////
	
	// Test vectors
	mpz_class e_tilde_test("0xBBB5ABB7452E6E1A92DBE48A178BB1D7D432E76930DDDDA5FF6622D76D25B39B9F3FD1B4B1660D69A987D0BB47");
	mpz_class v_prime_tilde_test("0x0D6D04955AC35F1A2D0268816B3946F6C50A82B156888999208BE9DD2757F6862EAD7DBDF598609225DD27F1103A15422710429927CC4CC95F01354DC2AB428E725CF8A27596B7B25EB8BA780A613C81B7506C2A5BECC540B0149B1DFEB4DD3D15B7D6ED14D8F6416C7367C2586300115DC92CC845EA635FF79F9AE0417D5E3F433E55C2E9ECADBA7F7D4F644760A366C04FCB018E45CB3B0F559E08AB159F6E976EBBF36448459F1B9EA5F1F7E71159D79998A8E760432877345416C79B24D184BA72A2E48672EF004895EE907B1BFFD35365D1AA91BEB1E1B12F793EE23635B6BB971C8992C3");
	mpz_class r_A_test("0x01A7B7470063345F87212D62F9D4E8EA4ECA78E6A6A71DE64DBF273970AFD4BAF80568F3BB9878C56EB857F41D34477536B4058A2B88BDCABD515CC2C173646267B952731C6BF8632D333368339611B48112DA7CEBD11281987B040035D6A63E6236C1FF90C7739240D3DDEE905BE73B759712971E124CCB852E9FD454FF9104083A7AF99910B3509289");
	
	std::vector<mpz_class> a_tilde_test;
	a_tilde_test.push_back(mpz_class("0x7622FFA28514B79650D98E49B0C6CD9A558216FE3EE4DDC551405F78E4ACD14C0BA060409DE10AE10600CCAFF6734AC6353BB7246E929997C375E036DDA9")); // s~
	a_tilde_test.push_back(mpz_class("0xE5B5C4B03E78F8C46D637265E57822CD57F70994361CD2BEDF8127FF1092BD3821038A1FE732906DD13A9797CC267E4214D9CB756147838DB334D1E64452")); // a1~
	a_tilde_test.push_back(mpz_class("0xF1DB7871B669CE64D0C75F91ECFBC97C6E8AEE0B9CAE90684D4B800F1B2C650D70559F962572C1434342639B0739557615A58B25B3DA59A1E20592A09091")); // a2~
	a_tilde_test.push_back(mpz_class("0x2230F071F1883E51265E06380C4A59360C35077C4B7B98E33090FA437A23C78FAC7C808CF3D40AE1E2F976AA261E70BC02CAE599173A5D9842346EB88032")); // a3~
	
	// Verifier input to proof
	mpz_class n1_proof1("0x677A2A3F6EB0135F4571");
	mpz_class context("0xB7FC4FCA77E2FA6010F346B2F535F5ACE62B0C84");
	
	std::vector<bool> proof_spec;
	proof_spec.push_back(false);	// don't reveal a1
	proof_spec.push_back(false);	// don't reveal a2
	proof_spec.push_back(true);		// reveal a3
	proof_spec.push_back(false);	// don't reveal a4
	
	// Proof output
	mpz_class c;
	mpz_class A_prime;
	mpz_class e_hat;
	mpz_class v_prime_hat;
	std::vector<mpz_class> a_i_hat;
	std::vector<silvia_attribute*> a_i;
	
	// Generate the proof
	prover.prove(proof_spec, n1_proof1, context, c, A_prime, e_hat, v_prime_hat, a_i_hat, a_i, &e_tilde_test, &v_prime_tilde_test, &r_A_test, &a_tilde_test);
	
	// Check general proof factors
	CPPUNIT_ASSERT(A_prime == mpz_class("0x2533EDE93E23A28A07C7277933166284D9F5BB2C2D0F6ACC9995B164DA597176AD26304455DCFAAA1C973EC69E74559362270322716FC2DABC5F1B5147091DA66731E46F6B2BFC9FE45D65557BA900BFB1177A6A7257C8A756352689D09E33638F9DF9B711027A49D2983E6CE9876AF1C421510A60BC0D3B6E292F0707A078DE"));
	CPPUNIT_ASSERT(c == mpz_class("0x90A81B3A344E8F6707A8845B5277FE82EA9250E6"));
	CPPUNIT_ASSERT(e_hat == mpz_class("0xBBB5ABB7452E6E1A92DC2226E20E87770D63ED25FE4C98954999527F9382BAAE25BF05D731A62199B02EB23D95"));
	CPPUNIT_ASSERT(v_prime_hat == mpz_class("0x0D6D04955AC35F1A2D026E533D5B1100C160309361AFB8A7C43A141DB70230B8062B741B72813155B7F9B4627C2404777F01AF6DBBFD70DBC727E99FCA59AC8CFFA057067E1B7580E2C5280A0975AC1CB08FC6EF440051112353482160110D770726CC1DA4AACA26592D76208DDA8C045A7A85FEA1520B7853AB54BBDD2224DE3CABE5E68F257B8937B831334EBA074326010D188361B8DC452B32398CF4AAA2AF6FC256352BE684726001DA6D1A4479365096993F929D0BA2C65C658ACF511561A72F7AA2BC54D835D3378A24A483C6C603AB65DA5161BA153E5AED11F0383034260FC35A55B5"));
	
	// Check ZKP values for hidden attributes
	CPPUNIT_ASSERT(a_i_hat.size() == 4);
	
	CPPUNIT_ASSERT(a_i_hat[0] == mpz_class("0x7622FFA28514B79650D9F25B0E15E89E2F4D4DC1683EC494539F390E17294A33A8C0084CCB2FCD7CEEFAD1B3FF8E59A1B54D15C4B85888CED98016882AE9")); // ZKP value for s
	CPPUNIT_ASSERT(a_i_hat[1] == mpz_class("0xE5B5C4B03E78F8C46D637265E57822CD57F70994361CD2BEDF8127FF1092BD3821038A1FE732906DD42085CB71ACC52F944812C439A97CFE10A9EA572FF8")); // ZKP value for a1
	CPPUNIT_ASSERT(a_i_hat[2] == mpz_class("0xF1DB7871B669CE64D0C75F91ECFBC97C6E8AEE0B9CAE90684D4B800F1B2C650D70559F962572C1434628E276C7F9D0B2247ADA1D1097A58A3DFD95A3CD1D")); // ZKP value for a2
	CPPUNIT_ASSERT(a_i_hat[3] == mpz_class("0x2230F071F1883E51265E06380C4A59360C35077C4B7B98E33090FA437A23C78FAC7C808CF3D40AE1E5E116D61D535495306E43E17CAE4E709B3246E05E8A")); // ZKP value for a4
	
	// Check revealed attributes
	CPPUNIT_ASSERT(a_i.size() == 1);
	
	CPPUNIT_ASSERT(a_i[0]->rep() == m3.rep());
}
Esempio n. 17
0
void MainWindow::on_pushAsymmDecrypt_clicked()
{
	if(lastUsedAlgo != selectedAsymmAlgo())
	{
		QMessageBox::critical(this, "Ошибка", "Строка была зашифрована другим алгоритмом.", QMessageBox::Ok);
		return;
	}

	switch(lastUsedAlgo)
	{
	case Scrambler::ElGamalCypher:
	{
		if(ui->editAsymmEncrypted->text() == ""
				|| ui->editAsymmPrivateKey->text() == ""
				|| ui->editAsymmPubKey->text() == "")
		{
			QMessageBox::critical(this, "Ошибка", "Зашифрованная строка и ключи не должны быть пустыми.", QMessageBox::Ok);
			return;
		}

		QStringList key = ui->editAsymmPubKey->text().split(" ", QString::SkipEmptyParts);
		if(key.length() < 3)
		{
			QMessageBox::critical(this, "Ошибка", "Открытый ключ должен состоять из трех чисел, разделенных пробелом.", QMessageBox::Ok);
			return;
		}

		Scrambler::ElGamal::openKey pubkey(key[0], key[1], key[2]);
		ui->editAsymmSource->setText(Scrambler::ElGamal::DecryptElGamal(ui->editAsymmEncrypted->text(), pubkey, ui->editAsymmPrivateKey->text()));
		break;
	}

	case Scrambler::Rsa:
	{
		if(ui->editAsymmEncrypted->text() == ""
				|| ui->editAsymmPrivateKey->text() == "")
		{
			QMessageBox::critical(this, "Ошибка", "Зашифрованная строка и закрытый ключ не должны быть пустыми.", QMessageBox::Ok);
			return;
		}

		QStringList key = ui->editAsymmPrivateKey->text().split(" ", QString::SkipEmptyParts);
		if(key.length() < 2)
		{
			QMessageBox::critical(this, "Ошибка", "Закрытый ключ должен состоять из двух чисел, разделенных пробелом.", QMessageBox::Ok);
			return;
		}

		Scrambler::RSA::closedKey privatekey(key[0], key[1]);
		ui->editAsymmSource->setText(Scrambler::RSA::DecryptRSA(ui->editAsymmEncrypted->text(), privatekey));
		break;
	}

	case Scrambler::Caesar:
	case Scrambler::Invalid:
	case Scrambler::SingleReshuffle:
	case Scrambler::SingleWithKey:
	case Scrambler::DoubleReshuffle:
	case Scrambler::Gronsfeld:
	case Scrambler::ManyAlphabet:
	case Scrambler::GammaCypher:
		break;
	}
}
Esempio n. 18
0
void irma_verify_tests::test_verify_irma_proof_cmdgen()
{
	////////////////////////////////////////////////////////////////////
	// Issuer public key
	////////////////////////////////////////////////////////////////////
	
	mpz_class n("0x88CC7BD5EAA39006A63D1DBA18BDAF00130725597A0A46F0BACCEF163952833BCBDD4070281CC042B4255488D0E260B4D48A31D94BCA67C854737D37890C7B21184A053CD579176681093AB0EF0B8DB94AFD1812A78E1E62AE942651BB909E6F5E5A2CEF6004946CCA3F66EC21CB9AC01FF9D3E88F19AC27FC77B1903F141049");
	mpz_class Z("0x3F7BAA7B26D110054A2F427939E61AC4E844139CEEBEA24E5C6FB417FFEB8F38272FBFEEC203DB43A2A498C49B7746B809461B3D1F514308EEB31F163C5B6FD5E41FFF1EB2C5987A79496161A56E595BC9271AAA65D2F6B72F561A78DD6115F5B706D92D276B95B1C90C49981FE79C23A19A2105032F9F621848BC57352AB2AC");
	mpz_class S("0x617DB25740673217DF74BDDC8D8AC1345B54B9AEA903451EC2C6EFBE994301F9CABB254D14E4A9FD2CD3FCC2C0EFC87803F0959C9550B2D2A2EE869BCD6C5DF7B9E1E24C18E0D2809812B056CE420A75494F9C09C3405B4550FD97D57B4930F75CD9C9CE0A820733CB7E6FC1EEAF299C3844C1C9077AC705B774D7A20E77BA30");
	std::vector<mpz_class> R;
	
	R.push_back(mpz_class("0x6B4D9D7D654E4B1285D4689E12D635D4AF85167460A3B47DB9E7B80A4D476DBEEC0B8960A4ACAECF25E18477B953F028BD71C6628DD2F047D9C0A6EE8F2BC7A8B34821C14B269DBD8A95DCCD5620B60F64B132E09643CFCE900A3045331207F794D4F7B4B0513486CB04F76D62D8B14B5F031A8AD9FFF3FAB8A68E74593C5D8B"));
	R.push_back(mpz_class("0x177CB93935BB62C52557A8DD43075AA6DCDD02E2A004C56A81153595849A476C515A1FAE9E596C22BE960D3E963ECFAC68F638EBF89642798CCAE946F2F179D30ABE0EDA9A44E15E9CD24B522F6134B06AC09F72F04614D42FDBDB36B09F60F7F8B1A570789D861B7DBD40427254F0336D0923E1876527525A09CDAB261EA7EE"));
	R.push_back(mpz_class("0x12ED9D5D9C9960BACE45B7471ED93572EA0B82C611120127701E4EF22A591CDC173136A468926103736A56713FEF3111FDE19E67CE632AB140A6FF6E09245AC3D6E022CD44A7CC36BCBE6B2189960D3D47513AB2610F27D272924A84154646027B73893D3EE8554767318942A8403F0CD2A41264814388BE4DF345E479EF52A8"));
	R.push_back(mpz_class("0x7AF1083437CDAC568FF1727D9C8AC4768A15912B03A8814839CF053C85696DF3A5681558F06BAD593F8A09C4B9C3805464935E0372CBD235B18686B540963EB9310F9907077E36EED0251D2CF1D2DDD6836CF793ED23D266080BF43C31CF3D304E2055EF44D454F477354664E1025B3F134ACE59272F07D0FD4995BDAACCDC0B"));
	R.push_back(mpz_class("0x614BF5243C26D62E8C7C9B0FAE9C57F44B05714894C3DCF583D9797C423C1635F2E4F1697E92771EB98CF36999448CEFC20CB6E10931DED3927DB0DFF56E18BD3A6096F2FF1BFF1A703F3CCE6F37D589B5626354DF0DB277EF73DA8A2C7347689B79130559FB94B6260C13D8DC7D264BA26953B906488B87CDC9DFD0BC69C551"));
	R.push_back(mpz_class("0x5CAE46A432BE9DB72F3B106E2104B68F361A9B3E7B06BBE3E52E60E69832618B941C952AA2C6EEFFC222311EBBAB922F7020D609D1435A8F3F941F4373E408BE5FEBAF471D05C1B91030789F7FEA450F61D6CB9A4DD8642253327E7EBF49C1600C2A075EC9B9DEC196DDBDC373C29D1AF5CEAD34FA6993B8CDD739D04EA0D253"));
	R.push_back(mpz_class("0x52E49FE8B12BFE9F12300EF5FBDE1800D4611A587E9F4763C11E3476BBA671BFD2E868436C9E8066F96958C897DD6D291567C0C490329793F35E925B77B304249EA6B30241F5D014E1C533EAC27AA9D9FCA7049D3A8D89058969FC2CD4DC63DF38740701D5E2B7299C49EC6F190DA19F4F6BC3834EC1AE145AF51AFEBA027EAA"));
	R.push_back(mpz_class("0x05AA7EE2AD981BEE4E3D4DF8F86414797A8A38706C84C9376D324070C908724BB89B224CB5ADE8CDDB0F65EBE9965F5C710C59704C88607E3C527D57A548E24904F4991383E5028535AE21D11D5BF87C3C5178E638DDF16E666EA31F286D6D1B3251E0B1470E621BEE94CDFA1D2E47A86FD2F900D5DDCB42080DAB583CBEEEDF"));
	R.push_back(mpz_class("0x73D3AB9008DC2BD65161A0D7BFC6C29669C975B54A1339D8385BC7D5DEC88C6D4BD482BFBC7A7DE44B016646B378B6A85FBC1219D351FE475DC178F90DF4961CA980EB4F157B764EC3ECF19604FEDE0551AA42FB12B7F19667AC9F2C46D1185E66072EA709CC0D9689CE721A47D54C028D7B0B01AEEC1C4C9A03979BE9080C21"));
	R.push_back(mpz_class("0x33F10AB2D18B94D870C684B5436B38AC419C08FB065A2C608C4E2E2060FE436945A15F8D80F373B35C3230654A92F99B1A1C8D5BB10B83646A112506022AF7D4D09F7403EC5AECDB077DA945FE0BE661BAFEDDDDC5E43A4C5D1A0B28AE2AA838C6C8A7AE3DF150DBD0A207891F1D6C4001B88D1D91CF380EE15E4E632F33BD02"));
	
	silvia_pub_key pubkey(n, S, Z, R);
	
	////////////////////////////////////////////////////////////////////
	// Verifier specification
	////////////////////////////////////////////////////////////////////
	
	std::vector<std::string> attribute_names;
	std::vector<bool> D;
	
	attribute_names.push_back("expires");
	attribute_names.push_back("over12");
	attribute_names.push_back("over16");
	attribute_names.push_back("over18");
	attribute_names.push_back("over21");
	
	D.push_back(true);
	D.push_back(false);
	D.push_back(false);
	D.push_back(true);
	D.push_back(false);
	
	silvia_verifier_specification vspec("Bar", "Age: 18+", 801, 10, attribute_names, D);
	
	silvia_irma_verifier verifier(&pubkey, &vspec);
	
	std::vector<bytestring> commands = verifier.get_select_commands();
	
	CPPUNIT_ASSERT(commands.size() == 2);
	
	CPPUNIT_ASSERT(commands[0] == "00A404000849524D416361726400");
	CPPUNIT_ASSERT(commands[1] == "00A4040009F849524D416361726400");
	
	std::vector<bytestring> results;
	results.push_back("6A82");
	results.push_back("0102030405060708099000");
	
	CPPUNIT_ASSERT(verifier.submit_select_data(results));
	
	commands = verifier.get_proof_commands();
	
	CPPUNIT_ASSERT(commands.size() == 11);
	CPPUNIT_ASSERT(commands[0].substr(0, 9) == "8020000028000A0012");
	CPPUNIT_ASSERT(commands[1].substr(0, 5) == "802A00000A");
	CPPUNIT_ASSERT(commands[2] == "802B0100");
	CPPUNIT_ASSERT(commands[3] == "802B0200");
	CPPUNIT_ASSERT(commands[4] == "802B0300");
	CPPUNIT_ASSERT(commands[5] == "802C0000");
	CPPUNIT_ASSERT(commands[6] == "802C0100");
	CPPUNIT_ASSERT(commands[7] == "802C0200");
	CPPUNIT_ASSERT(commands[8] == "802C0300");
	CPPUNIT_ASSERT(commands[9] == "802C0400");
	CPPUNIT_ASSERT(commands[10] == "802C0500");
}
Esempio n. 19
0
std::string X509_Certificate::to_string() const
   {
   std::ostringstream out;

   out << "Version: " << this->x509_version() << "\n";
   out << "Subject: " << subject_dn() << "\n";
   out << "Issuer: " << issuer_dn() << "\n";
   out << "Issued: " << this->not_before().readable_string() << "\n";
   out << "Expires: " << this->not_after().readable_string() << "\n";

   out << "Constraints:\n";
   Key_Constraints constraints = this->constraints();
   if(constraints == NO_CONSTRAINTS)
      out << " None\n";
   else
      {
      if(constraints & DIGITAL_SIGNATURE)
         out << "   Digital Signature\n";
      if(constraints & NON_REPUDIATION)
         out << "   Non-Repudiation\n";
      if(constraints & KEY_ENCIPHERMENT)
         out << "   Key Encipherment\n";
      if(constraints & DATA_ENCIPHERMENT)
         out << "   Data Encipherment\n";
      if(constraints & KEY_AGREEMENT)
         out << "   Key Agreement\n";
      if(constraints & KEY_CERT_SIGN)
         out << "   Cert Sign\n";
      if(constraints & CRL_SIGN)
         out << "   CRL Sign\n";
      if(constraints & ENCIPHER_ONLY)
         out << "   Encipher Only\n";
      if(constraints & DECIPHER_ONLY)
         out << "   Decipher Only\n";
      }

   const std::vector<OID> policies = this->certificate_policy_oids();
   if(!policies.empty())
      {
      out << "Policies: " << "\n";
      for(auto oid : policies)
         out << "   " << oid.as_string() << "\n";
      }

   std::vector<OID> ex_constraints = this->extended_key_usage();
   if(!ex_constraints.empty())
      {
      out << "Extended Constraints:\n";
      for(size_t i = 0; i != ex_constraints.size(); i++)
         out << "   " << OIDS::oid2str(ex_constraints[i]) << "\n";
      }

   const NameConstraints& name_constraints = this->name_constraints();

   if(!name_constraints.permitted().empty() || !name_constraints.excluded().empty())
      {
      out << "Name Constraints:\n";

      if(!name_constraints.permitted().empty())
         {
         out << "   Permit";
         for(auto st: name_constraints.permitted())
            {
            out << " " << st.base();
            }
         out << "\n";
         }

      if(!name_constraints.excluded().empty())
         {
         out << "   Exclude";
         for(auto st: name_constraints.excluded())
            {
            out << " " << st.base();
            }
         out << "\n";
         }
      }

   if(!ocsp_responder().empty())
      out << "OCSP responder " << ocsp_responder() << "\n";

   std::vector<std::string> ca_issuers = this->ca_issuers();
   if(!ca_issuers.empty())
      {
      out << "CA Issuers:\n";
      for(size_t i = 0; i != ca_issuers.size(); i++)
         out << "   URI: " << ca_issuers[i] << "\n";
      }

   if(!crl_distribution_point().empty())
      out << "CRL " << crl_distribution_point() << "\n";

   out << "Signature algorithm: " <<
      OIDS::oid2str(this->signature_algorithm().get_oid()) << "\n";

   out << "Serial number: " << hex_encode(this->serial_number()) << "\n";

   if(this->authority_key_id().size())
     out << "Authority keyid: " << hex_encode(this->authority_key_id()) << "\n";

   if(this->subject_key_id().size())
     out << "Subject keyid: " << hex_encode(this->subject_key_id()) << "\n";

   try
      {
      std::unique_ptr<Public_Key> pubkey(this->subject_public_key());
      out << "Public Key [" << pubkey->algo_name() << "-" << pubkey->key_length() << "]\n\n";
      out << X509::PEM_encode(*pubkey);
      }
   catch(Decoding_Error&)
      {
      const AlgorithmIdentifier& alg_id = this->subject_public_key_algo();
      out << "Failed to decode key with oid " << alg_id.get_oid().as_string() << "\n";
      }

   return out.str();
   }
Esempio n. 20
0
void RippleAddress::setAccountPublic (const RippleAddress& seed )
{
	EdKeyPair pubkey(seed.getSeed());

    setAccountPublic (pubkey.getPubKey ());
}
Esempio n. 21
0
void NodeConnection::Listener()
{
	try
	{
		while(this->Socket != SOCKET_ERROR)
		{
			Packet  packet;
			
			packet.getCommand(this->Socket);

			//printf("%s\n", packet.command); //this printf are not really thread save, and they are only needed for debug

			if (!strcmp(packet.command, "pong")) //just a keep alive
			{
				packet.sendData(this->Socket); //resending it
			}else if(!strcmp(packet.command,"version"))
			{
				packet_version version(packet);
				this->Version = version.version;
			}else if(!strcmp(packet.command,"verack"))
			{
				packet_verack verack(packet);

				verack.sendData(this->Socket);

				//empty addr for now
				packet_addr addr;
				addr.addr_list.clear();
				addr.encodeData();

				addr.setChecksum_Lenght_Magic();


				addr.sendData(this->Socket);

				//empty inv for now, this should be the whole list of object hash
				bool finished = false;
				vector<sTag> inventory;
				std::shared_lock<std::shared_timed_mutex> mlock(bitmrc->sharedObj.mutex_);
				for (int i = 0; i < bitmrc->sharedObj.Dim; i++)
				{
					hash_table<ustring>::linked_node * cur = bitmrc->sharedObj.Table[i];
					while (cur != NULL)
					{
						sTag hash;
						memcpy(hash.ch, cur->hash.c_str(), 32);
						inventory.push_back(hash);

						cur = cur->next;
					}
				}
				mlock.unlock();
				unsigned int i = 0;
				while (!finished)
				{
					packet_inv inv;
					while (i < 50000 && i < inventory.size())
					{
						inv.inventory.push_back(inventory[i]);
						i++;
					}
					inv.encodeData();

					inv.setChecksum_Lenght_Magic();


					inv.sendData(this->Socket);
					if (i == inventory.size())
						finished = true;
				}
				this->state = 2;
			}else if(!strcmp(packet.command,"addr"))
			{
				packet_addr addr(packet);
				for(unsigned int i=0;i<addr.addr_list.size();i++)
				{
					if(addr.addr_list[i].IPv6_4[11] == 0xff &&  addr.addr_list[i].IPv6_4[10] == 0xff)
					{
						char buf[40];
						sprintf(buf,"%i.%i.%i.%i", addr.addr_list[i].IPv6_4[12], addr.addr_list[i].IPv6_4[13], addr.addr_list[i].IPv6_4[14], addr.addr_list[i].IPv6_4[15]);
						string ip(buf);

						//printf("%s\n",buf);

						sprintf(buf, "%i", addr.addr_list[i].port);
						string port(buf);

						NodeConnection *tmp_node= new NodeConnection(ip,port, this->bitmrc);

						this->bitmrc->connectNode(tmp_node);
					}	
				}
			}else if(!strcmp(packet.command,"inv"))
			{
				packet_inv inv(packet);
				packet_getdata needed;
				for (unsigned int i = 0; i < inv.inventory.size(); i++)
				{
					ustring tag;
					for (int j = 0; j < 32; j++)
					{
						tag += inv.inventory[i].ch[j];
					}
					
					
					if (this->bitmrc->sharedObj.searchByHash(tag).empty())
					{
						needed.inventory.push_back(inv.inventory[i]);
					}
				}
				if (!needed.inventory.empty())
				{
					needed.encodeData();
					needed.setChecksum_Lenght_Magic();
					Packets.push(needed);
				}
			}else if(!strcmp(packet.command,"getdata"))
			{
				packet_getdata getdata(packet);

				for (unsigned int i = 0; i < getdata.inventory.size(); i++)
				{
					ustring tag;
					for (int j = 0; j < 32; j++)
					{
						tag += getdata.inventory[i].ch[j];
					}
					ustring ObjPayload = this->bitmrc->sharedObj.searchByHash(tag);
					if (!ObjPayload.empty())
					{
						object obj;
						
						memset(obj.command, 0x00, sizeof obj.command);
						strncpy(obj.command, "object", 7);

						obj.message_payload = ObjPayload;
						obj.setChecksum_Lenght_Magic();
						Packets.push(obj);
					}
				}
			}else if(!strcmp(packet.command,"object"))
			{
				object obj(packet);
				bool check = checkPow(obj.message_payload, obj.Time);

				//if not ignore
				if (check)
				{
					ustring invHash = this->bitmrc->inventoryHash(obj.message_payload);
					int present = this->bitmrc->sharedObj.insert(obj.message_payload, invHash);
					
					sTag tag;
					memcpy(tag.ch, invHash.c_str(), 32);

					this->bitmrc->new_inv.push(tag);

					if (obj.objectType == type_getpubkey)
					{
						packet_getpubkey getpubkey(obj);
						
						std::shared_lock<std::shared_timed_mutex> mlock(this->bitmrc->mutex_priv);

						for (unsigned int i = 0; i < this->bitmrc->PrivAddresses.size(); i++)
						{
							ustring tag = this->bitmrc->PrivAddresses[i].getTag();
							if (getpubkey.tag == tag)
							{
								if(this->bitmrc->PrivAddresses[i].getLastPubKeyRequest() + 60 * 60 * 24 * 4 < time(NULL))
									this->bitmrc->sendObj(this->bitmrc->PrivAddresses[i].encodePubKey(),true);
								//else
									//printf("PubKey already shared recently");
							}
						}

						mlock.unlock();
					}
					else if (obj.objectType == type_pubkey)
					{
						packet_pubkey pubkey(obj);

						std::shared_lock<std::shared_timed_mutex> mlock(this->bitmrc->mutex_pub);

						for (unsigned int i = 0; i < this->bitmrc->PubAddresses.size(); i++)
						{
							if (!this->bitmrc->PubAddresses[i].waitingPubKey())
								continue;
							ustring tag = this->bitmrc->PubAddresses[i].getTag();
							if (pubkey.tag == tag)
							{
								this->bitmrc->PubAddresses[i].decodeFromObj(pubkey);
							}
						}

						mlock.unlock();
					}
					else if (obj.objectType == type_msg)
					{
						packet_msg msg(obj);

						if (this->bitmrc->decryptMsg(msg)) //it takes like 1-4 milliseconds
						{
							//printf("Message accepted\n");
						}
					}
					else if (obj.objectType == type_broadcast)
					{
						packet_broadcast broadcast(obj);

						if (this->bitmrc->decryptMsg(broadcast))
						{
							//printf("broadcast decrypted\n");
						}
					}
				}
			}
			
		}
	}catch(int e)
	{
		switch(e)
		{
		case CONNECTION_CLOSED:
		case CONNECTION_ERROR:
			this->Close();
			return;
		}
	}
}
Esempio n. 22
0
void credgen_tests::test_credgen_irma_testvec()
{
	mpz_class n("0x88CC7BD5EAA39006A63D1DBA18BDAF00130725597A0A46F0BACCEF163952833BCBDD4070281CC042B4255488D0E260B4D48A31D94BCA67C854737D37890C7B21184A053CD579176681093AB0EF0B8DB94AFD1812A78E1E62AE942651BB909E6F5E5A2CEF6004946CCA3F66EC21CB9AC01FF9D3E88F19AC27FC77B1903F141049");
	mpz_class Z("0x3F7BAA7B26D110054A2F427939E61AC4E844139CEEBEA24E5C6FB417FFEB8F38272FBFEEC203DB43A2A498C49B7746B809461B3D1F514308EEB31F163C5B6FD5E41FFF1EB2C5987A79496161A56E595BC9271AAA65D2F6B72F561A78DD6115F5B706D92D276B95B1C90C49981FE79C23A19A2105032F9F621848BC57352AB2AC");
	mpz_class S("0x617DB25740673217DF74BDDC8D8AC1345B54B9AEA903451EC2C6EFBE994301F9CABB254D14E4A9FD2CD3FCC2C0EFC87803F0959C9550B2D2A2EE869BCD6C5DF7B9E1E24C18E0D2809812B056CE420A75494F9C09C3405B4550FD97D57B4930F75CD9C9CE0A820733CB7E6FC1EEAF299C3844C1C9077AC705B774D7A20E77BA30");
	std::vector<mpz_class> R;
	
	R.push_back(mpz_class("0x6B4D9D7D654E4B1285D4689E12D635D4AF85167460A3B47DB9E7B80A4D476DBEEC0B8960A4ACAECF25E18477B953F028BD71C6628DD2F047D9C0A6EE8F2BC7A8B34821C14B269DBD8A95DCCD5620B60F64B132E09643CFCE900A3045331207F794D4F7B4B0513486CB04F76D62D8B14B5F031A8AD9FFF3FAB8A68E74593C5D8B"));
	R.push_back(mpz_class("0x177CB93935BB62C52557A8DD43075AA6DCDD02E2A004C56A81153595849A476C515A1FAE9E596C22BE960D3E963ECFAC68F638EBF89642798CCAE946F2F179D30ABE0EDA9A44E15E9CD24B522F6134B06AC09F72F04614D42FDBDB36B09F60F7F8B1A570789D861B7DBD40427254F0336D0923E1876527525A09CDAB261EA7EE"));
	R.push_back(mpz_class("0x12ED9D5D9C9960BACE45B7471ED93572EA0B82C611120127701E4EF22A591CDC173136A468926103736A56713FEF3111FDE19E67CE632AB140A6FF6E09245AC3D6E022CD44A7CC36BCBE6B2189960D3D47513AB2610F27D272924A84154646027B73893D3EE8554767318942A8403F0CD2A41264814388BE4DF345E479EF52A8"));
	R.push_back(mpz_class("0x7AF1083437CDAC568FF1727D9C8AC4768A15912B03A8814839CF053C85696DF3A5681558F06BAD593F8A09C4B9C3805464935E0372CBD235B18686B540963EB9310F9907077E36EED0251D2CF1D2DDD6836CF793ED23D266080BF43C31CF3D304E2055EF44D454F477354664E1025B3F134ACE59272F07D0FD4995BDAACCDC0B"));
	R.push_back(mpz_class("0x614BF5243C26D62E8C7C9B0FAE9C57F44B05714894C3DCF583D9797C423C1635F2E4F1697E92771EB98CF36999448CEFC20CB6E10931DED3927DB0DFF56E18BD3A6096F2FF1BFF1A703F3CCE6F37D589B5626354DF0DB277EF73DA8A2C7347689B79130559FB94B6260C13D8DC7D264BA26953B906488B87CDC9DFD0BC69C551"));
	R.push_back(mpz_class("0x5CAE46A432BE9DB72F3B106E2104B68F361A9B3E7B06BBE3E52E60E69832618B941C952AA2C6EEFFC222311EBBAB922F7020D609D1435A8F3F941F4373E408BE5FEBAF471D05C1B91030789F7FEA450F61D6CB9A4DD8642253327E7EBF49C1600C2A075EC9B9DEC196DDBDC373C29D1AF5CEAD34FA6993B8CDD739D04EA0D253"));
	R.push_back(mpz_class("0x52E49FE8B12BFE9F12300EF5FBDE1800D4611A587E9F4763C11E3476BBA671BFD2E868436C9E8066F96958C897DD6D291567C0C490329793F35E925B77B304249EA6B30241F5D014E1C533EAC27AA9D9FCA7049D3A8D89058969FC2CD4DC63DF38740701D5E2B7299C49EC6F190DA19F4F6BC3834EC1AE145AF51AFEBA027EAA"));
	R.push_back(mpz_class("0x05AA7EE2AD981BEE4E3D4DF8F86414797A8A38706C84C9376D324070C908724BB89B224CB5ADE8CDDB0F65EBE9965F5C710C59704C88607E3C527D57A548E24904F4991383E5028535AE21D11D5BF87C3C5178E638DDF16E666EA31F286D6D1B3251E0B1470E621BEE94CDFA1D2E47A86FD2F900D5DDCB42080DAB583CBEEEDF"));
	R.push_back(mpz_class("0x73D3AB9008DC2BD65161A0D7BFC6C29669C975B54A1339D8385BC7D5DEC88C6D4BD482BFBC7A7DE44B016646B378B6A85FBC1219D351FE475DC178F90DF4961CA980EB4F157B764EC3ECF19604FEDE0551AA42FB12B7F19667AC9F2C46D1185E66072EA709CC0D9689CE721A47D54C028D7B0B01AEEC1C4C9A03979BE9080C21"));
	R.push_back(mpz_class("0x33F10AB2D18B94D870C684B5436B38AC419C08FB065A2C608C4E2E2060FE436945A15F8D80F373B35C3230654A92F99B1A1C8D5BB10B83646A112506022AF7D4D09F7403EC5AECDB077DA945FE0BE661BAFEDDDDC5E43A4C5D1A0B28AE2AA838C6C8A7AE3DF150DBD0A207891F1D6C4001B88D1D91CF380EE15E4E632F33BD02"));
	
	silvia_pub_key pubkey(n, S, Z, R);
	
	silvia_credential_generator cred(&pubkey);
	
	silvia_integer_attribute m1(1313);
	silvia_integer_attribute m2(1314);
	silvia_integer_attribute m3(1315);
	silvia_integer_attribute m4(1316);
	
	std::vector<silvia_attribute*> attributes;
	attributes.push_back(&m1);
	attributes.push_back(&m2);
	attributes.push_back(&m3);
	attributes.push_back(&m4);
	
	cred.set_attributes(attributes);
	
	silvia_integer_attribute s(mpz_class("0xB1173E9CFA91149B60B6A3A5822B49FAF79A6EED971469FCABEA79BC82AF36E0"));
	cred.set_secret(s);
	
	// Test computing the commitment
	mpz_class U;
	mpz_class v_prime;
	mpz_class v_prime_test("0xAE472CE185E9484385B2B9D6CA64FD44AC3E45688A780389B73B4F0C266F110291798C303B0C7C28EDFEBCEA0B783F138AB00C873B820B8F77D659127286429A184C28E122743E31731487D6D049C981D09DEC7DB0909223C765E5027C3A4D7B64F61FACDA5FD9D20BDEA131EF2A16ED508E5393C632F28ED603E724ACE9E922410E2D6F85BA4B25DC8C");
	
	cred.compute_commitment(U, v_prime, &v_prime_test);
	
	CPPUNIT_ASSERT(U == mpz_class("0x303150D3557EC3496A6720FC23D5B77A4B6E396D86C130A3BD9B886EE86307D3F12BCE8AEC0D8C46AD20628C4F0C58AFD5E6E699BFFC398712FC202F1EA825FD42AA4D461E5C7C5D7294588331BDE3810E31609A6B963698F8A2F518AA6B58E0F8A7EFE52DB5DCC864AAECF4C817A33342F53BBADDE6EFE247E14CAB2010BEE4"));
	
	// Test proof of commitment
	mpz_class c;
	mpz_class v_prime_hat;
	mpz_class s_hat;
	
	mpz_class s_tilde_test("0x018CB1BFAAD3402714E796B4E2F7DC7246950A074D0A5F782E25005611FC6374FDC395DE21023512990742ACC70FBA8AED6FB68F17A4D84C7A27486E56099C");
	mpz_class v_prime_tilde_test("0xF87EFB6925659CA77DC2247069D84FC7CAA60318C4222A9FA16E303B92234367909AB4E082FCDF66692D98FE019E86DF0347FAD1AF09AE55F7E6C0F736586CBD9B14BC23F556F29DCA1CA79018C8AC611E21202A3FDE1A9FB50C0CD9044271ECA4A0C3595006085FC2891F72C88C63CF79E843F21C9CA426A808BC1A43297112C7C34A125967B85BEB4249EFCC2C16455CF796A0851D50EEEB115AA08A58C2DF86D1F08C40E5C47D");
	mpz_class n1_test("0x80FC58C623C80FC7092D");
	mpz_class context("0xBA45FCF32A16B18C344865A288F4D421A3C5FE03");
	
	cred.prove_commitment(n1_test, context, c, v_prime_hat, s_hat, &s_tilde_test, &v_prime_tilde_test);
	
	CPPUNIT_ASSERT(c == mpz_class("0x7838BDCB7F99A8AC732BC867F800E16A61361D38"));
	CPPUNIT_ASSERT(v_prime_hat == mpz_class("0xF87EFB6925659CA77DC2764867A8ED5370E1B2C5A3D073D1B40AA06A0529D309BF552A2ACE20E9167B1EB661C4FA0CB5398068D58A66AEC0D980C34E2B8CAA260F6720ADF052C4B5AB07E490D84BF4E42A7748EC4148502E1A744CCB42BD2D0C6F20B600E15121F57ED991AC8903A4BF2F2D393BEC08984648FB0B65FD9D3195991E8E1E734C2C45D24BBD7220956780FF48B22E40329E8C44F84C9790FA557BE9A6DC558CB1DF1D"));
	CPPUNIT_ASSERT(s_hat == mpz_class("0x018CB1BFAAD3402714E797080D1D96A8FEC58A0462672573A44ED3993AFA77505089E7F691A7ABE0939129DC3E9D2517361C7135AD7760AE9EB0D351216A9C"));
	
	// Test signature proof validation
	mpz_class n2_test("0x7BAF54ECE6CADE702CB8");
	
	cred.get_prover_nonce(&n2_test);
	
	mpz_class A("0x37FB456B3D4D38F890F5DECDBE8147DD476A8F951E325EB3E860ABD2CCD4F52A1EF46594ED2D450869328DFFF6ACBD049BB8DD7AE4E256EB501B79BC17E1D68AB224D9CC310EB73CC218C43E860346942D690BBCEE7A3ED392D3933BB8CE6D4539A4D08475738A84B0FFB7D1A0CF25644E6EABC97A52C62BBC507E6885D16373");
	mpz_class e("0x8000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006D093A6A327D0392ED2787DA24BB7D");
	mpz_class c_1("0xBE19129671FE5140C1E267A337AB4083C93EBC18");
	mpz_class e_hat("0x0137B079E0B05ADB0F1075005BA70D61EBEEE7A7DCC5DC685354F335FD7B53A6844B3E70E2CFCD38B5DDDD4470E6F520A20C496D6F587D3B8F690E8AA9090217F630481A05FDFC44DFF364574735BAFE4F29874812D4BD73EBDB10B631DA2C91D27059B9D52B679E86C8B6732C9A7020DD6E8B686D179C9767C50F1775215F0A");
	
	CPPUNIT_ASSERT(cred.verify_signature(context, A, e, c_1, e_hat) == true);
	
	// Test credential verification
	mpz_class v_prime_prime("0x0B2067BB63FEF96D093A81CB7BD270188E5F47AEEA74A350C3848114E353E0E2654205BAD43B632DDDC23CA357780544A63AA4ACCE35C6D9123C34CD31ABD153FF6FC59E7898CA6CEFE4A748E26384148C695EFC910E12AFFB16F0299A1F9A1B20BF84FB0E886BC32B135093600B674DCDD82A30595E64063358E18BD012752D21DC1A5657A6F8E466924D596031A8237E5A98F9636AAEFF55FE86A9AF973523611583B5B64E7713B84983759ED517382C9922A04B58BA086D6D121B277B06356041C8F2244D04D2BC");
	
	cred.compute_credential(A, e, v_prime_prime);
	
	CPPUNIT_ASSERT(cred.verify_credential() == true);
	
	silvia_credential* new_cred = cred.get_credential();
	
	mpz_class v_test("0x0B2067BB63FEF96D093A81CB7BD270188E5F47AEEA74A350C3848114E353E0E2654205BAD43B632DDDC23CA357780544A63AA4ACCE35C6D9123C34CD31ABD202469CA72461E10DF2A29E7E134760C8C0CAAEC78709119C673665FC5009309CAC9A4BB5361B0494B129D03A9ED84A7AD87DE4B16BDB69F37E09B1F3FE56550F456E04FB78CBE52A577B1A2429A9FB29F41C4716A9F3FCD2C6BBE38925E9E4B088573530901628491F96EAB564C8EC0488BAECB6667E4B48DE715436C8116428766E6F3877DE982AAF48");
	
	CPPUNIT_ASSERT(new_cred->get_A() == A);
	CPPUNIT_ASSERT(new_cred->get_e() == e);
	CPPUNIT_ASSERT(new_cred->get_v() == v_test);
	CPPUNIT_ASSERT(new_cred->get_secret() == s);
	CPPUNIT_ASSERT(new_cred->num_attributes() == 4);
	CPPUNIT_ASSERT(new_cred->get_attribute(0)->rep() == m1.rep());
	CPPUNIT_ASSERT(new_cred->get_attribute(1)->rep() == m2.rep());
	CPPUNIT_ASSERT(new_cred->get_attribute(2)->rep() == m3.rep());
	CPPUNIT_ASSERT(new_cred->get_attribute(3)->rep() == m4.rep());

	delete new_cred;
}