sm2.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #include <contrib/libs/openssl/redef.h>
  2. /*
  3. * Copyright 2017-2021 The OpenSSL Project Authors. All Rights Reserved.
  4. * Copyright 2017 Ribose Inc. All Rights Reserved.
  5. * Ported from Ribose contributions from Botan.
  6. *
  7. * Licensed under the OpenSSL license (the "License"). You may not use
  8. * this file except in compliance with the License. You can obtain a copy
  9. * in the file LICENSE in the source distribution or at
  10. * https://www.openssl.org/source/license.html
  11. */
  12. #ifndef OSSL_CRYPTO_SM2_H
  13. # define OSSL_CRYPTO_SM2_H
  14. # include <openssl/opensslconf.h>
  15. # ifndef OPENSSL_NO_SM2
  16. # include <openssl/ec.h>
  17. /* The default user id as specified in GM/T 0009-2012 */
  18. # define SM2_DEFAULT_USERID "1234567812345678"
  19. int sm2_compute_z_digest(uint8_t *out,
  20. const EVP_MD *digest,
  21. const uint8_t *id,
  22. const size_t id_len,
  23. const EC_KEY *key);
  24. /*
  25. * SM2 signature operation. Computes Z and then signs H(Z || msg) using SM2
  26. */
  27. ECDSA_SIG *sm2_do_sign(const EC_KEY *key,
  28. const EVP_MD *digest,
  29. const uint8_t *id,
  30. const size_t id_len,
  31. const uint8_t *msg, size_t msg_len);
  32. int sm2_do_verify(const EC_KEY *key,
  33. const EVP_MD *digest,
  34. const ECDSA_SIG *signature,
  35. const uint8_t *id,
  36. const size_t id_len,
  37. const uint8_t *msg, size_t msg_len);
  38. /*
  39. * SM2 signature generation.
  40. */
  41. int sm2_sign(const unsigned char *dgst, int dgstlen,
  42. unsigned char *sig, unsigned int *siglen, EC_KEY *eckey);
  43. /*
  44. * SM2 signature verification.
  45. */
  46. int sm2_verify(const unsigned char *dgst, int dgstlen,
  47. const unsigned char *sig, int siglen, EC_KEY *eckey);
  48. /*
  49. * SM2 encryption
  50. */
  51. int sm2_ciphertext_size(const EC_KEY *key, const EVP_MD *digest, size_t msg_len,
  52. size_t *ct_size);
  53. int sm2_plaintext_size(const unsigned char *ct, size_t ct_size, size_t *pt_size);
  54. int sm2_encrypt(const EC_KEY *key,
  55. const EVP_MD *digest,
  56. const uint8_t *msg,
  57. size_t msg_len,
  58. uint8_t *ciphertext_buf, size_t *ciphertext_len);
  59. int sm2_decrypt(const EC_KEY *key,
  60. const EVP_MD *digest,
  61. const uint8_t *ciphertext,
  62. size_t ciphertext_len, uint8_t *ptext_buf, size_t *ptext_len);
  63. # endif /* OPENSSL_NO_SM2 */
  64. #endif