Skip to main content

crypto_bigint/modular/boxed_monty_form/
ct.rs

1//! Constant-time support: impls of `Ct*` traits.
2
3use super::{BoxedMontyForm, BoxedMontyParams};
4use crate::{Choice, CtAssign, CtEq, CtSelect};
5use ctutils::{CtAssignSlice, CtEqSlice, CtSelectUsingCtAssign};
6
7impl CtAssign for BoxedMontyForm {
8    #[inline]
9    fn ct_assign(&mut self, other: &Self, choice: Choice) {
10        self.montgomery_form
11            .ct_assign(&other.montgomery_form, choice);
12        self.params.ct_assign(&other.params, choice);
13    }
14}
15impl CtAssignSlice for BoxedMontyForm {}
16
17impl CtEq for BoxedMontyForm {
18    fn ct_eq(&self, other: &Self) -> Choice {
19        self.montgomery_form.ct_eq(&other.montgomery_form) & self.params.ct_eq(&other.params)
20    }
21}
22impl CtEqSlice for BoxedMontyForm {}
23
24impl CtSelectUsingCtAssign for BoxedMontyForm {}
25
26impl CtAssign for BoxedMontyParams {
27    fn ct_assign(&mut self, other: &Self, choice: Choice) {
28        *self = self.ct_select(other, choice);
29    }
30}
31
32impl CtEq for BoxedMontyParams {
33    fn ct_eq(&self, other: &Self) -> Choice {
34        self.modulus().ct_eq(other.modulus())
35            & self.one().ct_eq(other.one())
36            & self.r2().ct_eq(other.r2())
37            & self.mod_inv().ct_eq(&other.mod_inv())
38    }
39}
40impl CtEqSlice for BoxedMontyParams {}
41
42impl CtSelect for BoxedMontyParams {
43    fn ct_select(&self, other: &Self, choice: Choice) -> Self {
44        self.as_ref().ct_select(other.as_ref(), choice).into()
45    }
46}