Documentation
¶
Index ¶
- Variables
- func AddParamsForCurve(curve elliptic.Curve, params *ECIESParams)
- func CBCDecrypt(rand io.Reader, params *ECIESParams, ...) ([]byte, error)
- func CBCEncrypt(rand io.Reader, params *ECIESParams, key, plaintext, authenticationData []byte) ([]byte, error)
- func CFBDecrypt(rand io.Reader, params *ECIESParams, ...) ([]byte, error)
- func CFBEncrypt(rand io.Reader, params *ECIESParams, key, plaintext, authenticationData []byte) ([]byte, error)
- func CTRDecrypt(rand io.Reader, params *ECIESParams, ...) ([]byte, error)
- func CTREncrypt(rand io.Reader, params *ECIESParams, key, plaintext, authenticationData []byte) ([]byte, error)
- func ConcatKDF(hash hash.Hash, sharedSecret, sharedInformation1 []byte, derivedKeyLength int) (derivedKey []byte, err error)
- func Encrypt(rand io.Reader, pub *PublicKey, ...) (ciphertext []byte, err error)
- func EncryptAEAD(rand io.Reader, pub *PublicKey, plaintext []byte) (ciphertext []byte, err error)
- func GCMDecrypt(rand io.Reader, params *ECIESParams, ...) (plaintext []byte, err error)
- func GCMEncrypt(rand io.Reader, params *ECIESParams, key, plaintext, authenticationData []byte) (ciphertext []byte, err error)
- func GenerateIV(length int, rand io.Reader) (iv []byte, err error)
- func MaxSharedKeyLength(pub *PublicKey) int
- func MessageTag(hash func() hash.Hash, key, msg, shared []byte) []byte
- func SymmetricBlockModeDecrypt(str func(cipher.Block, []byte) cipher.BlockMode, blockCipher cipher.Block, ...) []byte
- func SymmetricBlockModeEncrypt(str func(cipher.Block, []byte) cipher.BlockMode, blockCipher cipher.Block, ...) (ciphertext []byte)
- func SymmetricDecrypt(rand io.Reader, params *ECIESParams, ...) ([]byte, error)
- func SymmetricEncrypt(rand io.Reader, params *ECIESParams, key, plaintext, authenticationData []byte) ([]byte, error)
- func SymmetricStreamDecrypt(str func(cipher.Block, []byte) cipher.Stream, blockCipher cipher.Block, ...) (plaintext []byte)
- func SymmetricStreamEncrypt(str func(cipher.Block, []byte) cipher.Stream, blockCipher cipher.Block, ...) (ciphertext []byte)
- type ECIESParams
- type PrivateKey
- func (privateKey *PrivateKey) Decrypt(rand io.Reader, ciphertext, sharedInformation1, sharedInformation2 []byte) (plaintext []byte, err error)
- func (privateKey *PrivateKey) DecryptAEAD(rand io.Reader, ciphertext []byte) (plaintext []byte, err error)
- func (prv *PrivateKey) ExportECDSA() *ecdsa.PrivateKey
- func (prv *PrivateKey) GenerateShared(pub *PublicKey, keyLength int) (sk []byte, err error)
- type PublicKey
- type SymmetricCipherMode
Constants ¶
This section is empty.
Variables ¶
var ( ErrImport = fmt.Errorf("ecies: failed to import key") ErrInvalidCurve = fmt.Errorf("ecies: invalid elliptic curve") ErrInvalidParams = fmt.Errorf("ecies: invalid ECIES parameters") ErrInvalidPublicKey = fmt.Errorf("ecies: invalid public key") )
var ( ErrKeyDataTooLong = fmt.Errorf("ecies: can't supply requested key data") ErrInvalidMessage = fmt.Errorf("ecies: invalid message") )
var ( ErrUnsupportedECDHAlgorithm = fmt.Errorf("ecies: unsupported ECDH algorithm") ErrUnsupportedECIESParameters = fmt.Errorf("ecies: unsupported ECIES parameters") )
var ( ECIES_AES128_SHA256 = &ECIESParams{ Hash: sha256.New, HashAlgo: crypto.SHA256, Cipher: aes.NewCipher, BlockSize: aes.BlockSize, KeyLen: 32, SymmetricCipherMode: GCMCipherMode, } ECIES_AES256_SHA256 = &ECIESParams{ Hash: sha256.New, HashAlgo: crypto.SHA256, Cipher: aes.NewCipher, BlockSize: aes.BlockSize, KeyLen: 32, SymmetricCipherMode: GCMCipherMode, } ECIES_AES256_SHA384 = &ECIESParams{ Hash: sha512.New384, HashAlgo: crypto.SHA384, Cipher: aes.NewCipher, BlockSize: aes.BlockSize, KeyLen: 32, SymmetricCipherMode: GCMCipherMode, } ECIES_AES256_SHA512 = &ECIESParams{ Hash: sha512.New, HashAlgo: crypto.SHA512, Cipher: aes.NewCipher, BlockSize: aes.BlockSize, KeyLen: 32, SymmetricCipherMode: GCMCipherMode, } )
var ( CTRCipherMode = SymmetricCipherMode{ Encryptor: CTREncrypt, Decryptor: CTRDecrypt, } CFBCipherMode = SymmetricCipherMode{ Encryptor: CFBEncrypt, Decryptor: CFBDecrypt, } )
var CBCCipherMode = SymmetricCipherMode{ Encryptor: CBCEncrypt, Decryptor: CBCDecrypt, }
var GCMCipherMode = SymmetricCipherMode{ Encryptor: GCMEncrypt, Decryptor: GCMDecrypt, }
Functions ¶
func AddParamsForCurve ¶
func AddParamsForCurve(curve elliptic.Curve, params *ECIESParams)
func CBCDecrypt ¶
func CBCDecrypt(rand io.Reader, params *ECIESParams, key, ciphertext, authenticationData []byte) ([]byte, error)
CBCDecrypt performs Cipher Block Chaining (CBC) decryption using the block cipher specified in the parameters
func CBCEncrypt ¶
func CBCEncrypt(rand io.Reader, params *ECIESParams, key, plaintext, authenticationData []byte) ([]byte, error)
CBCEncrypt performs Cipher Block Chaining (CBC) encryption using the block cipher specified in the parameters
func CFBDecrypt ¶
func CFBDecrypt(rand io.Reader, params *ECIESParams, key, ciphertext, authenticationData []byte) ([]byte, error)
CFBDecrypt performs Cipher Feedback (CFB) decryption using the block cipher specified in the parameters
func CFBEncrypt ¶
func CFBEncrypt(rand io.Reader, params *ECIESParams, key, plaintext, authenticationData []byte) ([]byte, error)
CFBEncrypt performs Cipher Feedback (CFB) encryption using the block cipher specified in the parameters
func CTRDecrypt ¶
func CTRDecrypt(rand io.Reader, params *ECIESParams, key, ciphertext, authenticationData []byte) ([]byte, error)
CTRDecrypt carries out CTR decryption using the block cipher specified in the parameters
func CTREncrypt ¶
func CTREncrypt(rand io.Reader, params *ECIESParams, key, plaintext, authenticationData []byte) ([]byte, error)
CTREncrypt carries out CTR encryption using the block cipher specified in the parameters.
func ConcatKDF ¶
func ConcatKDF(hash hash.Hash, sharedSecret, sharedInformation1 []byte, derivedKeyLength int) (derivedKey []byte, err error)
ConcatKDF derives a symmetric key from a shared secret using a concatenation key derivation function using the `hash` hashing algorithm as the base and continuing until at least `derivedKeyLength` bytes is available See NIST SP 800-56 Concatenation Key Derivation Function (see section 5.8.1).
func Encrypt ¶
func Encrypt(rand io.Reader, pub *PublicKey, plaintext, sharedInformation1, sharedInformation2 []byte) (ciphertext []byte, err error)
Encrypt encrypts a message using ECIES as specified in SEC 1, 5.1.
sharedInformation1 and sharedInformation2 contain shared information that is not part of the resulting ciphertext. sharedInformation1 is fed into key derivation, sharedInformation2 is fed into the MAC. If the shared information parameters aren't being used, they should be nil.
func EncryptAEAD ¶
Galois/Counter Mode is an AEAD (authenticated cipher) - i.e. it is already authenticated and does not require additional tagging to protect the message integrity
func GCMDecrypt ¶
func GCMDecrypt(rand io.Reader, params *ECIESParams, key, ciphertext, authenticationData []byte) (plaintext []byte, err error)
GCMDecrypt performs Galois/Counter Mode decryption using the block cipher specified in the parameters
func GCMEncrypt ¶
func GCMEncrypt(rand io.Reader, params *ECIESParams, key, plaintext, authenticationData []byte) (ciphertext []byte, err error)
GCMEncrypt performs Galois/Counter Mode encryption using the block cipher specified in the parameters
func GenerateIV ¶
Generate an initialisation vector for CTR mode.
func MaxSharedKeyLength ¶
MaxSharedKeyLength returns the maximum length of the shared key the public key can produce.
func MessageTag ¶
MessageTag computes the MAC of a message (called the tag) as per SEC 1, 3.5.
func SymmetricBlockModeDecrypt ¶
func SymmetricBlockModeDecrypt(str func(cipher.Block, []byte) cipher.BlockMode, blockCipher cipher.Block, iv []byte, key, ciphertext []byte) []byte
Performs sysmmetric decryption using the specified block cipher
func SymmetricBlockModeEncrypt ¶
func SymmetricBlockModeEncrypt(str func(cipher.Block, []byte) cipher.BlockMode, blockCipher cipher.Block, iv []byte, key, plaintext []byte) (ciphertext []byte)
Performs sysmmetric encrypion using the specified block cipher
func SymmetricDecrypt ¶
func SymmetricDecrypt(rand io.Reader, params *ECIESParams, key, ciphertext, authenticationData []byte) ([]byte, error)
SymmetricDecrypt decrypts the `ciphertext` bytes with a symmetric cipher specified by `params` using key `key` and optionally authenticates the message with `authenticationData` (for AEAD ciphers (GCM) only)
func SymmetricEncrypt ¶
func SymmetricEncrypt(rand io.Reader, params *ECIESParams, key, plaintext, authenticationData []byte) ([]byte, error)
SymmetricEncrypt encrypts the `plaintext` bytes with a symmetric cipher specified by `params` using key `key` and optionally authenticates the message with `authenticationData` (for AEAD ciphers (GCM) only)
Types ¶
type ECIESParams ¶
type ECIESParams struct {
Hash func() hash.Hash // hash function
HashAlgo crypto.Hash
Cipher func([]byte) (cipher.Block, error) // symmetric cipher
BlockSize int // block size of symmetric cipher
KeyLen int // length of symmetric key
SymmetricCipherMode SymmetricCipherMode
}
func ParamsFromCurve ¶
func ParamsFromCurve(curve elliptic.Curve) (params *ECIESParams)
ParamsFromCurve selects parameters optimal for the selected elliptic curve. Only the curves P256, P384, and P512 are supported.
type PrivateKey ¶
PrivateKey is a representation of an elliptic curve private key.
func GenerateKey ¶
func GenerateKey(rand io.Reader, curve elliptic.Curve, params *ECIESParams) (prv *PrivateKey, err error)
Generate an elliptic curve public / private keypair. If params is nil, the recommended default parameters for the key will be chosen.
func ImportECDSA ¶
func ImportECDSA(prv *ecdsa.PrivateKey) *PrivateKey
Import an ECDSA private key as an ECIES private key.
func (*PrivateKey) Decrypt ¶
func (privateKey *PrivateKey) Decrypt(rand io.Reader, ciphertext, sharedInformation1, sharedInformation2 []byte) (plaintext []byte, err error)
Decrypt decrypts an ECIES ciphertext.
func (*PrivateKey) DecryptAEAD ¶
func (privateKey *PrivateKey) DecryptAEAD(rand io.Reader, ciphertext []byte) (plaintext []byte, err error)
Decryption in AEAD mode (w/o message tag)
func (*PrivateKey) ExportECDSA ¶
func (prv *PrivateKey) ExportECDSA() *ecdsa.PrivateKey
Export an ECIES private key as an ECDSA private key.
func (*PrivateKey) GenerateShared ¶
func (prv *PrivateKey) GenerateShared(pub *PublicKey, keyLength int) (sk []byte, err error)
ECDH key agreement method used to establish secret keys for encryption.
type PublicKey ¶
PublicKey is a representation of an elliptic curve public key.
func ImportECDSAPublic ¶
Import an ECDSA public key as an ECIES public key.
func (*PublicKey) ExportECDSA ¶
Export an ECIES public key as an ECDSA public key.