diff --git a/src/field.rs b/src/field.rs index 2241c13..9d8d041 100644 --- a/src/field.rs +++ b/src/field.rs @@ -96,17 +96,10 @@ impl FieldElement { /// Compute (self^(2^250-1), self^11), used as a helper function /// within invert() and pow22523(). - /// - /// XXX This returns an extra intermediate to save computation in - /// finding inverses, at the cost of an extra copy when it's not - /// used (e.g., when raising to (p-1)/2 or (p-5)/8). Good idea? fn pow22501(&self) -> (FieldElement, FieldElement) { // Instead of managing which temporary variables are used - // for what, we define as many as we need and trust the - // compiler to reuse stack space as appropriate. - // - // XXX testing some examples suggests that this does happen, - // but it would be good to check asm for this function. + // for what, we define as many as we need and leave stack + // allocation to the compiler // // Each temporary variable t_i is of the form (self)^e_i. // Squaring t_i corresponds to multiplying e_i by 2, @@ -177,12 +170,9 @@ impl FieldElement { /// /// The inverse is computed as self^(p-2), since /// x^(p-2)x = x^(p-1) = 1 (mod p). - // - // XXX do we want the debug assertion to check for zero? it breaks behaviour - // such as that such as in curve25519_dalek::montgomery::test::identity_to_monty. + /// + /// This function returns zero on input zero. pub fn invert(&self) -> FieldElement { - // debug_assert!(*self != FieldElement::zero()); - // The bits of p-2 = 2^255 -19 -2 are 11010111111...11. // // nonzero bits of exponent @@ -194,8 +184,7 @@ impl FieldElement { } /// Raise this field element to the power (p-5)/8 = 2^252 -3. - /// Used in decoding. - pub fn pow_p58(&self) -> FieldElement { + fn pow_p58(&self) -> FieldElement { // The bits of (p-5)/8 are 101111.....11. // // nonzero bits of exponent