digesttest.c 892 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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/digest.h>
  13. const char *digests[] = {
  14. #ifdef ENABLE_BROKEN_CRYPTO
  15. "md5",
  16. "sha1",
  17. #endif
  18. "sm3",
  19. "sha224",
  20. "sha256",
  21. "sha384",
  22. "sha512",
  23. "sha512-224",
  24. "sha512-256",
  25. };
  26. int main(void)
  27. {
  28. uint8_t dgst[64];
  29. size_t dgstlen;
  30. size_t i, j;
  31. for (i = 0; i < sizeof(digests)/sizeof(digests[0]); i++) {
  32. const DIGEST *algor = digest_from_name(digests[i]);
  33. digest(algor, (uint8_t *)"abc", 3, dgst, &dgstlen);
  34. printf("%s (%zu) ", digests[i], dgstlen);
  35. for (j = 0; j < dgstlen; j++) {
  36. printf("%02x", dgst[j]);
  37. }
  38. printf("\n");
  39. }
  40. return 0;
  41. }