Skip to content

Commit 093c282

Browse files
committed
Expand high assurance feature checks
1 parent 1da208f commit 093c282

3 files changed

Lines changed: 73 additions & 0 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
enforcement.
2626
- Added the optional Linux `guard-pages` feature with `GuardedSecretVec` for
2727
dynamic byte secrets stored between inaccessible pages.
28+
- Expanded the local check matrix and examples for optional high-assurance
29+
features.
2830
- Updated README, safety notes, and threat model for the new clearing model.
2931

3032
## 1.0.0-rc.4

‎examples/high_assurance.rs‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#[cfg(feature = "std")]
2+
use sanitization::ExpiringSecretBytes;
3+
#[cfg(all(
4+
feature = "guard-pages",
5+
target_os = "linux",
6+
any(target_arch = "x86_64", target_arch = "aarch64"),
7+
not(miri)
8+
))]
9+
use sanitization::GuardedSecretVec;
10+
#[cfg(all(
11+
feature = "memory-lock",
12+
target_os = "linux",
13+
any(target_arch = "x86_64", target_arch = "aarch64")
14+
))]
15+
use sanitization::LockedSecretBytes;
16+
#[cfg(all(feature = "cache-flush", target_arch = "x86_64", not(miri)))]
17+
use sanitization::{cache_flush::cache_flush_sanitize_bytes, SecretBytes};
18+
19+
fn main() {
20+
#[cfg(feature = "std")]
21+
{
22+
let mut key =
23+
ExpiringSecretBytes::<32>::from_array([7; 32], std::time::Duration::from_secs(300));
24+
assert_eq!(key.try_constant_time_eq(&[7; 32]), Ok(true));
25+
}
26+
27+
#[cfg(all(
28+
feature = "memory-lock",
29+
target_os = "linux",
30+
any(target_arch = "x86_64", target_arch = "aarch64")
31+
))]
32+
{
33+
let mut key = LockedSecretBytes::<32>::from_array([9; 32]).unwrap();
34+
assert!(key.constant_time_eq(&[9; 32]));
35+
key.secure_clear();
36+
}
37+
38+
#[cfg(all(feature = "cache-flush", target_arch = "x86_64", not(miri)))]
39+
{
40+
let mut scratch = [0xA5; 32];
41+
cache_flush_sanitize_bytes(&mut scratch);
42+
assert_eq!(scratch, [0; 32]);
43+
44+
let mut key = SecretBytes::<32>::from_array([1; 32]);
45+
key.secure_clear_and_flush();
46+
assert!(key.constant_time_eq(&[0; 32]));
47+
}
48+
49+
#[cfg(all(
50+
feature = "guard-pages",
51+
target_os = "linux",
52+
any(target_arch = "x86_64", target_arch = "aarch64"),
53+
not(miri)
54+
))]
55+
{
56+
let mut token = GuardedSecretVec::from_slice(b"session-key").unwrap();
57+
token.extend_from_slice(b"-v2").unwrap();
58+
assert_eq!(token.with_secret(|bytes| bytes.len()), 14);
59+
token.clear_secret();
60+
}
61+
}

‎scripts/checks.sh‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,21 @@ set -euo pipefail
44
cargo fmt --check
55
cargo test
66
cargo test --features alloc
7+
cargo test --features std
8+
cargo test --features memory-lock
9+
cargo test --features asm-compare
10+
cargo test --features cache-flush
11+
cargo test --features guard-pages
712
cargo test --features unsafe-wipe
813
cargo test --features unsafe-wipe,alloc
914
cargo test --all-features
1015
cargo check --examples
1116
cargo check --examples --features alloc
17+
cargo check --examples --features std
18+
cargo check --examples --features memory-lock
19+
cargo check --examples --features asm-compare
20+
cargo check --examples --features cache-flush
21+
cargo check --examples --features guard-pages
1222
cargo check --examples --features unsafe-wipe
1323
cargo check --examples --all-features
1424
cargo clippy --all-targets --no-default-features -- -D warnings

0 commit comments

Comments
 (0)