Browse Source

signatures in DER format

pull/5/head
orignal 7 years ago
parent
commit
a758a62048
  1. 2
      i2pd
  2. 16
      src/key.cpp

2
i2pd

@ -1 +1 @@
Subproject commit 4448884a3ebf822ecca7b39f2fe9777a79ae1863 Subproject commit 3d1b6e29c6cf3f1c56c279819e8100b1c775b775

16
src/key.cpp

@ -143,13 +143,17 @@ public:
bool Sign(const uint256 &hash, std::vector<unsigned char>& vchSig) bool Sign(const uint256 &hash, std::vector<unsigned char>& vchSig)
{ {
const BIGNUM * priv = EC_KEY_get0_private_key(pkey); const BIGNUM * priv = EC_KEY_get0_private_key(pkey);
BIGNUM * r = BN_new (), * s = BN_new ();
BIGNUM * d = BN_bin2bn (hash.begin (), 32, nullptr); BIGNUM * d = BN_bin2bn (hash.begin (), 32, nullptr);
i2p::crypto::GetGOSTR3410Curve (i2p::crypto::eGOSTR3410CryptoProA)->Sign (priv, d, r, s); ECDSA_SIG *sig = ECDSA_SIG_new ();
vchSig.resize(64); i2p::crypto::GetGOSTR3410Curve (i2p::crypto::eGOSTR3410CryptoProA)->Sign (priv, d, sig->r, sig->s);
i2p::crypto::bn2buf (r, &vchSig[0], 32); // encode signature is in DER format
i2p::crypto::bn2buf (s, &vchSig[32], 32); auto nSize = ECDSA_size (pkey); // max size
BN_free (d); BN_free (r); BN_free (s); vchSig.resize(nSize);
auto p = &vchSig[0];
nSize = i2d_ECDSA_SIG (sig, &p);
vchSig.resize(nSize); // acutal size
BN_free (d);
ECDSA_SIG_free(sig);
return true; return true;
} }

Loading…
Cancel
Save