Enforce that Fr of Engine is the scalar for curve points
In bellman, I want to write:
```rust
pub struct Point<C: CurveProjective>(pub C);
impl<C: CurveProjective> Copy for Point<C> { }
impl<C: CurveProjective> Clone for Point<C> {
fn clone(&self) -> Point<C> {
*self
}
}
impl<C: CurveProjective> Group<C::Engine> for Point<C> {
fn group_zero() -> Self {
Point(C::zero())
}
fn group_mul_assign(&mut self, by: &C::Scalar) {
self.0.mul_assign(by.into_repr());
}
fn group_add_assign(&mut self, other: &Self) {
self.0.add_assign(&other.0);
}
fn group_sub_assign(&mut self, other: &Self) {
self.0.sub_assign(&other.0);
}
}
```
However, this doesn't typecheck because the compiler cannot know that the `Engine`'s `Fr` type (as dictated by the `Group` trait) is the same as the `Scalar` type of the `CurveProjective` point. This can be solved with a where bound over the trait (for now), but it is generally a good idea for this to be constrained in `pairing`.
Add "scale_by_cofactor".
Add a function for Affine types that multiplies point by the cofactor of the
group. If the points are in the group, they'll thus end up in the
correct subgroup.
note: this patch is already being tested with previous unittests.
note: this patch raises warning for unused functions and consts.
RELIC interop
Closes#2
RELIC has changed the G2 generator to match ours: https://github.com/relic-toolkit/relic/commit/25aafecbecba237a786aa8881719b4a95eecefbc
RELIC will not have the same serialization as us.
One last difference is that RELIC conjugates the pairing result to account for the negative curve parameter. It doesn't matter for BLS curves but it's strictly more correct.
Introduce stable arithmetic to avoid nightly/unstable features for some platforms
This PR allows the user to opt-out of the "u128-support" feature so that they can use the stable compiler and avoid the unstable `i128_type` feature in the Rust compiler. (Pass `--no-default-features` to opt out.)
This roughly triples the cost of everything in my experience, but it's necessary on some platforms (`arm-linux-androideabi`) which Rust/LLVM doesn't compile 128-bit integers for correctly yet.
**Before this can be merged the CI needs to test against this being enabled or disabled.**
s/is_in_correct_subgroup/is_in_correct_subgroup_assuming_on_curve/
I added a new method`is_in_correct_subgroup_assuming_on_curve` and added the method `is_in_correct_subgroup` for the `CurveAffine` trait.
Group encoding negative test vectors
Closes#10
Also simplifies the encoding code, which has the side-effect of being useful for testing. Also adds more descriptive error reporting throughout the API. Also ensures use of Debug/Display are consistent with standard expectations.