Documentation
¶
Overview ¶
Package chacha20 implements ChaCha20 encryption and decryption with streaming support. It provides ChaCha20 encryption and decryption operations using the standard ChaCha20 algorithm with support for 256-bit keys and 96-bit nonces.
Index ¶
- func NewStreamDecrypter(r io.Reader, c *cipher.ChaCha20Cipher) io.Reader
- func NewStreamEncrypter(w io.Writer, c *cipher.ChaCha20Cipher) io.WriteCloser
- 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 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 decryption.
func NewStreamEncrypter ¶
func NewStreamEncrypter(w io.Writer, c *cipher.ChaCha20Cipher) io.WriteCloser
NewStreamEncrypter creates a new streaming ChaCha20 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 encryption.
Types ¶
type DecryptError ¶
type DecryptError struct {
Err error
}
DecryptError represents an error when ChaCha20 decryption fails. This error occurs when the underlying ChaCha20 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 encryption fails. This error occurs when the underlying ChaCha20 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 nonce size is invalid. ChaCha20 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 key size is invalid. ChaCha20 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 decrypter for standard decryption operations. It implements ChaCha20 decryption using the standard ChaCha20 algorithm with support for 256-bit keys and 96-bit nonces.
func NewStdDecrypter ¶
func NewStdDecrypter(c *cipher.ChaCha20Cipher) *StdDecrypter
NewStdDecrypter creates a new ChaCha20 decrypter with the specified cipher and key. Validates the key length and initializes the decrypter for ChaCha20 decryption operations. The key must be exactly 32 bytes (256 bits) and nonce must be 12 bytes.
func (*StdDecrypter) Decrypt ¶
func (d *StdDecrypter) Decrypt(src []byte) (dst []byte, err error)
Decrypt decrypts the given byte slice using ChaCha20 decryption. ChaCha20 is a stream cipher and can decrypt any amount of data. 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 encrypter for standard encryption operations. It implements ChaCha20 encryption using the standard ChaCha20 algorithm with support for 256-bit keys and 96-bit nonces.
func NewStdEncrypter ¶
func NewStdEncrypter(c *cipher.ChaCha20Cipher) *StdEncrypter
NewStdEncrypter creates a new ChaCha20 encrypter with the specified cipher and key. Validates the key length and nonce length, then initializes the encrypter for ChaCha20 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 encryption. ChaCha20 is a stream cipher and can encrypt any amount of data. 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 decrypter that implements io.Reader. It provides efficient decryption for large data streams by reading encrypted data from the underlying reader and decrypting it in real-time without buffering.
func (*StreamDecrypter) Read ¶
func (d *StreamDecrypter) Read(p []byte) (n int, err error)
Read implements io.Reader interface for streaming ChaCha20 decryption. Provides true streaming decryption by reading and decrypting data in chunks without buffering the entire dataset in memory.
type StreamEncrypter ¶
type StreamEncrypter struct {
Error error // Error field for storing encryption errors
// contains filtered or unexported fields
}
StreamEncrypter represents a streaming ChaCha20 encrypter that implements io.WriteCloser. It provides efficient encryption for large data streams by processing data in chunks and writing encrypted output to the underlying writer.
func (*StreamEncrypter) Close ¶
func (e *StreamEncrypter) Close() error
Close implements io.Closer interface for streaming ChaCha20 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 encryption. ChaCha20 is a stream cipher so it can handle any amount of data.
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
¶
- chacha20.go
- errors.go