Headerfile 中缺少定义 dh.h (openssl 1.1.0f)

Missing definitions in Headerfile dh.h (openssl 1.1.0f)

出于某种原因,我找不到 "struct dh_st" 的定义+成员。它应该在 openssl/dh.h 中,但事实并非如此。但是在早期版本的 openssl (openssl-1.0/openssl/dh.h) 中,有一个定义(不过我需要使用 1.1.0f)。

相关部分的代码片段:

DH *dh_obj;
// [...]
BIGNUM *temp_p = dh_obj->p; // p is not accessible/visible here!
// [...]

在 gcc 7.1.1 中编译期间的错误消息:

gcc -o dh dh.c -L/usr/lib -lssl -lcrypto && ./dh

dh.c: In function ‘main’: dh.c:57:26: error: dereferencing pointer to incomplete type ‘DH {aka struct dh_st}’ BIGNUM *temp_p = dh_obj->p;

这就是结构的样子(在 openssl-1.0 !! 不是我当前的版本,因为没有这样的定义)

struct dh_st {
/*
 * This first argument is used to pick up errors when a DH is passed
 * instead of a EVP_PKEY
 */
    int pad;
    int version;
    BIGNUM *p;
    BIGNUM *g;
    long length;                /* optional */
    BIGNUM *pub_key;            /* g^x % p */
    BIGNUM *priv_key;           /* x */
    int flags;
    BN_MONT_CTX *method_mont_p;
    /* Place holders if we want to do X9.42 DH */
    BIGNUM *q;
    BIGNUM *j;
    unsigned char *seed;
    int seedlen;
    BIGNUM *counter;
    int references;
    CRYPTO_EX_DATA ex_data;
    const DH_METHOD *meth;
    ENGINE *engine;

};

感谢任何帮助!

自从我了解不透明结构(感谢 @Some programmer dude),我发现 openssl 提供了某种 getter 和 setter 函数。 我做了一个例子来打印出一个 BIGNUM,它是 openssl 1.1.0f 中不透明结构 DH aka dh_st 的成员:

// dh_obj has been previously initialized with setter function that openssl provides 

const BIGNUM *member_p;
const BIGNUM *member_g;

DH_get0_pqg(dh_obj, &member_p, NULL, &member_g);  // getter function to get p, q, g, q is NULL in this case

// print BIIIIIG NUMBERS    
printf("len:%u\n%s\n",strlen(BN_bn2dec(member_p)),BN_bn2dec(member_p));
printf("len:%u\n%s\n",strlen(BN_bn2dec(member_g)),BN_bn2dec(member_g));

// [...]

任何值 p、q、g、priv_key 和 pub_key 也可以通过相应的函数 DH_get0_p()、DH_get0_q(), DH_get0_g(), DH_get0_priv_key(), 和 DH_get0_pub_key(), 分别

原型:

const BIGNUM *DH_get0_p(const DH *dh);


const BIGNUM *DH_get0_q(const DH *dh);


const BIGNUM *DH_get0_g(const DH *dh);

const BIGNUM *DH_get0_priv_key(const DH *dh);


const BIGNUM *DH_get0_pub_key(const DH *dh);