Skip to main content

Crate crystals_dilithium

Crate crystals_dilithium 

Source
Expand description

crystals-dilithium provides a pure Rust implementation of:

  • CRYSTALS-Dilithium (dilithium2, dilithium3, dilithium5)
  • ML-DSA (ml_dsa_44, ml_dsa_65, ml_dsa_87)

§Quick Example (Dilithium2)

use crystals_dilithium::dilithium2::Keypair;

let seed = [42u8; 32];
let msg = b"hello world";

let keypair = Keypair::generate(Some(&seed)).unwrap();
let sig = keypair.sign(msg);
assert!(keypair.verify(msg, &sig));

§Quick Example (ML-DSA-44)

use crystals_dilithium::ml_dsa_44::Keypair;
use crystals_dilithium::RandomMode;

let seed = [7u8; 32];
let msg = b"hello world";

let keypair = Keypair::generate(Some(&seed)).unwrap();
let sig = keypair
    .sign(msg, None, RandomMode::Deterministic)
    .unwrap();
assert!(keypair.verify(msg, &sig, None));

§Error Handling

Key generation and key deserialization APIs return Result, so malformed external input can be handled without panics.

use crystals_dilithium::dilithium2::PublicKey;

let invalid = [0u8; 7];
assert!(PublicKey::from_bytes(&invalid).is_err());

§Security Notes

  • This crate has not undergone a formal third-party security audit.
  • The high-level modules (dilithium*, ml_dsa_*) are the recommended API.
  • Low-level signing primitives are internal by default and are only exposed when the acvp-internal feature is enabled.

§Module Map

  • dilithium2, dilithium3, dilithium5: high-level CRYSTALS-Dilithium APIs
  • ml_dsa_44, ml_dsa_65, ml_dsa_87: high-level ML-DSA APIs
  • prehash: pre-hash helpers for ML-DSA prehash modes
  • sign (feature acvp-internal): low-level signing primitives (packed-buffer oriented)

§ML-DSA Modes

High-level ML-DSA modules expose three flows:

  • Pure mode: sign / verify
  • Pre-hash mode: prehash_sign / prehash_verify
  • Internal mode (acvp-internal): sign_internal, verify_internal, sign_mu, verify_mu

Signing randomness is controlled by RandomMode.

Modules§

dilithium2
dilithium3
dilithium5
ml_dsa_44
High-level ML-DSA-44 API.
ml_dsa_65
High-level ML-DSA-65 API.
ml_dsa_87
High-level ML-DSA-87 API.
prehash

Enums§

Error
RandomMode