Re: dlopen and d2i_DHparams
Re: dlopen and d2i_DHparams
- Subject: Re: dlopen and d2i_DHparams
- From: Kevin Van Vechten <email@hidden>
- Date: Thu, 18 Aug 2005 13:45:07 -0700
What is the difference between SHA1 and d2i_DHparams that would
cause the first program to fail but the second one to succeed?
The obvious difference in the code you provided is that SHA1 is
function invocation and d2i_DHparams is a function reference. I
don't know enough about dlopen semantics to know whether the
reference should be resolved or not, but I'm sure you could use dlsym
(3) to get a valid function reference.
- Kevin
On Aug 17, 2005, at 12:44 AM, Steve Checkoway wrote:
I'm getting strange behavior when I try to dlopen libcrypto.dylib
and then use d2i_DHparams.
$ cat foobar.cpp
#include <openssl/dh.h>
#include <openssl/asn1.h>
#include <openssl/bn.h>
#include <cstdio>
#include <dlfcn.h>
#ifdef DHparams_dup
# undef DHparams_dup
#endif
#define DHparams_dup
(x) \
(DH *)ASN1_dup((int (*)(...))
i2d_DHparams, \
(char *(*)(...))d2i_DHparams,
(char *)(x))
int main()
{
void *handle = dlopen("libcrypto.dylib", RTLD_LAZY|
RTLD_GLOBAL);
DH *dh = DH_new();
BN_hex2bn(&dh->p,
"FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024"
"E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD"
"3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC"
"6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F"
"24117C4B1FE649286651ECE65381FFFFFFFFFFFFFFFF");
dh->g = BN_new();
BN_set_word(dh->g, DH_GENERATOR_2);
DH *dh2 = DHparams_dup(dh);
dlclose(handle);
return 0;
}
$ make foo bar baz
g++ -o foo -lcrypto foobar.cpp
g++ -flat_namespace -undefined suppress -bind_at_load \
-o bar foobar.cpp
MACOSX_DEPLOYMENT_TARGET=10.3 g++ -undefined dynamic_lookup \
-bind_at_load -o baz foobar.cpp
$ ./foo
$ ./bar
dyld: Symbol not found: _d2i_DHparams
Referenced from: /Users/steve/temp/dlopen/./bar
Expected in: flat namespace
Trace/BPT trap
$ ./baz
dyld: Symbol not found: _d2i_DHparams
Referenced from: /Users/steve/temp/dlopen/./baz
Expected in: dynamic lookup
Trace/BPT trap
When I run ./foo it runs correctly. When I run ./bar and ./baz dyld
fails with the symbol not found. However, it works with other
functions such as SHA1.
$ cat hash.cpp
#include <openssl/sha.h>
#include <cstdio>
#include <cstring>
#include <dlfcn.h>
int main()
{
void *handle = dlopen("libcrypto.dylib", RTLD_LAZY|
RTLD_GLOBAL);
unsigned char md[SHA_DIGEST_LENGTH];
char hello[] = "Hello World!";
puts(hello);
SHA1((unsigned char *)hello, strlen(hello), md);
for(int i = 0; i < SHA_DIGEST_LENGTH; ++i)
printf("hhx", md[i]);
puts("");
dlclose(handle);
return 0;
}
$ make hash
g++ -flat_namespace -undefined suppress -bind_at_load \
-o hash hash.cpp
$ ./hash
Hello World!
2ef7bde608ce5404e97d5f042f95f89f1c232871
What is the difference between SHA1 and d2i_DHparams that would
cause the first program to fail but the second one to succeed?
- Steve _______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40opendarwin.org
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden