slhdsa: provide handy methods

This commit is contained in:
Sun Yimin 2025-05-27 10:12:08 +08:00 committed by GitHub
parent da0d651197
commit 6f6631236f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 2 deletions

View File

@ -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)
}

View File

@ -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)
}