Skip to content

Commit

Permalink
Add extension_degree() method to Field (#108)
Browse files Browse the repository at this point in the history
* Add extension_degree() method to Field

* Update ff/src/fields/mod.rs

Co-authored-by: Pratyush Mishra <pratyushmishra@berkeley.edu>
  • Loading branch information
ValarDragon and Pratyush authored Dec 5, 2020
1 parent 4df2d24 commit b39d24e
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
replacing `x.unitary_inverse()` with `let mut tmp = x.clone(); tmp.conjugate()`
- #53 (ark-poly) Add `Zero` trait bound to `Polynomial`.
- #106 (ark-ff, ark-ec) Add `Zeroize` trait bound to `Field, ProjectiveGroup, AffineGroup` traits.
- #108 (ark-ff) Add `extension_degree()` method to `Field`.

### Features
- #20 (ark-poly) Add structs/traits for multivariate polynomials
Expand Down
4 changes: 4 additions & 0 deletions ff/src/fields/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ macro_rules! impl_Fp {
impl<P: $FpParameters> Field for $Fp<P> {
type BasePrimeField = Self;

fn extension_degree() -> u64 {
1
}

#[inline]
fn double(&self) -> Self {
let mut temp = *self;
Expand Down
4 changes: 4 additions & 0 deletions ff/src/fields/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ pub trait Field:
Self::BasePrimeField::characteristic()
}

/// Returns the extension degree of this field with respect
/// to `Self::BasePrimeField`.
fn extension_degree() -> u64;

/// Returns `self + self`.
#[must_use]
fn double(&self) -> Self;
Expand Down
4 changes: 4 additions & 0 deletions ff/src/fields/models/cubic_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ impl<P: CubicExtParameters> One for CubicExtField<P> {
impl<P: CubicExtParameters> Field for CubicExtField<P> {
type BasePrimeField = P::BasePrimeField;

fn extension_degree() -> u64 {
3 * P::BaseField::extension_degree()
}

fn double(&self) -> Self {
let mut result = *self;
result.double_in_place();
Expand Down
4 changes: 4 additions & 0 deletions ff/src/fields/models/quadratic_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ impl<P: QuadExtParameters> One for QuadExtField<P> {
impl<P: QuadExtParameters> Field for QuadExtField<P> {
type BasePrimeField = P::BasePrimeField;

fn extension_degree() -> u64 {
2 * P::BaseField::extension_degree()
}

fn double(&self) -> Self {
let mut result = *self;
result.double_in_place();
Expand Down

0 comments on commit b39d24e

Please sign in to comment.