Hi David,

I'm down to symbol not defined for one item - incremental_send (and I can't
find what file this is supposed to be in).

I re-installed to /usr/include/openssl and used --prefix=/usr/include and
--openssldir=/usr/include/openssl

I'm trying to compile now with -lssl -lcrypto -L/usr/include/openssl

I believe -lssl tried linking to a legacy version of openssl (I saw a thread
on this on the openssl website FAQ section).

I'm using the examples in the O'Reilly OpenSSL book.  I've attached the file
I'm using for your review.

Here's what I'm getting now when I try and compile - this appears to be the
only error.

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

Thanks for your help,
Joel



On Feb 4, 2008 10:52 AM, David Schwartz <[EMAIL PROTECTED]> wrote:

>
> > Sorry I didn't update the list, but I tried with
> > -lssl and -lcrypto, as well as -I/usr/include/openssl.
>
> And what happened? Did you get the same error messages or different ones?
>
> > I've reinstalled openssl to no avail.
>
> What directories did you install to? And did you tell your compiler/linker
> to look in the right place?
>
> > Any other thoughts?
>
> Typical include lines look like this:
>
> #include <openssl/opensslconf.h>
>
> So adding "/usr/include/openssl" to the includes will only help if you
> installed the opensslconf.h file as
> "/usr/include/openssl/openssl/opensslconf.h" which doesn't seem to make
> much
> sense.
>
> Also, what file did '-lssl' actually wind up linking to? Was it the file
> you
> installed or some other file, perhaps one that came with your system?
>
> DS
>
>
> ______________________________________________________________________
> OpenSSL Project                                 http://www.openssl.org
> User Support Mailing List                    openssl-users@openssl.org
> Automated List Manager                           [EMAIL PROTECTED]
>
/*
 *
 *
 *
 *
 */

#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <string.h>
#include <pthread.h>
#include <stdlib.h>
#include <netinet/in.h>
#include <netdb.h>
#include <time.h>

#include <openssl/evp.h>
#include <openssl/ssl.h>
#include <openssl/x509.h>
#include <openssl/x509v3.h>
#include <openssl/err.h>
#include <openssl/pem.h>
#include <openssl/rand.h>
#include <openssl/bio.h>
#include <openssl/objects.h>

int seed_prng(int bytes)
{
  if (!RAND_load_file("/dev/random",bytes))
    return 0;
  return 1;
}

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(512)) 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(512)) {
    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);
  
}

Reply via email to