Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions doc/crypt.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1301,6 +1301,12 @@ \chapter{Stream Ciphers}
err = chacha_done(&st);
\end{verbatim}

To encrypt plaintext (or decrypt ciphertext) using ChaCha for data already in
memory with a single function call, the following function may be used.
\begin{verbatim}
err = chacha_memory(key, keylen, iv, ivlen, datain, datalen, rounds, dataout);
\end{verbatim}

\mysection{Salsa20 and XSalsa20}

\textit{Salsa20} was Daniel Bernstein's submission to the EU eSTREAM
Expand Down Expand Up @@ -1361,6 +1367,18 @@ \chapter{Stream Ciphers}
err = salsa20_done(&st);
\end{verbatim}

To encrypt plaintext (or decrypt ciphertext) using Salsa20 for data already in
memory with a single function call, the following function may be used.
\begin{verbatim}
err = salsa20_memory(key, keylen, iv, ivlen, datain, datalen, rounds, dataout);
\end{verbatim}

To encrypt plaintext (or decrypt ciphertext) using XSalsa20 for data already in
memory with a single function call, the following function may be used.
\begin{verbatim}
err = xsalsa20_memory(key, keylen, nonce, nonce_len, datain, datalen, rounds, dataout);
\end{verbatim}

For both \textit{Salsa20} and \textit{XSalsa20} rounds must be an even number
and if set to 0 the default number of rounds, 20, will be used.
\vspace{1mm}
Expand Down Expand Up @@ -1427,6 +1445,12 @@ \chapter{Stream Ciphers}
you do not need to re-run \textit{sosemanuk\_setup()} again, unless of course, you called
\textit{sosemanuk\_done()}.

To encrypt plaintext (or decrypt ciphertext) using Sosemanuk for data already in
memory with a single function call, the following function may be used.
\begin{verbatim}
err = sosemanuk_memory(key, keylen, iv, ivlen, datain, datalen, dataout);
\end{verbatim}

\mysection{Rabbit}

\textit{Rabbit}, along with Salsa20, Sosemanuk, and HC-128, was named one of the winners
Expand Down Expand Up @@ -1482,6 +1506,12 @@ \chapter{Stream Ciphers}
You will want to use a different IV but you do not need to call \textit{rabbit\_setup()} a 2nd time,
unless of course, you skipped calling \textit{rabbit\_setiv()}.

To encrypt plaintext (or decrypt ciphertext) using Rabbit for data already in
memory with a single function call, the following function may be used.
\begin{verbatim}
err = rabbit_memory(key, keylen, iv, ivlen, datain, datalen, dataout);
\end{verbatim}

For more information, see: \newline
\hspace{4em}- \url{http://www.ecrypt.eu.org/stream/p3ciphers/rabbit/rabbit_p3.pdf} \newline
\hspace{4em}- \url{https://tools.ietf.org/html/rfc4503}
Expand Down Expand Up @@ -1515,6 +1545,12 @@ \chapter{Stream Ciphers}
err = rc4_stream_done(&st);
\end{verbatim}

To encrypt plaintext (or decrypt ciphertext) using RC6 for data already in
memory with a single function call, the following function may be used.
\begin{verbatim}
err = rc4_stream_memory(key, keylen, datain, datalen, dataout);
\end{verbatim}

\mysection{Sober128}

Supported key size: must be multiple of 4 bytes
Expand Down Expand Up @@ -1542,6 +1578,12 @@ \chapter{Stream Ciphers}
err = sober128_stream_done(&st);
\end{verbatim}

To encrypt plaintext (or decrypt ciphertext) using Sober128 for data already in
memory with a single function call, the following function may be used.
\begin{verbatim}
err = sober128_stream_memory(key, keylen, iv, ivlen, datain, datalen, dataout);
\end{verbatim}

\chapter{Authenticated Encryption}

Authenticated Encryption - sometimes also called Authenticated Encryption with Associated Data (AEAD) - is a variant of encryption
Expand Down
28 changes: 28 additions & 0 deletions libtomcrypt_VS2008.vcproj
Original file line number Diff line number Diff line change
Expand Up @@ -2582,6 +2582,10 @@
RelativePath="src\stream\chacha\chacha_keystream.c"
>
</File>
<File
RelativePath="src\stream\chacha\chacha_memory.c"
>
</File>
<File
RelativePath="src\stream\chacha\chacha_setup.c"
>
Expand All @@ -2598,6 +2602,10 @@
RelativePath="src\stream\rabbit\rabbit.c"
>
</File>
<File
RelativePath="src\stream\rabbit\rabbit_memory.c"
>
</File>
</Filter>
<Filter
Name="rc4"
Expand All @@ -2606,6 +2614,10 @@
RelativePath="src\stream\rc4\rc4_stream.c"
>
</File>
<File
RelativePath="src\stream\rc4\rc4_stream_memory.c"
>
</File>
<File
RelativePath="src\stream\rc4\rc4_test.c"
>
Expand All @@ -2630,6 +2642,10 @@
RelativePath="src\stream\salsa20\salsa20_keystream.c"
>
</File>
<File
RelativePath="src\stream\salsa20\salsa20_memory.c"
>
</File>
<File
RelativePath="src\stream\salsa20\salsa20_setup.c"
>
Expand All @@ -2638,6 +2654,10 @@
RelativePath="src\stream\salsa20\salsa20_test.c"
>
</File>
<File
RelativePath="src\stream\salsa20\xsalsa20_memory.c"
>
</File>
<File
RelativePath="src\stream\salsa20\xsalsa20_setup.c"
>
Expand All @@ -2654,6 +2674,10 @@
RelativePath="src\stream\sober128\sober128_stream.c"
>
</File>
<File
RelativePath="src\stream\sober128\sober128_stream_memory.c"
>
</File>
<File
RelativePath="src\stream\sober128\sober128_test.c"
>
Expand Down Expand Up @@ -2710,6 +2734,10 @@
RelativePath="src\stream\sosemanuk\sosemanuk.c"
>
</File>
<File
RelativePath="src\stream\sosemanuk\sosemanuk_memory.c"
>
</File>
<File
RelativePath="src\stream\sosemanuk\sosemanuk_test.c"
>
Expand Down
15 changes: 9 additions & 6 deletions makefile.mingw
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,17 @@ src/pk/rsa/rsa_sign_saltlen_get.o src/pk/rsa/rsa_verify_hash.o src/prngs/chacha2
src/prngs/rc4.o src/prngs/rng_get_bytes.o src/prngs/rng_make_prng.o src/prngs/sober128.o \
src/prngs/sprng.o src/prngs/yarrow.o src/stream/chacha/chacha_crypt.o src/stream/chacha/chacha_done.o \
src/stream/chacha/chacha_ivctr32.o src/stream/chacha/chacha_ivctr64.o \
src/stream/chacha/chacha_keystream.o src/stream/chacha/chacha_setup.o src/stream/chacha/chacha_test.o \
src/stream/rabbit/rabbit.o src/stream/rc4/rc4_stream.o src/stream/rc4/rc4_test.o \
src/stream/salsa20/salsa20_crypt.o src/stream/salsa20/salsa20_done.o \
src/stream/chacha/chacha_keystream.o src/stream/chacha/chacha_memory.o \
src/stream/chacha/chacha_setup.o src/stream/chacha/chacha_test.o src/stream/rabbit/rabbit.o \
src/stream/rabbit/rabbit_memory.o src/stream/rc4/rc4_stream.o src/stream/rc4/rc4_stream_memory.o \
src/stream/rc4/rc4_test.o src/stream/salsa20/salsa20_crypt.o src/stream/salsa20/salsa20_done.o \
src/stream/salsa20/salsa20_ivctr64.o src/stream/salsa20/salsa20_keystream.o \
src/stream/salsa20/salsa20_setup.o src/stream/salsa20/salsa20_test.o \
src/stream/salsa20/salsa20_memory.o src/stream/salsa20/salsa20_setup.o \
src/stream/salsa20/salsa20_test.o src/stream/salsa20/xsalsa20_memory.o \
src/stream/salsa20/xsalsa20_setup.o src/stream/salsa20/xsalsa20_test.o \
src/stream/sober128/sober128_stream.o src/stream/sober128/sober128_test.o \
src/stream/sosemanuk/sosemanuk.o src/stream/sosemanuk/sosemanuk_test.o
src/stream/sober128/sober128_stream.o src/stream/sober128/sober128_stream_memory.o \
src/stream/sober128/sober128_test.o src/stream/sosemanuk/sosemanuk.o \
src/stream/sosemanuk/sosemanuk_memory.o src/stream/sosemanuk/sosemanuk_test.o

#List of test objects to compile
TOBJECTS=tests/base16_test.o tests/base32_test.o tests/base64_test.o tests/cipher_hash_test.o \
Expand Down
15 changes: 9 additions & 6 deletions makefile.msvc
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,17 @@ src/pk/rsa/rsa_sign_saltlen_get.obj src/pk/rsa/rsa_verify_hash.obj src/prngs/cha
src/prngs/rc4.obj src/prngs/rng_get_bytes.obj src/prngs/rng_make_prng.obj src/prngs/sober128.obj \
src/prngs/sprng.obj src/prngs/yarrow.obj src/stream/chacha/chacha_crypt.obj src/stream/chacha/chacha_done.obj \
src/stream/chacha/chacha_ivctr32.obj src/stream/chacha/chacha_ivctr64.obj \
src/stream/chacha/chacha_keystream.obj src/stream/chacha/chacha_setup.obj src/stream/chacha/chacha_test.obj \
src/stream/rabbit/rabbit.obj src/stream/rc4/rc4_stream.obj src/stream/rc4/rc4_test.obj \
src/stream/salsa20/salsa20_crypt.obj src/stream/salsa20/salsa20_done.obj \
src/stream/chacha/chacha_keystream.obj src/stream/chacha/chacha_memory.obj \
src/stream/chacha/chacha_setup.obj src/stream/chacha/chacha_test.obj src/stream/rabbit/rabbit.obj \
src/stream/rabbit/rabbit_memory.obj src/stream/rc4/rc4_stream.obj src/stream/rc4/rc4_stream_memory.obj \
src/stream/rc4/rc4_test.obj src/stream/salsa20/salsa20_crypt.obj src/stream/salsa20/salsa20_done.obj \
src/stream/salsa20/salsa20_ivctr64.obj src/stream/salsa20/salsa20_keystream.obj \
src/stream/salsa20/salsa20_setup.obj src/stream/salsa20/salsa20_test.obj \
src/stream/salsa20/salsa20_memory.obj src/stream/salsa20/salsa20_setup.obj \
src/stream/salsa20/salsa20_test.obj src/stream/salsa20/xsalsa20_memory.obj \
src/stream/salsa20/xsalsa20_setup.obj src/stream/salsa20/xsalsa20_test.obj \
src/stream/sober128/sober128_stream.obj src/stream/sober128/sober128_test.obj \
src/stream/sosemanuk/sosemanuk.obj src/stream/sosemanuk/sosemanuk_test.obj
src/stream/sober128/sober128_stream.obj src/stream/sober128/sober128_stream_memory.obj \
src/stream/sober128/sober128_test.obj src/stream/sosemanuk/sosemanuk.obj \
src/stream/sosemanuk/sosemanuk_memory.obj src/stream/sosemanuk/sosemanuk_test.obj

#List of test objects to compile
TOBJECTS=tests/base16_test.obj tests/base32_test.obj tests/base64_test.obj tests/cipher_hash_test.obj \
Expand Down
15 changes: 9 additions & 6 deletions makefile.unix
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,17 @@ src/pk/rsa/rsa_sign_saltlen_get.o src/pk/rsa/rsa_verify_hash.o src/prngs/chacha2
src/prngs/rc4.o src/prngs/rng_get_bytes.o src/prngs/rng_make_prng.o src/prngs/sober128.o \
src/prngs/sprng.o src/prngs/yarrow.o src/stream/chacha/chacha_crypt.o src/stream/chacha/chacha_done.o \
src/stream/chacha/chacha_ivctr32.o src/stream/chacha/chacha_ivctr64.o \
src/stream/chacha/chacha_keystream.o src/stream/chacha/chacha_setup.o src/stream/chacha/chacha_test.o \
src/stream/rabbit/rabbit.o src/stream/rc4/rc4_stream.o src/stream/rc4/rc4_test.o \
src/stream/salsa20/salsa20_crypt.o src/stream/salsa20/salsa20_done.o \
src/stream/chacha/chacha_keystream.o src/stream/chacha/chacha_memory.o \
src/stream/chacha/chacha_setup.o src/stream/chacha/chacha_test.o src/stream/rabbit/rabbit.o \
src/stream/rabbit/rabbit_memory.o src/stream/rc4/rc4_stream.o src/stream/rc4/rc4_stream_memory.o \
src/stream/rc4/rc4_test.o src/stream/salsa20/salsa20_crypt.o src/stream/salsa20/salsa20_done.o \
src/stream/salsa20/salsa20_ivctr64.o src/stream/salsa20/salsa20_keystream.o \
src/stream/salsa20/salsa20_setup.o src/stream/salsa20/salsa20_test.o \
src/stream/salsa20/salsa20_memory.o src/stream/salsa20/salsa20_setup.o \
src/stream/salsa20/salsa20_test.o src/stream/salsa20/xsalsa20_memory.o \
src/stream/salsa20/xsalsa20_setup.o src/stream/salsa20/xsalsa20_test.o \
src/stream/sober128/sober128_stream.o src/stream/sober128/sober128_test.o \
src/stream/sosemanuk/sosemanuk.o src/stream/sosemanuk/sosemanuk_test.o
src/stream/sober128/sober128_stream.o src/stream/sober128/sober128_stream_memory.o \
src/stream/sober128/sober128_test.o src/stream/sosemanuk/sosemanuk.o \
src/stream/sosemanuk/sosemanuk_memory.o src/stream/sosemanuk/sosemanuk_test.o

#List of test objects to compile (all goes to libtomcrypt_prof.a)
TOBJECTS=tests/base16_test.o tests/base32_test.o tests/base64_test.o tests/cipher_hash_test.o \
Expand Down
15 changes: 9 additions & 6 deletions makefile_include.mk
Original file line number Diff line number Diff line change
Expand Up @@ -369,14 +369,17 @@ src/pk/rsa/rsa_sign_saltlen_get.o src/pk/rsa/rsa_verify_hash.o src/prngs/chacha2
src/prngs/rc4.o src/prngs/rng_get_bytes.o src/prngs/rng_make_prng.o src/prngs/sober128.o \
src/prngs/sprng.o src/prngs/yarrow.o src/stream/chacha/chacha_crypt.o src/stream/chacha/chacha_done.o \
src/stream/chacha/chacha_ivctr32.o src/stream/chacha/chacha_ivctr64.o \
src/stream/chacha/chacha_keystream.o src/stream/chacha/chacha_setup.o src/stream/chacha/chacha_test.o \
src/stream/rabbit/rabbit.o src/stream/rc4/rc4_stream.o src/stream/rc4/rc4_test.o \
src/stream/salsa20/salsa20_crypt.o src/stream/salsa20/salsa20_done.o \
src/stream/chacha/chacha_keystream.o src/stream/chacha/chacha_memory.o \
src/stream/chacha/chacha_setup.o src/stream/chacha/chacha_test.o src/stream/rabbit/rabbit.o \
src/stream/rabbit/rabbit_memory.o src/stream/rc4/rc4_stream.o src/stream/rc4/rc4_stream_memory.o \
src/stream/rc4/rc4_test.o src/stream/salsa20/salsa20_crypt.o src/stream/salsa20/salsa20_done.o \
src/stream/salsa20/salsa20_ivctr64.o src/stream/salsa20/salsa20_keystream.o \
src/stream/salsa20/salsa20_setup.o src/stream/salsa20/salsa20_test.o \
src/stream/salsa20/salsa20_memory.o src/stream/salsa20/salsa20_setup.o \
src/stream/salsa20/salsa20_test.o src/stream/salsa20/xsalsa20_memory.o \
src/stream/salsa20/xsalsa20_setup.o src/stream/salsa20/xsalsa20_test.o \
src/stream/sober128/sober128_stream.o src/stream/sober128/sober128_test.o \
src/stream/sosemanuk/sosemanuk.o src/stream/sosemanuk/sosemanuk_test.o
src/stream/sober128/sober128_stream.o src/stream/sober128/sober128_stream_memory.o \
src/stream/sober128/sober128_test.o src/stream/sosemanuk/sosemanuk.o \
src/stream/sosemanuk/sosemanuk_memory.o src/stream/sosemanuk/sosemanuk_test.o

# List of test objects to compile (all goes to libtomcrypt_prof.a)
TOBJECTS=tests/base16_test.o tests/base32_test.o tests/base64_test.o tests/cipher_hash_test.o \
Expand Down
24 changes: 24 additions & 0 deletions src/headers/tomcrypt_cipher.h
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,9 @@ int chacha_crypt(chacha_state *st, const unsigned char *in, unsigned long inlen,
int chacha_keystream(chacha_state *st, unsigned char *out, unsigned long outlen);
int chacha_done(chacha_state *st);
int chacha_test(void);
int chacha_memory(const unsigned char *key, unsigned long keylen, unsigned long rounds,
const unsigned char *iv, unsigned long ivlen, ulong64 counter,
const unsigned char *datain, unsigned long datalen, unsigned char *dataout);

#endif /* LTC_CHACHA */

Expand All @@ -1028,6 +1031,9 @@ int salsa20_crypt(salsa20_state *st, const unsigned char *in, unsigned long inle
int salsa20_keystream(salsa20_state *st, unsigned char *out, unsigned long outlen);
int salsa20_done(salsa20_state *st);
int salsa20_test(void);
int salsa20_memory(const unsigned char *key, unsigned long keylen, unsigned long rounds,
const unsigned char *iv, unsigned long ivlen, ulong64 counter,
const unsigned char *datain, unsigned long datalen, unsigned char *dataout);

#endif /* LTC_SALSA20 */

Expand All @@ -1037,6 +1043,9 @@ int xsalsa20_setup(salsa20_state *st, const unsigned char *key, unsigned long
const unsigned char *nonce, unsigned long noncelen,
int rounds);
int xsalsa20_test(void);
int xsalsa20_memory(const unsigned char *key, unsigned long keylen, unsigned long rounds,
const unsigned char *nonce, unsigned long noncelen,
const unsigned char *datain, unsigned long datalen, unsigned char *dataout);

#endif /* LTC_XSALSA20 */

Expand All @@ -1061,6 +1070,10 @@ int sosemanuk_crypt(sosemanuk_state *st, const unsigned char *in, unsigned long
int sosemanuk_keystream(sosemanuk_state *st, unsigned char *out, unsigned long outlen);
int sosemanuk_done(sosemanuk_state *st);
int sosemanuk_test(void);
int sosemanuk_memory(const unsigned char *key, unsigned long keylen,
const unsigned char *iv, unsigned long ivlen,
const unsigned char *datain, unsigned long datalen,
unsigned char *dataout);

#endif /* LTC_SOSEMANUK */

Expand All @@ -1085,6 +1098,10 @@ int rabbit_crypt(rabbit_state* st, const unsigned char *in, unsigned long inlen,
int rabbit_keystream(rabbit_state* st, unsigned char *out, unsigned long outlen);
int rabbit_done(rabbit_state *st);
int rabbit_test(void);
int rabbit_memory(const unsigned char *key, unsigned long keylen,
const unsigned char *iv, unsigned long ivlen,
const unsigned char *datain, unsigned long datalen,
unsigned char *dataout);

#endif /* LTC_RABBIT */

Expand All @@ -1100,6 +1117,9 @@ int rc4_stream_crypt(rc4_state *st, const unsigned char *in, unsigned long inlen
int rc4_stream_keystream(rc4_state *st, unsigned char *out, unsigned long outlen);
int rc4_stream_done(rc4_state *st);
int rc4_stream_test(void);
int rc4_stream_memory(const unsigned char *key, unsigned long keylen,
const unsigned char *datain, unsigned long datalen,
unsigned char *dataout);

#endif /* LTC_RC4_STREAM */

Expand All @@ -1119,6 +1139,10 @@ int sober128_stream_crypt(sober128_state *st, const unsigned char *in, unsigned
int sober128_stream_keystream(sober128_state *st, unsigned char *out, unsigned long outlen);
int sober128_stream_done(sober128_state *st);
int sober128_stream_test(void);
int sober128_stream_memory(const unsigned char *key, unsigned long keylen,
const unsigned char *iv, unsigned long ivlen,
const unsigned char *datain, unsigned long datalen,
unsigned char *dataout);

#endif /* LTC_SOBER128_STREAM */

Expand Down
51 changes: 51 additions & 0 deletions src/stream/chacha/chacha_memory.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
*
* LibTomCrypt is a library that provides various cryptographic
* algorithms in a highly modular and flexible manner.
*
* The library is free for all purposes without any express
* guarantee it works.
*/

#include "tomcrypt_private.h"

#ifdef LTC_CHACHA

/**
Encrypt (or decrypt) bytes of ciphertext (or plaintext) with ChaCha
@param key The key
@param keylen The key length
@param iv The initial vector
@param ivlen The initial vector length
@param datain The plaintext (or ciphertext)
@param datalen The length of the input and output (octets)
@param rounds The number of rounds
@param dataout [out] The ciphertext (or plaintext)
@return CRYPT_OK if successful
*/
int chacha_memory(const unsigned char *key, unsigned long keylen, unsigned long rounds,
const unsigned char *iv, unsigned long ivlen, ulong64 counter,
const unsigned char *datain, unsigned long datalen, unsigned char *dataout)
{
chacha_state st;
int err;

LTC_ARGCHK(ivlen <= 8 || counter < 4294967296); /* 2**32 */

if ((err = chacha_setup(&st, key, keylen, rounds)) != CRYPT_OK) goto WIPE_KEY;
if (ivlen > 8) {
if ((err = chacha_ivctr32(&st, iv, ivlen, counter)) != CRYPT_OK) goto WIPE_KEY;
} else {
if ((err = chacha_ivctr64(&st, iv, ivlen, counter)) != CRYPT_OK) goto WIPE_KEY;
}
err = chacha_crypt(&st, datain, datalen, dataout);
WIPE_KEY:
chacha_done(&st);
return err;
}

#endif /* LTC_CHACHA */

/* ref: $Format:%D$ */
/* git commit: $Format:%H$ */
/* commit time: $Format:%ai$ */
Loading