Fri, 11 Oct 2013 15:34:15 +0530
Removed g_object_notify calls from ciphers and hashes
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
1 | /* |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
2 | * Original des taken from gpg |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
3 | * |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
4 | * des.c - Triple-DES encryption/decryption Algorithm |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
5 | * Copyright (C) 1998 Free Software Foundation, Inc. |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
6 | * |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
7 | * Please see below for more legal information! |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
8 | * |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
9 | * According to the definition of DES in FIPS PUB 46-2 from December 1993. |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
10 | * For a description of triple encryption, see: |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
11 | * Bruce Schneier: Applied Cryptography. Second Edition. |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
12 | * John Wiley & Sons, 1996. ISBN 0-471-12845-7. Pages 358 ff. |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
13 | * |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
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:
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:
diff
changeset
|
16 | * source distribution. |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
17 | * |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
18 | * This program is free software; you can redistribute it and/or modify |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
19 | * it under the terms of the GNU General Public License as published by |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
20 | * the Free Software Foundation; either version 2 of the License, or |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
21 | * (at your option) any later version. |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
22 | * |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
23 | * This program is distributed in the hope that it will be useful, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
24 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
25 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
26 | * GNU General Public License for more details. |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
27 | * |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
28 | * You should have received a copy of the GNU General Public License |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
29 | * along with this program; if not, write to the Free Software |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
30 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
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 "des3cipher.h" |
|
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:
34603
diff
changeset
|
34 | #include "enums.h" |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
35 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
36 | #include <string.h> |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
37 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
38 | /****************************************************************************** |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
39 | * Structs |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
40 | *****************************************************************************/ |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
41 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
42 | #define PURPLE_DES3_CIPHER_GET_PRIVATE(obj) \ |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
43 | (G_TYPE_INSTANCE_GET_PRIVATE((obj), PURPLE_TYPE_DES3_CIPHER, PurpleDES3CipherPrivate)) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
44 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
45 | typedef struct _PurpleDES3CipherPrivate PurpleDES3CipherPrivate; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
46 | struct _PurpleDES3CipherPrivate |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
47 | { |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
48 | PurpleCipherBatchMode mode; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
49 | guchar iv[8]; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
50 | /* First key for encryption */ |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
51 | PurpleCipher *key1; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
52 | /* Second key for decryption */ |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
53 | PurpleCipher *key2; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
54 | /* Third key for encryption */ |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
55 | PurpleCipher *key3; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
56 | }; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
57 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
58 | /****************************************************************************** |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
59 | * Enums |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
60 | *****************************************************************************/ |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
61 | enum { |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
62 | PROP_NONE, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
63 | PROP_BATCH_MODE, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
64 | PROP_IV, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
65 | PROP_KEY, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
66 | PROP_LAST, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
67 | }; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
68 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
69 | /****************************************************************************** |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
70 | * Globals |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
71 | *****************************************************************************/ |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
72 | static GObjectClass *parent_class = NULL; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
73 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
74 | /****************************************************************************** |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
75 | * Cipher Stuff |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
76 | *****************************************************************************/ |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
77 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
78 | static size_t |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
79 | purple_des3_cipher_get_key_size(PurpleCipher *cipher) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
80 | { |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
81 | return 24; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
82 | } |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
83 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
84 | /* |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
85 | * Fill a DES3 context with subkeys calculated from 3 64bit key. |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
86 | * Does not check parity bits, but simply ignore them. |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
87 | * Does not check for weak keys. |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
88 | **/ |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
89 | static void |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
90 | purple_des3_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:
diff
changeset
|
91 | { |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
92 | PurpleDES3Cipher *des3_cipher = PURPLE_DES3_CIPHER(cipher); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
93 | PurpleDES3CipherPrivate *priv = PURPLE_DES3_CIPHER_GET_PRIVATE(des3_cipher); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
94 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
95 | g_return_if_fail(len == 24); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
96 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
97 | purple_cipher_set_key(PURPLE_CIPHER(priv->key1), key + 0, |
|
34563
5c76133baa15
Fixed DES and DES3 ciphers according to the test suite.
Ankit Vani <a@nevitus.org>
parents:
34550
diff
changeset
|
98 | purple_cipher_get_key_size(PURPLE_CIPHER(priv->key1))); |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
99 | purple_cipher_set_key(PURPLE_CIPHER(priv->key2), key + 8, |
|
34563
5c76133baa15
Fixed DES and DES3 ciphers according to the test suite.
Ankit Vani <a@nevitus.org>
parents:
34550
diff
changeset
|
100 | purple_cipher_get_key_size(PURPLE_CIPHER(priv->key2))); |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
101 | purple_cipher_set_key(PURPLE_CIPHER(priv->key3), key + 16, |
|
34563
5c76133baa15
Fixed DES and DES3 ciphers according to the test suite.
Ankit Vani <a@nevitus.org>
parents:
34550
diff
changeset
|
102 | purple_cipher_get_key_size(PURPLE_CIPHER(priv->key3))); |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
103 | } |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
104 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
105 | static ssize_t |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
106 | purple_des3_cipher_ecb_encrypt(PurpleDES3Cipher *des3_cipher, const guchar input[], |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
107 | size_t in_len, guchar output[], size_t out_size) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
108 | { |
| 34889 | 109 | gsize offset = 0; |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
110 | int i = 0; |
| 34889 | 111 | gsize tmp; |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
112 | guint8 buf[8] = {0,0,0,0,0,0,0,0}; |
| 34889 | 113 | gsize out_len; |
| 34603 | 114 | PurpleDES3CipherPrivate *priv = PURPLE_DES3_CIPHER_GET_PRIVATE(des3_cipher); |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
115 | |
| 34603 | 116 | g_return_val_if_fail(out_size >= in_len, -1); |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
117 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
118 | while (offset + 8 <= in_len) { |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
119 | purple_des_cipher_ecb_crypt(PURPLE_DES_CIPHER(priv->key1), |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
120 | input + offset, output + offset, 0); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
121 | purple_des_cipher_ecb_crypt(PURPLE_DES_CIPHER(priv->key2), |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
122 | output + offset, buf, 1); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
123 | purple_des_cipher_ecb_crypt(PURPLE_DES_CIPHER(priv->key3), |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
124 | buf, output + offset, 0); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
125 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
126 | offset += 8; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
127 | } |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
128 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
129 | out_len = in_len; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
130 | if (offset < in_len) { |
| 34889 | 131 | g_return_val_if_fail(in_len >= offset, -1); |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
132 | out_len += in_len - offset; |
| 34603 | 133 | g_return_val_if_fail(out_size >= out_len, -1); |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
134 | tmp = offset; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
135 | memset(buf, 0, 8); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
136 | while (tmp < in_len) { |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
137 | buf[i++] = input[tmp]; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
138 | tmp++; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
139 | } |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
140 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
141 | purple_des_cipher_ecb_crypt(PURPLE_DES_CIPHER(priv->key1), |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
142 | buf, output + offset, 0); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
143 | purple_des_cipher_ecb_crypt(PURPLE_DES_CIPHER(priv->key2), |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
144 | output + offset, buf, 1); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
145 | purple_des_cipher_ecb_crypt(PURPLE_DES_CIPHER(priv->key3), |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
146 | buf, output + offset, 0); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
147 | } |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
148 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
149 | return out_len; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
150 | } |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
151 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
152 | static ssize_t |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
153 | purple_des3_cipher_cbc_encrypt(PurpleDES3Cipher *des3_cipher, const guchar input[], |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
154 | size_t in_len, guchar output[], size_t out_size) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
155 | { |
| 34889 | 156 | gsize offset = 0; |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
157 | int i = 0; |
| 34889 | 158 | gsize tmp; |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
159 | guint8 buf[8]; |
| 34889 | 160 | gsize out_len; |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
161 | PurpleDES3CipherPrivate *priv = PURPLE_DES3_CIPHER_GET_PRIVATE(des3_cipher); |
| 34889 | 162 | |
| 34603 | 163 | memcpy(buf, priv->iv, 8); |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
164 | |
| 34603 | 165 | g_return_val_if_fail(out_size >= in_len, -1); |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
166 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
167 | while (offset + 8 <= in_len) { |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
168 | for (i = 0; i < 8; i++) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
169 | buf[i] ^= input[offset + i]; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
170 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
171 | purple_des_cipher_ecb_crypt(PURPLE_DES_CIPHER(priv->key1), |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
172 | buf, output + offset, 0); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
173 | purple_des_cipher_ecb_crypt(PURPLE_DES_CIPHER(priv->key2), |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
174 | output + offset, buf, 1); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
175 | purple_des_cipher_ecb_crypt(PURPLE_DES_CIPHER(priv->key3), |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
176 | buf, output + offset, 0); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
177 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
178 | memcpy(buf, output+offset, 8); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
179 | offset += 8; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
180 | } |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
181 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
182 | out_len = in_len; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
183 | if (offset < in_len) { |
| 34889 | 184 | g_return_val_if_fail(in_len >= offset, -1); |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
185 | out_len += in_len - offset; |
| 34603 | 186 | g_return_val_if_fail(out_size >= out_len, -1); |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
187 | tmp = offset; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
188 | i = 0; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
189 | while (tmp < in_len) { |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
190 | buf[i++] ^= input[tmp]; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
191 | tmp++; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
192 | } |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
193 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
194 | purple_des_cipher_ecb_crypt(PURPLE_DES_CIPHER(priv->key1), |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
195 | buf, output + offset, 0); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
196 | purple_des_cipher_ecb_crypt(PURPLE_DES_CIPHER(priv->key2), |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
197 | output + offset, buf, 1); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
198 | purple_des_cipher_ecb_crypt(PURPLE_DES_CIPHER(priv->key3), |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
199 | buf, output + offset, 0); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
200 | } |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
201 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
202 | return out_len; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
203 | } |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
204 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
205 | static ssize_t |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
206 | purple_des3_cipher_encrypt(PurpleCipher *cipher, const guchar input[], |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
207 | size_t in_len, guchar output[], size_t out_size) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
208 | { |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
209 | PurpleDES3Cipher *des3_cipher = PURPLE_DES3_CIPHER(cipher); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
210 | PurpleDES3CipherPrivate *priv = PURPLE_DES3_CIPHER_GET_PRIVATE(des3_cipher); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
211 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
212 | if (priv->mode == PURPLE_CIPHER_BATCH_MODE_ECB) { |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
213 | return purple_des3_cipher_ecb_encrypt(des3_cipher, input, in_len, output, out_size); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
214 | } else if (priv->mode == PURPLE_CIPHER_BATCH_MODE_CBC) { |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
215 | return purple_des3_cipher_cbc_encrypt(des3_cipher, input, in_len, output, out_size); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
216 | } else { |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
217 | g_return_val_if_reached(0); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
218 | } |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
219 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
220 | return 0; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
221 | } |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
222 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
223 | static ssize_t |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
224 | purple_des3_cipher_ecb_decrypt(PurpleDES3Cipher *des3_cipher, const guchar input[], |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
225 | size_t in_len, guchar output[], size_t out_size) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
226 | { |
| 34889 | 227 | gsize offset = 0; |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
228 | int i = 0; |
| 34889 | 229 | gsize tmp; |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
230 | guint8 buf[8] = {0,0,0,0,0,0,0,0}; |
| 34889 | 231 | gsize out_len; |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
232 | PurpleDES3CipherPrivate *priv = PURPLE_DES3_CIPHER_GET_PRIVATE(des3_cipher); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
233 | |
| 34603 | 234 | g_return_val_if_fail(out_size >= in_len, -1); |
| 235 | ||
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
236 | while (offset + 8 <= in_len) { |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
237 | /* NOTE: Apply key in reverse */ |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
238 | purple_des_cipher_ecb_crypt(PURPLE_DES_CIPHER(priv->key3), |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
239 | input + offset, output + offset, 1); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
240 | purple_des_cipher_ecb_crypt(PURPLE_DES_CIPHER(priv->key2), |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
241 | output + offset, buf, 0); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
242 | purple_des_cipher_ecb_crypt(PURPLE_DES_CIPHER(priv->key1), |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
243 | buf, output + offset, 1); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
244 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
245 | offset += 8; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
246 | } |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
247 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
248 | out_len = in_len; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
249 | if (offset < in_len) { |
| 34889 | 250 | g_return_val_if_fail(in_len >= offset, -1); |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
251 | out_len += in_len - offset; |
| 34603 | 252 | g_return_val_if_fail(out_size >= out_len, -1); |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
253 | tmp = offset; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
254 | memset(buf, 0, 8); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
255 | while (tmp < in_len) { |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
256 | buf[i++] = input[tmp]; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
257 | tmp++; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
258 | } |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
259 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
260 | purple_des_cipher_ecb_crypt(PURPLE_DES_CIPHER(priv->key3), |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
261 | buf, output + offset, 1); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
262 | purple_des_cipher_ecb_crypt(PURPLE_DES_CIPHER(priv->key2), |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
263 | output + offset, buf, 0); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
264 | purple_des_cipher_ecb_crypt(PURPLE_DES_CIPHER(priv->key1), |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
265 | buf, output + offset, 1); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
266 | } |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
267 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
268 | return out_len; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
269 | } |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
270 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
271 | static ssize_t |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
272 | purple_des3_cipher_cbc_decrypt(PurpleDES3Cipher *des3_cipher, const guchar input[], |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
273 | size_t in_len, guchar output[], size_t out_size) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
274 | { |
| 34889 | 275 | gsize offset = 0; |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
276 | int i = 0; |
| 34889 | 277 | gsize tmp; |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
278 | guint8 buf[8] = {0,0,0,0,0,0,0,0}; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
279 | guint8 link[8]; |
| 34889 | 280 | gsize out_len; |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
281 | PurpleDES3CipherPrivate *priv = PURPLE_DES3_CIPHER_GET_PRIVATE(des3_cipher); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
282 | |
| 34603 | 283 | g_return_val_if_fail(out_size >= in_len, -1); |
| 284 | ||
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
285 | memcpy(link, priv->iv, 8); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
286 | while (offset + 8 <= in_len) { |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
287 | purple_des_cipher_ecb_crypt(PURPLE_DES_CIPHER(priv->key3), |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
288 | input + offset, output + offset, 1); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
289 | purple_des_cipher_ecb_crypt(PURPLE_DES_CIPHER(priv->key2), |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
290 | output + offset, buf, 0); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
291 | purple_des_cipher_ecb_crypt(PURPLE_DES_CIPHER(priv->key1), |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
292 | buf, output + offset, 1); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
293 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
294 | for (i = 0; i < 8; i++) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
295 | output[offset + i] ^= link[i]; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
296 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
297 | memcpy(link, input + offset, 8); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
298 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
299 | offset+=8; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
300 | } |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
301 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
302 | out_len = in_len; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
303 | if(offset<in_len) { |
| 34889 | 304 | g_return_val_if_fail(in_len >= offset, -1); |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
305 | out_len += in_len - offset; |
| 34603 | 306 | g_return_val_if_fail(out_size >= out_len, -1); |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
307 | tmp = offset; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
308 | memset(buf, 0, 8); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
309 | i = 0; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
310 | while(tmp<in_len) { |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
311 | buf[i++] = input[tmp]; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
312 | tmp++; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
313 | } |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
314 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
315 | purple_des_cipher_ecb_crypt(PURPLE_DES_CIPHER(priv->key3), |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
316 | buf, output + offset, 1); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
317 | purple_des_cipher_ecb_crypt(PURPLE_DES_CIPHER(priv->key2), |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
318 | output + offset, buf, 0); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
319 | purple_des_cipher_ecb_crypt(PURPLE_DES_CIPHER(priv->key1), |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
320 | buf, output + offset, 1); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
321 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
322 | for (i = 0; i < 8; i++) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
323 | output[offset + i] ^= link[i]; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
324 | } |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
325 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
326 | return out_len; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
327 | } |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
328 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
329 | static ssize_t |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
330 | purple_des3_cipher_decrypt(PurpleCipher *cipher, const guchar input[], |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
331 | size_t in_len, guchar output[], size_t out_size) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
332 | { |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
333 | PurpleDES3Cipher *des3_cipher = PURPLE_DES3_CIPHER(cipher); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
334 | PurpleDES3CipherPrivate *priv = PURPLE_DES3_CIPHER_GET_PRIVATE(cipher); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
335 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
336 | if (priv->mode == PURPLE_CIPHER_BATCH_MODE_ECB) { |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
337 | return purple_des3_cipher_ecb_decrypt(des3_cipher, input, in_len, output, out_size); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
338 | } else if (priv->mode == PURPLE_CIPHER_BATCH_MODE_CBC) { |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
339 | return purple_des3_cipher_cbc_decrypt(des3_cipher, input, in_len, output, out_size); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
340 | } else { |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
341 | g_return_val_if_reached(0); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
342 | } |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
343 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
344 | return 0; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
345 | } |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
346 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
347 | static void |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
348 | purple_des3_cipher_set_batch_mode(PurpleCipher *cipher, PurpleCipherBatchMode mode) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
349 | { |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
350 | PurpleDES3Cipher *des3_cipher = PURPLE_DES3_CIPHER(cipher); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
351 | PurpleDES3CipherPrivate *priv = PURPLE_DES3_CIPHER_GET_PRIVATE(des3_cipher); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
352 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
353 | priv->mode = mode; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
354 | } |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
355 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
356 | static PurpleCipherBatchMode |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
357 | purple_des3_cipher_get_batch_mode(PurpleCipher *cipher) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
358 | { |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
359 | PurpleDES3Cipher *des3_cipher = PURPLE_DES3_CIPHER(cipher); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
360 | PurpleDES3CipherPrivate *priv = PURPLE_DES3_CIPHER_GET_PRIVATE(des3_cipher); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
361 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
362 | return priv->mode; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
363 | } |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
364 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
365 | static void |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
366 | purple_des3_cipher_set_iv(PurpleCipher *cipher, guchar *iv, size_t len) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
367 | { |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
368 | PurpleDES3Cipher *des3_cipher = PURPLE_DES3_CIPHER(cipher); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
369 | PurpleDES3CipherPrivate *priv = PURPLE_DES3_CIPHER_GET_PRIVATE(des3_cipher); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
370 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
371 | g_return_if_fail(len == 8); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
372 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
373 | memcpy(priv->iv, iv, len); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
374 | } |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
375 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
376 | /****************************************************************************** |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
377 | * Object Stuff |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
378 | *****************************************************************************/ |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
379 | static void |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
380 | purple_des3_cipher_get_property(GObject *obj, guint param_id, GValue *value, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
381 | GParamSpec *pspec) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
382 | { |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
383 | PurpleCipher *cipher = PURPLE_CIPHER(obj); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
384 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
385 | switch(param_id) { |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
386 | case PROP_BATCH_MODE: |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
387 | g_value_set_enum(value, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
388 | purple_cipher_get_batch_mode(cipher)); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
389 | break; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
390 | default: |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
391 | G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
392 | break; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
393 | } |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
394 | } |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
395 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
396 | static void |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
397 | purple_des3_cipher_set_property(GObject *obj, guint param_id, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
398 | const GValue *value, GParamSpec *pspec) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
399 | { |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
400 | PurpleCipher *cipher = PURPLE_CIPHER(obj); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
401 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
402 | switch(param_id) { |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
403 | case PROP_BATCH_MODE: |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
404 | purple_cipher_set_batch_mode(cipher, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
405 | g_value_get_enum(value)); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
406 | break; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
407 | case PROP_IV: |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
408 | { |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
409 | guchar *iv = (guchar *)g_value_get_string(value); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
410 | purple_cipher_set_iv(cipher, iv, strlen((gchar*)iv)); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
411 | } |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
412 | break; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
413 | case PROP_KEY: |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
414 | 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:
diff
changeset
|
415 | purple_des3_cipher_get_key_size(cipher)); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
416 | break; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
417 | default: |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
418 | G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
419 | break; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
420 | } |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
421 | } |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
422 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
423 | static void |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
424 | purple_des3_cipher_finalize(GObject *obj) |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
425 | { |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
426 | PurpleDES3Cipher *des3_cipher = PURPLE_DES3_CIPHER(obj); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
427 | PurpleDES3CipherPrivate *priv = PURPLE_DES3_CIPHER_GET_PRIVATE(des3_cipher); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
428 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
429 | g_object_unref(G_OBJECT(priv->key1)); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
430 | g_object_unref(G_OBJECT(priv->key2)); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
431 | g_object_unref(G_OBJECT(priv->key3)); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
432 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
433 | memset(priv->iv, 0, sizeof(priv->iv)); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
434 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
435 | parent_class->finalize(obj); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
436 | } |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
437 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
438 | static void |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
439 | purple_des3_cipher_class_init(PurpleDES3CipherClass *klass) { |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
440 | GObjectClass *obj_class = G_OBJECT_CLASS(klass); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
441 | PurpleCipherClass *cipher_class = PURPLE_CIPHER_CLASS(klass); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
442 | GParamSpec *pspec; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
443 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
444 | parent_class = g_type_class_peek_parent(klass); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
445 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
446 | obj_class->finalize = purple_des3_cipher_finalize; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
447 | obj_class->get_property = purple_des3_cipher_get_property; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
448 | obj_class->set_property = purple_des3_cipher_set_property; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
449 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
450 | cipher_class->set_iv = purple_des3_cipher_set_iv; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
451 | cipher_class->encrypt = purple_des3_cipher_encrypt; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
452 | cipher_class->decrypt = purple_des3_cipher_decrypt; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
453 | cipher_class->set_key = purple_des3_cipher_set_key; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
454 | cipher_class->set_batch_mode = purple_des3_cipher_set_batch_mode; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
455 | cipher_class->get_batch_mode = purple_des3_cipher_get_batch_mode; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
456 | cipher_class->get_key_size = purple_des3_cipher_get_key_size; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
457 | |
|
34544
a41098b81e93
Changed property string batchMode to batch_mode
Ankit Vani <a@nevitus.org>
parents:
34537
diff
changeset
|
458 | pspec = g_param_spec_enum("batch_mode", "batch_mode", "batch_mode", |
|
34537
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
459 | PURPLE_TYPE_CIPHER_BATCH_MODE, 0, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
460 | G_PARAM_READWRITE); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
461 | g_object_class_install_property(obj_class, PROP_BATCH_MODE, pspec); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
462 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
463 | pspec = g_param_spec_string("iv", "iv", "iv", NULL, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
464 | G_PARAM_WRITABLE); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
465 | g_object_class_install_property(obj_class, PROP_IV, pspec); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
466 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
467 | pspec = g_param_spec_string("key", "key", "key", NULL, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
468 | G_PARAM_WRITABLE); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
469 | g_object_class_install_property(obj_class, PROP_KEY, pspec); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
470 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
471 | g_type_class_add_private(klass, sizeof(PurpleDES3CipherPrivate)); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
472 | } |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
473 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
474 | static void |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
475 | purple_des3_cipher_init(PurpleCipher *cipher) { |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
476 | PurpleDES3Cipher *des3_cipher = PURPLE_DES3_CIPHER(cipher); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
477 | PurpleDES3CipherPrivate *priv = PURPLE_DES3_CIPHER_GET_PRIVATE(des3_cipher); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
478 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
479 | priv->key1 = purple_des_cipher_new(); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
480 | priv->key2 = purple_des_cipher_new(); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
481 | priv->key3 = purple_des_cipher_new(); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
482 | } |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
483 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
484 | /****************************************************************************** |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
485 | * API |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
486 | *****************************************************************************/ |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
487 | GType |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
488 | purple_des3_cipher_get_gtype(void) { |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
489 | static GType type = 0; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
490 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
491 | if(type == 0) { |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
492 | static const GTypeInfo info = { |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
493 | sizeof(PurpleDES3CipherClass), |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
494 | NULL, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
495 | NULL, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
496 | (GClassInitFunc)purple_des3_cipher_class_init, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
497 | NULL, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
498 | NULL, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
499 | sizeof(PurpleDES3Cipher), |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
500 | 0, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
501 | (GInstanceInitFunc)purple_des3_cipher_init, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
502 | NULL |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
503 | }; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
504 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
505 | type = g_type_register_static(PURPLE_TYPE_CIPHER, |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
506 | "PurpleDES3Cipher", |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
507 | &info, 0); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
508 | } |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
509 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
510 | return type; |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
511 | } |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
512 | |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
513 | PurpleCipher * |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
514 | purple_des3_cipher_new(void) { |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
515 | return g_object_new(PURPLE_TYPE_DES3_CIPHER, NULL); |
|
fb40b0460a36
GObjectify the DES and Triple-DES ciphers
Ankit Vani <a@nevitus.org>
parents:
diff
changeset
|
516 | } |