mailchain: github.com/mailchain/mailchain/crypto/cipher Index | Files | Directories

package cipher

import "github.com/mailchain/mailchain/crypto/cipher"

Package cipher collects common cryptographic constants and interfaces.

Index

Package Files

cipher.go errors.go keyexchange.go

Constants

const (
    // NoOperation identified for Encrypt and Decrypter in noop package.
    NoOperation byte = 0x20

    // NACLECDH identified for Encrypt and Decrypter in nacl package using ECDH
    // for key exchange and share secret generation.
    NACLECDH byte = 0x2a

    // AES256CBC identified for Encrypt and Decrypter in aes256cbc package.
    AES256CBC byte = 0x2e
)

Variables

var (
    // ErrEncrypt returns the error message if encryption failed
    //
    ErrEncrypt = errors.New("cipher: encryption failed") //nolint:gochecknoglobals
    // ErrDecrypt returns the error message if decryption failed
    //
    ErrDecrypt = errors.New("cipher: decryption failed") //nolint:gochecknoglobals
)

type Decrypter Uses

type Decrypter interface {
    Decrypt(EncryptedContent) (PlainContent, error)
}

A Decrypter uses the PrivateKey to decrypt the supplied data.

The decryption method used is dependant on the implementation and must check that the data can be decrypted before continuing. Returned data should be the plain bytes that were supplied originally to the Encrypter.

type EncryptedContent Uses

type EncryptedContent []byte

EncryptedContent typed version of byte array that holds encrypted data.

Encrypt method returns the encrypted contents as EncryptedContent. Decrypt method accepts EncryptedContent as the encrypted contents to decrypt.

type Encrypter Uses

type Encrypter interface {
    Encrypt(PlainContent) (EncryptedContent, error)
}

An Encrypter uses the PublicKey to encrypt the supplied data.

The encryption method used is dependant on the implementation and must be included in the response. Returned encrypted data must include what encryption method was used as the first byte. The data can be decrypted using the corresponding PrivateKey and Decrypter method.

type KeyExchange Uses

type KeyExchange interface {
    // EphemeralKey generates a private/public key pair.
    EphemeralKey() (private crypto.PrivateKey, err error)

    // SharedSecret computes a secret value from a private / public key pair.
    // On sending a message the private key should be an ephemeralKey or generated private key,
    // the public key is the recipient public key.
    // On reading a message the private key is the recipient private key, the public key is the
    // ephemeralKey or generated public key.
    SharedSecret(privateKey crypto.PrivateKey, publicKey crypto.PublicKey) ([]byte, error)
}

KeyExchange agrees on a symmetric keys by performing a key exchange using asymmetric keys.

type PlainContent Uses

type PlainContent []byte

PlainContent typed version of byte array that holds plain data.

Encrypt method returns the encrypted contents as EncryptedContent. Decrypt method accepts EncryptedContent as the encrypted contents to decrypt.

Directories

PathSynopsis
aes256cbcPackage aes256cbc implements Advanced Encryption Standard with a 256 bit key length, using Chain Block Cipher mode (AES-256-CBC).
ciphertestPackage ciphertest is a generated GoMock package.
ecdhPackage ecdh has implementations for different asymmetric key exchange.
encrypter
nacl
noopPackage noop is a no operation encryption algorithm for use when the message is intended to be publically readable.

Package cipher imports 2 packages (graph) and is imported by 10 packages. Updated 2020-02-17. Refresh now. Tools for package owners.