demo_sm3.c 699 B

123456789101112131415161718192021222324252627282930313233343536
  1. /*
  2. * Copyright 2014-2022 The GmSSL Project. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the License); you may
  5. * not use this file except in compliance with the License.
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. */
  9. #include <stdio.h>
  10. #include <string.h>
  11. #include <stdlib.h>
  12. #include <gmssl/sm3.h>
  13. int main(int argc, char **argv)
  14. {
  15. SM3_CTX sm3_ctx;
  16. uint8_t buf[4096];
  17. size_t len;
  18. uint8_t dgst[32];
  19. int i;
  20. sm3_init(&sm3_ctx);
  21. while ((len = fread(buf, 1, sizeof(buf), stdin)) > 0) {
  22. sm3_update(&sm3_ctx, buf, len);
  23. }
  24. sm3_finish(&sm3_ctx, dgst);
  25. for (i = 0; i < sizeof(dgst); i++) {
  26. printf("%02x", dgst[i]);
  27. }
  28. printf("\n");
  29. return 0;
  30. }