github.com/hyperledger/aries-framework-go@v0.3.2/pkg/crypto/tinkcrypto/primitive/secp256k1/subtle/subtle.go (about)

     1  /*
     2  Copyright SecureKey Technologies Inc. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  // Package subtle provides subtle implementations of the digital signature primitive.
     8  package subtle
     9  
    10  import (
    11  	"crypto/ecdsa"
    12  	"crypto/elliptic"
    13  	"math/big"
    14  
    15  	secp256k1subtle "github.com/hyperledger/aries-framework-go/component/kmscrypto/crypto/tinkcrypto/primitive/secp256k1/subtle"
    16  )
    17  
    18  // Secp256k1Signature is a struct holding the r and s values of an secp256k1 signature.
    19  type Secp256k1Signature = secp256k1subtle.Secp256k1Signature
    20  
    21  // NewSecp256K1Signature creates a new Secp256k1Signature instance.
    22  func NewSecp256K1Signature(r, s *big.Int) *Secp256k1Signature {
    23  	return secp256k1subtle.NewSecp256K1Signature(r, s)
    24  }
    25  
    26  // DecodeSecp256K1Signature creates a new secp256k1 signature using the given byte slice.
    27  // The function assumes that the byte slice is the concatenation of the BigEndian
    28  // representation of two big integer r and s.
    29  func DecodeSecp256K1Signature(encodedBytes []byte, encoding string) (*Secp256k1Signature, error) {
    30  	return secp256k1subtle.DecodeSecp256K1Signature(encodedBytes, encoding)
    31  }
    32  
    33  // ValidateSecp256K1Params validates secp256k1 parameters.
    34  // The hash's strength must not be weaker than the curve's strength.
    35  // DER and IEEE_P1363 encodings are supported.
    36  func ValidateSecp256K1Params(hashAlg, curve, encoding string) error {
    37  	return secp256k1subtle.ValidateSecp256K1Params(hashAlg, curve, encoding)
    38  }
    39  
    40  // GetCurve returns the curve object that corresponds to the given curve type.
    41  // It returns null if the curve type is not supported.
    42  func GetCurve(curve string) elliptic.Curve {
    43  	return secp256k1subtle.GetCurve(curve)
    44  }
    45  
    46  // Secp256K1Signer is an implementation of Signer for secp256k1 Secp256k2 (Koblitz curve).
    47  // At the moment, the implementation only accepts DER encoding.
    48  type Secp256K1Signer = secp256k1subtle.Secp256K1Signer
    49  
    50  // NewSecp256K1Signer creates a new instance of Secp256K1Signer.
    51  func NewSecp256K1Signer(hashAlg string,
    52  	curve string,
    53  	encoding string,
    54  	keyValue []byte) (*Secp256K1Signer, error) {
    55  	return secp256k1subtle.NewSecp256K1Signer(hashAlg, curve, encoding, keyValue)
    56  }
    57  
    58  // NewSecp256K1SignerFromPrivateKey creates a new instance of Secp256K1Signer.
    59  func NewSecp256K1SignerFromPrivateKey(hashAlg string, encoding string,
    60  	privateKey *ecdsa.PrivateKey) (*Secp256K1Signer, error) {
    61  	return secp256k1subtle.NewSecp256K1SignerFromPrivateKey(hashAlg, encoding, privateKey)
    62  }
    63  
    64  // ConvertCurveName converts different forms of a curve name to the name that tink recognizes.
    65  func ConvertCurveName(name string) string {
    66  	return secp256k1subtle.ConvertCurveName(name)
    67  }
    68  
    69  // ECDSAVerifier is an implementation of Verifier for ECDSA.
    70  // At the moment, the implementation only accepts signatures with strict DER encoding.
    71  type ECDSAVerifier = secp256k1subtle.ECDSAVerifier
    72  
    73  // NewSecp256K1Verifier creates a new instance of Secp256K1Verifier.
    74  func NewSecp256K1Verifier(hashAlg, curve, encoding string, x, y []byte) (*ECDSAVerifier, error) {
    75  	return secp256k1subtle.NewSecp256K1Verifier(hashAlg, curve, encoding, x, y)
    76  }
    77  
    78  // NewSecp256K1VerifierFromPublicKey creates a new instance of ECDSAVerifier.
    79  func NewSecp256K1VerifierFromPublicKey(hashAlg, encoding string, publicKey *ecdsa.PublicKey) (*ECDSAVerifier, error) {
    80  	return secp256k1subtle.NewSecp256K1VerifierFromPublicKey(hashAlg, encoding, publicKey)
    81  }