class Sodium::Cipher::ChaCha20Ietf

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.

Also provides a ::Random interface.

Use with caution. When in doubt use ::Random::Secure

Possibly safe uses:

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_ietf_keybytes.to_i32
NONCE_SIZE = LibSodium.crypto_stream_chacha20_ietf_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, next_u : UInt8 next_u, nonce : Bytes | Nil nonce, nonce=(nonce : Bytes) nonce=, nonce? : Bytes | Nil | Nil nonce?, nonce_size : Int32 nonce_size, offset : UInt64 offset, offset=(offset : UInt64) offset=, random_bytes(bytes : Bytes) : Bytes random_bytes, random_key random_key, random_nonce random_nonce, update(src : Bytes, dst : Bytes)
update(src : Bytes) : Bytes
update

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

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

Class Method Detail

def self.key_size : Int32 #

[View source]
def self.nonce_size : Int32 #

[View source]
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]