cipher_breakout: 297b3c45: Removed the "new" api I added by moving ...
grim at pidgin.im
grim at pidgin.im
Wed Feb 16 19:50:47 EST 2011
----------------------------------------------------------------------
Revision: 297b3c454164169abfe0f00a6f125481e281018c
Parent: ff17a3cec71c28bf02779c3045e5e97580730425
Author: grim at pidgin.im
Date: 02/16/11 19:42:53
Branch: im.pidgin.cipher_breakout
URL: http://d.pidgin.im/viewmtn/revision/info/297b3c454164169abfe0f00a6f125481e281018c
Changelog:
Removed the "new" api I added by moving it to ciphers/gchecksum.c. Moved the gchecksum implements into gchecksum.c as a preproc macro, removed them from their individual files
Changes against parent ff17a3cec71c28bf02779c3045e5e97580730425
added libpurple/ciphers/gchecksum.c
patched libpurple/cipher.c
patched libpurple/cipher.h
patched libpurple/ciphers/Makefile.am
patched libpurple/ciphers/md5.c
patched libpurple/ciphers/sha1.c
patched libpurple/ciphers/sha256.c
-------------- next part --------------
============================================================
--- libpurple/cipher.c ac70a8ec8b469608b12da700f38e40c0d68d652f
+++ libpurple/cipher.c f5d4dbb82542b8f69e0caaf9291a147246b6c2ba
@@ -40,86 +40,6 @@
#include "signals.h"
#include "value.h"
-#if GLIB_CHECK_VERSION(2,16,0)
-void
-purple_g_checksum_init(PurpleCipherContext *context, GChecksumType type)
-{
- GChecksum *checksum;
-
- checksum = g_checksum_new(type);
- purple_cipher_context_set_data(context, checksum);
-}
-
-void
-purple_g_checksum_reset(PurpleCipherContext *context, GChecksumType type)
-{
- GChecksum *checksum;
-
- checksum = purple_cipher_context_get_data(context);
- g_return_if_fail(checksum != NULL);
-
-#if GLIB_CHECK_VERSION(2,18,0)
- g_checksum_reset(checksum);
-#else
- g_checksum_free(checksum);
- checksum = g_checksum_new(type);
- purple_cipher_context_set_data(context, checksum);
-#endif
-}
-
-void
-purple_g_checksum_uninit(PurpleCipherContext *context)
-{
- GChecksum *checksum;
-
- checksum = purple_cipher_context_get_data(context);
- g_return_if_fail(checksum != NULL);
-
- g_checksum_free(checksum);
-}
-
-void
-purple_g_checksum_append(PurpleCipherContext *context, const guchar *data,
- gsize len)
-{
- GChecksum *checksum;
-
- checksum = purple_cipher_context_get_data(context);
- g_return_if_fail(checksum != NULL);
-
- while (len >= G_MAXSSIZE) {
- g_checksum_update(checksum, data, G_MAXSSIZE);
- len -= G_MAXSSIZE;
- data += G_MAXSSIZE;
- }
-
- if (len)
- g_checksum_update(checksum, data, len);
-}
-
-gboolean
-purple_g_checksum_digest(PurpleCipherContext *context, GChecksumType type,
- gsize len, guchar *digest, gsize *out_len)
-{
- GChecksum *checksum;
- const gssize required_length = g_checksum_type_get_length(type);
-
- checksum = purple_cipher_context_get_data(context);
-
- g_return_val_if_fail(len >= required_length, FALSE);
- g_return_val_if_fail(checksum != NULL, FALSE);
-
- g_checksum_get_digest(checksum, digest, &len);
-
- purple_cipher_context_reset(context, NULL);
-
- if (out_len)
- *out_len = len;
-
- return TRUE;
-}
-#endif
-
/*******************************************************************************
* Structs
******************************************************************************/
============================================================
--- libpurple/cipher.h b7f25e6956260dbba392c172715643e18ed8ac43
+++ libpurple/cipher.h 69a89ce60a22ce61da7ecafcb47b10e1c23c1049
@@ -496,20 +496,7 @@ gchar *purple_cipher_http_digest_calcula
const gchar *session_key);
/*@}*/
-/*****************************************************************************/
-/** @name Purple Cipher GChecksum compatibility */
-/*****************************************************************************/
-/*@{*/
-#if GLIB_CHECK_VERSION(2,16,0)
-void purple_g_checksum_init(PurpleCipherContext *context, GChecksumType type);
-void purple_g_checksum_reset(PurpleCipherContext *context, GChecksumType type);
-void purple_g_checksum_uninit(PurpleCipherContext *context);
-void purple_g_checksum_append(PurpleCipherContext *context, const guchar *data, gsize len);
-gboolean purple_g_checksum_digest(PurpleCipherContext *context, GChecksumType type, gsize len, guchar *digest, gsize *out_len);
-#endif /* GLIB_CHECK_VERSION(2,16,0) */
-/*@}*/
-
G_END_DECLS
#endif /* PURPLE_CIPHER_H */
============================================================
--- libpurple/ciphers/Makefile.am d017ca8211e86ac6e3080e18fecdc9372096dd6f
+++ libpurple/ciphers/Makefile.am 15b306380ab2ae11dbaa1755e76e625a273fd62a
@@ -2,6 +2,7 @@ libpurple_ciphers_la_SOURCES=\
libpurple_ciphers_la_SOURCES=\
des.c \
+ gchecksum.c \
hmac.c \
md4.c \
md5.c \
============================================================
--- libpurple/ciphers/md5.c 9507a1008ed870f8cefe865cd6b81c4292d75d3e
+++ libpurple/ciphers/md5.c fc406dc092c9cc26261a07e446149cf2311eef36
@@ -24,48 +24,10 @@
*/
#include <cipher.h>
-#define MD5_HMAC_BLOCK_SIZE 64
+#if !GLIB_CHECK_VERSION(2,16,0)
-static size_t
-md5_get_block_size(PurpleCipherContext *context)
-{
- /* This does not change (in this case) */
- return MD5_HMAC_BLOCK_SIZE;
-}
+#define MD5_HMAC_BLOCK_SIZE 64
-#if GLIB_CHECK_VERSION(2,16,0)
-
-static void
-md5_init(PurpleCipherContext *context, void *extra)
-{
- purple_g_checksum_init(context, G_CHECKSUM_MD5);
-}
-
-static void
-md5_reset(PurpleCipherContext *context, void *extra)
-{
- purple_g_checksum_reset(context, G_CHECKSUM_MD5);
-}
-
-static gboolean
-md5_digest(PurpleCipherContext *context, gsize in_len, guchar digest[16],
- size_t *out_len)
-{
- return purple_g_checksum_digest(context, G_CHECKSUM_MD5, in_len,
- digest, out_len);
-}
-
-static PurpleCipherOps MD5Ops = {
- .init = md5_init,
- .reset = md5_reset,
- .uninit = purple_g_checksum_uninit,
- .append = purple_g_checksum_append,
- .digest = md5_digest,
- .get_block_size = md5_get_block_size,
-};
-
-#else /* GLIB_CHECK_VERSION(2,16,0) */
-
struct MD5Context {
guint32 total[2];
guint32 state[4];
@@ -85,6 +47,13 @@ struct MD5Context {
(b)[(i) + 3] = (guchar)((n) >> 24); \
}
+static size_t
+md5_get_block_size(PurpleCipherContext *context)
+{
+ /* This does not change (in this case) */
+ return MD5_HMAC_BLOCK_SIZE;
+}
+
static void
md5_init(PurpleCipherContext *context, gpointer extra) {
struct MD5Context *md5_context;
@@ -336,10 +305,10 @@ static PurpleCipherOps MD5Ops = {
.get_block_size = md5_get_block_size,
};
-#endif /* GLIB_CHECK_VERSION(2,16,0) */
-
PurpleCipherOps *
purple_md5_cipher_get_ops(void) {
return &MD5Ops;
}
+#endif /* !GLIB_CHECK_VERSION(2,16,0) */
+
============================================================
--- libpurple/ciphers/sha1.c c9306dda4508145cc4be65f468cfd4ec3a03ff60
+++ libpurple/ciphers/sha1.c 0bcf326f41abd57974d9f2e9194829d7ebcf4668
@@ -21,48 +21,8 @@
*/
#include <cipher.h>
-#define SHA1_HMAC_BLOCK_SIZE 64
+#if !GLIB_CHECK_VERSION(2,16,0)
-static size_t
-sha1_get_block_size(PurpleCipherContext *context)
-{
- /* This does not change (in this case) */
- return SHA1_HMAC_BLOCK_SIZE;
-}
-
-#if GLIB_CHECK_VERSION(2,16,0)
-
-static void
-sha1_init(PurpleCipherContext *context, void *extra)
-{
- purple_g_checksum_init(context, G_CHECKSUM_SHA1);
-}
-
-static void
-sha1_reset(PurpleCipherContext *context, void *extra)
-{
- purple_g_checksum_reset(context, G_CHECKSUM_SHA1);
-}
-
-static gboolean
-sha1_digest(PurpleCipherContext *context, gsize in_len, guchar digest[20],
- gsize *out_len)
-{
- return purple_g_checksum_digest(context, G_CHECKSUM_SHA1, in_len,
- digest, out_len);
-}
-
-static PurpleCipherOps SHA1Ops = {
- .init = sha1_init,
- .reset = sha1_reset,
- .uninit = purple_g_checksum_uninit,
- .append = purple_g_checksum_append,
- .digest = sha1_digest,
- .get_block_size = sha1_get_block_size,
-};
-
-#else /* GLIB_CHECK_VERSION(2,16,0) */
-
#define SHA1_HMAC_BLOCK_SIZE 64
#define SHA1_ROTL(X,n) ((((X) << (n)) | ((X) >> (32-(n)))) & 0xFFFFFFFF)
@@ -76,6 +36,13 @@ struct SHA1Context {
guint32 sizeLo;
};
+static size_t
+sha1_get_block_size(PurpleCipherContext *context)
+{
+ /* This does not change (in this case) */
+ return SHA1_HMAC_BLOCK_SIZE;
+}
+
static void
sha1_hash_block(struct SHA1Context *sha1_ctx) {
gint i;
@@ -294,10 +261,10 @@ static PurpleCipherOps SHA1Ops = {
.get_block_size = sha1_get_block_size,
};
-#endif /* GLIB_CHECK_VERSION(2,16,0) */
-
PurpleCipherOps *
purple_sha1_cipher_get_ops(void) {
return &SHA1Ops;
}
+#endif /* !GLIB_CHECK_VERSION(2,16,0) */
+
============================================================
--- libpurple/ciphers/sha256.c 357d6755747b6a50a76980e3713e9c1b81f5821d
+++ libpurple/ciphers/sha256.c 37a64492bc7d731e15d339591eeff59fd7b9e89c
@@ -21,48 +21,9 @@
*/
#include <cipher.h>
-#define SHA256_HMAC_BLOCK_SIZE 64
+#if !GLIB_CHECK_VERSION(2,16,0)
-static size_t
-sha256_get_block_size(PurpleCipherContext *context)
-{
- /* This does not change (in this case) */
- return SHA256_HMAC_BLOCK_SIZE;
-}
-
-#if GLIB_CHECK_VERSION(2,16,0)
-
-static void
-sha256_init(PurpleCipherContext *context, void *extra)
-{
- purple_g_checksum_init(context, G_CHECKSUM_SHA256);
-}
-
-static void
-sha256_reset(PurpleCipherContext *context, void *extra)
-{
- purple_g_checksum_reset(context, G_CHECKSUM_SHA256);
-}
-
-static gboolean
-sha256_digest(PurpleCipherContext *context, gsize in_len, guchar digest[20],
- gsize *out_len)
-{
- return purple_g_checksum_digest(context, G_CHECKSUM_SHA256, in_len,
- digest, out_len);
-}
-
-static PurpleCipherOps SHA256Ops = {
- .init = sha256_init,
- .reset = sha256_reset,
- .uninit = purple_g_checksum_uninit,
- .append = purple_g_checksum_append,
- .digest = sha256_digest,
- .get_block_size = sha256_get_block_size,
-};
-
-#else /* GLIB_CHECK_VERSION(2,16,0) */
-
+#define SHA256_HMAC_BLOCK_SIZE 64
#define SHA256_ROTR(X,n) ((((X) >> (n)) | ((X) << (32-(n)))) & 0xFFFFFFFF)
static const guint32 sha256_K[64] =
@@ -87,6 +48,13 @@ struct SHA256Context {
guint32 sizeLo;
};
+static size_t
+sha256_get_block_size(PurpleCipherContext *context)
+{
+ /* This does not change (in this case) */
+ return SHA256_HMAC_BLOCK_SIZE;
+}
+
static void
sha256_hash_block(struct SHA256Context *sha256_ctx) {
gint i;
@@ -296,10 +264,10 @@ static PurpleCipherOps SHA256Ops = {
.get_block_size = sha256_get_block_size,
};
-#endif /* GLIB_CHECK_VERSION(2,16,0) */
-
PurpleCipherOps *
purple_sha256_cipher_get_ops(void) {
return &SHA256Ops;
}
+#endif /* !GLIB_CHECK_VERSION(2,16,0) */
+
============================================================
--- /dev/null
+++ libpurple/ciphers/gchecksum.c 87cf9cb69672d46b03823aca0554c809fb163ecb
@@ -0,0 +1,132 @@
+#include <cipher.h>
+
+#if GLIB_CHECK_VERSION(2,16,0)
+
+void
+purple_g_checksum_init(PurpleCipherContext *context, GChecksumType type)
+{
+ GChecksum *checksum;
+
+ checksum = g_checksum_new(type);
+ purple_cipher_context_set_data(context, checksum);
+}
+
+void
+purple_g_checksum_reset(PurpleCipherContext *context, GChecksumType type)
+{
+ GChecksum *checksum;
+
+ checksum = purple_cipher_context_get_data(context);
+ g_return_if_fail(checksum != NULL);
+
+#if GLIB_CHECK_VERSION(2,18,0)
+ g_checksum_reset(checksum);
+#else
+ g_checksum_free(checksum);
+ checksum = g_checksum_new(type);
+ purple_cipher_context_set_data(context, checksum);
+#endif
+}
+
+void
+purple_g_checksum_uninit(PurpleCipherContext *context)
+{
+ GChecksum *checksum;
+
+ checksum = purple_cipher_context_get_data(context);
+ g_return_if_fail(checksum != NULL);
+
+ g_checksum_free(checksum);
+}
+
+void
+purple_g_checksum_append(PurpleCipherContext *context, const guchar *data,
+ gsize len)
+{
+ GChecksum *checksum;
+
+ checksum = purple_cipher_context_get_data(context);
+ g_return_if_fail(checksum != NULL);
+
+ while (len >= G_MAXSSIZE) {
+ g_checksum_update(checksum, data, G_MAXSSIZE);
+ len -= G_MAXSSIZE;
+ data += G_MAXSSIZE;
+ }
+
+ if (len)
+ g_checksum_update(checksum, data, len);
+}
+
+gboolean
+purple_g_checksum_digest(PurpleCipherContext *context, GChecksumType type,
+ gsize len, guchar *digest, gsize *out_len)
+{
+ GChecksum *checksum;
+ const gssize required_length = g_checksum_type_get_length(type);
+
+ checksum = purple_cipher_context_get_data(context);
+
+ g_return_val_if_fail(len >= required_length, FALSE);
+ g_return_val_if_fail(checksum != NULL, FALSE);
+
+ g_checksum_get_digest(checksum, digest, &len);
+
+ purple_cipher_context_reset(context, NULL);
+
+ if (out_len)
+ *out_len = len;
+
+ return TRUE;
+}
+
+/******************************************************************************
+ * Macros
+ *****************************************************************************/
+#define PURPLE_G_CHECKSUM_IMPLEMENTATION(lower, camel, type, block_size) \
+ static size_t \
+ lower##_get_block_size(PurpleCipherContext *context) { \
+ return (block_size); \
+ } \
+ \
+ static void \
+ lower##_init(PurpleCipherContext *context, gpointer extra) { \
+ purple_g_checksum_init(context, (type)); \
+ } \
+ \
+ static void \
+ lower##_reset(PurpleCipherContext *context, gpointer extra) { \
+ purple_g_checksum_reset(context, (type)); \
+ } \
+ \
+ static gboolean \
+ lower##_digest(PurpleCipherContext *context, gsize in_len, \
+ guchar digest[], size_t *out_len) \
+ { \
+ return purple_g_checksum_digest(context, (type), in_len, digest, \
+ out_len); \
+ } \
+ \
+ static PurpleCipherOps camel##Ops = { \
+ .init = lower##_init, \
+ .reset = lower##_reset, \
+ .uninit = purple_g_checksum_uninit, \
+ .append = purple_g_checksum_append, \
+ .digest = lower##_digest, \
+ .get_block_size = lower##_get_block_size, \
+ }; \
+ \
+ PurpleCipherOps * \
+ purple_##lower##_cipher_get_ops(void) { \
+ return &camel##Ops; \
+ }
+
+/******************************************************************************
+ * Macro Expansion
+ *****************************************************************************/
+PURPLE_G_CHECKSUM_IMPLEMENTATION(md5, MD5, G_CHECKSUM_MD5, 64);
+PURPLE_G_CHECKSUM_IMPLEMENTATION(sha1, SHA1, G_CHECKSUM_SHA1, 64);
+PURPLE_G_CHECKSUM_IMPLEMENTATION(sha256, SHA256, G_CHECKSUM_SHA256, 64);
+
+#endif /* GLIB_CHECK_VERSION(2,16,0) */
+
More information about the Commits
mailing list