test_suite_mdx.function 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* BEGIN_HEADER */
  2. #include "mbedtls/md5.h"
  3. #include "mbedtls/ripemd160.h"
  4. /* END_HEADER */
  5. /* BEGIN_CASE depends_on:MBEDTLS_MD5_C */
  6. void md5_text(char *text_src_string, data_t *hash)
  7. {
  8. int ret;
  9. unsigned char src_str[100];
  10. unsigned char output[16];
  11. memset(src_str, 0x00, sizeof(src_str));
  12. memset(output, 0x00, sizeof(output));
  13. strncpy((char *) src_str, text_src_string, sizeof(src_str) - 1);
  14. ret = mbedtls_md5(src_str, strlen((char *) src_str), output);
  15. TEST_ASSERT(ret == 0);
  16. TEST_ASSERT(mbedtls_test_hexcmp(output, hash->x,
  17. sizeof(output), hash->len) == 0);
  18. }
  19. /* END_CASE */
  20. /* BEGIN_CASE depends_on:MBEDTLS_RIPEMD160_C */
  21. void ripemd160_text(char *text_src_string, data_t *hash)
  22. {
  23. int ret;
  24. unsigned char src_str[100];
  25. unsigned char output[20];
  26. memset(src_str, 0x00, sizeof(src_str));
  27. memset(output, 0x00, sizeof(output));
  28. strncpy((char *) src_str, text_src_string, sizeof(src_str) - 1);
  29. ret = mbedtls_ripemd160(src_str, strlen((char *) src_str), output);
  30. TEST_ASSERT(ret == 0);
  31. TEST_ASSERT(mbedtls_test_hexcmp(output, hash->x,
  32. sizeof(output), hash->len) == 0);
  33. }
  34. /* END_CASE */
  35. /* BEGIN_CASE depends_on:MBEDTLS_MD5_C:MBEDTLS_SELF_TEST */
  36. void md5_selftest()
  37. {
  38. TEST_ASSERT(mbedtls_md5_self_test(1) == 0);
  39. }
  40. /* END_CASE */
  41. /* BEGIN_CASE depends_on:MBEDTLS_RIPEMD160_C:MBEDTLS_SELF_TEST */
  42. void ripemd160_selftest()
  43. {
  44. TEST_ASSERT(mbedtls_ripemd160_self_test(1) == 0);
  45. }
  46. /* END_CASE */