]> pd.if.org Git - zpackage/blob - libtomcrypt/src/stream/rc4/rc4_test.c
a7e48879cc96902be79b337bffd94dc1da1b45d3
[zpackage] / libtomcrypt / src / stream / rc4 / rc4_test.c
1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
2  *
3  * LibTomCrypt is a library that provides various cryptographic
4  * algorithms in a highly modular and flexible manner.
5  *
6  * The library is free for all purposes without any express
7  * guarantee it works.
8  */
9
10 #include "tomcrypt.h"
11
12 #ifdef LTC_RC4_STREAM
13
14 int rc4_stream_test(void)
15 {
16 #ifndef LTC_TEST
17    return CRYPT_NOP;
18 #else
19    rc4_state st;
20    int err;
21    const unsigned char key[] = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef };
22    const unsigned char pt[]  = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef };
23    const unsigned char ct[]  = { 0x75, 0xb7, 0x87, 0x80, 0x99, 0xe0, 0xc5, 0x96 };
24    unsigned char buf[10];
25
26    if ((err = rc4_stream_setup(&st, key, sizeof(key))) != CRYPT_OK)    return err;
27    if ((err = rc4_stream_crypt(&st, pt, sizeof(pt), buf)) != CRYPT_OK) return err;
28    if (compare_testvector(buf, sizeof(ct), ct, sizeof(ct), "RC4", 0))  return CRYPT_FAIL_TESTVECTOR;
29    if ((err = rc4_stream_done(&st)) != CRYPT_OK)                       return err;
30
31    return CRYPT_OK;
32 #endif
33 }
34
35 #endif
36
37 /* ref:         $Format:%D$ */
38 /* git commit:  $Format:%H$ */
39 /* commit time: $Format:%ai$ */