chiark / gitweb /
Add some more vectors, and a whinge about how Skipjack test vectors are.
[catacomb] / square.h
1 /* -*-c-*-
2  *
3  * $Id: square.h,v 1.1 2000/07/15 20:51:58 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 /*----- Revision history --------------------------------------------------* 
31  *
32  * $Log: square.h,v $
33  * Revision 1.1  2000/07/15 20:51:58  mdw
34  * New block cipher.
35  *
36  * Revision 1.1  2000/06/17 11:56:07  mdw
37  * New cipher.
38  *
39  */
40
41 /*----- Notes on the Square block cipher ----------------------------------*
42  *
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
50  * properties.
51  */
52
53 #ifndef CATACOMB_SQUARE_H
54 #define CATACOMB_SQUARE_H
55
56 #ifdef __cplusplus
57   extern "C" {
58 #endif
59
60 /*----- Header files ------------------------------------------------------*/
61
62 #include <stddef.h>
63
64 #include <mLib/bits.h>
65
66 /*----- Magical numbers ---------------------------------------------------*/
67
68 #define SQUARE_BLKSZ 16
69 #define SQUARE_KEYSZ 16
70 #define SQUARE_CLASS (N, L, 128)
71
72 extern const octet square_keysz[];
73
74 /*----- Data structures ---------------------------------------------------*/
75
76 #define SQUARE_MAXROUNDS 8
77 #define SQUARE_KWORDS ((SQUARE_MAXROUNDS + 1) * (SQUARE_BLKSZ / 4))
78
79 typedef struct square_ctx {
80   uint32 w[SQUARE_KWORDS];
81   uint32 wi[SQUARE_KWORDS];
82 } square_ctx;
83
84 /*----- Functions provided ------------------------------------------------*/
85
86 /* --- @square_init@ --- *
87  *
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
91  *
92  * Returns:     ---
93  *
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.
98  */
99
100 extern void square_init(square_ctx */*k*/,
101                           const void */*buf*/, size_t /*sz*/);
102
103 /* --- @square_eblk@, @square_dblk@ --- *
104  *
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
108  *
109  * Returns:     ---
110  *
111  * Use:         Low-level block encryption and decryption.
112  */
113
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*/);
118
119 /*----- That's all, folks -------------------------------------------------*/
120
121 #ifdef __cplusplus
122   }
123 #endif
124
125 #endif