1.\" $OpenBSD: d2i_ECPKParameters.3,v 1.13 2024/10/24 21:42:10 tb Exp $ 2.\" OpenSSL 05ea606a May 20 20:52:46 2016 -0400 3.\" 4.\" This file is a derived work. 5.\" The changes are covered by the following Copyright and license: 6.\" 7.\" Copyright (c) 2016 Ingo Schwarze <schwarze@openbsd.org> 8.\" 9.\" Permission to use, copy, modify, and distribute this software for any 10.\" purpose with or without fee is hereby granted, provided that the above 11.\" copyright notice and this permission notice appear in all copies. 12.\" 13.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 14.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 15.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 16.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 17.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 18.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 19.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 20.\" 21.\" The original file was written by Matt Caswell <matt@openssl.org>. 22.\" Copyright (c) 2013, 2015 The OpenSSL Project. All rights reserved. 23.\" 24.\" Redistribution and use in source and binary forms, with or without 25.\" modification, are permitted provided that the following conditions 26.\" are met: 27.\" 28.\" 1. Redistributions of source code must retain the above copyright 29.\" notice, this list of conditions and the following disclaimer. 30.\" 31.\" 2. Redistributions in binary form must reproduce the above copyright 32.\" notice, this list of conditions and the following disclaimer in 33.\" the documentation and/or other materials provided with the 34.\" distribution. 35.\" 36.\" 3. All advertising materials mentioning features or use of this 37.\" software must display the following acknowledgment: 38.\" "This product includes software developed by the OpenSSL Project 39.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)" 40.\" 41.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 42.\" endorse or promote products derived from this software without 43.\" prior written permission. For written permission, please contact 44.\" openssl-core@openssl.org. 45.\" 46.\" 5. Products derived from this software may not be called "OpenSSL" 47.\" nor may "OpenSSL" appear in their names without prior written 48.\" permission of the OpenSSL Project. 49.\" 50.\" 6. Redistributions of any form whatsoever must retain the following 51.\" acknowledgment: 52.\" "This product includes software developed by the OpenSSL Project 53.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)" 54.\" 55.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 56.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 57.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 58.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 59.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 60.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 61.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 62.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 63.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 64.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 65.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 66.\" OF THE POSSIBILITY OF SUCH DAMAGE. 67.\" 68.Dd $Mdocdate: October 24 2024 $ 69.Dt D2I_ECPKPARAMETERS 3 70.Os 71.Sh NAME 72.Nm d2i_ECPKParameters , 73.Nm i2d_ECPKParameters , 74.Nm d2i_ECPKParameters_bio , 75.Nm i2d_ECPKParameters_bio , 76.Nm d2i_ECPKParameters_fp , 77.Nm i2d_ECPKParameters_fp , 78.Nm d2i_ECParameters , 79.Nm i2d_ECParameters , 80.Nm ECParameters_dup , 81.Nm d2i_ECPrivateKey , 82.Nm i2d_ECPrivateKey , 83.Nm d2i_ECPrivateKey_bio , 84.Nm i2d_ECPrivateKey_bio , 85.Nm d2i_ECPrivateKey_fp , 86.Nm i2d_ECPrivateKey_fp , 87.Nm o2i_ECPublicKey , 88.Nm i2o_ECPublicKey , 89.Nm ECPKParameters_print , 90.Nm ECPKParameters_print_fp , 91.Nm ECParameters_print , 92.Nm ECParameters_print_fp , 93.Nm d2i_EC_PUBKEY , 94.Nm i2d_EC_PUBKEY , 95.Nm d2i_EC_PUBKEY_bio , 96.Nm i2d_EC_PUBKEY_bio , 97.Nm d2i_EC_PUBKEY_fp , 98.Nm i2d_EC_PUBKEY_fp 99.Nd decode and encode ASN.1 representations of elliptic curve entities 100.Sh SYNOPSIS 101.In openssl/ec.h 102.Ft EC_GROUP * 103.Fo d2i_ECPKParameters 104.Fa "EC_GROUP **val_out" 105.Fa "const unsigned char **der_in" 106.Fa "long length" 107.Fc 108.Ft int 109.Fo i2d_ECPKParameters 110.Fa "const EC_GROUP *val_in" 111.Fa "unsigned char **der_out" 112.Fc 113.Ft EC_GROUP * 114.Fo d2i_ECPKParameters_bio 115.Fa "BIO *in_bio" 116.Fa "EC_GROUP **val_out" 117.Fc 118.Ft int 119.Fo i2d_ECPKParameters_bio 120.Fa "BIO *out_bio" 121.Fa "EC_GROUP *val_in" 122.Fc 123.Ft EC_GROUP * 124.Fo d2i_ECPKParameters_fp 125.Fa "FILE *in_fp" 126.Fa "EC_GROUP **val_out" 127.Fc 128.Ft int 129.Fo i2d_ECPKParameters_fp 130.Fa "FILE *out_fp" 131.Fa "EC_GROUP *val_in" 132.Fc 133.Ft EC_KEY * 134.Fo d2i_ECParameters 135.Fa "EC_KEY **val_out" 136.Fa "const unsigned char **der_in" 137.Fa "long length" 138.Fc 139.Ft int 140.Fo i2d_ECParameters 141.Fa "EC_KEY *val_in" 142.Fa "unsigned char **der_out" 143.Fc 144.Ft EC_KEY * 145.Fo ECParameters_dup 146.Fa "EC_KEY *val_in" 147.Fc 148.Ft EC_KEY * 149.Fo d2i_ECPrivateKey 150.Fa "EC_KEY **val_out" 151.Fa "const unsigned char **der_in" 152.Fa "long length" 153.Fc 154.Ft int 155.Fo i2d_ECPrivateKey 156.Fa "EC_KEY *val_in" 157.Fa "unsigned char **der_out" 158.Fc 159.Ft EC_KEY * 160.Fo d2i_ECPrivateKey_bio 161.Fa "BIO *in_bio" 162.Fa "EC_KEY **val_out" 163.Fc 164.Ft int 165.Fo i2d_ECPrivateKey_bio 166.Fa "BIO *out_bio" 167.Fa "EC_KEY *val_in" 168.Fc 169.Ft EC_KEY * 170.Fo d2i_ECPrivateKey_fp 171.Fa "FILE *in_fp" 172.Fa "EC_KEY **val_out" 173.Fc 174.Ft int 175.Fo i2d_ECPrivateKey_fp 176.Fa "FILE *out_fp" 177.Fa "EC_KEY *val_in" 178.Fc 179.Ft EC_KEY * 180.Fo o2i_ECPublicKey 181.Fa "EC_KEY **val_out" 182.Fa "const unsigned char **der_in" 183.Fa "long length" 184.Fc 185.Ft int 186.Fo i2o_ECPublicKey 187.Fa "const EC_KEY *val_in" 188.Fa "unsigned char **der_out" 189.Fc 190.Ft int 191.Fo ECPKParameters_print 192.Fa "BIO *out_bio" 193.Fa "const EC_GROUP *val_in" 194.Fa "int indent" 195.Fc 196.Ft int 197.Fo ECPKParameters_print_fp 198.Fa "FILE *out_fp" 199.Fa "const EC_GROUP *val_in" 200.Fa "int indent" 201.Fc 202.Ft int 203.Fo ECParameters_print 204.Fa "BIO *out_bio" 205.Fa "const EC_KEY *val_in" 206.Fc 207.Ft int 208.Fo ECParameters_print_fp 209.Fa "FILE *out_fp" 210.Fa "const EC_KEY *val_in" 211.Fc 212.In openssl/x509.h 213.Ft EC_KEY * 214.Fo d2i_EC_PUBKEY 215.Fa "EC_KEY **val_out" 216.Fa "const unsigned char **der_in" 217.Fa "long length" 218.Fc 219.Ft int 220.Fo i2d_EC_PUBKEY 221.Fa "EC_KEY *val_in" 222.Fa "unsigned char **der_out" 223.Fc 224.Ft EC_KEY * 225.Fo d2i_EC_PUBKEY_bio 226.Fa "BIO *in_bio" 227.Fa "EC_KEY **val_out" 228.Fc 229.Ft int 230.Fo i2d_EC_PUBKEY_bio 231.Fa "BIO *out_bio" 232.Fa "EC_KEY *val_in" 233.Fc 234.Ft EC_KEY * 235.Fo d2i_EC_PUBKEY_fp 236.Fa "FILE *in_fp" 237.Fa "EC_KEY **val_out" 238.Fc 239.Ft int 240.Fo i2d_EC_PUBKEY_fp 241.Fa "FILE *out_fp" 242.Fa "EC_KEY *val_in" 243.Fc 244.Sh DESCRIPTION 245These functions decode and encode elliptic curve keys and parameters. 246For details about the semantics, examples, caveats, and bugs, see 247.Xr ASN1_item_d2i 3 . 248.Pp 249.Fn d2i_ECPKParameters 250and 251.Fn i2d_ECPKParameters 252decode and encode the parameters of an elliptic curve. 253.Fn d2i_ECPKParameters_bio , 254.Fn i2d_ECPKParameters_bio , 255.Fn d2i_ECPKParameters_fp , 256and 257.Fn i2d_ECPKParameters_fp 258are similar except that they decode or encode using a 259.Vt BIO 260or 261.Vt FILE 262pointer. 263These four functions are currently implemented as macros. 264.Pp 265.Fn d2i_ECParameters 266does the same parsing as 267.Fn d2i_ECPKParameters 268but saves the result in the 269.Fa group 270field of an 271.Vt EC_KEY 272structure. 273.Pp 274.Fn i2d_ECParameters 275produces the same output as 276.Fn i2d_ECPKParameters 277but uses 278.Fa val_in->group 279for input instead of 280.Fa val_in . 281.Pp 282.Fn ECParameters_dup 283allocates and initializes an empty 284.Vt EC_KEY 285object and copies the EC parameters from 286.Fa val_in 287to it by calling 288.Fn i2d_ECParameters 289and 290.Fn d2i_ECParameters . 291If a private or public key or any flags are present in 292.Fa val_in , 293they are not copied. 294.Pp 295.Fn d2i_ECPrivateKey 296and 297.Fn i2d_ECPrivateKey 298decode and encode an EC private key using an ASN.1 299.Vt ECPrivateKey 300structure defined in RFC 5915 section 3 and used for the privateKey 301field of the ASN.1 302.Vt PrivateKeyInfo 303structure defined in RFC 5208 section 5, see 304.Xr PKCS8_PRIV_KEY_INFO_new 3 . 305.Fn d2i_ECPrivateKey_bio , 306.Fn i2d_ECPrivateKey_bio , 307.Fn d2i_ECPrivateKey_fp , 308and 309.Fn i2d_ECPrivateKey_fp 310are similar except that they decode or encode using a 311.Vt BIO 312or 313.Vt FILE 314pointer. 315.Pp 316.Fn o2i_ECPublicKey 317and 318.Fn i2o_ECPublicKey 319decode and encode an EC public key. 320In contrast to 321.Xr ASN1_item_d2i 3 , 322.Fn o2i_ECPublicKey 323requires 324.Fa val_out , 325.Pf * Fa val_out , 326and 327.Po Pf * Fa val_out Pc Ns -> Ns Fa group 328to be 329.Pf non- Dv NULL . 330.Pp 331.Fn ECPKParameters_print 332and 333.Fn ECPKParameters_print_fp 334print human-readable output of the public parameters of the 335.Vt EC_GROUP 336to 337.Fa out_bio 338or 339.Fa out_fp . 340The output lines are indented by 341.Fa indent 342spaces. 343.Pp 344.Fn ECParameters_print 345and 346.Fn ECParameters_print_fp 347print the parameter components of 348.Fa val_in 349to 350.Fa out_bio 351or 352.Fa out_fp . 353.Pp 354.Fn d2i_EC_PUBKEY 355and 356.Fn i2d_EC_PUBKEY 357decode and encode an EC public key using an ASN.1 358.Vt SubjectPublicKeyInfo 359structure defined in RFC 5280 section 4.1 and documented in 360.Xr X509_PUBKEY_new 3 . 361.Fn d2i_EC_PUBKEY_bio , 362.Fn i2d_EC_PUBKEY_bio , 363.Fn d2i_EC_PUBKEY_fp , 364and 365.Fn i2d_EC_PUBKEY_fp 366are similar except that they decode or encode using a 367.Vt BIO 368or 369.Vt FILE 370pointer. 371.Sh RETURN VALUES 372.Fn d2i_ECPKParameters , 373.Fn d2i_ECPKParameters_bio , 374and 375.Fn d2i_ECPKParameters_fp 376return a valid 377.Vt EC_GROUP 378structure or 379.Dv NULL 380if an error occurs. 381.Pp 382.Fn d2i_ECParameters , 383.Fn ECParameters_dup , 384.Fn d2i_ECPrivateKey , 385.Fn d2i_ECPrivateKey_bio , 386.Fn d2i_ECPrivateKey_fp , 387.Fn o2i_ECPublicKey , 388.Fn d2i_EC_PUBKEY , 389.Fn d2i_EC_PUBKEY_bio , 390and 391.Fn d2i_EC_PUBKEY_fp 392return a valid 393.Vt EC_KEY 394structure or 395.Dv NULL 396if an error occurs. 397.Pp 398.Fn i2d_ECPKParameters , 399.Fn i2d_ECParameters , 400.Fn i2d_ECPrivateKey , 401.Fn i2o_ECPublicKey , 402and 403.Fn i2d_EC_PUBKEY 404return the number of bytes successfully encoded or a negative value if 405an error occurs. 406.Pp 407.Fn i2d_ECPKParameters_bio , 408.Fn i2d_ECPKParameters_fp , 409.Fn i2d_ECPrivateKey_bio , 410.Fn i2d_ECPrivateKey_fp , 411.Fn ECPKParameters_print , 412.Fn ECPKParameters_print_fp , 413.Fn ECParameters_print , 414.Fn ECParameters_print_fp , 415.Fn i2d_EC_PUBKEY_bio , 416and 417.Fn i2d_EC_PUBKEY_fp 418return 1 for success or 0 if an error occurs. 419.Sh SEE ALSO 420.Xr ASN1_item_d2i 3 , 421.Xr EC_GROUP_copy 3 , 422.Xr EC_GROUP_new 3 , 423.Xr EC_KEY_new 3 , 424.Xr EVP_PKEY_set1_EC_KEY 3 , 425.Xr PEM_write_ECPrivateKey 3 , 426.Xr PKCS8_PRIV_KEY_INFO_new 3 , 427.Xr X509_PUBKEY_new 3 428.Sh STANDARDS 429RFC 5915: Elliptic Curve Private Key Structure 430.Pp 431RFC 5208: Public-Key Cryptography Standards (PKCS) #8: 432Private-Key Information Syntax Specification 433.Pp 434RFC 5280: Internet X.509 Public Key Infrastructure Certificate and 435Certificate Revocation List (CRL) Profile, 436section 4.1: Basic Certificate Fields 437.Sh HISTORY 438.Fn d2i_ECPKParameters , 439.Fn i2d_ECPKParameters , 440.Fn d2i_ECPKParameters_bio , 441.Fn i2d_ECPKParameters_bio , 442.Fn d2i_ECPKParameters_fP , 443.Fn i2d_ECPKParameters_fp , 444.Fn d2i_ECParameters , 445.Fn i2d_ECParameters , 446.Fn ECParameters_dup , 447.Fn d2i_ECPrivateKey , 448.Fn i2d_ECPrivateKey , 449.Fn d2i_ECPrivateKey_bio , 450.Fn i2d_ECPrivateKey_bio , 451.Fn d2i_ECPrivateKey_fp , 452.Fn i2d_ECPrivateKey_fp , 453.Fn o2i_ECPublicKey , 454.Fn i2o_ECPublicKey , 455.Fn ECPKParameters_print , 456.Fn ECPKParameters_print_fp , 457.Fn ECParameters_print , 458.Fn ECParameters_print_fp , 459.Fn d2i_EC_PUBKEY , 460.Fn i2d_EC_PUBKEY , 461.Fn d2i_EC_PUBKEY_bio , 462.Fn i2d_EC_PUBKEY_bio , 463.Fn d2i_EC_PUBKEY_fp , 464and 465.Fn i2d_EC_PUBKEY_fp 466first appeared in OpenSSL 0.9.8 and have been available since 467.Ox 4.5 . 468