Compiling OpenSSL on a Mac

Hi everyone,

I'm having a build issue on a Mac (10.5) that resembles the problem mentioned on the FAQ page:

http://www.openssl.org/support/faq.html#BUILD9

I searched my HDD for a 'PROBLEMS' file and the only one I found was for emacs.  Doesn't look like what I need.


The issue I'm seeing is when compiling:

mac# openssl version
OpenSSL 0.9.7l 28 Sep 2006
- Hide quoted text -
mac# gcc blowfish.c -o blowfish
...
Undefined symbols:
  "_incremental_send", referenced from:
      _incremental_encrypt in ccbqFUEC.o
      _incremental_finish in ccbqFUEC.o
  "_EVP_DecryptUpdate", referenced from:
      _decrypt_example in ccbqFUEC.o
  "_EVP_EncryptInit", referenced from:
      _setup_for_encryption in ccbqFUEC.o
      _main in ccbqFUEC.o
  "_EVP_bf_cbc", referenced from:
      _setup_for_encryption in ccbqFUEC.o
      _setup_for_decryption in ccbqFUEC.o
      _main in ccbqFUEC.o
      _main in ccbqFUEC.o
  "_RAND_pseudo_bytes", referenced from:
      _select_random_iv in ccbqFUEC.o
  "_EVP_DecryptFinal", referenced from:
      _main in ccbqFUEC.o
  "_EVP_EncryptUpdate", referenced from:
      _encrypt_example in ccbqFUEC.o
      _encrypt_example in ccbqFUEC.o
      _incremental_encrypt in ccbqFUEC.o
  "_EVP_DecryptInit", referenced from:
      _setup_for_decryption in ccbqFUEC.o
      _main in ccbqFUEC.o
  "_RAND_bytes", referenced from:
      _select_random_key in ccbqFUEC.o
  "_EVP_EncryptFinal", referenced from:
      _encrypt_example in ccbqFUEC.o
      _incremental_finish in ccbqFUEC.o
  "_seed_prng", referenced from:
      _setup_for_encryption in ccbqFUEC.o
      _main in ccbqFUEC.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

Does anyone have any pointers or tips on how to rectify this?

Thanks for your help
LVL 1
jchristn123Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jkrCommented:
>>Does anyone have any pointers or tips on how to rectify this?

Sure. The basic problem is

gcc blowfish.c -o blowfish

This line will only compile the input file 'blowfish.c', but does not specify the OpenSSL library to link with. That should be

gcc blowfish.c -o blowfish -lssl

You might have to specify the pathe where the library resides in, then the command would look like

gcc blowfish.c -o blowfish -lssl -L/path/to/library
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jchristn123Author Commented:
Hi jkr,

Any idea where the library is installed to by default?

Thanks
0
jkrCommented:
That should be '/usr/local/ssl/libraries'. You can easily locate them using

find / -name "libssl*" -print
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

jchristn123Author Commented:
Hi jkr,

I tried each of the target paths in the output of find / -name "libssl*" -print and still receiving the symbol(s) not found error.  

I also tried -lcrypto and it didn't work there either.

Any other thoughts?

Thanks
0
jchristn123Author Commented:
FYI I tried:

gcc -I/usr/include/openssl -o blowfish-test blowfish-test.c -lssl -lcrypto

tried with and without -lcrypto, no luck at all.  

Also tried:

gcc blowfish-test.c -o blowfish-test -lssl -L/path/to/library

and it didn't work either.  Here is what I'm trying to compile (for reference)

#include <openssl/evp.h>
 
void select_random_key(char *key,int b)
{
  int i;
  
  RAND_bytes(key,b);
  for (i=0; i<b-1; i++) printf("%02X:",key[i]);
  printf("%02X\n",key[b-1]);
}
 
void select_random_iv(char *iv,int b)
{
  RAND_pseudo_bytes(iv,b);
}
 
int setup_for_encryption(void)
{
  EVP_CIPHER_CTX ctx;
  char key[EVP_MAX_KEY_LENGTH];
  char iv[EVP_MAX_IV_LENGTH];
  
  if (!seed_prng()) return 0;
  
  select_random_key(key,EVP_MAX_KEY_LENGTH);
  select_random_iv(iv,EVP_MAX_IV_LENGTH);
  EVP_EncryptInit(&ctx,EVP_bf_cbc(),key,iv);
  return 1;
}
 
void setup_for_decryption(char *key,char *iv)
{
  EVP_CIPHER_CTX ctx;
  EVP_DecryptInit(&ctx,EVP_bf_cbc(),key,iv);
}
 
char *encrypt_example(EVP_CIPHER_CTX *ctx,char *data,int inl,int *rb)
{
  char *ret;
  int i,tmp,ol;
  ol=0;
  ret=(char *)malloc(inl+EVP_CIPHER_CTX_block_size(ctx));
  for (i=0; i<inl/100; i++) {
    EVP_EncryptUpdate(ctx,&ret[ol],&tmp,&data[ol],100);
	ol+=tmp;
  }
  if (inl%100) {
    EVP_EncryptUpdate(ctx,&ret[ol],&tmp,&data[ol],inl%100);
	ol+=tmp;
  }
  EVP_EncryptFinal(ctx,&ret[ol],&tmp);
  *rb=ol+tmp;
  return ret;
}
 
int incremental_encrypt(EVP_CIPHER_CTX *ctx,char *data,int inl)
{
  char *buf;
  int ol;
  int bl=EVP_CIPHER_CTX_block_size(ctx);
  buf=(char *)malloc((inl+bl-1)/bl*bl);
  EVP_EncryptUpdate(ctx,buf,&ol,data,inl);
  if (ol) incremental_send(buf,ol);
  free(buf);
  return ol;
}
 
int incremental_finish(EVP_CIPHER_CTX *ctx)
{
  char *buf;
  int ol;
  buf=(char *)malloc(EVP_CIPHER_CTX_block_size(ctx));
  EVP_EncryptFinal(ctx,buf,&ol);
  if (ol) incremental_send(buf,ol);
  free(buf);
  return ol;
}  
 
char *decrypt_example(EVP_CIPHER_CTX *ctx,char *ct,int inl)
{
  char *pt=(char *)malloc(inl+EVP_CIPHER_CTX_block_size(ctx)+1);
  int ol;
  EVP_DecryptUpdate(ctx,pt,&ol,ct,inl);
  if (!ol) {
    free(pt);
	return NULL;
  }
  pt[ol]=0;
  return pt;
}
 
int main(int argc,char *argv[])
{
  EVP_CIPHER_CTX ctx;
  char key[EVP_MAX_KEY_LENGTH];
  char iv[EVP_MAX_IV_LENGTH];
  char *ct, *out;
  char final[EVP_MAX_BLOCK_LENGTH];
  char str[]="123456789abcdef";
  int i;
  
  if (!seed_prng()) {
    printf("ERROR: Unable to seed the PRNG.\n");
	abort();
  }
  
  select_random_key(key,EVP_MAX_KEY_LENGTH);
  select_random_iv(iv,EVP_MAX_IV_LENGTH);
  
  EVP_EncryptInit(&ctx,EVP_bf_cbc(),key,iv);
  ct=encrypt_example(&ctx,str,strlen(str),&i);
  printf("Ciphertext: %d bytes\n",i);
  
  EVP_DecryptInit(&ctx,EVP_bf_cbc(),key,iv);
  out=decrypt_example(&ctx,ct,8);
  printf("Decrypted: %s\n",out);
  out=decrypt_example(&ctx,ct+8,8);
  printf("Decrypted: %s\n",out);
  if (!EVP_DecryptFinal(&ctx,final,&i)) {
    printf("ERROR: Padding incorrect.\n");
	abort();
  }
  final[i]=0;
  printf("Decrypted: %s\n",final);
  
}

Open in new window

0
jchristn123Author Commented:
Any help would be appreciated tremendously!
0
jchristn123Author Commented:
I reinstalled again and now have it down to a single symbol not being recognized:

Undefined symbols:
  "_incremental_send", referenced from:
      _incremental_encrypt in cc4DdydW.o
      _incremental_finish in cc4DdydW.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

I'm using:

#gcc blowfish-test.c -o blowfish-test -lssl -lcrypto -L/usr/include/openssl

When I reinstalled openssl I pointed it to /usr/include/openssl as the installation destination

Any ideas?

Thanks!
0
jchristn123Author Commented:
My installation was failing, hence why it wasn't working.  Once I got the install to work, using -L fixed it.

Thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.