Sun, 17 Nov 2013 04:06:49 +0530
ciphers: Use G_PARAM_STATIC_STRINGS and ensure g_object_notify is always called
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
1 | /* |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
2 | * Original des taken from gpg |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
3 | * |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
4 | * des.c - DES encryption/decryption Algorithm |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
5 | * Copyright (C) 1998 Free Software Foundation, Inc. |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
6 | * |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
7 | * Please see below for more legal information! |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
8 | * |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
9 | * According to the definition of DES in FIPS PUB 46-2 from December 1993. |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
10 | * For a description of triple encryption, see: |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
11 | * Bruce Schneier: Applied Cryptography. Second Edition. |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
12 | * John Wiley & Sons, 1996. ISBN 0-471-12845-7. Pages 358 ff. |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
13 | * |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
14 | * Purple is the legal property of its developers, whose names are too numerous |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
15 | * to list here. Please refer to the COPYRIGHT file distributed with this |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
16 | * source distribution. |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
17 | * |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
18 | * This program is free software; you can redistribute it and/or modify |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
19 | * it under the terms of the GNU General Public License as published by |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
20 | * the Free Software Foundation; either version 2 of the License, or |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
21 | * (at your option) any later version. |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
22 | * |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
23 | * This program is distributed in the hope that it will be useful, |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
24 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
25 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
26 | * GNU General Public License for more details. |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
27 | * |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
28 | * You should have received a copy of the GNU General Public License |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
29 | * along with this program; if not, write to the Free Software |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
30 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
31 | */ |
|
35026
fde23518e1e5
Moved PurpleHash to cipher.[ch]
Ankit Vani <a@nevitus.org>
parents:
35014
diff
changeset
|
32 | #include "internal.h" |
|
34566
e0f887dee077
Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents:
34563
diff
changeset
|
33 | #include "descipher.h" |
|
34644
368d270dc0c3
Included enums.h in AES, DES and DES3 cipher to use the PURPLE_TYPE_BATCH_MODE GType for batch_mode property
Ankit Vani <a@nevitus.org>
parents:
34619
diff
changeset
|
34 | #include "enums.h" |
|
33911
a924aacd5a37
ciphers cleanup: encryption and decryption lengths
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33910
diff
changeset
|
35 | |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
36 | #include <string.h> |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
37 | |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
38 | /****************************************************************************** |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
39 | * Structs |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
40 | *****************************************************************************/ |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
41 | #define PURPLE_DES_CIPHER_GET_PRIVATE(obj) \ |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
42 | (G_TYPE_INSTANCE_GET_PRIVATE((obj), PURPLE_TYPE_DES_CIPHER, PurpleDESCipherPrivate)) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
43 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
44 | typedef struct { |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
45 | guint32 encrypt_subkeys[32]; |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
46 | guint32 decrypt_subkeys[32]; |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
47 | } PurpleDESCipherPrivate; |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
48 | |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
49 | /****************************************************************************** |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
50 | * Enums |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
51 | *****************************************************************************/ |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
52 | enum { |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
53 | PROP_NONE, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
54 | PROP_KEY, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
55 | PROP_LAST, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
56 | }; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
57 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
58 | /****************************************************************************** |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
59 | * Globals |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
60 | *****************************************************************************/ |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
61 | static GObjectClass *parent_class = NULL; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
62 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
63 | /* |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
64 | * The s-box values are permuted according to the 'primitive function P' |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
65 | */ |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
66 | static guint32 sbox1[64] = { |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
67 | 0x00808200, 0x00000000, 0x00008000, 0x00808202, 0x00808002, 0x00008202, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
68 | 0x00000002, 0x00008000, 0x00000200, 0x00808200, 0x00808202, 0x00000200, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
69 | 0x00800202, 0x00808002, 0x00800000, 0x00000002, 0x00000202, 0x00800200, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
70 | 0x00800200, 0x00008200, 0x00008200, 0x00808000, 0x00808000, 0x00800202, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
71 | 0x00008002, 0x00800002, 0x00800002, 0x00008002, 0x00000000, 0x00000202, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
72 | 0x00008202, 0x00800000, 0x00008000, 0x00808202, 0x00000002, 0x00808000, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
73 | 0x00808200, 0x00800000, 0x00800000, 0x00000200, 0x00808002, 0x00008000, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
74 | 0x00008200, 0x00800002, 0x00000200, 0x00000002, 0x00800202, 0x00008202, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
75 | 0x00808202, 0x00008002, 0x00808000, 0x00800202, 0x00800002, 0x00000202, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
76 | 0x00008202, 0x00808200, 0x00000202, 0x00800200, 0x00800200, 0x00000000, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
77 | 0x00008002, 0x00008200, 0x00000000, 0x00808002 |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
78 | }; |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
79 | |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
80 | static guint32 sbox2[64] = { |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
81 | 0x40084010, 0x40004000, 0x00004000, 0x00084010, 0x00080000, 0x00000010, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
82 | 0x40080010, 0x40004010, 0x40000010, 0x40084010, 0x40084000, 0x40000000, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
83 | 0x40004000, 0x00080000, 0x00000010, 0x40080010, 0x00084000, 0x00080010, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
84 | 0x40004010, 0x00000000, 0x40000000, 0x00004000, 0x00084010, 0x40080000, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
85 | 0x00080010, 0x40000010, 0x00000000, 0x00084000, 0x00004010, 0x40084000, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
86 | 0x40080000, 0x00004010, 0x00000000, 0x00084010, 0x40080010, 0x00080000, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
87 | 0x40004010, 0x40080000, 0x40084000, 0x00004000, 0x40080000, 0x40004000, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
88 | 0x00000010, 0x40084010, 0x00084010, 0x00000010, 0x00004000, 0x40000000, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
89 | 0x00004010, 0x40084000, 0x00080000, 0x40000010, 0x00080010, 0x40004010, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
90 | 0x40000010, 0x00080010, 0x00084000, 0x00000000, 0x40004000, 0x00004010, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
91 | 0x40000000, 0x40080010, 0x40084010, 0x00084000 |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
92 | }; |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
93 | |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
94 | static guint32 sbox3[64] = { |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
95 | 0x00000104, 0x04010100, 0x00000000, 0x04010004, 0x04000100, 0x00000000, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
96 | 0x00010104, 0x04000100, 0x00010004, 0x04000004, 0x04000004, 0x00010000, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
97 | 0x04010104, 0x00010004, 0x04010000, 0x00000104, 0x04000000, 0x00000004, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
98 | 0x04010100, 0x00000100, 0x00010100, 0x04010000, 0x04010004, 0x00010104, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
99 | 0x04000104, 0x00010100, 0x00010000, 0x04000104, 0x00000004, 0x04010104, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
100 | 0x00000100, 0x04000000, 0x04010100, 0x04000000, 0x00010004, 0x00000104, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
101 | 0x00010000, 0x04010100, 0x04000100, 0x00000000, 0x00000100, 0x00010004, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
102 | 0x04010104, 0x04000100, 0x04000004, 0x00000100, 0x00000000, 0x04010004, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
103 | 0x04000104, 0x00010000, 0x04000000, 0x04010104, 0x00000004, 0x00010104, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
104 | 0x00010100, 0x04000004, 0x04010000, 0x04000104, 0x00000104, 0x04010000, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
105 | 0x00010104, 0x00000004, 0x04010004, 0x00010100 |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
106 | }; |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
107 | |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
108 | static guint32 sbox4[64] = { |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
109 | 0x80401000, 0x80001040, 0x80001040, 0x00000040, 0x00401040, 0x80400040, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
110 | 0x80400000, 0x80001000, 0x00000000, 0x00401000, 0x00401000, 0x80401040, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
111 | 0x80000040, 0x00000000, 0x00400040, 0x80400000, 0x80000000, 0x00001000, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
112 | 0x00400000, 0x80401000, 0x00000040, 0x00400000, 0x80001000, 0x00001040, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
113 | 0x80400040, 0x80000000, 0x00001040, 0x00400040, 0x00001000, 0x00401040, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
114 | 0x80401040, 0x80000040, 0x00400040, 0x80400000, 0x00401000, 0x80401040, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
115 | 0x80000040, 0x00000000, 0x00000000, 0x00401000, 0x00001040, 0x00400040, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
116 | 0x80400040, 0x80000000, 0x80401000, 0x80001040, 0x80001040, 0x00000040, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
117 | 0x80401040, 0x80000040, 0x80000000, 0x00001000, 0x80400000, 0x80001000, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
118 | 0x00401040, 0x80400040, 0x80001000, 0x00001040, 0x00400000, 0x80401000, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
119 | 0x00000040, 0x00400000, 0x00001000, 0x00401040 |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
120 | }; |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
121 | |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
122 | static guint32 sbox5[64] = { |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
123 | 0x00000080, 0x01040080, 0x01040000, 0x21000080, 0x00040000, 0x00000080, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
124 | 0x20000000, 0x01040000, 0x20040080, 0x00040000, 0x01000080, 0x20040080, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
125 | 0x21000080, 0x21040000, 0x00040080, 0x20000000, 0x01000000, 0x20040000, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
126 | 0x20040000, 0x00000000, 0x20000080, 0x21040080, 0x21040080, 0x01000080, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
127 | 0x21040000, 0x20000080, 0x00000000, 0x21000000, 0x01040080, 0x01000000, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
128 | 0x21000000, 0x00040080, 0x00040000, 0x21000080, 0x00000080, 0x01000000, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
129 | 0x20000000, 0x01040000, 0x21000080, 0x20040080, 0x01000080, 0x20000000, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
130 | 0x21040000, 0x01040080, 0x20040080, 0x00000080, 0x01000000, 0x21040000, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
131 | 0x21040080, 0x00040080, 0x21000000, 0x21040080, 0x01040000, 0x00000000, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
132 | 0x20040000, 0x21000000, 0x00040080, 0x01000080, 0x20000080, 0x00040000, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
133 | 0x00000000, 0x20040000, 0x01040080, 0x20000080 |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
134 | }; |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
135 | |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
136 | static guint32 sbox6[64] = { |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
137 | 0x10000008, 0x10200000, 0x00002000, 0x10202008, 0x10200000, 0x00000008, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
138 | 0x10202008, 0x00200000, 0x10002000, 0x00202008, 0x00200000, 0x10000008, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
139 | 0x00200008, 0x10002000, 0x10000000, 0x00002008, 0x00000000, 0x00200008, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
140 | 0x10002008, 0x00002000, 0x00202000, 0x10002008, 0x00000008, 0x10200008, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
141 | 0x10200008, 0x00000000, 0x00202008, 0x10202000, 0x00002008, 0x00202000, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
142 | 0x10202000, 0x10000000, 0x10002000, 0x00000008, 0x10200008, 0x00202000, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
143 | 0x10202008, 0x00200000, 0x00002008, 0x10000008, 0x00200000, 0x10002000, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
144 | 0x10000000, 0x00002008, 0x10000008, 0x10202008, 0x00202000, 0x10200000, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
145 | 0x00202008, 0x10202000, 0x00000000, 0x10200008, 0x00000008, 0x00002000, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
146 | 0x10200000, 0x00202008, 0x00002000, 0x00200008, 0x10002008, 0x00000000, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
147 | 0x10202000, 0x10000000, 0x00200008, 0x10002008 |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
148 | }; |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
149 | |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
150 | static guint32 sbox7[64] = { |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
151 | 0x00100000, 0x02100001, 0x02000401, 0x00000000, 0x00000400, 0x02000401, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
152 | 0x00100401, 0x02100400, 0x02100401, 0x00100000, 0x00000000, 0x02000001, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
153 | 0x00000001, 0x02000000, 0x02100001, 0x00000401, 0x02000400, 0x00100401, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
154 | 0x00100001, 0x02000400, 0x02000001, 0x02100000, 0x02100400, 0x00100001, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
155 | 0x02100000, 0x00000400, 0x00000401, 0x02100401, 0x00100400, 0x00000001, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
156 | 0x02000000, 0x00100400, 0x02000000, 0x00100400, 0x00100000, 0x02000401, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
157 | 0x02000401, 0x02100001, 0x02100001, 0x00000001, 0x00100001, 0x02000000, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
158 | 0x02000400, 0x00100000, 0x02100400, 0x00000401, 0x00100401, 0x02100400, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
159 | 0x00000401, 0x02000001, 0x02100401, 0x02100000, 0x00100400, 0x00000000, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
160 | 0x00000001, 0x02100401, 0x00000000, 0x00100401, 0x02100000, 0x00000400, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
161 | 0x02000001, 0x02000400, 0x00000400, 0x00100001 |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
162 | }; |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
163 | |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
164 | static guint32 sbox8[64] = { |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
165 | 0x08000820, 0x00000800, 0x00020000, 0x08020820, 0x08000000, 0x08000820, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
166 | 0x00000020, 0x08000000, 0x00020020, 0x08020000, 0x08020820, 0x00020800, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
167 | 0x08020800, 0x00020820, 0x00000800, 0x00000020, 0x08020000, 0x08000020, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
168 | 0x08000800, 0x00000820, 0x00020800, 0x00020020, 0x08020020, 0x08020800, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
169 | 0x00000820, 0x00000000, 0x00000000, 0x08020020, 0x08000020, 0x08000800, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
170 | 0x00020820, 0x00020000, 0x00020820, 0x00020000, 0x08020800, 0x00000800, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
171 | 0x00000020, 0x08020020, 0x00000800, 0x00020820, 0x08000800, 0x00000020, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
172 | 0x08000020, 0x08020000, 0x08020020, 0x08000000, 0x00020000, 0x08000820, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
173 | 0x00000000, 0x08020820, 0x00020020, 0x08000020, 0x08020000, 0x08000800, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
174 | 0x08000820, 0x00000000, 0x08020820, 0x00020800, 0x00020800, 0x00000820, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
175 | 0x00000820, 0x00020020, 0x08000000, 0x08020800 |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
176 | }; |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
177 | |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
178 | /* |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
179 | * These two tables are part of the 'permuted choice 1' function. |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
180 | * In this implementation several speed improvements are done. |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
181 | */ |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
182 | static guint32 leftkey_swap[16] = { |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
183 | 0x00000000, 0x00000001, 0x00000100, 0x00000101, 0x00010000, 0x00010001, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
184 | 0x00010100, 0x00010101, 0x01000000, 0x01000001, 0x01000100, 0x01000101, |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
185 | 0x01010000, 0x01010001, 0x01010100, 0x01010101 |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
186 | }; |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
187 | |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
188 | static guint32 rightkey_swap[16] = { |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
189 | 0x00000000, 0x01000000, 0x00010000, 0x01010000, 0x00000100, 0x01000100, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
190 | 0x00010100, 0x01010100, 0x00000001, 0x01000001, 0x00010001, 0x01010001, |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
191 | 0x00000101, 0x01000101, 0x00010101, 0x01010101, |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
192 | }; |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
193 | |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
194 | /* |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
195 | * Numbers of left shifts per round for encryption subkey schedule |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
196 | * To calculate the decryption key scheduling we just reverse the |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
197 | * ordering of the subkeys so we can omit the table for decryption |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
198 | * subkey schedule. |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
199 | */ |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
200 | static guint8 encrypt_rotate_tab[16] = { |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
201 | 1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1 |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
202 | }; |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
203 | |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
204 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
205 | /****************************************************************************** |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
206 | * Helpers |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
207 | *****************************************************************************/ |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
208 | /* |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
209 | * Macro to swap bits across two words |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
210 | */ |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
211 | #define DO_PERMUTATION(a, temp, b, offset, mask) \ |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
212 | temp = ((a>>offset) ^ b) & mask; \ |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
213 | b ^= temp; \ |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
214 | a ^= temp<<offset; |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
215 | |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
216 | /* |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
217 | * This performs the 'initial permutation' for the data to be encrypted or |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
218 | * decrypted |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
219 | */ |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
220 | #define INITIAL_PERMUTATION(left, temp, right) \ |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
221 | DO_PERMUTATION(left, temp, right, 4, 0x0f0f0f0f) \ |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
222 | DO_PERMUTATION(left, temp, right, 16, 0x0000ffff) \ |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
223 | DO_PERMUTATION(right, temp, left, 2, 0x33333333) \ |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
224 | DO_PERMUTATION(right, temp, left, 8, 0x00ff00ff) \ |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
225 | DO_PERMUTATION(left, temp, right, 1, 0x55555555) |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
226 | |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
227 | /* |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
228 | * The 'inverse initial permutation' |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
229 | */ |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
230 | #define FINAL_PERMUTATION(left, temp, right) \ |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
231 | DO_PERMUTATION(left, temp, right, 1, 0x55555555) \ |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
232 | DO_PERMUTATION(right, temp, left, 8, 0x00ff00ff) \ |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
233 | DO_PERMUTATION(right, temp, left, 2, 0x33333333) \ |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
234 | DO_PERMUTATION(left, temp, right, 16, 0x0000ffff) \ |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
235 | DO_PERMUTATION(left, temp, right, 4, 0x0f0f0f0f) |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
236 | |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
237 | /* |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
238 | * A full DES round including 'expansion function', 'sbox substitution' |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
239 | * and 'primitive function P' but without swapping the left and right word. |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
240 | */ |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
241 | #define DES_ROUND(from, to, work, subkey) \ |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
242 | work = ((from<<1) | (from>>31)) ^ *subkey++; \ |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
243 | to ^= sbox8[ work & 0x3f ]; \ |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
244 | to ^= sbox6[ (work>>8) & 0x3f ]; \ |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
245 | to ^= sbox4[ (work>>16) & 0x3f ]; \ |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
246 | to ^= sbox2[ (work>>24) & 0x3f ]; \ |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
247 | work = ((from>>3) | (from<<29)) ^ *subkey++; \ |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
248 | to ^= sbox7[ work & 0x3f ]; \ |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
249 | to ^= sbox5[ (work>>8) & 0x3f ]; \ |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
250 | to ^= sbox3[ (work>>16) & 0x3f ]; \ |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
251 | to ^= sbox1[ (work>>24) & 0x3f ]; |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
252 | |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
253 | |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
254 | /* |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
255 | * Macros to convert 8 bytes from/to 32bit words |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
256 | */ |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
257 | #define READ_64BIT_DATA(data, left, right) \ |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
258 | left = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3]; \ |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
259 | right = (data[4] << 24) | (data[5] << 16) | (data[6] << 8) | data[7]; |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
260 | |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
261 | #define WRITE_64BIT_DATA(data, left, right) \ |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
262 | data[0] = (left >> 24) &0xff; data[1] = (left >> 16) &0xff; \ |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
263 | data[2] = (left >> 8) &0xff; data[3] = left &0xff; \ |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
264 | data[4] = (right >> 24) &0xff; data[5] = (right >> 16) &0xff; \ |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
265 | data[6] = (right >> 8) &0xff; data[7] = right &0xff; |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
266 | |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
267 | /****************************************************************************** |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
268 | * Cipher Stuff |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
269 | *****************************************************************************/ |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
270 | /* |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
271 | * des_key_schedule(): Calculate 16 subkeys pairs (even/odd) for |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
272 | * 16 encryption rounds. |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
273 | * To calculate subkeys for decryption the caller |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
274 | * have to reorder the generated subkeys. |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
275 | * |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
276 | * rawkey: 8 Bytes of key data |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
277 | * subkey: Array of at least 32 guint32s. Will be filled |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
278 | * with calculated subkeys. |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
279 | * |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
280 | */ |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
281 | static void |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
282 | purple_des_cipher_key_schedule(const guint8 * rawkey, guint32 * subkey) { |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
283 | guint32 left, right, work; |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
284 | int round; |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
285 | |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
286 | READ_64BIT_DATA (rawkey, left, right) |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
287 | |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
288 | DO_PERMUTATION (right, work, left, 4, 0x0f0f0f0f) |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
289 | DO_PERMUTATION (right, work, left, 0, 0x10101010) |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
290 | |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
291 | left = (leftkey_swap[(left >> 0) & 0xf] << 3) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
292 | | (leftkey_swap[(left >> 8) & 0xf] << 2) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
293 | | (leftkey_swap[(left >> 16) & 0xf] << 1) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
294 | | (leftkey_swap[(left >> 24) & 0xf] ) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
295 | | (leftkey_swap[(left >> 5) & 0xf] << 7) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
296 | | (leftkey_swap[(left >> 13) & 0xf] << 6) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
297 | | (leftkey_swap[(left >> 21) & 0xf] << 5) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
298 | | (leftkey_swap[(left >> 29) & 0xf] << 4); |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
299 | |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
300 | left &= 0x0fffffff; |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
301 | |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
302 | right = (rightkey_swap[(right >> 1) & 0xf] << 3) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
303 | | (rightkey_swap[(right >> 9) & 0xf] << 2) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
304 | | (rightkey_swap[(right >> 17) & 0xf] << 1) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
305 | | (rightkey_swap[(right >> 25) & 0xf] ) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
306 | | (rightkey_swap[(right >> 4) & 0xf] << 7) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
307 | | (rightkey_swap[(right >> 12) & 0xf] << 6) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
308 | | (rightkey_swap[(right >> 20) & 0xf] << 5) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
309 | | (rightkey_swap[(right >> 28) & 0xf] << 4); |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
310 | |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
311 | right &= 0x0fffffff; |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
312 | |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
313 | for (round = 0; round < 16; ++round) { |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
314 | left = ((left << encrypt_rotate_tab[round]) | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
315 | (left >> (28 - encrypt_rotate_tab[round]))) & 0x0fffffff; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
316 | right = ((right << encrypt_rotate_tab[round]) | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
317 | (right >> (28 - encrypt_rotate_tab[round]))) & 0x0fffffff; |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
318 | |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
319 | *subkey++ = ((left << 4) & 0x24000000) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
320 | | ((left << 28) & 0x10000000) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
321 | | ((left << 14) & 0x08000000) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
322 | | ((left << 18) & 0x02080000) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
323 | | ((left << 6) & 0x01000000) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
324 | | ((left << 9) & 0x00200000) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
325 | | ((left >> 1) & 0x00100000) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
326 | | ((left << 10) & 0x00040000) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
327 | | ((left << 2) & 0x00020000) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
328 | | ((left >> 10) & 0x00010000) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
329 | | ((right >> 13) & 0x00002000) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
330 | | ((right >> 4) & 0x00001000) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
331 | | ((right << 6) & 0x00000800) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
332 | | ((right >> 1) & 0x00000400) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
333 | | ((right >> 14) & 0x00000200) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
334 | | (right & 0x00000100) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
335 | | ((right >> 5) & 0x00000020) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
336 | | ((right >> 10) & 0x00000010) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
337 | | ((right >> 3) & 0x00000008) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
338 | | ((right >> 18) & 0x00000004) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
339 | | ((right >> 26) & 0x00000002) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
340 | | ((right >> 24) & 0x00000001); |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
341 | |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
342 | *subkey++ = ((left << 15) & 0x20000000) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
343 | | ((left << 17) & 0x10000000) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
344 | | ((left << 10) & 0x08000000) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
345 | | ((left << 22) & 0x04000000) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
346 | | ((left >> 2) & 0x02000000) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
347 | | ((left << 1) & 0x01000000) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
348 | | ((left << 16) & 0x00200000) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
349 | | ((left << 11) & 0x00100000) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
350 | | ((left << 3) & 0x00080000) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
351 | | ((left >> 6) & 0x00040000) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
352 | | ((left << 15) & 0x00020000) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
353 | | ((left >> 4) & 0x00010000) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
354 | | ((right >> 2) & 0x00002000) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
355 | | ((right << 8) & 0x00001000) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
356 | | ((right >> 14) & 0x00000808) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
357 | | ((right >> 9) & 0x00000400) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
358 | | ((right) & 0x00000200) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
359 | | ((right << 7) & 0x00000100) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
360 | | ((right >> 7) & 0x00000020) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
361 | | ((right >> 3) & 0x00000011) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
362 | | ((right << 2) & 0x00000004) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
363 | | ((right >> 21) & 0x00000002); |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
364 | } |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
365 | } |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
366 | |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
367 | /* |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
368 | * Fill a DES context with subkeys calculated from a 64bit key. |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
369 | * Does not check parity bits, but simply ignore them. |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
370 | * Does not check for weak keys. |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
371 | */ |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
372 | static void |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
373 | purple_des_cipher_set_key(PurpleCipher *cipher, const guchar *key, size_t len) { |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
374 | PurpleDESCipher *des_cipher = PURPLE_DES_CIPHER(cipher); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
375 | PurpleDESCipherPrivate *priv = PURPLE_DES_CIPHER_GET_PRIVATE(des_cipher); |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
376 | int i; |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
377 | |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
378 | g_return_if_fail(len == 8); |
|
33908
78b42fd69e02
ciphers cleanup: passing keys with length by default
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33881
diff
changeset
|
379 | |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
380 | purple_des_cipher_key_schedule(key, priv->encrypt_subkeys); |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
381 | |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
382 | for(i = 0; i < 32; i += 2) { |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
383 | priv->decrypt_subkeys[i] = priv->encrypt_subkeys[30 - i]; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
384 | priv->decrypt_subkeys[i + 1] = priv->encrypt_subkeys[31 - i]; |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
385 | } |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
386 | } |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
387 | |
|
33910
5749f2724b12
ciphers cleanup: get key size
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
388 | static size_t |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
389 | purple_des_cipher_get_key_size(PurpleCipher *cipher) |
|
33910
5749f2724b12
ciphers cleanup: get key size
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
390 | { |
|
5749f2724b12
ciphers cleanup: get key size
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
391 | return 8; |
|
5749f2724b12
ciphers cleanup: get key size
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
392 | } |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
393 | |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
394 | /* |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
395 | * Electronic Codebook Mode DES encryption/decryption of data according to |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
396 | * 'mode'. |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
397 | */ |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
398 | int |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
399 | purple_des_cipher_ecb_crypt(PurpleDESCipher *des_cipher, const guint8 * from, guint8 * to, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
400 | int mode) |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
401 | { |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
402 | guint32 left, right, work; |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
403 | guint32 *keys; |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
404 | PurpleDESCipherPrivate *priv = PURPLE_DES_CIPHER_GET_PRIVATE(des_cipher); |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
405 | |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
406 | keys = mode ? priv->decrypt_subkeys : |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
407 | priv->encrypt_subkeys; |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
408 | |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
409 | READ_64BIT_DATA (from, left, right) |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
410 | INITIAL_PERMUTATION (left, work, right) |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
411 | |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
412 | DES_ROUND (right, left, work, keys) DES_ROUND (left, right, work, keys) |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
413 | DES_ROUND (right, left, work, keys) DES_ROUND (left, right, work, keys) |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
414 | DES_ROUND (right, left, work, keys) DES_ROUND (left, right, work, keys) |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
415 | DES_ROUND (right, left, work, keys) DES_ROUND (left, right, work, keys) |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
416 | DES_ROUND (right, left, work, keys) DES_ROUND (left, right, work, keys) |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
417 | DES_ROUND (right, left, work, keys) DES_ROUND (left, right, work, keys) |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
418 | DES_ROUND (right, left, work, keys) DES_ROUND (left, right, work, keys) |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
419 | DES_ROUND (right, left, work, keys) DES_ROUND (left, right, work, keys) |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
420 | |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
421 | FINAL_PERMUTATION (right, work, left) |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
422 | WRITE_64BIT_DATA (to, right, left) |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
423 | |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
424 | return 0; |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
425 | } |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
426 | |
|
33911
a924aacd5a37
ciphers cleanup: encryption and decryption lengths
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33910
diff
changeset
|
427 | static ssize_t |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
428 | purple_des_cipher_encrypt(PurpleCipher *cipher, const guchar input[], |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
429 | size_t in_len, guchar output[], size_t out_size) |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
430 | { |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
431 | PurpleDESCipher *des_cipher = PURPLE_DES_CIPHER(cipher); |
| 34889 | 432 | |
|
34304
faf0414a8b51
Fix most of libpurple warnings about -Wsign-compare
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
34222
diff
changeset
|
433 | gsize offset = 0; |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
434 | int i = 0; |
|
34304
faf0414a8b51
Fix most of libpurple warnings about -Wsign-compare
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
34222
diff
changeset
|
435 | gsize tmp; |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
436 | guint8 buf[8] = {0,0,0,0,0,0,0,0}; |
|
34304
faf0414a8b51
Fix most of libpurple warnings about -Wsign-compare
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
34222
diff
changeset
|
437 | gsize out_len; |
|
33911
a924aacd5a37
ciphers cleanup: encryption and decryption lengths
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33910
diff
changeset
|
438 | |
|
34215
717a428718a6
ciphers: Fix DES sanity checking - this makes MSN work again
Daniel Atallah <datallah@pidgin.im>
parents:
33944
diff
changeset
|
439 | g_return_val_if_fail(out_size >= in_len, -1); |
|
33911
a924aacd5a37
ciphers cleanup: encryption and decryption lengths
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33910
diff
changeset
|
440 | |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
441 | while(offset + 8 <= in_len) { |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
442 | purple_des_cipher_ecb_crypt(des_cipher, input + offset, output + offset, 0); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
443 | offset += 8; |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
444 | } |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
445 | |
|
33911
a924aacd5a37
ciphers cleanup: encryption and decryption lengths
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33910
diff
changeset
|
446 | out_len = in_len; |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
447 | |
|
33911
a924aacd5a37
ciphers cleanup: encryption and decryption lengths
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33910
diff
changeset
|
448 | if(offset<in_len) { |
|
34304
faf0414a8b51
Fix most of libpurple warnings about -Wsign-compare
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
34222
diff
changeset
|
449 | g_return_val_if_fail(in_len >= offset, -1); |
|
33911
a924aacd5a37
ciphers cleanup: encryption and decryption lengths
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33910
diff
changeset
|
450 | out_len += in_len - offset; |
|
34215
717a428718a6
ciphers: Fix DES sanity checking - this makes MSN work again
Daniel Atallah <datallah@pidgin.im>
parents:
33944
diff
changeset
|
451 | g_return_val_if_fail(out_size >= out_len, -1); |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
452 | tmp = offset; |
|
33911
a924aacd5a37
ciphers cleanup: encryption and decryption lengths
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33910
diff
changeset
|
453 | while(tmp<in_len) { |
|
a924aacd5a37
ciphers cleanup: encryption and decryption lengths
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33910
diff
changeset
|
454 | buf[i++] = input[tmp]; |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
455 | tmp++; |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
456 | } |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
457 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
458 | purple_des_cipher_ecb_crypt(des_cipher, buf, output + offset, 0); |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
459 | } |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
460 | |
|
33911
a924aacd5a37
ciphers cleanup: encryption and decryption lengths
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33910
diff
changeset
|
461 | return out_len; |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
462 | } |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
463 | |
|
33944
1ca572ed7563
Fix some minor type warnings.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33914
diff
changeset
|
464 | static ssize_t |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
465 | purple_des_cipher_decrypt(PurpleCipher *cipher, const guchar input[], |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
466 | size_t in_len, guchar output[], size_t out_size) |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
467 | { |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
468 | PurpleDESCipher *des_cipher = PURPLE_DES_CIPHER(cipher); |
| 34889 | 469 | |
|
34304
faf0414a8b51
Fix most of libpurple warnings about -Wsign-compare
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
34222
diff
changeset
|
470 | gsize offset = 0; |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
471 | int i = 0; |
|
34304
faf0414a8b51
Fix most of libpurple warnings about -Wsign-compare
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
34222
diff
changeset
|
472 | gsize tmp; |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
473 | guint8 buf[8] = {0,0,0,0,0,0,0,0}; |
|
34304
faf0414a8b51
Fix most of libpurple warnings about -Wsign-compare
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
34222
diff
changeset
|
474 | gsize out_len; |
|
33911
a924aacd5a37
ciphers cleanup: encryption and decryption lengths
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33910
diff
changeset
|
475 | |
|
34215
717a428718a6
ciphers: Fix DES sanity checking - this makes MSN work again
Daniel Atallah <datallah@pidgin.im>
parents:
33944
diff
changeset
|
476 | g_return_val_if_fail(out_size >= in_len, -1); |
|
33911
a924aacd5a37
ciphers cleanup: encryption and decryption lengths
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33910
diff
changeset
|
477 | |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
478 | while(offset + 8 <= in_len) { |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
479 | purple_des_cipher_ecb_crypt(des_cipher, input + offset, output + offset, 1); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
480 | offset += 8; |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
481 | } |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
482 | |
|
33911
a924aacd5a37
ciphers cleanup: encryption and decryption lengths
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33910
diff
changeset
|
483 | out_len = in_len; |
|
a924aacd5a37
ciphers cleanup: encryption and decryption lengths
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33910
diff
changeset
|
484 | if(offset<in_len) { |
|
34304
faf0414a8b51
Fix most of libpurple warnings about -Wsign-compare
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
34222
diff
changeset
|
485 | g_return_val_if_fail(in_len >= offset, -1); |
|
33911
a924aacd5a37
ciphers cleanup: encryption and decryption lengths
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33910
diff
changeset
|
486 | out_len += in_len - offset; |
|
34215
717a428718a6
ciphers: Fix DES sanity checking - this makes MSN work again
Daniel Atallah <datallah@pidgin.im>
parents:
33944
diff
changeset
|
487 | g_return_val_if_fail(out_size >= out_len, -1); |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
488 | tmp = offset; |
|
33911
a924aacd5a37
ciphers cleanup: encryption and decryption lengths
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33910
diff
changeset
|
489 | while(tmp<in_len) { |
|
a924aacd5a37
ciphers cleanup: encryption and decryption lengths
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33910
diff
changeset
|
490 | buf[i++] = input[tmp]; |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
491 | tmp++; |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
492 | } |
|
33910
5749f2724b12
ciphers cleanup: get key size
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33909
diff
changeset
|
493 | |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
494 | purple_des_cipher_ecb_crypt(des_cipher, buf, output + offset, 1); |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
495 | } |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
496 | |
|
33911
a924aacd5a37
ciphers cleanup: encryption and decryption lengths
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33910
diff
changeset
|
497 | return out_len; |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
498 | } |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
499 | |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
500 | /****************************************************************************** |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
501 | * Object Stuff |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
502 | *****************************************************************************/ |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
503 | static void |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
504 | purple_des_cipher_set_property(GObject *obj, guint param_id, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
505 | const GValue *value, GParamSpec *pspec) |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
506 | { |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
507 | PurpleCipher *cipher = PURPLE_CIPHER(obj); |
|
33911
a924aacd5a37
ciphers cleanup: encryption and decryption lengths
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
33910
diff
changeset
|
508 | |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
509 | switch(param_id) { |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
510 | case PROP_KEY: |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
511 | purple_cipher_set_key(cipher, (guchar *)g_value_get_string(value), |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
512 | purple_des_cipher_get_key_size(cipher)); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
513 | break; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
514 | default: |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
515 | G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
516 | break; |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
517 | } |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
518 | } |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
519 | |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
520 | static void |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
521 | purple_des_cipher_class_init(PurpleDESCipherClass *klass) |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
522 | { |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
523 | GObjectClass *obj_class = G_OBJECT_CLASS(klass); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
524 | PurpleCipherClass *cipher_class = PURPLE_CIPHER_CLASS(klass); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
525 | GParamSpec *pspec; |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
526 | |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
527 | parent_class = g_type_class_peek_parent(klass); |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
528 | |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
529 | obj_class->set_property = purple_des_cipher_set_property; |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
530 | |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
531 | cipher_class->encrypt = purple_des_cipher_encrypt; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
532 | cipher_class->decrypt = purple_des_cipher_decrypt; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
533 | cipher_class->set_key = purple_des_cipher_set_key; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
534 | cipher_class->get_key_size = purple_des_cipher_get_key_size; |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
535 | |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
536 | pspec = g_param_spec_string("key", "key", "key", NULL, |
|
35062
2aee8634c912
ciphers: Use G_PARAM_STATIC_STRINGS and ensure g_object_notify is always called
Ankit Vani <a@nevitus.org>
parents:
35026
diff
changeset
|
537 | G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS); |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
538 | g_object_class_install_property(obj_class, PROP_KEY, pspec); |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
539 | |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
540 | g_type_class_add_private(klass, sizeof(PurpleDESCipherPrivate)); |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
541 | } |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
542 | |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
543 | /****************************************************************************** |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
544 | * API |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
545 | *****************************************************************************/ |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
546 | GType |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
547 | purple_des_cipher_get_type(void) { |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
548 | static GType type = 0; |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
549 | |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
550 | if(type == 0) { |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
551 | static const GTypeInfo info = { |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
552 | .class_size = sizeof(PurpleDESCipherClass), |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
553 | .class_init = (GClassInitFunc)purple_des_cipher_class_init, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
554 | .instance_size = sizeof(PurpleDESCipher), |
|
34548
18cc6efb5194
Added reset at every cipher's initialization
Ankit Vani <a@nevitus.org>
parents:
34547
diff
changeset
|
555 | .instance_init = (GInstanceInitFunc)purple_cipher_reset, |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
556 | }; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
557 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
558 | type = g_type_register_static(PURPLE_TYPE_CIPHER, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
559 | "PurpleDESCipher", |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
560 | &info, 0); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
561 | } |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
562 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
563 | return type; |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
564 | } |
|
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
565 | |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
566 | /** |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
567 | * purple_des_cipher_new: |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
568 | * |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
569 | * Creates a new #PurpleCipher instance which implements the DES block cipher. |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
570 | * |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
571 | * Return Value: The new DES implementation of #PurpleCipher. |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
572 | */ |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
573 | PurpleCipher * |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
574 | purple_des_cipher_new(void) { |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
575 | return g_object_new(PURPLE_TYPE_DES_CIPHER, NULL); |
|
31427
898d3736ee40
broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
576 | } |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
33944
diff
changeset
|
577 |