~/bend-docscommunity

poly1305.bend checks

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

2 imports
import Base
import ./chacha20.bend as ChaCha

Definitions

def nth source · line 11 · raw

@xs:List<&2, U32> -> @n:Nat -> U32

def zeros source · line 14 · raw

@n:Nat -> List<&2, U32>

def add_go source · line 22 · raw

@h:List<&2, U32> -> @c:List<&2, U32> -> @+u:U32 -> List<&2, U32>

h + c, limb by limb, carrying 8 bits at a time (add1305).

def add source · line 30 · raw

@h:List<&2, U32> -> @c:List<&2, U32> -> List<&2, U32>

def scale source · line 37 · raw

@xs:List<&2, U32> -> @+k:U32 -> List<&2, U32>

h * r mod p: the full product in 33 columns (sequential shifted adds, no indexing), then column 17 + k folds into column k times 320, because 2^136 = 2^6 * 2^130 = 320 (mod p). Column sums stay below 17 * 255^2, and 320 times that plus a column still fits in 32 bits.

def zip_add_long source · line 44 · raw

@xs:List<&2, U32> -> @ys:List<&2, U32> -> List<&2, U32>

def add_at source · line 55 · raw

@off:Nat -> @acc:List<&2, U32> -> @ys:List<&2, U32> -> List<&2, U32>

def mul_cols source · line 66 · raw

@hs:List<&2, U32> -> @+r:List<&2, U32> -> @acc:List<&2, U32> -> @+off:Nat -> List<&2, U32>

def mul_go source · line 73 · raw

@+h:List<&2, U32> -> @+r:List<&2, U32> -> List<&2, U32>

def carry16 source · line 78 · raw

@n:Nat -> @h:List<&2, U32> -> @+u:U32 -> List<&2, U32>

Carry the first 16 limbs; returns them with the carry appended.

def last source · line 90 · raw

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

def squeeze source · line 95 · raw

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

After the multiply: squeeze limbs back to 8 bits, folding the bits above 2^130 back in times 5 (two passes, as in TweetNaCl).

def clamp_byte source · line 101 · raw

@+i:U32 -> @+b:U32 -> U32

def clamp_go source · line 105 · raw

@xs:List<&2, U32> -> @+i:U32 -> List<&2, U32>

def block_limbs source · line 113 · raw

@+m:List<&2, U32> -> List<&2, U32>

One 16-byte block (the last may be short): c = block | 1, zero-padded to 17.

def blocks source · line 117 · raw

@n:Nat -> @+m:List<&2, U32> -> @+r:List<&2, U32> -> @h:List<&2, U32> -> List<&2, U32>

def minus_p source · line 124 · raw

List<&2, U32>

def freeze source · line 128 · raw

@+h:List<&2, U32> -> List<&2, U32>

Reduce fully mod p: h - p if that does not go negative.

def mac source · line 133 · raw

@+key:List<&2, U32> -> @+m:List<&2, U32> -> List<&2, U32>

The 16-byte tag of m under the 32-byte one-time key (r | s).

def pad16 source · line 140 · raw

@+xs:List<&2, U32> -> List<&2, U32>

def le64 source · line 143 · raw

@+n:U32 -> List<&2, U32>

def tag_of source · line 146 · raw

@+key:List<&2, U32> -> @+nonce:List<&2, U32> -> @+aad:List<&2, U32> -> @+ct:List<&2, U32> -> List<&2, U32>

def seal source · line 154 · raw

@+key:List<&2, U32> -> @+nonce:List<&2, U32> -> @+aad:List<&2, U32> -> @+pt:List<&2, U32> -> List<&2, U32>

ciphertext | tag

def eq_bytes source · line 158 · raw

@xs:List<&2, U32> -> @ys:List<&2, U32> -> Bool

def open source · line 169 · raw

@+key:List<&2, U32> -> @+nonce:List<&2, U32> -> @+aad:List<&2, U32> -> @+sealed:List<&2, U32> -> Maybe<&2, List<&2, U32>>

Decrypt ct | tag; None if the tag does not verify (the plaintext is never released on a bad tag).