From patchwork Sat Nov 15 18:51:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 708 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1763232816; bh=zY4BHee4m9QvRAfBpj7w/2mdUAS55lVswIrIgo+1Xww=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=QItQmvKB/cKshysyB4ss1igPfw6woqJ2eySlKJNNCENtW15KhYSOSOwKatIHK5Crn s6srP/2keErtoErffQTPock5boFAYA7wcf8ljbcfpxMFUW0X/cSq8AlhfgFaM3Lxbn Gc261X+QfkoNUq2G1R8UG26rUmQW/rZqo51GU8ajNON57ZIGxZnic4SHFBpKWgmi7s X9/962RpYmFPc52F4dWKzAj6yrOyW5SCA4G36JNXPZs8d9F4OTEv52b8cg+dZqWL4O dOAossaJveCkaxPRSrXdktfDQu3rVPQ7TBlt2oV/QJ6dxpu+xgdx+KUTb9M2H3yC06 9+JK5dZFHIS0Q== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 17D5E6861E for ; Sat, 15 Nov 2025 11:53:36 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id 0Tp8lQCUQb8Z for ; Sat, 15 Nov 2025 11:53:36 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1763232816; bh=zY4BHee4m9QvRAfBpj7w/2mdUAS55lVswIrIgo+1Xww=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=QItQmvKB/cKshysyB4ss1igPfw6woqJ2eySlKJNNCENtW15KhYSOSOwKatIHK5Crn s6srP/2keErtoErffQTPock5boFAYA7wcf8ljbcfpxMFUW0X/cSq8AlhfgFaM3Lxbn Gc261X+QfkoNUq2G1R8UG26rUmQW/rZqo51GU8ajNON57ZIGxZnic4SHFBpKWgmi7s X9/962RpYmFPc52F4dWKzAj6yrOyW5SCA4G36JNXPZs8d9F4OTEv52b8cg+dZqWL4O dOAossaJveCkaxPRSrXdktfDQu3rVPQ7TBlt2oV/QJ6dxpu+xgdx+KUTb9M2H3yC06 9+JK5dZFHIS0Q== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 073E06861A for ; Sat, 15 Nov 2025 11:53:36 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1763232814; bh=M08maH1zSo8FW/H+uVgRy92d/1ejqzpgwljPYRrtaws=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lUBI6mE8FgtHF4rhkx27vtt99P/jxlXc0mQ7vINueUiq/QeEOv+5tzWRSENLV6iws Mi1QHJxSIPDmzLfgUsx8dffVX8kj7ZVqHAqCXI5OowtEqyCSz/TnY2gaqyerzCKiU+ 1nbmYuJKuRmcyKSYAzEDCLLNmoQDTs5p/3RiazzwXhXqeJzm8Njajtwy7UsylAwtWt GKZ/hCrejcnssz7GyP0A+BSAbax74zKbxIgNYcghADlHtaF7XDLv5AQtXaqQ3NKVHL VJVKx32iwyroH0ZZthJ4QsxJeZ8sDL7eXp0g7tZdAnHPeNXrJr9n0xV0S7WDWiC5ii Z5HzbB2cPMlTw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 082526861A; Sat, 15 Nov 2025 11:53:34 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id Qf4pUmnwEBFF; Sat, 15 Nov 2025 11:53:33 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1763232809; bh=e4YKkkqUeanf8F5nTmF+SYJ7NXdzQdarM2WprL2QP4c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iBVp8xNjFZdeRNYO0ZcUkAA7ajApjDwePHCP97BqplC9IR5dvpS5GNFf/MkCm1X6j vkU2iCzEnkWIkfBmKMaowoS6253TOkvxuSObtYzu5gL78QK1vGplU0t04AAwHuaqBD 9CPbRX/1igAXNZsZdiqUItgxFiyCrLAiWc/qmNoC5vj/kQg/QskDc6Iqtb4waZrxZ8 l+SsQfGXzfMa2HNc00/4Il0uAT9fxCBymMI3w00a6BhgJleTFb/shhYZM7Z/Iy/Jgc CAUlQM/EKcwLimKpVrJWeqsAZ1xD5/7eGJ6SbEB3lHJ3PJi/uDjkGhhmuc8jSK72BF xvludYjawBxxg== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 36A616857C; Sat, 15 Nov 2025 11:53:29 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sat, 15 Nov 2025 11:51:59 -0700 Message-ID: <20251115185212.539268-11-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251115185212.539268-1-sjg@u-boot.org> References: <20251115185212.539268-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: K5WDFVKNJJPAYO6OL6C6GFDBOLIZLUYQ X-Message-ID-Hash: K5WDFVKNJJPAYO6OL6C6GFDBOLIZLUYQ X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Simon Glass X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 10/16] tkey: Use SHA256 to obtain the disk-encryption key List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass Rather than Blake2b, use SHA256 to obtain the disk-encryption key based on the key material provided by the TKey. This matches the upcoming disk-encryption test. Signed-off-by: Simon Glass --- drivers/misc/tkey-uclass.c | 25 ++++++++++++++++++------- test/cmd/tkey.c | 4 ++-- test/dm/tkey.c | 18 +++++++++--------- 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/drivers/misc/tkey-uclass.c b/drivers/misc/tkey-uclass.c index d2c4b8351fd..fad5ffd6534 100644 --- a/drivers/misc/tkey-uclass.c +++ b/drivers/misc/tkey-uclass.c @@ -18,6 +18,8 @@ #include #include #include +#include +#include /* TKey Protocol Constants */ #define TKEY_FRAME_HEADER_SIZE 1 @@ -670,6 +672,7 @@ int tkey_derive_disk_key(struct udevice *dev, const void *app_data, int app_size, const void *uss, int uss_size, void *disk_key, void *pubkey, void *key_hash) { + char pubkey_hex[TKEY_PUBKEY_SIZE * 2 + 1]; int ret; /* Load the signer app with USS */ @@ -693,14 +696,22 @@ int tkey_derive_disk_key(struct udevice *dev, const void *app_data, log_debug("Public key retrieved\n"); - /* Derive disk encryption key from public key using BLAKE2b */ - ret = blake2b(disk_key, 32, pubkey, 32, NULL, 0); - if (ret) { - log_debug("Failed to derive disk key (error %d)\n", ret); - return ret; - } + /* + * Derive disk encryption key from public key using SHA256 + * Must match Python tkey-fde-key.py implementation which does: + * hashlib.sha256(pubkey.encode()).digest() + * + * This converts the binary public key to hex string, + * then hashes the string bytes. + */ + bin2hex(pubkey_hex, pubkey, TKEY_PUBKEY_SIZE); + + sha256_context ctx; + sha256_starts(&ctx); + sha256_update(&ctx, (const u8 *)pubkey_hex, TKEY_PUBKEY_SIZE * 2); + sha256_finish(&ctx, disk_key); - log_debug("Disk encryption key derived\n"); + log_debug("Disk encryption key derived using SHA256\n"); /* Generate verification hash if requested */ if (key_hash) { diff --git a/test/cmd/tkey.c b/test/cmd/tkey.c index 605ce070f0e..f2d52850d4e 100644 --- a/test/cmd/tkey.c +++ b/test/cmd/tkey.c @@ -53,8 +53,8 @@ static int cmd_test_tkey_sandbox(struct unit_test_state *uts) /* Test getkey command */ ut_assertok(run_command("tkey getkey testuss", 0)); ut_assert_nextline("Public Key: 505152535455565758595a5b5c5d5e5f505152535455565758595a5b5c5d5e5f"); - ut_assert_nextline("Disk Key: 228b2f6abf8be05649b2417586150bbf3e1b3f669afa1c6151ddc72957933c21"); - ut_assert_nextline("Verification Hash: a72a46b8f8c7ff0824416ada886f62b6c2808896d71201a32814ab432c7a81cf"); + ut_assert_nextline("Disk Key: e9b0599268ff8b083ef80dbd04be207ce9a19a60a888ccb3fe93710a0a70a34e"); + ut_assert_nextline("Verification Hash: 8583a08d6c534e84ae81a8518071c16a8030893df05fecb84e514438591ba5ed"); /* After getkey, device should be in app mode */ ut_assertok(run_command("tkey fwmode", 0)); diff --git a/test/dm/tkey.c b/test/dm/tkey.c index 9dffae66a5e..4ff5ecad7ea 100644 --- a/test/dm/tkey.c +++ b/test/dm/tkey.c @@ -175,19 +175,19 @@ static int dm_test_tkey_derive_disk_key(struct unit_test_state *uts) 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, }; - /* Expected disk key: BLAKE2b(pubkey) */ + /* Expected disk key: SHA256(pubkey) - from emulator */ const u8 expected_disk_key[TKEY_DISK_KEY_SIZE] = { - 0x22, 0x8b, 0x2f, 0x6a, 0xbf, 0x8b, 0xe0, 0x56, - 0x49, 0xb2, 0x41, 0x75, 0x86, 0x15, 0x0b, 0xbf, - 0x3e, 0x1b, 0x3f, 0x66, 0x9a, 0xfa, 0x1c, 0x61, - 0x51, 0xdd, 0xc7, 0x29, 0x57, 0x93, 0x3c, 0x21, + 0xe9, 0xb0, 0x59, 0x92, 0x68, 0xff, 0x8b, 0x08, + 0x3e, 0xf8, 0x0d, 0xbd, 0x04, 0xbe, 0x20, 0x7c, + 0xe9, 0xa1, 0x9a, 0x60, 0xa8, 0x88, 0xcc, 0xb3, + 0xfe, 0x93, 0x71, 0x0a, 0x0a, 0x70, 0xa3, 0x4e, }; /* Expected key hash: BLAKE2b(disk_key) */ const u8 expected_key_hash[TKEY_HASH_SIZE] = { - 0xa7, 0x2a, 0x46, 0xb8, 0xf8, 0xc7, 0xff, 0x08, - 0x24, 0x41, 0x6a, 0xda, 0x88, 0x6f, 0x62, 0xb6, - 0xc2, 0x80, 0x88, 0x96, 0xd7, 0x12, 0x01, 0xa3, - 0x28, 0x14, 0xab, 0x43, 0x2c, 0x7a, 0x81, 0xcf, + 0x85, 0x83, 0xa0, 0x8d, 0x6c, 0x53, 0x4e, 0x84, + 0xae, 0x81, 0xa8, 0x51, 0x80, 0x71, 0xc1, 0x6a, + 0x80, 0x30, 0x89, 0x3d, 0xf0, 0x5f, 0xec, 0xb8, + 0x4e, 0x51, 0x44, 0x38, 0x59, 0x1b, 0xa5, 0xed, }; struct udevice *dev; u8 dummy_app[128];