2
0

d2i_PrivateKey.pod 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. =pod
  2. =head1 NAME
  3. d2i_PrivateKey_ex, d2i_PrivateKey, d2i_PublicKey, d2i_KeyParams,
  4. d2i_AutoPrivateKey_ex, d2i_AutoPrivateKey, i2d_PrivateKey, i2d_PublicKey,
  5. i2d_KeyParams, i2d_KeyParams_bio, d2i_PrivateKey_ex_bio, d2i_PrivateKey_bio,
  6. d2i_PrivateKey_ex_fp, d2i_PrivateKey_fp, d2i_KeyParams_bio, i2d_PrivateKey_bio,
  7. i2d_PrivateKey_fp
  8. - decode and encode functions for reading and saving EVP_PKEY structures
  9. =head1 SYNOPSIS
  10. #include <openssl/evp.h>
  11. EVP_PKEY *d2i_PrivateKey_ex(int type, EVP_PKEY **a, const unsigned char **pp,
  12. long length, OSSL_LIB_CTX *libctx,
  13. const char *propq);
  14. EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **a, const unsigned char **pp,
  15. long length);
  16. EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, const unsigned char **pp,
  17. long length);
  18. EVP_PKEY *d2i_KeyParams(int type, EVP_PKEY **a, const unsigned char **pp,
  19. long length);
  20. EVP_PKEY *d2i_AutoPrivateKey_ex(EVP_PKEY **a, const unsigned char **pp,
  21. long length, OSSL_LIB_CTX *libctx,
  22. const char *propq);
  23. EVP_PKEY *d2i_AutoPrivateKey(EVP_PKEY **a, const unsigned char **pp,
  24. long length);
  25. int i2d_PrivateKey(const EVP_PKEY *a, unsigned char **pp);
  26. int i2d_PublicKey(const EVP_PKEY *a, unsigned char **pp);
  27. int i2d_KeyParams(const EVP_PKEY *a, unsigned char **pp);
  28. int i2d_KeyParams_bio(BIO *bp, const EVP_PKEY *pkey);
  29. EVP_PKEY *d2i_KeyParams_bio(int type, EVP_PKEY **a, BIO *in);
  30. #include <openssl/x509.h>
  31. EVP_PKEY *d2i_PrivateKey_ex_bio(BIO *bp, EVP_PKEY **a, OSSL_LIB_CTX *libctx,
  32. const char *propq);
  33. EVP_PKEY *d2i_PrivateKey_bio(BIO *bp, EVP_PKEY **a);
  34. EVP_PKEY *d2i_PrivateKey_ex_fp(FILE *fp, EVP_PKEY **a, OSSL_LIB_CTX *libctx,
  35. const char *propq);
  36. EVP_PKEY *d2i_PrivateKey_fp(FILE *fp, EVP_PKEY **a);
  37. int i2d_PrivateKey_bio(BIO *bp, const EVP_PKEY *pkey);
  38. int i2d_PrivateKey_fp(FILE *fp, const EVP_PKEY *pkey);
  39. =head1 DESCRIPTION
  40. d2i_PrivateKey_ex() decodes a private key using algorithm I<type>. It attempts
  41. to use any key-specific format or PKCS#8 unencrypted PrivateKeyInfo format.
  42. The I<type> parameter should be a public key algorithm constant such as
  43. B<EVP_PKEY_RSA>. An error occurs if the decoded key does not match I<type>. Some
  44. private key decoding implementations may use cryptographic algorithms (for
  45. example to automatically derive the public key if it is not explicitly
  46. included in the encoding). In this case the supplied library context I<libctx>
  47. and property query string I<propq> are used.
  48. If successful and the I<a> parameter is not NULL the function assigns the
  49. returned B<EVP_PKEY> structure pointer to I<*a>, overwriting any previous value.
  50. d2i_PrivateKey() does the same as d2i_PrivateKey_ex() except that the default
  51. library context and property query string are used.
  52. d2i_PublicKey() does the same for public keys.
  53. d2i_KeyParams() does the same for key parameters.
  54. The d2i_PrivateKey_ex_bio() and d2i_PrivateKey_bio() functions are similar to
  55. d2i_PrivateKey_ex() and d2i_PrivateKey() respectively except that they decode
  56. the data read from the given BIO. The d2i_PrivateKey_ex_fp() and
  57. d2i_PrivateKey_fp() functions are the same except that they read the data from
  58. the given FILE.
  59. d2i_AutoPrivateKey_ex() and d2i_AutoPrivateKey() are similar to
  60. d2i_PrivateKey_ex() and d2i_PrivateKey() respectively except that they attempt
  61. to automatically detect the private key format.
  62. i2d_PrivateKey() encodes I<a>. It uses a key specific format or, if none is
  63. defined for that key type, PKCS#8 unencrypted PrivateKeyInfo format.
  64. i2d_PublicKey() does the same for public keys.
  65. i2d_KeyParams() does the same for key parameters.
  66. These functions are similar to the d2i_X509() functions; see L<d2i_X509(3)>.
  67. i2d_PrivateKey_bio() and i2d_PrivateKey_fp() do the same thing except that they
  68. encode to a B<BIO> or B<FILE> respectively. Again, these work similarly to the
  69. functions described in L<d2i_X509(3)>.
  70. =head1 NOTES
  71. All the functions that operate on data in memory update the data pointer I<*pp>
  72. after a successful operation, just like the other d2i and i2d functions;
  73. see L<d2i_X509(3)>.
  74. All these functions use DER format and unencrypted keys. Applications wishing
  75. to encrypt or decrypt private keys should use other functions such as
  76. d2i_PKCS8PrivateKey() instead.
  77. To decode a key with type B<EVP_PKEY_EC>, d2i_PublicKey() requires I<*a> to be
  78. a non-NULL EVP_PKEY structure assigned an EC_KEY structure referencing the proper
  79. EC_GROUP.
  80. =head1 RETURN VALUES
  81. The d2i_PrivateKey_ex(), d2i_PrivateKey(), d2i_AutoPrivateKey_ex(),
  82. d2i_AutoPrivateKey(), d2i_PrivateKey_ex_bio(), d2i_PrivateKey_bio(),
  83. d2i_PrivateKey_ex_fp(), d2i_PrivateKey_fp(), d2i_PublicKey(), d2i_KeyParams()
  84. and d2i_KeyParams_bio() functions return a valid B<EVP_PKEY> structure or NULL if
  85. an error occurs. The error code can be obtained by calling L<ERR_get_error(3)>.
  86. i2d_PrivateKey(), i2d_PublicKey() and i2d_KeyParams() return the number of
  87. bytes successfully encoded or a negative value if an error occurs. The error
  88. code can be obtained by calling L<ERR_get_error(3)>.
  89. i2d_PrivateKey_bio(), i2d_PrivateKey_fp() and i2d_KeyParams_bio() return 1 if
  90. successfully encoded or zero if an error occurs.
  91. =head1 SEE ALSO
  92. L<crypto(7)>,
  93. L<d2i_PKCS8PrivateKey_bio(3)>
  94. =head1 HISTORY
  95. d2i_PrivateKey_ex(), d2i_PrivateKey_ex_bio(), d2i_PrivateKey_ex_fp(), and
  96. d2i_AutoPrivateKey_ex() were added in OpenSSL 3.0.
  97. =head1 COPYRIGHT
  98. Copyright 2017-2021 The OpenSSL Project Authors. All Rights Reserved.
  99. Licensed under the Apache License 2.0 (the "License"). You may not use
  100. this file except in compliance with the License. You can obtain a copy
  101. in the file LICENSE in the source distribution or at
  102. L<https://www.openssl.org/source/license.html>.
  103. =cut