Files
cunicu/pkg/crypto/xeddsa_test.go
Steffen Vogel a74df99adb initial commit
Signed-off-by: Steffen Vogel <post@steffenvogel.de>
2021-12-15 18:03:58 +01:00

50 lines
742 B
Go

package crypto_test
import (
"crypto/rand"
"fmt"
"testing"
"riasc.eu/wice/pkg/crypto"
)
func TestXEdDSA(t *testing.T) {
sk, err := crypto.GeneratePrivateKey()
if err != nil {
t.Fail()
}
pk := sk.PublicKey()
msg := make([]byte, 200)
rnd := make([]byte, 32)
_, err = rand.Reader.Read(rnd[:])
if err != nil {
t.Fail()
}
_, err = rand.Reader.Read(msg[:])
if err != nil {
t.Fail()
}
signature := sk.Sign(msg, rnd)
fmt.Printf("PrivateKey = %s\n", sk)
fmt.Printf("PublicKey = %s\n", pk)
fmt.Printf("Signature = %s\n", signature)
res := pk.Verify(msg, signature)
if !res {
t.Error("Signature mismatch")
}
msg[0] ^= 0xff
res = pk.Verify(msg, signature)
if res {
t.Error("Signature false positive")
}
}