Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
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.
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.
var ZeroPadding = PaddingFunc(func(dst []byte) {
fill(dst, 0)
})
ZeroPadding fills an incomplete block with zeroes.
Functions ¶
func NewBlockReader ¶
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.
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.