Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add field arithmetic skeleton #7

Merged
merged 3 commits into from
Apr 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 9 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "doppio"
version = "0.1.0"
authors = ["Cathie Yun <[email protected]>", "Henry de Valence <[email protected]>"]
edition = "2018"


[dependencies]
curve25519-dalek = "1.1.3"
81 changes: 81 additions & 0 deletions src/field.rs
Original file line number Diff line number Diff line change
@@ -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<FieldElement> for FieldElement {
type Output = FieldElement;
fn add(self, rhs: FieldElement) -> FieldElement {
unimplemented!();
}
}

impl Sub<FieldElement> for FieldElement {
type Output = FieldElement;
fn sub(self, rhs: FieldElement) -> FieldElement {
unimplemented!();
}
}

impl Mul<FieldElement> for FieldElement {
type Output = FieldElement;
fn mul(self, rhs: FieldElement) -> FieldElement {
unimplemented!();
}
}

impl Default for FieldElement {
fn default() -> FieldElement {
FieldElement::zero()
}
}

impl From<Ristretto255Scalar> for FieldElement {
fn from(packed: Ristretto255Scalar) -> FieldElement {
unimplemented!();
}
}

impl Into<Ristretto255Scalar> 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);
}
}
11 changes: 11 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -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);
}
}