Skip to content

primefield+p384: upgrade to fiat-crypto v0.1.4#1157

Merged
tarcieri merged 1 commit intomasterfrom
primefield+p384/fiat-crypto-upgrade
Apr 30, 2025
Merged

primefield+p384: upgrade to fiat-crypto v0.1.4#1157
tarcieri merged 1 commit intomasterfrom
primefield+p384/fiat-crypto-upgrade

Conversation

@tarcieri
Copy link
Member

Updates the field element type generating macros in the primefield crate to be compatible with the latest fiat-crypto code as postprocessed by fiat-constify, and regenerates the p384 field impls using fiat-crypto v0.1.4.

This update leverages const_mut_refs to be much closer to the upstream fiat-crypto output, while still providing const fn support.

This change also starts extracting a fiat module within primeorder for macros that are specific to fiat-crypto output.

With this upgrade in place, upgrading the rest of the curve crates should be comparatively straightforward.

@tarcieri tarcieri force-pushed the primefield+p384/fiat-crypto-upgrade branch 3 times, most recently from 43254a1 to a01568a Compare April 30, 2025 22:21
@tarcieri
Copy link
Member Author

This saw similar speedups in scalar multiplication and inversion as were seen in p521 in #1156:

point operations/point-scalar mul
                        time:   [432.29 µs 434.73 µs 437.29 µs]
                        change: [-3.0895% -2.4875% -1.9227%] (p = 0.00 < 0.05)
                        Performance has improved.
scalar operations/invert
                        time:   [29.923 µs 29.973 µs 30.035 µs]
                        change: [-3.6955% -3.4156% -3.1371%] (p = 0.00 < 0.05)
                        Performance has improved.

Other operations were not impacted.

Comment on lines +57 to +61
$add(
&mut out,
&$mont_type(self.0.to_words()),
&$mont_type(rhs.0.to_words()),
);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The newtypes introduced in newer versions of fiat-crypto make these conversions somewhat annoying, and they're occurring wherever we invoke any generated code.

Fortunately sprinkling #[inline] on it seems to be sufficient to get the compiler to optimize them away, but it might make sense to support casting between generated field element types (which contain crypto-bigint::Uints) and references to their fiat-crypto generated newtypes.

The main thing that's missing right now is the fiat-crypto newtypes aren't annotated as #[repr(transparent)], as what's really needed here is a cast between the inner array type and the newtype. That shouldn't be too difficult to add in fiat-constify though.

Updates the field element type generating macros in the `primefield`
crate to be compatible with the latest `fiat-crypto` code as
postprocessed by `fiat-constify`, and regenerates the `p384` field impls
using `fiat-crypto` v0.1.4.

This update leverages `const_mut_refs` to be much closer to the upstream
`fiat-crypto` output, while still providing `const fn` support.

This change also starts extracting a `fiat` module within `primeorder`
for macros that are specific to `fiat-crypto` output.

With this upgrade in place, upgrading the rest of the curve crates
should be comparatively straightforward.
@tarcieri tarcieri force-pushed the primefield+p384/fiat-crypto-upgrade branch from a01568a to c26d1cc Compare April 30, 2025 22:33
@tarcieri tarcieri merged commit 55d893c into master Apr 30, 2025
134 checks passed
@tarcieri tarcieri deleted the primefield+p384/fiat-crypto-upgrade branch April 30, 2025 22:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant