Make EdwardsPoint (x, y) not public.

This commit is contained in:
Sean Bowe 2018-03-06 08:38:34 -07:00
parent f155c01cf5
commit 7a9879eb54
No known key found for this signature in database
GPG Key ID: 95684257D8F8B031
3 changed files with 17 additions and 15 deletions

View File

@ -32,8 +32,8 @@ use super::boolean::Boolean;
#[derive(Clone)]
pub struct EdwardsPoint<E: Engine> {
pub x: AllocatedNum<E>,
pub y: AllocatedNum<E>
x: AllocatedNum<E>,
y: AllocatedNum<E>
}
/// Perform a fixed-base scalar multiplication with
@ -84,6 +84,14 @@ pub fn fixed_base_multiplication<E, CS>(
}
impl<E: JubjubEngine> EdwardsPoint<E> {
pub fn get_x(&self) -> &AllocatedNum<E> {
&self.x
}
pub fn get_y(&self) -> &AllocatedNum<E> {
&self.y
}
pub fn assert_not_small_order<CS>(
&self,
mut cs: CS,
@ -183,12 +191,6 @@ impl<E: JubjubEngine> EdwardsPoint<E> {
)
}
/// This extracts the x-coordinate, which is an injective
/// encoding for elements of the prime order subgroup.
pub fn into_num(&self) -> AllocatedNum<E> {
self.x.clone()
}
/// Returns `self` if condition is true, and the neutral
/// element (0, 1) otherwise.
pub fn conditionally_select<CS>(

View File

@ -229,7 +229,7 @@ impl<'a, E: JubjubEngine> Circuit<E> for Spend<'a, E> {
let mut position_bits = vec![];
// Injective encoding.
let mut cur = cm.x.clone();
let mut cur = cm.get_x().clone();
for (i, e) in self.auth_path.into_iter().enumerate() {
let cs = &mut cs.namespace(|| format!("merkle tree hash {}", i));
@ -268,7 +268,7 @@ impl<'a, E: JubjubEngine> Circuit<E> for Spend<'a, E> {
pedersen_hash::Personalization::MerkleTree(i),
&preimage,
self.params
)?.x; // Injective encoding
)?.get_x().clone(); // Injective encoding
}
assert_eq!(position_bits.len(), tree_depth);
@ -473,7 +473,7 @@ impl<'a, E: JubjubEngine> Circuit<E> for Output<'a, E> {
// since we know it is prime order, and we know that
// the x-coordinate is an injective encoding for
// prime-order elements.
cm.x.inputize(cs.namespace(|| "commitment"))?;
cm.get_x().inputize(cs.namespace(|| "commitment"))?;
Ok(())
}

View File

@ -176,8 +176,8 @@ mod test {
params
).into_xy();
assert_eq!(res.x.get_value().unwrap(), expected.0);
assert_eq!(res.y.get_value().unwrap(), expected.1);
assert_eq!(res.get_x().get_value().unwrap(), expected.0);
assert_eq!(res.get_y().get_value().unwrap(), expected.1);
// Test against the output of a different personalization
let unexpected = ::pedersen_hash::pedersen_hash::<Bls12, _>(
@ -186,8 +186,8 @@ mod test {
params
).into_xy();
assert!(res.x.get_value().unwrap() != unexpected.0);
assert!(res.y.get_value().unwrap() != unexpected.1);
assert!(res.get_x().get_value().unwrap() != unexpected.0);
assert!(res.get_y().get_value().unwrap() != unexpected.1);
}
}
}