2
0

ECDSA_sign.pod 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. =pod
  2. =head1 NAME
  3. ECDSA_size, ECDSA_sign, ECDSA_do_sign,
  4. ECDSA_verify, ECDSA_do_verify, ECDSA_sign_setup, ECDSA_sign_ex,
  5. ECDSA_do_sign_ex - deprecated low-level elliptic curve digital signature algorithm
  6. (ECDSA) functions
  7. =head1 SYNOPSIS
  8. #include <openssl/ecdsa.h>
  9. The following functions have been deprecated since OpenSSL 3.0, and can be
  10. hidden entirely by defining B<OPENSSL_API_COMPAT> with a suitable version value,
  11. see L<openssl_user_macros(7)>:
  12. int ECDSA_size(const EC_KEY *eckey);
  13. int ECDSA_sign(int type, const unsigned char *dgst, int dgstlen,
  14. unsigned char *sig, unsigned int *siglen, EC_KEY *eckey);
  15. ECDSA_SIG *ECDSA_do_sign(const unsigned char *dgst, int dgst_len,
  16. EC_KEY *eckey);
  17. int ECDSA_verify(int type, const unsigned char *dgst, int dgstlen,
  18. const unsigned char *sig, int siglen, EC_KEY *eckey);
  19. int ECDSA_do_verify(const unsigned char *dgst, int dgst_len,
  20. const ECDSA_SIG *sig, EC_KEY* eckey);
  21. ECDSA_SIG *ECDSA_do_sign_ex(const unsigned char *dgst, int dgstlen,
  22. const BIGNUM *kinv, const BIGNUM *rp,
  23. EC_KEY *eckey);
  24. int ECDSA_sign_setup(EC_KEY *eckey, BN_CTX *ctx, BIGNUM **kinv, BIGNUM **rp);
  25. int ECDSA_sign_ex(int type, const unsigned char *dgst, int dgstlen,
  26. unsigned char *sig, unsigned int *siglen,
  27. const BIGNUM *kinv, const BIGNUM *rp, EC_KEY *eckey);
  28. =head1 DESCRIPTION
  29. See L<ECDSA_SIG_new(3)> for a description of the B<ECDSA_SIG> object.
  30. See L<i2d_ECDSA_SIG(3)> and L<d2i_ECDSA_SIG(3)> for information about encoding
  31. and decoding ECDSA signatures to/from DER.
  32. All of the functions described below are deprecated. Applications should
  33. use the higher level B<EVP> interface such as L<EVP_DigestSignInit(3)>
  34. or L<EVP_DigestVerifyInit(3)> instead.
  35. ECDSA_size() returns the maximum length of a DER encoded ECDSA signature
  36. created with the private EC key I<eckey>. To obtain the actual signature
  37. size use L<EVP_PKEY_sign(3)> with a NULL I<sig> parameter.
  38. ECDSA_sign() computes a digital signature of the I<dgstlen> bytes hash value
  39. I<dgst> using the private EC key I<eckey>. The DER encoded signatures is
  40. stored in I<sig> and its length is returned in I<sig_len>. Note: I<sig> must
  41. point to ECDSA_size(eckey) bytes of memory. The parameter I<type> is currently
  42. ignored. ECDSA_sign() is wrapper function for ECDSA_sign_ex() with I<kinv>
  43. and I<rp> set to NULL.
  44. ECDSA_do_sign() is similar to ECDSA_sign() except the signature is returned
  45. as a newly allocated B<ECDSA_SIG> structure (or NULL on error). ECDSA_do_sign()
  46. is a wrapper function for ECDSA_do_sign_ex() with I<kinv> and I<rp> set to
  47. NULL.
  48. ECDSA_verify() verifies that the signature in I<sig> of size I<siglen> is a
  49. valid ECDSA signature of the hash value I<dgst> of size I<dgstlen> using the
  50. public key I<eckey>. The parameter I<type> is ignored.
  51. ECDSA_do_verify() is similar to ECDSA_verify() except the signature is
  52. presented in the form of a pointer to an B<ECDSA_SIG> structure.
  53. The remaining functions utilise the internal I<kinv> and I<r> values used
  54. during signature computation. Most applications will never need to call these
  55. and some external ECDSA ENGINE implementations may not support them at all if
  56. either I<kinv> or I<r> is not NULL.
  57. ECDSA_sign_setup() may be used to precompute parts of the signing operation.
  58. I<eckey> is the private EC key and I<ctx> is a pointer to B<BN_CTX> structure
  59. (or NULL). The precomputed values or returned in I<kinv> and I<rp> and can be
  60. used in a later call to ECDSA_sign_ex() or ECDSA_do_sign_ex().
  61. ECDSA_sign_ex() computes a digital signature of the I<dgstlen> bytes hash value
  62. I<dgst> using the private EC key I<eckey> and the optional pre-computed values
  63. I<kinv> and I<rp>. The DER encoded signature is stored in I<sig> and its
  64. length is returned in I<sig_len>. Note: I<sig> must point to ECDSA_size(eckey)
  65. bytes of memory. The parameter I<type> is ignored.
  66. ECDSA_do_sign_ex() is similar to ECDSA_sign_ex() except the signature is
  67. returned as a newly allocated B<ECDSA_SIG> structure (or NULL on error).
  68. =head1 RETURN VALUES
  69. ECDSA_size() returns the maximum length signature or 0 on error.
  70. ECDSA_sign(), ECDSA_sign_ex() and ECDSA_sign_setup() return 1 if successful
  71. or 0 on error.
  72. ECDSA_do_sign() and ECDSA_do_sign_ex() return a pointer to an allocated
  73. B<ECDSA_SIG> structure or NULL on error.
  74. ECDSA_verify() and ECDSA_do_verify() return 1 for a valid
  75. signature, 0 for an invalid signature and -1 on error.
  76. The error codes can be obtained by L<ERR_get_error(3)>.
  77. =head1 EXAMPLES
  78. Creating an ECDSA signature of a given SHA-256 hash value using the
  79. named curve prime256v1 (aka P-256).
  80. This example uses deprecated functionality. See L</DESCRIPTION>.
  81. First step: create an EC_KEY object (note: this part is B<not> ECDSA
  82. specific)
  83. int ret;
  84. ECDSA_SIG *sig;
  85. EC_KEY *eckey;
  86. eckey = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
  87. if (eckey == NULL)
  88. /* error */
  89. if (EC_KEY_generate_key(eckey) == 0)
  90. /* error */
  91. Second step: compute the ECDSA signature of a SHA-256 hash value
  92. using ECDSA_do_sign():
  93. sig = ECDSA_do_sign(digest, 32, eckey);
  94. if (sig == NULL)
  95. /* error */
  96. or using ECDSA_sign():
  97. unsigned char *buffer, *pp;
  98. int buf_len;
  99. buf_len = ECDSA_size(eckey);
  100. buffer = OPENSSL_malloc(buf_len);
  101. pp = buffer;
  102. if (ECDSA_sign(0, dgst, dgstlen, pp, &buf_len, eckey) == 0)
  103. /* error */
  104. Third step: verify the created ECDSA signature using ECDSA_do_verify():
  105. ret = ECDSA_do_verify(digest, 32, sig, eckey);
  106. or using ECDSA_verify():
  107. ret = ECDSA_verify(0, digest, 32, buffer, buf_len, eckey);
  108. and finally evaluate the return value:
  109. if (ret == 1)
  110. /* signature ok */
  111. else if (ret == 0)
  112. /* incorrect signature */
  113. else
  114. /* error */
  115. =head1 CONFORMING TO
  116. ANSI X9.62, US Federal Information Processing Standard FIPS186-2
  117. (Digital Signature Standard, DSS)
  118. =head1 SEE ALSO
  119. L<EC_KEY_new(3)>,
  120. L<EVP_DigestSignInit(3)>,
  121. L<EVP_DigestVerifyInit(3)>,
  122. L<EVP_PKEY_sign(3)>
  123. L<i2d_ECDSA_SIG(3)>,
  124. L<d2i_ECDSA_SIG(3)>
  125. =head1 HISTORY
  126. All functionality described here was deprecated in OpenSSL 3.0.
  127. =head1 COPYRIGHT
  128. Copyright 2004-2022 The OpenSSL Project Authors. All Rights Reserved.
  129. Licensed under the Apache License 2.0 (the "License"). You may not use
  130. this file except in compliance with the License. You can obtain a copy
  131. in the file LICENSE in the source distribution or at
  132. L<https://www.openssl.org/source/license.html>.
  133. =cut