From 587d6a65ea84f8927c9795d7051a2db791bc0154 Mon Sep 17 00:00:00 2001 From: Roman Zeyde Date: Tue, 7 Jul 2015 10:38:16 +0300 Subject: [PATCH 1/3] Update documentation regarding ECDSA curves support --- README.md | 2 +- bignum.c | 2 +- tools/mktable.c | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index f694357fac..435f9f1ad6 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ These include: - Big Number (256 bit) Arithmetics - BIP32 Hierarchical Deterministic Wallets - BIP39 Mnemonic code -- ECDSA signing/verifying (only hardcoded secp256k1 curve, +- ECDSA signing/verifying (supports secp256k1 and nist256p1 curves, uses RFC6979 for deterministic signatures) - ECDSA public key derivation + Base58 address representation - HMAC-SHA256 and HMAC-SHA512 diff --git a/bignum.c b/bignum.c index 050078a095..dee2f72a05 100644 --- a/bignum.c +++ b/bignum.c @@ -364,7 +364,7 @@ void bn_inverse(bignum256 *x, const bignum256 *prime) // res = old(x)^((prime-2) % 2^(i*30)) // get the i-th limb of prime - 2 limb = prime->val[i]; - // this is not enough in general but fine for secp256k1 because prime->val[0] > 1 + // this is not enough in general but fine for secp256k1 & nist256p1 because prime->val[0] > 1 if (i == 0) limb -= 2; for (j = 0; j < 30; j++) { // invariants: diff --git a/tools/mktable.c b/tools/mktable.c index f509a941d4..e7ff12c261 100644 --- a/tools/mktable.c +++ b/tools/mktable.c @@ -6,9 +6,9 @@ #include "rand.h" /* - * This program prints the contents of the secp256k1_cp array. - * The entry secp256k1_cp[i][j] contains the number (2*j+1)*16^i*G, - * where G is the generator of secp256k1. + * This program prints the contents of the ecdsa_curve.cp array. + * The entry cp[i][j] contains the number (2*j+1)*16^i*G, + * where G is the generator of the specified elliptic curve. */ int main(int argc, char **argv) { int i,j,k; From ea16aa0b86761c1393c203aec7176976966fee74 Mon Sep 17 00:00:00 2001 From: Roman Zeyde Date: Tue, 7 Jul 2015 10:39:12 +0300 Subject: [PATCH 2/3] Remove unnecessary #include "secp256k1.h" --- bignum.c | 1 - tools/mktable.c | 1 - 2 files changed, 2 deletions(-) diff --git a/bignum.c b/bignum.c index dee2f72a05..694df3c7c7 100644 --- a/bignum.c +++ b/bignum.c @@ -25,7 +25,6 @@ #include #include #include "bignum.h" -#include "secp256k1.h" #include "macros.h" inline uint32_t read_be(const uint8_t *data) diff --git a/tools/mktable.c b/tools/mktable.c index e7ff12c261..77997039dc 100644 --- a/tools/mktable.c +++ b/tools/mktable.c @@ -2,7 +2,6 @@ #include #include "bignum.h" #include "ecdsa.h" -#include "secp256k1.h" #include "rand.h" /* From 749cf8b75fbbe4995d3840866ece79b992f86261 Mon Sep 17 00:00:00 2001 From: Roman Zeyde Date: Tue, 7 Jul 2015 10:58:08 +0300 Subject: [PATCH 3/3] gui: fixup after ECDSA updates --- gui/gui.pro | 2 +- gui/mainwindow.cpp | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/gui/gui.pro b/gui/gui.pro index 9b9c73af9d..2ac6ec09ad 100644 --- a/gui/gui.pro +++ b/gui/gui.pro @@ -4,7 +4,7 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = gui TEMPLATE = app -SOURCES += ../bip32.c ../bip39.c ../sha2.c ../pbkdf2.c ../hmac.c ../rand.c ../bignum.c ../ecdsa.c ../ripemd160.c ../base58.c ../secp256k1.c mainwindow.cpp main.cpp +SOURCES += ../bip32.c ../bip39.c ../sha2.c ../pbkdf2.c ../hmac.c ../rand.c ../bignum.c ../ecdsa.c ../ripemd160.c ../base58.c ../secp256k1.c ../nist256p1.c mainwindow.cpp main.cpp HEADERS += mainwindow.h ../bip32.h ../bip39.h diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index b3a19296f7..a67d288572 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -45,7 +45,8 @@ void MainWindow::on_spinAccount_valueChanged(int arg1) { if (!root_set) return; const char addr_version = 0x00, wif_version = 0x80; - char buf[128]; + const size_t buflen = 128; + char buf[buflen + 1]; HDNode node; // external chain for (int chain = 0; chain < 2; chain++) { @@ -54,14 +55,14 @@ void MainWindow::on_spinAccount_valueChanged(int arg1) hdnode_private_ckd(&node, 44 | 0x80000000); hdnode_private_ckd(&node, 0 | 0x80000000); // bitcoin hdnode_private_ckd(&node, (arg1 - 1) | 0x80000000); - hdnode_serialize_private(&node, buf); QString xprv = QString(buf); ui->lineXprv->setText(xprv); - hdnode_serialize_public(&node, buf); QString xpub = QString(buf); ui->lineXpub->setText(xpub); + hdnode_serialize_private(&node, buf, buflen); QString xprv = QString(buf); ui->lineXprv->setText(xprv); + hdnode_serialize_public(&node, buf, buflen); QString xpub = QString(buf); ui->lineXpub->setText(xpub); hdnode_private_ckd(&node, chain); // external / internal for (int i = 0; i < 100; i++) { HDNode node2 = node; hdnode_private_ckd(&node2, i); - ecdsa_get_address(node2.public_key, addr_version, buf); QString address = QString(buf); - ecdsa_get_wif(node2.private_key, wif_version, buf); QString wif = QString(buf); + ecdsa_get_address(node2.public_key, addr_version, buf, buflen); QString address = QString(buf); + ecdsa_get_wif(node2.private_key, wif_version, buf, buflen); QString wif = QString(buf); list->setItem(i, 0, new QTableWidgetItem(address)); list->setItem(i, 1, new QTableWidgetItem(wif)); list->setItem(i, 2, new QTableWidgetItem("0.0"));