From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2CD8DC636CA for ; Thu, 15 Jul 2021 19:05:10 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9F4CB613F5 for ; Thu, 15 Jul 2021 19:05:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9F4CB613F5 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C3CE0829CD; Thu, 15 Jul 2021 21:05:06 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="Uee0p1vf"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6A3D5829CD; Thu, 15 Jul 2021 21:05:03 +0200 (CEST) Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 55E2E82AA9 for ; Thu, 15 Jul 2021 21:04:56 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ilias.apalodimas@linaro.org Received: by mail-ed1-x52d.google.com with SMTP id h8so9648661eds.4 for ; Thu, 15 Jul 2021 12:04:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=6BvOWPGqR0hmg/FlIso87nX+mLK1ZrAt67L5/Nd+rN8=; b=Uee0p1vfRUCgSoolu5mvu6TkV/K0dDxKB/9aUASWyDyacNFtvzjgqvhVYzEfeNlElb S+YH+YsP5z4OHDct5/Wy1vKV3xvsT12un77WlnyAnVLpChJHVcRfIf7pt84IA5/TX3Xg iSs1EKPt6GdU/eo7qpg+HXQg7NOlsj5FAGtbeyWfJdMu0nhASgbMuRaEnXy/VTCoETWv 5izQV72YOoKlJlsxC07vKB9HafDi4ycvQ+YKSi6hlFz7ApbcLCJIk0B1c8PjbUvduTel rC8v8BvyQGCcTnpry+xpnUJssFPzff96lxWLxor8fhl0oLdjs1lvssynaihzy0ni0REP xSRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=6BvOWPGqR0hmg/FlIso87nX+mLK1ZrAt67L5/Nd+rN8=; b=hydgKq+PeC4JN+u4+b+nLvmDswhuiySM5nLzzuV9bRrgscC5HwR3E0kYwtny2sGm/t d7oSBzeJ0IN8upzyL/Vqm6YcK7843kaxR9pQnakNqeWz0Ra6NDhBOcDpsqDH3RYsMiqZ /bQ2JWWSffOVh7WLUsrs2ceI89kPkKsR8W1fIUO5Y8jSRXdulNxsGR4e7+3ARUe/2ViC YlnS1YITJmN/1Z/k6XABfT0ysY+msnBmFUYmjEFT/K1iySnQp7AXEnF/bzF6FfTU5OlN X7+y/1y1E5nSP+aWofoRDGw8Rk4ON4njMjQzDJI00G2XC/rxBBtGfAjdKC3F3APT4P1G EAMw== X-Gm-Message-State: AOAM530SsEMzCo7FkhH8mc3CTtUzfGuRSrYuISmQAwZVUTrHLk/oXBRT fkqBWeLMuS9RTXgoInagKyRALQ== X-Google-Smtp-Source: ABdhPJws3jHAY3tQ5osAHl6Wdy3ivEAqL0/Q77rsu+DePESpq3DYkeTm3UJhOBPcuV0x7h71WEO9ig== X-Received: by 2002:a05:6402:1bc6:: with SMTP id ch6mr9267169edb.267.1626375895981; Thu, 15 Jul 2021 12:04:55 -0700 (PDT) Received: from enceladus (ppp-94-66-243-35.home.otenet.gr. [94.66.243.35]) by smtp.gmail.com with ESMTPSA id aq24sm2117005ejc.48.2021.07.15.12.04.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Jul 2021 12:04:55 -0700 (PDT) Date: Thu, 15 Jul 2021 22:04:53 +0300 From: Ilias Apalodimas To: Simon Glass Cc: U-Boot Mailing List , Thirupathaiah Annapureddy , Heinrich Schuchardt Subject: Re: [PATCH 9/9] sandbox: tpm: Support extending a PCR multiple times Message-ID: References: <20210705154849.2083972-1-sjg@chromium.org> <20210705154849.2083972-10-sjg@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210705154849.2083972-10-sjg@chromium.org> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean On Mon, Jul 05, 2021 at 09:48:49AM -0600, Simon Glass wrote: > It is fairly easy to handle this case and it makes the emulator more > useful, since PCRs are commonly extended several times. > > Add support for this, using U-Boot's sha256 support. > > Signed-off-by: Simon Glass > --- > > drivers/tpm/tpm2_tis_sandbox.c | 19 ++++++++++++------- > 1 file changed, 12 insertions(+), 7 deletions(-) > > diff --git a/drivers/tpm/tpm2_tis_sandbox.c b/drivers/tpm/tpm2_tis_sandbox.c > index ed9c9a0bc9f..e84bcc7c4c8 100644 > --- a/drivers/tpm/tpm2_tis_sandbox.c > +++ b/drivers/tpm/tpm2_tis_sandbox.c > @@ -11,6 +11,7 @@ > #include > #include > #include > +#include > #include "sandbox_common.h" > > /* Hierarchies */ > @@ -407,15 +408,19 @@ static int sandbox_tpm2_extend(struct udevice *dev, int pcr_index, > const u8 *extension) > { > struct sandbox_tpm2 *tpm = dev_get_priv(dev); > - int i; > > - /* Only simulate the first extensions from all '0' with only '0' */ > - for (i = 0; i < TPM2_DIGEST_LEN; i++) > - if (tpm->pcr[pcr_index][i] || extension[i]) > - return TPM2_RC_FAILURE; > + if (!pcr_index) { > + memcpy(tpm->pcr[pcr_index], sandbox_extended_once_pcr, > + TPM2_DIGEST_LEN); Why do we have to treat pcr 0 specially? Can't we just get rid of sandbox_extended_once_pcr and just extend all the PCRs with the value wee get? > + } else { > + sha256_context ctx; > + > + sha256_starts(&ctx); > + sha256_update(&ctx, tpm->pcr[pcr_index], TPM2_DIGEST_LEN); > + sha256_update(&ctx, extension, TPM2_DIGEST_LEN); > + sha256_finish(&ctx, tpm->pcr[pcr_index]); > + } > > - memcpy(tpm->pcr[pcr_index], sandbox_extended_once_pcr, > - TPM2_DIGEST_LEN); > tpm->pcr_extensions[pcr_index]++; > > return 0; > -- > 2.32.0.93.g670b81a890-goog >