Documentation ¶
Index ¶
Constants ¶
const ( UnknownSignatureAlgorithm SignatureAlgorithm = crypto.UnknownSigningAlgorithm // ECDSA_P256 is ECDSA on NIST P-256 curve ECDSA_P256 = crypto.ECDSAP256 // ECDSA_secp256k1 is ECDSA on secp256k1 curve ECDSA_secp256k1 = crypto.ECDSASecp256k1 )
const ( UnknownHashAlgorithm HashAlgorithm = hash.UnknownHashingAlgorithm SHA2_256 = hash.SHA2_256 SHA2_384 = hash.SHA2_384 SHA3_256 = hash.SHA3_256 SHA3_384 = hash.SHA3_384 )
const MinSeedLength = 32
MinSeedLength is the generic minimum seed length required to make sure there is enough entropy to generate keys targeting 128 bits of security. (this is not a guarantee though).
This minimum is used when the seed source is not necessarily a CSPRG and the seed should be expanded before being passed to the key generation process.
Variables ¶
var DecodePrivateKey = crypto.DecodePrivateKey
DecodePrivateKey decodes a raw byte encoded private key with the given signature algorithm.
var DecodePublicKey = crypto.DecodePublicKey
DecodePublicKey decodes a raw byte encoded public key with the given signature algorithm.
Functions ¶
func CompatibleAlgorithms ¶
func CompatibleAlgorithms(sigAlgo SignatureAlgorithm, hashAlgo HashAlgorithm) bool
CompatibleAlgorithms returns true if the signature and hash algorithms are compatible.
Types ¶
type HashAlgorithm ¶
type HashAlgorithm = hash.HashingAlgorithm
HashAlgorithm is an identifier for a hash algorithm.
func StringToHashAlgorithm ¶
func StringToHashAlgorithm(s string) HashAlgorithm
StringToHashAlgorithm converts a string to a HashAlgorithm.
type Hasher ¶
func NewHasher ¶
func NewHasher(algo HashAlgorithm) (Hasher, error)
NewHasher initializes and returns a new hasher with the given hash algorithm.
This function returns an error if the hash algorithm is invalid.
type InMemorySigner ¶
type InMemorySigner struct { PrivateKey PrivateKey Hasher Hasher }
An InMemorySigner is a signer that generates signatures using an in-memory private key.
InMemorySigner implements simple signing that does not protect the private key against any tampering or side channel attacks.
func NewInMemorySigner ¶
func NewInMemorySigner(privateKey PrivateKey, hashAlgo HashAlgorithm) InMemorySigner
NewInMemorySigner initializes and returns a new in-memory signer with the provided private key and hasher.
type NaiveSigner ¶
type NaiveSigner = InMemorySigner
NaiveSigner is an alias for InMemorySigner.
func NewNaiveSigner ¶
func NewNaiveSigner(privateKey PrivateKey, hashAlgo HashAlgorithm) NaiveSigner
NewNaiveSigner is an alias for NewInMemorySigner.
type PrivateKey ¶
type PrivateKey = crypto.PrivateKey
A PrivateKey is a cryptographic private key that can be used for in-memory signing.
func DecodePrivateKeyHex ¶
func DecodePrivateKeyHex(sigAlgo SignatureAlgorithm, s string) (PrivateKey, error)
DecodePrivateKeyHex decodes a raw hex encoded private key with the given signature algorithm.
func GeneratePrivateKey ¶
func GeneratePrivateKey(sigAlgo SignatureAlgorithm, seed []byte) (PrivateKey, error)
GeneratePrivateKey generates a private key with the specified signature algorithm from the given seed.
type PublicKey ¶
A PublicKey is a cryptographic public key that can be used to verify signatures.
func DecodePublicKeyHex ¶
func DecodePublicKeyHex(sigAlgo SignatureAlgorithm, s string) (PublicKey, error)
DecodePublicKeyHex decodes a raw hex encoded public key with the given signature algorithm.
func DecodePublicKeyPEM ¶
func DecodePublicKeyPEM(sigAlgo SignatureAlgorithm, s string) (PublicKey, error)
DecodePublicKeyHex decodes a PEM ECDSA public key with the given curve, encoded in `sigAlgo`.
The function only supports ECDSA with P256 and secp256k1 curves.
type SignatureAlgorithm ¶
type SignatureAlgorithm = crypto.SigningAlgorithm
SignatureAlgorithm is an identifier for a signature algorithm (and parameters if applicable).
func StringToSignatureAlgorithm ¶
func StringToSignatureAlgorithm(s string) SignatureAlgorithm
StringToSignatureAlgorithm converts a string to a SignatureAlgorithm.