pegasus/xchacha20

Types

A key used for XChaCha20 encryption/decryption This type provides type-safety to ensure keys are used correctly

pub type CipherKey {
  CipherKey(data: BitArray)
}

Constructors

  • CipherKey(data: BitArray)

A nonce (number used once) used for XChaCha20 encryption/decryption Must be unique for each encryption operation with the same key

pub type Nonce {
  Nonce(data: BitArray)
}

Constructors

  • Nonce(data: BitArray)

Functions

pub fn decrypt(
  key: CipherKey,
  nonce: Nonce,
  ciphertext: BitArray,
) -> Result(BitArray, Error)

Decrypt data using XChaCha20

Takes a key, nonce, and ciphertext and returns the decrypted plaintext

pub fn encrypt(
  key: CipherKey,
  nonce: Nonce,
  plaintext: BitArray,
) -> Result(BitArray, Error)

Encrypt data using XChaCha20

Takes a key, nonce, and plaintext and returns the encrypted ciphertext

pub fn generate_key() -> Result(CipherKey, Error)

Generate a new random encryption key

Returns a 32-byte key suitable for XChaCha20 encryption

pub fn generate_nonce() -> Result(Nonce, Error)

Generate a new random nonce

Returns a 24-byte nonce suitable for XChaCha20 encryption

pub fn key_from_bitarray(
  key_data: BitArray,
) -> Result(CipherKey, Error)

Create a CipherKey from raw bytes

The key must be exactly 32 bytes

pub fn nonce_from_bitarray(
  nonce_data: BitArray,
) -> Result(Nonce, Error)

Create a Nonce from raw bytes

The nonce must be exactly 24 bytes

Search Document