m_sm3.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright 2017 The OpenSSL Project Authors. All Rights Reserved.
  3. * Copyright 2017 Ribose Inc. All Rights Reserved.
  4. *
  5. * Licensed under the Apache License 2.0 (the "License"). You may not use
  6. * this file except in compliance with the License. You can obtain a copy
  7. * in the file LICENSE in the source distribution or at
  8. * https://www.openssl.org/source/license.html
  9. */
  10. #include "internal/cryptlib.h"
  11. #ifndef OPENSSL_NO_SM3
  12. # include <openssl/evp.h>
  13. # include "internal/sm3.h"
  14. # include "internal/evp_int.h"
  15. static int init(EVP_MD_CTX *ctx)
  16. {
  17. return sm3_init(EVP_MD_CTX_md_data(ctx));
  18. }
  19. static int update(EVP_MD_CTX *ctx, const void *data, size_t count)
  20. {
  21. return sm3_update(EVP_MD_CTX_md_data(ctx), data, count);
  22. }
  23. static int final(EVP_MD_CTX *ctx, unsigned char *md)
  24. {
  25. return sm3_final(md, EVP_MD_CTX_md_data(ctx));
  26. }
  27. static const EVP_MD sm3_md = {
  28. NID_sm3,
  29. NID_sm3WithRSAEncryption,
  30. SM3_DIGEST_LENGTH,
  31. 0,
  32. init,
  33. update,
  34. final,
  35. NULL,
  36. NULL,
  37. SM3_CBLOCK,
  38. sizeof(EVP_MD *) + sizeof(SM3_CTX),
  39. };
  40. const EVP_MD *EVP_sm3(void)
  41. {
  42. return &sm3_md;
  43. }
  44. #endif