4

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?

ZP-ZPanda
  • 107
  • 1
  • 10
  • 1
    `BIGNUM` is probably an [opaque type](https://en.wikipedia.org/wiki/Opaque_data_type), which in C is usually implemented using something like `struct bignum` without ever actually defining what's in `struct bignum` in a way accessible to callers. In this case `BIGNUM` is probably a `typedef` to a similar `struct` that's not visible. (I don't have the time right now to actually look into the OpenSSL 3 definition of `BIGNUM` to see if that's the actual answer, hence this comment) – Andrew Henle May 07 '23 at 23:05
  • Thanks for your answers! I'll try modifying it to use pointers. – ZP-ZPanda May 07 '23 at 23:11
  • 1
    In the future please provide full unedited error messages as you see them, or the first few lines if there are too many. – n. m. could be an AI May 27 '23 at 05:09

1 Answers1

3

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.

dbush
  • 205,898
  • 23
  • 218
  • 273