From f87fff83cfc2b163c98fb9299c2507cb18681e7b Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 8 Nov 2026 14:26:42 +0000 Subject: [PATCH 1/2] Dispatchers: remove selectors, which nothing calls A selector (`_select`, `VG.Rust.selector`) returned the implementation a dispatcher would run, for the Rust code to choose once and call without choosing again; `VG.Dispatch.selected` listed the functions that got one. AES-GCM, their only caller, now calls the dispatchers, which choose once themselves. This removes the selectors from the trusted printer (`Rust.selector`, `Rust.Selected`), the emitter (`files`, `run` and the driver's `#assert_no_compiler_overrides`), the list in `Dispatch.lean`, their tests, and the generated `_select` functions. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01TKUFHFCSTvQuX83u32Ae29 --- .../src/dispatch/gcm.rs | 141 ------- .../src/dispatch/gcm.rs | 110 ------ .../src/dispatch/gcm.rs | 110 ------ .../src/dispatch/gcm.rs | 110 ------ .../src/dispatch/gcm.rs | 198 ---------- .../src/dispatch/gcm.rs | 360 ------------------ lean/VerifiedGarbage/Dispatch.lean | 17 - lean/VerifiedGarbage/TCB/Emit.lean | 19 +- lean/VerifiedGarbage/TCB/Rust.lean | 84 +--- lean/VerifiedGarbageTest/Dispatch.lean | 43 --- 10 files changed, 18 insertions(+), 1174 deletions(-) diff --git a/crates/verified-garbage-asm-aarch64/src/dispatch/gcm.rs b/crates/verified-garbage-asm-aarch64/src/dispatch/gcm.rs index 04e8aaeca12..ffc529d4668 100644 --- a/crates/verified-garbage-asm-aarch64/src/dispatch/gcm.rs +++ b/crates/verified-garbage-asm-aarch64/src/dispatch/gcm.rs @@ -207,21 +207,6 @@ pub unsafe fn vg_aes_gcm_open_to_auto(ctx: *const [u64; 32], rounds: usize, nonc unsafe { core::mem::transmute::<*mut (), Impl>(CHOSEN.load(core::sync::atomic::Ordering::Relaxed))(ctx, rounds, nonce, nonce_len, aad, aad_len, src, len, dst, dst_len, tag, tag_len) } } -/// The implementation of `vg_aes_gcm_open_to` that `vg_aes_gcm_open_to_auto` runs on this CPU, chosen as it chooses (`VG.Rust.selector`), so that it can be called without choosing again. -/// -/// # Safety -/// -/// Calling the function it returns carries exactly `vg_aes_gcm_open_to_auto`'s obligations (its `# Safety` section), which are those of each implementation it may return; calling this function has none. -#[allow(clippy::type_complexity)] -#[inline] -pub fn vg_aes_gcm_open_to_select() -> unsafe extern "C" fn(ctx: *const [u64; 32], rounds: usize, nonce: *const u8, nonce_len: usize, aad: *const u8, aad_len: usize, src: *const u8, len: usize, dst: *mut u8, dst_len: usize, tag: *const u8, tag_len: usize) -> u32 { - let cpu = verified_garbage_cpu::detected(); - if cpu.contains(crate::gcm::VG_AES_GCM_OPEN_TO_AES_FEATURES) { - return crate::gcm::vg_aes_gcm_open_to_aes; - } - crate::gcm::vg_aes_gcm_open_to -} - /// Absorbs additional data into an incremental AES-GCM encryption or decryption: with the key context `*ctx`, if the streaming state `*state` represents a message with `aad_len` bytes (modulo 2⁶⁴) of additional data and no text yet, it then represents that message with the `len` bytes at `data` appended to its additional data. All of the additional data comes before the text (§7.1 step 5): after text, the state represents no message. /// /// Contract: `VG.Spec.Gcm.streamAadContract`. Constant time: only the pointers, `aad_len` and `len` may affect timing, not the key context, the state or the data. @@ -269,21 +254,6 @@ pub unsafe fn vg_aes_gcm_stream_aad_auto(ctx: *const [u64; 32], state: *mut [u64 unsafe { core::mem::transmute::<*mut (), Impl>(CHOSEN.load(core::sync::atomic::Ordering::Relaxed))(ctx, state, aad_len, data, len) } } -/// The implementation of `vg_aes_gcm_stream_aad` that `vg_aes_gcm_stream_aad_auto` runs on this CPU, chosen as it chooses (`VG.Rust.selector`), so that it can be called without choosing again. -/// -/// # Safety -/// -/// Calling the function it returns carries exactly `vg_aes_gcm_stream_aad_auto`'s obligations (its `# Safety` section), which are those of each implementation it may return; calling this function has none. -#[allow(clippy::type_complexity)] -#[inline] -pub fn vg_aes_gcm_stream_aad_select() -> unsafe extern "C" fn(ctx: *const [u64; 32], state: *mut [u64; 10], aad_len: u64, data: *const u8, len: usize) { - let cpu = verified_garbage_cpu::detected(); - if cpu.contains(crate::gcm::VG_AES_GCM_STREAM_AAD_AES_FEATURES) { - return crate::gcm::vg_aes_gcm_stream_aad_aes; - } - crate::gcm::vg_aes_gcm_stream_aad -} - /// Starts an incremental AES-GCM encryption or decryption (NIST SP 800-38D §7): with the key context `*ctx` that `vg_aes_gcm_init` wrote, makes the streaming state `*state` represent the message with the IV the `nonce_len` bytes at `nonce`, and no additional data or text yet. Continue with `vg_aes_gcm_stream_aad`, then `vg_aes_gcm_stream_encrypt` or `vg_aes_gcm_stream_decrypt`, then `vg_aes_gcm_stream_finish` or `vg_aes_gcm_stream_verify`, with the same key context. /// /// The function checks no length: GCM requires a nonce of 1 to `2^61 - 1` bytes (§5.2.1.1), which the caller must check. @@ -333,21 +303,6 @@ pub unsafe fn vg_aes_gcm_stream_init_auto(ctx: *const [u64; 32], nonce: *const u unsafe { core::mem::transmute::<*mut (), Impl>(CHOSEN.load(core::sync::atomic::Ordering::Relaxed))(ctx, nonce, nonce_len, state) } } -/// The implementation of `vg_aes_gcm_stream_init` that `vg_aes_gcm_stream_init_auto` runs on this CPU, chosen as it chooses (`VG.Rust.selector`), so that it can be called without choosing again. -/// -/// # Safety -/// -/// Calling the function it returns carries exactly `vg_aes_gcm_stream_init_auto`'s obligations (its `# Safety` section), which are those of each implementation it may return; calling this function has none. -#[allow(clippy::type_complexity)] -#[inline] -pub fn vg_aes_gcm_stream_init_select() -> unsafe extern "C" fn(ctx: *const [u64; 32], nonce: *const u8, nonce_len: usize, state: *mut [u64; 10]) { - let cpu = verified_garbage_cpu::detected(); - if cpu.contains(crate::gcm::VG_AES_GCM_STREAM_INIT_AES_FEATURES) { - return crate::gcm::vg_aes_gcm_stream_init_aes; - } - crate::gcm::vg_aes_gcm_stream_init -} - /// AES-GCM authenticated encryption (NIST SP 800-38D §7.1, GCM-AE, with a 128-bit tag), out of place, of a plaintext in pieces: with the key context `*ctx` that `vg_aes_gcm_init` wrote for `rounds` rounds, encrypts the concatenation of the `src_count` slices that `src` lists (each an address and a length, in bytes), under the IV the `nonce_len` bytes at `nonce`, writes the ciphertext to the `len` bytes at `dst`, and writes the tag of the ciphertext and the `aad_len` bytes of additional data at `aad` to `*tag`: `vg_aes_gcm_seal` with the plaintext gathered from `src`. A shorter tag is the first bytes of this one. /// /// The function checks no length. GCM is secure only for a nonce of 1 to `2^61 - 1` bytes, at most `2^36 - 32` bytes of data and at most `2^61 - 1` bytes of additional data (§5.2.1.1), which the caller must ensure; and a nonce must never be used twice with the same key. @@ -497,21 +452,6 @@ pub unsafe fn vg_aes_gcm_stream_finish_auto(ctx: *const [u64; 32], rounds: usize unsafe { core::mem::transmute::<*mut (), Impl>(CHOSEN.load(core::sync::atomic::Ordering::Relaxed))(ctx, rounds, state, aad_len, text_len, tag) } } -/// The implementation of `vg_aes_gcm_stream_finish` that `vg_aes_gcm_stream_finish_auto` runs on this CPU, chosen as it chooses (`VG.Rust.selector`), so that it can be called without choosing again. -/// -/// # Safety -/// -/// Calling the function it returns carries exactly `vg_aes_gcm_stream_finish_auto`'s obligations (its `# Safety` section), which are those of each implementation it may return; calling this function has none. -#[allow(clippy::type_complexity)] -#[inline] -pub fn vg_aes_gcm_stream_finish_select() -> unsafe extern "C" fn(ctx: *const [u64; 32], rounds: usize, state: *mut [u64; 10], aad_len: u64, text_len: u64, tag: *mut [u8; 16]) { - let cpu = verified_garbage_cpu::detected(); - if cpu.contains(crate::gcm::VG_AES_GCM_STREAM_FINISH_AES_FEATURES) { - return crate::gcm::vg_aes_gcm_stream_finish_aes; - } - crate::gcm::vg_aes_gcm_stream_finish -} - /// Finishes an incremental AES-GCM decryption and checks its tag (NIST SP 800-38D §7.2 steps 6–8): with the key context `*ctx` that `vg_aes_gcm_init` wrote for `rounds` rounds and the received tag the `tag_len` bytes at `tag`, if the streaming state `*state` represents a message with `aad_len` bytes of additional data and exactly `text_len` bytes of ciphertext, returns 1 if `tag_len` is between 4 and 16 and the received tag is the first `tag_len` bytes of the message's 128-bit tag, and 0 otherwise. The tags are compared without a branch. /// /// Contract: `VG.Spec.Gcm.streamVerifyContract`. Constant time: only the pointers, `rounds`, `aad_len`, `text_len` and `tag_len` may affect timing, not the key context, the state or the tags. @@ -561,21 +501,6 @@ pub unsafe fn vg_aes_gcm_stream_verify_auto(ctx: *const [u64; 32], rounds: usize unsafe { core::mem::transmute::<*mut (), Impl>(CHOSEN.load(core::sync::atomic::Ordering::Relaxed))(ctx, rounds, state, aad_len, text_len, tag, tag_len) } } -/// The implementation of `vg_aes_gcm_stream_verify` that `vg_aes_gcm_stream_verify_auto` runs on this CPU, chosen as it chooses (`VG.Rust.selector`), so that it can be called without choosing again. -/// -/// # Safety -/// -/// Calling the function it returns carries exactly `vg_aes_gcm_stream_verify_auto`'s obligations (its `# Safety` section), which are those of each implementation it may return; calling this function has none. -#[allow(clippy::type_complexity)] -#[inline] -pub fn vg_aes_gcm_stream_verify_select() -> unsafe extern "C" fn(ctx: *const [u64; 32], rounds: usize, state: *mut [u64; 10], aad_len: u64, text_len: u64, tag: *const u8, tag_len: usize) -> u32 { - let cpu = verified_garbage_cpu::detected(); - if cpu.contains(crate::gcm::VG_AES_GCM_STREAM_VERIFY_AES_FEATURES) { - return crate::gcm::vg_aes_gcm_stream_verify_aes; - } - crate::gcm::vg_aes_gcm_stream_verify -} - /// Encrypts the next piece of the text of an incremental AES-GCM encryption (NIST SP 800-38D §7.1): with the key context `*ctx` that `vg_aes_gcm_init` wrote for `rounds` rounds, if the streaming state `*state` represents a message with `aad_len` bytes of additional data and the ciphertext of exactly `text_len` bytes of plaintext so far, encrypts the `len` bytes at `data` in place, as the continuation of that plaintext, and the state then represents the message with them appended. /// /// The function checks no length: GCM requires at most `2^36 - 32` bytes of text and at most `2^61 - 1` bytes of additional data (§5.2.1.1), which the caller must check. @@ -626,21 +551,6 @@ pub unsafe fn vg_aes_gcm_stream_encrypt_auto(ctx: *const [u64; 32], rounds: usiz unsafe { core::mem::transmute::<*mut (), Impl>(CHOSEN.load(core::sync::atomic::Ordering::Relaxed))(ctx, rounds, state, aad_len, text_len, data, len) } } -/// The implementation of `vg_aes_gcm_stream_encrypt` that `vg_aes_gcm_stream_encrypt_auto` runs on this CPU, chosen as it chooses (`VG.Rust.selector`), so that it can be called without choosing again. -/// -/// # Safety -/// -/// Calling the function it returns carries exactly `vg_aes_gcm_stream_encrypt_auto`'s obligations (its `# Safety` section), which are those of each implementation it may return; calling this function has none. -#[allow(clippy::type_complexity)] -#[inline] -pub fn vg_aes_gcm_stream_encrypt_select() -> unsafe extern "C" fn(ctx: *const [u64; 32], rounds: usize, state: *mut [u64; 10], aad_len: u64, text_len: u64, data: *mut u8, len: usize) { - let cpu = verified_garbage_cpu::detected(); - if cpu.contains(crate::gcm::VG_AES_GCM_STREAM_ENCRYPT_AES_FEATURES) { - return crate::gcm::vg_aes_gcm_stream_encrypt_aes; - } - crate::gcm::vg_aes_gcm_stream_encrypt -} - /// Decrypts the next piece of the text of an incremental AES-GCM decryption (NIST SP 800-38D §7.2): with the key context `*ctx` that `vg_aes_gcm_init` wrote for `rounds` rounds, if the streaming state `*state` represents a message with `aad_len` bytes of additional data and exactly `text_len` bytes of ciphertext so far, decrypts the `len` bytes of ciphertext at `data` in place, as the continuation of that ciphertext, and the state then represents the message with them appended. The plaintext is not authenticated until `vg_aes_gcm_stream_verify` has returned 1. /// /// The function checks no length: GCM requires at most `2^36 - 32` bytes of text and at most `2^61 - 1` bytes of additional data (§5.2.1.1), which the caller must check. @@ -691,21 +601,6 @@ pub unsafe fn vg_aes_gcm_stream_decrypt_auto(ctx: *const [u64; 32], rounds: usiz unsafe { core::mem::transmute::<*mut (), Impl>(CHOSEN.load(core::sync::atomic::Ordering::Relaxed))(ctx, rounds, state, aad_len, text_len, data, len) } } -/// The implementation of `vg_aes_gcm_stream_decrypt` that `vg_aes_gcm_stream_decrypt_auto` runs on this CPU, chosen as it chooses (`VG.Rust.selector`), so that it can be called without choosing again. -/// -/// # Safety -/// -/// Calling the function it returns carries exactly `vg_aes_gcm_stream_decrypt_auto`'s obligations (its `# Safety` section), which are those of each implementation it may return; calling this function has none. -#[allow(clippy::type_complexity)] -#[inline] -pub fn vg_aes_gcm_stream_decrypt_select() -> unsafe extern "C" fn(ctx: *const [u64; 32], rounds: usize, state: *mut [u64; 10], aad_len: u64, text_len: u64, data: *mut u8, len: usize) { - let cpu = verified_garbage_cpu::detected(); - if cpu.contains(crate::gcm::VG_AES_GCM_STREAM_DECRYPT_AES_FEATURES) { - return crate::gcm::vg_aes_gcm_stream_decrypt_aes; - } - crate::gcm::vg_aes_gcm_stream_decrypt -} - /// `vg_aes_gcm_seal` with the 8 prepared powers of the hash subkey of the key context at `*pw` (`VG.Spec.Gcm.Powers8Repr`), which it may read instead of computing them. Computes the same result as `vg_aes_gcm_seal`. The powers are secret, as the key context is: they may not affect timing; all other memory, aliasing and constant-time requirements are unchanged. Contract: `VG.Spec.Gcm.sealWithPowersContract`. /// /// It runs the first of these implementations that applies, which `VG.Dispatch.ranking` orders (`VG.Rust.Rank`): `vg_aes_gcm_seal_with_powers_aes_sha3` if the CPU supports its features (`VG_AES_GCM_SEAL_WITH_POWERS_AES_SHA3_FEATURES`); `vg_aes_gcm_seal_with_powers_aes` if the CPU supports its features (`VG_AES_GCM_SEAL_WITH_POWERS_AES_FEATURES`); or else `vg_aes_gcm_seal_with_powers`, which needs no CPU feature. It chooses on its first call, and calls the one it chose from then on without choosing again. Each has this documentation but for its stack (whose requirements here are the largest) and what it writes. @@ -759,24 +654,6 @@ pub unsafe fn vg_aes_gcm_seal_with_powers_auto(ctx: *const [u64; 32], rounds: us unsafe { core::mem::transmute::<*mut (), Impl>(CHOSEN.load(core::sync::atomic::Ordering::Relaxed))(ctx, rounds, nonce, nonce_len, aad, aad_len, data, len, tag, pw) } } -/// The implementation of `vg_aes_gcm_seal_with_powers` that `vg_aes_gcm_seal_with_powers_auto` runs on this CPU, chosen as it chooses (`VG.Rust.selector`), so that it can be called without choosing again. -/// -/// # Safety -/// -/// Calling the function it returns carries exactly `vg_aes_gcm_seal_with_powers_auto`'s obligations (its `# Safety` section), which are those of each implementation it may return; calling this function has none. -#[allow(clippy::type_complexity)] -#[inline] -pub fn vg_aes_gcm_seal_with_powers_select() -> unsafe extern "C" fn(ctx: *const [u64; 32], rounds: usize, nonce: *const u8, nonce_len: usize, aad: *const u8, aad_len: usize, data: *mut u8, len: usize, tag: *mut [u8; 16], pw: *const [u64; 16]) { - let cpu = verified_garbage_cpu::detected(); - if cpu.contains(crate::gcm::VG_AES_GCM_SEAL_WITH_POWERS_AES_SHA3_FEATURES) { - return crate::gcm::vg_aes_gcm_seal_with_powers_aes_sha3; - } - if cpu.contains(crate::gcm::VG_AES_GCM_SEAL_WITH_POWERS_AES_FEATURES) { - return crate::gcm::vg_aes_gcm_seal_with_powers_aes; - } - crate::gcm::vg_aes_gcm_seal_with_powers -} - /// `vg_aes_gcm_open` with the 8 prepared powers of the hash subkey of the key context at `*pw` (`VG.Spec.Gcm.Powers8Repr`), which it may read instead of computing them. Computes the same result as `vg_aes_gcm_open`. The powers are secret, as the key context is: they may not affect timing; all other memory, aliasing and constant-time requirements are unchanged. Contract: `VG.Spec.Gcm.openWithPowersContract`. /// /// It runs the first of these implementations that applies, which `VG.Dispatch.ranking` orders (`VG.Rust.Rank`): `vg_aes_gcm_open_with_powers_aes_sha3` if the CPU supports its features (`VG_AES_GCM_OPEN_WITH_POWERS_AES_SHA3_FEATURES`); `vg_aes_gcm_open_with_powers_aes` if the CPU supports its features (`VG_AES_GCM_OPEN_WITH_POWERS_AES_FEATURES`); or else `vg_aes_gcm_open_with_powers`, which needs no CPU feature. It chooses on its first call, and calls the one it chose from then on without choosing again. Each has this documentation but for its stack (whose requirements here are the largest) and what it writes. @@ -829,21 +706,3 @@ pub unsafe fn vg_aes_gcm_open_with_powers_auto(ctx: *const [u64; 32], rounds: us // either carries the caller's obligations, which are those of every implementation. unsafe { core::mem::transmute::<*mut (), Impl>(CHOSEN.load(core::sync::atomic::Ordering::Relaxed))(ctx, rounds, nonce, nonce_len, aad, aad_len, data, len, tag, tag_len, pw) } } - -/// The implementation of `vg_aes_gcm_open_with_powers` that `vg_aes_gcm_open_with_powers_auto` runs on this CPU, chosen as it chooses (`VG.Rust.selector`), so that it can be called without choosing again. -/// -/// # Safety -/// -/// Calling the function it returns carries exactly `vg_aes_gcm_open_with_powers_auto`'s obligations (its `# Safety` section), which are those of each implementation it may return; calling this function has none. -#[allow(clippy::type_complexity)] -#[inline] -pub fn vg_aes_gcm_open_with_powers_select() -> unsafe extern "C" fn(ctx: *const [u64; 32], rounds: usize, nonce: *const u8, nonce_len: usize, aad: *const u8, aad_len: usize, data: *mut u8, len: usize, tag: *const u8, tag_len: usize, pw: *const [u64; 16]) -> u32 { - let cpu = verified_garbage_cpu::detected(); - if cpu.contains(crate::gcm::VG_AES_GCM_OPEN_WITH_POWERS_AES_SHA3_FEATURES) { - return crate::gcm::vg_aes_gcm_open_with_powers_aes_sha3; - } - if cpu.contains(crate::gcm::VG_AES_GCM_OPEN_WITH_POWERS_AES_FEATURES) { - return crate::gcm::vg_aes_gcm_open_with_powers_aes; - } - crate::gcm::vg_aes_gcm_open_with_powers -} diff --git a/crates/verified-garbage-asm-arm/src/dispatch/gcm.rs b/crates/verified-garbage-asm-arm/src/dispatch/gcm.rs index 59e3dd0729a..cd63bc569a7 100644 --- a/crates/verified-garbage-asm-arm/src/dispatch/gcm.rs +++ b/crates/verified-garbage-asm-arm/src/dispatch/gcm.rs @@ -14,166 +14,56 @@ pub use crate::gcm::vg_aes_gcm_init as vg_aes_gcm_init_auto; #[allow(unused_imports)] pub use crate::gcm::vg_aes_gcm_seal as vg_aes_gcm_seal_auto; -/// The implementation of `vg_aes_gcm_seal` that `vg_aes_gcm_seal_auto` runs on this CPU, chosen as it chooses (`VG.Rust.selector`), so that it can be called without choosing again. -/// -/// # Safety -/// -/// Calling the function it returns carries exactly `vg_aes_gcm_seal_auto`'s obligations (its `# Safety` section), which are those of each implementation it may return; calling this function has none. -#[allow(clippy::type_complexity)] -#[inline] -pub fn vg_aes_gcm_seal_select() -> unsafe extern "C" fn(ctx: *const [u64; 32], rounds: usize, nonce: *const u8, nonce_len: usize, aad: *const u8, aad_len: usize, data: *mut u8, len: usize, tag: *mut [u8; 16]) { - crate::gcm::vg_aes_gcm_seal -} - /// `vg_aes_gcm_open`, the only implementation of it on this target, which needs no CPU feature /// (`VG.Rust.Group`): another name of it, so that the code calling it is the same on every /// target. #[allow(unused_imports)] pub use crate::gcm::vg_aes_gcm_open as vg_aes_gcm_open_auto; -/// The implementation of `vg_aes_gcm_open` that `vg_aes_gcm_open_auto` runs on this CPU, chosen as it chooses (`VG.Rust.selector`), so that it can be called without choosing again. -/// -/// # Safety -/// -/// Calling the function it returns carries exactly `vg_aes_gcm_open_auto`'s obligations (its `# Safety` section), which are those of each implementation it may return; calling this function has none. -#[allow(clippy::type_complexity)] -#[inline] -pub fn vg_aes_gcm_open_select() -> unsafe extern "C" fn(ctx: *const [u64; 32], rounds: usize, nonce: *const u8, nonce_len: usize, aad: *const u8, aad_len: usize, data: *mut u8, len: usize, tag: *const u8, tag_len: usize) -> u32 { - crate::gcm::vg_aes_gcm_open -} - /// `vg_aes_gcm_open_to`, the only implementation of it on this target, which needs no CPU feature /// (`VG.Rust.Group`): another name of it, so that the code calling it is the same on every /// target. #[allow(unused_imports)] pub use crate::gcm::vg_aes_gcm_open_to as vg_aes_gcm_open_to_auto; -/// The implementation of `vg_aes_gcm_open_to` that `vg_aes_gcm_open_to_auto` runs on this CPU, chosen as it chooses (`VG.Rust.selector`), so that it can be called without choosing again. -/// -/// # Safety -/// -/// Calling the function it returns carries exactly `vg_aes_gcm_open_to_auto`'s obligations (its `# Safety` section), which are those of each implementation it may return; calling this function has none. -#[allow(clippy::type_complexity)] -#[inline] -pub fn vg_aes_gcm_open_to_select() -> unsafe extern "C" fn(ctx: *const [u64; 32], rounds: usize, nonce: *const u8, nonce_len: usize, aad: *const u8, aad_len: usize, src: *const u8, len: usize, dst: *mut u8, dst_len: usize, tag: *const u8, tag_len: usize) -> u32 { - crate::gcm::vg_aes_gcm_open_to -} - /// `vg_aes_gcm_stream_aad`, the only implementation of it on this target, which needs no CPU feature /// (`VG.Rust.Group`): another name of it, so that the code calling it is the same on every /// target. #[allow(unused_imports)] pub use crate::gcm::vg_aes_gcm_stream_aad as vg_aes_gcm_stream_aad_auto; -/// The implementation of `vg_aes_gcm_stream_aad` that `vg_aes_gcm_stream_aad_auto` runs on this CPU, chosen as it chooses (`VG.Rust.selector`), so that it can be called without choosing again. -/// -/// # Safety -/// -/// Calling the function it returns carries exactly `vg_aes_gcm_stream_aad_auto`'s obligations (its `# Safety` section), which are those of each implementation it may return; calling this function has none. -#[allow(clippy::type_complexity)] -#[inline] -pub fn vg_aes_gcm_stream_aad_select() -> unsafe extern "C" fn(ctx: *const [u64; 32], state: *mut [u64; 10], aad_len: u64, data: *const u8, len: usize) { - crate::gcm::vg_aes_gcm_stream_aad -} - /// `vg_aes_gcm_stream_init`, the only implementation of it on this target, which needs no CPU feature /// (`VG.Rust.Group`): another name of it, so that the code calling it is the same on every /// target. #[allow(unused_imports)] pub use crate::gcm::vg_aes_gcm_stream_init as vg_aes_gcm_stream_init_auto; -/// The implementation of `vg_aes_gcm_stream_init` that `vg_aes_gcm_stream_init_auto` runs on this CPU, chosen as it chooses (`VG.Rust.selector`), so that it can be called without choosing again. -/// -/// # Safety -/// -/// Calling the function it returns carries exactly `vg_aes_gcm_stream_init_auto`'s obligations (its `# Safety` section), which are those of each implementation it may return; calling this function has none. -#[allow(clippy::type_complexity)] -#[inline] -pub fn vg_aes_gcm_stream_init_select() -> unsafe extern "C" fn(ctx: *const [u64; 32], nonce: *const u8, nonce_len: usize, state: *mut [u64; 10]) { - crate::gcm::vg_aes_gcm_stream_init -} - /// `vg_aes_gcm_seal_gather`, the only implementation of it on this target, which needs no CPU feature /// (`VG.Rust.Group`): another name of it, so that the code calling it is the same on every /// target. #[allow(unused_imports)] pub use crate::gcm::vg_aes_gcm_seal_gather as vg_aes_gcm_seal_gather_auto; -/// The implementation of `vg_aes_gcm_seal_gather` that `vg_aes_gcm_seal_gather_auto` runs on this CPU, chosen as it chooses (`VG.Rust.selector`), so that it can be called without choosing again. -/// -/// # Safety -/// -/// Calling the function it returns carries exactly `vg_aes_gcm_seal_gather_auto`'s obligations (its `# Safety` section), which are those of each implementation it may return; calling this function has none. -#[allow(clippy::type_complexity)] -#[inline] -pub fn vg_aes_gcm_seal_gather_select() -> unsafe extern "C" fn(ctx: *const [u64; 32], rounds: usize, nonce: *const u8, nonce_len: usize, aad: *const u8, aad_len: usize, src: *const [usize; 2], src_count: usize, dst: *mut u8, len: usize, tag: *mut [u8; 16]) { - crate::gcm::vg_aes_gcm_seal_gather -} - /// `vg_aes_gcm_stream_finish`, the only implementation of it on this target, which needs no CPU feature /// (`VG.Rust.Group`): another name of it, so that the code calling it is the same on every /// target. #[allow(unused_imports)] pub use crate::gcm::vg_aes_gcm_stream_finish as vg_aes_gcm_stream_finish_auto; -/// The implementation of `vg_aes_gcm_stream_finish` that `vg_aes_gcm_stream_finish_auto` runs on this CPU, chosen as it chooses (`VG.Rust.selector`), so that it can be called without choosing again. -/// -/// # Safety -/// -/// Calling the function it returns carries exactly `vg_aes_gcm_stream_finish_auto`'s obligations (its `# Safety` section), which are those of each implementation it may return; calling this function has none. -#[allow(clippy::type_complexity)] -#[inline] -pub fn vg_aes_gcm_stream_finish_select() -> unsafe extern "C" fn(ctx: *const [u64; 32], rounds: usize, state: *mut [u64; 10], aad_len: u64, text_len: u64, tag: *mut [u8; 16]) { - crate::gcm::vg_aes_gcm_stream_finish -} - /// `vg_aes_gcm_stream_verify`, the only implementation of it on this target, which needs no CPU feature /// (`VG.Rust.Group`): another name of it, so that the code calling it is the same on every /// target. #[allow(unused_imports)] pub use crate::gcm::vg_aes_gcm_stream_verify as vg_aes_gcm_stream_verify_auto; -/// The implementation of `vg_aes_gcm_stream_verify` that `vg_aes_gcm_stream_verify_auto` runs on this CPU, chosen as it chooses (`VG.Rust.selector`), so that it can be called without choosing again. -/// -/// # Safety -/// -/// Calling the function it returns carries exactly `vg_aes_gcm_stream_verify_auto`'s obligations (its `# Safety` section), which are those of each implementation it may return; calling this function has none. -#[allow(clippy::type_complexity)] -#[inline] -pub fn vg_aes_gcm_stream_verify_select() -> unsafe extern "C" fn(ctx: *const [u64; 32], rounds: usize, state: *mut [u64; 10], aad_len: u64, text_len: u64, tag: *const u8, tag_len: usize) -> u32 { - crate::gcm::vg_aes_gcm_stream_verify -} - /// `vg_aes_gcm_stream_encrypt`, the only implementation of it on this target, which needs no CPU feature /// (`VG.Rust.Group`): another name of it, so that the code calling it is the same on every /// target. #[allow(unused_imports)] pub use crate::gcm::vg_aes_gcm_stream_encrypt as vg_aes_gcm_stream_encrypt_auto; -/// The implementation of `vg_aes_gcm_stream_encrypt` that `vg_aes_gcm_stream_encrypt_auto` runs on this CPU, chosen as it chooses (`VG.Rust.selector`), so that it can be called without choosing again. -/// -/// # Safety -/// -/// Calling the function it returns carries exactly `vg_aes_gcm_stream_encrypt_auto`'s obligations (its `# Safety` section), which are those of each implementation it may return; calling this function has none. -#[allow(clippy::type_complexity)] -#[inline] -pub fn vg_aes_gcm_stream_encrypt_select() -> unsafe extern "C" fn(ctx: *const [u64; 32], rounds: usize, state: *mut [u64; 10], aad_len: u64, text_len: u64, data: *mut u8, len: usize) { - crate::gcm::vg_aes_gcm_stream_encrypt -} - /// `vg_aes_gcm_stream_decrypt`, the only implementation of it on this target, which needs no CPU feature /// (`VG.Rust.Group`): another name of it, so that the code calling it is the same on every /// target. #[allow(unused_imports)] pub use crate::gcm::vg_aes_gcm_stream_decrypt as vg_aes_gcm_stream_decrypt_auto; - -/// The implementation of `vg_aes_gcm_stream_decrypt` that `vg_aes_gcm_stream_decrypt_auto` runs on this CPU, chosen as it chooses (`VG.Rust.selector`), so that it can be called without choosing again. -/// -/// # Safety -/// -/// Calling the function it returns carries exactly `vg_aes_gcm_stream_decrypt_auto`'s obligations (its `# Safety` section), which are those of each implementation it may return; calling this function has none. -#[allow(clippy::type_complexity)] -#[inline] -pub fn vg_aes_gcm_stream_decrypt_select() -> unsafe extern "C" fn(ctx: *const [u64; 32], rounds: usize, state: *mut [u64; 10], aad_len: u64, text_len: u64, data: *mut u8, len: usize) { - crate::gcm::vg_aes_gcm_stream_decrypt -} diff --git a/crates/verified-garbage-asm-powerpc64le/src/dispatch/gcm.rs b/crates/verified-garbage-asm-powerpc64le/src/dispatch/gcm.rs index 020338251a6..8d205fc5aba 100644 --- a/crates/verified-garbage-asm-powerpc64le/src/dispatch/gcm.rs +++ b/crates/verified-garbage-asm-powerpc64le/src/dispatch/gcm.rs @@ -14,166 +14,56 @@ pub use crate::gcm::vg_aes_gcm_init as vg_aes_gcm_init_auto; #[allow(unused_imports)] pub use crate::gcm::vg_aes_gcm_seal as vg_aes_gcm_seal_auto; -/// The implementation of `vg_aes_gcm_seal` that `vg_aes_gcm_seal_auto` runs on this CPU, chosen as it chooses (`VG.Rust.selector`), so that it can be called without choosing again. -/// -/// # Safety -/// -/// Calling the function it returns carries exactly `vg_aes_gcm_seal_auto`'s obligations (its `# Safety` section), which are those of each implementation it may return; calling this function has none. -#[allow(clippy::type_complexity)] -#[inline] -pub fn vg_aes_gcm_seal_select() -> unsafe extern "C" fn(ctx: *const [u64; 32], rounds: usize, nonce: *const u8, nonce_len: usize, aad: *const u8, aad_len: usize, data: *mut u8, len: usize, tag: *mut [u8; 16]) { - crate::gcm::vg_aes_gcm_seal -} - /// `vg_aes_gcm_open`, the only implementation of it on this target, which needs no CPU feature /// (`VG.Rust.Group`): another name of it, so that the code calling it is the same on every /// target. #[allow(unused_imports)] pub use crate::gcm::vg_aes_gcm_open as vg_aes_gcm_open_auto; -/// The implementation of `vg_aes_gcm_open` that `vg_aes_gcm_open_auto` runs on this CPU, chosen as it chooses (`VG.Rust.selector`), so that it can be called without choosing again. -/// -/// # Safety -/// -/// Calling the function it returns carries exactly `vg_aes_gcm_open_auto`'s obligations (its `# Safety` section), which are those of each implementation it may return; calling this function has none. -#[allow(clippy::type_complexity)] -#[inline] -pub fn vg_aes_gcm_open_select() -> unsafe extern "C" fn(ctx: *const [u64; 32], rounds: usize, nonce: *const u8, nonce_len: usize, aad: *const u8, aad_len: usize, data: *mut u8, len: usize, tag: *const u8, tag_len: usize) -> u32 { - crate::gcm::vg_aes_gcm_open -} - /// `vg_aes_gcm_open_to`, the only implementation of it on this target, which needs no CPU feature /// (`VG.Rust.Group`): another name of it, so that the code calling it is the same on every /// target. #[allow(unused_imports)] pub use crate::gcm::vg_aes_gcm_open_to as vg_aes_gcm_open_to_auto; -/// The implementation of `vg_aes_gcm_open_to` that `vg_aes_gcm_open_to_auto` runs on this CPU, chosen as it chooses (`VG.Rust.selector`), so that it can be called without choosing again. -/// -/// # Safety -/// -/// Calling the function it returns carries exactly `vg_aes_gcm_open_to_auto`'s obligations (its `# Safety` section), which are those of each implementation it may return; calling this function has none. -#[allow(clippy::type_complexity)] -#[inline] -pub fn vg_aes_gcm_open_to_select() -> unsafe extern "C" fn(ctx: *const [u64; 32], rounds: usize, nonce: *const u8, nonce_len: usize, aad: *const u8, aad_len: usize, src: *const u8, len: usize, dst: *mut u8, dst_len: usize, tag: *const u8, tag_len: usize) -> u32 { - crate::gcm::vg_aes_gcm_open_to -} - /// `vg_aes_gcm_stream_aad`, the only implementation of it on this target, which needs no CPU feature /// (`VG.Rust.Group`): another name of it, so that the code calling it is the same on every /// target. #[allow(unused_imports)] pub use crate::gcm::vg_aes_gcm_stream_aad as vg_aes_gcm_stream_aad_auto; -/// The implementation of `vg_aes_gcm_stream_aad` that `vg_aes_gcm_stream_aad_auto` runs on this CPU, chosen as it chooses (`VG.Rust.selector`), so that it can be called without choosing again. -/// -/// # Safety -/// -/// Calling the function it returns carries exactly `vg_aes_gcm_stream_aad_auto`'s obligations (its `# Safety` section), which are those of each implementation it may return; calling this function has none. -#[allow(clippy::type_complexity)] -#[inline] -pub fn vg_aes_gcm_stream_aad_select() -> unsafe extern "C" fn(ctx: *const [u64; 32], state: *mut [u64; 10], aad_len: u64, data: *const u8, len: usize) { - crate::gcm::vg_aes_gcm_stream_aad -} - /// `vg_aes_gcm_stream_init`, the only implementation of it on this target, which needs no CPU feature /// (`VG.Rust.Group`): another name of it, so that the code calling it is the same on every /// target. #[allow(unused_imports)] pub use crate::gcm::vg_aes_gcm_stream_init as vg_aes_gcm_stream_init_auto; -/// The implementation of `vg_aes_gcm_stream_init` that `vg_aes_gcm_stream_init_auto` runs on this CPU, chosen as it chooses (`VG.Rust.selector`), so that it can be called without choosing again. -/// -/// # Safety -/// -/// Calling the function it returns carries exactly `vg_aes_gcm_stream_init_auto`'s obligations (its `# Safety` section), which are those of each implementation it may return; calling this function has none. -#[allow(clippy::type_complexity)] -#[inline] -pub fn vg_aes_gcm_stream_init_select() -> unsafe extern "C" fn(ctx: *const [u64; 32], nonce: *const u8, nonce_len: usize, state: *mut [u64; 10]) { - crate::gcm::vg_aes_gcm_stream_init -} - /// `vg_aes_gcm_seal_gather`, the only implementation of it on this target, which needs no CPU feature /// (`VG.Rust.Group`): another name of it, so that the code calling it is the same on every /// target. #[allow(unused_imports)] pub use crate::gcm::vg_aes_gcm_seal_gather as vg_aes_gcm_seal_gather_auto; -/// The implementation of `vg_aes_gcm_seal_gather` that `vg_aes_gcm_seal_gather_auto` runs on this CPU, chosen as it chooses (`VG.Rust.selector`), so that it can be called without choosing again. -/// -/// # Safety -/// -/// Calling the function it returns carries exactly `vg_aes_gcm_seal_gather_auto`'s obligations (its `# Safety` section), which are those of each implementation it may return; calling this function has none. -#[allow(clippy::type_complexity)] -#[inline] -pub fn vg_aes_gcm_seal_gather_select() -> unsafe extern "C" fn(ctx: *const [u64; 32], rounds: usize, nonce: *const u8, nonce_len: usize, aad: *const u8, aad_len: usize, src: *const [usize; 2], src_count: usize, dst: *mut u8, len: usize, tag: *mut [u8; 16]) { - crate::gcm::vg_aes_gcm_seal_gather -} - /// `vg_aes_gcm_stream_finish`, the only implementation of it on this target, which needs no CPU feature /// (`VG.Rust.Group`): another name of it, so that the code calling it is the same on every /// target. #[allow(unused_imports)] pub use crate::gcm::vg_aes_gcm_stream_finish as vg_aes_gcm_stream_finish_auto; -/// The implementation of `vg_aes_gcm_stream_finish` that `vg_aes_gcm_stream_finish_auto` runs on this CPU, chosen as it chooses (`VG.Rust.selector`), so that it can be called without choosing again. -/// -/// # Safety -/// -/// Calling the function it returns carries exactly `vg_aes_gcm_stream_finish_auto`'s obligations (its `# Safety` section), which are those of each implementation it may return; calling this function has none. -#[allow(clippy::type_complexity)] -#[inline] -pub fn vg_aes_gcm_stream_finish_select() -> unsafe extern "C" fn(ctx: *const [u64; 32], rounds: usize, state: *mut [u64; 10], aad_len: u64, text_len: u64, tag: *mut [u8; 16]) { - crate::gcm::vg_aes_gcm_stream_finish -} - /// `vg_aes_gcm_stream_verify`, the only implementation of it on this target, which needs no CPU feature /// (`VG.Rust.Group`): another name of it, so that the code calling it is the same on every /// target. #[allow(unused_imports)] pub use crate::gcm::vg_aes_gcm_stream_verify as vg_aes_gcm_stream_verify_auto; -/// The implementation of `vg_aes_gcm_stream_verify` that `vg_aes_gcm_stream_verify_auto` runs on this CPU, chosen as it chooses (`VG.Rust.selector`), so that it can be called without choosing again. -/// -/// # Safety -/// -/// Calling the function it returns carries exactly `vg_aes_gcm_stream_verify_auto`'s obligations (its `# Safety` section), which are those of each implementation it may return; calling this function has none. -#[allow(clippy::type_complexity)] -#[inline] -pub fn vg_aes_gcm_stream_verify_select() -> unsafe extern "C" fn(ctx: *const [u64; 32], rounds: usize, state: *mut [u64; 10], aad_len: u64, text_len: u64, tag: *const u8, tag_len: usize) -> u32 { - crate::gcm::vg_aes_gcm_stream_verify -} - /// `vg_aes_gcm_stream_encrypt`, the only implementation of it on this target, which needs no CPU feature /// (`VG.Rust.Group`): another name of it, so that the code calling it is the same on every /// target. #[allow(unused_imports)] pub use crate::gcm::vg_aes_gcm_stream_encrypt as vg_aes_gcm_stream_encrypt_auto; -/// The implementation of `vg_aes_gcm_stream_encrypt` that `vg_aes_gcm_stream_encrypt_auto` runs on this CPU, chosen as it chooses (`VG.Rust.selector`), so that it can be called without choosing again. -/// -/// # Safety -/// -/// Calling the function it returns carries exactly `vg_aes_gcm_stream_encrypt_auto`'s obligations (its `# Safety` section), which are those of each implementation it may return; calling this function has none. -#[allow(clippy::type_complexity)] -#[inline] -pub fn vg_aes_gcm_stream_encrypt_select() -> unsafe extern "C" fn(ctx: *const [u64; 32], rounds: usize, state: *mut [u64; 10], aad_len: u64, text_len: u64, data: *mut u8, len: usize) { - crate::gcm::vg_aes_gcm_stream_encrypt -} - /// `vg_aes_gcm_stream_decrypt`, the only implementation of it on this target, which needs no CPU feature /// (`VG.Rust.Group`): another name of it, so that the code calling it is the same on every /// target. #[allow(unused_imports)] pub use crate::gcm::vg_aes_gcm_stream_decrypt as vg_aes_gcm_stream_decrypt_auto; - -/// The implementation of `vg_aes_gcm_stream_decrypt` that `vg_aes_gcm_stream_decrypt_auto` runs on this CPU, chosen as it chooses (`VG.Rust.selector`), so that it can be called without choosing again. -/// -/// # Safety -/// -/// Calling the function it returns carries exactly `vg_aes_gcm_stream_decrypt_auto`'s obligations (its `# Safety` section), which are those of each implementation it may return; calling this function has none. -#[allow(clippy::type_complexity)] -#[inline] -pub fn vg_aes_gcm_stream_decrypt_select() -> unsafe extern "C" fn(ctx: *const [u64; 32], rounds: usize, state: *mut [u64; 10], aad_len: u64, text_len: u64, data: *mut u8, len: usize) { - crate::gcm::vg_aes_gcm_stream_decrypt -} diff --git a/crates/verified-garbage-asm-riscv64/src/dispatch/gcm.rs b/crates/verified-garbage-asm-riscv64/src/dispatch/gcm.rs index 4104b6c4e39..b063fdbb8e8 100644 --- a/crates/verified-garbage-asm-riscv64/src/dispatch/gcm.rs +++ b/crates/verified-garbage-asm-riscv64/src/dispatch/gcm.rs @@ -14,166 +14,56 @@ pub use crate::gcm::vg_aes_gcm_init as vg_aes_gcm_init_auto; #[allow(unused_imports)] pub use crate::gcm::vg_aes_gcm_seal as vg_aes_gcm_seal_auto; -/// The implementation of `vg_aes_gcm_seal` that `vg_aes_gcm_seal_auto` runs on this CPU, chosen as it chooses (`VG.Rust.selector`), so that it can be called without choosing again. -/// -/// # Safety -/// -/// Calling the function it returns carries exactly `vg_aes_gcm_seal_auto`'s obligations (its `# Safety` section), which are those of each implementation it may return; calling this function has none. -#[allow(clippy::type_complexity)] -#[inline] -pub fn vg_aes_gcm_seal_select() -> unsafe extern "C" fn(ctx: *const [u64; 32], rounds: usize, nonce: *const u8, nonce_len: usize, aad: *const u8, aad_len: usize, data: *mut u8, len: usize, tag: *mut [u8; 16]) { - crate::gcm::vg_aes_gcm_seal -} - /// `vg_aes_gcm_open`, the only implementation of it on this target, which needs no CPU feature /// (`VG.Rust.Group`): another name of it, so that the code calling it is the same on every /// target. #[allow(unused_imports)] pub use crate::gcm::vg_aes_gcm_open as vg_aes_gcm_open_auto; -/// The implementation of `vg_aes_gcm_open` that `vg_aes_gcm_open_auto` runs on this CPU, chosen as it chooses (`VG.Rust.selector`), so that it can be called without choosing again. -/// -/// # Safety -/// -/// Calling the function it returns carries exactly `vg_aes_gcm_open_auto`'s obligations (its `# Safety` section), which are those of each implementation it may return; calling this function has none. -#[allow(clippy::type_complexity)] -#[inline] -pub fn vg_aes_gcm_open_select() -> unsafe extern "C" fn(ctx: *const [u64; 32], rounds: usize, nonce: *const u8, nonce_len: usize, aad: *const u8, aad_len: usize, data: *mut u8, len: usize, tag: *const u8, tag_len: usize) -> u32 { - crate::gcm::vg_aes_gcm_open -} - /// `vg_aes_gcm_open_to`, the only implementation of it on this target, which needs no CPU feature /// (`VG.Rust.Group`): another name of it, so that the code calling it is the same on every /// target. #[allow(unused_imports)] pub use crate::gcm::vg_aes_gcm_open_to as vg_aes_gcm_open_to_auto; -/// The implementation of `vg_aes_gcm_open_to` that `vg_aes_gcm_open_to_auto` runs on this CPU, chosen as it chooses (`VG.Rust.selector`), so that it can be called without choosing again. -/// -/// # Safety -/// -/// Calling the function it returns carries exactly `vg_aes_gcm_open_to_auto`'s obligations (its `# Safety` section), which are those of each implementation it may return; calling this function has none. -#[allow(clippy::type_complexity)] -#[inline] -pub fn vg_aes_gcm_open_to_select() -> unsafe extern "C" fn(ctx: *const [u64; 32], rounds: usize, nonce: *const u8, nonce_len: usize, aad: *const u8, aad_len: usize, src: *const u8, len: usize, dst: *mut u8, dst_len: usize, tag: *const u8, tag_len: usize) -> u32 { - crate::gcm::vg_aes_gcm_open_to -} - /// `vg_aes_gcm_stream_aad`, the only implementation of it on this target, which needs no CPU feature /// (`VG.Rust.Group`): another name of it, so that the code calling it is the same on every /// target. #[allow(unused_imports)] pub use crate::gcm::vg_aes_gcm_stream_aad as vg_aes_gcm_stream_aad_auto; -/// The implementation of `vg_aes_gcm_stream_aad` that `vg_aes_gcm_stream_aad_auto` runs on this CPU, chosen as it chooses (`VG.Rust.selector`), so that it can be called without choosing again. -/// -/// # Safety -/// -/// Calling the function it returns carries exactly `vg_aes_gcm_stream_aad_auto`'s obligations (its `# Safety` section), which are those of each implementation it may return; calling this function has none. -#[allow(clippy::type_complexity)] -#[inline] -pub fn vg_aes_gcm_stream_aad_select() -> unsafe extern "C" fn(ctx: *const [u64; 32], state: *mut [u64; 10], aad_len: u64, data: *const u8, len: usize) { - crate::gcm::vg_aes_gcm_stream_aad -} - /// `vg_aes_gcm_stream_init`, the only implementation of it on this target, which needs no CPU feature /// (`VG.Rust.Group`): another name of it, so that the code calling it is the same on every /// target. #[allow(unused_imports)] pub use crate::gcm::vg_aes_gcm_stream_init as vg_aes_gcm_stream_init_auto; -/// The implementation of `vg_aes_gcm_stream_init` that `vg_aes_gcm_stream_init_auto` runs on this CPU, chosen as it chooses (`VG.Rust.selector`), so that it can be called without choosing again. -/// -/// # Safety -/// -/// Calling the function it returns carries exactly `vg_aes_gcm_stream_init_auto`'s obligations (its `# Safety` section), which are those of each implementation it may return; calling this function has none. -#[allow(clippy::type_complexity)] -#[inline] -pub fn vg_aes_gcm_stream_init_select() -> unsafe extern "C" fn(ctx: *const [u64; 32], nonce: *const u8, nonce_len: usize, state: *mut [u64; 10]) { - crate::gcm::vg_aes_gcm_stream_init -} - /// `vg_aes_gcm_seal_gather`, the only implementation of it on this target, which needs no CPU feature /// (`VG.Rust.Group`): another name of it, so that the code calling it is the same on every /// target. #[allow(unused_imports)] pub use crate::gcm::vg_aes_gcm_seal_gather as vg_aes_gcm_seal_gather_auto; -/// The implementation of `vg_aes_gcm_seal_gather` that `vg_aes_gcm_seal_gather_auto` runs on this CPU, chosen as it chooses (`VG.Rust.selector`), so that it can be called without choosing again. -/// -/// # Safety -/// -/// Calling the function it returns carries exactly `vg_aes_gcm_seal_gather_auto`'s obligations (its `# Safety` section), which are those of each implementation it may return; calling this function has none. -#[allow(clippy::type_complexity)] -#[inline] -pub fn vg_aes_gcm_seal_gather_select() -> unsafe extern "C" fn(ctx: *const [u64; 32], rounds: usize, nonce: *const u8, nonce_len: usize, aad: *const u8, aad_len: usize, src: *const [usize; 2], src_count: usize, dst: *mut u8, len: usize, tag: *mut [u8; 16]) { - crate::gcm::vg_aes_gcm_seal_gather -} - /// `vg_aes_gcm_stream_finish`, the only implementation of it on this target, which needs no CPU feature /// (`VG.Rust.Group`): another name of it, so that the code calling it is the same on every /// target. #[allow(unused_imports)] pub use crate::gcm::vg_aes_gcm_stream_finish as vg_aes_gcm_stream_finish_auto; -/// The implementation of `vg_aes_gcm_stream_finish` that `vg_aes_gcm_stream_finish_auto` runs on this CPU, chosen as it chooses (`VG.Rust.selector`), so that it can be called without choosing again. -/// -/// # Safety -/// -/// Calling the function it returns carries exactly `vg_aes_gcm_stream_finish_auto`'s obligations (its `# Safety` section), which are those of each implementation it may return; calling this function has none. -#[allow(clippy::type_complexity)] -#[inline] -pub fn vg_aes_gcm_stream_finish_select() -> unsafe extern "C" fn(ctx: *const [u64; 32], rounds: usize, state: *mut [u64; 10], aad_len: u64, text_len: u64, tag: *mut [u8; 16]) { - crate::gcm::vg_aes_gcm_stream_finish -} - /// `vg_aes_gcm_stream_verify`, the only implementation of it on this target, which needs no CPU feature /// (`VG.Rust.Group`): another name of it, so that the code calling it is the same on every /// target. #[allow(unused_imports)] pub use crate::gcm::vg_aes_gcm_stream_verify as vg_aes_gcm_stream_verify_auto; -/// The implementation of `vg_aes_gcm_stream_verify` that `vg_aes_gcm_stream_verify_auto` runs on this CPU, chosen as it chooses (`VG.Rust.selector`), so that it can be called without choosing again. -/// -/// # Safety -/// -/// Calling the function it returns carries exactly `vg_aes_gcm_stream_verify_auto`'s obligations (its `# Safety` section), which are those of each implementation it may return; calling this function has none. -#[allow(clippy::type_complexity)] -#[inline] -pub fn vg_aes_gcm_stream_verify_select() -> unsafe extern "C" fn(ctx: *const [u64; 32], rounds: usize, state: *mut [u64; 10], aad_len: u64, text_len: u64, tag: *const u8, tag_len: usize) -> u32 { - crate::gcm::vg_aes_gcm_stream_verify -} - /// `vg_aes_gcm_stream_encrypt`, the only implementation of it on this target, which needs no CPU feature /// (`VG.Rust.Group`): another name of it, so that the code calling it is the same on every /// target. #[allow(unused_imports)] pub use crate::gcm::vg_aes_gcm_stream_encrypt as vg_aes_gcm_stream_encrypt_auto; -/// The implementation of `vg_aes_gcm_stream_encrypt` that `vg_aes_gcm_stream_encrypt_auto` runs on this CPU, chosen as it chooses (`VG.Rust.selector`), so that it can be called without choosing again. -/// -/// # Safety -/// -/// Calling the function it returns carries exactly `vg_aes_gcm_stream_encrypt_auto`'s obligations (its `# Safety` section), which are those of each implementation it may return; calling this function has none. -#[allow(clippy::type_complexity)] -#[inline] -pub fn vg_aes_gcm_stream_encrypt_select() -> unsafe extern "C" fn(ctx: *const [u64; 32], rounds: usize, state: *mut [u64; 10], aad_len: u64, text_len: u64, data: *mut u8, len: usize) { - crate::gcm::vg_aes_gcm_stream_encrypt -} - /// `vg_aes_gcm_stream_decrypt`, the only implementation of it on this target, which needs no CPU feature /// (`VG.Rust.Group`): another name of it, so that the code calling it is the same on every /// target. #[allow(unused_imports)] pub use crate::gcm::vg_aes_gcm_stream_decrypt as vg_aes_gcm_stream_decrypt_auto; - -/// The implementation of `vg_aes_gcm_stream_decrypt` that `vg_aes_gcm_stream_decrypt_auto` runs on this CPU, chosen as it chooses (`VG.Rust.selector`), so that it can be called without choosing again. -/// -/// # Safety -/// -/// Calling the function it returns carries exactly `vg_aes_gcm_stream_decrypt_auto`'s obligations (its `# Safety` section), which are those of each implementation it may return; calling this function has none. -#[allow(clippy::type_complexity)] -#[inline] -pub fn vg_aes_gcm_stream_decrypt_select() -> unsafe extern "C" fn(ctx: *const [u64; 32], rounds: usize, state: *mut [u64; 10], aad_len: u64, text_len: u64, data: *mut u8, len: usize) { - crate::gcm::vg_aes_gcm_stream_decrypt -} diff --git a/crates/verified-garbage-asm-x86/src/dispatch/gcm.rs b/crates/verified-garbage-asm-x86/src/dispatch/gcm.rs index 319cb913941..32b906145d1 100644 --- a/crates/verified-garbage-asm-x86/src/dispatch/gcm.rs +++ b/crates/verified-garbage-asm-x86/src/dispatch/gcm.rs @@ -111,27 +111,6 @@ pub unsafe fn vg_aes_gcm_seal_auto(ctx: *const [u64; 32], rounds: usize, nonce: unsafe { core::mem::transmute::<*mut (), Impl>(CHOSEN.load(core::sync::atomic::Ordering::Relaxed))(ctx, rounds, nonce, nonce_len, aad, aad_len, data, len, tag) } } -/// The implementation of `vg_aes_gcm_seal` that `vg_aes_gcm_seal_auto` runs on this CPU, chosen as it chooses (`VG.Rust.selector`), so that it can be called without choosing again. -/// -/// # Safety -/// -/// Calling the function it returns carries exactly `vg_aes_gcm_seal_auto`'s obligations (its `# Safety` section), which are those of each implementation it may return; calling this function has none. -#[allow(clippy::type_complexity)] -#[inline] -pub fn vg_aes_gcm_seal_select() -> unsafe extern "C" fn(ctx: *const [u64; 32], rounds: usize, nonce: *const u8, nonce_len: usize, aad: *const u8, aad_len: usize, data: *mut u8, len: usize, tag: *mut [u8; 16]) { - let cpu = verified_garbage_cpu::detected(); - if cpu.contains(crate::gcm::VG_AES_GCM_SEAL_AESNI_PCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_seal_aesni_pclmul; - } - if cpu.contains(crate::gcm::VG_AES_GCM_SEAL_AESNI_FEATURES) { - return crate::gcm::vg_aes_gcm_seal_aesni; - } - if cpu.contains(crate::gcm::VG_AES_GCM_SEAL_PCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_seal_pclmul; - } - crate::gcm::vg_aes_gcm_seal -} - /// AES-GCM authenticated decryption (NIST SP 800-38D §7.2, GCM-AD): with the key context `*ctx` that `vg_aes_gcm_init` wrote for `rounds` rounds and the received tag the `tag_len` bytes at `tag`, returns 1 if `tag_len` is between 4 and 16 and the tag is the first `tag_len` bytes of that of the `len` bytes of ciphertext at `data` and the `aad_len` bytes of additional data at `aad`, under the IV the `nonce_len` bytes at `nonce`, having then decrypted the ciphertext in place; otherwise returns 0, and the bytes at `data` are unchanged. The tags are compared without a branch. /// /// The function checks no other length: GCM requires a nonce of 1 to `2^61 - 1` bytes, at most `2^36 - 32` bytes of ciphertext and at most `2^61 - 1` bytes of additional data (§5.2.1.1), which the caller must check. @@ -192,27 +171,6 @@ pub unsafe fn vg_aes_gcm_open_auto(ctx: *const [u64; 32], rounds: usize, nonce: unsafe { core::mem::transmute::<*mut (), Impl>(CHOSEN.load(core::sync::atomic::Ordering::Relaxed))(ctx, rounds, nonce, nonce_len, aad, aad_len, data, len, tag, tag_len) } } -/// The implementation of `vg_aes_gcm_open` that `vg_aes_gcm_open_auto` runs on this CPU, chosen as it chooses (`VG.Rust.selector`), so that it can be called without choosing again. -/// -/// # Safety -/// -/// Calling the function it returns carries exactly `vg_aes_gcm_open_auto`'s obligations (its `# Safety` section), which are those of each implementation it may return; calling this function has none. -#[allow(clippy::type_complexity)] -#[inline] -pub fn vg_aes_gcm_open_select() -> unsafe extern "C" fn(ctx: *const [u64; 32], rounds: usize, nonce: *const u8, nonce_len: usize, aad: *const u8, aad_len: usize, data: *mut u8, len: usize, tag: *const u8, tag_len: usize) -> u32 { - let cpu = verified_garbage_cpu::detected(); - if cpu.contains(crate::gcm::VG_AES_GCM_OPEN_AESNI_PCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_open_aesni_pclmul; - } - if cpu.contains(crate::gcm::VG_AES_GCM_OPEN_AESNI_FEATURES) { - return crate::gcm::vg_aes_gcm_open_aesni; - } - if cpu.contains(crate::gcm::VG_AES_GCM_OPEN_PCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_open_pclmul; - } - crate::gcm::vg_aes_gcm_open -} - /// AES-GCM authenticated decryption (NIST SP 800-38D §7.2, GCM-AD), out of place: with the key context `*ctx` that `vg_aes_gcm_init` wrote for `rounds` rounds and the received tag the `tag_len` bytes at `tag`, returns 1 if `tag_len` is between 4 and 16 and the tag is the first `tag_len` bytes of that of the `len` bytes of ciphertext at `src` and the `aad_len` bytes of additional data at `aad`, under the IV the `nonce_len` bytes at `nonce`, having then written the plaintext to the `dst_len = len` bytes at `dst`; otherwise returns 0, having written zeros to them: `vg_aes_gcm_open` with the ciphertext read from `src` and the plaintext written to `dst`. `src` is not written, and `dst` is a buffer of its own: it overlaps no other buffer, `src` included. The tags are compared without a branch. /// /// The function checks no other length: GCM requires a nonce of 1 to `2^61 - 1` bytes, at most `2^36 - 32` bytes of ciphertext and at most `2^61 - 1` bytes of additional data (§5.2.1.1), which the caller must check. @@ -275,27 +233,6 @@ pub unsafe fn vg_aes_gcm_open_to_auto(ctx: *const [u64; 32], rounds: usize, nonc unsafe { core::mem::transmute::<*mut (), Impl>(CHOSEN.load(core::sync::atomic::Ordering::Relaxed))(ctx, rounds, nonce, nonce_len, aad, aad_len, src, len, dst, dst_len, tag, tag_len) } } -/// The implementation of `vg_aes_gcm_open_to` that `vg_aes_gcm_open_to_auto` runs on this CPU, chosen as it chooses (`VG.Rust.selector`), so that it can be called without choosing again. -/// -/// # Safety -/// -/// Calling the function it returns carries exactly `vg_aes_gcm_open_to_auto`'s obligations (its `# Safety` section), which are those of each implementation it may return; calling this function has none. -#[allow(clippy::type_complexity)] -#[inline] -pub fn vg_aes_gcm_open_to_select() -> unsafe extern "C" fn(ctx: *const [u64; 32], rounds: usize, nonce: *const u8, nonce_len: usize, aad: *const u8, aad_len: usize, src: *const u8, len: usize, dst: *mut u8, dst_len: usize, tag: *const u8, tag_len: usize) -> u32 { - let cpu = verified_garbage_cpu::detected(); - if cpu.contains(crate::gcm::VG_AES_GCM_OPEN_TO_AESNI_PCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_open_to_aesni_pclmul; - } - if cpu.contains(crate::gcm::VG_AES_GCM_OPEN_TO_AESNI_FEATURES) { - return crate::gcm::vg_aes_gcm_open_to_aesni; - } - if cpu.contains(crate::gcm::VG_AES_GCM_OPEN_TO_PCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_open_to_pclmul; - } - crate::gcm::vg_aes_gcm_open_to -} - /// Absorbs additional data into an incremental AES-GCM encryption or decryption: with the key context `*ctx`, if the streaming state `*state` represents a message with `aad_len` bytes (modulo 2⁶⁴) of additional data and no text yet, it then represents that message with the `len` bytes at `data` appended to its additional data. All of the additional data comes before the text (§7.1 step 5): after text, the state represents no message. /// /// Contract: `VG.Spec.Gcm.streamAadContract`. Constant time: only the pointers, `aad_len` and `len` may affect timing, not the key context, the state or the data. @@ -345,21 +282,6 @@ pub unsafe fn vg_aes_gcm_stream_aad_auto(ctx: *const [u64; 32], state: *mut [u64 unsafe { core::mem::transmute::<*mut (), Impl>(CHOSEN.load(core::sync::atomic::Ordering::Relaxed))(ctx, state, aad_len, data, len) } } -/// The implementation of `vg_aes_gcm_stream_aad` that `vg_aes_gcm_stream_aad_auto` runs on this CPU, chosen as it chooses (`VG.Rust.selector`), so that it can be called without choosing again. -/// -/// # Safety -/// -/// Calling the function it returns carries exactly `vg_aes_gcm_stream_aad_auto`'s obligations (its `# Safety` section), which are those of each implementation it may return; calling this function has none. -#[allow(clippy::type_complexity)] -#[inline] -pub fn vg_aes_gcm_stream_aad_select() -> unsafe extern "C" fn(ctx: *const [u64; 32], state: *mut [u64; 10], aad_len: u64, data: *const u8, len: usize) { - let cpu = verified_garbage_cpu::detected(); - if cpu.contains(crate::gcm::VG_AES_GCM_STREAM_AAD_PCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_stream_aad_pclmul; - } - crate::gcm::vg_aes_gcm_stream_aad -} - /// AES-GCM authenticated encryption (NIST SP 800-38D §7.1, GCM-AE, with a 128-bit tag), out of place, of a plaintext in pieces: with the key context `*ctx` that `vg_aes_gcm_init` wrote for `rounds` rounds, encrypts the concatenation of the `src_count` slices that `src` lists (each an address and a length, in bytes), under the IV the `nonce_len` bytes at `nonce`, writes the ciphertext to the `len` bytes at `dst`, and writes the tag of the ciphertext and the `aad_len` bytes of additional data at `aad` to `*tag`: `vg_aes_gcm_seal` with the plaintext gathered from `src`. A shorter tag is the first bytes of this one. /// /// The function checks no length. GCM is secure only for a nonce of 1 to `2^61 - 1` bytes, at most `2^36 - 32` bytes of data and at most `2^61 - 1` bytes of additional data (§5.2.1.1), which the caller must ensure; and a nonce must never be used twice with the same key. @@ -422,27 +344,6 @@ pub unsafe fn vg_aes_gcm_seal_gather_auto(ctx: *const [u64; 32], rounds: usize, unsafe { core::mem::transmute::<*mut (), Impl>(CHOSEN.load(core::sync::atomic::Ordering::Relaxed))(ctx, rounds, nonce, nonce_len, aad, aad_len, src, src_count, dst, len, tag) } } -/// The implementation of `vg_aes_gcm_seal_gather` that `vg_aes_gcm_seal_gather_auto` runs on this CPU, chosen as it chooses (`VG.Rust.selector`), so that it can be called without choosing again. -/// -/// # Safety -/// -/// Calling the function it returns carries exactly `vg_aes_gcm_seal_gather_auto`'s obligations (its `# Safety` section), which are those of each implementation it may return; calling this function has none. -#[allow(clippy::type_complexity)] -#[inline] -pub fn vg_aes_gcm_seal_gather_select() -> unsafe extern "C" fn(ctx: *const [u64; 32], rounds: usize, nonce: *const u8, nonce_len: usize, aad: *const u8, aad_len: usize, src: *const [usize; 2], src_count: usize, dst: *mut u8, len: usize, tag: *mut [u8; 16]) { - let cpu = verified_garbage_cpu::detected(); - if cpu.contains(crate::gcm::VG_AES_GCM_SEAL_GATHER_AESNI_PCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_seal_gather_aesni_pclmul; - } - if cpu.contains(crate::gcm::VG_AES_GCM_SEAL_GATHER_AESNI_FEATURES) { - return crate::gcm::vg_aes_gcm_seal_gather_aesni; - } - if cpu.contains(crate::gcm::VG_AES_GCM_SEAL_GATHER_PCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_seal_gather_pclmul; - } - crate::gcm::vg_aes_gcm_seal_gather -} - /// Starts an incremental AES-GCM encryption or decryption (NIST SP 800-38D §7): with the key context `*ctx` that `vg_aes_gcm_init` wrote, makes the streaming state `*state` represent the message with the IV the `nonce_len` bytes at `nonce`, and no additional data or text yet. Continue with `vg_aes_gcm_stream_aad`, then `vg_aes_gcm_stream_encrypt` or `vg_aes_gcm_stream_decrypt`, then `vg_aes_gcm_stream_finish` or `vg_aes_gcm_stream_verify`, with the same key context. /// /// The function checks no length: GCM requires a nonce of 1 to `2^61 - 1` bytes (§5.2.1.1), which the caller must check. @@ -494,21 +395,6 @@ pub unsafe fn vg_aes_gcm_stream_init_auto(ctx: *const [u64; 32], nonce: *const u unsafe { core::mem::transmute::<*mut (), Impl>(CHOSEN.load(core::sync::atomic::Ordering::Relaxed))(ctx, nonce, nonce_len, state) } } -/// The implementation of `vg_aes_gcm_stream_init` that `vg_aes_gcm_stream_init_auto` runs on this CPU, chosen as it chooses (`VG.Rust.selector`), so that it can be called without choosing again. -/// -/// # Safety -/// -/// Calling the function it returns carries exactly `vg_aes_gcm_stream_init_auto`'s obligations (its `# Safety` section), which are those of each implementation it may return; calling this function has none. -#[allow(clippy::type_complexity)] -#[inline] -pub fn vg_aes_gcm_stream_init_select() -> unsafe extern "C" fn(ctx: *const [u64; 32], nonce: *const u8, nonce_len: usize, state: *mut [u64; 10]) { - let cpu = verified_garbage_cpu::detected(); - if cpu.contains(crate::gcm::VG_AES_GCM_STREAM_INIT_PCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_stream_init_pclmul; - } - crate::gcm::vg_aes_gcm_stream_init -} - /// Finishes an incremental AES-GCM encryption or decryption (NIST SP 800-38D §7.1 steps 5–6, §7.2 steps 6–7): with the key context `*ctx` that `vg_aes_gcm_init` wrote for `rounds` rounds, if the streaming state `*state` represents a message with `aad_len` bytes of additional data and exactly `text_len` bytes of ciphertext, writes its 128-bit tag to `*tag`. A shorter tag is the first bytes of this one; to check a received tag, use `vg_aes_gcm_stream_verify`. /// /// Contract: `VG.Spec.Gcm.streamFinishContract`. Constant time: only the pointers, `rounds`, `aad_len` and `text_len` may affect timing, not the key context or the state. @@ -566,27 +452,6 @@ pub unsafe fn vg_aes_gcm_stream_finish_auto(ctx: *const [u64; 32], rounds: usize unsafe { core::mem::transmute::<*mut (), Impl>(CHOSEN.load(core::sync::atomic::Ordering::Relaxed))(ctx, rounds, state, aad_len, text_len, tag) } } -/// The implementation of `vg_aes_gcm_stream_finish` that `vg_aes_gcm_stream_finish_auto` runs on this CPU, chosen as it chooses (`VG.Rust.selector`), so that it can be called without choosing again. -/// -/// # Safety -/// -/// Calling the function it returns carries exactly `vg_aes_gcm_stream_finish_auto`'s obligations (its `# Safety` section), which are those of each implementation it may return; calling this function has none. -#[allow(clippy::type_complexity)] -#[inline] -pub fn vg_aes_gcm_stream_finish_select() -> unsafe extern "C" fn(ctx: *const [u64; 32], rounds: usize, state: *mut [u64; 10], aad_len: u64, text_len: u64, tag: *mut [u8; 16]) { - let cpu = verified_garbage_cpu::detected(); - if cpu.contains(crate::gcm::VG_AES_GCM_STREAM_FINISH_AESNI_PCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_stream_finish_aesni_pclmul; - } - if cpu.contains(crate::gcm::VG_AES_GCM_STREAM_FINISH_AESNI_FEATURES) { - return crate::gcm::vg_aes_gcm_stream_finish_aesni; - } - if cpu.contains(crate::gcm::VG_AES_GCM_STREAM_FINISH_PCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_stream_finish_pclmul; - } - crate::gcm::vg_aes_gcm_stream_finish -} - /// Finishes an incremental AES-GCM decryption and checks its tag (NIST SP 800-38D §7.2 steps 6–8): with the key context `*ctx` that `vg_aes_gcm_init` wrote for `rounds` rounds and the received tag the `tag_len` bytes at `tag`, if the streaming state `*state` represents a message with `aad_len` bytes of additional data and exactly `text_len` bytes of ciphertext, returns 1 if `tag_len` is between 4 and 16 and the received tag is the first `tag_len` bytes of the message's 128-bit tag, and 0 otherwise. The tags are compared without a branch. /// /// Contract: `VG.Spec.Gcm.streamVerifyContract`. Constant time: only the pointers, `rounds`, `aad_len`, `text_len` and `tag_len` may affect timing, not the key context, the state or the tags. @@ -644,27 +509,6 @@ pub unsafe fn vg_aes_gcm_stream_verify_auto(ctx: *const [u64; 32], rounds: usize unsafe { core::mem::transmute::<*mut (), Impl>(CHOSEN.load(core::sync::atomic::Ordering::Relaxed))(ctx, rounds, state, aad_len, text_len, tag, tag_len) } } -/// The implementation of `vg_aes_gcm_stream_verify` that `vg_aes_gcm_stream_verify_auto` runs on this CPU, chosen as it chooses (`VG.Rust.selector`), so that it can be called without choosing again. -/// -/// # Safety -/// -/// Calling the function it returns carries exactly `vg_aes_gcm_stream_verify_auto`'s obligations (its `# Safety` section), which are those of each implementation it may return; calling this function has none. -#[allow(clippy::type_complexity)] -#[inline] -pub fn vg_aes_gcm_stream_verify_select() -> unsafe extern "C" fn(ctx: *const [u64; 32], rounds: usize, state: *mut [u64; 10], aad_len: u64, text_len: u64, tag: *const u8, tag_len: usize) -> u32 { - let cpu = verified_garbage_cpu::detected(); - if cpu.contains(crate::gcm::VG_AES_GCM_STREAM_VERIFY_AESNI_PCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_stream_verify_aesni_pclmul; - } - if cpu.contains(crate::gcm::VG_AES_GCM_STREAM_VERIFY_AESNI_FEATURES) { - return crate::gcm::vg_aes_gcm_stream_verify_aesni; - } - if cpu.contains(crate::gcm::VG_AES_GCM_STREAM_VERIFY_PCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_stream_verify_pclmul; - } - crate::gcm::vg_aes_gcm_stream_verify -} - /// Encrypts the next piece of the text of an incremental AES-GCM encryption (NIST SP 800-38D §7.1): with the key context `*ctx` that `vg_aes_gcm_init` wrote for `rounds` rounds, if the streaming state `*state` represents a message with `aad_len` bytes of additional data and the ciphertext of exactly `text_len` bytes of plaintext so far, encrypts the `len` bytes at `data` in place, as the continuation of that plaintext, and the state then represents the message with them appended. /// /// The function checks no length: GCM requires at most `2^36 - 32` bytes of text and at most `2^61 - 1` bytes of additional data (§5.2.1.1), which the caller must check. @@ -723,27 +567,6 @@ pub unsafe fn vg_aes_gcm_stream_encrypt_auto(ctx: *const [u64; 32], rounds: usiz unsafe { core::mem::transmute::<*mut (), Impl>(CHOSEN.load(core::sync::atomic::Ordering::Relaxed))(ctx, rounds, state, aad_len, text_len, data, len) } } -/// The implementation of `vg_aes_gcm_stream_encrypt` that `vg_aes_gcm_stream_encrypt_auto` runs on this CPU, chosen as it chooses (`VG.Rust.selector`), so that it can be called without choosing again. -/// -/// # Safety -/// -/// Calling the function it returns carries exactly `vg_aes_gcm_stream_encrypt_auto`'s obligations (its `# Safety` section), which are those of each implementation it may return; calling this function has none. -#[allow(clippy::type_complexity)] -#[inline] -pub fn vg_aes_gcm_stream_encrypt_select() -> unsafe extern "C" fn(ctx: *const [u64; 32], rounds: usize, state: *mut [u64; 10], aad_len: u64, text_len: u64, data: *mut u8, len: usize) { - let cpu = verified_garbage_cpu::detected(); - if cpu.contains(crate::gcm::VG_AES_GCM_STREAM_ENCRYPT_AESNI_PCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_stream_encrypt_aesni_pclmul; - } - if cpu.contains(crate::gcm::VG_AES_GCM_STREAM_ENCRYPT_AESNI_FEATURES) { - return crate::gcm::vg_aes_gcm_stream_encrypt_aesni; - } - if cpu.contains(crate::gcm::VG_AES_GCM_STREAM_ENCRYPT_PCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_stream_encrypt_pclmul; - } - crate::gcm::vg_aes_gcm_stream_encrypt -} - /// Decrypts the next piece of the text of an incremental AES-GCM decryption (NIST SP 800-38D §7.2): with the key context `*ctx` that `vg_aes_gcm_init` wrote for `rounds` rounds, if the streaming state `*state` represents a message with `aad_len` bytes of additional data and exactly `text_len` bytes of ciphertext so far, decrypts the `len` bytes of ciphertext at `data` in place, as the continuation of that ciphertext, and the state then represents the message with them appended. The plaintext is not authenticated until `vg_aes_gcm_stream_verify` has returned 1. /// /// The function checks no length: GCM requires at most `2^36 - 32` bytes of text and at most `2^61 - 1` bytes of additional data (§5.2.1.1), which the caller must check. @@ -801,24 +624,3 @@ pub unsafe fn vg_aes_gcm_stream_decrypt_auto(ctx: *const [u64; 32], rounds: usiz // either carries the caller's obligations, which are those of every implementation. unsafe { core::mem::transmute::<*mut (), Impl>(CHOSEN.load(core::sync::atomic::Ordering::Relaxed))(ctx, rounds, state, aad_len, text_len, data, len) } } - -/// The implementation of `vg_aes_gcm_stream_decrypt` that `vg_aes_gcm_stream_decrypt_auto` runs on this CPU, chosen as it chooses (`VG.Rust.selector`), so that it can be called without choosing again. -/// -/// # Safety -/// -/// Calling the function it returns carries exactly `vg_aes_gcm_stream_decrypt_auto`'s obligations (its `# Safety` section), which are those of each implementation it may return; calling this function has none. -#[allow(clippy::type_complexity)] -#[inline] -pub fn vg_aes_gcm_stream_decrypt_select() -> unsafe extern "C" fn(ctx: *const [u64; 32], rounds: usize, state: *mut [u64; 10], aad_len: u64, text_len: u64, data: *mut u8, len: usize) { - let cpu = verified_garbage_cpu::detected(); - if cpu.contains(crate::gcm::VG_AES_GCM_STREAM_DECRYPT_AESNI_PCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_stream_decrypt_aesni_pclmul; - } - if cpu.contains(crate::gcm::VG_AES_GCM_STREAM_DECRYPT_AESNI_FEATURES) { - return crate::gcm::vg_aes_gcm_stream_decrypt_aesni; - } - if cpu.contains(crate::gcm::VG_AES_GCM_STREAM_DECRYPT_PCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_stream_decrypt_pclmul; - } - crate::gcm::vg_aes_gcm_stream_decrypt -} diff --git a/crates/verified-garbage-asm-x86_64/src/dispatch/gcm.rs b/crates/verified-garbage-asm-x86_64/src/dispatch/gcm.rs index 70704591c4d..a9be9b43e1f 100644 --- a/crates/verified-garbage-asm-x86_64/src/dispatch/gcm.rs +++ b/crates/verified-garbage-asm-x86_64/src/dispatch/gcm.rs @@ -150,24 +150,6 @@ pub unsafe fn vg_aes_gcm_stream_aad_auto(ctx: *const [u64; 32], state: *mut [u64 unsafe { core::mem::transmute::<*mut (), Impl>(CHOSEN.load(core::sync::atomic::Ordering::Relaxed))(ctx, state, aad_len, data, len) } } -/// The implementation of `vg_aes_gcm_stream_aad` that `vg_aes_gcm_stream_aad_auto` runs on this CPU, chosen as it chooses (`VG.Rust.selector`), so that it can be called without choosing again. -/// -/// # Safety -/// -/// Calling the function it returns carries exactly `vg_aes_gcm_stream_aad_auto`'s obligations (its `# Safety` section), which are those of each implementation it may return; calling this function has none. -#[allow(clippy::type_complexity)] -#[inline] -pub fn vg_aes_gcm_stream_aad_select() -> unsafe extern "sysv64" fn(ctx: *const [u64; 32], state: *mut [u64; 10], aad_len: u64, data: *const u8, len: usize) { - let cpu = verified_garbage_cpu::detected(); - if cpu.contains(crate::gcm::VG_AES_GCM_STREAM_AAD_VPCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_stream_aad_vpclmul; - } - if cpu.contains(crate::gcm::VG_AES_GCM_STREAM_AAD_PCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_stream_aad_pclmul; - } - crate::gcm::vg_aes_gcm_stream_aad -} - /// Starts an incremental AES-GCM encryption or decryption (NIST SP 800-38D §7): with the key context `*ctx` that `vg_aes_gcm_init` wrote, makes the streaming state `*state` represent the message with the IV the `nonce_len` bytes at `nonce`, and no additional data or text yet. Continue with `vg_aes_gcm_stream_aad`, then `vg_aes_gcm_stream_encrypt` or `vg_aes_gcm_stream_decrypt`, then `vg_aes_gcm_stream_finish` or `vg_aes_gcm_stream_verify`, with the same key context. /// /// The function checks no length: GCM requires a nonce of 1 to `2^61 - 1` bytes (§5.2.1.1), which the caller must check. @@ -220,24 +202,6 @@ pub unsafe fn vg_aes_gcm_stream_init_auto(ctx: *const [u64; 32], nonce: *const u unsafe { core::mem::transmute::<*mut (), Impl>(CHOSEN.load(core::sync::atomic::Ordering::Relaxed))(ctx, nonce, nonce_len, state) } } -/// The implementation of `vg_aes_gcm_stream_init` that `vg_aes_gcm_stream_init_auto` runs on this CPU, chosen as it chooses (`VG.Rust.selector`), so that it can be called without choosing again. -/// -/// # Safety -/// -/// Calling the function it returns carries exactly `vg_aes_gcm_stream_init_auto`'s obligations (its `# Safety` section), which are those of each implementation it may return; calling this function has none. -#[allow(clippy::type_complexity)] -#[inline] -pub fn vg_aes_gcm_stream_init_select() -> unsafe extern "sysv64" fn(ctx: *const [u64; 32], nonce: *const u8, nonce_len: usize, state: *mut [u64; 10]) { - let cpu = verified_garbage_cpu::detected(); - if cpu.contains(crate::gcm::VG_AES_GCM_STREAM_INIT_VPCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_stream_init_vpclmul; - } - if cpu.contains(crate::gcm::VG_AES_GCM_STREAM_INIT_PCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_stream_init_pclmul; - } - crate::gcm::vg_aes_gcm_stream_init -} - /// Wipes the 1032-byte `*ctx`, a prepared key context of `vg_aes_gcm_prepare`: sets to zero the key context and the powers its count (the 64-bit word at byte 1024) says are present: its first 1024 bytes if the count is at least 48, 512 if it is at least 16, and 256 otherwise (the bytes after them were not written). Contract: `VG.Spec.Gcm.wipePreparedContract`. Constant time: only the pointer and which of those the count is may affect timing, not the bytes wiped. /// /// It runs the first of these implementations that applies, which `VG.Dispatch.ranking` orders (`VG.Rust.Rank`): `vg_aes_gcm_wipe_prepared_avx` if the CPU supports its features (`VG_AES_GCM_WIPE_PREPARED_AVX_FEATURES`); or else `vg_aes_gcm_wipe_prepared`, which needs no CPU feature. It chooses on its first call, and calls the one it chose from then on without choosing again. Each has this documentation but for its stack (whose requirements here are the largest) and what it writes. @@ -350,42 +314,6 @@ pub unsafe fn vg_aes_gcm_stream_finish_auto(ctx: *const [u64; 32], rounds: usize unsafe { core::mem::transmute::<*mut (), Impl>(CHOSEN.load(core::sync::atomic::Ordering::Relaxed))(ctx, rounds, state, aad_len, text_len, tag) } } -/// The implementation of `vg_aes_gcm_stream_finish` that `vg_aes_gcm_stream_finish_auto` runs on this CPU, chosen as it chooses (`VG.Rust.selector`), so that it can be called without choosing again. -/// -/// # Safety -/// -/// Calling the function it returns carries exactly `vg_aes_gcm_stream_finish_auto`'s obligations (its `# Safety` section), which are those of each implementation it may return; calling this function has none. -#[allow(clippy::type_complexity)] -#[inline] -pub fn vg_aes_gcm_stream_finish_select() -> unsafe extern "sysv64" fn(ctx: *const [u64; 32], rounds: usize, state: *mut [u64; 10], aad_len: u64, text_len: u64, tag: *mut [u8; 16]) { - let cpu = verified_garbage_cpu::detected(); - if cpu.contains(crate::gcm::VG_AES_GCM_STREAM_FINISH_VAES_VPCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_stream_finish_vaes_vpclmul; - } - if cpu.contains(crate::gcm::VG_AES_GCM_STREAM_FINISH_VAES_PCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_stream_finish_vaes_pclmul; - } - if cpu.contains(crate::gcm::VG_AES_GCM_STREAM_FINISH_AESNI_VPCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_stream_finish_aesni_vpclmul; - } - if cpu.contains(crate::gcm::VG_AES_GCM_STREAM_FINISH_AESNI_PCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_stream_finish_aesni_pclmul; - } - if cpu.contains(crate::gcm::VG_AES_GCM_STREAM_FINISH_VAES_FEATURES) { - return crate::gcm::vg_aes_gcm_stream_finish_vaes; - } - if cpu.contains(crate::gcm::VG_AES_GCM_STREAM_FINISH_AESNI_FEATURES) { - return crate::gcm::vg_aes_gcm_stream_finish_aesni; - } - if cpu.contains(crate::gcm::VG_AES_GCM_STREAM_FINISH_VPCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_stream_finish_vpclmul; - } - if cpu.contains(crate::gcm::VG_AES_GCM_STREAM_FINISH_PCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_stream_finish_pclmul; - } - crate::gcm::vg_aes_gcm_stream_finish -} - /// Finishes an incremental AES-GCM decryption and checks its tag (NIST SP 800-38D §7.2 steps 6–8): with the key context `*ctx` that `vg_aes_gcm_init` wrote for `rounds` rounds and the received tag the `tag_len` bytes at `tag`, if the streaming state `*state` represents a message with `aad_len` bytes of additional data and exactly `text_len` bytes of ciphertext, returns 1 if `tag_len` is between 4 and 16 and the received tag is the first `tag_len` bytes of the message's 128-bit tag, and 0 otherwise. The tags are compared without a branch. /// /// Contract: `VG.Spec.Gcm.streamVerifyContract`. Constant time: only the pointers, `rounds`, `aad_len`, `text_len` and `tag_len` may affect timing, not the key context, the state or the tags. @@ -456,42 +384,6 @@ pub unsafe fn vg_aes_gcm_stream_verify_auto(ctx: *const [u64; 32], rounds: usize unsafe { core::mem::transmute::<*mut (), Impl>(CHOSEN.load(core::sync::atomic::Ordering::Relaxed))(ctx, rounds, state, aad_len, text_len, tag, tag_len) } } -/// The implementation of `vg_aes_gcm_stream_verify` that `vg_aes_gcm_stream_verify_auto` runs on this CPU, chosen as it chooses (`VG.Rust.selector`), so that it can be called without choosing again. -/// -/// # Safety -/// -/// Calling the function it returns carries exactly `vg_aes_gcm_stream_verify_auto`'s obligations (its `# Safety` section), which are those of each implementation it may return; calling this function has none. -#[allow(clippy::type_complexity)] -#[inline] -pub fn vg_aes_gcm_stream_verify_select() -> unsafe extern "sysv64" fn(ctx: *const [u64; 32], rounds: usize, state: *mut [u64; 10], aad_len: u64, text_len: u64, tag: *const u8, tag_len: usize) -> u32 { - let cpu = verified_garbage_cpu::detected(); - if cpu.contains(crate::gcm::VG_AES_GCM_STREAM_VERIFY_VAES_VPCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_stream_verify_vaes_vpclmul; - } - if cpu.contains(crate::gcm::VG_AES_GCM_STREAM_VERIFY_VAES_PCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_stream_verify_vaes_pclmul; - } - if cpu.contains(crate::gcm::VG_AES_GCM_STREAM_VERIFY_AESNI_VPCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_stream_verify_aesni_vpclmul; - } - if cpu.contains(crate::gcm::VG_AES_GCM_STREAM_VERIFY_AESNI_PCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_stream_verify_aesni_pclmul; - } - if cpu.contains(crate::gcm::VG_AES_GCM_STREAM_VERIFY_VAES_FEATURES) { - return crate::gcm::vg_aes_gcm_stream_verify_vaes; - } - if cpu.contains(crate::gcm::VG_AES_GCM_STREAM_VERIFY_AESNI_FEATURES) { - return crate::gcm::vg_aes_gcm_stream_verify_aesni; - } - if cpu.contains(crate::gcm::VG_AES_GCM_STREAM_VERIFY_VPCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_stream_verify_vpclmul; - } - if cpu.contains(crate::gcm::VG_AES_GCM_STREAM_VERIFY_PCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_stream_verify_pclmul; - } - crate::gcm::vg_aes_gcm_stream_verify -} - /// `vg_aes_gcm_seal` with a 1032-byte context from `vg_aes_gcm_prepare`. Computes the same result, using the AES key schedule and hash subkey in its first 256 bytes, and may read the prepared powers its count says are present. The powers remain secret; how many are present may affect timing; all other memory, aliasing and constant-time requirements are unchanged. Contract: `VG.Spec.Gcm.sealPreparedContract`. /// /// It runs the first of these implementations that applies, which `VG.Dispatch.ranking` orders (`VG.Rust.Rank`): `vg_aes_gcm_seal_prepared_vaes_vpclmul_avx512` if the CPU supports its features (`VG_AES_GCM_SEAL_PREPARED_VAES_VPCLMUL_AVX512_FEATURES`); `vg_aes_gcm_seal_prepared_vaes_vpclmul` if the CPU supports its features (`VG_AES_GCM_SEAL_PREPARED_VAES_VPCLMUL_FEATURES`); `vg_aes_gcm_seal_prepared_vaes_pclmul` if the CPU supports its features (`VG_AES_GCM_SEAL_PREPARED_VAES_PCLMUL_FEATURES`); `vg_aes_gcm_seal_prepared_aesni_vpclmul` if the CPU supports its features (`VG_AES_GCM_SEAL_PREPARED_AESNI_VPCLMUL_FEATURES`); `vg_aes_gcm_seal_prepared_aesni_pclmul_avx` if the CPU supports its features (`VG_AES_GCM_SEAL_PREPARED_AESNI_PCLMUL_AVX_FEATURES`); `vg_aes_gcm_seal_prepared_aesni_pclmul` if the CPU supports its features (`VG_AES_GCM_SEAL_PREPARED_AESNI_PCLMUL_FEATURES`); `vg_aes_gcm_seal_prepared_vaes` if the CPU supports its features (`VG_AES_GCM_SEAL_PREPARED_VAES_FEATURES`); `vg_aes_gcm_seal_prepared_aesni` if the CPU supports its features (`VG_AES_GCM_SEAL_PREPARED_AESNI_FEATURES`); `vg_aes_gcm_seal_prepared_vpclmul` if the CPU supports its features (`VG_AES_GCM_SEAL_PREPARED_VPCLMUL_FEATURES`); `vg_aes_gcm_seal_prepared_pclmul` if the CPU supports its features (`VG_AES_GCM_SEAL_PREPARED_PCLMUL_FEATURES`); or else `vg_aes_gcm_seal_prepared`, which needs no CPU feature. It chooses on its first call, and calls the one it chose from then on without choosing again. Each has this documentation but for its stack (whose requirements here are the largest) and what it writes. @@ -568,48 +460,6 @@ pub unsafe fn vg_aes_gcm_seal_prepared_auto(ctx: *const [u64; 129], rounds: usiz unsafe { core::mem::transmute::<*mut (), Impl>(CHOSEN.load(core::sync::atomic::Ordering::Relaxed))(ctx, rounds, nonce, nonce_len, aad, aad_len, data, len, tag) } } -/// The implementation of `vg_aes_gcm_seal_prepared` that `vg_aes_gcm_seal_prepared_auto` runs on this CPU, chosen as it chooses (`VG.Rust.selector`), so that it can be called without choosing again. -/// -/// # Safety -/// -/// Calling the function it returns carries exactly `vg_aes_gcm_seal_prepared_auto`'s obligations (its `# Safety` section), which are those of each implementation it may return; calling this function has none. -#[allow(clippy::type_complexity)] -#[inline] -pub fn vg_aes_gcm_seal_prepared_select() -> unsafe extern "sysv64" fn(ctx: *const [u64; 129], rounds: usize, nonce: *const u8, nonce_len: usize, aad: *const u8, aad_len: usize, data: *mut u8, len: usize, tag: *mut [u8; 16]) { - let cpu = verified_garbage_cpu::detected(); - if cpu.contains(crate::gcm::VG_AES_GCM_SEAL_PREPARED_VAES_VPCLMUL_AVX512_FEATURES) { - return crate::gcm::vg_aes_gcm_seal_prepared_vaes_vpclmul_avx512; - } - if cpu.contains(crate::gcm::VG_AES_GCM_SEAL_PREPARED_VAES_VPCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_seal_prepared_vaes_vpclmul; - } - if cpu.contains(crate::gcm::VG_AES_GCM_SEAL_PREPARED_VAES_PCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_seal_prepared_vaes_pclmul; - } - if cpu.contains(crate::gcm::VG_AES_GCM_SEAL_PREPARED_AESNI_VPCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_seal_prepared_aesni_vpclmul; - } - if cpu.contains(crate::gcm::VG_AES_GCM_SEAL_PREPARED_AESNI_PCLMUL_AVX_FEATURES) { - return crate::gcm::vg_aes_gcm_seal_prepared_aesni_pclmul_avx; - } - if cpu.contains(crate::gcm::VG_AES_GCM_SEAL_PREPARED_AESNI_PCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_seal_prepared_aesni_pclmul; - } - if cpu.contains(crate::gcm::VG_AES_GCM_SEAL_PREPARED_VAES_FEATURES) { - return crate::gcm::vg_aes_gcm_seal_prepared_vaes; - } - if cpu.contains(crate::gcm::VG_AES_GCM_SEAL_PREPARED_AESNI_FEATURES) { - return crate::gcm::vg_aes_gcm_seal_prepared_aesni; - } - if cpu.contains(crate::gcm::VG_AES_GCM_SEAL_PREPARED_VPCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_seal_prepared_vpclmul; - } - if cpu.contains(crate::gcm::VG_AES_GCM_SEAL_PREPARED_PCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_seal_prepared_pclmul; - } - crate::gcm::vg_aes_gcm_seal_prepared -} - /// `vg_aes_gcm_open` with a 1032-byte context from `vg_aes_gcm_prepare`. Computes the same result, using the AES key schedule and hash subkey in its first 256 bytes, and may read the prepared powers its count says are present. The powers remain secret; how many are present may affect timing; all other memory, aliasing and constant-time requirements are unchanged. Contract: `VG.Spec.Gcm.openPreparedContract`. /// /// It runs the first of these implementations that applies, which `VG.Dispatch.ranking` orders (`VG.Rust.Rank`): `vg_aes_gcm_open_prepared_vaes_vpclmul_avx512` if the CPU supports its features (`VG_AES_GCM_OPEN_PREPARED_VAES_VPCLMUL_AVX512_FEATURES`); `vg_aes_gcm_open_prepared_vaes_vpclmul` if the CPU supports its features (`VG_AES_GCM_OPEN_PREPARED_VAES_VPCLMUL_FEATURES`); `vg_aes_gcm_open_prepared_vaes_pclmul` if the CPU supports its features (`VG_AES_GCM_OPEN_PREPARED_VAES_PCLMUL_FEATURES`); `vg_aes_gcm_open_prepared_aesni_vpclmul` if the CPU supports its features (`VG_AES_GCM_OPEN_PREPARED_AESNI_VPCLMUL_FEATURES`); `vg_aes_gcm_open_prepared_aesni_pclmul_avx` if the CPU supports its features (`VG_AES_GCM_OPEN_PREPARED_AESNI_PCLMUL_AVX_FEATURES`); `vg_aes_gcm_open_prepared_aesni_pclmul` if the CPU supports its features (`VG_AES_GCM_OPEN_PREPARED_AESNI_PCLMUL_FEATURES`); `vg_aes_gcm_open_prepared_vaes` if the CPU supports its features (`VG_AES_GCM_OPEN_PREPARED_VAES_FEATURES`); `vg_aes_gcm_open_prepared_aesni` if the CPU supports its features (`VG_AES_GCM_OPEN_PREPARED_AESNI_FEATURES`); `vg_aes_gcm_open_prepared_vpclmul` if the CPU supports its features (`VG_AES_GCM_OPEN_PREPARED_VPCLMUL_FEATURES`); `vg_aes_gcm_open_prepared_pclmul` if the CPU supports its features (`VG_AES_GCM_OPEN_PREPARED_PCLMUL_FEATURES`); or else `vg_aes_gcm_open_prepared`, which needs no CPU feature. It chooses on its first call, and calls the one it chose from then on without choosing again. Each has this documentation but for its stack (whose requirements here are the largest) and what it writes. @@ -686,48 +536,6 @@ pub unsafe fn vg_aes_gcm_open_prepared_auto(ctx: *const [u64; 129], rounds: usiz unsafe { core::mem::transmute::<*mut (), Impl>(CHOSEN.load(core::sync::atomic::Ordering::Relaxed))(ctx, rounds, nonce, nonce_len, aad, aad_len, data, len, tag, tag_len) } } -/// The implementation of `vg_aes_gcm_open_prepared` that `vg_aes_gcm_open_prepared_auto` runs on this CPU, chosen as it chooses (`VG.Rust.selector`), so that it can be called without choosing again. -/// -/// # Safety -/// -/// Calling the function it returns carries exactly `vg_aes_gcm_open_prepared_auto`'s obligations (its `# Safety` section), which are those of each implementation it may return; calling this function has none. -#[allow(clippy::type_complexity)] -#[inline] -pub fn vg_aes_gcm_open_prepared_select() -> unsafe extern "sysv64" fn(ctx: *const [u64; 129], rounds: usize, nonce: *const u8, nonce_len: usize, aad: *const u8, aad_len: usize, data: *mut u8, len: usize, tag: *const u8, tag_len: usize) -> u32 { - let cpu = verified_garbage_cpu::detected(); - if cpu.contains(crate::gcm::VG_AES_GCM_OPEN_PREPARED_VAES_VPCLMUL_AVX512_FEATURES) { - return crate::gcm::vg_aes_gcm_open_prepared_vaes_vpclmul_avx512; - } - if cpu.contains(crate::gcm::VG_AES_GCM_OPEN_PREPARED_VAES_VPCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_open_prepared_vaes_vpclmul; - } - if cpu.contains(crate::gcm::VG_AES_GCM_OPEN_PREPARED_VAES_PCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_open_prepared_vaes_pclmul; - } - if cpu.contains(crate::gcm::VG_AES_GCM_OPEN_PREPARED_AESNI_VPCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_open_prepared_aesni_vpclmul; - } - if cpu.contains(crate::gcm::VG_AES_GCM_OPEN_PREPARED_AESNI_PCLMUL_AVX_FEATURES) { - return crate::gcm::vg_aes_gcm_open_prepared_aesni_pclmul_avx; - } - if cpu.contains(crate::gcm::VG_AES_GCM_OPEN_PREPARED_AESNI_PCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_open_prepared_aesni_pclmul; - } - if cpu.contains(crate::gcm::VG_AES_GCM_OPEN_PREPARED_VAES_FEATURES) { - return crate::gcm::vg_aes_gcm_open_prepared_vaes; - } - if cpu.contains(crate::gcm::VG_AES_GCM_OPEN_PREPARED_AESNI_FEATURES) { - return crate::gcm::vg_aes_gcm_open_prepared_aesni; - } - if cpu.contains(crate::gcm::VG_AES_GCM_OPEN_PREPARED_VPCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_open_prepared_vpclmul; - } - if cpu.contains(crate::gcm::VG_AES_GCM_OPEN_PREPARED_PCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_open_prepared_pclmul; - } - crate::gcm::vg_aes_gcm_open_prepared -} - /// `vg_aes_gcm_open_to` with a 1032-byte context from `vg_aes_gcm_prepare`. Computes the same result, using the AES key schedule and hash subkey in its first 256 bytes, and may read the prepared powers its count says are present. The powers remain secret; how many are present may affect timing; all other memory, aliasing and constant-time requirements are unchanged. Contract: `VG.Spec.Gcm.openToPreparedContract`. /// /// It runs the first of these implementations that applies, which `VG.Dispatch.ranking` orders (`VG.Rust.Rank`): `vg_aes_gcm_open_to_prepared_vaes_vpclmul_avx512` if the CPU supports its features (`VG_AES_GCM_OPEN_TO_PREPARED_VAES_VPCLMUL_AVX512_FEATURES`); `vg_aes_gcm_open_to_prepared_vaes_vpclmul` if the CPU supports its features (`VG_AES_GCM_OPEN_TO_PREPARED_VAES_VPCLMUL_FEATURES`); `vg_aes_gcm_open_to_prepared_vaes_pclmul` if the CPU supports its features (`VG_AES_GCM_OPEN_TO_PREPARED_VAES_PCLMUL_FEATURES`); `vg_aes_gcm_open_to_prepared_aesni_vpclmul` if the CPU supports its features (`VG_AES_GCM_OPEN_TO_PREPARED_AESNI_VPCLMUL_FEATURES`); `vg_aes_gcm_open_to_prepared_aesni_pclmul_avx` if the CPU supports its features (`VG_AES_GCM_OPEN_TO_PREPARED_AESNI_PCLMUL_AVX_FEATURES`); `vg_aes_gcm_open_to_prepared_aesni_pclmul` if the CPU supports its features (`VG_AES_GCM_OPEN_TO_PREPARED_AESNI_PCLMUL_FEATURES`); `vg_aes_gcm_open_to_prepared_vaes` if the CPU supports its features (`VG_AES_GCM_OPEN_TO_PREPARED_VAES_FEATURES`); `vg_aes_gcm_open_to_prepared_aesni` if the CPU supports its features (`VG_AES_GCM_OPEN_TO_PREPARED_AESNI_FEATURES`); `vg_aes_gcm_open_to_prepared_vpclmul` if the CPU supports its features (`VG_AES_GCM_OPEN_TO_PREPARED_VPCLMUL_FEATURES`); `vg_aes_gcm_open_to_prepared_pclmul` if the CPU supports its features (`VG_AES_GCM_OPEN_TO_PREPARED_PCLMUL_FEATURES`); or else `vg_aes_gcm_open_to_prepared`, which needs no CPU feature. It chooses on its first call, and calls the one it chose from then on without choosing again. Each has this documentation but for its stack (whose requirements here are the largest) and what it writes. @@ -806,48 +614,6 @@ pub unsafe fn vg_aes_gcm_open_to_prepared_auto(ctx: *const [u64; 129], rounds: u unsafe { core::mem::transmute::<*mut (), Impl>(CHOSEN.load(core::sync::atomic::Ordering::Relaxed))(ctx, rounds, nonce, nonce_len, aad, aad_len, src, len, dst, dst_len, tag, tag_len) } } -/// The implementation of `vg_aes_gcm_open_to_prepared` that `vg_aes_gcm_open_to_prepared_auto` runs on this CPU, chosen as it chooses (`VG.Rust.selector`), so that it can be called without choosing again. -/// -/// # Safety -/// -/// Calling the function it returns carries exactly `vg_aes_gcm_open_to_prepared_auto`'s obligations (its `# Safety` section), which are those of each implementation it may return; calling this function has none. -#[allow(clippy::type_complexity)] -#[inline] -pub fn vg_aes_gcm_open_to_prepared_select() -> unsafe extern "sysv64" fn(ctx: *const [u64; 129], rounds: usize, nonce: *const u8, nonce_len: usize, aad: *const u8, aad_len: usize, src: *const u8, len: usize, dst: *mut u8, dst_len: usize, tag: *const u8, tag_len: usize) -> u32 { - let cpu = verified_garbage_cpu::detected(); - if cpu.contains(crate::gcm::VG_AES_GCM_OPEN_TO_PREPARED_VAES_VPCLMUL_AVX512_FEATURES) { - return crate::gcm::vg_aes_gcm_open_to_prepared_vaes_vpclmul_avx512; - } - if cpu.contains(crate::gcm::VG_AES_GCM_OPEN_TO_PREPARED_VAES_VPCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_open_to_prepared_vaes_vpclmul; - } - if cpu.contains(crate::gcm::VG_AES_GCM_OPEN_TO_PREPARED_VAES_PCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_open_to_prepared_vaes_pclmul; - } - if cpu.contains(crate::gcm::VG_AES_GCM_OPEN_TO_PREPARED_AESNI_VPCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_open_to_prepared_aesni_vpclmul; - } - if cpu.contains(crate::gcm::VG_AES_GCM_OPEN_TO_PREPARED_AESNI_PCLMUL_AVX_FEATURES) { - return crate::gcm::vg_aes_gcm_open_to_prepared_aesni_pclmul_avx; - } - if cpu.contains(crate::gcm::VG_AES_GCM_OPEN_TO_PREPARED_AESNI_PCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_open_to_prepared_aesni_pclmul; - } - if cpu.contains(crate::gcm::VG_AES_GCM_OPEN_TO_PREPARED_VAES_FEATURES) { - return crate::gcm::vg_aes_gcm_open_to_prepared_vaes; - } - if cpu.contains(crate::gcm::VG_AES_GCM_OPEN_TO_PREPARED_AESNI_FEATURES) { - return crate::gcm::vg_aes_gcm_open_to_prepared_aesni; - } - if cpu.contains(crate::gcm::VG_AES_GCM_OPEN_TO_PREPARED_VPCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_open_to_prepared_vpclmul; - } - if cpu.contains(crate::gcm::VG_AES_GCM_OPEN_TO_PREPARED_PCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_open_to_prepared_pclmul; - } - crate::gcm::vg_aes_gcm_open_to_prepared -} - /// `vg_aes_gcm_seal_gather` with a 1032-byte context from `vg_aes_gcm_prepare`. Computes the same result, using the AES key schedule and hash subkey in its first 256 bytes, and may read the prepared powers its count says are present. The powers remain secret; how many are present may affect timing; all other memory, aliasing and constant-time requirements are unchanged. Contract: `VG.Spec.Gcm.sealGatherPreparedContract`. /// /// It runs the first of these implementations that applies, which `VG.Dispatch.ranking` orders (`VG.Rust.Rank`): `vg_aes_gcm_seal_gather_prepared_vaes_vpclmul_avx512` if the CPU supports its features (`VG_AES_GCM_SEAL_GATHER_PREPARED_VAES_VPCLMUL_AVX512_FEATURES`); `vg_aes_gcm_seal_gather_prepared_vaes_vpclmul` if the CPU supports its features (`VG_AES_GCM_SEAL_GATHER_PREPARED_VAES_VPCLMUL_FEATURES`); `vg_aes_gcm_seal_gather_prepared_vaes_pclmul` if the CPU supports its features (`VG_AES_GCM_SEAL_GATHER_PREPARED_VAES_PCLMUL_FEATURES`); `vg_aes_gcm_seal_gather_prepared_aesni_vpclmul` if the CPU supports its features (`VG_AES_GCM_SEAL_GATHER_PREPARED_AESNI_VPCLMUL_FEATURES`); `vg_aes_gcm_seal_gather_prepared_aesni_pclmul_avx` if the CPU supports its features (`VG_AES_GCM_SEAL_GATHER_PREPARED_AESNI_PCLMUL_AVX_FEATURES`); `vg_aes_gcm_seal_gather_prepared_aesni_pclmul` if the CPU supports its features (`VG_AES_GCM_SEAL_GATHER_PREPARED_AESNI_PCLMUL_FEATURES`); `vg_aes_gcm_seal_gather_prepared_vaes` if the CPU supports its features (`VG_AES_GCM_SEAL_GATHER_PREPARED_VAES_FEATURES`); `vg_aes_gcm_seal_gather_prepared_aesni` if the CPU supports its features (`VG_AES_GCM_SEAL_GATHER_PREPARED_AESNI_FEATURES`); `vg_aes_gcm_seal_gather_prepared_vpclmul` if the CPU supports its features (`VG_AES_GCM_SEAL_GATHER_PREPARED_VPCLMUL_FEATURES`); `vg_aes_gcm_seal_gather_prepared_pclmul` if the CPU supports its features (`VG_AES_GCM_SEAL_GATHER_PREPARED_PCLMUL_FEATURES`); or else `vg_aes_gcm_seal_gather_prepared`, which needs no CPU feature. It chooses on its first call, and calls the one it chose from then on without choosing again. Each has this documentation but for its stack (whose requirements here are the largest) and what it writes. @@ -926,48 +692,6 @@ pub unsafe fn vg_aes_gcm_seal_gather_prepared_auto(ctx: *const [u64; 129], round unsafe { core::mem::transmute::<*mut (), Impl>(CHOSEN.load(core::sync::atomic::Ordering::Relaxed))(ctx, rounds, nonce, nonce_len, aad, aad_len, src, src_count, dst, len, tag) } } -/// The implementation of `vg_aes_gcm_seal_gather_prepared` that `vg_aes_gcm_seal_gather_prepared_auto` runs on this CPU, chosen as it chooses (`VG.Rust.selector`), so that it can be called without choosing again. -/// -/// # Safety -/// -/// Calling the function it returns carries exactly `vg_aes_gcm_seal_gather_prepared_auto`'s obligations (its `# Safety` section), which are those of each implementation it may return; calling this function has none. -#[allow(clippy::type_complexity)] -#[inline] -pub fn vg_aes_gcm_seal_gather_prepared_select() -> unsafe extern "sysv64" fn(ctx: *const [u64; 129], rounds: usize, nonce: *const u8, nonce_len: usize, aad: *const u8, aad_len: usize, src: *const [usize; 2], src_count: usize, dst: *mut u8, len: usize, tag: *mut [u8; 16]) { - let cpu = verified_garbage_cpu::detected(); - if cpu.contains(crate::gcm::VG_AES_GCM_SEAL_GATHER_PREPARED_VAES_VPCLMUL_AVX512_FEATURES) { - return crate::gcm::vg_aes_gcm_seal_gather_prepared_vaes_vpclmul_avx512; - } - if cpu.contains(crate::gcm::VG_AES_GCM_SEAL_GATHER_PREPARED_VAES_VPCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_seal_gather_prepared_vaes_vpclmul; - } - if cpu.contains(crate::gcm::VG_AES_GCM_SEAL_GATHER_PREPARED_VAES_PCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_seal_gather_prepared_vaes_pclmul; - } - if cpu.contains(crate::gcm::VG_AES_GCM_SEAL_GATHER_PREPARED_AESNI_VPCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_seal_gather_prepared_aesni_vpclmul; - } - if cpu.contains(crate::gcm::VG_AES_GCM_SEAL_GATHER_PREPARED_AESNI_PCLMUL_AVX_FEATURES) { - return crate::gcm::vg_aes_gcm_seal_gather_prepared_aesni_pclmul_avx; - } - if cpu.contains(crate::gcm::VG_AES_GCM_SEAL_GATHER_PREPARED_AESNI_PCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_seal_gather_prepared_aesni_pclmul; - } - if cpu.contains(crate::gcm::VG_AES_GCM_SEAL_GATHER_PREPARED_VAES_FEATURES) { - return crate::gcm::vg_aes_gcm_seal_gather_prepared_vaes; - } - if cpu.contains(crate::gcm::VG_AES_GCM_SEAL_GATHER_PREPARED_AESNI_FEATURES) { - return crate::gcm::vg_aes_gcm_seal_gather_prepared_aesni; - } - if cpu.contains(crate::gcm::VG_AES_GCM_SEAL_GATHER_PREPARED_VPCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_seal_gather_prepared_vpclmul; - } - if cpu.contains(crate::gcm::VG_AES_GCM_SEAL_GATHER_PREPARED_PCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_seal_gather_prepared_pclmul; - } - crate::gcm::vg_aes_gcm_seal_gather_prepared -} - /// `vg_aes_gcm_stream_encrypt` with a 1032-byte context from `vg_aes_gcm_prepare`. Computes the same result, using the AES key schedule and hash subkey in its first 256 bytes, and may read the prepared powers its count says are present. The powers remain secret; how many are present may affect timing; all other memory, aliasing and constant-time requirements are unchanged. Contract: `VG.Spec.Gcm.streamEncryptPreparedContract`. /// /// It runs the first of these implementations that applies, which `VG.Dispatch.ranking` orders (`VG.Rust.Rank`): `vg_aes_gcm_stream_encrypt_prepared_vaes_vpclmul_avx512` if the CPU supports its features (`VG_AES_GCM_STREAM_ENCRYPT_PREPARED_VAES_VPCLMUL_AVX512_FEATURES`); `vg_aes_gcm_stream_encrypt_prepared_vaes_vpclmul` if the CPU supports its features (`VG_AES_GCM_STREAM_ENCRYPT_PREPARED_VAES_VPCLMUL_FEATURES`); `vg_aes_gcm_stream_encrypt_prepared_vaes_pclmul` if the CPU supports its features (`VG_AES_GCM_STREAM_ENCRYPT_PREPARED_VAES_PCLMUL_FEATURES`); `vg_aes_gcm_stream_encrypt_prepared_aesni_vpclmul` if the CPU supports its features (`VG_AES_GCM_STREAM_ENCRYPT_PREPARED_AESNI_VPCLMUL_FEATURES`); `vg_aes_gcm_stream_encrypt_prepared_aesni_pclmul_avx` if the CPU supports its features (`VG_AES_GCM_STREAM_ENCRYPT_PREPARED_AESNI_PCLMUL_AVX_FEATURES`); `vg_aes_gcm_stream_encrypt_prepared_aesni_pclmul` if the CPU supports its features (`VG_AES_GCM_STREAM_ENCRYPT_PREPARED_AESNI_PCLMUL_FEATURES`); `vg_aes_gcm_stream_encrypt_prepared_vaes` if the CPU supports its features (`VG_AES_GCM_STREAM_ENCRYPT_PREPARED_VAES_FEATURES`); `vg_aes_gcm_stream_encrypt_prepared_aesni` if the CPU supports its features (`VG_AES_GCM_STREAM_ENCRYPT_PREPARED_AESNI_FEATURES`); `vg_aes_gcm_stream_encrypt_prepared_vpclmul` if the CPU supports its features (`VG_AES_GCM_STREAM_ENCRYPT_PREPARED_VPCLMUL_FEATURES`); `vg_aes_gcm_stream_encrypt_prepared_pclmul` if the CPU supports its features (`VG_AES_GCM_STREAM_ENCRYPT_PREPARED_PCLMUL_FEATURES`); or else `vg_aes_gcm_stream_encrypt_prepared`, which needs no CPU feature. It chooses on its first call, and calls the one it chose from then on without choosing again. Each has this documentation but for its stack (whose requirements here are the largest) and what it writes. @@ -1042,48 +766,6 @@ pub unsafe fn vg_aes_gcm_stream_encrypt_prepared_auto(ctx: *const [u64; 129], ro unsafe { core::mem::transmute::<*mut (), Impl>(CHOSEN.load(core::sync::atomic::Ordering::Relaxed))(ctx, rounds, state, aad_len, text_len, data, len) } } -/// The implementation of `vg_aes_gcm_stream_encrypt_prepared` that `vg_aes_gcm_stream_encrypt_prepared_auto` runs on this CPU, chosen as it chooses (`VG.Rust.selector`), so that it can be called without choosing again. -/// -/// # Safety -/// -/// Calling the function it returns carries exactly `vg_aes_gcm_stream_encrypt_prepared_auto`'s obligations (its `# Safety` section), which are those of each implementation it may return; calling this function has none. -#[allow(clippy::type_complexity)] -#[inline] -pub fn vg_aes_gcm_stream_encrypt_prepared_select() -> unsafe extern "sysv64" fn(ctx: *const [u64; 129], rounds: usize, state: *mut [u64; 10], aad_len: u64, text_len: u64, data: *mut u8, len: usize) { - let cpu = verified_garbage_cpu::detected(); - if cpu.contains(crate::gcm::VG_AES_GCM_STREAM_ENCRYPT_PREPARED_VAES_VPCLMUL_AVX512_FEATURES) { - return crate::gcm::vg_aes_gcm_stream_encrypt_prepared_vaes_vpclmul_avx512; - } - if cpu.contains(crate::gcm::VG_AES_GCM_STREAM_ENCRYPT_PREPARED_VAES_VPCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_stream_encrypt_prepared_vaes_vpclmul; - } - if cpu.contains(crate::gcm::VG_AES_GCM_STREAM_ENCRYPT_PREPARED_VAES_PCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_stream_encrypt_prepared_vaes_pclmul; - } - if cpu.contains(crate::gcm::VG_AES_GCM_STREAM_ENCRYPT_PREPARED_AESNI_VPCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_stream_encrypt_prepared_aesni_vpclmul; - } - if cpu.contains(crate::gcm::VG_AES_GCM_STREAM_ENCRYPT_PREPARED_AESNI_PCLMUL_AVX_FEATURES) { - return crate::gcm::vg_aes_gcm_stream_encrypt_prepared_aesni_pclmul_avx; - } - if cpu.contains(crate::gcm::VG_AES_GCM_STREAM_ENCRYPT_PREPARED_AESNI_PCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_stream_encrypt_prepared_aesni_pclmul; - } - if cpu.contains(crate::gcm::VG_AES_GCM_STREAM_ENCRYPT_PREPARED_VAES_FEATURES) { - return crate::gcm::vg_aes_gcm_stream_encrypt_prepared_vaes; - } - if cpu.contains(crate::gcm::VG_AES_GCM_STREAM_ENCRYPT_PREPARED_AESNI_FEATURES) { - return crate::gcm::vg_aes_gcm_stream_encrypt_prepared_aesni; - } - if cpu.contains(crate::gcm::VG_AES_GCM_STREAM_ENCRYPT_PREPARED_VPCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_stream_encrypt_prepared_vpclmul; - } - if cpu.contains(crate::gcm::VG_AES_GCM_STREAM_ENCRYPT_PREPARED_PCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_stream_encrypt_prepared_pclmul; - } - crate::gcm::vg_aes_gcm_stream_encrypt_prepared -} - /// `vg_aes_gcm_stream_decrypt` with a 1032-byte context from `vg_aes_gcm_prepare`. Computes the same result, using the AES key schedule and hash subkey in its first 256 bytes, and may read the prepared powers its count says are present. The powers remain secret; how many are present may affect timing; all other memory, aliasing and constant-time requirements are unchanged. Contract: `VG.Spec.Gcm.streamDecryptPreparedContract`. /// /// It runs the first of these implementations that applies, which `VG.Dispatch.ranking` orders (`VG.Rust.Rank`): `vg_aes_gcm_stream_decrypt_prepared_vaes_vpclmul_avx512` if the CPU supports its features (`VG_AES_GCM_STREAM_DECRYPT_PREPARED_VAES_VPCLMUL_AVX512_FEATURES`); `vg_aes_gcm_stream_decrypt_prepared_vaes_vpclmul` if the CPU supports its features (`VG_AES_GCM_STREAM_DECRYPT_PREPARED_VAES_VPCLMUL_FEATURES`); `vg_aes_gcm_stream_decrypt_prepared_vaes_pclmul` if the CPU supports its features (`VG_AES_GCM_STREAM_DECRYPT_PREPARED_VAES_PCLMUL_FEATURES`); `vg_aes_gcm_stream_decrypt_prepared_aesni_vpclmul` if the CPU supports its features (`VG_AES_GCM_STREAM_DECRYPT_PREPARED_AESNI_VPCLMUL_FEATURES`); `vg_aes_gcm_stream_decrypt_prepared_aesni_pclmul_avx` if the CPU supports its features (`VG_AES_GCM_STREAM_DECRYPT_PREPARED_AESNI_PCLMUL_AVX_FEATURES`); `vg_aes_gcm_stream_decrypt_prepared_aesni_pclmul` if the CPU supports its features (`VG_AES_GCM_STREAM_DECRYPT_PREPARED_AESNI_PCLMUL_FEATURES`); `vg_aes_gcm_stream_decrypt_prepared_vaes` if the CPU supports its features (`VG_AES_GCM_STREAM_DECRYPT_PREPARED_VAES_FEATURES`); `vg_aes_gcm_stream_decrypt_prepared_aesni` if the CPU supports its features (`VG_AES_GCM_STREAM_DECRYPT_PREPARED_AESNI_FEATURES`); `vg_aes_gcm_stream_decrypt_prepared_vpclmul` if the CPU supports its features (`VG_AES_GCM_STREAM_DECRYPT_PREPARED_VPCLMUL_FEATURES`); `vg_aes_gcm_stream_decrypt_prepared_pclmul` if the CPU supports its features (`VG_AES_GCM_STREAM_DECRYPT_PREPARED_PCLMUL_FEATURES`); or else `vg_aes_gcm_stream_decrypt_prepared`, which needs no CPU feature. It chooses on its first call, and calls the one it chose from then on without choosing again. Each has this documentation but for its stack (whose requirements here are the largest) and what it writes. @@ -1157,45 +839,3 @@ pub unsafe fn vg_aes_gcm_stream_decrypt_prepared_auto(ctx: *const [u64; 129], ro // either carries the caller's obligations, which are those of every implementation. unsafe { core::mem::transmute::<*mut (), Impl>(CHOSEN.load(core::sync::atomic::Ordering::Relaxed))(ctx, rounds, state, aad_len, text_len, data, len) } } - -/// The implementation of `vg_aes_gcm_stream_decrypt_prepared` that `vg_aes_gcm_stream_decrypt_prepared_auto` runs on this CPU, chosen as it chooses (`VG.Rust.selector`), so that it can be called without choosing again. -/// -/// # Safety -/// -/// Calling the function it returns carries exactly `vg_aes_gcm_stream_decrypt_prepared_auto`'s obligations (its `# Safety` section), which are those of each implementation it may return; calling this function has none. -#[allow(clippy::type_complexity)] -#[inline] -pub fn vg_aes_gcm_stream_decrypt_prepared_select() -> unsafe extern "sysv64" fn(ctx: *const [u64; 129], rounds: usize, state: *mut [u64; 10], aad_len: u64, text_len: u64, data: *mut u8, len: usize) { - let cpu = verified_garbage_cpu::detected(); - if cpu.contains(crate::gcm::VG_AES_GCM_STREAM_DECRYPT_PREPARED_VAES_VPCLMUL_AVX512_FEATURES) { - return crate::gcm::vg_aes_gcm_stream_decrypt_prepared_vaes_vpclmul_avx512; - } - if cpu.contains(crate::gcm::VG_AES_GCM_STREAM_DECRYPT_PREPARED_VAES_VPCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_stream_decrypt_prepared_vaes_vpclmul; - } - if cpu.contains(crate::gcm::VG_AES_GCM_STREAM_DECRYPT_PREPARED_VAES_PCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_stream_decrypt_prepared_vaes_pclmul; - } - if cpu.contains(crate::gcm::VG_AES_GCM_STREAM_DECRYPT_PREPARED_AESNI_VPCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_stream_decrypt_prepared_aesni_vpclmul; - } - if cpu.contains(crate::gcm::VG_AES_GCM_STREAM_DECRYPT_PREPARED_AESNI_PCLMUL_AVX_FEATURES) { - return crate::gcm::vg_aes_gcm_stream_decrypt_prepared_aesni_pclmul_avx; - } - if cpu.contains(crate::gcm::VG_AES_GCM_STREAM_DECRYPT_PREPARED_AESNI_PCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_stream_decrypt_prepared_aesni_pclmul; - } - if cpu.contains(crate::gcm::VG_AES_GCM_STREAM_DECRYPT_PREPARED_VAES_FEATURES) { - return crate::gcm::vg_aes_gcm_stream_decrypt_prepared_vaes; - } - if cpu.contains(crate::gcm::VG_AES_GCM_STREAM_DECRYPT_PREPARED_AESNI_FEATURES) { - return crate::gcm::vg_aes_gcm_stream_decrypt_prepared_aesni; - } - if cpu.contains(crate::gcm::VG_AES_GCM_STREAM_DECRYPT_PREPARED_VPCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_stream_decrypt_prepared_vpclmul; - } - if cpu.contains(crate::gcm::VG_AES_GCM_STREAM_DECRYPT_PREPARED_PCLMUL_FEATURES) { - return crate::gcm::vg_aes_gcm_stream_decrypt_prepared_pclmul; - } - crate::gcm::vg_aes_gcm_stream_decrypt_prepared -} diff --git a/lean/VerifiedGarbage/Dispatch.lean b/lean/VerifiedGarbage/Dispatch.lean index 0c87feafe9f..0ecd2f97d5a 100644 --- a/lean/VerifiedGarbage/Dispatch.lean +++ b/lean/VerifiedGarbage/Dispatch.lean @@ -86,21 +86,4 @@ def ranking : Rust.Ranking := [ ("arm", [ { suffix := "_umaal" }])] -/-- The functions that also get a selector, `_select`, which returns -the implementation their dispatcher would run instead of running it -(`VG.Rust.selector`), for each target by its name: their bases' names. Like -the ranking, it is not trusted: it only says which functions get one. -/ -def selected : Rust.Selected := - -- AES-GCM's functions that `AesGcm` calls for each message, which a key - -- selects when it is created (`src/aead/aes_gcm.rs`): on x86-64 those - -- reading its prepared key context, on AArch64 its powers where they do. - let stream := ["stream_init", "stream_aad", "stream_finish", "stream_verify"] - let plain := ["seal", "open", "open_to", "seal_gather", "stream_encrypt", "stream_decrypt"] - let gcm (fs : List String) : List String := (fs ++ stream).map ("vg_aes_gcm_" ++ ·) - [("x86_64", gcm (plain.map (· ++ "_prepared"))), - -- AArch64's `encrypt` copies its pieces and seals them (`AesGcm::seal_pieces`). - ("aarch64", gcm ((plain.erase "seal_gather").map fun f => - if f == "seal" || f == "open" then f ++ "_with_powers" else f))] ++ - (["x86", "arm", "powerpc64le", "riscv64"].map fun t => (t, gcm plain)) - end VG.Dispatch diff --git a/lean/VerifiedGarbage/TCB/Emit.lean b/lean/VerifiedGarbage/TCB/Emit.lean index 529fbd351ce..e18b62cffd4 100644 --- a/lean/VerifiedGarbage/TCB/Emit.lean +++ b/lean/VerifiedGarbage/TCB/Emit.lean @@ -69,9 +69,7 @@ their calls (`Rust.Internal`). (`registrations`, `grouped`, `genericGroups`), writes a program that imports them all and the ranking of the dispatchers of every target (`VerifiedGarbage/Dispatch.lean`, `VG.Dispatch.ranking`, which only orders -the implementations a dispatcher tries: see `Rust.Rank`, and -`VG.Dispatch.selected`, the functions that also get a selector: -`Rust.Selected`), checks that the whole list depends only on the standard +the implementations a dispatcher tries: see `Rust.Rank`), checks that the whole list depends only on the standard axioms, that what it runs is what the kernel checked and that the `Spec/` names it uses come from `Spec/` (`TCB/Audit.lean`), and emits it (`driver`), and runs that program, whose `main` is `run`. @@ -211,8 +209,8 @@ each variant of its interface and target in `vars` (each combination of variants of its interfaces). It fails to elaborate unless each module defines its list (or variant), with types that agree, unless everything emitted depends only on the standard axioms (`#assert_standard_axioms`), unless the compiled -code of everything emitted, of the ranking of the dispatchers and the list of -selectors (`VerifiedGarbage/Dispatch.lean`, `Rust.Rank`, `Rust.Selected`) and of `run` is what the kernel checked +code of everything emitted, of the ranking of the dispatchers +(`VerifiedGarbage/Dispatch.lean`, `Rust.Rank`) and of `run` is what the kernel checked (`#assert_no_compiler_overrides`) and unless every `VG.Spec` definition is declared in `Spec/` (`#assert_spec_origin`). It is a module, which does not load the private data (`.olean.private`) of what it imports: run with Lake's setup for it @@ -235,10 +233,10 @@ def driver (mods : List String) (gens : List (List String × List String) := []) String.join (groups.map fun (gs, vs) => s!" {instances gs vs},\n") ++ " []]\n\n" ++ "#assert_standard_axioms all\n" ++ - "#assert_no_compiler_overrides all VG.Dispatch.ranking VG.Dispatch.selected run\n" ++ + "#assert_no_compiler_overrides all VG.Dispatch.ranking run\n" ++ "#assert_spec_origin\n\n" ++ "end VG.Emit\n\n" ++ - "def main (args : List String) : IO UInt32 :=\n VG.Emit.run VG.Emit.all VG.Dispatch.ranking args VG.Dispatch.selected\n\nend\n" + "def main (args : List String) : IO UInt32 :=\n VG.Emit.run VG.Emit.all VG.Dispatch.ranking args\n\nend\n" /-- The target directory a registration, generic or variant module's path names: `X86_64` for `VerifiedGarbage.Artifacts.Sha3.X86_64`, @@ -348,7 +346,7 @@ def codeDirs (dir : FilePath) : IO (List String) := do return (ds.qsort (· < ·)).toList /-- Writes the files generated from `as` (with the dispatchers that `ranking` -orders, `Rust.Rank`, and the selectors `selected` asks for, `Rust.Selected`) under the directory in `args` (by +orders, `Rust.Rank`) under the directory in `args` (by default `../crates`), deleting any other generated file in the directories of generated files of a crate of generated code there (`codeDirs`, and nothing else: the rest of those crates, and the other crates, are not the emitter's); @@ -359,10 +357,9 @@ With `--part FILE`, `as` are the artifacts of a part (`parts`): only the files of their targets' crates are written or checked, and the other generated files in those crates' directories of generated files; then `FILE` gets their targets, for `finish`, which checks the rest. -/ -def run (as : List Artifact) (ranking : Rust.Ranking) (args : List String) - (selected : Rust.Selected := []) : IO UInt32 := do +def run (as : List Artifact) (ranking : Rust.Ranking) (args : List String) : IO UInt32 := do let some (check, part, dir) := parseArgs args | do IO.eprintln usage; return 2 - let files ← match Rust.files as ranking selected with + let files ← match Rust.files as ranking with | .ok files => pure files | .error e => do IO.eprintln e; return 1 let targets := Rust.targetsOf as diff --git a/lean/VerifiedGarbage/TCB/Rust.lean b/lean/VerifiedGarbage/TCB/Rust.lean index 42c745df805..6e6bd9c9651 100644 --- a/lean/VerifiedGarbage/TCB/Rust.lean +++ b/lean/VerifiedGarbage/TCB/Rust.lean @@ -1709,32 +1709,6 @@ pub use crate:::: as _auto; A function whose base needs CPU features gets none (there is nothing to fall back on), and neither does an implementation that is not a base. -A function the ranking's file lists for its target (`Selected`, -`VerifiedGarbage/Dispatch.lean`, which is not trusted either: it only says -which functions get one) also gets a *selector*, `_select`, next to its -dispatcher (`selector`). It tries the dispatcher's implementations in the -same order, under the same conditions, but returns the first that applies, -or the base, as a pointer to it instead of calling it, so that the Rust code -can choose once and call it as often as it likes without choosing again. It -is safe to call, since it calls nothing but `detected()`; calling what it -returns carries exactly the dispatcher's obligations, which are that -function's: - -```rust -/// -#[inline] -pub fn _select() -> unsafe extern "" fn { - let cpu = verified_garbage_cpu::detected(); - if cpu.contains(crate::::_FEATURES) { - return crate::::; - } - … - crate:::: -} -``` - -A function whose base is its only implementation returns it. - A table of functions (`FnTable`) is chosen the same way, by `dispatch/fn_tables.rs` (`tableDispatcher`). Its implementations are the tables of the same interface and the same words of data whose names are its @@ -2033,32 +2007,6 @@ def soleDispatcher (g : Group) : String := "#[allow(unused_imports)]\n" ++ s!"pub use crate::{b.module}::{b.name} as {auto};\n" -/-- The functions that get a selector besides their dispatcher (see above), -for each target by its name (`Target.name`): their bases' names. -/ -abbrev Selected := List (String × List String) - -/-- The name of the selector of the function whose base is `base`. -/ -def selectName (base : String) : String := base ++ "_select" - -/-- The selector of the function `g` (see above), given its implementations' -`arms` (none for a function whose base is its only implementation). -/ -def selector (g : Group) (arms : List Arm) : String := - let b := g.base - let auto := autoName b.name - let ty := s!"unsafe extern \"{b.target.rustAbi}\" fn{b.sig.rust}" - docComment "" (s!"The implementation of `{b.name}` that `{auto}` runs on this CPU, chosen as it \ - chooses (`VG.Rust.selector`), so that it can be called without choosing again.\n\n\ - # Safety\n\n\ - Calling the function it returns carries exactly `{auto}`'s obligations (its `# Safety` \ - section), which are those of each implementation it may return; calling this function \ - has none.") ++ - -- The type is the implementations' signature, as a pointer. - "#[allow(clippy::type_complexity)]\n" ++ - "#[inline]\n" ++ - s!"pub fn {selectName b.name}() -> {ty} " ++ "{\n" ++ - choice " " b arms ++ - "}\n" - /-- Whether `v` is a vendor of lowercase ASCII letters, digits and underscores (the text the dispatcher puts in `cfg!(target_vendor = "…")`). -/ def vendorOk (v : String) : Bool := @@ -2093,25 +2041,19 @@ def checkChoice (a : Artifact) : Except String Unit := do throw s!"{a.target.name}: {a.name} needs the feature `{f}`" /-- The dispatchers of the artifacts `as` of the module `m` of a target (see -above), with the selectors of those whose bases `selected` names, as the -text that follows its functions in its file; `names` are the names of every -artifact of the target, none of which may be a dispatcher's or a -selector's. -/ -def dispatchers (rs : List Rank) (names : List String) (m : String) (as : List Artifact) - (selected : List String := []) : Except String String := do +above), as the text that follows its functions in its file; `names` are the +names of every artifact of the target, none of which may be a +dispatcher's. -/ +def dispatchers (rs : List Rank) (names : List String) (m : String) (as : List Artifact) : + Except String String := do let gs := (groupsOf as).filter (·.base.features.isEmpty) let texts ← gs.mapM fun g => do let auto := autoName g.base.name if names.contains auto then throw s!"{g.base.target.name}: {auto} is both an artifact and the dispatcher of {g.base.name}" - let sel := selected.contains g.base.name - if sel && names.contains (selectName g.base.name) then - throw s!"{g.base.target.name}: {selectName g.base.name} is both an artifact and the \ - selector of {g.base.name}" let arms ← if g.members.isEmpty then pure [] else armsOf rs m g.base.target.name (g.members.map fun (a, s) => (Impl.ofArtifact a, s)) - let disp := if g.members.isEmpty then soleDispatcher g else dispatcher g arms - return disp ++ if sel then "\n" ++ selector g arms else "" + return if g.members.isEmpty then soleDispatcher g else dispatcher g arms return String.join (texts.map ("\n" ++ ·)) /-- The tables of functions `ts` of a target, with their implementations: in @@ -2278,14 +2220,13 @@ code has an instruction its target's printer cannot encode writable array parameter, at most its size (`checkWritten`), or its vendor or `extra` features are not names (`checkChoice`), or `ranking` (each target's, by its name) does not rank an implementation a dispatcher -calls (`dispatchers`, `checkRanks`), or `selected` names a function of a -target that has no dispatcher there (`dispatchers`); with each module's -dispatchers, and the selectors `selected` asks for, after its functions. Each check of +calls (`dispatchers`, `checkRanks`); with each module's dispatchers after its +functions. Each check of every artifact runs on `tasks` tasks (`forMPar`), one check after the other, so the error is the one checking them in order would give; what they read of an artifact more than once is computed once, on `tasks` tasks (`Prepared`, `prepareAll`). -/ -def files (as : List Artifact) (ranking : Ranking := []) (selected : Selected := []) : +def files (as : List Artifact) (ranking : Ranking := []) : Except String (List (String × String)) := do -- The same artifacts, with equal parts the same value in memory -- (`ShareCommon.shareCommon'` returns its argument): the code of every call @@ -2316,13 +2257,8 @@ def files (as : List Artifact) (ranking : Ranking := []) (selected : Selected := checkRanks t rs let arts := as.filter (·.target.name == t) let names := arts.map (·.name) - let sel := (selected.lookup t).getD [] - for n in sel do - unless (distinct arts (·.module)).any (fun m => (groupsOf (arts.filter (·.module == m))).any - fun g => g.base.name == n && g.base.features.isEmpty) do - throw s!"{t}: {n} has a selector (`VG.Dispatch.selected`) but no dispatcher" let fns ← (distinct arts (·.module)).mapM fun m => do - return ((t, m), ← dispatchers rs names m (arts.filter (·.module == m)) sel) + return ((t, m), ← dispatchers rs names m (arts.filter (·.module == m))) let tps := ps.filter (·.art.target.name == t) let rankModule (T : FnTable) : String := match T.fns.head? with | none => "" diff --git a/lean/VerifiedGarbageTest/Dispatch.lean b/lean/VerifiedGarbageTest/Dispatch.lean index 840132a6e77..427bdd99c78 100644 --- a/lean/VerifiedGarbageTest/Dispatch.lean +++ b/lean/VerifiedGarbageTest/Dispatch.lean @@ -91,49 +91,6 @@ def has (text part : String) : Bool := (text.splitOn part).length > 1 #guard has (((out.find? (·.1 == "verified-garbage-asm-aarch64/src/dispatch/mod.rs")).map (·.2)).getD "") "pub mod poly1305;\n" -/-! ## Selectors (`Rust.selector`) -/ - -/-- The files with selectors for `vg_poly1305_update` and `vg_poly1305_init`. -/ -def selOut (sel : Rust.Selected) : Except String (List (String × String)) := - Rust.files Artifacts.Poly1305.AArch64.artifacts Dispatch.ranking sel - -def selFile : String := - match selOut [("aarch64", ["vg_poly1305_update", "vg_poly1305_init"])] with - | .ok fs => ((fs.find? (·.1 == "verified-garbage-asm-aarch64/src/dispatch/poly1305.rs")).map - (·.2)).getD "" - | .error e => e - --- None unless asked for: the files are those without. -#guard !has file "_select" -#guard match selOut [] with - | .ok fs => fs == out - | .error _ => false - --- `vg_poly1305_update_select`: the dispatcher's arms, returning the function instead of calling --- it, then the base; its dispatcher is as it was. -#guard has selFile - "pub fn vg_poly1305_update_select() -> unsafe extern \"C\" fn(state: *mut [u64; 16], count: u64, \ - data: *const u8, len: usize) {\n \ - let cpu = verified_garbage_cpu::detected();\n \ - if (cfg!(target_vendor = \"apple\") || verified_garbage_cpu::requested(\ - verified_garbage_cpu::Features(verified_garbage_cpu::feature::NEON))) && \ - cpu.contains(verified_garbage_cpu::Features(verified_garbage_cpu::feature::NEON)) {\n \ - return crate::poly1305::vg_poly1305_update_neon;\n }\n \ - crate::poly1305::vg_poly1305_update\n}\n" -#guard has selFile "/// Calling the function it returns carries exactly `vg_poly1305_update_auto`'s obligations" -#guard has selFile " static CHOSEN: core::sync::atomic::AtomicPtr<()> =\n" - --- A function whose base is its only implementation returns it. -#guard has selFile - "pub fn vg_poly1305_init_select() -> unsafe extern \"C\" fn(state: *mut [u64; 16], \ - key: *const [u8; 32]) {\n crate::poly1305::vg_poly1305_init\n}\n" -#guard !has selFile "vg_poly1305_finalize_select" - --- A name that is not the base of a function with a dispatcher fails the emitter. -#guard match selOut [("aarch64", ["vg_poly1305_update_neon"])] with - | .error e => has e "vg_poly1305_update_neon has a selector (`VG.Dispatch.selected`) but no dispatcher" - | .ok _ => false - /-! ## A registration's `extra` features and `vendor` (`Artifact.extra`, `Artifact.vendor`) -/ /-- The ranking without its rule for Poly1305's `_neon`, which ranks `_neon` alone. -/ From 429fb1d840520a011d49c43b31fe0268676ee57f Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 8 Nov 2026 14:39:39 +0000 Subject: [PATCH 2/2] Emit test: the driver without VG.Dispatch.selected Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01TKUFHFCSTvQuX83u32Ae29 --- lean/VerifiedGarbageTest/Emit.lean | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lean/VerifiedGarbageTest/Emit.lean b/lean/VerifiedGarbageTest/Emit.lean index 4bf431fc9c9..68ff2591bae 100644 --- a/lean/VerifiedGarbageTest/Emit.lean +++ b/lean/VerifiedGarbageTest/Emit.lean @@ -69,13 +69,13 @@ open VG.Emit []]\n\ \n\ #assert_standard_axioms all\n\ - #assert_no_compiler_overrides all VG.Dispatch.ranking VG.Dispatch.selected run\n\ + #assert_no_compiler_overrides all VG.Dispatch.ranking run\n\ #assert_spec_origin\n\ \n\ end VG.Emit\n\ \n\ def main (args : List String) : IO UInt32 :=\n \ - VG.Emit.run VG.Emit.all VG.Dispatch.ranking args VG.Dispatch.selected\n\ + VG.Emit.run VG.Emit.all VG.Dispatch.ranking args\n\ \n\ end\n" @@ -121,13 +121,13 @@ open VG.Emit []]\n\ \n\ #assert_standard_axioms all\n\ - #assert_no_compiler_overrides all VG.Dispatch.ranking VG.Dispatch.selected run\n\ + #assert_no_compiler_overrides all VG.Dispatch.ranking run\n\ #assert_spec_origin\n\ \n\ end VG.Emit\n\ \n\ def main (args : List String) : IO UInt32 :=\n \ - VG.Emit.run VG.Emit.all VG.Dispatch.ranking args VG.Dispatch.selected\n\ + VG.Emit.run VG.Emit.all VG.Dispatch.ranking args\n\ \n\ end\n" @@ -187,13 +187,13 @@ open VG.Emit []]\n\ \n\ #assert_standard_axioms all\n\ - #assert_no_compiler_overrides all VG.Dispatch.ranking VG.Dispatch.selected run\n\ + #assert_no_compiler_overrides all VG.Dispatch.ranking run\n\ #assert_spec_origin\n\ \n\ end VG.Emit\n\ \n\ def main (args : List String) : IO UInt32 :=\n \ - VG.Emit.run VG.Emit.all VG.Dispatch.ranking args VG.Dispatch.selected\n\ + VG.Emit.run VG.Emit.all VG.Dispatch.ranking args\n\ \n\ end\n"