crypto

package
v0.0.16 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2023 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package crypto provides the Katzenpost parameterization of the Sphinx Packet Format cryptographic operations.

Index

Constants

View Source
const (
	// HashLength is the output size of the unkeyed hash in bytes.
	HashLength = sha512.Size256

	// MACKeyLength is the key size of the MAC in bytes.
	MACKeyLength = 32

	// MACLength is the tag size of the MAC in bytes.
	MACLength = 16

	// StreamKeyLength is the key size of the stream cipher in bytes.
	StreamKeyLength = 16

	// StreamIVLength is the IV size of the stream cipher in bytes.
	StreamIVLength = 16

	// SPRPKeyLength is the key size of the SPRP in bytes.
	SPRPKeyLength = 48

	// SPRPIVLength is the IV size of the SPRP in bytes.
	SPRPIVLength = StreamIVLength

	// GroupElementLength is the length of a DH group element in bytes.
	GroupElementLength = ecdh.GroupElementLength
)

Variables

This section is empty.

Functions

func Hash

func Hash(msg []byte) [HashLength]byte

Hash calculates the digest of message m.

func NewMAC

func NewMAC(key *[MACKeyLength]byte) hash.Hash

NewMAC returns a new hash.Hash implementing the Sphinx MAC with the provided key.

func SPRPDecrypt

func SPRPDecrypt(key *[SPRPKeyLength]byte, iv *[SPRPIVLength]byte, msg []byte) []byte

SPRPDecrypt returns the plaintext of the message msg, decrypted via the Sphinx SPRP with the provided key and IV.

func SPRPEncrypt

func SPRPEncrypt(key *[SPRPKeyLength]byte, iv *[SPRPIVLength]byte, msg []byte) []byte

SPRPEncrypt returns the ciphertext of the message msg, encrypted via the Sphinx SPRP with the provided key and IV.

Types

type PacketKeys

type PacketKeys struct {
	HeaderMAC          [MACKeyLength]byte
	HeaderEncryption   [StreamKeyLength]byte
	HeaderEncryptionIV [StreamIVLength]byte
	PayloadEncryption  [SPRPKeyLength]byte
	BlindingFactor     [GroupElementLength]byte
}

PacketKeys are the per-hop Sphinx Packet Keys, derived from the blinded DH key exchange.

func KDF

KDF takes the input key material and returns the Sphinx Packet keys.

func (*PacketKeys) Reset

func (k *PacketKeys) Reset()

Reset clears the PacketKeys structure such that no sensitive data is left in memory.

type Stream

type Stream struct {
	cipher.Stream
}

Stream is the Sphinx stream cipher.

func NewStream

func NewStream(key *[StreamKeyLength]byte, iv *[StreamIVLength]byte) *Stream

NewStream returns a new Stream implementing the Sphinx Stream Cipher with the provided key and IV.

func (*Stream) KeyStream

func (s *Stream) KeyStream(dst []byte)

KeyStream fills the buffer dst with key stream output.

func (*Stream) Reset

func (s *Stream) Reset()

Reset clears the Stream instance such that no sensitive data is left in memory.

Jump to

Keyboard shortcuts

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