SM2.pod 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. =pod
  2. =head1 NAME
  3. SM2 - Chinese SM2 signature and encryption algorithm support
  4. =head1 DESCRIPTION
  5. The B<SM2> algorithm was first defined by the Chinese national standard GM/T
  6. 0003-2012 and was later standardized by ISO as ISO/IEC 14888. B<SM2> is actually
  7. an elliptic curve based algorithm. The current implementation in OpenSSL supports
  8. both signature and encryption schemes via the EVP interface.
  9. When doing the B<SM2> signature algorithm, it requires a distinguishing identifier
  10. to form the message prefix which is hashed before the real message is hashed.
  11. =head1 NOTES
  12. B<SM2> signatures can be generated by using the 'DigestSign' series of APIs, for
  13. instance, EVP_DigestSignInit(), EVP_DigestSignUpdate() and EVP_DigestSignFinal().
  14. Ditto for the verification process by calling the 'DigestVerify' series of APIs.
  15. There are several special steps that need to be done before computing an B<SM2>
  16. signature.
  17. The B<EVP_PKEY> structure will default to using ECDSA for signatures when it is
  18. created. It should be set to B<EVP_PKEY_SM2> by calling:
  19. EVP_PKEY_set_alias_type(pkey, EVP_PKEY_SM2);
  20. Then an ID should be set by calling:
  21. EVP_PKEY_CTX_set1_id(pctx, id, id_len);
  22. When calling the EVP_DigestSignInit() or EVP_DigestVerifyInit() functions, a
  23. preallocated B<EVP_PKEY_CTX> should be assigned to the B<EVP_MD_CTX>. This is
  24. done by calling:
  25. EVP_MD_CTX_set_pkey_ctx(mctx, pctx);
  26. And normally there is no need to pass a B<pctx> parameter to EVP_DigestSignInit()
  27. or EVP_DigestVerifyInit() in such a scenario.
  28. =head1 EXAMPLES
  29. This example demonstrates the calling sequence for using an B<EVP_PKEY> to verify
  30. a message with the SM2 signature algorithm and the SM3 hash algorithm:
  31. #include <openssl/evp.h>
  32. /* obtain an EVP_PKEY using whatever methods... */
  33. EVP_PKEY_set_alias_type(pkey, EVP_PKEY_SM2);
  34. mctx = EVP_MD_CTX_new();
  35. pctx = EVP_PKEY_CTX_new(pkey, NULL);
  36. EVP_PKEY_CTX_set1_id(pctx, id, id_len);
  37. EVP_MD_CTX_set_pkey_ctx(mctx, pctx);;
  38. EVP_DigestVerifyInit(mctx, NULL, EVP_sm3(), NULL, pkey);
  39. EVP_DigestVerifyUpdate(mctx, msg, msg_len);
  40. EVP_DigestVerifyFinal(mctx, sig, sig_len)
  41. =head1 SEE ALSO
  42. L<EVP_PKEY_CTX_new(3)>,
  43. L<EVP_PKEY_set_alias_type(3)>,
  44. L<EVP_DigestSignInit(3)>,
  45. L<EVP_DigestVerifyInit(3)>,
  46. L<EVP_PKEY_CTX_set1_id(3)>,
  47. L<EVP_MD_CTX_set_pkey_ctx(3)>
  48. =head1 COPYRIGHT
  49. Copyright 2018-2020 The OpenSSL Project Authors. All Rights Reserved.
  50. Licensed under the OpenSSL license (the "License"). You may not use
  51. this file except in compliance with the License. You can obtain a copy
  52. in the file LICENSE in the source distribution or at
  53. L<https://www.openssl.org/source/license.html>.
  54. =cut