11 #if !defined(OPENSSL_NO_DH) 15 #define GetPKeyDH(obj, pkey) do { \ 16 GetPKey((obj), (pkey)); \ 17 if (EVP_PKEY_type((pkey)->type) != EVP_PKEY_DH) { \ 18 ossl_raise(rb_eRuntimeError, "THIS IS NOT A DH!") ; \ 22 #define DH_HAS_PRIVATE(dh) ((dh)->priv_key) 24 #ifdef OSSL_ENGINE_ENABLED 25 # define DH_PRIVATE(dh) (DH_HAS_PRIVATE(dh) || (dh)->engine) 27 # define DH_PRIVATE(dh) DH_HAS_PRIVATE(dh) 49 if (!(pkey = EVP_PKEY_new())) {
52 if (!EVP_PKEY_assign_DH(pkey, dh)) {
69 if (EVP_PKEY_type(pkey->type) != EVP_PKEY_DH) {
84 #if defined(HAVE_DH_GENERATE_PARAMETERS_EX) && HAVE_BN_GENCB 85 struct dh_blocking_gen_arg {
94 dh_blocking_gen(
void *arg)
96 struct dh_blocking_gen_arg *gen = (
struct dh_blocking_gen_arg *)arg;
97 gen->result = DH_generate_parameters_ex(gen->dh, gen->size, gen->gen, gen->cb);
105 #if defined(HAVE_DH_GENERATE_PARAMETERS_EX) && HAVE_BN_GENCB 107 struct ossl_generate_cb_arg cb_arg;
108 struct dh_blocking_gen_arg gen_arg;
113 memset(&cb_arg, 0,
sizeof(
struct ossl_generate_cb_arg));
116 BN_GENCB_set(&cb, ossl_generate_cb_2, &cb_arg);
121 if (cb_arg.yield == 1) {
123 dh_blocking_gen(&gen_arg);
129 if (!gen_arg.result) {
141 if (!DH_generate_key(dh)) {
231 dh = d2i_DHparams_bio(in,
NULL);
238 if (!EVP_PKEY_assign_DH(pkey, dh)) {
297 if (!(out = BIO_new(BIO_s_mem()))) {
300 if (!PEM_write_bio_DHparams(out, pkey->pkey.dh)) {
327 if((len = i2d_DHparams(pkey->pkey.dh,
NULL)) <= 0)
331 if(i2d_DHparams(pkey->pkey.dh, &p) < 0)
380 if (!(out = BIO_new(BIO_s_mem()))) {
383 if (!DHparams_print(out, pkey->pkey.dh)) {
421 dh = DHparams_dup(pkey->pkey.dh);
449 if (!DH_check(dh, &codes)) {
481 if (!DH_generate_key(dh))
511 if ((len = DH_compute_key((
unsigned char *)
RSTRING_PTR(str), pub_key, dh)) < 0) {
531 0xf4, 0xcd, 0x71, 0xe5, 0x8d, 0x18, 0x3f, 0x98,
532 0x9f, 0x4f, 0x60, 0xb0, 0x02, 0x2e, 0xfe, 0x7c,
533 0x09, 0xdf, 0x15, 0xc4, 0x1c, 0x71, 0x63, 0xba,
534 0x04, 0xb8, 0x27, 0x94, 0x44, 0xc8, 0x93, 0xa8,
535 0x48, 0x4c, 0xca, 0x6d, 0x7a, 0xae, 0x18, 0x4a,
536 0x81, 0x91, 0xb6, 0xce, 0x4d, 0x8e, 0xf6, 0xe5,
537 0x08, 0x04, 0x8c, 0x52, 0x8f, 0xe3, 0x4a, 0x31,
538 0x44, 0x47, 0x19, 0xa1, 0x4a, 0xc8, 0x8b, 0xcb,
551 0x9d, 0x25, 0x39, 0x5c, 0xb4, 0x54, 0x8a, 0xff,
552 0x25, 0xe6, 0xd6, 0x9f, 0x4c, 0xc3, 0xc1, 0x8d,
553 0xa1, 0xfa, 0xba, 0x88, 0x4c, 0x53, 0xa9, 0x74,
554 0xda, 0xfa, 0xba, 0x0b, 0x20, 0xbe, 0x40, 0xd7,
555 0xba, 0xe7, 0x1d, 0x70, 0x28, 0x61, 0x60, 0x4c,
556 0x49, 0x01, 0x5f, 0xd9, 0x0f, 0x60, 0x16, 0x3d,
557 0xba, 0xd3, 0xa9, 0x5e, 0xfa, 0x98, 0x64, 0x60,
558 0x26, 0x0e, 0x04, 0x75, 0xd8, 0x13, 0xd7, 0x31,
559 0xb4, 0x8e, 0xad, 0xeb, 0x9c, 0x57, 0x4c, 0x8f,
560 0x65, 0xf3, 0x90, 0x16, 0x31, 0xdc, 0x15, 0x6f,
561 0x7d, 0x1d, 0x00, 0xae, 0x76, 0xf2, 0xd1, 0x11,
562 0xd1, 0x4f, 0x88, 0x7b, 0x29, 0x9f, 0xf6, 0xce,
563 0x68, 0xef, 0x57, 0xe7, 0x85, 0xf2, 0x40, 0x54,
564 0x1c, 0x12, 0x40, 0xa2, 0x35, 0x25, 0xcf, 0x12,
565 0xa3, 0xe1, 0x07, 0x8e, 0xdb, 0x1d, 0xb4, 0x14,
566 0xff, 0x57, 0xe7, 0x19, 0x8d, 0x51, 0x77, 0x83
579 if (dh->p ==
NULL || dh->g ==
NULL){
#define GetPKeyDH(obj, pkey)
static unsigned char DEFAULT_DH_1024_PRIM[]
static VALUE dh_instance(VALUE klass, DH *dh)
static VALUE ossl_dh_generate_key(VALUE self)
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
#define OSSL_PKEY_BN(keytype, name)
#define ossl_str_adjust(str, p)
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)
static VALUE ossl_dh_compute_key(VALUE self, VALUE pub)
static VALUE ossl_dh_to_text(VALUE self)
DH * OSSL_DEFAULT_DH_1024
VALUE ossl_membio2str(BIO *bio)
VALUE ossl_dh_new(EVP_PKEY *pkey)
static VALUE ossl_dh_check_params(VALUE self)
void ossl_generate_cb(int p, int n, void *arg)
VALUE ossl_to_der_if_possible(VALUE obj)
int rb_block_given_p(void)
VALUE rb_hash_aset(VALUE hash, VALUE key, VALUE val)
#define OSSL_BIO_reset(bio)
static VALUE ossl_dh_s_generate(int argc, VALUE *argv, VALUE klass)
static VALUE ossl_dh_initialize(int argc, VALUE *argv, VALUE self)
#define DEF_OSSL_PKEY_BN(class, keytype, name)
static VALUE ossl_dh_to_public_key(VALUE self)
void * rb_thread_call_without_gvl(void *(*func)(void *), void *data1, rb_unblock_function_t *ubf, void *data2)
static unsigned char DEFAULT_DH_1024_GEN[]
void rb_define_alias(VALUE klass, const char *name1, const char *name2)
Defines an alias of a method.
static unsigned char DEFAULT_DH_512_GEN[]
#define WrapPKey(klass, obj, pkey)
BIO * ossl_obj2bio(VALUE obj)
static VALUE ossl_dh_to_der(VALUE self)
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
static DH * ossl_create_dh(unsigned char *p, size_t plen, unsigned char *g, size_t glen)
static unsigned char DEFAULT_DH_512_PRIM[]
static VALUE ossl_dh_is_public(VALUE self)
void rb_jump_tag(int tag)
static VALUE ossl_dh_export(VALUE self)
VALUE rb_define_module_under(VALUE outer, const char *name)
static DH * dh_generate(int size, int gen)
void ossl_raise(VALUE exc, const char *fmt,...)
static unsigned int hash(const char *str, unsigned int len)
VALUE ossl_bn_new(const BIGNUM *bn)
BIGNUM * GetBNPtr(VALUE obj)
VALUE rb_define_module(const char *name)
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
static VALUE ossl_dh_is_private(VALUE self)
static VALUE ossl_dh_get_params(VALUE self)
VALUE rb_str_new(const char *, long)