~/bend-docscommunity

ecdsa.bend checks

raw source on the hub · import element-crypto@0.1.0.0/ecdsa.bend as Ecdsa

6 imports
import Base
import element-math@0.1.0.0/big.bend as Big
import ./hash.bend as Hash
import ./hmac.bend as Hmac
import ./ecp256.bend as E256
import ./ecp384.bend as E384

Types

type Field source · line 22 · raw

Data

type Curve source · line 26 · raw

Data

type BigCurve source · line 44 · raw

Data

type Pt source · line 47 · raw

Data

Definitions

def p256 source · line 29 · raw

Curve

def p384 source · line 32 · raw

Curve

def verify_rs source · line 35 · raw

@fld:Field -> @+qx:List<&2, U32> -> @+qy:List<&2, U32> -> @+r:List<&2, U32> -> @+s:List<&2, U32> -> @+e:List<&2, U32> -> Bool

def num source · line 50 · raw

@+s:String -> List<&2, U32>

def curve source · line 53 · raw

@+p:String -> @+b:String -> @+n:String -> @+gx:String -> @+gy:String -> @+size:Nat -> BigCurve

def p256_big source · line 57 · raw

BigCurve

def p384_big source · line 66 · raw

BigCurve

def pt source · line 75 · raw

@+x:List<&2, U32> -> @+y:List<&2, U32> -> @+z:List<&2, U32> -> Pt

def mm source · line 80 · raw

@+f:0x280fb10bca5c5d06ed8109bb4300bab8/big.Mod -> @+a:List<&2, U32> -> @+b:List<&2, U32> -> List<&2, U32>

def fa source · line 83 · raw

@+f:0x280fb10bca5c5d06ed8109bb4300bab8/big.Mod -> @+a:List<&2, U32> -> @+b:List<&2, U32> -> List<&2, U32>

def fs source · line 86 · raw

@+f:0x280fb10bca5c5d06ed8109bb4300bab8/big.Mod -> @+a:List<&2, U32> -> @+b:List<&2, U32> -> List<&2, U32>

def times8 source · line 89 · raw

@+f:0x280fb10bca5c5d06ed8109bb4300bab8/big.Mod -> @+a:List<&2, U32> -> List<&2, U32>

def infinity source · line 94 · raw

@+f:0x280fb10bca5c5d06ed8109bb4300bab8/big.Mod -> Pt

def dbl source · line 99 · raw

@+f:0x280fb10bca5c5d06ed8109bb4300bab8/big.Mod -> @p:Pt -> Pt

dbl-2001-b (a = -3). Infinity (Z = 0) and Y = 0 both give Z3 = 0.

def add_general source · line 116 · raw

@+f:0x280fb10bca5c5d06ed8109bb4300bab8/big.Mod -> @p:Pt -> @q:Pt -> @+u1:List<&2, U32> -> @+s1:List<&2, U32> -> @+h:List<&2, U32> -> @+r0:List<&2, U32> -> @+z1z1:List<&2, U32> -> @+z2z2:List<&2, U32> -> Pt

add-2007-bl, general case (P != +-Q, neither at infinity).

def add_case source · line 131 · raw

@inf1:Bool -> @inf2:Bool -> @hz:Bool -> @rz:Bool -> @+f:0x280fb10bca5c5d06ed8109bb4300bab8/big.Mod -> @+p:Pt -> @+q:Pt -> @+u1:List<&2, U32> -> @+s1:List<&2, U32> -> @+h:List<&2, U32> -> @+r0:List<&2, U32> -> @+z1z1:List<&2, U32> -> @+z2z2:List<&2, U32> -> Pt

def add source · line 150 · raw

@+f:0x280fb10bca5c5d06ed8109bb4300bab8/big.Mod -> @p:Pt -> @q:Pt -> Pt

def pick_add source · line 161 · raw

@b1:Bool -> @b2:Bool -> @+f:0x280fb10bca5c5d06ed8109bb4300bab8/big.Mod -> @+d:Pt -> @+g:Pt -> @+q:Pt -> @+gq:Pt -> Pt

def joint source · line 177 · raw

@b1s:List<&2, Bool> -> @b2s:List<&2, Bool> -> @+f:0x280fb10bca5c5d06ed8109bb4300bab8/big.Mod -> @+g:Pt -> @+q:Pt -> @+gq:Pt -> @+acc:Pt -> Pt

u1 G + u2 Q from both scalars' bits, most significant first.

def drop_zeros source · line 190 · raw

@bs:List<&2, U32> -> List<&2, U32>

def reduce_once source · line 198 · raw

@+m:0x280fb10bca5c5d06ed8109bb4300bab8/big.Mod -> @+x:List<&2, U32> -> List<&2, U32>

x mod m for x below 2m.

def fits source · line 202 · raw

@+size:Nat -> @+bs:List<&2, U32> -> Bool

A big-endian integer of at most size bytes, as k limbs; ok says it fit.

def limbs source · line 205 · raw

@+m:0x280fb10bca5c5d06ed8109bb4300bab8/big.Mod -> @+bs:List<&2, U32> -> List<&2, U32>

def in_range source · line 208 · raw

@+m:0x280fb10bca5c5d06ed8109bb4300bab8/big.Mod -> @+x:List<&2, U32> -> Bool

def on_curve source · line 211 · raw

@+f:0x280fb10bca5c5d06ed8109bb4300bab8/big.Mod -> @+b:List<&2, U32> -> @+x:List<&2, U32> -> @+y:List<&2, U32> -> Bool

def x_of source · line 214 · raw

@+f:0x280fb10bca5c5d06ed8109bb4300bab8/big.Mod -> @p:Pt -> List<&2, U32>

def is_inf source · line 220 · raw

@p:Pt -> Bool

def verify source · line 228 · raw

@c:Curve -> @+h:0x29d6f1ff259add9ea6c8f213fda12377/hash.Hash -> @+qx:List<&2, U32> -> @+qy:List<&2, U32> -> @+r_b:List<&2, U32> -> @+s_b:List<&2, U32> -> @+msg:List<&2, U32> -> Bool

Verify (r, s) over msg with the public point (qx, qy); all big-endian bytes.

def curve_size source · line 234 · raw

@c:Curve -> Nat

def verify_point source · line 240 · raw

@+c:Curve -> @+h:0x29d6f1ff259add9ea6c8f213fda12377/hash.Hash -> @+point:List<&2, U32> -> @+r:List<&2, U32> -> @+s:List<&2, U32> -> @+msg:List<&2, U32> -> Bool

The public key as an uncompressed SEC 1 point: 04 || X || Y.

def verify_big source · line 248 · raw

@c:BigCurve -> @+h:0x29d6f1ff259add9ea6c8f213fda12377/hash.Hash -> @+qx:List<&2, U32> -> @+qy:List<&2, U32> -> @+r_b:List<&2, U32> -> @+s_b:List<&2, U32> -> @+msg:List<&2, U32> -> Bool

Verify (r, s) over msg with the public point (qx, qy); all big-endian bytes.

def big_curve_size source · line 271 · raw

@c:BigCurve -> Nat

def verify_point_big source · line 276 · raw

@+c:BigCurve -> @+h:0x29d6f1ff259add9ea6c8f213fda12377/hash.Hash -> @+point:List<&2, U32> -> @+r:List<&2, U32> -> @+s:List<&2, U32> -> @+msg:List<&2, U32> -> Bool

def len source · line 283 · raw

@+bs:List<&2, U32> -> Nat

def der_int_ok source · line 288 · raw

@+v:List<&2, U32> -> Bool

A DER INTEGER's content is minimal and non-negative (X.690 8.3.2): at least one byte, the first below 0x80, and no leading 00 unless the next byte needs it.

def der_sig_ok source · line 298 · raw

@+sig:List<&2, U32> -> @+r:List<&2, U32> -> @+t:List<&2, U32> -> @+s:List<&2, U32> -> Bool

ECDSA-Sig-Value (RFC 5480 2.2.3, SEC 1 C.5) in strict DER: SEQUENCE { INTEGER r, INTEGER s } and nothing after it, every length in short form (a P-256 or P-384 signature is under 128 bytes, so a long form is never minimal), both integers minimal. BER, extra bytes and other tags are refused, as Wycheproof's ecdsa_*_test.json requires.

def verify_der source · line 308 · raw

@+c:Curve -> @+h:0x29d6f1ff259add9ea6c8f213fda12377/hash.Hash -> @+point:List<&2, U32> -> @+sig:List<&2, U32> -> @+msg:List<&2, U32> -> Bool

verify_point with (r, s) as a DER ECDSA-Sig-Value (X.509 and TLS signatures).