add packaging
[platform/upstream/nettle.git] / des.h
1 /* des.h
2  *
3  * The des block cipher. And triple des.
4  */
5
6 /* nettle, low-level cryptographics library
7  *
8  * Copyright (C) 1992, 2001, Dana L. How, Niels Möller
9  * 
10  * The nettle library is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU Lesser General Public License as published by
12  * the Free Software Foundation; either version 2.1 of the License, or (at your
13  * option) any later version.
14  * 
15  * The nettle library is distributed in the hope that it will be useful, but
16  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
18  * License for more details.
19  * 
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with the nettle library; see the file COPYING.LIB.  If not, write to
22  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
23  * MA 02111-1301, USA.
24  */
25
26 /*
27  *      des - fast & portable DES encryption & decryption.
28  *      Copyright (C) 1992  Dana L. How
29  *      Please see the file `../lib/descore.README' for the complete copyright
30  *      notice.
31  *
32  * Slightly edited by Niels Möller, 1997
33  */
34
35 #ifndef NETTLE_DES_H_INCLUDED
36 #define NETTLE_DES_H_INCLUDED
37
38 #include "nettle-types.h"
39
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43
44 /* Namespace mangling */
45 #define des_set_key nettle_des_set_key
46 #define des_encrypt nettle_des_encrypt
47 #define des_decrypt nettle_des_decrypt
48 #define des_check_parity nettle_des_check_parity
49 #define des_fix_parity nettle_des_fix_parity
50 #define des3_set_key nettle_des3_set_key
51 #define des3_encrypt nettle_des3_encrypt
52 #define des3_decrypt nettle_des3_decrypt
53
54 #define DES_KEY_SIZE 8
55 #define DES_BLOCK_SIZE 8
56
57 /* Expanded key length */
58 #define _DES_KEY_LENGTH 32
59
60 struct des_ctx
61 {
62   uint32_t key[_DES_KEY_LENGTH];
63 };
64
65 /* Returns 1 for good keys and 0 for weak keys. */
66 int
67 des_set_key(struct des_ctx *ctx, const uint8_t *key);
68
69 void
70 des_encrypt(const struct des_ctx *ctx,
71             unsigned length, uint8_t *dst,
72             const uint8_t *src);
73 void
74 des_decrypt(const struct des_ctx *ctx,
75             unsigned length, uint8_t *dst,
76             const uint8_t *src);
77
78 int
79 des_check_parity(unsigned length, const uint8_t *key);
80
81 void
82 des_fix_parity(unsigned length, uint8_t *dst,
83                const uint8_t *src);
84
85 #define DES3_KEY_SIZE 24
86 #define DES3_BLOCK_SIZE DES_BLOCK_SIZE
87
88 struct des3_ctx
89 {
90   struct des_ctx des[3];
91 };
92
93
94 /* Returns 1 for good keys and 0 for weak keys. */
95 int
96 des3_set_key(struct des3_ctx *ctx, const uint8_t *key);
97
98 void
99 des3_encrypt(const struct des3_ctx *ctx,
100              unsigned length, uint8_t *dst,
101              const uint8_t *src);
102 void
103 des3_decrypt(const struct des3_ctx *ctx,
104              unsigned length, uint8_t *dst,
105              const uint8_t *src);
106
107 #ifdef __cplusplus
108 }
109 #endif
110
111 #endif /* NETTLE_DES_H_INCLUDED */