symm/latinpoly.c, etc.: AEADs based on Salsa20 and ChaCha with Poly1305.
[catacomb] / symm / chacha-poly1305.c
diff --git a/symm/chacha-poly1305.c b/symm/chacha-poly1305.c
new file mode 100644 (file)
index 0000000..c286635
--- /dev/null
@@ -0,0 +1,74 @@
+/* -*-c-*-
+ *
+ * AEAD schemes based on ChaCha and Poly1305
+ *
+ * (c) 2018 Straylight/Edgeware
+ */
+
+/*----- Licensing notice --------------------------------------------------*
+ *
+ * This file is part of Catacomb.
+ *
+ * Catacomb is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Library General Public License as published
+ * by the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Catacomb is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with Catacomb.  If not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ * USA.
+ */
+
+/*----- Header files ------------------------------------------------------*/
+
+#include "chacha.h"
+#include "latinpoly-def.h"
+
+/*----- Main code ---------------------------------------------------------*/
+
+LATINPOLY_DEF(chacha20, chacha, "chacha20")
+LATINPOLY_DEF(chacha12, chacha, "chacha12")
+LATINPOLY_DEF(chacha8, chacha, "chacha8")
+
+/*----- Test rig ----------------------------------------------------------*/
+
+#ifdef TEST_RIG
+
+#include <mLib/quis.h>
+#include <mLib/testrig.h>
+#include "latinpoly-test.h"
+
+static int check_chacha20(dstr *v)
+  { return latinpoly_test(&chacha20_poly1305, v); }
+static int check_chacha12(dstr *v)
+  { return latinpoly_test(&chacha12_poly1305, v); }
+static int check_chacha8(dstr *v)
+  { return latinpoly_test(&chacha8_poly1305, v); }
+
+static const test_chunk tests[] = {
+  { "chacha20-poly1305", check_chacha20,
+    { &type_hex, &type_hex, &type_hex, &type_hex, &type_hex, &type_hex } },
+  { "chacha12-poly1305", check_chacha12,
+    { &type_hex, &type_hex, &type_hex, &type_hex, &type_hex, &type_hex } },
+  { "chacha8-poly1305", check_chacha8,
+    { &type_hex, &type_hex, &type_hex, &type_hex, &type_hex, &type_hex } },
+  { 0, 0, { 0 } }
+#undef TEST
+};
+
+int main(int argc, char *argv[])
+{
+  ego(argv[0]);
+  test_run(argc, argv, tests, SRCDIR"/t/chacha");
+  return (0);
+}
+
+#endif
+
+/*----- That's all, folks -------------------------------------------------*/