Skip to content

Conversation

@briansmith
Copy link
Owner

Generate some of the C boilerplate, particularly the large constants. The output is written into target/curves/, and can be merged into the actual code in crypto/fipsmodule/ec/ using a two-way merge tool; this is the same as the Rust code generation.

Changes to gfp_p{256,384}.c are due to differences in the generator's output:

  • The generator doesn't generate trailing commas in arrays.
  • The generator consistently avoids adding leading zeros to hex constants, and consistently format values less than 10 in decimal; the exiting code used a mix of styles.
  • The generator wraps arrays consistently; the existing code used a mix of wrapping styles.
  • The generator does not nest constants in the functions that need them. This was changed to support future refactorings.
  • In order to support P-521, we avoid TOBN as it won't work for 32-bit targets for P-521 since there are an odd number of limbs in that case.

Generate some of the C boilerplate, particularly the large constants.
The output is written into target/curves/, and can be merged into
the actual code in crypto/fipsmodule/ec/ using a two-way merge tool;
this is the same as the Rust code generation.

Changes to gfp_p{256,384}.c are due to differences in the generator's
output:

* The generator doesn't generate trailing commas in arrays.
* The generator consistently avoids adding leading zeros to hex
  constants, and consistently format values less than 10 in decimal;
  the exiting code used a mix of styles.
* The generator wraps arrays consistently; the existing code used a
  mix of wrapping styles.
* The generator does not nest constants in the functions that need
  them. This was changed to support future refactorings.
Values for P-521 have an odd number of limbs in 32-bit mode, which
means we can't keep using `TOBN`, and also Montgomery-encoded
values are different for 32-bit and 64-bit.
@briansmith briansmith self-assigned this Oct 30, 2023
@briansmith
Copy link
Owner Author

@vkrasnov PTAL.

@briansmith briansmith merged commit 07aff69 into main Nov 13, 2023
@briansmith briansmith deleted the b/generator-c branch November 13, 2023 20:45
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.

2 participants