3 * $Id: square.h,v 1.1 2000/07/15 20:51:58 mdw Exp $
5 * The Square block cipher
7 * (c) 2000 Straylight/Edgeware
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of Catacomb.
14 * Catacomb is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU Library General Public License as
16 * published by the Free Software Foundation; either version 2 of the
17 * License, or (at your option) any later version.
19 * Catacomb is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Library General Public License for more details.
24 * You should have received a copy of the GNU Library General Public
25 * License along with Catacomb; if not, write to the Free
26 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
30 /*----- Revision history --------------------------------------------------*
33 * Revision 1.1 2000/07/15 20:51:58 mdw
36 * Revision 1.1 2000/06/17 11:56:07 mdw
41 /*----- Notes on the Square block cipher ----------------------------------*
43 * Invented by Joan Daemen and Vincent Rijmen, Square is a fast and
44 * relatively simple 128-bit block cipher. It is the predecessor to
45 * Rijndael. I have grave doubts about the security of Square, though: a
46 * dedicated attack against Square's structure by Knudsen has been extended
47 * by the Twofish team against Rijndael, and I believe that this extended
48 * attack is also effective against Square. This is a shame: the structure
49 * of Square (and Rijndael) is extremely elegant, and has some extremely nice
53 #ifndef CATACOMB_SQUARE_H
54 #define CATACOMB_SQUARE_H
60 /*----- Header files ------------------------------------------------------*/
64 #include <mLib/bits.h>
66 /*----- Magical numbers ---------------------------------------------------*/
68 #define SQUARE_BLKSZ 16
69 #define SQUARE_KEYSZ 16
70 #define SQUARE_CLASS (N, L, 128)
72 extern const octet square_keysz
[];
74 /*----- Data structures ---------------------------------------------------*/
76 #define SQUARE_MAXROUNDS 8
77 #define SQUARE_KWORDS ((SQUARE_MAXROUNDS + 1) * (SQUARE_BLKSZ / 4))
79 typedef struct square_ctx
{
80 uint32 w
[SQUARE_KWORDS
];
81 uint32 wi
[SQUARE_KWORDS
];
84 /*----- Functions provided ------------------------------------------------*/
86 /* --- @square_init@ --- *
88 * Arguments: @square_ctx *k@ = pointer to context to initialize
89 * @const void *buf@ = pointer to buffer of key material
90 * @size_t sz@ = size of the key material
94 * Use: Initializes a Square context with a particular key. This
95 * implementation of Square doesn't impose any particular
96 * limits on the key size except that it must be multiple of 4
97 * bytes long. 256 bits seems sensible, though.
100 extern void square_init(square_ctx */
*k*/
,
101 const void */
*buf*/
, size_t /*sz*/);
103 /* --- @square_eblk@, @square_dblk@ --- *
105 * Arguments: @const square_ctx *k@ = pointer to Square context
106 * @const uint32 s[4]@ = pointer to source block
107 * @uint32 d[4]@ = pointer to destination block
111 * Use: Low-level block encryption and decryption.
114 extern void square_eblk(const square_ctx */
*k*/
,
115 const uint32 */
*s*/
, uint32 */
*dst*/
);
116 extern void square_dblk(const square_ctx */
*k*/
,
117 const uint32 */
*s*/
, uint32 */
*dst*/
);
119 /*----- That's all, folks -------------------------------------------------*/