-
Notifications
You must be signed in to change notification settings - Fork 168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add weierstrass::FixedBaseScalarMul
trait
#49
Conversation
@str4d @tuxxy pushing this up early for a bit of design review. I implemented
I added some test vectors for secp256k1, which is both what I'm immediately interested in and also provides a PoC that the trait is working at a conceptual level. For now I left a TODO in the |
Codecov Report
@@ Coverage Diff @@
## master #49 +/- ##
==========================================
- Coverage 82.02% 81.27% -0.75%
==========================================
Files 12 12
Lines 1296 1346 +50
==========================================
+ Hits 1063 1094 +31
- Misses 233 252 +19
Continue to review full report at Codecov.
|
9442cf9
to
71e89ca
Compare
weierstrass::FixedBaseScalarMul
trait
998f55d
to
73cbf5b
Compare
73cbf5b
to
9634ecd
Compare
5471a48
to
9634ecd
Compare
Adds a trait for fixed-base scalar multiplication which accepts `&ScalarBytes` as input and returns an associated point type, whose bounds allow for a `From` conversion to either the `CompressedCurvePoint` or `UncompressedCurvePoint` for a given curve. Using this trait, a `weierstrass::PublicKey<C>::from_secret_key` method is conditionally implemented when the curve `C` impls the `FixedBaseScalarMul` trait, allowing generic computation of a public key from a secret key, with optional point compression (selected via a `compress` argument).
9634ecd
to
46c9a3c
Compare
pub fn from_secret_key(secret_key: &SecretKey<C::ScalarSize>, compress: bool) -> Option<Self> { | ||
let ct_option = C::mul_base(secret_key.secret_scalar()); | ||
|
||
if ct_option.is_some().into() { | ||
let affine_point = ct_option.unwrap(); | ||
|
||
if compress { | ||
Some(PublicKey::Compressed(affine_point.into())) | ||
} else { | ||
Some(PublicKey::Uncompressed(affine_point.into())) | ||
} | ||
} else { | ||
None | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was able to eliminate the Default
bound on AffinePoint
by having this return an Option
rather than a CtOption
as soon as scalar multiplication is complete (i.e. unwrapping the CtOption
containing the public key).
Since we're dealing with a public key after scalar multiplication is complete, this seems ok to me.
Going to go ahead and merge this as I think it's a pretty basic and important feature. There are some potential alternative designs to explore/consider here, but I think this is a reasonable start. |
Adds a trait for fixed-base scalar multiplication which accepts
&ScalarBytes
as input and returns an associated point type, whose bounds allow for aFrom
conversion to either theCompressedCurvePoint
orUncompressedCurvePoint
for a given curve.Using this trait, a
weierstrass::PublicKey<C>::from_secret_key
method is conditionally implemented when the curveC
impls theFixedBaseScalarMul
trait, allowing generic computation of a public key from a secret key, with optional point compression (selected via acompress
argument).