Mercurial > pidgin
annotate libpurple/ciphers/des.c @ 31398:85412e09b61b
Fix libpurple compile when PURPLE_HIDE_STRUCTS is enabled.
author | Elliott Sales de Andrade <qulogic@pidgin.im> |
---|---|
date | Sun, 20 Mar 2011 19:29:31 +0000 |
parents | ca94413ccd0e |
children |
rev | line source |
---|---|
31218
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
1 /* |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
2 * purple |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
3 * |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
4 * Purple is the legal property of its developers, whose names are too numerous |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
5 * to list here. Please refer to the COPYRIGHT file distributed with this |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
6 * source distribution. |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
7 * |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
8 * Original des taken from gpg |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
9 * |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
10 * des.c - DES and Triple-DES encryption/decryption Algorithm |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
11 * Copyright (C) 1998 Free Software Foundation, Inc. |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
12 * |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
13 * Please see below for more legal information! |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
14 * |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
15 * According to the definition of DES in FIPS PUB 46-2 from December 1993. |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
16 * For a description of triple encryption, see: |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
17 * Bruce Schneier: Applied Cryptography. Second Edition. |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
18 * John Wiley & Sons, 1996. ISBN 0-471-12845-7. Pages 358 ff. |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
19 * |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
20 * This file is part of GnuPG. |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
21 * |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
22 * This program is free software; you can redistribute it and/or modify |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
23 * it under the terms of the GNU General Public License as published by |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
24 * the Free Software Foundation; either version 2 of the License, or |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
25 * (at your option) any later version. |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
26 * |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
27 * This program is distributed in the hope that it will be useful, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
30 * GNU General Public License for more details. |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
31 * |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
32 * You should have received a copy of the GNU General Public License |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
33 * along with this program; if not, write to the Free Software |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
34 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
35 */ |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
36 #include <cipher.h> |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
37 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
38 /****************************************************************************** |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
39 * DES |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
40 *****************************************************************************/ |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
41 typedef struct _des_ctx |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
42 { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
43 guint32 encrypt_subkeys[32]; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
44 guint32 decrypt_subkeys[32]; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
45 } des_ctx[1]; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
46 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
47 /* |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
48 * The s-box values are permuted according to the 'primitive function P' |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
49 */ |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
50 static const guint32 sbox1[64] = |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
51 { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
52 0x00808200, 0x00000000, 0x00008000, 0x00808202, 0x00808002, 0x00008202, 0x00000002, 0x00008000, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
53 0x00000200, 0x00808200, 0x00808202, 0x00000200, 0x00800202, 0x00808002, 0x00800000, 0x00000002, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
54 0x00000202, 0x00800200, 0x00800200, 0x00008200, 0x00008200, 0x00808000, 0x00808000, 0x00800202, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
55 0x00008002, 0x00800002, 0x00800002, 0x00008002, 0x00000000, 0x00000202, 0x00008202, 0x00800000, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
56 0x00008000, 0x00808202, 0x00000002, 0x00808000, 0x00808200, 0x00800000, 0x00800000, 0x00000200, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
57 0x00808002, 0x00008000, 0x00008200, 0x00800002, 0x00000200, 0x00000002, 0x00800202, 0x00008202, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
58 0x00808202, 0x00008002, 0x00808000, 0x00800202, 0x00800002, 0x00000202, 0x00008202, 0x00808200, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
59 0x00000202, 0x00800200, 0x00800200, 0x00000000, 0x00008002, 0x00008200, 0x00000000, 0x00808002 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
60 }; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
61 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
62 static const guint32 sbox2[64] = |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
63 { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
64 0x40084010, 0x40004000, 0x00004000, 0x00084010, 0x00080000, 0x00000010, 0x40080010, 0x40004010, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
65 0x40000010, 0x40084010, 0x40084000, 0x40000000, 0x40004000, 0x00080000, 0x00000010, 0x40080010, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
66 0x00084000, 0x00080010, 0x40004010, 0x00000000, 0x40000000, 0x00004000, 0x00084010, 0x40080000, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
67 0x00080010, 0x40000010, 0x00000000, 0x00084000, 0x00004010, 0x40084000, 0x40080000, 0x00004010, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
68 0x00000000, 0x00084010, 0x40080010, 0x00080000, 0x40004010, 0x40080000, 0x40084000, 0x00004000, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
69 0x40080000, 0x40004000, 0x00000010, 0x40084010, 0x00084010, 0x00000010, 0x00004000, 0x40000000, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
70 0x00004010, 0x40084000, 0x00080000, 0x40000010, 0x00080010, 0x40004010, 0x40000010, 0x00080010, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
71 0x00084000, 0x00000000, 0x40004000, 0x00004010, 0x40000000, 0x40080010, 0x40084010, 0x00084000 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
72 }; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
73 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
74 static const guint32 sbox3[64] = |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
75 { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
76 0x00000104, 0x04010100, 0x00000000, 0x04010004, 0x04000100, 0x00000000, 0x00010104, 0x04000100, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
77 0x00010004, 0x04000004, 0x04000004, 0x00010000, 0x04010104, 0x00010004, 0x04010000, 0x00000104, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
78 0x04000000, 0x00000004, 0x04010100, 0x00000100, 0x00010100, 0x04010000, 0x04010004, 0x00010104, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
79 0x04000104, 0x00010100, 0x00010000, 0x04000104, 0x00000004, 0x04010104, 0x00000100, 0x04000000, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
80 0x04010100, 0x04000000, 0x00010004, 0x00000104, 0x00010000, 0x04010100, 0x04000100, 0x00000000, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
81 0x00000100, 0x00010004, 0x04010104, 0x04000100, 0x04000004, 0x00000100, 0x00000000, 0x04010004, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
82 0x04000104, 0x00010000, 0x04000000, 0x04010104, 0x00000004, 0x00010104, 0x00010100, 0x04000004, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
83 0x04010000, 0x04000104, 0x00000104, 0x04010000, 0x00010104, 0x00000004, 0x04010004, 0x00010100 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
84 }; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
85 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
86 static const guint32 sbox4[64] = |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
87 { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
88 0x80401000, 0x80001040, 0x80001040, 0x00000040, 0x00401040, 0x80400040, 0x80400000, 0x80001000, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
89 0x00000000, 0x00401000, 0x00401000, 0x80401040, 0x80000040, 0x00000000, 0x00400040, 0x80400000, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
90 0x80000000, 0x00001000, 0x00400000, 0x80401000, 0x00000040, 0x00400000, 0x80001000, 0x00001040, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
91 0x80400040, 0x80000000, 0x00001040, 0x00400040, 0x00001000, 0x00401040, 0x80401040, 0x80000040, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
92 0x00400040, 0x80400000, 0x00401000, 0x80401040, 0x80000040, 0x00000000, 0x00000000, 0x00401000, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
93 0x00001040, 0x00400040, 0x80400040, 0x80000000, 0x80401000, 0x80001040, 0x80001040, 0x00000040, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
94 0x80401040, 0x80000040, 0x80000000, 0x00001000, 0x80400000, 0x80001000, 0x00401040, 0x80400040, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
95 0x80001000, 0x00001040, 0x00400000, 0x80401000, 0x00000040, 0x00400000, 0x00001000, 0x00401040 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
96 }; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
97 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
98 static const guint32 sbox5[64] = |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
99 { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
100 0x00000080, 0x01040080, 0x01040000, 0x21000080, 0x00040000, 0x00000080, 0x20000000, 0x01040000, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
101 0x20040080, 0x00040000, 0x01000080, 0x20040080, 0x21000080, 0x21040000, 0x00040080, 0x20000000, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
102 0x01000000, 0x20040000, 0x20040000, 0x00000000, 0x20000080, 0x21040080, 0x21040080, 0x01000080, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
103 0x21040000, 0x20000080, 0x00000000, 0x21000000, 0x01040080, 0x01000000, 0x21000000, 0x00040080, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
104 0x00040000, 0x21000080, 0x00000080, 0x01000000, 0x20000000, 0x01040000, 0x21000080, 0x20040080, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
105 0x01000080, 0x20000000, 0x21040000, 0x01040080, 0x20040080, 0x00000080, 0x01000000, 0x21040000, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
106 0x21040080, 0x00040080, 0x21000000, 0x21040080, 0x01040000, 0x00000000, 0x20040000, 0x21000000, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
107 0x00040080, 0x01000080, 0x20000080, 0x00040000, 0x00000000, 0x20040000, 0x01040080, 0x20000080 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
108 }; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
109 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
110 static const guint32 sbox6[64] = |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
111 { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
112 0x10000008, 0x10200000, 0x00002000, 0x10202008, 0x10200000, 0x00000008, 0x10202008, 0x00200000, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
113 0x10002000, 0x00202008, 0x00200000, 0x10000008, 0x00200008, 0x10002000, 0x10000000, 0x00002008, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
114 0x00000000, 0x00200008, 0x10002008, 0x00002000, 0x00202000, 0x10002008, 0x00000008, 0x10200008, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
115 0x10200008, 0x00000000, 0x00202008, 0x10202000, 0x00002008, 0x00202000, 0x10202000, 0x10000000, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
116 0x10002000, 0x00000008, 0x10200008, 0x00202000, 0x10202008, 0x00200000, 0x00002008, 0x10000008, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
117 0x00200000, 0x10002000, 0x10000000, 0x00002008, 0x10000008, 0x10202008, 0x00202000, 0x10200000, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
118 0x00202008, 0x10202000, 0x00000000, 0x10200008, 0x00000008, 0x00002000, 0x10200000, 0x00202008, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
119 0x00002000, 0x00200008, 0x10002008, 0x00000000, 0x10202000, 0x10000000, 0x00200008, 0x10002008 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
120 }; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
121 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
122 static const guint32 sbox7[64] = |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
123 { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
124 0x00100000, 0x02100001, 0x02000401, 0x00000000, 0x00000400, 0x02000401, 0x00100401, 0x02100400, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
125 0x02100401, 0x00100000, 0x00000000, 0x02000001, 0x00000001, 0x02000000, 0x02100001, 0x00000401, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
126 0x02000400, 0x00100401, 0x00100001, 0x02000400, 0x02000001, 0x02100000, 0x02100400, 0x00100001, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
127 0x02100000, 0x00000400, 0x00000401, 0x02100401, 0x00100400, 0x00000001, 0x02000000, 0x00100400, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
128 0x02000000, 0x00100400, 0x00100000, 0x02000401, 0x02000401, 0x02100001, 0x02100001, 0x00000001, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
129 0x00100001, 0x02000000, 0x02000400, 0x00100000, 0x02100400, 0x00000401, 0x00100401, 0x02100400, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
130 0x00000401, 0x02000001, 0x02100401, 0x02100000, 0x00100400, 0x00000000, 0x00000001, 0x02100401, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
131 0x00000000, 0x00100401, 0x02100000, 0x00000400, 0x02000001, 0x02000400, 0x00000400, 0x00100001 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
132 }; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
133 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
134 static const guint32 sbox8[64] = |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
135 { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
136 0x08000820, 0x00000800, 0x00020000, 0x08020820, 0x08000000, 0x08000820, 0x00000020, 0x08000000, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
137 0x00020020, 0x08020000, 0x08020820, 0x00020800, 0x08020800, 0x00020820, 0x00000800, 0x00000020, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
138 0x08020000, 0x08000020, 0x08000800, 0x00000820, 0x00020800, 0x00020020, 0x08020020, 0x08020800, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
139 0x00000820, 0x00000000, 0x00000000, 0x08020020, 0x08000020, 0x08000800, 0x00020820, 0x00020000, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
140 0x00020820, 0x00020000, 0x08020800, 0x00000800, 0x00000020, 0x08020020, 0x00000800, 0x00020820, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
141 0x08000800, 0x00000020, 0x08000020, 0x08020000, 0x08020020, 0x08000000, 0x00020000, 0x08000820, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
142 0x00000000, 0x08020820, 0x00020020, 0x08000020, 0x08020000, 0x08000800, 0x08000820, 0x00000000, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
143 0x08020820, 0x00020800, 0x00020800, 0x00000820, 0x00000820, 0x00020020, 0x08000000, 0x08020800 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
144 }; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
145 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
146 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
147 /* |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
148 * * These two tables are part of the 'permuted choice 1' function. |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
149 * * In this implementation several speed improvements are done. |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
150 * */ |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
151 static const guint32 leftkey_swap[16] = |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
152 { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
153 0x00000000, 0x00000001, 0x00000100, 0x00000101, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
154 0x00010000, 0x00010001, 0x00010100, 0x00010101, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
155 0x01000000, 0x01000001, 0x01000100, 0x01000101, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
156 0x01010000, 0x01010001, 0x01010100, 0x01010101 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
157 }; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
158 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
159 static const guint32 rightkey_swap[16] = |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
160 { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
161 0x00000000, 0x01000000, 0x00010000, 0x01010000, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
162 0x00000100, 0x01000100, 0x00010100, 0x01010100, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
163 0x00000001, 0x01000001, 0x00010001, 0x01010001, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
164 0x00000101, 0x01000101, 0x00010101, 0x01010101, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
165 }; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
166 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
167 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
168 /* |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
169 * Numbers of left shifts per round for encryption subkey schedule |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
170 * To calculate the decryption key scheduling we just reverse the |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
171 * ordering of the subkeys so we can omit the table for decryption |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
172 * subkey schedule. |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
173 */ |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
174 static const guint8 encrypt_rotate_tab[16] = |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
175 { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
176 1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
177 }; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
178 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
179 /* |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
180 * Macro to swap bits across two words |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
181 **/ |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
182 #define DO_PERMUTATION(a, temp, b, offset, mask) \ |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
183 temp = ((a>>offset) ^ b) & mask; \ |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
184 b ^= temp; \ |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
185 a ^= temp<<offset; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
186 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
187 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
188 /* |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
189 * This performs the 'initial permutation' for the data to be encrypted or decrypted |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
190 **/ |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
191 #define INITIAL_PERMUTATION(left, temp, right) \ |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
192 DO_PERMUTATION(left, temp, right, 4, 0x0f0f0f0f) \ |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
193 DO_PERMUTATION(left, temp, right, 16, 0x0000ffff) \ |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
194 DO_PERMUTATION(right, temp, left, 2, 0x33333333) \ |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
195 DO_PERMUTATION(right, temp, left, 8, 0x00ff00ff) \ |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
196 DO_PERMUTATION(left, temp, right, 1, 0x55555555) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
197 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
198 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
199 /* |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
200 * The 'inverse initial permutation' |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
201 **/ |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
202 #define FINAL_PERMUTATION(left, temp, right) \ |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
203 DO_PERMUTATION(left, temp, right, 1, 0x55555555) \ |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
204 DO_PERMUTATION(right, temp, left, 8, 0x00ff00ff) \ |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
205 DO_PERMUTATION(right, temp, left, 2, 0x33333333) \ |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
206 DO_PERMUTATION(left, temp, right, 16, 0x0000ffff) \ |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
207 DO_PERMUTATION(left, temp, right, 4, 0x0f0f0f0f) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
208 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
209 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
210 /* |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
211 * A full DES round including 'expansion function', 'sbox substitution' |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
212 * and 'primitive function P' but without swapping the left and right word. |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
213 **/ |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
214 #define DES_ROUND(from, to, work, subkey) \ |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
215 work = ((from<<1) | (from>>31)) ^ *subkey++; \ |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
216 to ^= sbox8[ work & 0x3f ]; \ |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
217 to ^= sbox6[ (work>>8) & 0x3f ]; \ |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
218 to ^= sbox4[ (work>>16) & 0x3f ]; \ |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
219 to ^= sbox2[ (work>>24) & 0x3f ]; \ |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
220 work = ((from>>3) | (from<<29)) ^ *subkey++; \ |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
221 to ^= sbox7[ work & 0x3f ]; \ |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
222 to ^= sbox5[ (work>>8) & 0x3f ]; \ |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
223 to ^= sbox3[ (work>>16) & 0x3f ]; \ |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
224 to ^= sbox1[ (work>>24) & 0x3f ]; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
225 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
226 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
227 /* |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
228 * Macros to convert 8 bytes from/to 32bit words |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
229 **/ |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
230 #define READ_64BIT_DATA(data, left, right) \ |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
231 left = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3]; \ |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
232 right = (data[4] << 24) | (data[5] << 16) | (data[6] << 8) | data[7]; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
233 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
234 #define WRITE_64BIT_DATA(data, left, right) \ |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
235 data[0] = (left >> 24) &0xff; data[1] = (left >> 16) &0xff; \ |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
236 data[2] = (left >> 8) &0xff; data[3] = left &0xff; \ |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
237 data[4] = (right >> 24) &0xff; data[5] = (right >> 16) &0xff; \ |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
238 data[6] = (right >> 8) &0xff; data[7] = right &0xff; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
239 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
240 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
241 /* |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
242 * des_key_schedule(): Calculate 16 subkeys pairs (even/odd) for |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
243 * 16 encryption rounds. |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
244 * To calculate subkeys for decryption the caller |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
245 * have to reorder the generated subkeys. |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
246 * |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
247 * rawkey: 8 Bytes of key data |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
248 * subkey: Array of at least 32 guint32s. Will be filled |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
249 * with calculated subkeys. |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
250 * |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
251 **/ |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
252 static void |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
253 des_key_schedule (const guint8 * rawkey, guint32 * subkey) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
254 { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
255 guint32 left, right, work; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
256 int round; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
257 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
258 READ_64BIT_DATA (rawkey, left, right) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
259 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
260 DO_PERMUTATION (right, work, left, 4, 0x0f0f0f0f) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
261 DO_PERMUTATION (right, work, left, 0, 0x10101010) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
262 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
263 left = (leftkey_swap[(left >> 0) & 0xf] << 3) | (leftkey_swap[(left >> 8) & 0xf] << 2) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
264 | (leftkey_swap[(left >> 16) & 0xf] << 1) | (leftkey_swap[(left >> 24) & 0xf]) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
265 | (leftkey_swap[(left >> 5) & 0xf] << 7) | (leftkey_swap[(left >> 13) & 0xf] << 6) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
266 | (leftkey_swap[(left >> 21) & 0xf] << 5) | (leftkey_swap[(left >> 29) & 0xf] << 4); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
267 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
268 left &= 0x0fffffff; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
269 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
270 right = (rightkey_swap[(right >> 1) & 0xf] << 3) | (rightkey_swap[(right >> 9) & 0xf] << 2) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
271 | (rightkey_swap[(right >> 17) & 0xf] << 1) | (rightkey_swap[(right >> 25) & 0xf]) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
272 | (rightkey_swap[(right >> 4) & 0xf] << 7) | (rightkey_swap[(right >> 12) & 0xf] << 6) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
273 | (rightkey_swap[(right >> 20) & 0xf] << 5) | (rightkey_swap[(right >> 28) & 0xf] << 4); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
274 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
275 right &= 0x0fffffff; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
276 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
277 for (round = 0; round < 16; ++round) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
278 { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
279 left = ((left << encrypt_rotate_tab[round]) | (left >> (28 - encrypt_rotate_tab[round]))) & 0x0fffffff; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
280 right = ((right << encrypt_rotate_tab[round]) | (right >> (28 - encrypt_rotate_tab[round]))) & 0x0fffffff; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
281 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
282 *subkey++ = ((left << 4) & 0x24000000) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
283 | ((left << 28) & 0x10000000) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
284 | ((left << 14) & 0x08000000) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
285 | ((left << 18) & 0x02080000) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
286 | ((left << 6) & 0x01000000) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
287 | ((left << 9) & 0x00200000) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
288 | ((left >> 1) & 0x00100000) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
289 | ((left << 10) & 0x00040000) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
290 | ((left << 2) & 0x00020000) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
291 | ((left >> 10) & 0x00010000) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
292 | ((right >> 13) & 0x00002000) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
293 | ((right >> 4) & 0x00001000) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
294 | ((right << 6) & 0x00000800) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
295 | ((right >> 1) & 0x00000400) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
296 | ((right >> 14) & 0x00000200) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
297 | (right & 0x00000100) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
298 | ((right >> 5) & 0x00000020) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
299 | ((right >> 10) & 0x00000010) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
300 | ((right >> 3) & 0x00000008) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
301 | ((right >> 18) & 0x00000004) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
302 | ((right >> 26) & 0x00000002) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
303 | ((right >> 24) & 0x00000001); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
304 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
305 *subkey++ = ((left << 15) & 0x20000000) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
306 | ((left << 17) & 0x10000000) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
307 | ((left << 10) & 0x08000000) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
308 | ((left << 22) & 0x04000000) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
309 | ((left >> 2) & 0x02000000) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
310 | ((left << 1) & 0x01000000) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
311 | ((left << 16) & 0x00200000) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
312 | ((left << 11) & 0x00100000) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
313 | ((left << 3) & 0x00080000) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
314 | ((left >> 6) & 0x00040000) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
315 | ((left << 15) & 0x00020000) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
316 | ((left >> 4) & 0x00010000) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
317 | ((right >> 2) & 0x00002000) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
318 | ((right << 8) & 0x00001000) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
319 | ((right >> 14) & 0x00000808) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
320 | ((right >> 9) & 0x00000400) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
321 | ((right) & 0x00000200) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
322 | ((right << 7) & 0x00000100) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
323 | ((right >> 7) & 0x00000020) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
324 | ((right >> 3) & 0x00000011) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
325 | ((right << 2) & 0x00000004) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
326 | ((right >> 21) & 0x00000002); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
327 } |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
328 } |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
329 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
330 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
331 /* |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
332 * Fill a DES context with subkeys calculated from a 64bit key. |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
333 * Does not check parity bits, but simply ignore them. |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
334 * Does not check for weak keys. |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
335 **/ |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
336 static void |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
337 des_set_key (PurpleCipherContext *context, const guchar * key) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
338 { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
339 struct _des_ctx *ctx = purple_cipher_context_get_data(context); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
340 int i; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
341 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
342 des_key_schedule (key, ctx->encrypt_subkeys); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
343 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
344 for(i=0; i<32; i+=2) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
345 { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
346 ctx->decrypt_subkeys[i] = ctx->encrypt_subkeys[30-i]; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
347 ctx->decrypt_subkeys[i+1] = ctx->encrypt_subkeys[31-i]; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
348 } |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
349 } |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
350 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
351 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
352 /* |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
353 * Electronic Codebook Mode DES encryption/decryption of data according |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
354 * to 'mode'. |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
355 **/ |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
356 static int |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
357 des_ecb_crypt (struct _des_ctx *ctx, const guint8 * from, guint8 * to, int mode) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
358 { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
359 guint32 left, right, work; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
360 guint32 *keys; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
361 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
362 keys = mode ? ctx->decrypt_subkeys : ctx->encrypt_subkeys; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
363 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
364 READ_64BIT_DATA (from, left, right) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
365 INITIAL_PERMUTATION (left, work, right) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
366 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
367 DES_ROUND (right, left, work, keys) DES_ROUND (left, right, work, keys) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
368 DES_ROUND (right, left, work, keys) DES_ROUND (left, right, work, keys) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
369 DES_ROUND (right, left, work, keys) DES_ROUND (left, right, work, keys) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
370 DES_ROUND (right, left, work, keys) DES_ROUND (left, right, work, keys) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
371 DES_ROUND (right, left, work, keys) DES_ROUND (left, right, work, keys) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
372 DES_ROUND (right, left, work, keys) DES_ROUND (left, right, work, keys) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
373 DES_ROUND (right, left, work, keys) DES_ROUND (left, right, work, keys) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
374 DES_ROUND (right, left, work, keys) DES_ROUND (left, right, work, keys) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
375 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
376 FINAL_PERMUTATION (right, work, left) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
377 WRITE_64BIT_DATA (to, right, left) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
378 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
379 return 0; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
380 } |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
381 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
382 static gint |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
383 des_encrypt(PurpleCipherContext *context, const guchar data[], |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
384 size_t len, guchar output[], size_t *outlen) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
385 { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
386 int offset = 0; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
387 int i = 0; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
388 int tmp; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
389 guint8 buf[8] = {0,0,0,0,0,0,0,0}; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
390 while(offset+8<=len) { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
391 des_ecb_crypt(purple_cipher_context_get_data(context), |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
392 data+offset, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
393 output+offset, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
394 0); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
395 offset+=8; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
396 } |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
397 *outlen = len; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
398 if(offset<len) { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
399 *outlen += len - offset; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
400 tmp = offset; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
401 while(tmp<len) { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
402 buf[i++] = data[tmp]; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
403 tmp++; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
404 } |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
405 des_ecb_crypt(purple_cipher_context_get_data(context), |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
406 buf, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
407 output+offset, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
408 0); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
409 } |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
410 return 0; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
411 } |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
412 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
413 static gint |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
414 des_decrypt(PurpleCipherContext *context, const guchar data[], |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
415 size_t len, guchar output[], size_t *outlen) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
416 { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
417 int offset = 0; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
418 int i = 0; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
419 int tmp; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
420 guint8 buf[8] = {0,0,0,0,0,0,0,0}; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
421 while(offset+8<=len) { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
422 des_ecb_crypt(purple_cipher_context_get_data(context), |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
423 data+offset, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
424 output+offset, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
425 1); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
426 offset+=8; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
427 } |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
428 *outlen = len; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
429 if(offset<len) { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
430 *outlen += len - offset; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
431 tmp = offset; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
432 while(tmp<len) { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
433 buf[i++] = data[tmp]; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
434 tmp++; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
435 } |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
436 des_ecb_crypt(purple_cipher_context_get_data(context), |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
437 buf, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
438 output+offset, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
439 1); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
440 } |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
441 return 0; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
442 } |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
443 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
444 static void |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
445 des_init(PurpleCipherContext *context, gpointer extra) { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
446 struct _des_ctx *mctx; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
447 mctx = g_new0(struct _des_ctx, 1); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
448 purple_cipher_context_set_data(context, mctx); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
449 } |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
450 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
451 static void |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
452 des_uninit(PurpleCipherContext *context) { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
453 struct _des_ctx *des_context; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
454 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
455 des_context = purple_cipher_context_get_data(context); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
456 memset(des_context, 0, sizeof(*des_context)); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
457 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
458 g_free(des_context); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
459 des_context = NULL; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
460 } |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
461 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
462 static PurpleCipherOps DESOps = { |
31353
ca94413ccd0e
Named initializers and most other C99isms don't work in Visual C++ .NET 2005 in
Florian Quèze <florian@instantbird.org>
parents:
31219
diff
changeset
|
463 NULL, /* Set option */ |
ca94413ccd0e
Named initializers and most other C99isms don't work in Visual C++ .NET 2005 in
Florian Quèze <florian@instantbird.org>
parents:
31219
diff
changeset
|
464 NULL, /* Get option */ |
ca94413ccd0e
Named initializers and most other C99isms don't work in Visual C++ .NET 2005 in
Florian Quèze <florian@instantbird.org>
parents:
31219
diff
changeset
|
465 des_init, /* init */ |
ca94413ccd0e
Named initializers and most other C99isms don't work in Visual C++ .NET 2005 in
Florian Quèze <florian@instantbird.org>
parents:
31219
diff
changeset
|
466 NULL, /* reset */ |
ca94413ccd0e
Named initializers and most other C99isms don't work in Visual C++ .NET 2005 in
Florian Quèze <florian@instantbird.org>
parents:
31219
diff
changeset
|
467 des_uninit, /* uninit */ |
ca94413ccd0e
Named initializers and most other C99isms don't work in Visual C++ .NET 2005 in
Florian Quèze <florian@instantbird.org>
parents:
31219
diff
changeset
|
468 NULL, /* set iv */ |
ca94413ccd0e
Named initializers and most other C99isms don't work in Visual C++ .NET 2005 in
Florian Quèze <florian@instantbird.org>
parents:
31219
diff
changeset
|
469 NULL, /* append */ |
ca94413ccd0e
Named initializers and most other C99isms don't work in Visual C++ .NET 2005 in
Florian Quèze <florian@instantbird.org>
parents:
31219
diff
changeset
|
470 NULL, /* digest */ |
ca94413ccd0e
Named initializers and most other C99isms don't work in Visual C++ .NET 2005 in
Florian Quèze <florian@instantbird.org>
parents:
31219
diff
changeset
|
471 des_encrypt, /* encrypt */ |
ca94413ccd0e
Named initializers and most other C99isms don't work in Visual C++ .NET 2005 in
Florian Quèze <florian@instantbird.org>
parents:
31219
diff
changeset
|
472 des_decrypt, /* decrypt */ |
ca94413ccd0e
Named initializers and most other C99isms don't work in Visual C++ .NET 2005 in
Florian Quèze <florian@instantbird.org>
parents:
31219
diff
changeset
|
473 NULL, /* set salt */ |
ca94413ccd0e
Named initializers and most other C99isms don't work in Visual C++ .NET 2005 in
Florian Quèze <florian@instantbird.org>
parents:
31219
diff
changeset
|
474 NULL, /* get salt size */ |
ca94413ccd0e
Named initializers and most other C99isms don't work in Visual C++ .NET 2005 in
Florian Quèze <florian@instantbird.org>
parents:
31219
diff
changeset
|
475 des_set_key, /* set key */ |
ca94413ccd0e
Named initializers and most other C99isms don't work in Visual C++ .NET 2005 in
Florian Quèze <florian@instantbird.org>
parents:
31219
diff
changeset
|
476 NULL, /* get key size */ |
ca94413ccd0e
Named initializers and most other C99isms don't work in Visual C++ .NET 2005 in
Florian Quèze <florian@instantbird.org>
parents:
31219
diff
changeset
|
477 NULL, /* set batch mode */ |
ca94413ccd0e
Named initializers and most other C99isms don't work in Visual C++ .NET 2005 in
Florian Quèze <florian@instantbird.org>
parents:
31219
diff
changeset
|
478 NULL, /* get batch mode */ |
ca94413ccd0e
Named initializers and most other C99isms don't work in Visual C++ .NET 2005 in
Florian Quèze <florian@instantbird.org>
parents:
31219
diff
changeset
|
479 NULL, /* get block size */ |
ca94413ccd0e
Named initializers and most other C99isms don't work in Visual C++ .NET 2005 in
Florian Quèze <florian@instantbird.org>
parents:
31219
diff
changeset
|
480 NULL /* set key with len */ |
31218
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
481 }; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
482 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
483 /****************************************************************************** |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
484 * Triple-DES |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
485 *****************************************************************************/ |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
486 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
487 typedef struct _des3_ctx |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
488 { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
489 PurpleCipherBatchMode mode; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
490 guchar iv[8]; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
491 /* First key for encryption */ |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
492 struct _des_ctx key1; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
493 /* Second key for decryption */ |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
494 struct _des_ctx key2; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
495 /* Third key for encryption */ |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
496 struct _des_ctx key3; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
497 } des3_ctx[1]; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
498 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
499 /* |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
500 * Fill a DES3 context with subkeys calculated from 3 64bit key. |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
501 * Does not check parity bits, but simply ignore them. |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
502 * Does not check for weak keys. |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
503 **/ |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
504 static void |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
505 des3_set_key(PurpleCipherContext *context, const guchar * key) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
506 { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
507 struct _des3_ctx *ctx = purple_cipher_context_get_data(context); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
508 int i; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
509 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
510 des_key_schedule (key + 0, ctx->key1.encrypt_subkeys); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
511 des_key_schedule (key + 8, ctx->key2.encrypt_subkeys); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
512 des_key_schedule (key + 16, ctx->key3.encrypt_subkeys); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
513 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
514 for (i = 0; i < 32; i += 2) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
515 { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
516 ctx->key1.decrypt_subkeys[i] = ctx->key1.encrypt_subkeys[30-i]; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
517 ctx->key1.decrypt_subkeys[i+1] = ctx->key1.encrypt_subkeys[31-i]; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
518 ctx->key2.decrypt_subkeys[i] = ctx->key2.encrypt_subkeys[30-i]; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
519 ctx->key2.decrypt_subkeys[i+1] = ctx->key2.encrypt_subkeys[31-i]; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
520 ctx->key3.decrypt_subkeys[i] = ctx->key3.encrypt_subkeys[30-i]; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
521 ctx->key3.decrypt_subkeys[i+1] = ctx->key3.encrypt_subkeys[31-i]; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
522 } |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
523 } |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
524 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
525 static gint |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
526 des3_ecb_encrypt(struct _des3_ctx *ctx, const guchar data[], |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
527 size_t len, guchar output[], size_t *outlen) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
528 { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
529 int offset = 0; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
530 int i = 0; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
531 int tmp; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
532 guint8 buf[8] = {0,0,0,0,0,0,0,0}; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
533 while (offset + 8 <= len) { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
534 des_ecb_crypt(&ctx->key1, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
535 data+offset, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
536 output+offset, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
537 0); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
538 des_ecb_crypt(&ctx->key2, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
539 output+offset, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
540 buf, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
541 1); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
542 des_ecb_crypt(&ctx->key3, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
543 buf, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
544 output+offset, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
545 0); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
546 offset += 8; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
547 } |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
548 *outlen = len; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
549 if (offset < len) { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
550 *outlen += len - offset; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
551 tmp = offset; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
552 memset(buf, 0, 8); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
553 while (tmp < len) { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
554 buf[i++] = data[tmp]; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
555 tmp++; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
556 } |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
557 des_ecb_crypt(&ctx->key1, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
558 buf, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
559 output+offset, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
560 0); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
561 des_ecb_crypt(&ctx->key2, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
562 output+offset, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
563 buf, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
564 1); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
565 des_ecb_crypt(&ctx->key3, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
566 buf, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
567 output+offset, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
568 0); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
569 } |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
570 return 0; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
571 } |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
572 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
573 static gint |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
574 des3_cbc_encrypt(struct _des3_ctx *ctx, const guchar data[], |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
575 size_t len, guchar output[], size_t *outlen) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
576 { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
577 int offset = 0; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
578 int i = 0; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
579 int tmp; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
580 guint8 buf[8]; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
581 memcpy(buf, ctx->iv, 8); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
582 while (offset + 8 <= len) { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
583 for (i = 0; i < 8; i++) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
584 buf[i] ^= data[offset + i]; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
585 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
586 des_ecb_crypt(&ctx->key1, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
587 buf, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
588 output+offset, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
589 0); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
590 des_ecb_crypt(&ctx->key2, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
591 output+offset, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
592 buf, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
593 1); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
594 des_ecb_crypt(&ctx->key3, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
595 buf, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
596 output+offset, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
597 0); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
598 memcpy(buf, output+offset, 8); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
599 offset += 8; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
600 } |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
601 *outlen = len; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
602 if (offset < len) { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
603 *outlen += len - offset; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
604 tmp = offset; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
605 i = 0; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
606 while (tmp < len) { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
607 buf[i++] ^= data[tmp]; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
608 tmp++; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
609 } |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
610 des_ecb_crypt(&ctx->key1, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
611 buf, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
612 output+offset, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
613 0); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
614 des_ecb_crypt(&ctx->key2, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
615 output+offset, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
616 buf, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
617 1); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
618 des_ecb_crypt(&ctx->key3, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
619 buf, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
620 output+offset, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
621 0); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
622 } |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
623 return 0; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
624 } |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
625 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
626 static gint |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
627 des3_encrypt(PurpleCipherContext *context, const guchar data[], |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
628 size_t len, guchar output[], size_t *outlen) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
629 { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
630 struct _des3_ctx *ctx = purple_cipher_context_get_data(context); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
631 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
632 if (ctx->mode == PURPLE_CIPHER_BATCH_MODE_ECB) { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
633 return des3_ecb_encrypt(ctx, data, len, output, outlen); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
634 } else if (ctx->mode == PURPLE_CIPHER_BATCH_MODE_CBC) { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
635 return des3_cbc_encrypt(ctx, data, len, output, outlen); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
636 } else { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
637 g_return_val_if_reached(0); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
638 } |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
639 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
640 return 0; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
641 } |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
642 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
643 static gint |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
644 des3_ecb_decrypt(struct _des3_ctx *ctx, const guchar data[], |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
645 size_t len, guchar output[], size_t *outlen) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
646 { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
647 int offset = 0; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
648 int i = 0; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
649 int tmp; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
650 guint8 buf[8] = {0,0,0,0,0,0,0,0}; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
651 while (offset + 8 <= len) { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
652 /* NOTE: Apply key in reverse */ |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
653 des_ecb_crypt(&ctx->key3, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
654 data+offset, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
655 output+offset, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
656 1); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
657 des_ecb_crypt(&ctx->key2, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
658 output+offset, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
659 buf, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
660 0); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
661 des_ecb_crypt(&ctx->key1, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
662 buf, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
663 output+offset, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
664 1); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
665 offset+=8; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
666 } |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
667 *outlen = len; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
668 if (offset < len) { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
669 *outlen += len - offset; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
670 tmp = offset; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
671 memset(buf, 0, 8); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
672 while (tmp < len) { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
673 buf[i++] = data[tmp]; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
674 tmp++; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
675 } |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
676 des_ecb_crypt(&ctx->key3, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
677 buf, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
678 output+offset, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
679 1); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
680 des_ecb_crypt(&ctx->key2, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
681 output+offset, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
682 buf, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
683 0); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
684 des_ecb_crypt(&ctx->key1, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
685 buf, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
686 output+offset, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
687 1); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
688 } |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
689 return 0; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
690 } |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
691 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
692 static gint |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
693 des3_cbc_decrypt(struct _des3_ctx *ctx, const guchar data[], |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
694 size_t len, guchar output[], size_t *outlen) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
695 { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
696 int offset = 0; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
697 int i = 0; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
698 int tmp; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
699 guint8 buf[8] = {0,0,0,0,0,0,0,0}; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
700 guint8 link[8]; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
701 memcpy(link, ctx->iv, 8); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
702 while (offset + 8 <= len) { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
703 des_ecb_crypt(&ctx->key3, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
704 data+offset, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
705 output+offset, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
706 1); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
707 des_ecb_crypt(&ctx->key2, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
708 output+offset, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
709 buf, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
710 0); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
711 des_ecb_crypt(&ctx->key1, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
712 buf, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
713 output+offset, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
714 1); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
715 for (i = 0; i < 8; i++) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
716 output[offset + i] ^= link[i]; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
717 memcpy(link, data + offset, 8); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
718 offset+=8; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
719 } |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
720 *outlen = len; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
721 if(offset<len) { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
722 *outlen += len - offset; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
723 tmp = offset; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
724 memset(buf, 0, 8); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
725 i = 0; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
726 while(tmp<len) { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
727 buf[i++] = data[tmp]; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
728 tmp++; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
729 } |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
730 des_ecb_crypt(&ctx->key3, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
731 buf, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
732 output+offset, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
733 1); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
734 des_ecb_crypt(&ctx->key2, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
735 output+offset, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
736 buf, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
737 0); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
738 des_ecb_crypt(&ctx->key1, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
739 buf, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
740 output+offset, |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
741 1); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
742 for (i = 0; i < 8; i++) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
743 output[offset + i] ^= link[i]; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
744 } |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
745 return 0; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
746 } |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
747 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
748 static gint |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
749 des3_decrypt(PurpleCipherContext *context, const guchar data[], |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
750 size_t len, guchar output[], size_t *outlen) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
751 { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
752 struct _des3_ctx *ctx = purple_cipher_context_get_data(context); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
753 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
754 if (ctx->mode == PURPLE_CIPHER_BATCH_MODE_ECB) { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
755 return des3_ecb_decrypt(ctx, data, len, output, outlen); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
756 } else if (ctx->mode == PURPLE_CIPHER_BATCH_MODE_CBC) { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
757 return des3_cbc_decrypt(ctx, data, len, output, outlen); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
758 } else { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
759 g_return_val_if_reached(0); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
760 } |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
761 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
762 return 0; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
763 } |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
764 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
765 static void |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
766 des3_set_batch(PurpleCipherContext *context, PurpleCipherBatchMode mode) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
767 { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
768 struct _des3_ctx *ctx = purple_cipher_context_get_data(context); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
769 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
770 ctx->mode = mode; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
771 } |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
772 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
773 static PurpleCipherBatchMode |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
774 des3_get_batch(PurpleCipherContext *context) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
775 { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
776 struct _des3_ctx *ctx = purple_cipher_context_get_data(context); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
777 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
778 return ctx->mode; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
779 } |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
780 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
781 static void |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
782 des3_set_iv(PurpleCipherContext *context, guchar *iv, size_t len) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
783 { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
784 struct _des3_ctx *ctx; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
785 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
786 g_return_if_fail(len == 8); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
787 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
788 ctx = purple_cipher_context_get_data(context); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
789 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
790 memcpy(ctx->iv, iv, len); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
791 } |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
792 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
793 static void |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
794 des3_init(PurpleCipherContext *context, gpointer extra) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
795 { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
796 struct _des3_ctx *mctx; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
797 mctx = g_new0(struct _des3_ctx, 1); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
798 purple_cipher_context_set_data(context, mctx); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
799 } |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
800 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
801 static void |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
802 des3_uninit(PurpleCipherContext *context) |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
803 { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
804 struct _des3_ctx *des3_context; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
805 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
806 des3_context = purple_cipher_context_get_data(context); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
807 memset(des3_context, 0, sizeof(*des3_context)); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
808 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
809 g_free(des3_context); |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
810 des3_context = NULL; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
811 } |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
812 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
813 static PurpleCipherOps DES3Ops = { |
31353
ca94413ccd0e
Named initializers and most other C99isms don't work in Visual C++ .NET 2005 in
Florian Quèze <florian@instantbird.org>
parents:
31219
diff
changeset
|
814 NULL, /* Set option */ |
ca94413ccd0e
Named initializers and most other C99isms don't work in Visual C++ .NET 2005 in
Florian Quèze <florian@instantbird.org>
parents:
31219
diff
changeset
|
815 NULL, /* Get option */ |
ca94413ccd0e
Named initializers and most other C99isms don't work in Visual C++ .NET 2005 in
Florian Quèze <florian@instantbird.org>
parents:
31219
diff
changeset
|
816 des3_init, /* init */ |
ca94413ccd0e
Named initializers and most other C99isms don't work in Visual C++ .NET 2005 in
Florian Quèze <florian@instantbird.org>
parents:
31219
diff
changeset
|
817 NULL, /* reset */ |
ca94413ccd0e
Named initializers and most other C99isms don't work in Visual C++ .NET 2005 in
Florian Quèze <florian@instantbird.org>
parents:
31219
diff
changeset
|
818 des3_uninit, /* uninit */ |
ca94413ccd0e
Named initializers and most other C99isms don't work in Visual C++ .NET 2005 in
Florian Quèze <florian@instantbird.org>
parents:
31219
diff
changeset
|
819 des3_set_iv, /* set iv */ |
ca94413ccd0e
Named initializers and most other C99isms don't work in Visual C++ .NET 2005 in
Florian Quèze <florian@instantbird.org>
parents:
31219
diff
changeset
|
820 NULL, /* append */ |
ca94413ccd0e
Named initializers and most other C99isms don't work in Visual C++ .NET 2005 in
Florian Quèze <florian@instantbird.org>
parents:
31219
diff
changeset
|
821 NULL, /* digest */ |
ca94413ccd0e
Named initializers and most other C99isms don't work in Visual C++ .NET 2005 in
Florian Quèze <florian@instantbird.org>
parents:
31219
diff
changeset
|
822 des3_encrypt, /* encrypt */ |
ca94413ccd0e
Named initializers and most other C99isms don't work in Visual C++ .NET 2005 in
Florian Quèze <florian@instantbird.org>
parents:
31219
diff
changeset
|
823 des3_decrypt, /* decrypt */ |
ca94413ccd0e
Named initializers and most other C99isms don't work in Visual C++ .NET 2005 in
Florian Quèze <florian@instantbird.org>
parents:
31219
diff
changeset
|
824 NULL, /* set salt */ |
ca94413ccd0e
Named initializers and most other C99isms don't work in Visual C++ .NET 2005 in
Florian Quèze <florian@instantbird.org>
parents:
31219
diff
changeset
|
825 NULL, /* get salt size */ |
ca94413ccd0e
Named initializers and most other C99isms don't work in Visual C++ .NET 2005 in
Florian Quèze <florian@instantbird.org>
parents:
31219
diff
changeset
|
826 des3_set_key, /* set key */ |
ca94413ccd0e
Named initializers and most other C99isms don't work in Visual C++ .NET 2005 in
Florian Quèze <florian@instantbird.org>
parents:
31219
diff
changeset
|
827 NULL, /* get key size */ |
ca94413ccd0e
Named initializers and most other C99isms don't work in Visual C++ .NET 2005 in
Florian Quèze <florian@instantbird.org>
parents:
31219
diff
changeset
|
828 des3_set_batch, /* set batch mode */ |
ca94413ccd0e
Named initializers and most other C99isms don't work in Visual C++ .NET 2005 in
Florian Quèze <florian@instantbird.org>
parents:
31219
diff
changeset
|
829 des3_get_batch, /* get batch mode */ |
ca94413ccd0e
Named initializers and most other C99isms don't work in Visual C++ .NET 2005 in
Florian Quèze <florian@instantbird.org>
parents:
31219
diff
changeset
|
830 NULL, /* get block size */ |
ca94413ccd0e
Named initializers and most other C99isms don't work in Visual C++ .NET 2005 in
Florian Quèze <florian@instantbird.org>
parents:
31219
diff
changeset
|
831 NULL /* set key with len */ |
31218
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
832 }; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
833 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
834 /****************************************************************************** |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
835 * Registration |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
836 *****************************************************************************/ |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
837 PurpleCipherOps * |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
838 purple_des_cipher_get_ops(void) { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
839 return &DESOps; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
840 } |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
841 |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
842 PurpleCipherOps * |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
843 purple_des3_cipher_get_ops(void) { |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
844 return &DES3Ops; |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
845 } |
076d62344ede
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
846 |