chiark / gitweb /
key/key-io.c (key_new): Don't leak attribute `sym_table' on error.
[catacomb] / symm / des3.h
1 /* -*-c-*-
2  *
3  * Implementation of double- and triple-DES
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 #ifndef CATACOMB_DES3_H
29 #define CATACOMB_DES3_H
30
31 #ifdef __cplusplus
32   extern "C" {
33 #endif
34
35 /*----- Notes on double- and triple-DES -----------------------------------*
36  *
37  * The normal recommendation for using DES now is `triple DES'.
38  * Conventionally, this involves an encrypt-decrypt-encrypt sequence,
39  * although whether the first and last operations use the same key is
40  * unfortunately not agreed upon.  This interface handles both cases (and the
41  * single-key one too, although the simple @des@ calls are quicker for that).
42  */
43
44 /*----- Header files ------------------------------------------------------*/
45
46 #include <stddef.h>
47
48 #include <mLib/bits.h>
49
50 #ifndef CATACOMB_DES_H
51 #  include "des.h"
52 #endif
53
54 /*----- Magical numbers ---------------------------------------------------*/
55
56 #define DES3_BLKSZ 8
57 #define DES3_KEYSZ 21
58 #define DES3_CLASS (N, B, 64)
59
60 extern const octet des3_keysz[];
61
62 /*----- Data structures ---------------------------------------------------*/
63
64 typedef struct des3_ctx {
65   des_ctx a, b, c;
66 } des3_ctx;
67
68 /*----- Functions provided ------------------------------------------------*/
69
70 /* --- @des3_init@ --- *
71  *
72  * Arguments:   @des3_ctx *k@ = pointer to key block
73  *              @const void *buf@ = pointer to key buffer
74  *              @size_t sz@ = size of key material
75  *
76  * Returns:     ---
77  *
78  * Use:         Initializes a DES key buffer.  The key buffer may have length
79  *              7, 8, 14, 16, 21, or 24.  These correspond to one, two or
80  *              three DES keys, either packed or unpacked (i.e., still
81  *              containing parity bits).
82  */
83
84 extern void des3_init(des3_ctx */*k*/, const void */*buf*/, size_t /*sz*/);
85
86 /* --- @des3_eblk@, @des_dblk@ --- *
87  *
88  * Arguments:   @const des3_ctx *k@ = pointer to key block
89  *              @const uint32 s[2]@ = pointer to source block
90  *              @uint32 d[2]@ = pointer to destination block
91  *
92  * Returns:     ---
93  *
94  * Use:         Low-level block encryption and decryption.
95  */
96
97 extern void des3_eblk(const des3_ctx */*k*/,
98                       const uint32 */*s*/, uint32 */*d*/);
99 extern void des3_dblk(const des3_ctx */*k*/,
100                       const uint32 */*s*/, uint32 */*d*/);
101
102 /*----- That's all, folks -------------------------------------------------*/
103
104 #ifdef __cplusplus
105   }
106 #endif
107
108 #endif