ecies

package
v1.0.4026 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 5, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidCurve               = fmt.Errorf("ecies: invalid elliptic curve")
	ErrInvalidParams              = fmt.Errorf("ecies: invalid ECIES parameters")
	ErrInvalidPublicKey           = fmt.Errorf("ecies: invalid public key")
	ErrInvalidPrivateKey          = fmt.Errorf("ecies: invalid private key")
	ErrSharedKeyIsPointAtInfinity = fmt.Errorf("ecies: shared key is point at infinity")
	ErrSharedKeyTooBig            = fmt.Errorf("ecies: shared key params are too big")
	ErrUnsupportedECIESParameters = fmt.Errorf("ecies: unsupported ECIES parameters")

	ErrKeyDataTooLong = fmt.Errorf("ecies: can't supply requested key data")
	ErrSharedTooLong  = fmt.Errorf("ecies: shared secret is too long")
	ErrInvalidMessage = fmt.Errorf("ecies: invalid message")
)
View Source
var (
	ECIES_AES128_SHA256 = &ECIESParams{
		Hash:      sha256.New,
		Cipher:    aes.NewCipher,
		BlockSize: aes.BlockSize,
		KeyLen:    16,
	}
	ECIES_AES192_SHA384 = &ECIESParams{
		Hash:      sha512.New384,
		Cipher:    aes.NewCipher,
		BlockSize: aes.BlockSize,
		KeyLen:    24,
	}
	ECIES_AES256_SHA256 = &ECIESParams{
		Hash:      sha256.New,
		Cipher:    aes.NewCipher,
		BlockSize: aes.BlockSize,
		KeyLen:    32,
	}
	ECIES_AES256_SHA384 = &ECIESParams{
		Hash:      sha512.New384,
		Cipher:    aes.NewCipher,
		BlockSize: aes.BlockSize,
		KeyLen:    32,
	}
	ECIES_AES256_SHA512 = &ECIESParams{
		Hash:      sha512.New,
		Cipher:    aes.NewCipher,
		BlockSize: aes.BlockSize,
		KeyLen:    32,
	}
)

Functions

func AddParamsFromCurve

func AddParamsFromCurve(curve elliptic.Curve, ecie *ECIESParams)

func Decrypt

func Decrypt(priv *PrivateKey, c, s1, s2 []byte) (m []byte, err error)

func Encrypt

func Encrypt(rand io.Reader, pub *PublicKey, m, s1, s2 []byte) (ct []byte, err error)

Encrypt encrypts a message using ECIES as specified in SEC 1, 5.1.

s1 and s2 contain shared information that is not part of the resulting ciphertext. s1 is fed into key derivation, s2 is fed into the MAC. If the shared information parameters aren't being used, they should be nil.

func MaxSharedKeyLength

func MaxSharedKeyLength(pub *PublicKey) int

MaxSharedKeyLength returns the maximum length of the shared key the public key can produce.

Types

type ECIESParams

type ECIESParams struct {
	Hash      func() hash.Hash                   // hash function
	Cipher    func([]byte) (cipher.Block, error) // symmetric cipher
	BlockSize int                                // block size of symmetric cipher
	KeyLen    int                                // length of symmetric key
}

func ParamsFromCurve

func ParamsFromCurve(curve elliptic.Curve) *ECIESParams

type PrivateKey

type PrivateKey struct {
	PublicKey
	D *big.Int
}

PrivateKey is a representation of an elliptic curve private key.

func GenerateKey

func GenerateKey(rand io.Reader, curve elliptic.Curve, params *ECIESParams) (priv *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 ImportECDSAPrivateKey

func ImportECDSAPrivateKey(priv *ecdsa.PrivateKey) *PrivateKey

Import an ECDSA private key as an ECIES private key.

func (*PrivateKey) Decrypt

func (priv *PrivateKey) Decrypt(c, s1, s2 []byte) (m []byte, err error)

Decrypt decrypts an ECIES ciphertext.

func (*PrivateKey) ExportECDSA

func (priv *PrivateKey) ExportECDSA() *ecdsa.PrivateKey

Export an ECIES private key as an ECDSA private key.

func (*PrivateKey) GenerateShared

func (priv *PrivateKey) GenerateShared(pub *PublicKey, skLen, macLen int) (sk []byte, err error)

ECDH key agreement method used to establish secret keys for encryption.

func (*PrivateKey) Public

func (priv *PrivateKey) Public() crypto.PublicKey

Public returns the public key corresponding to priv.

type PublicKey

type PublicKey struct {
	X *big.Int
	Y *big.Int
	elliptic.Curve
	Params *ECIESParams
}

PublicKey is a representation of an elliptic curve public key.

func ImportECDSAPublicKey

func ImportECDSAPublicKey(pub *ecdsa.PublicKey) *PublicKey

Import an ECDSA public key as an ECIES public key.

func (*PublicKey) ExportECDSA

func (pub *PublicKey) ExportECDSA() *ecdsa.PublicKey

Export an ECIES public key as an ECDSA public key.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL