diff --git a/.github/workflows/cargo-checkct.yml b/.github/workflows/cargo-checkct.yml new file mode 100644 index 000000000..fa527d0e7 --- /dev/null +++ b/.github/workflows/cargo-checkct.yml @@ -0,0 +1,28 @@ +name: cargo-checkct + +on: + pull_request: + paths-ignore: + - README.md + push: + branches: + - master + paths-ignore: + - README.md + +env: + CARGO_INCREMENTAL: 0 + RUSTFLAGS: "-Dwarnings" + RUSTDOCFLAGS: "-Dwarnings" + +jobs: + checkct: + name: Run cargo-checkct + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - uses: Ledger-Donjon/action-cargo-checkct@v1 + with: + directory: . diff --git a/checkct/.cargo/config.toml b/checkct/.cargo/config.toml new file mode 100644 index 000000000..9c036e0aa --- /dev/null +++ b/checkct/.cargo/config.toml @@ -0,0 +1,10 @@ +[build] +target = ["thumbv7em-none-eabihf", "riscv32imac-unknown-none-elf", "x86_64-unknown-linux-gnu"] + +[target.'cfg(target_os = "linux")'] +rustflags = ["-C", "link-arg=-nostartfiles", "-C", "relocation-model=static"] + +[unstable] +unstable-options = true +build-std = ["core", "panic_abort"] +build-std-features = ["panic_immediate_abort", "compiler-builtins-mem"] diff --git a/checkct/Cargo.lock b/checkct/Cargo.lock new file mode 100644 index 000000000..4c5ab1043 --- /dev/null +++ b/checkct/Cargo.lock @@ -0,0 +1,98 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "autocfg" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" + +[[package]] +name = "checkct_macros" +version = "0.1.0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "crypto-bigint" +version = "0.7.0-pre.3" +dependencies = [ + "num-traits", + "rand_core 0.9.3", + "subtle", +] + +[[package]] +name = "driver" +version = "0.0.0" +dependencies = [ + "checkct_macros", + "crypto-bigint", + "rand_core 0.6.4", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "proc-macro2" +version = "1.0.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" + +[[package]] +name = "rand_core" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38" + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.101" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ce2b7fc941b3a24138a0a7cf8e858bfc6a992e7978a068a5c760deb0ed43caf" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" diff --git a/checkct/Cargo.toml b/checkct/Cargo.toml new file mode 100644 index 000000000..2c89b753a --- /dev/null +++ b/checkct/Cargo.toml @@ -0,0 +1,7 @@ +[workspace] +members = ["driver"] +resolver = "2" + +[profile.release] +debug = true +panic = "abort" diff --git a/checkct/driver/Cargo.toml b/checkct/driver/Cargo.toml new file mode 100644 index 000000000..67cf950e5 --- /dev/null +++ b/checkct/driver/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "driver" +version = "0.0.0" +publish = false +edition = "2021" + +[dependencies] +rand_core = "0.6.4" +checkct_macros = { path = "../../cargo-checkct/checkct_macros" } +crypto-bigint = { path = "../.." } diff --git a/checkct/driver/src/driver.rs b/checkct/driver/src/driver.rs new file mode 100644 index 000000000..ad8cee040 --- /dev/null +++ b/checkct/driver/src/driver.rs @@ -0,0 +1,7 @@ +use crate::rng::{CryptoRng, PrivateRng, PublicRng, RngCore}; +use checkct_macros::checkct; + +#[checkct] +pub fn checkct() { + // USER CODE GOES HERE +} diff --git a/checkct/driver/src/main.rs b/checkct/driver/src/main.rs new file mode 100644 index 000000000..6c25eeb54 --- /dev/null +++ b/checkct/driver/src/main.rs @@ -0,0 +1,17 @@ +//----- AUTOGENERATED BY CARGO-CHECKCT: DO NOT MODIFY ----- +// +#![no_std] +#![no_main] + +mod driver; +mod rng; + +#[no_mangle] +pub extern "C" fn _start() -> ! { + panic!() +} + +#[panic_handler] +fn panic(_info: &core::panic::PanicInfo) -> ! { + loop {} +} diff --git a/checkct/driver/src/rng.rs b/checkct/driver/src/rng.rs new file mode 100644 index 000000000..5a1f188bf --- /dev/null +++ b/checkct/driver/src/rng.rs @@ -0,0 +1,83 @@ +//----- AUTOGENERATED BY CARGO-CHECKCT: DO NOT MODIFY ----- +// +#[no_mangle] +#[inline(never)] +pub fn __checkct_private_rand() -> u8 { + unsafe { core::ptr::read_volatile(0xcafe as *const u8) } +} + +#[no_mangle] +#[inline(never)] +pub fn __checkct_public_rand() -> u8 { + unsafe { core::ptr::read_volatile(0xf00d as *const u8) } +} + +pub use rand_core::{CryptoRng, RngCore}; + +pub struct PrivateRng; + +impl PrivateRng { + pub const fn new() -> Self { + Self + } +} + +impl RngCore for PrivateRng { + fn next_u32(&mut self) -> u32 { + (__checkct_private_rand() as u32) << 24 + | (__checkct_private_rand() as u32) << 16 + | (__checkct_private_rand() as u32) << 8 + | (__checkct_private_rand() as u32) + } + + fn next_u64(&mut self) -> u64 { + (self.next_u32() as u64) << 32 | (self.next_u32() as u64) + } + + fn fill_bytes(&mut self, dest: &mut [u8]) { + for d in dest { + *d = __checkct_private_rand(); + } + } + + fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), rand_core::Error> { + self.fill_bytes(dest); + Ok(()) + } +} + +impl CryptoRng for PrivateRng {} + +pub struct PublicRng; + +impl PublicRng { + pub const fn new() -> Self { + Self + } +} + +impl RngCore for PublicRng { + fn next_u32(&mut self) -> u32 { + (__checkct_public_rand() as u32) << 24 + | (__checkct_public_rand() as u32) << 16 + | (__checkct_public_rand() as u32) << 8 + | (__checkct_public_rand() as u32) + } + + fn next_u64(&mut self) -> u64 { + (self.next_u32() as u64) << 32 | (self.next_u32() as u64) + } + + fn fill_bytes(&mut self, dest: &mut [u8]) { + for d in dest { + *d = __checkct_public_rand(); + } + } + + fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), rand_core::Error> { + self.fill_bytes(dest); + Ok(()) + } +} + +impl CryptoRng for PublicRng {} diff --git a/checkct/rust-toolchain.toml b/checkct/rust-toolchain.toml new file mode 100644 index 000000000..e1fba38cf --- /dev/null +++ b/checkct/rust-toolchain.toml @@ -0,0 +1,5 @@ +[toolchain] +channel = "nightly" +targets = ["thumbv7em-none-eabihf", "riscv32imac-unknown-none-elf", "x86_64-unknown-linux-gnu"] +profile = "minimal" +components = ["rustfmt", "rust-src"]