Skip to content

Module BSV::Primitives::Curve

Low-level secp256k1 elliptic curve operations.

Backed by the pure Ruby {Secp256k1} module via an OpenSSL compatibility shim. The shim preserves the OpenSSL::PKey::EC interface so consumer code is unchanged. All constants and methods operate on the secp256k1 curve.

Constants

G

The generator point (base point).

GROUP

The secp256k1 curve group.

HALF_N

Half the curve order, used for low-S normalisation.

N

The curve order (number of points on the curve).

Public Class Methods

add_points(point_a, point_b)

Add two curve points together.

Uses +Point#add+ where available (Ruby 3.0+ / OpenSSL 3), falling back to multi-scalar multiplication for Ruby 2.7 compatibility. - @param point_a [OpenSSL::PKey::EC::Point] first point - @param point_b [OpenSSL::PKey::EC::Point] second point - @return [OpenSSL::PKey::EC::Point] the sum of the two points

multiply_generator(scalar_bn)

Multiply the generator point by a scalar (constant-time).

Uses the Montgomery ladder by default, matching OpenSSL convention. Safe for both secret and public scalars. For explicit variable-time multiplication of public scalars, use {multiply_generator_vt}. - @param scalar_bn [OpenSSL::BN] the scalar multiplier - @return [OpenSSL::PKey::EC::Point] the resulting curve point

multiply_generator_ct(scalar_bn)

Multiply the generator point by a secret scalar (constant-time).

Alias for {multiply_generator} — retained for backward compatibility and expressiveness. - @param scalar_bn [OpenSSL::BN] the secret scalar multiplier - @return [OpenSSL::PKey::EC::Point] the resulting curve point

multiply_generator_vt(scalar_bn)

Multiply the generator point by a public scalar (variable-time, wNAF).

Faster than {multiply_generator} but leaks timing information about the scalar. Use only for public scalars (e.g. signature verification). - @param scalar_bn [OpenSSL::BN] the public scalar multiplier - @return [OpenSSL::PKey::EC::Point] the resulting curve point

multiply_point(point, scalar_bn)

Multiply an arbitrary curve point by a scalar (constant-time).

Uses the Montgomery ladder by default, matching OpenSSL convention. Safe for both secret and public scalars. For explicit variable-time multiplication of public scalars, use {multiply_point_vt}. - @param point [OpenSSL::PKey::EC::Point] the point to multiply - @param scalar_bn [OpenSSL::BN] the scalar multiplier - @return [OpenSSL::PKey::EC::Point] the resulting curve point

multiply_point_ct(point, scalar_bn)

Multiply an arbitrary curve point by a secret scalar (constant-time).

Alias for {multiply_point} — retained for backward compatibility and expressiveness. - @param point [OpenSSL::PKey::EC::Point] the base point - @param scalar_bn [OpenSSL::BN] the secret scalar multiplier - @return [OpenSSL::PKey::EC::Point] the resulting curve point

multiply_point_vt(point, scalar_bn)

Multiply an arbitrary curve point by a public scalar (variable-time, wNAF).

Faster than {multiply_point} but leaks timing information about the scalar. Use only for public scalars (e.g. signature verification). - @param point [OpenSSL::PKey::EC::Point] the point to multiply - @param scalar_bn [OpenSSL::BN] the public scalar multiplier - @return [OpenSSL::PKey::EC::Point] the resulting curve point

point_from_bytes(bytes)

Reconstruct a curve point from its byte representation. - @param bytes [String] compressed (33 bytes) or uncompressed (65 bytes) point encoding - @return [OpenSSL::PKey::EC::Point] the decoded curve point

point_x(point)

Extract the x-coordinate from a curve point as a big number. - @param point [OpenSSL::PKey::EC::Point] the curve point - @return [OpenSSL::BN] the x-coordinate