chiark / gitweb /
configure.ac: Replace with a new version.
[catacomb] / square.h
1 /* -*-c-*-
2  *
3  * $Id: square.h,v 1.2 2004/04/08 01:36:15 mdw Exp $
4  *
5  * The Square block cipher
6  *
7  * (c) 2000 Straylight/Edgeware
8  */
9
10 /*----- Licensing notice --------------------------------------------------*
11  *
12  * This file is part of Catacomb.
13  *
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.
18  *
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.
23  *
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,
27  * MA 02111-1307, USA.
28  */
29
30 /*----- Notes on the Square block cipher ----------------------------------*
31  *
32  * Invented by Joan Daemen and Vincent Rijmen, Square is a fast and
33  * relatively simple 128-bit block cipher.  It is the predecessor to
34  * Rijndael.  I have grave doubts about the security of Square, though: a
35  * dedicated attack against Square's structure by Knudsen has been extended
36  * by the Twofish team against Rijndael, and I believe that this extended
37  * attack is also effective against Square.  This is a shame: the structure
38  * of Square (and Rijndael) is extremely elegant, and has some extremely nice
39  * properties.
40  */
41
42 #ifndef CATACOMB_SQUARE_H
43 #define CATACOMB_SQUARE_H
44
45 #ifdef __cplusplus
46   extern "C" {
47 #endif
48
49 /*----- Header files ------------------------------------------------------*/
50
51 #include <stddef.h>
52
53 #include <mLib/bits.h>
54
55 /*----- Magical numbers ---------------------------------------------------*/
56
57 #define SQUARE_BLKSZ 16
58 #define SQUARE_KEYSZ 16
59 #define SQUARE_CLASS (N, L, 128)
60
61 extern const octet square_keysz[];
62
63 /*----- Data structures ---------------------------------------------------*/
64
65 #define SQUARE_MAXROUNDS 8
66 #define SQUARE_KWORDS ((SQUARE_MAXROUNDS + 1) * (SQUARE_BLKSZ / 4))
67
68 typedef struct square_ctx {
69   uint32 w[SQUARE_KWORDS];
70   uint32 wi[SQUARE_KWORDS];
71 } square_ctx;
72
73 /*----- Functions provided ------------------------------------------------*/
74
75 /* --- @square_init@ --- *
76  *
77  * Arguments:   @square_ctx *k@ = pointer to context to initialize
78  *              @const void *buf@ = pointer to buffer of key material
79  *              @size_t sz@ = size of the key material
80  *
81  * Returns:     ---
82  *
83  * Use:         Initializes a Square context with a particular key.  This
84  *              implementation of Square doesn't impose any particular
85  *              limits on the key size except that it must be multiple of 4
86  *              bytes long.  256 bits seems sensible, though.
87  */
88
89 extern void square_init(square_ctx */*k*/,
90                           const void */*buf*/, size_t /*sz*/);
91
92 /* --- @square_eblk@, @square_dblk@ --- *
93  *
94  * Arguments:   @const square_ctx *k@ = pointer to Square context
95  *              @const uint32 s[4]@ = pointer to source block
96  *              @uint32 d[4]@ = pointer to destination block
97  *
98  * Returns:     ---
99  *
100  * Use:         Low-level block encryption and decryption.
101  */
102
103 extern void square_eblk(const square_ctx */*k*/,
104                           const uint32 */*s*/, uint32 */*dst*/);
105 extern void square_dblk(const square_ctx */*k*/,
106                           const uint32 */*s*/, uint32 */*dst*/);
107
108 /*----- That's all, folks -------------------------------------------------*/
109
110 #ifdef __cplusplus
111   }
112 #endif
113
114 #endif