blob: 302b2e5f91849f529d4b294c4ebfda7edf9fcee9 [file] [log] [blame]
Paul Bakker33b43f12013-08-20 11:48:36 +02001/* BEGIN_HEADER */
Paul Bakker367dae42009-06-28 21:50:27 +00002#include <polarssl/arc4.h>
Paul Bakker33b43f12013-08-20 11:48:36 +02003/* END_HEADER */
Paul Bakker367dae42009-06-28 21:50:27 +00004
Paul Bakker33b43f12013-08-20 11:48:36 +02005/* BEGIN_DEPENDENCIES
6 * depends_on:POLARSSL_ARC4_C
7 * END_DEPENDENCIES
8 */
Paul Bakker5690efc2011-05-26 13:16:06 +00009
Paul Bakker33b43f12013-08-20 11:48:36 +020010/* BEGIN_CASE */
11void arc4_crypt( char *hex_src_string, char *hex_key_string,
12 char *hex_dst_string )
Paul Bakker367dae42009-06-28 21:50:27 +000013{
14 unsigned char src_str[1000];
15 unsigned char key_str[1000];
Paul Bakkerbaad6502010-03-21 15:42:15 +000016 unsigned char dst_str[1000];
17 unsigned char dst_hexstr[2000];
Paul Bakker69998dd2009-07-11 19:15:20 +000018 int src_len, key_len;
19 arc4_context ctx;
Paul Bakker367dae42009-06-28 21:50:27 +000020
21 memset(src_str, 0x00, 1000);
22 memset(key_str, 0x00, 1000);
Paul Bakkerbaad6502010-03-21 15:42:15 +000023 memset(dst_str, 0x00, 1000);
24 memset(dst_hexstr, 0x00, 2000);
Paul Bakker367dae42009-06-28 21:50:27 +000025
Paul Bakker33b43f12013-08-20 11:48:36 +020026 src_len = unhexify( src_str, hex_src_string );
27 key_len = unhexify( key_str, hex_key_string );
Paul Bakker367dae42009-06-28 21:50:27 +000028
Paul Bakker367dae42009-06-28 21:50:27 +000029 arc4_setup(&ctx, key_str, key_len);
Paul Bakkerbaad6502010-03-21 15:42:15 +000030 TEST_ASSERT( arc4_crypt(&ctx, src_len, src_str, dst_str ) == 0 );
31 hexify( dst_hexstr, dst_str, src_len );
Paul Bakker367dae42009-06-28 21:50:27 +000032
Paul Bakker33b43f12013-08-20 11:48:36 +020033 TEST_ASSERT( strcmp( (char *) dst_hexstr, hex_dst_string ) == 0 );
Paul Bakker367dae42009-06-28 21:50:27 +000034}
Paul Bakker33b43f12013-08-20 11:48:36 +020035/* END_CASE */
Paul Bakker3d360822009-07-05 11:29:38 +000036
Paul Bakker33b43f12013-08-20 11:48:36 +020037/* BEGIN_CASE */
38void arc4_selftest()
Paul Bakker3d360822009-07-05 11:29:38 +000039{
40 TEST_ASSERT( arc4_self_test( 0 ) == 0 );
41}
Paul Bakker33b43f12013-08-20 11:48:36 +020042/* END_CASE */