31 #if !defined(POLARSSL_CONFIG_FILE)
34 #include POLARSSL_CONFIG_FILE
37 #if defined(POLARSSL_ARC4_C)
41 #if defined(POLARSSL_PLATFORM_C)
44 #define polarssl_printf printf
47 #if !defined(POLARSSL_ARC4_ALT)
63 for( i = 0; i < 256; i++ )
64 m[i] = (
unsigned char) i;
68 for( i = 0; i < 256; i++, k++ )
70 if( k >= keylen ) k = 0;
73 j = ( j + a + key[k] ) & 0xFF;
75 m[j] = (
unsigned char) a;
83 unsigned char *output )
93 for( i = 0; i < length; i++ )
95 x = ( x + 1 ) & 0xFF; a = m[x];
96 y = ( y + a ) & 0xFF; b = m[y];
98 m[x] = (
unsigned char) b;
99 m[y] = (
unsigned char) a;
101 output[i] = (
unsigned char)
102 ( input[i] ^ m[(
unsigned char)( a + b )] );
113 #if defined(POLARSSL_SELF_TEST)
123 static const unsigned char arc4_test_key[3][8] =
125 { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF },
126 { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF },
127 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
130 static const unsigned char arc4_test_pt[3][8] =
132 { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF },
133 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
134 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
137 static const unsigned char arc4_test_ct[3][8] =
139 { 0x75, 0xB7, 0x87, 0x80, 0x99, 0xE0, 0xC5, 0x96 },
140 { 0x74, 0x94, 0xC2, 0xE7, 0x10, 0x4B, 0x08, 0x79 },
141 { 0xDE, 0x18, 0x89, 0x41, 0xA3, 0x37, 0x5D, 0x3A }
150 unsigned char ibuf[8];
151 unsigned char obuf[8];
154 for( i = 0; i < 3; i++ )
159 memcpy( ibuf, arc4_test_pt[i], 8 );
164 if( memcmp( obuf, arc4_test_ct[i], 8 ) != 0 )
int arc4_crypt(arc4_context *ctx, size_t length, const unsigned char *input, unsigned char *output)
ARC4 cipher function.
void arc4_setup(arc4_context *ctx, const unsigned char *key, unsigned int keylen)
ARC4 key schedule.
int arc4_self_test(int verbose)
Checkup routine.
Configuration options (set of defines)
The ARCFOUR stream cipher.