12#if !defined(OPENSSL_NO_DH)
14#define GetPKeyDH(obj, pkey) do { \
15 GetPKey((obj), (pkey)); \
16 if (EVP_PKEY_base_id(pkey) != EVP_PKEY_DH) { \
17 ossl_raise(rb_eRuntimeError, "THIS IS NOT A DH!") ; \
20#define GetDH(obj, dh) do { \
22 GetPKeyDH((obj), _pkey); \
23 (dh) = EVP_PKEY_get0_DH(_pkey); \
45 if (!(pkey = EVP_PKEY_new())) {
48 if (!EVP_PKEY_assign_DH(pkey, dh)) {
63 obj = dh_instance(
cDH, DH_new());
66 if (EVP_PKEY_base_id(pkey) != EVP_PKEY_DH) {
90dh_blocking_gen(
void *
arg)
93 gen->result = DH_generate_parameters_ex(
gen->dh,
gen->size,
gen->gen,
gen->cb);
118 if (cb_arg.
yield == 1) {
120 dh_blocking_gen(&gen_arg);
127 if (!gen_arg.result) {
137 if (!DH_generate_key(
dh)) {
229 dh = d2i_DHparams_bio(in,
NULL);
236 if (!EVP_PKEY_assign_DH(pkey,
dh)) {
244ossl_dh_initialize_copy(
VALUE self,
VALUE other)
248 const BIGNUM *pub, *priv;
251 if (EVP_PKEY_base_id(pkey) != EVP_PKEY_NONE)
253 GetDH(other, dh_other);
255 dh = DHparams_dup(dh_other);
258 EVP_PKEY_assign_DH(pkey,
dh);
260 DH_get0_key(dh_other, &pub, &priv);
262 BIGNUM *pub2 = BN_dup(pub);
263 BIGNUM *priv2 = BN_dup(priv);
265 if (!pub2 || (priv && !priv2)) {
267 BN_clear_free(priv2);
270 DH_set0_key(
dh, pub2, priv2);
284ossl_dh_is_public(
VALUE self)
290 DH_get0_key(
dh, &bn,
NULL);
303ossl_dh_is_private(
VALUE self)
309 DH_get0_key(
dh,
NULL, &bn);
311#if !defined(OPENSSL_NO_ENGINE)
329ossl_dh_export(
VALUE self)
336 if (!(out = BIO_new(BIO_s_mem()))) {
339 if (!PEM_write_bio_DHparams(out,
dh)) {
358ossl_dh_to_der(
VALUE self)
370 if(i2d_DHparams(
dh, &p) < 0)
386ossl_dh_get_params(
VALUE self)
393 DH_get0_pqg(
dh, &p, &q, &g);
415ossl_dh_to_text(
VALUE self)
422 if (!(out = BIO_new(BIO_s_mem()))) {
425 if (!DHparams_print(out,
dh)) {
456ossl_dh_to_public_key(
VALUE self)
461 GetDH(
self, orig_dh);
462 dh = DHparams_dup(orig_dh);
481ossl_dh_check_params(
VALUE self)
487 if (!DH_check(
dh, &codes)) {
511ossl_dh_generate_key(
VALUE self)
516 if (!DH_generate_key(
dh))
char str[HTML_ESCAPE_MAX_LEN+1]
VALUE rb_define_class_under(VALUE, const char *, VALUE)
Defines a class under the namespace of outer.
VALUE rb_define_module_under(VALUE, const char *)
void rb_define_alias(VALUE, const char *, const char *)
Defines an alias of a method.
int rb_block_given_p(void)
Determines if the current method is given a block.
VALUE rb_cObject
Object class.
void rb_jump_tag(int tag)
Continues the exception caught by rb_protect() and rb_eval_string_protect().
VALUE rb_obj_class(VALUE)
Equivalent to Object#class in Ruby.
#define BN_GENCB_free(cb)
VALUE ossl_to_der_if_possible(VALUE obj)
void ossl_raise(VALUE exc, const char *fmt,...)
void ossl_clear_error(void)
#define ossl_str_adjust(str, p)
#define OSSL_BIO_reset(bio)
BIO * ossl_obj2bio(volatile VALUE *pobj)
VALUE ossl_membio2str(BIO *bio)
VALUE ossl_bn_new(const BIGNUM *bn)
int ossl_generate_cb_2(int p, int n, BN_GENCB *cb)
void ossl_generate_cb_stop(void *ptr)
#define OSSL_PKEY_BN_DEF3(_keytype, _type, _group, a1, a2, a3)
#define OSSL_PKEY_BN_DEF2(_keytype, _type, _group, a1, a2)
#define GetPKey(obj, pkey)
#define SetPKey(obj, pkey)
#define DEF_OSSL_PKEY_BN(class, keytype, name)
VALUE ossl_dh_new(EVP_PKEY *pkey)
void * rb_thread_call_without_gvl(void *(*func)(void *), void *data1, rb_unblock_function_t *ubf, void *data2)