--- a/libpurple/cipher.c Sun May 05 15:37:25 2013 +0200
+++ b/libpurple/cipher.c Sun May 05 16:29:14 2013 +0200
@@ -473,50 +473,49 @@
-purple_cipher_context_encrypt(PurpleCipherContext *context, const guchar data[],
- size_t len, guchar output[], size_t *outlen)
+purple_cipher_context_encrypt(PurpleCipherContext *context, + const guchar input[], size_t in_len, guchar output[], size_t out_size) PurpleCipher *cipher = NULL;
- g_return_val_if_fail(context, -1);
+ g_return_val_if_fail(context != NULL, -1); + g_return_val_if_fail(input != NULL, -1); + g_return_val_if_fail(output != NULL, -1); + g_return_val_if_fail(out_size < in_len, -1); cipher = context->cipher;
g_return_val_if_fail(cipher, -1);
if(cipher->ops && cipher->ops->encrypt)
- return cipher->ops->encrypt(context, data, len, output, outlen);
+ return cipher->ops->encrypt(context, input, in_len, output, out_size); purple_debug_warning("cipher", "the %s cipher does not support the encrypt"
"operation\n", cipher->name);
-purple_cipher_context_decrypt(PurpleCipherContext *context, const guchar data[],
- size_t len, guchar output[], size_t *outlen)
+purple_cipher_context_decrypt(PurpleCipherContext *context, + const guchar input[], size_t in_len, guchar output[], size_t out_size) PurpleCipher *cipher = NULL;
- g_return_val_if_fail(context, -1);
+ g_return_val_if_fail(context != NULL, -1); + g_return_val_if_fail(input != NULL, -1); + g_return_val_if_fail(output != NULL, -1); cipher = context->cipher;
g_return_val_if_fail(cipher, -1);
if(cipher->ops && cipher->ops->decrypt)
- return cipher->ops->decrypt(context, data, len, output, outlen);
+ return cipher->ops->decrypt(context, input, in_len, output, out_size); purple_debug_warning("cipher", "the %s cipher does not support the decrypt"
"operation\n", cipher->name);
--- a/libpurple/cipher.h Sun May 05 15:37:25 2013 +0200
+++ b/libpurple/cipher.h Sun May 05 16:29:14 2013 +0200
@@ -103,10 +103,10 @@
size_t (*get_digest_size)(PurpleCipherContext *context);
/** The encrypt function */
- int (*encrypt)(PurpleCipherContext *context, const guchar data[], size_t len, guchar output[], size_t *outlen);
+ ssize_t (*encrypt)(PurpleCipherContext *context, const guchar input[], size_t in_len, guchar output[], size_t out_size); /** The decrypt function */
- int (*decrypt)(PurpleCipherContext *context, const guchar data[], size_t len, guchar output[], size_t *outlen);
+ ssize_t (*decrypt)(PurpleCipherContext *context, const guchar input[], size_t in_len, guchar output[], size_t out_size); /** The set salt function */
void (*set_salt)(PurpleCipherContext *context, guchar *salt, size_t len);
@@ -347,28 +347,28 @@
* Encrypts data using the context
- * @param context The context
- * @param data The data to encrypt
- * @param len The length of the data
- * @param output The output buffer
- * @param outlen The len of data that was outputed
+ * @param context The context + * @param input The data to encrypt + * @param in_len The length of the data + * @param output The output buffer + * @param out_size The size of the output buffer - * @return A cipher specific status code
+ * @return A length of data that was outputed or -1, if failed -gint purple_cipher_context_encrypt(PurpleCipherContext *context, const guchar data[], size_t len, guchar output[], size_t *outlen);
+ssize_t purple_cipher_context_encrypt(PurpleCipherContext *context, const guchar input[], size_t in_len, guchar output[], size_t out_size); * Decrypts data using the context
- * @param context The context
- * @param data The data to encrypt
- * @param len The length of the returned value
- * @param output The output buffer
- * @param outlen The len of data that was outputed
+ * @param context The context + * @param input The data to encrypt + * @param in_len The length of the returned value + * @param output The output buffer + * @param out_size The size of the output buffer - * @return A cipher specific status code
+ * @return A length of data that was outputed or -1, if failed -gint purple_cipher_context_decrypt(PurpleCipherContext *context, const guchar data[], size_t len, guchar output[], size_t *outlen);
+ssize_t purple_cipher_context_decrypt(PurpleCipherContext *context, const guchar input[], size_t in_len, guchar output[], size_t out_size); * Sets the salt on a context
--- a/libpurple/ciphers/des.c Sun May 05 15:37:25 2013 +0200
+++ b/libpurple/ciphers/des.c Sun May 05 16:29:14 2013 +0200
@@ -33,6 +33,8 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
@@ -387,27 +389,32 @@
-des_encrypt(PurpleCipherContext *context, const guchar data[],
- size_t len, guchar output[], size_t *outlen)
+des_encrypt(PurpleCipherContext *context, const guchar input[], size_t in_len, + guchar output[], size_t out_size) guint8 buf[8] = {0,0,0,0,0,0,0,0};
+ g_return_val_if_fail(out_size < in_len, -1); + while(offset+8<=in_len) { des_ecb_crypt(purple_cipher_context_get_data(context),
- *outlen += len - offset;
+ out_len += in_len - offset; + g_return_val_if_fail(out_size < out_len, -1);
des_ecb_crypt(purple_cipher_context_get_data(context),
@@ -415,30 +422,35 @@
-des_decrypt(PurpleCipherContext *context, const guchar data[],
- size_t len, guchar output[], size_t *outlen)
+des_decrypt(PurpleCipherContext *context, const guchar input[], size_t in_len, + guchar output[], size_t out_size) guint8 buf[8] = {0,0,0,0,0,0,0,0};
+ g_return_val_if_fail(out_size < in_len, -1); + while(offset+8<=in_len) { des_ecb_crypt(purple_cipher_context_get_data(context),
- *outlen += len - offset;
+ out_len += in_len - offset; + g_return_val_if_fail(out_size < out_len, -1);
des_ecb_crypt(purple_cipher_context_get_data(context),
@@ -446,7 +458,7 @@
@@ -538,17 +550,21 @@
-des3_ecb_encrypt(struct _des3_ctx *ctx, const guchar data[],
- size_t len, guchar output[], size_t *outlen)
+des3_ecb_encrypt(struct _des3_ctx *ctx, const guchar input[], size_t in_len, + guchar output[], size_t out_size) guint8 buf[8] = {0,0,0,0,0,0,0,0};
- while (offset + 8 <= len) {
+ g_return_val_if_fail(out_size < in_len, -1); + while (offset + 8 <= in_len) { des_ecb_crypt(&ctx->key1,
des_ecb_crypt(&ctx->key2,
@@ -561,13 +577,14 @@
- *outlen += len - offset;
+ out_len += in_len - offset; + g_return_val_if_fail(out_size < out_len, -1);
des_ecb_crypt(&ctx->key1,
@@ -583,21 +600,25 @@
-des3_cbc_encrypt(struct _des3_ctx *ctx, const guchar data[],
- size_t len, guchar output[], size_t *outlen)
+des3_cbc_encrypt(struct _des3_ctx *ctx, const guchar input[], size_t in_len, + guchar output[], size_t out_size) - while (offset + 8 <= len) {
+ g_return_val_if_fail(out_size < in_len, -1); + while (offset + 8 <= in_len) { - buf[i] ^= data[offset + i];
+ buf[i] ^= input[offset + i]; des_ecb_crypt(&ctx->key1,
@@ -614,13 +635,14 @@
memcpy(buf, output+offset, 8);
- *outlen += len - offset;
+ out_len += in_len - offset; + g_return_val_if_fail(out_size < out_len, -1);
+ buf[i++] ^= input[tmp]; des_ecb_crypt(&ctx->key1,
@@ -636,19 +658,19 @@
-des3_encrypt(PurpleCipherContext *context, const guchar data[],
- size_t len, guchar output[], size_t *outlen)
+des3_encrypt(PurpleCipherContext *context, const guchar input[], size_t in_len, + guchar output[], size_t out_size) struct _des3_ctx *ctx = purple_cipher_context_get_data(context);
if (ctx->mode == PURPLE_CIPHER_BATCH_MODE_ECB) {
- return des3_ecb_encrypt(ctx, data, len, output, outlen);
+ return des3_ecb_encrypt(ctx, input, in_len, output, out_size); } else if (ctx->mode == PURPLE_CIPHER_BATCH_MODE_CBC) {
- return des3_cbc_encrypt(ctx, data, len, output, outlen);
+ return des3_cbc_encrypt(ctx, input, in_len, output, out_size); g_return_val_if_reached(0);
@@ -657,17 +679,21 @@
-des3_ecb_decrypt(struct _des3_ctx *ctx, const guchar data[],
- size_t len, guchar output[], size_t *outlen)
+des3_ecb_decrypt(struct _des3_ctx *ctx, const guchar input[], size_t in_len, + guchar output[], size_t out_size) guint8 buf[8] = {0,0,0,0,0,0,0,0};
- while (offset + 8 <= len) {
+ g_return_val_if_fail(out_size < in_len, -1); + while (offset + 8 <= in_len) { /* NOTE: Apply key in reverse */
des_ecb_crypt(&ctx->key3,
des_ecb_crypt(&ctx->key2,
@@ -680,13 +706,14 @@
- *outlen += len - offset;
+ out_len += in_len - offset; + g_return_val_if_fail(out_size < out_len, -1);
des_ecb_crypt(&ctx->key3,
@@ -702,22 +729,26 @@
-des3_cbc_decrypt(struct _des3_ctx *ctx, const guchar data[],
- size_t len, guchar output[], size_t *outlen)
+des3_cbc_decrypt(struct _des3_ctx *ctx, const guchar input[], size_t in_len, + guchar output[], size_t out_size) guint8 buf[8] = {0,0,0,0,0,0,0,0};
+ g_return_val_if_fail(out_size < in_len, -1); memcpy(link, ctx->iv, 8);
- while (offset + 8 <= len) {
+ while (offset + 8 <= in_len) { des_ecb_crypt(&ctx->key3,
des_ecb_crypt(&ctx->key2,
@@ -730,17 +761,18 @@
output[offset + i] ^= link[i];
- memcpy(link, data + offset, 8);
+ memcpy(link, input + offset, 8);
- *outlen += len - offset;
+ out_len += in_len - offset; + g_return_val_if_fail(out_size < out_len, -1);
des_ecb_crypt(&ctx->key3,
@@ -758,19 +790,19 @@
output[offset + i] ^= link[i];
-des3_decrypt(PurpleCipherContext *context, const guchar data[],
- size_t len, guchar output[], size_t *outlen)
+des3_decrypt(PurpleCipherContext *context, const guchar input[], size_t in_len, + guchar output[], size_t out_size) struct _des3_ctx *ctx = purple_cipher_context_get_data(context);
if (ctx->mode == PURPLE_CIPHER_BATCH_MODE_ECB) {
- return des3_ecb_decrypt(ctx, data, len, output, outlen);
+ return des3_ecb_decrypt(ctx, input, in_len, output, out_size); } else if (ctx->mode == PURPLE_CIPHER_BATCH_MODE_CBC) {
- return des3_cbc_decrypt(ctx, data, len, output, outlen);
+ return des3_cbc_decrypt(ctx, input, in_len, output, out_size); g_return_val_if_reached(0);
--- a/libpurple/ciphers/rc4.c Sun May 05 15:37:25 2013 +0200
+++ b/libpurple/ciphers/rc4.c Sun May 05 16:29:14 2013 +0200
@@ -19,6 +19,8 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
@@ -95,9 +97,10 @@
-rc4_encrypt(PurpleCipherContext *context, const guchar data[],
- size_t len, guchar output[], size_t *outlen) {
+rc4_encrypt(PurpleCipherContext *context, const guchar input[], size_t in_len, + guchar output[], size_t out_size) { @@ -110,7 +113,7 @@
- for(i = 0; i < len; i++)
+ for(i = 0; i < in_len; i++) y = (state[x] + y) % 256;
@@ -118,14 +121,12 @@
z = state[x] + (state[y]) % 256;
- output[i] = data[i] ^ state[z];
+ output[i] = input[i] ^ state[z];
static PurpleCipherOps RC4Ops = {
--- a/libpurple/ntlm.c Sun May 05 15:37:25 2013 +0200
+++ b/libpurple/ntlm.c Sun May 05 16:29:14 2013 +0200
@@ -192,12 +192,11 @@
PurpleCipherContext *context;
cipher = purple_ciphers_find_cipher("des");
context = purple_cipher_context_new(cipher, NULL);
purple_cipher_context_set_key(context, key, 8);
- purple_cipher_context_encrypt(context, plaintext, 8, result, &outlen);
+ purple_cipher_context_encrypt(context, plaintext, 8, result, 8); purple_cipher_context_destroy(context);
--- a/libpurple/protocols/msn/nexus.c Sun May 05 15:37:25 2013 +0200
+++ b/libpurple/protocols/msn/nexus.c Sun May 05 16:29:14 2013 +0200
@@ -147,7 +147,6 @@
PurpleCipherContext *des3;
des3 = purple_cipher_context_new_by_name("des3", NULL);
purple_cipher_context_set_key(des3, (guchar *)key, 24);
@@ -156,9 +155,9 @@
- purple_cipher_context_decrypt(des3, (guchar *)data, len, (guchar *)out, &outlen);
+ purple_cipher_context_decrypt(des3, (guchar *)data, len, (guchar *)out, len); - purple_cipher_context_encrypt(des3, (guchar *)data, len, (guchar *)out, &outlen);
+ purple_cipher_context_encrypt(des3, (guchar *)data, len, (guchar *)out, len); purple_cipher_context_destroy(des3);