summaryrefslogtreecommitdiff
path: root/pjlib-util/src/pjlib-util-test
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2007-02-26 02:33:14 +0000
committerBenny Prijono <bennylp@teluu.com>2007-02-26 02:33:14 +0000
commitbf839cd77520ad28437e55a73fd8167838023f42 (patch)
tree140617414ee6d99323f69d2d478d767ddf4b7ecd /pjlib-util/src/pjlib-util-test
parenta34fbb64e27b5075a4207318ba356349669b4f08 (diff)
Added CRC32 code to pjlib-util, and implemented STUN FINGERPRINT and MESSAGE-INTEGRITY
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@1002 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjlib-util/src/pjlib-util-test')
-rw-r--r--pjlib-util/src/pjlib-util-test/encryption.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/pjlib-util/src/pjlib-util-test/encryption.c b/pjlib-util/src/pjlib-util-test/encryption.c
index 0c5de154..34e5ae59 100644
--- a/pjlib-util/src/pjlib-util-test/encryption.c
+++ b/pjlib-util/src/pjlib-util-test/encryption.c
@@ -383,6 +383,58 @@ static int rfc2202_test(void)
return 0;
}
+/* CRC32 test data, generated from crc32 test on a Linux box */
+struct
+{
+ char *input;
+ pj_uint32_t crc;
+} crc32_test_data[] =
+{
+ {
+ "",
+ 0x0
+ },
+ {
+ "Hello World",
+ 0x4a17b156
+ },
+ {
+ /* Something read from /dev/random */
+ "\x21\x21\x98\x10\x62\x59\xbc\x58\x42\x24\xe5\xf3\x92\x0a\x68\x3c\xa7\x67\x73\xc3",
+ 0x506693be
+ },
+ {
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
+ 0xcab11777
+ },
+ {
+ "123456789",
+ 0xCBF43926
+ }
+};
+
+/*
+ * CRC32 test
+ */
+static int crc32_test(void)
+{
+ unsigned i;
+
+ PJ_LOG(3, (THIS_FILE, " crc32 test.."));
+
+ for (i=0; i<PJ_ARRAY_SIZE(crc32_test_data); ++i) {
+ pj_uint32_t crc;
+
+ crc = pj_crc32_calc((pj_uint8_t*)crc32_test_data[i].input,
+ pj_ansi_strlen(crc32_test_data[i].input));
+ if (crc != crc32_test_data[i].crc) {
+ PJ_LOG(3,(THIS_FILE, " error: crc mismatch on test %d", i));
+ return -80;
+ }
+ }
+ return 0;
+}
+
int encryption_test()
{
@@ -400,6 +452,10 @@ int encryption_test()
if (rc != 0)
return rc;
+ rc = crc32_test();
+ if (rc != 0)
+ return rc;
+
return 0;
}