crypto

package
v0.0.32 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: AGPL-3.0, AGPL-3.0 Imports: 11 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 = 32

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

	// 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
)

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     nike.PrivateKey
}

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

func KDF

func KDF(ikm []byte, scheme nike.Scheme) *PacketKeys

KDF takes the input key material and returns the Sphinx Packet keys. HOWEVER if the NIKE scheme interface object is set to nil then the BlindingFactor will not be generated by the KDF. The reason we do this is because KEMSphinx doesn't need the BlindingFactor.

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