Skip to content

Commit b44155f

Browse files
authored
Merge pull request #431 from libtom/streams-add-single-call-crypt-functions
Streams - add single call crypt functions
2 parents e77ad63 + a2b343b commit b44155f

21 files changed

+518
-44
lines changed

doc/crypt.tex

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,6 +1301,12 @@ \chapter{Stream Ciphers}
13011301
err = chacha_done(&st);
13021302
\end{verbatim}
13031303

1304+
To encrypt plaintext (or decrypt ciphertext) using ChaCha for data already in
1305+
memory with a single function call, the following function may be used.
1306+
\begin{verbatim}
1307+
err = chacha_memory(key, keylen, iv, ivlen, datain, datalen, rounds, dataout);
1308+
\end{verbatim}
1309+
13041310
\mysection{Salsa20 and XSalsa20}
13051311

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

1370+
To encrypt plaintext (or decrypt ciphertext) using Salsa20 for data already in
1371+
memory with a single function call, the following function may be used.
1372+
\begin{verbatim}
1373+
err = salsa20_memory(key, keylen, iv, ivlen, datain, datalen, rounds, dataout);
1374+
\end{verbatim}
1375+
1376+
To encrypt plaintext (or decrypt ciphertext) using XSalsa20 for data already in
1377+
memory with a single function call, the following function may be used.
1378+
\begin{verbatim}
1379+
err = xsalsa20_memory(key, keylen, nonce, nonce_len, datain, datalen, rounds, dataout);
1380+
\end{verbatim}
1381+
13641382
For both \textit{Salsa20} and \textit{XSalsa20} rounds must be an even number
13651383
and if set to 0 the default number of rounds, 20, will be used.
13661384
\vspace{1mm}
@@ -1427,6 +1445,12 @@ \chapter{Stream Ciphers}
14271445
you do not need to re-run \textit{sosemanuk\_setup()} again, unless of course, you called
14281446
\textit{sosemanuk\_done()}.
14291447

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

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

1509+
To encrypt plaintext (or decrypt ciphertext) using Rabbit for data already in
1510+
memory with a single function call, the following function may be used.
1511+
\begin{verbatim}
1512+
err = rabbit_memory(key, keylen, iv, ivlen, datain, datalen, dataout);
1513+
\end{verbatim}
1514+
14851515
For more information, see: \newline
14861516
\hspace{4em}- \url{http://www.ecrypt.eu.org/stream/p3ciphers/rabbit/rabbit_p3.pdf} \newline
14871517
\hspace{4em}- \url{https://tools.ietf.org/html/rfc4503}
@@ -1515,6 +1545,12 @@ \chapter{Stream Ciphers}
15151545
err = rc4_stream_done(&st);
15161546
\end{verbatim}
15171547

1548+
To encrypt plaintext (or decrypt ciphertext) using RC6 for data already in
1549+
memory with a single function call, the following function may be used.
1550+
\begin{verbatim}
1551+
err = rc4_stream_memory(key, keylen, datain, datalen, dataout);
1552+
\end{verbatim}
1553+
15181554
\mysection{Sober128}
15191555

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

1581+
To encrypt plaintext (or decrypt ciphertext) using Sober128 for data already in
1582+
memory with a single function call, the following function may be used.
1583+
\begin{verbatim}
1584+
err = sober128_stream_memory(key, keylen, iv, ivlen, datain, datalen, dataout);
1585+
\end{verbatim}
1586+
15451587
\chapter{Authenticated Encryption}
15461588

15471589
Authenticated Encryption - sometimes also called Authenticated Encryption with Associated Data (AEAD) - is a variant of encryption

libtomcrypt_VS2008.vcproj

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2582,6 +2582,10 @@
25822582
RelativePath="src\stream\chacha\chacha_keystream.c"
25832583
>
25842584
</File>
2585+
<File
2586+
RelativePath="src\stream\chacha\chacha_memory.c"
2587+
>
2588+
</File>
25852589
<File
25862590
RelativePath="src\stream\chacha\chacha_setup.c"
25872591
>
@@ -2598,6 +2602,10 @@
25982602
RelativePath="src\stream\rabbit\rabbit.c"
25992603
>
26002604
</File>
2605+
<File
2606+
RelativePath="src\stream\rabbit\rabbit_memory.c"
2607+
>
2608+
</File>
26012609
</Filter>
26022610
<Filter
26032611
Name="rc4"
@@ -2606,6 +2614,10 @@
26062614
RelativePath="src\stream\rc4\rc4_stream.c"
26072615
>
26082616
</File>
2617+
<File
2618+
RelativePath="src\stream\rc4\rc4_stream_memory.c"
2619+
>
2620+
</File>
26092621
<File
26102622
RelativePath="src\stream\rc4\rc4_test.c"
26112623
>
@@ -2630,6 +2642,10 @@
26302642
RelativePath="src\stream\salsa20\salsa20_keystream.c"
26312643
>
26322644
</File>
2645+
<File
2646+
RelativePath="src\stream\salsa20\salsa20_memory.c"
2647+
>
2648+
</File>
26332649
<File
26342650
RelativePath="src\stream\salsa20\salsa20_setup.c"
26352651
>
@@ -2638,6 +2654,10 @@
26382654
RelativePath="src\stream\salsa20\salsa20_test.c"
26392655
>
26402656
</File>
2657+
<File
2658+
RelativePath="src\stream\salsa20\xsalsa20_memory.c"
2659+
>
2660+
</File>
26412661
<File
26422662
RelativePath="src\stream\salsa20\xsalsa20_setup.c"
26432663
>
@@ -2654,6 +2674,10 @@
26542674
RelativePath="src\stream\sober128\sober128_stream.c"
26552675
>
26562676
</File>
2677+
<File
2678+
RelativePath="src\stream\sober128\sober128_stream_memory.c"
2679+
>
2680+
</File>
26572681
<File
26582682
RelativePath="src\stream\sober128\sober128_test.c"
26592683
>
@@ -2710,6 +2734,10 @@
27102734
RelativePath="src\stream\sosemanuk\sosemanuk.c"
27112735
>
27122736
</File>
2737+
<File
2738+
RelativePath="src\stream\sosemanuk\sosemanuk_memory.c"
2739+
>
2740+
</File>
27132741
<File
27142742
RelativePath="src\stream\sosemanuk\sosemanuk_test.c"
27152743
>

makefile.mingw

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,14 +199,17 @@ src/pk/rsa/rsa_sign_saltlen_get.o src/pk/rsa/rsa_verify_hash.o src/prngs/chacha2
199199
src/prngs/rc4.o src/prngs/rng_get_bytes.o src/prngs/rng_make_prng.o src/prngs/sober128.o \
200200
src/prngs/sprng.o src/prngs/yarrow.o src/stream/chacha/chacha_crypt.o src/stream/chacha/chacha_done.o \
201201
src/stream/chacha/chacha_ivctr32.o src/stream/chacha/chacha_ivctr64.o \
202-
src/stream/chacha/chacha_keystream.o src/stream/chacha/chacha_setup.o src/stream/chacha/chacha_test.o \
203-
src/stream/rabbit/rabbit.o src/stream/rc4/rc4_stream.o src/stream/rc4/rc4_test.o \
204-
src/stream/salsa20/salsa20_crypt.o src/stream/salsa20/salsa20_done.o \
202+
src/stream/chacha/chacha_keystream.o src/stream/chacha/chacha_memory.o \
203+
src/stream/chacha/chacha_setup.o src/stream/chacha/chacha_test.o src/stream/rabbit/rabbit.o \
204+
src/stream/rabbit/rabbit_memory.o src/stream/rc4/rc4_stream.o src/stream/rc4/rc4_stream_memory.o \
205+
src/stream/rc4/rc4_test.o src/stream/salsa20/salsa20_crypt.o src/stream/salsa20/salsa20_done.o \
205206
src/stream/salsa20/salsa20_ivctr64.o src/stream/salsa20/salsa20_keystream.o \
206-
src/stream/salsa20/salsa20_setup.o src/stream/salsa20/salsa20_test.o \
207+
src/stream/salsa20/salsa20_memory.o src/stream/salsa20/salsa20_setup.o \
208+
src/stream/salsa20/salsa20_test.o src/stream/salsa20/xsalsa20_memory.o \
207209
src/stream/salsa20/xsalsa20_setup.o src/stream/salsa20/xsalsa20_test.o \
208-
src/stream/sober128/sober128_stream.o src/stream/sober128/sober128_test.o \
209-
src/stream/sosemanuk/sosemanuk.o src/stream/sosemanuk/sosemanuk_test.o
210+
src/stream/sober128/sober128_stream.o src/stream/sober128/sober128_stream_memory.o \
211+
src/stream/sober128/sober128_test.o src/stream/sosemanuk/sosemanuk.o \
212+
src/stream/sosemanuk/sosemanuk_memory.o src/stream/sosemanuk/sosemanuk_test.o
210213

211214
#List of test objects to compile
212215
TOBJECTS=tests/base16_test.o tests/base32_test.o tests/base64_test.o tests/cipher_hash_test.o \

makefile.msvc

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,14 +192,17 @@ src/pk/rsa/rsa_sign_saltlen_get.obj src/pk/rsa/rsa_verify_hash.obj src/prngs/cha
192192
src/prngs/rc4.obj src/prngs/rng_get_bytes.obj src/prngs/rng_make_prng.obj src/prngs/sober128.obj \
193193
src/prngs/sprng.obj src/prngs/yarrow.obj src/stream/chacha/chacha_crypt.obj src/stream/chacha/chacha_done.obj \
194194
src/stream/chacha/chacha_ivctr32.obj src/stream/chacha/chacha_ivctr64.obj \
195-
src/stream/chacha/chacha_keystream.obj src/stream/chacha/chacha_setup.obj src/stream/chacha/chacha_test.obj \
196-
src/stream/rabbit/rabbit.obj src/stream/rc4/rc4_stream.obj src/stream/rc4/rc4_test.obj \
197-
src/stream/salsa20/salsa20_crypt.obj src/stream/salsa20/salsa20_done.obj \
195+
src/stream/chacha/chacha_keystream.obj src/stream/chacha/chacha_memory.obj \
196+
src/stream/chacha/chacha_setup.obj src/stream/chacha/chacha_test.obj src/stream/rabbit/rabbit.obj \
197+
src/stream/rabbit/rabbit_memory.obj src/stream/rc4/rc4_stream.obj src/stream/rc4/rc4_stream_memory.obj \
198+
src/stream/rc4/rc4_test.obj src/stream/salsa20/salsa20_crypt.obj src/stream/salsa20/salsa20_done.obj \
198199
src/stream/salsa20/salsa20_ivctr64.obj src/stream/salsa20/salsa20_keystream.obj \
199-
src/stream/salsa20/salsa20_setup.obj src/stream/salsa20/salsa20_test.obj \
200+
src/stream/salsa20/salsa20_memory.obj src/stream/salsa20/salsa20_setup.obj \
201+
src/stream/salsa20/salsa20_test.obj src/stream/salsa20/xsalsa20_memory.obj \
200202
src/stream/salsa20/xsalsa20_setup.obj src/stream/salsa20/xsalsa20_test.obj \
201-
src/stream/sober128/sober128_stream.obj src/stream/sober128/sober128_test.obj \
202-
src/stream/sosemanuk/sosemanuk.obj src/stream/sosemanuk/sosemanuk_test.obj
203+
src/stream/sober128/sober128_stream.obj src/stream/sober128/sober128_stream_memory.obj \
204+
src/stream/sober128/sober128_test.obj src/stream/sosemanuk/sosemanuk.obj \
205+
src/stream/sosemanuk/sosemanuk_memory.obj src/stream/sosemanuk/sosemanuk_test.obj
203206

204207
#List of test objects to compile
205208
TOBJECTS=tests/base16_test.obj tests/base32_test.obj tests/base64_test.obj tests/cipher_hash_test.obj \

makefile.unix

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -209,14 +209,17 @@ src/pk/rsa/rsa_sign_saltlen_get.o src/pk/rsa/rsa_verify_hash.o src/prngs/chacha2
209209
src/prngs/rc4.o src/prngs/rng_get_bytes.o src/prngs/rng_make_prng.o src/prngs/sober128.o \
210210
src/prngs/sprng.o src/prngs/yarrow.o src/stream/chacha/chacha_crypt.o src/stream/chacha/chacha_done.o \
211211
src/stream/chacha/chacha_ivctr32.o src/stream/chacha/chacha_ivctr64.o \
212-
src/stream/chacha/chacha_keystream.o src/stream/chacha/chacha_setup.o src/stream/chacha/chacha_test.o \
213-
src/stream/rabbit/rabbit.o src/stream/rc4/rc4_stream.o src/stream/rc4/rc4_test.o \
214-
src/stream/salsa20/salsa20_crypt.o src/stream/salsa20/salsa20_done.o \
212+
src/stream/chacha/chacha_keystream.o src/stream/chacha/chacha_memory.o \
213+
src/stream/chacha/chacha_setup.o src/stream/chacha/chacha_test.o src/stream/rabbit/rabbit.o \
214+
src/stream/rabbit/rabbit_memory.o src/stream/rc4/rc4_stream.o src/stream/rc4/rc4_stream_memory.o \
215+
src/stream/rc4/rc4_test.o src/stream/salsa20/salsa20_crypt.o src/stream/salsa20/salsa20_done.o \
215216
src/stream/salsa20/salsa20_ivctr64.o src/stream/salsa20/salsa20_keystream.o \
216-
src/stream/salsa20/salsa20_setup.o src/stream/salsa20/salsa20_test.o \
217+
src/stream/salsa20/salsa20_memory.o src/stream/salsa20/salsa20_setup.o \
218+
src/stream/salsa20/salsa20_test.o src/stream/salsa20/xsalsa20_memory.o \
217219
src/stream/salsa20/xsalsa20_setup.o src/stream/salsa20/xsalsa20_test.o \
218-
src/stream/sober128/sober128_stream.o src/stream/sober128/sober128_test.o \
219-
src/stream/sosemanuk/sosemanuk.o src/stream/sosemanuk/sosemanuk_test.o
220+
src/stream/sober128/sober128_stream.o src/stream/sober128/sober128_stream_memory.o \
221+
src/stream/sober128/sober128_test.o src/stream/sosemanuk/sosemanuk.o \
222+
src/stream/sosemanuk/sosemanuk_memory.o src/stream/sosemanuk/sosemanuk_test.o
220223

221224
#List of test objects to compile (all goes to libtomcrypt_prof.a)
222225
TOBJECTS=tests/base16_test.o tests/base32_test.o tests/base64_test.o tests/cipher_hash_test.o \

makefile_include.mk

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -369,14 +369,17 @@ src/pk/rsa/rsa_sign_saltlen_get.o src/pk/rsa/rsa_verify_hash.o src/prngs/chacha2
369369
src/prngs/rc4.o src/prngs/rng_get_bytes.o src/prngs/rng_make_prng.o src/prngs/sober128.o \
370370
src/prngs/sprng.o src/prngs/yarrow.o src/stream/chacha/chacha_crypt.o src/stream/chacha/chacha_done.o \
371371
src/stream/chacha/chacha_ivctr32.o src/stream/chacha/chacha_ivctr64.o \
372-
src/stream/chacha/chacha_keystream.o src/stream/chacha/chacha_setup.o src/stream/chacha/chacha_test.o \
373-
src/stream/rabbit/rabbit.o src/stream/rc4/rc4_stream.o src/stream/rc4/rc4_test.o \
374-
src/stream/salsa20/salsa20_crypt.o src/stream/salsa20/salsa20_done.o \
372+
src/stream/chacha/chacha_keystream.o src/stream/chacha/chacha_memory.o \
373+
src/stream/chacha/chacha_setup.o src/stream/chacha/chacha_test.o src/stream/rabbit/rabbit.o \
374+
src/stream/rabbit/rabbit_memory.o src/stream/rc4/rc4_stream.o src/stream/rc4/rc4_stream_memory.o \
375+
src/stream/rc4/rc4_test.o src/stream/salsa20/salsa20_crypt.o src/stream/salsa20/salsa20_done.o \
375376
src/stream/salsa20/salsa20_ivctr64.o src/stream/salsa20/salsa20_keystream.o \
376-
src/stream/salsa20/salsa20_setup.o src/stream/salsa20/salsa20_test.o \
377+
src/stream/salsa20/salsa20_memory.o src/stream/salsa20/salsa20_setup.o \
378+
src/stream/salsa20/salsa20_test.o src/stream/salsa20/xsalsa20_memory.o \
377379
src/stream/salsa20/xsalsa20_setup.o src/stream/salsa20/xsalsa20_test.o \
378-
src/stream/sober128/sober128_stream.o src/stream/sober128/sober128_test.o \
379-
src/stream/sosemanuk/sosemanuk.o src/stream/sosemanuk/sosemanuk_test.o
380+
src/stream/sober128/sober128_stream.o src/stream/sober128/sober128_stream_memory.o \
381+
src/stream/sober128/sober128_test.o src/stream/sosemanuk/sosemanuk.o \
382+
src/stream/sosemanuk/sosemanuk_memory.o src/stream/sosemanuk/sosemanuk_test.o
380383

381384
# List of test objects to compile (all goes to libtomcrypt_prof.a)
382385
TOBJECTS=tests/base16_test.o tests/base32_test.o tests/base64_test.o tests/cipher_hash_test.o \

src/headers/tomcrypt_cipher.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,6 +1009,9 @@ int chacha_crypt(chacha_state *st, const unsigned char *in, unsigned long inlen,
10091009
int chacha_keystream(chacha_state *st, unsigned char *out, unsigned long outlen);
10101010
int chacha_done(chacha_state *st);
10111011
int chacha_test(void);
1012+
int chacha_memory(const unsigned char *key, unsigned long keylen, unsigned long rounds,
1013+
const unsigned char *iv, unsigned long ivlen, ulong64 counter,
1014+
const unsigned char *datain, unsigned long datalen, unsigned char *dataout);
10121015

10131016
#endif /* LTC_CHACHA */
10141017

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

10321038
#endif /* LTC_SALSA20 */
10331039

@@ -1037,6 +1043,9 @@ int xsalsa20_setup(salsa20_state *st, const unsigned char *key, unsigned long
10371043
const unsigned char *nonce, unsigned long noncelen,
10381044
int rounds);
10391045
int xsalsa20_test(void);
1046+
int xsalsa20_memory(const unsigned char *key, unsigned long keylen, unsigned long rounds,
1047+
const unsigned char *nonce, unsigned long noncelen,
1048+
const unsigned char *datain, unsigned long datalen, unsigned char *dataout);
10401049

10411050
#endif /* LTC_XSALSA20 */
10421051

@@ -1061,6 +1070,10 @@ int sosemanuk_crypt(sosemanuk_state *st, const unsigned char *in, unsigned long
10611070
int sosemanuk_keystream(sosemanuk_state *st, unsigned char *out, unsigned long outlen);
10621071
int sosemanuk_done(sosemanuk_state *st);
10631072
int sosemanuk_test(void);
1073+
int sosemanuk_memory(const unsigned char *key, unsigned long keylen,
1074+
const unsigned char *iv, unsigned long ivlen,
1075+
const unsigned char *datain, unsigned long datalen,
1076+
unsigned char *dataout);
10641077

10651078
#endif /* LTC_SOSEMANUK */
10661079

@@ -1085,6 +1098,10 @@ int rabbit_crypt(rabbit_state* st, const unsigned char *in, unsigned long inlen,
10851098
int rabbit_keystream(rabbit_state* st, unsigned char *out, unsigned long outlen);
10861099
int rabbit_done(rabbit_state *st);
10871100
int rabbit_test(void);
1101+
int rabbit_memory(const unsigned char *key, unsigned long keylen,
1102+
const unsigned char *iv, unsigned long ivlen,
1103+
const unsigned char *datain, unsigned long datalen,
1104+
unsigned char *dataout);
10881105

10891106
#endif /* LTC_RABBIT */
10901107

@@ -1100,6 +1117,9 @@ int rc4_stream_crypt(rc4_state *st, const unsigned char *in, unsigned long inlen
11001117
int rc4_stream_keystream(rc4_state *st, unsigned char *out, unsigned long outlen);
11011118
int rc4_stream_done(rc4_state *st);
11021119
int rc4_stream_test(void);
1120+
int rc4_stream_memory(const unsigned char *key, unsigned long keylen,
1121+
const unsigned char *datain, unsigned long datalen,
1122+
unsigned char *dataout);
11031123

11041124
#endif /* LTC_RC4_STREAM */
11051125

@@ -1119,6 +1139,10 @@ int sober128_stream_crypt(sober128_state *st, const unsigned char *in, unsigned
11191139
int sober128_stream_keystream(sober128_state *st, unsigned char *out, unsigned long outlen);
11201140
int sober128_stream_done(sober128_state *st);
11211141
int sober128_stream_test(void);
1142+
int sober128_stream_memory(const unsigned char *key, unsigned long keylen,
1143+
const unsigned char *iv, unsigned long ivlen,
1144+
const unsigned char *datain, unsigned long datalen,
1145+
unsigned char *dataout);
11221146

11231147
#endif /* LTC_SOBER128_STREAM */
11241148

src/stream/chacha/chacha_memory.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
2+
*
3+
* LibTomCrypt is a library that provides various cryptographic
4+
* algorithms in a highly modular and flexible manner.
5+
*
6+
* The library is free for all purposes without any express
7+
* guarantee it works.
8+
*/
9+
10+
#include "tomcrypt_private.h"
11+
12+
#ifdef LTC_CHACHA
13+
14+
/**
15+
Encrypt (or decrypt) bytes of ciphertext (or plaintext) with ChaCha
16+
@param key The key
17+
@param keylen The key length
18+
@param iv The initial vector
19+
@param ivlen The initial vector length
20+
@param datain The plaintext (or ciphertext)
21+
@param datalen The length of the input and output (octets)
22+
@param rounds The number of rounds
23+
@param dataout [out] The ciphertext (or plaintext)
24+
@return CRYPT_OK if successful
25+
*/
26+
int chacha_memory(const unsigned char *key, unsigned long keylen, unsigned long rounds,
27+
const unsigned char *iv, unsigned long ivlen, ulong64 counter,
28+
const unsigned char *datain, unsigned long datalen, unsigned char *dataout)
29+
{
30+
chacha_state st;
31+
int err;
32+
33+
LTC_ARGCHK(ivlen <= 8 || counter < 4294967296); /* 2**32 */
34+
35+
if ((err = chacha_setup(&st, key, keylen, rounds)) != CRYPT_OK) goto WIPE_KEY;
36+
if (ivlen > 8) {
37+
if ((err = chacha_ivctr32(&st, iv, ivlen, counter)) != CRYPT_OK) goto WIPE_KEY;
38+
} else {
39+
if ((err = chacha_ivctr64(&st, iv, ivlen, counter)) != CRYPT_OK) goto WIPE_KEY;
40+
}
41+
err = chacha_crypt(&st, datain, datalen, dataout);
42+
WIPE_KEY:
43+
chacha_done(&st);
44+
return err;
45+
}
46+
47+
#endif /* LTC_CHACHA */
48+
49+
/* ref: $Format:%D$ */
50+
/* git commit: $Format:%H$ */
51+
/* commit time: $Format:%ai$ */

0 commit comments

Comments
 (0)