選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 

255 行
11 KiB

  1. /*******************************************************************************
  2. File Name:
  3. m2m_ssl.h
  4. Summary:
  5. WINC SSL Interface.
  6. Description:
  7. WINC SSL Interface.
  8. *******************************************************************************/
  9. //DOM-IGNORE-BEGIN
  10. /*******************************************************************************
  11. * Copyright (C) 2021 Microchip Technology Inc. and its subsidiaries.
  12. *
  13. * Subject to your compliance with these terms, you may use Microchip software
  14. * and any derivatives exclusively with Microchip products. It is your
  15. * responsibility to comply with third party license terms applicable to your
  16. * use of third party software (including open source software) that may
  17. * accompany Microchip software.
  18. *
  19. * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
  20. * EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
  21. * WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
  22. * PARTICULAR PURPOSE.
  23. *
  24. * IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
  25. * INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
  26. * WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
  27. * BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
  28. * FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN
  29. * ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
  30. * THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
  31. *******************************************************************************/
  32. //DOM-IGNORE-END
  33. /** @defgroup SSLAPI SSL
  34. @brief
  35. Provides a description of the SSL Layer.
  36. @{
  37. @defgroup SSLCallbacks Callbacks
  38. @brief
  39. Provides detail on the available callbacks for the SSL Layer.
  40. @defgroup SSLEnums Enumerations and Typedefs
  41. @brief
  42. Specifies the enums and Data Structures used by the SSL APIs.
  43. @defgroup SSLFUNCTIONS Functions
  44. @brief
  45. Provides detail on the available APIs for the SSL Layer.
  46. @}
  47. */
  48. #ifndef __M2M_SSL_H__
  49. #define __M2M_SSL_H__
  50. /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
  51. INCLUDES
  52. *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
  53. #include "nm_common.h"
  54. #include "m2m_types.h"
  55. #include "nmdrv.h"
  56. #include "ecc_types.h"
  57. #include "socket.h"
  58. /*!
  59. @ingroup SSLCallbacks
  60. @typedef void (*tpfAppSSLCb)(uint8_t u8MsgType, void* pvMsg);
  61. @brief A callback to get SSL notifications.
  62. @param[in] u8MsgType
  63. The type of the message received.
  64. @param[in] pvMsg
  65. A structure to provide notification payload.
  66. */
  67. typedef void (*tpfAppSSLCb)(uint8_t u8MsgType, void *pvMsg);
  68. /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
  69. FUNCTION PROTOTYPES
  70. *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
  71. /*!
  72. @ingroup SSLFUNCTIONS
  73. @fn int8_t m2m_ssl_init(tpfAppSSLCb pfAppSSLCb);
  74. @brief Initializes the SSL layer.
  75. @param[in] pfAppSSLCb
  76. Application SSL callback function.
  77. @return The function returns @ref M2M_SUCCESS for success and a negative value otherwise.
  78. */
  79. int8_t m2m_ssl_init(tpfAppSSLCb pfAppSSLCb);
  80. /*!
  81. @ingroup SSLFUNCTIONS
  82. @fn int8_t m2m_ssl_handshake_rsp(tstrEccReqInfo* strECCResp, uint8_t* pu8RspDataBuff, uint16_t u16RspDataSz);
  83. @brief Sends ECC responses to the WINC.
  84. @param[in] strECCResp
  85. ECC Response struct.
  86. @param[in] pu8RspDataBuff
  87. Pointer of the response data to be sent.
  88. @param[in] u16RspDataSz
  89. Response data size.
  90. @return The function returns @ref M2M_SUCCESS for success and a negative value otherwise.
  91. */
  92. int8_t m2m_ssl_handshake_rsp(tstrEccReqInfo *strECCResp, uint8_t *pu8RspDataBuff, uint16_t u16RspDataSz);
  93. /*!
  94. @ingroup SSLFUNCTIONS
  95. @fn int8_t m2m_ssl_send_certs_to_winc(uint8_t* pu8Buffer, uint32_t u32BufferSz);
  96. @brief Sends certificates to the WINC.
  97. @param[in] pu8Buffer
  98. Pointer to the certificates. The buffer format must match the format of @ref tstrTlsSrvSecHdr.
  99. @param[in] u32BufferSz
  100. Size of the certificates.
  101. @return The function returns @ref M2M_SUCCESS for success and a negative value otherwise.
  102. */
  103. int8_t m2m_ssl_send_certs_to_winc(uint8_t *pu8Buffer, uint32_t u32BufferSz);
  104. /*!
  105. @ingroup SSLFUNCTIONS
  106. @fn int8_t m2m_ssl_retrieve_next_for_verifying(tenuEcNamedCurve *penuCurve, uint8_t *pu8Value, uint16_t *pu16ValueSz, uint8_t *pu8Sig, uint16_t *pu16SigSz, tstrECPoint *pstrKey);
  107. @brief Retrieve the next set of information from the WINC for ECDSA verification.
  108. @param[out] penuCurve
  109. The named curve.
  110. @param[out] pu8Value
  111. Value retrieved for verification. This is the digest of the message, truncated/prepended to the appropriate size.
  112. @param[inout] pu16ValueSz
  113. in: Size of value buffer provided by caller.
  114. out: Size of value retrieved (provided for convenience; the value size is in fact determined by the curve).
  115. @param[out] pu8Sig
  116. Signature retrieved for verification.
  117. @param[inout] pu16SigSz
  118. in: Size of signature buffer provided by caller.
  119. out: Size of signature retrieved (provided for convenience; the signature size is in fact determined by the curve).
  120. @param[out] pstrKey
  121. Public key retrieved for verification.
  122. @return The function returns @ref M2M_SUCCESS for success and a negative value otherwise.
  123. @pre This function should only be called after the application has been notified that
  124. verification information is ready via @ref ECC_REQ_SIGN_VERIFY.
  125. @warning If this function returns @ref M2M_ERR_FAIL, then any remaining verification info from
  126. the WINC is lost.
  127. */
  128. int8_t m2m_ssl_retrieve_next_for_verifying(tenuEcNamedCurve *penuCurve, uint8_t *pu8Value, uint16_t *pu16ValueSz, uint8_t *pu8Sig, uint16_t *pu16SigSz, tstrECPoint *pstrKey);
  129. /*!
  130. @ingroup SSLFUNCTIONS
  131. @fn int8_t m2m_ssl_retrieve_cert(uint16_t *pu16Curve, uint8_t *pu8Value, uint8_t *pu8Sig, tstrECPoint *pstrKey);
  132. @brief Retrieve the next set of information from the WINC for ECDSA verification.
  133. @param[out] pu16Curve
  134. The named curve, to be cast to type @ref tenuEcNamedCurve.
  135. @param[out] pu8Value
  136. Value retrieved for verification. This is the digest of the message, truncated/prepended to the appropriate size.
  137. The size of the value is equal to the field size of the curve, hence is determined by pu16Curve.
  138. @param[out] pu8Sig
  139. Signature retrieved for verification.
  140. The size of the signature is equal to twice the field size of the curve, hence is determined by pu16Curve.
  141. @param[out] pstrKey
  142. Public key retrieved for verification.
  143. @return The function returns @ref M2M_SUCCESS for success and a negative value otherwise.
  144. @pre This function should only be called after the application has been notified that
  145. verification information is ready via @ref ECC_REQ_SIGN_VERIFY.
  146. @warning If this function returns @ref M2M_ERR_FAIL, then any remaining verification info from
  147. the WINC is lost.
  148. @warning This API has been deprecated and is kept for legacy purposes only. It is recommended
  149. that @ref m2m_ssl_retrieve_next_for_verifying is used instead.
  150. */
  151. int8_t m2m_ssl_retrieve_cert(uint16_t *pu16Curve, uint8_t *pu8Value, uint8_t *pu8Sig, tstrECPoint *pstrKey);
  152. /*!
  153. @ingroup SSLFUNCTIONS
  154. @fn int8_t m2m_ssl_retrieve_hash(uint8_t *pu8Value, uint16_t u16ValueSz)
  155. @brief Retrieve the value from the WINC for ECDSA signing.
  156. @param[out] pu8Value
  157. Value retrieved for signing. This is the digest of the message, truncated/prepended to the appropriate size.
  158. @param[in] u16ValueSz
  159. Size of value to be retrieved. (The application should obtain this information,
  160. along with the curve, from the associated @ref ECC_REQ_SIGN_GEN notification.)
  161. @return The function returns @ref M2M_SUCCESS for success and a negative value otherwise.
  162. @pre This function should only be called after the application has been notified that
  163. signing information is ready via @ref ECC_REQ_SIGN_GEN.
  164. @warning If this function returns @ref M2M_ERR_FAIL, then the value for signing is lost.
  165. */
  166. int8_t m2m_ssl_retrieve_hash(uint8_t *pu8Value, uint16_t u16ValueSz);
  167. /*!
  168. @ingroup SSLFUNCTIONS
  169. @fn void m2m_ssl_stop_retrieving(void);
  170. @brief Allow SSL driver to tidy up when the application chooses not to retrieve all available
  171. information.
  172. @return None.
  173. @warning The application must call this function if it has been notified (via
  174. @ref ECC_REQ_SIGN_GEN or @ref ECC_REQ_SIGN_VERIFY) that information is available for
  175. retrieving from the WINC, but chooses not to retrieve it all.
  176. The application must not call this function if it has retrieved all the available
  177. information, or if a retrieve function returned @ref M2M_ERR_FAIL indicating that any
  178. remaining information has been lost.
  179. @see m2m_ssl_retrieve_next_for_verifying\n
  180. m2m_ssl_retrieve_cert\n
  181. m2m_ssl_retrieve_hash
  182. */
  183. void m2m_ssl_stop_retrieving(void);
  184. /*!
  185. @ingroup SSLFUNCTIONS
  186. @fn NMI_API void m2m_ssl_stop_processing_certs(void);
  187. @brief Allow SSL driver to tidy up in case application does not read all available certificates.
  188. @return None.
  189. @warning This API has been deprecated and is kept for legacy purposes only. It is recommended
  190. that @ref m2m_ssl_stop_retrieving is used instead.
  191. */
  192. void m2m_ssl_stop_processing_certs(void);
  193. /*!
  194. @ingroup SSLFUNCTIONS
  195. @fn void m2m_ssl_ecc_process_done(void);
  196. @brief Allow SSL driver to tidy up after application has finished processing ECC message.
  197. @return None.
  198. @warning The application should call this function after receiving an SSL callback with message
  199. type @ref M2M_SSL_REQ_ECC, after retrieving any related information, and before
  200. calling @ref m2m_ssl_handshake_rsp.
  201. */
  202. void m2m_ssl_ecc_process_done(void);
  203. /*!
  204. @ingroup SSLFUNCTIONS
  205. @fn int8_t m2m_ssl_set_active_ciphersuites(uint32_t u32SslCsBMP);
  206. @brief Sets the active ciphersuites.
  207. @details Override the default Active SSL ciphers in the SSL module with a certain combination selected by
  208. the caller in the form of a bitmap containing the required ciphers to be on.\n
  209. There is no need to call this function if the application will not change the default ciphersuites.
  210. @param[in] u32SslCsBMP
  211. Bitmap containing the desired ciphers to be enabled for the SSL module. The ciphersuites are defined in
  212. @ref SSLCipherSuiteID.
  213. The default ciphersuites are all ciphersuites supported by the firmware with the exception of ECC ciphersuites.
  214. The caller can override the default with any desired combination.
  215. If u32SslCsBMP does not contain any ciphersuites supported by firmware, then the current active list will not
  216. change.
  217. @return The function returns @ref M2M_SUCCESS for success and a negative value otherwise.
  218. */
  219. int8_t m2m_ssl_set_active_ciphersuites(uint32_t u32SslCsBMP);
  220. #endif /* __M2M_SSL_H__ */