ecp256.bend checks
raw source on the hub · import element-crypto@0.1.0.0/ecp256.bend as Ecp256
3 imports
import Base import ./fep256.bend as F import ./fen256.bend as N
Types
type Pt source · line 17 · raw
Data
Pt@x:0x29d6f1ff259add9ea6c8f213fda12377/fep256.Fe -> @y:0x29d6f1ff259add9ea6c8f213fda12377/fep256.Fe -> @z:0x29d6f1ff259add9ea6c8f213fda12377/fep256.Fe -> Pt
Definitions
def b source · line 21 · raw
0x29d6f1ff259add9ea6c8f213fda12377/fep256.Fe
b, G in Montgomery form.
def base source · line 24 · raw
Pt
def infinity source · line 27 · raw
Pt
def is_inf source · line 30 · raw
@p:Pt -> Bool
def dbl source · line 36 · raw
@p:Pt -> Pt
dbl-2001-b (a = -3). Infinity (Z = 0) and Y = 0 both give Z3 = 0.
def add_general source · line 56 · raw
@p:Pt -> @q:Pt -> @+u1:0x29d6f1ff259add9ea6c8f213fda12377/fep256.Fe -> @+s1:0x29d6f1ff259add9ea6c8f213fda12377/fep256.Fe -> @+h:0x29d6f1ff259add9ea6c8f213fda12377/fep256.Fe -> @+r0:0x29d6f1ff259add9ea6c8f213fda12377/fep256.Fe -> @+z1z1:0x29d6f1ff259add9ea6c8f213fda12377/fep256.Fe -> @+z2z2:0x29d6f1ff259add9ea6c8f213fda12377/fep256.Fe -> Pt
add-2007-bl, general case (P != +-Q, neither at infinity).
def add_case source · line 71 · raw
@inf1:Bool -> @inf2:Bool -> @hz:Bool -> @rz:Bool -> @+p:Pt -> @+q:Pt -> @+u1:0x29d6f1ff259add9ea6c8f213fda12377/fep256.Fe -> @+s1:0x29d6f1ff259add9ea6c8f213fda12377/fep256.Fe -> @+h:0x29d6f1ff259add9ea6c8f213fda12377/fep256.Fe -> @+r0:0x29d6f1ff259add9ea6c8f213fda12377/fep256.Fe -> @+z1z1:0x29d6f1ff259add9ea6c8f213fda12377/fep256.Fe -> @+z2z2:0x29d6f1ff259add9ea6c8f213fda12377/fep256.Fe -> Pt
def add source · line 90 · raw
@p:Pt -> @q:Pt -> Pt
def pick_add source · line 101 · raw
@b1:Bool -> @b2:Bool -> @+d:Pt -> @+g:Pt -> @+q:Pt -> @+gq:Pt -> Pt
def joint source · line 117 · raw
@b1s:List<&2, Bool> -> @b2s:List<&2, Bool> -> @+g:Pt -> @+q:Pt -> @+gq:Pt -> @+acc:Pt -> Pt
u1 G + u2 Q from both scalars' bits, most significant first.
def on_curve source · line 129 · raw
@+x:0x29d6f1ff259add9ea6c8f213fda12377/fep256.Fe -> @+y:0x29d6f1ff259add9ea6c8f213fda12377/fep256.Fe -> Bool
y^2 = x^3 - 3x + b, x and y in Montgomery form.
def point_ok source · line 133 · raw
@+qx:List<&2, U32> -> @+qy:List<&2, U32> -> Bool
The public point from its big-endian coordinates: both below p and on the curve.
def point_of source · line 138 · raw
@+qx:List<&2, U32> -> @+qy:List<&2, U32> -> Pt
def affine_x source · line 142 · raw
@p:Pt -> List<&2, U32>
The affine x as big-endian bytes (one inversion).
def affine source · line 149 · raw
@p:Pt -> List<&2, U32>
X then Y, affine, big-endian.
def finite_x source · line 156 · raw
@inf:Bool -> @+p:Pt -> Maybe<&2, List<&2, U32>>
def joint_x source · line 165 · raw
@b1s:List<&2, Bool> -> @b2s:List<&2, Bool> -> @+qx:List<&2, U32> -> @+qy:List<&2, U32> -> Maybe<&2, List<&2, U32>>
x of u1 G + u2 Q (the scalars as bits, top first), or None at infinity. The caller has checked the point (point_ok).
def byte_bools source · line 173 · raw
@c:Nat -> @+b:U32 -> List<&2, Bool>
def bools_of_bytes source · line 181 · raw
@bs:List<&2, U32> -> List<&2, Bool>
Bits of big-endian bytes, most significant first.
def in_range_n source · line 189 · raw
@+x:0x29d6f1ff259add9ea6c8f213fda12377/fen256.Fe -> Bool
0 < x < n, for x read from bytes.
def x_matches source · line 193 · raw
@m:Maybe<&2, List<&2, U32>> -> @+r:0x29d6f1ff259add9ea6c8f213fda12377/fen256.Fe -> Bool
x (below p, and p < 2n) mod n equals r.
def verify_if source · line 202 · raw
@ok:Bool -> @+qx:List<&2, U32> -> @+qy:List<&2, U32> -> @+r:0x29d6f1ff259add9ea6c8f213fda12377/fen256.Fe -> @+s:0x29d6f1ff259add9ea6c8f213fda12377/fen256.Fe -> @+e:0x29d6f1ff259add9ea6c8f213fda12377/fen256.Fe -> Bool
w = s^-1 (Montgomery form); u1 = e w and u2 = r w come out plain, as e and r enter plain (a b R^-1 of a plain and a Montgomery value is plain).
def verify_rs source · line 214 · raw
@+qx:List<&2, U32> -> @+qy:List<&2, U32> -> @+rb:List<&2, U32> -> @+sb:List<&2, U32> -> @+eb:List<&2, U32> -> Bool
(r, s) against the public point (qx, qy) and the truncated digest e, all big-endian; the caller has checked that none is longer than the curve's size.
def byte_bits source · line 221 · raw
@c:Nat -> @+b:U32 -> List<&2, U32>
def bits_of_bytes source · line 229 · raw
@bs:List<&2, U32> -> List<&2, U32>
Bits of big-endian bytes, most significant first, as 0 or 1.
def select_pt source · line 236 · raw
@+s:U32 -> @a:Pt -> @b:Pt -> Pt
def ladder source · line 242 · raw
@bits:List<&2, U32> -> @+p:Pt -> @+acc:Pt -> Pt
k P, top bit first: every bit doubles and adds, and the bit picks by a mask.
def times source · line 251 · raw
@+k:List<&2, U32> -> @+p:Pt -> Pt
k P for a scalar k as big-endian bytes.