eff

package
v0.0.0-...-c94e5b3 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//Magic number used for file signature/identification
	Magic = "OCSEFF"
)

Variables

View Source
var (
	//ErrInvalidHeader invalid header
	ErrInvalidHeader = errors.New("invalid header")
	//ErrInvalidPublicKey invalid public key
	ErrInvalidPublicKey = errors.New("invalid public key")
	//ErrBadSignature bad signature
	ErrBadSignature = errors.New("bad signature")
	//ErrBadCertificate bad certificate
	ErrBadCertificate = errors.New("bad certificate")
	//ErrNoMatchingCertificates no matching certificates
	ErrNoMatchingCertificates = errors.New("no matching certificates")
)
View Source
var (
	//ErrInvalidAlgo invalid algorithm
	ErrInvalidAlgo = errors.New("invalid algorithm")
)

Functions

func MarshalEFF

func MarshalEFF(h *Header, ct []byte, w io.Writer) error

MarshalEFF writes a EFF file given a Header and cipher text

Types

type Algorithm

type Algorithm uint8

Algorithm EFF AEAD encryption algorithm

const (
	//UnknownAlgo unknown or not set
	UnknownAlgo Algorithm = iota
	//AES256GCM AES 256 bit GCM mode
	AES256GCM
	//ChaCha20Poly1305 ChaCha20 with Poly1305 MAC
	ChaCha20Poly1305
)
type Header struct {
	Version               uint8         `msgpack:"v"`
	Algo                  Algorithm     `msgpack:"a"`
	CertificateID         []byte        `msgpack:"c"`
	Signature             []byte        `msgpack:"s"`
	IntendedCertificateID []byte        `msgpack:"i"`
	EphemeralAlgo         cki.Algorithm `msgpack:"ea"`
	EphemeralPublicKey    []byte        `msgpack:"ek"`
	EphemeralKDFSalt      []byte        `msgpack:"es"`
	Certificates          [][]byte      `msgpack:"ac,omitempty"`
	// contains filtered or unexported fields
}

Header representation of a OCS EPF Header

func NewHeader

func NewHeader(sigCert, intendedCert *cki.Certificate) (*Header, cki.PrivateKey, error)

NewHeader creates a new header and ephemeral key using a designated signing key (from) and an intended recipient key (to)

func NewHeaderWithOptions

func NewHeaderWithOptions(sigCert, intendedCert *cki.Certificate, options ...HeaderOption) (*Header, error)

NewHeaderWithOptions creates a new header with a specific set of options applied using a designated signing key (from) and an intended recipient key (to)

func ParseEFF

func ParseEFF(r io.Reader) (*Header, error)

ParseEFF reads a EFF file and returns the header. The cipher text is not read

func ParseHeader

func ParseHeader(d []byte) (*Header, error)

ParseHeader unmarshals in a msgpack encoded header

func (*Header) Bytes

func (h *Header) Bytes() ([]byte, error)

Bytes encodes the header to msgpack

func (*Header) Decrypt

func (h *Header) Decrypt(cp cki.CertPool, priv cki.PrivateKey, d []byte, sending bool) ([]byte, error)

Decrypt deciphers the given data using the private key of the intended certificate. sending is available if the sender wants to decypher their own message

func (*Header) Encrypt

func (h *Header) Encrypt(cp cki.CertPool, pk cki.PrivateKey, d []byte) ([]byte, error)

Encrypt creates cipher text based on the signing private key and plain text

type HeaderOption

type HeaderOption func(*Header) error

HeaderOption header creation option

func WithEmbeddedCerts

func WithEmbeddedCerts(c ...*cki.Certificate) HeaderOption

WithEmbeddedCerts specifies which certificates to include in the header certificates are parsed to ensure validity

func WithEncryptionAlgo

func WithEncryptionAlgo(a Algorithm) HeaderOption

WithEncryptionAlgo specifies which encryption (AEAD) algorithm to use

func WithEphemeral

func WithEphemeral(a cki.Algorithm) (cki.PrivateKey, HeaderOption, error)

WithEphemeral creates a new ephemeral key pair based off the given algorithm

Jump to

Keyboard shortcuts

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