Method: OpenSSL::PKey::DH#compute_key
- Defined in:
- ossl_pkey_dh.c
#compute_key(pub_bn) ⇒ aString
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 the DH instance returned by
DH#public_key as that contains the DH parameters only.
532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 |
# File 'ossl_pkey_dh.c', line 532
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;
}
|