#![forbid(unsafe_code)]
pub use oxicrypto_core::{
ct_eq,
ct_is_zero,
ct_select,
Aead,
AlgorithmCategory,
AlgorithmId,
ConstantTimeEq,
CryptoError,
Hash,
Kdf,
KeyAgreement,
KeyPair,
Mac,
Rng,
SecretKey,
SecretVec,
Signer,
StreamingHash,
StreamingMac,
Verifier,
Zeroize,
ZeroizeOnDrop,
};
#[cfg(feature = "pure")]
pub use oxicrypto_hash::{
parallel_hash128,
parallel_hash128_xof,
parallel_hash256,
parallel_hash256_xof,
HashBuilder,
ParallelHash128,
ParallelHash256,
};
#[cfg(feature = "pure")]
pub use oxicrypto_aead::{
aes128_key_unwrap,
aes128_key_wrap,
aes256_key_unwrap,
aes256_key_wrap,
open_box,
seal_box,
seal_with_random_nonce,
AesGcmSiv128,
AesGcmSiv256,
Deoxys2_128,
XChaCha20Poly1305,
};
#[cfg(feature = "pure")]
pub use oxicrypto_kdf::{
argon2id_derive,
balloon_sha256,
balloon_sha512,
hkdf_expand_label_sha256,
hkdf_expand_label_sha384,
hkdf_sha256_expand,
hkdf_sha256_extract,
hkdf_sha384_expand,
hkdf_sha384_extract,
hkdf_sha512_expand,
hkdf_sha512_extract,
pbkdf2_sha256,
pbkdf2_sha512,
scrypt_derive,
Argon2Params,
Argon2idStretchParams,
BalloonHasher,
BalloonParams,
BalloonStretchParams,
BalloonVariant,
HkdfSha384,
KeyStretcher,
Pbkdf2StretchParams,
ScryptStretchParams,
StretchParams,
Stretcher,
};
#[cfg(feature = "pure")]
pub mod cipher {
pub use oxicrypto_cipher::{
aes128_encrypt_block, aes256_encrypt_block, chacha20_keystream_block, AES128_KEY_LEN,
AES256_KEY_LEN, AES_BLOCK_LEN, CHACHA20_KEY_LEN, CHACHA20_NONCE_LEN,
};
}
#[cfg(feature = "pure")]
pub use oxicrypto_sig::{
schnorr_bip340_sign_with_aux,
EcdsaP256Signer,
EcdsaP256Verifier,
EcdsaP384Signer,
EcdsaP384Verifier,
EcdsaP521Signer,
EcdsaP521Verifier,
Ed448SigningKey,
Ed448VerifyingKey,
RsaPkcs1v15Sha256Signer,
RsaPkcs1v15Sha256Verifier,
RsaPkcs1v15Sha384Signer,
RsaPkcs1v15Sha384Verifier,
RsaPkcs1v15Sha512Signer,
RsaPkcs1v15Sha512Verifier,
RsaPssSha256Signer,
RsaPssSha256Verifier,
SchnorrBip340,
};
#[cfg(feature = "pure")]
pub use oxicrypto_mac::HmacSha384;
#[cfg(feature = "pure")]
pub use oxicrypto_kex::{EcdhP256, EcdhP384};
#[cfg(feature = "pure")]
pub mod hpke {
pub use oxicrypto_kex::hpke::{AeadId, HpkeContextR, HpkeContextS, HpkeSuite, KdfId, KemId};
}
#[cfg(feature = "pure")]
pub use oxicrypto_rand::{random_bytes, random_nonce, random_range, reseed};
pub mod algo;
pub use algo::*;
pub mod version;
#[cfg(feature = "pq-preview")]
pub use version::PqSuite;
pub use version::{available_algorithms, enabled_features, version, Suite, VersionInfo};
#[cfg(feature = "aws-lc")]
pub mod aws_lc {
pub use oxicrypto_adapter_aws_lc::*;
}
#[cfg(feature = "pkcs11")]
pub mod pkcs11 {
pub use oxicrypto_adapter_pkcs11::*;
}
#[cfg(feature = "pq-preview")]
pub mod pq {
pub use oxicrypto_pq::*;
}
#[cfg(feature = "simd")]
pub mod simd {
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct CpuInfo {
pub has_aes_ni: bool,
pub has_sha_ni: bool,
pub has_avx2: bool,
pub has_neon: bool,
}
#[must_use]
pub fn cpu_info() -> CpuInfo {
cpu_info_impl()
}
#[cfg(any(target_arch = "x86_64", target_arch = "x86"))]
fn cpu_info_impl() -> CpuInfo {
cpufeatures::new!(oxi_aes_det, "aes");
cpufeatures::new!(oxi_sha_det, "sha");
cpufeatures::new!(oxi_avx2_det, "avx2");
CpuInfo {
has_aes_ni: oxi_aes_det::get(),
has_sha_ni: oxi_sha_det::get(),
has_avx2: oxi_avx2_det::get(),
has_neon: false,
}
}
#[cfg(target_arch = "aarch64")]
fn cpu_info_impl() -> CpuInfo {
cpufeatures::new!(oxi_aes_det, "aes");
cpufeatures::new!(oxi_sha2_det, "sha2");
CpuInfo {
has_aes_ni: oxi_aes_det::get(),
has_sha_ni: oxi_sha2_det::get(),
has_avx2: false,
has_neon: true,
}
}
#[cfg(not(any(target_arch = "x86_64", target_arch = "x86", target_arch = "aarch64",)))]
fn cpu_info_impl() -> CpuInfo {
CpuInfo {
has_aes_ni: false,
has_sha_ni: false,
has_avx2: false,
has_neon: false,
}
}
}
#[cfg(feature = "pure")]
pub fn new_rng() -> Result<oxicrypto_core::Box<dyn Rng>, CryptoError> {
oxicrypto_rand::OxiRng::new()
.map(|r| oxicrypto_core::Box::new(r) as oxicrypto_core::Box<dyn Rng>)
}
#[cfg(feature = "pure")]
#[must_use]
#[inline]
pub fn sha256(msg: &[u8]) -> [u8; 32] {
let h = hash_impl(HashAlgo::Sha256);
let mut out = [0u8; 32];
h.hash(msg, &mut out)
.expect("SHA-256 cannot fail: buffer is always correct size");
out
}
#[cfg(feature = "pure")]
#[must_use]
#[inline]
pub fn sha512(msg: &[u8]) -> [u8; 64] {
let h = hash_impl(HashAlgo::Sha512);
let mut out = [0u8; 64];
h.hash(msg, &mut out)
.expect("SHA-512 cannot fail: buffer is always correct size");
out
}
#[cfg(feature = "pure")]
#[must_use]
#[inline]
pub fn blake3(msg: &[u8]) -> [u8; 32] {
let h = hash_impl(HashAlgo::Blake3);
let mut out = [0u8; 32];
h.hash(msg, &mut out)
.expect("BLAKE3 cannot fail: buffer is always correct size");
out
}
pub mod prelude {
pub use oxicrypto_core::{
Aead, AlgorithmCategory, AlgorithmId, ConstantTimeEq, CryptoError, Hash, Kdf, Kem,
KeyAgreement, KeyPair, Mac, PasswordHash, Rng, SecretKey, SecretVec, Signer, StreamingAead,
StreamingHash, StreamingMac, Verifier, Zeroize, ZeroizeOnDrop,
};
pub use crate::{AeadAlgo, HashAlgo, KdfAlgo, KexAlgo, MacAlgo, SigAlgo};
#[cfg(feature = "pq-preview")]
pub use crate::{PqKemAlgo, PqSigAlgo};
#[cfg(feature = "pure")]
pub use crate::{
aead_impl, blake3, hash_impl, kdf_impl, kex_impl, mac_impl, new_rng, sha256, sha512,
signer_impl, verifier_impl,
};
pub use crate::{available_algorithms, version, VersionInfo};
}
#[cfg(test)]
#[cfg(feature = "pure")]
mod tests;