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