arcis_compiler/utils/
curve_point.rs1use crate::{
2 traits::{Reveal, ToMontgomery},
3 utils::{
4 elliptic_curve::AffineEdwardsPoint,
5 field::{BaseField, ScalarField},
6 },
7};
8use curve25519_dalek_arcium_fork::{
9 field::FieldElement,
10 EdwardsPoint,
11 RistrettoPoint as ArcisRistrettoPoint,
12};
13use primitives::algebra::elliptic_curve::{Curve25519Ristretto, Point, Scalar};
14use std::ops::Mul;
15
16pub trait Curve: Clone + Copy + Reveal {
17 fn generator() -> Self;
18}
19
20pub type CurvePoint = Point<Curve25519Ristretto>;
21
22impl Mul<CurvePoint> for ScalarField {
23 type Output = CurvePoint;
24
25 fn mul(self, rhs: CurvePoint) -> Self::Output {
26 rhs * Scalar::<Curve25519Ristretto>::from_le_bytes(&self.to_le_bytes()).unwrap()
27 }
28}
29
30impl Reveal for CurvePoint {
31 fn reveal(self) -> Self {
32 self
33 }
34}
35
36impl ToMontgomery for CurvePoint {
37 type Output = BaseField;
38
39 fn to_montgomery(self, _is_expected_non_identity: bool) -> (BaseField, BaseField) {
40 AffineEdwardsPoint::from(self).to_montgomery(true)
42 }
43}
44
45impl Curve for CurvePoint {
46 fn generator() -> Self {
47 Self::generator()
48 }
49}
50
51impl From<AffineEdwardsPoint<BaseField>> for CurvePoint {
52 fn from(value: AffineEdwardsPoint<BaseField>) -> Self {
53 let x = FieldElement::from_bytes(&value.x.to_le_bytes());
54 let y = FieldElement::from_bytes(&value.y.to_le_bytes());
55 let xy = FieldElement::from_bytes(&(value.x * value.y).to_le_bytes());
56 Self::new(ArcisRistrettoPoint::new_unchecked(
57 EdwardsPoint::new_unchecked(x, y, FieldElement::ONE, xy),
58 ))
59 }
60}