3 * The SAFER block cipher
5 * (c) 2001 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 SAFER block cipher -----------------------------------*
30 * SAFER was designed by James Massey (who also worked on IDEA) for Cylink.
31 * It's free -- patents or other silliness. The original key schedule had
32 * some weaknesses, and a new one (the SK version) was added. SAFER has a
33 * variable number of rounds. The standard interface uses the recommended
34 * number for the given key schedule algorithm and key size.
36 * SAFER got a bad press in Schneier's book `Applied Cryptography'. I think
37 * this is undeserved. SAFER is a well-designed cipher which mostly looks
41 #ifndef CATACOMB_SAFER_H
42 #define CATACOMB_SAFER_H
48 /*----- Header files ------------------------------------------------------*/
52 #include <mLib/bits.h>
54 /*----- Magical numbers ---------------------------------------------------*/
58 #define SAFER_CLASS (N, B, 64)
60 #define SAFERSK_BLKSZ SAFER_BLKSZ
61 #define SAFERSK_KEYSZ 16
62 #define SAFERSK_CLASS SAFER_CLASS
64 #define SAFER_MAXROUNDS 12
66 extern const octet safer_keysz[];
67 #define safersk_keysz safer_keysz
69 /*----- Data structures ---------------------------------------------------*/
71 typedef struct safer_ctx {
72 octet k[8 * (2 * SAFER_MAXROUNDS + 1)];
74 } safer_ctx, safersk_ctx;
76 /*----- Functions provided ------------------------------------------------*/
78 /* --- @safer_setup@ --- *
80 * Arguments: @safer_ctx *k@ = pointer to context to initialize
81 * @unsigned r@ = number of rounds wanted
82 * @unsigned f@ = various other flags
83 * @const void *buf@ = pointer to key material
84 * @size_t sz@ = size of key material in bytes
88 * Use: Initializes an SAFER expanded key. A default number of
89 * rounds is chosen, based on the key length.
94 extern void safer_setup(safer_ctx */*k*/, unsigned /*r*/, unsigned /*f*/,
95 const void */*buf*/, size_t /*sz*/);
97 /* --- @safer_init@, @safersk_init@ --- *
99 * Arguments: @safer_ctx *k@ = pointer to context to initialize
100 * @const void *buf@ = pointer to key material
101 * @size_t sz@ = size of key material in bytes
105 * Use: Initializes an SAFER expanded key. A default number of
106 * rounds is chosen, based on the key length.
109 extern void safer_init(safer_ctx */*k*/,
110 const void */*buf*/, size_t /*sz*/);
111 extern void safersk_init(safer_ctx */*k*/,
112 const void */*buf*/, size_t /*sz*/);
114 /* --- @safer_eblk@, @safer_dblk@ --- *
116 * Arguments: @const safer_ctx *k@ = pointer to SAFER context
117 * @const uint32 s[2]@ = pointer to source block
118 * @const uint32 d[2]@ = pointer to destination block
122 * Use: Low-level block encryption and decryption.
125 extern void safer_eblk(const safer_ctx */*k*/,
126 const uint32 */*s*/, uint32 */*dst*/);
127 extern void safer_dblk(const safer_ctx */*k*/,
128 const uint32 */*s*/, uint32 */*dst*/);
130 #define safersk_eblk safer_eblk
131 #define safersk_dblk safer_dblk
133 /*----- That's all, folks -------------------------------------------------*/