ssl_pkey.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #ifndef _SSL_PKEY_H_
  14. #define _SSL_PKEY_H_
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #include "ssl_types.h"
  19. /**
  20. * @brief create a private key object according to input private key
  21. *
  22. * @param ipk - input private key point
  23. *
  24. * @return new private key object point
  25. */
  26. EVP_PKEY* __EVP_PKEY_new(EVP_PKEY *ipk);
  27. /**
  28. * @brief create a private key object
  29. *
  30. * @param none
  31. *
  32. * @return private key object point
  33. */
  34. EVP_PKEY* EVP_PKEY_new(void);
  35. /**
  36. * @brief load a character key context into system context. If '*a' is pointed to the
  37. * private key, then load key into it. Or create a new private key object
  38. *
  39. * @param type - private key type
  40. * @param a - a point pointed to a private key point
  41. * @param pp - a point pointed to the key context memory point
  42. * @param length - key bytes
  43. *
  44. * @return private key object point
  45. */
  46. EVP_PKEY* d2i_PrivateKey(int type,
  47. EVP_PKEY **a,
  48. const unsigned char **pp,
  49. long length);
  50. /**
  51. * @brief decodes and load a buffer BIO into a EVP key context. If '*a' is pointed to the
  52. * private key, then load key into it. Or create a new private key object
  53. *
  54. * @param bp BIO object containing the key
  55. * @param a Pointer to an existing EVP_KEY or NULL if a new key shall be created
  56. *
  57. * @return Created or updated EVP_PKEY
  58. */
  59. EVP_PKEY *d2i_PrivateKey_bio(BIO *bp, EVP_PKEY **a);
  60. /**
  61. * @brief Same as d2i_PrivateKey_bio
  62. *
  63. * @param bp BIO object containing the key
  64. * @param a Pointer to an existing EVP_KEY or NULL if a new key shall be created
  65. *
  66. * @return Created or updated EVP_PKEY
  67. */
  68. RSA *d2i_RSAPrivateKey_bio(BIO *bp,RSA **rsa);
  69. /**
  70. * @brief loads a private key in PEM format from BIO object
  71. *
  72. * @param bp BIO object containing the key
  73. * @param x Pointer to an existent PKEY or NULL if a new key shall be created
  74. * @param cb Password callback (not used)
  75. * @param u User context (not used)
  76. *
  77. * @return Created or updated EVP_PKEY
  78. */
  79. EVP_PKEY *PEM_read_bio_PrivateKey(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, void *u);
  80. /**
  81. * @brief RSA key in PEM format from BIO object
  82. *
  83. * @param bp BIO object containing the key
  84. * @param x Pointer to an existent PKEY or NULL if a new key shall be created
  85. * @param cb Password callback (not used)
  86. * @param u User context (not used)
  87. *
  88. * @return Created or updated EVP_PKEY
  89. */
  90. RSA *PEM_read_bio_RSAPrivateKey(BIO *bp, RSA **rsa, pem_password_cb *cb, void *u);
  91. /**
  92. * @brief free a private key object
  93. *
  94. * @param pkey - private key object point
  95. *
  96. * @return none
  97. */
  98. void EVP_PKEY_free(EVP_PKEY *x);
  99. /**
  100. * @brief load private key into the SSL
  101. *
  102. * @param type - private key type
  103. * @param ssl - SSL point
  104. * @param len - data bytes
  105. * @param d - data point
  106. *
  107. * @return result
  108. * 0 : failed
  109. * 1 : OK
  110. */
  111. int SSL_use_PrivateKey_ASN1(int type, SSL *ssl, const unsigned char *d, long len);
  112. #ifdef __cplusplus
  113. }
  114. #endif
  115. #endif