chacha20

package
v2.0.10+incompatible Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2020 License: GPL-3.0, BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package ChaCha20 implements the core ChaCha20 function as specified in https://tools.ietf.org/html/rfc7539#section-2.3.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HChaCha20

func HChaCha20(key *[8]uint32, nonce *[4]uint32) [8]uint32

HChaCha20 uses the ChaCha20 core to generate a derived key from a key and a nonce. It should only be used as part of the XChaCha20 construction.

func XORKeyStream

func XORKeyStream(out, in []byte, counter *[16]byte, key *[32]byte)

XORKeyStream crypts bytes from in to out using the given key and counters. In and out must overlap entirely or not at all. Counter contains the raw ChaCha20 counter bytes (i.e. block counter followed by nonce).

Types

type Cipher

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

Cipher is a stateful instance of ChaCha20 using a particular key and nonce. A *Cipher implements the cipher.Stream interface.

func New

func New(key [8]uint32, nonce [3]uint32) *Cipher

New creates a new ChaCha20 stream cipher with the given key and nonce. The initial counter value is set to 0.

func (*Cipher) Advance

func (s *Cipher) Advance()

Advance discards bytes in the key stream until the next 64 byte block boundary is reached and updates the counter accordingly. If the key stream is already at a block boundary no bytes will be discarded and the counter will be unchanged.

func (*Cipher) XORKeyStream

func (s *Cipher) XORKeyStream(dst, src []byte)

XORKeyStream XORs each byte in the given slice with a byte from the cipher's key stream. Dst and src must overlap entirely or not at all.

If len(dst) < len(src), XORKeyStream will panic. It is acceptable to pass a dst bigger than src, and in that case, XORKeyStream will only update dst[:len(src)] and will not touch the rest of dst.

Multiple calls to XORKeyStream behave as if the concatenation of the src buffers was passed in a single run. That is, Cipher maintains state and does not reset at each XORKeyStream call.

Jump to

Keyboard shortcuts

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