Skip to content

Commit

Permalink
Support different bigint implementations (#106)
Browse files Browse the repository at this point in the history
* Sync

* Replace BigInt type alias with a structure

* Sync

* Add doc comments

* Add option to use num-bigint

* Move common macros to separate module

* Implement remaining traits

* Write more docs & examples

* Remove redundant tests

* Update remaining crate to support new BigInt

* Bump version, update README, write more docs, fix missing trait

* Add checking / searching primes capabilities

* Remove Sign from exporting / importing

* Implement a few more traits

* Remove ambiguous method is_even from NumberTests

* Implement more ops

* Impl Display trait

* Fix clippy warnings

* Delete commented out tests

* Return back old samplabe implementation

* Remove Sign enum

* Put warning in README

* Fix doctests
  • Loading branch information
Denis Varlakov committed Feb 16, 2021
1 parent 4d2bf30 commit 598d08b
Show file tree
Hide file tree
Showing 33 changed files with 2,224 additions and 515 deletions.
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

0 comments on commit 598d08b

Please sign in to comment.