veko doc
Self-Contained API Reference • Gradual Types • Capabilities • Wasm Sandbox

crypto/sig

lib/crypto/sig.vk

lib/crypto/sig.vk Pure-Veko multi-precision modular arithmetic, ECDSA P-256 SHA-256, RSA PKCS#1 v1.5 SHA-256, and RSA-PSS SHA-256 verifiers. Uses base-2^24 positive limbs so limb * limb = 2^48 never overflows signed 64-bit integers.

signature
bn-from-be = fn [b bytes] block
signature
bn-to-be = fn [a block, out_len i64] bytes
signature
bn-cmp = fn [a block, b block] i64
signature
bn-add = fn [a block, b block] block
signature
bn-sub = fn [a block, b block] block

Computes a - b assuming a >= b.

signature
bn-mul = fn [a block, b block] block

Full multiplication a * b via Comba column accumulation (zero random-access writes).

signature
bn-mod = fn [a block, m block] block

Computes a mod m via bit-by-bit shift-subtract (exact for any modulus size).

signature
bn-mod-add = fn [a block, b block, m block] block
signature
bn-mod-sub = fn [a block, b block, m block] block
signature
bn-mod-pow = fn [base_in block, exp block, m_in block] any

Computes base^exp mod m (m odd) via Montgomery binary exponentiation.

signature
rsa-pkcs1-sha256-verify = fn [mod_be bytes, exp_be bytes, msg bytes, sig bytes] bool
signature
rsa-pkcs1-sha384-verify = fn [mod_be bytes, exp_be bytes, msg bytes, sig bytes] bool
signature
rsa-pkcs1-sha512-verify = fn [mod_be bytes, exp_be bytes, msg bytes, sig bytes] bool
signature
rsa-pss-sha256-verify = fn [mod_be bytes, exp_be bytes, msg bytes, sig bytes] bool
signature
rsa-pss-sha384-verify = fn [mod_be bytes, exp_be bytes, msg bytes, sig bytes] bool

Verifies an RSA-PSS + SHA-384 (0x0805 rsa_pss_rsae_sha384, 48-byte salt) signature.

signature
rsa-pss-sha512-verify = fn [mod_be bytes, exp_be bytes, msg bytes, sig bytes] bool

Verifies an RSA-PSS + SHA-512 (0x0806 rsa_pss_rsae_sha512, 64-byte salt) signature.

signature
ecdsa-p256-verify = fn [pk_point bytes, msg bytes, sig_der bytes] bool
signature
ecdsa-p384-verify = fn [pk_point bytes, msg bytes, sig_der bytes] bool
signature
ecdsa-p256-pubkey = fn [priv32 bytes] bytes

Derives the 65-byte uncompressed SEC1 public key (0x04 || X(32) || Y(32)) from a 32-byte P-256 private scalar.

signature
ecdhe-p256 = fn [priv32 bytes, peer_pub65 bytes] bytes

Computes RFC 8446 Section 7.4.2 ECDHE P-256 (secp256r1, 0x0017) 32-byte shared secret X-coordinate.

signature
ecdsa-p256-sign = fn [priv32 bytes, msg bytes] bytes

Signs msg with ECDSA P-256 / SHA-256 using RFC 6979 deterministic nonces, returning ASN.1 DER (r, s).

Executable Example
veko
use [sig = crypto/sig]
priv = bytes/fill 32 0x2a
pubk = sig/ecdsa-p256-pubkey priv
msg = bytes/from-str 'veko ecdsa p256 sign/verify'
signature = sig/ecdsa-p256-sign priv msg
if not (sig/ecdsa-p256-verify pubk msg signature) [ err 'ecdsa-p256 sign/verify failed' ] else [ .ok ]
signature
rsa-pss-sha256-sign = fn [mod_be bytes, priv_exp_be bytes, msg bytes, salt bytes] bytes

Signs msg using RSA-PSS + SHA-256 (0x0804) with a 32-byte salt, returning a k-byte signature.

signature
pkcs8-extract-private-key = fn [pkcs8_der bytes] bytes

Extracts the inner private-key OCTET STRING from a PKCS#8 PrivateKeyInfo DER blob.

signature
parse-private-key-der = fn [key_der bytes, label_hint str] any

Parses a PKCS#8 (PRIVATE KEY), SEC1 (EC PRIVATE KEY), or PKCS#1 (RSA PRIVATE KEY) DER blob. Returns { kind = .ed25519 | .p256 | .rsa, priv = bytes, n = bytes, d = bytes }.