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

Generate code for the scalar field of standard curves #1259

Merged
merged 1 commit into from
May 31, 2022

Conversation

jedisct1
Copy link
Contributor

fiat-crypto is already used for arithmetic on scalars, at least by the Zig standard library and in Rust (p384_rs, being merged into the p384 crate as we speak).

So it may be useful to pregenerate and test this in fiat-crypto.

This change adds support for the curve25519, p256, secp256k1, p384 and p521 scalar fields.

@JasonGross
Copy link
Collaborator

This is nice, but I'm afraid fiat-crypto is too slow at larger curves to support this. 6+ hours of CI time is really too much. Do you have thoughts on how to support this better? Options I can think of:

  1. Making this PR about adding 64-bit versions only (with the possible exception of curve25519)
  2. Having slow code gen be tested in a separate CI job that runs after the main ones, possibly only on master, possibly pushing any newly generated files that it makes?

Also, this PR is missing Java files.

@jedisct1
Copy link
Contributor Author

CI is indeed a major issue.

Testing slow and fast cases in distinct jobs may be the way to go, especially since we already have such distinction with the "lite" files.

@jedisct1
Copy link
Contributor Author

jedisct1 commented May 27, 2022

Also, this PR is missing Java files.

The Java files are included, but they were generated with funny names:

FiatuLucurve2u5u5u1u9u.java
FiatuLucurve2u5u5u1u9uuscalar.java

This is a distinct issue, that also happens on master. This is on macOS; it probably doesn't happen on Linux.

[UPDATE] to_title_case is the root cause:

sed -E 's/.*/\\L&/; s/[a-z]*/\\u&/g'

\u is a GNU extension, that doesn't exist in other sed implementations.

@tarcieri
Copy link

Having slow code gen be tested in a separate CI job that runs after the main ones, possibly only on master, possibly pushing any newly generated files that it makes?

This seems reasonable to me

tarcieri added a commit to RustCrypto/elliptic-curves that referenced this pull request May 27, 2022
Imports the 32-bit fiat-crypto scalar field implementation generated by
@jedisct1 from this PR:

mit-plv/fiat-crypto#1259

Gates all field backends and precomputed constants on
`target_pointer_width`, substituting 12-limb 32-bit versions for 32-bit
targets where necessary.

Inversions are implemented using 64-bit arithmetic, so for now they are
marked as `todo!()`.
tarcieri added a commit to RustCrypto/elliptic-curves that referenced this pull request May 27, 2022
Imports the 32-bit fiat-crypto scalar field implementation generated by
@jedisct1 from this PR:

mit-plv/fiat-crypto#1259

Gates all field backends and precomputed constants on
`target_pointer_width`, substituting 12-limb 32-bit versions for 32-bit
targets where necessary.

Inversions are implemented using 64-bit arithmetic, so for now they are
marked as `todo!()`.
tarcieri added a commit to RustCrypto/elliptic-curves that referenced this pull request May 27, 2022
Imports the 32-bit fiat-crypto scalar field implementation generated by
@jedisct1 from this PR:

mit-plv/fiat-crypto#1259

Gates all field backends and precomputed constants on
`target_pointer_width`, substituting 12-limb 32-bit versions for 32-bit
targets where necessary.

Inversions are implemented using 64-bit arithmetic, so for now they are
marked as `todo!()`.
tarcieri added a commit to RustCrypto/elliptic-curves that referenced this pull request May 27, 2022
Imports the 32-bit fiat-crypto scalar field implementation generated by
@jedisct1 from this PR:

mit-plv/fiat-crypto#1259

Gates all field backends and precomputed constants on
`target_pointer_width`, substituting 12-limb 32-bit versions for 32-bit
targets where necessary.

Inversions are implemented using 64-bit arithmetic, so for now they are
marked as `todo!()`.
@tarcieri
Copy link

Alternatively, if the scalar fields could be included in the fiat-crypto Rust crate releases, that would work just as well: https://crates.io/crates/fiat-crypto

@jedisct1 jedisct1 force-pushed the add-scalar-fields branch 3 times, most recently from 848e7be to 90ee584 Compare May 28, 2022 21:06
fiat-crypto is already used for arithmetic on scalars, at least
by the Zig standard library and in Rust (p384_rs, being merged
into the p384 crate as we speak).

So it may be useful to pregenerate and test this in fiat-crypto.

This change adds support for the curve25519, p256, secp256k1
and p384 scalar fields.
@jedisct1
Copy link
Contributor Author

Removing P521 code generation makes it more reasonable. Due to its size, Java cannot compile the P521 scalar code anyway.

@spitters
Copy link

spitters commented Jun 8, 2022

https://github.com/ejgallego/coq-universe
tries to improve CI by better caching with the use of Dune. Could this be helpful here?

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.

4 participants