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