x25519.bend checks
raw source on the hub · import element-crypto@0.1.0.0/x25519.bend as X25519
2 imports
import Base import ./fe25519.bend as F
Types
type L4 source · line 172 · raw
Data
L4@x2:List<&2, U32> -> @z2:List<&2, U32> -> @x3:List<&2, U32> -> @z3:List<&2, U32> -> L4
type L5 source · line 215 · raw
Data
L5@x2:0x29d6f1ff259add9ea6c8f213fda12377/fe25519.Fe -> @z2:0x29d6f1ff259add9ea6c8f213fda12377/fe25519.Fe -> @x3:0x29d6f1ff259add9ea6c8f213fda12377/fe25519.Fe -> @z3:0x29d6f1ff259add9ea6c8f213fda12377/fe25519.Fe -> @swap:U32 -> L5
Definitions
def zeros source · line 14 · raw
@n:Nat -> List<&2, U32>
def or0 source · line 21 · raw
@m:Maybe<&2, U32> -> U32
def nth source · line 28 · raw
@xs:List<&2, U32> -> @n:Nat -> U32
def carry_go source · line 34 · raw
@xs:List<&2, U32> -> @+c:U32 -> List<&2, U32>
Carry limbs to 8 bits; returns the limbs with the final carry appended.
def add_low source · line 42 · raw
@xs:List<&2, U32> -> @+v:U32 -> List<&2, U32>
def reduce source · line 51 · raw
@+xs:List<&2, U32> -> List<&2, U32>
Reduce 32 limbs of any size to 32 limbs < 256 (value mod p, maybe >= p): carry, fold the overflow above 2^256 back times 38, twice.
def zip_add source · line 58 · raw
@xs:List<&2, U32> -> @ys:List<&2, U32> -> List<&2, U32>
def zip_sub source · line 65 · raw
@xs:List<&2, U32> -> @ys:List<&2, U32> -> List<&2, U32>
def add source · line 72 · raw
@a:List<&2, U32> -> @b:List<&2, U32> -> List<&2, U32>
def four_p source · line 76 · raw
List<&2, U32>
4p = 2^257 - 76 with limbs 436, 510, ..., 510 (each above any reduced limb).
def sub source · line 79 · raw
@a:List<&2, U32> -> @b:List<&2, U32> -> List<&2, U32>
def scale source · line 82 · raw
@xs:List<&2, U32> -> @+k:U32 -> List<&2, U32>
def zip_add_long source · line 90 · raw
@xs:List<&2, U32> -> @ys:List<&2, U32> -> List<&2, U32>
Like zip_add, but keeps the tail of the longer first list.
def add_at source · line 102 · raw
@off:Nat -> @acc:List<&2, U32> -> @ys:List<&2, U32> -> List<&2, U32>
acc + (ys shifted by off limbs)
def mul_cols source · line 114 · raw
@as:List<&2, U32> -> @+b:List<&2, U32> -> @acc:List<&2, U32> -> @+off:Nat -> List<&2, U32>
Schoolbook product into 63 columns.
def mul source · line 121 · raw
@+a:List<&2, U32> -> @+b:List<&2, U32> -> List<&2, U32>
def sq source · line 125 · raw
@+a:List<&2, U32> -> List<&2, U32>
def mul_small source · line 128 · raw
@+a:List<&2, U32> -> @+k:U32 -> List<&2, U32>
def inv_go source · line 133 · raw
@n:Nat -> @+a:List<&2, U32> -> @+c:List<&2, U32> -> @+bit:U32 -> List<&2, U32>
a^(p-2) = a^-1: p - 2 = 2^255 - 21, whose bits from 254 down are all 1 except bits 4 and 2 (TweetNaCl's inv25519).
def invert source · line 141 · raw
@+a:List<&2, U32> -> List<&2, U32>
def p_limbs source · line 145 · raw
List<&2, U32>
Canonical form: subtract p while the value is >= p (at most twice).
def sub_p_go source · line 149 · raw
@xs:List<&2, U32> -> @ps:List<&2, U32> -> @+borrow:U32 -> List<&2, U32>
a - p with borrow; the borrow out tells whether a < p.
def minus_p_once source · line 157 · raw
@+a:List<&2, U32> -> List<&2, U32>
def freeze source · line 161 · raw
@+a:List<&2, U32> -> List<&2, U32>
def clamp source · line 166 · raw
@+k:List<&2, U32> -> List<&2, U32>
def bit_at source · line 169 · raw
@+k:List<&2, U32> -> @+t:U32 -> U32
def cswap source · line 175 · raw
@+swap:U32 -> @st:L4 -> L4
def rung source · line 181 · raw
@st:L4 -> @+x1:List<&2, U32> -> L4
One rung (RFC 7748 section 5, after the conditional swap).
def ladder source · line 195 · raw
@n:Nat -> @+k:List<&2, U32> -> @+x1:List<&2, U32> -> @+t:U32 -> @+swap:U32 -> @st:L4 -> L4
def one source · line 203 · raw
List<&2, U32>
def result source · line 206 · raw
@st:L4 -> List<&2, U32>
def scalar_bits source · line 218 · raw
@+k:List<&2, U32> -> @n:Nat -> @+t:U32 -> @+acc:List<&2, U32> -> List<&2, U32>
def rung_fe source · line 225 · raw
@xs:Pair(0x29d6f1ff259add9ea6c8f213fda12377/fe25519.Fe, 0x29d6f1ff259add9ea6c8f213fda12377/fe25519.Fe) -> @zs:Pair(0x29d6f1ff259add9ea6c8f213fda12377/fe25519.Fe, 0x29d6f1ff259add9ea6c8f213fda12377/fe25519.Fe) -> @+x1:0x29d6f1ff259add9ea6c8f213fda12377/fe25519.Fe -> @+b:U32 -> L5
def step_fe source · line 241 · raw
@st:L5 -> @+x1:0x29d6f1ff259add9ea6c8f213fda12377/fe25519.Fe -> @+b:U32 -> L5
def ladder_fe source · line 247 · raw
@bits:List<&2, U32> -> @+x1:0x29d6f1ff259add9ea6c8f213fda12377/fe25519.Fe -> @st:L5 -> L5
def finish_fe source · line 254 · raw
@xs:Pair(0x29d6f1ff259add9ea6c8f213fda12377/fe25519.Fe, 0x29d6f1ff259add9ea6c8f213fda12377/fe25519.Fe) -> @zs:Pair(0x29d6f1ff259add9ea6c8f213fda12377/fe25519.Fe, 0x29d6f1ff259add9ea6c8f213fda12377/fe25519.Fe) -> List<&2, U32>
def result_fe source · line 261 · raw
@st:L5 -> List<&2, U32>
def x25519 source · line 267 · raw
@+k:List<&2, U32> -> @+u:List<&2, U32> -> List<&2, U32>
X25519(k, u): both 32 bytes little-endian; the top bit of u is ignored.
def x25519_list source · line 274 · raw
@+k:List<&2, U32> -> @+u:List<&2, U32> -> List<&2, U32>
The list-limb ladder this replaced (2026-11-05), kept for the differential test in crypto_vectors until the fe25519 one has run in Element for a while.
def base_point source · line 278 · raw
List<&2, U32>
def public_key source · line 281 · raw
@+k:List<&2, U32> -> List<&2, U32>
def is_all_zero source · line 288 · raw
@bs:List<&2, U32> -> Bool
An all-zero result means the peer sent a low-order point. RFC 7748 §6.1 lets a protocol check it; TLS (RFC 8446 §7.4.2, RFC 8422 §5.11) MUST abort. The result is public at this point, so the check needs no constant time.