1 /*********************************************************************
2 * Filename: blowfish_test.c
3 * Author: Brad Conte (brad AT bradconte.com)
5 * Disclaimer: This code is presented "as is" without any guarantees.
6 * Details: Performs known-answer tests on the corresponding Base64
7 implementation. These tests do not encompass the full
8 range of available test vectors, however, if the tests
9 pass it is very, very likely that the code is correct
10 and was compiled properly. This code also serves as
11 example usage of the functions.
12 *********************************************************************/
14 /*************************** HEADER FILES ***************************/
19 /*********************** FUNCTION DEFINITIONS ***********************/
22 BYTE text[3][1024] = {{"fo"},
24 {"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."}};
25 BYTE code[3][1024] = {{"Zm8="},
27 {"TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz\nIHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2Yg\ndGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGlu\ndWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRo\nZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4="}};
33 for (idx = 0; idx < 3; idx++) {
34 buf_len = base64_encode(text[idx], buf, strlen(text[idx]), 1);
35 pass = pass && ((buf_len == strlen(code[idx])) &&
36 (buf_len == base64_encode(text[idx], NULL, strlen(text[idx]), 1)));
37 pass = pass && !strcmp(code[idx], buf);
39 memset(buf, 0, sizeof(buf));
40 buf_len = base64_decode(code[idx], buf, strlen(code[idx]));
41 pass = pass && ((buf_len == strlen(text[idx])) &&
42 (buf_len == base64_decode(code[idx], NULL, strlen(code[idx]))));
43 pass = pass && !strcmp(text[idx], buf);
51 printf("Base64 tests: %s\n", base64_test() ? "PASSED" : "FAILED");