noxtls 0.2.20

TLS/DTLS protocol and connection state machine for the noxtls Rust stack.
Documentation
// Copyright (c) 2019-2026, Argenox Technologies LLC
// All rights reserved.
//
// SPDX-License-Identifier: GPL-2.0-only OR LicenseRef-Argenox-Commercial-License

//! Bridges [`noxtls_platform`] traits into DRBG and validation helpers.

use noxtls_core::Result;
use noxtls_crypto::HmacDrbgSha256;
use noxtls_platform::{EntropySource, TimeSource};

/// Instantiates an HMAC-DRBG from platform entropy (minimum 32 bytes entropy + 16 byte nonce).
pub fn noxtls_hmac_drbg_from_entropy(
    entropy: &mut dyn EntropySource,
    personalization: &[u8],
) -> Result<HmacDrbgSha256> {
    let mut seed = [0_u8; 32];
    let mut nonce = [0_u8; 16];
    entropy.fill(&mut seed);
    entropy.fill(&mut nonce);
    HmacDrbgSha256::noxtls_new(&seed, &nonce, personalization)
}

/// Fills `out` with unpredictable bytes from `entropy`.
pub fn noxtls_fill_random(entropy: &mut dyn EntropySource, out: &mut [u8]) {
    entropy.fill(out);
}

/// Returns PKIX GeneralizedTime `now` for certificate chain validation.
#[must_use]
pub fn noxtls_cert_validation_time_now(
    time: &dyn TimeSource,
) -> noxtls_platform::GeneralizedTimeString {
    noxtls_platform::noxtls_format_unix_secs_as_generalized_time(time.unix_secs())
}