ecdsa_sm2.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /**
  2. * \file ecdsa_sm2.h
  3. *
  4. * \brief This file contains ECDSA definitions and functions.
  5. *
  6. * The Elliptic Curve Digital Signature Algorithm (ECDSA) is defined in
  7. * <em>Standards for Efficient Cryptography Group (SECG):
  8. * SEC1 Elliptic Curve Cryptography</em>.
  9. * The use of ECDSA for TLS is defined in <em>RFC-4492: Elliptic Curve
  10. * Cryptography (ECC) Cipher Suites for Transport Layer Security (TLS)</em>.
  11. *
  12. */
  13. /*
  14. * Copyright The Mbed TLS Contributors
  15. * SPDX-License-Identifier: Apache-2.0
  16. *
  17. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  18. * not use this file except in compliance with the License.
  19. * You may obtain a copy of the License at
  20. *
  21. * http://www.apache.org/licenses/LICENSE-2.0
  22. *
  23. * Unless required by applicable law or agreed to in writing, software
  24. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  25. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  26. * See the License for the specific language governing permissions and
  27. * limitations under the License.
  28. */
  29. #ifndef MBEDTLS_ECDSA_SM2_H
  30. #define MBEDTLS_ECDSA_SM2_H
  31. #if !defined(MBEDTLS_CONFIG_FILE)
  32. #include "mbedtls/config.h"
  33. #else
  34. #include MBEDTLS_CONFIG_FILE
  35. #endif
  36. #include "mbedtls/ecp.h"
  37. #include "mbedtls/md.h"
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. /*
  42. * Set a group using well-known domain parameters
  43. */
  44. int sm2_param_load( mbedtls_ecp_group *grp );
  45. /**
  46. * Compute ECDSA-SM2 signature of a hashed message
  47. */
  48. int mbedtls_ecdsa_sm2_sign(mbedtls_ecp_group *grp, mbedtls_mpi *r, mbedtls_mpi *s,
  49. const mbedtls_mpi *d, const unsigned char *buf, size_t blen,
  50. int(*f_rng)(void *, unsigned char *, size_t), void *p_rng);
  51. /*
  52. * Deterministic Guomi SM2 signature wrapper
  53. */
  54. int mbedtls_ecdsa_sm2_sign_det(mbedtls_ecp_group *grp, mbedtls_mpi *r, mbedtls_mpi *s,
  55. const mbedtls_mpi *d, const unsigned char *buf, size_t blen,
  56. mbedtls_md_type_t md_alg);
  57. /*
  58. * Verify ECDSA Guomi SM2 signature of hashed message
  59. */
  60. int mbedtls_ecdsa_sm2_verify(mbedtls_ecp_group *grp,
  61. const unsigned char *buf, size_t blen,
  62. const mbedtls_ecp_point *Q, const mbedtls_mpi *r, const mbedtls_mpi *s);
  63. /*
  64. * Compute and write ecdsa sm2 signature
  65. */
  66. int mbedtls_ecdsa_sm2_write_signature(mbedtls_ecdsa_context *ctx, mbedtls_md_type_t md_alg,
  67. const unsigned char *hash, size_t hlen,
  68. unsigned char *sig, size_t *slen,
  69. int(*f_rng)(void *, unsigned char *, size_t),
  70. void *p_rng);
  71. int mbedtls_ecdsa_sm2_write_signature_det(mbedtls_ecdsa_context *ctx,
  72. const unsigned char *hash, size_t hlen,
  73. unsigned char *sig, size_t *slen,
  74. mbedtls_md_type_t md_alg);
  75. /*
  76. * Read and check sm2 signature
  77. */
  78. int mbedtls_ecdsa_sm2_read_signature(mbedtls_ecdsa_context *ctx,
  79. const unsigned char *hash, size_t hlen,
  80. const unsigned char *sig, size_t slen);
  81. #ifdef __cplusplus
  82. }
  83. #endif
  84. #endif /* ecdsa.h */