1 /*********************************************************************
2 * Filename: arcfour_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 ARCFOUR
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 ***********************/
23 BYTE key[3][10] = {{"Key"}, {"Wiki"}, {"Secret"}};
24 BYTE stream[3][10] = {{0xEB,0x9F,0x77,0x81,0xB7,0x34,0xCA,0x72,0xA7,0x19},
25 {0x60,0x44,0xdb,0x6d,0x41,0xb7},
26 {0x04,0xd4,0x6b,0x05,0x3c,0xa8,0x7b,0x59}};
27 int stream_len[3] = {10,6,8};
32 // Only test the output stream. Note that the state can be reused.
33 for (idx = 0; idx < 3; idx++) {
34 arcfour_key_setup(state, key[idx], strlen(key[idx]));
35 arcfour_generate_stream(state, buf, stream_len[idx]);
36 pass = pass && !memcmp(stream[idx], buf, stream_len[idx]);
44 printf("ARCFOUR tests: %s\n", rc4_test() ? "SUCCEEDED" : "FAILED");