ECDSA_sign.3ossl 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. .\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42)
  2. .\"
  3. .\" Standard preamble:
  4. .\" ========================================================================
  5. .de Sp \" Vertical space (when we can't use .PP)
  6. .if t .sp .5v
  7. .if n .sp
  8. ..
  9. .de Vb \" Begin verbatim text
  10. .ft CW
  11. .nf
  12. .ne \\$1
  13. ..
  14. .de Ve \" End verbatim text
  15. .ft R
  16. .fi
  17. ..
  18. .\" Set up some character translations and predefined strings. \*(-- will
  19. .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
  20. .\" double quote, and \*(R" will give a right double quote. \*(C+ will
  21. .\" give a nicer C++. Capital omega is used to do unbreakable dashes and
  22. .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
  23. .\" nothing in troff, for use with C<>.
  24. .tr \(*W-
  25. .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
  26. .ie n \{\
  27. . ds -- \(*W-
  28. . ds PI pi
  29. . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
  30. . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
  31. . ds L" ""
  32. . ds R" ""
  33. . ds C` ""
  34. . ds C' ""
  35. 'br\}
  36. .el\{\
  37. . ds -- \|\(em\|
  38. . ds PI \(*p
  39. . ds L" ``
  40. . ds R" ''
  41. . ds C`
  42. . ds C'
  43. 'br\}
  44. .\"
  45. .\" Escape single quotes in literal strings from groff's Unicode transform.
  46. .ie \n(.g .ds Aq \(aq
  47. .el .ds Aq '
  48. .\"
  49. .\" If the F register is >0, we'll generate index entries on stderr for
  50. .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
  51. .\" entries marked with X<> in POD. Of course, you'll have to process the
  52. .\" output yourself in some meaningful fashion.
  53. .\"
  54. .\" Avoid warning from groff about undefined register 'F'.
  55. .de IX
  56. ..
  57. .nr rF 0
  58. .if \n(.g .if rF .nr rF 1
  59. .if (\n(rF:(\n(.g==0)) \{\
  60. . if \nF \{\
  61. . de IX
  62. . tm Index:\\$1\t\\n%\t"\\$2"
  63. ..
  64. . if !\nF==2 \{\
  65. . nr % 0
  66. . nr F 2
  67. . \}
  68. . \}
  69. .\}
  70. .rr rF
  71. .\"
  72. .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
  73. .\" Fear. Run. Save yourself. No user-serviceable parts.
  74. . \" fudge factors for nroff and troff
  75. .if n \{\
  76. . ds #H 0
  77. . ds #V .8m
  78. . ds #F .3m
  79. . ds #[ \f1
  80. . ds #] \fP
  81. .\}
  82. .if t \{\
  83. . ds #H ((1u-(\\\\n(.fu%2u))*.13m)
  84. . ds #V .6m
  85. . ds #F 0
  86. . ds #[ \&
  87. . ds #] \&
  88. .\}
  89. . \" simple accents for nroff and troff
  90. .if n \{\
  91. . ds ' \&
  92. . ds ` \&
  93. . ds ^ \&
  94. . ds , \&
  95. . ds ~ ~
  96. . ds /
  97. .\}
  98. .if t \{\
  99. . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
  100. . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
  101. . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
  102. . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
  103. . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
  104. . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
  105. .\}
  106. . \" troff and (daisy-wheel) nroff accents
  107. .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
  108. .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
  109. .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
  110. .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
  111. .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
  112. .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
  113. .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
  114. .ds ae a\h'-(\w'a'u*4/10)'e
  115. .ds Ae A\h'-(\w'A'u*4/10)'E
  116. . \" corrections for vroff
  117. .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
  118. .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
  119. . \" for low resolution devices (crt and lpr)
  120. .if \n(.H>23 .if \n(.V>19 \
  121. \{\
  122. . ds : e
  123. . ds 8 ss
  124. . ds o a
  125. . ds d- d\h'-1'\(ga
  126. . ds D- D\h'-1'\(hy
  127. . ds th \o'bp'
  128. . ds Th \o'LP'
  129. . ds ae ae
  130. . ds Ae AE
  131. .\}
  132. .rm #[ #] #H #V #F C
  133. .\" ========================================================================
  134. .\"
  135. .IX Title "ECDSA_SIGN 3ossl"
  136. .TH ECDSA_SIGN 3ossl "2024-09-03" "3.3.2" "OpenSSL"
  137. .\" For nroff, turn off justification. Always turn off hyphenation; it makes
  138. .\" way too many mistakes in technical documents.
  139. .if n .ad l
  140. .nh
  141. .SH "NAME"
  142. ECDSA_size, ECDSA_sign, ECDSA_do_sign,
  143. ECDSA_verify, ECDSA_do_verify, ECDSA_sign_setup, ECDSA_sign_ex,
  144. ECDSA_do_sign_ex \- deprecated low\-level elliptic curve digital signature algorithm
  145. (ECDSA) functions
  146. .SH "SYNOPSIS"
  147. .IX Header "SYNOPSIS"
  148. .Vb 1
  149. \& #include <openssl/ecdsa.h>
  150. .Ve
  151. .PP
  152. The following functions have been deprecated since OpenSSL 3.0, and can be
  153. hidden entirely by defining \fB\s-1OPENSSL_API_COMPAT\s0\fR with a suitable version value,
  154. see \fBopenssl_user_macros\fR\|(7):
  155. .PP
  156. .Vb 1
  157. \& int ECDSA_size(const EC_KEY *eckey);
  158. \&
  159. \& int ECDSA_sign(int type, const unsigned char *dgst, int dgstlen,
  160. \& unsigned char *sig, unsigned int *siglen, EC_KEY *eckey);
  161. \& ECDSA_SIG *ECDSA_do_sign(const unsigned char *dgst, int dgst_len,
  162. \& EC_KEY *eckey);
  163. \&
  164. \& int ECDSA_verify(int type, const unsigned char *dgst, int dgstlen,
  165. \& const unsigned char *sig, int siglen, EC_KEY *eckey);
  166. \& int ECDSA_do_verify(const unsigned char *dgst, int dgst_len,
  167. \& const ECDSA_SIG *sig, EC_KEY* eckey);
  168. \&
  169. \& ECDSA_SIG *ECDSA_do_sign_ex(const unsigned char *dgst, int dgstlen,
  170. \& const BIGNUM *kinv, const BIGNUM *rp,
  171. \& EC_KEY *eckey);
  172. \& int ECDSA_sign_setup(EC_KEY *eckey, BN_CTX *ctx, BIGNUM **kinv, BIGNUM **rp);
  173. \& int ECDSA_sign_ex(int type, const unsigned char *dgst, int dgstlen,
  174. \& unsigned char *sig, unsigned int *siglen,
  175. \& const BIGNUM *kinv, const BIGNUM *rp, EC_KEY *eckey);
  176. .Ve
  177. .SH "DESCRIPTION"
  178. .IX Header "DESCRIPTION"
  179. See \fBECDSA_SIG_new\fR\|(3) for a description of the \fB\s-1ECDSA_SIG\s0\fR object.
  180. .PP
  181. See \fBi2d_ECDSA_SIG\fR\|(3) and \fBd2i_ECDSA_SIG\fR\|(3) for information about encoding
  182. and decoding \s-1ECDSA\s0 signatures to/from \s-1DER.\s0
  183. .PP
  184. All of the functions described below are deprecated. Applications should
  185. use the higher level \fB\s-1EVP\s0\fR interface such as \fBEVP_DigestSignInit\fR\|(3)
  186. or \fBEVP_DigestVerifyInit\fR\|(3) instead.
  187. .PP
  188. \&\fBECDSA_size()\fR returns the maximum length of a \s-1DER\s0 encoded \s-1ECDSA\s0 signature
  189. created with the private \s-1EC\s0 key \fIeckey\fR. To obtain the actual signature
  190. size use \fBEVP_PKEY_sign\fR\|(3) with a \s-1NULL\s0 \fIsig\fR parameter.
  191. .PP
  192. \&\fBECDSA_sign()\fR computes a digital signature of the \fIdgstlen\fR bytes hash value
  193. \&\fIdgst\fR using the private \s-1EC\s0 key \fIeckey\fR. The \s-1DER\s0 encoded signatures is
  194. stored in \fIsig\fR and its length is returned in \fIsig_len\fR. Note: \fIsig\fR must
  195. point to ECDSA_size(eckey) bytes of memory. The parameter \fItype\fR is currently
  196. ignored. \fBECDSA_sign()\fR is wrapper function for \fBECDSA_sign_ex()\fR with \fIkinv\fR
  197. and \fIrp\fR set to \s-1NULL.\s0
  198. .PP
  199. \&\fBECDSA_do_sign()\fR is similar to \fBECDSA_sign()\fR except the signature is returned
  200. as a newly allocated \fB\s-1ECDSA_SIG\s0\fR structure (or \s-1NULL\s0 on error). \fBECDSA_do_sign()\fR
  201. is a wrapper function for \fBECDSA_do_sign_ex()\fR with \fIkinv\fR and \fIrp\fR set to
  202. \&\s-1NULL.\s0
  203. .PP
  204. \&\fBECDSA_verify()\fR verifies that the signature in \fIsig\fR of size \fIsiglen\fR is a
  205. valid \s-1ECDSA\s0 signature of the hash value \fIdgst\fR of size \fIdgstlen\fR using the
  206. public key \fIeckey\fR. The parameter \fItype\fR is ignored.
  207. .PP
  208. \&\fBECDSA_do_verify()\fR is similar to \fBECDSA_verify()\fR except the signature is
  209. presented in the form of a pointer to an \fB\s-1ECDSA_SIG\s0\fR structure.
  210. .PP
  211. The remaining functions utilise the internal \fIkinv\fR and \fIr\fR values used
  212. during signature computation. Most applications will never need to call these
  213. and some external \s-1ECDSA ENGINE\s0 implementations may not support them at all if
  214. either \fIkinv\fR or \fIr\fR is not \s-1NULL.\s0
  215. .PP
  216. \&\fBECDSA_sign_setup()\fR may be used to precompute parts of the signing operation.
  217. \&\fIeckey\fR is the private \s-1EC\s0 key and \fIctx\fR is a pointer to \fB\s-1BN_CTX\s0\fR structure
  218. (or \s-1NULL\s0). The precomputed values or returned in \fIkinv\fR and \fIrp\fR and can be
  219. used in a later call to \fBECDSA_sign_ex()\fR or \fBECDSA_do_sign_ex()\fR.
  220. .PP
  221. \&\fBECDSA_sign_ex()\fR computes a digital signature of the \fIdgstlen\fR bytes hash value
  222. \&\fIdgst\fR using the private \s-1EC\s0 key \fIeckey\fR and the optional pre-computed values
  223. \&\fIkinv\fR and \fIrp\fR. The \s-1DER\s0 encoded signature is stored in \fIsig\fR and its
  224. length is returned in \fIsig_len\fR. Note: \fIsig\fR must point to ECDSA_size(eckey)
  225. bytes of memory. The parameter \fItype\fR is ignored.
  226. .PP
  227. \&\fBECDSA_do_sign_ex()\fR is similar to \fBECDSA_sign_ex()\fR except the signature is
  228. returned as a newly allocated \fB\s-1ECDSA_SIG\s0\fR structure (or \s-1NULL\s0 on error).
  229. .SH "RETURN VALUES"
  230. .IX Header "RETURN VALUES"
  231. \&\fBECDSA_size()\fR returns the maximum length signature or 0 on error.
  232. .PP
  233. \&\fBECDSA_sign()\fR, \fBECDSA_sign_ex()\fR and \fBECDSA_sign_setup()\fR return 1 if successful
  234. or 0 on error.
  235. .PP
  236. \&\fBECDSA_do_sign()\fR and \fBECDSA_do_sign_ex()\fR return a pointer to an allocated
  237. \&\fB\s-1ECDSA_SIG\s0\fR structure or \s-1NULL\s0 on error.
  238. .PP
  239. \&\fBECDSA_verify()\fR and \fBECDSA_do_verify()\fR return 1 for a valid
  240. signature, 0 for an invalid signature and \-1 on error.
  241. The error codes can be obtained by \fBERR_get_error\fR\|(3).
  242. .SH "EXAMPLES"
  243. .IX Header "EXAMPLES"
  244. Creating an \s-1ECDSA\s0 signature of a given \s-1SHA\-256\s0 hash value using the
  245. named curve prime256v1 (aka P\-256).
  246. This example uses deprecated functionality. See \*(L"\s-1DESCRIPTION\*(R"\s0.
  247. .PP
  248. First step: create an \s-1EC_KEY\s0 object (note: this part is \fBnot\fR \s-1ECDSA\s0
  249. specific)
  250. .PP
  251. .Vb 3
  252. \& int ret;
  253. \& ECDSA_SIG *sig;
  254. \& EC_KEY *eckey;
  255. \&
  256. \& eckey = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
  257. \& if (eckey == NULL)
  258. \& /* error */
  259. \& if (EC_KEY_generate_key(eckey) == 0)
  260. \& /* error */
  261. .Ve
  262. .PP
  263. Second step: compute the \s-1ECDSA\s0 signature of a \s-1SHA\-256\s0 hash value
  264. using \fBECDSA_do_sign()\fR:
  265. .PP
  266. .Vb 3
  267. \& sig = ECDSA_do_sign(digest, 32, eckey);
  268. \& if (sig == NULL)
  269. \& /* error */
  270. .Ve
  271. .PP
  272. or using \fBECDSA_sign()\fR:
  273. .PP
  274. .Vb 2
  275. \& unsigned char *buffer, *pp;
  276. \& int buf_len;
  277. \&
  278. \& buf_len = ECDSA_size(eckey);
  279. \& buffer = OPENSSL_malloc(buf_len);
  280. \& pp = buffer;
  281. \& if (ECDSA_sign(0, dgst, dgstlen, pp, &buf_len, eckey) == 0)
  282. \& /* error */
  283. .Ve
  284. .PP
  285. Third step: verify the created \s-1ECDSA\s0 signature using \fBECDSA_do_verify()\fR:
  286. .PP
  287. .Vb 1
  288. \& ret = ECDSA_do_verify(digest, 32, sig, eckey);
  289. .Ve
  290. .PP
  291. or using \fBECDSA_verify()\fR:
  292. .PP
  293. .Vb 1
  294. \& ret = ECDSA_verify(0, digest, 32, buffer, buf_len, eckey);
  295. .Ve
  296. .PP
  297. and finally evaluate the return value:
  298. .PP
  299. .Vb 6
  300. \& if (ret == 1)
  301. \& /* signature ok */
  302. \& else if (ret == 0)
  303. \& /* incorrect signature */
  304. \& else
  305. \& /* error */
  306. .Ve
  307. .SH "CONFORMING TO"
  308. .IX Header "CONFORMING TO"
  309. \&\s-1ANSI X9.62, US\s0 Federal Information Processing Standard \s-1FIPS186\-2\s0
  310. (Digital Signature Standard, \s-1DSS\s0)
  311. .SH "SEE ALSO"
  312. .IX Header "SEE ALSO"
  313. \&\fBEC_KEY_new\fR\|(3),
  314. \&\fBEVP_DigestSignInit\fR\|(3),
  315. \&\fBEVP_DigestVerifyInit\fR\|(3),
  316. \&\fBEVP_PKEY_sign\fR\|(3)
  317. \&\fBi2d_ECDSA_SIG\fR\|(3),
  318. \&\fBd2i_ECDSA_SIG\fR\|(3)
  319. .SH "HISTORY"
  320. .IX Header "HISTORY"
  321. All functionality described here was deprecated in OpenSSL 3.0.
  322. .SH "COPYRIGHT"
  323. .IX Header "COPYRIGHT"
  324. Copyright 2004\-2022 The OpenSSL Project Authors. All Rights Reserved.
  325. .PP
  326. Licensed under the Apache License 2.0 (the \*(L"License\*(R"). You may not use
  327. this file except in compliance with the License. You can obtain a copy
  328. in the file \s-1LICENSE\s0 in the source distribution or at
  329. <https://www.openssl.org/source/license.html>.