mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-16 03:18:09 +00:00
test_openssl: fix build with openssl 1.1.0+
OpenSSL 1.1.0 made R and S fields of ECDSA_SIG structure internal. We need to use ECDSA_SIG_set0 function now. For some reason the test fails, but previously the code was not even possible to compile with OpenSSL 1.1.0. Still need to figure out why the test fails :-(
This commit is contained in:
parent
8d8bc9c762
commit
a54c5fe89e
@ -24,9 +24,11 @@
|
||||
/* OpenSSL's SHA256_CTX/SHA512_CTX conflicts with our own */
|
||||
#define SHA256_CTX _openssl_SHA256_CTX
|
||||
#define SHA512_CTX _openssl_SHA512_CTX
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/ecdsa.h>
|
||||
#include <openssl/obj_mac.h>
|
||||
#include <openssl/sha.h>
|
||||
#include <openssl/opensslv.h>
|
||||
#undef SHA256_CTX
|
||||
#undef SHA512_CTX
|
||||
|
||||
@ -103,8 +105,14 @@ void openssl_check(unsigned int iterations, int nid, const ecdsa_curve *curve)
|
||||
|
||||
// copy signature to the OpenSSL struct
|
||||
ECDSA_SIG *signature = ECDSA_SIG_new();
|
||||
#if OPENSSL_VERSION_NUMBER < 0x10100000L
|
||||
BN_bin2bn(sig, 32, signature->r);
|
||||
BN_bin2bn(sig + 32, 32, signature->s);
|
||||
#else
|
||||
BIGNUM *R = BN_bin2bn(sig, 32, NULL);
|
||||
BIGNUM *S = BN_bin2bn(sig + 32, 32, NULL);
|
||||
ECDSA_SIG_set0(signature, R, S);
|
||||
#endif
|
||||
|
||||
// compute the digest of the message
|
||||
// note: these are OpenSSL functions, not our own
|
||||
@ -113,8 +121,9 @@ void openssl_check(unsigned int iterations, int nid, const ecdsa_curve *curve)
|
||||
SHA256_Final(hash, &sha256);
|
||||
|
||||
// verify all went well, i.e. we can decrypt our signature with OpenSSL
|
||||
if (ECDSA_do_verify(hash, 32, signature, eckey) != 1) {
|
||||
printf("OpenSSL verification failed\n");
|
||||
int v = ECDSA_do_verify(hash, 32, signature, eckey);
|
||||
if (v != 1) {
|
||||
printf("OpenSSL verification failed (%d)\n", v);
|
||||
return;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user