Search code examples
copensslcryptographysignatureelliptic-curve

openssl api funtion reference issue


I am trying to generate and play around with openssl eliptic curves. running this: from the documentation

EC_GROUP *curve;
if(NULL == (curve = EC_GROUP_new_by_curve_name(NID_secp224r1)))
      handleErrors(); 
EC_KEY *key;
if(NULL == (key = EC_KEY_new_by_curve_name(NID_secp224r1)))
     handleErrors();
if(1 != EC_KEY_generate_key(key)) handleErrors();

with theese includes:

#include <openssl/obj_mac.h>
#include <openssl/ec.h>
#include <openssl/bn.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

I have looked through the ec.h file and it has the functions I am calling. My error is this:

key_gen.c:(.text+0x15): undefined reference to `EC_GROUP_new_by_curve_name'
key_gen.c:(.text+0x2a): undefined reference to `handleErrors'
key_gen.c:(.text+0x34): undefined reference to `EC_KEY_new_by_curve_name'
key_gen.c:(.text+0x49): undefined reference to `handleErrors'
key_gen.c:(.text+0x55): undefined reference to `EC_KEY_generate_key'
key_gen.c:(.text+0x64): undefined reference to `handleErrors'

do I need any more includes?


Solution

  • You need to link in the OpenSSL crypto library when compiling:

    gcc -g -Wall -Wextra -o key_gen key_gen.c -lcrypto