Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
2c4f806
[storage] initial migration to crc32c
andresilva Jan 8, 2026
3df8f05
[runtime] import crc32 module from storage
andresilva Jan 8, 2026
b1f8365
[runtime/buffer] use crc32 module
andresilva Jan 8, 2026
0a4fc66
[workspace] remove crc32fast
andresilva Jan 8, 2026
3fa093f
[runtime/crc32] more tests
andresilva Jan 8, 2026
d973254
[runtime/crc32] verify against crc crate
andresilva Jan 8, 2026
8545410
[storage] stray comment
andresilva Jan 8, 2026
5c014b4
[storage] regenerate conformance
andresilva Jan 8, 2026
d49f551
[storage] fix reference to crc32::SIZE
andresilva Jan 8, 2026
e893bfe
[cryptography] import crc32 hasher
andresilva Jan 8, 2026
8473945
[runtime] cleanup checksum size
andresilva Jan 8, 2026
ffab542
[cryptography] conformance
andresilva Jan 8, 2026
43ba668
[runtime] fix unused warnings
andresilva Jan 8, 2026
a5e3d6a
[cryptography/crc32] docs
andresilva Jan 8, 2026
3be4969
[workspace] disable default features for crc-fast
andresilva Jan 8, 2026
5b7fd7e
[cryptography/crc32] don't expose SIZE const
andresilva Jan 8, 2026
73e7855
[cryptography] enable crc-fast panic-handler
andresilva Jan 8, 2026
b5619d2
[runtime] nit
andresilva Jan 8, 2026
20b7c41
[cryptography/crc32] remove useless fill
andresilva Jan 8, 2026
985168e
[cryptography] nits
andresilva Jan 8, 2026
7fc809e
[cryptography] better arbitrary for blake3, sha256 and crc32
andresilva Jan 8, 2026
b15afea
[cryptography] regenerate conformance
andresilva Jan 8, 2026
3762114
[cryptography] update conformance
andresilva Jan 8, 2026
4cbd258
Merge branch 'main' into andre/crc32c
andresilva Jan 8, 2026
9bfaf83
[workspace] regenerate conformance
andresilva Jan 8, 2026
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
35 changes: 33 additions & 2 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ commonware-storage = { version = "0.0.64", path = "storage", default-features =
commonware-stream = { version = "0.0.64", path = "stream" }
commonware-utils = { version = "0.0.64", path = "utils", default-features = false }
console-subscriber = "0.5.0"
crc32fast = "1.5.0"
crc = "3.4.0"
crc-fast = "1.10.0"
criterion = "0.7.0"
crossterm = "0.29.0"
ctutils = "0.3.1"
Expand Down
5 changes: 4 additions & 1 deletion runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ commonware-conformance = { workspace = true, optional = true }
commonware-macros.workspace = true
commonware-parallel = { workspace = true, features = ["std"] }
commonware-utils = { workspace = true, features = ["std"] }
crc32fast.workspace = true
crc-fast.workspace = true
futures.workspace = true
governor.workspace = true
io-uring = { workspace = true, optional = true }
Expand Down Expand Up @@ -68,6 +68,9 @@ iouring-storage = [ "io-uring" ]
iouring-network = [ "io-uring" ]
tokio-console = [ "dep:console-subscriber", "tokio/tracing" ]

[dev-dependencies]
crc.workspace = true

[lib]
bench = false
crate-type = ["rlib", "cdylib"]
6 changes: 3 additions & 3 deletions runtime/src/utils/buffer/pool/append.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use crate::{
pool::{Checksum, PoolRef, Read, CHECKSUM_SIZE},
tip::Buffer,
},
Blob, Error, RwLock, RwLockWriteGuard,
Blob, Crc32, Error, RwLock, RwLockWriteGuard,
};
use commonware_utils::StableBuf;
use std::{num::NonZeroUsize, sync::Arc};
Expand Down Expand Up @@ -628,7 +628,7 @@ impl<B: Blob> Append<B> {
let logical_page = &buffer.data[start_read_idx..end_read_idx];
write_buffer.extend_from_slice(logical_page);

let crc = crc32fast::hash(logical_page);
let crc = Crc32::checksum(logical_page);
let logical_page_size_u16 =
u16::try_from(logical_page_size).expect("page size must fit in u16 for CRC record");

Expand Down Expand Up @@ -664,7 +664,7 @@ impl<B: Blob> Append<B> {
}
write_buffer.extend_from_slice(partial_page);
let partial_len = partial_page.len();
let crc = crc32fast::hash(partial_page);
let crc = Crc32::checksum(partial_page);

// Pad with zeros to fill up to logical_page_size.
write_buffer.resize(write_buffer.len() + (logical_page_size - partial_len), 0);
Expand Down
16 changes: 8 additions & 8 deletions runtime/src/utils/buffer/pool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
//! full or partial. A partial page's logical bytes are immutable on commit, and if it's re-written,
//! it's only to add more bytes after the existing ones.

use crate::{Blob, Error};
use crate::{crc32, Blob, Crc32, Error};
use bytes::{Buf, BufMut};
use commonware_codec::{EncodeFixed, FixedSize, Read as CodecRead, ReadExt, Write};
use commonware_utils::StableBuf;
Expand All @@ -38,7 +38,7 @@ pub use read::Read;
use tracing::{debug, error};

// A checksum record contains two u16 lengths and two CRCs (each 4 bytes).
const CHECKSUM_SIZE: u64 = 12;
const CHECKSUM_SIZE: u64 = (2 * u16::SIZE + 2 * crc32::SIZE) as u64;

/// Read the designated page from the underlying blob and return its logical bytes as a vector if it
/// passes the integrity check, returning error otherwise. Safely handles partial pages. Caller can
Expand Down Expand Up @@ -128,7 +128,7 @@ impl Checksum {
return None;
}

let computed_crc = crc32fast::hash(&buf[..len_usize]);
let computed_crc = Crc32::checksum(&buf[..len_usize]);
if computed_crc != crc {
debug!("Invalid CRC: doesn't match page contents. Using fallback CRC");
if crc_record.validate_fallback(buf, crc_start_idx) {
Expand Down Expand Up @@ -159,7 +159,7 @@ impl Checksum {
return false;
}

let computed_crc = crc32fast::hash(&buf[..len_usize]);
let computed_crc = Crc32::checksum(&buf[..len_usize]);
if computed_crc != crc {
debug!("Invalid fallback CRC: doesn't match page contents.");
return false;
Expand Down Expand Up @@ -335,7 +335,7 @@ mod tests {
page[..data.len()].copy_from_slice(data);

// Compute CRC of the data portion
let crc = crc32fast::hash(&page[..data.len()]);
let crc = Crc32::checksum(&page[..data.len()]);
let record = Checksum::new(data.len() as u16, crc);

// Write the CRC record at the end
Expand Down Expand Up @@ -380,7 +380,7 @@ mod tests {
// Write some data and compute correct CRC
let data = b"hello world";
page[..data.len()].copy_from_slice(data);
let crc = crc32fast::hash(&page[..data.len()]);
let crc = Crc32::checksum(&page[..data.len()]);
let record = Checksum::new(data.len() as u16, crc);

let crc_start = physical_page_size - CHECKSUM_SIZE_USIZE;
Expand All @@ -403,7 +403,7 @@ mod tests {
// Write data and compute CRC for the larger portion
let data = b"hello world, this is longer";
page[..data.len()].copy_from_slice(data);
let crc = crc32fast::hash(&page[..data.len()]);
let crc = Crc32::checksum(&page[..data.len()]);

// Create a record where len2 has the valid CRC for longer data
let record = Checksum {
Expand Down Expand Up @@ -432,7 +432,7 @@ mod tests {
// Write data
let data = b"fallback data";
page[..data.len()].copy_from_slice(data);
let valid_crc = crc32fast::hash(&page[..data.len()]);
let valid_crc = Crc32::checksum(&page[..data.len()]);
let valid_len = data.len() as u16;

// Create a record where:
Expand Down
4 changes: 2 additions & 2 deletions runtime/src/utils/buffer/pool/page_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ impl Pool {
#[cfg(test)]
mod tests {
use super::{super::Checksum, *};
use crate::{buffer::pool::CHECKSUM_SIZE, deterministic, Runner as _, Storage as _};
use crate::{buffer::pool::CHECKSUM_SIZE, deterministic, Crc32, Runner as _, Storage as _};
use commonware_macros::test_traced;
use commonware_utils::{NZUsize, NZU16};
use std::num::NonZeroU16;
Expand Down Expand Up @@ -489,7 +489,7 @@ mod tests {
for i in 0..11 {
// Write logical data followed by Checksum.
let logical_data = vec![i as u8; PAGE_SIZE.get() as usize];
let crc = crc32fast::hash(&logical_data);
let crc = Crc32::checksum(&logical_data);
let record = Checksum::new(PAGE_SIZE.get(), crc);
let mut page_data = logical_data;
page_data.extend_from_slice(&record.to_bytes());
Expand Down
4 changes: 2 additions & 2 deletions runtime/src/utils/buffer/pool/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ impl<B: Blob> Read<B> {
#[cfg(test)]
mod tests {
use super::super::{append::Append, PoolRef};
use crate::{deterministic, Blob, Error, Runner as _, Storage as _};
use crate::{deterministic, Blob, Crc32, Error, Runner as _, Storage as _};
use commonware_macros::test_traced;
use commonware_utils::{NZUsize, NZU16};
use std::num::NonZeroU16;
Expand Down Expand Up @@ -448,7 +448,7 @@ mod tests {
// Corrupt page 0 to claim a shorter (partial) length with a valid CRC.
let page_size = PAGE_SIZE.get() as u64;
let short_len = page_size / 2;
let crc = crc32fast::hash(&data[..short_len as usize]);
let crc = Crc32::checksum(&data[..short_len as usize]);
let record = super::Checksum::new(short_len as u16, crc);
let crc_offset = page_size; // CRC record starts after logical page bytes
blob.write_at(record.to_bytes().to_vec(), crc_offset)
Expand Down
Loading
Loading