Exemplo n.º 1
0
func TestSignatureVerifierSHA2_384(t *testing.T) {
	// Create a signature
	primitives.SetSecurityLevel("SHA2", 384)

	cert, key, err := primitives.NewSelfSignedCert()
	if err != nil {
		t.Fatal(err)
	}

	message := []byte("Hello World!")
	signature, err := primitives.ECDSASign(key, message)
	if err != nil {
		t.Fatal(err)
	}

	// Instantiate a new SignatureVerifier
	sv := NewX509ECDSASignatureVerifier()

	// Verify the signature
	ok, err := sv.Verify(cert, signature, message)
	if err != nil {
		t.Fatal(err)
	}
	if !ok {
		t.Fatal("Signature does not verify")
	}
}
Exemplo n.º 2
0
func BenchmarkSign(b *testing.B) {
	b.StopTimer()
	b.ResetTimer()

	//b.Logf("#iterations %d\n", b.N)
	signKey, _ := primitives.NewECDSAKey()
	hash := make([]byte, 48)

	for i := 0; i < b.N; i++ {
		rand.Read(hash)
		b.StartTimer()
		primitives.ECDSASign(signKey, hash)
		b.StopTimer()
	}
}
Exemplo n.º 3
0
func BenchmarkVerify(b *testing.B) {
	b.StopTimer()
	b.ResetTimer()

	//b.Logf("#iterations %d\n", b.N)
	signKey, _ := primitives.NewECDSAKey()
	verKey := signKey.PublicKey
	hash := make([]byte, 48)

	for i := 0; i < b.N; i++ {
		rand.Read(hash)
		sigma, _ := primitives.ECDSASign(signKey, hash)
		b.StartTimer()
		primitives.ECDSAVerify(&verKey, hash, sigma)
		b.StopTimer()
	}
}
Exemplo n.º 4
0
func (node *nodeImpl) signWithEnrollmentKey(msg []byte) ([]byte, error) {
	return primitives.ECDSASign(node.enrollPrivKey, msg)
}
Exemplo n.º 5
0
func (node *nodeImpl) sign(signKey interface{}, msg []byte) ([]byte, error) {
	return primitives.ECDSASign(signKey, msg)
}
Exemplo n.º 6
0
func (validator *validatorImpl) sign(signKey interface{}, msg []byte) ([]byte, error) {
	sigma, err := primitives.ECDSASign(signKey, msg)

	return sigma, err
}