class Sodium::Cipher::ChaCha20

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

Instance Method Summary

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

dup dup, edible? edible?, final final, key key, key=(key : Bytes | SecureBuffer) key=, key? : Slice(UInt8) | Sodium::SecureBuffer | Nil key?, key_size : Int32 key_size, nonce nonce, nonce=(nonce : Bytes) nonce=, nonce? : Slice(UInt8)? 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 = nil, nonce = nil) new

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]