abla/crypto/p256/core
Generated from source.
Source module; follow its importing module's re-export links.
Source: abla/crypto/p256/core.ab
P256Curve (class)
class P256Curve(val field: BnModulus, val order: BnModulus, val work: int)
The two moduli and the work area of one operation: made for it and released at its end.
p256Open (fun)
trusted fun p256Open(): P256Curve
Allocates and returns the field modulus, scalar modulus and scratch storage for a P-256 operation.
p256Close (fun)
trusted fun p256Close(curve: P256Curve): void
Releases both moduli and the scratch storage owned by the P-256 context.
p256Inverse (fun)
@inline fun p256Inverse(m: int): int
Where a BnModulus (abla/crypto/bignum) keeps what the arithmetic reads, for eight limbs.
p256One (fun)
@inline fun p256One(m: int): int
Where a BnModulus (abla/crypto/bignum) keeps what the arithmetic reads, for eight limbs.
p256Scratch (fun)
@inline fun p256Scratch(m: int): int
Where a BnModulus (abla/crypto/bignum) keeps what the arithmetic reads, for eight limbs.
p256FProductUnrolled (fun)
@noinline trusted fun p256FProductUnrolled(t: int, a: int, b: int): void
--- The field of the curve, unrolled (the prime is public: p = 2^256 - 2^224 + 2^192 + 2^96 - 1) ----------------------------------------------
p256FProductLoops (fun)
@noinline trusted fun p256FProductLoops(t: int, a: int, b: int): void
What p256FProductUnrolled does, as loops: LLVM's -O0 register scavenger on Xtensa cannot place the unrolled function (as with X25519's), and a 32-bit CPU gains nothing from the unrolling.
p256FProductWide (fun)
@noinline trusted fun p256FProductWide(t: int, a: int, b: int): void
The product of the elements at a and b as the 16 words of 32 bits at t that p256FProductUnrolled leaves, from four limbs of 64 bits each (a limb pair of the layout): 16 products of 64 x 64 -> 128 instead of 64 of 32 x 32 -> 64. For targets where that product is one instruction (x86-64, AArch64: abla/uint128's native multiply).
p256FReduceWide64 (fun)
@noinline trusted fun p256FReduceWide64(out: int, t: int): void
The product at t (eight limbs of 64 bits) / 2^256 mod p, fully reduced, at out: Montgomery reduction limb by limb. -p^-1 is 1 modulo 2^64 (p ends in 64 one bits), so the multiplier of each step is the limb itself, and q p = q (2^64 - 1) + q (2^32 - 1) 2^64 + q (2^64 - 2^32 + 1) 2^192: the first term clears the limb and carries q up, so a step is two products and the additions. The result is below 2 p (the product of two reduced elements is below p 2^256), and p is subtracted when it is p or more.
p256FMul (fun)
@noinline trusted fun p256FMul(out: int, a: int, b: int, t: int): void
out = a * b / 2^256 mod p: the Montgomery multiplication of the field, fully reduced and bit for bit what bnMontgomeryMultiply gives; t is 16 words of scratch. The product and the reduction are separate calls (the registers of a caller are not those of sixteen words and their carries).
p256FReduceLoops (fun)
@noinline trusted fun p256FReduceLoops(out: int, t: int): void
What p256FReduceWide does, as loops over the words in memory (the m of each of the first eight words replaces it in t, the result words the last eight): the unrolled function is more than LLVM's -O0 register scavenger on Xtensa can place, and a 32-bit CPU gains nothing from it.
p256FReduceWide (fun)
@noinline trusted fun p256FReduceWide(out: int, t: int): void
The product at t (16 words) / 2^256 mod p, fully reduced, at out: Montgomery reduction word by word, with p = 2^256 - 2^224 + 2^192 + 2^96 - 1 (so m = t_i and m p is four shifted copies of m: no multiplication), the carries kept as signed 64-bit values.
p256FAdd (fun)
@noinline trusted fun p256FAdd(out: int, a: int, b: int): void
out = a + b mod p (operands below p; out may be either): the sum, then p subtracted when the sum is p or more.
p256FSub (fun)
@noinline trusted fun p256FSub(out: int, a: int, b: int): void
out = a - b mod p (operands below p; out may be either): the difference, then p added back when it borrowed.
p256Multiply (fun)
@inline trusted fun p256Multiply(m: int, out: int, a: int, b: int): void
out = a * b / 2^256 mod the modulus at m.
p256Add (fun)
trusted fun p256Add(m: int, out: int, a: int, b: int): void
out = a + b mod the modulus. out may be either. Uses the modulus's scratch.
p256Subtract (fun)
trusted fun p256Subtract(m: int, out: int, a: int, b: int): void
out = a - b mod the modulus. out may be either. Uses the modulus's scratch.
p256PointAdd (fun)
trusted fun p256PointAdd(f: int, work: int, out: int, p: int, q: int): void
out = p + q, projective points in Montgomery form; out is neither. Renes-Costello-Batina, algorithm 4.
p256PointDouble (fun)
trusted fun p256PointDouble(f: int, work: int, out: int, p: int): void
out = 2 p; out is not p. Renes-Costello-Batina, algorithm 6.
p256InRange (fun)
trusted fun p256InRange(order: int, value: int): u32
Nonzero when the eight limbs at value are a number from 1 to n-1, n at order: every limb is read, and only the verdict is public (a key or a nonce candidate that is refused). It is returned as a word, not a bool: a comparison here would be a branch on a target with no conditional set.
p256ScalarMultiply (fun)
trusted fun p256ScalarMultiply(f: int, work: int, out: int, point: int, scalar: int): void
out = scalar * point: scalar is eight plain limbs (secret), point projective in Montgomery form, and out is neither. Every window of four bits does the same four doublings, one addition and a read of the whole table of sixteen multiples.
p256MultiplyPlain (fun)
trusted fun p256MultiplyPlain(m: BnModulus, out: int, a: int, b: int): void
out = a `b` mod the modulus, all plain (the ECDSA signature: r d, and s = (e + r d) * k^-1: d and k^-1 are secret).
p256MultiplyPlainBody (fun)
@inline trusted fun p256MultiplyPlainBody(memory: int, out: int, a: int, b: int, encoded: int): void
What p256MultiplyPlain does, on a modulus block at memory and a work area of eight limbs.
p256FixedBaseMultiply (fun)
trusted fun p256FixedBaseMultiply(f: int, work: int, out: int, table: int, scalar: int): void
out = scalar * G, the generator: scalar is eight plain limbs (secret), table the sixteen entries of p256CombTable, out neither. The scalar is read as four 64-bit rows, column t of the rows (one bit of each: a digit of four bits) picks one entry (the whole table is read, bnLookup), and 64 columns from the top each do one doubling and one addition: 64 doublings, not the 256 of a window method, since the table already holds the multiples of G by 2^64, 2^128 and 2^192.
p256Bytes (fun)
trusted fun p256Bytes(limbs: int, count: int): string
The count bytes at limbs as a string, most significant first.
p256IsZero (fun)
trusted fun p256IsZero(value: int): bool
Whether the eight limbs are zero (for a decision that is public: a rejected key or point).
p256ToAffine (fun)
trusted fun p256ToAffine(c: P256Curve, point: int, x: int, y: int): bool
The point at point (projective, Montgomery) as plain affine x and y, or false for the point at infinity.
p256Generator (fun)
trusted fun p256Generator(c: P256Curve, out: int): void
The generator, projective in Montgomery form, at out (24 limbs).
p256ParsePoint (fun)
trusted fun p256ParsePoint(c: P256Curve, encoded: string, out: int): bool
out (24 limbs) the public point encoded (0x04 || X || Y) in Montgomery form, if it is a point of the curve.
p256ParseScalar (fun)
trusted fun p256ParseScalar(c: P256Curve, key: string, out: int): bool
The 32 bytes at key as a private scalar in out (eight limbs), if it is in 1..n-1.
p256DigestScalar (fun)
trusted fun p256DigestScalar(c: P256Curve, digest: string, out: int): void
out = the digest's leftmost 256 bits as a number, reduced mod n (it is below 2 n).
p256PublicKey (fun)
trusted fun p256PublicKey(privateKey: string): CryptoResult
The public key, 65 bytes (0x04 || X || Y), of a private key of 32 bytes.
p256IsValidPublicKey (fun)
trusted fun p256IsValidPublicKey(encoded: string): bool
Whether encoded is an uncompressed point of the curve (and so a valid public key).
p256Ecdh (fun)
trusted fun p256Ecdh(privateKey: string, peerPublicKey: string): CryptoResult
ECDH: the x coordinate, 32 bytes, of privateKey times the peer's public point. The peer's point is checked; a private key out of range is refused.
p256GeneratePrivateKey (fun)
trusted fun p256GeneratePrivateKey(): CryptoResult
A random private key of 32 bytes, or a failure if there is no random source (see cryptoSetRandom).
p256Nonce (fun)
trusted fun p256Nonce(c: P256Curve, key: string, reduced: string): string
RFC 6979's nonce for SHA-256 and the private key key (32 bytes) for the message hash h1, or "" if no candidate falls in 1..n-1 in 100 tries (it always does). reduced is h1 mod n as bytes.
p256EcdsaSignRaw (fun)
trusted fun p256EcdsaSignRaw(privateKey: string, message: string): CryptoResult
ECDSA over SHA-256 (RFC 6979 nonce, so a message always gets the same signature): the 64 bytes r || s.
p256SignatureToDer (fun)
fun p256SignatureToDer(raw: string): string
The signature r || s (64 bytes) as DER, the form X.509 and TLS carry.
p256SignatureFromDer (fun)
fun p256SignatureFromDer(der: string): string
r || s (64 bytes) from a strict DER signature, or "".
p256EcdsaSign (fun)
trusted fun p256EcdsaSign(privateKey: string, message: string): CryptoResult
ECDSA over SHA-256, the signature as DER.
p256EcdsaVerifyDigestRaw (fun)
trusted fun p256EcdsaVerifyDigestRaw(publicKey: string, digest: string, signature: string): bool
Verifies signature (64 bytes, r || s) over a message digest (SHA-256 normally; a longer digest is cut to its leftmost 256 bits, as ECDSA says) by the public key. Public inputs: not constant time.
p256EcdsaVerifyRaw (fun)
trusted fun p256EcdsaVerifyRaw(publicKey: string, message: string, signature: string): bool
ECDSA over SHA-256, the signature as r || s (64 bytes).
p256EcdsaVerify (fun)
trusted fun p256EcdsaVerify(publicKey: string, message: string, signature: string): bool
ECDSA over SHA-256, the signature as strict DER.
p256EcdsaVerifySha384 (fun)
trusted fun p256EcdsaVerifySha384(publicKey: string, message: string, signature: string): bool
ECDSA over SHA-384 (TLS 1.2's ecdsa_secp256r1 with a longer hash; the digest is cut to 256 bits).
Built from Abla v0.2.79 source ba5d6b7d. Examples and generated signatures follow that source revision.