Next: , Previous: crypto aes, Up: crypto


2.3.2 ARCFOUR stream cipher

The (weinholt crypto arcfour) library provides the well-known ARCFOUR stream cipher. It is the fastest of the ciphers provided by this library collection.

Since this is a stream cipher there is no block length.

— Procedure: expand-arcfour-key key

Expands the bytevector key into an ARCFOUR keystream value. The return value has an unspecified type and is suitable for use with the other procedures exported by this library.

Never use the same key to encrypt two different plaintexts.

— Procedure: arcfour! source source-start target target-start k keystream

Reads k bytes from source starting at source-start, XORs them with bytes from the keystream, and writes them to target starting at target-start. If source and target are the same object then it is required that target-start be less then or equal to source-start.

          (import (weinholt crypto arcfour))
          (let ((buf #vu8(90 60 247 233 181 200 38 52 121 82 133
                          98 244 159 12 97 90 157 43 183 249 170
                          73 244 126))
                (keystream (expand-arcfour-key
                            (string->utf8 "hardly a secret"))))
            (arcfour-discard! keystream 3000)
            (arcfour! buf 0 buf 0 (bytevector-length buf) keystream)
            (clear-arcfour-keystream! keystream)
            (utf8->string buf))
          ⇒ "I AM POKEY THE PENGUIN!!!"
— Procedure: arcfour-discard! keystream n

Discards n bytes from the keystream keystream. It is recommended that the beginning of the keystream is discarded. Some protocols, e.g. RFC 4345, require it.

— Procedure: clear-arcfour-keystream! keystream

Removes all key material from the keystream.