# Stream ciphers

BlockCipher

The `BlockCipher` class is an abstract class that is used to implement a symmetric block cipher. By default the cipher operates in encryption mode. When the reverse flag is set, the decryption mode is activated. For a block cipher, a block size controls the cipher operations. The class also defines the constants that control the block padding with the associated methods.

block-cipher-p
Cipher
PAD-NONE

The `PAD-NONE` constant indicates that the block should not be padded.

PAD-BIT-MODE

The `PAD-BIT` constant indicates that the block should be padded in bit mode.

PAD-ANSI-X923

The `PAD-ANSI-X923` constant indicates that the block should be padded according to ANSI X 923 standard.

PAD-NIST-800

The `PAD-NIST-800` constant indicates that the block should be padded according to NIST 800-38A recommendations. This is the default mode.

get-block-size
Integer
none

The `get-block-size` method returns the cipher block size.

set-padding-mode
none
Item

The `set-padding-mode` method sets the cipher padding mode.

get-padding-mode
Item
none

The `get-padding-mode` method returns the cipher padding mode.

InputCipher

The `InputCipher` class is an stream interface that can stream out an input stream from a cipher. In other word, an input stream is read and block are encoded as long as the input stream read characters. If the cipher is nil, the input cipher simply read the input stream and is therefore transparent. The class acts like an input stream, read the character from the bounded input stream and encode or decode them from the bounded cipher. The `InputCipher` defines several modes of operations. In electronic codebook mode or ECB, the character are encoded in a block basis. In cipher block chaining mode, the block are encoded by doing an XOR operation with the previous block. Other modes such like cipher feedback mode and output feedback mode are also defined.

input-cipher-p
Input
InputCipher
Cipher

The `InputCipher` constructor creates an input cipher with a cipher object. The first argument is the cipher to used for processing.

InputCipher
Cipher Input

The `InputCipher` constructor creates an input cipher with a cipher object and an input stream. The first argument is the cipher to used for processing. The second argument is the input stream object used for the character reading.

InputCipher
Cipher InputStream Item

The `InputCipher` constructor creates an input cipher with a cipher object, an input stream and a mode. The first argument is the cipher to used for processing. The second argument is the input stream object used for the character reading. The third argument is the input cipher mode which can be either ECB, CBC, CFB or OFB.

ECB

The `ECB` constant indicates that the input cipher is to operate in electronic codebook mode. This mode is the default mode.

CBC

The `CBC` constant indicates that the input cipher is to operate in cipher chaining block mode.

CFB

The `CFB` constant indicates that the input cipher is to operate in cipher feedback block mode.

OFB

The `OFB` constant indicates that the input cipher is to operate in output feedback block mode.

reset
none
none

The `reset` method reset the input cipher object.

get-mode
Item
none

The `get-mode` method returns the input cipher operating mode.

set-iv
none
String|Buffer

The `set-iv` method sets the input cipher initial vector. In the first form, the initial vector is set from an octet string. In the second form, the initial vector is set from a buffer object.

get-iv
String
none

The `get-iv` method returns the input cipher initial vector as an octet string.

set-is
none
InputStream

The `set-is` method sets the input cipher input stream. This method can be used to chain multiple input streams in a unique coding session.

Aes

The `Aes` class is a block cipher class that implements the advanced encryption standard (AES), originally known as rijndael. This is an original implementation that conforms to the standard FIPS PUB 197. It should be noted that the AES standard, unlike rijndael, defines a fixed block size of 16 bytes (4 words) and 3 keys sizes (128, 192, 256).

aes-p
BlockCipher
Aes
Key

The `Aes` constructor creates a direct cipher with a key. The first argument is the key used by the cipher.

Aes
Key Boolean

The `Aes` constructor creates a cipher with a key and a reverse flag. The first argument is the key used by the cipher. The second argument is the reverse flag.