frexpl: Update regarding AIX.
[gnulib.git] / lib / des.h
1 /* des.h --- DES cipher implementation.
2  * Copyright (C) 2005, 2007, 2009, 2010 Free Software Foundation, Inc.
3  *
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.
8  *
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.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this file; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301, USA.
18  *
19  */
20
21 /* Adapted for gnulib by Simon Josefsson, based on Libgcrypt. */
22
23 #ifndef DES_H
24 # define DES_H
25
26 #include <stddef.h>
27 #include <stdint.h>
28 #include <stdbool.h>
29
30 /*
31  * Encryption/Decryption context of DES
32  */
33 typedef struct
34 {
35   uint32_t encrypt_subkeys[32];
36   uint32_t decrypt_subkeys[32];
37 } gl_des_ctx;
38
39 /*
40  * Encryption/Decryption context of Triple-DES
41  */
42 typedef struct
43 {
44   uint32_t encrypt_subkeys[96];
45   uint32_t decrypt_subkeys[96];
46 } gl_3des_ctx;
47
48 /* Check whether the 8 byte key is weak.  Does not check the parity
49  * bits of the key but simple ignore them. */
50 extern bool
51 gl_des_is_weak_key (const char * key);
52
53 /*
54  * DES
55  * ---
56  */
57
58 /* Fill a DES context CTX with subkeys calculated from 64bit KEY.
59  * Does not check parity bits, but simply ignore them.  Does not check
60  * for weak keys. */
61 extern void
62 gl_des_setkey (gl_des_ctx *ctx, const char * key);
63
64 /* Fill a DES context CTX with subkeys calculated from 64bit KEY, with
65  * weak key checking.  Does not check parity bits, but simply ignore
66  * them. */
67 extern bool
68 gl_des_makekey (gl_des_ctx *ctx, const char * key, size_t keylen);
69
70 /* Electronic Codebook Mode DES encryption/decryption of data
71  * according to 'mode'. */
72 extern void
73 gl_des_ecb_crypt (gl_des_ctx *ctx, const char * from,  char * to, int mode);
74
75 #define gl_des_ecb_encrypt(ctx, from, to)  gl_des_ecb_crypt(ctx, from, to, 0)
76 #define gl_des_ecb_decrypt(ctx, from, to)  gl_des_ecb_crypt(ctx, from, to, 1)
77
78 /* Triple-DES
79  * ----------
80  */
81
82 /* Fill a Triple-DES context CTX with subkeys calculated from two
83  * 64bit keys in KEY1 and KEY2.  Does not check the parity bits of the
84  * keys, but simply ignore them.  Does not check for weak keys. */
85 extern void
86 gl_3des_set2keys (gl_3des_ctx *ctx,
87                   const char * key1,
88                   const char * key2);
89
90 /*
91  * Fill a Triple-DES context CTX with subkeys calculated from three
92  * 64bit keys in KEY1, KEY2 and KEY3.  Does not check the parity bits
93  * of the keys, but simply ignore them.  Does not check for weak
94  * keys. */
95 extern void
96 gl_3des_set3keys (gl_3des_ctx *ctx,
97                   const char * key1,
98                   const char * key2,
99                   const char * key3);
100
101 /* Fill a Triple-DES context CTX with subkeys calculated from three
102  * concatenated 64bit keys in KEY, with weak key checking.  Does not
103  * check the parity bits of the keys, but simply ignore them. */
104 extern bool
105 gl_3des_makekey (gl_3des_ctx *ctx,
106                  const char * key,
107                  size_t keylen);
108
109 /* Electronic Codebook Mode Triple-DES encryption/decryption of data
110  * according to 'mode'.  Sometimes this mode is named 'EDE' mode
111  * (Encryption-Decryption-Encryption). */
112 extern void
113 gl_3des_ecb_crypt (gl_3des_ctx *ctx,
114                    const char * from,
115                    char * to,
116                    int mode);
117
118 #define gl_3des_ecb_encrypt(ctx, from, to) gl_3des_ecb_crypt(ctx,from,to,0)
119 #define gl_3des_ecb_decrypt(ctx, from, to) gl_3des_ecb_crypt(ctx,from,to,1)
120
121 #endif /* DES_H */