test_suite_arc4.function 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /* BEGIN_HEADER */
  2. #include "mbedtls/arc4.h"
  3. /* END_HEADER */
  4. /* BEGIN_DEPENDENCIES
  5. * depends_on:MBEDTLS_ARC4_C
  6. * END_DEPENDENCIES
  7. */
  8. /* BEGIN_CASE */
  9. void mbedtls_arc4_crypt( char *hex_src_string, char *hex_key_string,
  10. char *hex_dst_string )
  11. {
  12. unsigned char src_str[1000];
  13. unsigned char key_str[1000];
  14. unsigned char dst_str[1000];
  15. unsigned char dst_hexstr[2000];
  16. int src_len, key_len;
  17. mbedtls_arc4_context ctx;
  18. memset(src_str, 0x00, 1000);
  19. memset(key_str, 0x00, 1000);
  20. memset(dst_str, 0x00, 1000);
  21. memset(dst_hexstr, 0x00, 2000);
  22. mbedtls_arc4_init( &ctx );
  23. src_len = unhexify( src_str, hex_src_string );
  24. key_len = unhexify( key_str, hex_key_string );
  25. mbedtls_arc4_setup(&ctx, key_str, key_len);
  26. TEST_ASSERT( mbedtls_arc4_crypt(&ctx, src_len, src_str, dst_str ) == 0 );
  27. hexify( dst_hexstr, dst_str, src_len );
  28. TEST_ASSERT( strcmp( (char *) dst_hexstr, hex_dst_string ) == 0 );
  29. exit:
  30. mbedtls_arc4_free( &ctx );
  31. }
  32. /* END_CASE */
  33. /* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
  34. void arc4_selftest()
  35. {
  36. TEST_ASSERT( mbedtls_arc4_self_test( 1 ) == 0 );
  37. }
  38. /* END_CASE */