mirror of
https://github.com/sonr-io/crypto.git
synced 2026-01-12 04:09:13 +00:00
40 lines
941 B
Go
Executable File
40 lines
941 B
Go
Executable File
//
|
|
// Copyright Coinbase, Inc. All Rights Reserved.
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
|
|
package curves
|
|
|
|
import (
|
|
"crypto/ecdsa"
|
|
"math/big"
|
|
)
|
|
|
|
// EcdsaVerify runs a curve- or algorithm-specific ECDSA verification function on input
|
|
// an ECDSA public (verification) key, a message digest, and an ECDSA signature.
|
|
// It must return true if all the parameters are sane and the ECDSA signature is valid,
|
|
// and false otherwise
|
|
type EcdsaVerify func(pubKey *EcPoint, hash []byte, signature *EcdsaSignature) bool
|
|
|
|
// EcdsaSignature represents a (composite) digital signature
|
|
type EcdsaSignature struct {
|
|
R *big.Int
|
|
S *big.Int
|
|
V int
|
|
}
|
|
|
|
// Static type assertion
|
|
var _ EcdsaVerify = VerifyEcdsa
|
|
|
|
// Verifies ECDSA signature using core types.
|
|
func VerifyEcdsa(pk *EcPoint, hash []byte, sig *EcdsaSignature) bool {
|
|
return ecdsa.Verify(
|
|
&ecdsa.PublicKey{
|
|
Curve: pk.Curve,
|
|
X: pk.X,
|
|
Y: pk.Y,
|
|
},
|
|
hash, sig.R, sig.S)
|
|
}
|