exp2l: Work around a NetBSD 10.0/i386 bug.
[gnulib.git] / lib / des.h
blobc4a1784d5507852795481c9544a891862f5a4707
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>
28 * Encryption/Decryption context of DES
30 typedef struct
32 uint32_t encrypt_subkeys[32];
33 uint32_t decrypt_subkeys[32];
34 } gl_des_ctx;
37 * Encryption/Decryption context of Triple-DES
39 typedef struct
41 uint32_t encrypt_subkeys[96];
42 uint32_t decrypt_subkeys[96];
43 } gl_3des_ctx;
45 /* Check whether the 8 byte key is weak. Does not check the parity
46 * bits of the key but simple ignore them. */
47 extern bool
48 gl_des_is_weak_key (const char * key);
51 * DES
52 * ---
55 /* Fill a DES context CTX with subkeys calculated from 64bit KEY.
56 * Does not check parity bits, but simply ignore them. Does not check
57 * for weak keys. */
58 extern void
59 gl_des_setkey (gl_des_ctx *ctx, const char * key);
61 /* Fill a DES context CTX with subkeys calculated from 64bit KEY, with
62 * weak key checking. Does not check parity bits, but simply ignore
63 * them. */
64 extern bool
65 gl_des_makekey (gl_des_ctx *ctx, const char * key, size_t keylen);
67 /* Electronic Codebook Mode DES encryption/decryption of data
68 * according to 'mode'. */
69 extern void
70 gl_des_ecb_crypt (gl_des_ctx *ctx, const char * from, char * to, int mode);
72 #define gl_des_ecb_encrypt(ctx, from, to) gl_des_ecb_crypt(ctx, from, to, 0)
73 #define gl_des_ecb_decrypt(ctx, from, to) gl_des_ecb_crypt(ctx, from, to, 1)
75 /* Triple-DES
76 * ----------
79 /* Fill a Triple-DES context CTX with subkeys calculated from two
80 * 64bit keys in KEY1 and KEY2. Does not check the parity bits of the
81 * keys, but simply ignore them. Does not check for weak keys. */
82 extern void
83 gl_3des_set2keys (gl_3des_ctx *ctx,
84 const char * key1,
85 const char * key2);
88 * Fill a Triple-DES context CTX with subkeys calculated from three
89 * 64bit keys in KEY1, KEY2 and KEY3. Does not check the parity bits
90 * of the keys, but simply ignore them. Does not check for weak
91 * keys. */
92 extern void
93 gl_3des_set3keys (gl_3des_ctx *ctx,
94 const char * key1,
95 const char * key2,
96 const char * key3);
98 /* Fill a Triple-DES context CTX with subkeys calculated from three
99 * concatenated 64bit keys in KEY, with weak key checking. Does not
100 * check the parity bits of the keys, but simply ignore them. */
101 extern bool
102 gl_3des_makekey (gl_3des_ctx *ctx,
103 const char * key,
104 size_t keylen);
106 /* Electronic Codebook Mode Triple-DES encryption/decryption of data
107 * according to 'mode'. Sometimes this mode is named 'EDE' mode
108 * (Encryption-Decryption-Encryption). */
109 extern void
110 gl_3des_ecb_crypt (gl_3des_ctx *ctx,
111 const char * from,
112 char * to,
113 int mode);
115 #define gl_3des_ecb_encrypt(ctx, from, to) gl_3des_ecb_crypt(ctx,from,to,0)
116 #define gl_3des_ecb_decrypt(ctx, from, to) gl_3des_ecb_crypt(ctx,from,to,1)
118 #endif /* DES_H */