cipherio

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 26, 2020 License: MIT Imports: 3 Imported by: 3

README

cipherio

go.dev reference Go Report Card GitHub release License

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BitPadding = PaddingFunc(func(dst []byte) {
	dst[0] = 0x80
	fill(dst[1:], 0)
})

BitPadding fills an incomplete block with 0x80 followed by zeroes.

This is defined by ISO/IEC 9797-1 as Padding Method 2 and is also known as ISO padding.

View Source
var PKCS7Padding = PaddingFunc(func(dst []byte) {
	n := len(dst)
	if n > 255 {
		panic(fmt.Errorf("cipherio: PKCS#7 padding cannot fill more than 255 bytes: %d > 255", n))
	}
	fill(dst, byte(n))
})

PKCS7Padding fills an incomplete block by repeating the total number of padding bytes.

PKCS#7 is described by RFC 5652.

WARNING: this padding method MUST NOT be used with a block size larger than 256 bytes.

View Source
var ZeroPadding = PaddingFunc(func(dst []byte) {
	fill(dst, 0)
})

ZeroPadding fills an incomplete block with zeroes.

Functions

func NewBlockReader

func NewBlockReader(src io.Reader, blockMode cipher.BlockMode) io.Reader

NewBlockReader wraps the given Reader to add on-the-fly encryption or decryption using the given BlockMode.

The input must be aligned to the cipher block size: ErrUnexpectedEOF is returned if EOF is reached in the middle of a block.

This Reader avoids buffering and copies as much as possible. A call to Read leads to at most one Read from the wrapped Reader. Unless the destination buffer is smaller than BlockSize, (en|de)cryption happens inplace within it.

There is no dynamic allocation: an internal buffer of BlockSize bytes is used to store both incomplete blocks (not yet (en|de)crypted) and partially read blocks (already (en|de)crypted).

The wrapped Reader is guaranteed to never be consumed beyond the last requested block. This means that it is safe to stop reading from this Reader at a block boundary and then resume reading from the wrapped Reader for another purpose.

func NewBlockReaderWithPadding

func NewBlockReaderWithPadding(src io.Reader, blockMode cipher.BlockMode, padding Padding) io.Reader

NewBlockReaderWithPadding is similar to NewBlockReader, except that any incomplete block is filled with the given padding instead of returning ErrUnexpectedEOF.

Types

type Padding

type Padding interface {
	Fill(dst []byte)
}

Padding defines how to fill an incomplete block.

type PaddingFunc

type PaddingFunc func(dst []byte)

PaddingFunc allows to implement the Padding interface with a padding function.

func (PaddingFunc) Fill

func (p PaddingFunc) Fill(dst []byte)

Fill an incomplete block.

Directories

Path Synopsis
Package iomock is a generated GoMock package.
Package iomock is a generated GoMock package.

Jump to

Keyboard shortcuts

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