Update main Makefile.mingw to look for current version of pidgin source.
[siplcs.git] / src / purple / purple-digest.c
blobcbecc29ed2371e59080245976996ed841fda09ac
1 /**
2 * @file purple-digest.c
4 * pidgin-sipe
6 * Copyright (C) 2010 SIPE Project <http://sipe.sourceforge.net/>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "glib.h"
24 #include "cipher.h"
26 #include "sipe-digest.h"
28 void sipe_digest_hmac_md5(const guchar *key, gsize key_length,
29 const guchar *data, gsize data_length,
30 guchar *digest)
32 PurpleCipherContext *context = purple_cipher_context_new_by_name("hmac", NULL);
33 purple_cipher_context_set_option(context, "hash", "md5");
34 purple_cipher_context_set_key_with_len(context, key, key_length);
35 purple_cipher_context_append(context, data, data_length);
36 purple_cipher_context_digest(context, SIPE_DIGEST_HMAC_MD5_LENGTH, digest, NULL);
37 purple_cipher_context_destroy(context);
40 static void purple_digest(const gchar *algorithm,
41 const guchar *data, gsize data_length,
42 guchar *digest, gsize digest_length)
44 PurpleCipherContext *ctx = purple_cipher_context_new_by_name(algorithm, NULL);
45 purple_cipher_context_append(ctx, data, data_length);
46 purple_cipher_context_digest(ctx, digest_length, digest, NULL);
47 purple_cipher_context_destroy(ctx);
50 void sipe_digest_md4(const guchar *data, gsize length, guchar *digest)
52 purple_digest("md4", data, length, digest, SIPE_DIGEST_MD4_LENGTH);
55 void sipe_digest_md5(const guchar *data, gsize length, guchar *digest)
57 purple_digest("md5", data, length, digest, SIPE_DIGEST_MD5_LENGTH);
60 void sipe_digest_sha1(const guchar *data, gsize length, guchar *digest)
62 purple_digest("sha1", data, length, digest, SIPE_DIGEST_SHA1_LENGTH);
65 /* Stream HMAC(SHA1) digest for file transfer */
66 gpointer sipe_digest_ft_start(const guchar *sha1_digest)
68 PurpleCipherContext *context = purple_cipher_context_new_by_name("hmac", NULL);
69 purple_cipher_context_set_option(context, "hash", "sha1");
70 /* used only the first 16 bytes of the 20 byte SHA1 digest */
71 purple_cipher_context_set_key_with_len(context, sha1_digest, 16);
72 return(context);
75 void sipe_digest_ft_update(gpointer context, const guchar *data, gsize length)
77 purple_cipher_context_append(context, data, length);
80 void sipe_digest_ft_end(gpointer context, guchar *digest)
82 purple_cipher_context_digest(context, SIPE_DIGEST_FILETRANSFER_LENGTH, digest, NULL);
85 void sipe_digest_ft_destroy(gpointer context)
87 purple_cipher_context_destroy(context);
91 Local Variables:
92 mode: c
93 c-file-style: "bsd"
94 indent-tabs-mode: t
95 tab-width: 8
96 End: