chiark / gitweb /
math/t/mpx-mul4: Fix comment markers.
[catacomb] / symm / des.h
1 /* -*-c-*-
2  *
3  * The Data Encryption Standard
4  *
5  * (c) 1999 Straylight/Edgeware
6  */
7
8 /*----- Licensing notice --------------------------------------------------*
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.
16  *
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.
21  *
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
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
40 #ifndef CATACOMB_DES_H
41 #define CATACOMB_DES_H
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
59 extern const octet des_keysz[];
60
61 /*----- Data structures ---------------------------------------------------*/
62
63 typedef struct des_ctx {
64   uint32 k[32];
65 } des_ctx;
66
67 /*----- Functions provided ------------------------------------------------*/
68
69 /* --- @des_expand@ --- *
70  *
71  * Arguments:   @const octet *k@ = pointer to key material
72  *              @size_t n@ = number of octets of key material (7 or 8)
73  *              @uint32 *xx, *yy@ = where to put the results
74  *
75  * Returns:     ---
76  *
77  * Use:         Extracts 64 bits of key material from the given buffer,
78  *              possibly expanding it from 56 to 64 bits on the way.
79  *              Parity is set correctly if the key is expanded.
80  */
81
82 extern void des_expand(const octet */*k*/, size_t /*n*/,
83                        uint32 */*xx*/, uint32 */*yy*/);
84
85 /* --- @des_init@ --- *
86  *
87  * Arguments:   @des_ctx *k@ = pointer to key block
88  *              @const void *buf@ = pointer to key buffer
89  *              @size_t sz@ = size of key material
90  *
91  * Returns:     ---
92  *
93  * Use:         Initializes a DES key buffer.  The key buffer may be either 7
94  *              or 8 bytes long.  If it's 8 bytes, the key is assumed to be
95  *              padded with parity bits in the low order bit of each octet.
96  *              These are stripped out without checking prior to the actual
97  *              key scheduling.
98  */
99
100 extern void des_init(des_ctx */*k*/, const void */*buf*/, size_t /*sz*/);
101
102 /* --- @des_eblk@, @des_dblk@ --- *
103  *
104  * Arguments:   @const des_ctx *k@ = pointer to key block
105  *              @const uint32 s[2]@ = pointer to source block
106  *              @uint32 d[2]@ = pointer to destination block
107  *
108  * Returns:     ---
109  *
110  * Use:         Low-level block encryption and decryption.
111  */
112
113 extern void des_eblk(const des_ctx */*k*/,
114                      const uint32 */*s*/, uint32 */*d*/);
115 extern void des_dblk(const des_ctx */*k*/,
116                      const uint32 */*s*/, uint32 */*d*/);
117
118 /*----- That's all, folks -------------------------------------------------*/
119
120 #ifdef __cplusplus
121   }
122 #endif
123
124 #endif