rubysl-openssl 2.4.0 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/ext/rubysl/openssl/deprecation.rb +1 -0
  3. data/ext/rubysl/openssl/extconf.rb +6 -8
  4. data/ext/rubysl/openssl/openssl_missing.c +1 -3
  5. data/ext/rubysl/openssl/openssl_missing.h +1 -3
  6. data/ext/rubysl/openssl/ossl.c +15 -3
  7. data/ext/rubysl/openssl/ossl.h +5 -4
  8. data/ext/rubysl/openssl/ossl_asn1.c +19 -13
  9. data/ext/rubysl/openssl/ossl_asn1.h +1 -2
  10. data/ext/rubysl/openssl/ossl_bio.c +1 -2
  11. data/ext/rubysl/openssl/ossl_bio.h +1 -3
  12. data/ext/rubysl/openssl/ossl_bn.c +227 -90
  13. data/ext/rubysl/openssl/ossl_bn.h +1 -3
  14. data/ext/rubysl/openssl/ossl_cipher.c +5 -11
  15. data/ext/rubysl/openssl/ossl_cipher.h +1 -3
  16. data/ext/rubysl/openssl/ossl_config.c +1 -2
  17. data/ext/rubysl/openssl/ossl_config.h +1 -3
  18. data/ext/rubysl/openssl/ossl_digest.c +6 -7
  19. data/ext/rubysl/openssl/ossl_digest.h +1 -3
  20. data/ext/rubysl/openssl/ossl_engine.c +11 -7
  21. data/ext/rubysl/openssl/ossl_engine.h +1 -2
  22. data/ext/rubysl/openssl/ossl_hmac.c +1 -2
  23. data/ext/rubysl/openssl/ossl_hmac.h +1 -2
  24. data/ext/rubysl/openssl/ossl_ns_spki.c +7 -6
  25. data/ext/rubysl/openssl/ossl_ns_spki.h +1 -3
  26. data/ext/rubysl/openssl/ossl_ocsp.c +39 -25
  27. data/ext/rubysl/openssl/ossl_ocsp.h +1 -2
  28. data/ext/rubysl/openssl/ossl_pkcs12.c +10 -6
  29. data/ext/rubysl/openssl/ossl_pkcs12.h +1 -3
  30. data/ext/rubysl/openssl/ossl_pkcs5.c +0 -1
  31. data/ext/rubysl/openssl/ossl_pkcs7.c +29 -16
  32. data/ext/rubysl/openssl/ossl_pkcs7.h +1 -3
  33. data/ext/rubysl/openssl/ossl_pkey.c +10 -8
  34. data/ext/rubysl/openssl/ossl_pkey.h +5 -6
  35. data/ext/rubysl/openssl/ossl_pkey_dh.c +5 -74
  36. data/ext/rubysl/openssl/ossl_pkey_dsa.c +7 -6
  37. data/ext/rubysl/openssl/ossl_pkey_ec.c +4 -2
  38. data/ext/rubysl/openssl/ossl_pkey_rsa.c +5 -5
  39. data/ext/rubysl/openssl/ossl_rand.c +13 -5
  40. data/ext/rubysl/openssl/ossl_rand.h +1 -3
  41. data/ext/rubysl/openssl/ossl_ssl.c +334 -265
  42. data/ext/rubysl/openssl/ossl_ssl.h +1 -5
  43. data/ext/rubysl/openssl/ossl_ssl_session.c +5 -1
  44. data/ext/rubysl/openssl/ossl_version.h +1 -2
  45. data/ext/rubysl/openssl/ossl_x509.c +1 -3
  46. data/ext/rubysl/openssl/ossl_x509.h +1 -2
  47. data/ext/rubysl/openssl/ossl_x509attr.c +9 -6
  48. data/ext/rubysl/openssl/ossl_x509cert.c +14 -12
  49. data/ext/rubysl/openssl/ossl_x509crl.c +15 -13
  50. data/ext/rubysl/openssl/ossl_x509ext.c +13 -8
  51. data/ext/rubysl/openssl/ossl_x509name.c +9 -6
  52. data/ext/rubysl/openssl/ossl_x509req.c +12 -10
  53. data/ext/rubysl/openssl/ossl_x509revoked.c +12 -10
  54. data/ext/rubysl/openssl/ossl_x509store.c +17 -10
  55. data/ext/rubysl/openssl/ruby_missing.h +1 -2
  56. data/lib/openssl/bn.rb +2 -8
  57. data/lib/openssl/buffering.rb +3 -7
  58. data/lib/openssl/cipher.rb +3 -9
  59. data/lib/openssl/config.rb +2 -1
  60. data/lib/openssl/digest.rb +3 -10
  61. data/lib/openssl/pkey.rb +37 -0
  62. data/lib/openssl/ssl.rb +128 -17
  63. data/lib/openssl/x509.rb +2 -8
  64. data/lib/rubysl/openssl.rb +4 -7
  65. data/lib/rubysl/openssl/version.rb +1 -1
  66. metadata +12 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 02c28e54552a012c04288964b9388152e2e08396
4
- data.tar.gz: 092a697ea348a292d7ea1d37c2bdef94e1398496
3
+ metadata.gz: b5891637a7b61280d9cf53442718d278f44de04e
4
+ data.tar.gz: f0144074795d3268b386c773e00a4495cde6759f
5
5
  SHA512:
6
- metadata.gz: 14d006d186aaaa3b84d0031f6c680276eb1f1a0d837a061d72545076325e6a421c46fa433204a9e68bd842836bd6e39cffd12eaf87eec0c34a0e1a959c439590
7
- data.tar.gz: d553256a8678cd64b99c01705e2b01902e913dc78ce47d5e1b55fb2479164b5beb22cf7422294cc81695968adf103b99829a653b4820f6ffec18477bf09dc0cb
6
+ metadata.gz: ba962b6d3311055b901193dd303e79912bf7097bba7e49ce0dd0e2623c8ddcf1bc699d35d139bfcabc8b2bdae6f26328a1a4f0617cdac54a478abae6ff3a9510
7
+ data.tar.gz: 132cc0ae45c8e2d3cf13a22f9a77373db4fb2c6dd477b2d65652baf495bb553239ce7f566f001b8d9841433be6d8ab6ef9df33a8b8d73d03b8b6195335221d24
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: false
1
2
  module OpenSSL
2
3
  def self.deprecated_warning_flag
3
4
  unless flag = (@deprecated_warning_flag ||= nil)
@@ -1,18 +1,14 @@
1
1
  # -*- coding: us-ascii -*-
2
+ # frozen_string_literal: false
2
3
  =begin
3
- = $RCSfile$ -- Generator for Makefile
4
-
5
4
  = Info
6
5
  'OpenSSL for Ruby 2' project
7
6
  Copyright (C) 2002 Michal Rokos <m.rokos@sh.cvut.cz>
8
7
  All rights reserved.
9
8
 
10
9
  = Licence
11
- This program is licenced under the same licence as Ruby.
10
+ This program is licensed under the same licence as Ruby.
12
11
  (See the file 'LICENCE'.)
13
-
14
- = Version
15
- $Id$
16
12
  =end
17
13
 
18
14
  require "mkmf"
@@ -59,7 +55,7 @@ unless have_header("openssl/conf_api.h")
59
55
  raise "OpenSSL 0.9.6 or later required."
60
56
  end
61
57
  unless OpenSSL.check_func("SSL_library_init()", "openssl/ssl.h")
62
- Logging::message "You may be using a version of OpenSSL or SSL provided by Apple.\nIf you encounter issues, please use another SSL library. (e.g. using `configure --with-openssl-dir=/path/to/openssl')"
58
+ raise "Ignore OpenSSL broken by Apple.\nPlease use another openssl. (e.g. using `configure --with-openssl-dir=/path/to/openssl')"
63
59
  end
64
60
 
65
61
  Logging::message "=== Checking for OpenSSL features... ===\n"
@@ -87,6 +83,7 @@ have_func("HMAC_CTX_init")
87
83
  have_func("PEM_def_callback")
88
84
  have_func("PKCS5_PBKDF2_HMAC")
89
85
  have_func("PKCS5_PBKDF2_HMAC_SHA1")
86
+ have_func("RAND_egd")
90
87
  have_func("X509V3_set_nconf")
91
88
  have_func("X509V3_EXT_nconf_nid")
92
89
  have_func("X509_CRL_add0_revoked")
@@ -112,6 +109,7 @@ have_func("TLSv1_1_client_method")
112
109
  have_func("TLSv1_2_method")
113
110
  have_func("TLSv1_2_server_method")
114
111
  have_func("TLSv1_2_client_method")
112
+ have_func("SSL_CTX_set_alpn_select_cb")
115
113
  have_macro("OPENSSL_NPN_NEGOTIATED", ['openssl/ssl.h']) && $defs.push("-DHAVE_OPENSSL_NPN_NEGOTIATED")
116
114
  unless have_func("SSL_set_tlsext_host_name", ['openssl/ssl.h'])
117
115
  have_macro("SSL_set_tlsext_host_name", ['openssl/ssl.h']) && $defs.push("-DHAVE_SSL_SET_TLSEXT_HOST_NAME")
@@ -157,7 +155,7 @@ have_macro("EVP_CTRL_GCM_GET_TAG", ['openssl/evp.h']) && $defs.push("-DHAVE_AUTH
157
155
  Logging::message "=== Checking done. ===\n"
158
156
 
159
157
  create_header
160
- create_makefile("openssl/openssl") {|conf|
158
+ create_makefile("openssl") {|conf|
161
159
  conf << "THREAD_MODEL = #{CONFIG["THREAD_MODEL"]}\n"
162
160
  }
163
161
  Logging::message "Done.\n"
@@ -1,11 +1,10 @@
1
1
  /*
2
- * $Id: openssl_missing.c 40625 2013-05-09 12:12:17Z akr $
3
2
  * 'OpenSSL for Ruby' project
4
3
  * Copyright (C) 2001-2002 Michal Rokos <m.rokos@sh.cvut.cz>
5
4
  * All rights reserved.
6
5
  */
7
6
  /*
8
- * This program is licenced under the same licence as Ruby.
7
+ * This program is licensed under the same licence as Ruby.
9
8
  * (See the file 'LICENCE'.)
10
9
  */
11
10
  #include RUBY_EXTCONF_H
@@ -353,4 +352,3 @@ ASN1_put_eoc(unsigned char **pp)
353
352
  return 2;
354
353
  }
355
354
  #endif
356
-
@@ -1,11 +1,10 @@
1
1
  /*
2
- * $Id: openssl_missing.h 32230 2011-06-26 01:32:03Z emboss $
3
2
  * 'OpenSSL for Ruby' project
4
3
  * Copyright (C) 2001-2002 Michal Rokos <m.rokos@sh.cvut.cz>
5
4
  * All rights reserved.
6
5
  */
7
6
  /*
8
- * This program is licenced under the same licence as Ruby.
7
+ * This program is licensed under the same licence as Ruby.
9
8
  * (See the file 'LICENCE'.)
10
9
  */
11
10
  #if !defined(_OSSL_OPENSSL_MISSING_H_)
@@ -195,4 +194,3 @@ int ASN1_put_eoc(unsigned char **pp);
195
194
 
196
195
 
197
196
  #endif /* _OSSL_OPENSSL_MISSING_H_ */
198
-
@@ -1,11 +1,10 @@
1
1
  /*
2
- * $Id: ossl.c 47744 2014-09-30 05:25:32Z nobu $
3
2
  * 'OpenSSL for Ruby' project
4
3
  * Copyright (C) 2001-2002 Michal Rokos <m.rokos@sh.cvut.cz>
5
4
  * All rights reserved.
6
5
  */
7
6
  /*
8
- * This program is licenced under the same licence as Ruby.
7
+ * This program is licensed under the same licence as Ruby.
9
8
  * (See the file 'LICENCE'.)
10
9
  */
11
10
  #include "ossl.h"
@@ -556,6 +555,20 @@ static void Init_ossl_locks(void)
556
555
  * OpenSSL provides SSL, TLS and general purpose cryptography. It wraps the
557
556
  * OpenSSL[http://www.openssl.org/] library.
558
557
  *
558
+ * = Install
559
+ *
560
+ * OpenSSL comes bundled with the Standard Library of Ruby.
561
+ *
562
+ * This means the OpenSSL extension is compiled with Ruby and packaged on
563
+ * build. During compile time, Ruby will need to link against the OpenSSL
564
+ * library on your system. However, you cannot use openssl provided by Apple to
565
+ * build standard library openssl.
566
+ *
567
+ * If you use OSX, you should install another openssl and run ```./configure
568
+ * --with-openssl-dir=/path/to/another-openssl```. For Homebrew user, run `brew
569
+ * install openssl` and then ```./configure --with-openssl-dir=`brew --prefix
570
+ * openssl` ```.
571
+ *
559
572
  * = Examples
560
573
  *
561
574
  * All examples assume you have loaded OpenSSL with:
@@ -1165,4 +1178,3 @@ main(int argc, char *argv[])
1165
1178
  return 0;
1166
1179
  }
1167
1180
  #endif /* OSSL_DEBUG */
1168
-
@@ -1,11 +1,10 @@
1
1
  /*
2
- * $Id: ossl.h 44582 2014-01-13 00:57:42Z nobu $
3
2
  * 'OpenSSL for Ruby' project
4
3
  * Copyright (C) 2001-2002 Michal Rokos <m.rokos@sh.cvut.cz>
5
4
  * All rights reserved.
6
5
  */
7
6
  /*
8
- * This program is licenced under the same licence as Ruby.
7
+ * This program is licensed under the same licence as Ruby.
9
8
  * (See the file 'LICENCE'.)
10
9
  */
11
10
  #if !defined(_OSSL_H_)
@@ -45,7 +44,7 @@ extern "C" {
45
44
  # define assert(condition)
46
45
  #endif
47
46
 
48
- #if defined(_WIN32)
47
+ #if defined(_WIN32) && !defined(LIBRESSL_VERSION_NUMBER)
49
48
  # include <openssl/e_os2.h>
50
49
  # define OSSL_NO_CONF_API 1
51
50
  # if !defined(OPENSSL_SYS_WIN32)
@@ -64,6 +63,9 @@ extern "C" {
64
63
  #include <openssl/rand.h>
65
64
  #include <openssl/conf.h>
66
65
  #include <openssl/conf_api.h>
66
+ #if !defined(_WIN32)
67
+ # include <openssl/crypto.h>
68
+ #endif
67
69
  #undef X509_NAME
68
70
  #undef PKCS7_SIGNER_INFO
69
71
  #if defined(HAVE_OPENSSL_ENGINE_H) && defined(HAVE_EVP_CIPHER_CTX_ENGINE)
@@ -244,4 +246,3 @@ void Init_openssl(void);
244
246
  #endif
245
247
 
246
248
  #endif /* _OSSL_H_ */
247
-
@@ -1,11 +1,10 @@
1
1
  /*
2
- * $Id: ossl_asn1.c 47744 2014-09-30 05:25:32Z nobu $
3
2
  * 'OpenSSL for Ruby' team members
4
3
  * Copyright (C) 2003
5
4
  * All rights reserved.
6
5
  */
7
6
  /*
8
- * This program is licenced under the same licence as Ruby.
7
+ * This program is licensed under the same licence as Ruby.
9
8
  * (See the file 'LICENCE'.)
10
9
  */
11
10
  #include "ossl.h"
@@ -1029,7 +1028,7 @@ static VALUE
1029
1028
  ossl_asn1_traverse(VALUE self, VALUE obj)
1030
1029
  {
1031
1030
  unsigned char *p;
1032
- volatile VALUE tmp;
1031
+ VALUE tmp;
1033
1032
  long len, read = 0, offset = 0;
1034
1033
 
1035
1034
  obj = ossl_to_der_if_possible(obj);
@@ -1037,6 +1036,7 @@ ossl_asn1_traverse(VALUE self, VALUE obj)
1037
1036
  p = (unsigned char *)RSTRING_PTR(tmp);
1038
1037
  len = RSTRING_LEN(tmp);
1039
1038
  ossl_asn1_decode0(&p, len, &offset, 0, 1, &read);
1039
+ RB_GC_GUARD(tmp);
1040
1040
  int_ossl_decode_sanity_check(len, read, offset);
1041
1041
  return Qnil;
1042
1042
  }
@@ -1058,7 +1058,7 @@ ossl_asn1_decode(VALUE self, VALUE obj)
1058
1058
  {
1059
1059
  VALUE ret;
1060
1060
  unsigned char *p;
1061
- volatile VALUE tmp;
1061
+ VALUE tmp;
1062
1062
  long len, read = 0, offset = 0;
1063
1063
 
1064
1064
  obj = ossl_to_der_if_possible(obj);
@@ -1066,6 +1066,7 @@ ossl_asn1_decode(VALUE self, VALUE obj)
1066
1066
  p = (unsigned char *)RSTRING_PTR(tmp);
1067
1067
  len = RSTRING_LEN(tmp);
1068
1068
  ret = ossl_asn1_decode0(&p, len, &offset, 0, 0, &read);
1069
+ RB_GC_GUARD(tmp);
1069
1070
  int_ossl_decode_sanity_check(len, read, offset);
1070
1071
  return ret;
1071
1072
  }
@@ -1089,7 +1090,7 @@ ossl_asn1_decode_all(VALUE self, VALUE obj)
1089
1090
  VALUE ary, val;
1090
1091
  unsigned char *p;
1091
1092
  long len, tmp_len = 0, read = 0, offset = 0;
1092
- volatile VALUE tmp;
1093
+ VALUE tmp;
1093
1094
 
1094
1095
  obj = ossl_to_der_if_possible(obj);
1095
1096
  tmp = rb_str_new4(StringValue(obj));
@@ -1104,6 +1105,7 @@ ossl_asn1_decode_all(VALUE self, VALUE obj)
1104
1105
  read += tmp_read;
1105
1106
  tmp_len -= tmp_read;
1106
1107
  }
1108
+ RB_GC_GUARD(tmp);
1107
1109
  int_ossl_decode_sanity_check(len, read, offset);
1108
1110
  return ary;
1109
1111
  }
@@ -1360,13 +1362,13 @@ ossl_asn1cons_each(VALUE self)
1360
1362
 
1361
1363
  /*
1362
1364
  * call-seq:
1363
- * ObjectId.register(object_id, short_name, long_name)
1365
+ * OpenSSL::ASN1::ObjectId.register(object_id, short_name, long_name)
1364
1366
  *
1365
1367
  * This adds a new ObjectId to the internal tables. Where +object_id+ is the
1366
1368
  * numerical form, +short_name+ is the short name, and +long_name+ is the long
1367
1369
  * name.
1368
1370
  *
1369
- * Returns +true+ if successful. Raises an ASN1Error otherwise.
1371
+ * Returns +true+ if successful. Raises an OpenSSL::ASN1::ASN1Error if it fails.
1370
1372
  *
1371
1373
  */
1372
1374
  static VALUE
@@ -1384,11 +1386,11 @@ ossl_asn1obj_s_register(VALUE self, VALUE oid, VALUE sn, VALUE ln)
1384
1386
 
1385
1387
  /* Document-method: OpenSSL::ASN1::ObjectId#sn
1386
1388
  *
1387
- * The short name of the ObjectId, as defined in +openssl/objects.h+.
1389
+ * The short name of the ObjectId, as defined in <openssl/objects.h>.
1388
1390
  */
1389
1391
  /* Document-method: OpenSSL::ASN1::ObjectId#short_name
1390
1392
  *
1391
- * #short_name is an alias to #sn
1393
+ * +short_name+ is an alias to +sn+
1392
1394
  */
1393
1395
  static VALUE
1394
1396
  ossl_asn1obj_get_sn(VALUE self)
@@ -1405,11 +1407,11 @@ ossl_asn1obj_get_sn(VALUE self)
1405
1407
 
1406
1408
  /* Document-method: OpenSSL::ASN1::ObjectId#ln
1407
1409
  *
1408
- * The long name of the ObjectId, as defined in +openssl/objects.h+.
1410
+ * The long name of the ObjectId, as defined in <openssl/objects.h>.
1409
1411
  */
1410
- /* Document-method: OpenSSL::ASN1::ObjectId.long_name
1412
+ /* Document-method: OpenSSL::ASN1::ObjectId#long_name
1411
1413
  *
1412
- * #long_name is an alias to #ln
1414
+ * +long_name+ is an alias to +ln+
1413
1415
  */
1414
1416
  static VALUE
1415
1417
  ossl_asn1obj_get_ln(VALUE self)
@@ -1426,7 +1428,7 @@ ossl_asn1obj_get_ln(VALUE self)
1426
1428
 
1427
1429
  /* Document-method: OpenSSL::ASN1::ObjectId#oid
1428
1430
  *
1429
- * The object identifier as a String.
1431
+ * The object identifier as a +String+, e.g. "1.2.3.4.5"
1430
1432
  */
1431
1433
  static VALUE
1432
1434
  ossl_asn1obj_get_oid(VALUE self)
@@ -1809,6 +1811,10 @@ Init_ossl_asn1(void)
1809
1811
  *
1810
1812
  * == OpenSSL::ASN1::ObjectId
1811
1813
  *
1814
+ * NOTE: While OpenSSL::ASN1::ObjectId.new will allocate a new ObjectId,
1815
+ * it is not typically allocated this way, but rather that are received from
1816
+ * parsed ASN1 encodings.
1817
+ *
1812
1818
  * While OpenSSL::ASN1::ObjectId.new will allocate a new ObjectId, it is
1813
1819
  * not typically allocated this way, but rather that are received from
1814
1820
  * parsed ASN1 encodings.
@@ -1,11 +1,10 @@
1
1
  /*
2
- * $Id: ossl_asn1.h 27437 2010-04-22 08:04:13Z nobu $
3
2
  * 'OpenSSL for Ruby' team members
4
3
  * Copyright (C) 2003
5
4
  * All rights reserved.
6
5
  */
7
6
  /*
8
- * This program is licenced under the same licence as Ruby.
7
+ * This program is licensed under the same licence as Ruby.
9
8
  * (See the file 'LICENCE'.)
10
9
  */
11
10
  #if !defined(_OSSL_ASN1_H_)
@@ -1,11 +1,10 @@
1
1
  /*
2
- * $Id: ossl_bio.c 47042 2014-08-03 01:56:01Z nobu $
3
2
  * 'OpenSSL for Ruby' team members
4
3
  * Copyright (C) 2003
5
4
  * All rights reserved.
6
5
  */
7
6
  /*
8
- * This program is licenced under the same licence as Ruby.
7
+ * This program is licensed under the same licence as Ruby.
9
8
  * (See the file 'LICENCE'.)
10
9
  */
11
10
  #include "ossl.h"
@@ -1,11 +1,10 @@
1
1
  /*
2
- * $Id: ossl_bio.h 25189 2009-10-02 12:04:37Z akr $
3
2
  * 'OpenSSL for Ruby' team members
4
3
  * Copyright (C) 2003
5
4
  * All rights reserved.
6
5
  */
7
6
  /*
8
- * This program is licenced under the same licence as Ruby.
7
+ * This program is licensed under the same licence as Ruby.
9
8
  * (See the file 'LICENCE'.)
10
9
  */
11
10
  #if !defined(_OSSL_BIO_H_)
@@ -18,4 +17,3 @@ VALUE ossl_membio2str(BIO*);
18
17
  VALUE ossl_protect_membio2str(BIO*,int*);
19
18
 
20
19
  #endif
21
-
@@ -1,21 +1,22 @@
1
1
  /*
2
- * $Id: ossl_bn.c 48662 2014-12-01 06:38:04Z nobu $
3
2
  * 'OpenSSL for Ruby' project
4
3
  * Copyright (C) 2001-2002 Technorama team <oss-ruby@technorama.net>
5
4
  * All rights reserved.
6
5
  */
7
6
  /*
8
- * This program is licenced under the same licence as Ruby.
7
+ * This program is licensed under the same licence as Ruby.
9
8
  * (See the file 'LICENCE'.)
10
9
  */
11
10
  /* modified by Michal Rokos <m.rokos@sh.cvut.cz> */
12
11
  #include "ossl.h"
13
12
 
14
- #define WrapBN(klass, obj, bn) do { \
13
+ #define NewBN(klass) \
14
+ TypedData_Wrap_Struct((klass), &ossl_bn_type, 0)
15
+ #define SetBN(obj, bn) do { \
15
16
  if (!(bn)) { \
16
17
  ossl_raise(rb_eRuntimeError, "BN wasn't initialized!"); \
17
18
  } \
18
- (obj) = TypedData_Wrap_Struct((klass), &ossl_bn_type, (bn)); \
19
+ RTYPEDDATA_DATA(obj) = (bn); \
19
20
  } while (0)
20
21
 
21
22
  #define GetBN(obj, bn) do { \
@@ -53,6 +54,13 @@ static const rb_data_type_t ossl_bn_type = {
53
54
  * Classes
54
55
  */
55
56
  VALUE cBN;
57
+
58
+ /* Document-class: OpenSSL::BNError
59
+ *
60
+ * BNError < OpenSSLError
61
+ *
62
+ * Generic Error for all of OpenSSL::BN (big num)
63
+ */
56
64
  VALUE eBNError;
57
65
 
58
66
  /*
@@ -64,11 +72,12 @@ ossl_bn_new(const BIGNUM *bn)
64
72
  BIGNUM *newbn;
65
73
  VALUE obj;
66
74
 
75
+ obj = NewBN(cBN);
67
76
  newbn = bn ? BN_dup(bn) : BN_new();
68
77
  if (!newbn) {
69
78
  ossl_raise(eBNError, NULL);
70
79
  }
71
- WrapBN(cBN, obj, newbn);
80
+ SetBN(obj, newbn);
72
81
 
73
82
  return obj;
74
83
  }
@@ -77,6 +86,7 @@ BIGNUM *
77
86
  GetBNPtr(VALUE obj)
78
87
  {
79
88
  BIGNUM *bn = NULL;
89
+ VALUE newobj;
80
90
 
81
91
  if (RTEST(rb_obj_is_kind_of(obj, cBN))) {
82
92
  GetBN(obj, bn);
@@ -84,10 +94,11 @@ GetBNPtr(VALUE obj)
84
94
  case T_FIXNUM:
85
95
  case T_BIGNUM:
86
96
  obj = rb_String(obj);
97
+ newobj = NewBN(cBN); /* GC bug */
87
98
  if (!BN_dec2bn(&bn, StringValuePtr(obj))) {
88
99
  ossl_raise(eBNError, NULL);
89
100
  }
90
- WrapBN(cBN, obj, bn); /* Handle potencial mem leaks */
101
+ SetBN(newobj, bn); /* Handle potencial mem leaks */
91
102
  break;
92
103
  case T_NIL:
93
104
  break;
@@ -111,23 +122,25 @@ static VALUE
111
122
  ossl_bn_alloc(VALUE klass)
112
123
  {
113
124
  BIGNUM *bn;
114
- VALUE obj;
125
+ VALUE obj = NewBN(klass);
115
126
 
116
127
  if (!(bn = BN_new())) {
117
128
  ossl_raise(eBNError, NULL);
118
129
  }
119
- WrapBN(klass, obj, bn);
130
+ SetBN(obj, bn);
120
131
 
121
132
  return obj;
122
133
  }
123
134
 
124
- /*
125
- * call-seq:
126
- * BN.new => aBN
127
- * BN.new(bn) => aBN
128
- * BN.new(integer) => aBN
129
- * BN.new(string) => aBN
130
- * BN.new(string, 0 | 2 | 10 | 16) => aBN
135
+ /* Document-method: OpenSSL::BN.new
136
+ *
137
+ * OpenSSL::BN.new => aBN
138
+ * OpenSSL::BN.new(bn) => aBN
139
+ * OpenSSL::BN.new(integer) => aBN
140
+ * OpenSSL::BN.new(string) => aBN
141
+ * OpenSSL::BN.new(string, 0 | 2 | 10 | 16) => aBN
142
+ *
143
+ * Construct a new OpenSSL BigNum object.
131
144
  */
132
145
  static VALUE
133
146
  ossl_bn_initialize(int argc, VALUE *argv, VALUE self)
@@ -320,11 +333,6 @@ ossl_bn_coerce(VALUE self, VALUE other)
320
333
  }
321
334
 
322
335
  #define BIGNUM_BOOL1(func) \
323
- /* \
324
- * call-seq: \
325
- * bn.##func -> true | false \
326
- * \
327
- */ \
328
336
  static VALUE \
329
337
  ossl_bn_##func(VALUE self) \
330
338
  { \
@@ -335,22 +343,33 @@ ossl_bn_coerce(VALUE self, VALUE other)
335
343
  } \
336
344
  return Qfalse; \
337
345
  }
346
+
347
+ /*
348
+ * Document-method: OpenSSL::BN#zero?
349
+ * bn.zero? => true | false
350
+ */
338
351
  BIGNUM_BOOL1(is_zero)
352
+
353
+ /*
354
+ * Document-method: OpenSSL::BN#one?
355
+ * bn.one? => true | false
356
+ */
339
357
  BIGNUM_BOOL1(is_one)
358
+
359
+ /*
360
+ * Document-method: OpenSSL::BN#odd?
361
+ * bn.odd? => true | false
362
+ */
340
363
  BIGNUM_BOOL1(is_odd)
341
364
 
342
365
  #define BIGNUM_1c(func) \
343
- /* \
344
- * call-seq: \
345
- * bn.##func -> aBN \
346
- * \
347
- */ \
348
366
  static VALUE \
349
367
  ossl_bn_##func(VALUE self) \
350
368
  { \
351
369
  BIGNUM *bn, *result; \
352
370
  VALUE obj; \
353
371
  GetBN(self, bn); \
372
+ obj = NewBN(CLASS_OF(self)); \
354
373
  if (!(result = BN_new())) { \
355
374
  ossl_raise(eBNError, NULL); \
356
375
  } \
@@ -358,23 +377,24 @@ BIGNUM_BOOL1(is_odd)
358
377
  BN_free(result); \
359
378
  ossl_raise(eBNError, NULL); \
360
379
  } \
361
- WrapBN(CLASS_OF(self), obj, result); \
380
+ SetBN(obj, result); \
362
381
  return obj; \
363
382
  }
383
+
384
+ /*
385
+ * Document-method: OpenSSL::BN#sqr
386
+ * bn.sqr => aBN
387
+ */
364
388
  BIGNUM_1c(sqr)
365
389
 
366
390
  #define BIGNUM_2(func) \
367
- /* \
368
- * call-seq: \
369
- * bn.##func(bn2) -> aBN \
370
- * \
371
- */ \
372
391
  static VALUE \
373
392
  ossl_bn_##func(VALUE self, VALUE other) \
374
393
  { \
375
394
  BIGNUM *bn1, *bn2 = GetBNPtr(other), *result; \
376
395
  VALUE obj; \
377
396
  GetBN(self, bn1); \
397
+ obj = NewBN(CLASS_OF(self)); \
378
398
  if (!(result = BN_new())) { \
379
399
  ossl_raise(eBNError, NULL); \
380
400
  } \
@@ -382,24 +402,30 @@ BIGNUM_1c(sqr)
382
402
  BN_free(result); \
383
403
  ossl_raise(eBNError, NULL); \
384
404
  } \
385
- WrapBN(CLASS_OF(self), obj, result); \
405
+ SetBN(obj, result); \
386
406
  return obj; \
387
407
  }
408
+
409
+ /*
410
+ * Document-method: OpenSSL::BN#+
411
+ * bn + bn2 => aBN
412
+ */
388
413
  BIGNUM_2(add)
414
+
415
+ /*
416
+ * Document-method: OpenSSL::BN#-
417
+ * bn - bn2 => aBN
418
+ */
389
419
  BIGNUM_2(sub)
390
420
 
391
421
  #define BIGNUM_2c(func) \
392
- /* \
393
- * call-seq: \
394
- * bn.##func(bn2) -> aBN \
395
- * \
396
- */ \
397
422
  static VALUE \
398
423
  ossl_bn_##func(VALUE self, VALUE other) \
399
424
  { \
400
425
  BIGNUM *bn1, *bn2 = GetBNPtr(other), *result; \
401
426
  VALUE obj; \
402
427
  GetBN(self, bn1); \
428
+ obj = NewBN(CLASS_OF(self)); \
403
429
  if (!(result = BN_new())) { \
404
430
  ossl_raise(eBNError, NULL); \
405
431
  } \
@@ -407,19 +433,51 @@ BIGNUM_2(sub)
407
433
  BN_free(result); \
408
434
  ossl_raise(eBNError, NULL); \
409
435
  } \
410
- WrapBN(CLASS_OF(self), obj, result); \
436
+ SetBN(obj, result); \
411
437
  return obj; \
412
438
  }
439
+
440
+ /*
441
+ * Document-method: OpenSSL::BN#*
442
+ * bn * bn2 => aBN
443
+ */
413
444
  BIGNUM_2c(mul)
445
+
446
+ /*
447
+ * Document-method: OpenSSL::BN#%
448
+ * bn % bn2 => aBN
449
+ */
414
450
  BIGNUM_2c(mod)
451
+
452
+ /*
453
+ * Document-method: OpenSSL::BN#**
454
+ * bn ** bn2 => aBN
455
+ */
415
456
  BIGNUM_2c(exp)
457
+
458
+ /*
459
+ * Document-method: OpenSSL::BN#gcd
460
+ * bn.gcd(bn2) => aBN
461
+ */
416
462
  BIGNUM_2c(gcd)
463
+
464
+ /*
465
+ * Document-method: OpenSSL::BN#mod_sqr
466
+ * bn.mod_sqr(bn2) => aBN
467
+ */
417
468
  BIGNUM_2c(mod_sqr)
469
+
470
+ /*
471
+ * Document-method: OpenSSL::BN#mod_inverse
472
+ * bn.mod_inverse(bn2) => aBN
473
+ */
418
474
  BIGNUM_2c(mod_inverse)
419
475
 
420
476
  /*
421
- * call-seq:
477
+ * Document-method: OpenSSL::BN#/
422
478
  * bn1 / bn2 => [result, remainder]
479
+ *
480
+ * Division of OpenSSL::BN instances
423
481
  */
424
482
  static VALUE
425
483
  ossl_bn_div(VALUE self, VALUE other)
@@ -429,6 +487,8 @@ ossl_bn_div(VALUE self, VALUE other)
429
487
 
430
488
  GetBN(self, bn1);
431
489
 
490
+ obj1 = NewBN(CLASS_OF(self));
491
+ obj2 = NewBN(CLASS_OF(self));
432
492
  if (!(r1 = BN_new())) {
433
493
  ossl_raise(eBNError, NULL);
434
494
  }
@@ -441,18 +501,13 @@ ossl_bn_div(VALUE self, VALUE other)
441
501
  BN_free(r2);
442
502
  ossl_raise(eBNError, NULL);
443
503
  }
444
- WrapBN(CLASS_OF(self), obj1, r1);
445
- WrapBN(CLASS_OF(self), obj2, r2);
504
+ SetBN(obj1, r1);
505
+ SetBN(obj2, r2);
446
506
 
447
507
  return rb_ary_new3(2, obj1, obj2);
448
508
  }
449
509
 
450
510
  #define BIGNUM_3c(func) \
451
- /* \
452
- * call-seq: \
453
- * bn.##func(bn1, bn2) -> aBN \
454
- * \
455
- */ \
456
511
  static VALUE \
457
512
  ossl_bn_##func(VALUE self, VALUE other1, VALUE other2) \
458
513
  { \
@@ -460,6 +515,7 @@ ossl_bn_div(VALUE self, VALUE other)
460
515
  BIGNUM *bn3 = GetBNPtr(other2), *result; \
461
516
  VALUE obj; \
462
517
  GetBN(self, bn1); \
518
+ obj = NewBN(CLASS_OF(self)); \
463
519
  if (!(result = BN_new())) { \
464
520
  ossl_raise(eBNError, NULL); \
465
521
  } \
@@ -467,20 +523,35 @@ ossl_bn_div(VALUE self, VALUE other)
467
523
  BN_free(result); \
468
524
  ossl_raise(eBNError, NULL); \
469
525
  } \
470
- WrapBN(CLASS_OF(self), obj, result); \
526
+ SetBN(obj, result); \
471
527
  return obj; \
472
528
  }
529
+
530
+ /*
531
+ * Document-method: OpenSSL::BN#mod_add
532
+ * bn.mod_add(bn1, bn2) -> aBN
533
+ */
473
534
  BIGNUM_3c(mod_add)
535
+
536
+ /*
537
+ * Document-method: OpenSSL::BN#mod_sub
538
+ * bn.mod_sub(bn1, bn2) -> aBN
539
+ */
474
540
  BIGNUM_3c(mod_sub)
541
+
542
+ /*
543
+ * Document-method: OpenSSL::BN#mod_mul
544
+ * bn.mod_mul(bn1, bn2) -> aBN
545
+ */
475
546
  BIGNUM_3c(mod_mul)
547
+
548
+ /*
549
+ * Document-method: OpenSSL::BN#mod_exp
550
+ * bn.mod_exp(bn1, bn2) -> aBN
551
+ */
476
552
  BIGNUM_3c(mod_exp)
477
553
 
478
554
  #define BIGNUM_BIT(func) \
479
- /* \
480
- * call-seq: \
481
- * bn.##func(bit) -> self \
482
- * \
483
- */ \
484
555
  static VALUE \
485
556
  ossl_bn_##func(VALUE self, VALUE bit) \
486
557
  { \
@@ -491,13 +562,32 @@ BIGNUM_3c(mod_exp)
491
562
  } \
492
563
  return self; \
493
564
  }
565
+
566
+ /*
567
+ * Document-method: OpenSSL::BN#set_bit!
568
+ * bn.set_bit!(bit) -> self
569
+ */
494
570
  BIGNUM_BIT(set_bit)
571
+
572
+ /*
573
+ * Document-method: OpenSSL::BN#clear_bit!
574
+ * bn.clear_bit!(bit) -> self
575
+ */
495
576
  BIGNUM_BIT(clear_bit)
496
- BIGNUM_BIT(mask_bits)
497
577
 
498
578
  /*
499
- * call-seq:
579
+ * Document-method: OpenSSL::BN#mask_bit!
580
+ * bn.mask_bit!(bit) -> self
581
+ */
582
+ BIGNUM_BIT(mask_bits)
583
+
584
+ /* Document-method: OpenSSL::BN#bit_set?
585
+ *
586
+ * Returns boolean of whether +bit+ is set.
587
+ * Bitwise operations for openssl BIGNUMs.
588
+ *
500
589
  * bn.bit_set?(bit) => true | false
590
+ *
501
591
  */
502
592
  static VALUE
503
593
  ossl_bn_is_bit_set(VALUE self, VALUE bit)
@@ -514,11 +604,6 @@ ossl_bn_is_bit_set(VALUE self, VALUE bit)
514
604
  }
515
605
 
516
606
  #define BIGNUM_SHIFT(func) \
517
- /* \
518
- * call-seq: \
519
- * bn.##func(bits) -> aBN \
520
- * \
521
- */ \
522
607
  static VALUE \
523
608
  ossl_bn_##func(VALUE self, VALUE bits) \
524
609
  { \
@@ -527,6 +612,7 @@ ossl_bn_is_bit_set(VALUE self, VALUE bit)
527
612
  VALUE obj; \
528
613
  b = NUM2INT(bits); \
529
614
  GetBN(self, bn); \
615
+ obj = NewBN(CLASS_OF(self)); \
530
616
  if (!(result = BN_new())) { \
531
617
  ossl_raise(eBNError, NULL); \
532
618
  } \
@@ -534,18 +620,25 @@ ossl_bn_is_bit_set(VALUE self, VALUE bit)
534
620
  BN_free(result); \
535
621
  ossl_raise(eBNError, NULL); \
536
622
  } \
537
- WrapBN(CLASS_OF(self), obj, result); \
623
+ SetBN(obj, result); \
538
624
  return obj; \
539
625
  }
626
+
627
+ /*
628
+ * Document-method: OpenSSL::BN#<<
629
+ * call-seq:
630
+ * bn << bits -> aBN
631
+ */
540
632
  BIGNUM_SHIFT(lshift)
633
+
634
+ /*
635
+ * Document-method: OpenSSL::BN#>>
636
+ * call-seq:
637
+ * bn >> bits -> aBN
638
+ */
541
639
  BIGNUM_SHIFT(rshift)
542
640
 
543
641
  #define BIGNUM_SELF_SHIFT(func) \
544
- /* \
545
- * call-seq: \
546
- * bn.##func!(bits) -> self \
547
- * \
548
- */ \
549
642
  static VALUE \
550
643
  ossl_bn_self_##func(VALUE self, VALUE bits) \
551
644
  { \
@@ -557,15 +650,20 @@ BIGNUM_SHIFT(rshift)
557
650
  ossl_raise(eBNError, NULL); \
558
651
  return self; \
559
652
  }
653
+
654
+ /*
655
+ * Document-method: OpenSSL::BN#lshift!
656
+ * bn.lshift!(bits) -> self
657
+ */
560
658
  BIGNUM_SELF_SHIFT(lshift)
659
+
660
+ /*
661
+ * Document-method: OpenSSL::BN#rshift!
662
+ * bn.rshift!(bits) -> self
663
+ */
561
664
  BIGNUM_SELF_SHIFT(rshift)
562
665
 
563
666
  #define BIGNUM_RAND(func) \
564
- /* \
565
- * call-seq: \
566
- * BN.##func(bits [, fill [, odd]]) -> aBN \
567
- * \
568
- */ \
569
667
  static VALUE \
570
668
  ossl_bn_s_##func(int argc, VALUE *argv, VALUE klass) \
571
669
  { \
@@ -581,6 +679,7 @@ BIGNUM_SELF_SHIFT(rshift)
581
679
  top = NUM2INT(fill); \
582
680
  } \
583
681
  b = NUM2INT(bits); \
682
+ obj = NewBN(klass); \
584
683
  if (!(result = BN_new())) { \
585
684
  ossl_raise(eBNError, NULL); \
586
685
  } \
@@ -588,23 +687,28 @@ BIGNUM_SELF_SHIFT(rshift)
588
687
  BN_free(result); \
589
688
  ossl_raise(eBNError, NULL); \
590
689
  } \
591
- WrapBN(klass, obj, result); \
690
+ SetBN(obj, result); \
592
691
  return obj; \
593
692
  }
693
+
694
+ /*
695
+ * Document-method: OpenSSL::BN.rand
696
+ * BN.rand(bits [, fill [, odd]]) -> aBN
697
+ */
594
698
  BIGNUM_RAND(rand)
699
+
700
+ /*
701
+ * Document-method: OpenSSL::BN.pseudo_rand
702
+ * BN.pseudo_rand(bits [, fill [, odd]]) -> aBN
703
+ */
595
704
  BIGNUM_RAND(pseudo_rand)
596
705
 
597
706
  #define BIGNUM_RAND_RANGE(func) \
598
- /* \
599
- * call-seq: \
600
- * BN.##func(range) -> aBN \
601
- * \
602
- */ \
603
707
  static VALUE \
604
708
  ossl_bn_s_##func##_range(VALUE klass, VALUE range) \
605
709
  { \
606
710
  BIGNUM *bn = GetBNPtr(range), *result; \
607
- VALUE obj; \
711
+ VALUE obj = NewBN(klass); \
608
712
  if (!(result = BN_new())) { \
609
713
  ossl_raise(eBNError, NULL); \
610
714
  } \
@@ -612,10 +716,22 @@ BIGNUM_RAND(pseudo_rand)
612
716
  BN_free(result); \
613
717
  ossl_raise(eBNError, NULL); \
614
718
  } \
615
- WrapBN(klass, obj, result); \
719
+ SetBN(obj, result); \
616
720
  return obj; \
617
721
  }
722
+
723
+ /*
724
+ * Document-method: OpenSSL::BN.rand_range
725
+ * BN.rand_range(range) -> aBN
726
+ *
727
+ */
618
728
  BIGNUM_RAND_RANGE(rand)
729
+
730
+ /*
731
+ * Document-method: OpenSSL::BN.pseudo_rand_range
732
+ * BN.pseudo_rand_range(range) -> aBN
733
+ *
734
+ */
619
735
  BIGNUM_RAND_RANGE(pseudo_rand)
620
736
 
621
737
  /*
@@ -646,6 +762,7 @@ ossl_bn_s_generate_prime(int argc, VALUE *argv, VALUE klass)
646
762
  add = GetBNPtr(vadd);
647
763
  rem = NIL_P(vrem) ? NULL : GetBNPtr(vrem);
648
764
  }
765
+ obj = NewBN(klass);
649
766
  if (!(result = BN_new())) {
650
767
  ossl_raise(eBNError, NULL);
651
768
  }
@@ -653,17 +770,12 @@ ossl_bn_s_generate_prime(int argc, VALUE *argv, VALUE klass)
653
770
  BN_free(result);
654
771
  ossl_raise(eBNError, NULL);
655
772
  }
656
- WrapBN(klass, obj, result);
773
+ SetBN(obj, result);
657
774
 
658
775
  return obj;
659
776
  }
660
777
 
661
778
  #define BIGNUM_NUM(func) \
662
- /* \
663
- * call-seq: \
664
- * bn.##func -> integer \
665
- * \
666
- */ \
667
779
  static VALUE \
668
780
  ossl_bn_##func(VALUE self) \
669
781
  { \
@@ -671,7 +783,17 @@ ossl_bn_s_generate_prime(int argc, VALUE *argv, VALUE klass)
671
783
  GetBN(self, bn); \
672
784
  return INT2FIX(BN_##func(bn)); \
673
785
  }
786
+
787
+ /*
788
+ * Document-method: OpenSSL::BN#num_bytes
789
+ * bn.num_bytes => integer
790
+ */
674
791
  BIGNUM_NUM(num_bytes)
792
+
793
+ /*
794
+ * Document-method: OpenSSL::BN#num_bits
795
+ * bn.num_bits => integer
796
+ */
675
797
  BIGNUM_NUM(num_bits)
676
798
 
677
799
  static VALUE
@@ -693,11 +815,6 @@ ossl_bn_copy(VALUE self, VALUE other)
693
815
  }
694
816
 
695
817
  #define BIGNUM_CMP(func) \
696
- /* \
697
- * call-seq: \
698
- * bn.##func(bn2) -> integer \
699
- * \
700
- */ \
701
818
  static VALUE \
702
819
  ossl_bn_##func(VALUE self, VALUE other) \
703
820
  { \
@@ -705,9 +822,30 @@ ossl_bn_copy(VALUE self, VALUE other)
705
822
  GetBN(self, bn1); \
706
823
  return INT2FIX(BN_##func(bn1, bn2)); \
707
824
  }
825
+
826
+ /*
827
+ * Document-method: OpenSSL::BN#cmp
828
+ * bn.cmp(bn2) => integer
829
+ */
830
+ /*
831
+ * Document-method: OpenSSL::BN#<=>
832
+ * bn <=> bn2 => integer
833
+ */
708
834
  BIGNUM_CMP(cmp)
835
+
836
+ /*
837
+ * Document-method: OpenSSL::BN#ucmp
838
+ * bn.ucmp(bn2) => integer
839
+ */
709
840
  BIGNUM_CMP(ucmp)
710
841
 
842
+ /*
843
+ * call-seq:
844
+ * big.eql?(obj) => true or false
845
+ *
846
+ * Returns <code>true</code> only if <i>obj</i> is a
847
+ * <code>Bignum</code> with the same value as <i>big</i>. Contrast this
848
+ */
711
849
  static VALUE
712
850
  ossl_bn_eql(VALUE self, VALUE other)
713
851
  {
@@ -912,4 +1050,3 @@ Init_ossl_bn(void)
912
1050
  */
913
1051
  rb_define_method(cBN, "prime_fasttest?", ossl_bn_is_prime_fasttest, -1);
914
1052
  }
915
-