Ruby  2.1.10p492(2016-04-01revision54464)
ossl_pkey_rsa.c
Go to the documentation of this file.
1 /*
2  * $Id: ossl_pkey_rsa.c 40316 2013-04-16 02:24:09Z zzak $
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_RSA)
12 
13 #include "ossl.h"
14 
15 #define GetPKeyRSA(obj, pkey) do { \
16  GetPKey((obj), (pkey)); \
17  if (EVP_PKEY_type((pkey)->type) != EVP_PKEY_RSA) { /* PARANOIA? */ \
18  ossl_raise(rb_eRuntimeError, "THIS IS NOT A RSA!") ; \
19  } \
20 } while (0)
21 
22 #define RSA_HAS_PRIVATE(rsa) ((rsa)->p && (rsa)->q)
23 #define RSA_PRIVATE(obj,rsa) (RSA_HAS_PRIVATE(rsa)||OSSL_PKEY_IS_PRIVATE(obj))
24 
25 /*
26  * Classes
27  */
30 
31 /*
32  * Public
33  */
34 static VALUE
36 {
37  EVP_PKEY *pkey;
38  VALUE obj;
39 
40  if (!rsa) {
41  return Qfalse;
42  }
43  if (!(pkey = EVP_PKEY_new())) {
44  return Qfalse;
45  }
46  if (!EVP_PKEY_assign_RSA(pkey, rsa)) {
47  EVP_PKEY_free(pkey);
48  return Qfalse;
49  }
50  WrapPKey(klass, obj, pkey);
51 
52  return obj;
53 }
54 
55 VALUE
56 ossl_rsa_new(EVP_PKEY *pkey)
57 {
58  VALUE obj;
59 
60  if (!pkey) {
61  obj = rsa_instance(cRSA, RSA_new());
62  }
63  else {
64  if (EVP_PKEY_type(pkey->type) != EVP_PKEY_RSA) {
65  ossl_raise(rb_eTypeError, "Not a RSA key!");
66  }
67  WrapPKey(cRSA, obj, pkey);
68  }
69  if (obj == Qfalse) {
71  }
72 
73  return obj;
74 }
75 
76 /*
77  * Private
78  */
79 #if defined(HAVE_RSA_GENERATE_KEY_EX) && HAVE_BN_GENCB
80 struct rsa_blocking_gen_arg {
81  RSA *rsa;
82  BIGNUM *e;
83  int size;
84  BN_GENCB *cb;
85  int result;
86 };
87 
88 static void *
89 rsa_blocking_gen(void *arg)
90 {
91  struct rsa_blocking_gen_arg *gen = (struct rsa_blocking_gen_arg *)arg;
92  gen->result = RSA_generate_key_ex(gen->rsa, gen->size, gen->e, gen->cb);
93  return 0;
94 }
95 #endif
96 
97 static RSA *
98 rsa_generate(int size, unsigned long exp)
99 {
100 #if defined(HAVE_RSA_GENERATE_KEY_EX) && HAVE_BN_GENCB
101  int i;
102  BN_GENCB cb;
103  struct ossl_generate_cb_arg cb_arg;
104  struct rsa_blocking_gen_arg gen_arg;
105  RSA *rsa = RSA_new();
106  BIGNUM *e = BN_new();
107 
108  if (!rsa || !e) {
109  if (e) BN_free(e);
110  if (rsa) RSA_free(rsa);
111  return 0;
112  }
113  for (i = 0; i < (int)sizeof(exp) * 8; ++i) {
114  if (exp & (1UL << i)) {
115  if (BN_set_bit(e, i) == 0) {
116  BN_free(e);
117  RSA_free(rsa);
118  return 0;
119  }
120  }
121  }
122 
123  memset(&cb_arg, 0, sizeof(struct ossl_generate_cb_arg));
124  if (rb_block_given_p())
125  cb_arg.yield = 1;
126  BN_GENCB_set(&cb, ossl_generate_cb_2, &cb_arg);
127  gen_arg.rsa = rsa;
128  gen_arg.e = e;
129  gen_arg.size = size;
130  gen_arg.cb = &cb;
131  if (cb_arg.yield == 1) {
132  /* we cannot release GVL when callback proc is supplied */
133  rsa_blocking_gen(&gen_arg);
134  } else {
135  /* there's a chance to unblock */
136  rb_thread_call_without_gvl(rsa_blocking_gen, &gen_arg, ossl_generate_cb_stop, &cb_arg);
137  }
138  if (!gen_arg.result) {
139  BN_free(e);
140  RSA_free(rsa);
141  if (cb_arg.state) rb_jump_tag(cb_arg.state);
142  return 0;
143  }
144 
145  BN_free(e);
146  return rsa;
147 #else
148  return RSA_generate_key(size, exp, rb_block_given_p() ? ossl_generate_cb : NULL, NULL);
149 #endif
150 }
151 
152 /*
153  * call-seq:
154  * RSA.generate(size) => RSA instance
155  * RSA.generate(size, exponent) => RSA instance
156  *
157  * Generates an RSA keypair. +size+ is an integer representing the desired key
158  * size. Keys smaller than 1024 should be considered insecure. +exponent+ is
159  * an odd number normally 3, 17, or 65537.
160  */
161 static VALUE
163 {
164 /* why does this method exist? why can't initialize take an optional exponent? */
165  RSA *rsa;
166  VALUE size, exp;
167  VALUE obj;
168 
169  rb_scan_args(argc, argv, "11", &size, &exp);
170 
171  rsa = rsa_generate(NUM2INT(size), NIL_P(exp) ? RSA_F4 : NUM2ULONG(exp)); /* err handled by rsa_instance */
172  obj = rsa_instance(klass, rsa);
173 
174  if (obj == Qfalse) {
175  RSA_free(rsa);
177  }
178 
179  return obj;
180 }
181 
182 /*
183  * call-seq:
184  * RSA.new(key_size) => RSA instance
185  * RSA.new(encoded_key) => RSA instance
186  * RSA.new(encoded_key, pass_phrase) => RSA instance
187  *
188  * Generates or loads an RSA keypair. If an integer +key_size+ is given it
189  * represents the desired key size. Keys less than 1024 bits should be
190  * considered insecure.
191  *
192  * A key can instead be loaded from an +encoded_key+ which must be PEM or DER
193  * encoded. A +pass_phrase+ can be used to decrypt the key. If none is given
194  * OpenSSL will prompt for the pass phrase.
195  *
196  * = Examples
197  *
198  * OpenSSL::PKey::RSA.new 2048
199  * OpenSSL::PKey::RSA.new File.read 'rsa.pem'
200  * OpenSSL::PKey::RSA.new File.read('rsa.pem'), 'my pass phrase'
201  */
202 static VALUE
204 {
205  EVP_PKEY *pkey;
206  RSA *rsa;
207  BIO *in;
208  char *passwd = NULL;
209  VALUE arg, pass;
210 
211  GetPKey(self, pkey);
212  if(rb_scan_args(argc, argv, "02", &arg, &pass) == 0) {
213  rsa = RSA_new();
214  }
215  else if (FIXNUM_P(arg)) {
216  rsa = rsa_generate(FIX2INT(arg), NIL_P(pass) ? RSA_F4 : NUM2ULONG(pass));
217  if (!rsa) ossl_raise(eRSAError, NULL);
218  }
219  else {
220  if (!NIL_P(pass)) passwd = StringValuePtr(pass);
221  arg = ossl_to_der_if_possible(arg);
222  in = ossl_obj2bio(arg);
223  rsa = PEM_read_bio_RSAPrivateKey(in, NULL, ossl_pem_passwd_cb, passwd);
224  if (!rsa) {
225  OSSL_BIO_reset(in);
226  rsa = PEM_read_bio_RSA_PUBKEY(in, NULL, NULL, NULL);
227  }
228  if (!rsa) {
229  OSSL_BIO_reset(in);
230  rsa = d2i_RSAPrivateKey_bio(in, NULL);
231  }
232  if (!rsa) {
233  OSSL_BIO_reset(in);
234  rsa = d2i_RSA_PUBKEY_bio(in, NULL);
235  }
236  if (!rsa) {
237  OSSL_BIO_reset(in);
238  rsa = PEM_read_bio_RSAPublicKey(in, NULL, NULL, NULL);
239  }
240  if (!rsa) {
241  OSSL_BIO_reset(in);
242  rsa = d2i_RSAPublicKey_bio(in, NULL);
243  }
244  BIO_free(in);
245  if (!rsa) {
246  ossl_raise(eRSAError, "Neither PUB key nor PRIV key");
247  }
248  }
249  if (!EVP_PKEY_assign_RSA(pkey, rsa)) {
250  RSA_free(rsa);
252  }
253 
254  return self;
255 }
256 
257 /*
258  * call-seq:
259  * rsa.public? => true
260  *
261  * The return value is always true since every private key is also a public
262  * key.
263  */
264 static VALUE
266 {
267  EVP_PKEY *pkey;
268 
269  GetPKeyRSA(self, pkey);
270  /*
271  * This method should check for n and e. BUG.
272  */
273  return Qtrue;
274 }
275 
276 /*
277  * call-seq:
278  * rsa.private? => true | false
279  *
280  * Does this keypair contain a private key?
281  */
282 static VALUE
284 {
285  EVP_PKEY *pkey;
286 
287  GetPKeyRSA(self, pkey);
288 
289  return (RSA_PRIVATE(self, pkey->pkey.rsa)) ? Qtrue : Qfalse;
290 }
291 
292 /*
293  * call-seq:
294  * rsa.export([cipher, pass_phrase]) => PEM-format String
295  * rsa.to_pem([cipher, pass_phrase]) => PEM-format String
296  * rsa.to_s([cipher, pass_phrase]) => PEM-format String
297  *
298  * Outputs this keypair in PEM encoding. If +cipher+ and +pass_phrase+ are
299  * given they will be used to encrypt the key. +cipher+ must be an
300  * OpenSSL::Cipher::Cipher instance.
301  */
302 static VALUE
304 {
305  EVP_PKEY *pkey;
306  BIO *out;
307  const EVP_CIPHER *ciph = NULL;
308  char *passwd = NULL;
309  VALUE cipher, pass, str;
310 
311  GetPKeyRSA(self, pkey);
312 
313  rb_scan_args(argc, argv, "02", &cipher, &pass);
314 
315  if (!NIL_P(cipher)) {
316  ciph = GetCipherPtr(cipher);
317  if (!NIL_P(pass)) {
318  StringValue(pass);
319  if (RSTRING_LENINT(pass) < OSSL_MIN_PWD_LEN)
320  ossl_raise(eOSSLError, "OpenSSL requires passwords to be at least four characters long");
321  passwd = RSTRING_PTR(pass);
322  }
323  }
324  if (!(out = BIO_new(BIO_s_mem()))) {
326  }
327  if (RSA_HAS_PRIVATE(pkey->pkey.rsa)) {
328  if (!PEM_write_bio_RSAPrivateKey(out, pkey->pkey.rsa, ciph,
329  NULL, 0, ossl_pem_passwd_cb, passwd)) {
330  BIO_free(out);
332  }
333  } else {
334  if (!PEM_write_bio_RSA_PUBKEY(out, pkey->pkey.rsa)) {
335  BIO_free(out);
337  }
338  }
339  str = ossl_membio2str(out);
340 
341  return str;
342 }
343 
344 /*
345  * call-seq:
346  * rsa.to_der => DER-format String
347  *
348  * Outputs this keypair in DER encoding.
349  */
350 static VALUE
352 {
353  EVP_PKEY *pkey;
354  int (*i2d_func)_((const RSA*, unsigned char**));
355  unsigned char *p;
356  long len;
357  VALUE str;
358 
359  GetPKeyRSA(self, pkey);
360  if(RSA_HAS_PRIVATE(pkey->pkey.rsa))
361  i2d_func = i2d_RSAPrivateKey;
362  else
363  i2d_func = (int (*)(const RSA*, unsigned char**))i2d_RSA_PUBKEY;
364  if((len = i2d_func(pkey->pkey.rsa, NULL)) <= 0)
366  str = rb_str_new(0, len);
367  p = (unsigned char *)RSTRING_PTR(str);
368  if(i2d_func(pkey->pkey.rsa, &p) < 0)
370  ossl_str_adjust(str, p);
371 
372  return str;
373 }
374 
375 #define ossl_rsa_buf_size(pkey) (RSA_size((pkey)->pkey.rsa)+16)
376 
377 /*
378  * call-seq:
379  * rsa.public_encrypt(string) => String
380  * rsa.public_encrypt(string, padding) => String
381  *
382  * Encrypt +string+ with the public key. +padding+ defaults to PKCS1_PADDING.
383  * The encrypted string output can be decrypted using #private_decrypt.
384  */
385 static VALUE
387 {
388  EVP_PKEY *pkey;
389  int buf_len, pad;
390  VALUE str, buffer, padding;
391 
392  GetPKeyRSA(self, pkey);
393  rb_scan_args(argc, argv, "11", &buffer, &padding);
394  pad = (argc == 1) ? RSA_PKCS1_PADDING : NUM2INT(padding);
395  StringValue(buffer);
396  str = rb_str_new(0, ossl_rsa_buf_size(pkey));
397  buf_len = RSA_public_encrypt(RSTRING_LENINT(buffer), (unsigned char *)RSTRING_PTR(buffer),
398  (unsigned char *)RSTRING_PTR(str), pkey->pkey.rsa,
399  pad);
400  if (buf_len < 0) ossl_raise(eRSAError, NULL);
401  rb_str_set_len(str, buf_len);
402 
403  return str;
404 }
405 
406 /*
407  * call-seq:
408  * rsa.public_decrypt(string) => String
409  * rsa.public_decrypt(string, padding) => String
410  *
411  * Decrypt +string+, which has been encrypted with the private key, with the
412  * public key. +padding+ defaults to PKCS1_PADDING.
413  */
414 static VALUE
416 {
417  EVP_PKEY *pkey;
418  int buf_len, pad;
419  VALUE str, buffer, padding;
420 
421  GetPKeyRSA(self, pkey);
422  rb_scan_args(argc, argv, "11", &buffer, &padding);
423  pad = (argc == 1) ? RSA_PKCS1_PADDING : NUM2INT(padding);
424  StringValue(buffer);
425  str = rb_str_new(0, ossl_rsa_buf_size(pkey));
426  buf_len = RSA_public_decrypt(RSTRING_LENINT(buffer), (unsigned char *)RSTRING_PTR(buffer),
427  (unsigned char *)RSTRING_PTR(str), pkey->pkey.rsa,
428  pad);
429  if (buf_len < 0) ossl_raise(eRSAError, NULL);
430  rb_str_set_len(str, buf_len);
431 
432  return str;
433 }
434 
435 /*
436  * call-seq:
437  * rsa.private_encrypt(string) => String
438  * rsa.private_encrypt(string, padding) => String
439  *
440  * Encrypt +string+ with the private key. +padding+ defaults to PKCS1_PADDING.
441  * The encrypted string output can be decrypted using #public_decrypt.
442  */
443 static VALUE
445 {
446  EVP_PKEY *pkey;
447  int buf_len, pad;
448  VALUE str, buffer, padding;
449 
450  GetPKeyRSA(self, pkey);
451  if (!RSA_PRIVATE(self, pkey->pkey.rsa)) {
452  ossl_raise(eRSAError, "private key needed.");
453  }
454  rb_scan_args(argc, argv, "11", &buffer, &padding);
455  pad = (argc == 1) ? RSA_PKCS1_PADDING : NUM2INT(padding);
456  StringValue(buffer);
457  str = rb_str_new(0, ossl_rsa_buf_size(pkey));
458  buf_len = RSA_private_encrypt(RSTRING_LENINT(buffer), (unsigned char *)RSTRING_PTR(buffer),
459  (unsigned char *)RSTRING_PTR(str), pkey->pkey.rsa,
460  pad);
461  if (buf_len < 0) ossl_raise(eRSAError, NULL);
462  rb_str_set_len(str, buf_len);
463 
464  return str;
465 }
466 
467 /*
468  * call-seq:
469  * rsa.private_decrypt(string) => String
470  * rsa.private_decrypt(string, padding) => String
471  *
472  * Decrypt +string+, which has been encrypted with the public key, with the
473  * private key. +padding+ defaults to PKCS1_PADDING.
474  */
475 static VALUE
477 {
478  EVP_PKEY *pkey;
479  int buf_len, pad;
480  VALUE str, buffer, padding;
481 
482  GetPKeyRSA(self, pkey);
483  if (!RSA_PRIVATE(self, pkey->pkey.rsa)) {
484  ossl_raise(eRSAError, "private key needed.");
485  }
486  rb_scan_args(argc, argv, "11", &buffer, &padding);
487  pad = (argc == 1) ? RSA_PKCS1_PADDING : NUM2INT(padding);
488  StringValue(buffer);
489  str = rb_str_new(0, ossl_rsa_buf_size(pkey));
490  buf_len = RSA_private_decrypt(RSTRING_LENINT(buffer), (unsigned char *)RSTRING_PTR(buffer),
491  (unsigned char *)RSTRING_PTR(str), pkey->pkey.rsa,
492  pad);
493  if (buf_len < 0) ossl_raise(eRSAError, NULL);
494  rb_str_set_len(str, buf_len);
495 
496  return str;
497 }
498 
499 /*
500  * call-seq:
501  * rsa.params => hash
502  *
503  * THIS METHOD IS INSECURE, PRIVATE INFORMATION CAN LEAK OUT!!!
504  *
505  * Stores all parameters of key to the hash. The hash has keys 'n', 'e', 'd',
506  * 'p', 'q', 'dmp1', 'dmq1', 'iqmp'.
507  *
508  * Don't use :-)) (It's up to you)
509  */
510 static VALUE
512 {
513  EVP_PKEY *pkey;
514  VALUE hash;
515 
516  GetPKeyRSA(self, pkey);
517 
518  hash = rb_hash_new();
519 
520  rb_hash_aset(hash, rb_str_new2("n"), ossl_bn_new(pkey->pkey.rsa->n));
521  rb_hash_aset(hash, rb_str_new2("e"), ossl_bn_new(pkey->pkey.rsa->e));
522  rb_hash_aset(hash, rb_str_new2("d"), ossl_bn_new(pkey->pkey.rsa->d));
523  rb_hash_aset(hash, rb_str_new2("p"), ossl_bn_new(pkey->pkey.rsa->p));
524  rb_hash_aset(hash, rb_str_new2("q"), ossl_bn_new(pkey->pkey.rsa->q));
525  rb_hash_aset(hash, rb_str_new2("dmp1"), ossl_bn_new(pkey->pkey.rsa->dmp1));
526  rb_hash_aset(hash, rb_str_new2("dmq1"), ossl_bn_new(pkey->pkey.rsa->dmq1));
527  rb_hash_aset(hash, rb_str_new2("iqmp"), ossl_bn_new(pkey->pkey.rsa->iqmp));
528 
529  return hash;
530 }
531 
532 /*
533  * call-seq:
534  * rsa.to_text => String
535  *
536  * THIS METHOD IS INSECURE, PRIVATE INFORMATION CAN LEAK OUT!!!
537  *
538  * Dumps all parameters of a keypair to a String
539  *
540  * Don't use :-)) (It's up to you)
541  */
542 static VALUE
544 {
545  EVP_PKEY *pkey;
546  BIO *out;
547  VALUE str;
548 
549  GetPKeyRSA(self, pkey);
550  if (!(out = BIO_new(BIO_s_mem()))) {
552  }
553  if (!RSA_print(out, pkey->pkey.rsa, 0)) { /* offset = 0 */
554  BIO_free(out);
556  }
557  str = ossl_membio2str(out);
558 
559  return str;
560 }
561 
562 /*
563  * call-seq:
564  * rsa.public_key -> RSA
565  *
566  * Makes new RSA instance containing the public key from the private key.
567  */
568 static VALUE
570 {
571  EVP_PKEY *pkey;
572  RSA *rsa;
573  VALUE obj;
574 
575  GetPKeyRSA(self, pkey);
576  /* err check performed by rsa_instance */
577  rsa = RSAPublicKey_dup(pkey->pkey.rsa);
578  obj = rsa_instance(CLASS_OF(self), rsa);
579  if (obj == Qfalse) {
580  RSA_free(rsa);
582  }
583  return obj;
584 }
585 
586 /*
587  * TODO: Test me
588 
589 static VALUE
590 ossl_rsa_blinding_on(VALUE self)
591 {
592  EVP_PKEY *pkey;
593 
594  GetPKeyRSA(self, pkey);
595 
596  if (RSA_blinding_on(pkey->pkey.rsa, ossl_bn_ctx) != 1) {
597  ossl_raise(eRSAError, NULL);
598  }
599  return self;
600 }
601 
602 static VALUE
603 ossl_rsa_blinding_off(VALUE self)
604 {
605  EVP_PKEY *pkey;
606 
607  GetPKeyRSA(self, pkey);
608  RSA_blinding_off(pkey->pkey.rsa);
609 
610  return self;
611 }
612  */
613 
614 OSSL_PKEY_BN(rsa, n)
615 OSSL_PKEY_BN(rsa, e)
616 OSSL_PKEY_BN(rsa, d)
617 OSSL_PKEY_BN(rsa, p)
618 OSSL_PKEY_BN(rsa, q)
619 OSSL_PKEY_BN(rsa, dmp1)
620 OSSL_PKEY_BN(rsa, dmq1)
621 OSSL_PKEY_BN(rsa, iqmp)
622 
623 /*
624  * INIT
625  */
626 #define DefRSAConst(x) rb_define_const(cRSA, #x,INT2FIX(RSA_##x))
627 
628 void
630 {
631 #if 0
632  mOSSL = rb_define_module("OpenSSL"); /* let rdoc know about mOSSL and mPKey */
634 #endif
635 
636  /* Document-class: OpenSSL::PKey::RSAError
637  *
638  * Generic exception that is raised if an operation on an RSA PKey
639  * fails unexpectedly or in case an instantiation of an instance of RSA
640  * fails due to non-conformant input data.
641  */
643 
644  /* Document-class: OpenSSL::PKey::RSA
645  *
646  * RSA is an asymmetric public key algorithm that has been formalized in
647  * RFC 3447. It is in widespread use in public key infrastuctures (PKI)
648  * where certificates (cf. OpenSSL::X509::Certificate) often are issued
649  * on the basis of a public/private RSA key pair. RSA is used in a wide
650  * field of applications such as secure (symmetric) key exchange, e.g.
651  * when establishing a secure TLS/SSL connection. It is also used in
652  * various digital signature schemes.
653  */
655 
657  rb_define_method(cRSA, "initialize", ossl_rsa_initialize, -1);
658 
659  rb_define_method(cRSA, "public?", ossl_rsa_is_public, 0);
660  rb_define_method(cRSA, "private?", ossl_rsa_is_private, 0);
661  rb_define_method(cRSA, "to_text", ossl_rsa_to_text, 0);
662  rb_define_method(cRSA, "export", ossl_rsa_export, -1);
663  rb_define_alias(cRSA, "to_pem", "export");
664  rb_define_alias(cRSA, "to_s", "export");
665  rb_define_method(cRSA, "to_der", ossl_rsa_to_der, 0);
666  rb_define_method(cRSA, "public_key", ossl_rsa_to_public_key, 0);
667  rb_define_method(cRSA, "public_encrypt", ossl_rsa_public_encrypt, -1);
668  rb_define_method(cRSA, "public_decrypt", ossl_rsa_public_decrypt, -1);
669  rb_define_method(cRSA, "private_encrypt", ossl_rsa_private_encrypt, -1);
670  rb_define_method(cRSA, "private_decrypt", ossl_rsa_private_decrypt, -1);
671 
672  DEF_OSSL_PKEY_BN(cRSA, rsa, n);
673  DEF_OSSL_PKEY_BN(cRSA, rsa, e);
674  DEF_OSSL_PKEY_BN(cRSA, rsa, d);
675  DEF_OSSL_PKEY_BN(cRSA, rsa, p);
676  DEF_OSSL_PKEY_BN(cRSA, rsa, q);
677  DEF_OSSL_PKEY_BN(cRSA, rsa, dmp1);
678  DEF_OSSL_PKEY_BN(cRSA, rsa, dmq1);
679  DEF_OSSL_PKEY_BN(cRSA, rsa, iqmp);
680 
682 
683  DefRSAConst(PKCS1_PADDING);
684  DefRSAConst(SSLV23_PADDING);
685  DefRSAConst(NO_PADDING);
686  DefRSAConst(PKCS1_OAEP_PADDING);
687 
688 /*
689  * TODO: Test it
690  rb_define_method(cRSA, "blinding_on!", ossl_rsa_blinding_on, 0);
691  rb_define_method(cRSA, "blinding_off!", ossl_rsa_blinding_off, 0);
692  */
693 }
694 
695 #else /* defined NO_RSA */
696 void
698 {
699 }
700 #endif /* NO_RSA */
701 
VALUE mOSSL
Definition: ossl.c:259
VP_EXPORT int
Definition: bigdecimal.c:5172
static VALUE ossl_rsa_private_decrypt(int argc, VALUE *argv, VALUE self)
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
Definition: class.c:1646
VALUE mPKey
Definition: ossl_pkey.c:16
C_block * out
Definition: crypt.c:308
VALUE ePKeyError
Definition: ossl_pkey.c:18
#define OSSL_PKEY_BN(keytype, name)
Definition: ossl_pkey.h:103
#define ossl_str_adjust(str, p)
Definition: ossl.h:138
VALUE rb_eTypeError
Definition: error.c:548
#define NUM2ULONG(x)
#define RSTRING_PTR(str)
#define CLASS_OF(v)
NIL_P(eventloop_thread)
Definition: tcltklib.c:4056
int const char * in
Definition: crypt.c:639
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
Definition: class.c:657
return Qtrue
Definition: tcltklib.c:9618
#define GetPKey(obj, pkey)
Definition: ossl_pkey.h:30
VALUE ossl_rsa_new(EVP_PKEY *)
Definition: ossl_pkey_rsa.c:56
#define rb_str_new2
#define DefRSAConst(x)
int size
Definition: encoding.c:49
VALUE ossl_membio2str(BIO *bio)
Definition: ossl_bio.c:77
static VALUE ossl_rsa_to_public_key(VALUE self)
VALUE eRSAError
Definition: ossl_pkey_rsa.c:29
#define OSSL_MIN_PWD_LEN
Definition: ossl.h:81
d
Definition: strlcat.c:58
i
Definition: enum.c:446
VALUE hash
Definition: tkutil.c:267
void ossl_generate_cb(int p, int n, void *arg)
Definition: ossl_pkey.c:25
#define RSA_HAS_PRIVATE(rsa)
Definition: ossl_pkey_rsa.c:22
memset(y->frac+ix+1, 0,(y->Prec-(ix+1))*sizeof(BDIGIT))
VALUE ossl_to_der_if_possible(VALUE obj)
Definition: ossl.c:283
#define FIXNUM_P(f)
return Qfalse
Definition: tcltklib.c:6790
int rb_block_given_p(void)
Definition: eval.c:712
#define ossl_rsa_buf_size(pkey)
#define StringValuePtr(v)
VALUE cRSA
Definition: ossl_pkey_rsa.c:28
static VALUE char * str
Definition: tcltklib.c:3539
static VALUE ossl_rsa_initialize(int argc, VALUE *argv, VALUE self)
#define OSSL_BIO_reset(bio)
Definition: ossl.h:155
#define DEF_OSSL_PKEY_BN(class, keytype, name)
Definition: ossl_pkey.h:145
static VALUE VALUE obj
Definition: tcltklib.c:3150
#define FIX2INT(x)
static VALUE ossl_rsa_private_encrypt(int argc, VALUE *argv, VALUE self)
VALUE eOSSLError
Definition: ossl.c:264
const EVP_CIPHER * GetCipherPtr(VALUE obj)
Definition: ossl_cipher.c:45
int len
Definition: enumerator.c:1332
void * rb_thread_call_without_gvl(void *(*func)(void *), void *data1, rb_unblock_function_t *ubf, void *data2)
static VALUE ossl_rsa_is_private(VALUE self)
VALUE arg
Definition: enum.c:2427
static VALUE ossl_rsa_public_encrypt(int argc, VALUE *argv, VALUE self)
static VALUE ossl_rsa_is_public(VALUE self)
VALUE * argv
Definition: tcltklib.c:1969
void rb_define_alias(VALUE klass, const char *name1, const char *name2)
Defines an alias of a method.
Definition: class.c:1688
#define WrapPKey(klass, obj, pkey)
Definition: ossl_pkey.h:23
#define StringValue(v)
static VALUE ossl_rsa_to_text(VALUE self)
BIO * ossl_obj2bio(VALUE obj)
Definition: ossl_bio.c:17
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
Definition: class.c:1719
#define GetPKeyRSA(obj, pkey)
Definition: ossl_pkey_rsa.c:15
int argc
Definition: tcltklib.c:1968
rb_hash_aset(hash, RARRAY_AREF(key_value_pair, 0), RARRAY_AREF(key_value_pair, 1))
static VALUE rsa_instance(VALUE klass, RSA *rsa)
Definition: ossl_pkey_rsa.c:35
void rb_jump_tag(int tag)
Definition: eval.c:706
static RSA * rsa_generate(int size, unsigned long exp)
Definition: ossl_pkey_rsa.c:98
#define _(args)
Definition: dln.h:28
VALUE rb_define_module_under(VALUE outer, const char *name)
Definition: class.c:747
static VALUE ossl_rsa_s_generate(int argc, VALUE *argv, VALUE klass)
static VALUE ossl_rsa_to_der(VALUE self)
klass
Definition: tcltklib.c:3496
#define RSA_PRIVATE(obj, rsa)
Definition: ossl_pkey_rsa.c:23
static VALUE ossl_rsa_public_decrypt(int argc, VALUE *argv, VALUE self)
void ossl_raise(VALUE exc, const char *fmt,...)
Definition: ossl.c:333
static VALUE ossl_rsa_export(int argc, VALUE *argv, VALUE self)
#define RSTRING_LENINT(str)
register C_block * p
Definition: crypt.c:309
VALUE rb_str_new(const char *, long)
Definition: string.c:534
data n
Definition: enum.c:860
void Init_ossl_rsa(void)
#define NUM2INT(x)
VALUE rb_hash_new(void)
Definition: hash.c:307
VALUE ossl_bn_new(const BIGNUM *bn)
Definition: ossl_bn.c:43
BDIGIT e
Definition: bigdecimal.c:5209
unsigned long VALUE
Definition: ripper.y:88
int ossl_pem_passwd_cb(char *buf, int max_len, int flag, void *pwd)
Definition: ossl.c:162
VALUE rb_define_module(const char *name)
Definition: class.c:727
VALUE cPKey
Definition: ossl_pkey.c:17
#define NULL
Definition: _sdbm.c:102
q
Definition: tcltklib.c:2964
volatile VALUE result
Definition: enum.c:1989
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Definition: class.c:1479
static VALUE ossl_rsa_get_params(VALUE self)
void rb_str_set_len(VALUE, long)
Definition: string.c:2007