Standard preamble:
========================================================================
..
.... Set up some character translations and predefined strings. \*(-- will
give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
double quote, and \*(R" will give a right double quote. \*(C+ will
give a nicer C++. Capital omega is used to do unbreakable dashes and
therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
nothing in troff, for use with C<>.
.tr \(*W- . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\}
Escape single quotes in literal strings from groff's Unicode transform.
If the F register is >0, we'll generate index entries on stderr for
titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
entries marked with X<> in POD. Of course, you'll have to process the
output yourself in some meaningful fashion.
Avoid warning from groff about undefined register 'F'.
.. .nr rF 0 . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF
Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
Fear. Run. Save yourself. No user-serviceable parts.
. \" fudge factors for nroff and troff . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] .\} . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents . \" corrections for vroff . \" for low resolution devices (crt and lpr) \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} ========================================================================
Title "D2I_RSAPRIVATEKEY 3ossl"
way too many mistakes in technical documents.
.Vb 12 TYPE *d2i_TYPEPrivateKey(TYPE **a, const unsigned char **ppin, long length); TYPE *d2i_TYPEPrivateKey_bio(BIO *bp, TYPE **a); TYPE *d2i_TYPEPrivateKey_fp(FILE *fp, TYPE **a); TYPE *d2i_TYPEPublicKey(TYPE **a, const unsigned char **ppin, long length); TYPE *d2i_TYPEPublicKey_bio(BIO *bp, TYPE **a); TYPE *d2i_TYPEPublicKey_fp(FILE *fp, TYPE **a); TYPE *d2i_TYPEparams(TYPE **a, const unsigned char **ppin, long length); TYPE *d2i_TYPEparams_bio(BIO *bp, TYPE **a); TYPE *d2i_TYPEparams_fp(FILE *fp, TYPE **a); TYPE *d2i_TYPE_PUBKEY(TYPE **a, const unsigned char **ppin, long length); TYPE *d2i_TYPE_PUBKEY_bio(BIO *bp, TYPE **a); TYPE *d2i_TYPE_PUBKEY_fp(FILE *fp, TYPE **a); \& int i2d_TYPEPrivateKey(const TYPE *a, unsigned char **ppout); int i2d_TYPEPrivateKey(TYPE *a, unsigned char **ppout); int i2d_TYPEPrivateKey_fp(FILE *fp, const TYPE *a); int i2d_TYPEPrivateKey_fp(FILE *fp, TYPE *a); int i2d_TYPEPrivateKey_bio(BIO *bp, const TYPE *a); int i2d_TYPEPrivateKey_bio(BIO *bp, TYPE *a); int i2d_TYPEPublicKey(const TYPE *a, unsigned char **ppout); int i2d_TYPEPublicKey(TYPE *a, unsigned char **ppout); int i2d_TYPEPublicKey_fp(FILE *fp, const TYPE *a); int i2d_TYPEPublicKey_fp(FILE *fp, TYPE *a); int i2d_TYPEPublicKey_bio(BIO *bp, const TYPE *a); int i2d_TYPEPublicKey_bio(BIO *bp, TYPE *a); int i2d_TYPEparams(const TYPE *a, unsigned char **ppout); int i2d_TYPEparams(TYPE *a, unsigned char **ppout); int i2d_TYPEparams_fp(FILE *fp, const TYPE *a); int i2d_TYPEparams_fp(FILE *fp, TYPE *a); int i2d_TYPEparams_bio(BIO *bp, const TYPE *a); int i2d_TYPEparams_bio(BIO *bp, TYPE *a); int i2d_TYPE_PUBKEY(const TYPE *a, unsigned char **ppout); int i2d_TYPE_PUBKEY(TYPE *a, unsigned char **ppout); int i2d_TYPE_PUBKEY_fp(FILE *fp, const TYPE *a); int i2d_TYPE_PUBKEY_fp(FILE *fp, TYPE *a); int i2d_TYPE_PUBKEY_bio(BIO *bp, const TYPE *a); int i2d_TYPE_PUBKEY_bio(BIO *bp, TYPE *a); .Ve
In the description here, \f(BI\s-1TYPE\s0 is used a placeholder for any of the OpenSSL datatypes, such as \s-1RSA\s0. The function parameters ppin and ppout are generally either both named \fIpp in the headers, or in and out.
All the functions here behave the way that's described in d2i_X509\|(3).
Please note that not all functions in the synopsis are available for all key types. For example, there are no d2i_RSAparams() or i2d_RSAparams(), because the PKCS#1 \s-1RSA\s0 structure doesn't include any key parameters.
\fBd2i_\f(BI\s-1TYPE\s0PrivateKey() and derivates thereof decode \s-1DER\s0 encoded \fB\f(BI\s-1TYPE\s0 private key data organized in a type specific structure.
\fBd2i_\f(BI\s-1TYPE\s0PublicKey() and derivates thereof decode \s-1DER\s0 encoded \fB\f(BI\s-1TYPE\s0 public key data organized in a type specific structure.
\fBd2i_\f(BI\s-1TYPE\s0params() and derivates thereof decode \s-1DER\s0 encoded \f(BI\s-1TYPE\s0 key parameters organized in a type specific structure.
\fBd2i_\f(BI\s-1TYPE\s0_PUBKEY() and derivates thereof decode \s-1DER\s0 encoded \f(BI\s-1TYPE\s0 public key data organized in a SubjectPublicKeyInfo structure.
\fBi2d_\f(BI\s-1TYPE\s0PrivateKey() and derivates thereof encode the private key \fB\f(BI\s-1TYPE\s0 data into a type specific \s-1DER\s0 encoded structure.
\fBi2d_\f(BI\s-1TYPE\s0PublicKey() and derivates thereof encode the public key \fB\f(BI\s-1TYPE\s0 data into a type specific \s-1DER\s0 encoded structure.
\fBi2d_\f(BI\s-1TYPE\s0params() and derivates thereof encode the \f(BI\s-1TYPE\s0 key parameters data into a type specific \s-1DER\s0 encoded structure.
\fBi2d_\f(BI\s-1TYPE\s0_PUBKEY() and derivates thereof encode the public key \fB\f(BI\s-1TYPE\s0 data into a \s-1DER\s0 encoded SubjectPublicKeyInfo structure.
For example, d2i_RSAPrivateKey() and d2i_RSAPublicKey() expects the structure defined by PKCS#1. Similarly, i2d_RSAPrivateKey() and i2d_RSAPublicKey() produce \s-1DER\s0 encoded string organized according to PKCS#1.
There are two migration paths:
Migrating \f(BIi2d functions to \f(BI\s-1OSSL_ENCODER\s0 Subsection "Migrating i2d functions to OSSL_ENCODER"
The exact \s-1OSSL_ENCODER\s0\|(3) output is driven by arguments rather than by function names. The sample code to get \s-1DER\s0 encoded output in a type specific structure is uniform, the only things that vary are the selection of what part of the \s-1EVP_PKEY\s0 should be output, and the structure. The \fBi2d functions names can therefore be translated into two variables, \fIselection and structure as follows:
The following sample code does the rest of the work:
.Vb 10 unsigned char *p = buffer; /* |buffer| is supplied by the caller */ size_t len = buffer_size; /* assumed be the size of |buffer| */ OSSL_ENCODER_CTX *ctx = OSSL_ENCODER_CTX_new_for_pkey(pkey, selection, "DER", structure, NULL, NULL); if (ctx == NULL) { /* fatal error handling */ } if (OSSL_ENCODER_CTX_get_num_encoders(ctx) == 0) { OSSL_ENCODER_CTX_free(ctx); /* non-fatal error handling */ } if (!OSSL_ENCODER_to_data(ctx, &p, &len)) { OSSL_ENCODER_CTX_free(ctx); /* error handling */ } OSSL_ENCODER_CTX_free(ctx); .Ve
The functions can also understand \s-1BER\s0 forms.
The actual \s-1TYPE\s0 structure passed to i2d_\f(BI\s-1TYPE\s0() must be a valid populated \f(BI\s-1TYPE\s0 structure \*(-- it cannot simply be fed with an empty structure such as that returned by TYPE_new().
The encoded data is in binary form and may contain embedded zeros. Therefore, any \s-1FILE\s0 pointers or BIOs should be opened in binary mode. Functions such as strlen() will not return the correct length of the encoded structure.
The ways that *ppin and *ppout are incremented after the operation can trap the unwary. See the \s-1WARNINGS\s0 section in d2i_X509\|(3) for some common errors. The reason for this-auto increment behaviour is to reflect a typical usage of \s-1ASN1\s0 functions: after one structure is encoded or decoded another will be processed after it.
The following points about the data types might be useful:
\fBi2d_\f(BI\s-1TYPE\s0() returns the number of bytes successfully encoded or a negative value if an error occurs.
\fBi2d_\f(BI\s-1TYPE\s0_bio() and i2d_\f(BI\s-1TYPE\s0_fp() return 1 for success and 0 if an error occurs.
Licensed under the Apache License 2.0 (the \*(L"License\*(R"). You may not use this file except in compliance with the License. You can obtain a copy in the file \s-1LICENSE\s0 in the source distribution or at <https://www.openssl.org/source/license.html>.