Skip to content

Commit

Permalink
✅add some tests, 🔖 bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
colinxu2020 committed Jul 9, 2024
1 parent 8352132 commit 4292f65
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "SLH-DSA"
version = "0.1.2"
version = "0.1.3"
description = "The pure python impl of the slh-das algorithm(based on fips205)."
authors = [
{name = "Colinxu2020", email = "[email protected]"},
Expand Down
4 changes: 2 additions & 2 deletions slhdsa/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from slhdsa.slhdsa import PublicKey, SecretKey, KeyPair
from slhdsa.parameters import * # noqa: F403
from slhdsa.exception import SLHDSAException, SLHDSASignException, SLHDSAVerifyException
from slhdsa.exception import SLHDSAException, SLHDSASignException, SLHDSAVerifyException, SLHDSAKeyException


__all__ = ["PublicKey", "SecretKey", "KeyPair", "SLHDSAException", "SLHDSASignException", "SLHDSAVerifyException"]
__all__ = ["PublicKey", "SecretKey", "KeyPair", "SLHDSAException", "SLHDSASignException", "SLHDSAVerifyException", "SLHDSAKeyException"]
for algo in ["shake", "sha2"]:
for size in ["128", "192", "256"]:
for suffix in ["s", "f"]:
Expand Down
23 changes: 22 additions & 1 deletion tests/test_a.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from random import randbytes, randint

from pytest import raises

from slhdsa import KeyPair, sha2_128s, sha2_128f, sha2_192s, sha2_192f, sha2_256s, sha2_256f
from slhdsa import shake_128s, shake_128f, shake_192s, shake_192f, shake_256s, shake_256f
from slhdsa import SLHDSAKeyException, PublicKey, SecretKey


def _for_all(judger):
Expand Down Expand Up @@ -93,4 +96,22 @@ def judge(para):
assert not kp.verify(msg, sig2)
sig3 = randbytes(10) + sig[10:]
assert not kp.verify(msg, sig3)
_for_all(judge)
_for_all(judge)

def test6():
def judge(para):
pk = KeyPair.gen(para).pub.digest()[:-1]
with raises(SLHDSAKeyException):
PublicKey.from_digest(pk, para)
sk = KeyPair.gen(para).sec.digest()[:-1]
with raises(SLHDSAKeyException):
SecretKey.from_digest(sk, para)
with raises(SLHDSAKeyException):
SecretKey.from_digest(sk+b'a', para)
kp = KeyPair.gen(para).digest()[:-1]
with raises(SLHDSAKeyException):
KeyPair.from_digest(kp, para)
with raises(SLHDSAKeyException):
KeyPair.from_digest(kp+b'a', para)
_for_all(judge)

0 comments on commit 4292f65

Please sign in to comment.