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

Commits on Aug 31, 2018

  1. Update to Rust beta channel.

    mbr committed Aug 31, 2018
    Copy the full SHA
    a7cd6e0 View commit details

Commits on Sep 3, 2018

  1. Use Formatter debug helpers. Hide SecretKeyShares.

    Output "..." in the `Debug` implementation of `SecretKeyShare`, to make
    it consistent with `SecretKey`.
    afck committed Sep 3, 2018
    Copy the full SHA
    a03d258 View commit details
  2. Merge pull request #22 from poanetwork/afck-fmt

    Use Formatter debug helpers. Hide SecretKeyShares.
    vkomenda authored Sep 3, 2018
    Copy the full SHA
    76ac2a5 View commit details
  3. Simplify Poly multiplication, speed up interpolation. (#23)

    * Simplify Poly multiplication, speed up interpolation.
    
    Also add more `Mul` implementations.
    
    * Postpone division: speed up interpolation some more.
    
    * Speed up interpolation: re-use base polynomial.
    afck authored Sep 3, 2018
    Copy the full SHA
    ded335f View commit details

Commits on Sep 4, 2018

  1. Copy the full SHA
    72d1c60 View commit details
  2. Copy the full SHA
    f7d9c26 View commit details
  3. Merge pull request #28 from poanetwork/try-prefixed-constructors

    Added 'try_' constructors to secret types.
    vkomenda authored Sep 4, 2018
    Copy the full SHA
    a2fa8a4 View commit details

Commits on Sep 12, 2018

  1. Copy the full SHA
    b39cc1f View commit details

Commits on Sep 13, 2018

  1. Merge pull request #32 from poanetwork/ag_typos

    Typo fixes, added Code of Conduct file
    andogro authored Sep 13, 2018
    Copy the full SHA
    b48a4b6 View commit details

Commits on Sep 14, 2018

  1. Copy the full SHA
    5f09f96 View commit details

Commits on Sep 19, 2018

  1. Adds a few more benchmarks for poly operators. Changed benchmarks to …

    …use a seeded rng for reproducibility.
    fhaynes authored and afck committed Sep 19, 2018
    Copy the full SHA
    e0c488a View commit details

Commits on Sep 22, 2018

  1. use Rust 1.29

    vkomenda authored and afck committed Sep 22, 2018
    Copy the full SHA
    e28b77d View commit details

Commits on Sep 26, 2018

  1. Update authors list.

    afck authored and c0gent committed Sep 26, 2018
    Copy the full SHA
    42f4ace View commit details
  2. Run cargo-deadlinks in CI.

    afck authored and c0gent committed Sep 26, 2018
    Copy the full SHA
    b786d89 View commit details

Commits on Sep 27, 2018

  1. Add benchmark for combining signatures

    fhaynes authored and afck committed Sep 27, 2018
    Copy the full SHA
    4b1e6ee View commit details
  2. Copy the full SHA
    bc04ea5 View commit details
  3. Copy the full SHA
    c72bc9a View commit details

Commits on Oct 2, 2018

  1. Copy the full SHA
    3645668 View commit details

Commits on Oct 8, 2018

  1. Merge xor_vec and hash_bytes.

    They are only used together, and the API of `xor_vec` is a bit dangerous
    since it silently stops at the minimum of the two arguments' lengths.
    afck committed Oct 8, 2018
    Copy the full SHA
    0bb41bd View commit details
  2. Copy the full SHA
    84e8b69 View commit details
  3. Convert all uses of Bls12 and friends to refer to root lib.rs ins…

    …tead of importing from pairing directly.
    mbr authored and afck committed Oct 8, 2018
    Copy the full SHA
    d69590b View commit details
  4. Prepare for adding mock cryptography for testing.

    * Add a feature flag (that doesn't do anything yet).
    * Give `clear_fr` a stronger type to prevent mistakes and ensure the
      right amount of memory gets cleared.
    * Re-export the engine and related types from `lib.rs`.
    afck committed Oct 8, 2018
    Copy the full SHA
    0efdad4 View commit details
  5. Reexport pairing.

    Since we are reexporting some of the pairing types, we should also
    export pairing itself, to make all the matching traits available and
    avoid version conflicts.
    afck committed Oct 8, 2018
    Copy the full SHA
    191cf0b View commit details
  6. Remove mlock.

    It currently causes too many problems to be practical. We will re-enable
    it once we have a dedicated allocator for locked memory.
    afck committed Oct 8, 2018
    Copy the full SHA
    ad11cea View commit details
  7. Remove try_ methods.

    afck committed Oct 8, 2018
    Copy the full SHA
    214e5f8 View commit details

Commits on Oct 9, 2018

  1. Optimize polynomial interpolation in the curve.

    Slightly reduce the number of multiplication and division operations in
    the scalar field.
    afck committed Oct 9, 2018
    Copy the full SHA
    3d324bb View commit details
  2. Merge pull request #46 from poanetwork/afck-interpolate

    Optimize polynomial interpolation in the curve.
    vkomenda authored Oct 9, 2018
    Copy the full SHA
    f1742a6 View commit details

Commits on Oct 11, 2018

  1. Copy the full SHA
    d9da308 View commit details
  2. Remove explicit Send+Sync impl for Error.

    afck authored and mbr committed Oct 11, 2018
    Copy the full SHA
    90f63e3 View commit details
  3. Mocktography (#49)

    Added mocktography (feature `use-insecure-test-only-mock-crypto) and factored out CI execution script.
    mbr authored Oct 11, 2018
    Copy the full SHA
    d133bb6 View commit details
  4. Copy the full SHA
    20de873 View commit details

Commits on Oct 16, 2018

  1. Add cargo audit to CI.

    mbr authored and afck committed Oct 16, 2018
    Copy the full SHA
    0d4c376 View commit details
  2. Copy the full SHA
    2ca1d2e View commit details
  3. Use hex_fmt 0.2.0.

    afck authored and mbr committed Oct 16, 2018
    Copy the full SHA
    29b40ff View commit details

Commits on Oct 20, 2018

  1. Version 0.2.0

    Also: Follow the soon-to-be-official formatting guidelines:
    https://github.com/nrc/rfcs/blob/style-guide/style-guide/cargo.md
    afck committed Oct 20, 2018
    Copy the full SHA
    96db9fb View commit details

Commits on Oct 22, 2018

  1. Make hash_g2 public.

    This function can be useful, to avoid redundant hashing of a long message.
    afck committed Oct 22, 2018
    Copy the full SHA
    1d613c2 View commit details
  2. Version 0.2.1

    afck committed Oct 22, 2018
    Copy the full SHA
    a4e0da3 View commit details

Commits on Oct 27, 2018

  1. Upgrade to Rust 1.30.0.

    afck committed Oct 27, 2018
    Copy the full SHA
    54026f5 View commit details

Commits on Oct 28, 2018

  1. Merge pull request #58 from poanetwork/afck-rust-1.30.0

    Upgrade to Rust 1.30.0.
    vkomenda authored Oct 28, 2018
    Copy the full SHA
    0cadd31 View commit details

Commits on Oct 30, 2018

  1. Instead of macro_use, use use.

    afck committed Oct 30, 2018
    Copy the full SHA
    05cde32 View commit details

Commits on Nov 1, 2018

  1. Added security audit link

    andogro authored and afck committed Nov 1, 2018
    Copy the full SHA
    3ffe4b3 View commit details

Commits on Nov 6, 2018

  1. Linked to security audit in POA wiki

    andogro authored and afck committed Nov 6, 2018
    Copy the full SHA
    a0aa960 View commit details
  2. Update rand reference

    andogro authored and afck committed Nov 6, 2018
    Copy the full SHA
    4fec9da View commit details

Commits on Nov 26, 2018

  1. Make serialization less wasteful.

    This removes the unneeded length from key and signature representation,
    removing 8 bytes from each. Also adds `from_bytes` and `to_bytes`
    methods to convert keys and signatures.
    afck committed Nov 26, 2018
    Copy the full SHA
    c7eda7a View commit details

Commits on Nov 29, 2018

  1. Copy the full SHA
    c2d63b2 View commit details

Commits on Dec 10, 2018

  1. Copy the full SHA
    1b1df40 View commit details

Commits on Dec 18, 2018

  1. Migrate to rand 0.6.

    afck committed Dec 18, 2018
    Copy the full SHA
    a14e7d1 View commit details
  2. Export serde_impl::FieldWrap.

    afck committed Dec 18, 2018
    Copy the full SHA
    8b6fa87 View commit details
  3. Update docs.rs link.

    afck committed Dec 18, 2018
    Copy the full SHA
    9ab0989 View commit details
  4. Version 0.3.0

    afck committed Dec 18, 2018
    Copy the full SHA
    dbb9fae View commit details
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