1use alloc::vec::Vec;
2
3use elliptic_curve::subtle::{Choice, ConditionallySelectable, ConstantTimeEq};
4use openvm_algebra_guest::IntMod;
5
6use crate::internal::P256Coord;
7
8impl Copy for P256Coord {}
11
12impl Default for P256Coord {
13 fn default() -> Self {
14 <Self as IntMod>::ZERO
15 }
16}
17
18impl ConditionallySelectable for P256Coord {
19 fn conditional_select(a: &P256Coord, b: &P256Coord, choice: Choice) -> P256Coord {
20 P256Coord::from_le_bytes_unchecked(
21 &a.as_le_bytes()
22 .iter()
23 .zip(b.as_le_bytes().iter())
24 .map(|(a, b)| u8::conditional_select(a, b, choice))
25 .collect::<Vec<_>>(),
26 )
27 }
28}
29
30impl ConstantTimeEq for P256Coord {
31 fn ct_eq(&self, other: &P256Coord) -> Choice {
32 #[cfg(not(target_os = "zkvm"))]
33 {
34 self.as_le_bytes().ct_eq(other.as_le_bytes())
36 }
37 #[cfg(target_os = "zkvm")]
38 {
39 Choice::from((self == other) as u8)
42 }
43 }
44}