RE: Using libcrypto in a shared library
Maybe creating the library with ld rather than gcc might work better? Ted -Original Message-From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]On Behalf Of BorisSent: Wednesday, February 02, 2005 2:58 PMTo: openssl-users@openssl.orgSubject: Using libcrypto in a shared library Hi I'm having troubles using libcrypto in a shared library. Here is what I did: 1. I'm on RedHat 7.2 2. I installed OpenSSL by "./config shared" andgot /usr/local/ssl/lib/libcrypto.so 3. I wrote a sample library calling EVA functions (the library source attached below - decrypt.c) 4. I compiled the decrypt.c as follows: gcc -fpic -c decrypt.c -o decrypt.o -I/usr/local/ssl/include gcc -shared decrypt.o -o libdecrypt.so -L/usr/local/ssl/lib -lcrypto 5. I added current and the OpenSSL directories to the library path: LD_LIBRARY_PATH=$(pwd):/usr/local/ssl/lib When I try to run the testlib program (source attached below) the program fails on dlopen() Could someone please advise, whatam I doing wrong? Thanks in advance // decrypt.c #include "testlib.h"#include stdio.h#include openssl/evp.h#include fcntl.h int test_decrypt(){ int >int encfd; unsigned char outbuf[1032]; int olen, tlen, n; char inbuff[1032]; EVP_CIPHER_CTX ctx; unsigned char key[16]; unsigned char iv[8]; char *encfile = "blowfish_enc"; memset (key, 0, 16); memset (iv, 0, 8); strcpy(key,"1234567890123456"); strcpy(iv,"12345678"); if ((encfd = open (encfile, O_RDONLY)) == -1) { return onerr; } memset (inbuff, 0, sizeof(inbuff)); if ((n = read (encfd, inbuff, sizeof(inbuff))) == -1) { close(encfd); return onerr; } close (encfd); EVP_CIPHER_CTX_init (ctx); EVP_DecryptInit (ctx, EVP_bf_cbc (), key, iv); memset (outbuf, 0, sizeof(outbuf)); if (EVP_DecryptUpdate (ctx, outbuf, olen, inbuff, n) != 1) { return onerr; } if (EVP_DecryptFinal (ctx, outbuf + olen, tlen) != 1) { return onerr; } olen += tlen; printf("Output: %s", outbuf); return 0;} // testlib.c #include stdio.h#include stdlib.h#include unistd.h#include dlfcn.h int main(int argc, char **argv){void *handle;int (*test_decrypt)(void);char *c; handle = dlopen("libdecrypt.so", 1);c = dlerror();if(c){fprintf(stderr, "couldnt open library\n");abort();}test_decrypt = dlsym(handle, "test_decrypt");c = dlerror();if(c){fprintf(stderr, "couldnt get function symbol\n");abort();}test_decrypt();dlclose(handle);return 0;}
Re: Using libcrypto in a shared library
May be "export" will help you. export LD_LIBRARY_PATH=$(pwd):/usr/local/ssl/lib
Re: Using libcrypto in a shared library
thanks I will check the ld - Original Message - From: Ted Mittelstaedt To: openssl-users@openssl.org Sent: Thursday, February 03, 2005 10:59 AM Subject: RE: Using libcrypto in a shared library Maybe creating the library with ld rather than gcc might work better? Ted -Original Message-From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]On Behalf Of BorisSent: Wednesday, February 02, 2005 2:58 PMTo: openssl-users@openssl.orgSubject: Using libcrypto in a shared library Hi I'm having troubles using libcrypto in a shared library. Here is what I did: 1. I'm on RedHat 7.2 2. I installed OpenSSL by "./config shared" andgot /usr/local/ssl/lib/libcrypto.so 3. I wrote a sample library calling EVA functions (the library source attached below - decrypt.c) 4. I compiled the decrypt.c as follows: gcc -fpic -c decrypt.c -o decrypt.o -I/usr/local/ssl/include gcc -shared decrypt.o -o libdecrypt.so -L/usr/local/ssl/lib -lcrypto 5. I added current and the OpenSSL directories to the library path: LD_LIBRARY_PATH=$(pwd):/usr/local/ssl/lib When I try to run the testlib program (source attached below) the program fails on dlopen() Could someone please advise, whatam I doing wrong? Thanks in advance // decrypt.c #include "testlib.h"#include stdio.h#include openssl/evp.h#include fcntl.h int test_decrypt(){ int >int encfd; unsigned char outbuf[1032]; int olen, tlen, n; char inbuff[1032]; EVP_CIPHER_CTX ctx; unsigned char key[16]; unsigned char iv[8]; char *encfile = "blowfish_enc"; memset (key, 0, 16); memset (iv, 0, 8); strcpy(key,"1234567890123456"); strcpy(iv,"12345678"); if ((encfd = open (encfile, O_RDONLY)) == -1) { return onerr; } memset (inbuff, 0, sizeof(inbuff)); if ((n = read (encfd, inbuff, sizeof(inbuff))) == -1) { close(encfd); return onerr; } close (encfd); EVP_CIPHER_CTX_init (ctx); EVP_DecryptInit (ctx, EVP_bf_cbc (), key, iv); memset (outbuf, 0, sizeof(outbuf)); if (EVP_DecryptUpdate (ctx, outbuf, olen, inbuff, n) != 1) { return onerr; } if (EVP_DecryptFinal (ctx, outbuf + olen, tlen) != 1) { return onerr; } olen += tlen; printf("Output: %s", outbuf); return 0;} // testlib.c #include stdio.h#include stdlib.h#include unistd.h#include dlfcn.h int main(int argc, char **argv){void *handle;int (*test_decrypt)(void);char *c; handle = dlopen("libdecrypt.so", 1);c = dlerror();if(c){fprintf(stderr, "couldnt open library\n");abort();}test_decrypt = dlsym(handle, "test_decrypt");c = dlerror();if(c){fprintf(stderr, "couldnt get function symbol\n");abort();}test_decrypt();dlclose(handle);return 0;}
Re: Using libcrypto in a shared library
Thanks a lot. That was it. That's what happens when you try to do complex stuff without practicing the basics. Unfortunately we (I) don't always have the time to attend courses - we just need to get the job done. - Original Message - From: Zerg To: openssl-users@openssl.org Sent: Thursday, February 03, 2005 12:48 PM Subject: Re: Using libcrypto in a shared library May be "export" will help you. export LD_LIBRARY_PATH=$(pwd):/usr/local/ssl/lib
Using libcrypto in a shared library
Hi I'm having troubles using libcrypto in a shared library. Here is what I did: 1. I'm on RedHat 7.2 2. I installed OpenSSL by "./config shared" andgot /usr/local/ssl/lib/libcrypto.so 3. I wrote a sample library calling EVA functions (the library source attached below - decrypt.c) 4. I compiled the decrypt.c as follows: gcc -fpic -c decrypt.c -o decrypt.o -I/usr/local/ssl/include gcc -shared decrypt.o -o libdecrypt.so -L/usr/local/ssl/lib -lcrypto 5. I added current and the OpenSSL directories to the library path: LD_LIBRARY_PATH=$(pwd):/usr/local/ssl/lib When I try to run the testlib program (source attached below) the program fails on dlopen() Could someone please advise, whatam I doing wrong? Thanks in advance // decrypt.c #include "testlib.h"#include stdio.h#include openssl/evp.h#include fcntl.h int test_decrypt(){ int >int encfd; unsigned char outbuf[1032]; int olen, tlen, n; char inbuff[1032]; EVP_CIPHER_CTX ctx; unsigned char key[16]; unsigned char iv[8]; char *encfile = "blowfish_enc"; memset (key, 0, 16); memset (iv, 0, 8); strcpy(key,"1234567890123456"); strcpy(iv,"12345678"); if ((encfd = open (encfile, O_RDONLY)) == -1) { return onerr; } memset (inbuff, 0, sizeof(inbuff)); if ((n = read (encfd, inbuff, sizeof(inbuff))) == -1) { close(encfd); return onerr; } close (encfd); EVP_CIPHER_CTX_init (ctx); EVP_DecryptInit (ctx, EVP_bf_cbc (), key, iv); memset (outbuf, 0, sizeof(outbuf)); if (EVP_DecryptUpdate (ctx, outbuf, olen, inbuff, n) != 1) { return onerr; } if (EVP_DecryptFinal (ctx, outbuf + olen, tlen) != 1) { return onerr; } olen += tlen; printf("Output: %s", outbuf); return 0;} // testlib.c #include stdio.h#include stdlib.h#include unistd.h#include dlfcn.h int main(int argc, char **argv){void *handle;int (*test_decrypt)(void);char *c; handle = dlopen("libdecrypt.so", 1);c = dlerror();if(c){fprintf(stderr, "couldnt open library\n");abort();}test_decrypt = dlsym(handle, "test_decrypt");c = dlerror();if(c){fprintf(stderr, "couldnt get function symbol\n");abort();}test_decrypt();dlclose(handle);return 0;}