Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/third_party/rust/neqo-transport/src/packet/   (Firefox Browser Version 153.0.1©)  Datei vom 27.6.2026 mit Größe 2 kB image not shown  

Quelle  retry.rs

  Sprache: Rust
 

// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::cell::RefCell;

use neqo_common::qerror;
use nss::{
    Mode, RecordProtection as Aead, RecordProtectionOps as _, TLS_AES_128_GCM_SHA256,
    TLS_VERSION_1_3, hkdf,
};

use crate::{Error, Res, version::Version};

/// The AEAD used for Retry is fixed, so use thread local storage.
fn make_aead(version: Version, mode: Mode) -> Aead {
    #[cfg(debug_assertions)]
    ::nss::assert_initialized();

    let secret = hkdf::import_key(TLS_VERSION_1_3, version.retry_secret()).expect("can import key");
    Aead::new(
        TLS_VERSION_1_3,
        TLS_AES_128_GCM_SHA256,
        &secret,
        version.label_prefix(),
        mode,
    )
    .expect("can create AEAD")
}
#[cfg(feature = "draft-29")]
thread_local!(static RETRY_AEAD_29_ENC: RefCell<Aead> = RefCell::new(make_aead(Version::Draft29, Mode::Encrypt)));
#[cfg(feature = "draft-29")]
thread_local!(static RETRY_AEAD_29_DEC: RefCell<Aead> = RefCell::new(make_aead(Version::Draft29, Mode::Decrypt)));
thread_local!(static RETRY_AEAD_V1_ENC: RefCell<Aead> = RefCell::new(make_aead(Version::Version1, Mode::Encrypt)));
thread_local!(static RETRY_AEAD_V1_DEC: RefCell<Aead> = RefCell::new(make_aead(Version::Version1, Mode::Decrypt)));
thread_local!(static RETRY_AEAD_V2_ENC: RefCell<Aead> = RefCell::new(make_aead(Version::Version2, Mode::Encrypt)));
thread_local!(static RETRY_AEAD_V2_DEC: RefCell<Aead> = RefCell::new(make_aead(Version::Version2, Mode::Decrypt)));

/// Run a function with the appropriate Retry AEAD.
pub fn use_aead<F, T>(version: Version, mode: Mode, f: F) -> Res<T>
where
    F: FnOnce(&Aead) -> Res<T>,
{
    match (version, mode) {
        (Version::Version2, Mode::Encrypt) => &RETRY_AEAD_V2_ENC,
        (Version::Version2, Mode::Decrypt) => &RETRY_AEAD_V2_DEC,
        (Version::Version1, Mode::Encrypt) => &RETRY_AEAD_V1_ENC,
        (Version::Version1, Mode::Decrypt) => &RETRY_AEAD_V1_DEC,
        #[cfg(feature = "draft-29")]
        (Version::Draft29, Mode::Encrypt) => &RETRY_AEAD_29_ENC,
        #[cfg(feature = "draft-29")]
        (Version::Draft29, Mode::Decrypt) => &RETRY_AEAD_29_DEC,
    }
    .try_with(|aead| f(&aead.borrow()))
    .map_err(|e| {
        qerror!("Unable to access Retry AEAD: {e:?}");
        Error::Internal
    })?
}

/// Determine how large the expansion is for a given key.
pub fn expansion(version: Version) -> usize {
    use_aead(version, Mode::Encrypt, |aead| Ok(aead.expansion()))
        .expect("Unable to access Retry AEAD")
}

Messung V0.5 in Prozent
C=91 H=96 G=93

¤ Dauer der Verarbeitung: 0.2 Sekunden  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.