{"id":31286323,"url":"https://github.com/vercingetorx/dilithium-nim","last_synced_at":"2025-09-24T09:20:53.163Z","repository":{"id":314210986,"uuid":"1054598741","full_name":"vercingetorx/dilithium-nim","owner":"vercingetorx","description":"CRYSTALS-Dilithium in pure Nim","archived":false,"fork":false,"pushed_at":"2025-09-11T17:45:28.000Z","size":995,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-09-21T14:52:00.147Z","etag":null,"topics":["cryptography","crystals-dilithium","digital-signature","dilithium","nim","nim-lang","post-quantum-cryptography"],"latest_commit_sha":null,"homepage":"","language":"Nim","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vercingetorx.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":"2025-09-11T04:34:39.000Z","updated_at":"2025-09-11T17:45:32.000Z","dependencies_parsed_at":"2025-09-11T07:59:18.516Z","dependency_job_id":"00542fd3-1eac-4681-950d-f30baad7a130","html_url":"https://github.com/vercingetorx/dilithium-nim","commit_stats":null,"previous_names":["vercingetorx/dilithium-nim"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/vercingetorx/dilithium-nim","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vercingetorx%2Fdilithium-nim","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vercingetorx%2Fdilithium-nim/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vercingetorx%2Fdilithium-nim/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vercingetorx%2Fdilithium-nim/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vercingetorx","download_url":"https://codeload.github.com/vercingetorx/dilithium-nim/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vercingetorx%2Fdilithium-nim/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":276723246,"owners_count":25693111,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-24T02:00:09.776Z","response_time":97,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["cryptography","crystals-dilithium","digital-signature","dilithium","nim","nim-lang","post-quantum-cryptography"],"created_at":"2025-09-24T09:20:52.005Z","updated_at":"2025-09-24T09:20:53.150Z","avatar_url":"https://github.com/vercingetorx.png","language":"Nim","funding_links":[],"categories":[],"sub_categories":[],"readme":"# dilithium-nim — Pure Nim CRYSTALS-Dilithium (signatures)\n\nA **pure Nim** port of the CRYSTALS-Dilithium digital signature scheme (post-quantum).\nUses SHAKE (Keccak) and constant-time helpers implemented in Nim.\n\nDilithium lets you create a **public key**, sign messages with a **secret key**, and anyone can verify those signatures with the public key. It’s NIST-standardized.\n\n## Status\n\n* Implements the full signature API (keygen, sign, verify) for **Dilithium2/3/5**.\n* Passes the official **NIST KAT (.rsp)** vectors.\n* Supports both **deterministic** and **randomized** signing (compile-time toggle).\n* Optional **context label** (up to 255 bytes).\n\n## Sizes (by parameter set)\n\n| Set        | Public Key | Secret Key | Signature |\n| ---------- | ---------- | ---------- | --------- |\n| Dilithium2 | 1312 B     | 2528 B     | 2420 B    |\n| Dilithium3 | 1952 B     | 4000 B     | 3293 B    |\n| Dilithium5 | 2592 B     | 4864 B     | 4595 B    |\n\n\u003e Message size is unchanged by signing; only the signature is added.\n\n## Quick API\n\nSimple, human-readable API (see `dilithium.nim`).\n\n```nim\nimport dilithium  # exports: generateKeypair, signDetached, verifyDetached, signMessage, openSignedMessage\n\n# 1) Make a key pair (uses OS randomness).\nlet (publicKey, secretKey) = generateKeypair()\n\n# 2) Sign a message (detached signature).\nlet message = \"Meet at 12:30 near the cafe.\"\nlet signature = signDetached(message, secretKey)   # optional label: signDetached(message, secretKey, \"orders\")\n\n# 3) Verify the detached signature.\nlet ok = verifyDetached(signature, message, publicKey)\ndoAssert ok\n\n# 4) Sign a message as a single blob (attached: signature stored before the message).\nlet signedBlob = signMessage(message, secretKey)   # optional label: signMessage(message, secretKey, \"chat\")\n\n# 5) Verify and recover the original message from a signed blob.\nlet (valid, recovered) = openSignedMessage(signedBlob, publicKey)\ndoAssert valid\n```\n\n### With a context label (optional)\n\nUse a short label to keep signatures scoped to a feature in your app (e.g., `\"login\"`, `\"invoice\"`).\nYou must pass **the same label** to both sign and verify.\n\n```nim\nlet label = \"orders\"\nlet sig = signDetached(\"Order #4821: ship today\", secretKey, label)\nlet ok  = verifyDetached(sig, \"Order #4821: ship today\", publicKey, label)  # true\nlet no  = verifyDetached(sig, \"Order #4821: ship today\", publicKey, \"WRONG\")# false\n```\n\n## Deterministic vs randomized signing\n\nBy default we follow the reference: **randomized signing** adds fresh randomness to each signature.\n\n**disable** randomized signing at compile time:\n\n```bash\n# Deterministic signing (rnd = all zero bytes):\n-d:nors or -d:norandsig\n```\n\nEnable it (default, can be omitted):\n\n```bash\n# Randomized signing (fresh randomness per signature):\n-d:rs or -d:randsig\n```\n\n## Selecting the parameter set\n\nDefault is **Dilithium2**. Choose at compile time:\n\n```bash\n-d:mode=2   # Dilithium2\n-d:mode=3   # Dilithium3\n-d:mode=5   # Dilithium5\n```\n\n## Testing (KAT)\n\nA lightweight KAT harness is included (parses NIST `.rsp` and checks `pk/sk/sm`):\n\n```bash\n# Example: point to the Dilithium2 vectors\nKAT_RSP=/nistkat/PQCsignKAT_Dilithium2.rsp \\\nnim c -r -d:kat nistkat/test_kat_runner.nim\n```\n\nTips:\n\n* Use `KAT_LIMIT=N` to run only the first N vectors while debugging.\n\n## RNG\n\n* **Public API** uses the OS RNG (e.g., `/dev/urandom`) for keygen and (if enabled) for randomized signing.\n* The **KAT harness** uses the same deterministic DRBG as the reference so results match the `.rsp` files.\n\n## Security notes\n\n* Constant-time primitives are used where required, but this code has **not been audited**.\n* Nim is GC’d; **secret zeroization is not guaranteed**. Be careful with long-lived secrets.\n\n## Layout\n\n```\nsrc/\n  ntt.nim           # Number-theoretic transform and tables\n  packing.nim       # (Un)packing of keys/signatures\n  params.nim        # Parameter set \u0026 sizes; selected by DILITHIUM_MODE (2/3/5)\n  poly.nim          # Polynomial ops\n  polyvec.nim       # Vectors of polynomials\n  randombytes.nim   # OS RNG for public API (e.g., /dev/urandom)\n  reduce.nim        # Modular reduction helpers\n  rounding.nim      # power2round, decompose, hints (make_hint/use_hint)\n  sign.nim          # Keygen, sign, verify (public API)\n  symmetric.nim     # SHAKE256 wrappers (XOF/PRF)\ndilithium.nim       # high-level, friendly API\ntest/               # basic tests\nnistkat/            # KAT tests\nprivate/            # crypto backends\n```\n\n### Note\n\nThis project is for reference/education. Do **not** use in production without an independent security review.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvercingetorx%2Fdilithium-nim","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvercingetorx%2Fdilithium-nim","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvercingetorx%2Fdilithium-nim/lists"}