mirror of
https://github.com/GOSTSec/gostcoin
synced 2025-02-05 19:34:16 +00:00
initial support of openssl 1.1
This commit is contained in:
parent
efb9b835c7
commit
6251947af6
@ -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 \
|
||||
|
26
src/Crypto.h
Normal file
26
src/Crypto.h
Normal file
@ -0,0 +1,26 @@
|
||||
#ifndef CRYPTO_H__
|
||||
#define CRYPTO_H__
|
||||
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/ecdsa.h>
|
||||
|
||||
#include <openssl/opensslv.h>
|
||||
#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
|
||||
|
10
src/key.cpp
10
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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user