cipher

package
v0.0.0-...-ad5b1a2 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2024 License: GPL-3.0 Imports: 2 Imported by: 0

Documentation

Overview

Package cipher provides a common interface for symmetric ciphers. This includes both block ciphers and (in the future) stream ciphers. Block cipher modes such as CBC and GCM can be implemented in a cipher-independent way.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Block

type Block interface {
	// BlockSize returns the configured algorithms block size
	BlockSize() int

	// Encrypt encrypts the first block of src and returns it
	Encrypt(dst, src []byte)

	// Decrypt decrypts the first block of src and returns it
	Decrypt(dst, src []byte)
}

Block represents a block cipher implementation (with preconfigured key).

It should never be used directly. You should always use a block cipher mode, which in turn uses this block cipher under the hood.

type BlockMode

type BlockMode interface {
	// BlockSize returns the configured algorithms block size
	BlockSize() int

	// CryptBlocks encrypts or decrypts a number of blocks.
	CryptBlocks(dst, src []byte)
}

BlockMode represents a block cipher running in a specific configured mode (CBC, ECB, etc.). It either encrypts or decrypts data.

func NewCBCDecrypter

func NewCBCDecrypter(b Block, iv []byte) BlockMode

NewCBCDecrypter returns a BlockMode which decrypts in cipher block chaining mode, using the given Block. The length of iv must be the same as the Block's block size and must match the iv used to encrypt the data.

func NewCBCEncrypter

func NewCBCEncrypter(b Block, iv []byte) BlockMode

NewCBCDecrypter returns a BlockMode which decrypts in cipher block chaining mode, using the given Block. The length of iv must be the same as the Block's block size and must match the iv used to encrypt the data.

type Stream

type Stream interface {
	// XORKeyStream XORs each byte in src with a byte from the key stream.
	// Because Stream maintains state, multiple calls to XORKeyStream should
	// behave just as if it was called with a single, concatenated array
	XORKeyStream(dst, src []byte)
}

Stream represents a stream cipher.

func NewCTR

func NewCTR(b Block, iv []byte) Stream

Jump to

Keyboard shortcuts

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