New multiprecision integer arithmetic suite.
[u/mdw/catacomb] / des.h
1 /* -*-c-*-
2 *
3 * $Id: des.h,v 1.1 1999/09/03 08:41:11 mdw Exp $
4 *
5 * The Data Encryption Standard
6 *
7 * (c) 1999 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: des.h,v $
33 * Revision 1.1 1999/09/03 08:41:11 mdw
34 * Initial import.
35 *
36 */
37
38 /*----- Notes on the Data Encryption Standard -----------------------------*
39 *
40 * Almost twenty years after it was first accepted, DES is still the standard
41 * block cipher. It's showing its age in its small key size and poor
42 * optimiziation for software implementations, but it's not really been badly
43 * dented by the intensive analysis thrown at it.
44 *
45 * This interface is here for compatibility with existing protocols, and
46 * because it's a trivial veneer over the base DES code which is used by the
47 * @des3@ interface which implements proper strong triple-DES.
48 */
49
50 #ifndef DES_H
51 #define DES_H
52
53 #ifdef __cplusplus
54 extern "C" {
55 #endif
56
57 /*----- Header files ------------------------------------------------------*/
58
59 #include <stddef.h>
60
61 #include <mLib/bits.h>
62
63 /*----- Magical numbers ---------------------------------------------------*/
64
65 #define DES_BLKSZ 8
66 #define DES_KEYSZ 7
67 #define DES_CLASS (N, B, 64)
68
69 /*----- Data structures ---------------------------------------------------*/
70
71 typedef struct des_ctx {
72 uint32 k[32];
73 } des_ctx;
74
75 /*----- Functions provided ------------------------------------------------*/
76
77 /* --- @des_init@ --- *
78 *
79 * Arguments: @des_ctx *k@ = pointer to key block
80 * @const void *buf@ = pointer to key buffer
81 * @size_t sz@ = size of key material
82 *
83 * Returns: ---
84 *
85 * Use: Initializes a DES key buffer. The key buffer may be either 7
86 * or 8 bytes long. If it's 8 bytes, the key is assumed to be
87 * padded with parity bits in the low order bit of each octet.
88 * These are stripped out without checking prior to the actual
89 * key scheduling.
90 */
91
92 extern void des_init(des_ctx */*k*/, const void */*buf*/, size_t /*sz*/);
93
94 /* --- @des_eblk@, @des_dblk@ --- *
95 *
96 * Arguments: @const des_ctx *k@ = pointer to key block
97 * @const uint32 s[2]@ = pointer to source block
98 * @uint32 d[2]@ = pointer to destination block
99 *
100 * Returns: ---
101 *
102 * Use: Low-level block encryption and decryption.
103 */
104
105 extern void des_eblk(const des_ctx */*k*/,
106 const uint32 */*s*/, uint32 */*d*/);
107 extern void des_dblk(const des_ctx */*k*/,
108 const uint32 */*s*/, uint32 */*d*/);
109
110 /*----- That's all, folks -------------------------------------------------*/
111
112 #ifdef __cplusplus
113 }
114 #endif
115
116 #endif