Skip to content

Commit 6e6239e

Browse files
authored
Merge pull request #1 from robinhundt/add-github-actions
Add github actions
2 parents ad409ce + df691c0 commit 6e6239e

File tree

29 files changed

+318
-82
lines changed

29 files changed

+318
-82
lines changed

.github/workflows/bench.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: bench
2+
3+
on:
4+
push:
5+
branches:
6+
- "main"
7+
8+
jobs:
9+
benchmarks:
10+
runs-on: "ubicloud-standard-4"
11+
steps:
12+
- name: Check out repository
13+
uses: actions/checkout@v4
14+
with:
15+
submodules: recursive
16+
- name: Install nightly
17+
uses: dtolnay/rust-toolchain@master
18+
id: toolchain
19+
with:
20+
toolchain: stable
21+
- name: Override default toolchain
22+
run: rustup override set ${{steps.toolchain.outputs.name}}
23+
- run: cargo --version
24+
- name: Install bencher
25+
uses: bencherdev/bencher@main
26+
- name: Run benchmarks
27+
run: |
28+
bencher run \
29+
--project cryprot \
30+
--token '${{ secrets.BENCHER_API_TOKEN }}' \
31+
--branch main \
32+
--testbed ubicloud-standard-4 \
33+
--github-actions '${{ secrets.GITHUB_TOKEN }}' \
34+
'cargo bench'

.github/workflows/pull_request.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: Pull Request
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- "main"
7+
env:
8+
CARGO_TERM_COLOR: always
9+
10+
jobs:
11+
test:
12+
name: Test
13+
runs-on: "${{ matrix.os }}"
14+
strategy:
15+
matrix:
16+
os: [ "ubuntu-latest", "windows-latest", "macos-14" ]
17+
steps:
18+
- name: Check out repository
19+
uses: actions/checkout@v4
20+
with:
21+
submodules: recursive
22+
- name: Install nightly
23+
uses: dtolnay/rust-toolchain@master
24+
id: toolchain
25+
with:
26+
toolchain: nightly-2025-02-14
27+
components: "rustfmt, miri"
28+
- name: Override default toolchain
29+
run: rustup override set ${{steps.toolchain.outputs.name}}
30+
- run: cargo --version
31+
- name: Install NASM
32+
if: ${{ matrix.os == 'windows-latest' }}
33+
uses: ilammy/setup-nasm@v1
34+
- name: Cache
35+
uses: Swatinem/rust-cache@v2
36+
- name: Run tests
37+
run: cargo test --workspace --verbose --all-features --no-fail-fast
38+
- name: Run miri test
39+
env:
40+
RUSTFLAGS: "-C target-cpu=native"
41+
MIRIFLAGS: "-Zmiri-disable-isolation"
42+
run: cargo miri t -p cryprot-codes -p cryprot-core
43+
lint:
44+
name: Lint
45+
runs-on: "ubuntu-latest"
46+
steps:
47+
- name: Check out repository
48+
uses: actions/checkout@v4
49+
with:
50+
submodules: recursive
51+
- name: Install nightly
52+
uses: dtolnay/rust-toolchain@master
53+
id: toolchain
54+
with:
55+
toolchain: nightly-2025-02-14
56+
components: "clippy, rustfmt"
57+
- name: Override default toolchain
58+
run: rustup override set ${{steps.toolchain.outputs.name}}
59+
- run: cargo --version
60+
- name: Cache
61+
uses: Swatinem/rust-cache@v2
62+
- name: Check formatting
63+
run: cargo fmt --all --check
64+
- name: Check Clippy
65+
run: cargo clippy --workspace --all-features --examples -- -D warnings

.github/workflows/push.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: CI
2+
3+
on: [ "push" ]
4+
5+
env:
6+
CARGO_TERM_COLOR: always
7+
8+
jobs:
9+
Test:
10+
runs-on: "ubuntu-latest"
11+
steps:
12+
- name: Check out repository
13+
uses: actions/checkout@v4
14+
with:
15+
submodules: recursive
16+
- name: Install nightly
17+
uses: dtolnay/rust-toolchain@master
18+
id: toolchain
19+
with:
20+
toolchain: nightly-2025-02-14
21+
- name: Override default toolchain
22+
run: rustup override set ${{steps.toolchain.outputs.name}}
23+
- run: cargo --version
24+
- name: Cache
25+
uses: Swatinem/rust-cache@v2
26+
- name: Test
27+
run: cargo test --workspace --verbose --all-features --no-fail-fast

.github/workflows/rustdoc.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: rustdoc
2+
3+
on:
4+
push:
5+
branches:
6+
- "main"
7+
8+
jobs:
9+
# Build job
10+
build:
11+
runs-on: "ubuntu-latest"
12+
env:
13+
# deny rustdoc warnings
14+
RUSTDOCFLAGS: -D warnings
15+
steps:
16+
- name: Check out repository
17+
uses: actions/checkout@v4
18+
with:
19+
submodules: recursive
20+
- name: Install nightly
21+
uses: dtolnay/rust-toolchain@master
22+
id: toolchain
23+
with:
24+
toolchain: nightly-2025-02-14
25+
- name: Override default toolchain
26+
run: rustup override set ${{steps.toolchain.outputs.name}}
27+
- run: cargo --version
28+
- name: Cache
29+
uses: Swatinem/rust-cache@v2
30+
- name: Create Docs
31+
run: cargo doc --workspace --verbose --all-features --no-deps -Zunstable-options -Zrustdoc-scrape-examples
32+
- name: Fix permissions
33+
run: |
34+
chmod -c -R +rX "target/doc/" | while read line; do
35+
echo "::warning title=Invalid file permissions automatically fixed::$line"
36+
done
37+
- name: Upload Pages artifact
38+
uses: actions/upload-pages-artifact@v3
39+
with:
40+
path: "target/doc/"
41+
42+
# Deploy job
43+
deploy:
44+
# Add a dependency to the build job
45+
needs: build
46+
47+
# Grant GITHUB_TOKEN the permissions required to make a Pages deployment
48+
permissions:
49+
pages: write # to deploy to Pages
50+
id-token: write # to verify the deployment originates from an appropriate source
51+
52+
# Deploy to the github-pages environment
53+
environment:
54+
name: github-pages
55+
url: ${{ steps.deployment.outputs.page_url }}
56+
57+
# Specify runner + deployment step
58+
runs-on: ubuntu-latest
59+
steps:
60+
- name: Deploy to GitHub Pages
61+
id: deployment
62+
uses: actions/deploy-pages@v4 # or specific "vX.X.X" version tag for this action
63+

cryprot-codes/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ cpufeatures.workspace = true
2323
cryprot-core.workspace = true
2424
fastdivide.workspace = true
2525
hybrid-array = { workspace = true }
26-
libote-codes = { version = "0.1.0", git = "https://github.com/robinhundt/libote-codes.git", optional = true }
2726
rand.workspace = true
2827
seq-macro.workspace = true
2928

29+
[target.'cfg(target_os = "linux")'.dependencies]
30+
libote-codes = { version = "0.1.0", git = "https://github.com/robinhundt/libote-codes.git", optional = true }
31+
3032
[dev-dependencies]
3133
criterion.workspace = true
3234

cryprot-codes/benches/bench.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ fn criterion_benchmark(c: &mut Criterion) {
3232
});
3333
}
3434

35-
#[cfg(feature = "bench-libote")]
35+
#[cfg(all(feature = "bench-libote", target_os = "linux"))]
3636
{
3737
use cryprot_codes::ex_conv::ExConvCodeConfig;
3838

cryprot-codes/src/ex_conv.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ mod tests {
269269
use bytemuck::cast_slice_mut;
270270
use cryprot_core::block::Block;
271271
#[cfg(feature = "libote-compat")]
272-
use rand::{rngs::StdRng, RngCore, SeedableRng};
272+
use rand::{RngCore, SeedableRng, rngs::StdRng};
273273

274274
use super::*;
275275

@@ -321,7 +321,7 @@ mod tests {
321321
assert_eq!(code.parity_cols(), code_size);
322322
}
323323

324-
#[cfg(feature = "libote-compat")]
324+
#[cfg(all(feature = "libote-compat", target_os = "linux"))]
325325
#[test]
326326
fn test_compare_to_libote() {
327327
let message_size = 200;
@@ -347,7 +347,7 @@ mod tests {
347347
}
348348
}
349349

350-
#[cfg(feature = "libote-compat")]
350+
#[cfg(all(feature = "libote-compat", target_os = "linux"))]
351351
#[test]
352352
fn test_compare_to_libote_bytes() {
353353
let message_size = 200;

cryprot-codes/src/ex_conv/expander.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ impl ExpanderCode {
129129
#[cfg(test)]
130130
mod tests {
131131
use bytemuck::cast_slice_mut;
132-
use rand::{rngs::StdRng, RngCore, SeedableRng};
132+
use rand::{RngCore, SeedableRng, rngs::StdRng};
133133

134134
use super::*;
135135

cryprot-codes/src/ex_conv/expander_modd.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::mem::{self};
22

3-
use bytemuck::cast_slice_mut;
3+
use bytemuck::{cast_slice, cast_slice_mut};
44
use cryprot_core::{Block, utils::log2_ceil};
55
use fastdivide::DividerU64;
66

@@ -13,7 +13,7 @@ pub(crate) struct ExpanderModd {
1313
rng: FastAesRng,
1414
mod_val: u64,
1515
idx: usize,
16-
vals: Box<[u64; RAND_U64_VALS]>,
16+
vals: Box<[Block; RAND_BLOCKS]>,
1717
mod_divider: DividerU64,
1818
m_is_pow2: bool,
1919
m_pow2_mask: u64,
@@ -22,11 +22,12 @@ pub(crate) struct ExpanderModd {
2222

2323
impl ExpanderModd {
2424
pub(crate) fn new(seed: Block, m: u64) -> Self {
25+
let vals = Box::new([Block::ZERO; RAND_BLOCKS]);
2526
let mut expander = ExpanderModd {
2627
rng: FastAesRng::new(seed),
2728
mod_val: 0,
2829
idx: 0,
29-
vals: Box::new([0; RAND_U64_VALS]),
30+
vals,
3031
mod_divider: DividerU64::divide_by(1), // Dummy initial value
3132
m_is_pow2: false,
3233
m_pow2_mask: 0,
@@ -51,12 +52,14 @@ impl ExpanderModd {
5152

5253
#[inline(always)]
5354
pub(crate) fn get(&mut self) -> usize {
54-
if self.idx == self.vals.len() {
55+
// RAND_U64_VALS is equal to len of vals: &[u64]
56+
if self.idx == RAND_U64_VALS {
5557
self.refill();
5658
}
57-
// SAFETY: self.idx is always < self.vals.len(). If self.idx == self.vals.len(),
58-
// it is set to to 0 in self.refill()
59-
let val = unsafe { *self.vals.get_unchecked(self.idx) };
59+
let vals: &[u64] = cast_slice(&self.vals[..]);
60+
// SAFETY: self.idx is always < RAND_U64_VALS == vals.len(). If self.idx ==
61+
// RAND_U64_VALS, it is set to to 0 in self.refill()
62+
let val = unsafe { *vals.get_unchecked(self.idx) };
6063
self.idx += 1;
6164
val as usize
6265
}
@@ -67,14 +70,15 @@ impl ExpanderModd {
6770
self.rng.refill();
6871

6972
let src = self.rng.blocks();
70-
let dest: &mut [Block] = cast_slice_mut(&mut self.vals[..]);
73+
let dest: &mut [Block] = &mut self.vals[..];
7174
if self.m_is_pow2 {
7275
for (dest, src) in dest.iter_mut().zip(src) {
7376
*dest = *src & self.m_pow2_mask_blk;
7477
}
7578
} else {
7679
dest.copy_from_slice(src);
77-
for chunk in self.vals.chunks_mut(32) {
80+
let vals: &mut [u64] = cast_slice_mut(&mut self.vals[..]);
81+
for chunk in vals.chunks_mut(32) {
7882
Self::do_mod32(chunk, &self.mod_divider, self.mod_val);
7983
}
8084
}

cryprot-codes/src/ex_conv/fast_aes_rng.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use bytemuck::{cast_mut, cast_ref, cast_slice, cast_slice_mut};
2-
use cryprot_core::{aes_rng::AesRng, Block};
2+
use cryprot_core::{Block, aes_rng::AesRng};
33
use rand::{RngCore, SeedableRng};
44

55
// Simple PRNG implementation for the accumulator

0 commit comments

Comments
 (0)