/pidgin/main: cdb480f66f8d: fixed the cipher unittests and remov...
Gary Kramlich
grim at reaperworld.com
Sun Jun 23 03:43:13 EDT 2013
Changeset: cdb480f66f8da423a25a74a5200076c8be8402e8
Author: Gary Kramlich <grim at reaperworld.com>
Date: 2013-06-23 02:34 -0500
Branch: default
URL: https://hg.pidgin.im/pidgin/main/rev/cdb480f66f8d
Description:
fixed the cipher unittests and removed some uncessary g_return_val_if_fails since the cipher api is alredy doing the check, and since the ones in the des stuff seemed to be doing the opposite of the check that the cipher api was doing
diffstat:
libpurple/ciphers/des.c | 12 ------------
libpurple/tests/test_cipher.c | 43 ++++++++++++++++---------------------------
2 files changed, 16 insertions(+), 39 deletions(-)
diffs (169 lines):
diff --git a/libpurple/ciphers/des.c b/libpurple/ciphers/des.c
--- a/libpurple/ciphers/des.c
+++ b/libpurple/ciphers/des.c
@@ -399,8 +399,6 @@ des_encrypt(PurpleCipherContext *context
guint8 buf[8] = {0,0,0,0,0,0,0,0};
ssize_t out_len;
- g_return_val_if_fail(out_size < in_len, -1);
-
while(offset+8<=in_len) {
des_ecb_crypt(purple_cipher_context_get_data(context),
input+offset,
@@ -435,8 +433,6 @@ des_decrypt(PurpleCipherContext *context
guint8 buf[8] = {0,0,0,0,0,0,0,0};
ssize_t out_len;
- g_return_val_if_fail(out_size < in_len, -1);
-
while(offset+8<=in_len) {
des_ecb_crypt(purple_cipher_context_get_data(context),
input+offset,
@@ -562,8 +558,6 @@ des3_ecb_encrypt(struct _des3_ctx *ctx,
guint8 buf[8] = {0,0,0,0,0,0,0,0};
ssize_t out_len;
- g_return_val_if_fail(out_size < in_len, -1);
-
while (offset + 8 <= in_len) {
des_ecb_crypt(&ctx->key1,
input+offset,
@@ -616,8 +610,6 @@ des3_cbc_encrypt(struct _des3_ctx *ctx,
ssize_t out_len;
memcpy(buf, ctx->iv, 8);
- g_return_val_if_fail(out_size < in_len, -1);
-
while (offset + 8 <= in_len) {
for (i = 0; i < 8; i++)
buf[i] ^= input[offset + i];
@@ -690,8 +682,6 @@ des3_ecb_decrypt(struct _des3_ctx *ctx,
guint8 buf[8] = {0,0,0,0,0,0,0,0};
ssize_t out_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,
@@ -745,8 +735,6 @@ des3_cbc_decrypt(struct _des3_ctx *ctx,
guint8 link[8];
ssize_t out_len;
- g_return_val_if_fail(out_size < in_len, -1);
-
memcpy(link, ctx->iv, 8);
while (offset + 8 <= in_len) {
des_ecb_crypt(&ctx->key3,
diff --git a/libpurple/tests/test_cipher.c b/libpurple/tests/test_cipher.c
--- a/libpurple/tests/test_cipher.c
+++ b/libpurple/tests/test_cipher.c
@@ -22,8 +22,7 @@
context = purple_cipher_context_new(cipher, NULL); \
purple_cipher_context_append(context, (guchar *)(data), strlen((data))); \
\
- ret = purple_cipher_context_digest_to_str(context, sizeof(cdigest), cdigest, \
- NULL); \
+ ret = purple_cipher_context_digest_to_str(context, cdigest, sizeof(cdigest)); \
\
fail_unless(ret == TRUE, NULL); \
\
@@ -85,8 +84,7 @@ END_TEST
context = purple_cipher_context_new(cipher, NULL); \
purple_cipher_context_append(context, (guchar *)(data), strlen((data))); \
\
- ret = purple_cipher_context_digest_to_str(context, sizeof(cdigest), cdigest, \
- NULL); \
+ ret = purple_cipher_context_digest_to_str(context, cdigest, sizeof(cdigest)); \
\
fail_unless(ret == TRUE, NULL); \
\
@@ -159,8 +157,7 @@ END_TEST
purple_cipher_context_append(context, buff, 1000); \
} \
\
- ret = purple_cipher_context_digest_to_str(context, sizeof(cdigest), cdigest, \
- NULL); \
+ ret = purple_cipher_context_digest_to_str(context, cdigest, sizeof(cdigest)); \
\
fail_unless(ret == TRUE, NULL); \
\
@@ -220,8 +217,7 @@ END_TEST
purple_cipher_context_append(context, buff, 1000); \
} \
\
- ret = purple_cipher_context_digest_to_str(context, sizeof(cdigest), cdigest, \
- NULL); \
+ ret = purple_cipher_context_digest_to_str(context, cdigest, sizeof(cdigest)); \
\
fail_unless(ret == TRUE, NULL); \
\
@@ -267,20 +263,17 @@ END_TEST
guchar decrypt[len+1] = in; \
guchar key[8+1] = keyz;\
guchar encrypt[len+1] = out;\
- size_t outlen; \
\
cipher = purple_ciphers_find_cipher("des"); \
context = purple_cipher_context_new(cipher, NULL); \
- purple_cipher_context_set_key(context, key); \
+ purple_cipher_context_set_key(context, key, sizeof(key)); \
\
- ret = purple_cipher_context_encrypt(context, decrypt, len, answer, &outlen); \
- fail_unless(ret == 0, NULL); \
- fail_unless(outlen == (len), NULL); \
+ ret = purple_cipher_context_encrypt(context, decrypt, len, answer, sizeof(answer)); \
+ fail_unless(ret == len, NULL); \
fail_unless(memcmp(encrypt, answer, len) == 0, NULL); \
\
- ret = purple_cipher_context_decrypt(context, encrypt, len, answer, &outlen); \
- fail_unless(ret == 0, NULL); \
- fail_unless(outlen == (len), NULL); \
+ ret = purple_cipher_context_decrypt(context, encrypt, len, answer, sizeof(answer)); \
+ fail_unless(ret == len, NULL); \
fail_unless(memcmp(decrypt, answer, len) == 0, NULL); \
\
purple_cipher_context_destroy(context); \
@@ -314,23 +307,20 @@ END_TEST
guchar answer[len+1]; \
guchar decrypt[len+1] = in; \
guchar encrypt[len+1] = out; \
- size_t outlen; \
gint ret = 0; \
\
cipher = purple_ciphers_find_cipher("des3"); \
context = purple_cipher_context_new(cipher, NULL); \
- purple_cipher_context_set_key(context, (guchar *)key); \
+ purple_cipher_context_set_key(context, (guchar *)key, sizeof(key)); \
purple_cipher_context_set_batch_mode(context, (mode)); \
purple_cipher_context_set_iv(context, (guchar *)iv, 8); \
\
- ret = purple_cipher_context_encrypt(context, decrypt, len, answer, &outlen); \
- fail_unless(ret == 0, NULL); \
- fail_unless(outlen == (len), NULL); \
+ ret = purple_cipher_context_encrypt(context, decrypt, len, answer, sizeof(answer)); \
+ fail_unless(ret == len, NULL); \
fail_unless(memcmp(encrypt, answer, len) == 0, NULL); \
\
- ret = purple_cipher_context_decrypt(context, encrypt, len, answer, &outlen); \
- fail_unless(ret == 0, NULL); \
- fail_unless(outlen == (len), NULL); \
+ ret = purple_cipher_context_decrypt(context, encrypt, len, answer, sizeof(answer)); \
+ fail_unless(ret == len, NULL); \
fail_unless(memcmp(decrypt, answer, len) == 0, NULL); \
\
purple_cipher_context_destroy(context); \
@@ -488,11 +478,10 @@ END_TEST
cipher = purple_ciphers_find_cipher("hmac"); \
context = purple_cipher_context_new(cipher, NULL); \
purple_cipher_context_set_option(context, "hash", type); \
- purple_cipher_context_set_key_with_len(context, (guchar *)key, (key_len)); \
+ purple_cipher_context_set_key(context, (guchar *)key, (key_len)); \
\
purple_cipher_context_append(context, (guchar *)(data), (data_len)); \
- ret = purple_cipher_context_digest_to_str(context, sizeof(cdigest), cdigest, \
- NULL); \
+ ret = purple_cipher_context_digest_to_str(context, cdigest, sizeof(cdigest)); \
\
fail_unless(ret == TRUE, NULL); \
fail_unless(strcmp((digest), cdigest) == 0, NULL); \
More information about the Commits
mailing list