/pidgin/main: c92c6f818320: Finish up the ciphers and hashes
Gary Kramlich
grim at reaperworld.com
Wed Mar 30 19:25:27 EDT 2016
Changeset: c92c6f818320544343da2012d7865639298ef785
Author: Gary Kramlich <grim at reaperworld.com>
Date: 2016-03-10 20:54 -0600
Branch: default
URL: https://hg.pidgin.im/pidgin/main/rev/c92c6f818320
Description:
Finish up the ciphers and hashes
diffstat:
libpurple/tests/Makefile.am | 37 +-
libpurple/tests/test_cipher.c | 610 ------------------------------------------
libpurple/tests/test_des.c | 69 ++++
libpurple/tests/test_des3.c | 223 +++++++++++++++
libpurple/tests/test_hmac.c | 379 ++++++++++++++++++++++++++
libpurple/tests/test_md4.c | 0
libpurple/tests/test_md5.c | 0
libpurple/tests/test_sha1.c | 0
libpurple/tests/test_sha256.c | 0
9 files changed, 696 insertions(+), 622 deletions(-)
diffs (truncated from 1364 to 300 lines):
diff --git a/libpurple/tests/Makefile.am b/libpurple/tests/Makefile.am
--- a/libpurple/tests/Makefile.am
+++ b/libpurple/tests/Makefile.am
@@ -6,22 +6,35 @@ COMMON_LIBS=\
$(GPLUGIN_LIBS)
test_programs=\
- test_md4hash \
- test_md5hash \
- test_sha1hash \
- test_sha256hash
+ test_des \
+ test_des3 \
+ test_hmac \
+ test_md4 \
+ test_md5 \
+ test_sha1 \
+ test_sha256
-test_md4hash_SOURCES=test_md4hash.c
-test_md4hash_LDADD=$(COMMON_LIBS)
-test_md5hash_SOURCES=test_md5hash.c
-test_md5hash_LDADD=$(COMMON_LIBS)
+test_des_SOURCES=test_des.c
+test_des_LDADD=$(COMMON_LIBS)
-test_sha1hash_SOURCES=test_sha1hash.c
-test_sha1hash_LDADD=$(COMMON_LIBS)
+test_des3_SOURCES=test_des3.c
+test_des3_LDADD=$(COMMON_LIBS)
-test_sha256hash_SOURCES=test_sha256hash.c
-test_sha256hash_LDADD=$(COMMON_LIBS)
+test_hmac_SOURCES=test_hmac.c
+test_hmac_LDADD=$(COMMON_LIBS)
+
+test_md4_SOURCES=test_md4.c
+test_md4_LDADD=$(COMMON_LIBS)
+
+test_md5_SOURCES=test_md5.c
+test_md5_LDADD=$(COMMON_LIBS)
+
+test_sha1_SOURCES=test_sha1.c
+test_sha1_LDADD=$(COMMON_LIBS)
+
+test_sha256_SOURCES=test_sha256.c
+test_sha256_LDADD=$(COMMON_LIBS)
AM_CPPFLAGS = \
-I$(top_srcdir)/libpurple \
diff --git a/libpurple/tests/test_cipher.c b/libpurple/tests/test_cipher.c
deleted file mode 100644
--- a/libpurple/tests/test_cipher.c
+++ /dev/null
@@ -1,610 +0,0 @@
-#include <glib.h>
-#include <check.h>
-#include <stdlib.h>
-#include <string.h>
-
-#undef HAVE_DBUS
-
-#include "tests.h"
-
-#include "../ciphers/des3cipher.h"
-#include "../ciphers/descipher.h"
-#include "../ciphers/hmaccipher.h"
-#include "../ciphers/md4hash.h"
-#include "../ciphers/md5hash.h"
-#include "../ciphers/sha1hash.h"
-#include "../ciphers/sha256hash.h"
-
-/******************************************************************************
- * DES Tests
- *****************************************************************************/
-#define DES_TEST(in, keyz, out, len) { \
- PurpleCipher *cipher = NULL; \
- guchar answer[len+1]; \
- gint ret = 0; \
- guchar decrypt[len+1] = in; \
- guchar key[8+1] = keyz;\
- guchar encrypt[len+1] = out;\
- \
- cipher = purple_des_cipher_new(); \
- purple_cipher_set_key(cipher, key, 8); \
- \
- ret = purple_cipher_encrypt(cipher, decrypt, len, answer, len); \
- fail_unless(ret == len, NULL); \
- fail_unless(memcmp(encrypt, answer, len) == 0, NULL); \
- \
- ret = purple_cipher_decrypt(cipher, encrypt, len, answer, len); \
- fail_unless(ret == len, NULL); \
- fail_unless(memcmp(decrypt, answer, len) == 0, NULL); \
- \
- g_object_unref(cipher); \
-}
-
-START_TEST(test_des_12345678) {
- DES_TEST("12345678",
- "\x3b\x38\x98\x37\x15\x20\xf7\x5e",
- "\x06\x22\x05\xac\x6a\x0d\x55\xdd",
- 8);
-}
-END_TEST
-
-START_TEST(test_des_abcdefgh) {
- DES_TEST("abcdefgh",
- "\x3b\x38\x98\x37\x15\x20\xf7\x5e",
- "\x62\xe0\xc6\x8c\x48\xe4\x75\xed",
- 8);
-}
-END_TEST
-
-/******************************************************************************
- * DES3 Tests
- * See http://csrc.nist.gov/groups/ST/toolkit/examples.html
- * and some NULL things I made up
- *****************************************************************************/
-
-#define DES3_TEST(in, key, iv, out, len, mode) { \
- PurpleCipher *cipher = NULL; \
- guchar answer[len+1]; \
- guchar decrypt[len+1] = in; \
- guchar encrypt[len+1] = out; \
- gint ret = 0; \
- \
- cipher = purple_des3_cipher_new(); \
- purple_cipher_set_key(cipher, (guchar *)key, 24); \
- purple_cipher_set_batch_mode(cipher, (mode)); \
- purple_cipher_set_iv(cipher, (guchar *)iv, 8); \
- \
- ret = purple_cipher_encrypt(cipher, decrypt, len, answer, len); \
- fail_unless(ret == len, NULL); \
- fail_unless(memcmp(encrypt, answer, len) == 0, NULL); \
- \
- ret = purple_cipher_decrypt(cipher, encrypt, len, answer, len); \
- fail_unless(ret == len, NULL); \
- fail_unless(memcmp(decrypt, answer, len) == 0, NULL); \
- \
- g_object_unref(cipher); \
-}
-
-START_TEST(test_des3_ecb_nist1) {
- DES3_TEST(
- "\x6B\xC1\xBE\xE2\x2E\x40\x9F\x96\xE9\x3D\x7E\x11\x73\x93\x17\x2A"
- "\xAE\x2D\x8A\x57\x1E\x03\xAC\x9C\x9E\xB7\x6F\xAC\x45\xAF\x8E\x51",
- "\x01\x23\x45\x67\x89\xAB\xCD\xEF"
- "\x23\x45\x67\x89\xAB\xCD\xEF\x01"
- "\x45\x67\x89\xAB\xCD\xEF\x01\x23",
- "00000000", /* ignored */
- "\x71\x47\x72\xF3\x39\x84\x1D\x34\x26\x7F\xCC\x4B\xD2\x94\x9C\xC3"
- "\xEE\x11\xC2\x2A\x57\x6A\x30\x38\x76\x18\x3F\x99\xC0\xB6\xDE\x87",
- 32,
- PURPLE_CIPHER_BATCH_MODE_ECB);
-}
-END_TEST
-
-START_TEST(test_des3_ecb_nist2) {
- DES3_TEST(
- "\x6B\xC1\xBE\xE2\x2E\x40\x9F\x96\xE9\x3D\x7E\x11\x73\x93\x17\x2A"
- "\xAE\x2D\x8A\x57\x1E\x03\xAC\x9C\x9E\xB7\x6F\xAC\x45\xAF\x8E\x51",
- "\x01\x23\x45\x67\x89\xAB\xCD\xEF"
- "\x23\x45\x67\x89\xAB\xCD\xEF\x01"
- "\x01\x23\x45\x67\x89\xAB\xCD\xEF",
- "00000000", /* ignored */
- "\x06\xED\xE3\xD8\x28\x84\x09\x0A\xFF\x32\x2C\x19\xF0\x51\x84\x86"
- "\x73\x05\x76\x97\x2A\x66\x6E\x58\xB6\xC8\x8C\xF1\x07\x34\x0D\x3D",
- 32,
- PURPLE_CIPHER_BATCH_MODE_ECB);
-}
-END_TEST
-
-START_TEST(test_des3_ecb_null_key) {
- DES3_TEST(
- "\x16\xf4\xb3\x77\xfd\x4b\x9e\xca",
- "\x38\x00\x88\x6a\xef\xcb\x00\xad"
- "\x5d\xe5\x29\x00\x7d\x98\x64\x4c"
- "\x86\x00\x7b\xd3\xc7\x00\x7b\x32",
- "00000000", /* ignored */
- "\xc0\x60\x30\xa1\xb7\x25\x42\x44",
- 8,
- PURPLE_CIPHER_BATCH_MODE_ECB);
-}
-END_TEST
-
-START_TEST(test_des3_ecb_null_text) {
- DES3_TEST(
- "\x65\x73\x34\xc1\x19\x00\x79\x65",
- "\x32\x64\xda\x10\x13\x6a\xfe\x1e"
- "\x37\x54\xd1\x2c\x41\x04\x10\x40"
- "\xaf\x1c\x75\x2b\x51\x3a\x03\xf5",
- "00000000", /* ignored */
- "\xe5\x80\xf6\x12\xf8\x4e\xd9\x6c",
- 8,
- PURPLE_CIPHER_BATCH_MODE_ECB);
-}
-END_TEST
-
-START_TEST(test_des3_ecb_null_key_and_text) {
- DES3_TEST(
- "\xdf\x7f\x00\x92\xe7\xc1\x49\xd2",
- "\x0e\x41\x00\xc4\x8b\xf0\x6e\xa1"
- "\x66\x49\x42\x63\x22\x00\xf0\x99"
- "\x6b\x22\xc1\x37\x9c\x00\xe4\x8f",
- "00000000", /* ignored */
- "\x73\xd8\x1f\x1f\x50\x01\xe4\x79",
- 8,
- PURPLE_CIPHER_BATCH_MODE_ECB);
-}
-END_TEST
-
-START_TEST(test_des3_cbc_nist1) {
- DES3_TEST(
- "\x6B\xC1\xBE\xE2\x2E\x40\x9F\x96\xE9\x3D\x7E\x11\x73\x93\x17\x2A"
- "\xAE\x2D\x8A\x57\x1E\x03\xAC\x9C\x9E\xB7\x6F\xAC\x45\xAF\x8E\x51",
- "\x01\x23\x45\x67\x89\xAB\xCD\xEF"
- "\x23\x45\x67\x89\xAB\xCD\xEF\x01"
- "\x45\x67\x89\xAB\xCD\xEF\x01\x23",
- "\xF6\x9F\x24\x45\xDF\x4F\x9B\x17",
- "\x20\x79\xC3\xD5\x3A\xA7\x63\xE1\x93\xB7\x9E\x25\x69\xAB\x52\x62"
- "\x51\x65\x70\x48\x1F\x25\xB5\x0F\x73\xC0\xBD\xA8\x5C\x8E\x0D\xA7",
- 32,
- PURPLE_CIPHER_BATCH_MODE_CBC);
-}
-END_TEST
-
-START_TEST(test_des3_cbc_nist2) {
- DES3_TEST(
- "\x6B\xC1\xBE\xE2\x2E\x40\x9F\x96\xE9\x3D\x7E\x11\x73\x93\x17\x2A"
- "\xAE\x2D\x8A\x57\x1E\x03\xAC\x9C\x9E\xB7\x6F\xAC\x45\xAF\x8E\x51",
- "\x01\x23\x45\x67\x89\xAB\xCD\xEF"
- "\x23\x45\x67\x89\xAB\xCD\xEF\x01"
- "\x01\x23\x45\x67\x89\xAB\xCD\xEF",
- "\xF6\x9F\x24\x45\xDF\x4F\x9B\x17",
- "\x74\x01\xCE\x1E\xAB\x6D\x00\x3C\xAF\xF8\x4B\xF4\x7B\x36\xCC\x21"
- "\x54\xF0\x23\x8F\x9F\xFE\xCD\x8F\x6A\xCF\x11\x83\x92\xB4\x55\x81",
- 32,
- PURPLE_CIPHER_BATCH_MODE_CBC);
-}
-END_TEST
-
-START_TEST(test_des3_cbc_null_key) {
- DES3_TEST(
- "\x16\xf4\xb3\x77\xfd\x4b\x9e\xca",
- "\x38\x00\x88\x6a\xef\xcb\x00\xad"
- "\x5d\xe5\x29\x00\x7d\x98\x64\x4c"
- "\x86\x00\x7b\xd3\xc7\x00\x7b\x32",
- "\x31\x32\x33\x34\x35\x36\x37\x38",
- "\x52\xe7\xde\x96\x39\x87\x87\xdb",
- 8,
- PURPLE_CIPHER_BATCH_MODE_CBC);
-}
-END_TEST
-
-START_TEST(test_des3_cbc_null_text) {
- DES3_TEST(
- "\x65\x73\x34\xc1\x19\x00\x79\x65",
- "\x32\x64\xda\x10\x13\x6a\xfe\x1e"
- "\x37\x54\xd1\x2c\x41\x04\x10\x40"
- "\xaf\x1c\x75\x2b\x51\x3a\x03\xf5",
- "\x7C\xAF\x0D\x57\x1E\x57\x10\xDA",
- "\x40\x12\x0e\x00\x85\xff\x6c\xc2",
- 8,
- PURPLE_CIPHER_BATCH_MODE_CBC);
-}
-END_TEST
-
-START_TEST(test_des3_cbc_null_key_and_text) {
- DES3_TEST(
- "\xdf\x7f\x00\x92\xe7\xc1\x49\xd2",
- "\x0e\x41\x00\xc4\x8b\xf0\x6e\xa1"
- "\x66\x49\x42\x63\x22\x00\xf0\x99"
- "\x6b\x22\xc1\x37\x9c\x00\xe4\x8f",
- "\x01\x19\x0D\x2c\x40\x67\x89\x67",
- "\xa7\xc1\x10\xbe\x9b\xd5\x8a\x67",
- 8,
- PURPLE_CIPHER_BATCH_MODE_CBC);
-}
-END_TEST
-
-/******************************************************************************
- * HMAC Tests
- * See RFC2202 and some other NULL tests I made up
- *****************************************************************************/
-
-#define HMAC_TEST(data, data_len, key, key_len, type, digest) { \
- PurpleCipher *cipher = NULL; \
- PurpleHash *hash = NULL; \
- gchar cdigest[41]; \
- gboolean ret = FALSE; \
- \
- hash = purple_##type##_hash_new(); \
- cipher = purple_hmac_cipher_new(hash); \
- purple_cipher_set_key(cipher, (guchar *)key, (key_len)); \
- \
- purple_cipher_append(cipher, (guchar *)(data), (data_len)); \
- ret = purple_cipher_digest_to_str(cipher, cdigest, sizeof(cdigest)); \
- \
- fail_unless(ret == TRUE, NULL); \
More information about the Commits
mailing list