Documentation
¶
Overview ¶
Package aes implements convenience helpers for AES block cipher modes.
Index ¶
- Constants
- Variables
- func GenerateIV() ([]byte, error)
- func GenerateKey(size int) ([]byte, error)
- func GenerateRandomBytes(n int) ([]byte, error)
- func GenerateSIVKey(size int) ([]byte, error)
- type AEADCipher
- func NewAESGCMSIV(masterKey []byte, nonceAndData ...[]byte) (AEADCipher, error)
- func NewGCM(key, nonce, additionalData []byte) (AEADCipher, error)
- func NewGCMWithTagSize(key, nonce, additionalData []byte, tagSize int) (AEADCipher, error)
- func NewGHASHSIV(key []byte, additionalData ...[]byte) (AEADCipher, error)
- func NewSIV(key []byte, additionalData ...[]byte) (AEADCipher, error)
- type AESGCMSIVKeySizeError
- type AESGCMSIVNonceSizeError
- type Cipher
- type GCMDataSizeError
- type GCMNonceSizeError
- type GCMTagSizeError
- type GHASHSIVKeySizeError
- type IgeIvSizeError
- type InvalidCiphertextError
- type InvalidDataError
- type IvSizeError
- type KeySizeError
- type Mode
- type SIVKeySizeError
Constants ¶
const ( // IGEIVSize is the size, in bytes, of an IGE initialization vector. IGEIVSize = stdaes.BlockSize << 1 // KeySize128 is the size, in bytes, of an AES-128 key. KeySize128 = 16 // KeySize192 is the size, in bytes, of an AES-192 key. KeySize192 = 24 // KeySize256 is the size, in bytes, of an AES-256 key. KeySize256 = 32 )
const ( // SIVTagSize is the size, in bytes, of an AES-SIV authentication tag. SIVTagSize = 16 // SIVKeySize128 is the size, in bytes, of an AES-128-SIV key. SIVKeySize128 = KeySize128 << 1 // SIVKeySize192 is the size, in bytes, of an AES-192-SIV key. SIVKeySize192 = KeySize192 << 1 // SIVKeySize256 is the size, in bytes, of an AES-256-SIV key. SIVKeySize256 = KeySize256 << 1 )
const ( // GHASHSIVKeySize128 is the size, in bytes, of an AES-128-GHASH-SIV key. GHASHSIVKeySize128 = KeySize128 // GHASHSIVKeySize192 is the size, in bytes, of an AES-192-GHASH-SIV key. GHASHSIVKeySize192 = KeySize192 // GHASHSIVKeySize256 is the size, in bytes, of an AES-256-GHASH-SIV key. GHASHSIVKeySize256 = KeySize256 )
const ( // AESGCMSIVKeySize128 is the size, in bytes, of an AES-128-GCM-SIV key. AESGCMSIVKeySize128 = KeySize128 // AESGCMSIVKeySize256 is the size, in bytes, of an AES-256-GCM-SIV key. AESGCMSIVKeySize256 = KeySize256 // AESGCMSIVNonceSize is the required AES-GCM-SIV nonce size, in bytes. AESGCMSIVNonceSize = 12 // AESGCMSIVTagSize is the size, in bytes, of an AES-GCM-SIV tag. AESGCMSIVTagSize = 16 )
Variables ¶
var ErrSIVAuthFailed = aesinternal.ErrSIVOpen
ErrSIVAuthFailed is returned when SIV authentication fails.
var ErrUnknownMode = errors.New("aes: unknown cipher mode")
ErrUnknownMode is returned when New is called with an unknown mode.
Functions ¶
func GenerateIV ¶
GenerateIV returns a new random AES initialization vector.
func GenerateKey ¶
GenerateKey returns a new random AES key of the given size.
The size must be KeySize128, KeySize192, or KeySize256.
func GenerateRandomBytes ¶
GenerateRandomBytes returns n cryptographically secure random bytes.
func GenerateSIVKey ¶
GenerateSIVKey returns a new random AES-SIV key of the given size.
The size must be SIVKeySize128, SIVKeySize192, or SIVKeySize256.
Types ¶
type AEADCipher ¶
type AEADCipher interface {
cipher.AEAD
Encrypt(plaintext []byte) ([]byte, error)
Decrypt(ciphertext []byte) ([]byte, error)
}
AEADCipher is an authenticated encryption cipher.
It includes the standard cipher.AEAD API and the package's Encrypt and Decrypt convenience methods.
func NewAESGCMSIV ¶
func NewAESGCMSIV(masterKey []byte, nonceAndData ...[]byte) (AEADCipher, error)
NewAESGCMSIV returns a new RFC 8452 AES-GCM-SIV AEAD.
The masterKey must be AESGCMSIVKeySize128 or AESGCMSIVKeySize256 bytes long. New code should pass the nonce and additional data to Seal and Open. Passing nonce and additionalData here is supported for the legacy Encrypt and Decrypt helpers.
func NewGCM ¶
func NewGCM(key, nonce, additionalData []byte) (AEADCipher, error)
NewGCM returns a new AES-GCM cipher with the standard 16-byte tag.
The key must be 16, 24, or 32 bytes. The nonce must not be reused with the same key. A 12-byte nonce is recommended.
func NewGCMWithTagSize ¶
func NewGCMWithTagSize(key, nonce, additionalData []byte, tagSize int) (AEADCipher, error)
NewGCMWithTagSize returns a new AES-GCM cipher with a custom tag size.
The tagSize must be between 12 and 16 bytes. The nonce must be 12 bytes.
func NewGHASHSIV ¶
func NewGHASHSIV(key []byte, additionalData ...[]byte) (AEADCipher, error)
NewGHASHSIV returns a new AES-GHASH-SIV AEAD.
AES-GHASH-SIV has the same public behavior as NewSIV, but uses GHASH instead of CMAC for the synthetic IV calculation.
func NewSIV ¶
func NewSIV(key []byte, additionalData ...[]byte) (AEADCipher, error)
NewSIV returns a new AES-SIV AEAD.
The key must be SIVKeySize128, SIVKeySize192, or SIVKeySize256 bytes long. Additional data should normally be supplied to Seal and Open. The optional additionalData values are kept for the legacy Encrypt and Decrypt helpers.
type AESGCMSIVKeySizeError ¶
type AESGCMSIVKeySizeError int
AESGCMSIVKeySizeError is returned when an AES-GCM-SIV key has the wrong length.
func (AESGCMSIVKeySizeError) Error ¶
func (e AESGCMSIVKeySizeError) Error() string
type AESGCMSIVNonceSizeError ¶
type AESGCMSIVNonceSizeError int
AESGCMSIVNonceSizeError is returned when an AES-GCM-SIV nonce has the wrong length.
func (AESGCMSIVNonceSizeError) Error ¶
func (e AESGCMSIVNonceSizeError) Error() string
type Cipher ¶
type Cipher struct {
// contains filtered or unexported fields
}
Cipher is a reusable AES cipher with a fixed mode, key, IV, and padding mode.
func New ¶
New returns a new Cipher for the given mode.
The key must be 16, 24, or 32 bytes. The IV must be 16 bytes for most modes, IGEIVSize bytes for ModeIGE, and nil for ModeECB. The padding mode may be nil when the input is already block aligned.
type GCMDataSizeError ¶
type GCMDataSizeError int
GCMDataSizeError is returned when AES-GCM plaintext is too large.
func (GCMDataSizeError) Error ¶
func (e GCMDataSizeError) Error() string
type GCMNonceSizeError ¶
type GCMNonceSizeError int
GCMNonceSizeError is returned when an AES-GCM nonce has the wrong length.
func (GCMNonceSizeError) Error ¶
func (e GCMNonceSizeError) Error() string
type GCMTagSizeError ¶
type GCMTagSizeError int
GCMTagSizeError is returned when an AES-GCM tag has the wrong length.
func (GCMTagSizeError) Error ¶
func (e GCMTagSizeError) Error() string
type GHASHSIVKeySizeError ¶
type GHASHSIVKeySizeError int
GHASHSIVKeySizeError is returned when an AES-GHASH-SIV key has the wrong length.
func (GHASHSIVKeySizeError) Error ¶
func (e GHASHSIVKeySizeError) Error() string
type IgeIvSizeError ¶
type IgeIvSizeError int
IgeIvSizeError is returned when an IGE initialization vector has the wrong length.
func (IgeIvSizeError) Error ¶
func (e IgeIvSizeError) Error() string
type InvalidCiphertextError ¶
type InvalidCiphertextError int
InvalidCiphertextError is returned when ciphertext is empty or not block aligned.
func (InvalidCiphertextError) Error ¶
func (e InvalidCiphertextError) Error() string
type InvalidDataError ¶
type InvalidDataError int
InvalidDataError is returned when plaintext is empty or not block aligned.
func (InvalidDataError) Error ¶
func (e InvalidDataError) Error() string
type IvSizeError ¶
type IvSizeError int
IvSizeError is returned when an initialization vector has the wrong length.
func (IvSizeError) Error ¶
func (e IvSizeError) Error() string
type KeySizeError ¶
type KeySizeError int
KeySizeError is returned when an AES key has the wrong length.
func (KeySizeError) Error ¶
func (e KeySizeError) Error() string
type Mode ¶
type Mode uint8
Mode identifies an AES mode of operation.
const ( // ModeCBC selects cipher block chaining mode. ModeCBC Mode = iota + 1 // ModeCFB selects cipher feedback mode. ModeCFB // ModeCTR selects counter mode. ModeCTR // ModeECB selects electronic codebook mode. ModeECB // ModeIGE selects infinite garble extension mode. ModeIGE // ModeOFB selects output feedback mode. ModeOFB )
type SIVKeySizeError ¶
type SIVKeySizeError int
SIVKeySizeError is returned when an AES-SIV key has the wrong length.
func (SIVKeySizeError) Error ¶
func (e SIVKeySizeError) Error() string