Skip to content

Commit

Permalink
Renamed variables and added docstring to sphincs+ to make pylint happy.
Browse files Browse the repository at this point in the history
  • Loading branch information
rugo committed Oct 27, 2022
1 parent b62e8e2 commit b802315
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
26 changes: 21 additions & 5 deletions securesystemslib/sphincs_keys.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
"""
<Program Name>
sphincs_keys.py
<Author>
Ruben Gonzalez <[email protected]>
<Started>
Otober 12, 2022.
<Copyright>
See LICENSE for licensing information.
<Purpose>
The goal of this module is to include SPHINCS+ post-quantum signature support.
"""
# 'os' required to generate OS-specific randomness (os.urandom) suitable for
# cryptographic use.
# http://docs.python.org/2/library/os.html#miscellaneous-functions
import os

from securesystemslib import exceptions, formats

_SPX_AVAIL = True
SPX_AVAIL = True
NO_SPX_MSG = "spinhcs+ key support requires the pyspx library"

try:
from pyspx import shake_128s
except ImportError:
_SPX_AVAIL = False
SPX_AVAIL = False

_SHAKE_SEED_LEN = 48

Expand All @@ -24,7 +40,7 @@ def generate_public_and_private():
Raises:
UnsupportedLibraryError: In case pyspx is not available.
"""
if not _SPX_AVAIL:
if not SPX_AVAIL:
raise exceptions.UnsupportedLibraryError(NO_SPX_MSG)
seed = os.urandom(_SHAKE_SEED_LEN)
public, private = shake_128s.generate_keypair(seed)
Expand All @@ -43,7 +59,7 @@ def create_signature(public_key, private_key, data, scheme):
Raises:
UnsupportedLibraryError: In case pyspx is not available.
"""
if not _SPX_AVAIL:
if not SPX_AVAIL:
raise exceptions.UnsupportedLibraryError(NO_SPX_MSG)
formats.SPHINCSPUBLIC_SCHEMA.check_match(public_key)
formats.SPHINCSPRIVATE_SCHEMA.check_match(private_key)
Expand All @@ -66,7 +82,7 @@ def verify_signature(public_key, scheme, signature, data):
Raises:
UnsupportedLibraryError: In case pyspx is not available.
"""
if not _SPX_AVAIL:
if not SPX_AVAIL:
raise exceptions.UnsupportedLibraryError(NO_SPX_MSG)
formats.SPHINCSPUBLIC_SCHEMA.check_match(public_key)

Expand Down
3 changes: 1 addition & 2 deletions tests/check_public_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,11 @@ def test_keys(self):
):
securesystemslib.keys.verify_signature(keydict, sig, data)

SPX_KEY_LEN = 7_856
keydict["keytype"] = "sphincs"
keydict["scheme"] = "sphincs-shake-128s"
sig = {
"keyid": "f00",
"sig": "A" * SPX_KEY_LEN,
"sig": "A" * 7_856,
}
with self.assertRaises(
securesystemslib.exceptions.UnsupportedLibraryError
Expand Down
4 changes: 2 additions & 2 deletions tests/test_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,12 +492,12 @@ def test_verify_signature(self): # pylint: disable=too-many-statements
self.assertTrue(verified, "Incorrect signature.")

# Verify that sphincs fails if PySPX is not installed
KEYS.sphincs_keys._SPX_AVAIL = False # Monkey patch availability
KEYS.sphincs_keys.SPX_AVAIL = False # Monkey patch availability
with self.assertRaises(
securesystemslib.exceptions.UnsupportedLibraryError
):
KEYS.verify_signature(self.sphincskey_dict, sphincs_signature, DATA)
KEYS.sphincs_keys._SPX_AVAIL = True
KEYS.sphincs_keys.SPX_AVAIL = True

# Verify ecdsa key with HEX encoded keyval instead of PEM encoded keyval
ecdsa_key = KEYS.generate_ecdsa_key()
Expand Down

0 comments on commit b802315

Please sign in to comment.