Added SAFER block cipher.
[u/mdw/catacomb] / safer.h
1 /* -*-c-*-
2 *
3 * $Id: safer.h,v 1.1 2001/04/29 17:37:35 mdw Exp $
4 *
5 * The SAFER block cipher
6 *
7 * (c) 2001 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: safer.h,v $
33 * Revision 1.1 2001/04/29 17:37:35 mdw
34 * Added SAFER block cipher.
35 *
36 */
37
38 #ifndef CATACOMB_SAFER_H
39 #define CATACOMB_SAFER_H
40
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44
45 /*----- Header files ------------------------------------------------------*/
46
47 #include <stddef.h>
48
49 #include <mLib/bits.h>
50
51 /*----- Magical numbers ---------------------------------------------------*/
52
53 #define SAFER_BLKSZ 8
54 #define SAFER_KEYSZ 8
55 #define SAFER_CLASS (N, B, 64)
56
57 #define SAFERSK_BLKSZ SAFER_BLKSZ
58 #define SAFERSK_KEYSZ 16
59 #define SAFERSK_CLASS SAFER_CLASS
60
61 #define SAFER_MAXROUNDS 12
62
63 extern const octet safer_keysz[];
64 #define safersk_keysz safer_keysz
65
66 /*----- Data structures ---------------------------------------------------*/
67
68 typedef struct safer_ctx {
69 octet k[8 * (2 * SAFER_MAXROUNDS + 1)];
70 unsigned r;
71 } safer_ctx, safersk_ctx;
72
73 /*----- Functions provided ------------------------------------------------*/
74
75 /* --- @safer_setup@ --- *
76 *
77 * Arguments: @safer_ctx *k@ = pointer to context to initialize
78 * @unsigned r@ = number of rounds wanted
79 * @unsigned f@ = various other flags
80 * @const void *buf@ = pointer to key material
81 * @size_t sz@ = size of key material in bytes
82 *
83 * Returns: ---
84 *
85 * Use: Initializes an SAFER expanded key. A default number of
86 * rounds is chosen, based on the key length.
87 */
88
89 #define SAFER_SK 1u
90
91 extern void safer_setup(safer_ctx */*k*/, unsigned /*r*/, unsigned /*f*/,
92 const void */*buf*/, size_t /*sz*/);
93
94 /* --- @safer_init@, @safersk_init@ --- *
95 *
96 * Arguments: @safer_ctx *k@ = pointer to context to initialize
97 * @const void *buf@ = pointer to key material
98 * @size_t sz@ = size of key material in bytes
99 *
100 * Returns: ---
101 *
102 * Use: Initializes an SAFER expanded key. A default number of
103 * rounds is chosen, based on the key length.
104 */
105
106 extern void safer_init(safer_ctx */*k*/,
107 const void */*buf*/, size_t /*sz*/);
108 extern void safersk_init(safer_ctx */*k*/,
109 const void */*buf*/, size_t /*sz*/);
110
111 /* --- @safer_eblk@, @safer_dblk@ --- *
112 *
113 * Arguments: @const safer_ctx *k@ = pointer to SAFER context
114 * @const uint32 s[2]@ = pointer to source block
115 * @const uint32 d[2]@ = pointer to destination block
116 *
117 * Returns: ---
118 *
119 * Use: Low-level block encryption and decryption.
120 */
121
122 extern void safer_eblk(const safer_ctx */*k*/,
123 const uint32 */*s*/, uint32 */*dst*/);
124 extern void safer_dblk(const safer_ctx */*k*/,
125 const uint32 */*s*/, uint32 */*dst*/);
126
127 #define safersk_eblk safer_eblk
128 #define safersk_dblk safer_dblk
129
130 /*----- That's all, folks -------------------------------------------------*/
131
132 #ifdef __cplusplus
133 }
134 #endif
135
136 #endif