4 * Purple is the legal property of its developers, whose names are too numerous
5 * to list here. Please refer to the COPYRIGHT file distributed with this
8 * Original des taken from gpg
10 * des.c - DES and Triple-DES encryption/decryption Algorithm
11 * Copyright (C) 1998 Free Software Foundation, Inc.
13 * Please see below for more legal information!
15 * According to the definition of DES in FIPS PUB 46-2 from December 1993.
16 * For a description of triple encryption, see:
17 * Bruce Schneier: Applied Cryptography. Second Edition.
18 * John Wiley & Sons, 1996. ISBN 0-471-12845-7. Pages 358 ff.
20 * This file is part of GnuPG.
22 * This program is free software; you can redistribute it and/or modify
23 * it under the terms of the GNU General Public License as published by
24 * the Free Software Foundation; either version 2 of the License, or
25 * (at your option) any later version.
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU General Public License for more details.
32 * You should have received a copy of the GNU General Public License
33 * along with this program; if not, write to the Free Software
34 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
38 #include "dbus-maybe.h"
43 /*******************************************************************************
45 ******************************************************************************/
46 struct _PurpleCipher
{
47 gchar
*name
; /**< Internal name - used for searching */
48 PurpleCipherOps
*ops
; /**< Operations supported by this cipher */
49 guint ref
; /**< Reference count */
52 struct _PurpleCipherContext
{
53 PurpleCipher
*cipher
; /**< Cipher this context is under */
54 gpointer data
; /**< Internal cipher state data */
57 /******************************************************************************
59 *****************************************************************************/
60 static GList
*ciphers
= NULL
;
62 /******************************************************************************
64 *****************************************************************************/
66 purple_cipher_get_name(PurpleCipher
*cipher
) {
67 g_return_val_if_fail(cipher
, NULL
);
73 purple_cipher_get_capabilities(PurpleCipher
*cipher
) {
74 PurpleCipherOps
*ops
= NULL
;
77 g_return_val_if_fail(cipher
, 0);
80 g_return_val_if_fail(ops
, 0);
83 caps
|= PURPLE_CIPHER_CAPS_SET_OPT
;
85 caps
|= PURPLE_CIPHER_CAPS_GET_OPT
;
87 caps
|= PURPLE_CIPHER_CAPS_INIT
;
89 caps
|= PURPLE_CIPHER_CAPS_RESET
;
91 caps
|= PURPLE_CIPHER_CAPS_UNINIT
;
93 caps
|= PURPLE_CIPHER_CAPS_SET_IV
;
95 caps
|= PURPLE_CIPHER_CAPS_APPEND
;
97 caps
|= PURPLE_CIPHER_CAPS_DIGEST
;
99 caps
|= PURPLE_CIPHER_CAPS_ENCRYPT
;
101 caps
|= PURPLE_CIPHER_CAPS_DECRYPT
;
103 caps
|= PURPLE_CIPHER_CAPS_SET_SALT
;
104 if(ops
->get_salt_size
)
105 caps
|= PURPLE_CIPHER_CAPS_GET_SALT_SIZE
;
107 caps
|= PURPLE_CIPHER_CAPS_SET_KEY
;
108 if(ops
->get_key_size
)
109 caps
|= PURPLE_CIPHER_CAPS_GET_KEY_SIZE
;
110 if(ops
->set_batch_mode
)
111 caps
|= PURPLE_CIPHER_CAPS_SET_BATCH_MODE
;
112 if(ops
->get_batch_mode
)
113 caps
|= PURPLE_CIPHER_CAPS_GET_BATCH_MODE
;
114 if(ops
->get_block_size
)
115 caps
|= PURPLE_CIPHER_CAPS_GET_BLOCK_SIZE
;
116 if(ops
->set_key_with_len
)
117 caps
|= PURPLE_CIPHER_CAPS_SET_KEY_WITH_LEN
;
123 purple_cipher_digest_region(const gchar
*name
, const guchar
*data
,
124 size_t data_len
, size_t in_len
,
125 guchar digest
[], size_t *out_len
)
127 PurpleCipher
*cipher
;
128 PurpleCipherContext
*context
;
129 gboolean ret
= FALSE
;
131 g_return_val_if_fail(name
, FALSE
);
132 g_return_val_if_fail(data
, FALSE
);
134 cipher
= purple_ciphers_find_cipher(name
);
136 g_return_val_if_fail(cipher
, FALSE
);
138 if(!cipher
->ops
->append
|| !cipher
->ops
->digest
) {
139 purple_debug_warning("cipher", "purple_cipher_region failed: "
140 "the %s cipher does not support appending and or "
141 "digesting.", cipher
->name
);
145 context
= purple_cipher_context_new(cipher
, NULL
);
146 purple_cipher_context_append(context
, data
, data_len
);
147 ret
= purple_cipher_context_digest(context
, in_len
, digest
, out_len
);
148 purple_cipher_context_destroy(context
);
153 /******************************************************************************
155 *****************************************************************************/
157 purple_ciphers_find_cipher(const gchar
*name
) {
158 PurpleCipher
*cipher
;
161 g_return_val_if_fail(name
, NULL
);
163 for(l
= ciphers
; l
; l
= l
->next
) {
164 cipher
= PURPLE_CIPHER(l
->data
);
166 if(!g_ascii_strcasecmp(cipher
->name
, name
))
174 purple_ciphers_register_cipher(const gchar
*name
, PurpleCipherOps
*ops
) {
175 PurpleCipher
*cipher
= NULL
;
177 g_return_val_if_fail(name
, NULL
);
178 g_return_val_if_fail(ops
, NULL
);
179 g_return_val_if_fail(!purple_ciphers_find_cipher(name
), NULL
);
181 cipher
= g_new0(PurpleCipher
, 1);
182 PURPLE_DBUS_REGISTER_POINTER(cipher
, PurpleCipher
);
184 cipher
->name
= g_strdup(name
);
187 ciphers
= g_list_append(ciphers
, cipher
);
189 purple_signal_emit(purple_ciphers_get_handle(), "cipher-added", cipher
);
195 purple_ciphers_unregister_cipher(PurpleCipher
*cipher
) {
196 g_return_val_if_fail(cipher
, FALSE
);
197 g_return_val_if_fail(cipher
->ref
== 0, FALSE
);
199 purple_signal_emit(purple_ciphers_get_handle(), "cipher-removed", cipher
);
201 ciphers
= g_list_remove(ciphers
, cipher
);
203 g_free(cipher
->name
);
205 PURPLE_DBUS_UNREGISTER_POINTER(cipher
);
212 purple_ciphers_get_ciphers() {
216 /******************************************************************************
217 * PurpleCipher Subsystem API
218 *****************************************************************************/
220 purple_ciphers_get_handle() {
226 /* These are implemented in the purple-ciphers sublibrary built in the ciphers
227 * directory. We could put a header file in there, but it's less hassle for
228 * the developer to just add it here since they have to register it here as
231 PurpleCipherOps
*purple_des_cipher_get_ops();
232 PurpleCipherOps
*purple_des3_cipher_get_ops();
233 PurpleCipherOps
*purple_hmac_cipher_get_ops();
234 PurpleCipherOps
*purple_md4_cipher_get_ops();
235 PurpleCipherOps
*purple_md5_cipher_get_ops();
236 PurpleCipherOps
*purple_rc4_cipher_get_ops();
237 PurpleCipherOps
*purple_sha1_cipher_get_ops();
238 PurpleCipherOps
*purple_sha256_cipher_get_ops();
241 purple_ciphers_init() {
244 handle
= purple_ciphers_get_handle();
246 purple_signal_register(handle
, "cipher-added",
247 purple_marshal_VOID__POINTER
, NULL
, 1,
248 purple_value_new(PURPLE_TYPE_SUBTYPE
,
249 PURPLE_SUBTYPE_CIPHER
));
250 purple_signal_register(handle
, "cipher-removed",
251 purple_marshal_VOID__POINTER
, NULL
, 1,
252 purple_value_new(PURPLE_TYPE_SUBTYPE
,
253 PURPLE_SUBTYPE_CIPHER
));
255 purple_ciphers_register_cipher("md5", purple_md5_cipher_get_ops());
256 purple_ciphers_register_cipher("sha1", purple_sha1_cipher_get_ops());
257 purple_ciphers_register_cipher("sha256", purple_sha256_cipher_get_ops());
258 purple_ciphers_register_cipher("md4", purple_md4_cipher_get_ops());
259 purple_ciphers_register_cipher("hmac", purple_hmac_cipher_get_ops());
260 purple_ciphers_register_cipher("des", purple_des_cipher_get_ops());
261 purple_ciphers_register_cipher("des3", purple_des3_cipher_get_ops());
262 purple_ciphers_register_cipher("rc4", purple_rc4_cipher_get_ops());
266 purple_ciphers_uninit() {
267 PurpleCipher
*cipher
;
270 for(l
= ciphers
; l
; l
= ll
) {
273 cipher
= PURPLE_CIPHER(l
->data
);
274 purple_ciphers_unregister_cipher(cipher
);
277 g_list_free(ciphers
);
279 purple_signals_unregister_by_instance(purple_ciphers_get_handle());
282 /******************************************************************************
283 * PurpleCipherContext API
284 *****************************************************************************/
286 purple_cipher_context_set_option(PurpleCipherContext
*context
, const gchar
*name
,
289 PurpleCipher
*cipher
= NULL
;
291 g_return_if_fail(context
);
292 g_return_if_fail(name
);
294 cipher
= context
->cipher
;
295 g_return_if_fail(cipher
);
297 if(cipher
->ops
&& cipher
->ops
->set_option
)
298 cipher
->ops
->set_option(context
, name
, value
);
300 purple_debug_warning("cipher", "the %s cipher does not support the "
301 "set_option operation\n", cipher
->name
);
305 purple_cipher_context_get_option(PurpleCipherContext
*context
, const gchar
*name
) {
306 PurpleCipher
*cipher
= NULL
;
308 g_return_val_if_fail(context
, NULL
);
309 g_return_val_if_fail(name
, NULL
);
311 cipher
= context
->cipher
;
312 g_return_val_if_fail(cipher
, NULL
);
314 if(cipher
->ops
&& cipher
->ops
->get_option
)
315 return cipher
->ops
->get_option(context
, name
);
317 purple_debug_warning("cipher", "the %s cipher does not support the "
318 "get_option operation\n", cipher
->name
);
324 PurpleCipherContext
*
325 purple_cipher_context_new(PurpleCipher
*cipher
, void *extra
) {
326 PurpleCipherContext
*context
= NULL
;
328 g_return_val_if_fail(cipher
, NULL
);
332 context
= g_new0(PurpleCipherContext
, 1);
333 context
->cipher
= cipher
;
335 if(cipher
->ops
->init
)
336 cipher
->ops
->init(context
, extra
);
341 PurpleCipherContext
*
342 purple_cipher_context_new_by_name(const gchar
*name
, void *extra
) {
343 PurpleCipher
*cipher
;
345 g_return_val_if_fail(name
, NULL
);
347 cipher
= purple_ciphers_find_cipher(name
);
349 g_return_val_if_fail(cipher
, NULL
);
351 return purple_cipher_context_new(cipher
, extra
);
355 purple_cipher_context_reset(PurpleCipherContext
*context
, void *extra
) {
356 PurpleCipher
*cipher
= NULL
;
358 g_return_if_fail(context
);
360 cipher
= context
->cipher
;
361 g_return_if_fail(cipher
);
363 if(cipher
->ops
&& cipher
->ops
->reset
)
364 context
->cipher
->ops
->reset(context
, extra
);
368 purple_cipher_context_destroy(PurpleCipherContext
*context
) {
369 PurpleCipher
*cipher
= NULL
;
371 g_return_if_fail(context
);
373 cipher
= context
->cipher
;
374 g_return_if_fail(cipher
);
378 if(cipher
->ops
&& cipher
->ops
->uninit
)
379 cipher
->ops
->uninit(context
);
381 memset(context
, 0, sizeof(*context
));
387 purple_cipher_context_set_iv(PurpleCipherContext
*context
, guchar
*iv
, size_t len
)
389 PurpleCipher
*cipher
= NULL
;
391 g_return_if_fail(context
);
392 g_return_if_fail(iv
);
394 cipher
= context
->cipher
;
395 g_return_if_fail(cipher
);
397 if(cipher
->ops
&& cipher
->ops
->set_iv
)
398 cipher
->ops
->set_iv(context
, iv
, len
);
400 purple_debug_warning("cipher", "the %s cipher does not support the set"
401 "initialization vector operation\n", cipher
->name
);
405 purple_cipher_context_append(PurpleCipherContext
*context
, const guchar
*data
,
408 PurpleCipher
*cipher
= NULL
;
410 g_return_if_fail(context
);
412 cipher
= context
->cipher
;
413 g_return_if_fail(cipher
);
415 if(cipher
->ops
&& cipher
->ops
->append
)
416 cipher
->ops
->append(context
, data
, len
);
418 purple_debug_warning("cipher", "the %s cipher does not support the append "
419 "operation\n", cipher
->name
);
423 purple_cipher_context_digest(PurpleCipherContext
*context
, size_t in_len
,
424 guchar digest
[], size_t *out_len
)
426 PurpleCipher
*cipher
= NULL
;
428 g_return_val_if_fail(context
, FALSE
);
430 cipher
= context
->cipher
;
432 if(cipher
->ops
&& cipher
->ops
->digest
)
433 return cipher
->ops
->digest(context
, in_len
, digest
, out_len
);
435 purple_debug_warning("cipher", "the %s cipher does not support the digest "
436 "operation\n", cipher
->name
);
442 purple_cipher_context_digest_to_str(PurpleCipherContext
*context
, size_t in_len
,
443 gchar digest_s
[], size_t *out_len
)
445 /* 8k is a bit excessive, will tweak later. */
446 guchar digest
[BUF_LEN
* 4];
449 g_return_val_if_fail(context
, FALSE
);
450 g_return_val_if_fail(digest_s
, FALSE
);
452 if(!purple_cipher_context_digest(context
, sizeof(digest
), digest
, &dlen
))
455 /* in_len must be greater than dlen * 2 so we have room for the NUL. */
456 if(in_len
<= dlen
* 2)
459 for(n
= 0; n
< dlen
; n
++)
460 sprintf(digest_s
+ (n
* 2), "%02x", digest
[n
]);
462 digest_s
[n
* 2] = '\0';
471 purple_cipher_context_encrypt(PurpleCipherContext
*context
, const guchar data
[],
472 size_t len
, guchar output
[], size_t *outlen
)
474 PurpleCipher
*cipher
= NULL
;
476 g_return_val_if_fail(context
, -1);
478 cipher
= context
->cipher
;
479 g_return_val_if_fail(cipher
, -1);
481 if(cipher
->ops
&& cipher
->ops
->encrypt
)
482 return cipher
->ops
->encrypt(context
, data
, len
, output
, outlen
);
484 purple_debug_warning("cipher", "the %s cipher does not support the encrypt"
485 "operation\n", cipher
->name
);
495 purple_cipher_context_decrypt(PurpleCipherContext
*context
, const guchar data
[],
496 size_t len
, guchar output
[], size_t *outlen
)
498 PurpleCipher
*cipher
= NULL
;
500 g_return_val_if_fail(context
, -1);
502 cipher
= context
->cipher
;
503 g_return_val_if_fail(cipher
, -1);
505 if(cipher
->ops
&& cipher
->ops
->decrypt
)
506 return cipher
->ops
->decrypt(context
, data
, len
, output
, outlen
);
508 purple_debug_warning("cipher", "the %s cipher does not support the decrypt"
509 "operation\n", cipher
->name
);
519 purple_cipher_context_set_salt(PurpleCipherContext
*context
, guchar
*salt
) {
520 PurpleCipher
*cipher
= NULL
;
522 g_return_if_fail(context
);
524 cipher
= context
->cipher
;
525 g_return_if_fail(cipher
);
527 if(cipher
->ops
&& cipher
->ops
->set_salt
)
528 cipher
->ops
->set_salt(context
, salt
);
530 purple_debug_warning("cipher", "the %s cipher does not support the "
531 "set_salt operation\n", cipher
->name
);
535 purple_cipher_context_get_salt_size(PurpleCipherContext
*context
) {
536 PurpleCipher
*cipher
= NULL
;
538 g_return_val_if_fail(context
, -1);
540 cipher
= context
->cipher
;
541 g_return_val_if_fail(cipher
, -1);
543 if(cipher
->ops
&& cipher
->ops
->get_salt_size
)
544 return cipher
->ops
->get_salt_size(context
);
546 purple_debug_warning("cipher", "the %s cipher does not support the "
547 "get_salt_size operation\n", cipher
->name
);
554 purple_cipher_context_set_key(PurpleCipherContext
*context
, const guchar
*key
) {
555 PurpleCipher
*cipher
= NULL
;
557 g_return_if_fail(context
);
559 cipher
= context
->cipher
;
560 g_return_if_fail(cipher
);
562 if(cipher
->ops
&& cipher
->ops
->set_key
)
563 cipher
->ops
->set_key(context
, key
);
565 purple_debug_warning("cipher", "the %s cipher does not support the "
566 "set_key operation\n", cipher
->name
);
570 purple_cipher_context_get_key_size(PurpleCipherContext
*context
) {
571 PurpleCipher
*cipher
= NULL
;
573 g_return_val_if_fail(context
, -1);
575 cipher
= context
->cipher
;
576 g_return_val_if_fail(cipher
, -1);
578 if(cipher
->ops
&& cipher
->ops
->get_key_size
)
579 return cipher
->ops
->get_key_size(context
);
581 purple_debug_warning("cipher", "the %s cipher does not support the "
582 "get_key_size operation\n", cipher
->name
);
589 purple_cipher_context_set_batch_mode(PurpleCipherContext
*context
,
590 PurpleCipherBatchMode mode
)
592 PurpleCipher
*cipher
= NULL
;
594 g_return_if_fail(context
);
596 cipher
= context
->cipher
;
597 g_return_if_fail(cipher
);
599 if(cipher
->ops
&& cipher
->ops
->set_batch_mode
)
600 cipher
->ops
->set_batch_mode(context
, mode
);
602 purple_debug_warning("cipher", "The %s cipher does not support the "
603 "set_batch_mode operation\n", cipher
->name
);
606 PurpleCipherBatchMode
607 purple_cipher_context_get_batch_mode(PurpleCipherContext
*context
)
609 PurpleCipher
*cipher
= NULL
;
611 g_return_val_if_fail(context
, -1);
613 cipher
= context
->cipher
;
614 g_return_val_if_fail(cipher
, -1);
616 if(cipher
->ops
&& cipher
->ops
->get_batch_mode
)
617 return cipher
->ops
->get_batch_mode(context
);
619 purple_debug_warning("cipher", "The %s cipher does not support the "
620 "get_batch_mode operation\n", cipher
->name
);
626 purple_cipher_context_get_block_size(PurpleCipherContext
*context
)
628 PurpleCipher
*cipher
= NULL
;
630 g_return_val_if_fail(context
, -1);
632 cipher
= context
->cipher
;
633 g_return_val_if_fail(cipher
, -1);
635 if(cipher
->ops
&& cipher
->ops
->get_block_size
)
636 return cipher
->ops
->get_block_size(context
);
638 purple_debug_warning("cipher", "The %s cipher does not support the "
639 "get_block_size operation\n", cipher
->name
);
645 purple_cipher_context_set_key_with_len(PurpleCipherContext
*context
,
646 const guchar
*key
, size_t len
)
648 PurpleCipher
*cipher
= NULL
;
650 g_return_if_fail(context
);
652 cipher
= context
->cipher
;
653 g_return_if_fail(cipher
);
655 if(cipher
->ops
&& cipher
->ops
->set_key_with_len
)
656 cipher
->ops
->set_key_with_len(context
, key
, len
);
658 purple_debug_warning("cipher", "The %s cipher does not support the "
659 "set_key_with_len operation\n", cipher
->name
);
663 purple_cipher_context_set_data(PurpleCipherContext
*context
, gpointer data
) {
664 g_return_if_fail(context
);
666 context
->data
= data
;
670 purple_cipher_context_get_data(PurpleCipherContext
*context
) {
671 g_return_val_if_fail(context
, NULL
);
673 return context
->data
;
676 gchar
*purple_cipher_http_digest_calculate_session_key(
677 const gchar
*algorithm
,
678 const gchar
*username
,
680 const gchar
*password
,
682 const gchar
*client_nonce
)
684 PurpleCipher
*cipher
;
685 PurpleCipherContext
*context
;
686 gchar hash
[33]; /* We only support MD5. */
688 g_return_val_if_fail(username
!= NULL
, NULL
);
689 g_return_val_if_fail(realm
!= NULL
, NULL
);
690 g_return_val_if_fail(password
!= NULL
, NULL
);
691 g_return_val_if_fail(nonce
!= NULL
, NULL
);
693 /* Check for a supported algorithm. */
694 g_return_val_if_fail(algorithm
== NULL
||
695 *algorithm
== '\0' ||
696 g_ascii_strcasecmp(algorithm
, "MD5") ||
697 g_ascii_strcasecmp(algorithm
, "MD5-sess"), NULL
);
699 cipher
= purple_ciphers_find_cipher("md5");
700 g_return_val_if_fail(cipher
!= NULL
, NULL
);
702 context
= purple_cipher_context_new(cipher
, NULL
);
704 purple_cipher_context_append(context
, (guchar
*)username
, strlen(username
));
705 purple_cipher_context_append(context
, (guchar
*)":", 1);
706 purple_cipher_context_append(context
, (guchar
*)realm
, strlen(realm
));
707 purple_cipher_context_append(context
, (guchar
*)":", 1);
708 purple_cipher_context_append(context
, (guchar
*)password
, strlen(password
));
710 if (algorithm
!= NULL
&& !g_ascii_strcasecmp(algorithm
, "MD5-sess"))
714 if (client_nonce
== NULL
)
716 purple_cipher_context_destroy(context
);
717 purple_debug_error("cipher", "Required client_nonce missing for MD5-sess digest calculation.\n");
721 purple_cipher_context_digest(context
, sizeof(digest
), digest
, NULL
);
722 purple_cipher_context_destroy(context
);
724 context
= purple_cipher_context_new(cipher
, NULL
);
725 purple_cipher_context_append(context
, digest
, sizeof(digest
));
726 purple_cipher_context_append(context
, (guchar
*)":", 1);
727 purple_cipher_context_append(context
, (guchar
*)nonce
, strlen(nonce
));
728 purple_cipher_context_append(context
, (guchar
*)":", 1);
729 purple_cipher_context_append(context
, (guchar
*)client_nonce
, strlen(client_nonce
));
732 purple_cipher_context_digest_to_str(context
, sizeof(hash
), hash
, NULL
);
733 purple_cipher_context_destroy(context
);
735 return g_strdup(hash
);
738 gchar
*purple_cipher_http_digest_calculate_response(
739 const gchar
*algorithm
,
741 const gchar
*digest_uri
,
745 const gchar
*nonce_count
,
746 const gchar
*client_nonce
,
747 const gchar
*session_key
)
749 PurpleCipher
*cipher
;
750 PurpleCipherContext
*context
;
751 static gchar hash2
[33]; /* We only support MD5. */
753 g_return_val_if_fail(method
!= NULL
, NULL
);
754 g_return_val_if_fail(digest_uri
!= NULL
, NULL
);
755 g_return_val_if_fail(nonce
!= NULL
, NULL
);
756 g_return_val_if_fail(session_key
!= NULL
, NULL
);
758 /* Check for a supported algorithm. */
759 g_return_val_if_fail(algorithm
== NULL
||
760 *algorithm
== '\0' ||
761 g_ascii_strcasecmp(algorithm
, "MD5") ||
762 g_ascii_strcasecmp(algorithm
, "MD5-sess"), NULL
);
764 /* Check for a supported "quality of protection". */
765 g_return_val_if_fail(qop
== NULL
||
767 g_ascii_strcasecmp(qop
, "auth") ||
768 g_ascii_strcasecmp(qop
, "auth-int"), NULL
);
770 cipher
= purple_ciphers_find_cipher("md5");
771 g_return_val_if_fail(cipher
!= NULL
, NULL
);
773 context
= purple_cipher_context_new(cipher
, NULL
);
775 purple_cipher_context_append(context
, (guchar
*)method
, strlen(method
));
776 purple_cipher_context_append(context
, (guchar
*)":", 1);
777 purple_cipher_context_append(context
, (guchar
*)digest_uri
, strlen(digest_uri
));
779 if (qop
!= NULL
&& !g_ascii_strcasecmp(qop
, "auth-int"))
781 PurpleCipherContext
*context2
;
782 gchar entity_hash
[33];
786 purple_cipher_context_destroy(context
);
787 purple_debug_error("cipher", "Required entity missing for auth-int digest calculation.\n");
791 context2
= purple_cipher_context_new(cipher
, NULL
);
792 purple_cipher_context_append(context2
, (guchar
*)entity
, strlen(entity
));
793 purple_cipher_context_digest_to_str(context2
, sizeof(entity_hash
), entity_hash
, NULL
);
794 purple_cipher_context_destroy(context2
);
796 purple_cipher_context_append(context
, (guchar
*)":", 1);
797 purple_cipher_context_append(context
, (guchar
*)entity_hash
, strlen(entity_hash
));
800 purple_cipher_context_digest_to_str(context
, sizeof(hash2
), hash2
, NULL
);
801 purple_cipher_context_destroy(context
);
803 context
= purple_cipher_context_new(cipher
, NULL
);
804 purple_cipher_context_append(context
, (guchar
*)session_key
, strlen(session_key
));
805 purple_cipher_context_append(context
, (guchar
*)":", 1);
806 purple_cipher_context_append(context
, (guchar
*)nonce
, strlen(nonce
));
807 purple_cipher_context_append(context
, (guchar
*)":", 1);
809 if (qop
!= NULL
&& *qop
!= '\0')
811 if (nonce_count
== NULL
)
813 purple_cipher_context_destroy(context
);
814 purple_debug_error("cipher", "Required nonce_count missing for digest calculation.\n");
818 if (client_nonce
== NULL
)
820 purple_cipher_context_destroy(context
);
821 purple_debug_error("cipher", "Required client_nonce missing for digest calculation.\n");
825 purple_cipher_context_append(context
, (guchar
*)nonce_count
, strlen(nonce_count
));
826 purple_cipher_context_append(context
, (guchar
*)":", 1);
827 purple_cipher_context_append(context
, (guchar
*)client_nonce
, strlen(client_nonce
));
828 purple_cipher_context_append(context
, (guchar
*)":", 1);
830 purple_cipher_context_append(context
, (guchar
*)qop
, strlen(qop
));
832 purple_cipher_context_append(context
, (guchar
*)":", 1);
835 purple_cipher_context_append(context
, (guchar
*)hash2
, strlen(hash2
));
836 purple_cipher_context_digest_to_str(context
, sizeof(hash2
), hash2
, NULL
);
837 purple_cipher_context_destroy(context
);
839 return g_strdup(hash2
);