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 ¶
- func NewCBCDecrypter(c Cipher, iv []byte, r io.Reader) io.Reader
- func NewCBCEncrypter(c Cipher, iv []byte, w io.Writer) io.Writer
- func NewCFBDecrypter(c Cipher, s int, iv []byte, r io.Reader) io.Reader
- func NewCFBEncrypter(c Cipher, s int, iv []byte, w io.Writer) io.Writer
- func NewCMAC(c Cipher) hash.Hash
- func NewCTRReader(c Cipher, iv []byte, r io.Reader) io.Reader
- func NewCTRWriter(c Cipher, iv []byte, w io.Writer) io.Writer
- func NewEAXDecrypter(c Cipher, iv []byte, hdr []byte, tagBytes int, r io.Reader) io.Reader
- func NewEAXEncrypter(c Cipher, iv []byte, hdr []byte, tagBytes int, w io.Writer) io.WriteCloser
- func NewECBDecrypter(c Cipher, r io.Reader) io.Reader
- func NewECBEncrypter(c Cipher, w io.Writer) io.Writer
- func NewOFBReader(c Cipher, iv []byte, r io.Reader) io.Reader
- func NewOFBWriter(c Cipher, iv []byte, w io.Writer) io.Writer
- type Cipher
- type EAXTagError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewCBCDecrypter ¶
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 ¶
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 ¶
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 ¶
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 ¶
NewCMAC returns a new instance of a CMAC message authentication code digest using the given Cipher.
func NewCTRReader ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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