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

add power impl and expose Fq::from_montgomery_limbs #98

Merged
merged 3 commits into from
Apr 3, 2024
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
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,30 @@
# 0.7.0

* Fix: Add `no_std` compatibility.

# 0.8.0

* Add fiat-generated finite field implementations by @hdevalence in #64
* refactor(arkworks): feature-gated Arkworks compatibility by @TalDerei in #67
* Implement Bls12377 using our own backend by @cronokirby in #71
* ci: add job to test u32_backend by @redshiftzero in #72
* Arkworks feature gating by @cronokirby in #73
* Implement traits in a no_std context when possible by @cronokirby in #74
* Implement the start of a minimal curve implementation by @cronokirby in #75
* ci: add job building with no alloc feature by @redshiftzero in #76
* arkworks independent projective arithmetic ops by @redshiftzero in #77
* Make modular reduction work for large byte sizes by @cronokirby in #78
* Implement FromStr for all the fields by @cronokirby in #79
* Implement a checked conversion from bytes method in Fq by @cronokirby in #81
* arkworks-independent sqrts, point encoding/decoding by @cronokirby in #80
* ci: use larger runners by @conorsch in #83
* ci: dedicated profile for release + debug_assert by @conorsch in #84
* rearranging arkworks / non-arkworks ECC code by @redshiftzero in #82

# 0.9.0

* Make raw constructors of field elements private by @cronokirby in #90
* Add missing methods as need for integrating the latest version of this crate by @cronokirby in #91
* fix: field modulus by @TalDerei in #92
* adjust anyhow scope and remove unused dependencies by @neithanmo in #96
* add power impl and expose `Fq::from_montgomery_limbs` by @redshiftzero in #98
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "decaf377"
version = "0.8.0"
version = "0.9.0"
authors = [
"Henry de Valence <[email protected]>",
"redshiftzero <[email protected]>",
Expand Down
12 changes: 12 additions & 0 deletions src/fields/fq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,18 @@ impl Fq {
};
Self::from_le_bytes_mod_order(&bytes)
}

/// Raise this element to a given power.
///
/// Note: Arkworks provides another method for this, called `pow`.
pub fn power<S: AsRef<[u64]>>(&self, exp: S) -> Self {
let mut res = Fq::from(1u64);
let exp_u64 = exp.as_ref();
for _ in 0..exp_u64[0] {
res *= self;
}
res
}
}

#[cfg(test)]
Expand Down
3 changes: 3 additions & 0 deletions src/fields/fq/u32/wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ impl Fq {
Self(fiat::FqMontgomeryDomainFieldElement(limbs))
}

/// Instantiate a constant field element from its montgomery limbs.
///
/// This should only be used if you are familiar with the internals of the library.
pub const fn from_montgomery_limbs(limbs: [u64; N_64]) -> Fq {
Self(fiat::FqMontgomeryDomainFieldElement([
limbs[0] as u32,
Expand Down
5 changes: 4 additions & 1 deletion src/fields/fq/u64/wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ impl Fq {
bytes
}

pub(crate) const fn from_montgomery_limbs(limbs: [u64; N]) -> Fq {
/// Instantiate a constant field element from its montgomery limbs.
///
/// This should only be used if you are familiar with the internals of the library.
pub const fn from_montgomery_limbs(limbs: [u64; N]) -> Fq {
Self(fiat::FqMontgomeryDomainFieldElement(limbs))
}

Expand Down
Loading