Documentation
¶
Index ¶
- Constants
- Variables
- func Pad(x []byte, size int) []byte
- type Cipher
- type ECKey
- func (k *ECKey) Decrypt(ciphertext []byte, c Cipher, hash hash.Hash, options ...Option) ([]byte, error)
- func (k *ECKey) ECPublic() *ECPublicKey
- func (k *ECKey) Private() ([]byte, error)
- func (k *ECKey) PrivateASN1() ([]byte, error)
- func (k *ECKey) PrivateRaw() []byte
- func (k *ECKey) Public() PublicKey
- func (k *ECKey) Sign(digest []byte) ([]byte, error)
- type ECPublicKey
- func (k *ECPublicKey) DH(hash hash.Hash, g PrivateKey, options ...Option) ([]byte, error)
- func (k *ECPublicKey) Encrypt(m []byte, c Cipher, hash hash.Hash, options ...Option) ([]byte, error)
- func (k *ECPublicKey) Fingerprint(h hash.Hash) []byte
- func (k *ECPublicKey) Key() ([]byte, error)
- func (k *ECPublicKey) KeyASN1() ([]byte, error)
- func (k *ECPublicKey) Name() string
- func (k *ECPublicKey) Points() (x *big.Int, y *big.Int)
- func (k *ECPublicKey) Size() int
- func (k *ECPublicKey) Verify(digest []byte, signature []byte) (bool, error)
- type Option
- type OptionHKDF
- type PrivateKey
- type PublicKey
Constants ¶
const ( // CipherAES_GCM is a AHEAD cipher and is recommended for most use cases CipherAES_GCM = iota // CipherChacha20 is a UNAUTHENTICATED cipher and is only provided with the expectation // you will handle the data integrity by using a MAC. Or instead please use one of the // provided authenticated ChaCha ciphers below. CipherChacha20 // CipherChacha20_SHA256 is a authenticated Encrypt-then-MAC (EtM) cipher using ChaCha20 // the MAC is a SHA256 hmac with the secret being the encryption key CipherChacha20_SHA256 // CipherChacha20_SHA512 is a authenticated Encrypt-then-MAC (EtM) cipher using ChaCha20 // the MAC is a SHA512 hmac with the secret being the encryption key CipherChacha20_SHA512 // CipherChaCha20Poly1305 is a authenticated cipher which takes a 256bit key CipherChaCha20Poly1305 // CipherSalsa20 is a UNAUTHENTICATED cipher and is only provided with the expectation // you will handle the data integrity by using a MAC. Or instead please use one of the // provided authenticated ChaCha ciphers below. CipherSalsa20 )
Variables ¶
var ( // ErrUnknownCipher is returned if the cipher provided is unsupported ErrUnknownCipher = errors.New("unknown cipher suite") // ErrCipherTxtSmall is returned if the data is so small it must be invalid ErrCipherTxtSmall = errors.New("cipher text is too small") // ErrAuthFail is returned when the ciphertext mac fails ErrAuthFail = errors.New("message authentication failed") // ErrKeySize is returned if the key is not supported in the encryption algorithm ErrKeySize = errors.New("key size not supported") )
var ( // ErrWrongKey is returned if the key is the wrong type ErrWrongKey = errors.New("wrong key type or curve") // ErrInvalidPem is returned when invalid PEM data is attempted to be decoded ErrInvalidPem = errors.New("invalid PEM data failed to parse") // ErrDerivePub is returned if there is a error in extracting the pub key from private D ErrDerivePub = errors.New("could not derive public key") )
Functions ¶
Types ¶
type ECKey ¶
type ECKey struct {
// contains filtered or unexported fields
}
ECKey is a Elliptic Curve
func NewECCurve ¶
func NewECCurve(priv *ecdsa.PrivateKey) *ECKey
NewECCurve takes a ECDSA key and converts it to a Rome private key
func ParseECPrivate ¶
ParseECPrivate will read a PEM ASN.1 DER encoded key
func ParseECPrivateASN1 ¶
ParseECPrivateASN1 will read a ASN.1 DER encoded key
func (*ECKey) Decrypt ¶
func (k *ECKey) Decrypt(ciphertext []byte, c Cipher, hash hash.Hash, options ...Option) ([]byte, error)
Decrypt uses ECIES hybrid encryption. Cipher is used to specify the encryption algorithm and hash is used to derive the key via the ECDH
func (*ECKey) ECPublic ¶
func (k *ECKey) ECPublic() *ECPublicKey
ECPublic returns the ECPublic interface instead of the unified rome interface. It is not recommended this function is used.
func (*ECKey) PrivateASN1 ¶
PrivateASN1 will return the private key as ASN.1 DER bytes
func (*ECKey) PrivateRaw ¶
PrivateRaw returns the private key (D)
type ECPublicKey ¶
type ECPublicKey struct {
// contains filtered or unexported fields
}
ECPublicKey holds the X and Y parameters for the key
func ParseECPublic ¶
func ParseECPublic(public []byte) (*ECPublicKey, error)
ParseECPublic will read elliptic curve public key from PEM ASN.1 DER format
func ParseECPublicASN1 ¶
func ParseECPublicASN1(der []byte) (*ECPublicKey, error)
ParseECPublicASN1 will read a elliptic curve public key from ASN.1 DER format
func (*ECPublicKey) DH ¶
func (k *ECPublicKey) DH(hash hash.Hash, g PrivateKey, options ...Option) ([]byte, error)
DH calculates a ECDH using your specified hash function for key generation
func (*ECPublicKey) Encrypt ¶
func (k *ECPublicKey) Encrypt(m []byte, c Cipher, hash hash.Hash, options ...Option) ([]byte, error)
Encrypt uses ECIES hybrid encryption. Cipher is used to specify the encryption algorithm and hash is used to derive the key via the ECDH
func (*ECPublicKey) Fingerprint ¶
func (k *ECPublicKey) Fingerprint(h hash.Hash) []byte
Fingerprint returns the hashed ASN.1 digest representing this public key. This function will panic if it fails to encode the public key.
func (*ECPublicKey) Key ¶
func (k *ECPublicKey) Key() ([]byte, error)
Key returns the public key in PEM ASN.1 DER format
func (*ECPublicKey) KeyASN1 ¶
func (k *ECPublicKey) KeyASN1() ([]byte, error)
KeyASN1 returns the public key formatted in ASN.1
type Option ¶
type Option any
Option allows you to specify exactly what you want a function to use. Functions only use the options relevant to them.
type OptionHKDF ¶
OptionHKDF is used in a DH and will overwrite the shared secret options
type PrivateKey ¶
type PrivateKey interface {
// Sign returns a ASN.1 formatted signature
Sign(digest []byte) ([]byte, error)
// Public returns the public key interface
Public() PublicKey
// Private returns the private key as PEM ANS.1 DER bytes
//
// Example Output:
//
// -----BEGIN EC PUBLIC KEY-----
// MIGbMBAGByqGSM49AgEGBSuBBAAjA4GGAAQAcnk2OsBaHEE1LW40x5ZyRubtyYN0
// P0lfNYr/J621MzgmHFWUhPXiGiNi5OLsoWkXAWBqoM5JHPI4GJXzrjBjh2gAgve4
// miuuyibmAF+KgXN8t24pm/Wo2owBTXjTPn2R4kPf8lvkeom3/uM8OQUxx3sn4Gld
// wnDkkVtMdB42du+DMQw=
//
// -----END EC PUBLIC KEY-----
Private() ([]byte, error)
// Private returns the private key as ANS.1 DER bytes
PrivateASN1() ([]byte, error)
// PrivateRaw if a elliptic or edwards curve the returned bytes will
// be the value D
PrivateRaw() []byte
// Decrypt will take a ECIES encrypted ciphertext and decrypt it using the
// private key
Decrypt(ciphertext []byte, cipher Cipher, hash hash.Hash, option ...Option) ([]byte, error)
}
PrivateKey holds the D point for the curve and the public key.
type PublicKey ¶
type PublicKey interface {
// Name returns the curve name
Name() string
// Size returns the key size in bytes
Size() int
// Verify will take a ASN.1 signature and return true if it's valid
Verify(digest []byte, signature []byte) (bool, error)
// Points returns the Elliptic/Edward Curve coordinates
Points() (x *big.Int, y *big.Int)
// Key returns the public key in PEM ASN.1 DER format
Key() ([]byte, error)
// KeyASN1 returns the public key formatted in ASN.1
KeyASN1() ([]byte, error)
// DH takes a hasher and the ephemeral private key
DH(h hash.Hash, g PrivateKey, options ...Option) ([]byte, error)
// Encrypt will uses ECIES to encrypt your message to the public key
Encrypt(msg []byte, cipher Cipher, hash hash.Hash, options ...Option) ([]byte, error)
// Fingerprint returns the hashed ASN.1 digest representing this
// public key. This function will panic if it fails to encode the
// public key.
Fingerprint(hash.Hash) []byte
}
PublicKey is a Elliptic/Edward curve public key
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package argon2 provides argon2id hash function which satisfies the hash.Hash interface
|
Package argon2 provides argon2id hash function which satisfies the hash.Hash interface |
|
Package brainpool provides generator functions for Brainpool Elliptic Curves
|
Package brainpool provides generator functions for Brainpool Elliptic Curves |
|
bcurves
Package brainpool provides the elliptic curves specified in rfc 5639
|
Package brainpool provides the elliptic curves specified in rfc 5639 |
|
Package derbytes is a slimmed down fork of crypto/x509 modified to support additional elliptic and edward curves.
|
Package derbytes is a slimmed down fork of crypto/x509 modified to support additional elliptic and edward curves. |
|
Package ed25519 provides a interface to use the Ed25519 Edwards Curve
|
Package ed25519 provides a interface to use the Ed25519 Edwards Curve |
|
Package ed448 provides a generator function for the Ed448 Edwards Curve
|
Package ed448 provides a generator function for the Ed448 Edwards Curve |
|
examples
|
|
|
ecdh
command
|
|
|
encrypt
command
|
|
|
generate
command
|
|
|
import
command
|
|
|
Package parse provides a unified parser for both Elliptic and Edwards Curves.
|
Package parse provides a unified parser for both Elliptic and Edwards Curves. |