class Sodium::Cipher::XChaCha20

Overview

These classes can be used to generate pseudo-random data from a key, or as building blocks for implementing custom constructions, but they are not alternatives to secretbox.

See https://libsodium.gitbook.io/doc/advanced/stream_ciphers for further information.

This class mimicks the OpenSSL::Cipher interface with minor differences.

See spec/sodium/cipher/chalsa_spec.cr for examples on how to use this class.

WARNING: Not validated against test vectors. You should probably write some before using this class.

Defined in:

sodium/cipher/chalsa.cr

Constant Summary

KEY_SIZE = LibSodium.crypto_stream_chacha20_keybytes.to_i32
NONCE_SIZE = LibSodium.crypto_stream_chacha20_noncebytes.to_i32

Class Method Summary

Instance Method Summary

Instance methods inherited from class Sodium::Cipher::Chalsa

dup dup, edible? edible?, final final, key : Crypto::Secret key, key=(key : Bytes | Crypto::Secret) : Crypto::Secret key=, key_size : Int32 key_size, nonce : Bytes? nonce, nonce=(nonce : Bytes) nonce=, nonce? : Bytes | Nil? nonce?, nonce_size : Int32 nonce_size, offset : Int32 offset, offset=(offset) offset=, random_bytes(bytes : Bytes) : Bytes
random_bytes(size : Int) : Bytes
random_bytes
, random_key random_key, random_nonce random_nonce, update(src : Bytes) : Bytes
update(src : Bytes, dst : Bytes)
update

Constructor methods inherited from class Sodium::Cipher::Chalsa

new(key : Crypto::Secret | Bytes, nonce = nil) new

Class Method Detail

def self.random #

[View source]

Instance Method Detail

def key_size : Int32 #

[View source]
def nonce_size : Int32 #

[View source]
def update(src : Bytes, dst : Bytes) : Bytes #

Xor's src with the cipher output and places in dst.

src and dst may be the same object but should not overlap.


[View source]