Skip to content
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

Upgrade curv interface #120

Merged
merged 93 commits into from
Jul 27, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
2b5c6b4
Impl From<u16> for BigInt
Jun 28, 2021
d469b0b
Add Polynomial
Jun 29, 2021
138f41d
Add the proof
Jun 29, 2021
076b59c
Update travis config
Jun 29, 2021
83699f4
Bump version
Jun 29, 2021
8882430
Rename coef0 to const_term + update docs
Jun 30, 2021
8aed496
Add sample_exact and sample_exact_with_fixed_const
Jun 30, 2021
369d50c
Rename LdeiProveError -> LdeiProofError
Jun 30, 2021
4f84e8a
Move polynomial into secret_sharing module
Jun 30, 2021
b5f322e
LDEI prove takes witness and statement
Jun 30, 2021
e47d41d
Comment out crypto primitives for a while
Jul 2, 2021
d841938
Update traits, add wrappers, and upgrade secp256k1 implementation
Jul 2, 2021
b335da5
Update polynomial
Jul 2, 2021
ef8d6f9
Do not access wrappers internal state directly, improve docs
Jul 3, 2021
24e35c7
Add generator wrapper
Jul 3, 2021
45c96b1
Add secp256k1 test
Jul 3, 2021
03d1c25
Implement Serialize, Deserialize for Point(Z)
Jul 5, 2021
36cddf0
Update feldman_vss
Jul 5, 2021
08764b7
Add {to,from}_bytes functions to PointZ
Jul 5, 2021
877721e
Update hashing
Jul 5, 2021
94a6459
Change curve_name method with associated constant
Jul 6, 2021
c50e757
Deref stylistic fix
Jul 6, 2021
ce61396
Optimise generator multiplication
Jul 6, 2021
dfd6ee9
Update docs
Jul 6, 2021
483d70f
Update commitments
Jul 6, 2021
e0b2da7
Update low_degree_exponent_interpolation
Jul 6, 2021
be6c8d9
Update sigma_correct_homomorphic_elgamal_enc
Jul 6, 2021
4ecc528
Update sigma_correct_homomorphic_elgamal_encryption_of_dlog
Jul 7, 2021
0c91c91
Wrappers: rename methods, implement PartialEq
Jul 7, 2021
93317ec
Update sigma_dlog
Jul 7, 2021
a63cea8
Update sigma_ec_ddh
Jul 7, 2021
c03f8e2
Rename curve_order to group_order
Jul 8, 2021
ac52e3f
Restrict the points to be of group order
Jul 9, 2021
c419d83
Split a large wrappers module into several files
Jul 9, 2021
1bedf0a
Update sigma_valid_pedersen
Jul 9, 2021
f30877c
Update sigma_valid_pedersen_blind
Jul 9, 2021
c3de0a8
Fix derived Serialize/Deserialize traits
Jul 9, 2021
7cb906f
Update coin_flip_optimal_rounds
Jul 9, 2021
6f5a511
Update dh_key_exchange
Jul 9, 2021
78012ea
Update dh_key_exchange_variant_with_pok_comm
Jul 9, 2021
c3877dd
Update diffie_hellman_key_exchange example
Jul 9, 2021
c90c3fc
Update pedersen_commitment
Jul 9, 2021
0d5bbc2
Update proof_of_knowledge_of_dlog example
Jul 9, 2021
683986b
Update verifiable_secret_sharing example
Jul 9, 2021
e88a14f
Fix warning
Jul 9, 2021
7b56c57
Fix clippy warnings
Jul 9, 2021
48ea95a
Update doc
Jul 9, 2021
64a3a57
Improve hashing
Jul 11, 2021
cddf56a
Write doc
Jul 11, 2021
a7b637c
Fix typos
Jul 12, 2021
aeb9761
Update travis config
Jul 12, 2021
605320d
Update P-256 curve implementation
Jul 13, 2021
9c7bd7d
Add tests
Jul 13, 2021
72552a7
Update Ed25519 curve
Jul 13, 2021
e651b0f
Update Ristretto curve
Jul 14, 2021
e9c149b
Ristretto: x=hash(y)
Jul 14, 2021
0f36489
Add the first BLS curve
Jul 15, 2021
f389d72
Default implementation for ECPoint::is_zero method
Jul 15, 2021
8be8d7f
Add tests, fix ed25519 negation
Jul 15, 2021
14dbcb7
Uncomment proofs of base_point2 picked randomly
Jul 15, 2021
f0177da
Add the second BLS curve
Jul 16, 2021
10e6e2d
Write doc
Jul 16, 2021
6725dfa
Add pairing, update docs
Jul 16, 2021
38f724c
Rename package
Jul 16, 2021
a5a0c5e
Update readme
Jul 16, 2021
2218630
Add changelog
Jul 17, 2021
8ea5d95
Merge Point&PointZ, Scalar&ScalarZ
Jul 19, 2021
e9c3cac
Serialize always succeeds
Jul 19, 2021
595dc89
Update doc
Jul 19, 2021
4cbec3d
Fix clippy warning
Jul 19, 2021
0a0a540
VerifiableSS returns polynomial used to derive secret shares
Jul 20, 2021
2a75890
Fix documentation
Jul 20, 2021
8fe5ea4
Optimize elliptic curves implementations
elichai Jul 20, 2021
89f3eda
Add serialize/deserialize to Scalars
elichai Jul 20, 2021
a955b6e
Use scalar/point `serialize` functions to implement serde serializati…
elichai Jul 20, 2021
c414579
Add serde tests
elichai Jul 20, 2021
10e083b
Add more EC serialize/deserialize tests
elichai Jul 22, 2021
043f969
Update examples
Jul 22, 2021
8543551
Update Cargo.toml
Jul 22, 2021
cfcaecf
Update docs
Jul 22, 2021
f65bd33
Update vss to use u16 instead of usize
Jul 22, 2021
f954bdb
Resolve TODO
Jul 22, 2021
affe7be
Fix doc
Jul 22, 2021
34873cd
Impl iter::{Sum, Product} for wrappers
Jul 23, 2021
2eb8b2b
Ristretto: return x=None instead of x=hash(y)
Jul 26, 2021
373672f
Add documentation for the rest of the curves
Jul 26, 2021
17d18f3
Improve point serialization
Jul 26, 2021
fc6e894
Improve scalar serialization
Jul 26, 2021
5abd70a
Move serde-related stuff to dedicated module
Jul 26, 2021
5d8b4bd
Improve serde tests
Jul 26, 2021
093f810
Remove PointRef wrapper
Jul 26, 2021
a1d1464
Move actual unsafe code to a single function
Jul 27, 2021
3e315f5
Finalization
Jul 27, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/elliptic/curves/secp256_k1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use crate::arithmetic::*;
use super::traits::*;

lazy_static::lazy_static! {
static ref CONTEXT: secp256k1::Secp256k1<secp256k1::VerifyOnly> = secp256k1::Secp256k1::verification_only();
static ref CONTEXT: secp256k1::Secp256k1<secp256k1::All> = secp256k1::Secp256k1::new();
elichai marked this conversation as resolved.
Show resolved Hide resolved

static ref CURVE_ORDER: BigInt = BigInt::from_bytes(&constants::CURVE_ORDER);

Expand Down Expand Up @@ -448,6 +448,19 @@ impl ECPoint for Secp256k1Point {
}
}

fn generator_mul(scalar: &Self::Scalar) -> Self {
match &*scalar.fe {
Some(sk) => Secp256k1Point {
purpose: "generator_mul",
ge: Some(PK(PublicKey::from_secret_key(&CONTEXT, sk))),
},
None => Secp256k1Point {
purpose: "generator_mul",
ge: None,
},
}
}

fn add_point(&self, other: &Self) -> Secp256k1Point {
let ge1 = match &self.ge {
Some(ge) => ge,
Expand Down
12 changes: 12 additions & 0 deletions src/elliptic/curves/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,18 @@ pub trait ECPoint: Zeroize + Clone + PartialEq + fmt::Debug + 'static {

/// Multiplies the point at scalar value
fn scalar_mul(&self, scalar: &Self::Scalar) -> Self;
/// Multiplies curve generator at given scalar
///
/// Basically, it's the same as `ECPoint::generator().scalar_mul(&s)`, but can be more efficient
/// because most curve libs have constant time high performance generator multiplication.
///
/// ## Correctness
///
/// Note that scalar is modulo [curve order](ECScalar::curve_order), so multiplying generator
/// at non-zero scalar **must** always produce non-zero point.
fn generator_mul(scalar: &Self::Scalar) -> Self {
Self::generator().scalar_mul(scalar)
}
/// Adds two points
fn add_point(&self, other: &Self) -> Self;
/// Substrates `other` from `self`
Expand Down
49 changes: 41 additions & 8 deletions src/elliptic/curves/wrappers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1111,19 +1111,19 @@ matrix! {
pairs = {
(_o<> Scalar<E>, Point<E>), (_o<> Scalar<E>, PointZ<E>),
(_r<> Scalar<E>, &Point<E>), (_r<> Scalar<E>, &PointZ<E>),
(_r<'p> Scalar<E>, PointRef<'p, E>), /*(_r<> Scalar<E>, Generator<E>),*/
(_r<'p> Scalar<E>, PointRef<'p, E>),

(_o<> ScalarZ<E>, Point<E>), (_o<> ScalarZ<E>, PointZ<E>),
(_r<> ScalarZ<E>, &Point<E>), (_r<> ScalarZ<E>, &PointZ<E>),
(_r<'p> ScalarZ<E>, PointRef<'p, E>), (_r<> ScalarZ<E>, Generator<E>),
(_r<'p> ScalarZ<E>, PointRef<'p, E>),

(_o<> &Scalar<E>, Point<E>), (_o<> &Scalar<E>, PointZ<E>),
(_r<> &Scalar<E>, &Point<E>), (_r<> &Scalar<E>, &PointZ<E>),
(_r<'p> &Scalar<E>, PointRef<'p, E>), /*(_r<> &Scalar<E>, Generator<E>),*/
(_r<'p> &Scalar<E>, PointRef<'p, E>),

(_o<> &ScalarZ<E>, Point<E>), (_o<> &ScalarZ<E>, PointZ<E>),
(_r<> &ScalarZ<E>, &Point<E>), (_r<> &ScalarZ<E>, &PointZ<E>),
(_r<'p> &ScalarZ<E>, PointRef<'p, E>), (_r<> &ScalarZ<E>, Generator<E>),
(_r<'p> &ScalarZ<E>, PointRef<'p, E>),

// --- and vice-versa ---

Expand All @@ -1141,9 +1141,6 @@ matrix! {

(r_<'p> PointRef<'p, E>, Scalar<E>), (r_<'p> PointRef<'p, E>, ScalarZ<E>),
(r_<'p> PointRef<'p, E>, &Scalar<E>), (r_<'p> PointRef<'p, E>, &ScalarZ<E>),

/*(r_<> Generator<E>, Scalar<E>),*/ (r_<> Generator<E>, ScalarZ<E>),
/*(r_<> Generator<E>, &Scalar<E>),*/ (r_<> Generator<E>, &ScalarZ<E>),
}
}

Expand Down Expand Up @@ -1207,7 +1204,7 @@ matrix! {
impl<E: Curve> ops::Mul<&Scalar<E>> for Generator<E> {
type Output = Point<E>;
fn mul(self, rhs: &Scalar<E>) -> Self::Output {
Point::from_raw(self.as_raw().scalar_mul(&rhs.as_raw()))
Point::from_raw(E::Point::generator_mul(rhs.as_raw()))
.expect("generator multiplied by non-zero scalar is always non-zero point")
}
}
Expand All @@ -1233,6 +1230,34 @@ impl<E: Curve> ops::Mul<Generator<E>> for Scalar<E> {
}
}

impl<E: Curve> ops::Mul<&ScalarZ<E>> for Generator<E> {
type Output = PointZ<E>;
fn mul(self, rhs: &ScalarZ<E>) -> Self::Output {
PointZ::from_raw(E::Point::generator_mul(rhs.as_raw()))
}
}

impl<E: Curve> ops::Mul<ScalarZ<E>> for Generator<E> {
type Output = PointZ<E>;
fn mul(self, rhs: ScalarZ<E>) -> Self::Output {
self.mul(&rhs)
}
}

impl<E: Curve> ops::Mul<Generator<E>> for &ScalarZ<E> {
type Output = PointZ<E>;
fn mul(self, rhs: Generator<E>) -> Self::Output {
rhs.mul(self)
}
}

impl<E: Curve> ops::Mul<Generator<E>> for ScalarZ<E> {
type Output = PointZ<E>;
fn mul(self, rhs: Generator<E>) -> Self::Output {
rhs.mul(self)
}
}

impl<E: Curve> ops::Neg for Scalar<E> {
type Output = Scalar<E>;

Expand Down Expand Up @@ -1289,6 +1314,14 @@ impl<'p, E: Curve> ops::Neg for PointRef<'p, E> {
}
}

impl<E: Curve> ops::Neg for Generator<E> {
type Output = Point<E>;

fn neg(self) -> Self::Output {
Point::from_raw(self.as_raw().neg_point()).expect("neg must not produce zero point")
}
}

impl<E: Curve> ops::Neg for PointZ<E> {
type Output = PointZ<E>;

Expand Down