Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp5245501ybe; Tue, 10 Sep 2019 00:16:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqx10vP7lqg1xHGdoBhMU7L/r8lxP/K7TnbZEWmxXulJd5sK2LxQvD0qXyNLtIfP7nK6YnzD X-Received: by 2002:a17:906:134e:: with SMTP id x14mr23213023ejb.280.1568099804954; Tue, 10 Sep 2019 00:16:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568099804; cv=none; d=google.com; s=arc-20160816; b=nU9sPX/MgIvt0g7o+qTeeuWr76eBFoLIeXBP7Eb5QhbAD2jZMV8E4dRchf09ElYx+x 3qGYNnWXz4z3DX7Cu8Laje9w4ubyck/W2jrTU56L6ySsBHINERyXNXgUHIhxCKx/jR+3 pvbgIcXoQgn5LW5Hr+ygP8gdpWB3yjVmgCKOwmY/nppnAmtwM7ALge7pLYqJZa5/NS/C 84iiKw/pnNtUo8zSMRHE4M5fUwEuUJEskb9HH9trODRakf9o6eLzVD3XRmLKzdyUrzsM d1B3RnjIGIcB68zAGfKUDsTNtyuj6NjcXRZvd7Sa7nPSN/adLf7edrAxEHEsOGDBDdnl DM2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id :dkim-signature:dkim-signature; bh=BMaX57m6H0SVf366mNdA5IBfLzkCluAg4wKWdRoKGac=; b=M5SavMeaoQgKlmRxZelS4XoGPSDaxjgJo0OnHxlig7aszHM119yR4M9Db28GcwXrDV dtpkZyAY9jq41MRx3B2hmUUAAU2/Uqpv3cOGl/Nd727oz4vLSc/4CYvhgLVBm4FgzkHI dtm81++LTyV+OhAx5TkrmmHlUvswwBYhxkFjPh8AUgQeBxTR4+Q4KnqduzHQUdMAI/eL rgC5Tz75DIlwLdiewX6eMScZYVwycktdDElxYB/sJbmXWVZikajfyh7RcP7ppTiKzXfH y5wVwvyY5O8wM7ZP+ZDYV63b7wEMaBlCufxcy16oJYre3Oa1+ySzbP4b1Wd/ptR1mj4S zCWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@hansenpartnership.com header.s=20151216 header.b=Cnn4dIOQ; dkim=fail header.i=@hansenpartnership.com header.s=20151216 header.b=Cnn4dIOQ; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=hansenpartnership.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g5si8695969ejw.309.2019.09.10.00.16.20; Tue, 10 Sep 2019 00:16:44 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@hansenpartnership.com header.s=20151216 header.b=Cnn4dIOQ; dkim=fail header.i=@hansenpartnership.com header.s=20151216 header.b=Cnn4dIOQ; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=hansenpartnership.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391095AbfIIMTW (ORCPT + 99 others); Mon, 9 Sep 2019 08:19:22 -0400 Received: from bedivere.hansenpartnership.com ([66.63.167.143]:48156 "EHLO bedivere.hansenpartnership.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387878AbfIIMTV (ORCPT ); Mon, 9 Sep 2019 08:19:21 -0400 Received: from localhost (localhost [127.0.0.1]) by bedivere.hansenpartnership.com (Postfix) with ESMTP id BC08A8EE180; Mon, 9 Sep 2019 05:19:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=hansenpartnership.com; s=20151216; t=1568031561; bh=NhdJcH88HXPtKCQlYFRa1Gg4xxlsRdGYmmY7MPRH0nU=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=Cnn4dIOQMm279oJ7reKFRYk9TNKxq7lrSRrpEDhlKfkoZcMtjgEcCJ7hFEao7GDy/ fbBxMlxqoxOSTNg1VpNcuFrei4Fa431y08y1wgKPOya8hZ6VA+c0qpKQHHN9rPQLB5 0M69tZul58NaYmOWQZ/zXaRQEuAdMnT7RYu853N4= Received: from bedivere.hansenpartnership.com ([127.0.0.1]) by localhost (bedivere.hansenpartnership.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id qcQsd55ZyDDh; Mon, 9 Sep 2019 05:19:21 -0700 (PDT) Received: from [192.168.6.117] (unknown [148.69.85.38]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bedivere.hansenpartnership.com (Postfix) with ESMTPSA id 8C2B88EE105; Mon, 9 Sep 2019 05:19:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=hansenpartnership.com; s=20151216; t=1568031561; bh=NhdJcH88HXPtKCQlYFRa1Gg4xxlsRdGYmmY7MPRH0nU=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=Cnn4dIOQMm279oJ7reKFRYk9TNKxq7lrSRrpEDhlKfkoZcMtjgEcCJ7hFEao7GDy/ fbBxMlxqoxOSTNg1VpNcuFrei4Fa431y08y1wgKPOya8hZ6VA+c0qpKQHHN9rPQLB5 0M69tZul58NaYmOWQZ/zXaRQEuAdMnT7RYu853N4= Message-ID: <1568031558.6613.32.camel@HansenPartnership.com> Subject: [PATCH v6 03/12] tpm-buf: add cursor based functions for response parsing From: James Bottomley To: linux-integrity@vger.kernel.org Cc: linux-crypto@vger.kernel.org, linux-security-module@vger.kernel.org, Jarkko Sakkinen Date: Mon, 09 Sep 2019 13:19:18 +0100 In-Reply-To: <1568031408.6613.29.camel@HansenPartnership.com> References: <1568031408.6613.29.camel@HansenPartnership.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.26.6 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org It's very convenient when parsing responses to have a cursor you simply move over the response extracting the data. Add such cursor functions for the TPM unsigned integer types. Signed-off-by: James Bottomley --- drivers/char/tpm/tpm-buf.c | 26 ++++++++++++++++++++++++++ drivers/char/tpm/tpm.h | 4 ++++ 2 files changed, 30 insertions(+) diff --git a/drivers/char/tpm/tpm-buf.c b/drivers/char/tpm/tpm-buf.c index 8c1ed8a14e01..553adb84b0ac 100644 --- a/drivers/char/tpm/tpm-buf.c +++ b/drivers/char/tpm/tpm-buf.c @@ -163,3 +163,29 @@ void tpm_buf_append_2b(struct tpm_buf *buf, struct tpm_buf *tpm2b) } EXPORT_SYMBOL_GPL(tpm_buf_append_2b); +/* functions for unmarshalling data and moving the cursor */ +u8 tpm_get_inc_u8(const u8 **ptr) +{ + return *((*ptr)++); +} +EXPORT_SYMBOL_GPL(tpm_get_inc_u8); + +u16 tpm_get_inc_u16(const u8 **ptr) +{ + u16 val; + + val = get_unaligned_be16(*ptr); + *ptr += sizeof(val); + return val; +} +EXPORT_SYMBOL_GPL(tpm_get_inc_u16); + +u32 tpm_get_inc_u32(const u8 **ptr) +{ + u32 val; + + val = get_unaligned_be32(*ptr); + *ptr += sizeof(val); + return val; +} +EXPORT_SYMBOL_GPL(tpm_get_inc_u32); diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h index 7627917db345..d942188debc9 100644 --- a/drivers/char/tpm/tpm.h +++ b/drivers/char/tpm/tpm.h @@ -302,6 +302,10 @@ void tpm_buf_append_u16(struct tpm_buf *buf, const u16 value); void tpm_buf_append_u32(struct tpm_buf *buf, const u32 value); void tpm_buf_append_2b(struct tpm_buf *buf, struct tpm_buf *tpm2b); +u8 tpm_get_inc_u8(const u8 **ptr); +u16 tpm_get_inc_u16(const u8 **ptr); +u32 tpm_get_inc_u32(const u8 **ptr); + extern struct class *tpm_class; extern struct class *tpmrm_class; extern dev_t tpm_devt; -- 2.16.4