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, string, string) | 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, string, string)
-
Create EC group and generator point from curve specification
Parameters:
- curve string, table or number curve specification (name, parameters, or NID)
- string [opt] |number flag asn1_flag
- string [opt] |number flag asn1_flag
Returns:
- ec_group the elliptic curve group
- ec_point the generator point
Usage:
group = require('openssl').group g = group.new('prime256v1') g = group.new(415) -- NID for prime256v1
- dup ()
-
Duplicate an EC_GROUP.
Returns:
-
ec_group
duplicated elliptic curve group
- generator ()
-
Get the generator point of the group.
Returns:
-
ec_point
generator point of the curve
- order ()
-
Get the order of the group.
Returns:
-
bn
order of the group
- cofactor ()
-
Get the cofactor of the group.
Returns:
-
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)
- 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)
- 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 ec_group EC group to compare
Returns:
-
boolean
true if equal, false otherwise
- point_new ()
-
Create a new EC point on this group.
Returns:
-
ec_point
new elliptic curve point (at infinity)
- point_dup (point)
-
Duplicate an EC point on this group.
Parameters:
- point ec_point the EC point to duplicate
Returns:
-
ec_point
duplicated EC point
- point_equal (a, b)
-
Compare two EC points for equality.
Parameters:
- a ec_point first EC point
- b ec_point second EC point
Returns:
-
boolean
true if equal, false otherwise
- point2oct (point[, form])
-
Convert EC point to octet string.
Parameters:
- point 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 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 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 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 ec_group the EC group
- point ec_point the EC point
- x bn x coordinate (for setting) (optional)
- y bn y coordinate (for setting) (optional)
Returns:
- bn x coordinate (when getting)
- bn y coordinate (when getting)
- set_to_infinity (group)
-
Set EC point to infinity.
Parameters:
- group ec_group the EC group
Returns:
-
ec_point
self
- is_at_infinity (group)
-
Check if EC point is at infinity.
Parameters:
- group 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 ec_group the EC group
Returns:
-
boolean
true if on curve, false otherwise
- point_add (group, a, b)
-
Add two EC points.
Parameters:
- group ec_group the EC group
- a ec_point first point
- b ec_point second point
Returns:
-
ec_point
result point (a + b)
- point_dbl (group)
-
Double an EC point.
Parameters:
- group ec_group the EC group
Returns:
-
ec_point
result point (2 * point)
- point_invert (group)
-
Invert an EC point.
Parameters:
- group ec_group the EC group
Returns:
-
ec_point
self (inverted)
- point_mul (group, n[, q[, m]])
-
Multiply EC point by a scalar.
Parameters:
- group ec_group the EC group
- n bn or number scalar multiplier
- q ec_point optional point for double scalar multiplication (optional)
- m bn optional second scalar for double scalar multiplication (optional)
Returns:
-
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