Whitespace fixes.

This commit is contained in:
Isis Lovecruft 2017-03-17 21:42:40 +00:00
parent a89177f80e
commit d549fdc8f9
Failed to extract signature
3 changed files with 29 additions and 28 deletions

View file

@ -1053,14 +1053,14 @@ impl ExtendedPoint {
/// Returns `Some<[u8;32]>` if `self` is in the image of the /// Returns `Some<[u8;32]>` if `self` is in the image of the
/// Elligator2 map. For a random point on the curve, this happens /// Elligator2 map. For a random point on the curve, this happens
/// with probability 1/2. Otherwise, returns `None`. /// with probability 1/2. Otherwise, returns `None`.
pub fn to_uniform_representative(&self) -> Option<[u8;32]> { pub fn to_uniform_representative(&self) -> Option<[u8; 32]> {
unimplemented!(); unimplemented!();
} }
/// Use Elligator2 to convert a uniformly random string to a curve /// Use Elligator2 to convert a uniformly random string to a curve
/// point. /// point.
#[allow(unused_variables)] // REMOVE WHEN IMPLEMENTED #[allow(unused_variables)] // REMOVE WHEN IMPLEMENTED
pub fn from_uniform_representative(bytes: &[u8;32]) -> ExtendedPoint { pub fn from_uniform_representative(bytes: &[u8; 32]) -> ExtendedPoint {
unimplemented!(); unimplemented!();
} }
} }

View file

@ -454,8 +454,9 @@ impl FieldElement {
FieldElement(limbs) FieldElement(limbs)
} }
#[cfg(not(feature="radix_51"))] #[cfg(not(feature="radix_51"))]
fn reduce(input: &[i64;10]) -> FieldElement { //FeCombine fn reduce(input: &[i64; 10]) -> FieldElement { //FeCombine
let mut c = [0i64;10]; let mut c = [0i64;10];
let mut h = input.clone(); let mut h = input.clone();
@ -533,7 +534,7 @@ impl FieldElement {
/* |h[0]| <= 2^25; from now on fits into int32 unchanged */ /* |h[0]| <= 2^25; from now on fits into int32 unchanged */
/* |h[1]| <= 1.01*2^24 */ /* |h[1]| <= 1.01*2^24 */
let mut output = FieldElement([0i32;10]); let mut output = FieldElement([0i32; 10]);
output[0] = h[0] as i32; output[0] = h[0] as i32;
output[1] = h[1] as i32; output[1] = h[1] as i32;
output[2] = h[2] as i32; output[2] = h[2] as i32;
@ -585,7 +586,7 @@ impl FieldElement {
} }
/// Parse a `FieldElement` from 32 bytes. /// Parse a `FieldElement` from 32 bytes.
#[cfg(feature="radix_51")] #[cfg(feature="radix_51")]
pub fn from_bytes(bytes: &[u8;32]) -> FieldElement { pub fn from_bytes(bytes: &[u8; 32]) -> FieldElement {
let low_51_bit_mask = (1u64 << 51) - 1; let low_51_bit_mask = (1u64 << 51) - 1;
FieldElement( FieldElement(
// load bits [ 0, 64), no shift // load bits [ 0, 64), no shift
@ -621,7 +622,7 @@ impl FieldElement {
/// assert!(data == bytes); /// assert!(data == bytes);
/// ``` /// ```
#[cfg(not(feature="radix_51"))] #[cfg(not(feature="radix_51"))]
pub fn to_bytes(&self) -> [u8;32] { //FeToBytes pub fn to_bytes(&self) -> [u8; 32] { //FeToBytes
// Comment preserved from ed25519.go (presumably originally from ref10): // Comment preserved from ed25519.go (presumably originally from ref10):
// //
// # Preconditions // # Preconditions
@ -752,7 +753,7 @@ impl FieldElement {
} }
/// Serialize this `FieldElement` to bytes. /// Serialize this `FieldElement` to bytes.
#[cfg(feature="radix_51")] #[cfg(feature="radix_51")]
pub fn to_bytes(&self) -> [u8;32] { pub fn to_bytes(&self) -> [u8; 32] {
// This reduces to the range [0,2^255), but we need [0,2^255-19) // This reduces to the range [0,2^255), but we need [0,2^255-19)
let mut limbs = FieldElement::reduce(self.0).0; let mut limbs = FieldElement::reduce(self.0).0;
// Let h = limbs[0] + limbs[1]*2^51 + ... + limbs[4]*2^204. // Let h = limbs[0] + limbs[1]*2^51 + ... + limbs[4]*2^204.
@ -925,7 +926,7 @@ impl FieldElement {
} }
#[cfg(not(feature="radix_51"))] #[cfg(not(feature="radix_51"))]
fn square_inner(&self) -> [i64;10] { fn square_inner(&self) -> [i64; 10] {
let f0 = self[0] as i64; let f0 = self[0] as i64;
let f1 = self[1] as i64; let f1 = self[1] as i64;
let f2 = self[2] as i64; let f2 = self[2] as i64;
@ -964,6 +965,7 @@ impl FieldElement {
h h
} }
#[cfg(feature="radix_51")] #[cfg(feature="radix_51")]
#[inline(always)] #[inline(always)]
fn square_inner(&self) -> [u64; 5] { fn square_inner(&self) -> [u64; 5] {
@ -1170,8 +1172,7 @@ impl FieldElement {
/// - `(0u8, zero)` if `v` is zero; /// - `(0u8, zero)` if `v` is zero;
/// - `(0u8, garbage)` if `u/v` is nonsquare. /// - `(0u8, garbage)` if `u/v` is nonsquare.
/// ///
pub fn sqrt_ratio(u: &FieldElement, v: &FieldElement) pub fn sqrt_ratio(u: &FieldElement, v: &FieldElement) -> (u8, FieldElement) {
-> (u8, FieldElement) {
// Using the same trick as in ed25519 decoding, we merge the // Using the same trick as in ed25519 decoding, we merge the
// inversion, the square root, and the square test as follows. // inversion, the square root, and the square test as follows.
// //
@ -1259,28 +1260,28 @@ mod test {
/// Random element a of GF(2^255-19), from Sage /// Random element a of GF(2^255-19), from Sage
/// a = 1070314506888354081329385823235218444233221\ /// a = 1070314506888354081329385823235218444233221\
/// 2228051251926706380353716438957572 /// 2228051251926706380353716438957572
pub static A_BYTES: [u8;32] = pub static A_BYTES: [u8; 32] =
[ 0x04, 0xfe, 0xdf, 0x98, 0xa7, 0xfa, 0x0a, 0x68, [ 0x04, 0xfe, 0xdf, 0x98, 0xa7, 0xfa, 0x0a, 0x68,
0x84, 0x92, 0xbd, 0x59, 0x08, 0x07, 0xa7, 0x03, 0x84, 0x92, 0xbd, 0x59, 0x08, 0x07, 0xa7, 0x03,
0x9e, 0xd1, 0xf6, 0xf2, 0xe1, 0xd9, 0xe2, 0xa4, 0x9e, 0xd1, 0xf6, 0xf2, 0xe1, 0xd9, 0xe2, 0xa4,
0xa4, 0x51, 0x47, 0x36, 0xf3, 0xc3, 0xa9, 0x17]; 0xa4, 0x51, 0x47, 0x36, 0xf3, 0xc3, 0xa9, 0x17];
/// Byte representation of a**2 /// Byte representation of a**2
static ASQ_BYTES: [u8;32] = static ASQ_BYTES: [u8; 32] =
[ 0x75, 0x97, 0x24, 0x9e, 0xe6, 0x06, 0xfe, 0xab, [ 0x75, 0x97, 0x24, 0x9e, 0xe6, 0x06, 0xfe, 0xab,
0x24, 0x04, 0x56, 0x68, 0x07, 0x91, 0x2d, 0x5d, 0x24, 0x04, 0x56, 0x68, 0x07, 0x91, 0x2d, 0x5d,
0x0b, 0x0f, 0x3f, 0x1c, 0xb2, 0x6e, 0xf2, 0xe2, 0x0b, 0x0f, 0x3f, 0x1c, 0xb2, 0x6e, 0xf2, 0xe2,
0x63, 0x9c, 0x12, 0xba, 0x73, 0x0b, 0xe3, 0x62]; 0x63, 0x9c, 0x12, 0xba, 0x73, 0x0b, 0xe3, 0x62];
/// Byte representation of 1/a /// Byte representation of 1/a
static AINV_BYTES: [u8;32] = static AINV_BYTES: [u8; 32] =
[0x96, 0x1b, 0xcd, 0x8d, 0x4d, 0x5e, 0xa2, 0x3a, [0x96, 0x1b, 0xcd, 0x8d, 0x4d, 0x5e, 0xa2, 0x3a,
0xe9, 0x36, 0x37, 0x93, 0xdb, 0x7b, 0x4d, 0x70, 0xe9, 0x36, 0x37, 0x93, 0xdb, 0x7b, 0x4d, 0x70,
0xb8, 0x0d, 0xc0, 0x55, 0xd0, 0x4c, 0x1d, 0x7b, 0xb8, 0x0d, 0xc0, 0x55, 0xd0, 0x4c, 0x1d, 0x7b,
0x90, 0x71, 0xd8, 0xe9, 0xb6, 0x18, 0xe6, 0x30]; 0x90, 0x71, 0xd8, 0xe9, 0xb6, 0x18, 0xe6, 0x30];
/// Byte representation of a^((p-5)/8) /// Byte representation of a^((p-5)/8)
static AP58_BYTES: [u8;32] = static AP58_BYTES: [u8; 32] =
[0x6a, 0x4f, 0x24, 0x89, 0x1f, 0x57, 0x60, 0x36, [0x6a, 0x4f, 0x24, 0x89, 0x1f, 0x57, 0x60, 0x36,
0xd0, 0xbe, 0x12, 0x3c, 0x8f, 0xf5, 0xb1, 0x59, 0xd0, 0xbe, 0x12, 0x3c, 0x8f, 0xf5, 0xb1, 0x59,
0xe0, 0xf0, 0xb8, 0x1b, 0x20, 0xd2, 0xb5, 0x1f, 0xe0, 0xf0, 0xb8, 0x1b, 0x20, 0xd2, 0xb5, 0x1f,

View file

@ -190,7 +190,7 @@ impl Scalar {
/// ``` /// ```
/// ///
pub fn hash_from_bytes<D>(input: &[u8]) -> Scalar pub fn hash_from_bytes<D>(input: &[u8]) -> Scalar
where D: Digest<OutputSize=U64> + Default { where D: Digest<OutputSize = U64> + Default {
let mut hash = D::default(); let mut hash = D::default();
hash.input(input); hash.input(input);
// XXX this seems clumsy // XXX this seems clumsy
@ -200,7 +200,7 @@ impl Scalar {
} }
/// View this `Scalar` as a sequence of bytes. /// View this `Scalar` as a sequence of bytes.
pub fn as_bytes<'a>(&'a self) -> &'a [u8;32] { pub fn as_bytes<'a>(&'a self) -> &'a [u8; 32] {
&self.0 &self.0
} }
@ -226,7 +226,7 @@ impl Scalar {
/// Intuitively, this is like a binary expansion, except that we /// Intuitively, this is like a binary expansion, except that we
/// allow some coefficients to grow up to `2^(w-1)` so that the /// allow some coefficients to grow up to `2^(w-1)` so that the
/// nonzero coefficients are as sparse as possible. /// nonzero coefficients are as sparse as possible.
pub fn non_adjacent_form(&self) -> [i8;256] { pub fn non_adjacent_form(&self) -> [i8; 256] {
// Step 1: write out bits of the scalar // Step 1: write out bits of the scalar
let mut naf = [0i8; 256]; let mut naf = [0i8; 256];
for i in 0..256 { for i in 0..256 {
@ -270,7 +270,7 @@ impl Scalar {
// Unpack a scalar into 12 21-bit limbs. // Unpack a scalar into 12 21-bit limbs.
fn unpack(&self) -> UnpackedScalar { fn unpack(&self) -> UnpackedScalar {
let mask_21bits: i64 = (1 << 21) -1; let mask_21bits: i64 = (1 << 21) -1;
let mut a = UnpackedScalar([0i64;12]); let mut a = UnpackedScalar([0i64; 12]);
a[ 0] = mask_21bits & load3(&self.0[ 0..]) ; a[ 0] = mask_21bits & load3(&self.0[ 0..]) ;
a[ 1] = mask_21bits & (load4(&self.0[ 2..]) >> 5); a[ 1] = mask_21bits & (load4(&self.0[ 2..]) >> 5);
a[ 2] = mask_21bits & (load3(&self.0[ 5..]) >> 2); a[ 2] = mask_21bits & (load3(&self.0[ 5..]) >> 2);
@ -296,7 +296,7 @@ impl Scalar {
/// ///
/// Precondition: self[31] <= 127. This is the case whenever /// Precondition: self[31] <= 127. This is the case whenever
/// `self` is reduced. /// `self` is reduced.
pub fn to_radix_16(&self) -> [i8;64] { pub fn to_radix_16(&self) -> [i8; 64] {
debug_assert!(self[31] <= 127); debug_assert!(self[31] <= 127);
let mut output = [0i8; 64]; let mut output = [0i8; 64];
@ -339,8 +339,8 @@ impl Scalar {
} }
/// Reduce a 512-bit little endian number mod l /// Reduce a 512-bit little endian number mod l
pub fn reduce(input: &[u8;64]) -> Scalar { pub fn reduce(input: &[u8; 64]) -> Scalar {
let mut s = [0i64;24]; let mut s = [0i64; 24];
// XXX express this as two unpack_limbs // XXX express this as two unpack_limbs
// some issues re: masking with the top byte of the 32byte input // some issues re: masking with the top byte of the 32byte input
@ -444,7 +444,7 @@ impl UnpackedScalar {
pub fn multiply_add(a: &UnpackedScalar, pub fn multiply_add(a: &UnpackedScalar,
b: &UnpackedScalar, b: &UnpackedScalar,
c: &UnpackedScalar) -> UnpackedScalar { c: &UnpackedScalar) -> UnpackedScalar {
let mut result = [0i64;24]; let mut result = [0i64; 24];
// Multiply a and b, and add c // Multiply a and b, and add c
result[0] = c[0] + a[0]*b[0]; result[0] = c[0] + a[0]*b[0];
@ -506,10 +506,10 @@ impl UnpackedScalar {
/// limbs. Reduction mod l amounts to eliminating all of the /// limbs. Reduction mod l amounts to eliminating all of the
/// high limbs while carrying as appropriate to prevent /// high limbs while carrying as appropriate to prevent
/// overflows in the lower limbs. /// overflows in the lower limbs.
fn reduce_limbs(mut limbs: &mut [i64;24]) -> UnpackedScalar { fn reduce_limbs(mut limbs: &mut [i64; 24]) -> UnpackedScalar {
#[inline] #[inline]
#[allow(dead_code)] #[allow(dead_code)]
fn do_reduction(limbs: &mut [i64;24], i:usize) { fn do_reduction(limbs: &mut [i64; 24], i:usize) {
limbs[i - 12] += limbs[i] * 666643; limbs[i - 12] += limbs[i] * 666643;
limbs[i - 11] += limbs[i] * 470296; limbs[i - 11] += limbs[i] * 470296;
limbs[i - 10] += limbs[i] * 654183; limbs[i - 10] += limbs[i] * 654183;
@ -531,7 +531,7 @@ impl UnpackedScalar {
#[allow(dead_code)] #[allow(dead_code)]
/// Carry excess from the `i`-th limb into the `(i+1)`-th limb. /// Carry excess from the `i`-th limb into the `(i+1)`-th limb.
/// Postcondition: `-2^20 <= limbs[i] < 2^20`. /// Postcondition: `-2^20 <= limbs[i] < 2^20`.
fn do_carry_centered(limbs: &mut [i64;24], i:usize) { fn do_carry_centered(limbs: &mut [i64; 24], i:usize) {
let carry: i64 = (limbs[i] + (1<<20)) >> 21; let carry: i64 = (limbs[i] + (1<<20)) >> 21;
limbs[i+1] += carry; limbs[i+1] += carry;
limbs[i ] -= carry << 21; limbs[i ] -= carry << 21;
@ -585,7 +585,7 @@ impl UnpackedScalar {
} }
// XXX better way to get [i64;12] from [i64;24] ? // XXX better way to get [i64;12] from [i64;24] ?
UnpackedScalar(*array_ref!(limbs,0,12)) UnpackedScalar(*array_ref!(limbs, 0, 12))
} }
} }
@ -632,7 +632,7 @@ mod test {
0xa7, 0x58, 0xaa, 0x1b, 0x88, 0xe0, 0x40, 0xd1, 0xa7, 0x58, 0xaa, 0x1b, 0x88, 0xe0, 0x40, 0xd1,
0x58, 0x9e, 0x7b, 0x7f, 0x23, 0x76, 0xef, 0x09]); 0x58, 0x9e, 0x7b, 0x7f, 0x23, 0x76, 0xef, 0x09]);
static A_NAF: [i8;256] = static A_NAF: [i8; 256] =
[0,13,0,0,0,0,0,0,0,7,0,0,0,0,0,0,-9,0,0,0,0,-11,0,0,0,0,3,0,0,0,0,1, [0,13,0,0,0,0,0,0,0,7,0,0,0,0,0,0,-9,0,0,0,0,-11,0,0,0,0,3,0,0,0,0,1,
0,0,0,0,9,0,0,0,0,-5,0,0,0,0,0,0,3,0,0,0,0,11,0,0,0,0,11,0,0,0,0,0, 0,0,0,0,9,0,0,0,0,-5,0,0,0,0,0,0,3,0,0,0,0,11,0,0,0,0,11,0,0,0,0,0,
-9,0,0,0,0,0,-3,0,0,0,0,9,0,0,0,0,0,1,0,0,0,0,0,0,-1,0,0,0,0,0,9,0, -9,0,0,0,0,0,-3,0,0,0,0,9,0,0,0,0,0,1,0,0,0,0,0,0,-1,0,0,0,0,0,9,0,
@ -679,7 +679,7 @@ mod test {
#[test] #[test]
fn scalar_reduce() { fn scalar_reduce() {
let mut bignum = [0u8;64]; let mut bignum = [0u8; 64];
// set bignum = x + 2^256x // set bignum = x + 2^256x
for i in 0..32 { for i in 0..32 {
bignum[ i] = X[i]; bignum[ i] = X[i];