aboutsummaryrefslogtreecommitdiff
path: root/lib/crypto-algorithms/base64_test.c
diff options
context:
space:
mode:
authorMark Haines <mjark@negativecurvature.net>2015-02-26 16:43:06 +0000
committerMark Haines <mjark@negativecurvature.net>2015-02-26 16:43:06 +0000
commit15bb93321fdf9c5ec2c75e03f9a1bb5fdf8b7e10 (patch)
treed754f9776a62095d5adfb257134f7bcff54c1157 /lib/crypto-algorithms/base64_test.c
parent6c56bcf2fd3db38c679b9cf9345051a7309fa02f (diff)
parentc61e5359cb454ae20c0b7b057c3a7b53e2beefd6 (diff)
Merge commit 'c61e5359cb454ae20c0b7b057c3a7b53e2beefd6' as 'lib/crypto-algorithms'
Diffstat (limited to 'lib/crypto-algorithms/base64_test.c')
-rw-r--r--lib/crypto-algorithms/base64_test.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/lib/crypto-algorithms/base64_test.c b/lib/crypto-algorithms/base64_test.c
new file mode 100644
index 0000000..c59cc98
--- /dev/null
+++ b/lib/crypto-algorithms/base64_test.c
@@ -0,0 +1,54 @@
+/*********************************************************************
+* Filename: blowfish_test.c
+* Author: Brad Conte (brad AT bradconte.com)
+* Copyright:
+* Disclaimer: This code is presented "as is" without any guarantees.
+* Details: Performs known-answer tests on the corresponding Base64
+ implementation. These tests do not encompass the full
+ range of available test vectors, however, if the tests
+ pass it is very, very likely that the code is correct
+ and was compiled properly. This code also serves as
+ example usage of the functions.
+*********************************************************************/
+
+/*************************** HEADER FILES ***************************/
+#include <stdio.h>
+#include <memory.h>
+#include "base64.h"
+
+/*********************** FUNCTION DEFINITIONS ***********************/
+int base64_test()
+{
+ BYTE text[3][1024] = {{"fo"},
+ {"foobar"},
+ {"Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure."}};
+ BYTE code[3][1024] = {{"Zm8="},
+ {"Zm9vYmFy"},
+ {"TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz\nIHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2Yg\ndGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGlu\ndWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRo\nZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4="}};
+ BYTE buf[1024];
+ size_t buf_len;
+ int pass = 1;
+ int idx;
+
+ for (idx = 0; idx < 3; idx++) {
+ buf_len = base64_encode(text[idx], buf, strlen(text[idx]), 1);
+ pass = pass && ((buf_len == strlen(code[idx])) &&
+ (buf_len == base64_encode(text[idx], NULL, strlen(text[idx]), 1)));
+ pass = pass && !strcmp(code[idx], buf);
+
+ memset(buf, 0, sizeof(buf));
+ buf_len = base64_decode(code[idx], buf, strlen(code[idx]));
+ pass = pass && ((buf_len == strlen(text[idx])) &&
+ (buf_len == base64_decode(code[idx], NULL, strlen(code[idx]))));
+ pass = pass && !strcmp(text[idx], buf);
+ }
+
+ return(pass);
+}
+
+int main()
+{
+ printf("Base64 tests: %s\n", base64_test() ? "PASSED" : "FAILED");
+
+ return 0;
+}