diff options
author | Benny Prijono <bennylp@teluu.com> | 2007-10-10 11:37:56 +0000 |
---|---|---|
committer | Benny Prijono <bennylp@teluu.com> | 2007-10-10 11:37:56 +0000 |
commit | a3354959d1493f86392296ab0e78512e633abf40 (patch) | |
tree | 8e73a0994d92c5b97d77cf43165f2bc84d5313a3 /pjlib-util/src/pjlib-util-test | |
parent | 0cb2d5b9e84601bb822a300c48a4ea8397d85850 (diff) |
Ticket #396: initial implementation of digest AKA (akav1-md5) authentication for IMS/3GPP
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@1488 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjlib-util/src/pjlib-util-test')
-rw-r--r-- | pjlib-util/src/pjlib-util-test/encryption.c | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/pjlib-util/src/pjlib-util-test/encryption.c b/pjlib-util/src/pjlib-util-test/encryption.c index 7d91e463..8fc2f828 100644 --- a/pjlib-util/src/pjlib-util-test/encryption.c +++ b/pjlib-util/src/pjlib-util-test/encryption.c @@ -465,10 +465,113 @@ static int crc32_test(void) } +/* + * Base64 test vectors (RFC 4648) + */ +static struct base64_test_vec +{ + const char *base256; + const char *base64; +} base64_test_vec[] = +{ + { + "", + "" + }, + { + "f", + "Zg==" + }, + { + "fo", + "Zm8=" + }, + { + "foo", + "Zm9v" + }, + { + "foob", + "Zm9vYg==" + }, + { + "fooba", + "Zm9vYmE=", + }, + { + "foobar", + "Zm9vYmFy" + }, + { + "\x14\xfb\x9c\x03\xd9\x7e", + "FPucA9l+" + }, + { + "\x14\xfb\x9c\x03\xd9", + "FPucA9k=" + }, + { + "\x14\xfb\x9c\x03", + "FPucAw==" + } +}; + + +static int base64_test(void) +{ + unsigned i; + char output[80]; + pj_status_t rc; + + PJ_LOG(3, (THIS_FILE, " base64 test..")); + + for (i=0; i<PJ_ARRAY_SIZE(base64_test_vec); ++i) { + /* Encode test */ + pj_str_t input; + int out_len = sizeof(output); + + rc = pj_base64_encode(base64_test_vec[i].base256, + strlen(base64_test_vec[i].base256), + output, &out_len); + if (rc != PJ_SUCCESS) + return -90; + + if (out_len != strlen(base64_test_vec[i].base64)) + return -91; + + output[out_len] = '\0'; + if (strcmp(output, base64_test_vec[i].base64) != 0) + return -92; + + /* Decode test */ + out_len = sizeof(output); + input.ptr = base64_test_vec[i].base64; + input.slen = strlen(base64_test_vec[i].base64); + rc = pj_base64_decode(&input, (pj_uint8_t*)output, &out_len); + if (rc != PJ_SUCCESS) + return -95; + + if (out_len != strlen(base64_test_vec[i].base256)) + return -96; + + output[out_len] = '\0'; + + if (strcmp(output, base64_test_vec[i].base256) != 0) + return -97; + } + + return 0; +} + + int encryption_test() { int rc; + rc = base64_test(); + if (rc != 0) + return rc; + rc = sha1_test1(); if (rc != 0) return rc; |