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); \ 36 dh_instance(
VALUE klass, DH *dh)
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) {
90 dh_blocking_gen(
void *arg)
118 if (cb_arg.
yield == 1) {
120 dh_blocking_gen(&gen_arg);
137 if (!DH_generate_key(dh)) {
167 dh = dh_generate(
NUM2INT(size), g);
168 obj = dh_instance(klass, dh);
219 if (!(dh = dh_generate(
NUM2INT(arg), g))) {
229 dh = d2i_DHparams_bio(in,
NULL);
236 if (!EVP_PKEY_assign_DH(pkey, dh)) {
244 ossl_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);
284 ossl_dh_is_public(
VALUE self)
290 DH_get0_key(dh, &bn,
NULL);
303 ossl_dh_is_private(
VALUE self)
309 DH_get0_key(dh,
NULL, &bn);
311 #if !defined(OPENSSL_NO_ENGINE) 312 return (bn || DH_get0_engine(dh)) ?
Qtrue :
Qfalse;
329 ossl_dh_export(
VALUE self)
336 if (!(out = BIO_new(BIO_s_mem()))) {
339 if (!PEM_write_bio_DHparams(out, dh)) {
358 ossl_dh_to_der(
VALUE self)
366 if((len = i2d_DHparams(dh,
NULL)) <= 0)
370 if(i2d_DHparams(dh, &p) < 0)
386 ossl_dh_get_params(
VALUE self)
393 DH_get0_pqg(dh, &p, &q, &g);
394 DH_get0_key(dh, &pub_key, &priv_key);
415 ossl_dh_to_text(
VALUE self)
422 if (!(out = BIO_new(BIO_s_mem()))) {
425 if (!DHparams_print(out, dh)) {
456 ossl_dh_to_public_key(
VALUE self)
461 GetDH(
self, orig_dh);
462 dh = DHparams_dup(orig_dh);
481 ossl_dh_check_params(
VALUE self)
487 if (!DH_check(dh, &codes)) {
511 ossl_dh_generate_key(
VALUE self)
516 if (!DH_generate_key(dh))
547 if ((len = DH_compute_key((
unsigned char *)
RSTRING_PTR(str), pub_key, dh)) < 0) {
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
int rb_block_given_p(void)
Determines if the current method is given a block.
void rb_jump_tag(int tag)
Continues the exception caught by rb_protect() and rb_eval_string_protect().
#define SetPKey(obj, pkey)
#define ossl_str_adjust(str, p)
BIO * ossl_obj2bio(volatile VALUE *pobj)
void rb_str_set_len(VALUE, long)
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
#define GetPKey(obj, pkey)
VALUE ossl_membio2str(BIO *bio)
VALUE ossl_dh_new(EVP_PKEY *pkey)
#define OSSL_PKEY_BN_DEF2(_keytype, _type, _group, a1, a2)
VALUE rb_obj_class(VALUE)
call-seq: obj.class -> class
VALUE ossl_to_der_if_possible(VALUE obj)
void ossl_generate_cb_stop(void *ptr)
void ossl_clear_error(void)
VALUE rb_hash_aset(VALUE hash, VALUE key, VALUE val)
RUBY_EXTERN VALUE rb_cObject
#define OSSL_BIO_reset(bio)
#define DEF_OSSL_PKEY_BN(class, keytype, name)
void * rb_thread_call_without_gvl(void *(*func)(void *), void *data1, rb_unblock_function_t *ubf, void *data2)
void rb_define_alias(VALUE klass, const char *name1, const char *name2)
Defines an alias of a method.
int ossl_generate_cb_2(int p, int n, BN_GENCB *cb)
#define OSSL_PKEY_BN_DEF3(_keytype, _type, _group, a1, a2, a3)
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
register unsigned int len
VALUE rb_define_module_under(VALUE outer, const char *name)
void ossl_raise(VALUE exc, const char *fmt,...)
#define BN_GENCB_free(cb)
VALUE ossl_bn_new(const BIGNUM *bn)
#define RB_INTEGER_TYPE_P(obj)
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
VALUE rb_str_new(const char *, long)