vb2api: pad digest buffers if they are larger than digest sizes
authorVadim Bendebury <vbendeb@chromium.org>
Wed, 6 Jul 2016 16:01:05 +0000 (09:01 -0700)
committerchrome-bot <chrome-bot@chromium.org>
Thu, 7 Jul 2016 06:00:44 +0000 (23:00 -0700)
Extending tpm PCRs in case of TPM2 requires 32 bit values, some
digests pre-calculated in vboot source code are 20 bytes in size. To
make sure that PCR extension is consistent, pad remaining buffer space
when a 20 byte digest is returned in a 32 byte buffer.

BRANCH=none
BUG=chrome-os-partner:50645
TEST=did not verify much, made sure that PCR extension commands
     triggered by coreboot succeed.

Change-Id: Ib16bdf782f18a6106eadb4b880cd1e67b56ad6db
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/358175
Reviewed-by: Randall Spangler <rspangler@chromium.org>
firmware/2lib/2api.c

index 059cb6c..c12a805 100644 (file)
@@ -199,6 +199,9 @@ int vb2api_get_pcr_digest(struct vb2_context *ctx,
                return VB2_ERROR_API_PCR_DIGEST_BUF;
 
        memcpy(dest, digest, digest_size);
+       if (digest_size < *dest_size)
+               memset(dest + digest_size, 0, *dest_size - digest_size);
+
        *dest_size = digest_size;
 
        return VB2_SUCCESS;