mirror of
https://github.com/emmansun/gmsm.git
synced 2025-06-28 08:23:26 +08:00
mldsa: add benchmark test
This commit is contained in:
parent
67ac5da71e
commit
8f0bd765ca
@ -8,6 +8,7 @@ package mldsa
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/rand"
|
||||
"encoding/asn1"
|
||||
"encoding/hex"
|
||||
"testing"
|
||||
@ -308,3 +309,33 @@ func (zr) Read(dst []byte) (n int, err error) {
|
||||
}
|
||||
|
||||
var zeroReader = zr{}
|
||||
|
||||
func BenchmarkKeyGen44(b *testing.B) {
|
||||
var d [32]byte
|
||||
rand.Read(d[:])
|
||||
b.ResetTimer()
|
||||
for b.Loop() {
|
||||
if _, err := NewKey44(d[:]); err != nil {
|
||||
b.Fatalf("NewKey44 failed: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkSign44(b *testing.B) {
|
||||
var seed [32]byte
|
||||
c := sigGen44InternalProjectionCases[0]
|
||||
sk, _ := hex.DecodeString(c.sk)
|
||||
mu, _ := hex.DecodeString(c.mu)
|
||||
priv, err := NewPrivateKey44(sk)
|
||||
if err != nil {
|
||||
b.Fatalf("NewPrivateKey44 failed: %v", err)
|
||||
}
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for b.Loop() {
|
||||
_, err := priv.signInternal(seed[:], mu)
|
||||
if err != nil {
|
||||
b.Fatalf("signInternal failed: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ package mldsa
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/rand"
|
||||
"encoding/asn1"
|
||||
"encoding/hex"
|
||||
"testing"
|
||||
@ -298,3 +299,33 @@ func TestVerify65(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkKeyGen65(b *testing.B) {
|
||||
var d [32]byte
|
||||
rand.Read(d[:])
|
||||
b.ResetTimer()
|
||||
for b.Loop() {
|
||||
if _, err := NewKey65(d[:]); err != nil {
|
||||
b.Fatalf("NewKey44 failed: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkSign65(b *testing.B) {
|
||||
var seed [32]byte
|
||||
c := sigGen65InternalProjectionCases[0]
|
||||
sk, _ := hex.DecodeString(c.sk)
|
||||
mu, _ := hex.DecodeString(c.mu)
|
||||
priv, err := NewPrivateKey65(sk)
|
||||
if err != nil {
|
||||
b.Fatalf("NewPrivateKey65 failed: %v", err)
|
||||
}
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for b.Loop() {
|
||||
_, err := priv.signInternal(seed[:], mu)
|
||||
if err != nil {
|
||||
b.Fatalf("signInternal failed: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ package mldsa
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/rand"
|
||||
"encoding/asn1"
|
||||
"encoding/hex"
|
||||
"testing"
|
||||
@ -258,3 +259,33 @@ func TestVerify87(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkKeyGen87(b *testing.B) {
|
||||
var d [32]byte
|
||||
rand.Read(d[:])
|
||||
b.ResetTimer()
|
||||
for b.Loop() {
|
||||
if _, err := NewKey87(d[:]); err != nil {
|
||||
b.Fatalf("NewKey44 failed: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkSign87(b *testing.B) {
|
||||
var seed [32]byte
|
||||
c := sigGen87InternalProjectionCases[0]
|
||||
sk, _ := hex.DecodeString(c.sk)
|
||||
mu, _ := hex.DecodeString(c.mu)
|
||||
priv, err := NewPrivateKey87(sk)
|
||||
if err != nil {
|
||||
b.Fatalf("NewPrivateKey87 failed: %v", err)
|
||||
}
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for b.Loop() {
|
||||
_, err := priv.signInternal(seed[:], mu)
|
||||
if err != nil {
|
||||
b.Fatalf("signInternal failed: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user