From 269b779eadb84366ccad8a3c53a66780684e4f62 Mon Sep 17 00:00:00 2001 From: Jochen Hoenicke Date: Mon, 25 Apr 2016 16:32:38 +0200 Subject: [PATCH 1/2] Updated cmake configuration for ed25519 --- CMakeLists.txt | 3 ++- Makefile | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0c80b48995..1baf398769 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,7 @@ cmake_minimum_required(VERSION 2.6) -set(SOURCES aescrypt.c aeskey.c aes_modes.c aestab.c base58.c bignum.c bip32.c bip39.c ecdsa.c hmac.c nist256p1.c pbkdf2.c rand.c ripemd160.c secp256k1.c sha2.c) +set(SOURCES aescrypt.c aeskey.c aes_modes.c aestab.c base58.c bignum.c bip32.c bip39.c ecdsa.c hmac.c nist256p1.c pbkdf2.c rand.c ripemd160.c secp256k1.c sha2.c ed25519-donna/ed25519.c) +include_directories(ed25519-donna) # disable sequence point warnings where they are expected set_source_files_properties(aeskey.c PROPERTIES diff --git a/Makefile b/Makefile index 7ae782975f..bded2f835a 100644 --- a/Makefile +++ b/Makefile @@ -37,9 +37,9 @@ SRCS = bignum.c ecdsa.c curves.c secp256k1.c nist256p1.c rand.c hmac.c bip32.c SRCS += ripemd160.c SRCS += sha2.c SRCS += aescrypt.c aeskey.c aestab.c aes_modes.c +SRCS += ed25519-donna/ed25519.c OBJS = $(SRCS:.c=.o) -OBJS += ed25519-donna/ed25519.o TESTLIBS = -lcheck -lrt -lpthread -lm TESTSSLLIBS = -lcrypto From 490fbed289388110f3ea5611389c931d023699bc Mon Sep 17 00:00:00 2001 From: Jochen Hoenicke Date: Mon, 25 Apr 2016 17:37:43 +0200 Subject: [PATCH 2/2] Adapted python unit test to new API --- c.pxd | 2 +- test_curves.py | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/c.pxd b/c.pxd index 6a445d6607..dc28f9c65f 100644 --- a/c.pxd +++ b/c.pxd @@ -5,7 +5,7 @@ cdef extern from "bip32.h": ctypedef struct HDNode: uint8_t public_key[33] - int hdnode_from_seed(const uint8_t *seed, int seed_len, HDNode *out) + int hdnode_from_seed(const uint8_t *seed, int seed_len, const char *curve, HDNode *out) int hdnode_private_ckd(HDNode *inout, uint32_t i) diff --git a/test_curves.py b/test_curves.py index c511bbc97f..845c41b0a2 100755 --- a/test_curves.py +++ b/test_curves.py @@ -41,11 +41,13 @@ random_iters = int(os.environ.get('ITERS', 1)) lib = c.cdll.LoadLibrary('./libtrezor-crypto.so') -lib.get_curve_by_name.restype = c.c_void_p +class curve_info(c.Structure): + _fields_ = [("bip32_name", c.c_char_p), + ("params", c.c_void_p)] +lib.get_curve_by_name.restype = c.POINTER(curve_info) BIGNUM = c.c_uint32 * 9 - class Random(random.Random): def randbytes(self, n): buf = (c.c_uint8 * n)() @@ -83,7 +85,7 @@ def r(request): @pytest.fixture(params=list(sorted(curves))) def curve(request): name = request.param - curve_ptr = lib.get_curve_by_name(name) + curve_ptr = lib.get_curve_by_name(name).contents.params assert curve_ptr, 'curve {} not found'.format(name) curve_obj = curves[name] curve_obj.ptr = c.c_void_p(curve_ptr) @@ -93,7 +95,7 @@ def curve(request): @pytest.fixture(params=points) def point(request): name = request.param.curve - curve_ptr = lib.get_curve_by_name(name) + curve_ptr = lib.get_curve_by_name(name).contents.params assert curve_ptr, 'curve {} not found'.format(name) curve_obj = curves[name] curve_obj.ptr = c.c_void_p(curve_ptr)