aes256

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 19, 2024 License: BSD-3-Clause Imports: 8 Imported by: 2

README

aes256

Go package that extendds the stdlib's aes and cipher packages to provide higher-level functionality.

Documentation

Index

Constants

View Source
const IVSize = 16

IVSize is the AES IV size in bytes.

View Source
const KeySize = 32

KeySize is the AES-256 key size in bytes.

View Source
const NonceSize = 12

NonceSize is the AES-256 GCM nonce size in bytes.

View Source
const TagSize = 16

TagSize is the AES-256 GCM tag size in bytes.

Variables

This section is empty.

Functions

func AddIV

func AddIV(iv []byte, x int) []byte

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

func AddNonce(nonce []byte, x int) []byte

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 CopyIV

func CopyIV(iv []byte) []byte

CopyIV makes a deep copy of the iv and returns the copy.

func CopyNonce

func CopyNonce(nonce []byte) []byte

CopyNonce makes a deep copy of the nonce and returns the copy.

func DecIV

func DecIV(iv []byte) []byte

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

func DecNonce(nonce []byte) []byte

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

func DecryptCTR(key, iv, data []byte) []byte

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

func DecryptGCM(key, nonce, data, additionalData []byte) ([]byte, error)

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

func DoCTR(key, iv, data []byte) []byte

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

func EncryptCTR(key, iv, data []byte) []byte

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

func EncryptGCM(key, nonce, data, additionalData []byte) []byte

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 IVToNonce

func IVToNonce(iv []byte) []byte

IVToNonce makes a copy of iv, truncated to NonceSize.

func IncIV

func IncIV(iv []byte) []byte

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

func IncNonce(nonce []byte) []byte

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

func NewCTR(key []byte, iv []byte) cipher.Stream

NewGTR creates a cipher.Stream for AES-256 CTR mode.

func NewGCM

func NewGCM(key []byte) cipher.AEAD

NewGCM creates a cipher.AEAD for AES-256 GCM mode.

func NewRandomIV

func NewRandomIV() []byte

NewRandomIV generates a random AES IV.

func NewRandomKey

func NewRandomKey() []byte

NewRandomKey generates a random AES-256 key.

func NewRandomNonce

func NewRandomNonce() []byte

NewRandomNonce generates a random nonce for AES-256 GCM mode.

func NewZeroIV

func NewZeroIV() []byte

NewZeroIV generates a zero IV value.

func NewZeroNonce

func NewZeroNonce() []byte

NewZeroNonce generates a zero nonce value for AES-256 GCM mode.

func ReadIVFile

func ReadIVFile(path string) ([]byte, error)

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

func ReadKeyFile(path string) ([]byte, error)

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

func ReadNonceFile(path string) ([]byte, error)

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

func SplitCiphertextTag(ciphertext []byte) ([]byte, []byte, error)

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL