Bitcoin Forum
December 03, 2016, 06:00:50 PM *
News: To be able to use the next phase of the beta forum software, please ensure that your email address is correct/functional.
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: i2o_ECPublicKey Not Working...  (Read 1367 times)
MatthewLM
Legendary
*
Offline Offline

Activity: 1092



View Profile WWW
June 07, 2012, 07:48:04 PM
 #1

Hello. To get anywhere with my bitcoin library I clearly need to have a cryptography library working. OpenSSL is playing up big time.

I have this test program:

Code:
#include <stdio.h>
#include <openssl/sha.h>
#include <openssl/ssl.h>

int main(){
    printf("OpenSSL version: %s\n",OPENSSL_VERSION_TEXT);
    EC_KEY * key = EC_KEY_new_by_curve_name(NID_secp256k1);
    if(!EC_KEY_generate_key(key)){
        printf("GENERATE KEY FAIL\n");
        return 1;
    }
    u_int8_t pubSize = i2o_ECPublicKey(key, NULL);
    if(!pubSize){
        printf("PUB KEY TO DATA ZERO\n");
        return 1;
    }
    u_int8_t * pubKey = malloc(pubSize);
    if(i2o_ECPublicKey(key, &pubKey) != pubSize){
        printf("PUB KEY TO DATA FAIL\n");
        return 1;
    }
    u_int8_t * hash = malloc(SHA256_DIGEST_LENGTH);
    SHA256(pubKey, pubSize, hash);
    for (int x = 0; x < 32; x++) {
        printf("%.2x",hash[x]);
    }
    EC_KEY_free(key);
    free(pubKey);
    free(hash);
    return 0;
}

But i2o_ECPublicKey corrupts the pubKey memory block. See here: http://stackoverflow.com/questions/10906524/openssl-i2o-ecpublickey-not-working

I'm using OpenSSL 1.0.1c.

Until this is sorted there is a major problem with developing cbitcoin.

Thanks.

Bitcoin Extra Wallet | Peercoin Android Wallet
BTC: 1D5A1q5d192j5gYuWiP3CSE5fcaaZxe6E9  PPC: PH7fVn1Xs7nkUFmdwCX2ZRYfLPCSwGxAq9
1480788050
Hero Member
*
Offline Offline

Posts: 1480788050

View Profile Personal Message (Offline)

Ignore
1480788050
Reply with quote  #2

1480788050
Report to moderator
1480788050
Hero Member
*
Offline Offline

Posts: 1480788050

View Profile Personal Message (Offline)

Ignore
1480788050
Reply with quote  #2

1480788050
Report to moderator
1480788050
Hero Member
*
Offline Offline

Posts: 1480788050

View Profile Personal Message (Offline)

Ignore
1480788050
Reply with quote  #2

1480788050
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1480788050
Hero Member
*
Offline Offline

Posts: 1480788050

View Profile Personal Message (Offline)

Ignore
1480788050
Reply with quote  #2

1480788050
Report to moderator
1480788050
Hero Member
*
Offline Offline

Posts: 1480788050

View Profile Personal Message (Offline)

Ignore
1480788050
Reply with quote  #2

1480788050
Report to moderator
gweedo
Legendary
*
Offline Offline

Activity: 1246


Java, PHP, HTML/CSS Programmer for Hire!


View Profile WWW
June 07, 2012, 07:54:31 PM
 #2

did you try homebrew? You would have to remove macports maybe a last ditch effort.

Want to earn 2500 SATOSHIS per hour? Come Chat and Chill in https://goseemybits.com/lobby
MatthewLM
Legendary
*
Offline Offline

Activity: 1092



View Profile WWW
June 07, 2012, 09:06:25 PM
 #3

Well I verified that the dylib and a files were for OpenSSL 1.0.1c by searching for the version in the files. Indeed I had libcrypto and libssl files for 1.0.1c. So I tried adding them to Xcode. First I ensured the -lssl and -lcrypto flags were removed and I tried the dylibs first. This is what I got:

Code:
warning: Unable to read symbols for /usr/local/ssl/lib/libcrypto.1.0.0.dylib (file not found).
warning: Unable to read symbols from "libcrypto.1.0.0.dylib" (not yet mapped into memory).
warning: Unable to read symbols for /usr/local/ssl/lib/libssl.1.0.0.dylib (file not found).
warning: Unable to read symbols from "libssl.1.0.0.dylib" (not yet mapped into memory).
[Switching to process 1266 thread 0x0]
dyld: Library not loaded: /usr/local/ssl/lib/libcrypto.1.0.0.dylib
  Referenced from: /Users/matt/Library/Developer/Xcode/DerivedData/cbitcoin-bdkcvvuopgevvwcciljkluzxqser/Build/Products/Debug/testKeyHash
  Reason: image not found

I found this odd. Surely the dynamic libraries can be loaded from any directory?

Well I tried moving them to /usr/local/ssl/lib/ and I get this:

Code:
OpenSSL version: OpenSSL 0.9.8r 8 Feb 2011

Erm... So a 1.0.1c dylib that gives the version 0.9.8r? Clearly something is corrupted. I get similar problems with the static libraries. "0.9.8r" is not anywhere in the library files but "1.0.1c" is. Does anyone know what on earth is going on?

Bitcoin Extra Wallet | Peercoin Android Wallet
BTC: 1D5A1q5d192j5gYuWiP3CSE5fcaaZxe6E9  PPC: PH7fVn1Xs7nkUFmdwCX2ZRYfLPCSwGxAq9
2112
Legendary
*
Offline Offline

Activity: 1708



View Profile
June 07, 2012, 10:06:35 PM
 #4

Does anyone know what on earth is going on?
"man dyld" knows. In the other thread about pointers to functions I expressed the suspiction that you simply don't understand the concepts of dynamic linking. Now I have a confirmation of that suspiction.

I'm so sorry.

Please comment, critique, criticize or ridicule BIP 2112: https://bitcointalk.org/index.php?topic=54382.0
Long-term mining prognosis: https://bitcointalk.org/index.php?topic=91101.0
MatthewLM
Legendary
*
Offline Offline

Activity: 1092



View Profile WWW
June 07, 2012, 10:10:53 PM
 #5

I must be dumb for not realising OPENSSL_VERSION_TEXT is a macro so it is being received by the old headers. I'll include the correct headers and look again later.

But no doubt the right library binaries are being loaded.

And yes I've always hated this linking nonsense. Tongue

Bitcoin Extra Wallet | Peercoin Android Wallet
BTC: 1D5A1q5d192j5gYuWiP3CSE5fcaaZxe6E9  PPC: PH7fVn1Xs7nkUFmdwCX2ZRYfLPCSwGxAq9
MatthewLM
Legendary
*
Offline Offline

Activity: 1092



View Profile WWW
June 08, 2012, 04:09:56 PM
 #6

@2112: I think I know what you meant now. To use weak linking? I might do that actually.

I haven't had time to sort out the OpenSSL headers yet but I still think the i2o_ECPublicKey won't work. If anyone understands it better please explain what might be wrong. Maybe the correct headers suddenly solves everything but I think that is a long shot.

Bitcoin Extra Wallet | Peercoin Android Wallet
BTC: 1D5A1q5d192j5gYuWiP3CSE5fcaaZxe6E9  PPC: PH7fVn1Xs7nkUFmdwCX2ZRYfLPCSwGxAq9
MatthewLM
Legendary
*
Offline Offline

Activity: 1092



View Profile WWW
June 16, 2012, 04:49:45 PM
 #7

I've spent the last week working on testing the scripts and improving the code quote dramatically.

Now I've been able to install OpenSSL 1.0.1c successfully and link it correctly but...

It still doesn't work. Does anyone know why i2o_ECPublicKey doesn't work? It works in the C++ bitcoin client so why not my code?

http://stackoverflow.com/questions/10906524/openssl-i2o-ecpublickey-not-working

Bitcoin Extra Wallet | Peercoin Android Wallet
BTC: 1D5A1q5d192j5gYuWiP3CSE5fcaaZxe6E9  PPC: PH7fVn1Xs7nkUFmdwCX2ZRYfLPCSwGxAq9
error
Hero Member
*****
Offline Offline

Activity: 574



View Profile
June 16, 2012, 06:07:30 PM
 #8

I've spent the last week working on testing the scripts and improving the code quote dramatically.

Now I've been able to install OpenSSL 1.0.1c successfully and link it correctly but...

It still doesn't work. Does anyone know why i2o_ECPublicKey doesn't work? It works in the C++ bitcoin client so why not my code?

http://stackoverflow.com/questions/10906524/openssl-i2o-ecpublickey-not-working

I know why it doesn't work and I posted a solution for you. Enjoy.

15UFyv6kfWgq83Pp3yhXPr8rknv9m6581W
MatthewLM
Legendary
*
Offline Offline

Activity: 1092



View Profile WWW
June 16, 2012, 06:13:40 PM
 #9

Thank you!

Should have figured that myself...

Bitcoin Extra Wallet | Peercoin Android Wallet
BTC: 1D5A1q5d192j5gYuWiP3CSE5fcaaZxe6E9  PPC: PH7fVn1Xs7nkUFmdwCX2ZRYfLPCSwGxAq9
error
Hero Member
*****
Offline Offline

Activity: 574



View Profile
June 16, 2012, 06:19:56 PM
 #10

Woohoo, I finally got some reputation on SO...

15UFyv6kfWgq83Pp3yhXPr8rknv9m6581W
MatthewLM
Legendary
*
Offline Offline

Activity: 1092



View Profile WWW
June 16, 2012, 07:07:25 PM
 #11

I'll give you the 100 reputation bounty tomorrow when it lets me.

Bitcoin Extra Wallet | Peercoin Android Wallet
BTC: 1D5A1q5d192j5gYuWiP3CSE5fcaaZxe6E9  PPC: PH7fVn1Xs7nkUFmdwCX2ZRYfLPCSwGxAq9
Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!