uefi-rs icon indicating copy to clipboard operation
uefi-rs copied to clipboard

PcrEventInputs alloc-only method?

Open RaitoBezarius opened this issue 2 years ago • 4 comments

Hi there (again me), I am doing some TPM2 stuff with the library.

I see that PcrEventInputs::new_in_buffer is available, but requires the user to perform the allocation, it is a bit suboptimal because the required size requires using computations of the sizes (basically copying the first line in the impl).

This could be awesome with a PcrEventInputs::new which does the allocation for us.

RaitoBezarius avatar Apr 29 '23 17:04 RaitoBezarius

Furthermore, I realize that EventHeader is not public, thus, I don't see how to get the memory size using core::mem::size_of unfortunately.

RaitoBezarius avatar Apr 30 '23 00:04 RaitoBezarius

(usecase: https://github.com/nix-community/lanzaboote/pull/167/files#diff-28330b5941f5596b9c3ee9e6e0eec67e914fb049a91af5a59c6ba13aa8241e09R50-R81)

RaitoBezarius avatar Apr 30 '23 00:04 RaitoBezarius

Thanks for the report, good catch. The allocation should happen automatically, indeed.

phip1611 avatar May 03 '23 09:05 phip1611

Furthermore, I realize that EventHeader is not public, thus, I don't see how to get the memory size using core::mem::size_of unfortunately.

I think the simplest thing to do here is just allocate a reasonable static size. It's OK for the buffer to be bigger than necessary, it just can't be smaller. For example: https://chromium.googlesource.com/chromiumos/platform/crdyboot/+/refs/heads/main/libcrdy/src/tpm.rs#132

That said, adding a new method to create a boxed allocation would also be good, I'll take a look at doing that.

nicholasbishop avatar May 17 '23 16:05 nicholasbishop