1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
3  *
4  * LibTomCrypt is a library that provides various cryptographic
5  * algorithms in a highly modular and flexible manner.
6  *
7  * The library is free for all purposes without any express
8  * guarantee it works.
9  */
10 
11 #ifdef LTC_HMAC
12 typedef struct Hmac_state {
13      hash_state     md;
14      int            hash;
15      hash_state     hashstate;
16      unsigned char  key[MAXBLOCKSIZE];
17 } hmac_state;
18 
19 int hmac_init(hmac_state *hmac, int hash, const unsigned char *key, unsigned long keylen);
20 int hmac_process(hmac_state *hmac, const unsigned char *in, unsigned long inlen);
21 int hmac_done(hmac_state *hmac, unsigned char *out, unsigned long *outlen);
22 int hmac_test(void);
23 int hmac_memory(int hash,
24                 const unsigned char *key, unsigned long keylen,
25                 const unsigned char *in,  unsigned long inlen,
26                       unsigned char *out, unsigned long *outlen);
27 int hmac_memory_multi(int hash,
28                 const unsigned char *key,  unsigned long keylen,
29                       unsigned char *out,  unsigned long *outlen,
30                 const unsigned char *in,   unsigned long inlen, ...);
31 int hmac_file(int hash, const char *fname, const unsigned char *key,
32               unsigned long keylen,
33               unsigned char *out, unsigned long *outlen);
34 #endif
35 
36 #ifdef LTC_OMAC
37 
38 typedef struct {
39    int             cipher_idx,
40                    buflen,
41                    blklen;
42    unsigned char   block[MAXBLOCKSIZE],
43                    prev[MAXBLOCKSIZE],
44                    Lu[2][MAXBLOCKSIZE];
45    symmetric_key   key;
46 } omac_state;
47 
48 int omac_init(omac_state *omac, int cipher, const unsigned char *key, unsigned long keylen);
49 int omac_process(omac_state *omac, const unsigned char *in, unsigned long inlen);
50 int omac_done(omac_state *omac, unsigned char *out, unsigned long *outlen);
51 int omac_memory(int cipher,
52                const unsigned char *key, unsigned long keylen,
53                const unsigned char *in,  unsigned long inlen,
54                      unsigned char *out, unsigned long *outlen);
55 int omac_memory_multi(int cipher,
56                 const unsigned char *key, unsigned long keylen,
57                       unsigned char *out, unsigned long *outlen,
58                 const unsigned char *in,  unsigned long inlen, ...);
59 int omac_file(int cipher,
60               const unsigned char *key, unsigned long keylen,
61               const          char *filename,
62                     unsigned char *out, unsigned long *outlen);
63 int omac_test(void);
64 #endif /* LTC_OMAC */
65 
66 #ifdef LTC_PMAC
67 
68 typedef struct {
69    unsigned char     Ls[32][MAXBLOCKSIZE],    /* L shifted by i bits to the left */
70                      Li[MAXBLOCKSIZE],        /* value of Li [current value, we calc from previous recall] */
71                      Lr[MAXBLOCKSIZE],        /* L * x^-1 */
72                      block[MAXBLOCKSIZE],     /* currently accumulated block */
73                      checksum[MAXBLOCKSIZE];  /* current checksum */
74 
75    symmetric_key     key;                     /* scheduled key for cipher */
76    unsigned long     block_index;             /* index # for current block */
77    int               cipher_idx,              /* cipher idx */
78                      block_len,               /* length of block */
79                      buflen;                  /* number of bytes in the buffer */
80 } pmac_state;
81 
82 int pmac_init(pmac_state *pmac, int cipher, const unsigned char *key, unsigned long keylen);
83 int pmac_process(pmac_state *pmac, const unsigned char *in, unsigned long inlen);
84 int pmac_done(pmac_state *pmac, unsigned char *out, unsigned long *outlen);
85 
86 int pmac_memory(int cipher,
87                const unsigned char *key, unsigned long keylen,
88                const unsigned char *in, unsigned long inlen,
89                      unsigned char *out, unsigned long *outlen);
90 
91 int pmac_memory_multi(int cipher,
92                 const unsigned char *key, unsigned long keylen,
93                       unsigned char *out, unsigned long *outlen,
94                 const unsigned char *in, unsigned long inlen, ...);
95 
96 int pmac_file(int cipher,
97              const unsigned char *key, unsigned long keylen,
98              const          char *filename,
99                    unsigned char *out, unsigned long *outlen);
100 
101 int pmac_test(void);
102 
103 /* internal functions */
104 int pmac_ntz(unsigned long x);
105 void pmac_shift_xor(pmac_state *pmac);
106 
107 #endif /* PMAC */
108 
109 #ifdef LTC_POLY1305
110 typedef struct {
111    ulong32 r[5];
112    ulong32 h[5];
113    ulong32 pad[4];
114    unsigned long leftover;
115    unsigned char buffer[16];
116    int final;
117 } poly1305_state;
118 
119 int poly1305_init(poly1305_state *st, const unsigned char *key, unsigned long keylen);
120 int poly1305_process(poly1305_state *st, const unsigned char *in, unsigned long inlen);
121 int poly1305_done(poly1305_state *st, unsigned char *mac, unsigned long *maclen);
122 int poly1305_memory(const unsigned char *key, unsigned long keylen, const unsigned char *in, unsigned long inlen, unsigned char *mac, unsigned long *maclen);
123 int poly1305_memory_multi(const unsigned char *key, unsigned long keylen, unsigned char *mac, unsigned long *maclen, const unsigned char *in,  unsigned long inlen, ...);
124 int poly1305_file(const char *fname, const unsigned char *key, unsigned long keylen, unsigned char *mac, unsigned long *maclen);
125 int poly1305_test(void);
126 #endif /* LTC_POLY1305 */
127 
128 #ifdef LTC_BLAKE2SMAC
129 typedef hash_state blake2smac_state;
130 int blake2smac_init(blake2smac_state *st, unsigned long outlen, const unsigned char *key, unsigned long keylen);
131 int blake2smac_process(blake2smac_state *st, const unsigned char *in, unsigned long inlen);
132 int blake2smac_done(blake2smac_state *st, unsigned char *mac, unsigned long *maclen);
133 int blake2smac_memory(const unsigned char *key, unsigned long keylen, const unsigned char *in, unsigned long inlen, unsigned char *mac, unsigned long *maclen);
134 int blake2smac_memory_multi(const unsigned char *key, unsigned long keylen, unsigned char *mac, unsigned long *maclen, const unsigned char *in,  unsigned long inlen, ...);
135 int blake2smac_file(const char *fname, const unsigned char *key, unsigned long keylen, unsigned char *mac, unsigned long *maclen);
136 int blake2smac_test(void);
137 #endif /* LTC_BLAKE2SMAC */
138 
139 #ifdef LTC_BLAKE2BMAC
140 typedef hash_state blake2bmac_state;
141 int blake2bmac_init(blake2bmac_state *st, unsigned long outlen, const unsigned char *key, unsigned long keylen);
142 int blake2bmac_process(blake2bmac_state *st, const unsigned char *in, unsigned long inlen);
143 int blake2bmac_done(blake2bmac_state *st, unsigned char *mac, unsigned long *maclen);
144 int blake2bmac_memory(const unsigned char *key, unsigned long keylen, const unsigned char *in, unsigned long inlen, unsigned char *mac, unsigned long *maclen);
145 int blake2bmac_memory_multi(const unsigned char *key, unsigned long keylen, unsigned char *mac, unsigned long *maclen, const unsigned char *in,  unsigned long inlen, ...);
146 int blake2bmac_file(const char *fname, const unsigned char *key, unsigned long keylen, unsigned char *mac, unsigned long *maclen);
147 int blake2bmac_test(void);
148 #endif /* LTC_BLAKE2BMAC */
149 
150 
151 #ifdef LTC_PELICAN
152 
153 typedef struct pelican_state
154 {
155     symmetric_key K;
156     unsigned char state[16];
157     int           buflen;
158 } pelican_state;
159 
160 int pelican_init(pelican_state *pelmac, const unsigned char *key, unsigned long keylen);
161 int pelican_process(pelican_state *pelmac, const unsigned char *in, unsigned long inlen);
162 int pelican_done(pelican_state *pelmac, unsigned char *out);
163 int pelican_test(void);
164 
165 int pelican_memory(const unsigned char *key, unsigned long keylen,
166                    const unsigned char *in, unsigned long inlen,
167                          unsigned char *out);
168 
169 #endif
170 
171 #ifdef LTC_XCBC
172 
173 /* add this to "keylen" to xcbc_init to use a pure three-key XCBC MAC */
174 #define LTC_XCBC_PURE  0x8000UL
175 
176 typedef struct {
177    unsigned char K[3][MAXBLOCKSIZE],
178                  IV[MAXBLOCKSIZE];
179 
180    symmetric_key key;
181 
182              int cipher,
183                  buflen,
184                  blocksize;
185 } xcbc_state;
186 
187 int xcbc_init(xcbc_state *xcbc, int cipher, const unsigned char *key, unsigned long keylen);
188 int xcbc_process(xcbc_state *xcbc, const unsigned char *in, unsigned long inlen);
189 int xcbc_done(xcbc_state *xcbc, unsigned char *out, unsigned long *outlen);
190 int xcbc_memory(int cipher,
191                const unsigned char *key, unsigned long keylen,
192                const unsigned char *in,  unsigned long inlen,
193                      unsigned char *out, unsigned long *outlen);
194 int xcbc_memory_multi(int cipher,
195                 const unsigned char *key, unsigned long keylen,
196                       unsigned char *out, unsigned long *outlen,
197                 const unsigned char *in,  unsigned long inlen, ...);
198 int xcbc_file(int cipher,
199               const unsigned char *key, unsigned long keylen,
200               const          char *filename,
201                     unsigned char *out, unsigned long *outlen);
202 int xcbc_test(void);
203 
204 #endif
205 
206 #ifdef LTC_F9_MODE
207 
208 typedef struct {
209    unsigned char akey[MAXBLOCKSIZE],
210                  ACC[MAXBLOCKSIZE],
211                  IV[MAXBLOCKSIZE];
212 
213    symmetric_key key;
214 
215              int cipher,
216                  buflen,
217                  keylen,
218                  blocksize;
219 } f9_state;
220 
221 int f9_init(f9_state *f9, int cipher, const unsigned char *key, unsigned long keylen);
222 int f9_process(f9_state *f9, const unsigned char *in, unsigned long inlen);
223 int f9_done(f9_state *f9, unsigned char *out, unsigned long *outlen);
224 int f9_memory(int cipher,
225                const unsigned char *key, unsigned long keylen,
226                const unsigned char *in,  unsigned long inlen,
227                      unsigned char *out, unsigned long *outlen);
228 int f9_memory_multi(int cipher,
229                 const unsigned char *key, unsigned long keylen,
230                       unsigned char *out, unsigned long *outlen,
231                 const unsigned char *in,  unsigned long inlen, ...);
232 int f9_file(int cipher,
233               const unsigned char *key, unsigned long keylen,
234               const          char *fname,
235                     unsigned char *out, unsigned long *outlen);
236 int f9_test(void);
237 
238 #endif
239 
240 /*
241  * ENC+AUTH modes
242  */
243 
244 #ifdef LTC_EAX_MODE
245 
246 #if !(defined(LTC_OMAC) && defined(LTC_CTR_MODE))
247    #error LTC_EAX_MODE requires LTC_OMAC and CTR
248 #endif
249 
250 typedef struct {
251    unsigned char N[MAXBLOCKSIZE];
252    symmetric_CTR ctr;
253    omac_state    headeromac, ctomac;
254 } eax_state;
255 
256 int eax_init(eax_state *eax, int cipher, const unsigned char *key, unsigned long keylen,
257              const unsigned char *nonce, unsigned long noncelen,
258              const unsigned char *header, unsigned long headerlen);
259 
260 int eax_encrypt(eax_state *eax, const unsigned char *pt, unsigned char *ct, unsigned long length);
261 int eax_decrypt(eax_state *eax, const unsigned char *ct, unsigned char *pt, unsigned long length);
262 int eax_addheader(eax_state *eax, const unsigned char *header, unsigned long length);
263 int eax_done(eax_state *eax, unsigned char *tag, unsigned long *taglen);
264 
265 int eax_encrypt_authenticate_memory(int cipher,
266     const unsigned char *key,    unsigned long keylen,
267     const unsigned char *nonce,  unsigned long noncelen,
268     const unsigned char *header, unsigned long headerlen,
269     const unsigned char *pt,     unsigned long ptlen,
270           unsigned char *ct,
271           unsigned char *tag,    unsigned long *taglen);
272 
273 int eax_decrypt_verify_memory(int cipher,
274     const unsigned char *key,    unsigned long keylen,
275     const unsigned char *nonce,  unsigned long noncelen,
276     const unsigned char *header, unsigned long headerlen,
277     const unsigned char *ct,     unsigned long ctlen,
278           unsigned char *pt,
279     const unsigned char *tag,    unsigned long taglen,
280           int           *stat);
281 
282  int eax_test(void);
283 #endif /* EAX MODE */
284 
285 #ifdef LTC_OCB_MODE
286 typedef struct {
287    unsigned char     L[MAXBLOCKSIZE],         /* L value */
288                      Ls[32][MAXBLOCKSIZE],    /* L shifted by i bits to the left */
289                      Li[MAXBLOCKSIZE],        /* value of Li [current value, we calc from previous recall] */
290                      Lr[MAXBLOCKSIZE],        /* L * x^-1 */
291                      R[MAXBLOCKSIZE],         /* R value */
292                      checksum[MAXBLOCKSIZE];  /* current checksum */
293 
294    symmetric_key     key;                     /* scheduled key for cipher */
295    unsigned long     block_index;             /* index # for current block */
296    int               cipher,                  /* cipher idx */
297                      block_len;               /* length of block */
298 } ocb_state;
299 
300 int ocb_init(ocb_state *ocb, int cipher,
301              const unsigned char *key, unsigned long keylen, const unsigned char *nonce);
302 
303 int ocb_encrypt(ocb_state *ocb, const unsigned char *pt, unsigned char *ct);
304 int ocb_decrypt(ocb_state *ocb, const unsigned char *ct, unsigned char *pt);
305 
306 int ocb_done_encrypt(ocb_state *ocb,
307                      const unsigned char *pt,  unsigned long ptlen,
308                            unsigned char *ct,
309                            unsigned char *tag, unsigned long *taglen);
310 
311 int ocb_done_decrypt(ocb_state *ocb,
312                      const unsigned char *ct,  unsigned long ctlen,
313                            unsigned char *pt,
314                      const unsigned char *tag, unsigned long taglen, int *stat);
315 
316 int ocb_encrypt_authenticate_memory(int cipher,
317     const unsigned char *key,    unsigned long keylen,
318     const unsigned char *nonce,
319     const unsigned char *pt,     unsigned long ptlen,
320           unsigned char *ct,
321           unsigned char *tag,    unsigned long *taglen);
322 
323 int ocb_decrypt_verify_memory(int cipher,
324     const unsigned char *key,    unsigned long keylen,
325     const unsigned char *nonce,
326     const unsigned char *ct,     unsigned long ctlen,
327           unsigned char *pt,
328     const unsigned char *tag,    unsigned long taglen,
329           int           *stat);
330 
331 int ocb_test(void);
332 
333 /* internal functions */
334 void ocb_shift_xor(ocb_state *ocb, unsigned char *Z);
335 int ocb_ntz(unsigned long x);
336 int s_ocb_done(ocb_state *ocb, const unsigned char *pt, unsigned long ptlen,
337                unsigned char *ct, unsigned char *tag, unsigned long *taglen, int mode);
338 
339 #endif /* LTC_OCB_MODE */
340 
341 #ifdef LTC_OCB3_MODE
342 typedef struct {
343    unsigned char     Offset_0[MAXBLOCKSIZE],       /* Offset_0 value */
344                      Offset_current[MAXBLOCKSIZE], /* Offset_{current_block_index} value */
345                      L_dollar[MAXBLOCKSIZE],       /* L_$ value */
346                      L_star[MAXBLOCKSIZE],         /* L_* value */
347                      L_[32][MAXBLOCKSIZE],         /* L_{i} values */
348                      tag_part[MAXBLOCKSIZE],       /* intermediate result of tag calculation */
349                      checksum[MAXBLOCKSIZE];       /* current checksum */
350 
351    /* AAD related members */
352    unsigned char     aSum_current[MAXBLOCKSIZE],    /* AAD related helper variable */
353                      aOffset_current[MAXBLOCKSIZE], /* AAD related helper variable */
354                      adata_buffer[MAXBLOCKSIZE];    /* AAD buffer */
355    int               adata_buffer_bytes;            /* bytes in AAD buffer */
356    unsigned long     ablock_index;                  /* index # for current adata (AAD) block */
357 
358    symmetric_key     key;                     /* scheduled key for cipher */
359    unsigned long     block_index;             /* index # for current data block */
360    int               cipher,                  /* cipher idx */
361                      tag_len,                 /* length of tag */
362                      block_len;               /* length of block */
363 } ocb3_state;
364 
365 int ocb3_init(ocb3_state *ocb, int cipher,
366              const unsigned char *key, unsigned long keylen,
367              const unsigned char *nonce, unsigned long noncelen,
368              unsigned long taglen);
369 
370 int ocb3_encrypt(ocb3_state *ocb, const unsigned char *pt, unsigned long ptlen, unsigned char *ct);
371 int ocb3_decrypt(ocb3_state *ocb, const unsigned char *ct, unsigned long ctlen, unsigned char *pt);
372 int ocb3_encrypt_last(ocb3_state *ocb, const unsigned char *pt, unsigned long ptlen, unsigned char *ct);
373 int ocb3_decrypt_last(ocb3_state *ocb, const unsigned char *ct, unsigned long ctlen, unsigned char *pt);
374 int ocb3_add_aad(ocb3_state *ocb, const unsigned char *aad, unsigned long aadlen);
375 int ocb3_done(ocb3_state *ocb, unsigned char *tag, unsigned long *taglen);
376 
377 int ocb3_encrypt_authenticate_memory(int cipher,
378     const unsigned char *key,    unsigned long keylen,
379     const unsigned char *nonce,  unsigned long noncelen,
380     const unsigned char *adata,  unsigned long adatalen,
381     const unsigned char *pt,     unsigned long ptlen,
382           unsigned char *ct,
383           unsigned char *tag,    unsigned long *taglen);
384 
385 int ocb3_decrypt_verify_memory(int cipher,
386     const unsigned char *key,    unsigned long keylen,
387     const unsigned char *nonce,  unsigned long noncelen,
388     const unsigned char *adata,  unsigned long adatalen,
389     const unsigned char *ct,     unsigned long ctlen,
390           unsigned char *pt,
391     const unsigned char *tag,    unsigned long taglen,
392           int           *stat);
393 
394 int ocb3_test(void);
395 
396 #endif /* LTC_OCB3_MODE */
397 
398 #ifdef LTC_CCM_MODE
399 
400 #define CCM_ENCRYPT LTC_ENCRYPT
401 #define CCM_DECRYPT LTC_DECRYPT
402 
403 typedef struct {
404    symmetric_key       K;
405    int                 cipher,               /* which cipher */
406                        taglen,               /* length of the tag */
407                        x;                    /* index in PAD */
408 
409    unsigned long       L,                    /* L value */
410                        ptlen,                /* length that will be enc / dec */
411                        current_ptlen,        /* current processed length */
412                        aadlen,               /* length of the aad */
413                        current_aadlen,       /* length of the currently provided add */
414                        noncelen;             /* length of the nonce */
415 
416    unsigned char       PAD[16],
417                        ctr[16],
418                        CTRPAD[16],
419                        CTRlen;
420 } ccm_state;
421 
422 int ccm_init(ccm_state *ccm, int cipher,
423              const unsigned char *key, int keylen, int ptlen, int taglen, int aadlen);
424 
425 int ccm_reset(ccm_state *ccm);
426 
427 int ccm_add_nonce(ccm_state *ccm,
428                   const unsigned char *nonce,     unsigned long noncelen);
429 
430 int ccm_add_aad(ccm_state *ccm,
431                 const unsigned char *adata,  unsigned long adatalen);
432 
433 int ccm_process(ccm_state *ccm,
434                 unsigned char *pt,     unsigned long ptlen,
435                 unsigned char *ct,
436                 int direction);
437 
438 int ccm_done(ccm_state *ccm,
439              unsigned char *tag,    unsigned long *taglen);
440 
441 int ccm_memory(int cipher,
442     const unsigned char *key,    unsigned long keylen,
443     symmetric_key       *uskey,
444     const unsigned char *nonce,  unsigned long noncelen,
445     const unsigned char *header, unsigned long headerlen,
446           unsigned char *pt,     unsigned long ptlen,
447           unsigned char *ct,
448           unsigned char *tag,    unsigned long *taglen,
449                     int  direction);
450 
451 int ccm_test(void);
452 
453 #endif /* LTC_CCM_MODE */
454 
455 #if defined(LRW_MODE) || defined(LTC_GCM_MODE)
456 void gcm_gf_mult(const unsigned char *a, const unsigned char *b, unsigned char *c);
457 #endif
458 
459 
460 /* table shared between GCM and LRW */
461 #if defined(LTC_GCM_TABLES) || defined(LTC_LRW_TABLES) || ((defined(LTC_GCM_MODE) || defined(LTC_GCM_MODE)) && defined(LTC_FAST))
462 extern const unsigned char gcm_shift_table[];
463 #endif
464 
465 #ifdef LTC_GCM_MODE
466 
467 #define GCM_ENCRYPT LTC_ENCRYPT
468 #define GCM_DECRYPT LTC_DECRYPT
469 
470 #define LTC_GCM_MODE_IV    0
471 #define LTC_GCM_MODE_AAD   1
472 #define LTC_GCM_MODE_TEXT  2
473 
474 typedef struct {
475    symmetric_key       K;
476    unsigned char       H[16],        /* multiplier */
477                        X[16],        /* accumulator */
478                        Y[16],        /* counter */
479                        Y_0[16],      /* initial counter */
480                        buf[16];      /* buffer for stuff */
481 
482    int                 cipher,       /* which cipher */
483                        ivmode,       /* Which mode is the IV in? */
484                        mode,         /* mode the GCM code is in */
485                        buflen;       /* length of data in buf */
486 
487    ulong64             totlen,       /* 64-bit counter used for IV and AAD */
488                        pttotlen;     /* 64-bit counter for the PT */
489 
490 #ifdef LTC_GCM_TABLES
491    unsigned char       PC[16][256][16]  /* 16 tables of 8x128 */
492 #ifdef LTC_GCM_TABLES_SSE2
493 __attribute__ ((aligned (16)))
494 #endif
495 ;
496 #endif
497 } gcm_state;
498 
499 void gcm_mult_h(const gcm_state *gcm, unsigned char *I);
500 
501 int gcm_init(gcm_state *gcm, int cipher,
502              const unsigned char *key, int keylen);
503 
504 int gcm_reset(gcm_state *gcm);
505 
506 int gcm_add_iv(gcm_state *gcm,
507                const unsigned char *IV,     unsigned long IVlen);
508 
509 int gcm_add_aad(gcm_state *gcm,
510                const unsigned char *adata,  unsigned long adatalen);
511 
512 int gcm_process(gcm_state *gcm,
513                      unsigned char *pt,     unsigned long ptlen,
514                      unsigned char *ct,
515                      int direction);
516 
517 int gcm_done(gcm_state *gcm,
518                      unsigned char *tag,    unsigned long *taglen);
519 
520 int gcm_memory(      int           cipher,
521                const unsigned char *key,    unsigned long keylen,
522                const unsigned char *IV,     unsigned long IVlen,
523                const unsigned char *adata,  unsigned long adatalen,
524                      unsigned char *pt,     unsigned long ptlen,
525                      unsigned char *ct,
526                      unsigned char *tag,    unsigned long *taglen,
527                                int direction);
528 int gcm_test(void);
529 
530 #endif /* LTC_GCM_MODE */
531 
532 #ifdef LTC_CHACHA20POLY1305_MODE
533 
534 typedef struct {
535    poly1305_state poly;
536    chacha_state chacha;
537    ulong64 aadlen;
538    ulong64 ctlen;
539    int aadflg;
540 } chacha20poly1305_state;
541 
542 #define CHACHA20POLY1305_ENCRYPT LTC_ENCRYPT
543 #define CHACHA20POLY1305_DECRYPT LTC_DECRYPT
544 
545 int chacha20poly1305_init(chacha20poly1305_state *st, const unsigned char *key, unsigned long keylen);
546 int chacha20poly1305_setiv(chacha20poly1305_state *st, const unsigned char *iv, unsigned long ivlen);
547 int chacha20poly1305_setiv_rfc7905(chacha20poly1305_state *st, const unsigned char *iv, unsigned long ivlen, ulong64 sequence_number);
548 int chacha20poly1305_add_aad(chacha20poly1305_state *st, const unsigned char *in, unsigned long inlen);
549 int chacha20poly1305_encrypt(chacha20poly1305_state *st, const unsigned char *in, unsigned long inlen, unsigned char *out);
550 int chacha20poly1305_decrypt(chacha20poly1305_state *st, const unsigned char *in, unsigned long inlen, unsigned char *out);
551 int chacha20poly1305_done(chacha20poly1305_state *st, unsigned char *tag, unsigned long *taglen);
552 int chacha20poly1305_memory(const unsigned char *key, unsigned long keylen,
553                             const unsigned char *iv,  unsigned long ivlen,
554                             const unsigned char *aad, unsigned long aadlen,
555                             const unsigned char *in,  unsigned long inlen,
556                                   unsigned char *out,
557                                   unsigned char *tag, unsigned long *taglen,
558                             int direction);
559 int chacha20poly1305_test(void);
560 
561 #endif /* LTC_CHACHA20POLY1305_MODE */
562 
563 /* ref:         $Format:%D$ */
564 /* git commit:  $Format:%H$ */
565 /* commit time: $Format:%ai$ */
566