Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/* des-compat.h
*
* The des block cipher, libdes/openssl-style interface.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2001 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
*/
#include "des-compat.h"
#include "cbc.h"
void des_ecb3_encrypt(const uint8_t *src, uint8_t *dst,
struct des_ctx *k1, struct des_ctx *k2,
struct des_ctx *k3, int enc)
{
switch(enc)
{
case DES_ENCRYPT:
des_encrypt(k1, dst, src, DES_BLOCK_SIZE);
des_decrypt(k2, dst, dst, DES_BLOCK_SIZE);
des_encrypt(k3, dst, dst, DES_BLOCK_SIZE);
break;
case DES_DECRYPT:
des_decrypt(k3, dst, src, DES_BLOCK_SIZE);
des_encrypt(k2, dst, dst, DES_BLOCK_SIZE);
des_decrypt(k1, dst, dst, DES_BLOCK_SIZE);
break;
default:
abort();
}
}
uint32_t
des_cbc_cksum(const uint8_t *src, uint8_t dst,
long length, struct des_ctx *ctx,
uint8_t *iv);
void
des_cbc_encrypt(const uint8_t *src, uint8_t *dst, long length,
struct des_ctx *ctx, uint8_t *iv,
int enc)
{
cbc_encrypt(ctx, (enc == DES_ENCRYPT) ? des_encrypt : des_decrypt,
DES_BLOCK_SIZE, iv,
length, dst, src);
}
void
des_3cbc_encrypt(const uint8_t *src, uint8_t *dst, long length,
struct des_ctx * k1,struct des_ctx *k2, struct des_ctx *k3,
/* What mode is this, two iv:s? */
uint8_t *iv1, uint8_t *iv2,
int enc);
void
des_ecb_encrypt(const uint8_t *src, uint8_t *dst, long length,
struct des_ctx *ctx, uint8_t *iv,
int enc)
{
)(enc == DES_ENCRYPT) ? des_encrypt : des_decrypt)(
}
void
des_ede3_cbc_encrypt(const uint8_t *src, uint8_t *dst, long length,
struct des_ctx * k1,struct des_ctx *k2, struct des_ctx *k3,
uint8_t *iv,
int enc);
int
des_set_odd_parity(uint8_t *key);
int
des_set_key(const uint8_t *key, struct des_ctx *ctx);
int
des_key_sched(const uint8_t *key, struct des_ctx *ctx);
int
des_is_weak_key(const uint8_t key);