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)
50 static void polarssl_zeroize(
void *v,
size_t n ) {
51 volatile unsigned char *p = v;
while( n-- ) *p++ = 0;
81 for( i = 0; i < 256; i++ )
82 m[i] = (
unsigned char) i;
86 for( i = 0; i < 256; i++, k++ )
88 if( k >= keylen ) k = 0;
91 j = ( j + a + key[k] ) & 0xFF;
93 m[j] = (
unsigned char) a;
101 unsigned char *output )
111 for( i = 0; i < length; i++ )
113 x = ( x + 1 ) & 0xFF; a = m[x];
114 y = ( y + a ) & 0xFF; b = m[y];
116 m[x] = (
unsigned char) b;
117 m[y] = (
unsigned char) a;
119 output[i] = (
unsigned char)
120 ( input[i] ^ m[(
unsigned char)( a + b )] );
131 #if defined(POLARSSL_SELF_TEST)
141 static const unsigned char arc4_test_key[3][8] =
143 { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF },
144 { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF },
145 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
148 static const unsigned char arc4_test_pt[3][8] =
150 { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF },
151 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
152 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
155 static const unsigned char arc4_test_ct[3][8] =
157 { 0x75, 0xB7, 0x87, 0x80, 0x99, 0xE0, 0xC5, 0x96 },
158 { 0x74, 0x94, 0xC2, 0xE7, 0x10, 0x4B, 0x08, 0x79 },
159 { 0xDE, 0x18, 0x89, 0x41, 0xA3, 0x37, 0x5D, 0x3A }
168 unsigned char ibuf[8];
169 unsigned char obuf[8];
174 for( i = 0; i < 3; i++ )
179 memcpy( ibuf, arc4_test_pt[i], 8 );
184 if( memcmp( obuf, arc4_test_ct[i], 8 ) != 0 )