Commit | Line | Data |
---|---|---|
d03ab969 | 1 | /* -*-c-*- |
2 | * | |
d03ab969 | 3 | * The Data Encryption Standard |
4 | * | |
5 | * (c) 1999 Straylight/Edgeware | |
6 | */ | |
7 | ||
45c0fd36 | 8 | /*----- Licensing notice --------------------------------------------------* |
d03ab969 | 9 | * |
10 | * This file is part of Catacomb. | |
11 | * | |
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. | |
45c0fd36 | 16 | * |
d03ab969 | 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. | |
45c0fd36 | 21 | * |
d03ab969 | 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, | |
25 | * MA 02111-1307, USA. | |
26 | */ | |
27 | ||
d03ab969 | 28 | /*----- Notes on the Data Encryption Standard -----------------------------* |
29 | * | |
30 | * Almost twenty years after it was first accepted, DES is still the standard | |
31 | * block cipher. It's showing its age in its small key size and poor | |
32 | * optimiziation for software implementations, but it's not really been badly | |
33 | * dented by the intensive analysis thrown at it. | |
34 | * | |
35 | * This interface is here for compatibility with existing protocols, and | |
36 | * because it's a trivial veneer over the base DES code which is used by the | |
37 | * @des3@ interface which implements proper strong triple-DES. | |
38 | */ | |
39 | ||
b3f05084 | 40 | #ifndef CATACOMB_DES_H |
41 | #define CATACOMB_DES_H | |
d03ab969 | 42 | |
43 | #ifdef __cplusplus | |
44 | extern "C" { | |
45 | #endif | |
46 | ||
47 | /*----- Header files ------------------------------------------------------*/ | |
48 | ||
49 | #include <stddef.h> | |
50 | ||
51 | #include <mLib/bits.h> | |
52 | ||
53 | /*----- Magical numbers ---------------------------------------------------*/ | |
54 | ||
55 | #define DES_BLKSZ 8 | |
56 | #define DES_KEYSZ 7 | |
57 | #define DES_CLASS (N, B, 64) | |
58 | ||
89ae755d | 59 | extern const octet des_keysz[]; |
60 | ||
d03ab969 | 61 | /*----- Data structures ---------------------------------------------------*/ |
62 | ||
63 | typedef struct des_ctx { | |
64 | uint32 k[32]; | |
65 | } des_ctx; | |
66 | ||
67 | /*----- Functions provided ------------------------------------------------*/ | |
68 | ||
3b09bd84 MW |
69 | /* --- @des_fixparity@ --- * |
70 | * | |
71 | * Arguments: @octet *z@ = output buffer pointer, or null | |
72 | * @const octet *p@ = input buffer pointer | |
73 | * @size_t sz@ = size of the buffers | |
74 | * | |
75 | * Returns: Zero if the input already had correct parity, @-1@ if changes | |
76 | * were necessary (in constant time). | |
77 | * | |
78 | * Use: Check the @sz@ bytes at @p@ for odd parity (as used in DES | |
79 | * keys); if @z@ is not null, then copy a parity-fixed version | |
80 | * of @p@ to @z@. The two buffers at @p@ and @z@ may coincide, | |
81 | * or be disjoint, but not otherwise overlap. | |
82 | */ | |
83 | ||
84 | extern int des_fixparity(octet */*z*/, const octet */*p*/, size_t /*sz*/); | |
85 | ||
986527ae | 86 | /* --- @des_expand@ --- * |
87 | * | |
88 | * Arguments: @const octet *k@ = pointer to key material | |
89 | * @size_t n@ = number of octets of key material (7 or 8) | |
90 | * @uint32 *xx, *yy@ = where to put the results | |
91 | * | |
92 | * Returns: --- | |
93 | * | |
94 | * Use: Extracts 64 bits of key material from the given buffer, | |
95 | * possibly expanding it from 56 to 64 bits on the way. | |
96 | * Parity is set correctly if the key is expanded. | |
97 | */ | |
98 | ||
99 | extern void des_expand(const octet */*k*/, size_t /*n*/, | |
100 | uint32 */*xx*/, uint32 */*yy*/); | |
101 | ||
d03ab969 | 102 | /* --- @des_init@ --- * |
103 | * | |
104 | * Arguments: @des_ctx *k@ = pointer to key block | |
105 | * @const void *buf@ = pointer to key buffer | |
106 | * @size_t sz@ = size of key material | |
107 | * | |
108 | * Returns: --- | |
109 | * | |
110 | * Use: Initializes a DES key buffer. The key buffer may be either 7 | |
111 | * or 8 bytes long. If it's 8 bytes, the key is assumed to be | |
112 | * padded with parity bits in the low order bit of each octet. | |
113 | * These are stripped out without checking prior to the actual | |
114 | * key scheduling. | |
115 | */ | |
116 | ||
117 | extern void des_init(des_ctx */*k*/, const void */*buf*/, size_t /*sz*/); | |
118 | ||
119 | /* --- @des_eblk@, @des_dblk@ --- * | |
120 | * | |
121 | * Arguments: @const des_ctx *k@ = pointer to key block | |
122 | * @const uint32 s[2]@ = pointer to source block | |
123 | * @uint32 d[2]@ = pointer to destination block | |
124 | * | |
125 | * Returns: --- | |
126 | * | |
127 | * Use: Low-level block encryption and decryption. | |
128 | */ | |
129 | ||
130 | extern void des_eblk(const des_ctx */*k*/, | |
131 | const uint32 */*s*/, uint32 */*d*/); | |
132 | extern void des_dblk(const des_ctx */*k*/, | |
133 | const uint32 */*s*/, uint32 */*d*/); | |
134 | ||
135 | /*----- That's all, folks -------------------------------------------------*/ | |
136 | ||
137 | #ifdef __cplusplus | |
138 | } | |
139 | #endif | |
140 | ||
141 | #endif |