Bitcoin Forum
May 24, 2024, 09:46:22 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Segfault using secp256k1  (Read 987 times)
joschua011 (OP)
Member
**
Offline Offline

Activity: 86
Merit: 10


View Profile
July 30, 2014, 07:17:30 PM
Last edit: July 30, 2014, 08:16:49 PM by joschua011
 #1

Not sure if this is the right place to ask this but i guess quite some people here are familliar with sipa's version of secp256k1
https://github.com/bitcoin/secp256k1

when i try to run this code:

Quote

    unsigned char privateKeyBytes[33];
// some code to fill privateKeyBytes[]
    unsigned char publicKeyBytes[33];

    int length;
    int* l;
    l = &length;

    unsigned char* pubkeyptr;
    unsigned char* privkeyptr;
    pubkeyptr = &publicKeyBytes[0];
    privkeyptr = &privateKeyBytes[0];

    secp256k1_ecdsa_pubkey_create(pubkeyptr, l, privkeyptr, 1);


I get Segmentation fault (core dumped)  Huh

stuck at this for some time now....any ideas?
Sophokles
Hero Member
*****
Offline Offline

Activity: 1218
Merit: 516


Eloncoin.org - Mars, here we come!


View Profile WWW
July 30, 2014, 08:23:54 PM
 #2

Not sure if this is the right place to ask this but i guess quite some people here are familliar with sipa's version of secp256k1
https://github.com/bitcoin/secp256k1

when i try to run this code:

Quote

    unsigned char privateKeyBytes[33];
// some code to fill privateKeyBytes[]
    unsigned char publicKeyBytes[33];

    int length;
    int* l;
    l = &length;

    unsigned char* pubkeyptr;
    unsigned char* privkeyptr;
    pubkeyptr = &publicKeyBytes[0];
    privkeyptr = &privateKeyBytes[0];

    secp256k1_ecdsa_pubkey_create(pubkeyptr, l, privkeyptr, 1);


I get Segmentation fault (core dumped)  Huh

stuck at this for some time now....any ideas?


Did you just change the code? I was going to look it up, could swear it looked different a few minutes ago. Anyway, the definition of the pointers is screwed up.









▄▄████████▄▄
▄▄████████████████▄▄
▄██
████████████████████▄
▄███
██████████████████████▄
▄████
███████████████████████▄
███████████████████████▄
█████████████████▄███████
████████████████▄███████▀
██████████▄▄███▄██████▀
████████▄████▄█████▀▀
██████▄██████████▀
███▄▄█████
███████▄
██▄██████████████
░▄██████████████▀
▄█████████████▀
████████████
███████████▀
███████▀▀
.
▄▄███████▄▄
▄███████████████▄
▄███████████████████▄
▄██████████
███████████
▄███████████████████████▄
█████████████████████████
█████████████████████████
█████████████████████████
▀█
██████████████████████▀
▀██
███████████████████▀
▀███████████████████▀
▀█████████
██████▀
▀▀███████▀▀
.
 ElonCoin.org 
.
████████▄▄███████▄▄
███████▄████████████▌
██████▐██▀███████▀▀██
███████████████████▐█▌
████▄▄▄▄▄▄▄▄▄▄██▄▄▄▄▄
███▐███▀▄█▄█▀▀█▄█▄▀
███████████████████
█████████████▄████
█████████▀░▄▄▄▄▄
███████▄█▄░▀█▄▄░▀
███▄██▄▀███▄█████▄▀
▄██████▄▀███████▀
████████▄▀████▀
█████▄▄
.
"I could either watch it
happen or be a part of it"
▬▬▬▬▬
joschua011 (OP)
Member
**
Offline Offline

Activity: 86
Merit: 10


View Profile
July 30, 2014, 08:44:51 PM
 #3

Did you just change the code? I was going to look it up, could swear it looked different a few minutes ago. Anyway, the definition of the pointers is screwed up.

Actually i did, added pubkeyptr and privkeyptr, but its still not working...
Sophokles
Hero Member
*****
Offline Offline

Activity: 1218
Merit: 516


Eloncoin.org - Mars, here we come!


View Profile WWW
July 30, 2014, 09:06:52 PM
 #4

Code:
 /** * In: compressed: whether the computed public key should be compressed

* seckey: pointer to a 32-byte private key.

* Out: pubkey: pointer to a 33-byte (if compressed) or 65-byte (if uncompressed)

* area to store the public key.

* pubkeylen: pointer to int that will be updated to contains the pubkey's

* length.

* Returns: 1: secret was valid, public key stores

* 0: secret was invalid, try again.

*/

int secp256k1_ecdsa_pubkey_create(unsigned char *pubkey, int *pubkeylen, const unsigned char *seckey, int compressed);

 

The function returns an int. Have the return value assigned to a variable.









▄▄████████▄▄
▄▄████████████████▄▄
▄██
████████████████████▄
▄███
██████████████████████▄
▄████
███████████████████████▄
███████████████████████▄
█████████████████▄███████
████████████████▄███████▀
██████████▄▄███▄██████▀
████████▄████▄█████▀▀
██████▄██████████▀
███▄▄█████
███████▄
██▄██████████████
░▄██████████████▀
▄█████████████▀
████████████
███████████▀
███████▀▀
.
▄▄███████▄▄
▄███████████████▄
▄███████████████████▄
▄██████████
███████████
▄███████████████████████▄
█████████████████████████
█████████████████████████
█████████████████████████
▀█
██████████████████████▀
▀██
███████████████████▀
▀███████████████████▀
▀█████████
██████▀
▀▀███████▀▀
.
 ElonCoin.org 
.
████████▄▄███████▄▄
███████▄████████████▌
██████▐██▀███████▀▀██
███████████████████▐█▌
████▄▄▄▄▄▄▄▄▄▄██▄▄▄▄▄
███▐███▀▄█▄█▀▀█▄█▄▀
███████████████████
█████████████▄████
█████████▀░▄▄▄▄▄
███████▄█▄░▀█▄▄░▀
███▄██▄▀███▄█████▄▀
▄██████▄▀███████▀
████████▄▀████▀
█████▄▄
.
"I could either watch it
happen or be a part of it"
▬▬▬▬▬
joschua011 (OP)
Member
**
Offline Offline

Activity: 86
Merit: 10


View Profile
July 30, 2014, 09:12:19 PM
 #5

The function returns an int. Have the return value assigned to a variable.

I tried:

Code:
    int result;
    result = secp256k1_ecdsa_pubkey_create(pubkeyptr, l, privkeyptr, compressed);

But still segfault :/
joschua011 (OP)
Member
**
Offline Offline

Activity: 86
Merit: 10


View Profile
July 30, 2014, 09:43:55 PM
 #6

I forgot to call secp256k1_start();

works now, anyway thanks for your help!
Sophokles
Hero Member
*****
Offline Offline

Activity: 1218
Merit: 516


Eloncoin.org - Mars, here we come!


View Profile WWW
July 30, 2014, 10:10:39 PM
 #7

Cool. Will fiddle with this library a little later as well. Looks really interesting. Just today completely wrapped my mind around ECDSA signatures, fascinating stuff.









▄▄████████▄▄
▄▄████████████████▄▄
▄██
████████████████████▄
▄███
██████████████████████▄
▄████
███████████████████████▄
███████████████████████▄
█████████████████▄███████
████████████████▄███████▀
██████████▄▄███▄██████▀
████████▄████▄█████▀▀
██████▄██████████▀
███▄▄█████
███████▄
██▄██████████████
░▄██████████████▀
▄█████████████▀
████████████
███████████▀
███████▀▀
.
▄▄███████▄▄
▄███████████████▄
▄███████████████████▄
▄██████████
███████████
▄███████████████████████▄
█████████████████████████
█████████████████████████
█████████████████████████
▀█
██████████████████████▀
▀██
███████████████████▀
▀███████████████████▀
▀█████████
██████▀
▀▀███████▀▀
.
 ElonCoin.org 
.
████████▄▄███████▄▄
███████▄████████████▌
██████▐██▀███████▀▀██
███████████████████▐█▌
████▄▄▄▄▄▄▄▄▄▄██▄▄▄▄▄
███▐███▀▄█▄█▀▀█▄█▄▀
███████████████████
█████████████▄████
█████████▀░▄▄▄▄▄
███████▄█▄░▀█▄▄░▀
███▄██▄▀███▄█████▄▀
▄██████▄▀███████▀
████████▄▀████▀
█████▄▄
.
"I could either watch it
happen or be a part of it"
▬▬▬▬▬
Remember remember the 5th of November
Legendary
*
Offline Offline

Activity: 1862
Merit: 1011

Reverse engineer from time to time


View Profile
July 30, 2014, 10:35:40 PM
 #8

Code:
 /** * In: compressed: whether the computed public key should be compressed

* seckey: pointer to a 32-byte private key.

* Out: pubkey: pointer to a 33-byte (if compressed) or 65-byte (if uncompressed)

* area to store the public key.

* pubkeylen: pointer to int that will be updated to contains the pubkey's

* length.

* Returns: 1: secret was valid, public key stores

* 0: secret was invalid, try again.

*/

int secp256k1_ecdsa_pubkey_create(unsigned char *pubkey, int *pubkeylen, const unsigned char *seckey, int compressed);

 

The function returns an int. Have the return value assigned to a variable.

Just wanted to let you know, that in C or C++ and in many languages in fact, you are not forced to store the return value of a function. It means that, that wasn't what was causing the issue Wink

BTC:1AiCRMxgf1ptVQwx6hDuKMu4f7F27QmJC2
Pages: [1]
  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!