From: AKASHI Takahiro <takahiro.akashi@linaro.org>
To: u-boot@lists.denx.de
Subject: [PATCH v2 09/17] efi_loader: signature: make efi_hash_regions more generic
Date: Wed, 8 Jul 2020 10:22:13 +0900 [thread overview]
Message-ID: <20200708012213.GB16575@laputa> (raw)
In-Reply-To: <4dadfbb9-3905-a728-36b7-2b8dc247fc53@gmx.de>
Heinrich,
On Fri, Jul 03, 2020 at 01:08:55PM +0200, Heinrich Schuchardt wrote:
> On 09.06.20 07:09, AKASHI Takahiro wrote:
> > There are a couple of occurrences of hash calculations in which a new
> > efi_hash_regions will be commonly used.
>
> Please, describe the difference.
the difference of what?
> Do you want to calculate the hash over an interval of regions?
I don't get your point.
What do you mean by "over an interval"?
> >
> > Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
>
> Please, provide a test for efi_hash_regions() in test/lib/.
>
> > ---
> > lib/efi_loader/efi_signature.c | 44 +++++++++++++---------------------
> > 1 file changed, 16 insertions(+), 28 deletions(-)
> >
> > diff --git a/lib/efi_loader/efi_signature.c b/lib/efi_loader/efi_signature.c
> > index f22dc151971f..03080bc0b11c 100644
> > --- a/lib/efi_loader/efi_signature.c
> > +++ b/lib/efi_loader/efi_signature.c
> > @@ -30,6 +30,7 @@ const efi_guid_t efi_guid_cert_type_pkcs7 = EFI_CERT_TYPE_PKCS7_GUID;
> > /**
> > * efi_hash_regions - calculate a hash value
> > * @regs: List of regions
>
> The argument should be renamed and the description corrected:
>
> @reg: first region
No. You don't understand the code.
Here, I refactored the code and simply extracted a common code as
efi_hash_regions.
The first argument is an array of "struct image_region".
(To avoid any confusion, I will change the description to "Array of".)
-Takahiro Akashi
> Best regards
>
> Heinrich
>
> > + * @count: Number of regions
> > * @hash: Pointer to a pointer to buffer holding a hash value
> > * @size: Size of buffer to be returned
> > *
> > @@ -37,18 +38,20 @@ const efi_guid_t efi_guid_cert_type_pkcs7 = EFI_CERT_TYPE_PKCS7_GUID;
> > *
> > * Return: true on success, false on error
> > */
> > -static bool efi_hash_regions(struct efi_image_regions *regs, void **hash,
> > - size_t *size)
> > +static bool efi_hash_regions(struct image_region *regs, int count,
> > + void **hash, size_t *size)
> > {
> > - *size = 0;
> > - *hash = calloc(1, SHA256_SUM_LEN);
> > if (!*hash) {
> > - EFI_PRINT("Out of memory\n");
> > - return false;
> > + *hash = calloc(1, SHA256_SUM_LEN);
> > + if (!*hash) {
> > + EFI_PRINT("Out of memory\n");
> > + return false;
> > + }
> > }
> > - *size = SHA256_SUM_LEN;
> > + if (size)
> > + *size = SHA256_SUM_LEN;
> >
> > - hash_calculate("sha256", regs->reg, regs->num, *hash);
> > + hash_calculate("sha256", regs, count, *hash);
> > #ifdef DEBUG
> > EFI_PRINT("hash calculated:\n");
> > print_hex_dump(" ", DUMP_PREFIX_OFFSET, 16, 1,
> > @@ -73,26 +76,10 @@ static bool efi_hash_msg_content(struct pkcs7_message *msg, void **hash,
> > {
> > struct image_region regtmp;
> >
> > - *size = 0;
> > - *hash = calloc(1, SHA256_SUM_LEN);
> > - if (!*hash) {
> > - EFI_PRINT("Out of memory\n");
> > - free(msg);
> > - return false;
> > - }
> > - *size = SHA256_SUM_LEN;
> > -
> > regtmp.data = msg->data;
> > regtmp.size = msg->data_len;
> >
> > - hash_calculate("sha256", ®tmp, 1, *hash);
> > -#ifdef DEBUG
> > - EFI_PRINT("hash calculated based on contentInfo:\n");
> > - print_hex_dump(" ", DUMP_PREFIX_OFFSET, 16, 1,
> > - *hash, SHA256_SUM_LEN, false);
> > -#endif
> > -
> > - return true;
> > + return efi_hash_regions(®tmp, 1, hash, size);
> > }
> >
> > /**
> > @@ -170,9 +157,10 @@ static bool efi_signature_verify(struct efi_image_regions *regs,
> > false);
> > #endif
> > /* against contentInfo first */
> > + hash = NULL;
> > if ((msg->data && efi_hash_msg_content(msg, &hash, &size)) ||
> > /* for signed image */
> > - efi_hash_regions(regs, &hash, &size)) {
> > + efi_hash_regions(regs->reg, regs->num, &hash, &size)) {
> > /* for authenticated variable */
> > if (ps_info->msgdigest_len != size ||
> > memcmp(hash, ps_info->msgdigest, size)) {
> > @@ -240,7 +228,7 @@ bool efi_signature_verify_with_list(struct efi_image_regions *regs,
> > regs, signed_info, siglist, valid_cert);
> >
> > if (!signed_info) {
> > - void *hash;
> > + void *hash = NULL;
> > size_t size;
> >
> > EFI_PRINT("%s: unsigned image\n", __func__);
> > @@ -254,7 +242,7 @@ bool efi_signature_verify_with_list(struct efi_image_regions *regs,
> > goto out;
> > }
> >
> > - if (!efi_hash_regions(regs, &hash, &size)) {
> > + if (!efi_hash_regions(regs->reg, regs->num, &hash, &size)) {
> > EFI_PRINT("Digesting unsigned image failed\n");
> > goto out;
> > }
> >
>
next prev parent reply other threads:[~2020-07-08 1:22 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-09 5:09 [PATCH v2 00/17] efi_loader: rework/improve UEFI secure boot code AKASHI Takahiro
2020-06-09 5:09 ` [PATCH v2 01/17] efi_loader: change efi objects initialization order AKASHI Takahiro
2020-07-03 10:29 ` Heinrich Schuchardt
2020-06-09 5:09 ` [PATCH v2 02/17] Revert "test: stabilize test_efi_secboot" AKASHI Takahiro
2020-07-03 10:30 ` Heinrich Schuchardt
2020-06-09 5:09 ` [PATCH v2 03/17] efi_loader: signature: replace debug to EFI_PRINT AKASHI Takahiro
2020-07-03 10:30 ` Heinrich Schuchardt
2020-06-09 5:09 ` [PATCH v2 04/17] efi_loader: variable: " AKASHI Takahiro
2020-06-09 5:09 ` [PATCH v2 05/17] efi_loader: image_loader: " AKASHI Takahiro
2020-07-03 10:38 ` Heinrich Schuchardt
2020-06-09 5:09 ` [PATCH v2 06/17] efi_loader: image_loader: add a check against certificate type of authenticode AKASHI Takahiro
2020-07-03 10:56 ` Heinrich Schuchardt
2020-07-08 1:08 ` AKASHI Takahiro
2020-06-09 5:09 ` [PATCH v2 07/17] efi_loader: image_loader: retrieve authenticode only if it exists AKASHI Takahiro
2020-06-09 5:09 ` [PATCH v2 08/17] efi_loader: signature: fix a size check against revocation list AKASHI Takahiro
2020-07-03 11:00 ` Heinrich Schuchardt
2020-07-08 1:12 ` AKASHI Takahiro
2020-07-08 1:30 ` AKASHI Takahiro
2020-06-09 5:09 ` [PATCH v2 09/17] efi_loader: signature: make efi_hash_regions more generic AKASHI Takahiro
2020-07-03 11:08 ` Heinrich Schuchardt
2020-07-08 1:22 ` AKASHI Takahiro [this message]
2020-06-09 5:09 ` [PATCH v2 10/17] efi_loader: image_loader: verification for all signatures should pass AKASHI Takahiro
2020-06-09 7:14 ` Heinrich Schuchardt
2020-06-09 5:09 ` [PATCH v2 11/17] efi_loader: image_loader: add digest-based verification for signed image AKASHI Takahiro
2020-06-09 5:09 ` [PATCH v2 12/17] test/py: efi_secboot: remove all "re.search" AKASHI Takahiro
2020-07-03 15:52 ` Heinrich Schuchardt
2020-06-09 5:09 ` [PATCH v2 13/17] test/py: efi_secboot: fix test case 1g of test_authvar AKASHI Takahiro
2020-07-03 16:08 ` Heinrich Schuchardt
2020-06-09 5:09 ` [PATCH v2 14/17] test/py: efi_secboot: split "signed image" test case-1 into two cases AKASHI Takahiro
2020-07-03 16:14 ` Heinrich Schuchardt
2020-06-09 5:09 ` [PATCH v2 15/17] test/py: efi_secboot: add a test against certificate revocation AKASHI Takahiro
2020-06-09 5:09 ` [PATCH v2 16/17] test/py: efi_secboot: add a test for multiple signatures AKASHI Takahiro
2020-06-09 5:09 ` [PATCH v2 17/17] test/py: efi_secboot: add a test for verifying with digest of signed image AKASHI Takahiro
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200708012213.GB16575@laputa \
--to=takahiro.akashi@linaro.org \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox