troubleshooting Question

Using openssl/blowfish.h and BF_set_key segmentation fault

Avatar of jchristn123
jchristn123 asked on
C
18 Comments2 Solutions1286 ViewsLast Modified:
Hello, I'm trying to use openssl/blowfish.h and getting a segmentation fault after compiling and running.  I'm not able to get past BF_set_key(), thus, I'm not getting very far at all!  Here's my code and output:

#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/blowfish.h>

int i,k;      
char randomString[16];      // 16-byte random
char bfKey[16];


int main(int nArg, char* pszArgs[])
{
  for (i=0; i<16; i++) {
    k=rand()%256;
    randomString[i]=(char)k;
  }
  randomString[16]='\0';
  printf("generated 16-byte random string %s\n",randomString);
  BF_KEY *bfKey;
  BF_set_key(bfKey,strlen(randomString),randomString);
  printf("bfKey=%s\n",bfKey);
  return 0;
}


#./untitled
generated 16-byte random string gÆisQÿJì)ͺ«òûãF
Segmentation fault


Can anyone help with this?

Thanks!
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 2 Answers and 18 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 18 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros