generic_array/ext_impls/
impl_subtle.rs1use subtle::{ConditionallySelectable, ConstantTimeEq};
2
3use crate::{ArrayLength, GenericArray};
4
5impl<T, N: ArrayLength> ConstantTimeEq for GenericArray<T, N>
6where
7 T: ConstantTimeEq,
8{
9 #[inline]
10 fn ct_eq(&self, other: &Self) -> subtle::Choice {
11 self.as_slice().ct_eq(other.as_slice())
12 }
13}
14
15impl<T, N: ArrayLength> ConditionallySelectable for GenericArray<T, N>
16where
17 GenericArray<T, N>: Copy,
18 T: ConditionallySelectable,
19{
20 #[inline]
21 fn conditional_select(a: &Self, b: &Self, choice: subtle::Choice) -> Self {
22 let mut out = *a;
23 out.conditional_assign(b, choice);
24 out
25 }
26
27 #[inline]
28 fn conditional_assign(&mut self, other: &Self, choice: subtle::Choice) {
29 for (a, b) in self.iter_mut().zip(other.iter()) {
30 a.conditional_assign(b, choice);
31 }
32 }
33}