d2i_RSAPrivateKey.3ossl 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  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 "D2I_RSAPRIVATEKEY 3ossl"
  136. .TH D2I_RSAPRIVATEKEY 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. d2i_DSAPrivateKey,
  143. d2i_DSAPrivateKey_bio,
  144. d2i_DSAPrivateKey_fp,
  145. d2i_DSAPublicKey,
  146. d2i_DSA_PUBKEY,
  147. d2i_DSA_PUBKEY_bio,
  148. d2i_DSA_PUBKEY_fp,
  149. d2i_DSAparams,
  150. d2i_RSAPrivateKey,
  151. d2i_RSAPrivateKey_bio,
  152. d2i_RSAPrivateKey_fp,
  153. d2i_RSAPublicKey,
  154. d2i_RSAPublicKey_bio,
  155. d2i_RSAPublicKey_fp,
  156. d2i_RSA_PUBKEY,
  157. d2i_RSA_PUBKEY_bio,
  158. d2i_RSA_PUBKEY_fp,
  159. d2i_DHparams,
  160. d2i_DHparams_bio,
  161. d2i_DHparams_fp,
  162. d2i_ECParameters,
  163. d2i_ECPrivateKey,
  164. d2i_ECPrivateKey_bio,
  165. d2i_ECPrivateKey_fp,
  166. d2i_EC_PUBKEY,
  167. d2i_EC_PUBKEY_bio,
  168. d2i_EC_PUBKEY_fp,
  169. i2d_RSAPrivateKey,
  170. i2d_RSAPrivateKey_bio,
  171. i2d_RSAPrivateKey_fp,
  172. i2d_RSAPublicKey,
  173. i2d_RSAPublicKey_bio,
  174. i2d_RSAPublicKey_fp,
  175. i2d_RSA_PUBKEY,
  176. i2d_RSA_PUBKEY_bio,
  177. i2d_RSA_PUBKEY_fp,
  178. i2d_DHparams,
  179. i2d_DHparams_bio,
  180. i2d_DHparams_fp,
  181. i2d_DSAPrivateKey,
  182. i2d_DSAPrivateKey_bio,
  183. i2d_DSAPrivateKey_fp,
  184. i2d_DSAPublicKey,
  185. i2d_DSA_PUBKEY,
  186. i2d_DSA_PUBKEY_bio,
  187. i2d_DSA_PUBKEY_fp,
  188. i2d_DSAparams,
  189. i2d_ECParameters,
  190. i2d_ECPrivateKey,
  191. i2d_ECPrivateKey_bio,
  192. i2d_ECPrivateKey_fp,
  193. i2d_EC_PUBKEY,
  194. i2d_EC_PUBKEY_bio,
  195. i2d_EC_PUBKEY_fp
  196. \&\- DEPRECATED
  197. .SH "SYNOPSIS"
  198. .IX Header "SYNOPSIS"
  199. The following functions have been deprecated since OpenSSL 3.0, and can be
  200. hidden entirely by defining \fB\s-1OPENSSL_API_COMPAT\s0\fR with a suitable version value,
  201. see \fBopenssl_user_macros\fR\|(7):
  202. .PP
  203. .Vb 12
  204. \& TYPE *d2i_TYPEPrivateKey(TYPE **a, const unsigned char **ppin, long length);
  205. \& TYPE *d2i_TYPEPrivateKey_bio(BIO *bp, TYPE **a);
  206. \& TYPE *d2i_TYPEPrivateKey_fp(FILE *fp, TYPE **a);
  207. \& TYPE *d2i_TYPEPublicKey(TYPE **a, const unsigned char **ppin, long length);
  208. \& TYPE *d2i_TYPEPublicKey_bio(BIO *bp, TYPE **a);
  209. \& TYPE *d2i_TYPEPublicKey_fp(FILE *fp, TYPE **a);
  210. \& TYPE *d2i_TYPEparams(TYPE **a, const unsigned char **ppin, long length);
  211. \& TYPE *d2i_TYPEparams_bio(BIO *bp, TYPE **a);
  212. \& TYPE *d2i_TYPEparams_fp(FILE *fp, TYPE **a);
  213. \& TYPE *d2i_TYPE_PUBKEY(TYPE **a, const unsigned char **ppin, long length);
  214. \& TYPE *d2i_TYPE_PUBKEY_bio(BIO *bp, TYPE **a);
  215. \& TYPE *d2i_TYPE_PUBKEY_fp(FILE *fp, TYPE **a);
  216. \&
  217. \& int i2d_TYPEPrivateKey(const TYPE *a, unsigned char **ppout);
  218. \& int i2d_TYPEPrivateKey(TYPE *a, unsigned char **ppout);
  219. \& int i2d_TYPEPrivateKey_fp(FILE *fp, const TYPE *a);
  220. \& int i2d_TYPEPrivateKey_fp(FILE *fp, TYPE *a);
  221. \& int i2d_TYPEPrivateKey_bio(BIO *bp, const TYPE *a);
  222. \& int i2d_TYPEPrivateKey_bio(BIO *bp, TYPE *a);
  223. \& int i2d_TYPEPublicKey(const TYPE *a, unsigned char **ppout);
  224. \& int i2d_TYPEPublicKey(TYPE *a, unsigned char **ppout);
  225. \& int i2d_TYPEPublicKey_fp(FILE *fp, const TYPE *a);
  226. \& int i2d_TYPEPublicKey_fp(FILE *fp, TYPE *a);
  227. \& int i2d_TYPEPublicKey_bio(BIO *bp, const TYPE *a);
  228. \& int i2d_TYPEPublicKey_bio(BIO *bp, TYPE *a);
  229. \& int i2d_TYPEparams(const TYPE *a, unsigned char **ppout);
  230. \& int i2d_TYPEparams(TYPE *a, unsigned char **ppout);
  231. \& int i2d_TYPEparams_fp(FILE *fp, const TYPE *a);
  232. \& int i2d_TYPEparams_fp(FILE *fp, TYPE *a);
  233. \& int i2d_TYPEparams_bio(BIO *bp, const TYPE *a);
  234. \& int i2d_TYPEparams_bio(BIO *bp, TYPE *a);
  235. \& int i2d_TYPE_PUBKEY(const TYPE *a, unsigned char **ppout);
  236. \& int i2d_TYPE_PUBKEY(TYPE *a, unsigned char **ppout);
  237. \& int i2d_TYPE_PUBKEY_fp(FILE *fp, const TYPE *a);
  238. \& int i2d_TYPE_PUBKEY_fp(FILE *fp, TYPE *a);
  239. \& int i2d_TYPE_PUBKEY_bio(BIO *bp, const TYPE *a);
  240. \& int i2d_TYPE_PUBKEY_bio(BIO *bp, TYPE *a);
  241. .Ve
  242. .SH "DESCRIPTION"
  243. .IX Header "DESCRIPTION"
  244. All functions described here are deprecated. Please use \s-1\fBOSSL_DECODER\s0\fR\|(3)
  245. instead of the \fBd2i\fR functions and \s-1\fBOSSL_ENCODER\s0\fR\|(3) instead of the \fBi2d\fR
  246. functions. See \*(L"Migration\*(R" below.
  247. .PP
  248. In the description here, \fB\f(BI\s-1TYPE\s0\fB\fR is used a placeholder for any of the
  249. OpenSSL datatypes, such as \fB\s-1RSA\s0\fR.
  250. The function parameters \fIppin\fR and \fIppout\fR are generally either both named
  251. \&\fIpp\fR in the headers, or \fIin\fR and \fIout\fR.
  252. .PP
  253. All the functions here behave the way that's described in \fBd2i_X509\fR\|(3).
  254. .PP
  255. Please note that not all functions in the synopsis are available for all key
  256. types. For example, there are no \fBd2i_RSAparams()\fR or \fBi2d_RSAparams()\fR,
  257. because the PKCS#1 \fB\s-1RSA\s0\fR structure doesn't include any key parameters.
  258. .PP
  259. \&\fBd2i_\f(BI\s-1TYPE\s0\fBPrivateKey\fR() and derivates thereof decode \s-1DER\s0 encoded
  260. \&\fB\f(BI\s-1TYPE\s0\fB\fR private key data organized in a type specific structure.
  261. .PP
  262. \&\fBd2i_\f(BI\s-1TYPE\s0\fBPublicKey\fR() and derivates thereof decode \s-1DER\s0 encoded
  263. \&\fB\f(BI\s-1TYPE\s0\fB\fR public key data organized in a type specific structure.
  264. .PP
  265. \&\fBd2i_\f(BI\s-1TYPE\s0\fBparams\fR() and derivates thereof decode \s-1DER\s0 encoded \fB\f(BI\s-1TYPE\s0\fB\fR
  266. key parameters organized in a type specific structure.
  267. .PP
  268. \&\fBd2i_\f(BI\s-1TYPE\s0\fB_PUBKEY\fR() and derivates thereof decode \s-1DER\s0 encoded \fB\f(BI\s-1TYPE\s0\fB\fR
  269. public key data organized in a \fBSubjectPublicKeyInfo\fR structure.
  270. .PP
  271. \&\fBi2d_\f(BI\s-1TYPE\s0\fBPrivateKey\fR() and derivates thereof encode the private key
  272. \&\fB\f(BI\s-1TYPE\s0\fB\fR data into a type specific \s-1DER\s0 encoded structure.
  273. .PP
  274. \&\fBi2d_\f(BI\s-1TYPE\s0\fBPublicKey\fR() and derivates thereof encode the public key
  275. \&\fB\f(BI\s-1TYPE\s0\fB\fR data into a type specific \s-1DER\s0 encoded structure.
  276. .PP
  277. \&\fBi2d_\f(BI\s-1TYPE\s0\fBparams\fR() and derivates thereof encode the \fB\f(BI\s-1TYPE\s0\fB\fR key
  278. parameters data into a type specific \s-1DER\s0 encoded structure.
  279. .PP
  280. \&\fBi2d_\f(BI\s-1TYPE\s0\fB_PUBKEY\fR() and derivates thereof encode the public key
  281. \&\fB\f(BI\s-1TYPE\s0\fB\fR data into a \s-1DER\s0 encoded \fBSubjectPublicKeyInfo\fR structure.
  282. .PP
  283. For example, \fBd2i_RSAPrivateKey()\fR and \fBd2i_RSAPublicKey()\fR expects the
  284. structure defined by PKCS#1.
  285. Similarly, \fBi2d_RSAPrivateKey()\fR and \fBi2d_RSAPublicKey()\fR produce \s-1DER\s0 encoded
  286. string organized according to PKCS#1.
  287. .SS "Migration"
  288. .IX Subsection "Migration"
  289. Migration from the diverse \fB\f(BI\s-1TYPE\s0\fB\fRs requires using corresponding new
  290. OpenSSL types. For all \fB\f(BI\s-1TYPE\s0\fB\fRs described here, the corresponding new
  291. type is \fB\s-1EVP_PKEY\s0\fR. The rest of this section assumes that this has been
  292. done, exactly how to do that is described elsewhere.
  293. .PP
  294. There are two migration paths:
  295. .IP "\(bu" 4
  296. Replace
  297. b<d2i_\fI\s-1TYPE\s0\fR\fBPrivateKey()\fR> with \fBd2i_PrivateKey\fR\|(3),
  298. b<d2i_\fI\s-1TYPE\s0\fR\fBPublicKey()\fR> with \fBd2i_PublicKey\fR\|(3),
  299. b<d2i_\fI\s-1TYPE\s0\fR\fBparams()\fR> with \fBd2i_KeyParams\fR\|(3),
  300. b<d2i_\fI\s-1TYPE\s0\fR\fB_PUBKEY()\fR> with \fBd2i_PUBKEY\fR\|(3),
  301. b<i2d_\fI\s-1TYPE\s0\fR\fBPrivateKey()\fR> with \fBi2d_PrivateKey\fR\|(3),
  302. b<i2d_\fI\s-1TYPE\s0\fR\fBPublicKey()\fR> with \fBi2d_PublicKey\fR\|(3),
  303. b<i2d_\fI\s-1TYPE\s0\fR\fBparams()\fR> with \fBi2d_KeyParams\fR\|(3),
  304. b<i2d_\fI\s-1TYPE\s0\fR\fB_PUBKEY()\fR> with \fBi2d_PUBKEY\fR\|(3).
  305. A caveat is that \fBi2d_PrivateKey\fR\|(3) may output a \s-1DER\s0 encoded PKCS#8
  306. outermost structure instead of the type specific structure, and that
  307. \&\fBd2i_PrivateKey\fR\|(3) recognises and unpacks a PKCS#8 structures.
  308. .IP "\(bu" 4
  309. Use \s-1\fBOSSL_DECODER\s0\fR\|(3) and \s-1\fBOSSL_ENCODER\s0\fR\|(3). How to migrate is described
  310. below. All those descriptions assume that the key to be encoded is in the
  311. variable \fIpkey\fR.
  312. .PP
  313. \fIMigrating \f(BIi2d\fI functions to \f(BI\s-1OSSL_ENCODER\s0\fI\fR
  314. .IX Subsection "Migrating i2d functions to OSSL_ENCODER"
  315. .PP
  316. The exact \s-1\fBOSSL_ENCODER\s0\fR\|(3) output is driven by arguments rather than by
  317. function names. The sample code to get \s-1DER\s0 encoded output in a type
  318. specific structure is uniform, the only things that vary are the selection
  319. of what part of the \fB\s-1EVP_PKEY\s0\fR should be output, and the structure. The
  320. \&\fBi2d\fR functions names can therefore be translated into two variables,
  321. \&\fIselection\fR and \fIstructure\fR as follows:
  322. .IP "\fBi2d_\f(BI\s-1TYPE\s0\fBPrivateKey\fR() translates into:" 4
  323. .IX Item "i2d_TYPEPrivateKey() translates into:"
  324. .Vb 2
  325. \& int selection = EVP_PKEY_KEYPAIR;
  326. \& const char *structure = "type\-specific";
  327. .Ve
  328. .IP "\fBi2d_\f(BI\s-1TYPE\s0\fBPublicKey\fR() translates into:" 4
  329. .IX Item "i2d_TYPEPublicKey() translates into:"
  330. .Vb 2
  331. \& int selection = EVP_PKEY_PUBLIC_KEY;
  332. \& const char *structure = "type\-specific";
  333. .Ve
  334. .IP "\fBi2d_\f(BI\s-1TYPE\s0\fBparams\fR() translates into:" 4
  335. .IX Item "i2d_TYPEparams() translates into:"
  336. .Vb 2
  337. \& int selection = EVP_PKEY_PARAMETERS;
  338. \& const char *structure = "type\-specific";
  339. .Ve
  340. .IP "\fBi2d_\f(BI\s-1TYPE\s0\fB_PUBKEY\fR() translates into:" 4
  341. .IX Item "i2d_TYPE_PUBKEY() translates into:"
  342. .Vb 2
  343. \& int selection = EVP_PKEY_PUBLIC_KEY;
  344. \& const char *structure = "SubjectPublicKeyInfo";
  345. .Ve
  346. .PP
  347. The following sample code does the rest of the work:
  348. .PP
  349. .Vb 10
  350. \& unsigned char *p = buffer; /* |buffer| is supplied by the caller */
  351. \& size_t len = buffer_size; /* assumed be the size of |buffer| */
  352. \& OSSL_ENCODER_CTX *ctx =
  353. \& OSSL_ENCODER_CTX_new_for_pkey(pkey, selection, "DER", structure,
  354. \& NULL, NULL);
  355. \& if (ctx == NULL) {
  356. \& /* fatal error handling */
  357. \& }
  358. \& if (OSSL_ENCODER_CTX_get_num_encoders(ctx) == 0) {
  359. \& OSSL_ENCODER_CTX_free(ctx);
  360. \& /* non\-fatal error handling */
  361. \& }
  362. \& if (!OSSL_ENCODER_to_data(ctx, &p, &len)) {
  363. \& OSSL_ENCODER_CTX_free(ctx);
  364. \& /* error handling */
  365. \& }
  366. \& OSSL_ENCODER_CTX_free(ctx);
  367. .Ve
  368. .SH "NOTES"
  369. .IX Header "NOTES"
  370. The letters \fBi\fR and \fBd\fR in \fBi2d_\f(BI\s-1TYPE\s0\fB\fR() stand for
  371. \&\*(L"internal\*(R" (that is, an internal C structure) and \*(L"\s-1DER\*(R"\s0 respectively.
  372. So \fBi2d_\f(BI\s-1TYPE\s0\fB\fR() converts from internal to \s-1DER.\s0
  373. .PP
  374. The functions can also understand \fB\s-1BER\s0\fR forms.
  375. .PP
  376. The actual \s-1TYPE\s0 structure passed to \fBi2d_\f(BI\s-1TYPE\s0\fB\fR() must be a valid
  377. populated \fB\f(BI\s-1TYPE\s0\fB\fR structure \*(-- it \fBcannot\fR simply be fed with an
  378. empty structure such as that returned by \fBTYPE_new()\fR.
  379. .PP
  380. The encoded data is in binary form and may contain embedded zeros.
  381. Therefore, any \s-1FILE\s0 pointers or BIOs should be opened in binary mode.
  382. Functions such as \fBstrlen()\fR will \fBnot\fR return the correct length
  383. of the encoded structure.
  384. .PP
  385. The ways that \fI*ppin\fR and \fI*ppout\fR are incremented after the operation
  386. can trap the unwary. See the \fB\s-1WARNINGS\s0\fR section in \fBd2i_X509\fR\|(3) for some
  387. common errors.
  388. The reason for this-auto increment behaviour is to reflect a typical
  389. usage of \s-1ASN1\s0 functions: after one structure is encoded or decoded
  390. another will be processed after it.
  391. .PP
  392. The following points about the data types might be useful:
  393. .IP "\fB\s-1DSA_PUBKEY\s0\fR" 4
  394. .IX Item "DSA_PUBKEY"
  395. Represents a \s-1DSA\s0 public key using a \fBSubjectPublicKeyInfo\fR structure.
  396. .IP "\fBDSAPublicKey\fR, \fBDSAPrivateKey\fR" 4
  397. .IX Item "DSAPublicKey, DSAPrivateKey"
  398. Use a non-standard OpenSSL format and should be avoided; use \fB\s-1DSA_PUBKEY\s0\fR,
  399. \&\fBPEM_write_PrivateKey\fR\|(3), or similar instead.
  400. .SH "RETURN VALUES"
  401. .IX Header "RETURN VALUES"
  402. \&\fBd2i_\f(BI\s-1TYPE\s0\fB\fR(), \fBd2i_\f(BI\s-1TYPE\s0\fB_bio\fR() and \fBd2i_\f(BI\s-1TYPE\s0\fB_fp\fR() return a valid
  403. \&\fB\f(BI\s-1TYPE\s0\fB\fR structure or \s-1NULL\s0 if an error occurs. If the \*(L"reuse\*(R" capability has
  404. been used with a valid structure being passed in via \fIa\fR, then the object is
  405. freed in the event of error and \fI*a\fR is set to \s-1NULL.\s0
  406. .PP
  407. \&\fBi2d_\f(BI\s-1TYPE\s0\fB\fR() returns the number of bytes successfully encoded or a negative
  408. value if an error occurs.
  409. .PP
  410. \&\fBi2d_\f(BI\s-1TYPE\s0\fB_bio\fR() and \fBi2d_\f(BI\s-1TYPE\s0\fB_fp\fR() return 1 for success and 0 if an
  411. error occurs.
  412. .SH "SEE ALSO"
  413. .IX Header "SEE ALSO"
  414. \&\s-1\fBOSSL_ENCODER\s0\fR\|(3), \s-1\fBOSSL_DECODER\s0\fR\|(3),
  415. \&\fBd2i_PrivateKey\fR\|(3), \fBd2i_PublicKey\fR\|(3), \fBd2i_KeyParams\fR\|(3),
  416. \&\fBd2i_PUBKEY\fR\|(3),
  417. \&\fBi2d_PrivateKey\fR\|(3), \fBi2d_PublicKey\fR\|(3), \fBi2d_KeyParams\fR\|(3),
  418. \&\fBi2d_PUBKEY\fR\|(3)
  419. .SH "COPYRIGHT"
  420. .IX Header "COPYRIGHT"
  421. Copyright 2020\-2023 The OpenSSL Project Authors. All Rights Reserved.
  422. .PP
  423. Licensed under the Apache License 2.0 (the \*(L"License\*(R"). You may not use
  424. this file except in compliance with the License. You can obtain a copy
  425. in the file \s-1LICENSE\s0 in the source distribution or at
  426. <https://www.openssl.org/source/license.html>.