Module ec.group
EC_GROUP module for Lua OpenSSL binding.
This module provides a complete wrapper for OpenSSL’s EC_GROUP operations, enabling elliptic curve group mathematical operations similar to BIGNUM.
Usage:
group = require('openssl').ec.group
Functions
| new (curve[, form[, flag]]) | Create EC group and generator point from curve specification |
| dup () | Duplicate an EC_GROUP. |
| generator () | Get the generator point of the group. |
| order () | Get the order of the group. |
| cofactor () | Get the cofactor of the group. |
| degree () | Get the degree of the group (field size in bits). |
| curve_name () | Get the curve name NID. |
| asn1_flag ([flag]) | Get or set the ASN1 flag. |
| point_conversion_form ([form]) | Get or set the point conversion form. |
| curve () | Get curve parameters (p, a, b). |
| seed () | Get the seed value for the group. |
| parse () | Parse the EC group to extract all parameters. |
| equal (other) | Compare two EC groups for equality. |
| point_new () | Create a new EC point on this group. |
| point_dup (point) | Duplicate an EC point on this group. |
| point_equal (a, b) | Compare two EC points for equality. |
| point2oct (point[, form]) | Convert EC point to octet string. |
| oct2point (oct) | Convert octet string to EC point. |
| point2bn (point[, form]) | Convert EC point to BIGNUM. |
| bn2point (bn) | Convert BIGNUM to EC point. |
| point2hex (point[, form]) | Convert EC point to hexadecimal string. |
| hex2point (hex) | Convert hexadecimal string to EC point. |
| affine_coordinates (group, point[, x[, y]]) | Get or set affine coordinates of an EC point. |
| set_to_infinity (group) | Set EC point to infinity. |
| is_at_infinity (group) | Check if EC point is at infinity. |
| is_on_curve (group) | Check if EC point is on the curve. |
| point_add (group, a, b) | Add two EC points. |
| point_dbl (group) | Double an EC point. |
| point_invert (group) | Invert an EC point. |
| point_mul (group, n[, q[, m]]) | Multiply EC point by a scalar. |
| generate_key () | Generate EC key pair from this group. |
| list () | List all available elliptic curve names. |
Functions
- new (curve[, form[, flag]])
-
Create EC group and generator point from curve specification
Parameters:
- curve string, table or number curve specification (name, parameters, or NID)
- form string or number point_conversion_form (optional)
- flag string or number asn1_flag (optional)
Returns:
-
openssl.ec_group
the elliptic curve group
Or
-
openssl.ec_point
the generator point
Or
- nil on error
- string error message — @see OpenSSL function: EC_GROUP_new_by_curve_name — @see OpenSSL function: EC_GROUP_new_curve_GFp
Usage:
local group = require('openssl').group -- Create group from curve name local ec_group, generator = group.new('prime256v1') -- Create group from NID local ec_group2, generator2 = group.new(415) -- NID for prime256v1 -- Create group with parameters local ec_group3, generator3 = group.new({ p = '0xFFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF', a = '0xFFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFC', b = '0x5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B', order = '0xFFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551', generator = '046B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C2964FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5', cofactor = 1 })
- dup ()
-
Duplicate an EC_GROUP.
Returns:
-
openssl.ec_group
duplicated elliptic curve group
- generator ()
-
Get the generator point of the group.
Returns:
-
openssl.ec_point
generator point of the curve
- order ()
-
Get the order of the group.
Returns:
-
openssl.bn
order of the group
- cofactor ()
-
Get the cofactor of the group.
Returns:
-
openssl.bn
cofactor of the group
- degree ()
-
Get the degree of the group (field size in bits).
Returns:
-
number
degree of the group
- curve_name ()
-
Get the curve name NID.
Returns:
-
number
NID of the curve
- asn1_flag ([flag])
-
Get or set the ASN1 flag.
Parameters:
- flag string or number ASN1 flag (“explicit” or “named_curve”) (optional)
Returns:
- string or number current ASN1 flag (when getting)
- openssl.ec_group self (when setting)
- point_conversion_form ([form])
-
Get or set the point conversion form.
Parameters:
- form string or number point conversion form (“compressed”, “uncompressed”, or “hybrid”) (optional)
Returns:
- string or number current conversion form (when getting)
- openssl.ec_group self (when setting)
- curve ()
-
Get curve parameters (p, a, b).
Returns:
-
table
containing p, a, b as BIGNUM objects
- seed ()
-
Get the seed value for the group.
Returns:
-
string or nil
seed value or nil if not set
- parse ()
-
Parse the EC group to extract all parameters.
Returns:
-
table
containing all group parameters (generator, order, cofactor, degree, curve_name, etc.)
- equal (other)
-
Compare two EC groups for equality.
Parameters:
- other openssl.ec_group EC group to compare
Returns:
-
boolean
true if equal, false otherwise
- point_new ()
-
Create a new EC point on this group.
Returns:
-
openssl.ec_point
new elliptic curve point (at infinity)
- point_dup (point)
-
Duplicate an EC point on this group.
Parameters:
- point openssl.ec_point the EC point to duplicate
Returns:
-
openssl.ec_point
duplicated EC point
- point_equal (a, b)
-
Compare two EC points for equality.
Parameters:
- a openssl.ec_point first EC point
- b openssl.ec_point second EC point
Returns:
-
boolean
true if equal, false otherwise
- point2oct (point[, form])
-
Convert EC point to octet string.
Parameters:
- point openssl.ec_point the EC point
- form string point conversion form (“compressed”, “uncompressed”, or “hybrid”) (optional)
Returns:
-
string or nil
octet string representation or nil on failure
- oct2point (oct)
-
Convert octet string to EC point.
Parameters:
- oct string octet string representation
Returns:
-
ec_point or nil
the resulting EC point or nil on failure
- point2bn (point[, form])
-
Convert EC point to BIGNUM.
Parameters:
- point openssl.ec_point the EC point
- form string point conversion form (“compressed”, “uncompressed”, or “hybrid”) (optional)
Returns:
-
bn or nil
the resulting BIGNUM or nil on failure
- bn2point (bn)
-
Convert BIGNUM to EC point.
Parameters:
- bn openssl.bn the BIGNUM to convert
Returns:
-
ec_point or nil
the resulting EC point or nil on failure
- point2hex (point[, form])
-
Convert EC point to hexadecimal string.
Parameters:
- point openssl.ec_point the EC point
- form string point conversion form (“compressed”, “uncompressed”, or “hybrid”) (optional)
Returns:
-
string or nil
hexadecimal string representation or nil on failure
- hex2point (hex)
-
Convert hexadecimal string to EC point.
Parameters:
- hex string hexadecimal string representation
Returns:
-
ec_point or nil
the resulting EC point or nil on failure
- affine_coordinates (group, point[, x[, y]])
-
Get or set affine coordinates of an EC point.
Parameters:
- group openssl.ec_group the EC group
- point openssl.ec_point the EC point
- x openssl.bn x coordinate (for setting) (optional)
- y openssl.bn y coordinate (for setting) (optional)
Returns:
- openssl.bn x coordinate (when getting)
- openssl.bn y coordinate (when getting)
- set_to_infinity (group)
-
Set EC point to infinity.
Parameters:
- group openssl.ec_group the EC group
Returns:
-
openssl.ec_point
self
- is_at_infinity (group)
-
Check if EC point is at infinity.
Parameters:
- group openssl.ec_group the EC group
Returns:
-
boolean
true if at infinity, false otherwise
- is_on_curve (group)
-
Check if EC point is on the curve.
Parameters:
- group openssl.ec_group the EC group
Returns:
-
boolean
true if on curve, false otherwise
- point_add (group, a, b)
-
Add two EC points.
Parameters:
- group openssl.ec_group the EC group
- a openssl.ec_point first point
- b openssl.ec_point second point
Returns:
-
openssl.ec_point
result point (a + b)
- point_dbl (group)
-
Double an EC point.
Parameters:
- group openssl.ec_group the EC group
Returns:
-
openssl.ec_point
result point (2 * point)
- point_invert (group)
-
Invert an EC point.
Parameters:
- group openssl.ec_group the EC group
Returns:
-
openssl.ec_point
self (inverted)
- point_mul (group, n[, q[, m]])
-
Multiply EC point by a scalar.
Parameters:
- group openssl.ec_group the EC group
- n bn or number scalar multiplier
- q openssl.ec_point optional point for double scalar multiplication (optional)
- m openssl.bn optional second scalar for double scalar multiplication (optional)
Returns:
-
openssl.ec_point
result point (n point) or (n point + m * q)
- generate_key ()
-
Generate EC key pair from this group.
Returns:
-
ec_key
generated EC key object or nil if failed
- list ()
-
List all available elliptic curve names.
Returns:
-
table
array of curve names and descriptions