Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp2409098lqb; Mon, 27 May 2024 20:51:53 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVCNU8fNTAVIOlRj2L9R6vk1ifsbw6kEsIlwUoLkMonBMixyb5VYo68bPrQifsknd9W14RLzOsM0xPFRzti/pkDRe2czS/MeCNOdN2E4g== X-Google-Smtp-Source: AGHT+IGlhoIpK2Z6HKPFE9iF7Cfhu5Emdpxt2kbQwZuT5lFWzyL38ONGW9q5o1DC4ktdh8j8jLLN X-Received: by 2002:a19:ad4a:0:b0:529:4864:9c17 with SMTP id 2adb3069b0e04-52967463e64mr9009119e87.57.1716868313139; Mon, 27 May 2024 20:51:53 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716868313; cv=pass; d=google.com; s=arc-20160816; b=usT1JMqtxez3dlHFQFs9gkGI6DgPYWZrD0lCSCuf7lKLju0SX39gjYj8V1KodLA/ng 7iRca6kep3Flitk+pStgSkqUniJg0drMHoTd6ljq2cYKNje/SjmCrhrszI4R8wOxW8ys PTaIKKxIA0zD5zUd7rWmiEbeZGNGFXK0qMLoe5rNpzByxKPVcb1s6jdHtCDySiSCr/H/ uQCdQcF0exgHuK007Kq656Sb9i/0/MZeGSHv8YrSMVNipJhtkZkluEjKI12zN4/NAOPD MpTRYhIoe5fQ8CcMKdF205ySCNCkWr8cKStx6AIA7YpDN4Mqe+gWlCM51u7m82OfH6tj lxCw== 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=Vt8KPXnGECIoZ2D51J0/35PpYj8hOVafgRdr2ZVCRc0=; fh=KFwIYojOnDNIufnnlXFKQTGNfalXnhK/xy0KsKaoQ2E=; b=ntz5v0ad7uPxhBXiXE0XBm1e2Q41IlF8GSJ+BQM7JgecN2PSdSgETSAyc9FwV5lqaP rLoX2/3TDaZTFUppKyy4zEaHjZrc3HjRvQNKmNOqEYkBEHaUgVVtBtntPFBbP2f1W7fT q+RTub1Dq1Zx2MQrX++aSVmQUv9PyeVl8I0h1ze3Q9y6sFeiCB0JCNPY3Fsvqht6q6cW uDWtyzL18tcCRu0nAMZD/xvDQpRfds+H5FbZBLyOGqkDnGXIfjLG92Igrt8i0JnjyCot CJ7PRdaZBZcDEi+CzoHbxPEyxN8EY0nc8z+F1tQDkAtmEszp6ec1o+E4m9DpozBYudTe FhdQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OwEjQoXw; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-crypto+bounces-4432-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-crypto+bounces-4432-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a62ddb069bbsi235900966b.101.2024.05.27.20.51.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 20:51:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto+bounces-4432-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OwEjQoXw; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-crypto+bounces-4432-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-crypto+bounces-4432-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 94F241F2315D for ; Tue, 28 May 2024 03:51:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E3332175AB; Tue, 28 May 2024 03:51:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OwEjQoXw" 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 8E80C17E8E4; Tue, 28 May 2024 03:51:45 +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=1716868305; cv=none; b=RyMSzroET6fzmTcA/V4XATst7ojoB+XlrtQ1cr1xHsvnZux/4u9QtoohmG72XgIJm2s0qkLDc7V//lBSvjXzthdzKRC4TQMiL3W8AUQzsgzMod2iGHmfpVMaS2qdnw0VLyfM/cu80Eo5oGBkYMxD8q11HAH4puUzQGeKU6W+XtI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716868305; c=relaxed/simple; bh=+iPQMa+6kqA2ZUh+VMv82Bt86ZQQJcbmF1UL0D12zgU=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=FkO1wzhnIOdMWOIj9uhnXnR85bcABIIwyyC7FNkeSmMKk3uSoPCt8SQdgeOVCtUHL4/HbCq/u6Ao3/8TSetua3wEhHBlW8reHrq+2PkGx+H/3zHqRMOey9S8G+w/HXuLqTZs4B0kGKAVB2x9RkUwgLd9UKQlw2G+t96L4/xv6+k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OwEjQoXw; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 75B02C32782; Tue, 28 May 2024 03:51:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716868305; bh=+iPQMa+6kqA2ZUh+VMv82Bt86ZQQJcbmF1UL0D12zgU=; h=From:To:Cc:Subject:Date:From; b=OwEjQoXw8tUNKXnC6ZHQXCqX15EaRAtYAcoyxmOHwE+25AQxtLCGQ/b2GmgrUPG29 C48jRJw3bNve++wTLpFcP56mLnhBAxHp30Zaq7dben+j9+x/WGHSDRRImd4lOpk/CZ kDHnOpkzjbFubaLMTAxQEUDjaHdwx9vJ64mVcx8N+NRJmee93eveQJ2jkm0MI2Nykb +++vmfkmJpuyTjjy2RjIP290suV7aY7UMaB9aWOFH+DzQTcitQkam8jD4lM6cO0X2L c4BPb+ba+MEiRWD+Xyzyxk7y5SLk/ETzu0xIRaneb4Dr4Do4XgmP4nqHKOcAlsf+rH HsMhf1/mwMNuQ== 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 , linux-crypto@vger.kernel.org, Stefan Berger , Jarkko Sakkinen , "David S. Miller" , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v6 0/6] KEYS: asymmetric: tpm2_key_{rsa,ecdsa} Date: Tue, 28 May 2024 06:51:15 +0300 Message-ID: <20240528035136.11464-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 Testing ======= RSA --- 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 ECDSA ----- tpm2_createprimary --hierarchy o -G ecc -c owner.txt tpm2_evictcontrol -c owner.txt 0x81000001 openssl ecparam -name prime256v1 -genkey -noout -out private.pem tpm2_import -C 0x81000001 -G ecc -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_sign $serial 0 plaintext.txt hash=sha256 > signed.dat keyctl pkey_verify $serial 0 plaintext.txt signed.dat hash=sha256 Open Issues =========== * When verifying ECDSA signature, _ecdsa_verify() returns -EKEYREJECTED. References ========== * v5: https://lore.kernel.org/linux-integrity/20240523212515.4875-1-jarkko@kernel.org/ * v4: https://lore.kernel.org/linux-integrity/20240522005252.17841-1-jarkko@kernel.org/ * v3: https://lore.kernel.org/linux-integrity/20240521152659.26438-1-jarkko@kernel.org/ * v2: https://lore.kernel.org/linux-integrity/336755.1716327854@warthog.procyon.org.uk/ * 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/ Jarkko Sakkinen (6): tpm: Open code tpm_buf_parameters() crypto: rsa-pkcs1pad: export rsa1_asn_lookup() KEYS: trusted: Change -EINVAL to -E2BIG crypto: tpm2_key: Introduce a TPM2 key type keys: asymmetric: Add tpm2_key_rsa keys: asymmetric: Add tpm2_key_ecdsa crypto/Kconfig | 7 + crypto/Makefile | 6 + crypto/asymmetric_keys/Kconfig | 30 + crypto/asymmetric_keys/Makefile | 2 + crypto/asymmetric_keys/tpm2_key_ecdsa.c | 441 ++++++++++++++ crypto/asymmetric_keys/tpm2_key_rsa.c | 678 ++++++++++++++++++++++ crypto/ecdsa.c | 1 - crypto/rsa-pkcs1pad.c | 16 +- crypto/tpm2_key.asn1 | 11 + crypto/tpm2_key.c | 134 +++++ drivers/char/tpm/tpm-buf.c | 26 - drivers/char/tpm/tpm2-cmd.c | 10 +- include/crypto/rsa-pkcs1pad.h | 20 + include/crypto/tpm2_key.h | 46 ++ include/linux/tpm.h | 10 +- security/keys/trusted-keys/Kconfig | 2 +- security/keys/trusted-keys/Makefile | 2 - security/keys/trusted-keys/tpm2key.asn1 | 11 - security/keys/trusted-keys/trusted_tpm2.c | 141 +---- 19 files changed, 1433 insertions(+), 161 deletions(-) create mode 100644 crypto/asymmetric_keys/tpm2_key_ecdsa.c create mode 100644 crypto/asymmetric_keys/tpm2_key_rsa.c create mode 100644 crypto/tpm2_key.asn1 create mode 100644 crypto/tpm2_key.c create mode 100644 include/crypto/rsa-pkcs1pad.h create mode 100644 include/crypto/tpm2_key.h delete mode 100644 security/keys/trusted-keys/tpm2key.asn1 -- 2.45.1