rokdocs
v0.1

rok::core::crypto

Cryptographic algorithms: pure computation, no OS (randomness is rok::std::crypto::random). Secret data is handled in constant time: no branch or memory index depends on it.

Modules

  • secret Secret storage (2.21.5): a buffer in the large-object space, so the collector never moves or copies it, zeroed by `wipe`, by `using` release and by the collection that frees it (`rok_gc_secret_new`).
  • sha2 SHA-2 (FIPS 180-4): SHA-256, SHA-384 and SHA-512, chosen by `HashAlgorithm`; `Digest` is a running hash.
  • hmac HMAC (RFC 2104) and HKDF (RFC 5869) over a SHA-2 function.
  • sha3 SHA-3 (FIPS 202): SHA3-256, SHA3-512 and the SHAKE128 / SHAKE256 extendable-output functions, all over Keccak-f[1600].
  • aead Authenticated encryption with associated data: AES-GCM (NIST SP 800-38D, 96-bit nonces) and ChaCha20-Poly1305 (RFC 8439).
  • x25519 X25519 (RFC 7748): Diffie-Hellman on Curve25519's u coordinate.
  • ed25519 Ed25519 (RFC 8032 5.1): pure EdDSA over edwards25519 with SHA-512.
  • ecdsa ECDSA (FIPS 186-5) on P-256 and P-384: verification, and signing with RFC 6979 deterministic nonces.
  • rsa RSA (RFC 8017): PKCS #1 v1.5 and PSS verification and signing (MGF1 with the message hash), moduli of 2048 to 4096 bits.
  • mlkem ML-KEM-768 (FIPS 203): k = 3, eta1 = eta2 = 2, du = 10, dv = 4.

Re-exports

secret::Secret

pub use secret::Secret

sha2::

pub use sha2::

sha3::

pub use sha3::

hmac::

pub use hmac::

aead::

pub use aead::

x25519::X25519

pub use x25519::X25519

mlkem::MlKem768

pub use mlkem::MlKem768

ed25519::Ed25519

pub use ed25519::Ed25519

ecdsa::

pub use ecdsa::

rsa::

pub use rsa::

Type aliases

Bytes

pub type Bytes = List<u8> | Slice<u8> | str | Secret

Byte input: a list, a view, a string's UTF-8 bytes or a secret.

Functions

constant_time_eq

pub fn constant_time_eq(a: Bytes, b: Bytes) -> bool

Whether a and b are equal, in time that depends only on their lengths.