module SecP256K1

Defined in:

bitcoinutil/secp256k1.cr

Constant Summary

EC_A = 0
EC_B = 7
EC_FIELD_SIZE = BigInt.new("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141", 16)
EC_GP = Point.new(EC_GX, EC_GY)
EC_GX = BigInt.new("55066263022277343669578718895168534326250603453777594175500187360389116729240")
EC_GY = BigInt.new("32670510020758816978083085130507043184471273380659243275938904335757337482424")
EC_PRIME = BigInt.new("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F", 16)
EC_VERBOSE = false

Class Method Summary

Class Method Detail

def self.coord_hex64(x : BigInt) #

return hex string of bigint. prepend '0' until 64-chars long


[View source]
def self.jive(pointA, pointB) #

jive() - Implementation of EC 'addition', which has nothing to do with addition. Draw line between pointA and pointB, and it will intersect curve in one other point -R. Reflect point -R over X-axis to end up at R, which is the result.


[View source]
def self.juke(point) #

juke() - Implementation of EC 'point doubling', which is a special case of EC Addition, where pointA and pointB are same. Draw tangent line at point, and it will intersect curve at point -R. Reflect point -R over X-axis to end up at R, which is the result.


[View source]
def self.modinv(a, n = EC_PRIME) #

Extended Euclidean Algorithm/'division' in elliptic curves


[View source]
def self.pubkey_format(point) #

returns compact public key format for point Consists of 2-char prefix '02' or '03' if odd followed by 64-char hex string of point.x


[View source]
def self.pubkey_format4(point) #

long point format


[View source]
def self.rand #

Return a random number up to 160 bits


[View source]
def self.sequence(gen_point, scalar) #

sequence() - Implementation of 'EC Multiplication', which is really hopping around the elliptic curve N times.


[View source]
def self.sign(datahash : BigInt, privKey : BigInt, rando : BigInt) #

Returns BigInt signature of datahash Note: rando needs to be same value for sign() and verify()


[View source]
def self.verify(sig : BigInt, datahash : BigInt, pubkeyPoint : Point, rando : BigInt) #

Verify that 'sig' was computed from datahash and rando using the private key that pubkeyPoint was derived from. @returns true if valid signature


[View source]