Skip to content

Commit

Permalink
review stream ciphers
Browse files Browse the repository at this point in the history
[skip ci]
  • Loading branch information
sjaeckel committed Sep 20, 2017
1 parent 2ccb3fb commit dd01232
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions doc/crypt.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1246,15 +1246,15 @@ \chapter{Stream Ciphers}
however LibTomCrypt's implementation works with bytes).

The API for all stream ciphers operates in mode: \textit{setup} -- \textit{crypt} -- \textit{crypt} -- ... -- \textit{done}.
Please note that both encryption and decryption is implemented via \textit{crypt}.
Please note that both encryption and decryption are implemented via \textit{crypt}.

Another useful feature of stream ciphers API is generation of random stream of bytes which works like:
Another useful feature of the stream ciphers API is generation of a random stream of bytes which works like:
\textit{setup} -- \textit{keystream} -- \textit{keystream} -- ... -- \textit{done}. The random stream generation is
implemented like encryption of a stream o zero bytes.
implemented like encryption of a stream of \textit{0x00} bytes.

\mysection{ChaCha}

The \textit{ChaCha} is currently the most modern stream cipher included in LibTomCrypt, so use this one unless you
\textit{ChaCha} is currently the most modern stream cipher included in LibTomCrypt, so use this one unless you
have a reason for using some of the older algorithms.

For more information about ChaCha see \url{https://en.wikipedia.org/wiki/ChaCha_(cipher)}.
Expand All @@ -1275,20 +1275,21 @@ \chapter{Stream Ciphers}
err = chacha_ivctr64(&st, nonce, 8, initial_64bit_ctr);
\end{verbatim}

The \textit{chacha\_setup} takes as a parameter the number of rounds -- choose 20 if you are not sure.
As always never ever used the same key + nonce pair more than once.
The \textit{chacha\_setup} takes the number of rounds as a parameter -- choose 20 if you are not sure.
As always never ever use the same key + nonce pair more than once.

For the actual encryption or decryption you to call:
For the actual encryption or decryption you have to call:
\begin{verbatim}
err = chacha_crypt(&st, in_buffer, in_len, out_buffer);
\end{verbatim}

If you just want a random stream of bytes initialize the cipher with truly random \textit{key} (32 bytes),
truly random \textit{nonce} (8 bytes) and zero initial counter. After that you can get a stream of pseudo--random
If you just want a random stream of bytes initialize the cipher with a truly random \textit{key} (32 bytes),
a truly random \textit{nonce} (8 bytes) and zero initial counter. After that you can get a stream of pseudo--random
bytes via:
\begin{verbatim}
err = chacha_keystream(&st, out_buffer, out_len);
\end{verbatim}
Note that it's probably a better idea to use the PRNG interface for this purpose as that one allows re-seeding.

At the end you have to terminate the state:
\begin{verbatim}
Expand All @@ -1301,13 +1302,13 @@ \chapter{Stream Ciphers}

Supported key size: 5--256 bytes

You need to initialize RC with a \textit{key} (no \textit{nonce}, no \textit{IV}, no \textit{counter}).
You need to initialize RC4 only with a \textit{key}.
\begin{verbatim}
rc4_state st;
err = rc4_stream_setup(&st, key, key_len);
\end{verbatim}

For the actual encryption or decryption you to call:
For the actual encryption or decryption you have to call:
\begin{verbatim}
err = rc4_stream_crypt(&st, in_buffer, in_len, out_buffer);
\end{verbatim}
Expand All @@ -1318,6 +1319,7 @@ \chapter{Stream Ciphers}
\begin{verbatim}
err = rc4_stream_keystream(&st, out_buffer, out_len);
\end{verbatim}
Note that it's probably a better idea to use the PRNG interface for this purpose as that one allows re-seeding.

At the end you have to terminate the state:
\begin{verbatim}
Expand Down Expand Up @@ -1345,6 +1347,7 @@ \chapter{Stream Ciphers}
\begin{verbatim}
err = sober128_stream_keystream(&st, out_buffer, out_len);
\end{verbatim}
Note that it's probably a better idea to use the PRNG interface for this purpose as that one allows re-seeding.

At the end you have to terminate the state:
\begin{verbatim}
Expand Down

0 comments on commit dd01232

Please sign in to comment.