1 /* des.h --- DES cipher implementation.
2 * Copyright (C) 2005 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, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 /* Adapted for gnulib by Simon Josefsson, based on Libgcrypt. */
31 * Encryption/Decryption context of DES
35 uint32_t encrypt_subkeys
[32];
36 uint32_t decrypt_subkeys
[32];
40 * Encryption/Decryption context of Triple-DES
44 uint32_t encrypt_subkeys
[96];
45 uint32_t decrypt_subkeys
[96];
48 /* Check whether the 8 byte key is weak. Does not check the parity
49 * bits of the key but simple ignore them. */
51 des_is_weak_key (const char * key
);
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
62 des_setkey (des_ctx
*ctx
, const char * key
);
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
68 des_makekey (des_ctx
*ctx
, const char * key
, size_t keylen
);
70 /* Electronic Codebook Mode DES encryption/decryption of data
71 * according to 'mode'. */
73 des_ecb_crypt (des_ctx
*ctx
, const char * from
, char * to
, int mode
);
75 #define des_ecb_encrypt(ctx, from, to) des_ecb_crypt(ctx, from, to, 0)
76 #define des_ecb_decrypt(ctx, from, to) des_ecb_crypt(ctx, from, to, 1)
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. */
86 tripledes_set2keys (tripledes_ctx
*ctx
, const char * key1
, 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
94 tripledes_set3keys (tripledes_ctx
*ctx
, const char * key1
,
95 const char * key2
, const char * key3
);
97 /* Fill a Triple-DES context CTX with subkeys calculated from three
98 * concatenated 64bit keys in KEY, with weak key checking. Does not
99 * check the parity bits of the keys, but simply ignore them. */
101 tripledes_makekey (tripledes_ctx
*ctx
, const char * key
, size_t keylen
);
103 /* Electronic Codebook Mode Triple-DES encryption/decryption of data
104 * according to 'mode'. Sometimes this mode is named 'EDE' mode
105 * (Encryption-Decryption-Encryption). */
107 tripledes_ecb_crypt (tripledes_ctx
*ctx
,
109 char * to
, int mode
);
111 #define tripledes_ecb_encrypt(ctx, from, to) tripledes_ecb_crypt(ctx,from,to,0)
112 #define tripledes_ecb_decrypt(ctx, from, to) tripledes_ecb_crypt(ctx,from,to,1)