From a758a62048bd49a6b4aed1c62d3c5bfe4fcd4cad Mon Sep 17 00:00:00 2001 From: orignal Date: Fri, 31 Mar 2017 19:27:51 -0400 Subject: [PATCH] signatures in DER format --- i2pd | 2 +- src/key.cpp | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/i2pd b/i2pd index 4448884..3d1b6e2 160000 --- a/i2pd +++ b/i2pd @@ -1 +1 @@ -Subproject commit 4448884a3ebf822ecca7b39f2fe9777a79ae1863 +Subproject commit 3d1b6e29c6cf3f1c56c279819e8100b1c775b775 diff --git a/src/key.cpp b/src/key.cpp index 2f68fe0..6ad95be 100644 --- a/src/key.cpp +++ b/src/key.cpp @@ -143,13 +143,17 @@ public: bool Sign(const uint256 &hash, std::vector& vchSig) { const BIGNUM * priv = EC_KEY_get0_private_key(pkey); - BIGNUM * r = BN_new (), * s = BN_new (); BIGNUM * d = BN_bin2bn (hash.begin (), 32, nullptr); - i2p::crypto::GetGOSTR3410Curve (i2p::crypto::eGOSTR3410CryptoProA)->Sign (priv, d, r, s); - vchSig.resize(64); - i2p::crypto::bn2buf (r, &vchSig[0], 32); - i2p::crypto::bn2buf (s, &vchSig[32], 32); - BN_free (d); BN_free (r); BN_free (s); + ECDSA_SIG *sig = ECDSA_SIG_new (); + i2p::crypto::GetGOSTR3410Curve (i2p::crypto::eGOSTR3410CryptoProA)->Sign (priv, d, sig->r, sig->s); + // encode signature is in DER format + auto nSize = ECDSA_size (pkey); // max size + 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; }