Documentation ¶
Index ¶
- Constants
- type PrKeyECDSA
- func (sk *PrKeyECDSA) Algorithm() SigningAlgorithm
- func (sk *PrKeyECDSA) Encode() []byte
- func (sk *PrKeyECDSA) Equals(other PrivateKey) bool
- func (sk *PrKeyECDSA) PublicKey() PublicKey
- func (sk *PrKeyECDSA) Sign(data []byte, alg hash.Hasher) (Signature, error)
- func (sk *PrKeyECDSA) Size() int
- func (sk *PrKeyECDSA) String() string
- type PrivateKey
- type PubKeyECDSA
- func (pk *PubKeyECDSA) Algorithm() SigningAlgorithm
- func (pk *PubKeyECDSA) Encode() []byte
- func (pk *PubKeyECDSA) Equals(other PublicKey) bool
- func (pk *PubKeyECDSA) Size() int
- func (pk *PubKeyECDSA) String() string
- func (pk *PubKeyECDSA) Verify(sig Signature, data []byte, alg hash.Hasher) (bool, error)
- type PublicKey
- type SECCurve
- type Signature
- type SigningAlgorithm
Constants ¶
const ( // MinSeedLen is a generic minimum seed length to guarantee a minimum entropy. // It is used when the seed source is not necessary a CSPRG and the seed // should be expanded before being passed to the generation process (key generation or other). MinSeedLen = 2 * (securityBits / 8) // NIST P256 SignatureLenECDSAP256 = 64 PrKeyLenECDSAP256 = 32 // PubKeyLenECDSAP256 is the size of uncompressed points on P256 PubKeyLenECDSAP256 = 64 KeyGenSeedMinLenECDSAP256 = PrKeyLenECDSAP256 + (securityBits / 8) // SECG secp256k1 SignatureLenECDSASecp256k1 = 64 PrKeyLenECDSASecp256k1 = 32 // PubKeyLenECDSASecp256k1 is the size of uncompressed points on P256 PubKeyLenECDSASecp256k1 = 64 KeyGenSeedMinLenECDSASecp256k1 = PrKeyLenECDSASecp256k1 + (securityBits / 8) )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type PrKeyECDSA ¶
type PrKeyECDSA struct {
// contains filtered or unexported fields
}
PrKeyECDSA is the private key of ECDSA, it implements the generic PrivateKey
func (*PrKeyECDSA) Algorithm ¶
func (sk *PrKeyECDSA) Algorithm() SigningAlgorithm
Algorithm returns the algo related to the private key
func (*PrKeyECDSA) Encode ¶
func (sk *PrKeyECDSA) Encode() []byte
Encode returns a byte representation of a private key. a simple raw byte encoding in big endian is used for all curves
func (*PrKeyECDSA) Equals ¶
func (sk *PrKeyECDSA) Equals(other PrivateKey) bool
Equals test the equality of two private keys
func (*PrKeyECDSA) PublicKey ¶
func (sk *PrKeyECDSA) PublicKey() PublicKey
PublicKey returns the public key associated to the private key
func (*PrKeyECDSA) Sign ¶
Sign signs an array of bytes It only reads the private key without modifiying it while hashers sha2 and sha3 are modified temporarily. the resulting signature is the concatenation bytes(r)||bytes(s) where r and s are padded to the curve order size
func (*PrKeyECDSA) Size ¶
func (sk *PrKeyECDSA) Size() int
Size returns the length of the private key in bytes
func (*PrKeyECDSA) String ¶
func (sk *PrKeyECDSA) String() string
String returns the hex string representation of the key.
type PrivateKey ¶
type PrivateKey interface { // Algorithm returns the signing algorithm related to the private key. Algorithm() SigningAlgorithm // Size return the key size in bytes. Size() int // String return a hex representation of the key String() string // Sign generates a signature using the provided hasher. Sign([]byte, hash.Hasher) (Signature, error) // PublicKey returns the public key. PublicKey() PublicKey // Encode returns a bytes representation of the private key Encode() []byte // Equals returns true if the given PrivateKeys are equal. Keys are considered unequal if their algorithms are // unequal or if their encoded representations are unequal. If the encoding of either key fails, they are considered // unequal as well. Equals(PrivateKey) bool }
PrivateKey is an unspecified signature scheme private key
func DecodePrivateKey ¶
func DecodePrivateKey(algo SigningAlgorithm, data []byte) (PrivateKey, error)
DecodePrivateKey decodes an array of bytes into a private key of the given algorithm
func GeneratePrivateKey ¶
func GeneratePrivateKey(algo SigningAlgorithm, seed []byte) (PrivateKey, error)
GeneratePrivateKey generates a private key of the algorithm using the entropy of the given seed
type PubKeyECDSA ¶
type PubKeyECDSA struct {
// contains filtered or unexported fields
}
PubKeyECDSA is the public key of ECDSA, it implements PublicKey
func (*PubKeyECDSA) Algorithm ¶
func (pk *PubKeyECDSA) Algorithm() SigningAlgorithm
Algorithm returns the the algo related to the private key
func (*PubKeyECDSA) Encode ¶
func (pk *PubKeyECDSA) Encode() []byte
Encode returns a byte representation of a public key. a simple uncompressed raw encoding X||Y is used for all curves X and Y are the big endian byte encoding of the x and y coordinates of the public key
func (*PubKeyECDSA) Equals ¶
func (pk *PubKeyECDSA) Equals(other PublicKey) bool
Equals test the equality of two private keys
func (*PubKeyECDSA) Size ¶
func (pk *PubKeyECDSA) Size() int
Size returns the length of the public key in bytes
func (*PubKeyECDSA) String ¶
func (pk *PubKeyECDSA) String() string
String returns the hex string representation of the key.
type PublicKey ¶
type PublicKey interface { // Algorithm returns the signing algorithm related to the public key. Algorithm() SigningAlgorithm // Size() return the key size in bytes. Size() int // String return a hex representation of the key String() string // Verify verifies a signature of an input message using the provided hasher. Verify(Signature, []byte, hash.Hasher) (bool, error) // Encode returns a bytes representation of the public key. Encode() []byte // Equals returns true if the given PublicKeys are equal. Keys are considered unequal if their algorithms are // unequal or if their encoded representations are unequal. If the encoding of either key fails, they are considered // unequal as well. Equals(PublicKey) bool }
PublicKey is an unspecified signature scheme public key.
func DecodePublicKey ¶
func DecodePublicKey(algo SigningAlgorithm, data []byte) (PublicKey, error)
DecodePublicKey decodes an array of bytes into a public key of the given algorithm
type SECCurve ¶
type SECCurve struct {
goec.CurveParams
}
A SECCurve represents a short-form Weierstrass curve with a=0 It embeds CurveParams from crypto/elliptic which implements NIST curves (a=-3) The functions involving the parameter `a` are re-written
func (*SECCurve) ScalarBaseMult ¶
ScalarBaseMult returns k*G, where G is the base point of the group and k is an integer in big-endian form. (taken from Go/crypto/elliptic)
type Signature ¶
type Signature []byte
Signature is a generic type, regardless of the signature scheme
type SigningAlgorithm ¶
type SigningAlgorithm int
SigningAlgorithm is an identifier for a signing algorithm (and parameters if applicable)
const ( UnknownSigningAlgorithm SigningAlgorithm = iota // BLSBLS12381 is BLS on BLS 12-381 curve BLSBLS12381 // ECDSAP256 is ECDSA on NIST P-256 curve ECDSAP256 // ECDSASecp256k1 is ECDSA on secp256k1 curve ECDSASecp256k1 )
func (SigningAlgorithm) String ¶
func (f SigningAlgorithm) String() string
String returns the string representation of this signing algorithm.