libpurple/ciphers/descipher.c

Mon, 23 Sep 2013 14:41:07 +0530

author
Ankit Vani <a@nevitus.org>
date
Mon, 23 Sep 2013 14:41:07 +0530
branch
soc.2013.gobjectification
changeset 34965
9abd15d6da07
parent 34889
4ea2da14cd0e
child 35014
21864c2f543f
permissions
-rw-r--r--

Removed 'get_name' from PurpleCipher

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 */
34566
e0f887dee077 Split PurpleCipher into PurpleCipher and PurpleHash. Hashes will subclass PurpleHash.
Ankit Vani <a@nevitus.org>
parents: 34563
diff changeset
32 #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
33 #include "enums.h"
33911
a924aacd5a37 ciphers cleanup: encryption and decryption lengths
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33910
diff changeset
34
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
35 #include <string.h>
31427
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
36
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
37 /******************************************************************************
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
38 * Structs
31427
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
39 *****************************************************************************/
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
40 #define PURPLE_DES_CIPHER_GET_PRIVATE(obj) \
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
41 (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
42
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
43 typedef struct {
31427
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
44 guint32 encrypt_subkeys[32];
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
45 guint32 decrypt_subkeys[32];
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
46 } PurpleDESCipherPrivate;
31427
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
47
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
48 /******************************************************************************
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
49 * Enums
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
50 *****************************************************************************/
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
51 enum {
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
52 PROP_NONE,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
53 PROP_KEY,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
54 PROP_LAST,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
55 };
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 * Globals
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
59 *****************************************************************************/
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
60 static GObjectClass *parent_class = NULL;
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
61
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
62 /*
31427
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
63 * 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
64 */
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
65 static guint32 sbox1[64] = {
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
66 0x00808200, 0x00000000, 0x00008000, 0x00808202, 0x00808002, 0x00008202,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
67 0x00000002, 0x00008000, 0x00000200, 0x00808200, 0x00808202, 0x00000200,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
68 0x00800202, 0x00808002, 0x00800000, 0x00000002, 0x00000202, 0x00800200,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
69 0x00800200, 0x00008200, 0x00008200, 0x00808000, 0x00808000, 0x00800202,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
70 0x00008002, 0x00800002, 0x00800002, 0x00008002, 0x00000000, 0x00000202,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
71 0x00008202, 0x00800000, 0x00008000, 0x00808202, 0x00000002, 0x00808000,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
72 0x00808200, 0x00800000, 0x00800000, 0x00000200, 0x00808002, 0x00008000,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
73 0x00008200, 0x00800002, 0x00000200, 0x00000002, 0x00800202, 0x00008202,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
74 0x00808202, 0x00008002, 0x00808000, 0x00800202, 0x00800002, 0x00000202,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
75 0x00008202, 0x00808200, 0x00000202, 0x00800200, 0x00800200, 0x00000000,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
76 0x00008002, 0x00008200, 0x00000000, 0x00808002
31427
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
77 };
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
78
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
79 static guint32 sbox2[64] = {
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
80 0x40084010, 0x40004000, 0x00004000, 0x00084010, 0x00080000, 0x00000010,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
81 0x40080010, 0x40004010, 0x40000010, 0x40084010, 0x40084000, 0x40000000,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
82 0x40004000, 0x00080000, 0x00000010, 0x40080010, 0x00084000, 0x00080010,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
83 0x40004010, 0x00000000, 0x40000000, 0x00004000, 0x00084010, 0x40080000,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
84 0x00080010, 0x40000010, 0x00000000, 0x00084000, 0x00004010, 0x40084000,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
85 0x40080000, 0x00004010, 0x00000000, 0x00084010, 0x40080010, 0x00080000,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
86 0x40004010, 0x40080000, 0x40084000, 0x00004000, 0x40080000, 0x40004000,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
87 0x00000010, 0x40084010, 0x00084010, 0x00000010, 0x00004000, 0x40000000,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
88 0x00004010, 0x40084000, 0x00080000, 0x40000010, 0x00080010, 0x40004010,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
89 0x40000010, 0x00080010, 0x00084000, 0x00000000, 0x40004000, 0x00004010,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
90 0x40000000, 0x40080010, 0x40084010, 0x00084000
31427
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
91 };
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
92
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
93 static guint32 sbox3[64] = {
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
94 0x00000104, 0x04010100, 0x00000000, 0x04010004, 0x04000100, 0x00000000,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
95 0x00010104, 0x04000100, 0x00010004, 0x04000004, 0x04000004, 0x00010000,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
96 0x04010104, 0x00010004, 0x04010000, 0x00000104, 0x04000000, 0x00000004,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
97 0x04010100, 0x00000100, 0x00010100, 0x04010000, 0x04010004, 0x00010104,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
98 0x04000104, 0x00010100, 0x00010000, 0x04000104, 0x00000004, 0x04010104,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
99 0x00000100, 0x04000000, 0x04010100, 0x04000000, 0x00010004, 0x00000104,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
100 0x00010000, 0x04010100, 0x04000100, 0x00000000, 0x00000100, 0x00010004,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
101 0x04010104, 0x04000100, 0x04000004, 0x00000100, 0x00000000, 0x04010004,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
102 0x04000104, 0x00010000, 0x04000000, 0x04010104, 0x00000004, 0x00010104,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
103 0x00010100, 0x04000004, 0x04010000, 0x04000104, 0x00000104, 0x04010000,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
104 0x00010104, 0x00000004, 0x04010004, 0x00010100
31427
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
105 };
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
106
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
107 static guint32 sbox4[64] = {
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
108 0x80401000, 0x80001040, 0x80001040, 0x00000040, 0x00401040, 0x80400040,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
109 0x80400000, 0x80001000, 0x00000000, 0x00401000, 0x00401000, 0x80401040,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
110 0x80000040, 0x00000000, 0x00400040, 0x80400000, 0x80000000, 0x00001000,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
111 0x00400000, 0x80401000, 0x00000040, 0x00400000, 0x80001000, 0x00001040,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
112 0x80400040, 0x80000000, 0x00001040, 0x00400040, 0x00001000, 0x00401040,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
113 0x80401040, 0x80000040, 0x00400040, 0x80400000, 0x00401000, 0x80401040,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
114 0x80000040, 0x00000000, 0x00000000, 0x00401000, 0x00001040, 0x00400040,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
115 0x80400040, 0x80000000, 0x80401000, 0x80001040, 0x80001040, 0x00000040,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
116 0x80401040, 0x80000040, 0x80000000, 0x00001000, 0x80400000, 0x80001000,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
117 0x00401040, 0x80400040, 0x80001000, 0x00001040, 0x00400000, 0x80401000,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
118 0x00000040, 0x00400000, 0x00001000, 0x00401040
31427
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
119 };
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
120
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
121 static guint32 sbox5[64] = {
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
122 0x00000080, 0x01040080, 0x01040000, 0x21000080, 0x00040000, 0x00000080,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
123 0x20000000, 0x01040000, 0x20040080, 0x00040000, 0x01000080, 0x20040080,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
124 0x21000080, 0x21040000, 0x00040080, 0x20000000, 0x01000000, 0x20040000,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
125 0x20040000, 0x00000000, 0x20000080, 0x21040080, 0x21040080, 0x01000080,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
126 0x21040000, 0x20000080, 0x00000000, 0x21000000, 0x01040080, 0x01000000,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
127 0x21000000, 0x00040080, 0x00040000, 0x21000080, 0x00000080, 0x01000000,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
128 0x20000000, 0x01040000, 0x21000080, 0x20040080, 0x01000080, 0x20000000,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
129 0x21040000, 0x01040080, 0x20040080, 0x00000080, 0x01000000, 0x21040000,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
130 0x21040080, 0x00040080, 0x21000000, 0x21040080, 0x01040000, 0x00000000,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
131 0x20040000, 0x21000000, 0x00040080, 0x01000080, 0x20000080, 0x00040000,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
132 0x00000000, 0x20040000, 0x01040080, 0x20000080
31427
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
133 };
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
134
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
135 static guint32 sbox6[64] = {
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
136 0x10000008, 0x10200000, 0x00002000, 0x10202008, 0x10200000, 0x00000008,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
137 0x10202008, 0x00200000, 0x10002000, 0x00202008, 0x00200000, 0x10000008,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
138 0x00200008, 0x10002000, 0x10000000, 0x00002008, 0x00000000, 0x00200008,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
139 0x10002008, 0x00002000, 0x00202000, 0x10002008, 0x00000008, 0x10200008,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
140 0x10200008, 0x00000000, 0x00202008, 0x10202000, 0x00002008, 0x00202000,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
141 0x10202000, 0x10000000, 0x10002000, 0x00000008, 0x10200008, 0x00202000,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
142 0x10202008, 0x00200000, 0x00002008, 0x10000008, 0x00200000, 0x10002000,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
143 0x10000000, 0x00002008, 0x10000008, 0x10202008, 0x00202000, 0x10200000,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
144 0x00202008, 0x10202000, 0x00000000, 0x10200008, 0x00000008, 0x00002000,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
145 0x10200000, 0x00202008, 0x00002000, 0x00200008, 0x10002008, 0x00000000,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
146 0x10202000, 0x10000000, 0x00200008, 0x10002008
31427
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
147 };
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
148
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
149 static guint32 sbox7[64] = {
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
150 0x00100000, 0x02100001, 0x02000401, 0x00000000, 0x00000400, 0x02000401,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
151 0x00100401, 0x02100400, 0x02100401, 0x00100000, 0x00000000, 0x02000001,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
152 0x00000001, 0x02000000, 0x02100001, 0x00000401, 0x02000400, 0x00100401,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
153 0x00100001, 0x02000400, 0x02000001, 0x02100000, 0x02100400, 0x00100001,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
154 0x02100000, 0x00000400, 0x00000401, 0x02100401, 0x00100400, 0x00000001,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
155 0x02000000, 0x00100400, 0x02000000, 0x00100400, 0x00100000, 0x02000401,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
156 0x02000401, 0x02100001, 0x02100001, 0x00000001, 0x00100001, 0x02000000,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
157 0x02000400, 0x00100000, 0x02100400, 0x00000401, 0x00100401, 0x02100400,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
158 0x00000401, 0x02000001, 0x02100401, 0x02100000, 0x00100400, 0x00000000,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
159 0x00000001, 0x02100401, 0x00000000, 0x00100401, 0x02100000, 0x00000400,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
160 0x02000001, 0x02000400, 0x00000400, 0x00100001
31427
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
161 };
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
162
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
163 static guint32 sbox8[64] = {
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
164 0x08000820, 0x00000800, 0x00020000, 0x08020820, 0x08000000, 0x08000820,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
165 0x00000020, 0x08000000, 0x00020020, 0x08020000, 0x08020820, 0x00020800,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
166 0x08020800, 0x00020820, 0x00000800, 0x00000020, 0x08020000, 0x08000020,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
167 0x08000800, 0x00000820, 0x00020800, 0x00020020, 0x08020020, 0x08020800,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
168 0x00000820, 0x00000000, 0x00000000, 0x08020020, 0x08000020, 0x08000800,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
169 0x00020820, 0x00020000, 0x00020820, 0x00020000, 0x08020800, 0x00000800,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
170 0x00000020, 0x08020020, 0x00000800, 0x00020820, 0x08000800, 0x00000020,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
171 0x08000020, 0x08020000, 0x08020020, 0x08000000, 0x00020000, 0x08000820,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
172 0x00000000, 0x08020820, 0x00020020, 0x08000020, 0x08020000, 0x08000800,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
173 0x08000820, 0x00000000, 0x08020820, 0x00020800, 0x00020800, 0x00000820,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
174 0x00000820, 0x00020020, 0x08000000, 0x08020800
31427
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
175 };
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 /*
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
178 * 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
179 * 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
180 */
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
181 static guint32 leftkey_swap[16] = {
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
182 0x00000000, 0x00000001, 0x00000100, 0x00000101, 0x00010000, 0x00010001,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
183 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
184 0x01010000, 0x01010001, 0x01010100, 0x01010101
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
185 };
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
186
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
187 static guint32 rightkey_swap[16] = {
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
188 0x00000000, 0x01000000, 0x00010000, 0x01010000, 0x00000100, 0x01000100,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
189 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
190 0x00000101, 0x01000101, 0x00010101, 0x01010101,
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
191 };
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 * 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
195 * 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
196 * 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
197 * subkey schedule.
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
198 */
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
199 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
200 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
201 };
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
202
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
203
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 * Helpers
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
206 *****************************************************************************/
31427
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
207 /*
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
208 * Macro to swap bits across two words
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
209 */
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
210 #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
211 temp = ((a>>offset) ^ b) & mask; \
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
212 b ^= temp; \
31427
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
213 a ^= temp<<offset;
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
214
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
215 /*
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
216 * 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
217 * decrypted
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
218 */
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
219 #define INITIAL_PERMUTATION(left, temp, right) \
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
220 DO_PERMUTATION(left, temp, right, 4, 0x0f0f0f0f) \
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
221 DO_PERMUTATION(left, temp, right, 16, 0x0000ffff) \
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
222 DO_PERMUTATION(right, temp, left, 2, 0x33333333) \
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
223 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
224 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
225
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 * The 'inverse initial permutation'
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
228 */
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
229 #define FINAL_PERMUTATION(left, temp, right) \
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
230 DO_PERMUTATION(left, temp, right, 1, 0x55555555) \
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
231 DO_PERMUTATION(right, temp, left, 8, 0x00ff00ff) \
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
232 DO_PERMUTATION(right, temp, left, 2, 0x33333333) \
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
233 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
234 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
235
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 * 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
238 * 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
239 */
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
240 #define DES_ROUND(from, to, work, subkey) \
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
241 work = ((from<<1) | (from>>31)) ^ *subkey++; \
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
242 to ^= sbox8[ work & 0x3f ]; \
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
243 to ^= sbox6[ (work>>8) & 0x3f ]; \
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
244 to ^= sbox4[ (work>>16) & 0x3f ]; \
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
245 to ^= sbox2[ (work>>24) & 0x3f ]; \
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
246 work = ((from>>3) | (from<<29)) ^ *subkey++; \
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
247 to ^= sbox7[ work & 0x3f ]; \
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
248 to ^= sbox5[ (work>>8) & 0x3f ]; \
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
249 to ^= sbox3[ (work>>16) & 0x3f ]; \
31427
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
250 to ^= sbox1[ (work>>24) & 0x3f ];
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
251
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 * 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
255 */
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
256 #define READ_64BIT_DATA(data, left, right) \
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
257 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
258 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
259
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
260 #define WRITE_64BIT_DATA(data, left, right) \
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
261 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
262 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
263 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
264 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
265
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
266 /******************************************************************************
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
267 * Cipher Stuff
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
268 *****************************************************************************/
31427
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
269 /*
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
270 * 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
271 * 16 encryption rounds.
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
272 * 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
273 * have to reorder the generated subkeys.
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
274 *
31427
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
275 * rawkey: 8 Bytes of key data
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
276 * 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
277 * with calculated subkeys.
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
278 *
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
279 */
31427
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
280 static void
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
281 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
282 guint32 left, right, work;
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
283 int round;
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
284
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
285 READ_64BIT_DATA (rawkey, left, right)
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
286
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
287 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
288 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
289
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
290 left = (leftkey_swap[(left >> 0) & 0xf] << 3)
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
291 | (leftkey_swap[(left >> 8) & 0xf] << 2)
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
292 | (leftkey_swap[(left >> 16) & 0xf] << 1)
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
293 | (leftkey_swap[(left >> 24) & 0xf] )
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
294 | (leftkey_swap[(left >> 5) & 0xf] << 7)
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
295 | (leftkey_swap[(left >> 13) & 0xf] << 6)
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
296 | (leftkey_swap[(left >> 21) & 0xf] << 5)
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
297 | (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
298
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
299 left &= 0x0fffffff;
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
300
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
301 right = (rightkey_swap[(right >> 1) & 0xf] << 3)
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
302 | (rightkey_swap[(right >> 9) & 0xf] << 2)
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
303 | (rightkey_swap[(right >> 17) & 0xf] << 1)
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
304 | (rightkey_swap[(right >> 25) & 0xf] )
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
305 | (rightkey_swap[(right >> 4) & 0xf] << 7)
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
306 | (rightkey_swap[(right >> 12) & 0xf] << 6)
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
307 | (rightkey_swap[(right >> 20) & 0xf] << 5)
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
308 | (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
309
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
310 right &= 0x0fffffff;
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
311
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
312 for (round = 0; round < 16; ++round) {
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
313 left = ((left << encrypt_rotate_tab[round]) |
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
314 (left >> (28 - encrypt_rotate_tab[round]))) & 0x0fffffff;
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
315 right = ((right << encrypt_rotate_tab[round]) |
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
316 (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
317
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
318 *subkey++ = ((left << 4) & 0x24000000)
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
319 | ((left << 28) & 0x10000000)
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
320 | ((left << 14) & 0x08000000)
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
321 | ((left << 18) & 0x02080000)
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
322 | ((left << 6) & 0x01000000)
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
323 | ((left << 9) & 0x00200000)
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
324 | ((left >> 1) & 0x00100000)
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
325 | ((left << 10) & 0x00040000)
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
326 | ((left << 2) & 0x00020000)
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
327 | ((left >> 10) & 0x00010000)
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
328 | ((right >> 13) & 0x00002000)
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
329 | ((right >> 4) & 0x00001000)
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
330 | ((right << 6) & 0x00000800)
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
331 | ((right >> 1) & 0x00000400)
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
332 | ((right >> 14) & 0x00000200)
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
333 | (right & 0x00000100)
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
334 | ((right >> 5) & 0x00000020)
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
335 | ((right >> 10) & 0x00000010)
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
336 | ((right >> 3) & 0x00000008)
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
337 | ((right >> 18) & 0x00000004)
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
338 | ((right >> 26) & 0x00000002)
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
339 | ((right >> 24) & 0x00000001);
31427
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
340
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
341 *subkey++ = ((left << 15) & 0x20000000)
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
342 | ((left << 17) & 0x10000000)
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
343 | ((left << 10) & 0x08000000)
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
344 | ((left << 22) & 0x04000000)
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
345 | ((left >> 2) & 0x02000000)
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
346 | ((left << 1) & 0x01000000)
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
347 | ((left << 16) & 0x00200000)
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
348 | ((left << 11) & 0x00100000)
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
349 | ((left << 3) & 0x00080000)
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
350 | ((left >> 6) & 0x00040000)
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
351 | ((left << 15) & 0x00020000)
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
352 | ((left >> 4) & 0x00010000)
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
353 | ((right >> 2) & 0x00002000)
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
354 | ((right << 8) & 0x00001000)
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
355 | ((right >> 14) & 0x00000808)
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
356 | ((right >> 9) & 0x00000400)
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
357 | ((right) & 0x00000200)
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
358 | ((right << 7) & 0x00000100)
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
359 | ((right >> 7) & 0x00000020)
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
360 | ((right >> 3) & 0x00000011)
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
361 | ((right << 2) & 0x00000004)
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
362 | ((right >> 21) & 0x00000002);
31427
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
363 }
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 /*
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
367 * 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
368 * 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
369 * Does not check for weak keys.
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
370 */
31427
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
371 static void
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
372 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
373 PurpleDESCipher *des_cipher = PURPLE_DES_CIPHER(cipher);
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
374 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
375 int i;
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
376
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
377 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
378
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
379 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
380
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
381 for(i = 0; i < 32; i += 2) {
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
382 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
383 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
384 }
34549
7ac9ea3e16e0 Added g_object_notify for property changes
Ankit Vani <a@nevitus.org>
parents: 34548
diff changeset
385
7ac9ea3e16e0 Added g_object_notify for property changes
Ankit Vani <a@nevitus.org>
parents: 34548
diff changeset
386 g_object_notify(G_OBJECT(cipher), "key");
31427
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
387 }
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
388
33910
5749f2724b12 ciphers cleanup: get key size
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33909
diff changeset
389 static size_t
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
390 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
391 {
5749f2724b12 ciphers cleanup: get key size
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33909
diff changeset
392 return 8;
5749f2724b12 ciphers cleanup: get key size
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33909
diff changeset
393 }
31427
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
394
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
395 /*
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
396 * 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
397 * 'mode'.
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
398 */
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
399 int
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
400 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
401 int mode)
31427
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
402 {
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
403 guint32 left, right, work;
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
404 guint32 *keys;
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
405 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
406
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
407 keys = mode ? priv->decrypt_subkeys :
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
408 priv->encrypt_subkeys;
31427
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
409
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
410 READ_64BIT_DATA (from, left, right)
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
411 INITIAL_PERMUTATION (left, work, right)
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
412
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 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
421
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
422 FINAL_PERMUTATION (right, work, left)
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
423 WRITE_64BIT_DATA (to, right, left)
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
424
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
425 return 0;
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
426 }
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
427
33911
a924aacd5a37 ciphers cleanup: encryption and decryption lengths
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33910
diff changeset
428 static ssize_t
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
429 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
430 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
431 {
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
432 PurpleDESCipher *des_cipher = PURPLE_DES_CIPHER(cipher);
34889
4ea2da14cd0e Merged default branch
Ankit Vani <a@nevitus.org>
parents: 34304 34644
diff changeset
433
34304
faf0414a8b51 Fix most of libpurple warnings about -Wsign-compare
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34222
diff changeset
434 gsize offset = 0;
31427
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
435 int i = 0;
34304
faf0414a8b51 Fix most of libpurple warnings about -Wsign-compare
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34222
diff changeset
436 gsize tmp;
31427
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
437 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
438 gsize out_len;
33911
a924aacd5a37 ciphers cleanup: encryption and decryption lengths
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33910
diff changeset
439
34215
717a428718a6 ciphers: Fix DES sanity checking - this makes MSN work again
Daniel Atallah <datallah@pidgin.im>
parents: 33944
diff changeset
440 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
441
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
442 while(offset + 8 <= in_len) {
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
443 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
444 offset += 8;
31427
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
445 }
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
446
33911
a924aacd5a37 ciphers cleanup: encryption and decryption lengths
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33910
diff changeset
447 out_len = in_len;
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
448
33911
a924aacd5a37 ciphers cleanup: encryption and decryption lengths
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33910
diff changeset
449 if(offset<in_len) {
34304
faf0414a8b51 Fix most of libpurple warnings about -Wsign-compare
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34222
diff changeset
450 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
451 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
452 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
453 tmp = offset;
33911
a924aacd5a37 ciphers cleanup: encryption and decryption lengths
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33910
diff changeset
454 while(tmp<in_len) {
a924aacd5a37 ciphers cleanup: encryption and decryption lengths
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33910
diff changeset
455 buf[i++] = input[tmp];
31427
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
456 tmp++;
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
457 }
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
458
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
459 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
460 }
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
461
33911
a924aacd5a37 ciphers cleanup: encryption and decryption lengths
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33910
diff changeset
462 return out_len;
31427
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
463 }
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
464
33944
1ca572ed7563 Fix some minor type warnings.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 33914
diff changeset
465 static ssize_t
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
466 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
467 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
468 {
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
469 PurpleDESCipher *des_cipher = PURPLE_DES_CIPHER(cipher);
34889
4ea2da14cd0e Merged default branch
Ankit Vani <a@nevitus.org>
parents: 34304 34644
diff changeset
470
34304
faf0414a8b51 Fix most of libpurple warnings about -Wsign-compare
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34222
diff changeset
471 gsize offset = 0;
31427
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
472 int i = 0;
34304
faf0414a8b51 Fix most of libpurple warnings about -Wsign-compare
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34222
diff changeset
473 gsize tmp;
31427
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
474 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
475 gsize out_len;
33911
a924aacd5a37 ciphers cleanup: encryption and decryption lengths
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33910
diff changeset
476
34215
717a428718a6 ciphers: Fix DES sanity checking - this makes MSN work again
Daniel Atallah <datallah@pidgin.im>
parents: 33944
diff changeset
477 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
478
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
479 while(offset + 8 <= in_len) {
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
480 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
481 offset += 8;
31427
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
482 }
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
483
33911
a924aacd5a37 ciphers cleanup: encryption and decryption lengths
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33910
diff changeset
484 out_len = in_len;
a924aacd5a37 ciphers cleanup: encryption and decryption lengths
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33910
diff changeset
485 if(offset<in_len) {
34304
faf0414a8b51 Fix most of libpurple warnings about -Wsign-compare
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34222
diff changeset
486 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
487 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
488 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
489 tmp = offset;
33911
a924aacd5a37 ciphers cleanup: encryption and decryption lengths
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33910
diff changeset
490 while(tmp<in_len) {
a924aacd5a37 ciphers cleanup: encryption and decryption lengths
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33910
diff changeset
491 buf[i++] = input[tmp];
31427
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
492 tmp++;
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
493 }
33910
5749f2724b12 ciphers cleanup: get key size
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33909
diff changeset
494
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
495 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
496 }
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
497
33911
a924aacd5a37 ciphers cleanup: encryption and decryption lengths
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33910
diff changeset
498 return out_len;
31427
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
499 }
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
500
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
501 /******************************************************************************
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
502 * Object Stuff
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
503 *****************************************************************************/
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
504 static void
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
505 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
506 const GValue *value, GParamSpec *pspec)
31427
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
507 {
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
508 PurpleCipher *cipher = PURPLE_CIPHER(obj);
33911
a924aacd5a37 ciphers cleanup: encryption and decryption lengths
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33910
diff changeset
509
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
510 switch(param_id) {
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
511 case PROP_KEY:
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
512 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
513 purple_des_cipher_get_key_size(cipher));
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
514 break;
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
515 default:
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
516 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
517 break;
31427
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 }
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
520
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
521 static void
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
522 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
523 {
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
524 GObjectClass *obj_class = G_OBJECT_CLASS(klass);
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
525 PurpleCipherClass *cipher_class = PURPLE_CIPHER_CLASS(klass);
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
526 GParamSpec *pspec;
31427
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
527
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
528 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
529
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
530 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
531
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
532 cipher_class->encrypt = purple_des_cipher_encrypt;
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
533 cipher_class->decrypt = purple_des_cipher_decrypt;
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
534 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
535 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
536
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
537 pspec = g_param_spec_string("key", "key", "key", NULL,
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
538 G_PARAM_WRITABLE);
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
539 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
540
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
541 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
542 }
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
543
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
544 /******************************************************************************
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
545 * API
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
546 *****************************************************************************/
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
547 GType
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
548 purple_des_cipher_get_type(void) {
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
549 static GType type = 0;
31427
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
550
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
551 if(type == 0) {
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
552 static const GTypeInfo info = {
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
553 .class_size = sizeof(PurpleDESCipherClass),
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
554 .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
555 .instance_size = sizeof(PurpleDESCipher),
34548
18cc6efb5194 Added reset at every cipher's initialization
Ankit Vani <a@nevitus.org>
parents: 34547
diff changeset
556 .instance_init = (GInstanceInitFunc)purple_cipher_reset,
34537
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
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
559 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
560 "PurpleDESCipher",
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
561 &info, 0);
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
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
564 return type;
31427
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
565 }
898d3736ee40 broke des and des3 out to ciphers/des.c
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
566
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
567 /**
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
568 * purple_des_cipher_new:
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
569 *
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
570 * 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
571 *
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
572 * 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
573 */
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
574 PurpleCipher *
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
575 purple_des_cipher_new(void) {
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
576 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
577 }
34537
fb40b0460a36 GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents: 33944
diff changeset
578

mercurial