use*_*811 5 c struct openssl header-files
出于某种原因,我找不到“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!
// [...]
Run Code Online (Sandbox Code Playgroud)
在 gcc 7.1.1 中编译期间的错误消息:
gcc -o dh dh.c -L/usr/lib -lssl -lcrypto && ./dh
dh.c:在函数“main”中:dh.c:57:26:错误:解引用指向不完整类型“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;
Run Code Online (Sandbox Code Playgroud)
};
任何帮助表示赞赏!
因此,由于我了解不透明结构(感谢@Some程序员花花公子),我发现 openssl 提供了某种 getter 和 setter 函数。我做了一个例子来打印一个 BIGNUM,它是 openssl 1.1.0f 中不透明结构 DH 又名 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));
// [...]
Run Code Online (Sandbox Code Playgroud)