openssl 2.1.2 → 2.2.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 (51) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +9 -7
  3. data/History.md +77 -0
  4. data/README.md +2 -2
  5. data/ext/openssl/extconf.rb +24 -14
  6. data/ext/openssl/openssl_missing.h +37 -2
  7. data/ext/openssl/ossl.c +51 -25
  8. data/ext/openssl/ossl.h +8 -5
  9. data/ext/openssl/ossl_asn1.c +26 -1
  10. data/ext/openssl/ossl_bn.c +9 -3
  11. data/ext/openssl/ossl_cipher.c +33 -24
  12. data/ext/openssl/ossl_digest.c +16 -51
  13. data/ext/openssl/ossl_engine.c +2 -12
  14. data/ext/openssl/ossl_hmac.c +5 -11
  15. data/ext/openssl/ossl_kdf.c +3 -19
  16. data/ext/openssl/ossl_ns_spki.c +1 -1
  17. data/ext/openssl/ossl_ocsp.c +6 -11
  18. data/ext/openssl/ossl_ocsp.h +3 -3
  19. data/ext/openssl/ossl_pkcs7.c +3 -19
  20. data/ext/openssl/ossl_pkcs7.h +16 -0
  21. data/ext/openssl/ossl_pkey.c +180 -14
  22. data/ext/openssl/ossl_pkey.h +5 -5
  23. data/ext/openssl/ossl_pkey_dh.c +1 -1
  24. data/ext/openssl/ossl_pkey_dsa.c +2 -2
  25. data/ext/openssl/ossl_pkey_ec.c +29 -0
  26. data/ext/openssl/ossl_pkey_rsa.c +17 -9
  27. data/ext/openssl/ossl_rand.c +2 -40
  28. data/ext/openssl/ossl_ssl.c +109 -25
  29. data/ext/openssl/ossl_ts.c +1514 -0
  30. data/ext/openssl/ossl_ts.h +16 -0
  31. data/ext/openssl/ossl_x509.c +91 -0
  32. data/ext/openssl/ossl_x509cert.c +2 -2
  33. data/ext/openssl/ossl_x509ext.c +14 -0
  34. data/ext/openssl/ossl_x509name.c +8 -4
  35. data/ext/openssl/ossl_x509store.c +0 -2
  36. data/lib/openssl.rb +25 -9
  37. data/lib/openssl/bn.rb +1 -1
  38. data/lib/openssl/buffering.rb +33 -17
  39. data/lib/openssl/cipher.rb +1 -1
  40. data/lib/openssl/config.rb +53 -26
  41. data/lib/openssl/digest.rb +10 -12
  42. data/lib/openssl/hmac.rb +13 -0
  43. data/lib/openssl/marshal.rb +30 -0
  44. data/lib/openssl/pkcs5.rb +1 -1
  45. data/lib/openssl/pkey.rb +18 -1
  46. data/lib/openssl/ssl.rb +46 -7
  47. data/lib/openssl/version.rb +5 -0
  48. data/lib/openssl/x509.rb +155 -1
  49. metadata +8 -6
  50. data/ext/openssl/deprecation.rb +0 -23
  51. data/ext/openssl/ossl_version.h +0 -15
@@ -272,7 +272,7 @@ Init_ossl_kdf(void)
272
272
  * # store this with the generated value
273
273
  * salt = OpenSSL::Random.random_bytes(16)
274
274
  * iter = 20_000
275
- * hash = OpenSSL::Digest::SHA256.new
275
+ * hash = OpenSSL::Digest.new('SHA256')
276
276
  * len = hash.digest_length
277
277
  * # the final value to be stored
278
278
  * value = OpenSSL::KDF.pbkdf2_hmac(pass, salt: salt, iterations: iter,
@@ -284,24 +284,8 @@ Init_ossl_kdf(void)
284
284
  * Typically, "==" short-circuits on evaluation, and is therefore
285
285
  * vulnerable to timing attacks. The proper way is to use a method that
286
286
  * always takes the same amount of time when comparing two values, thus
287
- * not leaking any information to potential attackers. To compare two
288
- * values, the following could be used:
289
- *
290
- * def eql_time_cmp(a, b)
291
- * unless a.length == b.length
292
- * return false
293
- * end
294
- * cmp = b.bytes
295
- * result = 0
296
- * a.bytes.each_with_index {|c,i|
297
- * result |= c ^ cmp[i]
298
- * }
299
- * result == 0
300
- * end
301
- *
302
- * Please note that the premature return in case of differing lengths
303
- * typically does not leak valuable information - when using PBKDF2, the
304
- * length of the values to be compared is of fixed size.
287
+ * not leaking any information to potential attackers. To do this, use
288
+ * +OpenSSL.fixed_length_secure_compare+.
305
289
  */
306
290
  mKDF = rb_define_module_under(mOSSL, "KDF");
307
291
  /*
@@ -350,7 +350,7 @@ ossl_spki_verify(VALUE self, VALUE key)
350
350
  * spki = OpenSSL::Netscape::SPKI.new
351
351
  * spki.challenge = "RandomChallenge"
352
352
  * spki.public_key = key.public_key
353
- * spki.sign(key, OpenSSL::Digest::SHA256.new)
353
+ * spki.sign(key, OpenSSL::Digest.new('SHA256'))
354
354
  * #send a request containing this to a server generating a certificate
355
355
  * === Verifying an SPKI request
356
356
  * request = #...
@@ -1489,13 +1489,15 @@ ossl_ocspcid_initialize_copy(VALUE self, VALUE other)
1489
1489
  * call-seq:
1490
1490
  * OpenSSL::OCSP::CertificateId.new(subject, issuer, digest = nil) -> certificate_id
1491
1491
  * OpenSSL::OCSP::CertificateId.new(der_string) -> certificate_id
1492
+ * OpenSSL::OCSP::CertificateId.new(obj) -> certificate_id
1492
1493
  *
1493
1494
  * Creates a new OpenSSL::OCSP::CertificateId for the given _subject_ and
1494
1495
  * _issuer_ X509 certificates. The _digest_ is a digest algorithm that is used
1495
1496
  * to compute the hash values. This defaults to SHA-1.
1496
1497
  *
1497
1498
  * If only one argument is given, decodes it as DER representation of a
1498
- * certificate ID.
1499
+ * certificate ID or generates certificate ID from the object that responds to
1500
+ * the to_der method.
1499
1501
  */
1500
1502
  static VALUE
1501
1503
  ossl_ocspcid_initialize(int argc, VALUE *argv, VALUE self)
@@ -1717,7 +1719,7 @@ Init_ossl_ocsp(void)
1717
1719
  * subject certificate so the CA knows which certificate we are asking
1718
1720
  * about:
1719
1721
  *
1720
- * digest = OpenSSL::Digest::SHA1.new
1722
+ * digest = OpenSSL::Digest.new('SHA1')
1721
1723
  * certificate_id =
1722
1724
  * OpenSSL::OCSP::CertificateId.new subject, issuer, digest
1723
1725
  *
@@ -1734,18 +1736,11 @@ Init_ossl_ocsp(void)
1734
1736
  * To submit the request to the CA for verification we need to extract the
1735
1737
  * OCSP URI from the subject certificate:
1736
1738
  *
1737
- * authority_info_access = subject.extensions.find do |extension|
1738
- * extension.oid == 'authorityInfoAccess'
1739
- * end
1740
- *
1741
- * descriptions = authority_info_access.value.split "\n"
1742
- * ocsp = descriptions.find do |description|
1743
- * description.start_with? 'OCSP'
1744
- * end
1739
+ * ocsp_uris = subject.ocsp_uris
1745
1740
  *
1746
1741
  * require 'uri'
1747
1742
  *
1748
- * ocsp_uri = URI ocsp[/URI:(.*)/, 1]
1743
+ * ocsp_uri = URI ocsp_uris[0]
1749
1744
  *
1750
1745
  * To submit the request we'll POST the request to the OCSP URI (per RFC
1751
1746
  * 2560). Note that we only handle HTTP requests and don't handle any
@@ -13,9 +13,9 @@
13
13
 
14
14
  #if !defined(OPENSSL_NO_OCSP)
15
15
  extern VALUE mOCSP;
16
- extern VALUE cOPCSReq;
17
- extern VALUE cOPCSRes;
18
- extern VALUE cOPCSBasicRes;
16
+ extern VALUE cOCSPReq;
17
+ extern VALUE cOCSPRes;
18
+ extern VALUE cOCSPBasicRes;
19
19
  #endif
20
20
 
21
21
  void Init_ossl_ocsp(void);
@@ -9,21 +9,6 @@
9
9
  */
10
10
  #include "ossl.h"
11
11
 
12
- #define NewPKCS7(klass) \
13
- TypedData_Wrap_Struct((klass), &ossl_pkcs7_type, 0)
14
- #define SetPKCS7(obj, pkcs7) do { \
15
- if (!(pkcs7)) { \
16
- ossl_raise(rb_eRuntimeError, "PKCS7 wasn't initialized."); \
17
- } \
18
- RTYPEDDATA_DATA(obj) = (pkcs7); \
19
- } while (0)
20
- #define GetPKCS7(obj, pkcs7) do { \
21
- TypedData_Get_Struct((obj), PKCS7, &ossl_pkcs7_type, (pkcs7)); \
22
- if (!(pkcs7)) { \
23
- ossl_raise(rb_eRuntimeError, "PKCS7 wasn't initialized."); \
24
- } \
25
- } while (0)
26
-
27
12
  #define NewPKCS7si(klass) \
28
13
  TypedData_Wrap_Struct((klass), &ossl_pkcs7_signer_info_type, 0)
29
14
  #define SetPKCS7si(obj, p7si) do { \
@@ -75,7 +60,7 @@ ossl_pkcs7_free(void *ptr)
75
60
  PKCS7_free(ptr);
76
61
  }
77
62
 
78
- static const rb_data_type_t ossl_pkcs7_type = {
63
+ const rb_data_type_t ossl_pkcs7_type = {
79
64
  "OpenSSL/PKCS7",
80
65
  {
81
66
  0, ossl_pkcs7_free,
@@ -803,9 +788,9 @@ ossl_pkcs7_decrypt(int argc, VALUE *argv, VALUE self)
803
788
  BIO *out;
804
789
  VALUE str;
805
790
 
806
- rb_scan_args(argc, argv, "21", &pkey, &cert, &flags);
791
+ rb_scan_args(argc, argv, "12", &pkey, &cert, &flags);
807
792
  key = GetPrivPKeyPtr(pkey); /* NO NEED TO DUP */
808
- x509 = GetX509CertPtr(cert); /* NO NEED TO DUP */
793
+ x509 = NIL_P(cert) ? NULL : GetX509CertPtr(cert); /* NO NEED TO DUP */
809
794
  flg = NIL_P(flags) ? 0 : NUM2INT(flags);
810
795
  GetPKCS7(self, p7);
811
796
  if(!(out = BIO_new(BIO_s_mem())))
@@ -1088,7 +1073,6 @@ Init_ossl_pkcs7(void)
1088
1073
  rb_define_alloc_func(cPKCS7Signer, ossl_pkcs7si_alloc);
1089
1074
  rb_define_method(cPKCS7Signer, "initialize", ossl_pkcs7si_initialize,3);
1090
1075
  rb_define_method(cPKCS7Signer, "issuer", ossl_pkcs7si_get_issuer, 0);
1091
- rb_define_alias(cPKCS7Signer, "name", "issuer");
1092
1076
  rb_define_method(cPKCS7Signer, "serial", ossl_pkcs7si_get_serial,0);
1093
1077
  rb_define_method(cPKCS7Signer,"signed_time",ossl_pkcs7si_get_signed_time,0);
1094
1078
 
@@ -10,6 +10,22 @@
10
10
  #if !defined(_OSSL_PKCS7_H_)
11
11
  #define _OSSL_PKCS7_H_
12
12
 
13
+ #define NewPKCS7(klass) \
14
+ TypedData_Wrap_Struct((klass), &ossl_pkcs7_type, 0)
15
+ #define SetPKCS7(obj, pkcs7) do { \
16
+ if (!(pkcs7)) { \
17
+ ossl_raise(rb_eRuntimeError, "PKCS7 wasn't initialized."); \
18
+ } \
19
+ RTYPEDDATA_DATA(obj) = (pkcs7); \
20
+ } while (0)
21
+ #define GetPKCS7(obj, pkcs7) do { \
22
+ TypedData_Get_Struct((obj), PKCS7, &ossl_pkcs7_type, (pkcs7)); \
23
+ if (!(pkcs7)) { \
24
+ ossl_raise(rb_eRuntimeError, "PKCS7 wasn't initialized."); \
25
+ } \
26
+ } while (0)
27
+
28
+ extern const rb_data_type_t ossl_pkcs7_type;
13
29
  extern VALUE cPKCS7;
14
30
  extern VALUE cPKCS7Signer;
15
31
  extern VALUE cPKCS7Recipient;
@@ -167,21 +167,27 @@ ossl_pkey_new_from_data(int argc, VALUE *argv, VALUE self)
167
167
  pass = ossl_pem_passwd_value(pass);
168
168
 
169
169
  bio = ossl_obj2bio(&data);
170
- if (!(pkey = d2i_PrivateKey_bio(bio, NULL))) {
171
- OSSL_BIO_reset(bio);
172
- if (!(pkey = PEM_read_bio_PrivateKey(bio, NULL, ossl_pem_passwd_cb, (void *)pass))) {
173
- OSSL_BIO_reset(bio);
174
- if (!(pkey = d2i_PUBKEY_bio(bio, NULL))) {
175
- OSSL_BIO_reset(bio);
176
- pkey = PEM_read_bio_PUBKEY(bio, NULL, ossl_pem_passwd_cb, (void *)pass);
177
- }
178
- }
179
- }
170
+ if ((pkey = d2i_PrivateKey_bio(bio, NULL)))
171
+ goto ok;
172
+ OSSL_BIO_reset(bio);
173
+ if ((pkey = d2i_PKCS8PrivateKey_bio(bio, NULL, ossl_pem_passwd_cb, (void *)pass)))
174
+ goto ok;
175
+ OSSL_BIO_reset(bio);
176
+ if ((pkey = d2i_PUBKEY_bio(bio, NULL)))
177
+ goto ok;
178
+ OSSL_BIO_reset(bio);
179
+ /* PEM_read_bio_PrivateKey() also parses PKCS #8 formats */
180
+ if ((pkey = PEM_read_bio_PrivateKey(bio, NULL, ossl_pem_passwd_cb, (void *)pass)))
181
+ goto ok;
182
+ OSSL_BIO_reset(bio);
183
+ if ((pkey = PEM_read_bio_PUBKEY(bio, NULL, NULL, NULL)))
184
+ goto ok;
180
185
 
181
186
  BIO_free(bio);
182
- if (!pkey)
183
- ossl_raise(ePKeyError, "Could not parse PKey");
187
+ ossl_raise(ePKeyError, "Could not parse PKey");
184
188
 
189
+ ok:
190
+ BIO_free(bio);
185
191
  return ossl_pkey_new(pkey);
186
192
  }
187
193
 
@@ -293,6 +299,160 @@ ossl_pkey_initialize(VALUE self)
293
299
  return self;
294
300
  }
295
301
 
302
+ /*
303
+ * call-seq:
304
+ * pkey.oid -> string
305
+ *
306
+ * Returns the short name of the OID associated with _pkey_.
307
+ */
308
+ static VALUE
309
+ ossl_pkey_oid(VALUE self)
310
+ {
311
+ EVP_PKEY *pkey;
312
+ int nid;
313
+
314
+ GetPKey(self, pkey);
315
+ nid = EVP_PKEY_id(pkey);
316
+ return rb_str_new_cstr(OBJ_nid2sn(nid));
317
+ }
318
+
319
+ /*
320
+ * call-seq:
321
+ * pkey.inspect -> string
322
+ *
323
+ * Returns a string describing the PKey object.
324
+ */
325
+ static VALUE
326
+ ossl_pkey_inspect(VALUE self)
327
+ {
328
+ EVP_PKEY *pkey;
329
+ int nid;
330
+
331
+ GetPKey(self, pkey);
332
+ nid = EVP_PKEY_id(pkey);
333
+ return rb_sprintf("#<%"PRIsVALUE":%p oid=%s>",
334
+ rb_class_name(CLASS_OF(self)), (void *)self,
335
+ OBJ_nid2sn(nid));
336
+ }
337
+
338
+ static VALUE
339
+ do_pkcs8_export(int argc, VALUE *argv, VALUE self, int to_der)
340
+ {
341
+ EVP_PKEY *pkey;
342
+ VALUE cipher, pass;
343
+ const EVP_CIPHER *enc = NULL;
344
+ BIO *bio;
345
+
346
+ GetPKey(self, pkey);
347
+ rb_scan_args(argc, argv, "02", &cipher, &pass);
348
+ if (argc > 0) {
349
+ /*
350
+ * TODO: EncryptedPrivateKeyInfo actually has more options.
351
+ * Should they be exposed?
352
+ */
353
+ enc = ossl_evp_get_cipherbyname(cipher);
354
+ pass = ossl_pem_passwd_value(pass);
355
+ }
356
+
357
+ bio = BIO_new(BIO_s_mem());
358
+ if (!bio)
359
+ ossl_raise(ePKeyError, "BIO_new");
360
+ if (to_der) {
361
+ if (!i2d_PKCS8PrivateKey_bio(bio, pkey, enc, NULL, 0,
362
+ ossl_pem_passwd_cb, (void *)pass)) {
363
+ BIO_free(bio);
364
+ ossl_raise(ePKeyError, "i2d_PKCS8PrivateKey_bio");
365
+ }
366
+ }
367
+ else {
368
+ if (!PEM_write_bio_PKCS8PrivateKey(bio, pkey, enc, NULL, 0,
369
+ ossl_pem_passwd_cb, (void *)pass)) {
370
+ BIO_free(bio);
371
+ ossl_raise(ePKeyError, "PEM_write_bio_PKCS8PrivateKey");
372
+ }
373
+ }
374
+ return ossl_membio2str(bio);
375
+ }
376
+
377
+ /*
378
+ * call-seq:
379
+ * pkey.private_to_der -> string
380
+ * pkey.private_to_der(cipher, password) -> string
381
+ *
382
+ * Serializes the private key to DER-encoded PKCS #8 format. If called without
383
+ * arguments, unencrypted PKCS #8 PrivateKeyInfo format is used. If called with
384
+ * a cipher name and a password, PKCS #8 EncryptedPrivateKeyInfo format with
385
+ * PBES2 encryption scheme is used.
386
+ */
387
+ static VALUE
388
+ ossl_pkey_private_to_der(int argc, VALUE *argv, VALUE self)
389
+ {
390
+ return do_pkcs8_export(argc, argv, self, 1);
391
+ }
392
+
393
+ /*
394
+ * call-seq:
395
+ * pkey.private_to_pem -> string
396
+ * pkey.private_to_pem(cipher, password) -> string
397
+ *
398
+ * Serializes the private key to PEM-encoded PKCS #8 format. See #private_to_der
399
+ * for more details.
400
+ */
401
+ static VALUE
402
+ ossl_pkey_private_to_pem(int argc, VALUE *argv, VALUE self)
403
+ {
404
+ return do_pkcs8_export(argc, argv, self, 0);
405
+ }
406
+
407
+ static VALUE
408
+ do_spki_export(VALUE self, int to_der)
409
+ {
410
+ EVP_PKEY *pkey;
411
+ BIO *bio;
412
+
413
+ GetPKey(self, pkey);
414
+ bio = BIO_new(BIO_s_mem());
415
+ if (!bio)
416
+ ossl_raise(ePKeyError, "BIO_new");
417
+ if (to_der) {
418
+ if (!i2d_PUBKEY_bio(bio, pkey)) {
419
+ BIO_free(bio);
420
+ ossl_raise(ePKeyError, "i2d_PUBKEY_bio");
421
+ }
422
+ }
423
+ else {
424
+ if (!PEM_write_bio_PUBKEY(bio, pkey)) {
425
+ BIO_free(bio);
426
+ ossl_raise(ePKeyError, "PEM_write_bio_PUBKEY");
427
+ }
428
+ }
429
+ return ossl_membio2str(bio);
430
+ }
431
+
432
+ /*
433
+ * call-seq:
434
+ * pkey.public_to_der -> string
435
+ *
436
+ * Serializes the public key to DER-encoded X.509 SubjectPublicKeyInfo format.
437
+ */
438
+ static VALUE
439
+ ossl_pkey_public_to_der(VALUE self)
440
+ {
441
+ return do_spki_export(self, 1);
442
+ }
443
+
444
+ /*
445
+ * call-seq:
446
+ * pkey.public_to_pem -> string
447
+ *
448
+ * Serializes the public key to PEM-encoded X.509 SubjectPublicKeyInfo format.
449
+ */
450
+ static VALUE
451
+ ossl_pkey_public_to_pem(VALUE self)
452
+ {
453
+ return do_spki_export(self, 0);
454
+ }
455
+
296
456
  /*
297
457
  * call-seq:
298
458
  * pkey.sign(digest, data) -> String
@@ -306,7 +466,7 @@ ossl_pkey_initialize(VALUE self)
306
466
  *
307
467
  * == Example
308
468
  * data = 'Sign me!'
309
- * digest = OpenSSL::Digest::SHA256.new
469
+ * digest = OpenSSL::Digest.new('SHA256')
310
470
  * pkey = OpenSSL::PKey::RSA.new(2048)
311
471
  * signature = pkey.sign(digest, data)
312
472
  */
@@ -360,7 +520,7 @@ ossl_pkey_sign(VALUE self, VALUE digest, VALUE data)
360
520
  *
361
521
  * == Example
362
522
  * data = 'Sign me!'
363
- * digest = OpenSSL::Digest::SHA256.new
523
+ * digest = OpenSSL::Digest.new('SHA256')
364
524
  * pkey = OpenSSL::PKey::RSA.new(2048)
365
525
  * signature = pkey.sign(digest, data)
366
526
  * pub_key = pkey.public_key
@@ -491,6 +651,12 @@ Init_ossl_pkey(void)
491
651
 
492
652
  rb_define_alloc_func(cPKey, ossl_pkey_alloc);
493
653
  rb_define_method(cPKey, "initialize", ossl_pkey_initialize, 0);
654
+ rb_define_method(cPKey, "oid", ossl_pkey_oid, 0);
655
+ rb_define_method(cPKey, "inspect", ossl_pkey_inspect, 0);
656
+ rb_define_method(cPKey, "private_to_der", ossl_pkey_private_to_der, -1);
657
+ rb_define_method(cPKey, "private_to_pem", ossl_pkey_private_to_pem, -1);
658
+ rb_define_method(cPKey, "public_to_der", ossl_pkey_public_to_der, 0);
659
+ rb_define_method(cPKey, "public_to_pem", ossl_pkey_public_to_pem, 0);
494
660
 
495
661
  rb_define_method(cPKey, "sign", ossl_pkey_sign, 2);
496
662
  rb_define_method(cPKey, "verify", ossl_pkey_verify, 3);
@@ -133,9 +133,9 @@ static VALUE ossl_##_keytype##_set_##_group(VALUE self, VALUE v1, VALUE v2, VALU
133
133
  BIGNUM *bn3 = NULL, *orig_bn3 = NIL_P(v3) ? NULL : GetBNPtr(v3);\
134
134
  \
135
135
  Get##_type(self, obj); \
136
- if (orig_bn1 && !(bn1 = BN_dup(orig_bn1)) || \
137
- orig_bn2 && !(bn2 = BN_dup(orig_bn2)) || \
138
- orig_bn3 && !(bn3 = BN_dup(orig_bn3))) { \
136
+ if ((orig_bn1 && !(bn1 = BN_dup(orig_bn1))) || \
137
+ (orig_bn2 && !(bn2 = BN_dup(orig_bn2))) || \
138
+ (orig_bn3 && !(bn3 = BN_dup(orig_bn3)))) { \
139
139
  BN_clear_free(bn1); \
140
140
  BN_clear_free(bn2); \
141
141
  BN_clear_free(bn3); \
@@ -163,8 +163,8 @@ static VALUE ossl_##_keytype##_set_##_group(VALUE self, VALUE v1, VALUE v2) \
163
163
  BIGNUM *bn2 = NULL, *orig_bn2 = NIL_P(v2) ? NULL : GetBNPtr(v2);\
164
164
  \
165
165
  Get##_type(self, obj); \
166
- if (orig_bn1 && !(bn1 = BN_dup(orig_bn1)) || \
167
- orig_bn2 && !(bn2 = BN_dup(orig_bn2))) { \
166
+ if ((orig_bn1 && !(bn1 = BN_dup(orig_bn1))) || \
167
+ (orig_bn2 && !(bn2 = BN_dup(orig_bn2)))) { \
168
168
  BN_clear_free(bn1); \
169
169
  BN_clear_free(bn2); \
170
170
  ossl_raise(eBNError, NULL); \
@@ -262,7 +262,7 @@ ossl_dh_initialize_copy(VALUE self, VALUE other)
262
262
  BIGNUM *pub2 = BN_dup(pub);
263
263
  BIGNUM *priv2 = BN_dup(priv);
264
264
 
265
- if (!pub2 || priv && !priv2) {
265
+ if (!pub2 || (priv && !priv2)) {
266
266
  BN_clear_free(pub2);
267
267
  BN_clear_free(priv2);
268
268
  ossl_raise(eDHError, "BN_dup");
@@ -513,7 +513,7 @@ ossl_dsa_to_public_key(VALUE self)
513
513
  * === Example
514
514
  * dsa = OpenSSL::PKey::DSA.new(2048)
515
515
  * doc = "Sign me"
516
- * digest = OpenSSL::Digest::SHA1.digest(doc)
516
+ * digest = OpenSSL::Digest.digest('SHA1', doc)
517
517
  * sig = dsa.syssign(digest)
518
518
  *
519
519
  *
@@ -558,7 +558,7 @@ ossl_dsa_sign(VALUE self, VALUE data)
558
558
  * === Example
559
559
  * dsa = OpenSSL::PKey::DSA.new(2048)
560
560
  * doc = "Sign me"
561
- * digest = OpenSSL::Digest::SHA1.digest(doc)
561
+ * digest = OpenSSL::Digest.digest('SHA1', doc)
562
562
  * sig = dsa.syssign(digest)
563
563
  * puts dsa.sysverify(digest, sig) # => true
564
564
  *