diff --git a/pyproject.toml b/pyproject.toml index 9e11ff8..af0e782 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 = "colinxu2020@gmail.com"}, diff --git a/slhdsa/__init__.py b/slhdsa/__init__.py index d4a7e5d..6acfc81 100644 --- a/slhdsa/__init__.py +++ b/slhdsa/__init__.py @@ -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"]: diff --git a/tests/test_a.py b/tests/test_a.py index 653dec4..f0760dd 100644 --- a/tests/test_a.py +++ b/tests/test_a.py @@ -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): @@ -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) \ No newline at end of file + _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) + \ No newline at end of file