test_suite_mdx.function 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. BEGIN_HEADER
  2. #include <polarssl/md2.h>
  3. #include <polarssl/md4.h>
  4. #include <polarssl/md5.h>
  5. END_HEADER
  6. BEGIN_CASE
  7. md2_text:text_src_string:hex_hash_string
  8. {
  9. unsigned char src_str[1000];
  10. unsigned char hash_str[1000];
  11. unsigned char output[33];
  12. memset(src_str, 0x00, 1000);
  13. memset(hash_str, 0x00, 1000);
  14. memset(output, 0x00, 33);
  15. strcpy( (char *) src_str, {text_src_string} );
  16. md2( src_str, strlen( (char *) src_str ), output );
  17. hexify( hash_str, output, 16 );
  18. TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 );
  19. }
  20. END_CASE
  21. BEGIN_CASE
  22. md4_text:text_src_string:hex_hash_string
  23. {
  24. unsigned char src_str[1000];
  25. unsigned char hash_str[1000];
  26. unsigned char output[33];
  27. memset(src_str, 0x00, 1000);
  28. memset(hash_str, 0x00, 1000);
  29. memset(output, 0x00, 33);
  30. strcpy( (char *) src_str, {text_src_string} );
  31. md4( src_str, strlen( (char *) src_str ), output );
  32. hexify( hash_str, output, 16 );
  33. TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 );
  34. }
  35. END_CASE
  36. BEGIN_CASE
  37. md5_text:text_src_string:hex_hash_string
  38. {
  39. unsigned char src_str[1000];
  40. unsigned char hash_str[1000];
  41. unsigned char output[33];
  42. memset(src_str, 0x00, 1000);
  43. memset(hash_str, 0x00, 1000);
  44. memset(output, 0x00, 33);
  45. strcpy( (char *) src_str, {text_src_string} );
  46. md5( src_str, strlen( (char *) src_str ), output );
  47. hexify( hash_str, output, 16 );
  48. TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 );
  49. }
  50. END_CASE
  51. BEGIN_CASE
  52. md2_hmac:trunc_size:hex_key_string:hex_src_string:hex_hash_string
  53. {
  54. unsigned char src_str[10000];
  55. unsigned char key_str[10000];
  56. unsigned char hash_str[10000];
  57. unsigned char output[33];
  58. int key_len, src_len;
  59. memset(src_str, 0x00, 10000);
  60. memset(key_str, 0x00, 10000);
  61. memset(hash_str, 0x00, 10000);
  62. memset(output, 0x00, 33);
  63. key_len = unhexify( key_str, {hex_key_string} );
  64. src_len = unhexify( src_str, {hex_src_string} );
  65. md2_hmac( key_str, key_len, src_str, src_len, output );
  66. hexify( hash_str, output, 16 );
  67. TEST_ASSERT( strncmp( (char *) hash_str, {hex_hash_string}, {trunc_size} * 2 ) == 0 );
  68. }
  69. END_CASE
  70. BEGIN_CASE
  71. md4_hmac:trunc_size:hex_key_string:hex_src_string:hex_hash_string
  72. {
  73. unsigned char src_str[10000];
  74. unsigned char key_str[10000];
  75. unsigned char hash_str[10000];
  76. unsigned char output[33];
  77. int key_len, src_len;
  78. memset(src_str, 0x00, 10000);
  79. memset(key_str, 0x00, 10000);
  80. memset(hash_str, 0x00, 10000);
  81. memset(output, 0x00, 33);
  82. key_len = unhexify( key_str, {hex_key_string} );
  83. src_len = unhexify( src_str, {hex_src_string} );
  84. md4_hmac( key_str, key_len, src_str, src_len, output );
  85. hexify( hash_str, output, 16 );
  86. TEST_ASSERT( strncmp( (char *) hash_str, {hex_hash_string}, {trunc_size} * 2 ) == 0 );
  87. }
  88. END_CASE
  89. BEGIN_CASE
  90. md5_hmac:trunc_size:hex_key_string:hex_src_string:hex_hash_string
  91. {
  92. unsigned char src_str[10000];
  93. unsigned char key_str[10000];
  94. unsigned char hash_str[10000];
  95. unsigned char output[33];
  96. int key_len, src_len;
  97. memset(src_str, 0x00, 10000);
  98. memset(key_str, 0x00, 10000);
  99. memset(hash_str, 0x00, 10000);
  100. memset(output, 0x00, 33);
  101. key_len = unhexify( key_str, {hex_key_string} );
  102. src_len = unhexify( src_str, {hex_src_string} );
  103. md5_hmac( key_str, key_len, src_str, src_len, output );
  104. hexify( hash_str, output, 16 );
  105. TEST_ASSERT( strncmp( (char *) hash_str, {hex_hash_string}, {trunc_size} * 2 ) == 0 );
  106. }
  107. END_CASE
  108. BEGIN_CASE
  109. md2_file:filename:hex_hash_string
  110. {
  111. unsigned char hash_str[65];
  112. unsigned char output[33];
  113. memset(hash_str, 0x00, 65);
  114. memset(output, 0x00, 33);
  115. md2_file( {filename}, output);
  116. hexify( hash_str, output, 16 );
  117. TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 );
  118. }
  119. END_CASE
  120. BEGIN_CASE
  121. md4_file:filename:hex_hash_string
  122. {
  123. unsigned char hash_str[65];
  124. unsigned char output[33];
  125. memset(hash_str, 0x00, 65);
  126. memset(output, 0x00, 33);
  127. md4_file( {filename}, output);
  128. hexify( hash_str, output, 16 );
  129. TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 );
  130. }
  131. END_CASE
  132. BEGIN_CASE
  133. md5_file:filename:hex_hash_string
  134. {
  135. unsigned char hash_str[65];
  136. unsigned char output[33];
  137. memset(hash_str, 0x00, 65);
  138. memset(output, 0x00, 33);
  139. md5_file( {filename}, output);
  140. hexify( hash_str, output, 16 );
  141. TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 );
  142. }
  143. END_CASE
  144. BEGIN_CASE
  145. md2_selftest:
  146. {
  147. TEST_ASSERT( md2_self_test( 0 ) == 0 );
  148. }
  149. END_CASE
  150. BEGIN_CASE
  151. md4_selftest:
  152. {
  153. TEST_ASSERT( md4_self_test( 0 ) == 0 );
  154. }
  155. END_CASE
  156. BEGIN_CASE
  157. md5_selftest:
  158. {
  159. TEST_ASSERT( md5_self_test( 0 ) == 0 );
  160. }
  161. END_CASE