Method: OpenSSL::PKey::DH#compute_key

Defined in:
ossl_pkey_dh.c

#compute_key(pub_bn) ⇒ aString

Parameters

  • pub_bn is a OpenSSL::BN.

Returns aString containing a shared secret computed from the other parties public value.

See DH_compute_key() for further information.

Returns:

  • (aString)


396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
# File 'ossl_pkey_dh.c', line 396

static VALUE
ossl_dh_compute_key(VALUE self, VALUE pub)
{
    DH *dh;
    EVP_PKEY *pkey;
    BIGNUM *pub_key;
    VALUE str;
    int len;

    GetPKeyDH(self, pkey);
    dh = pkey->pkey.dh;
    pub_key = GetBNPtr(pub);
    len = DH_size(dh);
    str = rb_str_new(0, len);
    if ((len = DH_compute_key(RSTRING_PTR(str), pub_key, dh)) < 0) {
	ossl_raise(eDHError, NULL);
    }
    rb_str_set_len(str, len);

    return str;
}