Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp2833480lqo; Mon, 20 May 2024 20:16:56 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWwKb/ioWQn7KZPf7YWqFQJQV9+lxoyVdTWm5RZ+K0Yhm/fa/kHBFURQRWF7ymRo7qUz+3Eoc+7ZoCpg/MEzVwCl6CRX5U139PoVXRYcw== X-Google-Smtp-Source: AGHT+IFN8/NAfWpPOIXmw/QrJ0WdWRsV0t5F2MM6m+hvHawNwPSDf5nL1Ks1raLNRTxYVozIINzL X-Received: by 2002:a17:90a:4307:b0:2b5:4ee8:e5e8 with SMTP id 98e67ed59e1d1-2b6cc758bb5mr27418959a91.16.1716261416097; Mon, 20 May 2024 20:16:56 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716261416; cv=pass; d=google.com; s=arc-20160816; b=rH0q2QBrbDXpBQYSr2ww0FhtR81zcFSp9IEiTVXE/z5n7yUJnnbRB/2bYP6+aM5vfr SxPOw4ZHXqdebZlyE9v98hl49j6cPjdBlf3EW+xUKc1tZbHwylDrg4bvJ2LMUH3zZwn9 PrSN+1plx+/tESNA87YhaIvN57O+gHIgE43Y9mT4hew82gSTb8Zr7v4wBEhq6WDCj/VQ d8z7uRIotvMJgZ+O/yO0lwa8z/P1+7DSVuBNp4Krpe2yCc+R1Ze8RR/37at9BpZNwaWR 5CMDvrpugSB0qgeo2Dkt5zZX9guEld8GM0zGocyuKm79zIxqplk0Rc4bJa1L3i8ZUsL9 GQXw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=g4e5yRHgT9H9ZbtcAPxsu+9Udlu8foB7OFFsDOH9s+k=; fh=QllyklU740HFzuIvhgNfuC0qgAIidDspe+kgohgUijw=; b=LzvTd44J0r7ilscnnSOPsImo72to5FzfK0GZTIt4fX2/jQKpbKUm/amaw/2SYky0JF 7m/u9aqzd5fMTY9a4MpQKGWKEylIZpgoQk4twDSlrubu2yQSIPa9yBTR7ebqG6YoPIMh JJFhV6HWxvdBKTp4j6q/ic/dLWpF7t3K4UoD2/IMiN/OZd7pMDjO5ed2LTdH+0ebJ3YJ gVrWNgt/YVh2OSYc4vU9Q3Zrk8icXdFud/+GBKMW+8NU9m3HEwM92J/gmkn6b3PX5cK5 9r8JgaCPMPYNt0J1kDGpyOJk0czqASVjzXnTXzKfjWxZuC0O5WtVgSkcnig9Cx+qFg8R y8Ug==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=mufnkycR; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-crypto+bounces-4286-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-crypto+bounces-4286-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 98e67ed59e1d1-2bd82cf2828si2454061a91.133.2024.05.20.20.16.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 May 2024 20:16:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto+bounces-4286-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=mufnkycR; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-crypto+bounces-4286-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-crypto+bounces-4286-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id B77D4282072 for ; Tue, 21 May 2024 03:16:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3762D134B1; Tue, 21 May 2024 03:16:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="mufnkycR" X-Original-To: linux-crypto@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DCBB3848A; Tue, 21 May 2024 03:16:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716261411; cv=none; b=PPtYCziyFlAFhS3tkAW6VrB+TDjG04zBTB3X6dL1I70BYn1JLQsjUCaSXw/cfZQjLnva2DREiv+S3sdwt+kkuhL71dRsQblZzKxROAcCkoLlFwAGfemg0D/1dt2o5VpvyncLEygv5G8ZP/qh4VvGC/vqjyCgaHinuwlWu/77i1g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716261411; c=relaxed/simple; bh=YK2OIxpfjJaaDk91GjlEjElige5eBrqgDYVjkNdZEEo=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=EaYkFn1zbWWA1ih4COtb5l5+3tKQGL1RLl7hMxFdTdCgyWW31T6YKHQOjNLo78sfy+b0gIdMAR2GB8L84x8QMa4QDQjF64UGNeJ6VXuedQFTO4IeuqyM30cvWre9vBRjXOgYi58m+wovV6rLNFgZ2Kpo7FmrL2BApQ8kHY08jcA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mufnkycR; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0E9C3C32786; Tue, 21 May 2024 03:16:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716261410; bh=YK2OIxpfjJaaDk91GjlEjElige5eBrqgDYVjkNdZEEo=; h=From:To:Cc:Subject:Date:From; b=mufnkycRqgDnEKVs0Z8YdZMXrmiM4FjhjHgsPPRH415K1hGvGc7FXZohKtrutljZJ kzd5d40xulh0Pe5nG+T9w48QmMwWGQXAldO8h/DZog93F7AE5pzXbZ032XIqjcl1HH j17xXmiw2y+BaaDIcYOlsBhX+uhkAPJRDMwvsqn7qQD8oTHoyolRomqbdwfq9mnCaQ prQhbvBXSTkiKRUzsk21QcU5fe7yrqYz8bLuKCF7t5FVaZu2GMtZQdGb6VGXk2Q8Nw fvol5NhCQvOKBf1nRvfjBr+GGbNKOs+3gDoo40MfjcXmDjrNMIVlESEVI/GzH9f4Vk UJ/mPhE6LgNCg== From: Jarkko Sakkinen To: Herbert Xu Cc: linux-integrity@vger.kernel.org, keyrings@vger.kernel.org, Andreas.Fuchs@infineon.com, James Prestwood , David Woodhouse , Eric Biggers , James Bottomley , Jarkko Sakkinen , "David S. Miller" , linux-crypto@vger.kernel.org (open list:CRYPTO API), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2 0/6] KEYS: asymmetric: tpm2_key_rsa Date: Tue, 21 May 2024 06:16:25 +0300 Message-ID: <20240521031645.17008-1-jarkko@kernel.org> X-Mailer: git-send-email 2.45.1 Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit ## Overview Introduce tpm2_key_rsa module, which implements asymmetric TPM2 RSA key. The feature can be enabled with the CONFIG_ASYMMETRIC_TPM2_KEY_RSA_SUBTYPE kconfig option. The idea in the design is to over time to have submodule per key type For instance, tpm2_key_ecdsa could be one potential future addition in the future. Perhaps, it might sense to consider at that point also a top-level tpm2_key module. The gist is that the naming convention is free from potential future bottlencks. ## Change Log v2 Cleaned up all the low-hanging fruit for the sake of saving everyones time. After this I move into reactive mode (I promise) ;-) ## Testing tpm2_createprimary --hierarchy o -G rsa2048 -c owner.txt tpm2_evictcontrol -c owner.txt 0x81000001 tpm2_getcap handles-persistent openssl genrsa -out private.pem 2048 tpm2_import -C 0x81000001 -G rsa -i private.pem -u key.pub -r key.priv tpm2_encodeobject -C 0x81000001 -u key.pub -r key.priv -o key.priv.pem openssl asn1parse -inform pem -in key.priv.pem -noout -out key.priv.der serial=`cat key.priv.der | keyctl padd asymmetric tpm @u` echo "abcdefg" > plaintext.txt keyctl pkey_encrypt $serial 0 plaintext.txt enc=pkcs1 > encrypted.dat keyctl pkey_decrypt $serial 0 encrypted.dat enc=pkcs1 > decrypted.dat keyctl pkey_sign $serial 0 plaintext.txt enc=pkcs1 hash=sha256 > signed.dat keyctl pkey_verify $serial 0 plaintext.txt signed.dat enc=pkcs1 hash=sha256 ## References - v1: https://lore.kernel.org/linux-integrity/20240520184727.22038-1-jarkko@kernel.org/ - Derived from https://lore.kernel.org/all/20200518172704.29608-1-prestwoj@gmail.com/ James Prestwood (1): keys: asymmetric: ASYMMETRIC_TPM2_KEY_RSA_SUBTYPE Jarkko Sakkinen (5): crypto: rsa-pkcs1pad: export rsa1_asn_lookup() lib: Expand asn1_encode_integer() to variable size integers tpm: Export tpm2_load_context() KEYS: trusted: Move tpm2_key_decode() to the TPM driver tpm: tpm2_key: Extend parser to TPM_LoadableKey crypto/asymmetric_keys/Kconfig | 16 + crypto/asymmetric_keys/Makefile | 1 + crypto/asymmetric_keys/tpm2_key_rsa.c | 698 ++++++++++++++++++ crypto/rsa-pkcs1pad.c | 16 +- drivers/char/tpm/Kconfig | 1 + drivers/char/tpm/Makefile | 5 + drivers/char/tpm/tpm.h | 2 - drivers/char/tpm/tpm2-cmd.c | 77 ++ drivers/char/tpm/tpm2-space.c | 61 -- drivers/char/tpm/tpm2_key.c | 119 +++ .../char/tpm}/tpm2key.asn1 | 0 include/crypto/rsa-pkcs1pad.h | 20 + include/crypto/tpm2_key.h | 35 + include/linux/asn1_encoder.h | 3 +- include/linux/tpm.h | 4 + lib/asn1_encoder.c | 185 ++--- security/keys/trusted-keys/Makefile | 2 - security/keys/trusted-keys/trusted_tpm2.c | 135 +--- 18 files changed, 1110 insertions(+), 270 deletions(-) create mode 100644 crypto/asymmetric_keys/tpm2_key_rsa.c create mode 100644 drivers/char/tpm/tpm2_key.c rename {security/keys/trusted-keys => drivers/char/tpm}/tpm2key.asn1 (100%) create mode 100644 include/crypto/rsa-pkcs1pad.h create mode 100644 include/crypto/tpm2_key.h -- 2.45.1