ecies

package
v0.0.0-...-a01cb7b Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

README

ECIES

Go implementation of ecies, modified from ethereum/go-ethereum/crypto/ecies/

Use only default params ECIES_AES128_SHA256 and curve secp256r1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidCurve               = fmt.Errorf("ecies: invalid elliptic curve")
	ErrInvalidPublicKey           = fmt.Errorf("ecies: invalid public key")
	ErrSharedKeyIsPointAtInfinity = fmt.Errorf("ecies: shared key is point at infinity")
	ErrSharedKeyTooBig            = fmt.Errorf("ecies: shared key params are too big")
)
View Source
var (
	ErrKeyDataTooLong = fmt.Errorf("ecies: can't supply requested key data")
	ErrInvalidMessage = fmt.Errorf("ecies: invalid message")
)
View Source
var (
	DefaultCurve  = elliptic.P256()
	DefaultParams = ECIES_AES128_SHA256
)
View Source
var (
	ECIES_AES128_SHA256 = &ECIESParams{
		Hash:      sha256.New,
		hashAlgo:  crypto.SHA256,
		Cipher:    aes.NewCipher,
		BlockSize: aes.BlockSize,
		KeyLen:    16,
	}
)

Functions

func Encrypt

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

Encrypt encrypts a message

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

	Cipher    func([]byte) (cipher.Block, error)
	BlockSize int
	KeyLen    int
	// contains filtered or unexported fields
}

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) (prv *PrivateKey, err error)

GenerateKey generate a random private key

func ImportECDSA

func ImportECDSA(prv *ecdsa.PrivateKey) *PrivateKey

Import an ECDSA private key as an ECIES private key.

func (*PrivateKey) Decrypt

func (prv *PrivateKey) Decrypt(c []byte) (m []byte, err error)

Decrypt decrypts an ECIES ciphertext

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, skLen, macLen int) (sk []byte, err error)

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

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 ImportECDSAPublic

func ImportECDSAPublic(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