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 72 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"'
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Changelog
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a changelog ! this is great :)


## v0.8.0-rc1
* Elliptic curve API has been significantly changed [#120]

In particular: ECPoint, ECScalar traits were redesigned. They remain,
but are not supposed to be used directly anymore. In replacement,
we introduce structures Point, Scalar representing elliptic point and
scalar. See curv::elliptic::curves module-level documentation to learn
more.
* Add low degree exponent interpolation proof [#119]

[#119]: https://github.com/ZenGo-X/curv/pull/119
[#120]: https://github.com/ZenGo-X/curv/pull/120
19 changes: 11 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,32 +1,35 @@
[package]
name = "curv"
version = "0.7.0"
name = "curv-kzen"
version = "0.8.0-rc1"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you explain the name change ?
why rc1?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We publish crate on crates.io under this name. I had to change the crate name to make automatic publishing possible (when you tag commit, and a new version is being uploaded to crates.io). But that's a package name, library name remains the same.

About the version — rc1 stands for "release candidate 1". It means that it's something close to what will be released in next version. My plan — I want to release curv v0.8.0-rc1, and then gradually update others crates. Updating other crates might require some changes in curv, and I'll be able to make these changes and publish v0.8.0-rc2, v0.8.0-rc3, etc. without messing with semver policies. Eventually, after all downstream crates are updated, v0.8.0 will be released.

edition = "2018"
authors = ["Omer Shlomovits"]
survived marked this conversation as resolved.
Show resolved Hide resolved
license = "MIT"
description = "Curv contains an extremly simple interface to onboard new elliptic curves. Use this library for general purpose elliptic curve cryptography"
repository = "https://github.com/ZenGo-X/curv"

[lib]
name = "curv"
crate-type = ["lib"]

[dependencies]
blake2b_simd = "0.5.7"
cryptoxide = "0.1.2"
curve25519-dalek = "1.2.3"
curve25519-dalek = "3"
derivative = "2.2"
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"
rand = "0.6"
rand = "0.7"
rand_legacy = { package = "rand", version = "0.6" }
ring-algorithm = "0.2.3"
rust-crypto = "^0.2"
serde = { version = "1.0", features = ["derive"] }
Expand All @@ -43,8 +46,8 @@ version = "0.20"
features = ["serde", "rand-std"]

[dependencies.p256]
version = "0.5"
features = ["ecdsa"]
version = "0.9"
features = ["ecdsa", "ecdsa-core", "zeroize"]

[dev-dependencies]
bincode = "1.1"
Expand Down
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@ The library has a built in support for some useful operations/primitives such as
schemes, zero knowledge proofs, and simple two party protocols such as ECDH and coin flip. The library comes with
serialize/deserialize support to be used in higher level code to implement networking.

### Usage

To use `curv` crate, add the following to your Cargo.toml:
```toml
[dependencies]
curv-kzen = "0.8"
```

The crate will be available under `curv` name, e.g.:
```rust
use curv::elliptic::curves::*;
```

### Currently Supported Elliptic Curves

| Curve | low level library | curve description |
Expand Down Expand Up @@ -44,8 +57,7 @@ You can choose any one which you prefer by specifying a feature:
* **num-bigint**, Rust's pure implementation of big integer. In order to use it, put in Cargo.toml:
```toml
[dependencies.curv]
git = "https://github.com/ZenGo-X/curv"
tag = "v0.6.0"
version = "0.8"
default-features = false
features = ["num-bigint"]
```
Expand Down
24 changes: 9 additions & 15 deletions examples/diffie_hellman_key_exchange.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use std::fmt::Debug;

use curv::elliptic::curves::traits::ECPoint;
use curv::elliptic::curves::*;

/// Diffie Hellman Key Exchange:
/// TO RUN:
Expand All @@ -11,17 +9,13 @@ use curv::elliptic::curves::traits::ECPoint;
/// notice: this library includes also a more involved ECDH scheme. see
/// dh_key_exchange_variant_with_pok_comm.rs

pub fn ecdh<P>()
where
P: ECPoint + Clone + Debug,
P::Scalar: Clone,
{
pub fn ecdh<E: Curve>() {
use curv::cryptographic_primitives::twoparty::dh_key_exchange::{
compute_pubkey, Party1FirstMessage, Party2FirstMessage,
};

let (kg_party_one_first_message, kg_ec_key_pair_party1) = Party1FirstMessage::<P>::first();
let (kg_party_two_first_message, kg_ec_key_pair_party2) = Party2FirstMessage::<P>::first();
let (kg_party_one_first_message, kg_ec_key_pair_party1) = Party1FirstMessage::<E>::first();
let (kg_party_two_first_message, kg_ec_key_pair_party2) = Party2FirstMessage::<E>::first();

assert_eq!(
compute_pubkey(
Expand All @@ -38,11 +32,11 @@ where
fn main() {
let curve_name = std::env::args().nth(1);
match curve_name.as_deref() {
Some("secp256k1") => ecdh::<curv::elliptic::curves::secp256_k1::GE>(),
Some("ristretto") => ecdh::<curv::elliptic::curves::curve_ristretto::GE>(),
Some("ed25519") => ecdh::<curv::elliptic::curves::ed25519::GE>(),
Some("bls12_381") => ecdh::<curv::elliptic::curves::bls12_381::g1::GE>(),
Some("p256") => ecdh::<curv::elliptic::curves::p256::GE>(),
Some("secp256k1") => ecdh::<Secp256k1>(),
// Some("ristretto") => ecdh::<curv::elliptic::curves::curve_ristretto::GE>(),
// Some("ed25519") => ecdh::<curv::elliptic::curves::ed25519::GE>(),
// Some("bls12_381") => ecdh::<curv::elliptic::curves::bls12_381::g1::GE>(),
// Some("p256") => ecdh::<curv::elliptic::curves::p256::GE>(),
survived marked this conversation as resolved.
Show resolved Hide resolved
Some(unknown_curve) => eprintln!("Unknown curve: {}", unknown_curve),
None => eprintln!("Missing curve name"),
}
Expand Down
28 changes: 11 additions & 17 deletions examples/pedersen_commitment.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use curv::arithmetic::{traits::*, BigInt};
use curv::elliptic::curves::traits::ECPoint;
use curv::arithmetic::*;
use curv::elliptic::curves::*;

use std::fmt::Debug;

/// Pedesen Commitment:
/// Pedersen Commitment:
/// compute c = mG + rH
/// where m is the commited value, G is the group generator,
/// H is a random point and r is a blinding value.
Expand All @@ -14,16 +12,13 @@ use std::fmt::Debug;
///
/// notice: this library includes also hash based commitments

pub fn ped_com<P>(message: &BigInt)
where
P: ECPoint + Debug,
{
pub fn ped_com<E: Curve>(message: &BigInt) {
use curv::cryptographic_primitives::commitments::pedersen_commitment::PedersenCommitment;
use curv::cryptographic_primitives::commitments::traits::Commitment;

let security_bits = 256;
let blinding_factor = BigInt::sample(security_bits);
let com = PedersenCommitment::<P>::create_commitment_with_user_defined_randomness(
let com = PedersenCommitment::<E>::create_commitment_with_user_defined_randomness(
message,
&blinding_factor,
);
Expand All @@ -36,15 +31,14 @@ where

fn main() {
let message = "commit me!";
let message_bytes = message.as_bytes();
let _message_bn = BigInt::from_bytes(message_bytes);
let _message_bn = BigInt::from_bytes(message.as_bytes());
let curve_name = std::env::args().nth(1);
match curve_name.as_deref() {
Some("secp256k1") => ped_com::<curv::elliptic::curves::secp256_k1::GE>(&_message_bn),
Some("ristretto") => ped_com::<curv::elliptic::curves::curve_ristretto::GE>(&_message_bn),
Some("ed25519") => ped_com::<curv::elliptic::curves::ed25519::GE>(&_message_bn),
Some("bls12_381") => ped_com::<curv::elliptic::curves::bls12_381::g1::GE>(&_message_bn),
Some("p256") => ped_com::<curv::elliptic::curves::p256::GE>(&_message_bn),
Some("secp256k1") => ped_com::<Secp256k1>(&_message_bn),
// Some("ristretto") => ped_com::<curv::elliptic::curves::curve_ristretto::GE>(&_message_bn),
// Some("ed25519") => ped_com::<curv::elliptic::curves::ed25519::GE>(&_message_bn),
// Some("bls12_381") => ped_com::<curv::elliptic::curves::bls12_381::g1::GE>(&_message_bn),
// Some("p256") => ped_com::<curv::elliptic::curves::p256::GE>(&_message_bn),
Some(unknown_curve) => eprintln!("Unknown curve: {}", unknown_curve),
None => eprintln!("Missing curve name"),
}
Expand Down
24 changes: 9 additions & 15 deletions examples/proof_of_knowledge_of_dlog.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use curv::elliptic::curves::traits::ECPoint;
use zeroize::Zeroize;
use curv::elliptic::curves::*;

/// Sigma protocol for proof of knowledge of discrete log
/// TO RUN:
Expand All @@ -10,27 +9,22 @@ use zeroize::Zeroize;
/// notice: this library includes other more complex sigma protocol.
/// see proofs folder for more details

pub fn dlog_proof<P>()
where
P: ECPoint + Clone,
P::Scalar: Zeroize,
{
pub fn dlog_proof<E: Curve>() {
use curv::cryptographic_primitives::proofs::sigma_dlog::*;
use curv::elliptic::curves::traits::ECScalar;

let witness: P::Scalar = ECScalar::new_random();
let dlog_proof = DLogProof::<P>::prove(&witness);
let witness = Scalar::random();
let dlog_proof = DLogProof::<E>::prove(&witness);
assert!(DLogProof::verify(&dlog_proof).is_ok());
}

fn main() {
let curve_name = std::env::args().nth(1);
match curve_name.as_deref() {
Some("secp256k1") => dlog_proof::<curv::elliptic::curves::secp256_k1::GE>(),
Some("ristretto") => dlog_proof::<curv::elliptic::curves::curve_ristretto::GE>(),
Some("ed25519") => dlog_proof::<curv::elliptic::curves::ed25519::GE>(),
Some("bls12_381") => dlog_proof::<curv::elliptic::curves::bls12_381::g1::GE>(),
Some("p256") => dlog_proof::<curv::elliptic::curves::p256::GE>(),
Some("secp256k1") => dlog_proof::<Secp256k1>(),
// Some("ristretto") => dlog_proof::<curv::elliptic::curves::curve_ristretto::GE>(),
// Some("ed25519") => dlog_proof::<curv::elliptic::curves::ed25519::GE>(),
// Some("bls12_381") => dlog_proof::<curv::elliptic::curves::bls12_381::g1::GE>(),
// Some("p256") => dlog_proof::<curv::elliptic::curves::p256::GE>(),
Some(unknown_curve) => eprintln!("Unknown curve: {}", unknown_curve),
None => eprintln!("Missing curve name"),
}
Expand Down
47 changes: 20 additions & 27 deletions examples/verifiable_secret_sharing.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use std::fmt::Debug;

use curv::elliptic::curves::traits::ECPoint;
use curv::elliptic::curves::*;

/// secret_sharing_3_out_of_5
/// Feldman VSS, based on Paul Feldman. 1987. A practical scheme for non-interactive verifiable secret sharing.
Expand All @@ -13,17 +11,12 @@ use curv::elliptic::curves::traits::ECPoint;
/// CURVE_NAME is any of the supported curves: i.e.:
/// cargo run --example verifiable_secret_sharing -- ed25519

pub fn secret_sharing_3_out_of_5<P>()
where
P: ECPoint + Clone,
P::Scalar: PartialEq + Clone + Debug,
{
pub fn secret_sharing_3_out_of_5<E: Curve>() {
use curv::cryptographic_primitives::secret_sharing::feldman_vss::VerifiableSS;
use curv::elliptic::curves::traits::ECScalar;

let secret: P::Scalar = ECScalar::new_random();
let secret = Scalar::random();

let (vss_scheme, secret_shares) = VerifiableSS::<P>::share(3, 5, &secret);
let (vss_scheme, secret_shares) = VerifiableSS::<E>::share(3, 5, &secret);

let shares_vec = vec![
secret_shares[0].clone(),
Expand All @@ -42,18 +35,18 @@ where
assert!(valid3.is_ok());
assert!(valid1.is_ok());

let g: P = ECPoint::generator();
let share1_public = g * secret_shares[0].clone();
let g = Point::generator();
let share1_public = g * &secret_shares[0];
let valid1_public = vss_scheme.validate_share_public(&share1_public, 1);
assert!(valid1_public.is_ok());

// test map (t,n) - (t',t')
let s = &vec![0, 1, 2, 3, 4];
let l0 = VerifiableSS::<P>::map_share_to_new_params(&vss_scheme.parameters, 0, &s);
let l1 = VerifiableSS::<P>::map_share_to_new_params(&vss_scheme.parameters, 1, &s);
let l2 = VerifiableSS::<P>::map_share_to_new_params(&vss_scheme.parameters, 2, &s);
let l3 = VerifiableSS::<P>::map_share_to_new_params(&vss_scheme.parameters, 3, &s);
let l4 = VerifiableSS::<P>::map_share_to_new_params(&vss_scheme.parameters, 4, &s);
let l0 = VerifiableSS::<E>::map_share_to_new_params(&vss_scheme.parameters, 0, &s);
let l1 = VerifiableSS::<E>::map_share_to_new_params(&vss_scheme.parameters, 1, &s);
let l2 = VerifiableSS::<E>::map_share_to_new_params(&vss_scheme.parameters, 2, &s);
let l3 = VerifiableSS::<E>::map_share_to_new_params(&vss_scheme.parameters, 3, &s);
let l4 = VerifiableSS::<E>::map_share_to_new_params(&vss_scheme.parameters, 4, &s);

let w = l0 * secret_shares[0].clone()
+ l1 * secret_shares[1].clone()
Expand All @@ -66,15 +59,15 @@ where
fn main() {
let curve_name = std::env::args().nth(1);
match curve_name.as_deref() {
Some("secp256k1") => secret_sharing_3_out_of_5::<curv::elliptic::curves::secp256_k1::GE>(),
Some("ristretto") => {
secret_sharing_3_out_of_5::<curv::elliptic::curves::curve_ristretto::GE>()
}
Some("ed25519") => secret_sharing_3_out_of_5::<curv::elliptic::curves::ed25519::GE>(),
Some("bls12_381") => {
secret_sharing_3_out_of_5::<curv::elliptic::curves::bls12_381::g1::GE>()
}
Some("p256") => secret_sharing_3_out_of_5::<curv::elliptic::curves::p256::GE>(),
Some("secp256k1") => secret_sharing_3_out_of_5::<Secp256k1>(),
// Some("ristretto") => {
// secret_sharing_3_out_of_5::<curv::elliptic::curves::curve_ristretto::GE>()
// }
// Some("ed25519") => secret_sharing_3_out_of_5::<curv::elliptic::curves::ed25519::GE>(),
// Some("bls12_381") => {
// secret_sharing_3_out_of_5::<curv::elliptic::curves::bls12_381::g1::GE>()
// }
// Some("p256") => secret_sharing_3_out_of_5::<curv::elliptic::curves::p256::GE>(),
Some(unknown_curve) => eprintln!("Unknown curve: {}", unknown_curve),
None => eprintln!("Missing curve name"),
}
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
2 changes: 1 addition & 1 deletion src/arithmetic/samplable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl Samplable for BigInt {
if bit_size == 0 {
return BigInt::zero();
}
let mut rng = OsRng::new().unwrap();
let mut rng = OsRng;
let bytes = (bit_size - 1) / 8 + 1;
let mut buf: Vec<u8> = vec![0; bytes];
rng.fill_bytes(&mut buf);
Expand Down
Loading