# module Secp256k1::Core

## Overview

Implements 256-bit `Secp256k1` Koblitz elliptic curve. Ref: secg.org/sec2-v2.pdf

`Secp256k1` has the characteristic prime `p`, it is defined over the prime field ℤ_p. Ref: en.bitcoin.it/wiki/Secp256k1

core.cr

## Class Method Detail

def self.ec_add(p : ECPoint, q : ECPoint, prime = EC_PRIME_P) #

The elliptic curve jive addition of point `p(x, y)` and `q(x, y)`.

We basically draw a line between `p` and `q` which will intersect the curve in the point `r` which will be mirrored over the `x`-axis.

Paramters:

• `p` (`ECPoint`): the point `p(x, y)` to be used in the jive addition.
• `q` (`ECPoint`): the point `q(x, y)` to be used in the jive addition.
• `prime` (`BigInt`): the prime number that shapes the field, default: `EC_PRIME_P`.

Returns another `ECPoint` as result.

def self.ec_double(p : ECPoint, prime = EC_PRIME_P) #

The elliptic curve juke point doubling of `p(x, y)`.

This is a special case of addition where both points are the same. We draw a tangent line at `p` which will intersect the curve at point `r` which will be mirrored over the `x`-axis.

Paramters:

• `p` (`ECPoint`): the point `p(x, y)` to be used in the juke doubling.
• `prime` (`BigInt`): the prime number that shapes the field, default: `EC_PRIME_P`.

Returns another `ECPoint` as result.

def self.ec_mod_inv(a : BigInt, prime = EC_PRIME_P) #

Computes the elliptic curve modular multiplicative inverse of `a`.

Paremeters:

• `a` (`BigInt`): the integer that we want the modular inverse of.
• `prime` (`BigInt`): the prime number that shapes the field, default: `EC_PRIME_P`.

Returns a `BigInt` value as result.

def self.ec_mul(p : ECPoint, s : BigInt) #

The elliptic curve sequence multiplication of point `p(x, y)` and a skalar `s`.

With `s` being a private key within the elliptic curve field size of `EC_ORDER_N`.

Paramters:

• `p` (`ECPoint`): the point `p(x, y)` to be used in the sequencing.
• `s` (`BigInt`): a skalar, in most cases a private key.

Returns another `ECPoint` as result, in most cases a public key.