ASN1_EXTERN_FUNCS.3ossl 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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 "ASN1_EXTERN_FUNCS 3ossl"
  136. .TH ASN1_EXTERN_FUNCS 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. ASN1_EXTERN_FUNCS, ASN1_ex_d2i, ASN1_ex_d2i_ex, ASN1_ex_i2d, ASN1_ex_new_func,
  143. ASN1_ex_new_ex_func, ASN1_ex_free_func, ASN1_ex_print_func,
  144. IMPLEMENT_EXTERN_ASN1
  145. \&\- ASN.1 external function support
  146. .SH "SYNOPSIS"
  147. .IX Header "SYNOPSIS"
  148. .Vb 1
  149. \& #include <openssl/asn1t.h>
  150. \&
  151. \& typedef int ASN1_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
  152. \& const ASN1_ITEM *it, int tag, int aclass, char opt,
  153. \& ASN1_TLC *ctx);
  154. \& typedef int ASN1_ex_d2i_ex(ASN1_VALUE **pval, const unsigned char **in, long len,
  155. \& const ASN1_ITEM *it, int tag, int aclass, char opt,
  156. \& ASN1_TLC *ctx, OSSL_LIB_CTX *libctx,
  157. \& const char *propq);
  158. \& typedef int ASN1_ex_i2d(const ASN1_VALUE **pval, unsigned char **out,
  159. \& const ASN1_ITEM *it, int tag, int aclass);
  160. \& typedef int ASN1_ex_new_func(ASN1_VALUE **pval, const ASN1_ITEM *it);
  161. \& typedef int ASN1_ex_new_ex_func(ASN1_VALUE **pval, const ASN1_ITEM *it,
  162. \& OSSL_LIB_CTX *libctx, const char *propq);
  163. \& typedef void ASN1_ex_free_func(ASN1_VALUE **pval, const ASN1_ITEM *it);
  164. \& typedef int ASN1_ex_print_func(BIO *out, const ASN1_VALUE **pval,
  165. \& int indent, const char *fname,
  166. \& const ASN1_PCTX *pctx);
  167. \&
  168. \& struct ASN1_EXTERN_FUNCS_st {
  169. \& void *app_data;
  170. \& ASN1_ex_new_func *asn1_ex_new;
  171. \& ASN1_ex_free_func *asn1_ex_free;
  172. \& ASN1_ex_free_func *asn1_ex_clear;
  173. \& ASN1_ex_d2i *asn1_ex_d2i;
  174. \& ASN1_ex_i2d *asn1_ex_i2d;
  175. \& ASN1_ex_print_func *asn1_ex_print;
  176. \& ASN1_ex_new_ex_func *asn1_ex_new_ex;
  177. \& ASN1_ex_d2i_ex *asn1_ex_d2i_ex;
  178. \& };
  179. \& typedef struct ASN1_EXTERN_FUNCS_st ASN1_EXTERN_FUNCS;
  180. \&
  181. \& #define IMPLEMENT_EXTERN_ASN1(sname, tag, fptrs)
  182. .Ve
  183. .SH "DESCRIPTION"
  184. .IX Header "DESCRIPTION"
  185. \&\s-1ASN.1\s0 data structures templates are typically defined in OpenSSL using a series
  186. of macros such as \s-1\fBASN1_SEQUENCE\s0()\fR, \s-1\fBASN1_SEQUENCE_END\s0()\fR and so on. Instead
  187. templates can also be defined based entirely on external functions. These
  188. external functions are called to perform operations such as creating a new
  189. \&\fB\s-1ASN1_VALUE\s0\fR or converting an \fB\s-1ASN1_VALUE\s0\fR to or from \s-1DER\s0 encoding.
  190. .PP
  191. The macro \s-1\fBIMPLEMENT_EXTERN_ASN1\s0()\fR can be used to create such an externally
  192. defined structure. The name of the structure should be supplied in the \fIsname\fR
  193. parameter. The tag for the structure (e.g. typically \fBV_ASN1_SEQUENCE\fR) should
  194. be supplied in the \fItag\fR parameter. Finally a pointer to an
  195. \&\fB\s-1ASN1_EXTERN_FUNCS\s0\fR structure should be supplied in the \fIfptrs\fR parameter.
  196. .PP
  197. The \fB\s-1ASN1_EXTERN_FUNCS\s0\fR structure has the following entries.
  198. .IP "\fIapp_data\fR" 4
  199. .IX Item "app_data"
  200. A pointer to arbitrary application specific data.
  201. .IP "\fIasn1_ex_new\fR" 4
  202. .IX Item "asn1_ex_new"
  203. A \*(L"new\*(R" function responsible for constructing a new \fB\s-1ASN1_VALUE\s0\fR object. The
  204. newly constructed value should be stored in \fI*pval\fR. The \fIit\fR parameter is a
  205. pointer to the \fB\s-1ASN1_ITEM\s0\fR template object created via the
  206. \&\s-1\fBIMPLEMENT_EXTERN_ASN1\s0()\fR macro.
  207. .Sp
  208. Returns a positive value on success or 0 on error.
  209. .IP "\fIasn1_ex_free\fR" 4
  210. .IX Item "asn1_ex_free"
  211. A \*(L"free\*(R" function responsible for freeing the \fB\s-1ASN1_VALUE\s0\fR passed in \fI*pval\fR
  212. that was previously allocated via a \*(L"new\*(R" function. The \fIit\fR parameter is a
  213. pointer to the \fB\s-1ASN1_ITEM\s0\fR template object created via the
  214. \&\s-1\fBIMPLEMENT_EXTERN_ASN1\s0()\fR macro.
  215. .IP "\fIasn1_ex_clear\fR" 4
  216. .IX Item "asn1_ex_clear"
  217. A \*(L"clear\*(R" function responsible for clearing any data in the \fB\s-1ASN1_VALUE\s0\fR passed
  218. in \fI*pval\fR and making it suitable for reuse. The \fIit\fR parameter is a pointer
  219. to the \fB\s-1ASN1_ITEM\s0\fR template object created via the \s-1\fBIMPLEMENT_EXTERN_ASN1\s0()\fR
  220. macro.
  221. .IP "\fIasn1_ex_d2i\fR" 4
  222. .IX Item "asn1_ex_d2i"
  223. A \*(L"d2i\*(R" function responsible for converting \s-1DER\s0 data with the tag \fItag\fR and
  224. class \fIclass\fR into an \fB\s-1ASN1_VALUE\s0\fR. If \fI*pval\fR is non-NULL then the
  225. \&\fB\s-1ASN_VALUE\s0\fR it points to should be reused. Otherwise a new \fB\s-1ASN1_VALUE\s0\fR
  226. should be allocated and stored in \fI*pval\fR. \fI*in\fR points to the \s-1DER\s0 data to be
  227. decoded and \fIlen\fR is the length of that data. After decoding \fI*in\fR should be
  228. updated to point at the next byte after the decoded data. If the \fB\s-1ASN1_VALUE\s0\fR
  229. is considered optional in this context then \fIopt\fR will be nonzero. Otherwise
  230. it will be zero. The \fIit\fR parameter is a pointer to the \fB\s-1ASN1_ITEM\s0\fR template
  231. object created via the \s-1\fBIMPLEMENT_EXTERN_ASN1\s0()\fR macro. A pointer to the current
  232. \&\fB\s-1ASN1_TLC\s0\fR context (which may be required for other \s-1ASN1\s0 function calls) is
  233. passed in the \fIctx\fR parameter.
  234. .Sp
  235. The \fIasn1_ex_d2i\fR entry may be \s-1NULL\s0 if \fIasn1_ex_d2i_ex\fR has been specified
  236. instead.
  237. .Sp
  238. Returns <= 0 on error or a positive value on success.
  239. .IP "\fIasn1_ex_i2d\fR" 4
  240. .IX Item "asn1_ex_i2d"
  241. An \*(L"i2d\*(R" function responsible for converting an \fB\s-1ASN1_VALUE\s0\fR into \s-1DER\s0 encoding.
  242. On entry \fI*pval\fR will contain the \fB\s-1ASN1_VALUE\s0\fR to be encoded. If default
  243. tagging is to be used then \fItag\fR will be \-1 on entry. Otherwise if implicit
  244. tagging should be used then \fItag\fR and \fIaclass\fR will be the tag and associated
  245. class.
  246. .Sp
  247. If \fIout\fR is not \s-1NULL\s0 then this function should write the \s-1DER\s0 encoded data to
  248. the buffer in \fI*out\fR, and then increment \fI*out\fR to point to immediately after
  249. the data just written.
  250. .Sp
  251. If \fIout\fR is \s-1NULL\s0 then no data should be written but the length calculated and
  252. returned as if it were.
  253. .Sp
  254. The \fIasn1_ex_i2d\fR entry may be \s-1NULL\s0 if \fIasn1_ex_i2d_ex\fR has been specified
  255. instead.
  256. .Sp
  257. The return value should be negative if a fatal error occurred, or 0 if a
  258. non-fatal error occurred. Otherwise it should return the length of the encoded
  259. data.
  260. .IP "\fIasn1_ex_print\fR" 4
  261. .IX Item "asn1_ex_print"
  262. A \*(L"print\*(R" function. \fIout\fR is the \s-1BIO\s0 to print the output to. \fI*pval\fR is the
  263. \&\fB\s-1ASN1_VALUE\s0\fR to be printed. \fIindent\fR is the number of spaces of indenting to
  264. be printed before any data is printed. \fIfname\fR is currently unused and is
  265. always "". \fIpctx\fR is a pointer to the \fB\s-1ASN1_PCTX\s0\fR for the print operation.
  266. .Sp
  267. Returns 0 on error or a positive value on success. If the return value is 2 then
  268. an additional newline will be printed after the data printed by this function.
  269. .IP "\fIasn1_ex_new_ex\fR" 4
  270. .IX Item "asn1_ex_new_ex"
  271. This is the same as \fIasn1_ex_new\fR except that it is additionally passed the
  272. \&\s-1OSSL_LIB_CTX\s0 to be used in \fIlibctx\fR and any property query string to be used
  273. for algorithm fetching in the \fIpropq\fR parameter. See
  274. \&\*(L"\s-1ALGORITHM FETCHING\*(R"\s0 in \fBcrypto\fR\|(7) for further details. If \fIasn1_ex_new_ex\fR is
  275. non \s-1NULL,\s0 then it will always be called in preference to \fIasn1_ex_new\fR.
  276. .IP "\fIasn1_ex_d2i_ex\fR" 4
  277. .IX Item "asn1_ex_d2i_ex"
  278. This is the same as \fIasn1_ex_d2i\fR except that it is additionally passed the
  279. \&\s-1OSSL_LIB_CTX\s0 to be used in \fIlibctx\fR and any property query string to be used
  280. for algorithm fetching in the \fIpropq\fR parameter. See
  281. \&\*(L"\s-1ALGORITHM FETCHING\*(R"\s0 in \fBcrypto\fR\|(7) for further details. If \fIasn1_ex_d2i_ex\fR is
  282. non \s-1NULL,\s0 then it will always be called in preference to \fIasn1_ex_d2i\fR.
  283. .SH "RETURN VALUES"
  284. .IX Header "RETURN VALUES"
  285. Return values for the various callbacks are as described above.
  286. .SH "SEE ALSO"
  287. .IX Header "SEE ALSO"
  288. \&\fBASN1_item_new_ex\fR\|(3)
  289. .SH "HISTORY"
  290. .IX Header "HISTORY"
  291. The \fIasn1_ex_new_ex\fR and \fIasn1_ex_d2i_ex\fR callbacks were added in OpenSSL 3.0.
  292. .SH "COPYRIGHT"
  293. .IX Header "COPYRIGHT"
  294. Copyright 2021 The OpenSSL Project Authors. All Rights Reserved.
  295. .PP
  296. Licensed under the Apache License 2.0 (the \*(L"License\*(R"). You may not use
  297. this file except in compliance with the License. You can obtain a copy
  298. in the file \s-1LICENSE\s0 in the source distribution or at
  299. <https://www.openssl.org/source/license.html>.