Documentation
¶
Overview ¶
Example ¶
if !common.Available {
return
}
key := make([]byte, KeySize)
rand.Read(key)
aead, err := New(key, 16)
if err != nil {
panic(err)
}
nonce := make([]byte, aead.NonceSize())
rand.Read(nonce)
ciphertext := aead.Seal(nil, nonce, []byte("hello, world!"), nil)
plaintext, err := aead.Open(nil, nonce, ciphertext, nil)
if err != nil {
panic(err)
}
fmt.Println(string(plaintext))
Output: hello, world!
Index ¶
Examples ¶
Constants ¶
const ( KeySize = 16 NonceSize = 16 )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Aegis128X4 ¶
func (*Aegis128X4) Open ¶
func (aead *Aegis128X4) Open(plaintext, nonce, ciphertext, additionalData []byte) ([]byte, error)
func (*Aegis128X4) Seal ¶
func (aead *Aegis128X4) Seal(dst, nonce, cleartext, additionalData []byte) []byte
type Decrypter ¶ added in v0.2.13
type Decrypter struct {
// contains filtered or unexported fields
}
Decrypter provides incremental authenticated decryption using AEGIS-128X4. Create one using NewDecrypter, call Decrypt or DecryptTo for each chunk of ciphertext, then call Final to verify the authentication tag.
IMPORTANT: The decrypted plaintext MUST NOT be used or revealed until Final returns nil. If Final returns an error, all decrypted data must be discarded as it may have been tampered with.
func NewDecrypter ¶ added in v0.2.13
NewDecrypter creates a new incremental decrypter. The key must be KeySize (16) bytes. The nonce must be at most NonceSize (16) bytes; shorter nonces are padded with zeros. The additionalData must match what was used during encryption. The tagLen must match what was used during encryption (16 or 32).
func (*Decrypter) Decrypt ¶ added in v0.2.13
Decrypt decrypts ciphertext and returns plaintext of the same length. Can be called multiple times for streaming decryption.
WARNING: The returned plaintext MUST NOT be used until Final returns nil. If Final returns an error, all decrypted data must be discarded.
Panics if called after Final.
func (*Decrypter) DecryptTo ¶ added in v0.2.13
DecryptTo decrypts ciphertext and writes plaintext to dst. The dst slice must have capacity for at least len(ciphertext) bytes. Returns the plaintext slice (a subslice of dst). If dst is nil or has insufficient capacity, a new slice is allocated.
WARNING: The plaintext MUST NOT be used until Final returns nil. If Final returns an error, all decrypted data must be discarded.
Panics if called after Final.
func (*Decrypter) Final ¶ added in v0.2.13
Final verifies the authentication tag. The tag must be tagLen bytes (as specified when creating the Decrypter). Returns nil if the tag is valid, or ErrAuth if verification fails.
If this returns an error, all previously decrypted data MUST be discarded as it may have been tampered with.
The Decrypter must not be used after calling Final.
type Encrypter ¶ added in v0.2.13
type Encrypter struct {
// contains filtered or unexported fields
}
Encrypter provides incremental authenticated encryption using AEGIS-128X4. Create one using NewEncrypter, call Encrypt or EncryptTo for each chunk of plaintext, then call Final to get the authentication tag.
func NewEncrypter ¶ added in v0.2.13
NewEncrypter creates a new incremental encrypter. The key must be KeySize (16) bytes. The nonce must be at most NonceSize (16) bytes; shorter nonces are padded with zeros. The additionalData is authenticated but not encrypted. The tagLen must be 16 or 32.
func (*Encrypter) Encrypt ¶ added in v0.2.13
Encrypt encrypts plaintext and returns ciphertext of the same length. Can be called multiple times for streaming encryption. Panics if called after Final.
func (*Encrypter) EncryptTo ¶ added in v0.2.13
EncryptTo encrypts plaintext and writes ciphertext to dst. The dst slice must have capacity for at least len(plaintext) bytes. Returns the ciphertext slice (a subslice of dst). If dst is nil or has insufficient capacity, a new slice is allocated. Panics if called after Final.