For some reason I can't find the definition+members of "struct dh_st". It is supposed to be in openssl/dh.h, but that is not the case. However in a earlier version of openssl (openssl-1.0/openssl/dh.h), there is an definition (I need to use 1.1.0f though).
Code-Snippet of the relevant part:
DH *dh_obj;
// [...]
BIGNUM *temp_p = dh_obj->p; // p is not accessible/visible here!
// [...]
Error message during compilation in 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;
And this is how the struct looks like (in openssl-1.0 !! not in my current version, because there is no such definition)
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;
};
Any Help appreciated!
Any of the values p, q, g, priv_key, and pub_key can also be retrieved separately from DH* structure by the corresponding function DH_get0_p(), DH_get0_q(), DH_get0_g(), DH_get0_priv_key(), and DH_get0_pub_key(), respectively
Prototype:
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);
So since I know about opaque structures (thanks to @Some programmer dude), I found out that openssl provides somekind of getter and setter functions. I made an example to print out a BIGNUM which is a member of the opaque structre DH aka dh_st in openssl 1.1.0f:
// 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));
// [...]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With