salsa20

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package salsa20 implements Salsa20 encryption and decryption with streaming support. It provides Salsa20 encryption and decryption operations using the standard Salsa20 algorithm with support for 32-byte keys and 8-byte nonces.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewStreamDecrypter

func NewStreamDecrypter(r io.Reader, c *cipher.Salsa20Cipher) io.Reader

NewStreamDecrypter creates a new streaming Salsa20 decrypter that reads encrypted data from the provided io.Reader. The decrypter uses the specified cipher interface and validates the key length and nonce length for proper Salsa20 decryption.

func NewStreamEncrypter

func NewStreamEncrypter(w io.Writer, c *cipher.Salsa20Cipher) io.WriteCloser

NewStreamEncrypter creates a new streaming Salsa20 encrypter that writes encrypted data to the provided io.Writer. The encrypter uses the specified cipher interface and validates the key length and nonce length for proper Salsa20 encryption.

Types

type DecryptError

type DecryptError struct {
	Err error // The underlying error that caused the failure
}

DecryptError represents an error when Salsa20 decryption fails. This error occurs when the underlying Salsa20 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 // The underlying error that caused the failure
}

EncryptError represents an error when Salsa20 encryption fails. This error occurs when the underlying Salsa20 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 KeySizeError

type KeySizeError int

KeySizeError represents an error when the Salsa20 key size is invalid. Salsa20 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 NonceSizeError

type NonceSizeError int

NonceSizeError represents an error when the Salsa20 nonce size is invalid. Salsa20 nonces must be exactly 8 bytes (64 bits) long. This error occurs when the provided nonce does not meet this size requirement.

func (NonceSizeError) Error

func (n NonceSizeError) 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 ReadError

type ReadError struct {
	Err error // The underlying error that caused the failure
}

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.

func (ReadError) Error

func (e ReadError) Error() string

Error returns a formatted error message describing the read failure. The message includes the underlying error for debugging.

type StdDecrypter

type StdDecrypter struct {
	Error error // Error field for storing decryption errors
	// contains filtered or unexported fields
}

StdDecrypter represents a Salsa20 decrypter for standard decryption operations. It implements Salsa20 decryption using the standard Salsa20 algorithm with support for 32-byte keys and 8-byte nonces.

func NewStdDecrypter

func NewStdDecrypter(c *cipher.Salsa20Cipher) *StdDecrypter

NewStdDecrypter creates a new Salsa20 decrypter with the specified cipher and key. Validates the key length and nonce length, then initializes the decrypter for Salsa20 decryption operations. The key must be exactly 32 bytes and nonce must be exactly 8 bytes.

func (*StdDecrypter) Decrypt

func (d *StdDecrypter) Decrypt(src []byte) (dst []byte, err error)

Decrypt decrypts the given byte slice using Salsa20 decryption. For Salsa20, decryption is the same as encryption.

type StdEncrypter

type StdEncrypter struct {
	Error error // Error field for storing encryption errors
	// contains filtered or unexported fields
}

StdEncrypter represents a Salsa20 encrypter for standard encryption operations. It implements Salsa20 encryption using the standard Salsa20 algorithm with support for 32-byte keys and 8-byte nonces.

func NewStdEncrypter

func NewStdEncrypter(c *cipher.Salsa20Cipher) *StdEncrypter

NewStdEncrypter creates a new Salsa20 encrypter with the specified cipher and key. Validates the key length and nonce length, then initializes the encrypter for Salsa20 encryption operations. The key must be exactly 32 bytes and nonce must be exactly 8 bytes.

func (*StdEncrypter) Encrypt

func (e *StdEncrypter) Encrypt(src []byte) (dst []byte, err error)

Encrypt encrypts the given byte slice using Salsa20 encryption. Salsa20 is a stream cipher, so it can encrypt data of any length.

type StreamDecrypter

type StreamDecrypter struct {
	Error error // Error field for storing decryption errors
	// contains filtered or unexported fields
}

StreamDecrypter represents a streaming Salsa20 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 chunks.

func (*StreamDecrypter) Read

func (d *StreamDecrypter) Read(p []byte) (n int, err error)

Read implements io.Reader interface for streaming Salsa20 decryption. On the first call, reads all encrypted data from the underlying reader and decrypts it. Subsequent calls return chunks of the decrypted data to maintain streaming interface.

type StreamEncrypter

type StreamEncrypter struct {
	Error error // Error field for storing encryption errors
	// contains filtered or unexported fields
}

StreamEncrypter represents a streaming Salsa20 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 Salsa20 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 Salsa20 encryption. Salsa20 is a stream cipher, so it can encrypt data of any length.

type WriteError

type WriteError struct {
	Err error // The underlying error that caused the failure
}

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

  • errors.go
  • salsa20.go

Jump to

Keyboard shortcuts

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