3 * The Square block cipher
5 * (c) 2000 Straylight/Edgeware
8 /*----- Licensing notice --------------------------------------------------*
10 * This file is part of Catacomb.
12 * Catacomb is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU Library General Public License as
14 * published by the Free Software Foundation; either version 2 of the
15 * License, or (at your option) any later version.
17 * Catacomb is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Library General Public License for more details.
22 * You should have received a copy of the GNU Library General Public
23 * License along with Catacomb; if not, write to the Free
24 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
28 /*----- Notes on the Square block cipher ----------------------------------*
30 * Invented by Joan Daemen and Vincent Rijmen, Square is a fast and
31 * relatively simple 128-bit block cipher. It is the predecessor to
32 * Rijndael. I have grave doubts about the security of Square, though: a
33 * dedicated attack against Square's structure by Knudsen has been extended
34 * by the Twofish team against Rijndael, and I believe that this extended
35 * attack is also effective against Square. This is a shame: the structure
36 * of Square (and Rijndael) is extremely elegant, and has some extremely nice
40 #ifndef CATACOMB_SQUARE_H
41 #define CATACOMB_SQUARE_H
47 /*----- Header files ------------------------------------------------------*/
51 #include <mLib/bits.h>
53 /*----- Magical numbers ---------------------------------------------------*/
55 #define SQUARE_BLKSZ 16
56 #define SQUARE_KEYSZ 16
57 #define SQUARE_CLASS (N, L, 128)
59 extern const octet square_keysz[];
61 /*----- Data structures ---------------------------------------------------*/
63 #define SQUARE_MAXROUNDS 8
64 #define SQUARE_KWORDS ((SQUARE_MAXROUNDS + 1) * (SQUARE_BLKSZ / 4))
66 typedef struct square_ctx {
67 uint32 w[SQUARE_KWORDS];
68 uint32 wi[SQUARE_KWORDS];
71 /*----- Functions provided ------------------------------------------------*/
73 /* --- @square_init@ --- *
75 * Arguments: @square_ctx *k@ = pointer to context to initialize
76 * @const void *buf@ = pointer to buffer of key material
77 * @size_t sz@ = size of the key material
81 * Use: Initializes a Square context with a particular key. This
82 * implementation of Square doesn't impose any particular
83 * limits on the key size except that it must be multiple of 4
84 * bytes long. 256 bits seems sensible, though.
87 extern void square_init(square_ctx */*k*/,
88 const void */*buf*/, size_t /*sz*/);
90 /* --- @square_eblk@, @square_dblk@ --- *
92 * Arguments: @const square_ctx *k@ = pointer to Square context
93 * @const uint32 s[4]@ = pointer to source block
94 * @uint32 d[4]@ = pointer to destination block
98 * Use: Low-level block encryption and decryption.
101 extern void square_eblk(const square_ctx */*k*/,
102 const uint32 */*s*/, uint32 */*dst*/);
103 extern void square_dblk(const square_ctx */*k*/,
104 const uint32 */*s*/, uint32 */*dst*/);
106 /*----- That's all, folks -------------------------------------------------*/