symm/latinpoly.c, etc.: AEADs based on Salsa20 and ChaCha with Poly1305.
[catacomb] / symm / salsa20-poly1305.c
diff --git a/symm/salsa20-poly1305.c b/symm/salsa20-poly1305.c
new file mode 100644 (file)
index 0000000..bfee0ba
--- /dev/null
@@ -0,0 +1,73 @@
+/* -*-c-*-
+ *
+ * AEAD schemes based on Salsa20 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 "latinpoly-def.h"
+#include "salsa20.h"
+
+/*----- Main code ---------------------------------------------------------*/
+
+LATINPOLY_DEF(salsa20, salsa20, "salsa20")
+LATINPOLY_DEF(salsa2012, salsa20, "salsa20/12")
+LATINPOLY_DEF(salsa208, salsa20, "salsa20/8")
+
+/*----- Test rig ----------------------------------------------------------*/
+
+#ifdef TEST_RIG
+
+#include <mLib/quis.h>
+#include <mLib/testrig.h>
+#include "latinpoly-test.h"
+
+static int check_salsa20(dstr *v)
+  { return latinpoly_test(&salsa20_poly1305, v); }
+static int check_salsa2012(dstr *v)
+  { return latinpoly_test(&salsa2012_poly1305, v); }
+static int check_salsa208(dstr *v)
+  { return latinpoly_test(&salsa208_poly1305, v); }
+
+static const test_chunk tests[] = {
+  { "salsa20-poly1305", check_salsa20,
+    { &type_hex, &type_hex, &type_hex, &type_hex, &type_hex, &type_hex } },
+  { "salsa20/12-poly1305", check_salsa2012,
+    { &type_hex, &type_hex, &type_hex, &type_hex, &type_hex, &type_hex } },
+  { "salsa20/8-poly1305", check_salsa208,
+    { &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/salsa20");
+  return (0);
+}
+
+#endif
+/*----- That's all, folks -------------------------------------------------*/