Constant-time comparison of two byte slices.
(a: &[u8], b: &[u8])
| 38 | |
| 39 | /// Constant-time comparison of two byte slices. |
| 40 | pub fn constant_time_eq(a: &[u8], b: &[u8]) -> bool { |
| 41 | if a.len() != b.len() { |
| 42 | return false; |
| 43 | } |
| 44 | a.iter() |
| 45 | .zip(b.iter()) |
| 46 | .fold(0u8, |acc, (x, y)| acc | (x ^ y)) |
| 47 | == 0 |
| 48 | } |
| 49 | |
| 50 | /// Master side of the mutual authentication. |
| 51 | /// |
no outgoing calls
no test coverage detected