Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: poanetwork/threshold_crypto
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.1.0
Choose a base ref
...
head repository: poanetwork/threshold_crypto
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Loading
Showing with 2,683 additions and 1,078 deletions.
  1. +5 −27 .travis.yml
  2. +73 −0 CODE_OF_CONDUCT.md
  3. +4 −4 CONTRIBUTING.md
  4. +37 −24 Cargo.toml
  5. +33 −17 README.md
  6. +104 −22 benches/bench.rs
  7. +19 −0 ci.sh
  8. +1 −5 examples/basic_pkc.rs
  9. +9 −12 examples/threshold_enc.rs
  10. +33 −36 examples/threshold_sig.rs
  11. +10 −0 src/cmp_pairing.rs
  12. +29 −0 src/codec_impl.rs
  13. +33 −33 src/error.rs
  14. +3 −2 src/into_fr.rs
  15. +529 −388 src/lib.rs
  16. +325 −0 src/mock/mod.rs
  17. +814 −0 src/mock/ms8.rs
  18. +279 −439 src/poly.rs
  19. +31 −0 src/secret.rs
  20. +303 −69 src/serde_impl.rs
  21. +9 −0 src/util.rs
32 changes: 5 additions & 27 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: rust
rust:
- stable
- 1.42.0
cache:
cargo: true
timeout: 1200
@@ -9,29 +9,7 @@ addons:
packages:
- unzip
before_install:
# The Rust stable toolchain is already installed, ${RUST_NEXT} is added to
# provide `cargo clippy` and `cargo fmt`.
- rustup toolchain install ${RUST_NEXT}
- rustup component add --toolchain=${RUST_NEXT} rustfmt-preview clippy-preview
# Some symlinking is still necessary for clippy to function properly.
- ln -sf ${HOME}/.rustup/toolchains/${RUST_NEXT}-x86_64-unknown-linux-gnu/bin/clippy-driver ${HOME}/.rustup/toolchains/${RUST_NEXT}-x86_64-unknown-linux-gnu/bin/cargo-clippy $HOME/.cargo/bin/
env:
global:
- RUST_BACKTRACE=1
# Enables additional cpu-specific optimizations.
- RUSTFLAGS="-D warnings -C target-cpu=native"
# Note: Currently (as of 2018-07-13), `clippy-preview` is only in the nightly
# release. A version of `rustfmt` that supports the `--check` option
# is also not in stable yet.
#
# A Clear migration path is swapping out `nightly-2018-07-13` with
# `beta` after the stable release of Rust 1.28; and finally migrating
# everything to `stable` at Rust 1.29.
- RUST_NEXT=nightly-2018-07-13
script:
- cargo +${RUST_NEXT} clippy -- --deny clippy
- cargo +${RUST_NEXT} clippy --tests --examples --benches -- --deny clippy
- cargo +${RUST_NEXT} clippy --all-features -- --deny clippy
- cargo +${RUST_NEXT} clippy --all-features --tests -- --deny clippy
- cargo +${RUST_NEXT} fmt -- --check
- cargo test --all-features --release
- rustup component add --toolchain=${TRAVIS_RUST_VERSION} rustfmt clippy
- cargo deadlinks --version || cargo install cargo-deadlinks
- cargo audit --version || cargo install cargo-audit
script: ./ci.sh
73 changes: 73 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, gender identity and expression, level of experience,
education, socio-economic status, nationality, personal appearance, race,
religion, or sexual identity and orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at andreas@poa.network. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html

[homepage]: https://www.contributor-covenant.org
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -9,11 +9,11 @@ submitting code or comments.
3. Write tests that cover your work.
4. Run Rustfmt, Clippy, and all tests to ensure CI rules are satisfied.
Correct versions and feature flags can be found in the
[`.travis.yml`](https://github.com/poanetwork/hbbft/blob/master/.travis.yml)
[`.travis.yml`](.travis.yml)
file.
5. Commit your changes (`git commit -am 'Add some feature'`).
6. Push to your branch (`git push origin my-new-feature`).
7. Create a new PR (Pull Request).
7. Create a new Pull Request.

### General

@@ -34,11 +34,11 @@ submitting code or comments.

### Issues

Creating and discussing [Issues](https://github.com/poanetwork/hbbft/issues)
Creating and discussing [Issues](https://github.com/poanetwork/threshold_crypto/issues)
provides significant value to the project. If you find a bug you can report it
in an Issue.

### Pull Requests
### Pull Requests (PR)

All pull requests should include:

61 changes: 37 additions & 24 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,37 +1,50 @@
[package]
name = "threshold_crypto"
# REMINDER: Update version in `README.md` when incrementing:
version = "0.1.0"
authors = ["Andreas Fackler <AndreasFackler@gmx.de>",
"Peter van Nostrand <jnz@riseup.net>"]
description = "Pairing threshold cryptography"
version = "0.4.0"
authors = [
"Vladimir Komendantskiy <komendantsky@gmail.com>",
"Andreas Fackler <AndreasFackler@gmx.de>",
"Peter van Nostrand <jnz@riseup.net>",
"Andrew Gross <andogro@gmail.com>",
"Nick Sanders <nsan1129@gmail.com>",
"Marc Brinkmann <git@marcbrinkmann.de>",
]
categories = ["cryptography"]
keywords = ["pairing", "threshold"]
license = "MIT/Apache-2.0"
repository = "https://github.com/poanetwork/threshold_crypto"
readme = "README.md"
keywords = ["pairing", "threshold"]
categories = ["cryptography"]
repository = "https://github.com/poanetwork/threshold_crypto"
description = "Pairing threshold cryptography"
edition = "2018"

[dependencies]
byteorder = "1.2.3"
errno = "0.2.4"
failure = "0.1"
init_with = "1.1.0"
lazy_static = "1.1.0"
log = "0.4.1"
memsec = "0.5.4"
pairing = { version = "0.14.2", features = ["u128-support"] }
rand = "0.4.2"
rand_derive = "0.3.1"
serde = "1.0.55"
serde_derive = "1.0.55"
tiny-keccak = "1.4"
byteorder = "1.3.4"
ff = "0.6.0"
group = "0.6.0"
hex_fmt = "0.3.0"
log = "0.4.8"
pairing = "0.16.0"
rand = "0.7.3"
rand_chacha = "0.2.2"
serde = { version = "1.0.104", features = ["derive"] }
thiserror = "1.0.22"
tiny-keccak = { version = "2.0.1", features = ["sha3"] }
zeroize = "1.1.0"

# optional
bincode = { version = "1.2.1", optional = true }
codec = { package = "parity-scale-codec", version = "1.2.0", default-features = false, features = ["derive"], optional = true }

[dev-dependencies]
bincode = "1.0.0"
criterion = "0.2"
rand = "0.4.2"
serde_derive = "1.0.55"
bincode = "1.2.1"
criterion = "0.3.1"
rand_xorshift = "0.2.0"

[[bench]]
name = "bench"
harness = false

[features]
use-insecure-test-only-mock-crypto = []
codec-support = ["codec", "bincode"]
50 changes: 33 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
# threshold_crypto

[![crates.io](https://img.shields.io/crates/v/threshold_crypto.svg)](https://crates.io/crates/threshold_crypto)
[![Documentation](https://docs.rs/threshold_crypto/badge.svg)](https://docs.rs/threshold_crypto)
[![Build Status](https://travis-ci.org/poanetwork/threshold_crypto.svg?branch=master)](https://travis-ci.org/poanetwork/threshold_crypto)

A pairing-based threshold cryptosystem for collaborative decryption and
signatures.
A pairing-based threshold cryptosystem for collaborative decryption and signatures.

The `threshold_crypto` crate provides constructors for encrypted message handling. It utilizes the [`pairing`](https://crates.io/crates/pairing) elliptic curve library to create and enable reconstruction of public and private key shares.
The `threshold_crypto` crate provides cryptographic keys with methods for signing and encrypting messages, as well as key sets for _threshold_ signatures and threshold encryption.

In a network environment, messages are signed and encrypted, and key and
signature shares are distributed to network participants. A message can be
decrypted and authenticated only with cooperation from at least `threshold +
The threshold signature scheme is described in [Threshold Signatures, Multisignatures and Blind Signatures Based on the Gap-Diffie-Hellman-Group Signature Scheme](https://www.iacr.org/archive/pkc2003/25670031/25670031.pdf) by Alexandra Boldyreva. This paper extends [Boneh-Lynn-Shacham](https://www.iacr.org/archive/asiacrypt2001/22480516.pdf) signatures to the threshold setting. Message encryption uses the [scheme by Baek and Zhang](http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.119.1717&rep=rep1&type=pdf).
Our implementation is based on the [`pairing`](https://crates.io/crates/pairing) elliptic curve library.

In a network environment, messages are signed and encrypted, and key and signature shares are distributed to network participants. A message can be decrypted and authenticated only with cooperation from at least `threshold +
1` nodes.

## Security Audit

An [official security audit](https://github.com/poanetwork/wiki/wiki/Threshold-Crypto-Audit) has been completed on `threshold_crypto` by [Jean-Philippe Aumasson](https://aumasson.jp/). No exploitable security issues were found, and potential improvements have been addressed. Outdated dependencies mentioned in the audit were updated in commit [54026f5](https://github.com/poanetwork/threshold_crypto/commit/54026f5fe7e0b5a52e446ac01a50469da1f15a71).

## Usage

`Cargo.toml`:

```toml
[dependencies]
rand = "0.4"
threshold_crypto = { version = "0.1", git = "https://github.com/poanetwork/threshold_crypto" }
threshold_crypto = { version = "0.4", git = "https://github.com/poanetwork/threshold_crypto" }
```

`main.rs`:
@@ -32,8 +37,8 @@ use threshold_crypto::SecretKey;

/// Very basic secret key usage.
fn main() {
let sk0: SecretKey = rand::random();
let sk1: SecretKey = rand::random();
let sk0 = SecretKey::random();
let sk1 = SecretKey::random();

let pk0 = sk0.public_key();

@@ -46,24 +51,26 @@ fn main() {
}
```

### Testing

Run tests with:

```
$ cargo test
```

### Examples

Run examples from the [`examples`](examples) directory using:

```
$ MLOCK_SECRETS=false cargo run --example <example name>
$ cargo run --example <example name>
```

Also see the
[distributed_key_generation](https://github.com/poanetwork/threshold_crypto/blob/d81953b55d181311c2a4eed2b6c34059fcf3fdae/src/poly.rs#L967)
test.

### Environment Variables

[`MLOCK_SECRETS`](https://github.com/poanetwork/threshold_crypto/blob/master/src/lib.rs#L51): Sets whether or not the Unix syscall [`mlock`](http://man7.org/linux/man-pages/man2/mlock.2.html) or WinAPI function [`VirtualLock`](https://msdn.microsoft.com/en-us/library/windows/desktop/aa366895(v=vs.85).aspx) is called on portions of memory containing secret values. This option is enabled by default (`MLOCK_SECRETS=true`). Disabling memory locking (`MLOCK_SECRETS=false`) allows secret values to be copied to disk, where they will not be zeroed on drop and may persist indefinitely. **Disabling memory locking should only be done in development and testing.**

Disabling memory locking is useful because it removes the possibility of tests failing due to reaching the testing system's locked memory limit. For example, if your crate uses `threshold_crypto` and you write a test that maintains hundreds or thousands of secrets in memory simultaneously, you run the risk of reaching your system's allowed number of locked pages, which will cause this library to fail.

## Application Details

The basic usage outline is:
@@ -93,6 +100,11 @@ must tolerate up to `t` adversarial (malicious or faulty) nodes. Because `t +
1` nodes are required to sign or reveal information, messages can be trusted
by third-parties as representing the consensus of the network.

### Documentation

* [crate documentation](https://docs.rs/threshold_crypto/)
* [crates.io package](https://crates.io/crates/threshold_crypto)

## Performance

Benchmarking functionality is kept in the [`benches` directory](benches). You
@@ -104,6 +116,10 @@ $ RUSTFLAGS="-C target_cpu=native" cargo bench

We use the [`criterion`](https://crates.io/crates/criterion) benchmarking library.

### Mock cryptography

To speed up automatic tests of crates depending on `threshold_crypto`, the `use-insecure-test-only-mock-crypto` feature is available. **Activating this feature will effectively disable encryption and should only be used during tests!** Essentially, the underlying elliptic curves will be replaced by small finite fields, yielding a 10-200X speed-up in execution. The resulting ciphers can be trivially broken in a number of ways and should never be used in production.

## License

Licensed under either of:
Loading