Author

Topic: i2o_ECPublicKey Not Working... (Read 1647 times)

legendary
Activity: 1190
Merit: 1004
June 16, 2012, 02:07:25 PM
#10
I'll give you the 100 reputation bounty tomorrow when it lets me.
hero member
Activity: 588
Merit: 500
June 16, 2012, 01:19:56 PM
#9
Woohoo, I finally got some reputation on SO...
legendary
Activity: 1190
Merit: 1004
June 16, 2012, 01:13:40 PM
#8
Thank you!

Should have figured that myself...
hero member
Activity: 588
Merit: 500
June 16, 2012, 01:07:30 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

I know why it doesn't work and I posted a solution for you. Enjoy.
legendary
Activity: 1190
Merit: 1004
June 16, 2012, 11:49:45 AM
#6
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
legendary
Activity: 1190
Merit: 1004
June 08, 2012, 11:09:56 AM
#5
@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.
legendary
Activity: 1190
Merit: 1004
June 07, 2012, 05:10:53 PM
#4
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
legendary
Activity: 2128
Merit: 1073
June 07, 2012, 05:06:35 PM
#3
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.
legendary
Activity: 1190
Merit: 1004
June 07, 2012, 04:06:25 PM
#2
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?
legendary
Activity: 1190
Merit: 1004
June 07, 2012, 02: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 
#include
#include

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.
Jump to: