2api.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. /* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
  2. * Use of this source code is governed by a BSD-style license that can be
  3. * found in the LICENSE file.
  4. */
  5. /* APIs between calling firmware and vboot_reference
  6. *
  7. * General notes:
  8. *
  9. * TODO: split this file into a vboot_entry_points.h file which contains the
  10. * entry points for the firmware to call vboot_reference, and a
  11. * vboot_firmware_exports.h which contains the APIs to be implemented by the
  12. * calling firmware and exported to vboot_reference.
  13. *
  14. * Notes:
  15. * * Assumes this code is never called in the S3 resume path. TPM resume
  16. * must be done elsewhere, and VB2_NV_DEBUG_RESET_MODE is ignored.
  17. */
  18. #ifndef VBOOT_2_API_H_
  19. #define VBOOT_2_API_H_
  20. #include <stdint.h>
  21. #include "2common.h"
  22. #include "2crypto.h"
  23. #include "2fw_hash_tags.h"
  24. #include "2id.h"
  25. #include "2recovery_reasons.h"
  26. #include "2return_codes.h"
  27. /* Size of non-volatile data used by vboot */
  28. #define VB2_NVDATA_SIZE 16
  29. /* Size of secure data spaces used by vboot */
  30. #define VB2_SECDATA_SIZE 10
  31. #define VB2_SECDATAK_SIZE 14
  32. /*
  33. * Recommended size of work buffer for firmware verification stage
  34. *
  35. * TODO: The recommended size really depends on which key algorithms are
  36. * used. Should have a better / more accurate recommendation than this.
  37. */
  38. #define VB2_WORKBUF_RECOMMENDED_SIZE (12 * 1024)
  39. /*
  40. * Recommended size of work buffer for kernel verification stage
  41. *
  42. * This is bigger because vboot 2.0 kernel preambles are usually padded to
  43. * 64 KB.
  44. *
  45. * TODO: The recommended size really depends on which key algorithms are
  46. * used. Should have a better / more accurate recommendation than this.
  47. */
  48. #define VB2_KERNEL_WORKBUF_RECOMMENDED_SIZE (80 * 1024)
  49. /* Recommended buffer size for vb2api_get_pcr_digest */
  50. #define VB2_PCR_DIGEST_RECOMMENDED_SIZE 32
  51. /* Flags for vb2_context.
  52. *
  53. * Unless otherwise noted, flags are set by verified boot and may be read (but
  54. * not set or cleared) by the caller.
  55. */
  56. enum vb2_context_flags {
  57. /*
  58. * Verified boot has changed nvdata[]. Caller must save nvdata[] back
  59. * to its underlying storage, then may clear this flag.
  60. */
  61. VB2_CONTEXT_NVDATA_CHANGED = (1 << 0),
  62. /*
  63. * Verified boot has changed secdata[]. Caller must save secdata[]
  64. * back to its underlying storage, then may clear this flag.
  65. */
  66. VB2_CONTEXT_SECDATA_CHANGED = (1 << 1),
  67. /* Recovery mode is requested this boot */
  68. VB2_CONTEXT_RECOVERY_MODE = (1 << 2),
  69. /* Developer mode is requested this boot */
  70. VB2_CONTEXT_DEVELOPER_MODE = (1 << 3),
  71. /*
  72. * Force recovery mode due to physical user request. Caller may set
  73. * this flag when initializing the context.
  74. */
  75. VB2_CONTEXT_FORCE_RECOVERY_MODE = (1 << 4),
  76. /*
  77. * Force developer mode enabled. Caller may set this flag when
  78. * initializing the context.
  79. */
  80. VB2_CONTEXT_FORCE_DEVELOPER_MODE = (1 << 5),
  81. /* Using firmware slot B. If this flag is clear, using slot A. */
  82. VB2_CONTEXT_FW_SLOT_B = (1 << 6),
  83. /* RAM should be cleared by caller this boot */
  84. VB2_CONTEXT_CLEAR_RAM = (1 << 7),
  85. /* Wipeout by the app should be requested. */
  86. VB2_CONTEXT_FORCE_WIPEOUT_MODE = (1 << 8),
  87. /* Erase TPM developer mode state if it is enabled. */
  88. VB2_DISABLE_DEVELOPER_MODE = (1 << 9),
  89. /*
  90. * Verified boot has changed secdatak[]. Caller must save secdatak[]
  91. * back to its underlying storage, then may clear this flag.
  92. */
  93. VB2_CONTEXT_SECDATAK_CHANGED = (1 << 10),
  94. /*
  95. * Allow kernel verification to roll forward the version in secdatak[].
  96. * Caller may set this flag before calling vb2api_kernel_phase3().
  97. */
  98. VB2_CONTEXT_ALLOW_KERNEL_ROLL_FORWARD = (1 << 11),
  99. /* Boot optimistically: don't touch failure counters */
  100. VB2_CONTEXT_NOFAIL_BOOT = (1 << 12),
  101. /*
  102. * Secdata is not ready this boot, but should be ready next boot. It
  103. * would like to reboot. The decision whether to reboot or not must be
  104. * deferred until vboot, because rebooting all the time before then
  105. * could cause a device with malfunctioning secdata to get stuck in an
  106. * unrecoverable crash loop.
  107. */
  108. VB2_CONTEXT_SECDATA_WANTS_REBOOT = (1 << 13),
  109. /* Boot is S3->S0 resume, not S5->S0 normal boot */
  110. VB2_CONTEXT_S3_RESUME = (1 << 14),
  111. };
  112. /*
  113. * Context for firmware verification. Pass this to all vboot APIs.
  114. *
  115. * Caller may relocate this between calls to vboot APIs.
  116. */
  117. struct vb2_context {
  118. /**********************************************************************
  119. * Fields which must be initialized by caller.
  120. */
  121. /*
  122. * Flags; see vb2_context_flags. Some flags may only be set by caller
  123. * prior to calling vboot functions.
  124. */
  125. uint32_t flags;
  126. /*
  127. * Work buffer, and length in bytes. Caller may relocate this between
  128. * calls to vboot APIs; it contains no internal pointers. Caller must
  129. * not examine the contents of this work buffer directly.
  130. */
  131. uint8_t *workbuf;
  132. uint32_t workbuf_size;
  133. /*
  134. * Non-volatile data. Caller must fill this from some non-volatile
  135. * location. If the VB2_CONTEXT_NVDATA_CHANGED flag is set when a
  136. * vb2api function returns, caller must save the data back to the
  137. * non-volatile location and then clear the flag.
  138. */
  139. uint8_t nvdata[VB2_NVDATA_SIZE];
  140. /*
  141. * Secure data for firmware verification stage. Caller must fill this
  142. * from some secure non-volatile location. If the
  143. * VB2_CONTEXT_SECDATA_CHANGED flag is set when a function returns,
  144. * caller must save the data back to the secure non-volatile location
  145. * and then clear the flag.
  146. */
  147. uint8_t secdata[VB2_SECDATA_SIZE];
  148. /*
  149. * Context pointer for use by caller. Verified boot never looks at
  150. * this. Put context here if you need it for APIs that verified boot
  151. * may call (vb2ex_...() functions).
  152. */
  153. void *non_vboot_context;
  154. /**********************************************************************
  155. * Fields caller may examine after calling vb2api_fw_phase1(). Caller
  156. * must set these fields to 0 before calling any vboot functions.
  157. */
  158. /*
  159. * Amount of work buffer used so far. Verified boot sub-calls use
  160. * this to know where the unused work area starts. Caller may use
  161. * this between calls to vboot APIs to know how much data must be
  162. * copied when relocating the work buffer.
  163. */
  164. uint32_t workbuf_used;
  165. /**********************************************************************
  166. * Fields caller must initialize before calling vb2api_kernel_phase1().
  167. */
  168. /*
  169. * Secure data for kernel verification stage. Caller must fill this
  170. * from some secure non-volatile location. If the
  171. * VB2_CONTEXT_SECDATAK_CHANGED flag is set when a function returns,
  172. * caller must save the data back to the secure non-volatile location
  173. * and then clear the flag.
  174. */
  175. uint8_t secdatak[VB2_SECDATAK_SIZE];
  176. };
  177. /* Resource index for vb2ex_read_resource() */
  178. enum vb2_resource_index {
  179. /* Google binary block */
  180. VB2_RES_GBB,
  181. /*
  182. * Firmware verified boot block (keyblock+preamble). Use
  183. * VB2_CONTEXT_FW_SLOT_B to determine whether this refers to slot A or
  184. * slot B; vboot will set that flag to the proper state before reading
  185. * the vblock.
  186. */
  187. VB2_RES_FW_VBLOCK,
  188. /*
  189. * Kernel verified boot block (keyblock+preamble) for the current
  190. * kernel partition. Used only by vb2api_kernel_load_vblock().
  191. * Contents are allowed to change between calls to that function (to
  192. * allow multiple kernels to be examined).
  193. */
  194. VB2_RES_KERNEL_VBLOCK,
  195. };
  196. /* Digest ID for vbapi_get_pcr_digest() */
  197. enum vb2_pcr_digest {
  198. /* Digest based on current developer and recovery mode flags */
  199. BOOT_MODE_PCR,
  200. /* SHA-256 hash digest of HWID, from GBB */
  201. HWID_DIGEST_PCR,
  202. };
  203. /******************************************************************************
  204. * APIs provided by verified boot.
  205. *
  206. * At a high level, call functions in the order described below. After each
  207. * call, examine vb2_context.flags to determine whether nvdata or secdata
  208. * needs to be written.
  209. *
  210. * If you need to cause the boot process to fail at any point, call
  211. * vb2api_fail(). Then check vb2_context.flags to see what data needs to be
  212. * written. Then reboot.
  213. *
  214. * Load nvdata from wherever you keep it.
  215. *
  216. * Load secdata from wherever you keep it.
  217. *
  218. * If it wasn't there at all (for example, this is the first boot
  219. * of a new system in the factory), call vb2api_secdata_create()
  220. * to initialize the data.
  221. *
  222. * If access to your storage is unreliable (reads/writes may
  223. * contain corrupt data), you may call vb2api_secdata_check() to
  224. * determine if the data was valid, and retry reading if it
  225. * wasn't. (In that case, you should also read back and check the
  226. * data after any time you write it, to make sure it was written
  227. * correctly.)
  228. *
  229. * Call vb2api_fw_phase1(). At present, this nominally decides whether
  230. * recovery mode is needed this boot.
  231. *
  232. * Call vb2api_fw_phase2(). At present, this nominally decides which
  233. * firmware slot will be attempted (A or B).
  234. *
  235. * Call vb2api_fw_phase3(). At present, this nominally verifies the
  236. * firmware keyblock and preamble.
  237. *
  238. * Lock down wherever you keep secdata. It should no longer be writable
  239. * this boot.
  240. *
  241. * Verify the hash of each section of code/data you need to boot the RW
  242. * firmware. For each section:
  243. *
  244. * Call vb2_init_hash() to see if the hash exists.
  245. *
  246. * Load the data for the section. Call vb2_extend_hash() on the
  247. * data as you load it. You can load it all at once and make one
  248. * call, or load and hash-extend a block at a time.
  249. *
  250. * Call vb2_check_hash() to see if the hash is valid.
  251. *
  252. * If it is valid, you may use the data and/or execute
  253. * code from that section.
  254. *
  255. * If the hash was invalid, you must reboot.
  256. *
  257. * At this point, firmware verification is done, and vb2_context contains the
  258. * kernel key needed to verify the kernel. That context should be preserved
  259. * and passed on to kernel selection. The kernel selection process may be
  260. * done by the same firmware image, or may be done by the RW firmware. The
  261. * recommended order is:
  262. *
  263. * Load secdatak from wherever you keep it.
  264. *
  265. * If it wasn't there at all (for example, this is the first boot
  266. * of a new system in the factory), call vb2api_secdatak_create()
  267. * to initialize the data.
  268. *
  269. * If access to your storage is unreliable (reads/writes may
  270. * contain corrupt data), you may call vb2api_secdatak_check() to
  271. * determine if the data was valid, and retry reading if it
  272. * wasn't. (In that case, you should also read back and check the
  273. * data after any time you write it, to make sure it was written
  274. * correctly.)
  275. *
  276. * Call vb2api_kernel_phase1(). At present, this decides which key to
  277. * use to verify kernel data - the recovery key from the GBB, or the
  278. * kernel subkey from the firmware verification stage.
  279. *
  280. * Kernel phase 2 is finding loading, and verifying the kernel partition.
  281. *
  282. * Find a boot device (you're on your own here).
  283. *
  284. * Call vb2api_load_kernel_vblock() for each kernel partition on the
  285. * boot device, until one succeeds.
  286. *
  287. * When that succeeds, call vb2api_get_kernel_size() to determine where
  288. * the kernel is located in the stream and how big it is. Load or map
  289. * the kernel. (Again, you're on your own. This is the responsibility of
  290. * the caller so that the caller can choose whether to allocate a buffer,
  291. * load the kernel data into a predefined area of RAM, or directly map a
  292. * kernel file into the address space. Note that technically it doesn't
  293. * matter whether the kernel data is even in the same file or stream as
  294. * the vblock, as long as the caller loads the right data.
  295. *
  296. * Call vb2api_verify_kernel_data() on the kernel data.
  297. *
  298. * If you ran out of kernels before finding a good one, call vb2api_fail()
  299. * with an appropriate recovery reason.
  300. *
  301. * Set the VB2_CONTEXT_ALLOW_KERNEL_ROLL_FORWARD flag if the current
  302. * kernel partition has the successful flag (that is, it's already known
  303. * or assumed to be a functional kernel partition).
  304. *
  305. * Call vb2api_kernel_phase3(). This cleans up from kernel verification
  306. * and updates the secure data if needed.
  307. *
  308. * Lock down wherever you keep secdatak. It should no longer be writable
  309. * this boot.
  310. */
  311. /**
  312. * Sanity-check the contents of the secure storage context.
  313. *
  314. * Use this if reading from secure storage may be flaky, and you want to retry
  315. * reading it several times.
  316. *
  317. * This may be called before vb2api_phase1().
  318. *
  319. * @param ctx Context pointer
  320. * @return VB2_SUCCESS, or non-zero error code if error.
  321. */
  322. int vb2api_secdata_check(const struct vb2_context *ctx);
  323. /**
  324. * Create fresh data in the secure storage context.
  325. *
  326. * Use this only when initializing the secure storage context on a new machine
  327. * the first time it boots. Do NOT simply use this if vb2api_secdata_check()
  328. * (or any other API in this library) fails; that could allow the secure data
  329. * to be rolled back to an insecure state.
  330. *
  331. * This may be called before vb2api_phase1().
  332. *
  333. * @param ctx Context pointer
  334. * @return VB2_SUCCESS, or non-zero error code if error.
  335. */
  336. int vb2api_secdata_create(struct vb2_context *ctx);
  337. /**
  338. * Sanity-check the contents of the kernel version secure storage context.
  339. *
  340. * Use this if reading from secure storage may be flaky, and you want to retry
  341. * reading it several times.
  342. *
  343. * This may be called before vb2api_phase1().
  344. *
  345. * @param ctx Context pointer
  346. * @return VB2_SUCCESS, or non-zero error code if error.
  347. */
  348. int vb2api_secdatak_check(const struct vb2_context *ctx);
  349. /**
  350. * Create fresh data in the kernel version secure storage context.
  351. *
  352. * Use this only when initializing the secure storage context on a new machine
  353. * the first time it boots. Do NOT simply use this if vb2api_secdatak_check()
  354. * (or any other API in this library) fails; that could allow the secure data
  355. * to be rolled back to an insecure state.
  356. *
  357. * This may be called before vb2api_phase1().
  358. *
  359. * @param ctx Context pointer
  360. * @return VB2_SUCCESS, or non-zero error code if error.
  361. */
  362. int vb2api_secdatak_create(struct vb2_context *ctx);
  363. /**
  364. * Report firmware failure to vboot.
  365. *
  366. * This may be called before vb2api_phase1() to indicate errors in the boot
  367. * process prior to the start of vboot.
  368. *
  369. * If this is called after vb2api_phase1(), on return, the calling firmware
  370. * should check for updates to secdata and/or nvdata, then reboot.
  371. *
  372. * @param reason Recovery reason
  373. * @param subcode Recovery subcode
  374. */
  375. void vb2api_fail(struct vb2_context *ctx, uint8_t reason, uint8_t subcode);
  376. /**
  377. * Firmware selection, phase 1.
  378. *
  379. * If the returned error is VB2_ERROR_API_PHASE1_RECOVERY, the calling firmware
  380. * should jump directly to recovery-mode firmware without rebooting.
  381. *
  382. * For other errors, the calling firmware should check for updates to secdata
  383. * and/or nvdata, then reboot.
  384. *
  385. * @param ctx Vboot context
  386. * @return VB2_SUCCESS, or error code on error.
  387. */
  388. int vb2api_fw_phase1(struct vb2_context *ctx);
  389. /**
  390. * Firmware selection, phase 2.
  391. *
  392. * On error, the calling firmware should check for updates to secdata and/or
  393. * nvdata, then reboot.
  394. *
  395. * @param ctx Vboot context
  396. * @return VB2_SUCCESS, or error code on error.
  397. */
  398. int vb2api_fw_phase2(struct vb2_context *ctx);
  399. /**
  400. * Firmware selection, phase 3.
  401. *
  402. * On error, the calling firmware should check for updates to secdata and/or
  403. * nvdata, then reboot.
  404. *
  405. * On success, the calling firmware should lock down secdata before continuing
  406. * with the boot process.
  407. *
  408. * @param ctx Vboot context
  409. * @return VB2_SUCCESS, or error code on error.
  410. */
  411. int vb2api_fw_phase3(struct vb2_context *ctx);
  412. /**
  413. * Same, but for new-style structs.
  414. */
  415. int vb21api_fw_phase3(struct vb2_context *ctx);
  416. /**
  417. * Initialize hashing data for the specified tag.
  418. *
  419. * @param ctx Vboot context
  420. * @param tag Tag to start hashing (enum vb2_hash_tag)
  421. * @param size If non-null, expected size of data for tag will be
  422. * stored here on output.
  423. * @return VB2_SUCCESS, or error code on error.
  424. */
  425. int vb2api_init_hash(struct vb2_context *ctx, uint32_t tag, uint32_t *size);
  426. /**
  427. * Same, but for new-style structs.
  428. */
  429. int vb21api_init_hash(struct vb2_context *ctx,
  430. const struct vb2_id *id,
  431. uint32_t *size);
  432. /**
  433. * Extend the hash started by vb2api_init_hash() with additional data.
  434. *
  435. * (This is the same for both old and new style structs.)
  436. *
  437. * @param ctx Vboot context
  438. * @param buf Data to hash
  439. * @param size Size of data in bytes
  440. * @return VB2_SUCCESS, or error code on error.
  441. */
  442. int vb2api_extend_hash(struct vb2_context *ctx,
  443. const void *buf,
  444. uint32_t size);
  445. /**
  446. * Check the hash value started by vb2api_init_hash().
  447. *
  448. * @param ctx Vboot context
  449. * @return VB2_SUCCESS, or error code on error.
  450. */
  451. int vb2api_check_hash(struct vb2_context *ctx);
  452. /**
  453. * Same, but for new-style structs.
  454. */
  455. int vb21api_check_hash(struct vb2_context *ctx);
  456. /**
  457. * Check the hash value started by vb2api_init_hash() while retrieving
  458. * calculated digest.
  459. *
  460. * @param ctx Vboot context
  461. * @param digest_out optional pointer to buffer to store digest
  462. * @param digest_out_size optional size of buffer to store digest
  463. * @return VB2_SUCCESS, or error code on error.
  464. */
  465. int vb2api_check_hash_get_digest(struct vb2_context *ctx, void *digest_out,
  466. uint32_t digest_out_size);
  467. /**
  468. * Get a PCR digest
  469. *
  470. * @param ctx Vboot context
  471. * @param which_digest PCR index of the digest
  472. * @param dest Destination where the digest is copied.
  473. * Recommended size is VB2_PCR_DIGEST_RECOMMENDED_SIZE.
  474. * @param dest_size IN: size of the buffer pointed by dest
  475. * OUT: size of the copied digest
  476. * @return VB2_SUCCESS, or error code on error
  477. */
  478. int vb2api_get_pcr_digest(struct vb2_context *ctx,
  479. enum vb2_pcr_digest which_digest,
  480. uint8_t *dest,
  481. uint32_t *dest_size);
  482. /**
  483. * Prepare for kernel verification stage.
  484. *
  485. * Must be called before other vb2api kernel functions.
  486. *
  487. * @param ctx Vboot context
  488. * @return VB2_SUCCESS, or error code on error.
  489. */
  490. int vb2api_kernel_phase1(struct vb2_context *ctx);
  491. /**
  492. * Load the verified boot block (vblock) for a kernel.
  493. *
  494. * This function may be called multiple times, to load and verify the
  495. * vblocks from multiple kernel partitions.
  496. *
  497. * @param ctx Vboot context
  498. * @param stream Kernel stream
  499. * @return VB2_SUCCESS, or error code on error.
  500. */
  501. int vb2api_load_kernel_vblock(struct vb2_context *ctx);
  502. /**
  503. * Get the size and offset of the kernel data for the most recent vblock.
  504. *
  505. * Valid after a successful call to vb2api_load_kernel_vblock().
  506. *
  507. * @param ctx Vboot context
  508. * @param offset_ptr Destination for offset in bytes of kernel data as
  509. * reported by vblock.
  510. * @param size_ptr Destination for size of kernel data in bytes.
  511. * @return VB2_SUCCESS, or error code on error.
  512. */
  513. int vb2api_get_kernel_size(struct vb2_context *ctx,
  514. uint32_t *offset_ptr,
  515. uint32_t *size_ptr);
  516. /**
  517. * Verify kernel data using the previously loaded kernel vblock.
  518. *
  519. * Valid after a successful call to vb2api_load_kernel_vblock(). This allows
  520. * the caller to load or map the kernel data, as appropriate, and pass the
  521. * pointer to the kernel data into vboot.
  522. *
  523. * @param ctx Vboot context
  524. * @param buf Pointer to kernel data
  525. * @param size Size of kernel data in bytes
  526. * @return VB2_SUCCESS, or error code on error.
  527. */
  528. int vb2api_verify_kernel_data(struct vb2_context *ctx,
  529. const void *buf,
  530. uint32_t size);
  531. /**
  532. * Clean up after kernel verification.
  533. *
  534. * Call this after successfully loading a vblock and verifying kernel data,
  535. * or if you've run out of boot devices and/or kernel partitions.
  536. *
  537. * This cleans up intermediate data structures in the vboot context, and
  538. * updates the version in the secure data if necessary.
  539. */
  540. int vb2api_kernel_phase3(struct vb2_context *ctx);
  541. /*****************************************************************************/
  542. /* APIs provided by the caller to verified boot */
  543. /**
  544. * Clear the TPM owner.
  545. *
  546. * @param ctx Vboot context
  547. * @return VB2_SUCCESS, or error code on error.
  548. */
  549. int vb2ex_tpm_clear_owner(struct vb2_context *ctx);
  550. /**
  551. * Read a verified boot resource.
  552. *
  553. * @param ctx Vboot context
  554. * @param index Resource index to read
  555. * @param offset Byte offset within resource to start at
  556. * @param buf Destination for data
  557. * @param size Amount of data to read
  558. * @return VB2_SUCCESS, or error code on error.
  559. */
  560. int vb2ex_read_resource(struct vb2_context *ctx,
  561. enum vb2_resource_index index,
  562. uint32_t offset,
  563. void *buf,
  564. uint32_t size);
  565. /**
  566. * Print debug output
  567. *
  568. * This should work like printf(). If func!=NULL, it will be a string with
  569. * the current function name; that can be used to generate prettier debug
  570. * output. If func==NULL, don't print any extra header/trailer so that this
  571. * can be used to composite a bigger output string from several calls - for
  572. * example, when doing a hex dump.
  573. *
  574. * @param func Function name generating output, or NULL.
  575. * @param fmt Printf format string
  576. */
  577. void vb2ex_printf(const char *func, const char *fmt, ...);
  578. /**
  579. * Initialize the hardware crypto engine to calculate a block-style digest.
  580. *
  581. * @param hash_alg Hash algorithm to use
  582. * @param data_size Expected total size of data to hash
  583. * @return VB2_SUCCESS, or non-zero error code (HWCRYPTO_UNSUPPORTED not fatal).
  584. */
  585. int vb2ex_hwcrypto_digest_init(enum vb2_hash_algorithm hash_alg,
  586. uint32_t data_size);
  587. /**
  588. * Extend the hash in the hardware crypto engine with another block of data.
  589. *
  590. * @param buf Next data block to hash
  591. * @param size Length of data block in bytes
  592. * @return VB2_SUCCESS, or non-zero error code.
  593. */
  594. int vb2ex_hwcrypto_digest_extend(const uint8_t *buf, uint32_t size);
  595. /**
  596. * Finalize the digest in the hardware crypto engine and extract the result.
  597. *
  598. * @param digest Destination buffer for resulting digest
  599. * @param digest_size Length of digest buffer in bytes
  600. * @return VB2_SUCCESS, or non-zero error code.
  601. */
  602. int vb2ex_hwcrypto_digest_finalize(uint8_t *digest, uint32_t digest_size);
  603. #endif /* VBOOT_2_API_H_ */