hab_defines.h 82 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222
  1. /*
  2. * Copyright (c) 2008-2012, Freescale Semiconductor, Inc.
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without modification,
  6. * are permitted provided that the following conditions are met:
  7. *
  8. * o Redistributions of source code must retain the above copyright notice, this list
  9. * of conditions and the following disclaimer.
  10. *
  11. * o Redistributions in binary form must reproduce the above copyright notice, this
  12. * list of conditions and the following disclaimer in the documentation and/or
  13. * other materials provided with the distribution.
  14. *
  15. * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
  16. * contributors may be used to endorse or promote products derived from this
  17. * software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  20. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  23. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  25. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  26. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. /*!
  31. * @file hab_defines.h
  32. * @brief defines for data structures and macros used for enabling secure boot
  33. *
  34. * @ingroup diag_init
  35. */
  36. #ifndef HAB_DEFINES_H
  37. #define HAB_DEFINES_H
  38. /*===========================================================================
  39. INCLUDE FILES
  40. =============================================================================*/
  41. #include <stdint.h> /* for integer types */
  42. #include <stdbool.h> /* for bool type */
  43. #include <stddef.h> /* for NULL and offsetof() */
  44. /*===========================================================================
  45. CONSTANTS
  46. =============================================================================*/
  47. /** @addtogroup struct
  48. * @{
  49. */
  50. #define HDR_BYTES 4 /* cannot use sizeof(hab_hdr_t) in preprocessor */
  51. /** @name External data structure tags
  52. * @anchor dat_tag
  53. *
  54. * Tag values 0x00 .. 0xef are reserved for HAB. Values 0xf0 .. 0xff
  55. * are available for custom use.
  56. */
  57. /*@{*/
  58. #define HAB_TAG_IVT 0xd1 /**< Image Vector Table */
  59. #define HAB_TAG_DCD 0xd2 /**< Device Configuration Data */
  60. #define HAB_TAG_CSF 0xd4 /**< Command Sequence File */
  61. #define HAB_TAG_CRT 0xd7 /**< Certificate */
  62. #define HAB_TAG_SIG 0xd8 /**< Signature */
  63. #define HAB_TAG_EVT 0xdb /**< Event */
  64. #define HAB_TAG_RVT 0xdd /**< ROM Vector Table */
  65. #define HAB_TAG_WRP 0x81 /**< Wrapped Key */
  66. #define HAB_TAG_MAC 0xac /**< Message Authentication Code */
  67. /* Values 00 ... 7e reserved for internal use. Values b0 ... cf reserved for
  68. * CSF commands. Values e0 ... ef reserved for key types.
  69. *
  70. * Available values: 82, 84, 87, 88, 8b, 8d, 8e, 90, 93, 95, 96, 99, 9a,
  71. * 9c, 9f, a0, a3, a5, a6, a9, aa, af
  72. *
  73. * Custom values: f0, f3, f5, f6, f9, fa, fc, ff
  74. */
  75. /*@}*/
  76. /** @name HAB version */
  77. /*@{*/
  78. #define HAB_MAJOR_VERSION 4 /**< Major version of this HAB release */
  79. #define HAB_MINOR_VERSION 1 /**< Minor version of this HAB release */
  80. #define HAB_VER_MAJ_WIDTH 4 /**< Major version field width */
  81. #define HAB_VER_MAJ_SHIFT 4 /**< Major version field offset */
  82. #define HAB_VER_MIN_WIDTH 4 /**< Minor version field width */
  83. #define HAB_VER_MIN_SHIFT 0 /**< Minor version field offset */
  84. /** Full version of this HAB release @hideinitializer */
  85. #define HAB_VERSION HAB_VER(HAB_MAJOR_VERSION, HAB_MINOR_VERSION)
  86. /** Base version for this HAB release @hideinitializer */
  87. #define HAB_BASE_VERSION HAB_VER(HAB_MAJOR_VERSION, 0)
  88. /*@}*/
  89. /* @} struct */
  90. /*---------------------------------------------------------------------------*/
  91. /** @addtogroup cmd
  92. * @{
  93. */
  94. /** @name Command tags
  95. * @anchor cmd_tag
  96. *
  97. * Tag values 0xb0 .. 0xcf are reserved for HAB. Values 0xf0 .. 0xff
  98. * are available for custom use.
  99. */
  100. /*@{*/
  101. #define HAB_CMD_SET 0xb1 /**< Set */
  102. #define HAB_CMD_INS_KEY 0xbe /**< Install Key */
  103. #define HAB_CMD_AUT_DAT 0xca /**< Authenticate Data */
  104. #define HAB_CMD_WRT_DAT 0xcc /**< Write Data */
  105. #define HAB_CMD_CHK_DAT 0xcf /**< Check Data */
  106. #define HAB_CMD_NOP 0xc0 /**< No Operation */
  107. #define HAB_CMD_INIT 0xb4 /**< Initialise */
  108. #define HAB_CMD_UNLK 0xb2 /**< Unlock */
  109. #ifdef HAB_FUTURE
  110. #define HAB_CMD_RMV_KEY /**< Remove Key */
  111. #define HAB_CMD_INS_REF /**< Install Reference Data */
  112. #define HAB_CMD_INS_PLG /**< Install Plugin */
  113. #define HAB_CMD_RMV_PLG /**< Remove Plugin */
  114. #define HAB_CMD_CHK_VER /**< Check SW Version */
  115. #endif
  116. /* Remaining values: b7, b8, bb, bd, c3, c5, c6, c9 */
  117. /*@}*/
  118. /* @} cmd */
  119. /*---------------------------------------------------------------------------*/
  120. /** @addtogroup pcl
  121. * @{
  122. */
  123. /** @name Protocol tags
  124. * @anchor pcl_tag
  125. *
  126. * Tag values 0x00 .. 0xef are reserved for HAB. Values 0xf0 .. 0xff are
  127. * available for custom use.
  128. */
  129. /*@{*/
  130. #define HAB_PCL_SRK 0x03 /**< SRK certificate format */
  131. #define HAB_PCL_X509 0x09 /**< X.509v3 certificate format */
  132. #define HAB_PCL_CMS 0xc5 /**< CMS/PKCS#7 signature format */
  133. #define HAB_PCL_BLOB 0xbb /**< SHW-specific wrapped key format */
  134. #define HAB_PCL_AEAD 0xa3 /**< Proprietary AEAD MAC format */
  135. #ifdef HAB_FUTURE
  136. #define HAB_PCL_WTLS 0x05 /**< OMA WTLS certificate format */
  137. #define HAB_PCL_FSL 0x0f /**< FSL bound signature protocol */
  138. #define HAB_PCL_HMAC 0x30 /**< NIST HMAC message authentication */
  139. #define HAB_PCL_CBCMAC 0x33 /**< CBC-MAC message authentication */
  140. #endif
  141. /*@}*/
  142. /* Available values: 06, 0a, 0c, 11, 12, 14, 17, 18, 1b, 1d, 1e, 21, 22, 24,
  143. * 27, 28, 2b, 2d, 2e, 35, 36, 39, 3a, 3c, 3f, 41, 42, 44, 47, 48, 4b, 4d, 4e,
  144. * 50, 53, 55, 56, 59, 5a, 5c, 5f, 60, 63, 65, 66, 69, 6a, 6c, 6f, 71, 72, 74,
  145. * 77, 78, 7b, 7d, 7e, 81, 82, 84, 87, 88, 8b, 8d, 8e, 90, 93, 95, 96, 99, 9a,
  146. * 9c, 9f, a0, a5, a6, a9, aa, ac, af, b1, b2, b4, b7, b8, bd, be, c0, c3, c6,
  147. * c9, ca, cc, cf, d1, d2, d4, d7, d8, db, dd, de, e1, e2, e4, e7, e8, eb, ed,
  148. * ee
  149. *
  150. * Custom values: f0, f3, f5, f6, f9, fa, fc, ff
  151. */
  152. /* @} pcl */
  153. /*---------------------------------------------------------------------------*/
  154. /** @addtogroup alg
  155. * @{
  156. */
  157. /** @name Algorithm types
  158. * @anchor alg_typ
  159. *
  160. * The most-significant nibble of an algorithm ID denotes the algorithm
  161. * type. Algorithms of the same type share the same interface.
  162. *
  163. * Types 0x0 .. 0xc are reserved for HAB. Types 0xd .. 0xf are available for
  164. * custom use. Within each reserved type N in 0 .. c, tag values 0xN0 .. 0xNc
  165. * are reserved for HAB. Values 0xNd .. 0xNf are available for custom use.
  166. */
  167. /*@{*/
  168. #define HAB_ALG_ANY 0x0 /**< Algorithm type ANY */
  169. #define HAB_ALG_HASH 0x1 /**< Hash algorithm type */
  170. #define HAB_ALG_SIG 0x2 /**< Signature algorithm type */
  171. #define HAB_ALG_FF 0x3 /**< Finite field arithmetic */
  172. #define HAB_ALG_EC 0x4 /**< Elliptic curve arithmetic */
  173. #define HAB_ALG_CIPHER 0x5 /**< Cipher algorithm type */
  174. #define HAB_ALG_MODE 0x6 /**< Cipher/hash modes */
  175. #define HAB_ALG_WRAP 0x7 /**< Key wrap algorithm type */
  176. /*@}*/
  177. /** @name Algorithm type ANY
  178. *
  179. * Algorithms of type ANY have no common interface: the protocol must know
  180. * what to do.
  181. */
  182. /*@{*/
  183. #ifdef HAB_FUTURE
  184. #define HAB_ALG_RANDOM /**< Random number generation */
  185. #endif
  186. /* Available values: 03, 05, 06, 09, 0a, 0c, 0f
  187. */
  188. /*@}*/
  189. /** @name Hash algorithms */
  190. /*@{*/
  191. #define HAB_ALG_SHA1 0x11 /**< SHA-1 algorithm ID */
  192. #define HAB_ALG_SHA256 0x17 /**< SHA-256 algorithm ID */
  193. #define HAB_ALG_SHA512 0x1b /**< SHA-512 algorithm ID */
  194. /* Available values: 0x14, 0x12, 18, 1d, 1e
  195. */
  196. /*@}*/
  197. /** @name Signature algorithms */
  198. /*@{*/
  199. #define HAB_ALG_PKCS1 0x21 /**< PKCS#1 RSA signature algorithm */
  200. #ifdef HAB_FUTURE
  201. #define HAB_ALG_DSA /**< NIST DSA signature algorithm */
  202. #define HAB_ALG_ECDSA /**< NIST ECDSA signature algorithm */
  203. #endif
  204. /* Available values: 22, 24, 27, 28, 2b, 2d, 2e
  205. */
  206. /*@}*/
  207. /** @name Cipher algorithms */
  208. /*@{*/
  209. #define HAB_ALG_AES 0x55 /**< AES algorithm ID */
  210. /* Available values: 50, 53, 56, 59, 5a, 5c, 5f
  211. */
  212. /*@}*/
  213. /** @name Cipher or hash modes */
  214. /*@{*/
  215. #define HAB_MODE_CCM 0x66 /**< Counter with CBC-MAC */
  216. #ifdef HAB_FUTURE
  217. #define HAB_MODE_HMAC /**< HMAC hash mode */
  218. #endif
  219. /* Available values: 60, 63, 65, 69, 6a, 6c, 6f
  220. */
  221. /*@}*/
  222. /** @name Key wrap algorithms */
  223. /*@{*/
  224. #define HAB_ALG_BLOB 0x71 /**< SHW-specific key wrap */
  225. /* Available values: 72, 74, 77, 78, 7b, 7d, 7e
  226. */
  227. /*@}*/
  228. /* Available values: 81, 82, 84, 87, 88, 8b, 8d, 8e, 90, 93, 95, 96, 99, 9a,
  229. * 9c, 9f, a0, a3, a5, a6, a9, aa, ac, af, b1, b2, b4, b7, b8, bb, bd, be, c0,
  230. * c3, c5, c6, c9, ca, cc, cf, d1, d2, d4, d7, d8, db, dd, de, e1, e2, e4, e7,
  231. * e8, eb, ed, ee, f0, f3, f5, f6, f9, fa, fc, ff
  232. */
  233. /* @} alg */
  234. /*---------------------------------------------------------------------------*/
  235. /** @addtogroup eng
  236. * @{
  237. */
  238. /** @name Engine plugin tags
  239. * @anchor eng_tag
  240. *
  241. * Tag values 0x00 .. 0xef and 0xff are reserved for HAB. Values 0xf0 .. 0xfe
  242. * are available for custom use.
  243. */
  244. /*@{*/
  245. #define HAB_ENG_ANY 0x00 /**< First compatible engine will be
  246. * selected automatically (no engine
  247. * configuration parameters are allowed).
  248. */
  249. #define HAB_ENG_SCC 0x03 /**< Security controller */
  250. #define HAB_ENG_RTIC 0x05 /**< Run-time integrity checker */
  251. #define HAB_ENG_SAHARA 0x06 /**< Crypto accelerator */
  252. #define HAB_ENG_CSU 0x0a /**< Central Security Unit */
  253. #define HAB_ENG_SRTC 0x0c /**< Secure clock */
  254. #ifdef HAB_FUTURE
  255. #define HAB_ENG_RNG 0x09 /**< Standalone random number generator */
  256. #define HAB_ENG_SJC 0x0f /**< Secure JTAG controller */
  257. #define HAB_ENG_WDOG 0x11 /**< Watchdog timer */
  258. #define HAB_ENG_SRC 0x12 /**< System Reset Controller */
  259. #define HAB_ENG_SPBA 0x14 /**< Shared Peripheral Bus Arbiter */
  260. #define HAB_ENG_IIM 0x17 /**< Fuse controller */
  261. #define HAB_ENG_IOMUX 0x18 /**< IO multiplexer */
  262. #endif
  263. #define HAB_ENG_DCP 0x1b /**< Data Co-Processor */
  264. #define HAB_ENG_CAAM 0x1d /**< Cryptographic Acceleration and
  265. Assurance Module */
  266. #define HAB_ENG_SNVS 0x1e /**< Secure Non-Volatile Storage */
  267. #define HAB_ENG_OCOTP 0x21 /**< Fuse controller */
  268. /** @cond rom */
  269. #define HAB_ENG_DTCP 0x22 /**< DTCP co-processor */
  270. #define HAB_ENG_ROM 0x36 /**< Protected ROM area */
  271. #define HAB_ENG_HDCP 0x24 /**< HDCP co-processor */
  272. #define HAB_ENG_RTL 0x77 /**< @rom RTL simulation engine */
  273. /** @endcond */
  274. #define HAB_ENG_SW 0xff /**< Software engine */
  275. /* Available values: 27, 28, 2b, 2d, 2e, 30, 33, 35,
  276. * 39, 3a, 3c, 3f, 41, 42, 44, 47, 48, 4b, 4d, 4e, 50, 53, 55, 56, 59, 5a,
  277. * 5c, 5f, 60, 63, 65, 66, 69, 6a, 6c, 6f, 71, 72, 74, 78, 7b, 7d, 7e, 81,
  278. * 82, 84, 87, 88, 8b, 8d, 8e, 90, 93, 95, 96, 99, 9a, 9c, 9f, a0, a3, a5, a6,
  279. * a9, aa, ac, af, b1, b2, b4, b7, b8, bb, bd, be, c0, c3, c5, c6, c9, ca, cc,
  280. * cf, d1, d2, d4, d7, d8, db, dd, de, e1, e2, e4, e7, e8, eb, ed, ee
  281. *
  282. * Custom values: f0, f3, f5, f6, f9, fa, fc
  283. */
  284. /*@}*/
  285. /* @} eng */
  286. /*---------------------------------------------------------------------------*/
  287. /** @addtogroup sah
  288. * @{
  289. */
  290. /** Maximum data blocks in a single hash */
  291. #define HAB_SAHARA_BLOCK_MAX 12
  292. /** @cond rom */
  293. /** @rom DMA storage requirement
  294. *
  295. * This figure is derived in several parts:
  296. * - each hash operation needs a 6-word descriptor structure
  297. * - each data block needs a 3-word link structure
  298. * - the result needs a 3-word link structure
  299. * - at least 40 bytes are required for SHA-256 result and memory manager
  300. * overhead: 64 bytes allows some small overhead.
  301. */
  302. #define HAB_SAHARA_DMA_MIN_BYTES (24 + HAB_SAHARA_BLOCK_MAX * 12 + 12 + 64)
  303. /** @endcond */
  304. /* @} sah */
  305. /*---------------------------------------------------------------------------*/
  306. /** @addtogroup dcp
  307. * @{
  308. */
  309. /** Maximum data blocks in a single hash */
  310. #define HAB_DCP_BLOCK_MAX 6
  311. /** @cond rom */
  312. /** @rom DMA storage requirement
  313. *
  314. * This figure is derived in two parts:
  315. * - each data block needs an 8-word work packet (descriptor)
  316. * - at least 40 bytes are required for SHA-256 result and memory manager
  317. * overhead: 64 bytes allows some small overhead.
  318. */
  319. #define HAB_DCP_DMA_MIN_BYTES (64 + HAB_DCP_BLOCK_MAX * 32)
  320. /** @endcond */
  321. /* @} dcp */
  322. /*---------------------------------------------------------------------------*/
  323. /** @addtogroup rtic
  324. * @{
  325. */
  326. /** Maximum data blocks in a single hash */
  327. #define HAB_RTIC_BLOCK_MAX 2
  328. /* @} rtic */
  329. /*---------------------------------------------------------------------------*/
  330. /** @addtogroup scc
  331. * @{
  332. */
  333. /** @cond rom */
  334. /** @rom DMA storage requirement
  335. *
  336. * This figure is derived in several stages, and assumes plaintext and
  337. * ciphertext buffers are both allocated in the DMA region :
  338. * - 4 blocks of plaintext required
  339. * - 4 blocks of ciphertext required
  340. * - each block is 16 bytes long
  341. * - the plaintext address must be block-aligned (up to 15 bytes overhead)
  342. * - the ciphertext address must be block-aligned (up to 3 bytes overhead)
  343. * - at least 8 bytes of memory manager overhead: allow 32 for comfort
  344. */
  345. #define HAB_SCC_DMA_MIN_BYTES ( (4+4)*16 + 15 + 3 + 32)
  346. /** @endcond */
  347. /* @} scc */
  348. /*---------------------------------------------------------------------------*/
  349. /** @addtogroup caam
  350. * @{
  351. */
  352. /** Maximum data blocks in an @ref cmd_aut_dat command */
  353. #define HAB_CAAM_BLOCK_MAX 8
  354. /** @cond rom */
  355. /** @rom Hash DMA storage requirement
  356. *
  357. * This figure is derived in several parts:
  358. * - each hash operation needs
  359. * - a 7-word descriptor, and
  360. * - a 32-byte result buffer (for SHA-256),
  361. * - giving a base requirement of (7*4 + 32) = 60 bytes
  362. * - each data block needs a 4-word link structure
  363. * - memory manager overhead is at least 8 bytes: 16 bytes allows flexibility
  364. */
  365. #define HAB_CAAM_HSH_DMA_MIN_BYTES (60 + HAB_CAAM_BLOCK_MAX * 16 + 16)
  366. /** @rom AEAD DMA storage requirement
  367. *
  368. * This figure is derived in several parts:
  369. * - each AEAD operation needs
  370. * - a 16-word descriptor,
  371. * - a 32-byte initial context value (B0 and CTR0), and
  372. * - a 16-byte MAC value,
  373. * - giving a base requirement of (16*4 + 32 + 16) = 112 bytes
  374. * - each data block needs a 4-word link structure
  375. * - memory manager overhead is at least 8 bytes: 16 bytes allows flexibility
  376. */
  377. #define HAB_CAAM_CCM_DMA_MIN_BYTES (112 + HAB_CAAM_BLOCK_MAX * 16 + 16)
  378. /** @rom RNG DMA storage requirement
  379. *
  380. * This figure is derived in several parts:
  381. * - each DRNG test operation allocates a DMA area with
  382. * - a 1-word header, and
  383. * - a 3-word job ring area, and
  384. * - a 54-word descriptor,
  385. * - requiring a total 58*4 = 232 bytes
  386. * - each DRNG test operation also allocates a DMA area with
  387. * - a 1-word header, and
  388. * - a 32-byte result buffer
  389. * - requiring a total 4 + 32 = 36 bytes
  390. */
  391. #define HAB_CAAM_RNG_DMA_MIN_BYTES (232 + 32)
  392. /** @endcond */
  393. /* @} caam */
  394. /*---------------------------------------------------------------------------*/
  395. /** @addtogroup key
  396. * @{
  397. */
  398. /** @name Key types
  399. * @anchor key_types
  400. *
  401. * Tag values 0xe0 .. 0xef are reserved for HAB. Values 0xf0 .. 0xff
  402. * are available for custom use.
  403. */
  404. /*@{*/
  405. #define HAB_KEY_PUBLIC 0xe1 /**< Public key type: data present */
  406. #define HAB_KEY_SECRET 0xe2 /**< Secret key type: data present */
  407. #define HAB_KEY_MASTER 0xed /**< Master KEK type */
  408. #define HAB_KEY_HASH 0xee /**< Any key type: hash only */
  409. /* Available values: e4, e7, e8, eb
  410. *
  411. * Custom values: f0, f3, f5, f6, f9, fa, fc, ff
  412. */
  413. /*@}*/
  414. /** @name Public key store indices */
  415. /*@{*/
  416. #define HAB_IDX_SRK 0 /**< Super-Root Key index */
  417. #define HAB_IDX_CSFK 1 /**< CSF key index */
  418. /*@}*/
  419. /** @name Key Counts */
  420. /*@{*/
  421. #define HAB_SRK_MIN 1 /**< Minimum Super-Root Key count */
  422. #define HAB_SRK_MAX 4 /**< Maximum Super-Root Key count */
  423. #define HAB_KEY_PUBLIC_MAX 5 /**< Maximum installed public key count
  424. * (incl Super-Root Key)
  425. */
  426. #define HAB_KEY_SECRET_MAX 4 /**< Maximum installed secret key count
  427. * (excl Master KEKs)
  428. */
  429. /*@}*/
  430. /* @} key */
  431. /*---------------------------------------------------------------------------*/
  432. #ifdef HAB_FUTURE
  433. /** @addtogroup key_ecdsa
  434. * @{
  435. */
  436. /** @name Bitfield definitions */
  437. /*@{*/
  438. #define HAB_KEY_ECDSA_FLG_WIDTH 8 /**< Width of @a flg field */
  439. #define HAB_KEY_ECDSA_FLG_SHIFT 0 /**< Offset of @a flg field */
  440. #define HAB_KEY_ECDSA_TYP_WIDTH 8 /**< Width of @a typ field */
  441. #define HAB_KEY_ECDSA_TYP_SHIFT 24 /**< Offset of @a typ field */
  442. #define HAB_KEY_ECDSA_SIZ_WIDTH 8 /**< Width of @a siz field */
  443. #define HAB_KEY_ECDSA_SIZ_SHIFT 16 /**< Offset of @a siz field */
  444. #define HAB_KEY_ECDSA_REDBITS_WIDTH 16 /**< Width of @a red_bits field */
  445. #define HAB_KEY_ECDSA_REDBITS_SHIFT 0 /**< Offset of @a red_bits field */
  446. /*@}*/
  447. /* @} key_ecdsa */
  448. #endif
  449. /*---------------------------------------------------------------------------*/
  450. /** @addtogroup key_pkcs1
  451. * @{
  452. */
  453. /** @name Bitfield definitions */
  454. /*@{*/
  455. #define HAB_KEY_PKCS1_FLG_WIDTH 8 /**< Width of @a flg field */
  456. #define HAB_KEY_PKCS1_FLG_SHIFT 0 /**< Offset of @a flg field */
  457. #define HAB_KEY_PKCS1_MODBYTES_WIDTH 16 /**< Width of mod_bytes field */
  458. #define HAB_KEY_PKCS1_MODBYTES_SHIFT 16 /**< Offset of mod_bytes field */
  459. #define HAB_KEY_PKCS1_EXPBYTES_WIDTH 16 /**< Width of exp_bytes field */
  460. #define HAB_KEY_PKCS1_EXPBYTES_SHIFT 0 /**< Offset of exp_bytes field */
  461. /*@}*/
  462. /** @name Binding flag bitfield definitions */
  463. /*@}*/
  464. #define HAB_KEY_BND_FLG_WIDTH 5 /**< Width of binding flags */
  465. #define HAB_KEY_BND_FLG_SHIFT 2 /**< Offset of binding flags */
  466. /*@}*/
  467. /* @} key_pkcs1 */
  468. /*---------------------------------------------------------------------------*/
  469. /** @addtogroup cmd_wrt_dat
  470. * @{
  471. */
  472. /** @name Parameter bitfield definitions.
  473. *
  474. * Apply to both @ref cmd_wrt_dat and @ref cmd_chk_dat commands. */
  475. /*@{*/
  476. #define HAB_CMD_WRT_DAT_FLAGS_WIDTH 5 /**< @a flags field width */
  477. #define HAB_CMD_WRT_DAT_FLAGS_SHIFT 3 /**< @a flags field offset */
  478. #define HAB_CMD_WRT_DAT_BYTES_WIDTH 3 /**< @a bytes field width */
  479. #define HAB_CMD_WRT_DAT_BYTES_SHIFT 0 /**< @a bytes field offset */
  480. /*@}*/
  481. /* @} cmd_wrt_dat */
  482. /*---------------------------------------------------------------------------*/
  483. /** @addtogroup bnd_obj
  484. * @{
  485. */
  486. /** @name Binding object IDs
  487. * @anchor bnd_ids
  488. *
  489. * The ASN.1 object identifiers used to identify HAB binding attributes are
  490. * defined in the following arc:
  491. *
  492. @verbatim
  493. id-fsl OBJECT IDENTIFIER ::= {
  494. joint-iso-itu-t(2) country(16) us(840) organization(1) fsl(123456) }
  495. id-habBnd OBJECT IDENTIFIER ::= {
  496. id-fsl hab(32) binding-objects(16) }
  497. id-habBnd-dat OBJECT IDENTIFIER ::= {
  498. id-habBnd dat(1) }
  499. id-habBnd-cfg OBJECT IDENTIFIER ::= {
  500. id-habBnd cfg(3) }
  501. id-habBnd-fid OBJECT IDENTIFIER ::= {
  502. id-habBnd fid(5) }
  503. id-habBnd-mid OBJECT IDENTIFIER ::= {
  504. id-habBnd mid(6) }
  505. id-habBnd-cid OBJECT IDENTIFIER ::= {
  506. id-habBnd cid(9) }
  507. @endverbatim
  508. *
  509. * The ASN.1 object identifiers used to identify HAB binding attributes are
  510. * single component extensions of id-habBnd using a component value less than
  511. * 128 (so that the component can be DER-encoded in a single byte).
  512. *
  513. * The DER encoding of an object identifier in this arc is the concatenation
  514. * of the DER prefix with the single byte identifier for the required binding
  515. * object. Binding object attribute values are encoded as an ASN.1 SET with
  516. * a single OCTET STRING member.
  517. */
  518. /*@{*/
  519. /** DER prefix
  520. *
  521. * @todo update description and encoding of binding object identifiers with
  522. * real fsl value instead of fsl(123456) encoded as 0x87, 0xc4, 0x40, and
  523. * confirm chosen values for hab(32) and binding-objects(16).
  524. */
  525. #define HAB_BND_DER_PREFIX \
  526. {0x06, 0x0a, 0x60, 0x86, 0x48, 0x01, 0x87, 0xc4, 0x40, 0x20, 0x10}
  527. #define HAB_BND_DAT 0x01 /**< Data type (mandatory) */
  528. #define HAB_BND_CFG 0x03 /**< Security configuration */
  529. #define HAB_BND_FID 0x05 /**< Fabrication UID */
  530. #define HAB_BND_MID 0x06 /**< Manufacturing ID */
  531. #define HAB_BND_CID 0x09 /**< Caller ID */
  532. /* Available values: 0a, 0c, 0f, 11, 12, 14, 17, 18, 1b, 1d, 1e, 21, 22, 24,
  533. * 27, 28, 2b, 2d, 2e, 30, 33, 35, 36, 39, 3a, 3c, 3f, 41, 42, 44, 47, 48, 4b,
  534. * 4d, 4e, 50, 53, 55, 56, 59, 5a, 5c, 5f, 60, 63, 65, 66, 69, 6a, 6c, 6f, 71,
  535. * 72, 74, 77, 78, 7b, 7d, 7e
  536. */
  537. /*@}*/
  538. /** @name Caller IDs
  539. *
  540. * Only the ROM caller ID is defined, but other caller IDs may be defined by
  541. * later boot stages.
  542. */
  543. /*@{*/
  544. #define HAB_CID_ROM 0 /**< ROM Caller ID */
  545. /*@}*/
  546. /* @} bnd_obj */
  547. #ifdef HAB_FUTURE
  548. /** @addtogroup sig_fsl
  549. * @{
  550. */
  551. #define HAB_BND_DAT_BYTES 512 /**< Maximum binding data size */
  552. /* @} sig_fsl */
  553. #endif
  554. /*===========================================================================
  555. MACROS
  556. =============================================================================*/
  557. /*
  558. * Helper macros
  559. */
  560. #define HAB_CMD_UNS 0xff
  561. #define DEFAULT_IMG_KEY_IDX 2
  562. #define GEN_MASK(width) \
  563. ((1UL << (width)) - 1)
  564. #define GEN_FIELD(f, width, shift) \
  565. (((f) & GEN_MASK(width)) << (shift))
  566. #define PACK_UINT32(a, b, c, d) \
  567. ((uint32_t) ( (((uint32_t)(a) & 0xFF) << 24) \
  568. |(((uint32_t)(b) & 0xFF) << 16) \
  569. |(((uint32_t)(c) & 0xFF) << 8) \
  570. |(((uint32_t)(d) & 0xFF)) ) )
  571. #define EXPAND_UINT32(w) \
  572. (uint8_t)((w)>>24), (uint8_t)((w)>>16), (uint8_t)((w)>>8), (uint8_t)(w)
  573. #define EXPAND_UINT16(w) \
  574. (uint8_t)((w)>>8), (uint8_t)(w)
  575. #define HDR(tag, bytes, par) \
  576. (uint8_t)(tag), (uint8_t)((bytes)>>8), (uint8_t)(bytes), (uint8_t)(par)
  577. #define HAB_VER(maj, min) \
  578. (GEN_FIELD((maj), HAB_VER_MAJ_WIDTH, HAB_VER_MAJ_SHIFT) \
  579. | GEN_FIELD((min), HAB_VER_MIN_WIDTH, HAB_VER_MIN_SHIFT))
  580. #define DCD_DATA(addr, data) EXPAND_UINT32(addr), EXPAND_UINT32(data)
  581. /*
  582. * CSF header
  583. */
  584. #define CSF_HDR(bytes, HABVER) \
  585. HDR(HAB_TAG_CSF, (bytes), HABVER)
  586. /*
  587. * DCD header
  588. */
  589. #define DCD_HDR(bytes, HABVER) \
  590. HDR(HAB_TAG_DCD, (bytes), HABVER)
  591. /*
  592. * IVT header (goes in the struct's hab_hdr_t field, not a byte array)
  593. */
  594. #define IVT_HDR(bytes, HABVER) \
  595. {HAB_TAG_IVT, {(uint8_t)((bytes)>>8), (uint8_t)(bytes)}, HABVER}
  596. /*
  597. * Write Data
  598. */
  599. #define WRT_DAT(flags, bytes, address, val_msk) \
  600. HDR(HAB_CMD_WRT_DAT, WRT_DAT_BYTES, WRT_DAT_PAR((flags), (bytes))), \
  601. EXPAND_UINT32(address), \
  602. EXPAND_UINT32(val_msk)
  603. #define WRT_DAT_BYTES 12
  604. #define MULTI_WRT_DAT(flags, bytes, address1, val_msk1, address2, \
  605. val_msk2, address3, val_msk3) \
  606. HDR(HAB_CMD_WRT_DAT, MULTI_WRT_DAT_BYTES, WRT_DAT_PAR((flags), (bytes))), \
  607. EXPAND_UINT32(address1), \
  608. EXPAND_UINT32(val_msk1), \
  609. EXPAND_UINT32(address2), \
  610. EXPAND_UINT32(val_msk2), \
  611. EXPAND_UINT32(address3), \
  612. EXPAND_UINT32(val_msk3)
  613. #define MULTI_WRT_DAT_BYTES 28
  614. #define WRT_DAT_PAR(flags, bytes) \
  615. (GEN_FIELD((flags), \
  616. HAB_CMD_WRT_DAT_FLAGS_WIDTH, \
  617. HAB_CMD_WRT_DAT_FLAGS_SHIFT) \
  618. | GEN_FIELD((bytes), \
  619. HAB_CMD_WRT_DAT_BYTES_WIDTH, \
  620. HAB_CMD_WRT_DAT_BYTES_SHIFT))
  621. /*
  622. * Check Data (forever)
  623. */
  624. #define CHK_DAT_FOREVER(flags, bytes, address, mask) \
  625. HDR(HAB_CMD_CHK_DAT, CHK_DAT_FOREVER_BYTES, WRT_DAT_PAR((flags), (bytes))), \
  626. EXPAND_UINT32(address), \
  627. EXPAND_UINT32(mask)
  628. #define CHK_DAT_FOREVER_BYTES 12
  629. /*
  630. * Check Data (polled)
  631. */
  632. #define HAB_CMD_CHK_DAT_COUNT 100
  633. #define CHK_DAT(flags, bytes, address, mask, count) \
  634. HDR(HAB_CMD_CHK_DAT, CHK_DAT_BYTES, WRT_DAT_PAR((flags), (bytes))), \
  635. EXPAND_UINT32(address), \
  636. EXPAND_UINT32(mask), \
  637. EXPAND_UINT32(count)
  638. #define CHK_DAT_BYTES 16
  639. /*
  640. * Set (generic - used internally only, or to generate invalid commands)
  641. */
  642. #define SET(bytes, itm, value) \
  643. HDR(HAB_CMD_SET, (bytes), (itm)), \
  644. EXPAND_UINT32(value)
  645. /*
  646. * Set (MID location)
  647. */
  648. #define SET_MID(bank, row, bit, fuses) \
  649. HDR(HAB_CMD_SET, SET_MID_BYTES, HAB_VAR_CFG_ITM_MID), \
  650. (bank), (row), (bit), (fuses)
  651. #define SET_MID_BYTES 8
  652. /*
  653. * Set (default ENG)
  654. */
  655. #define SET_ENG(alg, eng, cfg) \
  656. HDR(HAB_CMD_SET, SET_ENG_BYTES, HAB_VAR_CFG_ITM_ENG), \
  657. 0, (alg), (eng), (cfg)
  658. #define SET_ENG_BYTES 8
  659. /*
  660. * Init (engine)
  661. */
  662. #define INIT(eng) \
  663. HDR(HAB_CMD_INIT, INIT_BYTES, (eng))
  664. #define INIT_BYTES 4
  665. /*
  666. * Unlk (engine)
  667. */
  668. #define UNLK(eng, ...) \
  669. UNLK_ ## eng(__VA_ARGS__)
  670. #define UNLK_BYTES(eng, ...) \
  671. UNLK_BYTES_ ## eng(__VA_ARGS__)
  672. #define UNLK_HDR(eng, ...) \
  673. HDR(HAB_CMD_UNLK, UNLK_BYTES_ ## eng(__VA_ARGS__), eng)
  674. #define UNLK_FLG(flg) \
  675. 0, 0, 0, (uint8_t)(flg)
  676. #define UNLK_FLG_BYTES 4
  677. #define UNLK_HAB_ENG_SRTC(dnc) UNLK_HDR(HAB_ENG_SRTC)
  678. #define UNLK_BYTES_HAB_ENG_SRTC(dnc) HDR_BYTES
  679. #define UNLK_HAB_ENG_SNVS(flg) UNLK_HDR(HAB_ENG_SNVS), UNLK_FLG(flg)
  680. #define UNLK_BYTES_HAB_ENG_SNVS(flg) (HDR_BYTES + UNLK_FLG_BYTES)
  681. #define UNLK_HAB_ENG_CAAM(flg) UNLK_HDR(HAB_ENG_CAAM), UNLK_FLG(flg)
  682. #define UNLK_BYTES_HAB_ENG_CAAM(flg) (HDR_BYTES + UNLK_FLG_BYTES)
  683. /* The next definition uses a GCC extension employing ## to swallow the
  684. * trailing comma in case the macro is called with only the fixed arguments
  685. * (i.e. flg here). This extension appears to work in the GNU compatible mode
  686. * of RVDS and GHS compilers.
  687. */
  688. #define UNLK_HAB_ENG_OCOTP(flg, ...) \
  689. UNLK_HDR(HAB_ENG_OCOTP, flg), UNLK_FLG(flg), ## __VA_ARGS__
  690. #define UNLK_BYTES_HAB_ENG_OCOTP(flg, ...) \
  691. (HDR_BYTES + UNLK_FLG_BYTES \
  692. + ( ((flg) & (HAB_OCOTP_UNLOCK_FIELD_RETURN \
  693. |HAB_OCOTP_UNLOCK_JTAG \
  694. |HAB_OCOTP_UNLOCK_SCS)) \
  695. ? STUB_FAB_UID_BYTES \
  696. : 0 ))
  697. #if 0
  698. /* Note: no comma after HDR(). Supplied by _VAL macro if needed */
  699. #define UNLK(eng, val) \
  700. HDR(HAB_CMD_UNLK, UNLK_BYTES_ ## eng, (eng)) \
  701. UNLK_VAL_ ## eng(val)
  702. #define UNLK_BYTES(eng) \
  703. UNLK_BYTES_ ## eng
  704. #define UNLK_BYTES_HAB_ENG_SRTC HDR_BYTES
  705. #define UNLK_VAL_HAB_ENG_SRTC(val) /* no val field */
  706. #define UNLK_BYTES_HAB_ENG_SNVS (HDR_BYTES + 4)
  707. #define UNLK_VAL_HAB_ENG_SNVS(val) ,0,0,0,((val)&0xff)
  708. #define UNLK_BYTES_HAB_ENG_CAAM (HDR_BYTES + 4)
  709. #define UNLK_VAL_HAB_ENG_CAAM(val) ,0,0,0,((val)&0xff)
  710. #endif
  711. /*
  712. * NOP
  713. */
  714. #define NOP() \
  715. HDR(HAB_CMD_NOP, NOP_BYTES, 0xae) /* third param is ignored */
  716. #define NOP_BYTES 4
  717. /*
  718. * Install Key (generic - used internally only)
  719. */
  720. #define INS_KEY(bytes, flg, pcl, alg, src, tgt, crt) \
  721. HDR(HAB_CMD_INS_KEY, (bytes), (flg)), \
  722. (pcl), (alg), (src), (tgt), \
  723. EXPAND_UINT32(crt)
  724. #define INS_KEY_BASE_BYTES 12
  725. /*
  726. * Install Key (SRK)
  727. */
  728. #define INS_SRK(flg, alg, src, crt) \
  729. INS_KEY(INS_SRK_BYTES, (flg), \
  730. HAB_PCL_SRK, (alg), (src), HAB_IDX_SRK, \
  731. (crt))
  732. #define INS_SRK_BYTES INS_KEY_BASE_BYTES
  733. /*
  734. * Install Key (CSFK)
  735. */
  736. #define INS_CSFK(flg, pcl, crt) \
  737. INS_KEY(INS_CSFK_BYTES, (flg) | HAB_CMD_INS_KEY_CSF, \
  738. (pcl), HAB_ALG_ANY, HAB_IDX_SRK, HAB_IDX_CSFK, \
  739. (crt))
  740. #define INS_CSFK_BYTES INS_KEY_BASE_BYTES
  741. /*
  742. * Install Key (IMGK - no hash)
  743. */
  744. #define INS_IMGK(flg, pcl, src, tgt, crt) \
  745. INS_KEY(INS_IMGK_BYTES, (flg), \
  746. (pcl), HAB_ALG_ANY, (src), (tgt), \
  747. (crt))
  748. #define INS_IMGK_BYTES INS_KEY_BASE_BYTES
  749. /*
  750. * Install Key (IMGK - with hash). Must be followed by the crt_hsh contents
  751. * (e.g. using #include). The length field depends on using one of the
  752. * standard HAB algorithm names, with no adornments like casts or
  753. * parentheses. Note that the length macro cannot be used here: the ##
  754. * must appear in the body of this macro to prevent the alg parameter from
  755. * being expanded first.
  756. */
  757. #define INS_IMGK_HASH(flg, pcl, alg, src, tgt, crt) \
  758. INS_KEY(INS_KEY_BASE_BYTES + BYTES_ ## alg, (flg) | HAB_CMD_INS_KEY_HSH, \
  759. (pcl), (alg), (src), (tgt), \
  760. (crt))
  761. /*
  762. * Same as above but the hash length is fixed to the length of SHA1,
  763. * but the algorithm remains unchanged.
  764. */
  765. #define INS_IMGK_INV_HASH(flg, pcl, alg, src, tgt, crt) \
  766. INS_KEY(INS_IMGK_HASH_BYTES(HAB_ALG_SHA1), (flg) | HAB_CMD_INS_KEY_HSH, \
  767. (pcl), (alg), (src), (tgt), \
  768. (crt))
  769. #define INS_IMGK_HASH_BYTES(alg) \
  770. (INS_KEY_BASE_BYTES + BYTES_ ## alg)
  771. #define BYTES_HAB_ALG_SHA1 20
  772. #define BYTES_HAB_ALG_SHA256 32
  773. #define BYTES_HAB_ALG_SHA512 64
  774. /* dummy value for invalid hash alg - same as default hash algorithm */
  775. #define DEFAULT_HASH_ALG_BYTES BYTES_HAB_ALG_SHA256
  776. #define BYTES_HAB_ALG_PKCS1 DEFAULT_HASH_ALG_BYTES
  777. /*
  778. * Authenticate Data (generic - used internally only)
  779. */
  780. #define AUT_DAT(bytes, flg, key, pcl, eng, cfg, sig_start) \
  781. HDR(HAB_CMD_AUT_DAT, (bytes), (flg)), \
  782. (key), (pcl), (eng), (cfg), \
  783. EXPAND_UINT32(sig_start)
  784. #define AUT_DAT_BASE_BYTES 12
  785. /*
  786. * Authenticate Data (CSF)
  787. */
  788. #define AUT_CSF(flg, pcl, eng, cfg, sig_start) \
  789. AUT_DAT(AUT_CSF_BYTES, (flg), \
  790. HAB_IDX_CSFK, (pcl), (eng), (cfg), \
  791. (sig_start))
  792. #define AUT_CSF_BYTES AUT_DAT_BASE_BYTES
  793. /*
  794. * Authenticate Data (Image)
  795. */
  796. #define AUT_IMG(blocks, flg, key, pcl, eng, cfg, sig_start) \
  797. AUT_DAT(AUT_IMG_BYTES(blocks), (flg), \
  798. (key), (pcl), (eng), (cfg), \
  799. (sig_start))
  800. #define AUT_IMG_BYTES(blocks) \
  801. (AUT_DAT_BASE_BYTES + 8*(blocks))
  802. /** Supported widths of data commands.
  803. * @ingroup cmd_wrt_dat
  804. */
  805. typedef enum hab_data_width
  806. {
  807. HAB_DATA_WIDTH_BYTE = 1, /**< 8-bit value */
  808. HAB_DATA_WIDTH_HALF = 2, /**< 16-bit value */
  809. HAB_DATA_WIDTH_WORD = 4 /**< 32-bit value */
  810. } hab_data_width_t;
  811. /** Flags for Write Data commands.
  812. * @ingroup cmd_wrt_dat
  813. */
  814. typedef enum hab_cmd_wrt_dat_flg
  815. {
  816. HAB_CMD_WRT_DAT_MSK = 1, /**< Mask/value flag: if set, only specific
  817. * bits may be overwritten at target address
  818. * (otherwise all bits may be overwritten)
  819. */
  820. HAB_CMD_WRT_DAT_SET = 2 /**< Set/clear flag: if #HAB_CMD_WRT_DAT_MSK
  821. * set, bits at the target address overwritten
  822. * with this flag (otherwise it is ignored)
  823. */
  824. } hab_cmd_wrt_dat_flg_t;
  825. /** Flags for Check Data commands.
  826. * @ingroup cmd_chk_dat
  827. */
  828. typedef enum hab_cmd_chk_dat_flg
  829. {
  830. HAB_CMD_CHK_DAT_SET = 2, /**< Set/clear flag: bits set in mask must
  831. * match this flag
  832. */
  833. HAB_CMD_CHK_DAT_ANY = 4 /**< Any/all flag: if clear, all bits set in
  834. * mask must match (otherwise any bit
  835. * suffices)
  836. */
  837. } hab_cmd_chk_dat_flg_t;
  838. /** Flags for Authenticate Data commands.
  839. * @ingroup cmd_aut_dat
  840. */
  841. typedef enum hab_cmd_aut_dat_flg
  842. {
  843. HAB_CMD_AUT_DAT_CLR = 0, /**< No flags set */
  844. HAB_CMD_AUT_DAT_ABS = 1 /**< Absolute signature address */
  845. } hab_cmd_aut_dat_flg_t;
  846. /** Flags for Install Key commands.
  847. * @ingroup cmd_ins_key
  848. */
  849. typedef enum hab_cmd_ins_key_flg
  850. {
  851. HAB_CMD_INS_KEY_CLR = 0, /**< No flags set */
  852. HAB_CMD_INS_KEY_ABS = 1, /**< Absolute certificate address */
  853. HAB_CMD_INS_KEY_CSF = 2, /**< Install CSF key */
  854. HAB_CMD_INS_KEY_DAT = 4, /**< Key binds to Data Type */
  855. HAB_CMD_INS_KEY_CFG = 8, /**< Key binds to Configuration */
  856. HAB_CMD_INS_KEY_FID = 16, /**< Key binds to Fabrication UID */
  857. HAB_CMD_INS_KEY_MID = 32, /**< Key binds to Manufacturing ID */
  858. HAB_CMD_INS_KEY_CID = 64, /**< Key binds to Caller ID */
  859. HAB_CMD_INS_KEY_HSH = 128 /**< Certificate hash present */
  860. } hab_cmd_ins_key_flg_t;
  861. /** Key flags.
  862. * @ingroup key_pkcs1
  863. *
  864. * @ifrom
  865. *
  866. * The binding flags given here align with those in #hab_cmd_ins_key_flg
  867. *
  868. * @endrom
  869. *
  870. */
  871. typedef enum hab_key_flg
  872. {
  873. /* Two more flag values available */
  874. HAB_KEY_FLG_DAT = 4, /**< Key binds to Data Type */
  875. HAB_KEY_FLG_CFG = 8, /**< Key binds to Configuration */
  876. HAB_KEY_FLG_FID = 16, /**< Key binds to Fabrication UID */
  877. HAB_KEY_FLG_MID = 32, /**< Key binds to Manufacturing ID */
  878. HAB_KEY_FLG_CID = 64, /**< Key binds to Caller ID */
  879. HAB_KEY_FLG_CA = 128 /**< CA key */
  880. } hab_key_flg_t;
  881. /** Secret key flags.
  882. * @ingroup crt_blob
  883. */
  884. typedef enum hab_key_secret_flg
  885. {
  886. /* Seven more flag values available */
  887. HAB_KEY_FLG_KEK = 128 /**< KEK */
  888. } hab_key_secret_flg_t;
  889. /** Binding data types
  890. * @ingroup bnd_obj
  891. */
  892. typedef enum hab_dat {
  893. HAB_DAT_CSF = 0x0f, /**< CSF signature */
  894. HAB_DAT_IMG = 0x33, /**< Image signature */
  895. #ifdef HAB_FUTURE
  896. HAB_DAT_PLG = 0x3c, /**< Plugin signature */
  897. #endif
  898. HAB_DAT_MAX
  899. } hab_dat_t;
  900. /* Available values: 55, 5a, 66, 69, 96, 99, a5, aa, c3, cc, f0, ff
  901. */
  902. /** Target check types
  903. * @ingroup chk_tgt
  904. */
  905. typedef enum hab_target {
  906. HAB_TGT_MEMORY = 0x0f, /**< Check memory white list */
  907. HAB_TGT_PERIPHERAL = 0xf0, /**< Check peripheral white list */
  908. HAB_TGT_ANY = 0x55, /**< Check memory & peripheral white list */
  909. HAB_TGT_MAX
  910. } hab_target_t;
  911. /** Security configuration types
  912. * @ingroup status
  913. */
  914. typedef enum hab_config {
  915. /** @cond rom */
  916. HAB_CFG_FAB = 0x00, /**< @rom Un-programmed IC */
  917. /** @endcond */
  918. HAB_CFG_RETURN = 0x33, /**< Field Return IC */
  919. HAB_CFG_OPEN = 0xf0, /**< Non-secure IC */
  920. HAB_CFG_CLOSED = 0xcc /**< Secure IC */
  921. } hab_config_t;
  922. /* Available values: 0f, 3c, 55, 5a, 66, 69, 96, 99, a5, aa, ff
  923. */
  924. /** Security state types
  925. * @ingroup status
  926. */
  927. typedef enum hab_state {
  928. HAB_STATE_INITIAL = 0x33, /**< Initialising state (transitory) */
  929. HAB_STATE_CHECK = 0x55, /**< Check state (non-secure) */
  930. HAB_STATE_NONSECURE = 0x66, /**< Non-secure state */
  931. HAB_STATE_TRUSTED = 0x99, /**< Trusted state */
  932. HAB_STATE_SECURE = 0xaa, /**< Secure state */
  933. HAB_STATE_FAIL_SOFT = 0xcc, /**< Soft fail state */
  934. HAB_STATE_FAIL_HARD = 0xff, /**< Hard fail state (terminal) */
  935. HAB_STATE_NONE = 0xf0, /**< No security state machine */
  936. HAB_STATE_MAX
  937. } hab_state_t;
  938. /* Available values: 00, 0f, 3c, 5a, 69, 96, a5, c3
  939. */
  940. /** HAB status types
  941. * @ingroup status
  942. */
  943. typedef enum hab_status {
  944. HAB_STS_ANY = 0x00, /**< Match any status in
  945. * hab_rvt.report_event()
  946. */
  947. HAB_FAILURE = 0x33, /**< Operation failed */
  948. HAB_WARNING = 0x69, /**< Operation completed with warning */
  949. HAB_SUCCESS = 0xf0, /**< Operation completed successfully */
  950. HAB_STS_MAX
  951. } hab_status_t;
  952. /** Failure or warning reasons
  953. * @ingroup evt
  954. *
  955. * Values 0x80 ... 0xff are reserved for internal use.
  956. */
  957. typedef enum hab_reason {
  958. HAB_RSN_ANY = 0x00, /**< Match any reason in
  959. * hab_rvt.report_event()
  960. */
  961. HAB_ENG_FAIL = 0x30, /**< Engine failure. */
  962. HAB_INV_ADDRESS = 0x22, /**< Invalid address: access denied. */
  963. HAB_INV_ASSERTION = 0x0c, /**< Invalid assertion. */
  964. HAB_INV_CALL = 0x28, /**< Function called out of sequence. */
  965. HAB_INV_CERTIFICATE = 0x21, /**< Invalid certificate. */
  966. HAB_INV_COMMAND = 0x06, /**< Invalid command: command malformed. */
  967. HAB_INV_CSF = 0x11, /**< Invalid @ref csf. */
  968. HAB_INV_DCD = 0x27, /**< Invalid @ref dcd. */
  969. HAB_INV_INDEX = 0x0f, /**< Invalid index: access denied. */
  970. HAB_INV_IVT = 0x05, /**< Invalid @ref ivt. */
  971. HAB_INV_KEY = 0x1d, /**< Invalid key. */
  972. HAB_INV_RETURN = 0x1e, /**< Failed callback function. */
  973. HAB_INV_SIGNATURE = 0x18, /**< Invalid signature. */
  974. HAB_INV_SIZE = 0x17, /**< Invalid data size. */
  975. HAB_MEM_FAIL = 0x2e, /**< Memory failure. */
  976. HAB_OVR_COUNT = 0x2b, /**< Expired poll count. */
  977. HAB_OVR_STORAGE = 0x2d, /**< Exhausted storage region. */
  978. HAB_UNS_ALGORITHM = 0x12, /**< Unsupported algorithm. */
  979. HAB_UNS_COMMAND = 0x03, /**< Unsupported command. */
  980. HAB_UNS_ENGINE = 0x0a, /**< Unsupported engine. */
  981. HAB_UNS_ITEM = 0x24, /**< Unsupported configuration item. */
  982. HAB_UNS_KEY = 0x1b, /**< Unsupported key type or parameters. */
  983. HAB_UNS_PROTOCOL = 0x14, /**< Unsupported protocol. */
  984. HAB_UNS_STATE = 0x09, /**< Unsuitable state. */
  985. HAB_RSN_MAX
  986. } hab_reason_t;
  987. /* Available values: 33, 35, 36, 39, 3a, 3c, 3f, 41, 42, 44,
  988. * 47, 48, 4b, 4d, 4e, 50, 53, 55, 56, 59, 5a, 5c, 5f, 60, 63, 65, 66, 69, 6a,
  989. * 6c, 6f, 71, 72, 74, 77, 78, 7b, 7d, 7e
  990. */
  991. /** Audit logging contexts.
  992. * @ingroup evt
  993. *
  994. * This list is sorted in order of increasing priority: where two contexts
  995. * might apply, the latter one is used.
  996. *
  997. * Values 0x40 .. 0x5f are reserved for internal use.
  998. */
  999. typedef enum hab_context {
  1000. HAB_CTX_ANY = 0x00, /**< Match any context in
  1001. * hab_rvt.report_event()
  1002. */
  1003. /** @cond rom */
  1004. HAB_CTX_FAB = 0xff, /**< @rom Event logged in hab_fab_test() */
  1005. /** @endcond */
  1006. HAB_CTX_ENTRY = 0xe1, /**< Event logged in hab_rvt.entry() */
  1007. HAB_CTX_TARGET = 0x33, /**< Event logged in hab_rvt.check_target() */
  1008. HAB_CTX_AUTHENTICATE = 0x0a, /**< Event logged in
  1009. * hab_rvt.authenticate_image()
  1010. */
  1011. HAB_CTX_DCD = 0xdd, /**< Event logged in hab_rvt.run_dcd() */
  1012. HAB_CTX_CSF = 0xcf, /**< Event logged in hab_rvt.run_csf() */
  1013. HAB_CTX_COMMAND = 0xc0, /**< Event logged executing @ref csf or @ref
  1014. * dcd command
  1015. */
  1016. HAB_CTX_AUT_DAT = 0xdb, /**< Authenticated data block */
  1017. HAB_CTX_ASSERT = 0xa0, /**< Event logged in hab_rvt.assert() */
  1018. HAB_CTX_EXIT = 0xee, /**< Event logged in hab_rvt.exit() */
  1019. HAB_CTX_MAX
  1020. } hab_context_t;
  1021. /** Assertion types.
  1022. * @ingroup assert
  1023. */
  1024. typedef enum hab_assertion {
  1025. HAB_ASSERT_BLOCK = 0, /**< Assert that a memory block was authenticated */
  1026. HAB_ASSERT_MAX
  1027. } hab_assertion_t;
  1028. /** RTIC configuration flags
  1029. * @ingroup rtic
  1030. */
  1031. typedef enum hab_rtic_config {
  1032. HAB_RTIC_IN_SWAP8 = 0x01, /**< Set BYTE SWAP bit (reverse bytes within
  1033. * word on input to RTIC) */
  1034. HAB_RTIC_IN_SWAP16 = 0x02, /**< Set HALF WORD SWAP bit (reverse
  1035. * half-words within word on input to
  1036. * RTIC) */
  1037. HAB_RTIC_OUT_SWAP8 = 0x08, /**< Set HASH RESULT BYTE SWAP bit (reverse
  1038. * bytes within word on output from RTIC) */
  1039. HAB_RTIC_KEEP = 0x80 /**< Retain reference hash value for later
  1040. * monitoring */
  1041. } hab_rtic_config_t;
  1042. /** SAHARA configuration flags
  1043. * @ingroup sah
  1044. */
  1045. typedef enum hab_sahara_config {
  1046. HAB_SAHARA_IN_SWAP8 = 0x01, /**< Set MESS BYTE SWAP bit (reverse message
  1047. * bytes within word on input to
  1048. * SAHARA) */
  1049. HAB_SAHARA_IN_SWAP16 = 0x02, /**< Set MESS HALF WORD SWAP bit (reverse
  1050. * message half-words within word on input
  1051. * to SAHARA) */
  1052. /* no SWAP32 for SAHARA message - leave 0x04 value unassigned */
  1053. /* no SWAP8 for SAHARA descriptors/links - leave 0x08 value unassigned */
  1054. HAB_SAHARA_DSC_BE8_16 = 0x10, /**< Interpret descriptors and links as for
  1055. * BE-8 16-bit memory. */
  1056. HAB_SAHARA_DSC_BE8_32 = 0x20 /**< Interpret descriptors and links as for
  1057. * BE-8 32-bit memory. */
  1058. } hab_sahara_config_t;
  1059. /** CAAM configuration flags
  1060. * @ingroup caam
  1061. */
  1062. typedef enum hab_caam_config {
  1063. HAB_CAAM_IN_SWAP8 = 0x01, /**< Set Message Byte Swap Input bit (reverse
  1064. * message bytes within word on input to
  1065. * CAAM) */
  1066. HAB_CAAM_IN_SWAP16 = 0x02, /**< Set Message Half Word Swap Input bit
  1067. * (reverse message half-words within word
  1068. * on input to CAAM) */
  1069. /* no SWAP32 for CAAM message - leave 0x04 value unassigned */
  1070. HAB_CAAM_OUT_SWAP8 = 0x08, /**< Set Message Byte Swap Output bit
  1071. * (reverse message bytes within word on
  1072. * output from CAAM) */
  1073. HAB_CAAM_OUT_SWAP16 = 0x10, /**< Set Message Half Word Swap Output bit
  1074. * (reverse message half-words within word
  1075. * on output from CAAM) */
  1076. /* no SWAP32 for CAAM message - leave 0x20 value unassigned */
  1077. HAB_CAAM_DSC_SWAP8 = 0x40, /**< Set Control Byte Swap Input/Output bits
  1078. * (reverse descriptor/link bytes within
  1079. * word on input to or output from CAAM) */
  1080. HAB_CAAM_DSC_SWAP16 = 0x80 /**< Set Control Half Word Swap Input/Output
  1081. * bits (reverse descriptor/link half-words
  1082. * within word on input to or output from
  1083. * CAAM) */
  1084. } hab_caam_config_t;
  1085. /** CAAM unlock flags
  1086. * @ingroup caam
  1087. */
  1088. typedef enum hab_caam_unlock_flag {
  1089. HAB_CAAM_UNLOCK_MID = 0x01, /**< Leave Job Ring and DECO master ID
  1090. * registers unlocked */
  1091. HAB_CAAM_UNLOCK_RNG = 0x02 /**< Leave RNG state handle 0
  1092. * uninstantiated, do not generate
  1093. * descriptor keys, do not set AES DPA
  1094. * mask, do not block state handle 0 test
  1095. * instantiation */
  1096. } hab_caam_unlock_flag_t;
  1097. /** SNVS unlock flags
  1098. * @ingroup snvs
  1099. */
  1100. typedef enum hab_snvs_unlock_flag {
  1101. HAB_SNVS_UNLOCK_LP_SWR = 0x01, /**< Leave LP SW reset unlocked */
  1102. HAB_SNVS_UNLOCK_ZMK_WRITE = 0x02 /**< Leave Zeroisable Master Key write
  1103. * unlocked */
  1104. } hab_snvs_unlock_flag_t;
  1105. /** SNVS master keys
  1106. * @ingroup snvs
  1107. *
  1108. * @remark Note that the first two master key selections are completely
  1109. * interchangeable.
  1110. */
  1111. typedef enum hab_snvs_keys {
  1112. HAB_SNVS_OTPMK = 0, /**< OTP master key */
  1113. HAB_SNVS_OTPMK_ALIAS = 1, /**< OTP master key (alias) */
  1114. HAB_SNVS_ZMK = 2, /**< Zeroisable master key */
  1115. HAB_SNVS_CMK = 3 /**< Combined master key */
  1116. } hab_snvs_keys_t;
  1117. /** OCOTP unlock flags
  1118. * @ingroup ocotp
  1119. */
  1120. typedef enum hab_ocotp_unlock_flag {
  1121. HAB_OCOTP_UNLOCK_FIELD_RETURN = 0x01, /**< Leave Field Return activation
  1122. * unlocked */
  1123. HAB_OCOTP_UNLOCK_SRK_REVOKE = 0x02, /**< Leave SRK revocation unlocked */
  1124. HAB_OCOTP_UNLOCK_SCS = 0x04, /**< Leave SCS register unlocked */
  1125. HAB_OCOTP_UNLOCK_JTAG = 0x08 /**< Unlock JTAG using SCS HAB_JDE
  1126. * bit */
  1127. } hab_ocotp_unlock_flag_t;
  1128. /** DCP configuration flags
  1129. * @ingroup dcp
  1130. *
  1131. * @warning The byte-swapping controls produce unpredictable results unless
  1132. * the input data block lengths are multiples of 4 bytes.
  1133. */
  1134. typedef enum hab_dcp_config {
  1135. HAB_DCP_IN_SWAP8 = 0x01, /**< Set INPUT BYTE SWAP bit (reverse bytes
  1136. * within words on input to DCP) */
  1137. /* no SWAP16 for DCP - leave 0x02 value unassigned */
  1138. HAB_DCP_IN_SWAP32 = 0x04, /**< Set INPUT WORD SWAP bit (ignored for
  1139. * hashing) */
  1140. HAB_DCP_OUT_SWAP8 = 0x08, /**< Set OUPUT BYTE SWAP bit (reverse bytes
  1141. * within words on output from DCP) */
  1142. /* no SWAP16 for DCP - leave 0x10 value unassigned */
  1143. HAB_DCP_OUT_SWAP32 = 0x20 /**< Set OUTPUT WORD SWAP bit (ignored for
  1144. * hashing) */
  1145. } hab_dcp_config_t;
  1146. #ifdef HAB_FUTURE
  1147. /** EC key specification types.
  1148. * @ingroup key_ecdsa
  1149. */
  1150. typedef enum hab_ec_spec {
  1151. /** Named curve specification. The curve specification is a DER-encoded
  1152. * object identifier. Supported object identifiers are listed under @ref
  1153. * key_ecdsa_profile "ECDSA key profile".
  1154. */
  1155. HAB_EC_SPEC_NAMED_CURVE = 0x01
  1156. } hab_ec_spec_t;
  1157. #endif
  1158. /** Variable configuration items
  1159. * @ingroup cmd_set
  1160. */
  1161. typedef enum hab_var_cfg_itm {
  1162. HAB_VAR_CFG_ITM_MID = 0x01, /**< Manufacturing ID (MID) fuse locations */
  1163. HAB_VAR_CFG_ITM_ENG = 0x03 /**< Preferred engine for a given algorithm */
  1164. } hab_var_cfg_itm_t;
  1165. /*===========================================================================
  1166. ENUMS
  1167. =============================================================================*/
  1168. /*===========================================================================
  1169. STRUCTURES AND OTHER TYPEDEFS
  1170. =============================================================================*/
  1171. /** Header field components
  1172. * @ingroup hdr
  1173. */
  1174. typedef struct hab_hdr {
  1175. uint8_t tag; /**< Tag field */
  1176. uint8_t len[2]; /**< Length field in bytes (big-endian) */
  1177. uint8_t par; /**< Parameters field */
  1178. } hab_hdr_t;
  1179. /** Loader callback.
  1180. * @ingroup auth_img
  1181. *
  1182. * @par Purpose
  1183. *
  1184. * This function must be supplied by the library caller if required. It is
  1185. * intended to finalise image loading in those boot modes where only a portion
  1186. * of the image is loaded to a temporary initial location prior to device
  1187. * configuration.
  1188. *
  1189. * @par Operation
  1190. *
  1191. * This function is called during hab_rvt.authenticate_image() between running
  1192. * the @ref dcd and @ref csf. The operation of this function is defined by
  1193. * the caller.
  1194. *
  1195. * @param[in,out] start Initial (possibly partial) image load address on
  1196. * entry. Final image load address on exit.
  1197. *
  1198. * @param[in,out] bytes Initial (possibly partial) image size on entry. Final
  1199. * image size on exit.
  1200. *
  1201. * @param[in] boot_data Initial @ref ivt Boot Data load address.
  1202. *
  1203. * @remark The interpretation of the Boot Data is defined by the caller.
  1204. * Different boot components or modes may use different boot data, or even
  1205. * different loader callback functions.
  1206. *
  1207. * @warning It should not be assumed by this function that the Boot Data is
  1208. * valid or authentic.
  1209. *
  1210. * @warning It is the responsibility of the loader callback to check the final
  1211. * image load addresses using hab_rvt.check_target() prior to copying any image
  1212. * data.
  1213. *
  1214. * @pre The (possibly partial) image has been loaded in the initial load
  1215. * address, and the Boot Data is within the initial image.
  1216. *
  1217. * @pre The @ref dcd has been run, if provided.
  1218. *
  1219. * @post The final image load addresses pass hab_rvt.check_target().
  1220. *
  1221. * @retval #HAB_SUCCESS if all operations completed successfully,
  1222. *
  1223. * @retval #HAB_FAILURE otherwise.
  1224. */
  1225. typedef hab_status_t (*hab_loader_callback_f)(
  1226. void** start,
  1227. size_t* bytes,
  1228. const void* boot_data);
  1229. /*---------------------------------------------------------------------------*/
  1230. /** Image entry function prototype
  1231. * @ingroup rvt
  1232. *
  1233. * This typedef serves as the return type for hab_rvt.authenticate_image(). It
  1234. * specifies a void-void function pointer, but can be cast to another function
  1235. * pointer type if required.
  1236. */
  1237. typedef void (*hab_image_entry_f)(void);
  1238. /*---------------------------------------------------------------------------*/
  1239. /** @ref rvt structure
  1240. * @ingroup rvt
  1241. *
  1242. * @par Format
  1243. *
  1244. * The @ref rvt consists of a @ref hdr followed by a list of addresses as
  1245. * described further below.
  1246. */
  1247. struct hab_rvt {
  1248. /** @ref hdr with tag #HAB_TAG_RVT, length and HAB version fields
  1249. * (see @ref data)
  1250. */
  1251. hab_hdr_t hdr;
  1252. /** Enter and initialise HAB library.
  1253. * @ingroup entry
  1254. *
  1255. * @par Purpose
  1256. *
  1257. * This function initialises the HAB library and @ref shw plugins. It is
  1258. * intended for use by post-ROM boot stage components, via the @ref rvt,
  1259. * prior to calling any other HAB functions other than
  1260. * hab_rvt.report_event() and hab_rvt.report_status().
  1261. *
  1262. * @ifrom It is also intended for use by the boot ROM via hab_rvt.entry().
  1263. * @endrom
  1264. *
  1265. * @par Operation
  1266. *
  1267. * This function performs the following operations every time it is called:
  1268. *
  1269. * - Initialise the HAB library internal state
  1270. * - Initialise the internal secret key store (cleared at the next
  1271. * hab_rvt.exit())
  1272. * - Run the entry sequence of each available @ref shw plugin
  1273. *
  1274. * When first called from boot ROM, this function also performs the
  1275. * following operations prior to those given above:
  1276. *
  1277. * - Initialise the internal public key store (persists beyond
  1278. * hab_rvt.exit())
  1279. * - Run the self-test sequence of each available @ref shw plugin
  1280. * - If a state machine is present and enabled, change the security state
  1281. * as follows:
  1282. * - If the IC is configured as #HAB_CFG_OPEN or #HAB_CFG_RETURN, move to
  1283. * #HAB_STATE_NONSECURE
  1284. * - If the IC is configured as #HAB_CFG_CLOSED, move to
  1285. * #HAB_STATE_TRUSTED
  1286. * - Otherwise, leave the security state unchanged
  1287. *
  1288. * If any failure occurs in the operations above:
  1289. *
  1290. * - An audit event is logged
  1291. * - All remaining operations are abandoned (except that all @ref shw
  1292. * self-test and entry sequences are still executed)
  1293. * - If a state machine is present and enabled, the security state is set
  1294. * as follows:
  1295. * - @ifrom Unless the IC is configured as #HAB_CFG_FAB,@endrom move to
  1296. * #HAB_STATE_NONSECURE. Note that if a security violation has been
  1297. * detected by the HW, the final state will be #HAB_STATE_FAIL_SOFT or
  1298. * #HAB_STATE_FAIL_HARD depending on the HW configuration.
  1299. *
  1300. * @warning Boot sequences may comprise several images with each launching
  1301. * the next as well as alternative images should one boot device or boot
  1302. * image be unavailable or unusable. The authentication of each image in
  1303. * a boot sequence must be bracketed by its own hab_rvt.entry()
  1304. * ... hab_rvt.exit() pair in order to ensure that security state
  1305. * information gathered for one image cannot be misapplied to another
  1306. * image.
  1307. *
  1308. * @ifrom
  1309. *
  1310. * @warning This applies to each boot path in boot ROM as well, except for
  1311. * the fabrication test path.
  1312. *
  1313. * @endrom
  1314. *
  1315. * @post HAB library internal state is initialised.
  1316. *
  1317. * @post Available @ref shw plugins are initialised.
  1318. *
  1319. * @post If a failure or warning occurs during @ref shw plugin
  1320. * initialisation, an audit event is logged with the relevant @ref eng
  1321. * tag. The status and reason logged are described in the relevant @ref
  1322. * shw plugin documentation.
  1323. *
  1324. * @post Security state is initialised, if a state machine is present and
  1325. * enabled.
  1326. *
  1327. * @retval #HAB_SUCCESS on an IC not configured as #HAB_CFG_CLOSED,
  1328. * although unsuccessful operations will still generate audit log events,
  1329. *
  1330. * @retval #HAB_SUCCESS on other ICs if all commands completed
  1331. * without failure (even if warnings were generated),
  1332. *
  1333. * @retval #HAB_FAILURE otherwise.
  1334. */
  1335. hab_status_t (*entry)(void);
  1336. /** Finalise and exit HAB library.
  1337. * @ingroup exit
  1338. *
  1339. * @par Purpose
  1340. *
  1341. * This function finalises the HAB library and @ref shw plugins. It is
  1342. * intended for use by post-ROM boot stage components, via the @ref rvt,
  1343. * after calling other HAB functions and prior to launching the next boot
  1344. * stage or switching to another boot path.
  1345. *
  1346. * @ifrom It is also intended for use by the boot ROM via hab_rvt.exit().
  1347. * @endrom
  1348. *
  1349. * @par Operation
  1350. *
  1351. * This function performs the following operations:
  1352. *
  1353. * - Finalise the HAB library internal state
  1354. * - Clear the internal secret key store
  1355. * - Run the finalisation sequence of each available @ref shw plugin
  1356. *
  1357. * If any failure occurs, an audit event is logged and all remaining
  1358. * operations are abandoned (except that all @ref shw exit sequences are
  1359. * still executed).
  1360. *
  1361. * @warning See warnings for hab_rvt.entry().
  1362. *
  1363. * @post #HAB_ASSERT_BLOCK records are cleared from audit log. Note that
  1364. * other event records are not cleared.
  1365. *
  1366. * @post Any public keys installed by @ref csf commands remain active.
  1367. *
  1368. * @post Any secret keys installed by @ref csf commands are deleted.
  1369. *
  1370. * @post Available @ref shw plugins are in their final state as described
  1371. * in the relevant sections.
  1372. *
  1373. * @post If a failure or warning occurs, an audit event is logged with the
  1374. * @ref eng tag of the @ref shw plugin concerned. The status and reason
  1375. * logged are described in the relevant @ref shw plugin documentation.
  1376. *
  1377. * @retval #HAB_SUCCESS on an IC not configured as #HAB_CFG_CLOSED,
  1378. * although unsuccessful operations will still generate audit log events,
  1379. *
  1380. * @retval #HAB_SUCCESS on other ICs if all commands completed
  1381. * without failure (even if warnings were generated),
  1382. *
  1383. * @retval #HAB_FAILURE otherwise.
  1384. */
  1385. hab_status_t (*exit)(void);
  1386. /** Check target address
  1387. * @ingroup chk_tgt
  1388. *
  1389. * @par Purpose
  1390. *
  1391. * This function reports whether or not a given target region is allowed
  1392. * for either peripheral configuration or image loading in memory. It is
  1393. * intended for use by post-ROM boot stage components, via the @ref rvt,
  1394. * in order to avoid configuring security-sensitive peripherals, or
  1395. * loading images over sensitive memory regions or outside recognised
  1396. * memory devices in the address map.
  1397. *
  1398. * @ifrom It is also available for use by the boot ROM, both directly via
  1399. * hab_rvt.check_target() and indirectly via hab_rvt.authenticate_image().
  1400. * @endrom
  1401. *
  1402. * @par Operation
  1403. *
  1404. * The lists of allowed target regions vary by IC and core, and should be
  1405. * taken from the @ref ref_rug.
  1406. *
  1407. * @ifrom The allowed register sets for peripheral configuration and memory
  1408. * regions for image loading are defined in the @ref hal by
  1409. * #hab_hal_peripheral and #hab_hal_memory respectively. @endrom
  1410. *
  1411. * @param[in] type Type of target (memory, peripheral or any in which both
  1412. * the memory and peripheral regions are checked)
  1413. *
  1414. * @param[in] start Address of target region
  1415. *
  1416. * @param[in] bytes Size of target region
  1417. *
  1418. * @post if the given target region goes beyond the allowed regions, an
  1419. * audit event is logged with status #HAB_FAILURE and reason
  1420. * #HAB_INV_ADDRESS, together with the call parameters. See the @ref evt
  1421. * record documentation for details.
  1422. *
  1423. * @post For successful commands, no audit event is logged.
  1424. *
  1425. * @retval #HAB_SUCCESS on an IC not configured as #HAB_CFG_CLOSED,
  1426. * although unsuccessful operations will still generate audit log events,
  1427. *
  1428. * @retval #HAB_SUCCESS if the given target region lies wholly within the
  1429. * allowed regions for the requested type of target.
  1430. *
  1431. * @retval #HAB_FAILURE otherwise
  1432. */
  1433. hab_status_t (*check_target)(hab_target_t type,
  1434. const void* start,
  1435. size_t bytes);
  1436. /** Authenticate image.
  1437. * @ingroup auth_img
  1438. *
  1439. * @par Purpose
  1440. *
  1441. * This function combines DCD, CSF and Assert functions in a standard
  1442. * sequence in order to authenticate a loaded image. It is intended for
  1443. * use by post-ROM boot stage components, via the @ref rvt. Support for
  1444. * images partially loaded to an initial location is provided via a
  1445. * callback function.
  1446. *
  1447. * @ifrom It is also available for use by the boot ROM via
  1448. * hab_rvt.authenticate_image(). @endrom
  1449. *
  1450. * @par Operation
  1451. *
  1452. * This function performs the following sequence of operations:
  1453. * - Check that the initial image load addresses pass
  1454. * hab_rvt.check_target().
  1455. * - Check that the IVT offset lies within the initial image bounds.
  1456. * - Check that the @ref ivt @a self and @a entry pointers are not NULL
  1457. * - Check the @ref ivt header for consistency and compatability.
  1458. * - If provided in the @ref ivt, calculate the @ref dcd initial location,
  1459. * check that it lies within the initial image bounds, and run the @ref
  1460. * dcd commands.
  1461. * - If provided in the @ref ivt, calculate the Boot Data initial location
  1462. * and check that it lies within the initial image bounds.
  1463. * - If provided in the parameters, invoke the callback function with the
  1464. * initial image bounds and initial location of the @ref ivt Boot Data.
  1465. *
  1466. * From this point on, the full image is assumed to be in its final
  1467. * location. The following operations will be performed on all IC
  1468. * configurations (#hab_config), but will be only enforced on an IC
  1469. * configured as #HAB_CFG_CLOSED:
  1470. * - Check that the final image load addresses pass hab_rvt.check_target().
  1471. * - Check that the CSF lies within the image bounds, and run the CSF
  1472. * commands.
  1473. * - Check that all of the following data have been authenticated (using
  1474. * their final locations):
  1475. * - IVT;
  1476. * - DCD (if provided);
  1477. * - Boot Data (initial byte if provided);
  1478. * - Entry point (initial word).
  1479. *
  1480. * @param[in] cid Caller ID, used to identify which SW issued this call.
  1481. *
  1482. * @param[in] ivt_offset Offset in bytes of the IVT from the image start
  1483. * address.
  1484. *
  1485. * @param[in,out] start Initial (possibly partial) image load address on
  1486. * entry. Final image load address on exit.
  1487. *
  1488. * @param[in,out] bytes Initial (possibly partial) image size on entry.
  1489. * Final image size on exit.
  1490. *
  1491. * @param[in] loader Callback function to load the full image to its final
  1492. * load address. Set to NULL if not required.
  1493. *
  1494. * @remark Caller ID may be bound to signatures verified using keys
  1495. * installed with #HAB_CMD_INS_KEY_CID flag. See @ref cmd_ins_key and @ref
  1496. * bnd_obj for details.
  1497. *
  1498. * @remark A @a loader callback function may be supplied even if the image
  1499. * is already loaded to its final location on entry.
  1500. *
  1501. * @remark Boot Data (boot_data in @ref ivt) will be ignored if the
  1502. * @a loader callback function point is set to Null.
  1503. *
  1504. * @warning The @a loader callback function should lie within existing
  1505. * authenticated areas. @ifrom Or within the ROM. @endrom
  1506. *
  1507. * @warning It is the responsibility of the caller to check the initial
  1508. * image load addresses using hab_rvt.check_target() prior to loading the
  1509. * initial image and calling this function.
  1510. *
  1511. * @warning After completion of hab_rvt.authenticate_image(), the caller
  1512. * should test using hab_rvt.assert() that the Boot Data was
  1513. * authenticated.
  1514. *
  1515. * @post The post-conditions of the functions hab_rvt.check_target(),
  1516. * hab_rvt.run_dcd(), hab_rvt.run_csf() and hab_rvt.assert() apply also to
  1517. * this function. In particular, any audit events logged within the given
  1518. * functions have the context field appropriate to that function rather
  1519. * than #HAB_CTX_AUTHENTICATE. In addition, the side-effects and
  1520. * post-conditions of any callback function supplied apply.
  1521. *
  1522. * @post If a failure or warning occurs outside these contexts, an audit
  1523. * event is logged with status:
  1524. * - #HAB_FAILURE, with further reasons:
  1525. * - #HAB_INV_ADDRESS: initial or final image addresses outside allowed
  1526. * regions
  1527. * - #HAB_INV_ADDRESS: IVT, DCD, Boot Data or CSF outside image bounds
  1528. * - #HAB_INV_ADDRESS: IVT @a self or @a entry pointer is NULL
  1529. * - #HAB_INV_CALL: hab_rvt.entry() not run successfully prior to call
  1530. * - #HAB_INV_IVT: IVT malformed
  1531. * - #HAB_INV_IVT: IVT version number is less than HAB library version
  1532. * - #HAB_INV_RETURN: Callback function failed
  1533. *
  1534. * @retval entry field from @ref ivt on an IC not configured as
  1535. * #HAB_CFG_CLOSED provided that the following conditions are met
  1536. * (other unsuccessful operations will generate audit log events):
  1537. * - the @a start pointer and the pointer it locates are not NULL
  1538. * - the initial @ref ivt location is not NULL
  1539. * - the @ref ivt @ref hdr (given in the @a hdr field) is valid
  1540. * - the final @ref ivt location (given by the @a self field) is not NULL
  1541. * - any loader callback completed successfully,
  1542. *
  1543. * @retval entry field from @ref ivt on other ICs if all operations
  1544. * completed without failure (even if warnings were generated),
  1545. *
  1546. * @retval NULL otherwise.
  1547. */
  1548. hab_image_entry_f (*authenticate_image)(uint8_t cid,
  1549. ptrdiff_t ivt_offset,
  1550. void** start,
  1551. size_t* bytes,
  1552. hab_loader_callback_f loader);
  1553. /** Execute a boot configuration script.
  1554. * @ingroup run_dcd
  1555. *
  1556. * @par Purpose
  1557. *
  1558. * This function configures the IC based upon a @ref dcd table. It is
  1559. * intended for use by post-ROM boot stage components, via the @ref rvt.
  1560. * This function may be invoked as often as required for each boot stage.
  1561. *
  1562. * @ifrom It is also intended for use by the boot ROM, both directly via
  1563. * hab_rvt.run_dcd() and indirectly via hab_rvt.authenticate_image().
  1564. * @endrom
  1565. *
  1566. * The difference between the configuration functionality in this function
  1567. * and hab_rvt.run_csf() arises because the @ref dcd table is not
  1568. * authenticated prior to running the commands. Hence, there is a more
  1569. * limited range of commands allowed, and a limited range of parameters to
  1570. * allowed commands.
  1571. *
  1572. * @par Operation
  1573. *
  1574. * This function performs the following operations:
  1575. * - Checks the @ref hdr for compatibility and consistency
  1576. * - Makes an internal copy of the @ref dcd table
  1577. * - Executes the commands in sequence from the internal copy of the @ref
  1578. * dcd
  1579. *
  1580. * If any failure occurs, an audit event is logged and all remaining
  1581. * operations are abandoned.
  1582. *
  1583. * @param[in] dcd Address of the @ref dcd.
  1584. *
  1585. * @warning It is the responsibility of the caller to ensure that the @a
  1586. * dcd parameter points to a valid memory location.
  1587. *
  1588. * @warning The @ref dcd must be authenticated by a subsequent @ref csf
  1589. * command prior to launching the next boot image, in order to avoid
  1590. * unauthorised configurations which may subvert secure operation.
  1591. * Although the content of the next boot stage's CSF may be out of scope
  1592. * for the hab_rvt.run_dcd() caller, it is possible to enforce this
  1593. * constraint by using hab_rvt.assert() to ensure that both the DCD and
  1594. * any pointers used to locate it have been authenticated.
  1595. *
  1596. * @warning Each invocation of hab_rvt.run_dcd() must occur between a pair
  1597. * of hab_rvt.entry() and hab_rvt.exit() calls, although multiple
  1598. * hab_rvt.run_dcd() calls (and other HAB calls) may be made in one
  1599. * bracket. This constraint applies whether hab_rvt.run_dcd() is
  1600. * successful or not: a subsequent call to hab_rvt.exit() is required
  1601. * prior to launching the authenticated image or switching to another boot
  1602. * target.
  1603. *
  1604. * @post Many commands may cause side-effects. See the @ref dcd
  1605. * documentation.
  1606. *
  1607. * @post If a failure or warning occurs within a command handler, an audit
  1608. * event is logged with the offending command, copied from the DCD. The
  1609. * status and reason logged are described in the relevant command
  1610. * documentation.
  1611. *
  1612. * @post For other failures or warning, the status logged is:
  1613. * - #HAB_WARNING, with further reasons:
  1614. * - #HAB_UNS_COMMAND: unsupported command encountered, where DCD
  1615. * version and HAB library version differ
  1616. * - #HAB_FAILURE, with further reasons:
  1617. * - #HAB_INV_ADDRESS: NULL @a dcd parameter
  1618. * - #HAB_INV_CALL: hab_rvt.entry() not run successfully prior to call
  1619. * - #HAB_INV_COMMAND: command not allowed in DCD
  1620. * - #HAB_UNS_COMMAND: unrecognised command encountered, where DCD
  1621. * version and HAB library version match
  1622. * - #HAB_INV_DCD: DCD malformed or too large
  1623. * - #HAB_INV_DCD: DCD version number is less than HAB library version
  1624. * @retval #HAB_SUCCESS on an IC not configured as #HAB_CFG_CLOSED,
  1625. * although unsuccessful operations will still generate audit log events,
  1626. *
  1627. * @retval #HAB_SUCCESS on other ICs if all commands completed
  1628. * without failure (even if warnings were generated),
  1629. *
  1630. * @retval #HAB_FAILURE otherwise.
  1631. */
  1632. hab_status_t (*run_dcd)(const uint8_t* dcd);
  1633. /** Execute an authentication script.
  1634. * @ingroup run_csf
  1635. *
  1636. * @par Purpose
  1637. *
  1638. * This function authenticates SW images and configures the IC based upon
  1639. * a @ref csf. It is intended for use by post-ROM boot stage components,
  1640. * via the @ref rvt. This function may be invoked as often as required
  1641. * for each boot stage.
  1642. *
  1643. * @ifrom It is also available for use by the boot ROM via hab_rvt.run_csf,
  1644. * although it is anticipated that the boot ROM will mostly call this
  1645. * function indirectly via hab_rvt.authenticate_image(). @endrom
  1646. *
  1647. * @par Operation
  1648. *
  1649. * This function performs the following operations:
  1650. * - Checks the @ref hdr for compatibility and consistency
  1651. * - Makes an internal copy of the @ref csf
  1652. * - Executes the commands in sequence from the internal copy of the @ref
  1653. * csf
  1654. *
  1655. * The internal copy of the @ref csf is authenticated by an explicit
  1656. * command in the sequence. Prior to authentication, a limited set of
  1657. * commands is available to:
  1658. * - Install a Super-Root key (unless previously installed)
  1659. * - Install a CSF key (unless previously installed)
  1660. * - Specify any variable configuration items
  1661. * - Authenticate the CSF
  1662. *
  1663. * Subsequent to CSF authentication, the full set of commands is available.
  1664. *
  1665. * If any failure occurs, an audit event is logged and all remaining
  1666. * operations are abandoned.
  1667. *
  1668. * @param[in] csf Address of the @ref csf.
  1669. *
  1670. * @param[in] cid Caller ID, used to identify which SW issued this call.
  1671. *
  1672. * @remark Caller ID may be bound to signatures verified using keys
  1673. * installed with #HAB_CMD_INS_KEY_CID flag. See @ref cmd_ins_key and @ref
  1674. * bnd_obj for details.
  1675. *
  1676. * @warning It is the responsibility of the caller to ensure that the @a
  1677. * csf parameter points to a valid memory location.
  1678. *
  1679. * @warning Each invocation of hab_rvt.run_csf() must occur between a pair
  1680. * of hab_rvt.entry() and hab_rvt.exit() calls, although multiple
  1681. * hab_rvt.run_csf() calls (and other HAB calls) may be made in one
  1682. * bracket. This constraint applies whether hab_rvt.run_csf() is
  1683. * successful or not: a subsequent call to hab_rvt.exit() is required
  1684. * prior to launching the authenticated image or switching to another boot
  1685. * target.
  1686. *
  1687. * @post Many commands may cause side-effects. See the @ref csf
  1688. * documentation. In particular, note that keys installed by the @ref csf
  1689. * remain available for use in subsequent operations.
  1690. *
  1691. * @post If a failure or warning occurs within a command handler, an audit
  1692. * event is logged with the offending command, copied from the CSF. The
  1693. * status and reason logged are described in the relevant command
  1694. * documentation.
  1695. *
  1696. * @post For other failures or warning, the status logged is:
  1697. * - #HAB_WARNING, with further reasons:
  1698. * - #HAB_UNS_COMMAND: unsupported command encountered, where CSF
  1699. * version and HAB library version differ
  1700. * - #HAB_FAILURE, with further reasons:
  1701. * - #HAB_INV_ADDRESS: NULL @a csf parameter
  1702. * - #HAB_INV_CALL: hab_rvt.entry() not run successfully prior to call
  1703. * - #HAB_INV_COMMAND: command not allowed prior to CSF authentication
  1704. * - #HAB_UNS_COMMAND: unrecognised command encountered, where CSF
  1705. * version and HAB library version match
  1706. * - #HAB_INV_CSF: CSF not authenticated
  1707. * - #HAB_INV_CSF: CSF malformed or too large
  1708. * - #HAB_INV_CSF: CSF version number is less than HAB library version
  1709. *
  1710. * @retval #HAB_SUCCESS on an IC not configured as #HAB_CFG_CLOSED,
  1711. * although unsuccessful operations will still generate audit log events,
  1712. *
  1713. * @retval #HAB_SUCCESS on other ICs if all commands completed
  1714. * without failure (even if warnings were generated),
  1715. *
  1716. * @retval #HAB_FAILURE otherwise.
  1717. */
  1718. hab_status_t (*run_csf)(const uint8_t* csf,
  1719. uint8_t cid);
  1720. /** Test an assertion against the audit log.
  1721. * @ingroup assert
  1722. *
  1723. * @par Purpose
  1724. *
  1725. * This function allows the audit log to be interrogated. It is intended
  1726. * for use by post-ROM boot stage components, via the @ref rvt, to
  1727. * determine the state of authentication operations. This function may be
  1728. * invoked as often as required for each boot stage.
  1729. *
  1730. * @ifrom It is also available for use by the boot ROM, both directly via
  1731. * hab_rvt.assert() and indirectly via hab_rvt.authenticate_image().
  1732. * @endrom
  1733. *
  1734. * @par Operation
  1735. *
  1736. * This function checks the required assertion as detailed below.
  1737. *
  1738. * @param[in] type Assertion type.
  1739. *
  1740. * @param[in] data Assertion data.
  1741. *
  1742. * @param[in] count Data size or count.
  1743. *
  1744. * @par Memory block authentication:
  1745. * For #HAB_ASSERT_BLOCK assertion type, hab_rvt.assert() checks that the
  1746. * given memory block has been authenticated after running a CSF. The
  1747. * parameters are interpreted as follows:
  1748. *
  1749. * @par
  1750. * - @a data: memory block starting address
  1751. * - @a count: memory block size (in bytes)
  1752. *
  1753. * @par
  1754. *
  1755. * A simple interpretation of "memory block has been authenticated" is
  1756. * taken, such that the given block must lie wholly within a single
  1757. * contiguous block authenticated while running a CSF. A given memory
  1758. * block covered by the union of several neighboring or overlapping
  1759. * authenticated blocks could fail the test with this interpretation, but
  1760. * it is assumed that such cases will not arise in practice.
  1761. *
  1762. * @post If the assertion fails, an audit event is logged with status
  1763. * #HAB_FAILURE and reason #HAB_INV_ASSERTION, together with the call
  1764. * parameters. See the @ref evt record documentation for details.
  1765. *
  1766. * @post For successful commands, no audit event is logged.
  1767. *
  1768. * @retval #HAB_SUCCESS on an IC not configured as #HAB_CFG_CLOSED,
  1769. * although unsuccessful operations will still generate audit log events,
  1770. *
  1771. * @retval #HAB_SUCCESS on other ICs if the assertion is confirmed
  1772. *
  1773. * @retval #HAB_FAILURE otherwise
  1774. */
  1775. hab_status_t (*assert)(hab_assertion_t type,
  1776. const void* data,
  1777. uint32_t count);
  1778. /** Report an event from the audit log.
  1779. * @ingroup event
  1780. *
  1781. * @par Purpose
  1782. *
  1783. * This function allows the audit log to be interrogated. It is intended
  1784. * for use by post-ROM boot stage components, via the @ref rvt, to
  1785. * determine the state of authentication operations. This function may
  1786. * be called outside an hab_rvt.entry() / hab_rvt.exit() pair.
  1787. *
  1788. * @ifrom It is also available for use by the boot ROM, where it may be
  1789. * used to report boot failures as part of a tethered boot
  1790. * protocol. @endrom
  1791. *
  1792. * @par Operation
  1793. *
  1794. * This function performs the following operations:
  1795. * - Scans the audit log for a matching event
  1796. * - Copies the required details to the output parameters (if found)
  1797. *
  1798. * @param[in] status Status level of required event.
  1799. *
  1800. * @param[in] index Index of required event at given status level.
  1801. *
  1802. * @param[out] event @ref evt record.
  1803. *
  1804. * @param[in,out] bytes Size of @a event buffer on entry, size of event
  1805. * record on exit.
  1806. *
  1807. * @remark Use @a status = #HAB_STS_ANY to match any logged event,
  1808. * regardless of the status value logged.
  1809. *
  1810. * @remark Use @a index = 0 to return the first matching event, @a index =
  1811. * 1 to return the second matching event, and so on.
  1812. *
  1813. * @remark The data logged with each event is context-dependent. Refer to
  1814. * @ref evt record documentation.
  1815. *
  1816. * @warning Parameter @a bytes may not be NULL.
  1817. *
  1818. * @warning If the @a event buffer is a NULL pointer or too small to fit
  1819. * the event record, the required size is written to @a bytes, but no
  1820. * part of the event record is copied to the output buffer.
  1821. *
  1822. * @retval #HAB_SUCCESS if the required event is found, and the event
  1823. * record is copied to the output buffer.
  1824. *
  1825. * @retval #HAB_SUCCESS if the required event is found and @a event buffer
  1826. * passed is a NULL pointer.
  1827. *
  1828. * @retval #HAB_FAILURE otherwise
  1829. */
  1830. hab_status_t (*report_event)(hab_status_t status,
  1831. uint32_t index,
  1832. uint8_t* event,
  1833. size_t* bytes);
  1834. /** Report security status.
  1835. * @ingroup status
  1836. *
  1837. * @par Purpose
  1838. *
  1839. * This function reports the security configuration and state of the IC as
  1840. * well as searching the audit log to determine the status of the boot
  1841. * process. It is intended for use by post-ROM boot stage components, via
  1842. * the @ref rvt. This function may be called outside an
  1843. * hab_rvt.entry() / hab_rvt.exit() pair.
  1844. *
  1845. * @ifrom It is also available for use by the boot ROM, and should be used
  1846. * rather than the HAL function hab_hal_read_sec_cfg(). @endrom
  1847. *
  1848. * @par Operation
  1849. *
  1850. * This function reads the fuses which indicate the security
  1851. * configuration. The fusemap varies by IC, and should be taken from the
  1852. * @ref ref_rug. It also uses the @ref shw state machine, if present and
  1853. * enabled, to report on the security state.
  1854. *
  1855. * @param[out] config Security configuration, NULL if not required
  1856. *
  1857. * @param[out] state Security state, NULL if not required
  1858. *
  1859. * @remark If no @ref shw state machine is present and enabled, the state
  1860. * #HAB_STATE_NONE will be output.
  1861. *
  1862. * @retval #HAB_SUCCESS if no warning or failure audit events have been
  1863. * logged.
  1864. *
  1865. * @retval #HAB_WARNING otherwise, if only warning events have been logged.
  1866. *
  1867. * @retval #HAB_FAILURE otherwise
  1868. */
  1869. hab_status_t (*report_status)(hab_config_t* config, hab_state_t* state);
  1870. /** Enter failsafe boot mode.
  1871. * @ingroup safe
  1872. *
  1873. * @par Purpose
  1874. *
  1875. * This function provides a safe path when image authentication has failed
  1876. * and all possible boot paths have been exhausted. It is intended for
  1877. * use by post-ROM boot stage components, via the @ref rvt.
  1878. *
  1879. * @ifrom It is also available for use by the boot ROM via
  1880. * hab_rvt.failsafe(). @endrom
  1881. *
  1882. * @par Operation
  1883. *
  1884. * The precise details of this function vary by IC and core, and should be
  1885. * taken from @ref ref_rug.
  1886. *
  1887. * @warning This function does not return.
  1888. *
  1889. * @remark Since this function does not return, it implicitly performs the
  1890. * functionality of hab_rvt.exit() in order to ensure an appropriate
  1891. * configuration of the @ref shw plugins.
  1892. *
  1893. * @remark Two typical implementations are:
  1894. * - a low-level provisioning protocol in which an image is downloaded to
  1895. * RAM from an external host, authenticated and launched. The downloaded
  1896. * image may communicate with tools on the external host to report the
  1897. * reasons for boot failure, and may re-provision the end-product with
  1898. * authentic boot images.
  1899. * - a failsafe boot mode which does not allow execution to leave the ROM
  1900. * until the IC is reset.
  1901. */
  1902. void (*failsafe)(void);
  1903. };
  1904. /** @ref rvt type
  1905. * @ingroup rvt
  1906. */
  1907. typedef struct hab_rvt hab_rvt_t;
  1908. /*---------------------------------------------------------------------------*/
  1909. /** @ref ivt structure
  1910. * @ingroup ivt
  1911. *
  1912. * @par Format
  1913. *
  1914. * An @ref ivt consists of a @ref hdr followed by a list of addresses as
  1915. * described further below.
  1916. *
  1917. * @warning The @a entry address may not be NULL.
  1918. *
  1919. * @warning On an IC not configured as #HAB_CFG_CLOSED, the
  1920. * @a csf address may be NULL. If it is not NULL, the @ref csf will be
  1921. * processed, but any failures should be non-fatal.
  1922. *
  1923. * @warning On an IC configured as #HAB_CFG_CLOSED, the @a
  1924. * csf address may not be NULL, and @ref csf failures are typically fatal.
  1925. *
  1926. * @remark The Boot Data located using the @a boot_data field is interpreted
  1927. * by the HAB caller in a boot-mode specific manner. This may be used by the
  1928. * boot ROM as to determine the load address and boot device configuration for
  1929. * images loaded from block devices (see @ref ref_rug for details).
  1930. *
  1931. * @remark All addresses given in the IVT, including the Boot Data (if
  1932. * present) are those for the final load location.
  1933. *
  1934. * @anchor ila
  1935. *
  1936. * @par Initial load addresses
  1937. *
  1938. * The @a self field is used to calculate addresses in boot modes where an
  1939. * initial portion of the image is loaded to an initial location. In such
  1940. * cases, the IVT, Boot Data (if present) and DCD (if present) are used in
  1941. * configuring the IC and loading the full image to its final location. Only
  1942. * the IVT, Boot Data (if present) and DCD (if present) are required to be
  1943. * within the initial image portion.
  1944. *
  1945. * The method for calculating an initial load address for the DCD is
  1946. * illustrated in the following C fragment. Similar calculations apply to
  1947. * other fields.
  1948. *
  1949. @verbatim
  1950. hab_ivt_t* ivt_initial = <initial IVT load address>;
  1951. const void* dcd_initial = ivt_initial->dcd;
  1952. if (ivt_initial->dcd != NULL)
  1953. dcd_initial = (const uint8_t*)ivt_initial
  1954. + (ivt_initial->dcd - ivt_initial->self)
  1955. @endverbatim
  1956. */
  1957. struct hab_ivt {
  1958. /** @ref hdr with tag #HAB_TAG_IVT, length and HAB version fields
  1959. * (see @ref data)
  1960. */
  1961. hab_hdr_t hdr;
  1962. /** Absolute address of the first instruction to execute from the
  1963. * image
  1964. */
  1965. hab_image_entry_f entry;
  1966. /** Reserved in this version of HAB: should be NULL. */
  1967. const void* reserved1;
  1968. /** Absolute address of the image DCD: may be NULL. */
  1969. const void* dcd;
  1970. /** Absolute address of the Boot Data: may be NULL, but not interpreted
  1971. * any further by HAB
  1972. */
  1973. const void* boot_data;
  1974. /** Absolute address of the IVT.*/
  1975. const void* self;
  1976. /** Absolute address of the image CSF.*/
  1977. const void* csf;
  1978. /** Reserved in this version of HAB: should be zero. */
  1979. uint32_t reserved2;
  1980. };
  1981. /** @ref ivt type
  1982. * @ingroup ivt
  1983. */
  1984. typedef struct hab_ivt hab_ivt_t;
  1985. /*===========================================================================
  1986. FUNCTION PROTOTYPES
  1987. =============================================================================*/
  1988. #ifdef __cplusplus
  1989. extern "C" {
  1990. #endif
  1991. #ifdef __cplusplus
  1992. }
  1993. #endif
  1994. #endif /* HAB_DEFINES_H */