add CHD support.
[pcsx_rearmed.git] / deps / crypto / arcfour_test.c
1 /*********************************************************************
2 * Filename:   arcfour_test.c
3 * Author:     Brad Conte (brad AT bradconte.com)
4 * Copyright:
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 *********************************************************************/
13
14 /*************************** HEADER FILES ***************************/
15 #include <stdio.h>
16 #include <memory.h>
17 #include "arcfour.h"
18
19 /*********************** FUNCTION DEFINITIONS ***********************/
20 int rc4_test()
21 {
22         BYTE state[256];
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};
28         BYTE buf[1024];
29         int idx;
30         int pass = 1;
31
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]);
37         }
38
39         return(pass);
40 }
41
42 int main()
43 {
44         printf("ARCFOUR tests: %s\n", rc4_test() ? "SUCCEEDED" : "FAILED");
45
46         return(0);
47 }