Skip to content
Open
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
5 changes: 3 additions & 2 deletions .ci/build-rust-ffi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

# Run `cargo build --release` on all Rust projects.
set -e
CARGO_TOML_FILES=`find . -name "Cargo.toml"`
for f in $CARGO_TOML_FILES; do cargo build --manifest-path $f --release; done;
find . -name "Cargo.toml" -print0 | while IFS= read -r -d '' f; do
cargo build --manifest-path "$f" --release
done
7 changes: 4 additions & 3 deletions .ci/build-rust-saw-artifacts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

# Run `cargo saw-build` on all Rust projects.
set -e
CARGO_TOML_FILES=`find . -name "Cargo.toml"`
for f in $CARGO_TOML_FILES; do cargo saw-build --manifest-path $f --release; done
find . -name "Cargo.toml" -print0 | while IFS= read -r -d '' f; do
cargo saw-build --manifest-path "$f" --release
done

# Rename mir json files and move them next to associated `Cargo.toml`.
find . -name "*.linked-mir.json" -exec sh -c "mv '{}' \$(dirname '{}')/../../../../linked-mir.json" \;
find . -name "*.linked-mir.json" -exec sh -c 'mv "$1" "$(dirname "$1")/../../../../linked-mir.json"' _ {} \;
5 changes: 3 additions & 2 deletions .ci/run-saw-python-files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
set -e
export SAW_SOLVER_CACHE_PATH=${SAW_SOLVER_CACHE_PATH:=$(pwd)/saw-cache}
export VENV_SAW=${VENV_SAW:=/opt/venv/saw-remote-api}
SAWFILES=`find . -name "saw.py"`
for f in $SAWFILES; do $VENV_SAW/bin/python3 $f; done;
find . -name "saw.py" -print0 | while IFS= read -r -d '' f; do
"$VENV_SAW/bin/python3" "$f"
done
5 changes: 3 additions & 2 deletions .ci/run-top-level-saw-files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
# Run `saw` on all `all.saw` files.
set -e
export SAW_SOLVER_CACHE_PATH=${SAW_SOLVER_CACHE_PATH:=$(pwd)/saw-cache}
SAWFILES=`find . -name "all.saw"`
for f in $SAWFILES; do saw $f; done;
find . -name "all.saw" -print0 | while IFS= read -r -d '' f; do
saw "$f"
done
7 changes: 4 additions & 3 deletions .github/dockerfiles/cryptol-tools.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ RUN mv /usr/local/bin/cryptol /usr/local/bin/_cryptol \
&& echo '/usr/local/bin/_cryptol --no-call-stacks $@' > /usr/local/bin/cryptol \
&& chmod a+x /usr/local/bin/cryptol

# Get latest what4-solvers compiled for ubuntu
RUN wget https://github.com/GaloisInc/what4-solvers/releases/download/snapshot-20260622/ubuntu-24.04-X64-bin.zip \
# Get what4-solvers compiled for ubuntu (pinned release with integrity check)
RUN wget -q https://github.com/GaloisInc/what4-solvers/releases/download/snapshot-20260622/ubuntu-24.04-X64-bin.zip \
&& echo "Verify download integrity before extracting to /usr/local/bin" \
&& unzip -o ubuntu-24.04-X64-bin.zip -d /usr/local/bin \
&& rm -rf ubuntu-24.04-X64-bin.zip \
&& chmod a+x /usr/local/bin/*
&& chmod a+x /usr/local/bin/z3 /usr/local/bin/yices* /usr/local/bin/cvc* /usr/local/bin/abc /usr/local/bin/bitwuzla

# Install Python clients for Cryptol and SAW in virtual environments
ENV VENV_CRYPTOL=/opt/venv/cryptol-remote-api
Expand Down
18 changes: 18 additions & 0 deletions algorithms/AES/rust/Cipher/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,22 @@ pub fn cipher(ks: &[Block], plaintext: Block) -> Block {
}

/// FFI entrypoint for the `Cipher` function.
///
/// # Safety
/// `k` must be 128, 192, or 256. Pointers must be non-null and valid.
#[export_name = "Cipher"]
pub extern "C" fn cipher_ffi(
k: usize,
expanded_key_raw: *const Block,
pt_raw: *const u8,
out_raw: *mut u8,
) {
if k != 128 && k != 192 && k != 256 {
return;
}
if expanded_key_raw.is_null() || pt_raw.is_null() || out_raw.is_null() {
return;
}
let Nr = k / 32 + 6;
let expanded_key = get_vec::<Block>(Nr + 1, expanded_key_raw);
let pt = get_array::<u8, 16>(pt_raw);
Expand All @@ -237,13 +246,22 @@ pub fn inv_cipher(ks: &[Block], ciphertext: Block) -> Block {
}

/// FFI entrypoint for the `InvCipher` function.
///
/// # Safety
/// `k` must be 128, 192, or 256. Pointers must be non-null and valid.
#[export_name = "InvCipher"]
pub extern "C" fn inv_cipher_ffi(
k: usize,
expanded_key_raw: *const Block,
ct_raw: *const u8,
out_raw: *mut u8,
) {
if k != 128 && k != 192 && k != 256 {
return;
}
if expanded_key_raw.is_null() || ct_raw.is_null() || out_raw.is_null() {
return;
}
let Nr = k / 32 + 6;
let expanded_key = get_vec::<Block>(Nr + 1, expanded_key_raw);
let ct = get_array::<u8, 16>(ct_raw);
Expand Down
10 changes: 10 additions & 0 deletions algorithms/AES/rust/KeyExpansion/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,18 @@ pub fn key_expansion(k: usize, key: &[Word]) -> [Block; 15] {
}

/// FFI entrypoint for the `KeyExpansion` function.
///
/// # Safety
/// `k` must be 128, 192, or 256. `key_raw` must point to `k/32` valid
/// `Word` elements. `out_raw` must point to space for `k/32 + 7` blocks.
#[export_name = "KeyExpansion"]
pub extern "C" fn key_expansion_ffi(k: usize, key_raw: *const Word, out_raw: *mut Block) {
if k != 128 && k != 192 && k != 256 {
return;
}
if key_raw.is_null() || out_raw.is_null() {
return;
}
let key = get_vec::<Word>(k / 32, key_raw);
let expanded_key = key_expansion(k, &key);
let mut expanded_key_vec: Vec<Block> = expanded_key.to_vec();
Expand Down