Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenSSL and Rand_bytes

Tags:

macos

gcc

openssl

My question is in regards to using OpenSSL on Mac via GCC.

    #include <stdio.h>
    #include <openssl/rand.h>

    int main()
    {
     unsigned char key[128];
     Rand_bytes(key,128);
     return 0;
    }

I have the following code, that I am trying to compile with GCC. Here is what I enter into the command line

    gcc -o ossl ossl.c -lcrypto -lssl

However I get the following error.

Undefined symbols for architecture x86_64: "_Rand_bytes", referenced from: _main in cc2hf0Ij.o ld: symbol(s) not found for architecture x86_64 collect2: ld returned 1 exit status

I am not experienced when it comes to using openssl. Why am I receiving Undefined symbols for architecture x86_64?

like image 914
jti107 Avatar asked Jun 08 '26 17:06

jti107


1 Answers

int main()
{
    unsigned char key[128];
    Rand_bytes(key,128);
    return 0;
}

Try RAND_bytes:

int main()
{
    unsigned char key[128];
    int rc = RAND_bytes(key,sizeof(key));
    if(rc != 1)
        /* Handle failure */

    ...
    OPENSSL_cleanse(key,sizeof(key));
    return 0;
}

The OpenSSL docs are at RAND_bytes(3).

like image 111
jww Avatar answered Jun 10 '26 09:06

jww



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!