From 636a037bb19d89c30a9ffc934e47b3e5f4d101f9 Mon Sep 17 00:00:00 2001 From: Sean Bowe Date: Thu, 28 Sep 2017 12:52:14 -0600 Subject: [PATCH 1/4] Make `u128-support` feature opt-in rather than default. --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index ae2eed5..778a0c6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,4 +17,4 @@ clippy = { version = "0.0.151", optional = true } [features] unstable-features = [] u128-support = [] -default = ["u128-support"] +default = [] From 291fa719147d5b293833f904fc5fb9f084b50b18 Mon Sep 17 00:00:00 2001 From: Sean Bowe Date: Thu, 28 Sep 2017 13:03:01 -0600 Subject: [PATCH 2/4] This coercion doesn't take place on stable yet. --- src/wnaf.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wnaf.rs b/src/wnaf.rs index de5021d..0cdae3b 100644 --- a/src/wnaf.rs +++ b/src/wnaf.rs @@ -108,7 +108,7 @@ impl Wnaf<(), Vec, Vec> { // Return a Wnaf object that immutably borrows the computed base storage location, // but mutably borrows the scalar storage location. Wnaf { - base: &self.base, + base: &self.base[..], scalar: &mut self.scalar, window_size: window_size } @@ -131,7 +131,7 @@ impl Wnaf<(), Vec, Vec> { // immutably borrows the computed wNAF form scalar location. Wnaf { base: &mut self.base, - scalar: &self.scalar, + scalar: &self.scalar[..], window_size: window_size } } From 93e2a132b5229fc0414dfca07102513eebbee12a Mon Sep 17 00:00:00 2001 From: Sean Bowe Date: Thu, 28 Sep 2017 13:15:29 -0600 Subject: [PATCH 3/4] Mask rather than divn, closes #50. --- src/bls12_381/fq.rs | 5 ++++- src/bls12_381/fr.rs | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/bls12_381/fq.rs b/src/bls12_381/fq.rs index 8440b1d..569b57a 100644 --- a/src/bls12_381/fq.rs +++ b/src/bls12_381/fq.rs @@ -415,7 +415,10 @@ impl ::rand::Rand for Fq { fn rand(rng: &mut R) -> Self { loop { let mut tmp = Fq(FqRepr::rand(rng)); - tmp.0.divn(REPR_SHAVE_BITS); + + // Mask away the unused bits at the beginning. + tmp.0.as_mut()[5] &= 0xffffffffffffffff >> REPR_SHAVE_BITS; + if tmp.is_valid() { return tmp } diff --git a/src/bls12_381/fr.rs b/src/bls12_381/fr.rs index 0571563..d10ba93 100644 --- a/src/bls12_381/fr.rs +++ b/src/bls12_381/fr.rs @@ -237,7 +237,10 @@ impl ::rand::Rand for Fr { fn rand(rng: &mut R) -> Self { loop { let mut tmp = Fr(FrRepr::rand(rng)); - tmp.0.divn(REPR_SHAVE_BITS); + + // Mask away the unused bits at the beginning. + tmp.0.as_mut()[3] &= 0xffffffffffffffff >> REPR_SHAVE_BITS; + if tmp.is_valid() { return tmp } From 4aa51bd3d4dcd35f66c7fbeec9bc3cb35b1a852c Mon Sep 17 00:00:00 2001 From: Sean Bowe Date: Thu, 28 Sep 2017 13:32:34 -0600 Subject: [PATCH 4/4] Add security warnings and some instructions to README.md. --- Cargo.toml | 2 ++ README.md | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 778a0c6..c0457a2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,7 @@ [package] name = "pairing" + +# Remember to change version string in README.md. version = "0.11.0" authors = ["Sean Bowe "] license = "MIT/Apache-2.0" diff --git a/README.md b/README.md index 538a5c5..21086e8 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,20 @@ This is a Rust crate for using pairing-friendly elliptic curves. Currently, only ## [Documentation](https://docs.rs/pairing/) +Bring the `pairing` crate into your project just as you normally would. + +If you're using a supported platform and the nightly Rust compiler, you can enable the `u128-support` feature for faster arithmetic. + +```toml +[dependencies.pairing] +version = "0.11" +features = ["u128-support"] +``` + +## Security Warnings + +This library does not make any guarantees about constant-time operations, memory access patterns, or resistance to side-channel attacks. + ## License Licensed under either of