2016-01-28 10:16:26 -05:00
|
|
|
package crypto
|
|
|
|
|
|
|
|
import (
|
2016-01-29 07:22:31 -05:00
|
|
|
"testing"
|
2016-01-28 10:16:26 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestDSA(t *testing.T) {
|
2016-01-29 08:36:04 -05:00
|
|
|
var sk DSAPrivateKey
|
|
|
|
var pk DSAPublicKey
|
|
|
|
var err error
|
|
|
|
sk, err = sk.Generate()
|
2016-01-29 07:22:31 -05:00
|
|
|
if err == nil {
|
2016-01-29 08:36:04 -05:00
|
|
|
zeros := 0
|
|
|
|
for b, _ := range sk {
|
|
|
|
if b == 0 {
|
|
|
|
zeros ++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if zeros == len(sk) {
|
|
|
|
t.Logf("key generation yielded all zeros")
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
pk, err = sk.Public()
|
|
|
|
if err == nil {
|
|
|
|
data := make([]byte, 512)
|
|
|
|
var sig []byte
|
|
|
|
var signer Signer
|
|
|
|
signer, err = sk.NewSigner()
|
|
|
|
if err == nil {
|
|
|
|
sig, err = signer.Sign(data)
|
|
|
|
if err == nil {
|
|
|
|
t.Logf("sig=%q", sig)
|
|
|
|
var verify Verifier
|
|
|
|
verify, err = pk.NewVerifier()
|
|
|
|
if err == nil {
|
|
|
|
err = verify.Verify(data, sig)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-01-29 07:22:31 -05:00
|
|
|
}
|
2016-01-29 08:36:04 -05:00
|
|
|
if err != nil {
|
|
|
|
t.Logf("failed: %s", err.Error())
|
2016-01-29 07:22:31 -05:00
|
|
|
t.Fail()
|
|
|
|
}
|
2016-01-28 10:16:26 -05:00
|
|
|
}
|