timespec_get: New module.
[gnulib.git] / lib / des.h
blobee1943e0730388c3248258d3b220a21b5f0af481
1 /* des.h --- DES cipher implementation.
2 * Copyright (C) 2005, 2007, 2009-2021 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 General Public License as published
6 * by the Free Software Foundation; either version 2, or (at your
7 * option) any later version.
9 * This file is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this file; 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>
26 #include <stdbool.h>
29 * Encryption/Decryption context of DES
31 typedef struct
33 uint32_t encrypt_subkeys[32];
34 uint32_t decrypt_subkeys[32];
35 } gl_des_ctx;
38 * Encryption/Decryption context of Triple-DES
40 typedef struct
42 uint32_t encrypt_subkeys[96];
43 uint32_t decrypt_subkeys[96];
44 } gl_3des_ctx;
46 /* Check whether the 8 byte key is weak. Does not check the parity
47 * bits of the key but simple ignore them. */
48 extern bool
49 gl_des_is_weak_key (const char * key);
52 * DES
53 * ---
56 /* Fill a DES context CTX with subkeys calculated from 64bit KEY.
57 * Does not check parity bits, but simply ignore them. Does not check
58 * for weak keys. */
59 extern void
60 gl_des_setkey (gl_des_ctx *ctx, const char * key);
62 /* Fill a DES context CTX with subkeys calculated from 64bit KEY, with
63 * weak key checking. Does not check parity bits, but simply ignore
64 * them. */
65 extern bool
66 gl_des_makekey (gl_des_ctx *ctx, const char * key, size_t keylen);
68 /* Electronic Codebook Mode DES encryption/decryption of data
69 * according to 'mode'. */
70 extern void
71 gl_des_ecb_crypt (gl_des_ctx *ctx, const char * from, char * to, int mode);
73 #define gl_des_ecb_encrypt(ctx, from, to) gl_des_ecb_crypt(ctx, from, to, 0)
74 #define gl_des_ecb_decrypt(ctx, from, to) gl_des_ecb_crypt(ctx, from, to, 1)
76 /* Triple-DES
77 * ----------
80 /* Fill a Triple-DES context CTX with subkeys calculated from two
81 * 64bit keys in KEY1 and KEY2. Does not check the parity bits of the
82 * keys, but simply ignore them. Does not check for weak keys. */
83 extern void
84 gl_3des_set2keys (gl_3des_ctx *ctx,
85 const char * key1,
86 const char * key2);
89 * Fill a Triple-DES context CTX with subkeys calculated from three
90 * 64bit keys in KEY1, KEY2 and KEY3. Does not check the parity bits
91 * of the keys, but simply ignore them. Does not check for weak
92 * keys. */
93 extern void
94 gl_3des_set3keys (gl_3des_ctx *ctx,
95 const char * key1,
96 const char * key2,
97 const char * key3);
99 /* Fill a Triple-DES context CTX with subkeys calculated from three
100 * concatenated 64bit keys in KEY, with weak key checking. Does not
101 * check the parity bits of the keys, but simply ignore them. */
102 extern bool
103 gl_3des_makekey (gl_3des_ctx *ctx,
104 const char * key,
105 size_t keylen);
107 /* Electronic Codebook Mode Triple-DES encryption/decryption of data
108 * according to 'mode'. Sometimes this mode is named 'EDE' mode
109 * (Encryption-Decryption-Encryption). */
110 extern void
111 gl_3des_ecb_crypt (gl_3des_ctx *ctx,
112 const char * from,
113 char * to,
114 int mode);
116 #define gl_3des_ecb_encrypt(ctx, from, to) gl_3des_ecb_crypt(ctx,from,to,0)
117 #define gl_3des_ecb_decrypt(ctx, from, to) gl_3des_ecb_crypt(ctx,from,to,1)
119 #endif /* DES_H */