Skip to content

Commit

Permalink
Ensure G2 elements are in the correct subgroup of the twisted curve.
Browse files Browse the repository at this point in the history
  • Loading branch information
ebfull committed Dec 14, 2016
1 parent e6ebe3f commit ef95df6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "bn"
version = "0.4.1"
version = "0.4.2"
authors = ["Sean Bowe <ewillbefull@gmail.com>"]
description = "Pairing cryptography with the Barreto-Naehrig curve"
keywords = ["pairing","crypto","cryptography"]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -14,7 +14,7 @@ Add the `bn` crate to your dependencies in `Cargo.toml`...

```toml
[dependencies]
bn = "0.4.1"
bn = "0.4.2"
```

...and add an `extern crate` declaration to your crate root:
Expand Down
15 changes: 15 additions & 0 deletions src/groups/mod.rs
Expand Up @@ -30,6 +30,7 @@ pub trait GroupParams: Sized {
fn name() -> &'static str;
fn one() -> G<Self>;
fn coeff_b() -> Self::Base;
fn check_order() -> bool { false }
}

#[repr(C)]
Expand Down Expand Up @@ -181,6 +182,18 @@ impl<P: GroupParams> Decodable for AffineG<P> {

// y^2 = x^3 + b
if y.squared() == (x.squared() * x) + P::coeff_b() {
if P::check_order() {
let p: G<P> = G {
x: x,
y: y,
z: P::Base::one()
};

if (p * (-Fr::one())) + p != G::zero() {
return Err(s.error("point is not in the subgroup"))
}
}

Ok(AffineG {
x: x,
y: y
Expand Down Expand Up @@ -378,6 +391,8 @@ impl GroupParams for G2Params {
const_fq([0x38e7ecccd1dcff67, 0x65f0b37d93ce0d3e, 0xd749d0dd22ac00aa, 0x0141b9ce4a688d4d])
)
}

fn check_order() -> bool { true }
}

pub type G2 = G<G2Params>;
Expand Down

0 comments on commit ef95df6

Please sign in to comment.