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 23 commits
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
28 changes: 20 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
language: rust
cache: cargo
rust:
- stable
rust: stable
virt: lxd

before_script:
- rustup component add rustfmt-preview clippy
- cargo fmt --all -- --check
- cargo clippy -- -D clippy::all
env:
- BIGINT_BACKEND=rust-gmp-kzen
- BIGINT_BACKEND=num-bigint

before_install:
- rustup component add rustfmt clippy

script:
- cargo build --verbose
- cargo test --verbose
- cargo build --verbose --no-default-features --features $BIGINT_BACKEND
- cargo test --verbose --no-default-features --features $BIGINT_BACKEND
- if [[ "$BIGINT_BACKEND" = "rust-gmp-kzen" ]]; then cargo fmt --all -- --check; fi
- if [[ "$BIGINT_BACKEND" = "rust-gmp-kzen" ]]; then cargo clippy -- -D clippy::all; fi

deploy:
provider: cargo
token:
secure: "FE6A1XRyJtTK92rV3y5e0go+FDKn1HpJbYkHOacDqabTkUluXrCTw3ERFcQQ13QZdc9xkxoAs7roKp8ivl0Xg1IJCzI+yLb0ZR6YcYebKEqd06YFbBmejjvMsyyZHKPTQmroe+tBwcA1IqLLcAY8vmY5EGhJTsGUhovIomw1RvqM6gu9yUwII/sF0a5gqY761cJd4QoLlWTb1Er7DqZxoU9drhWAJQP7sLsspjLu6dOyWzb0A2mTmnek+iuVnt9mGPtjGk4FcNPGbEmNu3UPOVuXcyibFPIALEWrH0ouZB7E9k312g45LucSeKSimgQYQBNAzdsnkKyBwyTpGuaosGnMbI7mhoi3visV21RTbw61N05dmZTYb4VAMcx+93TslKMDv5nmIlUmKxULNRBSTPPtrg0/X7KuKaoHVstrxx0ohd8GFwGYQBB64mQaOxFBhoy//prpHjhFl+1cti4JHyaHFSV/PfaryvUfRg4q2Dlq1HP+ey5cPRPbwfpSO1RmXlIDWe21ncRnKSpgMHTPBzYNtil+gZyzHl5X4ZLvLCaHsZwZQPMFB+otlabFaS1caqkk1F1fHMrj8NMak/snb2IyUJqXgQivqzEn38G3k9/QHeQXhNVwyGDtdWV51P9XfXFpxrEuuWlXF56ABiWcF7bY7Y3DeCbnFNLkVkGZYvY="
on:
tags: true
condition: '"$TRAVIS_TAG" =~ ^v[0-9.]+$ && "$BIGINT_BACKEND" = "rust-gmp-kzen"'
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "curv"
version = "0.7.0"
version = "0.7.1"
edition = "2018"
authors = ["Omer Shlomovits"]
survived marked this conversation as resolved.
Show resolved Hide resolved
license = "MIT"
Expand All @@ -19,10 +19,11 @@ digest = "0.8.1"
ff-zeroize = "0.6.3"
funty = "=1.1.0"
generic-array = "0.14"
hex = "0.4"
hex = { version = "0.4", features = ["serde"] }
hmac = "0.7.1"
thiserror = "1"
merkle-sha3 = "^0.1"
lazy_static = "1.4.0"
lazy_static = "1.4"
num-traits = "0.2"
num-integer = "0.1"
pairing-plus = "0.19"
Expand Down
6 changes: 6 additions & 0 deletions src/arithmetic/big_gmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,12 @@ impl ring_algorithm::RingNormalize for BigInt {

crate::__bigint_impl_from! { u32, i32, u64 }

impl From<u16> for BigInt {
fn from(n: u16) -> Self {
BigInt::from(u64::from(n))
}
}

/// Internal helper trait. Creates short-hand for wrapping Mpz into BigInt.
trait Wrap {
fn wrap(self) -> BigInt;
Expand Down
6 changes: 6 additions & 0 deletions src/arithmetic/big_native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ impl num_traits::Num for BigInt {

crate::__bigint_impl_from! { u32, i32, u64 }

impl From<u16> for BigInt {
fn from(n: u16) -> Self {
BigInt::from(u64::from(n))
}
}

impl BasicOps for BigInt {
fn pow(&self, exponent: u32) -> Self {
self.num.pow(exponent).wrap()
Expand Down
2 changes: 1 addition & 1 deletion src/arithmetic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ mod test {
// Conversion traits
for<'a> u64: std::convert::TryFrom<&'a BigInt>,
for<'a> i64: std::convert::TryFrom<&'a BigInt>,
BigInt: From<u32> + From<i32> + From<u64>,
BigInt: From<u16> + From<u32> + From<i32> + From<u64>,
// STD Operators
BigInt: Add<Output = BigInt>
+ Sub<Output = BigInt>
Expand Down
44 changes: 28 additions & 16 deletions src/cryptographic_primitives/hashing/blake2b512.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
License MIT: https://github.com/KZen-networks/curv/blob/master/LICENSE
*/
use crate::arithmetic::traits::*;
use crate::elliptic::curves::traits::{ECPoint, ECScalar};
use crate::elliptic::curves::{Curve, Point, PointZ, ScalarZ};
use crate::BigInt;
use blake2b_simd::Params;

Expand All @@ -14,32 +14,46 @@ pub struct Blake;
impl Blake {
pub fn create_hash(big_ints: &[&BigInt], persona: &[u8]) -> BigInt {
let mut digest = Params::new().hash_length(64).personal(persona).to_state();
// let mut digest = Blake2b::with_params(64, &[], &[], persona);
for value in big_ints {
digest.update(&BigInt::to_bytes(value));
}

BigInt::from_bytes(digest.finalize().as_ref())
}

pub fn create_hash_from_ge<P: ECPoint>(ge_vec: &[&P], persona: &[u8]) -> P::Scalar {
pub fn create_hash_from_ge<E: Curve>(ge_vec: &[&Point<E>], persona: &[u8]) -> ScalarZ<E> {
let mut digest = Params::new().hash_length(64).personal(persona).to_state();
// let mut digest = Blake2b::with_params(64, &[], &[], persona);

for value in ge_vec {
digest.update(&value.pk_to_key_slice());
digest.update(&value.to_bytes(false));
}

let result = BigInt::from_bytes(digest.finalize().as_ref());
ECScalar::from(&result)
ScalarZ::from(&result)
}

pub fn create_hash_from_ge_z<E: Curve>(ge_vec: &[&PointZ<E>], persona: &[u8]) -> ScalarZ<E> {
let mut digest = Params::new().hash_length(64).personal(persona).to_state();
// let mut digest = Blake2b::with_params(64, &[], &[], persona);

for value in ge_vec {
match value.to_bytes(false) {
Some(serialized) => digest.update(&serialized),
None => digest.update(b"infinity point"),
};
}

let result = BigInt::from_bytes(digest.finalize().as_ref());
ScalarZ::from(&result)
}
}

#[cfg(test)]
mod tests {
use super::Blake;
use crate::arithmetic::traits::*;
use crate::elliptic::curves::traits::{ECPoint, ECScalar};
use crate::elliptic::curves::{Curve, Point};
use crate::BigInt;

#[test]
Expand All @@ -51,17 +65,15 @@ mod tests {

crate::test_for_all_curves!(create_hash_from_ge_test);

fn create_hash_from_ge_test<P>()
where
P: ECPoint,
P::Scalar: PartialEq + std::fmt::Debug,
{
let point = P::base_point2();
let result1 = Blake::create_hash_from_ge(&[&point, &P::generator()], b"Zcash_RedJubjubH");
assert!(result1.to_big_int().bit_length() > 240);
let result2 = Blake::create_hash_from_ge(&[&P::generator(), &point], b"Zcash_RedJubjubH");
fn create_hash_from_ge_test<E: Curve>() {
let base_point2 = Point::base_point2().to_point_owned();
let generator = Point::generator().to_point_owned();
let result1 =
Blake::create_hash_from_ge::<E>(&[&base_point2, &generator], b"Zcash_RedJubjubH");
assert!(result1.to_bigint().bit_length() > 240);
let result2 = Blake::create_hash_from_ge(&[&generator, &base_point2], b"Zcash_RedJubjubH");
assert_ne!(result1, result2);
let result3 = Blake::create_hash_from_ge(&[&P::generator(), &point], b"Zcash_RedJubjubH");
let result3 = Blake::create_hash_from_ge(&[&generator, &base_point2], b"Zcash_RedJubjubH");
assert_eq!(result2, result3);
}
}
43 changes: 27 additions & 16 deletions src/cryptographic_primitives/hashing/hash_sha256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@

use super::traits::Hash;
use crate::arithmetic::traits::*;
use crate::elliptic::curves::traits::{ECPoint, ECScalar};
use crate::elliptic::curves::{Curve, Point, PointZ, ScalarZ};

use digest::Digest;
use sha2::Sha256;

use crate::BigInt;

pub struct HSha256;

impl Hash for HSha256 {
Expand All @@ -27,15 +28,29 @@ impl Hash for HSha256 {
BigInt::from_bytes(&result_hex[..])
}

fn create_hash_from_ge<P: ECPoint>(ge_vec: &[&P]) -> P::Scalar {
fn create_hash_from_ge<E: Curve>(ge_vec: &[&Point<E>]) -> ScalarZ<E> {
let mut hasher = Sha256::new();
for value in ge_vec {
hasher.input(&value.to_bytes(false));
}

let result_hex = hasher.result();
let result = BigInt::from_bytes(&result_hex[..]);
ScalarZ::from(&result)
}

fn create_hash_from_ge_z<E: Curve>(ge_vec: &[&PointZ<E>]) -> ScalarZ<E> {
let mut hasher = Sha256::new();
for value in ge_vec {
hasher.input(&value.pk_to_key_slice());
match value.to_bytes(false) {
Some(serialized) => hasher.input(&serialized),
None => hasher.input(b"infinity"),
}
}

let result_hex = hasher.result();
let result = BigInt::from_bytes(&result_hex[..]);
ECScalar::from(&result)
ScalarZ::from(&result)
}

fn create_hash_from_slice(byte_slice: &[u8]) -> BigInt {
Expand All @@ -51,8 +66,7 @@ mod tests {
use super::HSha256;
use super::Hash;
use crate::arithmetic::traits::*;
use crate::elliptic::curves::traits::ECPoint;
use crate::elliptic::curves::traits::ECScalar;
use crate::elliptic::curves::{Curve, Point};
use crate::BigInt;
use sha2::Digest;
use sha2::Sha256;
Expand Down Expand Up @@ -111,17 +125,14 @@ mod tests {

crate::test_for_all_curves!(create_sha256_from_ge_test);

fn create_sha256_from_ge_test<P>()
where
P: ECPoint,
P::Scalar: PartialEq + std::fmt::Debug,
{
let point = P::base_point2();
let result1 = HSha256::create_hash_from_ge(&[&point, &P::generator()]);
assert!(result1.to_big_int().bit_length() > 240);
let result2 = HSha256::create_hash_from_ge(&[&P::generator(), &point]);
fn create_sha256_from_ge_test<E: Curve>() {
let generator = Point::generator().to_point_owned();
let base_point2 = Point::base_point2().to_point_owned();
let result1 = HSha256::create_hash_from_ge::<E>(&[&base_point2, &generator]);
assert!(result1.to_bigint().bit_length() > 240);
let result2 = HSha256::create_hash_from_ge(&[&generator, &base_point2]);
assert_ne!(result1, result2);
let result3 = HSha256::create_hash_from_ge(&[&P::generator(), &point]);
let result3 = HSha256::create_hash_from_ge(&[&generator, &base_point2]);
assert_eq!(result2, result3);
}
}
45 changes: 28 additions & 17 deletions src/cryptographic_primitives/hashing/hash_sha512.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

use super::traits::Hash;
use crate::arithmetic::traits::*;
use crate::elliptic::curves::traits::{ECPoint, ECScalar};
use crate::elliptic::curves::{Curve, Point, PointZ, ScalarZ};

use digest::Digest;
use sha2::Sha512;
Expand All @@ -28,15 +28,29 @@ impl Hash for HSha512 {
BigInt::from_bytes(&result_hex[..])
}

fn create_hash_from_ge<P: ECPoint>(ge_vec: &[&P]) -> P::Scalar {
fn create_hash_from_ge<E: Curve>(ge_vec: &[&Point<E>]) -> ScalarZ<E> {
let mut hasher = Sha512::new();
for value in ge_vec {
hasher.input(&value.pk_to_key_slice());
hasher.input(&value.to_bytes(false));
}

let result_hex = hasher.result();
let result = BigInt::from_bytes(&result_hex[..]);
ECScalar::from(&result)
ScalarZ::from(&result)
}

fn create_hash_from_ge_z<E: Curve>(ge_vec: &[&PointZ<E>]) -> ScalarZ<E> {
let mut hasher = Sha512::new();
for value in ge_vec {
match value.to_bytes(false) {
Some(serialized) => hasher.input(&serialized),
None => hasher.input(b"infinity"),
}
}

let result_hex = hasher.result();
let result = BigInt::from_bytes(&result_hex[..]);
ScalarZ::from(&result)
}

fn create_hash_from_slice(byte_slice: &[u8]) -> BigInt {
Expand All @@ -49,11 +63,11 @@ impl Hash for HSha512 {

#[cfg(test)]
mod tests {
use crate::arithmetic::*;
use crate::elliptic::curves::{Curve, Point};

use super::HSha512;
use super::Hash;
use crate::arithmetic::traits::*;
use crate::elliptic::curves::traits::{ECPoint, ECScalar};
use crate::BigInt;

#[test]
// Test Vectors taken from:
Expand Down Expand Up @@ -99,17 +113,14 @@ mod tests {

crate::test_for_all_curves!(create_sha512_from_ge_test);

fn create_sha512_from_ge_test<P>()
where
P: ECPoint,
P::Scalar: PartialEq + std::fmt::Debug,
{
let point = P::base_point2();
let result1 = HSha512::create_hash_from_ge(&[&point, &P::generator()]);
assert!(result1.to_big_int().bit_length() > 240);
let result2 = HSha512::create_hash_from_ge(&[&P::generator(), &point]);
fn create_sha512_from_ge_test<E: Curve>() {
let generator = Point::generator().to_point_owned();
let base_point2 = Point::base_point2().to_point_owned();
let result1 = HSha512::create_hash_from_ge::<E>(&[&base_point2, &generator]);
assert!(result1.to_bigint().bit_length() > 240);
let result2 = HSha512::create_hash_from_ge(&[&generator, &base_point2]);
assert_ne!(result1, result2);
let result3 = HSha512::create_hash_from_ge(&[&P::generator(), &point]);
let result3 = HSha512::create_hash_from_ge(&[&generator, &base_point2]);
assert_eq!(result2, result3);
}
}
Loading