sm3test.c 802 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #include <string.h>
  2. #include <stdio.h>
  3. #include "sm3.h"
  4. int main( int argc, char *argv[] )
  5. {
  6. unsigned char *input = "abc";
  7. int ilen = 3;
  8. unsigned char output[32];
  9. int i;
  10. sm3_context ctx;
  11. printf("Message:\n");
  12. printf("%s\n",input);
  13. sm3(input, ilen, output);
  14. printf("Hash:\n ");
  15. for(i=0; i<32; i++)
  16. {
  17. printf("%02x",output[i]);
  18. if (((i+1) % 4 ) == 0) printf(" ");
  19. }
  20. printf("\n");
  21. printf("Message:\n");
  22. for(i=0; i < 16; i++)
  23. printf("abcd");
  24. printf("\n");
  25. sm3_starts( &ctx );
  26. for(i=0; i < 16; i++)
  27. sm3_update( &ctx, "abcd", 4 );
  28. sm3_finish( &ctx, output );
  29. memset( &ctx, 0, sizeof( sm3_context ) );
  30. printf("Hash:\n ");
  31. for(i=0; i<32; i++)
  32. {
  33. printf("%02x",output[i]);
  34. if (((i+1) % 4 ) == 0) printf(" ");
  35. }
  36. printf("\n");
  37. //getch(); //VS2008
  38. }