Add an internal-representation no-op function.
[u/mdw/catacomb] / safer.h
CommitLineData
621468d8 1/* -*-c-*-
2 *
5233862a 3 * $Id: safer.h,v 1.2 2001/04/29 18:11:38 mdw Exp $
621468d8 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 $
5233862a 33 * Revision 1.2 2001/04/29 18:11:38 mdw
34 * Add some notes.
35 *
621468d8 36 * Revision 1.1 2001/04/29 17:37:35 mdw
37 * Added SAFER block cipher.
38 *
39 */
40
5233862a 41/*----- Notes on the SAFER block cipher -----------------------------------*
42 *
43 * SAFER was designed by James Massey (who also worked on IDEA) for Cylink.
44 * It's free -- patents or other silliness. The original key schedule had
45 * some weaknesses, and a new one (the SK version) was added. SAFER has a
46 * variable number of rounds. The standard interface uses the recommended
47 * number for the given key schedule algorithm and key size.
48 *
49 * SAFER got a bad press in Schneier's book `Applied Cryptography'. I think
50 * this is undeserved. SAFER is a well-designed cipher which mostly looks
51 * pretty solid.
52 */
53
621468d8 54#ifndef CATACOMB_SAFER_H
55#define CATACOMB_SAFER_H
56
57#ifdef __cplusplus
58 extern "C" {
59#endif
60
61/*----- Header files ------------------------------------------------------*/
62
63#include <stddef.h>
64
65#include <mLib/bits.h>
66
67/*----- Magical numbers ---------------------------------------------------*/
68
69#define SAFER_BLKSZ 8
70#define SAFER_KEYSZ 8
71#define SAFER_CLASS (N, B, 64)
72
73#define SAFERSK_BLKSZ SAFER_BLKSZ
74#define SAFERSK_KEYSZ 16
75#define SAFERSK_CLASS SAFER_CLASS
76
77#define SAFER_MAXROUNDS 12
78
79extern const octet safer_keysz[];
80#define safersk_keysz safer_keysz
81
82/*----- Data structures ---------------------------------------------------*/
83
84typedef struct safer_ctx {
85 octet k[8 * (2 * SAFER_MAXROUNDS + 1)];
86 unsigned r;
87} safer_ctx, safersk_ctx;
88
89/*----- Functions provided ------------------------------------------------*/
90
91/* --- @safer_setup@ --- *
92 *
93 * Arguments: @safer_ctx *k@ = pointer to context to initialize
94 * @unsigned r@ = number of rounds wanted
95 * @unsigned f@ = various other flags
96 * @const void *buf@ = pointer to key material
97 * @size_t sz@ = size of key material in bytes
98 *
99 * Returns: ---
100 *
101 * Use: Initializes an SAFER expanded key. A default number of
102 * rounds is chosen, based on the key length.
103 */
104
105#define SAFER_SK 1u
106
107extern void safer_setup(safer_ctx */*k*/, unsigned /*r*/, unsigned /*f*/,
108 const void */*buf*/, size_t /*sz*/);
109
110/* --- @safer_init@, @safersk_init@ --- *
111 *
112 * Arguments: @safer_ctx *k@ = pointer to context to initialize
113 * @const void *buf@ = pointer to key material
114 * @size_t sz@ = size of key material in bytes
115 *
116 * Returns: ---
117 *
118 * Use: Initializes an SAFER expanded key. A default number of
119 * rounds is chosen, based on the key length.
120 */
121
122extern void safer_init(safer_ctx */*k*/,
123 const void */*buf*/, size_t /*sz*/);
124extern void safersk_init(safer_ctx */*k*/,
125 const void */*buf*/, size_t /*sz*/);
126
127/* --- @safer_eblk@, @safer_dblk@ --- *
128 *
129 * Arguments: @const safer_ctx *k@ = pointer to SAFER context
130 * @const uint32 s[2]@ = pointer to source block
131 * @const uint32 d[2]@ = pointer to destination block
132 *
133 * Returns: ---
134 *
135 * Use: Low-level block encryption and decryption.
136 */
137
138extern void safer_eblk(const safer_ctx */*k*/,
139 const uint32 */*s*/, uint32 */*dst*/);
140extern void safer_dblk(const safer_ctx */*k*/,
141 const uint32 */*s*/, uint32 */*dst*/);
142
143#define safersk_eblk safer_eblk
144#define safersk_dblk safer_dblk
145
146/*----- That's all, folks -------------------------------------------------*/
147
148#ifdef __cplusplus
149 }
150#endif
151
152#endif