mirror of
https://codeberg.org/cunicu/cunicu.git
synced 2025-12-24 06:18:40 +08:00
50 lines
742 B
Go
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")
|
|
}
|
|
}
|