/pidgin/main: 822d515c34c9: ciphers cleanup: hmac - correctly se...
Tomasz Wasilczyk
tomkiewicz at cpw.pidgin.im
Mon May 6 09:50:19 EDT 2013
Changeset: 822d515c34c964363435b04f4281701d332fe501
Author: Tomasz Wasilczyk <tomkiewicz at cpw.pidgin.im>
Date: 2013-05-06 15:50 +0200
Branch: default
URL: https://hg.pidgin.im/pidgin/main/rev/822d515c34c9
Description:
ciphers cleanup: hmac - correctly set up after resetting state
diffstat:
libpurple/ciphers/hmac.c | 19 +++++++++++--------
1 files changed, 11 insertions(+), 8 deletions(-)
diffs (70 lines):
diff --git a/libpurple/ciphers/hmac.c b/libpurple/ciphers/hmac.c
--- a/libpurple/ciphers/hmac.c
+++ b/libpurple/ciphers/hmac.c
@@ -30,7 +30,7 @@ struct HMAC_Context {
PurpleCipherContext *hash;
char *name;
int blocksize;
- guchar *opad;
+ guchar *opad, *ipad;
};
static void
@@ -57,6 +57,8 @@ hmac_reset(PurpleCipherContext *context,
hctx->blocksize = 0;
g_free(hctx->opad);
hctx->opad = NULL;
+ g_free(hctx->ipad);
+ hctx->ipad = NULL;
}
static void
@@ -66,8 +68,10 @@ hmac_reset_state(PurpleCipherContext *co
hctx = purple_cipher_context_get_data(context);
- if (hctx->hash)
- purple_cipher_context_reset_state(hctx->hash, extra);
+ if (hctx->hash) {
+ purple_cipher_context_reset_state(hctx->hash, NULL);
+ purple_cipher_context_append(hctx->hash, hctx->ipad, hctx->blocksize);
+ }
}
static void
@@ -168,15 +172,15 @@ hmac_set_key(PurpleCipherContext *contex
{
struct HMAC_Context *hctx = purple_cipher_context_get_data(context);
int blocksize, i;
- guchar *ipad;
guchar *full_key;
g_return_if_fail(hctx->hash != NULL);
g_free(hctx->opad);
+ g_free(hctx->ipad);
blocksize = hctx->blocksize;
- ipad = g_malloc(blocksize);
+ hctx->ipad = g_malloc(blocksize);
hctx->opad = g_malloc(blocksize);
if (key_len > blocksize) {
@@ -195,15 +199,14 @@ hmac_set_key(PurpleCipherContext *contex
}
for(i = 0; i < blocksize; i++) {
- ipad[i] = 0x36 ^ full_key[i];
+ hctx->ipad[i] = 0x36 ^ full_key[i];
hctx->opad[i] = 0x5c ^ full_key[i];
}
g_free(full_key);
purple_cipher_context_reset(hctx->hash, NULL);
- purple_cipher_context_append(hctx->hash, ipad, blocksize);
- g_free(ipad);
+ purple_cipher_context_append(hctx->hash, hctx->ipad, blocksize);
}
static size_t
More information about the Commits
mailing list