test_suite_xtea.function 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. BEGIN_HEADER
  2. #include <polarssl/xtea.h>
  3. END_HEADER
  4. BEGIN_DEPENDENCIES
  5. depends_on:POLARSSL_XTEA_C
  6. END_DEPENDENCIES
  7. BEGIN_CASE
  8. xtea_encrypt_ecb:hex_key_string:hex_src_string:hex_dst_string
  9. {
  10. unsigned char key_str[100];
  11. unsigned char src_str[100];
  12. unsigned char dst_str[100];
  13. unsigned char output[100];
  14. xtea_context ctx;
  15. memset(key_str, 0x00, 100);
  16. memset(src_str, 0x00, 100);
  17. memset(dst_str, 0x00, 100);
  18. memset(output, 0x00, 100);
  19. unhexify( key_str, {hex_key_string} );
  20. unhexify( src_str, {hex_src_string} );
  21. xtea_setup( &ctx, key_str );
  22. TEST_ASSERT( xtea_crypt_ecb( &ctx, XTEA_ENCRYPT, src_str, output ) == 0 );
  23. hexify( dst_str, output, 8 );
  24. TEST_ASSERT( strcmp( (char *) dst_str, {hex_dst_string} ) == 0 );
  25. }
  26. END_CASE
  27. BEGIN_CASE
  28. xtea_decrypt_ecb:hex_key_string:hex_src_string:hex_dst_string
  29. {
  30. unsigned char key_str[100];
  31. unsigned char src_str[100];
  32. unsigned char dst_str[100];
  33. unsigned char output[100];
  34. xtea_context ctx;
  35. memset(key_str, 0x00, 100);
  36. memset(src_str, 0x00, 100);
  37. memset(dst_str, 0x00, 100);
  38. memset(output, 0x00, 100);
  39. unhexify( key_str, {hex_key_string} );
  40. unhexify( src_str, {hex_src_string} );
  41. xtea_setup( &ctx, key_str );
  42. TEST_ASSERT( xtea_crypt_ecb( &ctx, XTEA_DECRYPT, src_str, output ) == 0 );
  43. hexify( dst_str, output, 8 );
  44. TEST_ASSERT( strcmp( (char *) dst_str, {hex_dst_string} ) == 0 );
  45. }
  46. END_CASE
  47. BEGIN_CASE
  48. xtea_selftest:
  49. {
  50. TEST_ASSERT( xtea_self_test( 0 ) == 0 );
  51. }
  52. END_CASE