cipher

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2020 License: BSD-3-Clause Imports: 12 Imported by: 14

Documentation

Overview

Package cipher defines all ciphers used in Mute.

Index

Constants

This section is empty.

Variables

View Source
var RandFail = eofReader{}

RandFail is a Reader that doesn't deliver any data

View Source
var RandReader = rand.Reader

RandReader defines the CSPRNG used in Mute.

View Source
var RandZero = zeroReader{}

RandZero is a Reader that always returns 0.

Functions

func CKDF

func CKDF(nonce []byte) (k1, k2 []byte)

CKDF (Cheap Key Derivation Function) generates two keys k1 and k2 from the given nonce. Specification: https://github.com/mutecomm/mute/blob/master/doc/ciphers.md#ckdf-cheap-key-derivation-function

func ECDH

func ECDH(privateKey, peersPublicKey, ownPublicKey *[32]byte) (*[32]byte, error)

ECDH computes a Diffie-Hellman (DH) key exchange over the elliptic curve (EC) curve25519. If ownPublicKey is given it is used to check for the key reflection attack. Otherwise it is derived from privateKey.

func HMAC

func HMAC(key, buffer []byte) []byte

HMAC computes the keyed-hash message authentication code of buffer with the given key.

func Nonce

func Nonce(rand io.Reader) []byte

Nonce generates a random nonce.

func RandPass

func RandPass(rand io.Reader) string

RandPass returns a random 256-bit password in base64 encoding.

func SHA1

func SHA1(buffer []byte) []byte

SHA1 computes the SHA1 hash of the given buffer. In Mute SHA1 is only used for tokens.

func SHA256

func SHA256(buffer []byte) []byte

SHA256 computes the SHA256 hash of the given buffer. In Mute SHA256 is only used for hash chain operations.

func SHA512

func SHA512(buffer []byte) []byte

SHA512 computes the SHA512 hash of the given buffer. In Mute SHA512 is used for everything except tokens and hash chain operations. For example, key material is hashed with SHA512 and message authentication uses SHA512.

Types

type Curve25519Key

type Curve25519Key struct {
	// contains filtered or unexported fields
}

Curve25519Key holds a Curve25519 key pair.

func Curve25519Generate

func Curve25519Generate(rand io.Reader) (*Curve25519Key, error)

Curve25519Generate generates a new Curve25519 key pair.

func (*Curve25519Key) PrivateKey

func (c *Curve25519Key) PrivateKey() *[32]byte

PrivateKey returns the private key of an curve25519Key.

func (*Curve25519Key) PublicKey

func (c *Curve25519Key) PublicKey() *[32]byte

PublicKey returns the public key of an curve25519Key.

func (*Curve25519Key) SetPrivateKey

func (c *Curve25519Key) SetPrivateKey(key []byte) error

SetPrivateKey sets the private key of curve25519Key to key. SetPrivateKey returns an error, if len(key) != 32.

func (*Curve25519Key) SetPublicKey

func (c *Curve25519Key) SetPublicKey(key []byte) error

SetPublicKey sets the public key of curve25519Key to key. SetPublicKey returns an error, if len(key) != 32.

type Ed25519Key

type Ed25519Key struct {
	// contains filtered or unexported fields
}

Ed25519Key holds a Ed25519 key pair.

func Ed25519Generate

func Ed25519Generate(rand io.Reader) (*Ed25519Key, error)

Ed25519Generate generates a new Ed25519 key pair.

func (*Ed25519Key) PrivateKey

func (ed25519Key *Ed25519Key) PrivateKey() *[64]byte

PrivateKey returns the private key of an ed25519Key.

func (*Ed25519Key) PublicKey

func (ed25519Key *Ed25519Key) PublicKey() *[32]byte

PublicKey returns the public key of an ed25519Key.

func (*Ed25519Key) SetPrivateKey

func (ed25519Key *Ed25519Key) SetPrivateKey(key []byte) error

SetPrivateKey sets the private key of ed25519Key to key. SetPrivateKey returns an error, if len(key) != ed25519.PrivateKeySize.

func (*Ed25519Key) SetPublicKey

func (ed25519Key *Ed25519Key) SetPublicKey(key []byte) error

SetPublicKey sets the public key of ed25519Key to key. SetPublicKey returns an error, if len(key) != ed25519.PublicKeySize.

func (*Ed25519Key) Sign

func (ed25519Key *Ed25519Key) Sign(message []byte) []byte

Sign signs the given message with ed25519Key and returns the signature.

func (*Ed25519Key) Verify

func (ed25519Key *Ed25519Key) Verify(message []byte, sig []byte) bool

Verify verifies that the signature sig for message is valid for ed25519Key.

type NaClBoxKey

type NaClBoxKey struct {
	// contains filtered or unexported fields
}

NaClBoxKey holds the public and private keys for a NaCl-box.

func NaClBoxGenerate

func NaClBoxGenerate(rand io.Reader) (*NaClBoxKey, error)

NaClBoxGenerate generates a new NaClBox key pair.

func (*NaClBoxKey) PrivateKey

func (naClBoxKey *NaClBoxKey) PrivateKey() []byte

PrivateKey returns the private key of a NaClBox.

func (*NaClBoxKey) PublicKey

func (naClBoxKey *NaClBoxKey) PublicKey() []byte

PublicKey returns the public key of a NaClBox.

func (*NaClBoxKey) SetPrivateKey

func (naClBoxKey *NaClBoxKey) SetPrivateKey(key []byte) error

SetPrivateKey sets the private key of naclbox to key. SetPrivateKey returns an error, if len(key) != 32.

func (*NaClBoxKey) SetPublicKey

func (naClBoxKey *NaClBoxKey) SetPublicKey(key []byte) error

SetPublicKey sets the public key of naclbox to key. SetPublicKey returns an error, if len(key) != 32.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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