Skip to content

Commit

Permalink
Merge pull request #17 from zkcrypto/features-cleanup
Browse files Browse the repository at this point in the history
Change crate features to clarify functionality
  • Loading branch information
str4d committed Nov 14, 2019
2 parents 9aff249 + 6dfe4a4 commit 384e75e
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Expand Up @@ -69,7 +69,7 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: build
args: --verbose --target thumbv6m-none-eabi --no-default-features --features groups
args: --verbose --target thumbv6m-none-eabi --no-default-features --features groups,pairings

doc-links:
name: Nightly lint
Expand Down
3 changes: 2 additions & 1 deletion Cargo.toml
Expand Up @@ -25,7 +25,8 @@ version = "2.2.1"
default-features = false

[features]
default = ["groups", "pairings"]
default = ["groups", "pairings", "alloc"]
groups = []
pairings = ["groups"]
alloc = []
nightly = ["subtle/nightly"]
5 changes: 3 additions & 2 deletions README.md
Expand Up @@ -10,8 +10,9 @@ This crate provides an implementation of the BLS12-381 pairing-friendly elliptic
## Features

* `groups` (on by default): Enables APIs for performing group arithmetic with G1, G2, and GT.
* `pairings` (on by default): Enables APIs for performing pairings. This depends on the `alloc` crate.
* `nightly`: Enables `subtle/nightly` which prevents compiler optimizations that could jeopardize constant time operations.
* `pairings` (on by default): Enables some APIs for performing pairings.
* `alloc` (on by default): Enables APIs that require an allocator; these include pairing optimizations.
* `nightly`: Enables `subtle/nightly` which tries to prevent compiler optimizations that could jeopardize constant time operations. Requires the nightly Rust compiler.

## [Documentation](https://docs.rs/bls12_381)

Expand Down
8 changes: 4 additions & 4 deletions src/lib.rs
Expand Up @@ -23,7 +23,7 @@
// involve various binary operators, and so this lint is triggered unnecessarily.
#![allow(clippy::suspicious_arithmetic_impl)]

#[cfg(feature = "pairings")]
#[cfg(feature = "alloc")]
extern crate alloc;

#[cfg(test)]
Expand Down Expand Up @@ -71,11 +71,11 @@ mod fp6;
const BLS_X: u64 = 0xd201000000010000;
const BLS_X_IS_NEGATIVE: bool = true;

#[cfg(feature = "groups")]
#[cfg(feature = "pairings")]
mod pairings;

#[cfg(feature = "groups")]
#[cfg(feature = "pairings")]
pub use pairings::{pairing, Gt, MillerLoopResult};

#[cfg(feature = "pairings")]
#[cfg(all(feature = "pairings", feature = "alloc"))]
pub use pairings::{multi_miller_loop, G2Prepared};
10 changes: 5 additions & 5 deletions src/pairings.rs
Expand Up @@ -6,7 +6,7 @@ use core::ops::{Add, AddAssign, Mul, MulAssign, Neg, Sub, SubAssign};

use subtle::{Choice, ConditionallySelectable, ConstantTimeEq};

#[cfg(feature = "pairings")]
#[cfg(feature = "alloc")]
use alloc::vec::Vec;

/// Represents results of a Miller loop, one of the most expensive portions
Expand Down Expand Up @@ -219,7 +219,7 @@ impl<'a, 'b> Mul<&'b Scalar> for &'a Gt {
impl_binops_additive!(Gt, Gt);
impl_binops_multiplicative!(Gt, Scalar);

#[cfg(feature = "pairings")]
#[cfg(feature = "alloc")]
#[derive(Clone, Debug)]
/// This structure contains cached computations pertaining to a $\mathbb{G}_2$
/// element as part of the pairing function (specifically, the Miller loop) and
Expand All @@ -235,7 +235,7 @@ pub struct G2Prepared {
coeffs: Vec<(Fp2, Fp2, Fp2)>,
}

#[cfg(feature = "pairings")]
#[cfg(feature = "alloc")]
impl From<G2Affine> for G2Prepared {
fn from(q: G2Affine) -> G2Prepared {
struct Adder {
Expand Down Expand Up @@ -286,7 +286,7 @@ impl From<G2Affine> for G2Prepared {
}
}

#[cfg(feature = "pairings")]
#[cfg(feature = "alloc")]
/// Computes $$\sum_{i=1}^n \textbf{ML}(a_i, b_i)$$ given a series of terms
/// $$(a_1, b_1), (a_2, b_2), ..., (a_n, b_n).$$
///
Expand Down Expand Up @@ -544,7 +544,7 @@ fn test_unitary() {
assert_eq!(q, r);
}

#[cfg(feature = "pairings")]
#[cfg(feature = "alloc")]
#[test]
fn test_multi_miller_loop() {
let a1 = G1Affine::generator();
Expand Down

0 comments on commit 384e75e

Please sign in to comment.