Why can't I use `BIGNUM` in this C struct declaration?

154 Views Asked by At

I was experimenting with some ~2005 C code (using OpenSSL 0.9.8, I think) and I tried make-ing it with OpenSSL 3.0.2 on Ubuntu 22.04.

Minimum example:

#include <openssl/bn.h>

struct fraction
{
    BIGNUM numerator;
    BIGNUM denominator;
}

Expected: everything builds, just as intended.

Actual: complier complains about incomplete type declaration for both fields.

Why does this happen? Is this not a valid declaration? Or is it something else?

1

There are 1 best solutions below

0
dbush On BEST ANSWER

Later versions of OpenSSL made several types opaque, including BIGNUM, which means you can't instantiate them directly in user code. The BIGNUM type in particular became an opaque type starting with version 1.1.0.

You would instead need to use pointers:

struct fraction
{
    BIGNUM *numerator;
    BIGNUM *denominator;
};

And use the appropriate functions to create and destroy them, as well as use the relevant accessor functions to access the members.