OpenSSL used fixed Values for Diffie Hellman Key generation

大城市里の小女人 提交于 2019-12-06 05:11:05

The (outer) primes for the RFC3526 and RFC2409 groups are builtin, per this man page (should also be on your system under those names if 1.1.0+) -- they are actually in the code back to before 1.0.0 but without the BN_ prefix (though in the bn.h header) and previously undocumented. (In 1.1.0+ the old names are additionally #define'd if compatibility is set.)

AFAICS you must add the generator yourself, something like:

DH *dh = DH_new(); BIGNUM *two = BN_new(); 
if( !dh || !two ) /* error */;
BN_set_word(two,2); 

// corrected AGAIN!
DH_set0_pqg (dh, BN_dup(BN_get_rfc3526_prime_2048(NULL)), NULL, two);

// added: below 1.1.0 many API structs were not opaque, just
dh->p = BN_dup(/*not BN_*/ get_rfc3526_prime_2048(NULL));
dh->g = two; 
// leave q as unspecified

Note RFC5114 modp parameters are available prebuilt in DH* form but only in 1.1.0+.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!