Class: OpenSSL::PKey::EC::Point
- Inherits:
-
Object
- Object
- OpenSSL::PKey::EC::Point
- Defined in:
- ossl_pkey_ec.c
Defined Under Namespace
Classes: Error
Instance Method Summary collapse
- #eql?(b) ⇒ Boolean (also: #==)
- #infinity? ⇒ Boolean
-
#initialize(*args) ⇒ Object
constructor
See the OpenSSL documentation for EC_POINT_*.
- #invert! ⇒ self
- #make_affine! ⇒ self
- #mul(*args) ⇒ Object
- #on_curve? ⇒ Boolean
- #set_to_infinity! ⇒ self
-
#to_bn ⇒ OpenSSL::BN
See the OpenSSL documentation for EC_POINT_point2bn().
Constructor Details
#OpenSSL::PKey::EC::Point.new(point) ⇒ Object #OpenSSL::PKey::EC::Point.new(group) ⇒ Object #OpenSSL::PKey::EC::Point.new(group, bn) ⇒ Object
See the OpenSSL documentation for EC_POINT_*
1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 |
# File 'ossl_pkey_ec.c', line 1269
static VALUE ossl_ec_point_initialize(int argc, VALUE *argv, VALUE self)
{
ossl_ec_point *ec_point;
EC_POINT *point = NULL;
VALUE arg1, arg2;
VALUE group_v = Qnil;
const EC_GROUP *group = NULL;
TypedData_Get_Struct(self, ossl_ec_point, &ossl_ec_point_type, ec_point);
if (ec_point->point)
ossl_raise(eEC_POINT, "EC_POINT already initialized");
switch (rb_scan_args(argc, argv, "11", &arg1, &arg2)) {
case 1:
if (rb_obj_is_kind_of(arg1, cEC_POINT)) {
const EC_POINT *arg_point;
group_v = rb_iv_get(arg1, "@group");
SafeRequire_EC_GROUP(group_v, group);
SafeRequire_EC_POINT(arg1, arg_point);
point = EC_POINT_dup(arg_point, group);
} else if (rb_obj_is_kind_of(arg1, cEC_GROUP)) {
group_v = arg1;
SafeRequire_EC_GROUP(group_v, group);
point = EC_POINT_new(group);
} else {
ossl_raise(eEC_POINT, "wrong argument type: must be OpenSSL::PKey::EC::Point or OpenSSL::Pkey::EC::Group");
}
break;
case 2:
if (!rb_obj_is_kind_of(arg1, cEC_GROUP))
ossl_raise(rb_eArgError, "1st argument must be OpenSSL::PKey::EC::Group");
group_v = arg1;
SafeRequire_EC_GROUP(group_v, group);
if (rb_obj_is_kind_of(arg2, cBN)) {
const BIGNUM *bn = GetBNPtr(arg2);
point = EC_POINT_bn2point(group, bn, NULL, ossl_bn_ctx);
} else {
BIO *in = ossl_obj2bio(arg1);
/* BUG: finish me */
BIO_free(in);
if (point == NULL) {
ossl_raise(eEC_POINT, "unknown type for 2nd arg");
}
}
break;
default:
ossl_raise(rb_eArgError, "wrong number of arguments");
}
if (point == NULL)
ossl_raise(eEC_POINT, NULL);
if (NIL_P(group_v))
ossl_raise(rb_eRuntimeError, "missing group (internal error)");
ec_point->point = point;
rb_iv_set(self, "@group", group_v);
return self;
}
|
Instance Method Details
#eql?(point2) ⇒ Boolean #==(point2) ⇒ Boolean Also known as: ==
1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 |
# File 'ossl_pkey_ec.c', line 1346
static VALUE ossl_ec_point_eql(VALUE a, VALUE b)
{
EC_POINT *point1, *point2;
VALUE group_v1 = rb_iv_get(a, "@group");
VALUE group_v2 = rb_iv_get(b, "@group");
const EC_GROUP *group;
if (ossl_ec_group_eql(group_v1, group_v2) == Qfalse)
return Qfalse;
Require_EC_POINT(a, point1);
SafeRequire_EC_POINT(b, point2);
SafeRequire_EC_GROUP(group_v1, group);
if (EC_POINT_cmp(group, point1, point2, ossl_bn_ctx) == 1)
return Qfalse;
return Qtrue;
}
|
#infinity? ⇒ Boolean
1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 |
# File 'ossl_pkey_ec.c', line 1371
static VALUE ossl_ec_point_is_at_infinity(VALUE self)
{
EC_POINT *point;
VALUE group_v = rb_iv_get(self, "@group");
const EC_GROUP *group;
Require_EC_POINT(self, point);
SafeRequire_EC_GROUP(group_v, group);
switch (EC_POINT_is_at_infinity(group, point)) {
case 1: return Qtrue;
case 0: return Qfalse;
default: ossl_raise(cEC_POINT, "EC_POINT_is_at_infinity");
}
UNREACHABLE;
}
|
#invert! ⇒ self
1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 |
# File 'ossl_pkey_ec.c', line 1437
static VALUE ossl_ec_point_invert(VALUE self)
{
EC_POINT *point;
VALUE group_v = rb_iv_get(self, "@group");
const EC_GROUP *group;
Require_EC_POINT(self, point);
SafeRequire_EC_GROUP(group_v, group);
if (EC_POINT_invert(group, point, ossl_bn_ctx) != 1)
ossl_raise(cEC_POINT, "EC_POINT_invert");
return self;
}
|
#make_affine! ⇒ self
1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 |
# File 'ossl_pkey_ec.c', line 1417
static VALUE ossl_ec_point_make_affine(VALUE self)
{
EC_POINT *point;
VALUE group_v = rb_iv_get(self, "@group");
const EC_GROUP *group;
Require_EC_POINT(self, point);
SafeRequire_EC_GROUP(group_v, group);
if (EC_POINT_make_affine(group, point, ossl_bn_ctx) != 1)
ossl_raise(cEC_POINT, "EC_POINT_make_affine");
return self;
}
|
#mul(bn) ⇒ Object #mul(bn, bn) ⇒ Object #mul([bn], [point]) ⇒ Object #mul([bn], [point], bn) ⇒ Object
1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 |
# File 'ossl_pkey_ec.c', line 1508
static VALUE ossl_ec_point_mul(int argc, VALUE *argv, VALUE self)
{
EC_POINT *point1, *point2;
const EC_GROUP *group;
VALUE group_v = rb_iv_get(self, "@group");
VALUE bn_v1, bn_v2, r, points_v;
BIGNUM *bn1 = NULL, *bn2 = NULL;
Require_EC_POINT(self, point1);
SafeRequire_EC_GROUP(group_v, group);
r = rb_obj_alloc(cEC_POINT);
ossl_ec_point_initialize(1, &group_v, r);
Require_EC_POINT(r, point2);
argc = rb_scan_args(argc, argv, "12", &bn_v1, &points_v, &bn_v2);
if (rb_obj_is_kind_of(bn_v1, cBN)) {
bn1 = GetBNPtr(bn_v1);
if (argc >= 2) {
bn2 = GetBNPtr(points_v);
}
if (EC_POINT_mul(group, point2, bn2, point1, bn1, ossl_bn_ctx) != 1)
ossl_raise(eEC_POINT, "Multiplication failed");
} else {
size_t i, points_len, bignums_len;
const EC_POINT **points;
const BIGNUM **bignums;
Check_Type(bn_v1, T_ARRAY);
bignums_len = RARRAY_LEN(bn_v1);
bignums = (const BIGNUM **)OPENSSL_malloc(bignums_len * (int)sizeof(BIGNUM *));
for (i = 0; i < bignums_len; ++i) {
bignums[i] = GetBNPtr(rb_ary_entry(bn_v1, i));
}
if (!rb_obj_is_kind_of(points_v, rb_cArray)) {
OPENSSL_free((void *)bignums);
rb_raise(rb_eTypeError, "Argument2 must be an array");
}
rb_ary_unshift(points_v, self);
points_len = RARRAY_LEN(points_v);
points = (const EC_POINT **)OPENSSL_malloc(points_len * (int)sizeof(EC_POINT *));
for (i = 0; i < points_len; ++i) {
Get_EC_POINT(rb_ary_entry(points_v, i), points[i]);
}
if (argc >= 3) {
bn2 = GetBNPtr(bn_v2);
}
if (EC_POINTs_mul(group, point2, bn2, points_len, points, bignums, ossl_bn_ctx) != 1) {
OPENSSL_free((void *)bignums);
OPENSSL_free((void *)points);
ossl_raise(eEC_POINT, "Multiplication failed");
}
OPENSSL_free((void *)bignums);
OPENSSL_free((void *)points);
}
return r;
}
|
#on_curve? ⇒ Boolean
1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 |
# File 'ossl_pkey_ec.c', line 1394
static VALUE ossl_ec_point_is_on_curve(VALUE self)
{
EC_POINT *point;
VALUE group_v = rb_iv_get(self, "@group");
const EC_GROUP *group;
Require_EC_POINT(self, point);
SafeRequire_EC_GROUP(group_v, group);
switch (EC_POINT_is_on_curve(group, point, ossl_bn_ctx)) {
case 1: return Qtrue;
case 0: return Qfalse;
default: ossl_raise(cEC_POINT, "EC_POINT_is_on_curve");
}
UNREACHABLE;
}
|
#set_to_infinity! ⇒ self
1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 |
# File 'ossl_pkey_ec.c', line 1457
static VALUE ossl_ec_point_set_to_infinity(VALUE self)
{
EC_POINT *point;
VALUE group_v = rb_iv_get(self, "@group");
const EC_GROUP *group;
Require_EC_POINT(self, point);
SafeRequire_EC_GROUP(group_v, group);
if (EC_POINT_set_to_infinity(group, point) != 1)
ossl_raise(cEC_POINT, "EC_POINT_set_to_infinity");
return self;
}
|
#to_bn ⇒ OpenSSL::BN
See the OpenSSL documentation for EC_POINT_point2bn()
1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 |
# File 'ossl_pkey_ec.c', line 1478
static VALUE ossl_ec_point_to_bn(VALUE self)
{
EC_POINT *point;
VALUE bn_obj;
VALUE group_v = rb_iv_get(self, "@group");
const EC_GROUP *group;
point_conversion_form_t form;
BIGNUM *bn;
Require_EC_POINT(self, point);
SafeRequire_EC_GROUP(group_v, group);
form = EC_GROUP_get_point_conversion_form(group);
bn_obj = rb_obj_alloc(cBN);
bn = GetBNPtr(bn_obj);
if (EC_POINT_point2bn(group, point, form, bn, ossl_bn_ctx) == NULL)
ossl_raise(eEC_POINT, "EC_POINT_point2bn");
return bn_obj;
}
|