2
0

sm2.h 2.4 KB

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