Giter Club home page Giter Club logo

agora-unknown_order's Introduction

unknown_order

Crates.io Documentation License-Image minimum rustc 1.50 dependency status

Crate for handling groups of unknown order.

I've seen this commonly across multiple projects where they need a multiprecision library and use one of three libraries: Gnu MP BigNum Library, OpenSSL's BigNum Library and Rust's BigInt Library, depending on the needs and requirements (licensing, performance, platform target, constant time).

The default is to use the pure rust option without any external C bindings. This version is also friendly to WASM.

To use OpenSSL's BigNum library, you must have libcrypto and libssl in your path. Put the following in your Cargo.toml.

unknown_order = { version = "0.9", default-features = false, features = ["openssl"] }

To use Gnu MP BigNum library, you must have libgmp in your path. Put the following in your Cargo.toml.

unknown_order = { version = "0.9", default-features = false, features = ["gmp"] }

This library wraps them all into a common API, so they can be used interchangeably.

Groups of unknown order require using a modulus that is the composite of two big prime numbers. This library is designed to facilitate these use cases such as RSA, Paillier, Hyperelliptic Curves, Accumulators, CL signatures.

The modulus is not known at compile time which excludes using certain traits like ff::PrimeField, so unfortunately, the caller needs to remember to use methods prefixed with mod to achieve the desired results.

This library can only have one implementation active at a time. Mixing between implementations isn't necessarily a problem as much as injecting lots of dependencies and mixing licenses which is not a good idea. This also forces the user to understand what tradeoffs they are making when they select a specific implementation. For example, some implementations may not be constant time versus others which is important when used for cryptographic purposes.

When using features=openssl or features=gmp, the constant time implementations are used if available.

Examples

use unknown_order::BigNumber;

fn main() {
    // Create a safe group of unknown order
    let p = BigNumber::safe_prime(1024);
    let q = BigNumber::safe_prime(1024);
    let n = p.clone() * q.clone();
    
    // Simulate RSA algorithm, DO NOT USE totally insecure
    
    // Public key
    let e = BigNumber::from(65537);
    
    // throw away when done
    let totient = (p.clone() - 1) * (q.clone() - 1);
    
    // Secret key
    let d = e.invert(&totient).unwrap();
    
    
}

License

Licensed under either of:

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

This crate is part of the Hyperledger Labs Agora Project

agora-unknown_order's People

Contributors

mikelodder7 avatar ryjones avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

agora-unknown_order's Issues

Replace rust-gmp dependency by rug

As noted in #5 the rust-gmp dependency very likely contains UB by using the deprecated uninitialized function instead of MaybeUninit.
rust-gmp does not seem to be maintained with the last commit being in 2017 and 11 open pull requests.
I propose to replace rust-gmp by rug which is an actively maintained high-level interface to GMP (among others). The major difference is, that it statically links gmp instead of dynamically like rust-gmp. Personally, I see that as an advantage of rug over rust-gmp.

crypto-bigint

Hello!

I thought you might be interested in the crypto-bigint crate we've been working on as part of RustCrypto, which we are slowly beginning to use in our elliptic curve crates:

We're targeting Rust 1.51+ with it and aggressively trying to leverage both const generics and const fn as much as is possible on stable Rust.

We're targeting constant-time operation by default, with some secondary variable-time implementations explicitly called out as *_vartime.

I'm not sure we yet provide the functionality you need, or if the approach we're using (fixed-width, stack-allocated, no_std friendly big integers) actually maps well to this particular problem, but I thought I'd give it a mention.

If there's missing functionality you'd like to see implemented first, that's definitely something we'd like to know about:

https://github.com/RustCrypto/utils/issues/453

Support deterministic prime generation

The current API creates an internal RNG to use for prime generation. Allowing a user-provided RNG is very useful to deterministically re-generate a keypair from a seed. I'm not sure about openssl yet, but this should be doable for both GMP and rust backends.

Rust backend - safe_prime sometimes generates 1025 instead of 1024 bits

While running the tests for the rust backend, I received the following error:

โžœ  unknown_order git:(main) cargo test --release
    Finished release [optimized] target(s) in 0.03s
     Running unittests (target/release/deps/unknown_order-ed6009b21a5a84b7)

running 1 test
test rust_backend::safe_prime ... FAILED

failures:

---- rust_backend::safe_prime stdout ----
thread 'rust_backend::safe_prime' panicked at 'assertion failed: `(left == right)`
  left: `1025`,
 right: `1024`', src/rust_backend.rs:322:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
    rust_backend::safe_prime

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 34.91s

error: test failed, to rerun pass '--lib'

in most executions, the test passes but occasionally the prime size is off by one. I assume this is a bug in glass_pumpkin which is used to generate the safe primes for this backend.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.