drv_secure.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /* Copyright (C) 2018 RDA Technologies Limited and/or its affiliates("RDA").
  2. * All rights reserved.
  3. *
  4. * This software is supplied "AS IS" without any warranties.
  5. * RDA assumes no responsibility or liability for the use of the software,
  6. * conveys no license or title under any patent, copyright, or mask work
  7. * right to the product. RDA reserves the right to make changes in the
  8. * software without notification. RDA also make no representation or
  9. * warranty that such application will be suitable for the specified use
  10. * without further testing or modification.
  11. */
  12. #ifndef _DRV_SECURE_H_
  13. #define _DRV_SECURE_H_
  14. #include "osi_compiler.h"
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. /** 8910 image signature size */
  19. #define DRV_SECURE_BOOT_SIG_SIZE_8910 (608)
  20. /**
  21. * \brief opaque data structure for sig checker
  22. *
  23. * \p drvSigChecker_t is for signature checking, without holding all data
  24. * in RAM. Rather the data to be checked can be feed progressly. For example:
  25. *
  26. * \code{.cpp}
  27. * if (!drvSecureBootEnable())
  28. * return true;
  29. *
  30. * drvSigChecker_t *check = drvSigCheckerCreate(sig);
  31. * drvSigCheckerUpdate(check, data1, size1);
  32. * drvSigCheckerUpdate(check, data2, size2);
  33. * // ......
  34. * bool result = drvSigCheckerFinalCheck(check);
  35. * drvSigCheckerDelete(checker);
  36. * return result;
  37. * \endcode
  38. *
  39. * For progressive signature checker, it is recommended to check whether
  40. * secure boot is enabled beforehand.
  41. */
  42. typedef struct drvSigChecker drvSigChecker_t;
  43. /**
  44. * \brief Read the security flag from efuse
  45. *
  46. * \return
  47. * - true secure boot is enable.
  48. * - false secure boot is disable.
  49. */
  50. bool drvSecureBootEnable(void);
  51. /**
  52. * \brief Write the security flag into the efuse
  53. *
  54. * When secure boot is already enabled, this will return true directly.
  55. *
  56. * When bootloader is not signed, it will return false.
  57. *
  58. * It is possible to write multiple efuse bits inside. If there are power
  59. * failure during that, it is possible that efuse bits will be
  60. * inconsistent. And then the system will be unusable.
  61. *
  62. * \return
  63. * - true on success
  64. * - false on fail
  65. */
  66. bool drvSecureWriteSecureFlags(void);
  67. /**
  68. * \brief Get UID
  69. *
  70. * UID is a chip unique information. It can be used as unique
  71. * identification of chip. Also, development certification will use this.
  72. *
  73. * \param id output UID
  74. * \return
  75. * - true on success
  76. * - false on fail
  77. */
  78. bool drvGetUId(osiBits64_t *id);
  79. /**
  80. * \brief create a signature checker
  81. *
  82. * Signature check will use public key in efuse, so caller should call this
  83. * only when there are valid public key in efuse.
  84. *
  85. * \param sig signature, the memory can be released after this call
  86. * \return
  87. * - signature checker instance
  88. * - NULL on error, invalid parameter or out of memory
  89. */
  90. drvSigChecker_t *drvSigCheckerCreate(const void *sig);
  91. /**
  92. * \brief delete the signature checker
  93. *
  94. * \param checker signature checker
  95. */
  96. void drvSigCheckerDelete(drvSigChecker_t *checker);
  97. /**
  98. * \brief update data to be signed to signature checker
  99. *
  100. * \param checker signature checker
  101. * \param data data to be signed
  102. * \param size data size
  103. */
  104. void drvSigCheckerUpdate(drvSigChecker_t *checker, const void *data, uint32_t size);
  105. /**
  106. * \brief finalize signature checker, and check signature
  107. *
  108. * \param checker signature checker
  109. * \return
  110. * - true on success
  111. * - false on signature check fail
  112. */
  113. bool drvSigCheckerFinalCheck(drvSigChecker_t *checker);
  114. /**
  115. * \brief signature check with combined data and signature
  116. *
  117. * Signature check will use public key in efuse, so caller should call this
  118. * only when there are valid public key in efuse.
  119. *
  120. * The signature size of 8910 is fixed as \p DRV_SECURE_BOOT_SIG_SIZE_8910.
  121. * And the signature is at the end of \p data.
  122. *
  123. * \param data combined data to be signed and signature
  124. * \param size total size of data and signature
  125. * \return
  126. * - true on success
  127. * - false on fail, invalid parameters or verify fail
  128. */
  129. bool drvSecureEmbedSigCheck(const void *data, uint32_t size);
  130. /**
  131. * \brief signature check with separated data and signature
  132. *
  133. * Signature check will use public key in efuse, so caller should call this
  134. * only when there are valid public key in efuse.
  135. *
  136. * The signature size of 8910 is fixed as \p DRV_SECURE_BOOT_SIG_SIZE_8910.
  137. *
  138. * \param data data to be signed
  139. * \param data_size data size
  140. * \param sig signature
  141. * \return
  142. * - true on success
  143. * - false on fail, invalid parameters or verify fail
  144. */
  145. bool drvSecureSigCheck(const void *data, uint32_t data_size, const void *sig);
  146. /**
  147. * \brief signature check for file with embedded signature
  148. *
  149. * Signature check will use public key in efuse, so caller should call this
  150. * only when there are valid public key in efuse.
  151. *
  152. * \param fname file name
  153. * \return
  154. * - true on success
  155. * - false on fail, file access error or verify fail
  156. */
  157. bool drvSecureFileEmbedSigCheck(const char *fname);
  158. /**
  159. * \brief signature header check
  160. *
  161. * Check the input whether contains the valid signature header
  162. *
  163. * \param sig signature
  164. * \return
  165. * - true if contains valid header
  166. * - false if not valid header
  167. */
  168. bool drvSecureContainValidSigHeader(const void *sig);
  169. #ifdef CONFIG_CP_SIGN_ENABLE
  170. bool cpimagecheck(const void *header);
  171. #endif
  172. //#ifdef CONFIG_TRUSTZONE_SUPPORT //quectel
  173. #ifdef CONFIG_TEE_SUPPORT
  174. uint32_t drvGetSecureVersion(void);
  175. bool drvGetSecureLockStatus(void);
  176. bool drvVerifyCertPubkey(const void *cert_header);
  177. #endif
  178. #ifdef __cplusplus
  179. }
  180. #endif
  181. #endif /* _DRV_SECURE_H_ */