Documentation ¶
Index ¶
Constants ¶
const MaxAssociatedDataItems = 126
MaxAssociatedDataItems is the maximum number of associated data items
Variables ¶
var ( // ErrKeySize indicates the given key size is not supported ErrKeySize = errors.New("siv: bad key size") // ErrNotAuthentic indicates a ciphertext is malformed or corrupt ErrNotAuthentic = errors.New("siv: authentication failed") // ErrTooManyAssociatedDataItems indicates more than MaxAssociatedDataItems were given ErrTooManyAssociatedDataItems = errors.New("siv: too many associated data items") )
Functions ¶
func GenerateKey ¶ added in v0.2.0
GenerateKey generates a random 32-byte or 64-byte encryption key. Panics if the key size is unsupported or source of randomness fails.
func GenerateNonce ¶ added in v0.2.0
GenerateNonce generates a random nonce for the given `cipher.AEAD`. Panics if the configured nonce size is less than 16-bytes (128-bits)
func NewAEAD ¶ added in v0.2.0
NewAEAD returns an AES-SIV instance implementing cipher.AEAD interface, with the given cipher, nonce size, and a key which must be twice as long as an AES key, either 32 or 64 bytes to select AES-128 (AES-SIV-256) or AES-256 (AES-SIV-512).
Unless the given nonce size is less than zero, Seal and Open will panic when passed nonce of a different size.
Types ¶
type Cipher ¶
type Cipher struct {
// contains filtered or unexported fields
}
Cipher is an instance of AES-SIV, configured with either AES-CMAC or AES-PMAC as a message authentication code.
func NewAESCMACSIV ¶ added in v0.2.0
NewAESCMACSIV returns a new AES-SIV cipher with the given key, which must be twice as long as an AES key, either 32 or 64 bytes to select AES-128 (AES-CMAC-SIV-256), or AES-256 (AES-CMAC-SIV-512).
func NewAESPMACSIV ¶ added in v0.2.0
NewAESPMACSIV returns a new AES-SIV cipher with the given key, which must be twice as long as an AES key, either 32 or 64 bytes to select AES-128 (AES-PMAC-SIV-256), or AES-256 (AES-PMAC-SIV-512).
func (*Cipher) Open ¶
Open decrypts ciphertext, authenticates the decrypted plaintext and the given associated data items and, if successful, appends the resulting plaintext to dst, returning the updated slice. The additional data items must match the items passed to Seal.
The ciphertext and dst may alias exactly or not at all.
For nonce-based encryption, the nonce should be the last associated data item.
func (*Cipher) Seal ¶
Seal encrypts and authenticates plaintext, authenticates the given associated data items, and appends the result to dst, returning the updated slice.
The ciphertext and dst may alias exactly or not at all.
For nonce-based encryption, the nonce should be the last associated data item.
type StreamDecryptor ¶ added in v0.3.0
type StreamDecryptor struct {
// contains filtered or unexported fields
}
StreamDecryptor decrypts message streams, selecting the nonces using a 32-bit counter, generalized for any cipher.AEAD algorithm
This construction corresponds to the ℰ stream encryptor object as defined in the paper Online Authenticated-Encryption and its Nonce-Reuse Misuse-Resistance
func NewStreamDecryptor ¶ added in v0.3.0
func NewStreamDecryptor(alg string, key, nonce []byte) (*StreamDecryptor, error)
NewStreamDecryptor returns a STREAM encryptor instance with the given cipher, nonce, and a key which must be twice as long as an AES key, either 32 or 64 bytes to select AES-128 (AES-SIV-256) or AES-256 (AES-SIV-512).
func (*StreamDecryptor) NonceSize ¶ added in v0.3.0
func (d *StreamDecryptor) NonceSize() int
NonceSize returns the size of the nonce that must be passed to NewStreamDecryptor
func (*StreamDecryptor) Open ¶ added in v0.3.0
func (d *StreamDecryptor) Open(dst, ciphertext, aData []byte, lastBlock bool) ([]byte, error)
Open decrypts and authenticates the next ciphertext in the STREAM, and also authenticates the additional data, ensuring it matches the value passed to Seal.
If successful, it appends the resulting plaintext to dst and returns the updated slice.
The ciphertext and dst may alias exactly or not at all. To reuse ciphertext's storage for the decrypted output, use ciphertext[:0] as dst.
Even if the function fails, the contents of dst, up to its capacity, may be overwritten.
func (*StreamDecryptor) Overhead ¶ added in v0.3.0
func (d *StreamDecryptor) Overhead() int
Overhead returns the maximum difference between the lengths of a plaintext and its ciphertext, which in the case of AES-SIV modes is the size of the initialization vector
type StreamEncryptor ¶ added in v0.3.0
type StreamEncryptor struct {
// contains filtered or unexported fields
}
StreamEncryptor encrypts message streams, selecting the nonces using a 32-bit counter, generalized for any cipher.AEAD algorithm
This construction corresponds to the ℰ stream encryptor object as defined in the paper Online Authenticated-Encryption and its Nonce-Reuse Misuse-Resistance
func NewStreamEncryptor ¶ added in v0.3.0
func NewStreamEncryptor(alg string, key, nonce []byte) (*StreamEncryptor, error)
NewStreamEncryptor returns a STREAM encryptor instance with the given cipher, nonce, and a key which must be twice as long as an AES key, either 32 or 64 bytes to select AES-128 (AES-SIV-256) or AES-256 (AES-SIV-512).
func (*StreamEncryptor) NonceSize ¶ added in v0.3.0
func (e *StreamEncryptor) NonceSize() int
NonceSize returns the size of the nonce that must be passed to NewStreamEncryptor
func (*StreamEncryptor) Overhead ¶ added in v0.3.0
func (e *StreamEncryptor) Overhead() int
Overhead returns the maximum difference between the lengths of a plaintext and its ciphertext, which in the case of AES-SIV modes is the size of the initialization vector
func (*StreamEncryptor) Seal ¶ added in v0.3.0
func (e *StreamEncryptor) Seal(dst, plaintext, aData []byte, lastBlock bool) []byte
Seal the next message in the STREAM, which encrypts and authenticates plaintext, authenticates the additional data and appends the result to dst, returning the updated slice.
The plaintext and dst may alias exactly or not at all. To reuse plaintext's storage for the encrypted output, use plaintext[:0] as dst.
The lastBlock argument should be set to true if this is the last message in the STREAM. No further messages can be encrypted after the last one