chacha

package
v0.0.0-...-34d48bb Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2016 License: LGPL-3.0 Imports: 2 Imported by: 3

Documentation

Overview

Package chacha implements some low level functions of the ChaCha cipher family.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Core

func Core(dst *[64]byte, state *[64]byte, rounds int)

Core generates 64 byte keystream from the given state performing 'rounds' rounds and writes them to dst. This function expects valid values. (no nil ptr etc.) Core increments the counter of state.

func XORBlocks

func XORBlocks(dst, src []byte, state *[64]byte, rounds int)

XORBlocks crypts full block ( len(src) - (len(src) mod 64) bytes ) from src to dst using the state. Src and dst may be the same slice but otherwise should not overlap. This function increments the counter of state. If len(src) > len(dst), XORBlocks does nothing.

func XORKeyStream

func XORKeyStream(dst, src []byte, nonce *[12]byte, key *[32]byte, counter uint32, rounds int)

XORKeyStream crypts bytes from src to dst using the given key, nonce and counter. The rounds argument specifies the number of rounds (must be even) performed for keystream generation. (Common values are 20, 12 or 8) Src and dst may be the same slice but otherwise should not overlap. If len(dst) < len(src) this function panics.

Types

type Cipher

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

Cipher is the ChaCha/X struct. X is the number of rounds (e.g. ChaCha20 for 20 rounds)

func NewCipher

func NewCipher(nonce *[12]byte, key *[32]byte, rounds int) *Cipher

NewCipher returns a new *chacha.Cipher implementing the ChaCha/X (X = even number of rounds) stream cipher. The nonce must be unique for one key for all time.

func (*Cipher) SetCounter

func (c *Cipher) SetCounter(ctr uint32)

Sets the counter of the cipher. Notice that this function skips the unused keystream of the current 64 byte block.

func (*Cipher) XORKeyStream

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

XORKeyStream crypts bytes from src to dst. Src and dst may be the same slice but otherwise should not overlap. If len(dst) < len(src) the function panics.

Jump to

Keyboard shortcuts

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