End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
OpenSSL::PKey::DH#compute_key
dh.compute_key(pub_bn) → aString
ext/openssl/ossl_pkey_dh.c
View on GitHub ↗
static VALUE
ossl_dh_compute_key(VALUE self, VALUE pub)
{
DH *dh;
const BIGNUM *pub_key, *dh_p;
VALUE str;
int len;
GetDH(self, dh);
DH_get0_pqg(dh, &dh_p, NULL, NULL);
if (!dh_p)
ossl_raise(eDHError, "incomplete DH");
pub_key = GetBNPtr(pub);
len = DH_size(dh);
str = rb_str_new(0, len);
if ((len = DH_compute_key((unsigned char *)RSTRING_PTR(str), pub_key, dh)) < 0) {
ossl_raise(eDHError, NULL);
}
rb_str_set_len(str, len);
return str;
}
Returns a String containing a shared secret computed from the other party’s public value. See DH_compute_key() for further information.
Parameters
-
pub_bn is a
OpenSSL::BN, not theDHinstance returned byDH#public_keyas that contains theDHparameters only.