ce40b77a3c8bd77a6c8661cada97cf651161ce1c
[platform/upstream/nettle.git] / chacha-poly1305.h
1 /* chacha-poly1305.h
2
3    AEAD mechanism based on chacha and poly1305.
4    See draft-agl-tls-chacha20poly1305-04.
5
6    Copyright (C) 2014 Niels Möller
7
8    This file is part of GNU Nettle.
9
10    GNU Nettle is free software: you can redistribute it and/or
11    modify it under the terms of either:
12
13      * the GNU Lesser General Public License as published by the Free
14        Software Foundation; either version 3 of the License, or (at your
15        option) any later version.
16
17    or
18
19      * the GNU General Public License as published by the Free
20        Software Foundation; either version 2 of the License, or (at your
21        option) any later version.
22
23    or both in parallel, as here.
24
25    GNU Nettle is distributed in the hope that it will be useful,
26    but WITHOUT ANY WARRANTY; without even the implied warranty of
27    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
28    General Public License for more details.
29
30    You should have received copies of the GNU General Public License and
31    the GNU Lesser General Public License along with this program.  If
32    not, see http://www.gnu.org/licenses/.
33 */
34
35 #ifndef NETTLE_CHACHA_POLY1305_H_INCLUDED
36 #define NETTLE_CHACHA_POLY1305_H_INCLUDED
37
38 #include "chacha.h"
39 #include "poly1305.h"
40
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44
45 /* Name mangling */
46 #define chacha_poly1305_set_key nettle_chacha_poly1305_set_key
47 #define chacha_poly1305_set_nonce nettle_chacha_poly1305_set_nonce
48 #define chacha_poly1305_update nettle_chacha_poly1305_update
49 #define chacha_poly1305_decrypt nettle_chacha_poly1305_decrypt
50 #define chacha_poly1305_encrypt nettle_chacha_poly1305_encrypt
51 #define chacha_poly1305_digest nettle_chacha_poly1305_digest
52
53 #define CHACHA_POLY1305_BLOCK_SIZE 64
54 /* FIXME: Any need for 128-bit variant? */
55 #define CHACHA_POLY1305_KEY_SIZE 32
56 #define CHACHA_POLY1305_NONCE_SIZE CHACHA_NONCE96_SIZE
57 #define CHACHA_POLY1305_DIGEST_SIZE 16
58
59 struct chacha_poly1305_ctx
60 {
61   struct chacha_ctx chacha;
62   struct poly1305_ctx poly1305;
63   union nettle_block16 s;
64   uint64_t auth_size;
65   uint64_t data_size;
66   /* poly1305 block */
67   uint8_t block[POLY1305_BLOCK_SIZE];
68   unsigned index;
69 };
70
71 void
72 chacha_poly1305_set_key (struct chacha_poly1305_ctx *ctx,
73                          const uint8_t *key);
74 void
75 chacha_poly1305_set_nonce (struct chacha_poly1305_ctx *ctx,
76                            const uint8_t *nonce);
77
78 void
79 chacha_poly1305_update (struct chacha_poly1305_ctx *ctx,
80                         size_t length, const uint8_t *data);
81
82 void
83 chacha_poly1305_encrypt (struct chacha_poly1305_ctx *ctx,
84                          size_t length, uint8_t *dst, const uint8_t *src);
85                          
86 void
87 chacha_poly1305_decrypt (struct chacha_poly1305_ctx *ctx,
88                          size_t length, uint8_t *dst, const uint8_t *src);
89                          
90 void
91 chacha_poly1305_digest (struct chacha_poly1305_ctx *ctx,
92                         size_t length, uint8_t *digest);
93
94 #ifdef __cplusplus
95 }
96 #endif
97
98 #endif /* NETTLE_CHACHA_POLY1305_H_INCLUDED */