openssl 2.0.0.beta.1 → 2.0.0.beta.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of openssl might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d174a9df67d20906bf3a603a2b482e3af32c697d
4
- data.tar.gz: a0f9b0afe67208eaf57cbadfdd9bde7bcbcfa0b9
3
+ metadata.gz: 0fb175be42485b5b6a9a5ded1672a24812be75b4
4
+ data.tar.gz: 07d6597617677e14278d06045f922735881e465e
5
5
  SHA512:
6
- metadata.gz: 11f0885002e471acd940354b95c43cab740b00c2768323c3348f860127f8d78fce9e13a7bd9ee0d78968789c6b1c240b0711332701740a7691893139f48406f2
7
- data.tar.gz: 4355528336295a916266ba7c82ac7c3a4cbdc9d9bb155f3944ead1f3c962eca00f263646bff70f75c30d0ef065ed1022f4ca0c6273ee9f29c9820f083a2fdb9f
6
+ metadata.gz: c9e75e005f17b9b69cf7d7db1d0aa344e65ec31f543f76fc8c0f99a0535f393bf1807a0301f186f68a08269390099b4d753aa51ed214cef8278d4d6756100d51
7
+ data.tar.gz: b18c7445fff8461ef0fa7da91e20c7e7545b0cc228b2746dfb98d7f9d0ae8838271b38f264ff84eb78c93f7b579be4ce46b6307890434712a1a0dcf5e9981c87
data/History.md CHANGED
@@ -23,27 +23,31 @@ Supported platforms
23
23
  Notable changes
24
24
  ---------------
25
25
 
26
- * Add support for OpenSSL 1.1.0. [Feature #12324]
26
+ * Add support for OpenSSL 1.1.0. [[Feature #12324]](https://bugs.ruby-lang.org/issues/12324)
27
27
  * Add support for LibreSSL
28
28
 
29
29
  * OpenSSL::Cipher
30
30
 
31
31
  - OpenSSL::Cipher#key= and #iv= reject too long inputs. They used to truncate
32
- silently. [Bug #12561]
32
+ silently. [[Bug #12561]](https://bugs.ruby-lang.org/issues/12561)
33
33
 
34
34
  - OpenSSL::Cipher#iv_len= is added. It allows changing IV (nonce) length if
35
35
  using AEAD ciphers.
36
- [Bug #8667] [Bug #10420] [GH ruby/ruby#569] [GH ruby/openssl#58]
36
+ [[Bug #8667]](https://bugs.ruby-lang.org/issues/8667),
37
+ [[Bug #10420]](https://bugs.ruby-lang.org/issues/10420),
38
+ [[GH ruby/ruby#569]](https://github.com/ruby/ruby/pull/569),
39
+ [[GH ruby/openssl#58]](https://github.com/ruby/openssl/pull/58)
37
40
 
38
41
  - OpenSSL::Cipher#auth_tag_len= is added. This sets the authentication tag
39
42
  length to be generated by an AEAD cipher.
40
43
 
41
44
  * OpenSSL::OCSP
42
45
 
43
- - Accessor methods are added to OpenSSL::OCSP::CertificateId. [Feature #7181]
46
+ - Accessor methods are added to OpenSSL::OCSP::CertificateId.
47
+ [[Feature #7181]](https://bugs.ruby-lang.org/issues/7181)
44
48
 
45
49
  - OpenSSL::OCSP::Request and BasicResponse can be signed with non-SHA-1 hash
46
- algorithm. [Feature #11552]
50
+ algorithm. [[Feature #11552]](https://bugs.ruby-lang.org/issues/11552)
47
51
 
48
52
  - OpenSSL::OCSP::CertificateId and BasicResponse can be encoded into DER.
49
53
 
@@ -52,16 +56,25 @@ Notable changes
52
56
  - OpenSSL::OCSP::BasicResponse#add_status accepts absolute times. They used to
53
57
  accept only relative seconds from the current time.
54
58
 
55
- * OpenSSL::PKey::EC follows the general PKey interface. [Bug #6567]
59
+ * OpenSSL::PKey
60
+
61
+ - OpenSSL::PKey::EC follows the general PKey interface.
62
+ [[Bug #6567]](https://bugs.ruby-lang.org/issues/6567)
63
+
64
+ - OpenSSL::PKey.read raises OpenSSL::PKey::PKeyError instead of ArgumentError
65
+ for consistency with OpenSSL::PKey::{DH,DSA,RSA,EC}#new.
66
+ [[Bug #11774]](https://bugs.ruby-lang.org/issues/11774),
67
+ [[GH ruby/openssl#55]](https://github.com/ruby/openssl/pull/55)
56
68
 
57
- * OpenSSL::PKey.read raises OpenSSL::PKey::PKeyError instead of ArgumentError
58
- for consistency with OpenSSL::PKey::{DH,DSA,RSA,EC}#new.
59
- [Bug #11774] [GH ruby/openssl#55]
69
+ - OpenSSL::PKey::EC::Group retrieved by OpenSSL::PKey::EC#group is no longer
70
+ linked with the EC key. Modifications to the EC::Group have no effect on the
71
+ key. [[GH ruby/openssl#71]](https://github.com/ruby/openssl/pull/71)
60
72
 
61
73
  * OpenSSL::SSL
62
74
 
63
75
  - OpenSSL::SSL::SSLSocket#tmp_key is added. A client can call it after the
64
- connection is established to retrieve the ephemeral key. [GH ruby/ruby#1318]
76
+ connection is established to retrieve the ephemeral key.
77
+ [[GH ruby/ruby#1318]](https://github.com/ruby/ruby/pull/1318)
65
78
 
66
79
  - The automatic ephemeral ECDH curve selection is enabled by default when
67
80
  built with OpenSSL >= 1.0.2 or LibreSSL.
@@ -73,7 +86,8 @@ Notable changes
73
86
  - A new option 'verify_hostname' is added to OpenSSL::SSL::SSLContext. When it
74
87
  is enabled, and the SNI hostname is also set, the hostname verification on
75
88
  the server certificate is automatically performed. It is now enabled by
76
- OpenSSL::SSL::Context#set_params. [GH ruby/openssl#60]
89
+ OpenSSL::SSL::Context#set_params.
90
+ [[GH ruby/openssl#60]](https://github.com/ruby/openssl/pull/60)
77
91
 
78
92
  Removals
79
93
  --------
@@ -86,10 +100,12 @@ Removals
86
100
 
87
101
  - OpenSSL::PKey::DH::DEFAULT_512 is removed. Hence servers no longer use
88
102
  512-bit DH group by default. It is considered too weak nowadays.
89
- [Bug #11968] [GH ruby/ruby#1196]
103
+ [[Bug #11968]](https://bugs.ruby-lang.org/issues/11968),
104
+ [[GH ruby/ruby#1196]](https://github.com/ruby/ruby/pull/1196)
90
105
 
91
106
  - RC4 cipher suites are removed from OpenSSL::SSL::SSLContext::DEFAULT_PARAMS.
92
- RC4 is now considered to be weak. [GH ruby/openssl#50]
107
+ RC4 is now considered to be weak.
108
+ [[GH ruby/openssl#50]](https://github.com/ruby/openssl/pull/50)
93
109
 
94
110
  Deprecations
95
111
  ------------
@@ -44,9 +44,9 @@ You can redistribute it and/or modify it under either the terms of the
44
44
  For the list of those files and their copying conditions, see the
45
45
  file LEGAL.
46
46
 
47
- 5. The scripts and library files supplied as input to or produced as
47
+ 5. The scripts and library files supplied as input to or produced as
48
48
  output from the software do not automatically fall under the
49
- copyright of the software, but belong to whomever generated them,
49
+ copyright of the software, but belong to whomever generated them,
50
50
  and may be sold commercially, and may be aggregated with this
51
51
  software.
52
52
 
@@ -152,7 +152,5 @@ have_func("X509_get0_notBefore")
152
152
  Logging::message "=== Checking done. ===\n"
153
153
 
154
154
  create_header
155
- create_makefile("openssl") {|conf|
156
- conf << "THREAD_MODEL = #{CONFIG["THREAD_MODEL"]}\n"
157
- }
155
+ create_makefile("openssl")
158
156
  Logging::message "Done.\n"
@@ -190,15 +190,17 @@ ossl_pkcs12_initialize(int argc, VALUE *argv, VALUE self)
190
190
  if(!PKCS12_parse(pkcs, passphrase, &key, &x509, &x509s))
191
191
  ossl_raise(ePKCS12Error, "PKCS12_parse");
192
192
  ERR_pop_to_mark();
193
- pkey = rb_protect((VALUE (*)(VALUE))ossl_pkey_new, (VALUE)key,
194
- &st); /* NO DUP */
195
- if(st) goto err;
196
- cert = rb_protect((VALUE (*)(VALUE))ossl_x509_new, (VALUE)x509, &st);
197
- if(st) goto err;
198
- if(x509s){
199
- ca =
200
- rb_protect((VALUE (*)(VALUE))ossl_x509_sk2ary, (VALUE)x509s, &st);
201
- if(st) goto err;
193
+ if (key) {
194
+ pkey = rb_protect((VALUE (*)(VALUE))ossl_pkey_new, (VALUE)key, &st);
195
+ if (st) goto err;
196
+ }
197
+ if (x509) {
198
+ cert = rb_protect((VALUE (*)(VALUE))ossl_x509_new, (VALUE)x509, &st);
199
+ if (st) goto err;
200
+ }
201
+ if (x509s) {
202
+ ca = rb_protect((VALUE (*)(VALUE))ossl_x509_sk2ary, (VALUE)x509s, &st);
203
+ if (st) goto err;
202
204
  }
203
205
 
204
206
  err:
@@ -6,17 +6,6 @@
6
6
 
7
7
  #if !defined(OPENSSL_NO_EC) && (OPENSSL_VERSION_NUMBER >= 0x0090802fL)
8
8
 
9
- typedef struct {
10
- EC_GROUP *group;
11
- int dont_free;
12
- } ossl_ec_group;
13
-
14
- typedef struct {
15
- EC_POINT *point;
16
- int dont_free;
17
- } ossl_ec_point;
18
-
19
-
20
9
  #define EXPORT_PEM 0
21
10
  #define EXPORT_DER 1
22
11
 
@@ -29,66 +18,39 @@ static const rb_data_type_t ossl_ec_point_type;
29
18
  ossl_raise(rb_eRuntimeError, "THIS IS NOT A EC PKEY!"); \
30
19
  } \
31
20
  } while (0)
32
-
33
- #define SafeGet_ec_group(obj, group) do { \
34
- OSSL_Check_Kind((obj), cEC_GROUP); \
35
- TypedData_Get_Struct((obj), ossl_ec_group, &ossl_ec_group_type, (group)); \
36
- } while(0)
37
-
38
- #define Get_EC_KEY(obj, key) do { \
39
- EVP_PKEY *pkey; \
40
- GetPKeyEC((obj), pkey); \
41
- (key) = EVP_PKEY_get0_EC_KEY(pkey); \
42
- } while(0)
43
-
44
- #define Require_EC_KEY(obj, key) do { \
45
- Get_EC_KEY((obj), (key)); \
46
- if ((key) == NULL) \
47
- ossl_raise(eECError, "EC_KEY is not initialized"); \
48
- } while(0)
49
-
50
- #define SafeRequire_EC_KEY(obj, key) do { \
51
- OSSL_Check_Kind((obj), cEC); \
52
- Require_EC_KEY((obj), (key)); \
21
+ #define GetEC(obj, key) do { \
22
+ EVP_PKEY *_pkey; \
23
+ GetPKeyEC(obj, _pkey); \
24
+ (key) = EVP_PKEY_get0_EC_KEY(_pkey); \
25
+ } while (0)
26
+ #define SafeGetEC(obj, key) do { \
27
+ OSSL_Check_Kind(obj, cEC); \
28
+ GetEC(obj, key); \
53
29
  } while (0)
54
30
 
55
- #define Get_EC_GROUP(obj, g) do { \
56
- ossl_ec_group *ec_group; \
57
- TypedData_Get_Struct((obj), ossl_ec_group, &ossl_ec_group_type, ec_group); \
58
- if (ec_group == NULL) \
59
- ossl_raise(eEC_GROUP, "missing ossl_ec_group structure"); \
60
- (g) = ec_group->group; \
61
- } while(0)
62
-
63
- #define Require_EC_GROUP(obj, group) do { \
64
- Get_EC_GROUP((obj), (group)); \
31
+ #define GetECGroup(obj, group) do { \
32
+ TypedData_Get_Struct(obj, EC_GROUP, &ossl_ec_group_type, group); \
65
33
  if ((group) == NULL) \
66
- ossl_raise(eEC_GROUP, "EC_GROUP is not initialized"); \
67
- } while(0)
68
-
69
- #define SafeRequire_EC_GROUP(obj, group) do { \
34
+ ossl_raise(eEC_GROUP, "EC_GROUP is not initialized"); \
35
+ } while (0)
36
+ #define SafeGetECGroup(obj, group) do { \
70
37
  OSSL_Check_Kind((obj), cEC_GROUP); \
71
- Require_EC_GROUP((obj), (group)); \
72
- } while(0)
73
-
74
- #define Get_EC_POINT(obj, p) do { \
75
- ossl_ec_point *ec_point; \
76
- TypedData_Get_Struct((obj), ossl_ec_point, &ossl_ec_point_type, ec_point); \
77
- if (ec_point == NULL) \
78
- ossl_raise(eEC_POINT, "missing ossl_ec_point structure"); \
79
- (p) = ec_point->point; \
80
- } while(0)
38
+ GetECGroup(obj, group); \
39
+ } while (0)
81
40
 
82
- #define Require_EC_POINT(obj, point) do { \
83
- Get_EC_POINT((obj), (point)); \
41
+ #define GetECPoint(obj, point) do { \
42
+ TypedData_Get_Struct(obj, EC_POINT, &ossl_ec_point_type, point); \
84
43
  if ((point) == NULL) \
85
- ossl_raise(eEC_POINT, "EC_POINT is not initialized"); \
86
- } while(0)
87
-
88
- #define SafeRequire_EC_POINT(obj, point) do { \
44
+ ossl_raise(eEC_POINT, "EC_POINT is not initialized"); \
45
+ } while (0)
46
+ #define SafeGetECPoint(obj, point) do { \
89
47
  OSSL_Check_Kind((obj), cEC_POINT); \
90
- Require_EC_POINT((obj), (point)); \
48
+ GetECPoint(obj, point); \
91
49
  } while(0)
50
+ #define GetECPointGroup(obj, group) do { \
51
+ VALUE _group = rb_attr_get(obj, id_i_group); \
52
+ SafeGetECGroup(_group, group); \
53
+ } while (0)
92
54
 
93
55
  VALUE cEC;
94
56
  VALUE eECError;
@@ -108,7 +70,10 @@ static ID ID_uncompressed;
108
70
  static ID ID_compressed;
109
71
  static ID ID_hybrid;
110
72
 
111
- static ID id_i_group, id_i_key;
73
+ static ID id_i_group;
74
+
75
+ static VALUE ec_group_new(const EC_GROUP *group);
76
+ static VALUE ec_point_new(const EC_POINT *point, const EC_GROUP *group);
112
77
 
113
78
  static VALUE ec_instance(VALUE klass, EC_KEY *ec)
114
79
  {
@@ -163,8 +128,7 @@ ec_key_new_from_group(VALUE arg)
163
128
  if (rb_obj_is_kind_of(arg, cEC_GROUP)) {
164
129
  EC_GROUP *group;
165
130
 
166
- SafeRequire_EC_GROUP(arg, group);
167
-
131
+ SafeGetECGroup(arg, group);
168
132
  if (!(ec = EC_KEY_new()))
169
133
  ossl_raise(eECError, NULL);
170
134
 
@@ -244,7 +208,7 @@ static VALUE ossl_ec_key_initialize(int argc, VALUE *argv, VALUE self)
244
208
  } else if (rb_obj_is_kind_of(arg, cEC)) {
245
209
  EC_KEY *other_ec = NULL;
246
210
 
247
- SafeRequire_EC_KEY(arg, other_ec);
211
+ SafeGetEC(arg, other_ec);
248
212
  if (!(ec = EC_KEY_dup(other_ec)))
249
213
  ossl_raise(eECError, NULL);
250
214
  } else if (rb_obj_is_kind_of(arg, cEC_GROUP)) {
@@ -281,8 +245,6 @@ static VALUE ossl_ec_key_initialize(int argc, VALUE *argv, VALUE self)
281
245
  ossl_raise(eECError, "EVP_PKEY_assign_EC_KEY");
282
246
  }
283
247
 
284
- rb_ivar_set(self, id_i_group, Qnil);
285
-
286
248
  return self;
287
249
  }
288
250
 
@@ -295,7 +257,7 @@ ossl_ec_key_initialize_copy(VALUE self, VALUE other)
295
257
  GetPKey(self, pkey);
296
258
  if (EVP_PKEY_base_id(pkey) != EVP_PKEY_NONE)
297
259
  ossl_raise(eECError, "EC already initialized");
298
- SafeRequire_EC_KEY(other, ec);
260
+ SafeGetEC(other, ec);
299
261
 
300
262
  ec_new = EC_KEY_dup(ec);
301
263
  if (!ec_new)
@@ -304,80 +266,46 @@ ossl_ec_key_initialize_copy(VALUE self, VALUE other)
304
266
  EC_KEY_free(ec_new);
305
267
  ossl_raise(eECError, "EVP_PKEY_assign_EC_KEY");
306
268
  }
307
- rb_ivar_set(self, id_i_group, Qnil); /* EC_KEY_dup() also copies the EC_GROUP */
308
269
 
309
270
  return self;
310
271
  }
311
272
 
312
273
  /*
313
- * call-seq:
314
- * key.group => group
274
+ * call-seq:
275
+ * key.group => group
315
276
  *
316
- * Returns a constant <code>OpenSSL::EC::Group</code> that is tied to the key.
317
- * Modifying the returned group can make the key invalid.
277
+ * Returns the EC::Group that the key is associated with. Modifying the returned
278
+ * group does not affect +key+.
318
279
  */
319
- static VALUE ossl_ec_key_get_group(VALUE self)
280
+ static VALUE
281
+ ossl_ec_key_get_group(VALUE self)
320
282
  {
321
- VALUE group_v;
322
283
  EC_KEY *ec;
323
- ossl_ec_group *ec_group;
324
- EC_GROUP *group;
325
-
326
- Require_EC_KEY(self, ec);
327
-
328
- group_v = rb_attr_get(self, id_i_group);
329
- if (!NIL_P(group_v))
330
- return group_v;
284
+ const EC_GROUP *group;
331
285
 
332
- if ((group = (EC_GROUP *)EC_KEY_get0_group(ec)) != NULL) {
333
- group_v = rb_obj_alloc(cEC_GROUP);
334
- SafeGet_ec_group(group_v, ec_group);
335
- ec_group->group = group;
336
- ec_group->dont_free = 1;
337
- rb_ivar_set(group_v, id_i_key, self);
338
- rb_ivar_set(self, id_i_group, group_v);
339
- return group_v;
340
- }
286
+ GetEC(self, ec);
287
+ group = EC_KEY_get0_group(ec);
288
+ if (!group)
289
+ return Qnil;
341
290
 
342
- return Qnil;
291
+ return ec_group_new(group);
343
292
  }
344
293
 
345
294
  /*
346
- * call-seq:
347
- * key.group = group => group
348
- *
349
- * Returns the same object passed, not the group object associated with the key.
350
- * If you wish to access the group object tied to the key call key.group after setting
351
- * the group.
352
- *
353
- * Setting the group will immediately destroy any previously assigned group object.
354
- * The group is internally copied by OpenSSL. Modifying the original group after
355
- * assignment will not effect the internal key structure.
356
- * (your changes may be lost). BE CAREFUL.
295
+ * call-seq:
296
+ * key.group = group
357
297
  *
358
- * EC_KEY_set_group calls EC_GROUP_free(key->group) then EC_GROUP_dup(), not EC_GROUP_copy.
359
- * This documentation is accurate for OpenSSL 0.9.8b.
298
+ * Sets the EC::Group for the key. The group structure is internally copied so
299
+ * modifition to +group+ after assigning to a key has no effect on the key.
360
300
  */
361
- static VALUE ossl_ec_key_set_group(VALUE self, VALUE group_v)
301
+ static VALUE
302
+ ossl_ec_key_set_group(VALUE self, VALUE group_v)
362
303
  {
363
- VALUE old_group_v;
364
304
  EC_KEY *ec;
365
305
  EC_GROUP *group;
366
306
 
367
- Require_EC_KEY(self, ec);
368
- SafeRequire_EC_GROUP(group_v, group);
369
-
370
- old_group_v = rb_attr_get(self, id_i_group);
371
- if (!NIL_P(old_group_v)) {
372
- ossl_ec_group *old_ec_group;
373
- SafeGet_ec_group(old_group_v, old_ec_group);
374
-
375
- old_ec_group->group = NULL;
376
- old_ec_group->dont_free = 0;
377
- rb_ivar_set(old_group_v, id_i_key, Qnil);
378
- }
379
-
380
- rb_ivar_set(self, id_i_group, Qnil);
307
+ GetEC(self, ec);
308
+ SafeGetECGroup(group_v, group);
381
309
 
382
310
  if (EC_KEY_set_group(ec, group) != 1)
383
311
  ossl_raise(eECError, "EC_KEY_set_group");
@@ -396,8 +324,7 @@ static VALUE ossl_ec_key_get_private_key(VALUE self)
396
324
  EC_KEY *ec;
397
325
  const BIGNUM *bn;
398
326
 
399
- Require_EC_KEY(self, ec);
400
-
327
+ GetEC(self, ec);
401
328
  if ((bn = EC_KEY_get0_private_key(ec)) == NULL)
402
329
  return Qnil;
403
330
 
@@ -415,7 +342,7 @@ static VALUE ossl_ec_key_set_private_key(VALUE self, VALUE private_key)
415
342
  EC_KEY *ec;
416
343
  BIGNUM *bn = NULL;
417
344
 
418
- Require_EC_KEY(self, ec);
345
+ GetEC(self, ec);
419
346
  if (!NIL_P(private_key))
420
347
  bn = GetBNPtr(private_key);
421
348
 
@@ -432,26 +359,6 @@ static VALUE ossl_ec_key_set_private_key(VALUE self, VALUE private_key)
432
359
  return private_key;
433
360
  }
434
361
 
435
-
436
- static VALUE ossl_ec_point_dup(const EC_POINT *point, VALUE group_v)
437
- {
438
- VALUE obj;
439
- const EC_GROUP *group;
440
- ossl_ec_point *new_point;
441
-
442
- obj = rb_obj_alloc(cEC_POINT);
443
- TypedData_Get_Struct(obj, ossl_ec_point, &ossl_ec_point_type, new_point);
444
-
445
- SafeRequire_EC_GROUP(group_v, group);
446
-
447
- new_point->point = EC_POINT_dup(point, group);
448
- if (new_point->point == NULL)
449
- ossl_raise(eEC_POINT, "EC_POINT_dup");
450
- rb_ivar_set(obj, id_i_group, group_v);
451
-
452
- return obj;
453
- }
454
-
455
362
  /*
456
363
  * call-seq:
457
364
  * key.public_key => OpenSSL::PKey::EC::Point
@@ -462,18 +369,12 @@ static VALUE ossl_ec_key_get_public_key(VALUE self)
462
369
  {
463
370
  EC_KEY *ec;
464
371
  const EC_POINT *point;
465
- VALUE group;
466
-
467
- Require_EC_KEY(self, ec);
468
372
 
373
+ GetEC(self, ec);
469
374
  if ((point = EC_KEY_get0_public_key(ec)) == NULL)
470
375
  return Qnil;
471
376
 
472
- group = rb_funcall(self, rb_intern("group"), 0);
473
- if (NIL_P(group))
474
- ossl_raise(eECError, "EC_KEY_get0_get0_group (has public_key but no group???");
475
-
476
- return ossl_ec_point_dup(point, group);
377
+ return ec_point_new(point, EC_KEY_get0_group(ec));
477
378
  }
478
379
 
479
380
  /*
@@ -487,9 +388,9 @@ static VALUE ossl_ec_key_set_public_key(VALUE self, VALUE public_key)
487
388
  EC_KEY *ec;
488
389
  EC_POINT *point = NULL;
489
390
 
490
- Require_EC_KEY(self, ec);
391
+ GetEC(self, ec);
491
392
  if (!NIL_P(public_key))
492
- SafeRequire_EC_POINT(public_key, point);
393
+ SafeGetECPoint(public_key, point);
493
394
 
494
395
  switch (EC_KEY_set_public_key(ec, point)) {
495
396
  case 1:
@@ -515,7 +416,7 @@ static VALUE ossl_ec_key_is_public(VALUE self)
515
416
  {
516
417
  EC_KEY *ec;
517
418
 
518
- Require_EC_KEY(self, ec);
419
+ GetEC(self, ec);
519
420
 
520
421
  return EC_KEY_get0_public_key(ec) ? Qtrue : Qfalse;
521
422
  }
@@ -531,7 +432,7 @@ static VALUE ossl_ec_key_is_private(VALUE self)
531
432
  {
532
433
  EC_KEY *ec;
533
434
 
534
- Require_EC_KEY(self, ec);
435
+ GetEC(self, ec);
535
436
 
536
437
  return EC_KEY_get0_private_key(ec) ? Qtrue : Qfalse;
537
438
  }
@@ -545,7 +446,7 @@ static VALUE ossl_ec_key_to_string(VALUE self, VALUE ciph, VALUE pass, int forma
545
446
  VALUE str;
546
447
  const EVP_CIPHER *cipher = NULL;
547
448
 
548
- Require_EC_KEY(self, ec);
449
+ GetEC(self, ec);
549
450
 
550
451
  if (EC_KEY_get0_public_key(ec) == NULL)
551
452
  ossl_raise(eECError, "can't export - no public key set");
@@ -636,7 +537,7 @@ static VALUE ossl_ec_key_to_text(VALUE self)
636
537
  BIO *out;
637
538
  VALUE str;
638
539
 
639
- Require_EC_KEY(self, ec);
540
+ GetEC(self, ec);
640
541
  if (!(out = BIO_new(BIO_s_mem()))) {
641
542
  ossl_raise(eECError, "BIO_new(BIO_s_mem())");
642
543
  }
@@ -667,8 +568,7 @@ static VALUE ossl_ec_key_generate_key(VALUE self)
667
568
  {
668
569
  EC_KEY *ec;
669
570
 
670
- Require_EC_KEY(self, ec);
671
-
571
+ GetEC(self, ec);
672
572
  if (EC_KEY_generate_key(ec) != 1)
673
573
  ossl_raise(eECError, "EC_KEY_generate_key");
674
574
 
@@ -687,8 +587,7 @@ static VALUE ossl_ec_key_check_key(VALUE self)
687
587
  {
688
588
  EC_KEY *ec;
689
589
 
690
- Require_EC_KEY(self, ec);
691
-
590
+ GetEC(self, ec);
692
591
  if (EC_KEY_check_key(ec) != 1)
693
592
  ossl_raise(eECError, "EC_KEY_check_key");
694
593
 
@@ -708,8 +607,8 @@ static VALUE ossl_ec_key_dh_compute_key(VALUE self, VALUE pubkey)
708
607
  int buf_len;
709
608
  VALUE str;
710
609
 
711
- Require_EC_KEY(self, ec);
712
- SafeRequire_EC_POINT(pubkey, point);
610
+ GetEC(self, ec);
611
+ SafeGetECPoint(pubkey, point);
713
612
 
714
613
  /* BUG: need a way to figure out the maximum string size */
715
614
  buf_len = 1024;
@@ -738,7 +637,7 @@ static VALUE ossl_ec_key_dsa_sign_asn1(VALUE self, VALUE data)
738
637
  unsigned int buf_len;
739
638
  VALUE str;
740
639
 
741
- Require_EC_KEY(self, ec);
640
+ GetEC(self, ec);
742
641
  StringValue(data);
743
642
 
744
643
  if (EC_KEY_get0_private_key(ec) == NULL)
@@ -763,7 +662,7 @@ static VALUE ossl_ec_key_dsa_verify_asn1(VALUE self, VALUE data, VALUE sig)
763
662
  {
764
663
  EC_KEY *ec;
765
664
 
766
- Require_EC_KEY(self, ec);
665
+ GetEC(self, ec);
767
666
  StringValue(data);
768
667
  StringValue(sig);
769
668
 
@@ -778,12 +677,13 @@ static VALUE ossl_ec_key_dsa_verify_asn1(VALUE self, VALUE data, VALUE sig)
778
677
  UNREACHABLE;
779
678
  }
780
679
 
781
- static void ossl_ec_group_free(void *ptr)
680
+ /*
681
+ * OpenSSL::PKey::EC::Group
682
+ */
683
+ static void
684
+ ossl_ec_group_free(void *ptr)
782
685
  {
783
- ossl_ec_group *ec_group = ptr;
784
- if (!ec_group->dont_free && ec_group->group)
785
- EC_GROUP_clear_free(ec_group->group);
786
- ruby_xfree(ec_group);
686
+ EC_GROUP_clear_free(ptr);
787
687
  }
788
688
 
789
689
  static const rb_data_type_t ossl_ec_group_type = {
@@ -794,12 +694,23 @@ static const rb_data_type_t ossl_ec_group_type = {
794
694
  0, 0, RUBY_TYPED_FREE_IMMEDIATELY,
795
695
  };
796
696
 
797
- static VALUE ossl_ec_group_alloc(VALUE klass)
697
+ static VALUE
698
+ ossl_ec_group_alloc(VALUE klass)
699
+ {
700
+ return TypedData_Wrap_Struct(klass, &ossl_ec_group_type, NULL);
701
+ }
702
+
703
+ static VALUE
704
+ ec_group_new(const EC_GROUP *group)
798
705
  {
799
- ossl_ec_group *ec_group;
800
706
  VALUE obj;
707
+ EC_GROUP *group_new;
801
708
 
802
- obj = TypedData_Make_Struct(klass, ossl_ec_group, &ossl_ec_group_type, ec_group);
709
+ obj = ossl_ec_group_alloc(cEC_GROUP);
710
+ group_new = EC_GROUP_dup(group);
711
+ if (!group_new)
712
+ ossl_raise(eEC_GROUP, "EC_GROUP_dup");
713
+ RTYPEDDATA_DATA(obj) = group_new;
803
714
 
804
715
  return obj;
805
716
  }
@@ -828,11 +739,10 @@ static VALUE ossl_ec_group_alloc(VALUE klass)
828
739
  static VALUE ossl_ec_group_initialize(int argc, VALUE *argv, VALUE self)
829
740
  {
830
741
  VALUE arg1, arg2, arg3, arg4;
831
- ossl_ec_group *ec_group;
832
- EC_GROUP *group = NULL;
742
+ EC_GROUP *group;
833
743
 
834
- TypedData_Get_Struct(self, ossl_ec_group, &ossl_ec_group_type, ec_group);
835
- if (ec_group->group != NULL)
744
+ TypedData_Get_Struct(self, EC_GROUP, &ossl_ec_group_type, group);
745
+ if (group)
836
746
  ossl_raise(rb_eRuntimeError, "EC_GROUP is already initialized");
837
747
 
838
748
  switch (rb_scan_args(argc, argv, "13", &arg1, &arg2, &arg3, &arg4)) {
@@ -862,7 +772,7 @@ static VALUE ossl_ec_group_initialize(int argc, VALUE *argv, VALUE self)
862
772
  } else if (rb_obj_is_kind_of(arg1, cEC_GROUP)) {
863
773
  const EC_GROUP *arg1_group;
864
774
 
865
- SafeRequire_EC_GROUP(arg1, arg1_group);
775
+ SafeGetECGroup(arg1, arg1_group);
866
776
  if ((group = EC_GROUP_dup(arg1_group)) == NULL)
867
777
  ossl_raise(eEC_GROUP, "EC_GROUP_dup");
868
778
  } else {
@@ -925,8 +835,7 @@ static VALUE ossl_ec_group_initialize(int argc, VALUE *argv, VALUE self)
925
835
 
926
836
  if (group == NULL)
927
837
  ossl_raise(eEC_GROUP, "");
928
-
929
- ec_group->group = group;
838
+ RTYPEDDATA_DATA(self) = group;
930
839
 
931
840
  return self;
932
841
  }
@@ -934,24 +843,22 @@ static VALUE ossl_ec_group_initialize(int argc, VALUE *argv, VALUE self)
934
843
  static VALUE
935
844
  ossl_ec_group_initialize_copy(VALUE self, VALUE other)
936
845
  {
937
- ossl_ec_group *ec_group;
938
- EC_GROUP *orig;
846
+ EC_GROUP *group, *group_new;
939
847
 
940
- TypedData_Get_Struct(self, ossl_ec_group, &ossl_ec_group_type, ec_group);
941
- if (ec_group->group)
848
+ TypedData_Get_Struct(self, EC_GROUP, &ossl_ec_group_type, group_new);
849
+ if (group_new)
942
850
  ossl_raise(eEC_GROUP, "EC::Group already initialized");
943
- SafeRequire_EC_GROUP(other, orig);
851
+ SafeGetECGroup(other, group);
944
852
 
945
- ec_group->group = EC_GROUP_dup(orig);
946
- if (!ec_group->group)
853
+ group_new = EC_GROUP_dup(group);
854
+ if (!group_new)
947
855
  ossl_raise(eEC_GROUP, "EC_GROUP_dup");
948
-
949
- rb_ivar_set(self, id_i_key, Qnil);
856
+ RTYPEDDATA_DATA(self) = group_new;
950
857
 
951
858
  return self;
952
859
  }
953
860
 
954
- /*
861
+ /*
955
862
  * call-seq:
956
863
  * group1.eql?(group2) => true | false
957
864
  * group1 == group2 => true | false
@@ -963,8 +870,8 @@ static VALUE ossl_ec_group_eql(VALUE a, VALUE b)
963
870
  {
964
871
  EC_GROUP *group1 = NULL, *group2 = NULL;
965
872
 
966
- Require_EC_GROUP(a, group1);
967
- SafeRequire_EC_GROUP(b, group2);
873
+ GetECGroup(a, group1);
874
+ SafeGetECGroup(b, group2);
968
875
 
969
876
  if (EC_GROUP_cmp(group1, group2, ossl_bn_ctx) == 1)
970
877
  return Qfalse;
@@ -972,7 +879,7 @@ static VALUE ossl_ec_group_eql(VALUE a, VALUE b)
972
879
  return Qtrue;
973
880
  }
974
881
 
975
- /*
882
+ /*
976
883
  * call-seq:
977
884
  * group.generator => ec_point
978
885
  *
@@ -982,14 +889,15 @@ static VALUE ossl_ec_group_eql(VALUE a, VALUE b)
982
889
  */
983
890
  static VALUE ossl_ec_group_get_generator(VALUE self)
984
891
  {
985
- VALUE point_obj;
986
- EC_GROUP *group = NULL;
987
-
988
- Require_EC_GROUP(self, group);
892
+ EC_GROUP *group;
893
+ const EC_POINT *generator;
989
894
 
990
- point_obj = ossl_ec_point_dup(EC_GROUP_get0_generator(group), self);
895
+ GetECGroup(self, group);
896
+ generator = EC_GROUP_get0_generator(group);
897
+ if (!generator)
898
+ return Qnil;
991
899
 
992
- return point_obj;
900
+ return ec_point_new(generator, group);
993
901
  }
994
902
 
995
903
  /*
@@ -1007,8 +915,8 @@ static VALUE ossl_ec_group_set_generator(VALUE self, VALUE generator, VALUE orde
1007
915
  const EC_POINT *point;
1008
916
  const BIGNUM *o, *co;
1009
917
 
1010
- Require_EC_GROUP(self, group);
1011
- SafeRequire_EC_POINT(generator, point);
918
+ GetECGroup(self, group);
919
+ SafeGetECPoint(generator, point);
1012
920
  o = GetBNPtr(order);
1013
921
  co = GetBNPtr(cofactor);
1014
922
 
@@ -1032,7 +940,7 @@ static VALUE ossl_ec_group_get_order(VALUE self)
1032
940
  BIGNUM *bn;
1033
941
  EC_GROUP *group = NULL;
1034
942
 
1035
- Require_EC_GROUP(self, group);
943
+ GetECGroup(self, group);
1036
944
 
1037
945
  bn_obj = ossl_bn_new(NULL);
1038
946
  bn = GetBNPtr(bn_obj);
@@ -1057,7 +965,7 @@ static VALUE ossl_ec_group_get_cofactor(VALUE self)
1057
965
  BIGNUM *bn;
1058
966
  EC_GROUP *group = NULL;
1059
967
 
1060
- Require_EC_GROUP(self, group);
968
+ GetECGroup(self, group);
1061
969
 
1062
970
  bn_obj = ossl_bn_new(NULL);
1063
971
  bn = GetBNPtr(bn_obj);
@@ -1081,7 +989,7 @@ static VALUE ossl_ec_group_get_curve_name(VALUE self)
1081
989
  EC_GROUP *group = NULL;
1082
990
  int nid;
1083
991
 
1084
- Get_EC_GROUP(self, group);
992
+ GetECGroup(self, group);
1085
993
  if (group == NULL)
1086
994
  return Qnil;
1087
995
 
@@ -1128,7 +1036,7 @@ static VALUE ossl_s_builtin_curves(VALUE self)
1128
1036
  return ret;
1129
1037
  }
1130
1038
 
1131
- /*
1039
+ /*
1132
1040
  * call-seq:
1133
1041
  * group.asn1_flag -> Integer
1134
1042
  *
@@ -1141,8 +1049,7 @@ static VALUE ossl_ec_group_get_asn1_flag(VALUE self)
1141
1049
  EC_GROUP *group = NULL;
1142
1050
  int flag;
1143
1051
 
1144
- Require_EC_GROUP(self, group);
1145
-
1052
+ GetECGroup(self, group);
1146
1053
  flag = EC_GROUP_get_asn1_flag(group);
1147
1054
 
1148
1055
  return INT2NUM(flag);
@@ -1166,8 +1073,7 @@ static VALUE ossl_ec_group_set_asn1_flag(VALUE self, VALUE flag_v)
1166
1073
  {
1167
1074
  EC_GROUP *group = NULL;
1168
1075
 
1169
- Require_EC_GROUP(self, group);
1170
-
1076
+ GetECGroup(self, group);
1171
1077
  EC_GROUP_set_asn1_flag(group, NUM2INT(flag_v));
1172
1078
 
1173
1079
  return flag_v;
@@ -1187,8 +1093,7 @@ static VALUE ossl_ec_group_get_point_conversion_form(VALUE self)
1187
1093
  point_conversion_form_t form;
1188
1094
  VALUE ret;
1189
1095
 
1190
- Require_EC_GROUP(self, group);
1191
-
1096
+ GetECGroup(self, group);
1192
1097
  form = EC_GROUP_get_point_conversion_form(group);
1193
1098
 
1194
1099
  switch (form) {
@@ -1226,7 +1131,7 @@ static VALUE ossl_ec_group_set_point_conversion_form(VALUE self, VALUE form_v)
1226
1131
  point_conversion_form_t form;
1227
1132
  ID form_id = SYM2ID(form_v);
1228
1133
 
1229
- Require_EC_GROUP(self, group);
1134
+ GetECGroup(self, group);
1230
1135
 
1231
1136
  if (form_id == ID_uncompressed) {
1232
1137
  form = POINT_CONVERSION_UNCOMPRESSED;
@@ -1254,8 +1159,7 @@ static VALUE ossl_ec_group_get_seed(VALUE self)
1254
1159
  EC_GROUP *group = NULL;
1255
1160
  size_t seed_len;
1256
1161
 
1257
- Require_EC_GROUP(self, group);
1258
-
1162
+ GetECGroup(self, group);
1259
1163
  seed_len = EC_GROUP_get_seed_len(group);
1260
1164
 
1261
1165
  if (seed_len == 0)
@@ -1274,7 +1178,7 @@ static VALUE ossl_ec_group_set_seed(VALUE self, VALUE seed)
1274
1178
  {
1275
1179
  EC_GROUP *group = NULL;
1276
1180
 
1277
- Require_EC_GROUP(self, group);
1181
+ GetECGroup(self, group);
1278
1182
  StringValue(seed);
1279
1183
 
1280
1184
  if (EC_GROUP_set_seed(group, (unsigned char *)RSTRING_PTR(seed), RSTRING_LEN(seed)) != (size_t)RSTRING_LEN(seed))
@@ -1295,7 +1199,7 @@ static VALUE ossl_ec_group_get_degree(VALUE self)
1295
1199
  {
1296
1200
  EC_GROUP *group = NULL;
1297
1201
 
1298
- Require_EC_GROUP(self, group);
1202
+ GetECGroup(self, group);
1299
1203
 
1300
1204
  return INT2NUM(EC_GROUP_get_degree(group));
1301
1205
  }
@@ -1307,7 +1211,7 @@ static VALUE ossl_ec_group_to_string(VALUE self, int format)
1307
1211
  int i = -1;
1308
1212
  VALUE str;
1309
1213
 
1310
- Get_EC_GROUP(self, group);
1214
+ GetECGroup(self, group);
1311
1215
 
1312
1216
  if (!(out = BIO_new(BIO_s_mem())))
1313
1217
  ossl_raise(eEC_GROUP, "BIO_new(BIO_s_mem())");
@@ -1368,7 +1272,7 @@ static VALUE ossl_ec_group_to_text(VALUE self)
1368
1272
  BIO *out;
1369
1273
  VALUE str;
1370
1274
 
1371
- Require_EC_GROUP(self, group);
1275
+ GetECGroup(self, group);
1372
1276
  if (!(out = BIO_new(BIO_s_mem()))) {
1373
1277
  ossl_raise(eEC_GROUP, "BIO_new(BIO_s_mem())");
1374
1278
  }
@@ -1382,28 +1286,41 @@ static VALUE ossl_ec_group_to_text(VALUE self)
1382
1286
  }
1383
1287
 
1384
1288
 
1385
- static void ossl_ec_point_free(void *ptr)
1289
+ /*
1290
+ * OpenSSL::PKey::EC::Point
1291
+ */
1292
+ static void
1293
+ ossl_ec_point_free(void *ptr)
1386
1294
  {
1387
- ossl_ec_point *ec_point = ptr;
1388
- if (!ec_point->dont_free && ec_point->point)
1389
- EC_POINT_clear_free(ec_point->point);
1390
- ruby_xfree(ec_point);
1295
+ EC_POINT_clear_free(ptr);
1391
1296
  }
1392
1297
 
1393
1298
  static const rb_data_type_t ossl_ec_point_type = {
1394
- "OpenSSL/ec_point",
1299
+ "OpenSSL/EC_POINT",
1395
1300
  {
1396
1301
  0, ossl_ec_point_free,
1397
1302
  },
1398
1303
  0, 0, RUBY_TYPED_FREE_IMMEDIATELY,
1399
1304
  };
1400
1305
 
1401
- static VALUE ossl_ec_point_alloc(VALUE klass)
1306
+ static VALUE
1307
+ ossl_ec_point_alloc(VALUE klass)
1402
1308
  {
1403
- ossl_ec_point *ec_point;
1309
+ return TypedData_Wrap_Struct(klass, &ossl_ec_point_type, NULL);
1310
+ }
1311
+
1312
+ static VALUE
1313
+ ec_point_new(const EC_POINT *point, const EC_GROUP *group)
1314
+ {
1315
+ EC_POINT *point_new;
1404
1316
  VALUE obj;
1405
1317
 
1406
- obj = TypedData_Make_Struct(klass, ossl_ec_point, &ossl_ec_point_type, ec_point);
1318
+ obj = ossl_ec_point_alloc(cEC_POINT);
1319
+ point_new = EC_POINT_dup(point, group);
1320
+ if (!point_new)
1321
+ ossl_raise(eEC_POINT, "EC_POINT_dup");
1322
+ RTYPEDDATA_DATA(obj) = point_new;
1323
+ rb_ivar_set(obj, id_i_group, ec_group_new(group));
1407
1324
 
1408
1325
  return obj;
1409
1326
  }
@@ -1418,14 +1335,13 @@ static VALUE ossl_ec_point_alloc(VALUE klass)
1418
1335
  */
1419
1336
  static VALUE ossl_ec_point_initialize(int argc, VALUE *argv, VALUE self)
1420
1337
  {
1421
- ossl_ec_point *ec_point;
1422
- EC_POINT *point = NULL;
1338
+ EC_POINT *point;
1423
1339
  VALUE arg1, arg2;
1424
1340
  VALUE group_v = Qnil;
1425
1341
  const EC_GROUP *group = NULL;
1426
1342
 
1427
- TypedData_Get_Struct(self, ossl_ec_point, &ossl_ec_point_type, ec_point);
1428
- if (ec_point->point)
1343
+ TypedData_Get_Struct(self, EC_POINT, &ossl_ec_point_type, point);
1344
+ if (point)
1429
1345
  ossl_raise(eEC_POINT, "EC_POINT already initialized");
1430
1346
 
1431
1347
  switch (rb_scan_args(argc, argv, "11", &arg1, &arg2)) {
@@ -1434,13 +1350,13 @@ static VALUE ossl_ec_point_initialize(int argc, VALUE *argv, VALUE self)
1434
1350
  const EC_POINT *arg_point;
1435
1351
 
1436
1352
  group_v = rb_attr_get(arg1, id_i_group);
1437
- SafeRequire_EC_GROUP(group_v, group);
1438
- SafeRequire_EC_POINT(arg1, arg_point);
1353
+ SafeGetECGroup(group_v, group);
1354
+ SafeGetECPoint(arg1, arg_point);
1439
1355
 
1440
1356
  point = EC_POINT_dup(arg_point, group);
1441
1357
  } else if (rb_obj_is_kind_of(arg1, cEC_GROUP)) {
1442
1358
  group_v = arg1;
1443
- SafeRequire_EC_GROUP(group_v, group);
1359
+ SafeGetECGroup(group_v, group);
1444
1360
 
1445
1361
  point = EC_POINT_new(group);
1446
1362
  } else {
@@ -1452,7 +1368,7 @@ static VALUE ossl_ec_point_initialize(int argc, VALUE *argv, VALUE self)
1452
1368
  if (!rb_obj_is_kind_of(arg1, cEC_GROUP))
1453
1369
  ossl_raise(rb_eArgError, "1st argument must be OpenSSL::PKey::EC::Group");
1454
1370
  group_v = arg1;
1455
- SafeRequire_EC_GROUP(group_v, group);
1371
+ SafeGetECGroup(group_v, group);
1456
1372
 
1457
1373
  if (rb_obj_is_kind_of(arg2, cBN)) {
1458
1374
  const BIGNUM *bn = GetBNPtr(arg2);
@@ -1480,8 +1396,7 @@ static VALUE ossl_ec_point_initialize(int argc, VALUE *argv, VALUE self)
1480
1396
  if (NIL_P(group_v))
1481
1397
  ossl_raise(rb_eRuntimeError, "missing group (internal error)");
1482
1398
 
1483
- ec_point->point = point;
1484
-
1399
+ RTYPEDDATA_DATA(self) = point;
1485
1400
  rb_ivar_set(self, id_i_group, group_v);
1486
1401
 
1487
1402
  return self;
@@ -1490,23 +1405,22 @@ static VALUE ossl_ec_point_initialize(int argc, VALUE *argv, VALUE self)
1490
1405
  static VALUE
1491
1406
  ossl_ec_point_initialize_copy(VALUE self, VALUE other)
1492
1407
  {
1493
- ossl_ec_point *ec_point;
1494
- EC_POINT *orig;
1408
+ EC_POINT *point, *point_new;
1495
1409
  EC_GROUP *group;
1496
1410
  VALUE group_v;
1497
1411
 
1498
- TypedData_Get_Struct(self, ossl_ec_point, &ossl_ec_point_type, ec_point);
1499
- if (ec_point->point)
1412
+ TypedData_Get_Struct(self, EC_POINT, &ossl_ec_point_type, point_new);
1413
+ if (point_new)
1500
1414
  ossl_raise(eEC_POINT, "EC::Point already initialized");
1501
- SafeRequire_EC_POINT(other, orig);
1415
+ SafeGetECPoint(other, point);
1502
1416
 
1503
1417
  group_v = rb_obj_dup(rb_attr_get(other, id_i_group));
1504
- SafeRequire_EC_GROUP(group_v, group);
1418
+ SafeGetECGroup(group_v, group);
1505
1419
 
1506
- ec_point->point = EC_POINT_dup(orig, group);
1507
- if (!ec_point->point)
1420
+ point_new = EC_POINT_dup(point, group);
1421
+ if (!point_new)
1508
1422
  ossl_raise(eEC_POINT, "EC_POINT_dup");
1509
- rb_ivar_set(self, id_i_key, Qnil);
1423
+ RTYPEDDATA_DATA(self) = point_new;
1510
1424
  rb_ivar_set(self, id_i_group, group_v);
1511
1425
 
1512
1426
  return self;
@@ -1527,9 +1441,9 @@ static VALUE ossl_ec_point_eql(VALUE a, VALUE b)
1527
1441
  if (ossl_ec_group_eql(group_v1, group_v2) == Qfalse)
1528
1442
  return Qfalse;
1529
1443
 
1530
- Require_EC_POINT(a, point1);
1531
- SafeRequire_EC_POINT(b, point2);
1532
- SafeRequire_EC_GROUP(group_v1, group);
1444
+ GetECPoint(a, point1);
1445
+ SafeGetECPoint(b, point2);
1446
+ SafeGetECGroup(group_v1, group);
1533
1447
 
1534
1448
  if (EC_POINT_cmp(group, point1, point2, ossl_bn_ctx) == 1)
1535
1449
  return Qfalse;
@@ -1544,11 +1458,10 @@ static VALUE ossl_ec_point_eql(VALUE a, VALUE b)
1544
1458
  static VALUE ossl_ec_point_is_at_infinity(VALUE self)
1545
1459
  {
1546
1460
  EC_POINT *point;
1547
- VALUE group_v = rb_attr_get(self, id_i_group);
1548
1461
  const EC_GROUP *group;
1549
1462
 
1550
- Require_EC_POINT(self, point);
1551
- SafeRequire_EC_GROUP(group_v, group);
1463
+ GetECPoint(self, point);
1464
+ GetECPointGroup(self, group);
1552
1465
 
1553
1466
  switch (EC_POINT_is_at_infinity(group, point)) {
1554
1467
  case 1: return Qtrue;
@@ -1566,11 +1479,10 @@ static VALUE ossl_ec_point_is_at_infinity(VALUE self)
1566
1479
  static VALUE ossl_ec_point_is_on_curve(VALUE self)
1567
1480
  {
1568
1481
  EC_POINT *point;
1569
- VALUE group_v = rb_attr_get(self, id_i_group);
1570
1482
  const EC_GROUP *group;
1571
1483
 
1572
- Require_EC_POINT(self, point);
1573
- SafeRequire_EC_GROUP(group_v, group);
1484
+ GetECPoint(self, point);
1485
+ GetECPointGroup(self, group);
1574
1486
 
1575
1487
  switch (EC_POINT_is_on_curve(group, point, ossl_bn_ctx)) {
1576
1488
  case 1: return Qtrue;
@@ -1588,11 +1500,10 @@ static VALUE ossl_ec_point_is_on_curve(VALUE self)
1588
1500
  static VALUE ossl_ec_point_make_affine(VALUE self)
1589
1501
  {
1590
1502
  EC_POINT *point;
1591
- VALUE group_v = rb_attr_get(self, id_i_group);
1592
1503
  const EC_GROUP *group;
1593
1504
 
1594
- Require_EC_POINT(self, point);
1595
- SafeRequire_EC_GROUP(group_v, group);
1505
+ GetECPoint(self, point);
1506
+ GetECPointGroup(self, group);
1596
1507
 
1597
1508
  if (EC_POINT_make_affine(group, point, ossl_bn_ctx) != 1)
1598
1509
  ossl_raise(cEC_POINT, "EC_POINT_make_affine");
@@ -1607,11 +1518,10 @@ static VALUE ossl_ec_point_make_affine(VALUE self)
1607
1518
  static VALUE ossl_ec_point_invert(VALUE self)
1608
1519
  {
1609
1520
  EC_POINT *point;
1610
- VALUE group_v = rb_attr_get(self, id_i_group);
1611
1521
  const EC_GROUP *group;
1612
1522
 
1613
- Require_EC_POINT(self, point);
1614
- SafeRequire_EC_GROUP(group_v, group);
1523
+ GetECPoint(self, point);
1524
+ GetECPointGroup(self, group);
1615
1525
 
1616
1526
  if (EC_POINT_invert(group, point, ossl_bn_ctx) != 1)
1617
1527
  ossl_raise(cEC_POINT, "EC_POINT_invert");
@@ -1626,11 +1536,10 @@ static VALUE ossl_ec_point_invert(VALUE self)
1626
1536
  static VALUE ossl_ec_point_set_to_infinity(VALUE self)
1627
1537
  {
1628
1538
  EC_POINT *point;
1629
- VALUE group_v = rb_attr_get(self, id_i_group);
1630
1539
  const EC_GROUP *group;
1631
1540
 
1632
- Require_EC_POINT(self, point);
1633
- SafeRequire_EC_GROUP(group_v, group);
1541
+ GetECPoint(self, point);
1542
+ GetECPointGroup(self, group);
1634
1543
 
1635
1544
  if (EC_POINT_set_to_infinity(group, point) != 1)
1636
1545
  ossl_raise(cEC_POINT, "EC_POINT_set_to_infinity");
@@ -1648,13 +1557,12 @@ static VALUE ossl_ec_point_to_bn(VALUE self)
1648
1557
  {
1649
1558
  EC_POINT *point;
1650
1559
  VALUE bn_obj;
1651
- VALUE group_v = rb_attr_get(self, id_i_group);
1652
1560
  const EC_GROUP *group;
1653
1561
  point_conversion_form_t form;
1654
1562
  BIGNUM *bn;
1655
1563
 
1656
- Require_EC_POINT(self, point);
1657
- SafeRequire_EC_GROUP(group_v, group);
1564
+ GetECPoint(self, point);
1565
+ GetECPointGroup(self, group);
1658
1566
 
1659
1567
  form = EC_GROUP_get_point_conversion_form(group);
1660
1568
 
@@ -1692,12 +1600,12 @@ static VALUE ossl_ec_point_mul(int argc, VALUE *argv, VALUE self)
1692
1600
  VALUE arg1, arg2, arg3, result;
1693
1601
  const BIGNUM *bn_g = NULL;
1694
1602
 
1695
- Require_EC_POINT(self, point_self);
1696
- SafeRequire_EC_GROUP(group_v, group);
1603
+ GetECPoint(self, point_self);
1604
+ SafeGetECGroup(group_v, group);
1697
1605
 
1698
1606
  result = rb_obj_alloc(cEC_POINT);
1699
1607
  ossl_ec_point_initialize(1, &group_v, result);
1700
- Require_EC_POINT(result, point_result);
1608
+ GetECPoint(result, point_result);
1701
1609
 
1702
1610
  rb_scan_args(argc, argv, "12", &arg1, &arg2, &arg3);
1703
1611
  if (!RB_TYPE_P(arg1, T_ARRAY)) {
@@ -1730,7 +1638,7 @@ static VALUE ossl_ec_point_mul(int argc, VALUE *argv, VALUE self)
1730
1638
  points = ALLOCV_N(const EC_POINT *, tmp_p, num);
1731
1639
  points[0] = point_self; /* self */
1732
1640
  for (i = 0; i < num - 1; i++)
1733
- SafeRequire_EC_POINT(RARRAY_AREF(arg2, i), points[i + 1]);
1641
+ SafeGetECPoint(RARRAY_AREF(arg2, i), points[i + 1]);
1734
1642
 
1735
1643
  if (!NIL_P(arg3))
1736
1644
  bn_g = GetBNPtr(arg3);
@@ -1889,7 +1797,6 @@ void Init_ossl_ec(void)
1889
1797
  rb_define_method(cEC_POINT, "mul", ossl_ec_point_mul, -1);
1890
1798
 
1891
1799
  id_i_group = rb_intern("@group");
1892
- id_i_key = rb_intern("@key");
1893
1800
  }
1894
1801
 
1895
1802
  #else /* defined NO_EC */