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

Support different bigint implementations #106

Merged
merged 23 commits into from
Feb 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 10 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "curv"
version = "0.5.9"
version = "0.6.0"
edition = "2018"
authors = ["Omer Shlomovits"]
license = "MIT"
Expand All @@ -22,20 +22,21 @@ generic-array = "0.14"
hex = "^0.3"
hmac = "0.7.1"
merkle-sha3 = "^0.1"
lazy_static = "1.4.0"
num-traits = "0.2"
num-integer = "0.1"
pairing-plus = "0.19"
rand = "0.6"
ring-algorithm = "0.2.3"
rust-crypto = "^0.2"
serde = "1.0"
serde = { version = "1.0", features = ["derive"] }
serde_derive = "1.0"
sha2 = "0.8.0"
sha3 = "0.8.2"
zeroize = "0.10"

[dependencies.rust-gmp-kzen]
version = "0.5.0"
features = ["serde_support"]
rust-gmp-kzen = { version = "0.5", features = ["serde_support"], optional = true }
num-bigint = { version = "0.3", features = ["serde"], optional = true }

[dependencies.secp256k1]
version = "0.15.3"
Expand All @@ -50,3 +51,7 @@ bincode = "1.1"
serde_json = "1.0"
paste = "1.0.2"
proptest = "0.10"
proptest-derive = "0.2"

[features]
default = ["rust-gmp-kzen"]
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,22 @@ attacks as possible (see audit report).
### Build
Use `cargo build` to build everything including curve implementations, cryptoprimitives, BigInt, etc.

### Big integer implementation
The library supports a couple of bigint implementations and can easily switch between them.
You can choose any one which you prefer by specifying a feature:
* **rust-gmp-kzen**, uses GMP bindings, requires GMP to be installed on a machine. Used by default.
* **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"
default-features = false
features = ["num-bigint"]
```

**_Warning:_** `num-bigint` support is experimental and should not be used in production. For this
bigint implementation, we use prime numbers generator which is not considered secure.

### Examples
The library includes some basic examples to get you going. To run them:
`cargo run --example EXAMPLE_NAME -- CURVE_NAME`
Expand Down
5 changes: 2 additions & 3 deletions examples/pedersen_commitment.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use curv::arithmetic::{traits::*, BigInt};
use curv::elliptic::curves::traits::ECPoint;
use curv::BigInt;

use std::fmt::Debug;

Expand All @@ -18,7 +18,6 @@ pub fn ped_com<P>(message: &BigInt)
where
P: ECPoint + Debug,
{
use curv::arithmetic::traits::Samplable;
use curv::cryptographic_primitives::commitments::pedersen_commitment::PedersenCommitment;
use curv::cryptographic_primitives::commitments::traits::Commitment;

Expand All @@ -38,7 +37,7 @@ where
fn main() {
let message = "commit me!";
let message_bytes = message.as_bytes();
let _message_bn = BigInt::from(message_bytes);
let _message_bn = BigInt::from_bytes(message_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),
Expand Down
Loading