From 6f6631236fa4fb5b745547b9f297a888c4393d28 Mon Sep 17 00:00:00 2001 From: Sun Yimin Date: Tue, 27 May 2025 10:12:08 +0800 Subject: [PATCH] slhdsa: provide handy methods --- slhdsa/dsa_test.go | 4 ++-- slhdsa/parameterset.go | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/slhdsa/dsa_test.go b/slhdsa/dsa_test.go index 81b5c18..83a658b 100644 --- a/slhdsa/dsa_test.go +++ b/slhdsa/dsa_test.go @@ -71,7 +71,7 @@ func testData(t *testing.T, filename string, tc *slhtest) { context, _ := hex.DecodeString(tc.Context) sig, _ := hex.DecodeString(tc.Signature) sigOriginal := sig - privKey, err := NewPrivateKey(skBytes, params) + privKey, err := params.NewPrivateKey(skBytes) if err != nil { t.Fatalf("%v NewPrivateKey(%x) = %v", filename, skBytes, err) } @@ -100,7 +100,7 @@ func testData(t *testing.T, filename string, tc *slhtest) { sig = sig[privKey.params.n*(privKey.params.len+privKey.params.hm):] } // test verify - pub, err := NewPublicKey(pkBytes, params) + pub, err := params.NewPublicKey(pkBytes) if err != nil { t.Fatalf("%v NewPublicKey(%x) = %v", filename, pkBytes, err) } diff --git a/slhdsa/parameterset.go b/slhdsa/parameterset.go index bba7ddb..f64e470 100644 --- a/slhdsa/parameterset.go +++ b/slhdsa/parameterset.go @@ -1,5 +1,7 @@ package slhdsa +import "io" + const ( MAX_N = 32 MAX_M = 49 @@ -121,3 +123,19 @@ func (p *params) leafIdxMask() uint64 { func (p *params) String() string { return p.alg } + +// GenerateKey generates a new private key using the provided random source and the parameters +// specified by the receiver. +func (p *params) GenerateKey(rand io.Reader) (*PrivateKey, error) { + return GenerateKey(rand, p) +} + +// NewPublicKey creates a new PublicKey instance from the provided byte slice using the current parameter set. +func (p *params) NewPublicKey(bytes []byte) (*PublicKey, error) { + return NewPublicKey(bytes, p) +} + +// NewPrivateKey creates a new PrivateKey instance using the provided byte slice and the current parameter set. +func (p *params) NewPrivateKey(bytes []byte) (*PrivateKey, error) { + return NewPrivateKey(bytes, p) +}