3
* The des block cipher, libdes/openssl-style interface.
6
/* nettle, low-level cryptographics library
8
* Copyright (C) 2001 Niels M�ller
10
* The nettle library is free software; you can redistribute it and/or modify
11
* it under the terms of the GNU Lesser General Public License as published by
12
* the Free Software Foundation; either version 2.1 of the License, or (at your
13
* option) any later version.
15
* The nettle library is distributed in the hope that it will be useful, but
16
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18
* License for more details.
20
* You should have received a copy of the GNU Lesser General Public License
21
* along with the nettle library; see the file COPYING.LIB. If not, write to
22
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
26
#ifndef NETTLE_DES_COMPAT_H_INCLUDED
27
#define NETTLE_DES_COMPAT_H_INCLUDED
29
/* According to Assar, des_set_key, des_set_key_odd_parity,
30
* des_is_weak_key, plus the encryption functions (des_*_encrypt and
31
* des_cbc_cksum) would be a pretty useful subset. */
33
/* NOTE: This is quite experimental, and not all functions are
34
* implemented. Contributions, in particular test cases are welcome. */
38
/* We use some name mangling, to avoid collisions with either other
39
* nettle functions or with libcrypto. */
41
#define des_ecb3_encrypt nettle_openssl_des_ecb3_encrypt
42
#define des_cbc_cksum nettle_openssl_des_cbc_cksum
43
#define des_ncbc_encrypt nettle_openssl_des_ncbc_encrypt
44
#define des_cbc_encrypt nettle_openssl_des_cbc_encrypt
45
#define des_ecb_encrypt nettle_openssl_des_ecb_encrypt
46
#define des_ede3_cbc_encrypt nettle_openssl_des_ede3_cbc_encrypt
47
#define des_set_odd_parity nettle_openssl_des_set_odd_parity
48
#define des_check_key nettle_openssl_des_check_key
49
#define des_key_sched nettle_openssl_des_key_sched
50
#define des_is_weak_key nettle_openssl_des_is_weak_key
54
#define des_set_key nettle_openssl_des_key_sched
56
enum { DES_DECRYPT = 0, DES_ENCRYPT = 1 };
59
/* NOTE: Typedef:ed arrays should be avoided, but they're used here
60
* for compatibility. */
62
typedef uint32_t DES_LONG;
64
typedef struct des_ctx des_key_schedule[1];
66
typedef uint8_t des_cblock[DES_BLOCK_SIZE];
69
#define des_ecb2_encrypt(i,o,k1,k2,e) \
70
des_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e))
72
#define des_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \
73
des_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e))
76
extern int des_check_key;
80
/* Typing is a little confusing. Since both des_cblock and
81
des_key_schedule are typedef:ed arrays, it automatically decay to
84
But the functions are declared taking pointers to des_cblock, i.e.
85
pointers to arrays. And on the other hand, they take plain
86
des_key_schedule arguments, which is equivalent to pointers to
89
des_ecb3_encrypt(const des_cblock *src, des_cblock *dst,
92
des_key_schedule k3, int enc);
94
/* des_cbc_cksum in libdes returns a 32 bit integer, representing the
95
* latter half of the output block, using little endian byte order. */
97
des_cbc_cksum(const des_cblock *src, des_cblock *dst,
98
long length, des_key_schedule ctx,
99
const des_cblock *iv);
101
/* NOTE: Doesn't update iv. */
103
des_cbc_encrypt(const des_cblock *src, des_cblock *dst, long length,
104
des_key_schedule ctx, const des_cblock *iv,
107
/* Similar, but updates iv. */
109
des_ncbc_encrypt(const des_cblock *src, des_cblock *dst, long length,
110
des_key_schedule ctx, des_cblock *iv,
114
des_ecb_encrypt(const des_cblock *src, des_cblock *dst,
115
des_key_schedule ctx, int enc);
118
des_ede3_cbc_encrypt(const des_cblock *src, des_cblock *dst, long length,
126
des_set_odd_parity(des_cblock *key);
129
des_key_sched(const des_cblock *key, des_key_schedule ctx);
132
des_is_weak_key(const des_cblock *key);
134
#endif /* NETTLE_DES_COMPAT_H_INCLUDED */