diff --git a/.gitignore b/.gitignore index 088ba6b..ed7a6ee 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,12 @@ Cargo.lock # These are backup files generated by rustfmt **/*.rs.bk + + +#Added by cargo +# +#already existing elements are commented out + +/target +#**/*.rs.bk +#Cargo.lock \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..57ed35d --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "doppio" +version = "0.1.0" +authors = ["Cathie Yun ", "Henry de Valence "] +edition = "2018" + + +[dependencies] +curve25519-dalek = "1.1.3" diff --git a/src/field.rs b/src/field.rs new file mode 100644 index 0000000..efc1d1b --- /dev/null +++ b/src/field.rs @@ -0,0 +1,81 @@ +//! Field arithmetic for the doppio curve. +//! +//! Because doppio is intended for use in ristretto255-based proof +//! systems, the scalar field of ristretto255 is the *ground field* +//! for doppio. +//! +//! This implementation is derived from the 52-bit scalar +//! implementation contributed to `curve25519-dalek` by Andrew Moon. + +use std::default::Default; +use std::ops::{Add, Mul, Sub}; + +use crate::Ristretto255Scalar; + +/// A field element modulo \\(2\^{252} + +/// 27742317777372353535851937790883648493\\), the ground field for +/// the doppio curve and the scalar field for the ristretto255 group. +#[derive(Copy, Clone, Debug)] +pub struct FieldElement([u64; 5]); + +impl Add for FieldElement { + type Output = FieldElement; + fn add(self, rhs: FieldElement) -> FieldElement { + unimplemented!(); + } +} + +impl Sub for FieldElement { + type Output = FieldElement; + fn sub(self, rhs: FieldElement) -> FieldElement { + unimplemented!(); + } +} + +impl Mul for FieldElement { + type Output = FieldElement; + fn mul(self, rhs: FieldElement) -> FieldElement { + unimplemented!(); + } +} + +impl Default for FieldElement { + fn default() -> FieldElement { + FieldElement::zero() + } +} + +impl From for FieldElement { + fn from(packed: Ristretto255Scalar) -> FieldElement { + unimplemented!(); + } +} + +impl Into for FieldElement { + fn into(self) -> Ristretto255Scalar { + unimplemented!(); + } +} + +impl FieldElement { + pub fn zero() -> FieldElement { + FieldElement([0; 5]) + } + + pub fn one() -> FieldElement { + // This needs to return 1/R mod l + unimplemented!(); + } + + pub fn invert(&self) -> FieldElement { + unimplemented!(); + } +} + +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + assert_eq!(2 + 2, 4); + } +} diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..937ea92 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,11 @@ +pub type Ristretto255Scalar = curve25519_dalek::scalar::Scalar; + +mod field; + +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + assert_eq!(2 + 2, 4); + } +}