chiark / gitweb /
symm/latinpoly-def.h, etc.: Refactor in preparation for a related scheme.
[catacomb] / symm / chacha-poly1305.c
1 /* -*-c-*-
2  *
3  * AEAD schemes based on ChaCha and Poly1305
4  *
5  * (c) 2018 Straylight/Edgeware
6  */
7
8 /*----- Licensing notice --------------------------------------------------*
9  *
10  * This file is part of Catacomb.
11  *
12  * Catacomb is free software: you can redistribute it and/or modify it
13  * under the terms of the GNU Library General Public License as published
14  * by the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  *
17  * Catacomb is distributed in the hope that it will be useful, but
18  * WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20  * Library General Public License for more details.
21  *
22  * You should have received a copy of the GNU Library General Public
23  * License along with Catacomb.  If not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
25  * USA.
26  */
27
28 /*----- Header files ------------------------------------------------------*/
29
30 #include "chacha.h"
31 #include "latinpoly-def.h"
32
33 /*----- Main code ---------------------------------------------------------*/
34
35 LATINPOLY_DEF(chacha20, chacha, "chacha20")
36 LATINPOLY_DEF(chacha12, chacha, "chacha12")
37 LATINPOLY_DEF(chacha8, chacha, "chacha8")
38
39 /*----- Test rig ----------------------------------------------------------*/
40
41 #ifdef TEST_RIG
42
43 #include <mLib/quis.h>
44 #include <mLib/testrig.h>
45 #include "latinpoly-test.h"
46
47 static int check_chacha20_poly1305(dstr *v)
48   { return latinpoly_test(&chacha20_poly1305, v); }
49 static int check_chacha12_poly1305(dstr *v)
50   { return latinpoly_test(&chacha12_poly1305, v); }
51 static int check_chacha8_poly1305(dstr *v)
52   { return latinpoly_test(&chacha8_poly1305, v); }
53
54 static const test_chunk tests[] = {
55   { "chacha20-poly1305", check_chacha20_poly1305,
56     { &type_hex, &type_hex, &type_hex, &type_hex, &type_hex, &type_hex } },
57   { "chacha12-poly1305", check_chacha12_poly1305,
58     { &type_hex, &type_hex, &type_hex, &type_hex, &type_hex, &type_hex } },
59   { "chacha8-poly1305", check_chacha8_poly1305,
60     { &type_hex, &type_hex, &type_hex, &type_hex, &type_hex, &type_hex } },
61   { 0, 0, { 0 } }
62 #undef TEST
63 };
64
65 int main(int argc, char *argv[])
66 {
67   ego(argv[0]);
68   test_run(argc, argv, tests, SRCDIR"/t/chacha");
69   return (0);
70 }
71
72 #endif
73
74 /*----- That's all, folks -------------------------------------------------*/