You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

212 lines
6.2 KiB

  1. /**
  2. *
  3. * \file
  4. *
  5. * \brief WINC3400 Crypto API
  6. *
  7. * Copyright (c) 2016-2018 Microchip Technology Inc. and its subsidiaries.
  8. *
  9. * \asf_license_start
  10. *
  11. * \page License
  12. *
  13. * Subject to your compliance with these terms, you may use Microchip
  14. * software and any derivatives exclusively with Microchip products.
  15. * It is your responsibility to comply with third party license terms applicable
  16. * to your use of third party software (including open source software) that
  17. * may accompany Microchip software.
  18. *
  19. * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
  20. * WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
  21. * INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
  22. * AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
  23. * LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
  24. * LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
  25. * SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
  26. * POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
  27. * ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
  28. * RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
  29. * THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
  30. *
  31. * \asf_license_stop
  32. *
  33. */
  34. #ifndef __M2M_CRYPTO_H__
  35. #define __M2M_CRYPTO_H__
  36. /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
  37. INCLUDES
  38. *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
  39. #include "common/include/nm_common.h"
  40. #include "driver/include/m2m_types.h"
  41. /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
  42. MACROS
  43. *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
  44. #define M2M_SHA256_CONTEXT_BUFF_LEN 128
  45. #define M2M_SHA256_DIGEST_LEN 32
  46. /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
  47. DATA TYPES
  48. *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
  49. /*!
  50. @struct \
  51. tstrM2mSha256Ctxt
  52. @brief
  53. SHA256 context data
  54. */
  55. typedef struct sha256ctxt{
  56. uint32 au32Sha256CtxtBuff[M2M_SHA256_CONTEXT_BUFF_LEN/sizeof(uint32)];
  57. } tstrM2mSha256Ctxt;
  58. /*!
  59. @enum \
  60. tenuRsaSignStatus
  61. @brief
  62. RSA Signature status: pass or fail.
  63. */
  64. typedef enum{
  65. M2M_RSA_SIGN_OK,
  66. M2M_RSA_SIGN_FAIL
  67. } tenuRsaSignStatus;
  68. /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
  69. FUNCTION PROTOTYPES
  70. *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
  71. #ifdef __cplusplus
  72. extern "C" {
  73. #endif
  74. /*!
  75. @fn \
  76. sint8 m2m_sha256_hash_init(tstrM2mSha256Ctxt *psha256Ctxt);
  77. @brief SHA256 hash initialization
  78. @param[in] psha256Ctxt
  79. Pointer to a sha256 context allocated by the caller.
  80. */
  81. sint8 m2m_sha256_hash_init(tstrM2mSha256Ctxt *psha256Ctxt);
  82. /*!
  83. @fn \
  84. sint8 m2m_sha256_hash_update(tstrM2mSha256Ctxt *psha256Ctxt, uint8 *pu8Data, uint16 u16DataLength);
  85. @brief SHA256 hash update
  86. @param [in] psha256Ctxt
  87. Pointer to the sha256 context.
  88. @param [in] pu8Data
  89. Buffer holding the data submitted to the hash.
  90. @param [in] u16DataLength
  91. Size of the data bufefr in bytes.
  92. */
  93. sint8 m2m_sha256_hash_update(tstrM2mSha256Ctxt *psha256Ctxt, uint8 *pu8Data, uint16 u16DataLength);
  94. /*!
  95. @fn \
  96. sint8 m2m_sha256_hash_finish(tstrM2mSha256Ctxt *psha256Ctxt, uint8 *pu8Sha256Digest);
  97. @brief SHA256 hash finalization
  98. @param[in] psha256Ctxt
  99. Pointer to a sha256 context allocated by the caller.
  100. @param [in] pu8Sha256Digest
  101. Buffer allocated by the caller which will hold the resultant SHA256 Digest. It must be allocated no less than M2M_SHA256_DIGEST_LEN.
  102. */
  103. sint8 m2m_sha256_hash_finish(tstrM2mSha256Ctxt *psha256Ctxt, uint8 *pu8Sha256Digest);
  104. /*!
  105. @fn \
  106. sint8 m2m_rsa_sign_verify(uint8 *pu8N, uint16 u16NSize, uint8 *pu8E, uint16 u16ESize, uint8 *pu8SignedMsgHash, \
  107. uint16 u16HashLength, uint8 *pu8RsaSignature);
  108. @brief RSA Signature Verification
  109. The function shall request the RSA Signature verification from the WINC Firmware for the given message. The signed message shall be
  110. compressed to the corresponding hash algorithm before calling this function.
  111. The hash type is identified by the given hash length. For example, if the hash length is 32 bytes, then it is SHA256.
  112. @param[in] pu8N
  113. RSA Key modulus n.
  114. @param[in] u16NSize
  115. Size of the RSA modulus n in bytes.
  116. @param[in] pu8E
  117. RSA public exponent.
  118. @param[in] u16ESize
  119. Size of the RSA public exponent in bytes.
  120. @param[in] pu8SignedMsgHash
  121. The hash digest of the signed message.
  122. @param[in] u16HashLength
  123. The length of the hash digest.
  124. @param[out] pu8RsaSignature
  125. Signature value to be verified.
  126. */
  127. sint8 m2m_rsa_sign_verify(uint8 *pu8N, uint16 u16NSize, uint8 *pu8E, uint16 u16ESize, uint8 *pu8SignedMsgHash,
  128. uint16 u16HashLength, uint8 *pu8RsaSignature);
  129. /*!
  130. @fn \
  131. sint8 m2m_rsa_sign_gen(uint8 *pu8N, uint16 u16NSize, uint8 *pu8d, uint16 u16dSize, uint8 *pu8SignedMsgHash, \
  132. uint16 u16HashLength, uint8 *pu8RsaSignature);
  133. @brief RSA Signature Generation
  134. The function shall request the RSA Signature generation from the WINC Firmware for the given message. The signed message shall be
  135. compressed to the corresponding hash algorithm before calling this function.
  136. The hash type is identified by the given hash length. For example, if the hash length is 32 bytes, then it is SHA256.
  137. @param[in] pu8N
  138. RSA Key modulus n.
  139. @param[in] u16NSize
  140. Size of the RSA modulus n in bytes.
  141. @param[in] pu8d
  142. RSA private exponent.
  143. @param[in] u16dSize
  144. Size of the RSA private exponent in bytes.
  145. @param[in] pu8SignedMsgHash
  146. The hash digest of the signed message.
  147. @param[in] u16HashLength
  148. The length of the hash digest.
  149. @param[out] pu8RsaSignature
  150. Pointer to a user buffer allocated by teh caller shall hold the generated signature.
  151. */
  152. sint8 m2m_rsa_sign_gen(uint8 *pu8N, uint16 u16NSize, uint8 *pu8d, uint16 u16dSize, uint8 *pu8SignedMsgHash,
  153. uint16 u16HashLength, uint8 *pu8RsaSignature);
  154. #ifdef __cplusplus
  155. }
  156. #endif
  157. #endif /* __M2M_CRYPTO_H__ */