diff --git a/gostcoin-qt.pro b/gostcoin-qt.pro index e8b63bd..920c3b1 100644 --- a/gostcoin-qt.pro +++ b/gostcoin-qt.pro @@ -201,6 +201,7 @@ HEADERS += src/qt/bitcoingui.h \ src/ui_interface.h \ src/qt/rpcconsole.h \ src/i2p.h \ + src/Crypto.h \ src/Gost.h \ src/version.h \ src/netbase.h \ diff --git a/src/Crypto.h b/src/Crypto.h new file mode 100644 index 0000000..5c78a07 --- /dev/null +++ b/src/Crypto.h @@ -0,0 +1,26 @@ +#ifndef CRYPTO_H__ +#define CRYPTO_H__ + +#include +#include + +#include +#if (OPENSSL_VERSION_NUMBER < 0x010100000) || defined(LIBRESSL_VERSION_NUMBER) // 1.1.0 or LibreSSL +// define getters and setters introduced in 1.1.0 + +inline int ECDSA_SIG_set0(ECDSA_SIG *sig, BIGNUM *r, BIGNUM *s) + { + if (sig->r) BN_free (sig->r); + if (sig->s) BN_free (sig->s); + sig->r = r; sig->s = s; return 1; + } +inline void ECDSA_SIG_get0(const ECDSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps) + { *pr = sig->r; *ps = sig->s; } + +// ssl +#define TLS_method TLSv1_method + +#endif + +#endif + diff --git a/src/key.cpp b/src/key.cpp index e534417..4215c8f 100644 --- a/src/key.cpp +++ b/src/key.cpp @@ -2,6 +2,7 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +#include "Crypto.h" #include "Gost.h" #include "key.h" @@ -57,7 +58,9 @@ static int ECDSA_SIG_recover_key_GFp(EC_KEY *eckey, ECDSA_SIG *ecsig, const unsi if (!eckey) return 0; BIGNUM * d = BN_bin2bn (msg, msglen, nullptr); const auto& curve = i2p::crypto::GetGOSTR3410Curve (i2p::crypto::eGOSTR3410CryptoProA); - EC_POINT * pub = curve->RecoverPublicKey (d, ecsig->r, ecsig->s, recid % 2); + const BIGNUM * r, * s; + ECDSA_SIG_get0 (ecsig, &r, &s); + EC_POINT * pub = curve->RecoverPublicKey (d, r, s, recid % 2); BN_free (d); if (!pub) return 0; EC_KEY_set_public_key(eckey, pub); @@ -214,8 +217,9 @@ public: if (rec<0 || rec>=3) return false; ECDSA_SIG *sig = ECDSA_SIG_new(); - BN_bin2bn(&p64[0], 32, sig->r); - BN_bin2bn(&p64[32], 32, sig->s); + auto r = BN_bin2bn(&p64[0], 32, NULL); + auto s = BN_bin2bn(&p64[32], 32, NULL); + ECDSA_SIG_set0 (sig, r, s); bool ret = ECDSA_SIG_recover_key_GFp(pkey, sig, (unsigned char*)&hash, sizeof(hash), rec, 0) == 1; ECDSA_SIG_free(sig); return ret;