AkurAI Build
Menu

Public repository / master

AkurAI-Framework / crates/crypto/src/lib.rs

Latest change 3aae9f4e85241bcb775c31f5c03094becd3da56a - Pure-Rust UI layer: akurai-ui, akurai-crypto, Tailwind-grade akurai-css by Ólafur Búi Ólafsson

//! AkurAI-Framework auth crypto — pure `std`, zero dependencies.
//!
//! The primitives the framework's auth layer needs, written from the
//! standards and pinned by their known-answer vectors:
//! - **hashing**: [`sha256`] / incremental [`Sha256`] (FIPS 180-4).
//! - **MAC**: [`hmac_sha256`] (RFC 2104, vectors from RFC 4231) — for signed
//!   session cookies and tokens.
//! - **key derivation**: [`pbkdf2_sha256`] (RFC 8018, vectors from RFC 7914).
//! - **passwords**: [`hash_password`] / [`verify_password`] over the encoded
//!   form `pbkdf2-sha256$<iterations>$<salt_hex>$<hash_hex>`.
//! - **helpers**: constant-time [`ct_eq`], [`hex`] / [`from_hex`], and (off
//!   wasm) OS randomness via [`random_bytes`] / [`random_token`].
//!
//! ```
//! use akurai_crypto::{hex, hmac_sha256, sha256};
//!
//! assert_eq!(
//!     hex(&sha256(b"abc")),
//!     "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"
//! );
//! let tag = hmac_sha256(b"server-secret", b"session=42");
//! assert_eq!(tag.len(), 32);
//! ```
//!
//! This is **not** a general-purpose crypto library: no ciphers, no
//! signatures, no key exchange. It carries only what authentication needs; add
//! a primitive here only when auth requires it.

#![forbid(unsafe_code)]

mod ct;
mod hexcodec;
mod hmac;
mod password;
mod pbkdf2;
#[cfg(not(target_arch = "wasm32"))]
mod random;
mod sha256;

pub use ct::ct_eq;
pub use hexcodec::{from_hex, hex};
pub use hmac::hmac_sha256;
#[cfg(not(target_arch = "wasm32"))]
pub use password::hash_password;
pub use password::{verify_password, PASSWORD_ITERATIONS};
pub use pbkdf2::pbkdf2_sha256;
#[cfg(not(target_arch = "wasm32"))]
pub use random::{random_bytes, random_token};
pub use sha256::{sha256, Sha256};