We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 0b2ca10 commit e4f1350Copy full SHA for e4f1350
2 files changed
src/provenance.rs
@@ -32,3 +32,13 @@ pub fn provenance_hash(data: &[u8]) -> [u8; 32] {
32
pub fn tamper(_data: &[u8]) -> &'static [u8] {
33
b"TAMPERED: Journalist report from Jharkhand"
34
}
35
+
36
+/// Constant-time byte comparison — never short-circuits
37
+/// Prevents timing side-channel attacks on hash comparison
38
+pub fn constant_time_eq(a: &[u8; 32], b: &[u8; 32]) -> bool {
39
+ let mut result = 0u8;
40
+ for i in 0..32 {
41
+ result |= a[i] ^ b[i];
42
+ }
43
+ result == 0
44
+}
src/vfs.rs
@@ -38,7 +38,10 @@ impl FileNode {
pub fn verify(&self) -> bool {
- provenance_hash(&self.data) == self.provenance_hash
+ crate::provenance::constant_time_eq(
+ &provenance_hash(&self.data),
+ &self.provenance_hash
+)
45
46
47
0 commit comments