openssl 3.3.2 → 4.0.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.
- checksums.yaml +4 -4
- data/CONTRIBUTING.md +3 -0
- data/History.md +85 -0
- data/README.md +12 -11
- data/ext/openssl/extconf.rb +30 -69
- data/ext/openssl/openssl_missing.h +0 -206
- data/ext/openssl/ossl.c +280 -301
- data/ext/openssl/ossl.h +15 -10
- data/ext/openssl/ossl_asn1.c +598 -406
- data/ext/openssl/ossl_asn1.h +15 -1
- data/ext/openssl/ossl_bio.c +3 -3
- data/ext/openssl/ossl_bn.c +286 -291
- data/ext/openssl/ossl_cipher.c +252 -203
- data/ext/openssl/ossl_cipher.h +10 -1
- data/ext/openssl/ossl_config.c +1 -6
- data/ext/openssl/ossl_digest.c +74 -43
- data/ext/openssl/ossl_digest.h +9 -1
- data/ext/openssl/ossl_engine.c +39 -103
- data/ext/openssl/ossl_hmac.c +30 -36
- data/ext/openssl/ossl_kdf.c +42 -53
- data/ext/openssl/ossl_ns_spki.c +31 -37
- data/ext/openssl/ossl_ocsp.c +214 -241
- data/ext/openssl/ossl_pkcs12.c +26 -26
- data/ext/openssl/ossl_pkcs7.c +175 -145
- data/ext/openssl/ossl_pkey.c +162 -178
- data/ext/openssl/ossl_pkey.h +99 -99
- data/ext/openssl/ossl_pkey_dh.c +31 -68
- data/ext/openssl/ossl_pkey_dsa.c +15 -54
- data/ext/openssl/ossl_pkey_ec.c +179 -237
- data/ext/openssl/ossl_pkey_rsa.c +56 -103
- data/ext/openssl/ossl_provider.c +0 -7
- data/ext/openssl/ossl_rand.c +7 -14
- data/ext/openssl/ossl_ssl.c +478 -353
- data/ext/openssl/ossl_ssl.h +8 -8
- data/ext/openssl/ossl_ssl_session.c +93 -97
- data/ext/openssl/ossl_ts.c +81 -127
- data/ext/openssl/ossl_x509.c +9 -28
- data/ext/openssl/ossl_x509attr.c +33 -54
- data/ext/openssl/ossl_x509cert.c +69 -100
- data/ext/openssl/ossl_x509crl.c +78 -89
- data/ext/openssl/ossl_x509ext.c +45 -66
- data/ext/openssl/ossl_x509name.c +63 -88
- data/ext/openssl/ossl_x509req.c +55 -62
- data/ext/openssl/ossl_x509revoked.c +27 -41
- data/ext/openssl/ossl_x509store.c +38 -56
- data/lib/openssl/buffering.rb +30 -24
- data/lib/openssl/digest.rb +1 -1
- data/lib/openssl/pkey.rb +71 -49
- data/lib/openssl/ssl.rb +12 -79
- data/lib/openssl/version.rb +2 -1
- data/lib/openssl/x509.rb +9 -0
- data/lib/openssl.rb +9 -6
- metadata +1 -3
- data/ext/openssl/openssl_missing.c +0 -40
- data/lib/openssl/asn1.rb +0 -188
data/ext/openssl/ossl_pkey_ec.c
CHANGED
|
@@ -15,7 +15,7 @@ static const rb_data_type_t ossl_ec_point_type;
|
|
|
15
15
|
#define GetPKeyEC(obj, pkey) do { \
|
|
16
16
|
GetPKey((obj), (pkey)); \
|
|
17
17
|
if (EVP_PKEY_base_id(pkey) != EVP_PKEY_EC) { \
|
|
18
|
-
|
|
18
|
+
ossl_raise(rb_eRuntimeError, "THIS IS NOT A EC PKEY!"); \
|
|
19
19
|
} \
|
|
20
20
|
} while (0)
|
|
21
21
|
#define GetEC(obj, key) do { \
|
|
@@ -23,19 +23,19 @@ static const rb_data_type_t ossl_ec_point_type;
|
|
|
23
23
|
GetPKeyEC(obj, _pkey); \
|
|
24
24
|
(key) = EVP_PKEY_get0_EC_KEY(_pkey); \
|
|
25
25
|
if ((key) == NULL) \
|
|
26
|
-
ossl_raise(
|
|
26
|
+
ossl_raise(ePKeyError, "failed to get EC_KEY from EVP_PKEY"); \
|
|
27
27
|
} while (0)
|
|
28
28
|
|
|
29
29
|
#define GetECGroup(obj, group) do { \
|
|
30
30
|
TypedData_Get_Struct(obj, EC_GROUP, &ossl_ec_group_type, group); \
|
|
31
31
|
if ((group) == NULL) \
|
|
32
|
-
|
|
32
|
+
ossl_raise(eEC_GROUP, "EC_GROUP is not initialized"); \
|
|
33
33
|
} while (0)
|
|
34
34
|
|
|
35
35
|
#define GetECPoint(obj, point) do { \
|
|
36
36
|
TypedData_Get_Struct(obj, EC_POINT, &ossl_ec_point_type, point); \
|
|
37
37
|
if ((point) == NULL) \
|
|
38
|
-
|
|
38
|
+
ossl_raise(eEC_POINT, "EC_POINT is not initialized"); \
|
|
39
39
|
} while (0)
|
|
40
40
|
#define GetECPointGroup(obj, group) do { \
|
|
41
41
|
VALUE _group = rb_attr_get(obj, id_i_group); \
|
|
@@ -43,17 +43,13 @@ static const rb_data_type_t ossl_ec_point_type;
|
|
|
43
43
|
} while (0)
|
|
44
44
|
|
|
45
45
|
VALUE cEC;
|
|
46
|
-
static VALUE eECError;
|
|
47
46
|
static VALUE cEC_GROUP;
|
|
48
47
|
static VALUE eEC_GROUP;
|
|
49
48
|
static VALUE cEC_POINT;
|
|
50
49
|
static VALUE eEC_POINT;
|
|
51
50
|
|
|
52
|
-
static
|
|
53
|
-
|
|
54
|
-
static ID ID_uncompressed;
|
|
55
|
-
static ID ID_compressed;
|
|
56
|
-
static ID ID_hybrid;
|
|
51
|
+
static VALUE sym_GFp, sym_GF2m;
|
|
52
|
+
static VALUE sym_uncompressed, sym_compressed, sym_hybrid;
|
|
57
53
|
|
|
58
54
|
static ID id_i_group;
|
|
59
55
|
|
|
@@ -70,27 +66,27 @@ ec_key_new_from_group(VALUE arg)
|
|
|
70
66
|
EC_KEY *ec;
|
|
71
67
|
|
|
72
68
|
if (rb_obj_is_kind_of(arg, cEC_GROUP)) {
|
|
73
|
-
|
|
69
|
+
EC_GROUP *group;
|
|
74
70
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
71
|
+
GetECGroup(arg, group);
|
|
72
|
+
if (!(ec = EC_KEY_new()))
|
|
73
|
+
ossl_raise(ePKeyError, NULL);
|
|
78
74
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
75
|
+
if (!EC_KEY_set_group(ec, group)) {
|
|
76
|
+
EC_KEY_free(ec);
|
|
77
|
+
ossl_raise(ePKeyError, NULL);
|
|
78
|
+
}
|
|
83
79
|
} else {
|
|
84
|
-
|
|
80
|
+
int nid = OBJ_sn2nid(StringValueCStr(arg));
|
|
85
81
|
|
|
86
|
-
|
|
87
|
-
|
|
82
|
+
if (nid == NID_undef)
|
|
83
|
+
ossl_raise(ePKeyError, "invalid curve name");
|
|
88
84
|
|
|
89
|
-
|
|
90
|
-
|
|
85
|
+
if (!(ec = EC_KEY_new_by_curve_name(nid)))
|
|
86
|
+
ossl_raise(ePKeyError, NULL);
|
|
91
87
|
|
|
92
|
-
|
|
93
|
-
|
|
88
|
+
EC_KEY_set_asn1_flag(ec, OPENSSL_EC_NAMED_CURVE);
|
|
89
|
+
EC_KEY_set_conv_form(ec, POINT_CONVERSION_UNCOMPRESSED);
|
|
94
90
|
}
|
|
95
91
|
|
|
96
92
|
return ec;
|
|
@@ -117,12 +113,12 @@ ossl_ec_key_s_generate(VALUE klass, VALUE arg)
|
|
|
117
113
|
if (!pkey || EVP_PKEY_assign_EC_KEY(pkey, ec) != 1) {
|
|
118
114
|
EVP_PKEY_free(pkey);
|
|
119
115
|
EC_KEY_free(ec);
|
|
120
|
-
ossl_raise(
|
|
116
|
+
ossl_raise(ePKeyError, "EVP_PKEY_assign_EC_KEY");
|
|
121
117
|
}
|
|
122
118
|
RTYPEDDATA_DATA(obj) = pkey;
|
|
123
119
|
|
|
124
120
|
if (!EC_KEY_generate_key(ec))
|
|
125
|
-
|
|
121
|
+
ossl_raise(ePKeyError, "EC_KEY_generate_key");
|
|
126
122
|
|
|
127
123
|
return obj;
|
|
128
124
|
}
|
|
@@ -152,9 +148,14 @@ static VALUE ossl_ec_key_initialize(int argc, VALUE *argv, VALUE self)
|
|
|
152
148
|
|
|
153
149
|
rb_scan_args(argc, argv, "02", &arg, &pass);
|
|
154
150
|
if (NIL_P(arg)) {
|
|
151
|
+
#ifdef OSSL_HAVE_IMMUTABLE_PKEY
|
|
152
|
+
rb_raise(rb_eArgError, "OpenSSL::PKey::EC.new cannot be called " \
|
|
153
|
+
"without arguments; pkeys are immutable with OpenSSL 3.0");
|
|
154
|
+
#else
|
|
155
155
|
if (!(ec = EC_KEY_new()))
|
|
156
|
-
ossl_raise(
|
|
156
|
+
ossl_raise(ePKeyError, "EC_KEY_new");
|
|
157
157
|
goto legacy;
|
|
158
|
+
#endif
|
|
158
159
|
}
|
|
159
160
|
else if (rb_obj_is_kind_of(arg, cEC_GROUP)) {
|
|
160
161
|
ec = ec_key_new_from_group(arg);
|
|
@@ -176,7 +177,7 @@ static VALUE ossl_ec_key_initialize(int argc, VALUE *argv, VALUE self)
|
|
|
176
177
|
type = EVP_PKEY_base_id(pkey);
|
|
177
178
|
if (type != EVP_PKEY_EC) {
|
|
178
179
|
EVP_PKEY_free(pkey);
|
|
179
|
-
rb_raise(
|
|
180
|
+
rb_raise(ePKeyError, "incorrect pkey type: %s", OBJ_nid2sn(type));
|
|
180
181
|
}
|
|
181
182
|
RTYPEDDATA_DATA(self) = pkey;
|
|
182
183
|
return self;
|
|
@@ -186,13 +187,14 @@ static VALUE ossl_ec_key_initialize(int argc, VALUE *argv, VALUE self)
|
|
|
186
187
|
if (!pkey || EVP_PKEY_assign_EC_KEY(pkey, ec) != 1) {
|
|
187
188
|
EVP_PKEY_free(pkey);
|
|
188
189
|
EC_KEY_free(ec);
|
|
189
|
-
ossl_raise(
|
|
190
|
+
ossl_raise(ePKeyError, "EVP_PKEY_assign_EC_KEY");
|
|
190
191
|
}
|
|
191
192
|
RTYPEDDATA_DATA(self) = pkey;
|
|
192
193
|
return self;
|
|
193
194
|
}
|
|
194
195
|
|
|
195
196
|
#ifndef HAVE_EVP_PKEY_DUP
|
|
197
|
+
/* :nodoc: */
|
|
196
198
|
static VALUE
|
|
197
199
|
ossl_ec_key_initialize_copy(VALUE self, VALUE other)
|
|
198
200
|
{
|
|
@@ -206,12 +208,12 @@ ossl_ec_key_initialize_copy(VALUE self, VALUE other)
|
|
|
206
208
|
|
|
207
209
|
ec_new = EC_KEY_dup(ec);
|
|
208
210
|
if (!ec_new)
|
|
209
|
-
|
|
211
|
+
ossl_raise(ePKeyError, "EC_KEY_dup");
|
|
210
212
|
|
|
211
213
|
pkey = EVP_PKEY_new();
|
|
212
214
|
if (!pkey || EVP_PKEY_assign_EC_KEY(pkey, ec_new) != 1) {
|
|
213
215
|
EC_KEY_free(ec_new);
|
|
214
|
-
ossl_raise(
|
|
216
|
+
ossl_raise(ePKeyError, "EVP_PKEY_assign_EC_KEY");
|
|
215
217
|
}
|
|
216
218
|
RTYPEDDATA_DATA(self) = pkey;
|
|
217
219
|
|
|
@@ -235,7 +237,7 @@ ossl_ec_key_get_group(VALUE self)
|
|
|
235
237
|
GetEC(self, ec);
|
|
236
238
|
group = EC_KEY_get0_group(ec);
|
|
237
239
|
if (!group)
|
|
238
|
-
|
|
240
|
+
return Qnil;
|
|
239
241
|
|
|
240
242
|
return ec_group_new(group);
|
|
241
243
|
}
|
|
@@ -250,7 +252,7 @@ ossl_ec_key_get_group(VALUE self)
|
|
|
250
252
|
static VALUE
|
|
251
253
|
ossl_ec_key_set_group(VALUE self, VALUE group_v)
|
|
252
254
|
{
|
|
253
|
-
#
|
|
255
|
+
#ifdef OSSL_HAVE_IMMUTABLE_PKEY
|
|
254
256
|
rb_raise(ePKeyError, "pkeys are immutable on OpenSSL 3.0");
|
|
255
257
|
#else
|
|
256
258
|
EC_KEY *ec;
|
|
@@ -260,7 +262,7 @@ ossl_ec_key_set_group(VALUE self, VALUE group_v)
|
|
|
260
262
|
GetECGroup(group_v, group);
|
|
261
263
|
|
|
262
264
|
if (EC_KEY_set_group(ec, group) != 1)
|
|
263
|
-
ossl_raise(
|
|
265
|
+
ossl_raise(ePKeyError, "EC_KEY_set_group");
|
|
264
266
|
|
|
265
267
|
return group_v;
|
|
266
268
|
#endif
|
|
@@ -292,7 +294,7 @@ static VALUE ossl_ec_key_get_private_key(VALUE self)
|
|
|
292
294
|
*/
|
|
293
295
|
static VALUE ossl_ec_key_set_private_key(VALUE self, VALUE private_key)
|
|
294
296
|
{
|
|
295
|
-
#
|
|
297
|
+
#ifdef OSSL_HAVE_IMMUTABLE_PKEY
|
|
296
298
|
rb_raise(ePKeyError, "pkeys are immutable on OpenSSL 3.0");
|
|
297
299
|
#else
|
|
298
300
|
EC_KEY *ec;
|
|
@@ -303,14 +305,14 @@ static VALUE ossl_ec_key_set_private_key(VALUE self, VALUE private_key)
|
|
|
303
305
|
bn = GetBNPtr(private_key);
|
|
304
306
|
|
|
305
307
|
switch (EC_KEY_set_private_key(ec, bn)) {
|
|
306
|
-
|
|
308
|
+
case 1:
|
|
307
309
|
break;
|
|
308
|
-
|
|
310
|
+
case 0:
|
|
309
311
|
if (bn == NULL)
|
|
310
312
|
break;
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
ossl_raise(
|
|
313
|
+
/* fallthrough */
|
|
314
|
+
default:
|
|
315
|
+
ossl_raise(ePKeyError, "EC_KEY_set_private_key");
|
|
314
316
|
}
|
|
315
317
|
|
|
316
318
|
return private_key;
|
|
@@ -343,7 +345,7 @@ static VALUE ossl_ec_key_get_public_key(VALUE self)
|
|
|
343
345
|
*/
|
|
344
346
|
static VALUE ossl_ec_key_set_public_key(VALUE self, VALUE public_key)
|
|
345
347
|
{
|
|
346
|
-
#
|
|
348
|
+
#ifdef OSSL_HAVE_IMMUTABLE_PKEY
|
|
347
349
|
rb_raise(ePKeyError, "pkeys are immutable on OpenSSL 3.0");
|
|
348
350
|
#else
|
|
349
351
|
EC_KEY *ec;
|
|
@@ -354,14 +356,14 @@ static VALUE ossl_ec_key_set_public_key(VALUE self, VALUE public_key)
|
|
|
354
356
|
GetECPoint(public_key, point);
|
|
355
357
|
|
|
356
358
|
switch (EC_KEY_set_public_key(ec, point)) {
|
|
357
|
-
|
|
359
|
+
case 1:
|
|
358
360
|
break;
|
|
359
|
-
|
|
361
|
+
case 0:
|
|
360
362
|
if (point == NULL)
|
|
361
363
|
break;
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
ossl_raise(
|
|
364
|
+
/* fallthrough */
|
|
365
|
+
default:
|
|
366
|
+
ossl_raise(ePKeyError, "EC_KEY_set_public_key");
|
|
365
367
|
}
|
|
366
368
|
|
|
367
369
|
return public_key;
|
|
@@ -465,7 +467,7 @@ ossl_ec_key_export(int argc, VALUE *argv, VALUE self)
|
|
|
465
467
|
|
|
466
468
|
GetEC(self, ec);
|
|
467
469
|
if (EC_KEY_get0_public_key(ec) == NULL)
|
|
468
|
-
ossl_raise(
|
|
470
|
+
ossl_raise(ePKeyError, "can't export - no public key set");
|
|
469
471
|
if (EC_KEY_get0_private_key(ec))
|
|
470
472
|
return ossl_pkey_export_traditional(argc, argv, self, 0);
|
|
471
473
|
else
|
|
@@ -493,7 +495,7 @@ ossl_ec_key_to_der(VALUE self)
|
|
|
493
495
|
|
|
494
496
|
GetEC(self, ec);
|
|
495
497
|
if (EC_KEY_get0_public_key(ec) == NULL)
|
|
496
|
-
ossl_raise(
|
|
498
|
+
ossl_raise(ePKeyError, "can't export - no public key set");
|
|
497
499
|
if (EC_KEY_get0_private_key(ec))
|
|
498
500
|
return ossl_pkey_export_traditional(0, NULL, self, 1);
|
|
499
501
|
else
|
|
@@ -515,14 +517,14 @@ ossl_ec_key_to_der(VALUE self)
|
|
|
515
517
|
*/
|
|
516
518
|
static VALUE ossl_ec_key_generate_key(VALUE self)
|
|
517
519
|
{
|
|
518
|
-
#
|
|
520
|
+
#ifdef OSSL_HAVE_IMMUTABLE_PKEY
|
|
519
521
|
rb_raise(ePKeyError, "pkeys are immutable on OpenSSL 3.0");
|
|
520
522
|
#else
|
|
521
523
|
EC_KEY *ec;
|
|
522
524
|
|
|
523
525
|
GetEC(self, ec);
|
|
524
526
|
if (EC_KEY_generate_key(ec) != 1)
|
|
525
|
-
|
|
527
|
+
ossl_raise(ePKeyError, "EC_KEY_generate_key");
|
|
526
528
|
|
|
527
529
|
return self;
|
|
528
530
|
#endif
|
|
@@ -547,18 +549,18 @@ static VALUE ossl_ec_key_check_key(VALUE self)
|
|
|
547
549
|
GetEC(self, ec);
|
|
548
550
|
pctx = EVP_PKEY_CTX_new(pkey, /* engine */NULL);
|
|
549
551
|
if (!pctx)
|
|
550
|
-
ossl_raise(
|
|
552
|
+
ossl_raise(ePKeyError, "EVP_PKEY_CTX_new");
|
|
551
553
|
|
|
552
554
|
if (EC_KEY_get0_private_key(ec) != NULL) {
|
|
553
555
|
if (EVP_PKEY_check(pctx) != 1) {
|
|
554
556
|
EVP_PKEY_CTX_free(pctx);
|
|
555
|
-
ossl_raise(
|
|
557
|
+
ossl_raise(ePKeyError, "EVP_PKEY_check");
|
|
556
558
|
}
|
|
557
559
|
}
|
|
558
560
|
else {
|
|
559
561
|
if (EVP_PKEY_public_check(pctx) != 1) {
|
|
560
562
|
EVP_PKEY_CTX_free(pctx);
|
|
561
|
-
ossl_raise(
|
|
563
|
+
ossl_raise(ePKeyError, "EVP_PKEY_public_check");
|
|
562
564
|
}
|
|
563
565
|
}
|
|
564
566
|
|
|
@@ -568,7 +570,7 @@ static VALUE ossl_ec_key_check_key(VALUE self)
|
|
|
568
570
|
|
|
569
571
|
GetEC(self, ec);
|
|
570
572
|
if (EC_KEY_check_key(ec) != 1)
|
|
571
|
-
|
|
573
|
+
ossl_raise(ePKeyError, "EC_KEY_check_key");
|
|
572
574
|
#endif
|
|
573
575
|
|
|
574
576
|
return Qtrue;
|
|
@@ -586,7 +588,7 @@ ossl_ec_group_free(void *ptr)
|
|
|
586
588
|
static const rb_data_type_t ossl_ec_group_type = {
|
|
587
589
|
"OpenSSL/ec_group",
|
|
588
590
|
{
|
|
589
|
-
|
|
591
|
+
0, ossl_ec_group_free,
|
|
590
592
|
},
|
|
591
593
|
0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
|
|
592
594
|
};
|
|
@@ -606,7 +608,7 @@ ec_group_new(const EC_GROUP *group)
|
|
|
606
608
|
obj = ossl_ec_group_alloc(cEC_GROUP);
|
|
607
609
|
group_new = EC_GROUP_dup(group);
|
|
608
610
|
if (!group_new)
|
|
609
|
-
|
|
611
|
+
ossl_raise(eEC_GROUP, "EC_GROUP_dup");
|
|
610
612
|
RTYPEDDATA_DATA(obj) = group_new;
|
|
611
613
|
|
|
612
614
|
return obj;
|
|
@@ -634,7 +636,7 @@ static VALUE ossl_ec_group_initialize(int argc, VALUE *argv, VALUE self)
|
|
|
634
636
|
ossl_raise(rb_eRuntimeError, "EC_GROUP is already initialized");
|
|
635
637
|
|
|
636
638
|
switch (rb_scan_args(argc, argv, "13", &arg1, &arg2, &arg3, &arg4)) {
|
|
637
|
-
|
|
639
|
+
case 1:
|
|
638
640
|
if (rb_obj_is_kind_of(arg1, cEC_GROUP)) {
|
|
639
641
|
const EC_GROUP *arg1_group;
|
|
640
642
|
|
|
@@ -646,7 +648,7 @@ static VALUE ossl_ec_group_initialize(int argc, VALUE *argv, VALUE self)
|
|
|
646
648
|
|
|
647
649
|
group = PEM_read_bio_ECPKParameters(in, NULL, NULL, NULL);
|
|
648
650
|
if (!group) {
|
|
649
|
-
|
|
651
|
+
OSSL_BIO_reset(in);
|
|
650
652
|
group = d2i_ECPKParameters_bio(in, NULL);
|
|
651
653
|
}
|
|
652
654
|
|
|
@@ -656,11 +658,14 @@ static VALUE ossl_ec_group_initialize(int argc, VALUE *argv, VALUE self)
|
|
|
656
658
|
const char *name = StringValueCStr(arg1);
|
|
657
659
|
int nid = OBJ_sn2nid(name);
|
|
658
660
|
|
|
659
|
-
|
|
661
|
+
ossl_clear_error(); /* ignore errors in d2i_ECPKParameters_bio() */
|
|
660
662
|
if (nid == NID_undef)
|
|
661
663
|
ossl_raise(eEC_GROUP, "unknown curve name (%"PRIsVALUE")", arg1);
|
|
662
|
-
|
|
664
|
+
#if !defined(OPENSSL_IS_AWSLC)
|
|
663
665
|
group = EC_GROUP_new_by_curve_name(nid);
|
|
666
|
+
#else /* EC_GROUPs are static and immutable by default in AWS-LC. */
|
|
667
|
+
group = EC_GROUP_new_by_curve_name_mutable(nid);
|
|
668
|
+
#endif
|
|
664
669
|
if (group == NULL)
|
|
665
670
|
ossl_raise(eEC_GROUP, "unable to create curve (%"PRIsVALUE")", arg1);
|
|
666
671
|
|
|
@@ -670,32 +675,33 @@ static VALUE ossl_ec_group_initialize(int argc, VALUE *argv, VALUE self)
|
|
|
670
675
|
}
|
|
671
676
|
|
|
672
677
|
break;
|
|
673
|
-
|
|
678
|
+
case 4:
|
|
674
679
|
if (SYMBOL_P(arg1)) {
|
|
675
|
-
ID id = SYM2ID(arg1);
|
|
676
680
|
EC_GROUP *(*new_curve)(const BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *) = NULL;
|
|
677
681
|
const BIGNUM *p = GetBNPtr(arg2);
|
|
678
682
|
const BIGNUM *a = GetBNPtr(arg3);
|
|
679
683
|
const BIGNUM *b = GetBNPtr(arg4);
|
|
680
684
|
|
|
681
|
-
if (
|
|
685
|
+
if (arg1 == sym_GFp) {
|
|
682
686
|
new_curve = EC_GROUP_new_curve_GFp;
|
|
687
|
+
}
|
|
683
688
|
#if !defined(OPENSSL_NO_EC2M)
|
|
684
|
-
|
|
689
|
+
else if (arg1 == sym_GF2m) {
|
|
685
690
|
new_curve = EC_GROUP_new_curve_GF2m;
|
|
691
|
+
}
|
|
686
692
|
#endif
|
|
687
|
-
|
|
693
|
+
else {
|
|
688
694
|
ossl_raise(rb_eArgError, "unknown symbol, must be :GFp or :GF2m");
|
|
689
695
|
}
|
|
690
696
|
|
|
691
697
|
if ((group = new_curve(p, a, b, ossl_bn_ctx)) == NULL)
|
|
692
698
|
ossl_raise(eEC_GROUP, "EC_GROUP_new_by_GF*");
|
|
693
699
|
} else {
|
|
694
|
-
|
|
700
|
+
ossl_raise(rb_eArgError, "unknown argument, must be :GFp or :GF2m");
|
|
695
701
|
}
|
|
696
702
|
|
|
697
703
|
break;
|
|
698
|
-
|
|
704
|
+
default:
|
|
699
705
|
ossl_raise(rb_eArgError, "wrong number of arguments");
|
|
700
706
|
}
|
|
701
707
|
|
|
@@ -705,6 +711,7 @@ static VALUE ossl_ec_group_initialize(int argc, VALUE *argv, VALUE self)
|
|
|
705
711
|
return self;
|
|
706
712
|
}
|
|
707
713
|
|
|
714
|
+
/* :nodoc: */
|
|
708
715
|
static VALUE
|
|
709
716
|
ossl_ec_group_initialize_copy(VALUE self, VALUE other)
|
|
710
717
|
{
|
|
@@ -712,12 +719,12 @@ ossl_ec_group_initialize_copy(VALUE self, VALUE other)
|
|
|
712
719
|
|
|
713
720
|
TypedData_Get_Struct(self, EC_GROUP, &ossl_ec_group_type, group_new);
|
|
714
721
|
if (group_new)
|
|
715
|
-
|
|
722
|
+
ossl_raise(eEC_GROUP, "EC::Group already initialized");
|
|
716
723
|
GetECGroup(other, group);
|
|
717
724
|
|
|
718
725
|
group_new = EC_GROUP_dup(group);
|
|
719
726
|
if (!group_new)
|
|
720
|
-
|
|
727
|
+
ossl_raise(eEC_GROUP, "EC_GROUP_dup");
|
|
721
728
|
RTYPEDDATA_DATA(self) = group_new;
|
|
722
729
|
|
|
723
730
|
return self;
|
|
@@ -739,9 +746,9 @@ static VALUE ossl_ec_group_eql(VALUE a, VALUE b)
|
|
|
739
746
|
GetECGroup(b, group2);
|
|
740
747
|
|
|
741
748
|
switch (EC_GROUP_cmp(group1, group2, ossl_bn_ctx)) {
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
749
|
+
case 0: return Qtrue;
|
|
750
|
+
case 1: return Qfalse;
|
|
751
|
+
default: ossl_raise(eEC_GROUP, "EC_GROUP_cmp");
|
|
745
752
|
}
|
|
746
753
|
}
|
|
747
754
|
|
|
@@ -761,7 +768,7 @@ static VALUE ossl_ec_group_get_generator(VALUE self)
|
|
|
761
768
|
GetECGroup(self, group);
|
|
762
769
|
generator = EC_GROUP_get0_generator(group);
|
|
763
770
|
if (!generator)
|
|
764
|
-
|
|
771
|
+
return Qnil;
|
|
765
772
|
|
|
766
773
|
return ec_point_new(generator, group);
|
|
767
774
|
}
|
|
@@ -804,11 +811,10 @@ static VALUE ossl_ec_group_get_order(VALUE self)
|
|
|
804
811
|
{
|
|
805
812
|
VALUE bn_obj;
|
|
806
813
|
BIGNUM *bn;
|
|
807
|
-
EC_GROUP *group
|
|
814
|
+
EC_GROUP *group;
|
|
808
815
|
|
|
809
816
|
GetECGroup(self, group);
|
|
810
|
-
|
|
811
|
-
bn_obj = ossl_bn_new(NULL);
|
|
817
|
+
bn_obj = ossl_bn_new(BN_value_one());
|
|
812
818
|
bn = GetBNPtr(bn_obj);
|
|
813
819
|
|
|
814
820
|
if (EC_GROUP_get_order(group, bn, ossl_bn_ctx) != 1)
|
|
@@ -829,11 +835,10 @@ static VALUE ossl_ec_group_get_cofactor(VALUE self)
|
|
|
829
835
|
{
|
|
830
836
|
VALUE bn_obj;
|
|
831
837
|
BIGNUM *bn;
|
|
832
|
-
EC_GROUP *group
|
|
838
|
+
EC_GROUP *group;
|
|
833
839
|
|
|
834
840
|
GetECGroup(self, group);
|
|
835
|
-
|
|
836
|
-
bn_obj = ossl_bn_new(NULL);
|
|
841
|
+
bn_obj = ossl_bn_new(BN_value_one());
|
|
837
842
|
bn = GetBNPtr(bn_obj);
|
|
838
843
|
|
|
839
844
|
if (EC_GROUP_get_cofactor(group, bn, ossl_bn_ctx) != 1)
|
|
@@ -844,25 +849,23 @@ static VALUE ossl_ec_group_get_cofactor(VALUE self)
|
|
|
844
849
|
|
|
845
850
|
/*
|
|
846
851
|
* call-seq:
|
|
847
|
-
*
|
|
852
|
+
* group.curve_name -> string or nil
|
|
848
853
|
*
|
|
849
|
-
* Returns the curve name (
|
|
854
|
+
* Returns the curve name (short name) corresponding to this group, or +nil+
|
|
855
|
+
* if \OpenSSL does not have an OID associated with the group.
|
|
850
856
|
*
|
|
851
857
|
* See the OpenSSL documentation for EC_GROUP_get_curve_name()
|
|
852
858
|
*/
|
|
853
859
|
static VALUE ossl_ec_group_get_curve_name(VALUE self)
|
|
854
860
|
{
|
|
855
|
-
EC_GROUP *group
|
|
861
|
+
EC_GROUP *group;
|
|
856
862
|
int nid;
|
|
857
863
|
|
|
858
864
|
GetECGroup(self, group);
|
|
859
|
-
if (group == NULL)
|
|
860
|
-
return Qnil;
|
|
861
|
-
|
|
862
865
|
nid = EC_GROUP_get_curve_name(group);
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
return
|
|
866
|
+
if (nid == NID_undef)
|
|
867
|
+
return Qnil;
|
|
868
|
+
return rb_str_new_cstr(OBJ_nid2sn(nid));
|
|
866
869
|
}
|
|
867
870
|
|
|
868
871
|
/*
|
|
@@ -955,37 +958,36 @@ static VALUE ossl_ec_group_set_asn1_flag(VALUE self, VALUE flag_v)
|
|
|
955
958
|
*/
|
|
956
959
|
static VALUE ossl_ec_group_get_point_conversion_form(VALUE self)
|
|
957
960
|
{
|
|
958
|
-
EC_GROUP *group
|
|
961
|
+
EC_GROUP *group;
|
|
959
962
|
point_conversion_form_t form;
|
|
960
|
-
VALUE ret;
|
|
961
963
|
|
|
962
964
|
GetECGroup(self, group);
|
|
963
965
|
form = EC_GROUP_get_point_conversion_form(group);
|
|
964
966
|
|
|
965
967
|
switch (form) {
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
968
|
+
case POINT_CONVERSION_UNCOMPRESSED:
|
|
969
|
+
return sym_uncompressed;
|
|
970
|
+
case POINT_CONVERSION_COMPRESSED:
|
|
971
|
+
return sym_compressed;
|
|
972
|
+
case POINT_CONVERSION_HYBRID:
|
|
973
|
+
return sym_hybrid;
|
|
974
|
+
default:
|
|
975
|
+
ossl_raise(eEC_GROUP, "unsupported point conversion form: %d, " \
|
|
976
|
+
"this module should be updated", form);
|
|
970
977
|
}
|
|
971
|
-
|
|
972
|
-
return ID2SYM(ret);
|
|
973
978
|
}
|
|
974
979
|
|
|
975
980
|
static point_conversion_form_t
|
|
976
981
|
parse_point_conversion_form_symbol(VALUE sym)
|
|
977
982
|
{
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
if (
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
else
|
|
987
|
-
ossl_raise(rb_eArgError, "unsupported point conversion form %+"PRIsVALUE
|
|
988
|
-
" (expected :compressed, :uncompressed, or :hybrid)", sym);
|
|
983
|
+
if (sym == sym_uncompressed)
|
|
984
|
+
return POINT_CONVERSION_UNCOMPRESSED;
|
|
985
|
+
if (sym == sym_compressed)
|
|
986
|
+
return POINT_CONVERSION_COMPRESSED;
|
|
987
|
+
if (sym == sym_hybrid)
|
|
988
|
+
return POINT_CONVERSION_HYBRID;
|
|
989
|
+
ossl_raise(rb_eArgError, "unsupported point conversion form %+"PRIsVALUE
|
|
990
|
+
" (expected :compressed, :uncompressed, or :hybrid)", sym);
|
|
989
991
|
}
|
|
990
992
|
|
|
991
993
|
/*
|
|
@@ -1090,20 +1092,20 @@ static VALUE ossl_ec_group_to_string(VALUE self, int format)
|
|
|
1090
1092
|
ossl_raise(eEC_GROUP, "BIO_new(BIO_s_mem())");
|
|
1091
1093
|
|
|
1092
1094
|
switch(format) {
|
|
1093
|
-
|
|
1095
|
+
case EXPORT_PEM:
|
|
1094
1096
|
i = PEM_write_bio_ECPKParameters(out, group);
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
+
break;
|
|
1098
|
+
case EXPORT_DER:
|
|
1097
1099
|
i = i2d_ECPKParameters_bio(out, group);
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
+
break;
|
|
1101
|
+
default:
|
|
1100
1102
|
BIO_free(out);
|
|
1101
|
-
|
|
1103
|
+
ossl_raise(rb_eRuntimeError, "unknown format (internal error)");
|
|
1102
1104
|
}
|
|
1103
1105
|
|
|
1104
1106
|
if (i != 1) {
|
|
1105
1107
|
BIO_free(out);
|
|
1106
|
-
ossl_raise(
|
|
1108
|
+
ossl_raise(ePKeyError, NULL);
|
|
1107
1109
|
}
|
|
1108
1110
|
|
|
1109
1111
|
str = ossl_membio2str(out);
|
|
@@ -1147,11 +1149,11 @@ static VALUE ossl_ec_group_to_text(VALUE self)
|
|
|
1147
1149
|
|
|
1148
1150
|
GetECGroup(self, group);
|
|
1149
1151
|
if (!(out = BIO_new(BIO_s_mem()))) {
|
|
1150
|
-
|
|
1152
|
+
ossl_raise(eEC_GROUP, "BIO_new(BIO_s_mem())");
|
|
1151
1153
|
}
|
|
1152
1154
|
if (!ECPKParameters_print(out, group, 0)) {
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
+
BIO_free(out);
|
|
1156
|
+
ossl_raise(eEC_GROUP, NULL);
|
|
1155
1157
|
}
|
|
1156
1158
|
str = ossl_membio2str(out);
|
|
1157
1159
|
|
|
@@ -1171,7 +1173,7 @@ ossl_ec_point_free(void *ptr)
|
|
|
1171
1173
|
static const rb_data_type_t ossl_ec_point_type = {
|
|
1172
1174
|
"OpenSSL/EC_POINT",
|
|
1173
1175
|
{
|
|
1174
|
-
|
|
1176
|
+
0, ossl_ec_point_free,
|
|
1175
1177
|
},
|
|
1176
1178
|
0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
|
|
1177
1179
|
};
|
|
@@ -1191,7 +1193,7 @@ ec_point_new(const EC_POINT *point, const EC_GROUP *group)
|
|
|
1191
1193
|
obj = ossl_ec_point_alloc(cEC_POINT);
|
|
1192
1194
|
point_new = EC_POINT_dup(point, group);
|
|
1193
1195
|
if (!point_new)
|
|
1194
|
-
|
|
1196
|
+
ossl_raise(eEC_POINT, "EC_POINT_dup");
|
|
1195
1197
|
RTYPEDDATA_DATA(obj) = point_new;
|
|
1196
1198
|
rb_ivar_set(obj, id_i_group, ec_group_new(group));
|
|
1197
1199
|
|
|
@@ -1219,39 +1221,39 @@ static VALUE ossl_ec_point_initialize(int argc, VALUE *argv, VALUE self)
|
|
|
1219
1221
|
|
|
1220
1222
|
TypedData_Get_Struct(self, EC_POINT, &ossl_ec_point_type, point);
|
|
1221
1223
|
if (point)
|
|
1222
|
-
|
|
1224
|
+
rb_raise(eEC_POINT, "EC_POINT already initialized");
|
|
1223
1225
|
|
|
1224
1226
|
rb_scan_args(argc, argv, "11", &group_v, &arg2);
|
|
1225
1227
|
if (rb_obj_is_kind_of(group_v, cEC_POINT)) {
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1228
|
+
if (argc != 1)
|
|
1229
|
+
rb_raise(rb_eArgError, "invalid second argument");
|
|
1230
|
+
return ossl_ec_point_initialize_copy(self, group_v);
|
|
1229
1231
|
}
|
|
1230
1232
|
|
|
1231
1233
|
GetECGroup(group_v, group);
|
|
1232
1234
|
if (argc == 1) {
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1235
|
+
point = EC_POINT_new(group);
|
|
1236
|
+
if (!point)
|
|
1237
|
+
ossl_raise(eEC_POINT, "EC_POINT_new");
|
|
1236
1238
|
}
|
|
1237
1239
|
else {
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1240
|
+
if (rb_obj_is_kind_of(arg2, cBN)) {
|
|
1241
|
+
point = EC_POINT_bn2point(group, GetBNPtr(arg2), NULL, ossl_bn_ctx);
|
|
1242
|
+
if (!point)
|
|
1243
|
+
ossl_raise(eEC_POINT, "EC_POINT_bn2point");
|
|
1244
|
+
}
|
|
1245
|
+
else {
|
|
1246
|
+
StringValue(arg2);
|
|
1247
|
+
point = EC_POINT_new(group);
|
|
1248
|
+
if (!point)
|
|
1249
|
+
ossl_raise(eEC_POINT, "EC_POINT_new");
|
|
1250
|
+
if (!EC_POINT_oct2point(group, point,
|
|
1251
|
+
(unsigned char *)RSTRING_PTR(arg2),
|
|
1252
|
+
RSTRING_LEN(arg2), ossl_bn_ctx)) {
|
|
1253
|
+
EC_POINT_free(point);
|
|
1254
|
+
ossl_raise(eEC_POINT, "EC_POINT_oct2point");
|
|
1255
|
+
}
|
|
1256
|
+
}
|
|
1255
1257
|
}
|
|
1256
1258
|
|
|
1257
1259
|
RTYPEDDATA_DATA(self) = point;
|
|
@@ -1260,6 +1262,7 @@ static VALUE ossl_ec_point_initialize(int argc, VALUE *argv, VALUE self)
|
|
|
1260
1262
|
return self;
|
|
1261
1263
|
}
|
|
1262
1264
|
|
|
1265
|
+
/* :nodoc: */
|
|
1263
1266
|
static VALUE
|
|
1264
1267
|
ossl_ec_point_initialize_copy(VALUE self, VALUE other)
|
|
1265
1268
|
{
|
|
@@ -1269,7 +1272,7 @@ ossl_ec_point_initialize_copy(VALUE self, VALUE other)
|
|
|
1269
1272
|
|
|
1270
1273
|
TypedData_Get_Struct(self, EC_POINT, &ossl_ec_point_type, point_new);
|
|
1271
1274
|
if (point_new)
|
|
1272
|
-
|
|
1275
|
+
ossl_raise(eEC_POINT, "EC::Point already initialized");
|
|
1273
1276
|
GetECPoint(other, point);
|
|
1274
1277
|
|
|
1275
1278
|
group_v = rb_obj_dup(rb_attr_get(other, id_i_group));
|
|
@@ -1277,7 +1280,7 @@ ossl_ec_point_initialize_copy(VALUE self, VALUE other)
|
|
|
1277
1280
|
|
|
1278
1281
|
point_new = EC_POINT_dup(point, group);
|
|
1279
1282
|
if (!point_new)
|
|
1280
|
-
|
|
1283
|
+
ossl_raise(eEC_POINT, "EC_POINT_dup");
|
|
1281
1284
|
RTYPEDDATA_DATA(self) = point_new;
|
|
1282
1285
|
rb_ivar_set(self, id_i_group, group_v);
|
|
1283
1286
|
|
|
@@ -1304,9 +1307,9 @@ static VALUE ossl_ec_point_eql(VALUE a, VALUE b)
|
|
|
1304
1307
|
GetECGroup(group_v1, group);
|
|
1305
1308
|
|
|
1306
1309
|
switch (EC_POINT_cmp(group, point1, point2, ossl_bn_ctx)) {
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
+
case 0: return Qtrue;
|
|
1311
|
+
case 1: return Qfalse;
|
|
1312
|
+
default: ossl_raise(eEC_POINT, "EC_POINT_cmp");
|
|
1310
1313
|
}
|
|
1311
1314
|
|
|
1312
1315
|
UNREACHABLE;
|
|
@@ -1325,9 +1328,9 @@ static VALUE ossl_ec_point_is_at_infinity(VALUE self)
|
|
|
1325
1328
|
GetECPointGroup(self, group);
|
|
1326
1329
|
|
|
1327
1330
|
switch (EC_POINT_is_at_infinity(group, point)) {
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
+
case 1: return Qtrue;
|
|
1332
|
+
case 0: return Qfalse;
|
|
1333
|
+
default: ossl_raise(eEC_POINT, "EC_POINT_is_at_infinity");
|
|
1331
1334
|
}
|
|
1332
1335
|
|
|
1333
1336
|
UNREACHABLE;
|
|
@@ -1346,9 +1349,9 @@ static VALUE ossl_ec_point_is_on_curve(VALUE self)
|
|
|
1346
1349
|
GetECPointGroup(self, group);
|
|
1347
1350
|
|
|
1348
1351
|
switch (EC_POINT_is_on_curve(group, point, ossl_bn_ctx)) {
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
+
case 1: return Qtrue;
|
|
1353
|
+
case 0: return Qfalse;
|
|
1354
|
+
default: ossl_raise(eEC_POINT, "EC_POINT_is_on_curve");
|
|
1352
1355
|
}
|
|
1353
1356
|
|
|
1354
1357
|
UNREACHABLE;
|
|
@@ -1369,7 +1372,7 @@ static VALUE ossl_ec_point_make_affine(VALUE self)
|
|
|
1369
1372
|
GetECPointGroup(self, group);
|
|
1370
1373
|
|
|
1371
1374
|
rb_warn("OpenSSL::PKey::EC::Point#make_affine! is deprecated");
|
|
1372
|
-
#if !
|
|
1375
|
+
#if !defined(OSSL_HAVE_IMMUTABLE_PKEY) && !defined(OPENSSL_IS_AWSLC)
|
|
1373
1376
|
if (EC_POINT_make_affine(group, point, ossl_bn_ctx) != 1)
|
|
1374
1377
|
ossl_raise(eEC_POINT, "EC_POINT_make_affine");
|
|
1375
1378
|
#endif
|
|
@@ -1440,12 +1443,12 @@ ossl_ec_point_to_octet_string(VALUE self, VALUE conversion_form)
|
|
|
1440
1443
|
|
|
1441
1444
|
len = EC_POINT_point2oct(group, point, form, NULL, 0, ossl_bn_ctx);
|
|
1442
1445
|
if (!len)
|
|
1443
|
-
|
|
1446
|
+
ossl_raise(eEC_POINT, "EC_POINT_point2oct");
|
|
1444
1447
|
str = rb_str_new(NULL, (long)len);
|
|
1445
1448
|
if (!EC_POINT_point2oct(group, point, form,
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
+
(unsigned char *)RSTRING_PTR(str), len,
|
|
1450
|
+
ossl_bn_ctx))
|
|
1451
|
+
ossl_raise(eEC_POINT, "EC_POINT_point2oct");
|
|
1449
1452
|
return str;
|
|
1450
1453
|
}
|
|
1451
1454
|
|
|
@@ -1480,7 +1483,6 @@ static VALUE ossl_ec_point_add(VALUE self, VALUE other)
|
|
|
1480
1483
|
/*
|
|
1481
1484
|
* call-seq:
|
|
1482
1485
|
* point.mul(bn1 [, bn2]) => point
|
|
1483
|
-
* point.mul(bns, points [, bn2]) => point
|
|
1484
1486
|
*
|
|
1485
1487
|
* Performs elliptic curve point multiplication.
|
|
1486
1488
|
*
|
|
@@ -1488,11 +1490,9 @@ static VALUE ossl_ec_point_add(VALUE self, VALUE other)
|
|
|
1488
1490
|
* generator of the group of _point_. _bn2_ may be omitted, and in that case,
|
|
1489
1491
|
* the result is just <tt>bn1 * point</tt>.
|
|
1490
1492
|
*
|
|
1491
|
-
*
|
|
1492
|
-
*
|
|
1493
|
-
*
|
|
1494
|
-
* OpenSSL::PKey::EC::Point. Please note that <tt>points[0]</tt> is not
|
|
1495
|
-
* multiplied by <tt>bns[0]</tt>, but <tt>bns[1]</tt>.
|
|
1493
|
+
* Before version 4.0.0, and when compiled with OpenSSL 1.1.1 or older, this
|
|
1494
|
+
* method allowed another form:
|
|
1495
|
+
* point.mul(bns, points [, bn2]) => point
|
|
1496
1496
|
*/
|
|
1497
1497
|
static VALUE ossl_ec_point_mul(int argc, VALUE *argv, VALUE self)
|
|
1498
1498
|
{
|
|
@@ -1510,62 +1510,15 @@ static VALUE ossl_ec_point_mul(int argc, VALUE *argv, VALUE self)
|
|
|
1510
1510
|
GetECPoint(result, point_result);
|
|
1511
1511
|
|
|
1512
1512
|
rb_scan_args(argc, argv, "12", &arg1, &arg2, &arg3);
|
|
1513
|
-
if (
|
|
1514
|
-
|
|
1513
|
+
if (RB_TYPE_P(arg1, T_ARRAY) || argc > 2)
|
|
1514
|
+
rb_raise(rb_eNotImpError, "OpenSSL::PKey::EC::Point#mul with arrays " \
|
|
1515
|
+
"is no longer supported");
|
|
1515
1516
|
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
#if (defined(OPENSSL_VERSION_MAJOR) && OPENSSL_VERSION_MAJOR >= 3) || defined(LIBRESSL_VERSION_NUMBER)
|
|
1522
|
-
rb_raise(rb_eNotImpError, "calling #mul with arrays is not" \
|
|
1523
|
-
"supported by this OpenSSL version");
|
|
1524
|
-
#else
|
|
1525
|
-
/*
|
|
1526
|
-
* bignums | arg1[0] | arg1[1] | arg1[2] | ...
|
|
1527
|
-
* points | self | arg2[0] | arg2[1] | ...
|
|
1528
|
-
*/
|
|
1529
|
-
long i, num;
|
|
1530
|
-
VALUE bns_tmp, tmp_p, tmp_b;
|
|
1531
|
-
const EC_POINT **points;
|
|
1532
|
-
const BIGNUM **bignums;
|
|
1533
|
-
|
|
1534
|
-
Check_Type(arg1, T_ARRAY);
|
|
1535
|
-
Check_Type(arg2, T_ARRAY);
|
|
1536
|
-
if (RARRAY_LEN(arg1) != RARRAY_LEN(arg2) + 1) /* arg2 must be 1 larger */
|
|
1537
|
-
ossl_raise(rb_eArgError, "bns must be 1 longer than points; see the documentation");
|
|
1538
|
-
|
|
1539
|
-
rb_warning("OpenSSL::PKey::EC::Point#mul(ary, ary) is deprecated; " \
|
|
1540
|
-
"use #mul(bn) form instead");
|
|
1541
|
-
|
|
1542
|
-
num = RARRAY_LEN(arg1);
|
|
1543
|
-
bns_tmp = rb_ary_tmp_new(num);
|
|
1544
|
-
bignums = ALLOCV_N(const BIGNUM *, tmp_b, num);
|
|
1545
|
-
for (i = 0; i < num; i++) {
|
|
1546
|
-
VALUE item = RARRAY_AREF(arg1, i);
|
|
1547
|
-
bignums[i] = GetBNPtr(item);
|
|
1548
|
-
rb_ary_push(bns_tmp, item);
|
|
1549
|
-
}
|
|
1550
|
-
|
|
1551
|
-
points = ALLOCV_N(const EC_POINT *, tmp_p, num);
|
|
1552
|
-
points[0] = point_self; /* self */
|
|
1553
|
-
for (i = 0; i < num - 1; i++)
|
|
1554
|
-
GetECPoint(RARRAY_AREF(arg2, i), points[i + 1]);
|
|
1555
|
-
|
|
1556
|
-
if (!NIL_P(arg3))
|
|
1557
|
-
bn_g = GetBNPtr(arg3);
|
|
1558
|
-
|
|
1559
|
-
if (EC_POINTs_mul(group, point_result, bn_g, num, points, bignums, ossl_bn_ctx) != 1) {
|
|
1560
|
-
ALLOCV_END(tmp_b);
|
|
1561
|
-
ALLOCV_END(tmp_p);
|
|
1562
|
-
ossl_raise(eEC_POINT, NULL);
|
|
1563
|
-
}
|
|
1564
|
-
|
|
1565
|
-
ALLOCV_END(tmp_b);
|
|
1566
|
-
ALLOCV_END(tmp_p);
|
|
1567
|
-
#endif
|
|
1568
|
-
}
|
|
1517
|
+
BIGNUM *bn = GetBNPtr(arg1);
|
|
1518
|
+
if (!NIL_P(arg2))
|
|
1519
|
+
bn_g = GetBNPtr(arg2);
|
|
1520
|
+
if (EC_POINT_mul(group, point_result, bn_g, point_self, bn, ossl_bn_ctx) != 1)
|
|
1521
|
+
ossl_raise(eEC_POINT, NULL);
|
|
1569
1522
|
|
|
1570
1523
|
return result;
|
|
1571
1524
|
}
|
|
@@ -1573,15 +1526,6 @@ static VALUE ossl_ec_point_mul(int argc, VALUE *argv, VALUE self)
|
|
|
1573
1526
|
void Init_ossl_ec(void)
|
|
1574
1527
|
{
|
|
1575
1528
|
#undef rb_intern
|
|
1576
|
-
#if 0
|
|
1577
|
-
mPKey = rb_define_module_under(mOSSL, "PKey");
|
|
1578
|
-
cPKey = rb_define_class_under(mPKey, "PKey", rb_cObject);
|
|
1579
|
-
eOSSLError = rb_define_class_under(mOSSL, "OpenSSLError", rb_eStandardError);
|
|
1580
|
-
ePKeyError = rb_define_class_under(mPKey, "PKeyError", eOSSLError);
|
|
1581
|
-
#endif
|
|
1582
|
-
|
|
1583
|
-
eECError = rb_define_class_under(mPKey, "ECError", ePKeyError);
|
|
1584
|
-
|
|
1585
1529
|
/*
|
|
1586
1530
|
* Document-class: OpenSSL::PKey::EC
|
|
1587
1531
|
*
|
|
@@ -1603,17 +1547,15 @@ void Init_ossl_ec(void)
|
|
|
1603
1547
|
eEC_GROUP = rb_define_class_under(cEC_GROUP, "Error", eOSSLError);
|
|
1604
1548
|
eEC_POINT = rb_define_class_under(cEC_POINT, "Error", eOSSLError);
|
|
1605
1549
|
|
|
1606
|
-
|
|
1607
|
-
|
|
1550
|
+
sym_GFp = ID2SYM(rb_intern_const("GFp"));
|
|
1551
|
+
sym_GF2m = ID2SYM(rb_intern_const("GF2m"));
|
|
1608
1552
|
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1553
|
+
sym_uncompressed = ID2SYM(rb_intern_const("uncompressed"));
|
|
1554
|
+
sym_compressed = ID2SYM(rb_intern_const("compressed"));
|
|
1555
|
+
sym_hybrid = ID2SYM(rb_intern_const("hybrid"));
|
|
1612
1556
|
|
|
1613
1557
|
rb_define_const(cEC, "NAMED_CURVE", INT2NUM(OPENSSL_EC_NAMED_CURVE));
|
|
1614
|
-
#if defined(OPENSSL_EC_EXPLICIT_CURVE)
|
|
1615
1558
|
rb_define_const(cEC, "EXPLICIT_CURVE", INT2NUM(OPENSSL_EC_EXPLICIT_CURVE));
|
|
1616
|
-
#endif
|
|
1617
1559
|
|
|
1618
1560
|
rb_define_singleton_method(cEC, "builtin_curves", ossl_s_builtin_curves, 0);
|
|
1619
1561
|
|