class Crypto::ChaCha20::Native

Overview

The ChaCha20 cipher is a high-speed cipher. It is considerably faster than AES in software-only implementations, making it around three times as fast on platforms that lack specialized AES hardware. ChaCha20 is also not sensitive to timing attacks.

This is the pure Crystal scalar implementation.

Defined in:

crypto/chacha20/native.cr

Constant Summary

BLOCK_SIZE = Crypto::ChaCha20::BLOCK_SIZE

Constructors

Instance Method Summary

Instance methods inherited from class Crypto::ChaCha20::Cipher

encrypt(plaintext : Bytes, encrypted : Bytes) : Nil
encrypt(plaintext : Bytes) : Bytes
encrypt
, next_key_block : StaticArray(UInt32, 16) next_key_block, reset reset

Constructor Detail

def self.new(key : Bytes, nonce : Bytes, counter : UInt32 = 0_u32) #

The inputs to ChaCha20 are:

  • key: A 256-bit key, treated as a concatenation of eight 32-bit little- endian integers.
  • nonce: A 96-bit nonce, treated as a concatenation of three 32-bit little- endian integers.
  • counter: A 32-bit block count parameter, treated as a 32-bit little-endian integer.

[View source]
def self.new(key : String, nonce : String, counter : UInt32 = 0_u32) #

The inputs to ChaCha20 are:

  • key: A 256-bit key, treated as a concatenation of eight 32-bit little- endian integers. (hex encoded)
  • nonce: A 96-bit nonce, treated as a concatenation of three 32-bit little- endian integers. (hex encoded)
  • counter: A 32-bit block count parameter, treated as a 32-bit little-endian integer.

[View source]
def self.new(state : StaticArray(UInt32, 16)) #

Directly initialize using the state


[View source]

Instance Method Detail

def clone #

create a clone from the state


[View source]
def encrypt(plaintext : Bytes, encrypted : Bytes) : Nil #

reads from plaintext and writes to encrypted


[View source]
def encrypt(plaintext : IO, encrypted : IO) #

reads from plaintext and writes to encrypted


[View source]
def encrypt(plaintext : Bytes) : Bytes #

encrypt the plaintext returns the encrypted bytes


[View source]
def reset #

reset the counter


[View source]