[CHECKPOINT] Tidy, tidy, tidy.

This commit is contained in:
2019-05-26 15:03:42 -07:00
parent 2b63dfa376
commit 2f395721bc
3 changed files with 1239 additions and 1414 deletions

View File

@@ -8,33 +8,42 @@ pub struct Precomp {
pub xy2d: FieldElement pub xy2d: FieldElement
} }
pub fn ge_precomp_0(h: &mut Precomp)
{
h.yplusx.overwrite_with(&FieldElement::one());
h.yminusx.overwrite_with(&FieldElement::one());
h.xy2d.overwrite_with(&FieldElement::zero());
}
impl Precomp impl Precomp
{ {
pub fn new() -> Precomp pub fn new() -> Precomp
{ {
Precomp { Precomp {
yplusx: FieldElement::new(), yplusx: FieldElement::new(),
yminusx: FieldElement::new(), yminusx: FieldElement::new(),
xy2d: FieldElement::new() xy2d: FieldElement::new()
}
} }
}
#[cfg(test)] pub fn zero() -> Precomp
pub fn load_test_value(xs: &[u8]) -> Precomp { {
assert!(xs.len() == 160); Precomp {
Precomp { yplusx: FieldElement::one(),
yplusx: test_from_bytes(&xs[0..40]), yminusx: FieldElement::one(),
yminusx: test_from_bytes(&xs[40..80]), xy2d: FieldElement::zero()
xy2d: test_from_bytes(&xs[80..]) }
}
#[cfg(test)]
pub fn load_test_value(xs: &[u8]) -> Precomp {
assert!(xs.len() == 160);
Precomp {
yplusx: test_from_bytes(&xs[0..40]),
yminusx: test_from_bytes(&xs[40..80]),
xy2d: test_from_bytes(&xs[80..])
}
}
pub fn cmov(&mut self, u: &Precomp, b: bool)
{
self.yplusx.cmov(&u.yplusx, b);
self.yminusx.cmov(&u.yminusx, b);
self.xy2d.cmov(&u.xy2d, b);
} }
}
} }
/* k25519Precomp[i][j] = (j+1)*256^i*B */ /* k25519Precomp[i][j] = (j+1)*256^i*B */

View File

@@ -74,8 +74,7 @@ impl ED25519Private {
result.private.copy_from_slice(private); result.private.copy_from_slice(private);
result.prefix.copy_from_slice(prefix); result.prefix.copy_from_slice(prefix);
curve25519_scalar_mask(&mut result.private); curve25519_scalar_mask(&mut result.private);
let mut a = Point::new(); let a = Point::scalarmult_base(&result.private);
x25519_ge_scalarmult_base(&mut a, &result.private);
result.public.copy_from_slice(&a.encode()); result.public.copy_from_slice(&a.encode());
result result
} }
@@ -88,8 +87,7 @@ impl ED25519Private {
ctx.input(&self.prefix); ctx.input(&self.prefix);
ctx.input(&msg); ctx.input(&msg);
let nonce = digest_scalar(ctx.result().as_slice()); let nonce = digest_scalar(ctx.result().as_slice());
let mut r = Point::new(); let r = Point::scalarmult_base(&nonce);
x25519_ge_scalarmult_base(&mut r, &nonce);
let signature_r = r.encode(); let signature_r = r.encode();
let hram_digest = eddsa_digest(&signature_r, &self.public, &msg); let hram_digest = eddsa_digest(&signature_r, &self.public, &msg);
let hram = digest_scalar(&hram_digest); let hram = digest_scalar(&hram_digest);
@@ -151,8 +149,7 @@ impl ED25519Public {
a.invert(); a.invert();
let h_digest = eddsa_digest(signature_r, &self.public, msg); let h_digest = eddsa_digest(signature_r, &self.public, msg);
let h = digest_scalar(&h_digest); let h = digest_scalar(&h_digest);
let mut r = Point2::new(); let r = ge_double_scalarmult_vartime(&h, &a, &signature_s);
ge_double_scalarmult_vartime(&mut r, &h, &a, &signature_s);
let r_check = r.encode(); let r_check = r.encode();
signature_r.to_vec() == r_check signature_r.to_vec() == r_check
} }

File diff suppressed because it is too large Load Diff