Browse Source

support of openssl 1.1

pull/26/head
orignal 6 years ago
parent
commit
90ce779b9f
  1. 22
      src/key.cpp

22
src/key.cpp

@ -145,8 +145,10 @@ public:
{ {
const BIGNUM * priv = EC_KEY_get0_private_key(pkey); const BIGNUM * priv = EC_KEY_get0_private_key(pkey);
BIGNUM * d = BN_bin2bn (hash.begin (), 32, nullptr); BIGNUM * d = BN_bin2bn (hash.begin (), 32, nullptr);
ECDSA_SIG *sig = ECDSA_SIG_new (); BIGNUM * r = BN_new (), * s = BN_new ();
i2p::crypto::GetGOSTR3410Curve (i2p::crypto::eGOSTR3410CryptoProA)->Sign (priv, d, sig->r, sig->s); i2p::crypto::GetGOSTR3410Curve (i2p::crypto::eGOSTR3410CryptoProA)->Sign (priv, d, r, s);
ECDSA_SIG *sig = ECDSA_SIG_new ();
ECDSA_SIG_set0 (sig, r, s);
// encode signature is in DER format // encode signature is in DER format
auto nSize = ECDSA_size (pkey); // max size auto nSize = ECDSA_size (pkey); // max size
vchSig.resize(nSize); vchSig.resize(nSize);
@ -166,7 +168,9 @@ public:
d2i_ECDSA_SIG (&sig, &p, vchSig.size()); d2i_ECDSA_SIG (&sig, &p, vchSig.size());
const EC_POINT * pub = EC_KEY_get0_public_key(pkey); const EC_POINT * pub = EC_KEY_get0_public_key(pkey);
BIGNUM * d = BN_bin2bn (hash.begin (), 32, nullptr); BIGNUM * d = BN_bin2bn (hash.begin (), 32, nullptr);
bool ret = i2p::crypto::GetGOSTR3410Curve (i2p::crypto::eGOSTR3410CryptoProA)->Verify (pub, d, sig->r, sig->s); const BIGNUM * r, * s;
ECDSA_SIG_get0 (sig, &r, &s);
bool ret = i2p::crypto::GetGOSTR3410Curve (i2p::crypto::eGOSTR3410CryptoProA)->Verify (pub, d, r, s);
BN_free (d); BN_free (d);
ECDSA_SIG_free(sig); ECDSA_SIG_free(sig);
return ret; return ret;
@ -178,13 +182,15 @@ public:
ECDSA_SIG *sig = ECDSA_SIG_new (); ECDSA_SIG *sig = ECDSA_SIG_new ();
const BIGNUM * priv = EC_KEY_get0_private_key(pkey); const BIGNUM * priv = EC_KEY_get0_private_key(pkey);
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, sig->r, sig->s); BIGNUM * r = BN_new (), * s = BN_new ();
i2p::crypto::GetGOSTR3410Curve (i2p::crypto::eGOSTR3410CryptoProA)->Sign (priv, d, r, s);
ECDSA_SIG_set0 (sig, r, s);
BN_free (d); BN_free (d);
if (sig==NULL) if (sig==NULL)
return false; return false;
memset(p64, 0, 64); memset(p64, 0, 64);
int nBitsR = BN_num_bits(sig->r); int nBitsR = BN_num_bits(r);
int nBitsS = BN_num_bits(sig->s); int nBitsS = BN_num_bits(s);
if (nBitsR <= 256 && nBitsS <= 256) { if (nBitsR <= 256 && nBitsS <= 256) {
CPubKey pubkey; CPubKey pubkey;
GetPubKey(pubkey, true); GetPubKey(pubkey, true);
@ -201,8 +207,8 @@ public:
} }
} }
assert(fOk); assert(fOk);
BN_bn2bin(sig->r,&p64[32-(nBitsR+7)/8]); BN_bn2bin(r,&p64[32-(nBitsR+7)/8]);
BN_bn2bin(sig->s,&p64[64-(nBitsS+7)/8]); BN_bn2bin(s,&p64[64-(nBitsS+7)/8]);
} }
ECDSA_SIG_free(sig); ECDSA_SIG_free(sig);
return fOk; return fOk;

Loading…
Cancel
Save