Skip to content

[WIP] cargo-checkct #796

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/cargo-checkct.yml
Original file line number Diff line number Diff line change
@@ -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: .
10 changes: 10 additions & 0 deletions checkct/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -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"]
98 changes: 98 additions & 0 deletions checkct/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions checkct/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[workspace]
members = ["driver"]
resolver = "2"

[profile.release]
debug = true
panic = "abort"
10 changes: 10 additions & 0 deletions checkct/driver/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 = "../.." }
7 changes: 7 additions & 0 deletions checkct/driver/src/driver.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use crate::rng::{CryptoRng, PrivateRng, PublicRng, RngCore};
use checkct_macros::checkct;

#[checkct]
pub fn checkct() {
// USER CODE GOES HERE
}
17 changes: 17 additions & 0 deletions checkct/driver/src/main.rs
Original file line number Diff line number Diff line change
@@ -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 {}
}
83 changes: 83 additions & 0 deletions checkct/driver/src/rng.rs
Original file line number Diff line number Diff line change
@@ -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 {}
5 changes: 5 additions & 0 deletions checkct/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -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"]
Loading