aboutsummaryrefslogtreecommitdiff
path: root/src/crypto.rs
diff options
context:
space:
mode:
authorDaniel García <[email protected]>2019-02-11 23:45:55 +0100
committerDaniel García <[email protected]>2019-02-11 23:45:55 +0100
commit9636f33fdbc070afcc80321359621c3bfe75535d (patch)
treed0e58f50e9949d551d149148e34144d29619b49e /src/crypto.rs
parentbbe2a1b264b5ef4d8eba6643857a03e905ff9dec (diff)
downloadvaultwarden-9636f33fdbc070afcc80321359621c3bfe75535d.tar.gz
vaultwarden-9636f33fdbc070afcc80321359621c3bfe75535d.zip
Implement constant time equal check for admin, 2fa recover and 2fa remember tokens
Diffstat (limited to 'src/crypto.rs')
-rw-r--r--src/crypto.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/crypto.rs b/src/crypto.rs
index 9321f25f..628afcd0 100644
--- a/src/crypto.rs
+++ b/src/crypto.rs
@@ -36,3 +36,12 @@ pub fn get_random(mut array: Vec<u8>) -> Vec<u8> {
array
}
+
+//
+// Constant time compare
+//
+pub fn ct_eq<T: AsRef<[u8]>, U: AsRef<[u8]>>(a: T, b: U) -> bool {
+ use ring::constant_time::verify_slices_are_equal;
+
+ verify_slices_are_equal(a.as_ref(), b.as_ref()).is_ok()
+}