docs

您正在閱讀 v0.1.2 的文件。Nabi 0.1.2 已停止支援。 最新版本:v0.1.3 →

core::crypto

本頁內容

API 參考只有英文版,由標準函式庫原始碼中的英文文件註解產生。

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

Experimental: tested against NIST CAVP and Wycheproof vectors, not independently audited.

Modules

  • aead Authenticated encryption with associated data: AES-GCM (NIST SP 800-38D, 96-bit nonces) and ChaCha20-Poly1305 (RFC 8439).
  • ecdsa ECDSA (FIPS 186-5) on P-256 and P-384: verification, and signing with RFC 6979 deterministic nonces.
  • ed25519 Ed25519 (RFC 8032 5.1): pure EdDSA over edwards25519 with SHA-512.
  • hkdf HKDF (RFC 5869) over any HashAlgorithm: extract a pseudorandom key, expand it into output keying material.
  • hmac HMAC (RFC 2104) over any HashAlgorithm, SHA-2 or SHA-3.
  • mlkem ML-KEM-768 (FIPS 203): k = 3, eta1 = eta2 = 2, du = 10, dv = 4.
  • rsa RSA (RFC 8017): PKCS #1 v1.5 and PSS verification and signing (MGF1 with the message hash), moduli of 2048 to 4096 bits.
  • secret Secret storage: 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 (nabi_gc_secret_new).
  • sha2 SHA-2 (FIPS 180-4): SHA-256, SHA-384 and SHA-512.
  • sha3 SHA-3 (FIPS 202): SHA3-256, SHA3-512 and the SHAKE128 / SHAKE256 extendable-output functions, all over Keccak-f[1600].
  • x25519 X25519 (RFC 7748): Diffie-Hellman on Curve25519's u coordinate.

Re-exports

aead::{AeadAlgorithm, Aead}Source

pub use aead::{AeadAlgorithm, Aead}

ecdsa::EcCurveSource

pub use ecdsa::EcCurve
  • EcCurve The elliptic curves Ecdsa signs over: NIST P-256 and P-384.

hmac::HmacSource

pub use hmac::Hmac
  • Hmac A running HMAC.

secret::SecretSource

pub use secret::Secret
  • Secret A fixed-length secret byte string.

sha2::DigestSource

pub use sha2::Digest
  • Digest A running hash of a HashAlgorithm.

sha3::{Sha3_256, Sha3_512, Shake128, Shake256}Source

pub use sha3::{Sha3_256, Sha3_512, Shake128, Shake256}
  • Sha3_256 SHA3-256, fixed at compile time: 32-byte digests.
  • Sha3_512 SHA3-512, fixed at compile time: 64-byte digests.
  • Shake128 SHAKE128: update the input, then squeeze output in any pieces.
  • Shake256 SHAKE256, like Shake128.

Enums

HashAlgorithmSource

pub enum HashAlgorithm

A hash function chosen at run time (HMAC, HKDF, signatures, TLS).

Functions

constant_time_eqSource

pub fn constant_time_eq<A: AsBytes, B: AsBytes>(a: A, b: B) -> bool

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