test_suite_xtea.function 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /* BEGIN_HEADER */
  2. #include "mbedtls/xtea.h"
  3. /* END_HEADER */
  4. /* BEGIN_DEPENDENCIES
  5. * depends_on:MBEDTLS_XTEA_C
  6. * END_DEPENDENCIES
  7. */
  8. /* BEGIN_CASE */
  9. void xtea_encrypt_ecb( data_t * key_str, data_t * src_str,
  10. data_t * dst )
  11. {
  12. unsigned char output[100];
  13. mbedtls_xtea_context ctx;
  14. memset(output, 0x00, 100);
  15. mbedtls_xtea_setup( &ctx, key_str->x );
  16. TEST_ASSERT( mbedtls_xtea_crypt_ecb( &ctx, MBEDTLS_XTEA_ENCRYPT, src_str->x, output ) == 0 );
  17. TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, 8, dst->len ) == 0 );
  18. }
  19. /* END_CASE */
  20. /* BEGIN_CASE */
  21. void xtea_decrypt_ecb( data_t * key_str, data_t * src_str, data_t * dst )
  22. {
  23. unsigned char output[100];
  24. mbedtls_xtea_context ctx;
  25. memset(output, 0x00, 100);
  26. mbedtls_xtea_setup( &ctx, key_str->x );
  27. TEST_ASSERT( mbedtls_xtea_crypt_ecb( &ctx, MBEDTLS_XTEA_DECRYPT, src_str->x, output ) == 0 );
  28. TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, 8, dst->len ) == 0 );
  29. }
  30. /* END_CASE */
  31. /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
  32. void xtea_encrypt_cbc( data_t * key_str, data_t * iv_str,
  33. data_t * src_str, data_t * dst )
  34. {
  35. unsigned char output[100];
  36. mbedtls_xtea_context ctx;
  37. memset(output, 0x00, 100);
  38. mbedtls_xtea_setup( &ctx, key_str->x );
  39. TEST_ASSERT( mbedtls_xtea_crypt_cbc( &ctx, MBEDTLS_XTEA_ENCRYPT, src_str->len, iv_str->x,
  40. src_str->x, output ) == 0 );
  41. TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x,
  42. src_str->len, dst->len ) == 0 );
  43. }
  44. /* END_CASE */
  45. /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
  46. void xtea_decrypt_cbc( data_t * key_str, data_t * iv_str,
  47. data_t * src_str, data_t * dst )
  48. {
  49. unsigned char output[100];
  50. mbedtls_xtea_context ctx;
  51. memset(output, 0x00, 100);
  52. mbedtls_xtea_setup( &ctx, key_str->x );
  53. TEST_ASSERT( mbedtls_xtea_crypt_cbc( &ctx, MBEDTLS_XTEA_DECRYPT, src_str->len, iv_str->x,
  54. src_str->x, output ) == 0 );
  55. TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x,
  56. src_str->len, dst->len ) == 0 );
  57. }
  58. /* END_CASE */
  59. /* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
  60. void xtea_selftest( )
  61. {
  62. TEST_ASSERT( mbedtls_xtea_self_test( 1 ) == 0 );
  63. }
  64. /* END_CASE */