gitlog-to-changelog: Tweak documentation.
[gnulib.git] / lib / des.h
blobb8057a4209e05da748147b20b3c7e4ddfb79a13f
1 /* des.h --- DES cipher implementation.
2 * Copyright (C) 2005, 2007, 2009-2024 Free Software Foundation, Inc.
4 * This file is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as
6 * published by the Free Software Foundation; either version 2.1 of the
7 * License, or (at your option) any later version.
9 * This file is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 /* Adapted for gnulib by Simon Josefsson, based on Libgcrypt. */
21 #ifndef DES_H
22 #define DES_H
24 #include <stddef.h>
25 #include <stdint.h>
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
33 * Encryption/Decryption context of DES
35 typedef struct
37 uint32_t encrypt_subkeys[32];
38 uint32_t decrypt_subkeys[32];
39 } gl_des_ctx;
42 * Encryption/Decryption context of Triple-DES
44 typedef struct
46 uint32_t encrypt_subkeys[96];
47 uint32_t decrypt_subkeys[96];
48 } gl_3des_ctx;
50 /* Check whether the 8 byte key is weak. Does not check the parity
51 * bits of the key but simple ignore them. */
52 extern bool
53 gl_des_is_weak_key (const char * key);
56 * DES
57 * ---
60 /* Fill a DES context CTX with subkeys calculated from 64bit KEY.
61 * Does not check parity bits, but simply ignore them. Does not check
62 * for weak keys. */
63 extern void
64 gl_des_setkey (gl_des_ctx *ctx, const char * key);
66 /* Fill a DES context CTX with subkeys calculated from 64bit KEY, with
67 * weak key checking. Does not check parity bits, but simply ignore
68 * them. */
69 extern bool
70 gl_des_makekey (gl_des_ctx *ctx, const char * key, size_t keylen);
72 /* Electronic Codebook Mode DES encryption/decryption of data
73 * according to 'mode'. */
74 extern void
75 gl_des_ecb_crypt (gl_des_ctx *ctx, const char * from, char * to, int mode);
77 #define gl_des_ecb_encrypt(ctx, from, to) gl_des_ecb_crypt(ctx, from, to, 0)
78 #define gl_des_ecb_decrypt(ctx, from, to) gl_des_ecb_crypt(ctx, from, to, 1)
80 /* Triple-DES
81 * ----------
84 /* Fill a Triple-DES context CTX with subkeys calculated from two
85 * 64bit keys in KEY1 and KEY2. Does not check the parity bits of the
86 * keys, but simply ignore them. Does not check for weak keys. */
87 extern void
88 gl_3des_set2keys (gl_3des_ctx *ctx,
89 const char * key1,
90 const char * key2);
93 * Fill a Triple-DES context CTX with subkeys calculated from three
94 * 64bit keys in KEY1, KEY2 and KEY3. Does not check the parity bits
95 * of the keys, but simply ignore them. Does not check for weak
96 * keys. */
97 extern void
98 gl_3des_set3keys (gl_3des_ctx *ctx,
99 const char * key1,
100 const char * key2,
101 const char * key3);
103 /* Fill a Triple-DES context CTX with subkeys calculated from three
104 * concatenated 64bit keys in KEY, with weak key checking. Does not
105 * check the parity bits of the keys, but simply ignore them. */
106 extern bool
107 gl_3des_makekey (gl_3des_ctx *ctx,
108 const char * key,
109 size_t keylen);
111 /* Electronic Codebook Mode Triple-DES encryption/decryption of data
112 * according to 'mode'. Sometimes this mode is named 'EDE' mode
113 * (Encryption-Decryption-Encryption). */
114 extern void
115 gl_3des_ecb_crypt (gl_3des_ctx *ctx,
116 const char * from,
117 char * to,
118 int mode);
120 #define gl_3des_ecb_encrypt(ctx, from, to) gl_3des_ecb_crypt(ctx,from,to,0)
121 #define gl_3des_ecb_decrypt(ctx, from, to) gl_3des_ecb_crypt(ctx,from,to,1)
124 #ifdef __cplusplus
126 #endif
128 #endif /* DES_H */