mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-22 22:38:08 +00:00
test_openssl: Fix failing test
This commit is contained in:
parent
c70e440128
commit
b9043659c5
3
Makefile
3
Makefile
@ -27,6 +27,7 @@ CFLAGS += -I.
|
||||
CFLAGS += -DUSE_ETHEREUM=1
|
||||
CFLAGS += -DUSE_GRAPHENE=1
|
||||
CFLAGS += -DUSE_NEM=1
|
||||
CFLAGS += $(shell pkg-config --cflags openssl)
|
||||
|
||||
# disable certain optimizations and features when small footprint is required
|
||||
ifdef SMALL
|
||||
@ -55,7 +56,7 @@ SRCS += memzero.c
|
||||
OBJS = $(SRCS:.c=.o)
|
||||
|
||||
TESTLIBS = $(shell pkg-config --libs check) -lpthread -lm
|
||||
TESTSSLLIBS = -lcrypto
|
||||
TESTSSLLIBS = $(shell pkg-config --libs openssl)
|
||||
|
||||
all: test_check test_openssl test_speed aes/aestst tools libtrezor-crypto.so
|
||||
|
||||
|
@ -34,6 +34,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "ecdsa.h"
|
||||
#include "rand.h"
|
||||
@ -44,7 +45,7 @@
|
||||
|
||||
void openssl_check(unsigned int iterations, int nid, const ecdsa_curve *curve)
|
||||
{
|
||||
uint8_t sig[64], pub_key33[33], pub_key65[65], priv_key[32], msg[256], buffer[1000], hash[32], *p;
|
||||
uint8_t sig[64], pub_key33[33], pub_key65[65], priv_key[32], msg[256], hash[32];
|
||||
struct SHA256state_st sha256;
|
||||
EC_GROUP *ecgroup;
|
||||
|
||||
@ -64,24 +65,10 @@ void openssl_check(unsigned int iterations, int nid, const ecdsa_curve *curve)
|
||||
// generate the key
|
||||
EC_KEY_generate_key(eckey);
|
||||
// copy key to buffer
|
||||
p = buffer;
|
||||
i2d_ECPrivateKey(eckey, &p);
|
||||
|
||||
// size of the key is in buffer[8] and the key begins right after that
|
||||
int s = buffer[8];
|
||||
// extract key data
|
||||
if (s > 32) {
|
||||
for (int j = 0; j < 32; j++) {
|
||||
priv_key[j] = buffer[j + s - 23];
|
||||
}
|
||||
} else {
|
||||
for (int j = 0; j < 32 - s; j++) {
|
||||
priv_key[j] = 0;
|
||||
}
|
||||
for (int j = 0; j < s; j++) {
|
||||
priv_key[j + 32 - s] = buffer[j + 9];
|
||||
}
|
||||
}
|
||||
const BIGNUM *K = EC_KEY_get0_private_key(eckey);
|
||||
int bn_off = sizeof(priv_key) - BN_num_bytes(K);
|
||||
memset(priv_key, 0, bn_off);
|
||||
BN_bn2bin(K, priv_key + bn_off);
|
||||
|
||||
// use our ECDSA signer to sign the message with the key
|
||||
if (ecdsa_sign(curve, HASHER_SHA2, priv_key, msg, msg_len, sig, NULL, NULL) != 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user