ecies

package
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2023 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromX963

func FromX963(bytes []byte) *ecdsa.PublicKey

func ToX963

func ToX963(pubKey *ecdsa.PublicKey) []byte

func Unwrap

func Unwrap(w *WrappedSecret, privKey *ecdsa.PrivateKey) ([]byte, error)

Unwrap decrypts a WrappedSecret instance.

Types

type WrappedSecret

type WrappedSecret struct {
	//EncryptedData is the cypher text
	EncryptedData []byte
	//Tag is the AES GCM tag
	Tag []byte
	//EphermalPublicKey is the public key from the ephemeral keypair used to encrypt the data.
	EphemeralPublicKey *ecdsa.PublicKey
}

WrappedSecret represents data encrypted using ecies, specifically with the kSecKeyAlgorithmECIESEncryptionCofactorVariableIVX963SHA256AESGCM algorithm supported on apple platforms. See https://darthnull.org/secure-enclave-ecies/ for more info.

func Wrap

func Wrap(data []byte, target *ecdsa.PublicKey) (*WrappedSecret, error)

Wrap encrypts data using the kSecKeyAlgorithmECIESEncryptionCofactorVariableIVX963SHA256AESGCM algorithm supported on apple platforms. See https://darthnull.org/secure-enclave-ecies/ for more info. This algorithm:

  1. Generates a random ephemeral ECDH keypair
  2. Computes the shared secret between the ephemeral private key and the target public key using ECDH
  3. Uses the ANSI X9.63 Key Derivation algorithm to derive a 32 byte key from the shared secret, using the X9.63 public key format of the ephemeral public key as the shared info.
  4. Uses the first 16 bytes of the derived key as the AES-GCM key, and the last 16 bytes as the AES-GCM IV (nonce)
  5. Encrypts the data using AES-GCM.

Note: Because the IV is derived from the ephemeral public key and the ecdh shared secret, we don't need to store it as one normally would when doing AES-GCM encryption.

Only the P256 curve and SHA256 hash are supported.

Jump to

Keyboard shortcuts

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