Skip to main content

noxtls_crypto/
lib.rs

1// Copyright (c) 2019-2026, Argenox Technologies LLC
2// All rights reserved.
3//
4// SPDX-License-Identifier: GPL-2.0-only OR LicenseRef-Argenox-Commercial-License
5//
6// This file is part of the NoxTLS Library.
7//
8// This program is free software: you can redistribute it and/or modify
9// it under the terms of the GNU General Public License as published by the
10// Free Software Foundation; version 2 of the License.
11//
12// Alternatively, this file may be used under the terms of a commercial
13// license from Argenox Technologies LLC.
14//
15// See `noxtls/LICENSE` and `noxtls/LICENSE.md` in this repository for full details.
16// CONTACT: info@argenox.com
17
18#![cfg_attr(not(feature = "std"), no_std)]
19#![forbid(unsafe_code)]
20#![allow(clippy::incompatible_msrv)]
21#![allow(clippy::manual_rotate)]
22
23//! Cryptographic primitives for NoxTLS.
24//!
25//! This crate groups hash and MAC helpers ([`hash`]), deterministic randomness ([`drbg`]),
26//! public-key algorithms ([`pkc`]), and symmetric ciphers ([`sym`]) behind a single
27//! dependency surface re-exported from the crate root.
28
29#[cfg(not(feature = "std"))]
30#[macro_use]
31extern crate alloc;
32
33mod internal_alloc;
34
35pub mod drbg;
36pub mod hash;
37pub mod pkc;
38pub mod sym;
39
40pub use drbg::HmacDrbgSha256;
41pub use hash::{
42    bcrypt_pbkdf_sha512, decode_hex, hkdf_expand_sha256, hkdf_expand_sha384, hkdf_extract_sha256,
43    hkdf_extract_sha384, hmac_sha256, hmac_sha384, hmac_sha512, sha1, sha256, sha384, sha3_256,
44    sha3_384, sha3_512, sha512, shake256, tls12_finished_verify_data_sha256,
45    tls12_finished_verify_data_sha384, tls12_prf_sha256, tls12_prf_sha384, Digest, Sha256, Sha512,
46    TlsTranscriptSha256, TlsTranscriptSha384,
47};
48#[allow(deprecated)]
49pub use pkc::{
50    ecc_generate_keypair_auto, ed25519_generate_private_key_auto,
51    ed25519_public_key_from_subject_public_key_info, ed25519_verify, mldsa_generate_keypair_auto,
52    mldsa_public_key_from_subject_public_key_info, mldsa_verify, mlkem_decapsulate,
53    mlkem_encapsulate_auto, mlkem_generate_keypair_auto, p256_ecdh_shared_secret,
54    p256_ecdsa_sign_digest, p256_ecdsa_sign_digest_auto, p256_ecdsa_sign_sha256,
55    p256_ecdsa_sign_sha256_auto, p256_ecdsa_verify_digest, p256_ecdsa_verify_sha256,
56    p256_generate_private_key_auto, rsa_generate_keypair_secure_auto,
57    rsa_generate_keypair_with_policy_auto, rsaes_oaep_sha256_decrypt,
58    rsaes_oaep_sha256_decrypt_crt_only, rsaes_oaep_sha256_encrypt_auto, rsaes_pkcs1_v15_decrypt,
59    rsaes_pkcs1_v15_decrypt_crt_only, rsaes_pkcs1_v15_encrypt_auto, rsassa_pss_sha256_sign,
60    rsassa_pss_sha256_sign_auto, rsassa_pss_sha256_verify, rsassa_pss_sha384_sign,
61    rsassa_pss_sha384_sign_auto, rsassa_pss_sha384_verify, rsassa_sha1_sign, rsassa_sha1_verify,
62    rsassa_sha256_sign, rsassa_sha256_verify, rsassa_sha384_sign, rsassa_sha384_verify,
63    rsassa_sha512_sign, rsassa_sha512_verify, run_pq_self_tests, x25519, x25519_basepoint,
64    x25519_generate_private_key_auto, x25519_shared_secret, EccKeyAlgorithm, EccPrivateKey,
65    EccPublicKey, Ed25519PrivateKey, Ed25519PublicKey, MlDsaPrivateKey, MlDsaPublicKey,
66    MlKemPrivateKey, MlKemPublicKey, P256PrivateKey, P256PublicKey, RsaKeySizePolicy,
67    RsaPrivateKey, RsaPublicKey, X25519PrivateKey, X25519PublicKey, X448PrivateKey, X448PublicKey,
68    MLKEM_CIPHERTEXT_LEN, MLKEM_PRIVATE_KEY_LEN, MLKEM_PUBLIC_KEY_LEN, MLKEM_SHARED_SECRET_LEN,
69    OID_ID_MLDSA65,
70};
71#[cfg(feature = "hazardous-legacy-crypto")]
72pub use pkc::{rsa_generate_keypair_auto, rsa_generate_keypair_with_exponent_auto};
73#[cfg(feature = "hazardous-legacy-crypto")]
74pub use pkc::{x448, x448_basepoint, x448_generate_private_key_auto, x448_shared_secret};
75pub use sym::{
76    aes_cbc_decrypt, aes_cbc_encrypt, aes_ccm_decrypt, aes_ccm_encrypt, aes_cfb_apply,
77    aes_cfb_decrypt, aes_cfb_encrypt, aes_ctr_apply, aes_gcm_decrypt, aes_gcm_encrypt,
78    aes_ofb_apply, aes_xts_decrypt, aes_xts_encrypt, aria_cbc_decrypt, aria_cbc_encrypt,
79    aria_cfb_apply, aria_cfb_decrypt, aria_cfb_encrypt, aria_ctr_apply, aria_ctr_decrypt,
80    aria_ctr_encrypt, aria_ofb_apply, aria_ofb_decrypt, aria_ofb_encrypt, camellia_cbc_decrypt,
81    camellia_cbc_encrypt, camellia_cfb_apply, camellia_cfb_decrypt, camellia_cfb_encrypt,
82    camellia_ctr_apply, camellia_ctr_decrypt, camellia_ctr_encrypt, camellia_ofb_apply,
83    camellia_ofb_decrypt, camellia_ofb_encrypt, chacha20_poly1305_decrypt,
84    chacha20_poly1305_encrypt, poly1305_key_gen, poly1305_mac, poly1305_tags_equal, AesCipher,
85    AriaCipher, CamelliaCipher, ChaCha20,
86};
87#[cfg(feature = "hazardous-legacy-crypto")]
88pub use sym::{
89    aes_ecb_decrypt, aes_ecb_encrypt, aria_ecb_decrypt, aria_ecb_encrypt, camellia_ecb_decrypt,
90    camellia_ecb_encrypt, des_cbc_decrypt, des_cbc_encrypt, des_cfb_apply, des_cfb_decrypt,
91    des_cfb_encrypt, des_ctr_apply, des_ctr_decrypt, des_ctr_encrypt, des_ecb_decrypt,
92    des_ecb_encrypt, des_ofb_apply, des_ofb_decrypt, des_ofb_encrypt, DesCipher, Rc4,
93};