{"id":47915804,"url":"https://github.com/crabnebula-dev/moduletto","last_synced_at":"2026-04-08T09:00:47.655Z","repository":{"id":348746933,"uuid":"1198664112","full_name":"crabnebula-dev/moduletto","owner":"crabnebula-dev","description":"Pretty Fast Modulus Math on Arm with Rust","archived":false,"fork":false,"pushed_at":"2026-04-02T16:17:07.000Z","size":162,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-04T05:39:02.664Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/crabnebula-dev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-04-01T16:30:13.000Z","updated_at":"2026-04-03T07:35:29.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/crabnebula-dev/moduletto","commit_stats":null,"previous_names":["crabnebula-dev/moduletto"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/crabnebula-dev/moduletto","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crabnebula-dev%2Fmoduletto","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crabnebula-dev%2Fmoduletto/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crabnebula-dev%2Fmoduletto/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crabnebula-dev%2Fmoduletto/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/crabnebula-dev","download_url":"https://codeload.github.com/crabnebula-dev/moduletto/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crabnebula-dev%2Fmoduletto/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31426193,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-05T02:22:46.605Z","status":"ssl_error","status_checked_at":"2026-04-05T02:22:33.263Z","response_time":75,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-04-04T05:35:40.071Z","updated_at":"2026-04-05T06:00:49.495Z","avatar_url":"https://github.com/crabnebula-dev.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Moduletto Native Smart\n\nOptimized modular arithmetic and NTT for lattice cryptography. Includes a full Kyber-512 (ML-KEM-512) implementation with ARM64 NEON-accelerated int16 NTT in constant time, as WASM, and with optional no_std.\n\n## Performance\n\nFull Kyber-512 KEM session on Apple Silicon (M5 Pro):\n\n| Phase | Moduletto NEON i16 | LibOQS 0.15.0 | Kyber C Reference |\n|-------|:--------------------:|:-------------:|:-----------------:|\n| Key generation | 8.42 us | 7.19 us | 14.93 us |\n| Encapsulation | 16.79 us | 6.98 us | 14.57 us |\n| Decapsulation | 20.58 us | 8.27 us | 18.37 us |\n| **Total** | **45.79 us** | **22.44 us** | **47.87 us** |\n\nmoduletto is **faster than the Kyber C Reference** and within 2.04x of LibOQS. The remaining gap is primarily hashing overhead (~29 us/session for ~39 Keccak calls). Polynomial arithmetic alone is within 1.26x of LibOQS.\n\n## What's Inside\n\n### Core (`src/`)\n\n- **`modn.rs`** -- Generic `ModN\u003cN\u003e` type for modular arithmetic over any modulus \u003c 2^31. Variable-time operations using i64 native register arithmetic (3x faster than i128).\n- **`modn_ct.rs`** -- Constant-time variant of `ModN` with side-channel resistant operations (bitwise masks, no data-dependent branches). Zero overhead at the scalar level.\n- **`ntt.rs`** -- Number Theoretic Transform for `ModN\u003cN\u003e` polynomials (degree 256). Forward/inverse NTT with Cooley-Tukey/Gentleman-Sande butterflies.\n- **`wasm.rs`** -- Optional WebAssembly bindings via `wasm-bindgen`.\n\n### Kyber Benchmark (`examples/kyber_benchmark.rs`)\n\nA standalone Kyber-512 KEM implementation featuring:\n- **ARM64 NEON int16 NTT** -- Montgomery multiplication via `vmull_s16`/`vmovn_s32`/`vshrn_n_s32`, processing 8 coefficients per butterfly\n- **Inline Keccak-f[1600]** -- Pure-Rust implementation translated from XKCP\n- **SHA3-256/512, SHAKE-128/256** -- Complete hash suite for Kyber key derivation and sampling\n- **Full KEM flow** -- keygen, encapsulation, decapsulation with implicit rejection (FO transform)\n\n### Hybrid Post-Quantum Encryption (`examples/hybrid_pq_aes.rs`)\n\nA complete Kyber-512 + AES-256-GCM hybrid encryption system demonstrating the standard post-quantum key encapsulation pattern used in TLS 1.3 and Signal's PQXDH:\n\n```bash\ncargo run --release --example hybrid_pq_aes\n```\n\n1. Kyber-512 KEM establishes a 256-bit shared secret (768-byte ciphertext)\n2. AES-256-GCM encrypts arbitrary plaintext with the shared secret\n3. Tamper detection via GCM authentication tag + Kyber IND-CCA2 implicit rejection\n\n## Usage\n\n```rust\nuse moduletto::ModN;\n\n// Kyber-512 modulus\ntype Mod3329 = ModN\u003c3329\u003e;\n\nlet a = Mod3329::new(1234);\nlet b = Mod3329::new(5678);\nlet c = a.ct_mul(b);\n\n// Polynomial operations\nuse moduletto::ntt;\nlet mut poly = [Mod3329::zero(); 256];\n// ... populate poly ...\n// NTT-based polynomial multiplication available via ntt module\n```\n\n### Constant-time operations\n\n```rust\nuse moduletto::modn_ct::ModN as ModNCT;\n\ntype F = ModNCT\u003c3329\u003e;\nlet a = F::new(42);\nlet b = F::new(99);\n\n// No data-dependent branches or memory access\nlet sum = a.ct_add(b);\nlet selected = F::ct_select(a, b, true); // constant-time conditional\n```\n\n## Running Benchmarks\n\n```bash\n# Full Kyber-512 KEM benchmark (NEON i16 NTT on ARM64)\ncargo run --release --example kyber_benchmark\n\n# Criterion microbenchmarks for polynomial primitives\ncargo bench\n\n# no_std compatibility check\ncargo test --lib --no-default-features --release\n```\n\n## Feature Flags\n\n| Feature | Description |\n|---------|-------------|\n| `std` (default) | Standard library support |\n| `alloc` | Heap allocation + `libm` for no_std math |\n| `wasm` | WebAssembly bindings via `wasm-bindgen` |\n\n```toml\n# Default (std)\nmoduletto = \"0.1\"\n\n# no_std without allocator\nmoduletto = { version = \"0.1\", default-features = false }\n\n# no_std with allocator\nmoduletto = { version = \"0.1\", default-features = false, features = [\"alloc\"] }\n\n# WebAssembly\nmoduletto = { version = \"0.1\", features = [\"wasm\"] }\n```\n\n## Architecture\n\n- **ARM64 (Apple Silicon, Cortex-A)**: NEON int16 NTT for Kyber, i64 scalar for generic ModN\n- **x86-64**: i64 scalar (no SIMD NTT yet)\n- **WebAssembly**: Supported via `wasm` feature flag\n\n### Why i64 for generic ModN\n\nFor moduli \u003c 2^31, i64 is 3x faster than i128 on 64-bit platforms. i64 maps to native register width -- add/sub/mul are single instructions. i128 requires register pairs and multi-instruction sequences.\n\n| Operation (n=256) | i64 (this) | i128 | Speedup |\n|-------------------|:----------:|:----:|:-------:|\n| poly_add | 63 ns | ~295 ns | 3.2x |\n| poly_sub | 72 ns | ~370 ns | 3.5x |\n\n### Why int16 for Kyber NTT\n\nKyber's modulus q=3329 fits in 12 bits. Using i16 coefficients with ARM64 NEON intrinsics (`int16x8_t`) processes 8 coefficients per vector instruction. Montgomery multiplication (`fqmul`) uses `vmull_s16` -\u003e `vmovn_s32` -\u003e `vshrn_n_s32` to compute `a*b*R^{-1} mod q` entirely in NEON registers.\n\n## Formal Verification (`proofs/`)\n\nThe constant-time arithmetic is formally verified using Coq (Rocq 9.1) with an accompanying OCaml test harness.\n\n### Prerequisites\n\n```bash\n# macOS (Homebrew)\nbrew install rocq opam\n\n# Linux (apt) — install opam, then use it for Rocq\nsudo apt install opam\nopam init\nopam install rocq-prover\n```\n\nRequires Rocq/Coq \u003e= 9.0 and OCaml \u003e= 5.0.\n\n### Running\n\n```bash\n# Compile all Coq proofs and run OCaml tests\ncd proofs \u0026\u0026 make\n\n# Coq proofs only (type-checks all theorems)\nmake coq\n\n# OCaml runtime tests only (27,000+ test cases)\nmake ocaml\n\n# Clean build artifacts\nmake clean\n```\n\nA successful `make coq` means every theorem has been machine-checked by the Rocq kernel -- no axioms are used except one `Admitted` lemma for NTT linearity (the inductive list proof is mechanical but lengthy; it is covered by the OCaml runtime tests instead).\n\n### Coq proofs\n\n- **`ModularArithmetic.v`** -- Correctness of branchless CT add/sub/neg (equivalence to branching versions, correctness mod N, range closure, algebraic properties)\n- **`BarrettReduction.v`** -- Barrett reduction produces `x mod N` for inputs \u003c N^2, with quotient approximation bounds and Kyber-3329 instantiation\n- **`ConstantTime.v`** -- ct_select, ct_swap (XOR swap), ct_lt, ct_is_zero: functional correctness of all branchless primitives\n- **`NTT.v`** -- Kyber parameter verification: zeta=17 is a primitive 256th root of unity mod 3329, 128^(-1) = 3303 mod 3329, primality of 3329\n\n### OCaml test harness\n\n- **`test_moduletto.ml`** -- 27,000+ runtime tests validating VT/CT agreement, Barrett reduction, CT primitives, and NTT root-of-unity properties across sampled Kyber coefficient ranges\n\n## Fuzzing (`fuzz/`)\n\nCoverage-guided fuzzing via [cargo-fuzz](https://github.com/rust-fuzz/cargo-fuzz) (libFuzzer). Requires a nightly toolchain.\n\n### Prerequisites\n\n```bash\ncargo install cargo-fuzz\nrustup toolchain install nightly\n```\n\n### Running\n\n```bash\n# Run a specific target (runs until stopped with Ctrl-C)\ncargo +nightly fuzz run fuzz_ct_arith\n\n# Run for a fixed duration\ncargo +nightly fuzz run fuzz_barrett -- -max_total_time=60\n\n# List all available targets\ncargo +nightly fuzz list\n\n# Run all targets for 30 seconds each\nfor target in $(cargo +nightly fuzz list); do\n  echo \"=== $target ===\"\n  cargo +nightly fuzz run \"$target\" -- -max_total_time=30\ndone\n```\n\n### Fuzz targets\n\n| Target | What it tests |\n|--------|---------------|\n| `fuzz_ct_arith` | CT vs VT equivalence for add/sub/mul/neg, range invariants, algebraic properties (identity, inverse, roundtrip) |\n| `fuzz_barrett` | Barrett reduction correctness across six different moduli (7, 127, 251, 257, 3329, 65537) |\n| `fuzz_ntt_roundtrip` | NTT -\u003e INTT roundtrip for arbitrary polynomials, CT vs VT NTT agreement |\n| `fuzz_ct_primitives` | ct_select, ct_swap, ct_eq, ct_lt: specification compliance, reflexivity, double-swap identity |\n| `fuzz_poly_mul` | NTT polynomial multiplication vs schoolbook (ground truth), CT vs VT agreement |\n\nCrash artifacts are saved to `fuzz/artifacts/\u003ctarget\u003e/` and can be replayed with:\n\n```bash\ncargo +nightly fuzz run fuzz_ct_arith fuzz/artifacts/fuzz_ct_arith/\u003ccrash-file\u003e\n```\n\n## License\n\nPolyform-Noncommercial-1.0.0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrabnebula-dev%2Fmoduletto","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcrabnebula-dev%2Fmoduletto","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrabnebula-dev%2Fmoduletto/lists"}