New cipher.
[u/mdw/catacomb] / twofish.h
diff --git a/twofish.h b/twofish.h
new file mode 100644 (file)
index 0000000..c941bc5
--- /dev/null
+++ b/twofish.h
@@ -0,0 +1,117 @@
+/* -*-c-*-
+ *
+ * $Id: twofish.h,v 1.1 2000/06/17 12:10:17 mdw Exp $
+ *
+ * The Twofish block cipher
+ *
+ * (c) 2000 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.
+ */
+
+/*----- Revision history --------------------------------------------------* 
+ *
+ * $Log: twofish.h,v $
+ * Revision 1.1  2000/06/17 12:10:17  mdw
+ * New cipher.
+ *
+ */
+
+/*----- Notes on the Twofish block cipher ---------------------------------*
+ *
+ * Twofish was designed by Bruce Schneier, John Kelsey, Doug Whiting, David
+ * Wagner, Chris Hall and Niels Ferguson.  The algorithm is unpatented and
+ * free for anyone to use.  It is one of the five AES finalist algorithms.
+ * At the time of writing, the AES competition is still underway.
+ *
+ * Twofish is a complex cipher offering various space and time tradeoffs.
+ * This implementation has a heavy key schedule and fast bulk encryption.
+ */
+
+#ifndef CATACOMB_TWOFISH_H
+#define CATACOMB_TWOFISH_H
+
+#ifdef __cplusplus
+  extern "C" {
+#endif
+
+/*----- Header files ------------------------------------------------------*/
+
+#include <stddef.h>
+
+#include <mLib/bits.h>
+
+/*----- Magical numbers ---------------------------------------------------*/
+
+#define TWOFISH_BLKSZ 16
+#define TWOFISH_KEYSZ 32
+#define TWOFISH_CLASS (N, L, 128)
+
+extern const octet twofish_keysz[];
+
+/*----- Data structures ---------------------------------------------------*/
+
+typedef struct twofish_ctx {
+  uint32 k[40];
+  uint32 g[4][256];
+} twofish_ctx;
+
+/*----- Functions provided ------------------------------------------------*/
+
+/* --- @twofish_init@ --- *
+ *
+ * Arguments:  @twofish_ctx *k@ = pointer to key block to fill in
+ *             @const void *buf@ = pointer to buffer of key material
+ *             @size_t sz@ = size of key material
+ *
+ * Returns:    ---
+ *
+ * Use:                Initializes a Twofish key buffer.  Twofish accepts keys of up
+ *             to 256 bits in length.
+ */
+
+extern void twofish_init(twofish_ctx */*k*/,
+                        const void */*buf*/, size_t /*sz*/);
+
+/* --- @twofish_eblk@, @twofish_dblk@ --- *
+ *
+ * Arguments:  @const twofish_ctx *k@ = pointer to key block
+ *             @const uint32 s[4]@ = pointer to source block
+ *             @uint32 d[4]@ = pointer to destination block
+ *
+ * Returns:    ---
+ *
+ * Use:                Low-level block encryption and decryption.
+ */
+
+extern void twofish_eblk(const twofish_ctx */*k*/,
+                        const uint32 */*s*/, uint32 */*d*/);
+
+extern void twofish_dblk(const twofish_ctx */*k*/,
+                         const uint32 */*s*/, uint32 */*d*/);
+
+/*----- That's all, folks -------------------------------------------------*/
+
+#ifdef __cplusplus
+  }
+#endif
+
+#endif