block

package
v0.0.0-...-90c9d3a Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2010 License: BSD-3-Clause, GooglePatentClause Imports: 5 Imported by: 0

Documentation

Overview

The block package implements standard block cipher modes that can be wrapped around low-level block cipher implementations. See http://csrc.nist.gov/groups/ST/toolkit/BCM/current_modes.html and NIST Special Publication 800-38A.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewCBCDecrypter

func NewCBCDecrypter(c Cipher, iv []byte, r io.Reader) io.Reader

NewCBCDecrypter returns a reader that reads data from r and decrypts it using c in cipher block chaining (CBC) mode with the initialization vector iv. The returned Reader does not buffer or read ahead except as required by the cipher's block size.

func NewCBCEncrypter

func NewCBCEncrypter(c Cipher, iv []byte, w io.Writer) io.Writer

NewCBCEncrypter returns a writer that encrypts data using c in cipher block chaining (CBC) mode with the initialization vector iv and writes the encrypted data to w. The returned Writer does no buffering except as required by the cipher's block size, so there is no need for a Flush method.

func NewCFBDecrypter

func NewCFBDecrypter(c Cipher, s int, iv []byte, r io.Reader) io.Reader

NewCFBDecrypter returns a reader that reads data from r and decrypts it using c in s-bit cipher feedback (CFB) mode with the initialization vector iv. The returned Reader does not buffer or read ahead except as required by the cipher's block size. Modes for s not a multiple of 8 are unimplemented.

func NewCFBEncrypter

func NewCFBEncrypter(c Cipher, s int, iv []byte, w io.Writer) io.Writer

NewCFBEncrypter returns a writer that encrypts data using c in s-bit cipher feedback (CFB) mode with the initialization vector iv and writes the encrypted data to w. The returned Writer does no buffering except as required by the cipher's block size, so there is no need for a Flush method. Modes for s not a multiple of 8 are unimplemented.

func NewCMAC

func NewCMAC(c Cipher) hash.Hash

NewCMAC returns a new instance of a CMAC message authentication code digest using the given Cipher.

func NewCTRReader

func NewCTRReader(c Cipher, iv []byte, r io.Reader) io.Reader

NewCTRReader returns a reader that reads data from r, decrypts (or encrypts) it using c in counter (CTR) mode with the initialization vector iv. The returned Reader does not buffer and has no block size. In CTR mode, encryption and decryption are the same operation: a CTR reader applied to an encrypted stream produces a decrypted stream and vice versa.

func NewCTRWriter

func NewCTRWriter(c Cipher, iv []byte, w io.Writer) io.Writer

NewCTRWriter returns a writer that encrypts (or decrypts) data using c in counter (CTR) mode with the initialization vector iv and writes the encrypted data to w. The returned Writer does not buffer and has no block size. In CTR mode, encryption and decryption are the same operation: a CTR writer applied to an decrypted stream produces an encrypted stream and vice versa.

func NewEAXDecrypter

func NewEAXDecrypter(c Cipher, iv []byte, hdr []byte, tagBytes int, r io.Reader) io.Reader

NewEAXDecrypter creates and returns a new EAX decrypter using the given cipher c, initialization vector iv, associated data hdr, and tag length tagBytes. The encrypter's Read method decrypts and returns data read from r. At r's EOF, the encrypter checks the final authenticating tag and returns an EAXTagError if the tag is invalid. In that case, the message should be discarded. Note that the data stream returned from Read cannot be assumed to be valid, authenticated data until Read returns 0, nil to signal the end of the data.

func NewEAXEncrypter

func NewEAXEncrypter(c Cipher, iv []byte, hdr []byte, tagBytes int, w io.Writer) io.WriteCloser

NewEAXEncrypter creates and returns a new EAX encrypter using the given cipher c, initialization vector iv, associated data hdr, and tag length tagBytes. The encrypter's Write method encrypts the data it receives and writes that data to w. The encrypter's Close method writes a final authenticating tag to w.

func NewECBDecrypter

func NewECBDecrypter(c Cipher, r io.Reader) io.Reader

NewECBDecrypter returns a reader that reads data from r and decrypts it using c. It decrypts by calling c.Decrypt on each block in sequence; this mode is known as electronic codebook mode, or ECB. The returned Reader does not buffer or read ahead except as required by the cipher's block size.

func NewECBEncrypter

func NewECBEncrypter(c Cipher, w io.Writer) io.Writer

NewECBEncrypter returns a writer that encrypts data using c and writes it to w. It encrypts by calling c.Encrypt on each block in sequence; this mode is known as electronic codebook mode, or ECB. The returned Writer does no buffering except as required by the cipher's block size, so there is no need for a Flush method.

func NewOFBReader

func NewOFBReader(c Cipher, iv []byte, r io.Reader) io.Reader

NewOFBReader returns a reader that reads data from r, decrypts (or encrypts) it using c in output feedback (OFB) mode with the initialization vector iv. The returned Reader does not buffer and has no block size. In OFB mode, encryption and decryption are the same operation: an OFB reader applied to an encrypted stream produces a decrypted stream and vice versa.

func NewOFBWriter

func NewOFBWriter(c Cipher, iv []byte, w io.Writer) io.Writer

NewOFBWriter returns a writer that encrypts (or decrypts) data using c in cipher feedback (OFB) mode with the initialization vector iv and writes the encrypted data to w. The returned Writer does not buffer and has no block size. In OFB mode, encryption and decryption are the same operation: an OFB writer applied to an decrypted stream produces an encrypted stream and vice versa.

Types

type Cipher

type Cipher interface {
	// BlockSize returns the cipher's block size.
	BlockSize() int

	// Encrypt encrypts the first block in src into dst.
	// Src and dst may point at the same memory.
	Encrypt(src, dst []byte)

	// Decrypt decrypts the first block in src into dst.
	// Src and dst may point at the same memory.
	Decrypt(src, dst []byte)
}

A Cipher represents an implementation of block cipher using a given key. It provides the capability to encrypt or decrypt individual blocks. The mode implementations extend that capability to streams of blocks.

type EAXTagError

type EAXTagError struct {
	Read     []byte
	Computed []byte
}

An EAXTagError is returned when the message has failed to authenticate, because the tag at the end of the message stream (Read) does not match the tag computed from the message itself (Computed).

func (*EAXTagError) String

func (e *EAXTagError) String() string

Jump to

Keyboard shortcuts

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