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

sphincs+ support, for post-quantum crypto #169

Closed
wants to merge 22 commits into from

Conversation

lukpueh
Copy link
Member

@lukpueh lukpueh commented Jun 17, 2019

Fixes issue #:
Updates #160

Description of the changes being introduced by the pull request:
This is a review + friendly take-over, as requested by @JustinCappos in #160 (comment).

The PR does some clean-up and minor refactoring. See lukpueh/securesystemslib@d653691...lukpueh:add-pyspx-support for the changes on top of #160, and see #160 for prior reviews.

Thanks @cryptojedi and @joostrijneveld for your contribution. Please let me know what you think of my changes.

Please verify and check that the pull request fulfills the following
requirements
:

  • The code follows the Code Style Guidelines
  • Tests have been added for the bug fix or new feature
  • Docs have been added for the bug fix or new feature

cryptojedi and others added 20 commits June 18, 2019 12:39
Only the passing case was copied from ed25519, and inserted
between the passing and failure case. This effectively removed
error handling for incorrect ed25519 schemes.
Import third-party pyspx package in securesystemslib.spx_keys
only and require whoever imports securesystemslib.spx_keys to
handle ImportError (or IOError in case of missing C backend).

See securesystemslib.keys for exemplary import handling.

This commit also moves three spx-specific schema definitions from
securesystemslib.formats to securesystemslib.spx_keys, so that
the former does not have to deal with a conditional import of
an optional library.
Add pyspx to `extra_require` in setup.py, to optionally install
e.g. with `pip install securesystemslib[pyspx]`.
To create a signature the public key is not required.
- Remove trailing whitespace
- Remove redundant try/except blocks in functions, where
  - the exception is already handled by earlier function code
    (schema check)
  - the exception should be handled on module level (ImportError
    for optional PySPX)
- De-clutter (e.g. remove some obvious code comments, superfluous
  variable null value instantiations, redundant checks)
- Fix typos
- Enhance line wrapping
In 0baedd3 we changed
keys.create_signature to take the canonicalized and utf-8 encoded
data as argument.

This adopts the change in the spx related create_signature
dispatch block.
# Generate a new SPX key object.
spx_key = securesystemslib.keys.generate_spx_key()

if not filepath:
Copy link
Member

Choose a reason for hiding this comment

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

Should there be a check to see if a provided filepath is a directory?

And it could either be a warning or it could accept the directory and change the path to directory/keyid.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point. I created an issue for this. Feel free to comment there. #172


# Begin building the SPX key dictionary.
spx_key = {}
keytype = 'spx'
Copy link
Member

Choose a reason for hiding this comment

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

Do we need keytype and scheme separately? I see that SPX_SIG_SCHEMA is set to OneOf but only spx is provided. Is this just leaving it open for for future enhancement?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes we do. Currently we only support one spx scheme, i.e. SPHINCS+-SHAKE256, but it's conceivable to later add others (see sphincs.org).

I probably would have opted for a more descriptive scheme name, but that was the choice of the original author of this PR, and I think it is okay.

True
>>> scheme == 'spx'
True
>>> signature, scheme = \
Copy link
Member

Choose a reason for hiding this comment

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

Are these lines repeated?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good eyes. Seems like a copy-pasta error from ed25519_keys.py, which apparently served as base for spx_keys.py. Fixed in f6e47b9.

Copy link
Contributor

@mnm678 mnm678 left a comment

Choose a reason for hiding this comment

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

There was also some previous discussion in #160 about making sphincs support optional. Was there a decision about this?

raise securesystemslib.exceptions.CryptoError('An "spx" signature'
' could not be created with pyspx: ' + str(e))

return signature, scheme
Copy link
Contributor

Choose a reason for hiding this comment

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

This function takes scheme as a parameter and also returns it, is there a reason for this?

Copy link
Member

Choose a reason for hiding this comment

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

Well spotted!

Copy link
Member Author

Choose a reason for hiding this comment

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

Well spotted indeed. ;) I briefly considered removing it but left it for consistency with the rest of the create_signature functions, and to keep the diff small.

Besides, it kinda does make sense if scheme becomes an optional argument with a default, as is the case in ecdsa_keys.create_signature. So that, if the caller does not pass a scheme, s/he learns about the default by looking at the return value.

OTOH and in contrast to being consistent and keeping the diff small, I did remove the public_key argument from spx_keys.create_signature, because it makes no sense (see
a67a6b3).

If you're not opposed, I'd just leave it.

Copy link
Contributor

Choose a reason for hiding this comment

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

That makes sense, it seems fine as is.

@lukpueh
Copy link
Member Author

lukpueh commented Jul 11, 2019

@mnm678, regarding optionality of sphinx, it already is. Please see related commits 9beace8, 154bee1, 44db3df, and most notably, the docs update commit 335199d.

@joostrijneveld
Copy link

joostrijneveld commented Jul 11, 2019

Thanks for picking this up!

I'm afraid I cannot really contribute or comment until late September, but I wanted to point out that pyspx is still at the round 1 parameter sets (and code), and we've had a few minor changes to SPHINCS+ since then. From the outside it's all trivialities, but it would be annoying to roll out something and then have to make small tweaks shortly after. Perhaps @cryptojedi can comment / help out with that if necessary.

In general I feel like the naming of the parameter set needs to be improved to stress explicitly that we're dealing with shake256-192s here; in the context of round 2 changes, that should probably be shake256-192s-robust.

@lukpueh
Copy link
Member Author

lukpueh commented Aug 5, 2019

Hi @joostrijneveld, thanks for chiming back in!

From the outside it's all trivialities, but it would be annoying to roll out something and then have to make small tweaks shortly after.

Do I understand correctly that you advice to hold back merging until new releases of pyspx/SPHINCS+?

In general I feel like the naming of the parameter set needs to be improved to stress explicitly that we're dealing with shake256-192s here

Are you referring to the scheme discussion we had above?

@joshuagl
Copy link
Collaborator

joshuagl commented Feb 6, 2020

In Issue #179 we're working to ensure that any functionality with a native dependency presents meaningful user feedback when the native dependency is not available.

It would be great if this PR could implement functionality similar to #200 to ensure the spx_keys module can be imported even if the native dependency isn't available and that any functions which rely on that native dependency throw an UnsupportedLibraryError.

@lukpueh
Copy link
Member Author

lukpueh commented Oct 17, 2022

Superseded by #427

@lukpueh lukpueh closed this Oct 17, 2022
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.

None yet

6 participants