blob: 6bc5d1f45ee0e156cc1bfefedd37591d3ff4bb95 [file] [log] [blame]
Paul Bakker33b43f12013-08-20 11:48:36 +02001/* BEGIN_HEADER */
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +00002#include "mbedtls/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 Bakker8cfd9d82014-06-18 11:16:11 +020025 arc4_init( &ctx );
Paul Bakker367dae42009-06-28 21:50:27 +000026
Paul Bakker33b43f12013-08-20 11:48:36 +020027 src_len = unhexify( src_str, hex_src_string );
28 key_len = unhexify( key_str, hex_key_string );
Paul Bakker367dae42009-06-28 21:50:27 +000029
Paul Bakker367dae42009-06-28 21:50:27 +000030 arc4_setup(&ctx, key_str, key_len);
Paul Bakkerbaad6502010-03-21 15:42:15 +000031 TEST_ASSERT( arc4_crypt(&ctx, src_len, src_str, dst_str ) == 0 );
32 hexify( dst_hexstr, dst_str, src_len );
Paul Bakker367dae42009-06-28 21:50:27 +000033
Paul Bakker33b43f12013-08-20 11:48:36 +020034 TEST_ASSERT( strcmp( (char *) dst_hexstr, hex_dst_string ) == 0 );
Paul Bakker8cfd9d82014-06-18 11:16:11 +020035
Paul Bakkerbd51b262014-07-10 15:26:12 +020036exit:
Paul Bakker8cfd9d82014-06-18 11:16:11 +020037 arc4_free( &ctx );
Paul Bakker367dae42009-06-28 21:50:27 +000038}
Paul Bakker33b43f12013-08-20 11:48:36 +020039/* END_CASE */
Paul Bakker3d360822009-07-05 11:29:38 +000040
Manuel Pégourié-Gonnard20140162013-10-10 12:48:03 +020041/* BEGIN_CASE depends_on:POLARSSL_SELF_TEST */
Paul Bakker33b43f12013-08-20 11:48:36 +020042void arc4_selftest()
Paul Bakker3d360822009-07-05 11:29:38 +000043{
44 TEST_ASSERT( arc4_self_test( 0 ) == 0 );
45}
Paul Bakker33b43f12013-08-20 11:48:36 +020046/* END_CASE */