mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-07 21:13:44 +02:00
Make secure_eq more versatile.
This commit is contained in:
parent
4db2cfdc8c
commit
5114df03d9
1 changed files with 3 additions and 1 deletions
|
@ -14,7 +14,9 @@ pub mod x25519;
|
||||||
pub const ZEROES: [u8; 64] = [0_u8; 64];
|
pub const ZEROES: [u8; 64] = [0_u8; 64];
|
||||||
|
|
||||||
/// Constant time byte slice equality.
|
/// Constant time byte slice equality.
|
||||||
pub fn secure_eq(a: &[u8], b: &[u8]) -> bool {
|
#[inline]
|
||||||
|
pub fn secure_eq<A: AsRef<[u8]> + ?Sized, B: AsRef<[u8]> + ?Sized>(a: &A, b: &B) -> bool {
|
||||||
|
let (a, b) = (a.as_ref(), b.as_ref());
|
||||||
if a.len() == b.len() {
|
if a.len() == b.len() {
|
||||||
let mut x = 0u8;
|
let mut x = 0u8;
|
||||||
for (aa, bb) in a.iter().zip(b.iter()) {
|
for (aa, bb) in a.iter().zip(b.iter()) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue