|
1 | 1 | use core::ops::{Add, AddAssign, Mul, MulAssign}; |
| 2 | +use subtle::Choice; |
2 | 3 |
|
3 | 4 | const SECP256K1_N_0: u32 = 0xD0364141; |
4 | 5 | const SECP256K1_N_1: u32 = 0xBFD25E8C; |
@@ -69,21 +70,21 @@ impl Scalar { |
69 | 70 |
|
70 | 71 | #[must_use] |
71 | 72 | fn check_overflow(&self) -> bool { |
72 | | - let mut yes: bool = false; |
73 | | - let mut no: bool = false; |
74 | | - no = no || (self.0[7] < SECP256K1_N_7); /* No need for a > check. */ |
75 | | - no = no || (self.0[6] < SECP256K1_N_6); /* No need for a > check. */ |
76 | | - no = no || (self.0[5] < SECP256K1_N_5); /* No need for a > check. */ |
77 | | - no = no || (self.0[4] < SECP256K1_N_4); |
78 | | - yes = yes || ((self.0[4] > SECP256K1_N_4) && !no); |
79 | | - no = no || ((self.0[3] < SECP256K1_N_3) && !yes); |
80 | | - yes = yes || ((self.0[3] > SECP256K1_N_3) && !no); |
81 | | - no = no || ((self.0[2] < SECP256K1_N_2) && !yes); |
82 | | - yes = yes || ((self.0[2] > SECP256K1_N_2) && !no); |
83 | | - no = no || ((self.0[1] < SECP256K1_N_1) && !yes); |
84 | | - yes = yes || ((self.0[1] > SECP256K1_N_1) && !no); |
85 | | - yes = yes || ((self.0[0] >= SECP256K1_N_0) && !no); |
86 | | - return yes; |
| 73 | + let mut yes: Choice = 0.into(); |
| 74 | + let mut no: Choice = 0.into(); |
| 75 | + no |= Choice::from((self.0[7] < SECP256K1_N_7) as u8); /* No need for a > check. */ |
| 76 | + no |= Choice::from((self.0[6] < SECP256K1_N_6) as u8); /* No need for a > check. */ |
| 77 | + no |= Choice::from((self.0[5] < SECP256K1_N_5) as u8); /* No need for a > check. */ |
| 78 | + no |= Choice::from((self.0[4] < SECP256K1_N_4) as u8); |
| 79 | + yes |= Choice::from((self.0[4] > SECP256K1_N_4) as u8) & !no; |
| 80 | + no |= Choice::from((self.0[3] < SECP256K1_N_3) as u8) & !yes; |
| 81 | + yes |= Choice::from((self.0[3] > SECP256K1_N_3) as u8) & !no; |
| 82 | + no |= Choice::from((self.0[2] < SECP256K1_N_2) as u8) & !yes; |
| 83 | + yes |= Choice::from((self.0[2] > SECP256K1_N_2) as u8) & !no; |
| 84 | + no |= Choice::from((self.0[1] < SECP256K1_N_1) as u8) & !yes; |
| 85 | + yes |= Choice::from((self.0[1] > SECP256K1_N_1) as u8) & !no; |
| 86 | + yes |= Choice::from((self.0[0] >= SECP256K1_N_0) as u8) & !no; |
| 87 | + return yes.into(); |
87 | 88 | } |
88 | 89 |
|
89 | 90 | #[must_use] |
|
0 commit comments