test_suite_shax.function 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. BEGIN_HEADER
  2. #include <polarssl/sha1.h>
  3. #include <polarssl/sha2.h>
  4. #include <polarssl/sha4.h>
  5. END_HEADER
  6. BEGIN_CASE
  7. sha1:hex_src_string:hex_hash_string
  8. {
  9. unsigned char src_str[10000];
  10. unsigned char hash_str[10000];
  11. unsigned char output[41];
  12. int src_len;
  13. memset(src_str, 0x00, 10000);
  14. memset(hash_str, 0x00, 10000);
  15. memset(output, 0x00, 41);
  16. src_len = unhexify( src_str, {hex_src_string} );
  17. sha1( src_str, src_len, output );
  18. hexify( hash_str, output, 20 );
  19. TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 );
  20. }
  21. END_CASE
  22. BEGIN_CASE
  23. sha224:hex_src_string:hex_hash_string
  24. {
  25. unsigned char src_str[10000];
  26. unsigned char hash_str[10000];
  27. unsigned char output[57];
  28. int src_len;
  29. memset(src_str, 0x00, 10000);
  30. memset(hash_str, 0x00, 10000);
  31. memset(output, 0x00, 57);
  32. src_len = unhexify( src_str, {hex_src_string} );
  33. sha2( src_str, src_len, output, 1 );
  34. hexify( hash_str, output, 28 );
  35. TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 );
  36. }
  37. END_CASE
  38. BEGIN_CASE
  39. sha256:hex_src_string:hex_hash_string
  40. {
  41. unsigned char src_str[10000];
  42. unsigned char hash_str[10000];
  43. unsigned char output[65];
  44. int src_len;
  45. memset(src_str, 0x00, 10000);
  46. memset(hash_str, 0x00, 10000);
  47. memset(output, 0x00, 65);
  48. src_len = unhexify( src_str, {hex_src_string} );
  49. sha2( src_str, src_len, output, 0 );
  50. hexify( hash_str, output, 32 );
  51. TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 );
  52. }
  53. END_CASE
  54. BEGIN_CASE
  55. sha384:hex_src_string:hex_hash_string
  56. {
  57. unsigned char src_str[10000];
  58. unsigned char hash_str[10000];
  59. unsigned char output[97];
  60. int src_len;
  61. memset(src_str, 0x00, 10000);
  62. memset(hash_str, 0x00, 10000);
  63. memset(output, 0x00, 97);
  64. src_len = unhexify( src_str, {hex_src_string} );
  65. sha4( src_str, src_len, output, 1 );
  66. hexify( hash_str, output, 48 );
  67. TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 );
  68. }
  69. END_CASE
  70. BEGIN_CASE
  71. sha512:hex_src_string:hex_hash_string
  72. {
  73. unsigned char src_str[10000];
  74. unsigned char hash_str[10000];
  75. unsigned char output[129];
  76. int src_len;
  77. memset(src_str, 0x00, 10000);
  78. memset(hash_str, 0x00, 10000);
  79. memset(output, 0x00, 129);
  80. src_len = unhexify( src_str, {hex_src_string} );
  81. sha4( src_str, src_len, output, 0);
  82. hexify( hash_str, output, 64 );
  83. TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 );
  84. }
  85. END_CASE
  86. BEGIN_CASE
  87. sha1_file:filename:hex_hash_string
  88. {
  89. unsigned char hash_str[41];
  90. unsigned char output[21];
  91. memset(hash_str, 0x00, 41);
  92. memset(output, 0x00, 21);
  93. sha1_file( {filename}, output);
  94. hexify( hash_str, output, 20 );
  95. TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 );
  96. }
  97. END_CASE
  98. BEGIN_CASE
  99. sha224_file:filename:hex_hash_string
  100. {
  101. unsigned char hash_str[57];
  102. unsigned char output[29];
  103. memset(hash_str, 0x00, 57);
  104. memset(output, 0x00, 29);
  105. sha2_file( {filename}, output, 1);
  106. hexify( hash_str, output, 28 );
  107. TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 );
  108. }
  109. END_CASE
  110. BEGIN_CASE
  111. sha256_file:filename:hex_hash_string
  112. {
  113. unsigned char hash_str[65];
  114. unsigned char output[33];
  115. memset(hash_str, 0x00, 65);
  116. memset(output, 0x00, 33);
  117. sha2_file( {filename}, output, 0);
  118. hexify( hash_str, output, 32 );
  119. TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 );
  120. }
  121. END_CASE
  122. BEGIN_CASE
  123. sha384_file:filename:hex_hash_string
  124. {
  125. unsigned char hash_str[97];
  126. unsigned char output[49];
  127. memset(hash_str, 0x00, 97);
  128. memset(output, 0x00, 49);
  129. sha4_file( {filename}, output, 1);
  130. hexify( hash_str, output, 48 );
  131. TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 );
  132. }
  133. END_CASE
  134. BEGIN_CASE
  135. sha512_file:filename:hex_hash_string
  136. {
  137. unsigned char hash_str[129];
  138. unsigned char output[65];
  139. memset(hash_str, 0x00, 129);
  140. memset(output, 0x00, 65);
  141. sha4_file( {filename}, output, 0);
  142. hexify( hash_str, output, 64 );
  143. TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 );
  144. }
  145. END_CASE
  146. BEGIN_CASE
  147. sha1_selftest:
  148. {
  149. TEST_ASSERT( sha1_self_test( 0 ) == 0 );
  150. }
  151. END_CASE
  152. BEGIN_CASE
  153. sha2_selftest:
  154. {
  155. TEST_ASSERT( sha2_self_test( 0 ) == 0 );
  156. }
  157. END_CASE
  158. BEGIN_CASE
  159. sha4_selftest:
  160. {
  161. TEST_ASSERT( sha4_self_test( 0 ) == 0 );
  162. }
  163. END_CASE