.\" $OpenBSD: d2i_ECPKParameters.3,v 1.7 2016/12/11 14:22:43 schwarze Exp $ .\" OpenSSL 05ea606a May 20 20:52:46 2016 -0400 .\" .\" This file was written by Matt Caswell . .\" Copyright (c) 2013, 2015 The OpenSSL Project. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in .\" the documentation and/or other materials provided with the .\" distribution. .\" .\" 3. All advertising materials mentioning features or use of this .\" software must display the following acknowledgment: .\" "This product includes software developed by the OpenSSL Project .\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)" .\" .\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to .\" endorse or promote products derived from this software without .\" prior written permission. For written permission, please contact .\" openssl-core@openssl.org. .\" .\" 5. Products derived from this software may not be called "OpenSSL" .\" nor may "OpenSSL" appear in their names without prior written .\" permission of the OpenSSL Project. .\" .\" 6. Redistributions of any form whatsoever must retain the following .\" acknowledgment: .\" "This product includes software developed by the OpenSSL Project .\" for use in the OpenSSL Toolkit (http://www.openssl.org/)" .\" .\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY .\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR .\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, .\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; .\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, .\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED .\" OF THE POSSIBILITY OF SUCH DAMAGE. .\" .Dd $Mdocdate: December 11 2016 $ .Dt D2I_ECPKPARAMETERS 3 .Os .Sh NAME .Nm d2i_ECPKParameters , .Nm i2d_ECPKParameters , .Nm d2i_ECPKParameters_bio , .Nm i2d_ECPKParameters_bio , .Nm d2i_ECPKParameters_fp , .Nm i2d_ECPKParameters_fp , .Nm d2i_ECParameters , .Nm i2d_ECParameters , .Nm ECParameters_dup , .Nm d2i_ECPrivateKey , .Nm i2d_ECPrivateKey , .Nm o2i_ECPublicKey , .Nm i2o_ECPublicKey , .Nm ECPKParameters_print , .Nm ECPKParameters_print_fp , .Nm ECParameters_print , .Nm ECParameters_print_fp .Nd decode and encode ASN.1 representations of elliptic curve entities .Sh SYNOPSIS .In openssl/ec.h .Ft EC_GROUP * .Fo d2i_ECPKParameters .Fa "EC_GROUP **px" .Fa "const unsigned char **in" .Fa "long len" .Fc .Ft int .Fo i2d_ECPKParameters .Fa "const EC_GROUP *x" .Fa "unsigned char **out" .Fc .Ft EC_GROUP * .Fo d2i_ECPKParameters_bio .Fa "BIO *bp" .Fa "EC_GROUP **px" .Fc .Ft int .Fo i2d_ECPKParameters_bio .Fa "BIO *bp" .Fa "EC_GROUP **px" .Fc .Ft EC_GROUP * .Fo d2i_ECPKParameters_fp .Fa "FILE *fp" .Fa "EC_GROUP **px" .Fc .Ft int .Fo i2d_ECPKParameters_fp .Fa "FILE *fp" .Fa "EC_GROUP **px" .Fc .Ft EC_KEY * .Fo d2i_ECParameters .Fa "EC_KEY **key" .Fa "const unsigned char **in" .Fa "long len" .Fc .Ft int .Fo i2d_ECParameters .Fa "EC_KEY *key" .Fa "unsigned char **out" .Fc .Ft EC_KEY * .Fo ECParameters_dup .Fa "EC_KEY *key" .Fc .Ft EC_KEY * .Fo d2i_ECPrivateKey .Fa "EC_KEY **key" .Fa "const unsigned char **in" .Fa "long len" .Fc .Ft int .Fo i2d_ECPrivateKey .Fa "EC_KEY *key" .Fa "unsigned char **out" .Fc .Ft EC_KEY * .Fo o2i_ECPublicKey .Fa "EC_KEY **key" .Fa "const unsigned char **in" .Fa "long len" .Fc .Ft int .Fo i2o_ECPublicKey .Fa "EC_KEY *key" .Fa "unsigned char **out" .Fc .Ft int .Fo ECPKParameters_print .Fa "BIO *bp" .Fa "const EC_GROUP *x" .Fa "int off" .Fc .Ft int .Fo ECPKParameters_print_fp .Fa "FILE *fp" .Fa "const EC_GROUP *x" .Fa "int off" .Fc .Ft int .Fo ECParameters_print .Fa "BIO *bp" .Fa "const EC_KEY *key" .Fc .Ft int .Fo ECParameters_print_fp .Fa "FILE *fp" .Fa "const EC_KEY *key" .Fc .Sh DESCRIPTION .Fn d2i_ECPKParameters attempts to decode .Fa len bytes at .Pf * Fa in . If successful, a pointer to the .Vt EC_GROUP structure is returned. If an error occurred, then .Dv NULL is returned. If .Fa px is not .Dv NULL , then the returned structure is written to .Pf * Fa px . If .Pf * Fa px is not .Dv NULL , then it is assumed that .Pf * Fa px contains a valid .Vt EC_GROUP structure and an attempt is made to reuse it. If the call is successful, .Pf * Fa in is incremented to the byte following the parsed data. .Pp .Fn i2d_ECPKParameters encodes the structure pointed to by .Fa x into DER format. If .Fa out is not .Dv NULL , is writes the DER encoded data to the buffer at .Pf * Fa out and increments it to point after the data just written. If the return value is negative, an error occurred, otherwise it returns the length of the encoded data. .Pp If .Pf * Fa out is .Dv NULL , memory will be allocated for a buffer and the encoded data written to it. In this case .Pf * Fa out is not incremented, and it points to the start of the data just written. .Pp .Fn d2i_ECPKParameters_bio is similar to .Fn d2i_ECPKParameters except it attempts to parse data from .Vt BIO .Fa bp . .Fn d2i_ECPKParameters_fp is similar to .Fn d2i_ECPKParameters except it attempts to parse data from the .Vt FILE pointer .Fa fp . .Fn i2d_ECPKParameters_bio is similar to .Fn i2d_ECPKParameters except it writes the encoding of the structure .Fa x to .Vt BIO .Fa bp and it returns 1 for success or 0 for failure. .Fn i2d_ECPKParameters_fp is similar to .Fn i2d_ECPKParameters except it writes the encoding of the structure .Fa x to .Vt BIO .Sy bp and it returns 1 for success or 0 for failure. These four functions are currently implemented as macros. .Pp .Fn d2i_ECParameters does the same parsing as .Fn d2i_ECPKParameters but saves the result in the .Fa group field of an .Vt EC_KEY structure. .Pp .Fn i2d_ECParameters produces the same output as .Fn i2d_ECPKParameters but uses .Fa key->group for input instead of .Fa px . .Pp .Fn ECParameters_dup copies .Fa key by calling .Fn i2d_ECParameters and .Fn d2i_ECParameters . .Pp .Fn d2i_ECPrivateKey interprets .Fa len bytes at .Fa in as a DER-encoded private key, decodes it, stores the result in .Fa key as described above, and returns a pointer to it. .Pp .Fn i2d_ECPrivateKey encodes the private key .Fa a into DER format and writes it to .Fa out as described above. .Pp .Fn o2i_ECPublicKey takes a string of .Fa len octets from .Fa in , decodes them, and stores the resulting EC public key in the existing .Pf * Fa key . .Pp .Fn i2o_ECPublicKey encodes the public .Fa key into the octet string buffer .Pf * Fa out . If .Pf * Fa out is .Dv NULL , a new buffer of the required size is allocated; otherwise, the pointer is advanced to point to the octet after the last one written. .Pp These functions are very similar to the X.509 functions described in .Xr d2i_X509 3 , where further notes and examples are available. .Pp The .Fn ECPKParameters_print and .Fn ECPKParameters_print_fp functions print human-readable output of the public parameters of the .Vt EC_GROUP to .Fa bp or .Fa fp . The output lines are indented by .Fa off spaces. .Pp .Fn ECParameters_print and .Fn ECParameters_print_fp print the parameter components of .Fa key to .Fa bp or .Fa fp . .Sh RETURN VALUES .Fn d2i_ECPKParameters , .Fn d2i_ECPKParameters_bio , and .Fn d2i_ECPKParameters_fp return a valid .Vt EC_GROUP structure or .Dv NULL if an error occurs. .Pp .Fn d2i_ECParameters , .Fn ECParameters_dup , .Fn d2i_ECPrivateKey , and .Fn o2i_ECPublicKey return a valid .Vt EC_KEY structure or .Dv NULL if an error occurs. .Pp .Fn i2d_ECPKParameters , .Fn i2d_ECParameters , .Fn i2d_ECPrivateKey , and .Fn i2o_ECPublicKey return the number of bytes successfully encoded or a negative value if an error occurs. .Pp .Fn i2d_ECPKParameters_bio , .Fn i2d_ECPKParameters_fp , .Fn ECPKParameters_print , .Fn ECPKParameters_print_fp , .Fn ECParameters_print , and .Fn ECParameters_print_fp return 1 for success or 0 if an error occurs. .Sh SEE ALSO .Xr d2i_X509 3 , .Xr EC_GFp_simple_method 3 , .Xr EC_GROUP_copy 3 , .Xr EC_GROUP_new 3 , .Xr EC_KEY_new 3 , .Xr EC_POINT_add 3 , .Xr EC_POINT_new 3 , .Xr ECDSA_SIG_new 3