abla/crypto/bignum/core

Generated from source.

Source module; follow its importing module's re-export links.

Source: abla/crypto/bignum/core.ab

bnPointer (fun)

@inline trusted fun bnPointer(address: int): i64*

Returns the integer address as a native pointer without accessing the storage.

bnLoad (fun)

@inline trusted fun bnLoad(address: int): secretU32

Returns the secret 32-bit limb stored at a readable address.

bnStore (fun)

@inline trusted fun bnStore(address: int, value: secretU32): void

Stores the secret 32-bit limb at a writable address.

bnAllocate (fun)

trusted fun bnAllocate(words: int): int

Allocates zeroed space for the requested number of limbs and returns its native address.

bnRelease (fun)

trusted fun bnRelease(address: int, words: int): void

Wipes and frees what bnAllocate gave.

bnClear (fun)

@noinline trusted fun bnClear(address: int, words: int): void

Overwrites the requested limb range with zero in writable storage.

bnCopy (fun)

@noinline trusted fun bnCopy(to: int, from: int, words: int): void

Copies the requested number of 32-bit limbs forward between valid native buffers.

bnFromBytes (fun)

trusted fun bnFromBytes(to: int, words: int, data: int, count: int): void

The big-endian bytes at data as words limbs; the bytes must fit.

bnToBytes (fun)

trusted fun bnToBytes(to: int, count: int, from: int): void

Writes the low requested byte count of the limb array in big-endian order.

bnInverseWord (fun)

trusted fun bnInverseWord(to: int, modulus: int): void

-1 / modulus[0] mod 2^32 of an odd modulus, by Newton's iteration: the value is secret for a prime.

bnConditionalSubtractBody (fun)

@inline trusted fun bnConditionalSubtractBody(out: int, value: int, top: secretU32, modulus: int,
    words: int, scratch: int): void

out = a + b's value subtracted when it's at least b, or a carry says so: from value, words long, with top the word above it.

bnMontgomeryMultiplyBody (fun)

@inline trusted fun bnMontgomeryMultiplyBody(
    out: int, a: int, b: int, modulus: int, inverse: int, words: int, t: int
): void

out = a `b` / 2^(32 words) mod `modulus`, the product below modulus 2^(32 words). inverse holds bnInverseWord's word, t has 2 * words + 2 scratch words. out may be a or b.

bnMontgomeryMultiply (fun)

@noinline trusted fun bnMontgomeryMultiply(out: int, a: int, b: int, modulus: int, inverse: int,
    words: int, t: int): void

Writes the Montgomery product to the output using the supplied modulus, inverse, limb count, and scratch storage.

bnLoad64 (fun)

@inline trusted fun bnLoad64(address: int): u64

Returns the unsigned 64-bit word at a readable native address.

bnStore64 (fun)

@inline trusted fun bnStore64(address: int, value: u64): void

Stores an unsigned 64-bit word at a writable native address.

bnWideLimbs (fun)

@inline fun bnWideLimbs(words: int): bool

Whether the 64-bit limbs serve words 32-bit ones: the target multiplies 64 x 64 -> 128 in one instruction and the count is even.

bnMontgomeryMultiply64Body (fun)

@inline trusted fun bnMontgomeryMultiply64Body(
    out: int, a: int, b: int, modulus: int, inverse: int, words: int, t: int
): void

bnMontgomeryMultiplyBody on 64-bit limbs: words 32-bit limbs (even), inverse holds the 32-bit word, lifted here to 64 bits by one Newton step; t has 2 * words + 4 scratch words of 32 bits.

bnMontgomeryMultiply64 (fun)

@noinline trusted fun bnMontgomeryMultiply64(out: int, a: int, b: int, modulus: int, inverse: int,
    words: int, t: int): void

Writes the Montgomery product using 64-bit limbs, which requires an even count of 32-bit limbs and valid scratch storage.

bnLookup64Body (fun)

@inline trusted fun bnLookup64Body(out: int, table: int, count: int, words: int, index: secretU32): void

bnLookupBody on 64-bit limbs: words 32-bit limbs per entry (even).

bnLookup64 (fun)

@noinline trusted fun bnLookup64(out: int, table: int, count: int, words: int, index: secretU32): void

Copies the selected table row while scanning every row as 64-bit limbs, which requires an even count of 32-bit limbs per row.

bnExpMultiplyAt (fun)

@inline trusted fun bnExpMultiplyAt(memory: int, words: int, out: int, a: int, b: int): void

What bnExpSecretBody multiplies with: 64-bit limbs where bnWideLimbs says so.

bnLookupBody (fun)

@inline trusted fun bnLookupBody(out: int, table: int, count: int, words: int,
    index: secretU32): void

out = entry index of count entries of words limbs at table, reading them all.

bnLookup (fun)

@noinline trusted fun bnLookup(out: int, table: int, count: int, words: int,
    index: secretU32): void

Copies the selected limb row while scanning the full table.

bnLoadSecret64 (fun)

@inline trusted fun bnLoadSecret64(address: int): secretU64

Returns a secret word containing the 64 bits stored at the readable address.

bnStoreSecret64 (fun)

@inline trusted fun bnStoreSecret64(address: int, value: secretU64): void

Stores a secret 64-bit word at the writable native address.

bnResidueSquare64Body (fun)

@inline trusted fun bnResidueSquare64Body(out: int, modulus: int, words: int, t: int): void

bnResidueSquare on 64-bit limbs, each round one pass that doubles and also subtracts (into t) and one that picks.

bnResidueSquare (fun)

@noinline trusted fun bnResidueSquare(out: int, modulus: int, words: int, t: int): void

out = 2^(2 32 words) mod modulus, by doubling and subtracting. t as for multiply.

bnResidueSquareFor (fun)

@noinline trusted fun bnResidueSquareFor(out: int, modulus: int, words: int, t: int): void

bnResidueSquare on the limbs the target multiplies with (the generated fixtures read the 32-bit one's text, so the dispatch is here).

BnModulus (class)

class BnModulus(val memory: int, val words: int)

What a modulus needs ready: the modulus, its inverse word, 2^2k mod it, and its one (2^k mod it).

BnModulus.value (method)

fun value(): int

Returns the address of the modulus limbs.

BnModulus.inverse (method)

fun inverse(): int

Returns the address of the Montgomery inverse word.

BnModulus.square (method)

fun square(): int

Returns the address of the precomputed squared Montgomery radix.

BnModulus.one (method)

fun one(): int

Returns the address of the Montgomery representation of one.

BnModulus.scratch (method)

fun scratch(): int

Returns the address of the modulus's multiplication scratch storage.

BnModulus.total (method)

fun total(): int

Returns the number of 32-bit words in the complete modulus allocation.

bnScratchWords (fun)

fun bnScratchWords(words: int): int

Returns the number of scratch words required for a modulus of the given limb count.

bnModulusFrom (fun)

trusted fun bnModulusFrom(data: int, count: int, words: int): BnModulus

Prepares an odd modulus of words limbs from big-endian bytes.

bnModulusRelease (fun)

trusted fun bnModulusRelease(modulus: BnModulus): void

Clears and frees the storage owned by the modulus.

bnMultiply (fun)

@inline trusted fun bnMultiply(modulus: BnModulus, out: int, a: int, b: int): void

Moduli of 12 limbs or more (P-384, RSA) on 64-bit limbs where the target has the product; the 8-limb ones (P-256, Ed25519 scalars) stay as they are.

bnEncode (fun)

trusted fun bnEncode(modulus: BnModulus, out: int, a: int): void

Into and out of Montgomery form.

bnDecode (fun)

trusted fun bnDecode(modulus: BnModulus, out: int, a: int): void

Writes the ordinary residue obtained by converting a value out of Montgomery form.

bnMultiplyAt (fun)

@inline trusted fun bnMultiplyAt(memory: int, words: int, out: int, a: int, b: int): void

The multiplication of the exponentiations below on a modulus block at memory (a BnModulus's memory, words limbs): Montgomery's, with the block's modulus, inverse word and scratch.

bnExpSecret (fun)

@noinline trusted fun bnExpSecret(modulus: BnModulus, out: int, base: int, exponent: int,
    bits: int): void

out = base ^ exponent mod the modulus, base below it in plain form, exponent of bits bits in limbs. Every window squares four times and multiplies once by an entry read from all sixteen, whatever the exponent's bits are.

bnExpSecretBody (fun)

@inline trusted fun bnExpSecretBody(memory: int, words: int, out: int, base: int, exponent: int, bits: int,
    work: int): void

What bnExpSecret does, on a modulus block at memory and the work area it is given: work (17 * words limbs: the table of 16 powers, then one entry). tools/test-ct.sh reads this whole.

bnExpPublic (fun)

@noinline trusted fun bnExpPublic(modulus: BnModulus, out: int, base: int, exponent: string): void

out = base ^ exponent mod the modulus, with a public big-endian exponent. base stays secret: this branches only on the exponent's bits. (Not read by tools/test-ct.sh: the checker cannot tell a load of the exponent's bytes from a load of secret memory; its multiplications are the Montgomery multiplication it does read, and the condition is the exponent's, which is public.)

bnMultiplyPlain (fun)

@noinline trusted fun bnMultiplyPlain(out: int, a: int, aWords: int, b: int, bWords: int): void

out (aWords + bWords limbs) = a * b.

bnAddMultipleBody (fun)

@inline trusted fun bnAddMultipleBody(out: int, a: int, aWords: int, multiplier: secretU32): void

out += a * multiplier, the carry stored after aWords limbs.

bnLessPublic (fun)

trusted fun bnLessPublic(a: int, b: int, words: int): bool

a < b as a public answer to two values allowed to be known.

bnEqual (fun)

trusted fun bnEqual(a: int, b: int, words: int): bool

Whether two values are the same, as a mask made public: for a check that fails loudly.

bnPublicIsEven (fun)

fun bnPublicIsEven(a: array<int>): bool

Returns true if the least significant bit of the nonempty limb array is zero.

bnPublicIsZero (fun)

fun bnPublicIsZero(a: array<int>): bool

Returns true if all public limbs are zero.

bnPublicIsOne (fun)

fun bnPublicIsOne(a: array<int>): bool

Returns true if the nonempty little-endian limb array represents exactly one.

bnPublicHalve (fun)

fun bnPublicHalve(var a: array<int>): void

Divides the public limb array by two in place, dropping any remainder.

bnPublicAdd (fun)

fun bnPublicAdd(var a: array<int>, b: array<int>): void

Adds the equally sized limb arrays in place, discarding final carry.

bnPublicSubtract (fun)

fun bnPublicSubtract(var a: array<int>, b: array<int>): void

Subtracts equally sized limb arrays in place, discarding final borrow.

bnPublicLess (fun)

fun bnPublicLess(a: array<int>, b: array<int>): bool

Returns true when the first fixed-width public magnitude is smaller than the second.

bnPublicInverse (fun)

fun bnPublicInverse(value: array<int>, modulus: array<int>): array<int>

The inverse mod modulus (odd) of value, or an empty array if there is none.

Built from Abla v0.2.79 source ba5d6b7d. Examples and generated signatures follow that source revision.