这是indexloc提供的服务,不要输入任何密码
Skip to content

[opentitantool] SPHINCSPLUS refactoring #23730

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

Merged
merged 5 commits into from
Jun 28, 2024
Merged

[opentitantool] SPHINCSPLUS refactoring #23730

merged 5 commits into from
Jun 28, 2024

Conversation

cfrantz
Copy link
Contributor

@cfrantz cfrantz commented Jun 19, 2024

Refactor the SPHINCSPLUS library to support multiple algorithm variants.

  1. Patch the sphincsplus C reference implementation to give unique symbol names to each of the possible algorithm variants. The unique names are mangled onto the function names through classic C preprocessor abuse. We supply the "namespace" to our cc_library and rust_bindgen rules through the defines or clang_flags attributes of those rules.
  2. Refactor the rust binding:
    2a. Create an enum whose discriminants are the sphincsplus algorithm names. Create a macro_rules! macro that can expand an implementation for each discriminant that invokes the corresponding per-algorithm functions supplied by (1).
    2b. Create Spx{Public,Secret}Key structs to hold key material and their associated algorithm names. Create nice associated functions on these key types that provide nice interfaces to the lower-level functions supplied by (2a).
    2c. Add {Encode,Decode}Key traits that can serialize the key material to/from PEM files. Save the algorithm name into the PEM file so that when keys are loaded from files, they key material will get associated with the correct implementation functions.
  3. Plumb the new library into opentitanlib. Eliminate most of the legacy spx module in favor of using the new sphincsplus crate directly.

@cfrantz cfrantz requested review from moidx and jadephilipoom June 19, 2024 04:50
@cfrantz
Copy link
Contributor Author

cfrantz commented Jun 19, 2024

TODO:

  • Test with the ROM
  • Test with the HSM

Copy link
Contributor

@jadephilipoom jadephilipoom left a comment

Choose a reason for hiding this comment

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

This approach LGTM!

@cfrantz cfrantz changed the title [opentitantoo] SPHINCSPLUS refactoring [opentitantool] SPHINCSPLUS refactoring Jun 21, 2024
@cfrantz cfrantz marked this pull request as ready for review June 24, 2024 21:46
@cfrantz cfrantz requested a review from a team as a code owner June 24, 2024 21:46
@cfrantz cfrantz requested review from timothytrippel and removed request for a team June 24, 2024 21:46
@cfrantz cfrantz force-pushed the spx2 branch 3 times, most recently from f960793 to b2604bc Compare June 26, 2024 13:58
@cfrantz
Copy link
Contributor Author

cfrantz commented Jun 26, 2024

I've added domain handling to the sphincsplus crate and have plumbed that through to opentitantool in the form of a --domain command-line option on the relevant sign/verify commands.

I've also rewritten the headers on the existing PEM files to identify the keys as SPHINCS+_SHA2_128s_simple keys.

Passing CI is an effective test with the ROM.

I've also tested with the HSM, although in order to do that, I need to change the version of the reference implementation we import to the ref-impl's master branch. The HSM's current PQ implementation is still using the algorithms prior to the FORS indexing change.

@cfrantz cfrantz force-pushed the spx2 branch 4 times, most recently from 0a03c48 to e40555e Compare June 28, 2024 15:26
cfrantz added 5 commits June 28, 2024 13:12
Signed-off-by: Chris Frantz <cfrantz@google.com>
Rework the sphincsplus build to permit linking in multiple algorithm
variants without C symbol clashes.

1. Patch the sphincsplus C library to allow namespacing the relevant
   symbol names.  Since C does not have namespaces, we use the C
   preprocessor to token-paste a prefix onto the symbols.
2. Supply the namespace prefix in the `cc_library` build rules.

Signed-off-by: Chris Frantz <cfrantz@google.com>
1. Refactor the low-level interface into a macro that can access the
   low-level C functions for each algorithm variant we want to support.
2. Refactor key types to carry the algorithm variant along with the key
   material.
3. Save the algorithm name into the PEM files used for saving key
   material to disk.  Prefix the name with `RAW:` to convey that the PEM
   files are just raw bags of bytes with no internal structure.

Signed-off-by: Chris Frantz <cfrantz@google.com>
… crate

Signed-off-by: Chris Frantz <cfrantz@google.com>
Rewrite the SPX PEM key labels to identify the Sphincs+ algorithm
variant for the keys.

Signed-off-by: Chris Frantz <cfrantz@google.com>
@cfrantz
Copy link
Contributor Author

cfrantz commented Jun 28, 2024

The CI test failure is not related to this change.

@cfrantz cfrantz merged commit 3d5220a into lowRISC:master Jun 28, 2024
30 of 32 checks passed
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.

3 participants