Documentation
¶
Overview ¶
Package chacha20poly1305 implements ChaCha20-Poly1305 authenticated encryption and decryption with streaming support. It provides ChaCha20-Poly1305 AEAD (Authenticated Encryption with Associated Data) operations using the standard ChaCha20-Poly1305 algorithm with support for 256-bit keys, 96-bit nonces, and optional associated data.
Index ¶
- func NewStreamDecrypter(r io.Reader, c *cipher.ChaCha20Poly1305Cipher) io.Reader
- func NewStreamEncrypter(w io.Writer, c *cipher.ChaCha20Poly1305Cipher) io.WriteCloser
- type AuthenticationError
- type DecryptError
- type EncryptError
- type InvalidNonceSizeError
- type KeySizeError
- type ReadError
- type StdDecrypter
- type StdEncrypter
- type StreamDecrypter
- type StreamEncrypter
- type WriteError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewStreamDecrypter ¶
NewStreamDecrypter creates a new streaming ChaCha20-Poly1305 decrypter that reads encrypted data from the provided io.Reader. The decrypter uses the specified cipher interface and validates the key and nonce lengths for proper ChaCha20-Poly1305 decryption. The key must be exactly 32 bytes (256 bits) and nonce must be 12 bytes (96 bits).
func NewStreamEncrypter ¶
func NewStreamEncrypter(w io.Writer, c *cipher.ChaCha20Poly1305Cipher) io.WriteCloser
NewStreamEncrypter creates a new streaming ChaCha20-Poly1305 encrypter that writes encrypted data to the provided io.Writer. The encrypter uses the specified cipher interface and validates the key and nonce lengths for proper ChaCha20-Poly1305 encryption. Each chunk is encrypted independently with authentication for true stream processing. The key must be exactly 32 bytes (256 bits) and nonce must be 12 bytes (96 bits).
Types ¶
type AuthenticationError ¶
type AuthenticationError struct{}
AuthenticationError represents an error when ChaCha20-Poly1305 authentication fails. This occurs when the computed MAC doesn't match the expected MAC during decryption. This error indicates that the data has been tampered with or corrupted.
func (AuthenticationError) Error ¶
func (e AuthenticationError) Error() string
Error returns a formatted error message describing the authentication failure.
type DecryptError ¶
type DecryptError struct {
Err error
}
DecryptError represents an error when ChaCha20-Poly1305 decryption fails. This error occurs when the underlying ChaCha20-Poly1305 decryption operation fails. The error includes the underlying error for detailed debugging.
func (DecryptError) Error ¶
func (e DecryptError) Error() string
Error returns a formatted error message describing the decryption failure. The message includes the underlying error for debugging.
type EncryptError ¶
type EncryptError struct {
Err error
}
EncryptError represents an error when ChaCha20-Poly1305 encryption fails. This error occurs when the underlying ChaCha20-Poly1305 encryption operation fails. The error includes the underlying error for detailed debugging.
func (EncryptError) Error ¶
func (e EncryptError) Error() string
Error returns a formatted error message describing the encryption failure. The message includes the underlying error for debugging.
type InvalidNonceSizeError ¶
type InvalidNonceSizeError struct {
Size int
}
InvalidNonceSizeError represents an error when the ChaCha20-Poly1305 nonce size is invalid. ChaCha20-Poly1305 nonces must be exactly 12 bytes long. This error occurs when the provided nonce does not meet this size requirement.
func (InvalidNonceSizeError) Error ¶
func (e InvalidNonceSizeError) Error() string
Error returns a formatted error message describing the invalid nonce size. The message includes the actual nonce size and the required size for debugging.
type KeySizeError ¶
type KeySizeError int
KeySizeError represents an error when the ChaCha20-Poly1305 key size is invalid. ChaCha20-Poly1305 keys must be exactly 32 bytes (256 bits) long. This error occurs when the provided key does not meet this size requirement.
func (KeySizeError) Error ¶
func (k KeySizeError) Error() string
Error returns a formatted error message describing the invalid key size. The message includes the actual key size and the required size for debugging.
type ReadError ¶
type ReadError struct {
Err error
}
ReadError represents an error when reading encrypted data fails. This error occurs when reading encrypted data from the underlying reader fails. The error includes the underlying error for detailed debugging.
type StdDecrypter ¶
type StdDecrypter struct {
Error error // Error field for storing decryption errors
// contains filtered or unexported fields
}
StdDecrypter represents a ChaCha20-Poly1305 decrypter for standard decryption operations. It implements ChaCha20-Poly1305 AEAD decryption using the standard ChaCha20-Poly1305 algorithm with support for 256-bit keys, 96-bit nonces, and optional AAD with authentication verification.
func NewStdDecrypter ¶
func NewStdDecrypter(c *cipher.ChaCha20Poly1305Cipher) *StdDecrypter
NewStdDecrypter creates a new ChaCha20-Poly1305 decrypter with the specified cipher and key. Validates the key length and nonce length, then initializes the decrypter for ChaCha20-Poly1305 decryption operations. The key must be exactly 32 bytes (256 bits) and nonce must be 12 bytes (96 bits).
func (*StdDecrypter) Decrypt ¶
func (d *StdDecrypter) Decrypt(src []byte) (dst []byte, err error)
Decrypt decrypts the given byte slice using ChaCha20-Poly1305 decryption. ChaCha20-Poly1305 provides authenticated decryption, verifying both encryption and authentication. The input must include both encrypted data and authentication tag for successful decryption. Returns empty data when input is empty.
type StdEncrypter ¶
type StdEncrypter struct {
Error error // Error field for storing encryption errors
// contains filtered or unexported fields
}
StdEncrypter represents a ChaCha20-Poly1305 encrypter for standard encryption operations. It implements ChaCha20-Poly1305 AEAD (Authenticated Encryption with Associated Data) encryption using the standard ChaCha20-Poly1305 algorithm with support for 256-bit keys, 96-bit nonces, and optional AAD.
func NewStdEncrypter ¶
func NewStdEncrypter(c *cipher.ChaCha20Poly1305Cipher) *StdEncrypter
NewStdEncrypter creates a new ChaCha20-Poly1305 encrypter with the specified cipher and key. Validates the key length and nonce length, then initializes the encrypter for ChaCha20-Poly1305 encryption operations. The key must be exactly 32 bytes (256 bits) and nonce must be 12 bytes (96 bits).
func (*StdEncrypter) Encrypt ¶
func (e *StdEncrypter) Encrypt(src []byte) (dst []byte, err error)
Encrypt encrypts the given byte slice using ChaCha20-Poly1305 encryption. ChaCha20-Poly1305 provides authenticated encryption, returning ciphertext with authentication tag. The output includes both encrypted data and authentication tag for integrity verification. Returns empty data when input is empty.
type StreamDecrypter ¶
type StreamDecrypter struct {
Error error // Error field for storing decryption errors
// contains filtered or unexported fields
}
StreamDecrypter represents a streaming ChaCha20-Poly1305 decrypter that implements io.Reader. It provides efficient authenticated decryption for large data streams by reading encrypted data from the underlying reader and decrypting it in real-time with authentication verification.
Note: For streaming AEAD decryption, the encrypted data must contain length prefixes or use fixed-size chunks to properly separate authenticated blocks.
func (*StreamDecrypter) Read ¶
func (d *StreamDecrypter) Read(p []byte) (n int, err error)
Read implements io.Reader interface for streaming ChaCha20-Poly1305 decryption. Provides true streaming decryption by reading and decrypting authenticated data chunks without buffering the entire dataset in memory.
Note: This implementation reads the entire encrypted stream since ChaCha20-Poly1305 authenticates the complete message. For true chunked streaming, use multiple AEAD operations.
type StreamEncrypter ¶
type StreamEncrypter struct {
Error error // Error field for storing encryption errors
// contains filtered or unexported fields
}
StreamEncrypter represents a streaming ChaCha20-Poly1305 encrypter that implements io.WriteCloser. It provides efficient authenticated encryption for large data streams by processing data in chunks and writing encrypted output with authentication tags to the underlying writer.
Note: ChaCha20-Poly1305 is an AEAD cipher that authenticates the entire message. For true streaming, each chunk is encrypted independently with its own authentication tag.
func (*StreamEncrypter) Close ¶
func (e *StreamEncrypter) Close() error
Close implements io.Closer interface for streaming ChaCha20-Poly1305 encryption. Closes the underlying writer if it implements io.Closer.
func (*StreamEncrypter) Write ¶
func (e *StreamEncrypter) Write(p []byte) (n int, err error)
Write implements io.Writer interface for streaming ChaCha20-Poly1305 encryption. Each write operation encrypts the data with authentication and writes it to the underlying writer. For streaming AEAD, each chunk gets its own authentication tag.
type WriteError ¶
type WriteError struct {
Err error
}
WriteError represents an error when writing encrypted data fails. This error occurs when writing encrypted data to the underlying writer fails. The error includes the underlying error for detailed debugging.
func (WriteError) Error ¶
func (e WriteError) Error() string
Error returns a formatted error message describing the write failure. The message includes the underlying error for debugging.
Source Files
¶
- chacha20poly1305.go
- errors.go