Ruby  1.9.3p551(2014-11-13revision48407)
ossl_pkey_dh.c
Go to the documentation of this file.
1 /*
2  * $Id: ossl_pkey_dh.c 45157 2014-02-24 03:39:54Z usa $
3  * 'OpenSSL for Ruby' project
4  * Copyright (C) 2001-2002 Michal Rokos <m.rokos@sh.cvut.cz>
5  * All rights reserved.
6  */
7 /*
8  * This program is licenced under the same licence as Ruby.
9  * (See the file 'LICENCE'.)
10  */
11 #if !defined(OPENSSL_NO_DH)
12 
13 #include "ossl.h"
14 
15 #define GetPKeyDH(obj, pkey) do { \
16  GetPKey((obj), (pkey)); \
17  if (EVP_PKEY_type((pkey)->type) != EVP_PKEY_DH) { /* PARANOIA? */ \
18  ossl_raise(rb_eRuntimeError, "THIS IS NOT A DH!") ; \
19  } \
20 } while (0)
21 
22 #define DH_HAS_PRIVATE(dh) ((dh)->priv_key)
23 
24 #ifdef OSSL_ENGINE_ENABLED
25 # define DH_PRIVATE(dh) (DH_HAS_PRIVATE(dh) || (dh)->engine)
26 #else
27 # define DH_PRIVATE(dh) DH_HAS_PRIVATE(dh)
28 #endif
29 
30 
31 /*
32  * Classes
33  */
36 
37 /*
38  * Public
39  */
40 static VALUE
42 {
43  EVP_PKEY *pkey;
44  VALUE obj;
45 
46  if (!dh) {
47  return Qfalse;
48  }
49  if (!(pkey = EVP_PKEY_new())) {
50  return Qfalse;
51  }
52  if (!EVP_PKEY_assign_DH(pkey, dh)) {
53  EVP_PKEY_free(pkey);
54  return Qfalse;
55  }
56  WrapPKey(klass, obj, pkey);
57 
58  return obj;
59 }
60 
61 VALUE
62 ossl_dh_new(EVP_PKEY *pkey)
63 {
64  VALUE obj;
65 
66  if (!pkey) {
67  obj = dh_instance(cDH, DH_new());
68  } else {
69  if (EVP_PKEY_type(pkey->type) != EVP_PKEY_DH) {
70  ossl_raise(rb_eTypeError, "Not a DH key!");
71  }
72  WrapPKey(cDH, obj, pkey);
73  }
74  if (obj == Qfalse) {
76  }
77 
78  return obj;
79 }
80 
81 /*
82  * Private
83  */
84 static DH *
85 dh_generate(int size, int gen)
86 {
87  DH *dh;
88 
89  dh = DH_generate_parameters(size, gen,
91  NULL);
92  if (!dh) return 0;
93 
94  if (!DH_generate_key(dh)) {
95  DH_free(dh);
96  return 0;
97  }
98 
99  return dh;
100 }
101 
102 /*
103  * call-seq:
104  * DH.generate(size [, generator]) -> dh
105  *
106  * Creates a new DH instance from scratch by generating the private and public
107  * components alike.
108  *
109  * === Parameters
110  * * +size+ is an integer representing the desired key size. Keys smaller than 1024 bits should be considered insecure.
111  * * +generator+ is a small number > 1, typically 2 or 5.
112  *
113  */
114 static VALUE
116 {
117  DH *dh ;
118  int g = 2;
119  VALUE size, gen, obj;
120 
121  if (rb_scan_args(argc, argv, "11", &size, &gen) == 2) {
122  g = NUM2INT(gen);
123  }
124  dh = dh_generate(NUM2INT(size), g);
125  obj = dh_instance(klass, dh);
126  if (obj == Qfalse) {
127  DH_free(dh);
129  }
130 
131  return obj;
132 }
133 
134 /*
135  * call-seq:
136  * DH.new([size [, generator] | string]) -> dh
137  *
138  * Either generates a DH instance from scratch or by reading already existing
139  * DH parameters from +string+. Note that when reading a DH instance from
140  * data that was encoded from a DH instance by using DH#to_pem or DH#to_der
141  * the result will *not* contain a public/private key pair yet. This needs to
142  * be generated using DH#generate_key! first.
143  *
144  * === Parameters
145  * * +size+ is an integer representing the desired key size. Keys smaller than 1024 bits should be considered insecure.
146  * * +generator+ is a small number > 1, typically 2 or 5.
147  * * +string+ contains the DER or PEM encoded key.
148  *
149  * === Examples
150  * DH.new # -> dh
151  * DH.new(1024) # -> dh
152  * DH.new(1024, 5) # -> dh
153  * #Reading DH parameters
154  * dh = DH.new(File.read('parameters.pem')) # -> dh, but no public/private key yet
155  * dh.generate_key! # -> dh with public and private key
156  */
157 static VALUE
159 {
160  EVP_PKEY *pkey;
161  DH *dh;
162  int g = 2;
163  BIO *in;
164  VALUE arg, gen;
165 
166  GetPKey(self, pkey);
167  if(rb_scan_args(argc, argv, "02", &arg, &gen) == 0) {
168  dh = DH_new();
169  }
170  else if (FIXNUM_P(arg)) {
171  if (!NIL_P(gen)) {
172  g = NUM2INT(gen);
173  }
174  if (!(dh = dh_generate(FIX2INT(arg), g))) {
176  }
177  }
178  else {
179  arg = ossl_to_der_if_possible(arg);
180  in = ossl_obj2bio(arg);
181  dh = PEM_read_bio_DHparams(in, NULL, NULL, NULL);
182  if (!dh){
183  OSSL_BIO_reset(in);
184  dh = d2i_DHparams_bio(in, NULL);
185  }
186  BIO_free(in);
187  if (!dh) {
189  }
190  }
191  if (!EVP_PKEY_assign_DH(pkey, dh)) {
192  DH_free(dh);
194  }
195  return self;
196 }
197 
198 /*
199  * call-seq:
200  * dh.public? -> true | false
201  *
202  * Indicates whether this DH instance has a public key associated with it or
203  * not. The public key may be retrieved with DH#pub_key.
204  */
205 static VALUE
207 {
208  EVP_PKEY *pkey;
209 
210  GetPKeyDH(self, pkey);
211 
212  return (pkey->pkey.dh->pub_key) ? Qtrue : Qfalse;
213 }
214 
215 /*
216  * call-seq:
217  * dh.private? -> true | false
218  *
219  * Indicates whether this DH instance has a private key associated with it or
220  * not. The private key may be retrieved with DH#priv_key.
221  */
222 static VALUE
224 {
225  EVP_PKEY *pkey;
226 
227  GetPKeyDH(self, pkey);
228 
229  return (DH_PRIVATE(pkey->pkey.dh)) ? Qtrue : Qfalse;
230 }
231 
232 /*
233  * call-seq:
234  * dh.to_pem -> aString
235  *
236  * Encodes this DH to its PEM encoding. Note that any existing per-session
237  * public/private keys will *not* get encoded, just the Diffie-Hellman
238  * parameters will be encoded.
239  */
240 static VALUE
242 {
243  EVP_PKEY *pkey;
244  BIO *out;
245  VALUE str;
246 
247  GetPKeyDH(self, pkey);
248  if (!(out = BIO_new(BIO_s_mem()))) {
250  }
251  if (!PEM_write_bio_DHparams(out, pkey->pkey.dh)) {
252  BIO_free(out);
254  }
255  str = ossl_membio2str(out);
256 
257  return str;
258 }
259 
260 /*
261  * call-seq:
262  * dh.to_der -> aString
263  *
264  * Encodes this DH to its DER encoding. Note that any existing per-session
265  * public/private keys will *not* get encoded, just the Diffie-Hellman
266  * parameters will be encoded.
267 
268  */
269 static VALUE
271 {
272  EVP_PKEY *pkey;
273  unsigned char *p;
274  long len;
275  VALUE str;
276 
277  GetPKeyDH(self, pkey);
278  if((len = i2d_DHparams(pkey->pkey.dh, NULL)) <= 0)
280  str = rb_str_new(0, len);
281  p = (unsigned char *)RSTRING_PTR(str);
282  if(i2d_DHparams(pkey->pkey.dh, &p) < 0)
284  ossl_str_adjust(str, p);
285 
286  return str;
287 }
288 
289 /*
290  * call-seq:
291  * dh.params -> hash
292  *
293  * Stores all parameters of key to the hash
294  * INSECURE: PRIVATE INFORMATIONS CAN LEAK OUT!!!
295  * Don't use :-)) (I's up to you)
296  */
297 static VALUE
299 {
300  EVP_PKEY *pkey;
301  VALUE hash;
302 
303  GetPKeyDH(self, pkey);
304 
305  hash = rb_hash_new();
306 
307  rb_hash_aset(hash, rb_str_new2("p"), ossl_bn_new(pkey->pkey.dh->p));
308  rb_hash_aset(hash, rb_str_new2("g"), ossl_bn_new(pkey->pkey.dh->g));
309  rb_hash_aset(hash, rb_str_new2("pub_key"), ossl_bn_new(pkey->pkey.dh->pub_key));
310  rb_hash_aset(hash, rb_str_new2("priv_key"), ossl_bn_new(pkey->pkey.dh->priv_key));
311 
312  return hash;
313 }
314 
315 /*
316  * call-seq:
317  * dh.to_text -> aString
318  *
319  * Prints all parameters of key to buffer
320  * INSECURE: PRIVATE INFORMATIONS CAN LEAK OUT!!!
321  * Don't use :-)) (I's up to you)
322  */
323 static VALUE
325 {
326  EVP_PKEY *pkey;
327  BIO *out;
328  VALUE str;
329 
330  GetPKeyDH(self, pkey);
331  if (!(out = BIO_new(BIO_s_mem()))) {
333  }
334  if (!DHparams_print(out, pkey->pkey.dh)) {
335  BIO_free(out);
337  }
338  str = ossl_membio2str(out);
339 
340  return str;
341 }
342 
343 /*
344  * call-seq:
345  * dh.public_key -> aDH
346  *
347  * Returns a new DH instance that carries just the public information, i.e.
348  * the prime +p+ and the generator +g+, but no public/private key yet. Such
349  * a pair may be generated using DH#generate_key!. The "public key" needed
350  * for a key exchange with DH#compute_key is considered as per-session
351  * information and may be retrieved with DH#pub_key once a key pair has
352  * been generated.
353  * If the current instance already contains private information (and thus a
354  * valid public/private key pair), this information will no longer be present
355  * in the new instance generated by DH#public_key. This feature is helpful for
356  * publishing the Diffie-Hellman parameters without leaking any of the private
357  * per-session information.
358  *
359  * === Example
360  * dh = OpenSSL::PKey::DH.new(2048) # has public and private key set
361  * public_key = dh.public_key # contains only prime and generator
362  * parameters = public_key.to_der # it's safe to publish this
363  */
364 static VALUE
366 {
367  EVP_PKEY *pkey;
368  DH *dh;
369  VALUE obj;
370 
371  GetPKeyDH(self, pkey);
372  dh = DHparams_dup(pkey->pkey.dh); /* err check perfomed by dh_instance */
373  obj = dh_instance(CLASS_OF(self), dh);
374  if (obj == Qfalse) {
375  DH_free(dh);
377  }
378 
379  return obj;
380 }
381 
382 /*
383  * call-seq:
384  * dh.check_params -> true | false
385  *
386  * Validates the Diffie-Hellman parameters associated with this instance.
387  * It checks whether a safe prime and a suitable generator are used. If this
388  * is not the case, +false+ is returned.
389  */
390 static VALUE
392 {
393  DH *dh;
394  EVP_PKEY *pkey;
395  int codes;
396 
397  GetPKeyDH(self, pkey);
398  dh = pkey->pkey.dh;
399 
400  if (!DH_check(dh, &codes)) {
401  return Qfalse;
402  }
403 
404  return codes == 0 ? Qtrue : Qfalse;
405 }
406 
407 /*
408  * call-seq:
409  * dh.generate_key! -> self
410  *
411  * Generates a private and public key unless a private key already exists.
412  * If this DH instance was generated from public DH parameters (e.g. by
413  * encoding the result of DH#public_key), then this method needs to be
414  * called first in order to generate the per-session keys before performing
415  * the actual key exchange.
416  *
417  * === Example
418  * dh = OpenSSL::PKey::DH.new(2048)
419  * public_key = dh.public_key #contains no private/public key yet
420  * public_key.generate_key!
421  * puts public_key.private? # => true
422  */
423 static VALUE
425 {
426  DH *dh;
427  EVP_PKEY *pkey;
428 
429  GetPKeyDH(self, pkey);
430  dh = pkey->pkey.dh;
431 
432  if (!DH_generate_key(dh))
433  ossl_raise(eDHError, "Failed to generate key");
434  return self;
435 }
436 
437 /*
438  * call-seq:
439  * dh.compute_key(pub_bn) -> aString
440  *
441  * Returns a String containing a shared secret computed from the other party's public value.
442  * See DH_compute_key() for further information.
443  *
444  * === Parameters
445  * * +pub_bn+ is a OpenSSL::BN, *not* the DH instance returned by
446  * DH#public_key as that contains the DH parameters only.
447  */
448 static VALUE
450 {
451  DH *dh;
452  EVP_PKEY *pkey;
453  BIGNUM *pub_key;
454  VALUE str;
455  int len;
456 
457  GetPKeyDH(self, pkey);
458  dh = pkey->pkey.dh;
459  pub_key = GetBNPtr(pub);
460  len = DH_size(dh);
461  str = rb_str_new(0, len);
462  if ((len = DH_compute_key((unsigned char *)RSTRING_PTR(str), pub_key, dh)) < 0) {
464  }
465  rb_str_set_len(str, len);
466 
467  return str;
468 }
469 
470 OSSL_PKEY_BN(dh, p)
471 OSSL_PKEY_BN(dh, g)
472 OSSL_PKEY_BN(dh, pub_key)
473 OSSL_PKEY_BN(dh, priv_key)
474 
475 /*
476  * -----BEGIN DH PARAMETERS-----
477  * MEYCQQD0zXHljRg/mJ9PYLACLv58Cd8VxBxxY7oEuCeURMiTqEhMym16rhhKgZG2
478  * zk2O9uUIBIxSj+NKMURHGaFKyIvLAgEC
479  * -----END DH PARAMETERS-----
480  */
481 static unsigned char DEFAULT_DH_512_PRIM[] = {
482  0xf4, 0xcd, 0x71, 0xe5, 0x8d, 0x18, 0x3f, 0x98,
483  0x9f, 0x4f, 0x60, 0xb0, 0x02, 0x2e, 0xfe, 0x7c,
484  0x09, 0xdf, 0x15, 0xc4, 0x1c, 0x71, 0x63, 0xba,
485  0x04, 0xb8, 0x27, 0x94, 0x44, 0xc8, 0x93, 0xa8,
486  0x48, 0x4c, 0xca, 0x6d, 0x7a, 0xae, 0x18, 0x4a,
487  0x81, 0x91, 0xb6, 0xce, 0x4d, 0x8e, 0xf6, 0xe5,
488  0x08, 0x04, 0x8c, 0x52, 0x8f, 0xe3, 0x4a, 0x31,
489  0x44, 0x47, 0x19, 0xa1, 0x4a, 0xc8, 0x8b, 0xcb,
490 };
491 static unsigned char DEFAULT_DH_512_GEN[] = { 0x02 };
493 
494 /*
495  * -----BEGIN DH PARAMETERS-----
496  * MIGHAoGBAJ0lOVy0VIr/JebWn0zDwY2h+rqITFOpdNr6ugsgvkDXuucdcChhYExJ
497  * AV/ZD2AWPbrTqV76mGRgJg4EddgT1zG0jq3rnFdMj2XzkBYx3BVvfR0Arnby0RHR
498  * T4h7KZ/2zmjvV+eF8kBUHBJAojUlzxKj4QeO2x20FP9X5xmNUXeDAgEC
499  * -----END DH PARAMETERS-----
500  */
501 static unsigned char DEFAULT_DH_1024_PRIM[] = {
502  0x9d, 0x25, 0x39, 0x5c, 0xb4, 0x54, 0x8a, 0xff,
503  0x25, 0xe6, 0xd6, 0x9f, 0x4c, 0xc3, 0xc1, 0x8d,
504  0xa1, 0xfa, 0xba, 0x88, 0x4c, 0x53, 0xa9, 0x74,
505  0xda, 0xfa, 0xba, 0x0b, 0x20, 0xbe, 0x40, 0xd7,
506  0xba, 0xe7, 0x1d, 0x70, 0x28, 0x61, 0x60, 0x4c,
507  0x49, 0x01, 0x5f, 0xd9, 0x0f, 0x60, 0x16, 0x3d,
508  0xba, 0xd3, 0xa9, 0x5e, 0xfa, 0x98, 0x64, 0x60,
509  0x26, 0x0e, 0x04, 0x75, 0xd8, 0x13, 0xd7, 0x31,
510  0xb4, 0x8e, 0xad, 0xeb, 0x9c, 0x57, 0x4c, 0x8f,
511  0x65, 0xf3, 0x90, 0x16, 0x31, 0xdc, 0x15, 0x6f,
512  0x7d, 0x1d, 0x00, 0xae, 0x76, 0xf2, 0xd1, 0x11,
513  0xd1, 0x4f, 0x88, 0x7b, 0x29, 0x9f, 0xf6, 0xce,
514  0x68, 0xef, 0x57, 0xe7, 0x85, 0xf2, 0x40, 0x54,
515  0x1c, 0x12, 0x40, 0xa2, 0x35, 0x25, 0xcf, 0x12,
516  0xa3, 0xe1, 0x07, 0x8e, 0xdb, 0x1d, 0xb4, 0x14,
517  0xff, 0x57, 0xe7, 0x19, 0x8d, 0x51, 0x77, 0x83
518 };
519 static unsigned char DEFAULT_DH_1024_GEN[] = { 0x02 };
521 
522 static DH*
523 ossl_create_dh(unsigned char *p, size_t plen, unsigned char *g, size_t glen)
524 {
525  DH *dh;
526 
527  if ((dh = DH_new()) == NULL) ossl_raise(eDHError, NULL);
528  dh->p = BN_bin2bn(p, rb_long2int(plen), NULL);
529  dh->g = BN_bin2bn(g, rb_long2int(glen), NULL);
530  if (dh->p == NULL || dh->g == NULL){
531  DH_free(dh);
533  }
534 
535  return dh;
536 }
537 
538 /*
539  * INIT
540  */
541 void
543 {
544 #if 0
545  mOSSL = rb_define_module("OpenSSL"); /* let rdoc know about mOSSL and mPKey */
547 #endif
548 
549  /* Document-class: OpenSSL::PKey::DHError
550  *
551  * Generic exception that is raised if an operation on a DH PKey
552  * fails unexpectedly or in case an instantiation of an instance of DH
553  * fails due to non-conformant input data.
554  */
556  /* Document-class: OpenSSL::PKey::DH
557  *
558  * An implementation of the Diffie-Hellman key exchange protocol based on
559  * discrete logarithms in finite fields, the same basis that DSA is built
560  * on.
561  *
562  * === Accessor methods for the Diffie-Hellman parameters
563  * * DH#p
564  * The prime (an OpenSSL::BN) of the Diffie-Hellman parameters.
565  * * DH#g
566  * The generator (an OpenSSL::BN) g of the Diffie-Hellman parameters.
567  * * DH#pub_key
568  * The per-session public key (an OpenSSL::BN) matching the private key.
569  * This needs to be passed to DH#compute_key.
570  * * DH#priv_key
571  * The per-session private key, an OpenSSL::BN.
572  *
573  * === Example of a key exchange
574  * dh1 = OpenSSL::PKey::DH.new(2048)
575  * der = dh1.public_key.to_der #you may send this publicly to the participating party
576  * dh2 = OpenSSL::PKey::DH.new(der)
577  * dh2.generate_key! #generate the per-session key pair
578  * symm_key1 = dh1.compute_key(dh2.pub_key)
579  * symm_key2 = dh2.compute_key(dh1.pub_key)
580  *
581  * puts symm_key1 == symm_key2 # => true
582  */
585  rb_define_method(cDH, "initialize", ossl_dh_initialize, -1);
586  rb_define_method(cDH, "public?", ossl_dh_is_public, 0);
587  rb_define_method(cDH, "private?", ossl_dh_is_private, 0);
588  rb_define_method(cDH, "to_text", ossl_dh_to_text, 0);
589  rb_define_method(cDH, "export", ossl_dh_export, 0);
590  rb_define_alias(cDH, "to_pem", "export");
591  rb_define_alias(cDH, "to_s", "export");
592  rb_define_method(cDH, "to_der", ossl_dh_to_der, 0);
593  rb_define_method(cDH, "public_key", ossl_dh_to_public_key, 0);
594  rb_define_method(cDH, "params_ok?", ossl_dh_check_params, 0);
595  rb_define_method(cDH, "generate_key!", ossl_dh_generate_key, 0);
596  rb_define_method(cDH, "compute_key", ossl_dh_compute_key, 1);
597 
598  DEF_OSSL_PKEY_BN(cDH, dh, p);
599  DEF_OSSL_PKEY_BN(cDH, dh, g);
600  DEF_OSSL_PKEY_BN(cDH, dh, pub_key);
601  DEF_OSSL_PKEY_BN(cDH, dh, priv_key);
602  rb_define_method(cDH, "params", ossl_dh_get_params, 0);
603 
610 }
611 
612 #else /* defined NO_DH */
613 void
614 Init_ossl_dh()
615 {
616 }
617 #endif /* NO_DH */
#define GetPKeyDH(obj, pkey)
Definition: ossl_pkey_dh.c:15
VALUE mOSSL
Definition: ossl.c:250
static unsigned char DEFAULT_DH_1024_PRIM[]
Definition: ossl_pkey_dh.c:501
static VALUE dh_instance(VALUE klass, DH *dh)
Definition: ossl_pkey_dh.c:41
static VALUE ossl_dh_generate_key(VALUE self)
Definition: ossl_pkey_dh.c:424
#define NUM2INT(x)
Definition: ruby.h:536
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
Definition: class.c:1343
VALUE mPKey
Definition: ossl_pkey.c:16
C_block * out
Definition: crypt.c:308
#define CLASS_OF(v)
Definition: ruby.h:376
VALUE ePKeyError
Definition: ossl_pkey.c:18
#define OSSL_PKEY_BN(keytype, name)
Definition: ossl_pkey.h:93
rb_hash_aset(CALLBACK_TABLE, id_num, cmd)
#define ossl_str_adjust(str, p)
Definition: ossl.h:132
SYMID SyckParser * p
Definition: yaml2byte.c:119
VALUE rb_eTypeError
Definition: error.c:467
unsigned long VALUE
Definition: ruby.h:88
#define rb_long2int(n)
Definition: ruby.h:308
int const char * in
Definition: crypt.c:639
#define RSTRING_PTR(string)
Definition: generator.h:42
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
Definition: class.c:515
return Qtrue
Definition: tcltklib.c:9597
#define GetPKey(obj, pkey)
Definition: ossl_pkey.h:30
#define DH_PRIVATE(dh)
Definition: ossl_pkey_dh.c:27
static VALUE ossl_dh_compute_key(VALUE self, VALUE pub)
Definition: ossl_pkey_dh.c:449
return str
Definition: ruby.c:1183
static VALUE ossl_dh_to_text(VALUE self)
Definition: ossl_pkey_dh.c:324
VALUE ossl_membio2str(BIO *bio)
Definition: ossl_bio.c:77
#define FIXNUM_P(f)
Definition: ruby.h:338
VALUE cDH
Definition: ossl_pkey_dh.c:34
static VALUE ossl_dh_check_params(VALUE self)
Definition: ossl_pkey_dh.c:391
VALUE hash
Definition: tkutil.c:267
DH * OSSL_DEFAULT_DH_512
Definition: ossl_pkey_dh.c:492
void ossl_generate_cb(int p, int n, void *arg)
Definition: ossl_pkey.c:25
n NULL
Definition: yaml2byte.c:134
VALUE ossl_to_der_if_possible(VALUE obj)
Definition: ossl.c:274
return Qfalse
Definition: tcltklib.c:6768
int rb_block_given_p(void)
Definition: eval.c:604
#define OSSL_BIO_reset(bio)
Definition: ossl.h:149
static VALUE ossl_dh_s_generate(int argc, VALUE *argv, VALUE klass)
Definition: ossl_pkey_dh.c:115
VALUE ossl_dh_new(EVP_PKEY *)
Definition: ossl_pkey_dh.c:62
#define NIL_P(v)
Definition: ruby.h:374
static VALUE ossl_dh_initialize(int argc, VALUE *argv, VALUE self)
Definition: ossl_pkey_dh.c:158
#define DEF_OSSL_PKEY_BN(class, keytype, name)
Definition: ossl_pkey.h:135
static VALUE VALUE obj
Definition: tcltklib.c:3147
static VALUE ossl_dh_to_public_key(VALUE self)
Definition: ossl_pkey_dh.c:365
VALUE eDHError
Definition: ossl_pkey_dh.c:35
static unsigned char DEFAULT_DH_1024_GEN[]
Definition: ossl_pkey_dh.c:519
VALUE * argv
Definition: tcltklib.c:1962
void rb_define_alias(VALUE klass, const char *name1, const char *name2)
Defines an alias of a method.
Definition: class.c:1385
static unsigned char DEFAULT_DH_512_GEN[]
Definition: ossl_pkey_dh.c:491
#define WrapPKey(klass, obj, pkey)
Definition: ossl_pkey.h:23
BIO * ossl_obj2bio(VALUE obj)
Definition: ossl_bio.c:17
VALUE rb_hash_new(void)
Definition: hash.c:229
static VALUE ossl_dh_to_der(VALUE self)
Definition: ossl_pkey_dh.c:270
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
Definition: class.c:1416
static DH * ossl_create_dh(unsigned char *p, size_t plen, unsigned char *g, size_t glen)
Definition: ossl_pkey_dh.c:523
int argc
Definition: tcltklib.c:1961
static unsigned char DEFAULT_DH_512_PRIM[]
Definition: ossl_pkey_dh.c:481
#define FIX2INT(x)
Definition: ruby.h:538
register unsigned int len
Definition: name2ctype.h:22210
static VALUE ossl_dh_is_public(VALUE self)
Definition: ossl_pkey_dh.c:206
static VALUE ossl_dh_export(VALUE self)
Definition: ossl_pkey_dh.c:241
VALUE rb_define_module_under(VALUE outer, const char *name)
Definition: class.c:607
arg
Definition: ripper.y:1287
int size
Definition: encoding.c:51
static DH * dh_generate(int size, int gen)
Definition: ossl_pkey_dh.c:85
#define rb_str_set_len(str, length)
Definition: ruby_missing.h:30
klass
Definition: tcltklib.c:3493
void ossl_raise(VALUE exc, const char *fmt,...)
Definition: ossl.c:324
void Init_ossl_dh(void)
Definition: ossl_pkey_dh.c:542
VALUE ossl_bn_new(const BIGNUM *bn)
Definition: ossl_bn.c:43
BIGNUM * GetBNPtr(VALUE obj)
Definition: ossl_bn.c:58
VALUE rb_define_module(const char *name)
Definition: class.c:587
VALUE cPKey
Definition: ossl_pkey.c:17
DH * OSSL_DEFAULT_DH_1024
Definition: ossl_pkey_dh.c:520
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Definition: class.c:1210
static VALUE ossl_dh_is_private(VALUE self)
Definition: ossl_pkey_dh.c:223
VALUE rb_str_new2(const char *)
static VALUE ossl_dh_get_params(VALUE self)
Definition: ossl_pkey_dh.c:298
VALUE rb_str_new(const char *, long)
Definition: string.c:410