ed448_goldilocks/ristretto/
ristretto.rs

1#![allow(non_snake_case)]
2
3use crate::curve::twedwards::extended::ExtendedPoint;
4use std::fmt;
5use subtle::{Choice, ConstantTimeEq};
6
7pub struct RistrettoPoint(ExtendedPoint);
8
9#[derive(Copy, Clone)]
10pub struct CompressedRistretto([u8; 56]);
11
12impl fmt::Debug for CompressedRistretto {
13    fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
14        self.0[..].fmt(formatter)
15    }
16}
17
18impl ConstantTimeEq for CompressedRistretto {
19    fn ct_eq(&self, other: &CompressedRistretto) -> Choice {
20        self.as_bytes().ct_eq(other.as_bytes())
21    }
22}
23
24impl PartialEq for CompressedRistretto {
25    fn eq(&self, other: &CompressedRistretto) -> bool {
26        self.ct_eq(other).into()
27    }
28}
29impl Eq for CompressedRistretto {}
30
31impl CompressedRistretto {
32    pub fn as_bytes(&self) -> &[u8] {
33        &self.0
34    }
35}
36
37impl RistrettoPoint {
38    pub fn identity() -> RistrettoPoint {
39        RistrettoPoint(ExtendedPoint::identity())
40    }
41
42    pub fn equals(&self, other: &RistrettoPoint) -> bool {
43        let XY = self.0.X * other.0.Y;
44        let YX = self.0.Y * other.0.X;
45        XY == YX
46    }
47
48    pub fn encode(&self) -> CompressedRistretto {
49        todo!()
50    }
51}
52
53impl CompressedRistretto {
54    pub fn identity() -> CompressedRistretto {
55        CompressedRistretto([0; 56])
56    }
57
58    pub fn decode(&self) -> Option<RistrettoPoint> {
59        todo!()
60    }
61}