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];
450 g_return_val_if_fail(context
, FALSE
);
451 g_return_val_if_fail(digest_s
, FALSE
);
453 if(!purple_cipher_context_digest(context
, sizeof(digest
), digest
, &dlen
))
456 /* in_len must be greater than dlen * 2 so we have room for the NUL. */
457 if(in_len
<= dlen
* 2)
460 for(n
= 0; n
< dlen
; n
++)
461 sprintf(digest_s
+ (n
* 2), "%02x", digest
[n
]);
463 digest_s
[n
* 2] = '\0';
472 purple_cipher_context_encrypt(PurpleCipherContext
*context
, const guchar data
[],
473 size_t len
, guchar output
[], size_t *outlen
)
475 PurpleCipher
*cipher
= NULL
;
477 g_return_val_if_fail(context
, -1);
479 cipher
= context
->cipher
;
480 g_return_val_if_fail(cipher
, -1);
482 if(cipher
->ops
&& cipher
->ops
->encrypt
)
483 return cipher
->ops
->encrypt(context
, data
, len
, output
, outlen
);
485 purple_debug_warning("cipher", "the %s cipher does not support the encrypt"
486 "operation\n", cipher
->name
);
496 purple_cipher_context_decrypt(PurpleCipherContext
*context
, const guchar data
[],
497 size_t len
, guchar output
[], size_t *outlen
)
499 PurpleCipher
*cipher
= NULL
;
501 g_return_val_if_fail(context
, -1);
503 cipher
= context
->cipher
;
504 g_return_val_if_fail(cipher
, -1);
506 if(cipher
->ops
&& cipher
->ops
->decrypt
)
507 return cipher
->ops
->decrypt(context
, data
, len
, output
, outlen
);
509 purple_debug_warning("cipher", "the %s cipher does not support the decrypt"
510 "operation\n", cipher
->name
);
520 purple_cipher_context_set_salt(PurpleCipherContext
*context
, guchar
*salt
) {
521 PurpleCipher
*cipher
= NULL
;
523 g_return_if_fail(context
);
525 cipher
= context
->cipher
;
526 g_return_if_fail(cipher
);
528 if(cipher
->ops
&& cipher
->ops
->set_salt
)
529 cipher
->ops
->set_salt(context
, salt
);
531 purple_debug_warning("cipher", "the %s cipher does not support the "
532 "set_salt operation\n", cipher
->name
);
536 purple_cipher_context_get_salt_size(PurpleCipherContext
*context
) {
537 PurpleCipher
*cipher
= NULL
;
539 g_return_val_if_fail(context
, -1);
541 cipher
= context
->cipher
;
542 g_return_val_if_fail(cipher
, -1);
544 if(cipher
->ops
&& cipher
->ops
->get_salt_size
)
545 return cipher
->ops
->get_salt_size(context
);
547 purple_debug_warning("cipher", "the %s cipher does not support the "
548 "get_salt_size operation\n", cipher
->name
);
555 purple_cipher_context_set_key(PurpleCipherContext
*context
, const guchar
*key
) {
556 PurpleCipher
*cipher
= NULL
;
558 g_return_if_fail(context
);
560 cipher
= context
->cipher
;
561 g_return_if_fail(cipher
);
563 if(cipher
->ops
&& cipher
->ops
->set_key
)
564 cipher
->ops
->set_key(context
, key
);
566 purple_debug_warning("cipher", "the %s cipher does not support the "
567 "set_key operation\n", cipher
->name
);
571 purple_cipher_context_get_key_size(PurpleCipherContext
*context
) {
572 PurpleCipher
*cipher
= NULL
;
574 g_return_val_if_fail(context
, -1);
576 cipher
= context
->cipher
;
577 g_return_val_if_fail(cipher
, -1);
579 if(cipher
->ops
&& cipher
->ops
->get_key_size
)
580 return cipher
->ops
->get_key_size(context
);
582 purple_debug_warning("cipher", "the %s cipher does not support the "
583 "get_key_size operation\n", cipher
->name
);
590 purple_cipher_context_set_batch_mode(PurpleCipherContext
*context
,
591 PurpleCipherBatchMode mode
)
593 PurpleCipher
*cipher
= NULL
;
595 g_return_if_fail(context
);
597 cipher
= context
->cipher
;
598 g_return_if_fail(cipher
);
600 if(cipher
->ops
&& cipher
->ops
->set_batch_mode
)
601 cipher
->ops
->set_batch_mode(context
, mode
);
603 purple_debug_warning("cipher", "The %s cipher does not support the "
604 "set_batch_mode operation\n", cipher
->name
);
607 PurpleCipherBatchMode
608 purple_cipher_context_get_batch_mode(PurpleCipherContext
*context
)
610 PurpleCipher
*cipher
= NULL
;
612 g_return_val_if_fail(context
, -1);
614 cipher
= context
->cipher
;
615 g_return_val_if_fail(cipher
, -1);
617 if(cipher
->ops
&& cipher
->ops
->get_batch_mode
)
618 return cipher
->ops
->get_batch_mode(context
);
620 purple_debug_warning("cipher", "The %s cipher does not support the "
621 "get_batch_mode operation\n", cipher
->name
);
627 purple_cipher_context_get_block_size(PurpleCipherContext
*context
)
629 PurpleCipher
*cipher
= NULL
;
631 g_return_val_if_fail(context
, -1);
633 cipher
= context
->cipher
;
634 g_return_val_if_fail(cipher
, -1);
636 if(cipher
->ops
&& cipher
->ops
->get_block_size
)
637 return cipher
->ops
->get_block_size(context
);
639 purple_debug_warning("cipher", "The %s cipher does not support the "
640 "get_block_size operation\n", cipher
->name
);
646 purple_cipher_context_set_key_with_len(PurpleCipherContext
*context
,
647 const guchar
*key
, size_t len
)
649 PurpleCipher
*cipher
= NULL
;
651 g_return_if_fail(context
);
653 cipher
= context
->cipher
;
654 g_return_if_fail(cipher
);
656 if(cipher
->ops
&& cipher
->ops
->set_key_with_len
)
657 cipher
->ops
->set_key_with_len(context
, key
, len
);
659 purple_debug_warning("cipher", "The %s cipher does not support the "
660 "set_key_with_len operation\n", cipher
->name
);
664 purple_cipher_context_set_data(PurpleCipherContext
*context
, gpointer data
) {
665 g_return_if_fail(context
);
667 context
->data
= data
;
671 purple_cipher_context_get_data(PurpleCipherContext
*context
) {
672 g_return_val_if_fail(context
, NULL
);
674 return context
->data
;
677 gchar
*purple_cipher_http_digest_calculate_session_key(
678 const gchar
*algorithm
,
679 const gchar
*username
,
681 const gchar
*password
,
683 const gchar
*client_nonce
)
685 PurpleCipher
*cipher
;
686 PurpleCipherContext
*context
;
687 gchar hash
[33]; /* We only support MD5. */
689 g_return_val_if_fail(username
!= NULL
, NULL
);
690 g_return_val_if_fail(realm
!= NULL
, NULL
);
691 g_return_val_if_fail(password
!= NULL
, NULL
);
692 g_return_val_if_fail(nonce
!= NULL
, NULL
);
694 /* Check for a supported algorithm. */
695 g_return_val_if_fail(algorithm
== NULL
||
696 *algorithm
== '\0' ||
697 g_ascii_strcasecmp(algorithm
, "MD5") ||
698 g_ascii_strcasecmp(algorithm
, "MD5-sess"), NULL
);
700 cipher
= purple_ciphers_find_cipher("md5");
701 g_return_val_if_fail(cipher
!= NULL
, NULL
);
703 context
= purple_cipher_context_new(cipher
, NULL
);
705 purple_cipher_context_append(context
, (guchar
*)username
, strlen(username
));
706 purple_cipher_context_append(context
, (guchar
*)":", 1);
707 purple_cipher_context_append(context
, (guchar
*)realm
, strlen(realm
));
708 purple_cipher_context_append(context
, (guchar
*)":", 1);
709 purple_cipher_context_append(context
, (guchar
*)password
, strlen(password
));
711 if (algorithm
!= NULL
&& !g_ascii_strcasecmp(algorithm
, "MD5-sess"))
715 if (client_nonce
== NULL
)
717 purple_cipher_context_destroy(context
);
718 purple_debug_error("cipher", "Required client_nonce missing for MD5-sess digest calculation.\n");
722 purple_cipher_context_digest(context
, sizeof(digest
), digest
, NULL
);
723 purple_cipher_context_destroy(context
);
725 context
= purple_cipher_context_new(cipher
, NULL
);
726 purple_cipher_context_append(context
, digest
, sizeof(digest
));
727 purple_cipher_context_append(context
, (guchar
*)":", 1);
728 purple_cipher_context_append(context
, (guchar
*)nonce
, strlen(nonce
));
729 purple_cipher_context_append(context
, (guchar
*)":", 1);
730 purple_cipher_context_append(context
, (guchar
*)client_nonce
, strlen(client_nonce
));
733 purple_cipher_context_digest_to_str(context
, sizeof(hash
), hash
, NULL
);
734 purple_cipher_context_destroy(context
);
736 return g_strdup(hash
);
739 gchar
*purple_cipher_http_digest_calculate_response(
740 const gchar
*algorithm
,
742 const gchar
*digest_uri
,
746 const gchar
*nonce_count
,
747 const gchar
*client_nonce
,
748 const gchar
*session_key
)
750 PurpleCipher
*cipher
;
751 PurpleCipherContext
*context
;
752 static gchar hash2
[33]; /* We only support MD5. */
754 g_return_val_if_fail(method
!= NULL
, NULL
);
755 g_return_val_if_fail(digest_uri
!= NULL
, NULL
);
756 g_return_val_if_fail(nonce
!= NULL
, NULL
);
757 g_return_val_if_fail(session_key
!= NULL
, NULL
);
759 /* Check for a supported algorithm. */
760 g_return_val_if_fail(algorithm
== NULL
||
761 *algorithm
== '\0' ||
762 g_ascii_strcasecmp(algorithm
, "MD5") ||
763 g_ascii_strcasecmp(algorithm
, "MD5-sess"), NULL
);
765 /* Check for a supported "quality of protection". */
766 g_return_val_if_fail(qop
== NULL
||
768 g_ascii_strcasecmp(qop
, "auth") ||
769 g_ascii_strcasecmp(qop
, "auth-int"), NULL
);
771 cipher
= purple_ciphers_find_cipher("md5");
772 g_return_val_if_fail(cipher
!= NULL
, NULL
);
774 context
= purple_cipher_context_new(cipher
, NULL
);
776 purple_cipher_context_append(context
, (guchar
*)method
, strlen(method
));
777 purple_cipher_context_append(context
, (guchar
*)":", 1);
778 purple_cipher_context_append(context
, (guchar
*)digest_uri
, strlen(digest_uri
));
780 if (qop
!= NULL
&& !g_ascii_strcasecmp(qop
, "auth-int"))
782 PurpleCipherContext
*context2
;
783 gchar entity_hash
[33];
787 purple_cipher_context_destroy(context
);
788 purple_debug_error("cipher", "Required entity missing for auth-int digest calculation.\n");
792 context2
= purple_cipher_context_new(cipher
, NULL
);
793 purple_cipher_context_append(context2
, (guchar
*)entity
, strlen(entity
));
794 purple_cipher_context_digest_to_str(context2
, sizeof(entity_hash
), entity_hash
, NULL
);
795 purple_cipher_context_destroy(context2
);
797 purple_cipher_context_append(context
, (guchar
*)":", 1);
798 purple_cipher_context_append(context
, (guchar
*)entity_hash
, strlen(entity_hash
));
801 purple_cipher_context_digest_to_str(context
, sizeof(hash2
), hash2
, NULL
);
802 purple_cipher_context_destroy(context
);
804 context
= purple_cipher_context_new(cipher
, NULL
);
805 purple_cipher_context_append(context
, (guchar
*)session_key
, strlen(session_key
));
806 purple_cipher_context_append(context
, (guchar
*)":", 1);
807 purple_cipher_context_append(context
, (guchar
*)nonce
, strlen(nonce
));
808 purple_cipher_context_append(context
, (guchar
*)":", 1);
810 if (qop
!= NULL
&& *qop
!= '\0')
812 if (nonce_count
== NULL
)
814 purple_cipher_context_destroy(context
);
815 purple_debug_error("cipher", "Required nonce_count missing for digest calculation.\n");
819 if (client_nonce
== NULL
)
821 purple_cipher_context_destroy(context
);
822 purple_debug_error("cipher", "Required client_nonce missing for digest calculation.\n");
826 purple_cipher_context_append(context
, (guchar
*)nonce_count
, strlen(nonce_count
));
827 purple_cipher_context_append(context
, (guchar
*)":", 1);
828 purple_cipher_context_append(context
, (guchar
*)client_nonce
, strlen(client_nonce
));
829 purple_cipher_context_append(context
, (guchar
*)":", 1);
831 purple_cipher_context_append(context
, (guchar
*)qop
, strlen(qop
));
833 purple_cipher_context_append(context
, (guchar
*)":", 1);
836 purple_cipher_context_append(context
, (guchar
*)hash2
, strlen(hash2
));
837 purple_cipher_context_digest_to_str(context
, sizeof(hash2
), hash2
, NULL
);
838 purple_cipher_context_destroy(context
);
840 return g_strdup(hash2
);