|
1 | 1 | #![allow(non_snake_case)]
|
2 | 2 |
|
3 | 3 | use super::window::wnaf::LookupTable;
|
4 |
| -use crate::EdwardsScalar; |
| 4 | +use crate::Scalar; |
5 | 5 | use crate::curve::twedwards::{extended::ExtendedPoint, extensible::ExtensiblePoint};
|
| 6 | +use crate::field::CurveWithScalar; |
6 | 7 | use subtle::{Choice, ConditionallyNegatable};
|
7 | 8 |
|
8 |
| -pub fn variable_base(point: &ExtendedPoint, s: &EdwardsScalar) -> ExtendedPoint { |
| 9 | +pub fn variable_base<C: CurveWithScalar>(point: &ExtendedPoint, s: &Scalar<C>) -> ExtendedPoint { |
9 | 10 | let mut result = ExtensiblePoint::IDENTITY;
|
10 | 11 |
|
11 | 12 | // Recode Scalar
|
@@ -37,12 +38,30 @@ pub fn variable_base(point: &ExtendedPoint, s: &EdwardsScalar) -> ExtendedPoint
|
37 | 38 | #[cfg(test)]
|
38 | 39 | mod test {
|
39 | 40 | use super::*;
|
| 41 | + use crate::EdwardsScalar; |
40 | 42 | use crate::TWISTED_EDWARDS_BASE_POINT;
|
41 |
| - use crate::curve::scalar_mul::double_and_add; |
42 | 43 | use elliptic_curve::bigint::U448;
|
| 44 | + use subtle::ConditionallySelectable; |
43 | 45 |
|
44 | 46 | #[test]
|
45 | 47 | fn test_scalar_mul() {
|
| 48 | + /// Traditional double and add algorithm |
| 49 | + fn double_and_add(point: &ExtendedPoint, s_bits: [bool; 448]) -> ExtendedPoint { |
| 50 | + let mut result = ExtendedPoint::IDENTITY; |
| 51 | + |
| 52 | + // NB, we reverse here, so we are going from MSB to LSB |
| 53 | + // XXX: Would be great if subtle had a From<u32> for Choice. But maybe that is not it's purpose? |
| 54 | + for bit in s_bits.into_iter().rev() { |
| 55 | + result = result.double(); |
| 56 | + |
| 57 | + let mut p = ExtendedPoint::IDENTITY; |
| 58 | + p.conditional_assign(point, Choice::from(bit as u8)); |
| 59 | + result = result.add(&p); |
| 60 | + } |
| 61 | + |
| 62 | + result |
| 63 | + } |
| 64 | + |
46 | 65 | // XXX: In the future use known multiples from Sage in bytes form?
|
47 | 66 | let twisted_point = TWISTED_EDWARDS_BASE_POINT;
|
48 | 67 | let scalar = EdwardsScalar::new(U448::from_be_hex(
|
|
0 commit comments