|
1 | 1 | use core::marker::PhantomData;
|
2 | 2 |
|
3 |
| -use subtle::{Choice, ConditionallySelectable}; |
| 3 | +use subtle::{Choice, ConditionallySelectable, ConstantTimeEq}; |
4 | 4 |
|
5 |
| -use crate::{Limb, UInt}; |
| 5 | +use crate::{Limb, UInt, Zero}; |
6 | 6 |
|
7 | 7 | use super::{reduction::montgomery_reduction, GenericResidue};
|
8 | 8 |
|
|
50 | 50 | }
|
51 | 51 |
|
52 | 52 | impl<MOD: ResidueParams<LIMBS>, const LIMBS: usize> Residue<MOD, LIMBS> {
|
| 53 | + /// The representation of 0 mod `MOD`. |
| 54 | + pub const ZERO: Self = Self { |
| 55 | + montgomery_form: UInt::<LIMBS>::ZERO, |
| 56 | + phantom: PhantomData, |
| 57 | + }; |
| 58 | + |
53 | 59 | /// The representation of 1 mod `MOD`.
|
54 | 60 | pub const ONE: Self = Self {
|
55 | 61 | montgomery_form: MOD::R,
|
@@ -100,3 +106,19 @@ impl<MOD: ResidueParams<LIMBS> + Copy, const LIMBS: usize> ConditionallySelectab
|
100 | 106 | }
|
101 | 107 | }
|
102 | 108 | }
|
| 109 | + |
| 110 | +impl<MOD: ResidueParams<LIMBS>, const LIMBS: usize> ConstantTimeEq for Residue<MOD, LIMBS> { |
| 111 | + fn ct_eq(&self, other: &Self) -> Choice { |
| 112 | + self.montgomery_form.ct_eq(&other.montgomery_form) |
| 113 | + } |
| 114 | +} |
| 115 | + |
| 116 | +impl<MOD: ResidueParams<LIMBS>, const LIMBS: usize> Default for Residue<MOD, LIMBS> { |
| 117 | + fn default() -> Self { |
| 118 | + Self::ZERO |
| 119 | + } |
| 120 | +} |
| 121 | + |
| 122 | +impl<MOD: ResidueParams<LIMBS>, const LIMBS: usize> Zero for Residue<MOD, LIMBS> { |
| 123 | + const ZERO: Self = Self::ZERO; |
| 124 | +} |
0 commit comments