Documentation ¶
Index ¶
- Constants
- func AddIV(iv []byte, x int) []byte
- func AddNonce(nonce []byte, x int) []byte
- func CopyIV(iv []byte) []byte
- func CopyNonce(nonce []byte) []byte
- func DecIV(iv []byte) []byte
- func DecNonce(nonce []byte) []byte
- func DecryptCTR(key, iv, data []byte) []byte
- func DecryptGCM(key, nonce, data, additionalData []byte) ([]byte, error)
- func DoCTR(key, iv, data []byte) []byte
- func EncryptCTR(key, iv, data []byte) []byte
- func EncryptGCM(key, nonce, data, additionalData []byte) []byte
- func IVToNonce(iv []byte) []byte
- func IncIV(iv []byte) []byte
- func IncNonce(nonce []byte) []byte
- func NewCTR(key []byte, iv []byte) cipher.Stream
- func NewGCM(key []byte) cipher.AEAD
- func NewRandomIV() []byte
- func NewRandomKey() []byte
- func NewRandomNonce() []byte
- func NewZeroIV() []byte
- func NewZeroNonce() []byte
- func ReadIVFile(path string) ([]byte, error)
- func ReadKeyFile(path string) ([]byte, error)
- func ReadNonceFile(path string) ([]byte, error)
- func SplitCiphertextTag(ciphertext []byte) ([]byte, []byte, error)
- type IVSizeError
- type NonceSizeError
- type TagSizeError
Constants ¶
const IVSize = 16
IVSize is the AES IV size in bytes.
const KeySize = 32
KeySize is the AES-256 key size in bytes.
const NonceSize = 12
NonceSize is the AES-256 GCM nonce size in bytes.
const TagSize = 16
TagSize is the AES-256 GCM tag size in bytes.
Variables ¶
This section is empty.
Functions ¶
func AddIV ¶
AddIV adds x to the iv value, handling wrap-around when the iv would exceed IVSize bytes. iv is an in-out parameter, as well as the return value.
func AddNonce ¶
AddNonce adds x to the nonce value, handling wrap-around when the nonce would exceed NonceSize bytes. nonce is an in-out parameter, as well as the return value.
func DecIV ¶
DecIV decrements the iv value by one, handling wrap-around when the iv would become negative. iv is an in-out parameter, as well as the return value.
func DecNonce ¶
DecNonce decrements the nonce value by one, handling wrap-around when the nonce would become negative. nonce is an in-out parameter, as well as the return value.
func DecryptCTR ¶
EncryptCTR performs a one-shot AES-256 CTR decryption of the ciphertext data. This function reuses the data slice for the plaintext. Thus, on return, the ciphertext is ovewritten with the plaintext. As a convenience, this function also returns the slice.
func DecryptGCM ¶
DecryptGCM performs a one-shot AES-256 GCM decryption and authentication of the ciphertext data and additionalData. Note that this function overwrites the data slice to hold the plaintext. On success, the function returns the plaintext. Callers should generally use the return value, rather than treat data as an in-put parameter.
func DoCTR ¶
DoCTR performs a one-shot AES-256 CTR operation on data. The function reuses the data slice for the output. As a convenience, this function also returns the output slice.
func EncryptCTR ¶
EncryptCTR performs a one-shot AES-256 CTR encryption of the plaintext data. This function reuses the data slice for the ciphertext. Thus, on return, the plaintext is ovewritten with the ciphertext. As a convenience, this function also returns the output slice.
func EncryptGCM ¶
EncryptGCM performs a one-shot AES-256 GCM encryption operation and returns the plaintext. Note that this function overwrites the data slice to hold the ciphertext and tag. Since the addition of the tag may cause a new allocation, the caller should use the return slice as the output value, rather than treat data as an in-out parameter.
func IncIV ¶
IncIV increments the iv value by one, handling wrap-around when the iv would exceed IVSize bytes. iv is an in-out parameter, as well as the return value.
func IncNonce ¶
IncNonce increments the nonce value by one, handling wrap-around when the nonce would exceed NonceSize bytes. ononce is an in-out parameter, as well as the return value.
func NewCTR ¶
NewGTR creates a cipher.Stream for AES-256 CTR mode.
func NewGCM ¶
NewGCM creates a cipher.AEAD for AES-256 GCM mode.
func NewRandomNonce ¶
func NewRandomNonce() []byte
NewRandomNonce generates a random nonce for AES-256 GCM mode.
func NewZeroNonce ¶
func NewZeroNonce() []byte
NewZeroNonce generates a zero nonce value for AES-256 GCM mode.
func ReadIVFile ¶
ReadIVFile reads an AES IV from a file. The file should contain exactly IVSize bytes. If the file contains a different number of bytes, this functions returns an IVSizeError.
func ReadKeyFile ¶
ReadKeyFile reads an AES-256 key from a file. The file should contain exactly KeySize bytes. If the file contains a different number of bytes, this functions returns an aes.KeySizeError.
func ReadNonceFile ¶
ReadNonceFile reads an AES-256 GCM nonce from a file. The file should contain exactly NonceSize bytes. If the file contains a different number of bytes, this functions returns an NonceSizeError.
func SplitCiphertextTag ¶
SplitCiphertextTag takes as input an AES-256 GCM encrypted ciphertext and returns the two components of the ciphertext: the ciphertext proper, and the authentication tag (which is conventionally appended to the ciphertext).
Types ¶
type IVSizeError ¶
type IVSizeError int
IVSizeError indicates an invalid IV size. The integer value of the error is the size in bytes of the invalid IV.
func (IVSizeError) Error ¶
func (i IVSizeError) Error() string
type NonceSizeError ¶
type NonceSizeError int
NonceSizeError indicates an invalid nonce size. The integer value of the error is the size in bytes of the invalid nonce.
func (NonceSizeError) Error ¶
func (n NonceSizeError) Error() string
type TagSizeError ¶
type TagSizeError int
TagSizeError indicates an invalid GCM tag size. The integer value of the error is the size in bytes of the invalid tag.
func (TagSizeError) Error ¶
func (t TagSizeError) Error() string