SDK Documentation
@lanitlabs/pqc-lnqc714
Post-Quantum Key Encapsulation Mechanism (KEM) — LPN-based key agreement with LDPC error correction. Constant-time Rust/WASM engine supporting three security tiers: LNQC-256, LNQC-512, and LNQC-714.
$Install
npm install @lanitlabs/pqc-lnqc714→Quick Start
import LNQC from '@lanitlabs/pqc-lnqc714';
// ── Available variants ──────────────────────────
LNQC.getVariants(); // ["256", "512", "714"]
// ── 1. Generate a key pair (LNQC-512) ───────────
const keys = LNQC.keyGen("512");
// keys.publicKeyA: Uint8Array(262144) — 512×512 matrix
// keys.publicKeyT: Uint8Array(512) — noisy public key
// keys.privateKey: Uint8Array(512) — secret vector
// ── 2. Encapsulate a secret ─────────────────────
const msg = LNQC.randomBits(256);
const ct = LNQC.encapsulate("512",
keys.publicKeyA, keys.publicKeyT, msg,
);
// ct.u: Uint8Array(1048576) — 2048×512 ciphertext
// ct.v: Uint8Array(2048) — masked codeword
// ── 3. Decapsulate to recover the secret ────────
const recovered = LNQC.decapsulate("512",
keys.privateKey, ct.u, ct.v,
);
// recovered.equals(msg) → true#Security Tiers
All three variants use the same LPN-based KEM construction. Choose the tier that matches your security and size requirements.
| Variant | n | m | w | LDPC | Public Key | Ciphertext | Total | Use Case |
|---|---|---|---|---|---|---|---|---|
| LNQC-256 | 256 | 256 | 2 | (128, 1024) | 65,792 B | 263,168 B | ~321 KB | Lightweight / embedded |
| LNQC-512 | 512 | 512 | 4 | (256, 2048) | 262,656 B | 1,050,624 B | ~1.3 MB | Balanced / general |
| LNQC-714 | 714 | 714 | 4 | (357, 2856) | 510,510 B | 2,042,040 B | ~2.4 MB | Flagship / max security |
// LNQC-256 — lightweight (n=256, w=2)
const light = LNQC.keyGen("256");
// LNQC-512 — balanced (n=512, w=4)
const medium = LNQC.keyGen("512");
// LNQC-714 — flagship (n=714, w=4)
const heavy = LNQC.keyGen("714");#Platform Support
Node.js
Native WASM runtime via wasm-bindgen nodejs target. Auto-detected by the SDK wrapper.
const { LNQC } = require('@lanitlabs/pqc-lnqc714');
const keys = LNQC.keyGen("512");Browser
ES module bundler target. Works with webpack, Vite, Turbopack, and CDN imports.
<script type="module">
import LNQC from 'https://cdn.jsdelivr.net/npm/@lanitlabs/pqc-lnqc714/+esm';
const keys = LNQC.keyGen("512");
</script>Edge / Deno
The browser build also runs in Cloudflare Workers, Deno, and Bun via standard WASM support.
AAPI Reference
LNQC.getVariants()string[]Return the list of supported variant names: ['256', '512', '714'].
none
LNQC.getVariantInfo(variant)JSON stringReturn parameter info (n, m, noise weight, LDPC dimensions) for a variant.
variant: "256" | "512" | "714"
LNQC.keyGen(variant)KeyPairGenerate a fresh key pair for the given variant. Public key is (A, t), private key is s.
variant: "256" | "512" | "714"
LNQC.encapsulate(variant, pubKeyA, pubKeyT, message)CiphertextEncapsulate a secret message under a public key. Returns (U, V).
variant: "256" | "512" | "714",
pubKeyA: Uint8Array, pubKeyT: Uint8Array,
message: Uint8Array(ldpcDataBits)LNQC.decapsulate(variant, privKey, u, v)Uint8ArrayRecover the encapsulated secret using the private key. LDPC decoder corrects LPN noise.
variant: "256" | "512" | "714",
privKey: Uint8Array, u: Uint8Array, v: Uint8ArrayLNQC.randomBits(len)Uint8ArrayGenerate cryptographically secure random bits via OS entropy (getrandom / crypto.getRandomValues).
len: number
LNQC.constantTimeVerify(a, b)booleanCompare two byte arrays in constant time using subtle::ConstantTimeEq. No early-exit timing leakage.
a: Uint8Array, b: Uint8Array
>End-to-End Example
import LNQC from '@lanitlabs/pqc-lnqc714';
const alice = LNQC.keyGen("512");
const bob = LNQC.keyGen("512");
// Alice encapsulates
const secret = LNQC.randomBits(256);
const ct = LNQC.encapsulate("512",
alice.publicKeyA, alice.publicKeyT, secret,
);
// Bob decapsulates
const recovered = LNQC.decapsulate("512",
alice.privateKey, ct.u, ct.v,
);
// Constant-time comparison of shared secrets
const match = LNQC.constantTimeVerify(secret, recovered);
// match === true*Architecture
JS/TS ── dist/index.js (dynamic loader with variant routing)
│
┌───────────┴───────────┐
│ │
pkg/node/ pkg/browser/
(Node.js) (Bundler/CDN)
│ │
└───────────┬───────────┘
│
Rust/WASM src/crypto.rs
• 3 variants: LNQC-256/512/714 (Variant struct)
• Secure RNG via getrandom (OS entropy)
• Regular LDPC construction (col_weight=15)
• Per-variant lazy LDPC parameter caching
• Gallager bit-flipping decoder (200 iters)
• Sparse R_indices multiply
• subtle::ConstantTimeEq verificationPublished on npm as @lanitlabs/pqc-lnqc714
LNQC