Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify field extension arithmetic #161

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions derive/src/field/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,14 +282,6 @@ pub(crate) fn impl_field(input: TokenStream) -> TokenStream {
}
}

impl ::core::ops::Neg for #field {
type Output = #field;

#[inline]
fn neg(self) -> #field {
-&self
}
}

impl #field {
pub const SIZE: usize = #num_limbs * 8;
Expand Down Expand Up @@ -393,8 +385,17 @@ pub(crate) fn impl_field(input: TokenStream) -> TokenStream {
self.square()
}

// Returns the multiplicative inverse of the element. If it is zero, the method fails.
#[inline(always)]
fn invert(&self) -> CtOption<Self> {
self.invert()
const BYINVERTOR: crate::ff_ext::inverse::BYInverter<#by_inverter_constant> =
crate::ff_ext::inverse::BYInverter::<#by_inverter_constant>::new(&#modulus_limbs_ident, &#r2);

if let Some(inverse) = BYINVERTOR.invert::<{ Self::NUM_LIMBS }>(&self.0) {
subtle::CtOption::new(Self(inverse), subtle::Choice::from(1))
} else {
subtle::CtOption::new(Self::zero(), subtle::Choice::from(0))
}
}

#sqrt_impl
Expand Down
5 changes: 2 additions & 3 deletions src/bn256/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ use crate::ff::{Field, PrimeField};
use crate::group::Curve;
use crate::group::{cofactor::CofactorGroup, prime::PrimeCurveAffine, Group, GroupEncoding};
use crate::{
impl_add_binop_specify_output, impl_binops_additive, impl_binops_additive_specify_output,
impl_binops_multiplicative, impl_binops_multiplicative_mixed, impl_sub_binop_specify_output,
new_curve_impl,
impl_binops_additive, impl_binops_additive_specify_output, impl_binops_multiplicative,
impl_binops_multiplicative_mixed, new_curve_impl,
};
use crate::{Coordinates, CurveAffine, CurveExt};
use core::cmp;
Expand Down
Loading
Loading