Function tor_llcrypto::util::ct::ct_lookup
source · pub fn ct_lookup<T, F>(array: &[T], matches: F) -> Option<&T>
Expand description
Try to find an item in a slice without leaking where and whether the item was found.
If there is any item x
in the array
for which matches(x)
is true, this function will return a reference to one such
item. (We don’t specify which.)
Otherwise, this function returns none.
We evaluate matches
on every item of the array, and try not to
leak by timing which element (if any) matched. Note that if
matches
itself has side channels, this function can’t hide them.
Note that this doesn’t necessarily do a constant-time comparison, and that it is not constant-time for the found/not-found case.