Skip to content

Commit 7c5cf72

Browse files
committed
[WIP] cargo-checkct
1 parent e08a2d0 commit 7c5cf72

File tree

9 files changed

+260
-0
lines changed

9 files changed

+260
-0
lines changed

.github/workflows/cargo-checkct.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: cargo-checkct
2+
3+
on:
4+
pull_request:
5+
paths-ignore:
6+
- README.md
7+
push:
8+
branches:
9+
- master
10+
paths-ignore:
11+
- README.md
12+
13+
env:
14+
CARGO_INCREMENTAL: 0
15+
RUSTFLAGS: "-Dwarnings"
16+
RUSTDOCFLAGS: "-Dwarnings"
17+
18+
jobs:
19+
build:
20+
runs-on: ubuntu-latest
21+
uses: Ledger-Donjon/action-cargo-checkct
22+
with:
23+
directory: .

checkct/.cargo/config.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[build]
2+
target = ["thumbv7em-none-eabihf", "riscv32imac-unknown-none-elf", "x86_64-unknown-linux-gnu"]
3+
4+
[target.'cfg(target_os = "linux")']
5+
rustflags = ["-C", "link-arg=-nostartfiles", "-C", "relocation-model=static"]
6+
7+
[unstable]
8+
unstable-options = true
9+
build-std = ["core", "panic_abort"]
10+
build-std-features = ["panic_immediate_abort", "compiler-builtins-mem"]

checkct/Cargo.lock

Lines changed: 98 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

checkct/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[workspace]
2+
members = ["driver"]
3+
resolver = "2"
4+
5+
[profile.release]
6+
debug = true
7+
panic = "abort"

checkct/driver/Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "driver"
3+
version = "0.0.0"
4+
publish = false
5+
edition = "2021"
6+
7+
[dependencies]
8+
rand_core = "0.6.4"
9+
checkct_macros = { path = "../../../../cargo-checkct/checkct_macros" }
10+
crypto-bigint = { path = "../.." }

checkct/driver/src/driver.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
use crate::rng::{CryptoRng, PrivateRng, PublicRng, RngCore};
2+
use checkct_macros::checkct;
3+
4+
#[checkct]
5+
pub fn checkct() {
6+
// USER CODE GOES HERE
7+
}

checkct/driver/src/main.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//----- AUTOGENERATED BY CARGO-CHECKCT: DO NOT MODIFY -----
2+
//
3+
#![no_std]
4+
#![no_main]
5+
6+
mod driver;
7+
mod rng;
8+
9+
#[no_mangle]
10+
pub extern "C" fn _start() -> ! {
11+
panic!()
12+
}
13+
14+
#[panic_handler]
15+
fn panic(_info: &core::panic::PanicInfo) -> ! {
16+
loop {}
17+
}

checkct/driver/src/rng.rs

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
//----- AUTOGENERATED BY CARGO-CHECKCT: DO NOT MODIFY -----
2+
//
3+
#[no_mangle]
4+
#[inline(never)]
5+
pub fn __checkct_private_rand() -> u8 {
6+
unsafe { core::ptr::read_volatile(0xcafe as *const u8) }
7+
}
8+
9+
#[no_mangle]
10+
#[inline(never)]
11+
pub fn __checkct_public_rand() -> u8 {
12+
unsafe { core::ptr::read_volatile(0xf00d as *const u8) }
13+
}
14+
15+
pub use rand_core::{CryptoRng, RngCore};
16+
17+
pub struct PrivateRng;
18+
19+
impl PrivateRng {
20+
pub const fn new() -> Self {
21+
Self
22+
}
23+
}
24+
25+
impl RngCore for PrivateRng {
26+
fn next_u32(&mut self) -> u32 {
27+
(__checkct_private_rand() as u32) << 24
28+
| (__checkct_private_rand() as u32) << 16
29+
| (__checkct_private_rand() as u32) << 8
30+
| (__checkct_private_rand() as u32)
31+
}
32+
33+
fn next_u64(&mut self) -> u64 {
34+
(self.next_u32() as u64) << 32 | (self.next_u32() as u64)
35+
}
36+
37+
fn fill_bytes(&mut self, dest: &mut [u8]) {
38+
for d in dest {
39+
*d = __checkct_private_rand();
40+
}
41+
}
42+
43+
fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), rand_core::Error> {
44+
self.fill_bytes(dest);
45+
Ok(())
46+
}
47+
}
48+
49+
impl CryptoRng for PrivateRng {}
50+
51+
pub struct PublicRng;
52+
53+
impl PublicRng {
54+
pub const fn new() -> Self {
55+
Self
56+
}
57+
}
58+
59+
impl RngCore for PublicRng {
60+
fn next_u32(&mut self) -> u32 {
61+
(__checkct_public_rand() as u32) << 24
62+
| (__checkct_public_rand() as u32) << 16
63+
| (__checkct_public_rand() as u32) << 8
64+
| (__checkct_public_rand() as u32)
65+
}
66+
67+
fn next_u64(&mut self) -> u64 {
68+
(self.next_u32() as u64) << 32 | (self.next_u32() as u64)
69+
}
70+
71+
fn fill_bytes(&mut self, dest: &mut [u8]) {
72+
for d in dest {
73+
*d = __checkct_public_rand();
74+
}
75+
}
76+
77+
fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), rand_core::Error> {
78+
self.fill_bytes(dest);
79+
Ok(())
80+
}
81+
}
82+
83+
impl CryptoRng for PublicRng {}

checkct/rust-toolchain.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[toolchain]
2+
channel = "nightly"
3+
targets = ["thumbv7em-none-eabihf", "riscv32imac-unknown-none-elf", "x86_64-unknown-linux-gnu"]
4+
profile = "minimal"
5+
components = ["rustfmt", "rust-src"]

0 commit comments

Comments
 (0)