math/mpreduce.h: Missing include files.
[u/mdw/catacomb] / symm / square.h
1 /* -*-c-*-
2 *
3 * The Square block cipher
4 *
5 * (c) 2000 Straylight/Edgeware
6 */
7
8 /*----- Licensing notice --------------------------------------------------*
9 *
10 * This file is part of Catacomb.
11 *
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.
16 *
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.
21 *
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,
25 * MA 02111-1307, USA.
26 */
27
28 /*----- Notes on the Square block cipher ----------------------------------*
29 *
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
37 * properties.
38 */
39
40 #ifndef CATACOMB_SQUARE_H
41 #define CATACOMB_SQUARE_H
42
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46
47 /*----- Header files ------------------------------------------------------*/
48
49 #include <stddef.h>
50
51 #include <mLib/bits.h>
52
53 /*----- Magical numbers ---------------------------------------------------*/
54
55 #define SQUARE_BLKSZ 16
56 #define SQUARE_KEYSZ 16
57 #define SQUARE_CLASS (N, L, 128)
58
59 extern const octet square_keysz[];
60
61 /*----- Data structures ---------------------------------------------------*/
62
63 #define SQUARE_MAXROUNDS 8
64 #define SQUARE_KWORDS ((SQUARE_MAXROUNDS + 1) * (SQUARE_BLKSZ / 4))
65
66 typedef struct square_ctx {
67 uint32 w[SQUARE_KWORDS];
68 uint32 wi[SQUARE_KWORDS];
69 } square_ctx;
70
71 /*----- Functions provided ------------------------------------------------*/
72
73 /* --- @square_init@ --- *
74 *
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
78 *
79 * Returns: ---
80 *
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.
85 */
86
87 extern void square_init(square_ctx */*k*/,
88 const void */*buf*/, size_t /*sz*/);
89
90 /* --- @square_eblk@, @square_dblk@ --- *
91 *
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
95 *
96 * Returns: ---
97 *
98 * Use: Low-level block encryption and decryption.
99 */
100
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*/);
105
106 /*----- That's all, folks -------------------------------------------------*/
107
108 #ifdef __cplusplus
109 }
110 #endif
111
112 #endif