From b82f7a97e2bfac7cac2c71a260e67d88eb91facc Mon Sep 17 00:00:00 2001 From: deatil <2217957370@qq.com> Date: Sun, 1 Sep 2024 10:51:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kcdsa/kcdsa_test.go | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/kcdsa/kcdsa_test.go b/kcdsa/kcdsa_test.go index f4d2f010..841f0d7c 100644 --- a/kcdsa/kcdsa_test.go +++ b/kcdsa/kcdsa_test.go @@ -111,12 +111,27 @@ func Test_Sign(t *testing.T) { } func Test_SignBytes(t *testing.T) { + t.Run("sha256", func(t *testing.T) { + test_SignBytes(t, A2048B224SHA224, sha256.New224) + }) + t.Run("sha256", func(t *testing.T) { + test_SignBytes(t, A2048B224SHA224, sha256.New) + }) + t.Run("sha256", func(t *testing.T) { + test_SignBytes(t, A2048B224SHA256, sha256.New) + }) + t.Run("sha256", func(t *testing.T) { + test_SignBytes(t, A2048B256SHA256, sha256.New) + }) +} + +func test_SignBytes(t *testing.T, sizes ParameterSizes, h Hasher) { assertBool := cryptobin_test.AssertBoolT(t) assertNotEmpty := cryptobin_test.AssertNotEmptyT(t) assertError := cryptobin_test.AssertErrorT(t) var priv PrivateKey - err := GenerateParameters(&priv.PublicKey.Parameters, rand.Reader, A2048B224SHA224) + err := GenerateParameters(&priv.PublicKey.Parameters, rand.Reader, sizes) assertError(err, "GenerateParameters-Error") err = GenerateKey(&priv, rand.Reader) @@ -129,10 +144,10 @@ func Test_SignBytes(t *testing.T) { data := "123tesfd!dfsign" - sig, err := SignBytes(rand.Reader, &priv, sha256.New, []byte(data)) + sig, err := SignBytes(rand.Reader, &priv, h, []byte(data)) assertError(err, "Sign-sig-Error") - veri := VerifyBytes(pub, sha256.New, []byte(data), sig) + veri := VerifyBytes(pub, h, []byte(data), sig) assertBool(veri, "Sign-veri-Error") }