Bitcoin Forum
May 21, 2024, 07:22:21 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: « 1 [2]  All
  Print  
Author Topic: ECDsa Verification Speed  (Read 3139 times)
riplin
Member
**
Offline Offline

Activity: 116
Merit: 10


View Profile
July 08, 2013, 06:38:52 PM
Last edit: July 08, 2013, 06:52:17 PM by riplin
 #21

I managed to get it to compile in Visual Studio. 32bit right now because 64bit OpenSSL seems to be giving me some linker trouble (_ prefix on the BN_* functions). Haven't had the time to look at that yet.
We can only appeal to spia to make a version without openssl/gmp dependencies, which would be just perfect.

I'm trying to verify the correctness of a secret key (basically, check if not zero and below a certain number, as can be seen in the Satoshi client) using this library, specifically, this function:

Code:
/** Verify an ECDSA secret key.
 *  Returns: 1: secret key is valid
 *           0: secret key is invalid
 *  In:      seckey: pointer to a 32-byte secret key
 */
int secp256k1_ecdsa_seckey_verify(const unsigned char *seckey) {
    secp256k1_num_t sec;
    secp256k1_num_init(&sec);
    secp256k1_num_set_bin(&sec, seckey, 32);
    int ret = secp256k1_num_is_zero(&sec) ||
              (secp256k1_num_cmp(&sec, &secp256k1_ge_consts->order) >= 0);
    secp256k1_num_free(&sec);
    return ret;
}

Please note, in all functions in this library, 0 == bad, 1 == good.

I'm finding three issues. The first one is, secp256k1_num_is_zero returns 1 if it's zero, else, it returns 0.

In the comment above, it states that 1 == valid. So it should be doing !secp256k1_num_is_zero(&sec).

Second, it's doing an ||, but both tests should be 1, so that should be &&.

And third, he &sec is compared to &secp256k1_ge_consts->order (which is the same as the upper bound number in the Satoshi client, it's basically doing a > b, and then testing if a (&sec) is larger or equal to b. But it should be doing ... < 0 at the end, since a should be less than b.

It looks like the whole thing is inverted and the return value should be 0 == good an 1 == bad.
jackjack
Legendary
*
Offline Offline

Activity: 1176
Merit: 1255


May Bitcoin be touched by his Noodly Appendage


View Profile
July 12, 2013, 10:07:35 AM
 #22

It looks like the whole thing is inverted and the return value should be 0 == good an 1 == bad.
That's it

Own address: 19QkqAza7BHFTuoz9N8UQkryP4E9jHo4N3 - Pywallet support: 1AQDfx22pKGgXnUZFL1e4UKos3QqvRzNh5 - Bitcointalk++ script support: 1Pxeccscj1ygseTdSV1qUqQCanp2B2NMM2
Pywallet: instructions. Encrypted wallet support, export/import keys/addresses, backup wallets, export/import CSV data from/into wallet, merge wallets, delete/import addresses and transactions, recover altcoins sent to bitcoin addresses, sign/verify messages and files with Bitcoin addresses, recover deleted wallets, etc.
Pieter Wuille
Legendary
*
qt
Offline Offline

Activity: 1072
Merit: 1174


View Profile WWW
July 12, 2013, 11:49:27 PM
 #23

It looks like the whole thing is inverted and the return value should be 0 == good an 1 == bad.

Thanks, fixed!

I do Bitcoin stuff.
slothbag
Sr. Member
****
Offline Offline

Activity: 369
Merit: 250



View Profile
September 26, 2013, 05:51:23 AM
 #24

Thanks everyone! What I have now is functional at least; it's good to know that the performance can be improved down the line.

P.S. Does anyone have much interest in a c# implementation? I started this mostly to educate myself, but I'm making more progress than I was expecting.

Hey pmlyon, I am interested in a C# implementation of the ECDSA based message sign & verify in Bitcoin-QT.. See this thread https://bitcointalk.org/index.php?topic=297097.0. Hhave you had a go at implementing that in your project yet?
pmlyon (OP)
Member
**
Offline Offline

Activity: 72
Merit: 10


View Profile
September 28, 2013, 09:51:40 PM
 #25

Thanks everyone! What I have now is functional at least; it's good to know that the performance can be improved down the line.

P.S. Does anyone have much interest in a c# implementation? I started this mostly to educate myself, but I'm making more progress than I was expecting.

Hey pmlyon, I am interested in a C# implementation of the ECDSA based message sign & verify in Bitcoin-QT.. See this thread https://bitcointalk.org/index.php?topic=297097.0. Hhave you had a go at implementing that in your project yet?


Hi, we haven't implemented that in our project yet, but I think this thread may help you: https://bitcointalk.org/index.php?topic=279752.0

Josh has a link there to a managed wrapper he wrote around the sipa secp256k1 verifier:
https://github.com/joshlang/Secp256k1.NET
https://github.com/sipa/secp256k1

I plan on using these when we get to that stage, but haven't looked at them yet.

Author of BitSharp, a C# Bitcoin node
https://github.com/pmlyon/BitSharp/wiki
Pages: « 1 [2]  All
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!