NAME
Math::EllipticCurve::Prime::Point - points for elliptic curve operations over prime fields
VERSION
version 0.002
SYNOPSIS
use Math::EllipticCurve::Prime::Point;
my $p = Math::EllipticCurve::Prime::Point->new(curve => 'secp256r1',
x => Math::BigInt->new('0x01ff'),
y => Math::BigInt->new('0x03bc')); # not real points on the curve
my $p2 = $p->double;
print "(" . $p2->x . ", " . $p2->y . ")\n";
# Creates a point at infinity.
my $p3 = Math::EllipticCurve::Prime::Point->new(curve => 'secp256r1');
# Creates a point from a hexadecimal SEC representation.
my $p4 = Math::EllipticCurve::Prime::Point->from_hex("0401ff03bc");
$p4->curve(Math::EllipticCurve::Prime->new(name => 'secp256r1'));
DESCRIPTION
This class represents a point on a given elliptic curve. Using the methods provided, arithmetic operations can be performed, including point addition and scalar multiplication. Currently the operations are limited to these, as these are the operations most commonly used in cryptography.
METHODS
new
Create a new point. This constructor takes a hash as its sole argument. If the arguments x and y are both provided, assumes that these are instances of Math::BigInt. If x and y are not both provided, creates a new point at infinity.
from_hex
This method takes a hexadecimal-encoded representation of a point in the SEC format and creates a new Math::EllipticCurve::Prime::Point object. Currently this only understands uncompressed points (first byte 0x04) and the point at infinity.
from_bytes
This method takes a representation of a point in the SEC format and creates a new Math::EllipticCurve::Prime::Point object. Calls from_hex under the hood.
to_hex
This method produces a hexadecimal string representing a point in the uncompressed SEC format.
to_bytes
This method produces a byte string representing a point in the uncompressed SEC format.
copy
Makes a copy of the current point.
clone
A synonym for copy.
bmul
Multiplies this point by a scalar. The scalar should be a Math::BigInt. Like Math::BigInt, this modifies the present point. If you want to preserve this point, use the copy method to create a clone of the current point.
Requires that a curve has been set.
badd
Adds this point to another point. Like Math::BigInt, this modifies the present point. If you want to preserve this point, use the copy method to create a clone of the current point.
Requires that a curve has been set.
bdbl
Doubles the current point. Like Math::BigInt, this modifies the present point. If you want to preserve this point, use the copy method to create a clone of the current point.
Requires that a curve has been set.
multiply
Multiplies this point by a scalar. Returns a new point object.
Requires that a curve has been set.
add
Adds this point to another point. Returns a new point object.
Requires that a curve has been set.
double
Doubles this point. Returns a new point object.
Requires that a curve has been set.
infinity
Returns true if this point is the point at infinity, false otherwise.
x
Returns a Math::BigInt representing the x-coordinate of the point. Returns undef if this is the point at infinity. You should make a copy of the returned object; otherwise, you will modify the point.
y
Returns a Math::BigInt representing the y-coordinate of the point. Returns undef if this is the point at infinity. You should make a copy of the returned object; otherwise, you will modify the point.
curve
Returns the Math::EllipticCurve::Prime curve associated with this point, if any. Optionally takes an argument to set the curve.
AUTHOR
brian m. carlson <sandals@crustytoothpaste.net>
COPYRIGHT AND LICENSE
This software is copyright (c) 2013 by brian m. carlson.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.