abla/crypto/x25519/core
Generated from source.
Source module; follow its importing module's re-export links.
Source: abla/crypto/x25519/core.ab
x25519Pointer (fun)
@inline trusted fun x25519Pointer(address: int): i64*
BEGIN X25519 SECRET CORE
x25519Load (fun)
@inline trusted fun x25519Load(address: int): secretU32
Loads a secret 32-bit word from a valid readable address.
x25519Store (fun)
@inline trusted fun x25519Store(address: int, value: secretU32): void
Stores a secret 32-bit word at a valid writable address.
x25519CarryPass (fun)
@inline trusted fun x25519CarryPass(a: int): void
One pass of carries over the 32 limbs at a: each limb keeps 8 bits, and the carry out of the top limb comes back into the bottom one times 38.
x25519Carry (fun)
@inline trusted fun x25519Carry(a: int): void
Two passes leave every limb at most 255, the bottom one at most 293, from limbs of up to 2^27.
x25519AddBody (fun)
@inline trusted fun x25519AddBody(out: int, a: int, b: int): void
out = a + b. out may be either.
x25519SubBody (fun)
@inline trusted fun x25519SubBody(out: int, a: int, b: int): void
out = a - b, as a + 4p - b limb by limb (4p's limbs are all above 293), so nothing is negative.
x25519MulBody (fun)
@inline trusted fun x25519MulBody(out: int, a: int, b: int, t: int): void
out = a `b`; `t` has 64 words of scratch. `out` may be `a` or `b`. Each output limb is one sum in a register (at most 32 products of at most 293 293), then the high half folds down times 38.
x25519MulConstantBody (fun)
@inline trusted fun x25519MulConstantBody(out: int, a: int): void
out = a * 121665, the curve constant (A - 2) / 4.
x25519SwapBody (fun)
@inline trusted fun x25519SwapBody(mask: secretU32, a: int, b: int): void
Swaps the elements at a and b where mask has ones.
x25519Add (fun)
@noinline trusted fun x25519Add(out: int, a: int, b: int): void
Writes the field sum of two 32-limb elements to out.
x25519Sub (fun)
@noinline trusted fun x25519Sub(out: int, a: int, b: int): void
Writes the field difference a - b of two 32-limb elements to out.
x25519Multiply (fun)
@noinline trusted fun x25519Multiply(out: int, a: int, b: int, t: int): void
Writes the field product of two 32-limb elements to out, using t as scratch.
x25519MultiplyConstant (fun)
@noinline trusted fun x25519MultiplyConstant(out: int, a: int): void
Writes the 32-limb field product of a and the curve constant 121665 to out.
x25519Swap (fun)
@noinline trusted fun x25519Swap(mask: secretU32, a: int, b: int): void
Swaps two 32-limb elements in place under an all-ones mask and leaves them in place under a zero mask.
x25519SquareTimes (fun)
@noinline trusted fun x25519SquareTimes(a: int, count: int, t: int): void
Squares the 32-limb field element in place count times, using t as scratch.
x25519Copy (fun)
@noinline trusted fun x25519Copy(to: int, from: int): void
Copies 32 limbs from from to to in increasing address order.
x25519Invert (fun)
@noinline trusted fun x25519Invert(out: int, z: int, f: int, t: int): void
out = z ^ (p - 2), the inverse (zero for zero), by the chain of 254 squarings and 11 multiplications of Bernstein's ref10. f has four elements of scratch, t the multiplication's.
x25519Chain (fun)
@inline trusted fun x25519Chain(a: int): void
Carries up through the limbs without wrapping: the top limb keeps what it gets.
x25519Pack (fun)
@noinline trusted fun x25519Pack(out: int, a: int, s: int, bias: int): void
The element at a reduced to its one value below p = 2^255 - 19, as 32 bytes at out. s and bias are elements of scratch.
x25519M (fun)
@inline fun x25519M(a: secretU32, b: secretU32): secretU64
---- The field of X25519 in ten limbs of 26 and 25 bits (curve25519-donna's, ref10's radix 2^25.5) ------------------------- An element is ten 32-bit words, 40 bytes: limb i holds bits ceil(25.5 i) to ceil(25.5 (i + 1)) of the value, 26 bits in the even limbs and 25 in the odd ones, little endian; 2^255 is 19. A product is a widening 32 x 32 -> 64-bit multiply of secretU32 (secretU32.widen() secretU32.widen(), which the constant-time test reads on every target), 100 of them for a multiplication (the 32 x 32 limbs of the other representation took 1024). Limbs of a result are below 2^26 (2^25 for the odd ones) plus a few carries' worth; a sum has limbs below 2^27, which a multiplication takes (its sums of products stay below 2^64: at most ten products of limbs below 1.5 2^27 and 19 times that, the odd ones doubled).
x25519Store64 (fun)
@inline trusted fun x25519Store64(address: int, value: secretU64): void
A u64 as two words at address, low first (and back): the sums of products wait there between the multiplication and its carries.
x25519Load64 (fun)
@inline trusted fun x25519Load64(address: int): secretU64
Loads a secret 64-bit word from a valid readable address.
x25519FFinish (fun)
@noinline trusted fun x25519FFinish(out: int, t: int): void
Carries the ten sums of products (u64, below 2^64: ten words of two at t) into limbs and stores the element at out: the ref10 order of carries, the one out of limb 9 coming back into limb 0 times 19.
x25519FRow (fun)
@inline trusted fun x25519FRow(t: int, a: int, b: int, k: int): void
The sum of products of row k (limbs i and j = k - i mod 10 of a and b; k is a literal at every call, so LLVM unrolls the loop): the odd by odd products land one bit up (2^25.5 is not whole), so one factor doubles, and those past limb 9 wrap around times 19 (2^255 is 19). Stored as a u64 at t + 8 k.
x25519FProductsRows (fun)
@noinline trusted fun x25519FProductsRows(t: int, a: int, b: int): void
On Xtensa the rows are loops (x25519FRow, above): the unrolled code, ten rows of ten widening products in one function, is more than LLVM's -O0 register scavenger can place on that target (the --fast build fails with "Incomplete scavenging after 2nd pass"), and a 32-bit CPU gains nothing from the unrolling. Everywhere else the rows are written out, which is what LLVM's unrolling would make of them (it does not, at 100 products: 3 times slower).
x25519FProductsUnrolled (fun)
@noinline trusted fun x25519FProductsUnrolled(t: int, a: int, b: int): void
Writes ten 64-bit limb-product sums to t using the unrolled ten-limb implementation.
x25519FProducts (fun)
@noinline trusted fun x25519FProducts(t: int, a: int, b: int): void
Writes ten 64-bit limb-product sums to t using the implementation selected for the target.
x25519FSquareProducts (fun)
@noinline trusted fun x25519FSquareProducts(t: int, a: int): void
The sums of products of the square of the element at a into t (as x25519FProducts with b = a, with 55 products, not 100: the product of limbs i and j is made once and counted twice, and the doubling of two odd limbs and the 19 of a wrap are constants on the 64-bit product, which stays below 2^64 for limbs below 1.5 * 2^27).
x25519FSquare (fun)
@noinline trusted fun x25519FSquare(out: int, a: int, t: int): void
out = a * a, as x25519FMul(out, a, a, t) but with the dedicated products (on Xtensa, where the products are loops, the same call).
x25519FMulBody (fun)
@inline trusted fun x25519FMulBody(out: int, a: int, b: int, t: int): void
out = a * b (elements; out may be either); t has 80 bytes of scratch. The sums of products and the carries are out of line, so that the registers of a caller are not the ones of twenty limbs (see x25519FSquareTimes).
x25519FMulConstantBody (fun)
@inline trusted fun x25519FMulConstantBody(out: int, a: int, t: int): void
out = a * 121665, the curve constant (A - 2) / 4.
x25519FWeak (fun)
@inline trusted fun x25519FWeak(a: int): void
One pass of carries over the ten limbs at a: each limb keeps its 26 or 25 bits and the carry goes up, the one out of limb 9 coming back into limb 0 times 19. Limbs of up to 2^28 leave below 2^26 + 19 * 2^3 or so.
x25519FAddBody (fun)
@inline trusted fun x25519FAddBody(out: int, a: int, b: int): void
out = a + b, limb by limb: limbs below 2^27 from results of the other operations.
x25519FSubBody (fun)
@inline trusted fun x25519FSubBody(out: int, a: int, b: int): void
out = a - b, as a + 2p - b limb by limb (2p's limbs are above those of a result), then a pass of carries so that the next multiplication finds limbs near 2^26.
x25519FSwapBody (fun)
@inline trusted fun x25519FSwapBody(mask: secretU32, a: int, b: int): void
Swaps the elements at a and b where mask has ones.
x25519FMul (fun)
@noinline trusted fun x25519FMul(out: int, a: int, b: int, t: int): void
Writes the field product of two ten-limb elements to out, using 80 bytes at t for scratch.
x25519FAdd (fun)
@noinline trusted fun x25519FAdd(out: int, a: int, b: int): void
Writes the field sum of two ten-limb elements to out.
x25519FSub (fun)
@noinline trusted fun x25519FSub(out: int, a: int, b: int): void
Writes the field difference a - b of two ten-limb elements to out.
x25519FMulConstant (fun)
@noinline trusted fun x25519FMulConstant(out: int, a: int, t: int): void
Writes the ten-limb field product of a and the curve constant 121665 to out, using t as scratch.
x25519FSwap (fun)
@noinline trusted fun x25519FSwap(mask: secretU32, a: int, b: int): void
Swaps two ten-limb elements in place under an all-ones mask and leaves them in place under a zero mask.
x25519FCopy (fun)
@noinline trusted fun x25519FCopy(to: int, from: int): void
Copies ten limbs from from to to in increasing address order.
x25519FSquareTimes (fun)
@noinline trusted fun x25519FSquareTimes(a: int, count: int, t: int): void
Squares the ten-limb field element in place count times, using t as scratch.
x25519FInvert (fun)
@noinline trusted fun x25519FInvert(out: int, z: int, f: int, t: int): void
out = z ^ (p - 2), the inverse (zero for zero): the chain of x25519Invert. f has four elements of scratch.
x25519FChain (fun)
@inline trusted fun x25519FChain(a: int): void
Carries up through the limbs without wrapping: the top limb keeps what it gets.
x25519FPack (fun)
@noinline trusted fun x25519FPack(out: int, a: int, s: int, t: int): void
The element at a reduced to its one value below p = 2^255 - 19, as 32 bytes at out. s and t are elements of scratch.
x25519FUnpack (fun)
@noinline trusted fun x25519FUnpack(out: int, bytes: int): void
The 32 bytes at bytes as an element at out, the top bit dropped (RFC 7748 section 5): limb i is bits ceil(25.5 i) up.
x25519WorkSize (fun)
fun x25519WorkSize(): int
The work area one scalar multiplication takes. All of it is secret memory. +0 the clamped scalar, 32 bytes +64 the point's u coordinate as given, 32 bytes +128 u (an element), then x1, x2, z2, x3, z3, A, AA, B, BB, E, C, D, DA, CB, tmp: fifteen elements of 40 bytes (+192 to +792) +800 the inverse's four elements (to +960) +960 the pack's two scratch elements (to +1040) +1040 the result, 32 bytes +1088 the multiplication's scratch: ten sums of products of 8 bytes (to +1168)
x25519Ladder (fun)
@noinline trusted fun x25519Ladder(work: int): void
The Montgomery ladder of RFC 7748 section 5, 255 steps from bit 254 down, on the clamped scalar at work and the point at work + 128, leaving x2 and z2 at work + 232 and work + 272.
x25519Compute (fun)
@noinline trusted fun x25519Compute(work: int): void
The scalar (32 bytes at work, as given) times the point (32 bytes at work + 64, as given), result at work + 1040: clamps the scalar, drops the point's top bit, runs the ladder and multiplies by the inverse of z2.
x25519IsZero (fun)
@noinline trusted fun x25519IsZero(address: int): secretU32
All ones when the 32 bytes at address are all zero, else zero.
x25519 (fun)
fun x25519(scalar: string, point: string): CryptoResult
The X25519 function (RFC 7748 section 5): scalar times point, both 32 bytes, the result 32 bytes. For a key agreement, scalar is your private key and point the peer's public key. ok is false for a wrong length, and for an all-zero result.
x25519PublicKey (fun)
fun x25519PublicKey(scalar: string): CryptoResult
The public key of a private key: x25519 of it and the base point 9.
Built from Abla v0.2.79 source ba5d6b7d. Examples and generated signatures follow that source revision.