krypteia-silentops 0.2.0

Side-channel countermeasure toolkit: constant-time primitives, dudect-style timing leakage verifier, and shared SCA helpers for the krypteia workspace.
Documentation
// SPDX-License-Identifier: Apache-2.0
// Copyright 2026 Cédric Mesnil <cslashm@pm.me>

//! Build script: emit the `ct_thumb2` cfg for ARM targets whose ISA has the
//! Thumb-2 **IT-block** conditional execution used by the `ct::thumbv7`
//! constant-time backend. `ct/mod.rs` gates on it to pick the IT-block
//! backend (`thumbv7.rs`) vs the 2-operand Thumb-1 backend (`thumbv6m.rs`)
//! reliably across every M-profile core.
//!
//! # Why not a `cfg` / `target_feature`?
//!
//! rustc (checked on 1.96) emits **no** `target_feature = "thumb2"` for any
//! bare-metal M-profile target, and `target_has_atomic` is present on
//! `thumbv8m.base` (an M23 core that has **no** IT blocks), so neither is a
//! sound discriminator. The only reliable signal is the target triple:
//! IT blocks are valid iff the core is a Thumb-2 M-profile part — ARMv7-M
//! (`thumbv7…`) or ARMv8-M.main (`thumbv8m.main…`). ARMv6-M (`thumbv6m`) and
//! ARMv8-M.baseline (`thumbv8m.base`, Cortex-M23) have no IT.
//!
//! The `thumb` prefix is load-bearing: it excludes `armv7*` / `armv7a*`
//! (ARM/A32 state, where the `ite` instruction is undefined) while still
//! including `thumbv7a`/`thumbv7neon` (Thumb state on Cortex-A, where IT is
//! valid). See `ct/mod.rs` and the `asm-thumbv7` / `asm-thumbv6m` features.

use std::env;

fn main() {
    // Declare the cfg unconditionally so rustc's `unexpected_cfgs` lint stays
    // quiet on every target, including hosts where `ct_thumb2` is never set.
    println!("cargo::rustc-check-cfg=cfg(ct_thumb2)");

    // `TARGET` is the triple rustc compiles *for* (build scripts run on the
    // host, but this env var reflects the cross target). An empty value only
    // occurs in pathological invocations and is treated as non-thumb2 — the
    // safe direction (2-operand / generic backend, never IT on a core lacking
    // it).
    let target = env::var("TARGET").unwrap_or_default();
    if target.starts_with("thumbv7") || target.starts_with("thumbv8m.main") {
        println!("cargo::rustc-cfg=ct_thumb2");
    }

    // The target is part of Cargo's build fingerprint, so a target change
    // already re-runs this script; we only need to re-run when the script
    // itself changes.
    println!("cargo::rerun-if-changed=build.rs");
}