Ruby  2.0.0p353(2013-11-22revision43784)
ossl_pkey_rsa.c
Go to the documentation of this file.
1 /*
2  * $Id: ossl_pkey_rsa.c 36355 2012-07-10 13:57:11Z nobu $
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
35 rsa_instance(VALUE klass, RSA *rsa)
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.to_pem => PEM-format String
295  * rsa.to_pem(cipher, pass_phrase) => PEM-format String
296  *
297  * Outputs this keypair in PEM encoding. If +cipher+ and +pass_phrase+ are
298  * given they will be used to encrypt the key. +cipher+ must be an
299  * OpenSSL::Cipher::Cipher instance.
300  */
301 static VALUE
303 {
304  EVP_PKEY *pkey;
305  BIO *out;
306  const EVP_CIPHER *ciph = NULL;
307  char *passwd = NULL;
308  VALUE cipher, pass, str;
309 
310  GetPKeyRSA(self, pkey);
311 
312  rb_scan_args(argc, argv, "02", &cipher, &pass);
313 
314  if (!NIL_P(cipher)) {
315  ciph = GetCipherPtr(cipher);
316  if (!NIL_P(pass)) {
317  StringValue(pass);
318  if (RSTRING_LENINT(pass) < OSSL_MIN_PWD_LEN)
319  ossl_raise(eOSSLError, "OpenSSL requires passwords to be at least four characters long");
320  passwd = RSTRING_PTR(pass);
321  }
322  }
323  if (!(out = BIO_new(BIO_s_mem()))) {
325  }
326  if (RSA_HAS_PRIVATE(pkey->pkey.rsa)) {
327  if (!PEM_write_bio_RSAPrivateKey(out, pkey->pkey.rsa, ciph,
328  NULL, 0, ossl_pem_passwd_cb, passwd)) {
329  BIO_free(out);
331  }
332  } else {
333  if (!PEM_write_bio_RSA_PUBKEY(out, pkey->pkey.rsa)) {
334  BIO_free(out);
336  }
337  }
338  str = ossl_membio2str(out);
339 
340  return str;
341 }
342 
343 /*
344  * call-seq:
345  * rsa.to_der => DER-format String
346  *
347  * Outputs this keypair in DER encoding.
348  */
349 static VALUE
351 {
352  EVP_PKEY *pkey;
353  int (*i2d_func)_((const RSA*, unsigned char**));
354  unsigned char *p;
355  long len;
356  VALUE str;
357 
358  GetPKeyRSA(self, pkey);
359  if(RSA_HAS_PRIVATE(pkey->pkey.rsa))
360  i2d_func = i2d_RSAPrivateKey;
361  else
362  i2d_func = (int (*)(const RSA*, unsigned char**))i2d_RSA_PUBKEY;
363  if((len = i2d_func(pkey->pkey.rsa, NULL)) <= 0)
365  str = rb_str_new(0, len);
366  p = (unsigned char *)RSTRING_PTR(str);
367  if(i2d_func(pkey->pkey.rsa, &p) < 0)
369  ossl_str_adjust(str, p);
370 
371  return str;
372 }
373 
374 #define ossl_rsa_buf_size(pkey) (RSA_size((pkey)->pkey.rsa)+16)
375 
376 /*
377  * call-seq:
378  * rsa.public_encrypt(string) => String
379  * rsa.public_encrypt(string, padding) => String
380  *
381  * Encrypt +string+ with the public key. +padding+ defaults to PKCS1_PADDING.
382  * The encrypted string output can be decrypted using #private_decrypt.
383  */
384 static VALUE
386 {
387  EVP_PKEY *pkey;
388  int buf_len, pad;
389  VALUE str, buffer, padding;
390 
391  GetPKeyRSA(self, pkey);
392  rb_scan_args(argc, argv, "11", &buffer, &padding);
393  pad = (argc == 1) ? RSA_PKCS1_PADDING : NUM2INT(padding);
394  StringValue(buffer);
395  str = rb_str_new(0, ossl_rsa_buf_size(pkey));
396  buf_len = RSA_public_encrypt(RSTRING_LENINT(buffer), (unsigned char *)RSTRING_PTR(buffer),
397  (unsigned char *)RSTRING_PTR(str), pkey->pkey.rsa,
398  pad);
399  if (buf_len < 0) ossl_raise(eRSAError, NULL);
400  rb_str_set_len(str, buf_len);
401 
402  return str;
403 }
404 
405 /*
406  * call-seq:
407  * rsa.public_decrypt(string) => String
408  * rsa.public_decrypt(string, padding) => String
409  *
410  * Decrypt +string+, which has been encrypted with the private key, with the
411  * public key. +padding+ defaults to PKCS1_PADDING.
412  */
413 static VALUE
415 {
416  EVP_PKEY *pkey;
417  int buf_len, pad;
418  VALUE str, buffer, padding;
419 
420  GetPKeyRSA(self, pkey);
421  rb_scan_args(argc, argv, "11", &buffer, &padding);
422  pad = (argc == 1) ? RSA_PKCS1_PADDING : NUM2INT(padding);
423  StringValue(buffer);
424  str = rb_str_new(0, ossl_rsa_buf_size(pkey));
425  buf_len = RSA_public_decrypt(RSTRING_LENINT(buffer), (unsigned char *)RSTRING_PTR(buffer),
426  (unsigned char *)RSTRING_PTR(str), pkey->pkey.rsa,
427  pad);
428  if (buf_len < 0) ossl_raise(eRSAError, NULL);
429  rb_str_set_len(str, buf_len);
430 
431  return str;
432 }
433 
434 /*
435  * call-seq:
436  * rsa.private_encrypt(string) => String
437  * rsa.private_encrypt(string, padding) => String
438  *
439  * Encrypt +string+ with the private key. +padding+ defaults to PKCS1_PADDING.
440  * The encrypted string output can be decrypted using #public_decrypt.
441  */
442 static VALUE
444 {
445  EVP_PKEY *pkey;
446  int buf_len, pad;
447  VALUE str, buffer, padding;
448 
449  GetPKeyRSA(self, pkey);
450  if (!RSA_PRIVATE(self, pkey->pkey.rsa)) {
451  ossl_raise(eRSAError, "private key needed.");
452  }
453  rb_scan_args(argc, argv, "11", &buffer, &padding);
454  pad = (argc == 1) ? RSA_PKCS1_PADDING : NUM2INT(padding);
455  StringValue(buffer);
456  str = rb_str_new(0, ossl_rsa_buf_size(pkey));
457  buf_len = RSA_private_encrypt(RSTRING_LENINT(buffer), (unsigned char *)RSTRING_PTR(buffer),
458  (unsigned char *)RSTRING_PTR(str), pkey->pkey.rsa,
459  pad);
460  if (buf_len < 0) ossl_raise(eRSAError, NULL);
461  rb_str_set_len(str, buf_len);
462 
463  return str;
464 }
465 
466 /*
467  * call-seq:
468  * rsa.private_decrypt(string) => String
469  * rsa.private_decrypt(string, padding) => String
470  *
471  * Decrypt +string+, which has been encrypted with the public key, with the
472  * private key. +padding+ defaults to PKCS1_PADDING.
473  */
474 static VALUE
476 {
477  EVP_PKEY *pkey;
478  int buf_len, pad;
479  VALUE str, buffer, padding;
480 
481  GetPKeyRSA(self, pkey);
482  if (!RSA_PRIVATE(self, pkey->pkey.rsa)) {
483  ossl_raise(eRSAError, "private key needed.");
484  }
485  rb_scan_args(argc, argv, "11", &buffer, &padding);
486  pad = (argc == 1) ? RSA_PKCS1_PADDING : NUM2INT(padding);
487  StringValue(buffer);
488  str = rb_str_new(0, ossl_rsa_buf_size(pkey));
489  buf_len = RSA_private_decrypt(RSTRING_LENINT(buffer), (unsigned char *)RSTRING_PTR(buffer),
490  (unsigned char *)RSTRING_PTR(str), pkey->pkey.rsa,
491  pad);
492  if (buf_len < 0) ossl_raise(eRSAError, NULL);
493  rb_str_set_len(str, buf_len);
494 
495  return str;
496 }
497 
498 /*
499  * call-seq:
500  * rsa.params => hash
501  *
502  * THIS METHOD IS INSECURE, PRIVATE INFORMATION CAN LEAK OUT!!!
503  *
504  * Stores all parameters of key to the hash. The hash has keys 'n', 'e', 'd',
505  * 'p', 'q', 'dmp1', 'dmq1', 'iqmp'.
506  *
507  * Don't use :-)) (It's up to you)
508  */
509 static VALUE
511 {
512  EVP_PKEY *pkey;
513  VALUE hash;
514 
515  GetPKeyRSA(self, pkey);
516 
517  hash = rb_hash_new();
518 
519  rb_hash_aset(hash, rb_str_new2("n"), ossl_bn_new(pkey->pkey.rsa->n));
520  rb_hash_aset(hash, rb_str_new2("e"), ossl_bn_new(pkey->pkey.rsa->e));
521  rb_hash_aset(hash, rb_str_new2("d"), ossl_bn_new(pkey->pkey.rsa->d));
522  rb_hash_aset(hash, rb_str_new2("p"), ossl_bn_new(pkey->pkey.rsa->p));
523  rb_hash_aset(hash, rb_str_new2("q"), ossl_bn_new(pkey->pkey.rsa->q));
524  rb_hash_aset(hash, rb_str_new2("dmp1"), ossl_bn_new(pkey->pkey.rsa->dmp1));
525  rb_hash_aset(hash, rb_str_new2("dmq1"), ossl_bn_new(pkey->pkey.rsa->dmq1));
526  rb_hash_aset(hash, rb_str_new2("iqmp"), ossl_bn_new(pkey->pkey.rsa->iqmp));
527 
528  return hash;
529 }
530 
531 /*
532  * call-seq:
533  * rsa.to_text => String
534  *
535  * THIS METHOD IS INSECURE, PRIVATE INFORMATION CAN LEAK OUT!!!
536  *
537  * Dumps all parameters of a keypair to a String
538  *
539  * Don't use :-)) (It's up to you)
540  */
541 static VALUE
543 {
544  EVP_PKEY *pkey;
545  BIO *out;
546  VALUE str;
547 
548  GetPKeyRSA(self, pkey);
549  if (!(out = BIO_new(BIO_s_mem()))) {
551  }
552  if (!RSA_print(out, pkey->pkey.rsa, 0)) { /* offset = 0 */
553  BIO_free(out);
555  }
556  str = ossl_membio2str(out);
557 
558  return str;
559 }
560 
561 /*
562  * call-seq:
563  * rsa.public_key -> RSA
564  *
565  * Makes new RSA instance containing the public key from the private key.
566  */
567 static VALUE
569 {
570  EVP_PKEY *pkey;
571  RSA *rsa;
572  VALUE obj;
573 
574  GetPKeyRSA(self, pkey);
575  /* err check performed by rsa_instance */
576  rsa = RSAPublicKey_dup(pkey->pkey.rsa);
577  obj = rsa_instance(CLASS_OF(self), rsa);
578  if (obj == Qfalse) {
579  RSA_free(rsa);
581  }
582  return obj;
583 }
584 
585 /*
586  * TODO: Test me
587 
588 static VALUE
589 ossl_rsa_blinding_on(VALUE self)
590 {
591  EVP_PKEY *pkey;
592 
593  GetPKeyRSA(self, pkey);
594 
595  if (RSA_blinding_on(pkey->pkey.rsa, ossl_bn_ctx) != 1) {
596  ossl_raise(eRSAError, NULL);
597  }
598  return self;
599 }
600 
601 static VALUE
602 ossl_rsa_blinding_off(VALUE self)
603 {
604  EVP_PKEY *pkey;
605 
606  GetPKeyRSA(self, pkey);
607  RSA_blinding_off(pkey->pkey.rsa);
608 
609  return self;
610 }
611  */
612 
613 OSSL_PKEY_BN(rsa, n)
614 OSSL_PKEY_BN(rsa, e)
615 OSSL_PKEY_BN(rsa, d)
616 OSSL_PKEY_BN(rsa, p)
617 OSSL_PKEY_BN(rsa, q)
618 OSSL_PKEY_BN(rsa, dmp1)
619 OSSL_PKEY_BN(rsa, dmq1)
620 OSSL_PKEY_BN(rsa, iqmp)
621 
622 /*
623  * INIT
624  */
625 #define DefRSAConst(x) rb_define_const(cRSA, #x,INT2FIX(RSA_##x))
626 
627 void
629 {
630 #if 0
631  mOSSL = rb_define_module("OpenSSL"); /* let rdoc know about mOSSL and mPKey */
633 #endif
634 
635  /* Document-class: OpenSSL::PKey::RSAError
636  *
637  * Generic exception that is raised if an operation on an RSA PKey
638  * fails unexpectedly or in case an instantiation of an instance of RSA
639  * fails due to non-conformant input data.
640  */
642 
643  /* Document-class: OpenSSL::PKey::RSA
644  *
645  * RSA is an asymmetric public key algorithm that has been formalized in
646  * RFC 3447. It is in widespread use in public key infrastuctures (PKI)
647  * where certificates (cf. OpenSSL::X509::Certificate) often are issued
648  * on the basis of a public/private RSA key pair. RSA is used in a wide
649  * field of applications such as secure (symmetric) key exchange, e.g.
650  * when establishing a secure TLS/SSL connection. It is also used in
651  * various digital signature schemes.
652  */
654 
656  rb_define_method(cRSA, "initialize", ossl_rsa_initialize, -1);
657 
658  rb_define_method(cRSA, "public?", ossl_rsa_is_public, 0);
659  rb_define_method(cRSA, "private?", ossl_rsa_is_private, 0);
660  rb_define_method(cRSA, "to_text", ossl_rsa_to_text, 0);
661  rb_define_method(cRSA, "export", ossl_rsa_export, -1);
662  rb_define_alias(cRSA, "to_pem", "export");
663  rb_define_alias(cRSA, "to_s", "export");
664  rb_define_method(cRSA, "to_der", ossl_rsa_to_der, 0);
665  rb_define_method(cRSA, "public_key", ossl_rsa_to_public_key, 0);
666  rb_define_method(cRSA, "public_encrypt", ossl_rsa_public_encrypt, -1);
667  rb_define_method(cRSA, "public_decrypt", ossl_rsa_public_decrypt, -1);
668  rb_define_method(cRSA, "private_encrypt", ossl_rsa_private_encrypt, -1);
669  rb_define_method(cRSA, "private_decrypt", ossl_rsa_private_decrypt, -1);
670 
671  DEF_OSSL_PKEY_BN(cRSA, rsa, n);
672  DEF_OSSL_PKEY_BN(cRSA, rsa, e);
673  DEF_OSSL_PKEY_BN(cRSA, rsa, d);
674  DEF_OSSL_PKEY_BN(cRSA, rsa, p);
675  DEF_OSSL_PKEY_BN(cRSA, rsa, q);
676  DEF_OSSL_PKEY_BN(cRSA, rsa, dmp1);
677  DEF_OSSL_PKEY_BN(cRSA, rsa, dmq1);
678  DEF_OSSL_PKEY_BN(cRSA, rsa, iqmp);
679 
681 
682  DefRSAConst(PKCS1_PADDING);
683  DefRSAConst(SSLV23_PADDING);
684  DefRSAConst(NO_PADDING);
685  DefRSAConst(PKCS1_OAEP_PADDING);
686 
687 /*
688  * TODO: Test it
689  rb_define_method(cRSA, "blinding_on!", ossl_rsa_blinding_on, 0);
690  rb_define_method(cRSA, "blinding_off!", ossl_rsa_blinding_off, 0);
691  */
692 }
693 
694 #else /* defined NO_RSA */
695 void
697 {
698 }
699 #endif /* NO_RSA */
700 
VALUE cRSA
Definition: ossl_pkey_rsa.c:28
VALUE mOSSL
Definition: ossl.c:259
static VALUE ossl_rsa_private_decrypt(int argc, VALUE *argv, VALUE self)
int i
Definition: win32ole.c:784
#define NUM2INT(x)
Definition: ruby.h:622
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
Definition: class.c:1497
VALUE mPKey
Definition: ossl_pkey.c:16
#define CLASS_OF(v)
Definition: ruby.h:448
VALUE ePKeyError
Definition: ossl_pkey.c:18
#define OSSL_PKEY_BN(keytype, name)
Definition: ossl_pkey.h:103
#define Qtrue
Definition: ruby.h:434
#define ossl_str_adjust(str, p)
Definition: ossl.h:138
VALUE rb_eTypeError
Definition: error.c:511
void rb_str_set_len(VALUE, long)
Definition: string.c:1837
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
Definition: class.c:545
#define GetPKey(obj, pkey)
Definition: ossl_pkey.h:30
#define DefRSAConst(x)
VALUE ossl_rsa_new(EVP_PKEY *pkey)
Definition: ossl_pkey_rsa.c:56
VALUE ossl_membio2str(BIO *bio)
Definition: ossl_bio.c:77
#define FIXNUM_P(f)
Definition: ruby.h:355
static VALUE ossl_rsa_to_public_key(VALUE self)
#define OSSL_MIN_PWD_LEN
Definition: ossl.h:81
Win32OLEIDispatch * p
Definition: win32ole.c:786
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
VALUE ossl_to_der_if_possible(VALUE obj)
Definition: ossl.c:283
int rb_block_given_p(void)
Definition: eval.c:672
#define ossl_rsa_buf_size(pkey)
static VALUE ossl_rsa_initialize(int argc, VALUE *argv, VALUE self)
#define OSSL_BIO_reset(bio)
Definition: ossl.h:155
#define NIL_P(v)
Definition: ruby.h:446
#define DEF_OSSL_PKEY_BN(class, keytype, name)
Definition: ossl_pkey.h:145
static VALUE ossl_rsa_private_encrypt(int argc, VALUE *argv, VALUE self)
VALUE eOSSLError
Definition: ossl.c:264
int argc
Definition: ruby.c:130
#define Qfalse
Definition: ruby.h:433
const EVP_CIPHER * GetCipherPtr(VALUE obj)
Definition: ossl_cipher.c:45
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)
static VALUE ossl_rsa_public_encrypt(int argc, VALUE *argv, VALUE self)
static VALUE ossl_rsa_is_public(VALUE self)
void rb_define_alias(VALUE klass, const char *name1, const char *name2)
Defines an alias of a method.
Definition: class.c:1539
#define WrapPKey(klass, obj, pkey)
Definition: ossl_pkey.h:23
VALUE eRSAError
Definition: ossl_pkey_rsa.c:29
static VALUE ossl_rsa_to_text(VALUE self)
BIO * ossl_obj2bio(VALUE obj)
Definition: ossl_bio.c:17
VALUE rb_hash_new(void)
Definition: hash.c:234
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
Definition: class.c:1570
#define GetPKeyRSA(obj, pkey)
Definition: ossl_pkey_rsa.c:15
unsigned long VALUE
Definition: ruby.h:104
static VALUE result
Definition: nkf.c:40
#define FIX2INT(x)
Definition: ruby.h:624
static VALUE rsa_instance(VALUE klass, RSA *rsa)
Definition: ossl_pkey_rsa.c:35
void rb_jump_tag(int tag)
Definition: eval.c:666
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:637
#define RSTRING_PTR(str)
Definition: ruby.h:866
int size
Definition: encoding.c:52
#define NUM2ULONG(x)
Definition: ruby.h:601
static VALUE ossl_rsa_s_generate(int argc, VALUE *argv, VALUE klass)
static VALUE ossl_rsa_to_der(VALUE self)
#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:328
static VALUE ossl_rsa_export(int argc, VALUE *argv, VALUE self)
static unsigned int hash(const char *str, unsigned int len)
Definition: lex.c:56
VALUE ossl_bn_new(const BIGNUM *bn)
Definition: ossl_bn.c:43
#define StringValuePtr(v)
Definition: ruby.h:547
int ossl_pem_passwd_cb(char *buf, int max_len, int flag, void *pwd)
Definition: ossl.c:162
#define RSTRING_LENINT(str)
Definition: ruby.h:874
VALUE rb_define_module(const char *name)
Definition: class.c:617
VALUE cPKey
Definition: ossl_pkey.c:17
#define NULL
Definition: _sdbm.c:103
VALUE rb_hash_aset(VALUE, VALUE, VALUE)
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Definition: class.c:1344
static VALUE ossl_rsa_get_params(VALUE self)
VALUE rb_str_new2(const char *)
char ** argv
Definition: ruby.c:131
#define StringValue(v)
Definition: ruby.h:546
void Init_ossl_rsa()
VALUE rb_str_new(const char *, long)
Definition: string.c:425