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

Using more than one mode in an app #15

Open
carl-wallace opened this issue Sep 23, 2023 · 3 comments
Open

Using more than one mode in an app #15

carl-wallace opened this issue Sep 23, 2023 · 3 comments

Comments

@carl-wallace
Copy link

I set out to use this library in a certificate validation library but ran into issues trying to support any of modes 2, 3 and 5. I refactored a fork of the library to use proc macros to allow generating independent implementations and changed the features so all three can be used simultaneously. A copy is here: https://github.com/carl-wallace/dilithium/tree/macros. I have confirmed I can verify certificate signatures for each mode in a WASM project, but have not done any testing beyond that as yet. Any thoughts on the desire to use > 1 mode (did I miss something that made that possible as it was?) or on using proc macros to achieve this end?

@mberry
Copy link
Member

mberry commented Oct 1, 2023

Any thoughts on the desire to use > 1 mode

Definitely, it's been long on the list, not just for Dilithium but also Kyber/Sphincs, hopefully all in a consistent manner.

In sphincs there's a draft approach using const generics which is a messy solution in the current state of const generics where you need explicit trait bounds bubbling up, in the extreme case leading to api function signatures like this:

  fn sign(sig: &mut[u8], msg: &[u8], keypair: Keypair<F128>) 
  where [(); F128::CRYPTO_PUBLICKEYBYTES]:,
        [(); F128::CRYPTO_SECRETKEYBYTES]:,
        [(); F128::SPX_BYTES]:,
        [(); F128::SPX_N]:,
        [(); 2*F128::SPX_N]:,
        [(); F128::SPX_WOTS_LEN]:,
        [(); F128::SPX_DGST_BYTES]:,
        [(); F128::WOTS_STACK_LEN]:,
        [(); F128::SPX_FORS_MSG_BYTES]:,
        [(); F128::SPX_TREE_HEIGHT * F128::SPX_N + F128::SPX_WOTS_BYTES]:,
        [(); F128::SPX_FORS_HEIGHT]:,
        [(); F128::FORS_STACK_LEN]:,
        [(); F128::SPX_ADDR_BYTES + 2 * F128::SPX_N]:,
        [(); F128::SPX_ADDR_BYTES + 1 * F128::SPX_N]:,
        [(); F128::SPX_ADDR_BYTES + F128::SPX_FORS_TREES * F128::SPX_N]:,
        [(); F128::SPX_ADDR_BYTES + F128::SPX_WOTS_LEN * F128::SPX_N]:,
        [(); (F128::SPX_WOTS_LEN2 * F128::SPX_WOTS_LOGW + 7) / 8]:,
  {

Obviously that's not a good outcome, but it works and allows all modes to be used concurrently.

The other options are code duplication or macros, as you've done here. Const generics was what I'd hoped for but as time goes on I'd really like to get it done and not sure about the timeline for removing explicit bounds, if it ever comes.

Duplication isn't desirable from a maintainer point of view, 3x the number of LOC helps no one, but it would be simple to implement.

That leaves macros, which seem the reasonable compromise here. I'm not entirely sold on proc over declarative macros though. I've had a read over your code and it looks good, but do we really to bring in syn and quote to get this done? Quite sure this could all be done inline without resorting to the heavy-handedness of proc macros.

@carl-wallace
Copy link
Author

Thanks for the reply. I initially set out to identify what all would need to be parameterized from the api level down but that exploded pretty quickly so I shifted over to procmacros. That approach fell together pretty quickly. It could be tightened up but I tried to retain the existing code and structure to as great an extent as possible. I will give a look at whether declarative macros can work and will look at sphincs more closely (but it will likely be a few weeks before I get to it). Do you know of any pure Rust Falcon implementations by chance?

On other note, there were apparently some changes in the draft NIST standard for Dilithium (at least). So some code that had been successfully interoperating with other implementations both with your code and PQClean fails now against implementations that have been updated (which is only BouncyCastle so far in this hackathon group). Thanks again.

@mberry
Copy link
Member

mberry commented Oct 3, 2023 via email

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

No branches or pull requests

2 participants