From patchwork Tue Aug 21 15:57:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 10571951 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A39D11390 for ; Tue, 21 Aug 2018 15:58:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8F9DC29046 for ; Tue, 21 Aug 2018 15:58:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 83AAB2A4E9; Tue, 21 Aug 2018 15:58:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7054D2A4E2 for ; Tue, 21 Aug 2018 15:58:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728124AbeHUTSl (ORCPT ); Tue, 21 Aug 2018 15:18:41 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:45132 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726967AbeHUTSl (ORCPT ); Tue, 21 Aug 2018 15:18:41 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 687ED402178A; Tue, 21 Aug 2018 15:57:58 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-123-147.rdu2.redhat.com [10.10.123.147]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5E59B9464B; Tue, 21 Aug 2018 15:57:57 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 Subject: [PATCH 10/23] TPMLIB: Better format calls to TSS_*hmac*() From: David Howells To: denkenz@gmail.com, jarkko.sakkinen@linux.intel.com, jejb@linux.vnet.ibm.com Cc: keyrings@vger.kernel.org, linux-integrity@vger.kernel.org, tpmdd-devel@lists.sourceforge.net, linux-security-module@vger.kernel.org Date: Tue, 21 Aug 2018 16:57:56 +0100 Message-ID: <153486707690.13066.12378140282590781364.stgit@warthog.procyon.org.uk> In-Reply-To: <153486700916.13066.12870860668352070081.stgit@warthog.procyon.org.uk> References: <153486700916.13066.12870860668352070081.stgit@warthog.procyon.org.uk> User-Agent: StGit/unknown-version MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Tue, 21 Aug 2018 15:57:58 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Tue, 21 Aug 2018 15:57:58 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'dhowells@redhat.com' RCPT:'' Sender: linux-integrity-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Better format calls to TSS_rawhmac(), TSS_authhmac() and TSS_checkhmac*(). Each of these calls takes a varargs list of pairs of datasize and data values. Put each pair on its own line so that things are more obvious. Signed-off-by: David Howells --- drivers/char/tpm/tpm-library.c | 86 ++++++++++++++++++++++++++-------------- 1 file changed, 55 insertions(+), 31 deletions(-) diff --git a/drivers/char/tpm/tpm-library.c b/drivers/char/tpm/tpm-library.c index e4cfc1f090e1..41fe4247a4c8 100644 --- a/drivers/char/tpm/tpm-library.c +++ b/drivers/char/tpm/tpm-library.c @@ -153,9 +153,12 @@ static int TSS_authhmac(unsigned char *digest, const unsigned char *key, if (!ret) ret = crypto_shash_final(&sdesc->shash, paramdigest); if (!ret) - ret = TSS_rawhmac(digest, key, keylen, SHA1_DIGEST_SIZE, - paramdigest, TPM_NONCE_SIZE, h1, - TPM_NONCE_SIZE, h2, 1, &c, 0, 0); + ret = TSS_rawhmac(digest, key, keylen, + SHA1_DIGEST_SIZE, paramdigest, + TPM_NONCE_SIZE, h1, + TPM_NONCE_SIZE, h2, + 1, &c, + 0, 0); out: kfree(sdesc); return ret; @@ -229,9 +232,12 @@ static int TSS_checkhmac1(unsigned char *buffer, if (ret < 0) goto out; - ret = TSS_rawhmac(testhmac, key, keylen, SHA1_DIGEST_SIZE, paramdigest, - TPM_NONCE_SIZE, enonce, TPM_NONCE_SIZE, ononce, - 1, continueflag, 0, 0); + ret = TSS_rawhmac(testhmac, key, keylen, + SHA1_DIGEST_SIZE, paramdigest, + TPM_NONCE_SIZE, enonce, + TPM_NONCE_SIZE, ononce, + 1, continueflag, + 0, 0); if (ret < 0) goto out; @@ -322,18 +328,24 @@ static int TSS_checkhmac2(unsigned char *buffer, if (ret < 0) goto out; - ret = TSS_rawhmac(testhmac1, key1, keylen1, SHA1_DIGEST_SIZE, - paramdigest, TPM_NONCE_SIZE, enonce1, - TPM_NONCE_SIZE, ononce, 1, continueflag1, 0, 0); + ret = TSS_rawhmac(testhmac1, key1, keylen1, + SHA1_DIGEST_SIZE, paramdigest, + TPM_NONCE_SIZE, enonce1, + TPM_NONCE_SIZE, ononce, + 1, continueflag1, + 0, 0); if (ret < 0) goto out; if (memcmp(testhmac1, authdata1, SHA1_DIGEST_SIZE)) { ret = -EINVAL; goto out; } - ret = TSS_rawhmac(testhmac2, key2, keylen2, SHA1_DIGEST_SIZE, - paramdigest, TPM_NONCE_SIZE, enonce2, - TPM_NONCE_SIZE, ononce, 1, continueflag2, 0, 0); + ret = TSS_rawhmac(testhmac2, key2, keylen2, + SHA1_DIGEST_SIZE, paramdigest, + TPM_NONCE_SIZE, enonce2, + TPM_NONCE_SIZE, ononce, + 1, continueflag2, + 0, 0); if (ret < 0) goto out; if (memcmp(testhmac2, authdata2, SHA1_DIGEST_SIZE)) @@ -395,8 +407,10 @@ static int tpm_create_osap(struct tpm_chip *chip, TPM_NONCE_SIZE); memcpy(enonce, &(tb->data[TPM_DATA_OFFSET + sizeof(uint32_t) + TPM_NONCE_SIZE]), TPM_NONCE_SIZE); - return TSS_rawhmac(s->secret, key, SHA1_DIGEST_SIZE, TPM_NONCE_SIZE, - enonce, TPM_NONCE_SIZE, ononce, 0, 0); + return TSS_rawhmac(s->secret, key, SHA1_DIGEST_SIZE, + TPM_NONCE_SIZE, enonce, + TPM_NONCE_SIZE, ononce, + 0, 0); } /* @@ -488,18 +502,23 @@ int tpm_seal(struct tpm_chip *chip, struct tpm_buf *tb, uint16_t keytype, /* no pcr info specified */ ret = TSS_authhmac(td->pubauth, sess.secret, SHA1_DIGEST_SIZE, sess.enonce, td->nonceodd, cont, - sizeof(uint32_t), &ordinal, SHA1_DIGEST_SIZE, - td->encauth, sizeof(uint32_t), &pcrsize, - sizeof(uint32_t), &datsize, datalen, data, 0, - 0); + sizeof(uint32_t), &ordinal, + SHA1_DIGEST_SIZE, td->encauth, + sizeof(uint32_t), &pcrsize, + sizeof(uint32_t), &datsize, + datalen, data, + 0, 0); } else { /* pcr info specified */ ret = TSS_authhmac(td->pubauth, sess.secret, SHA1_DIGEST_SIZE, sess.enonce, td->nonceodd, cont, - sizeof(uint32_t), &ordinal, SHA1_DIGEST_SIZE, - td->encauth, sizeof(uint32_t), &pcrsize, - pcrinfosize, pcrinfo, sizeof(uint32_t), - &datsize, datalen, data, 0, 0); + sizeof(uint32_t), &ordinal, + SHA1_DIGEST_SIZE, td->encauth, + sizeof(uint32_t), &pcrsize, + pcrinfosize, pcrinfo, + sizeof(uint32_t), &datsize, + datalen, data, + 0, 0); } if (ret < 0) goto out; @@ -533,9 +552,10 @@ int tpm_seal(struct tpm_chip *chip, struct tpm_buf *tb, uint16_t keytype, sizeof(uint32_t) + encdatasize; /* check the HMAC in the response */ - ret = TSS_checkhmac1(tb->data, ordinal, td->nonceodd, sess.secret, - SHA1_DIGEST_SIZE, storedsize, TPM_DATA_OFFSET, 0, - 0); + ret = TSS_checkhmac1(tb->data, ordinal, td->nonceodd, + sess.secret, SHA1_DIGEST_SIZE, + storedsize, TPM_DATA_OFFSET, + 0, 0); /* copy the returned blob to caller */ if (!ret) { @@ -589,13 +609,17 @@ int tpm_unseal(struct tpm_chip *chip, struct tpm_buf *tb, return ret; } ret = TSS_authhmac(authdata1, keyauth, TPM_NONCE_SIZE, - enonce1, nonceodd, cont, sizeof(uint32_t), - &ordinal, bloblen, blob, 0, 0); + enonce1, nonceodd, cont, + sizeof(uint32_t), &ordinal, + bloblen, blob, + 0, 0); if (ret < 0) return ret; ret = TSS_authhmac(authdata2, blobauth, TPM_NONCE_SIZE, - enonce2, nonceodd, cont, sizeof(uint32_t), - &ordinal, bloblen, blob, 0, 0); + enonce2, nonceodd, cont, + sizeof(uint32_t), &ordinal, + bloblen, blob, + 0, 0); if (ret < 0) return ret; @@ -627,8 +651,8 @@ int tpm_unseal(struct tpm_chip *chip, struct tpm_buf *tb, keyauth, SHA1_DIGEST_SIZE, blobauth, SHA1_DIGEST_SIZE, sizeof(uint32_t), TPM_DATA_OFFSET, - *datalen, TPM_DATA_OFFSET + sizeof(uint32_t), 0, - 0); + *datalen, TPM_DATA_OFFSET + sizeof(uint32_t), + 0, 0); if (ret < 0) { pr_info("TSS_checkhmac2 failed (%d)\n", ret); return ret;