From patchwork Wed Oct 14 09:07:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 1381931 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=xilinx.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=monstr-eu.20150623.gappssmtp.com header.i=@monstr-eu.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=CaN7CZzl; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CB65B69pYz9sTs for ; Wed, 14 Oct 2020 20:07:58 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 78F1282396; Wed, 14 Oct 2020 11:07:53 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=xilinx.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=monstr-eu.20150623.gappssmtp.com header.i=@monstr-eu.20150623.gappssmtp.com header.b="CaN7CZzl"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A8227823AA; Wed, 14 Oct 2020 11:07:52 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ej1-x642.google.com (mail-ej1-x642.google.com [IPv6:2a00:1450:4864:20::642]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 7837C82369 for ; Wed, 14 Oct 2020 11:07:49 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=xilinx.com Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=monstr@monstr.eu Received: by mail-ej1-x642.google.com with SMTP id x7so3750638eje.8 for ; Wed, 14 Oct 2020 02:07:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monstr-eu.20150623.gappssmtp.com; s=20150623; h=sender:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=RQKY/oscrjDQU0pEDNWUmYiRj9EEVJrFp9FENZLMKo4=; b=CaN7CZzlNxu6A6TCOFaFqucUh+C8/sN867vwr51fn1FDR2G42bWH32Vm13A5odqERo 59put38OAcPsbs/cinvH2T38jTfhyQAFeDMZsL2v14kxS4XKSZ+68N2qs9P5fiXnqCH3 Cg8RRtM6DGTSKqay8rA22Cm3D3lcrRU6pwTii3N37NbnK+1epSjxI4C0PhQP06DisHUS QbDoWbjUanSMojuFIdr+y0D3Eg6Fi+o44gxqd5GriL12EUkTstjm1aGv8v9bMTWDphgN 0Or8ScM+ZQ7Rx3NkrTc2Ej+3WYBiVKFDooHA6uuHABdqYC6frOLD1/tRf1BiTDAkSc7c 2Xqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; bh=RQKY/oscrjDQU0pEDNWUmYiRj9EEVJrFp9FENZLMKo4=; b=OP2VmmRVdKQD8sqRVW8FETNAQDU7irpDY+4OLUIfGZ/fKDt0necTbErvDVVqaCPycF BrXVZPoHWzPZLiYnYrcLncpTBe4O6jdcwwTOF73jt3VZPj4FHJ9pnq/tgeAuk+wItyjE zaj3v/zutPAuVI1H7o+xiJ9/6XoFRf/B8e5D3e3OKzOo6YvwCOdsZRocIOcD5WHPovTN gAcFQPucoqqriDpC90pXOJozPPQ6cZYx2OHEzpUPPXdq/1PdV8F4rPSFQStaFvWzhL79 4zR77Rc4RCiYiL3KH4zGEGBcMFm7kdyR3ahS+YyGm/44LmHIRAHA5b9x4U+/Iy6NaDMw MRlg== X-Gm-Message-State: AOAM532T+Dh52EjMOHRBoeI3RY1x1k+uuPiyWFvoCL6lP0oOjkhncH/7 J5Tl31YMWWINTnIjbjVgIKRft5wPupjrSw== X-Google-Smtp-Source: ABdhPJwORp98X2G8ve0GUHym9aCoKd4NzHBIwurGoOshqxxtJKH2xV56crh/tu1UdA//1n9VwTcJNw== X-Received: by 2002:a17:906:557:: with SMTP id k23mr4051969eja.425.1602666468678; Wed, 14 Oct 2020 02:07:48 -0700 (PDT) Received: from localhost (nat-35.starnet.cz. [178.255.168.35]) by smtp.gmail.com with ESMTPSA id e17sm1334504ejh.64.2020.10.14.02.07.47 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 14 Oct 2020 02:07:48 -0700 (PDT) From: Michal Simek To: u-boot@lists.denx.de, git@xilinx.com Cc: Ashok Reddy Soma Subject: [PATCH] xilinx: zynqmp: Add support for saving sha3 key to different address Date: Wed, 14 Oct 2020 11:07:46 +0200 Message-Id: X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean By default 48B sha3 hash value is written to srcaddr which is not the best solution in case of that you want to use data for other operations. That's why add key_addr optional parameters which enables to write 48B sha3 hash value to specified address. Signed-off-by: Michal Simek Tested-by: Ashok Reddy Soma --- Based on https://lists.denx.de/pipermail/u-boot/2020-October/429294.html series. --- board/xilinx/zynqmp/cmds.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/board/xilinx/zynqmp/cmds.c b/board/xilinx/zynqmp/cmds.c index caddb64b820e..8430a23eb32c 100644 --- a/board/xilinx/zynqmp/cmds.c +++ b/board/xilinx/zynqmp/cmds.c @@ -285,11 +285,11 @@ static int do_zynqmp_rsa(cmd_tbl_t *cmdtp, int flag, int argc, static int do_zynqmp_sha3(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { - u64 srcaddr; + u64 srcaddr, hashaddr; u32 srclen, ret_payload[PAYLOAD_ARG_CNT]; int ret; - if (argc != cmdtp->maxargs) + if (argc > cmdtp->maxargs || argc < (cmdtp->maxargs - 1)) return CMD_RET_USAGE; if (zynqmp_firmware_version() <= PMUFW_V1_0) { @@ -302,6 +302,15 @@ static int do_zynqmp_sha3(cmd_tbl_t *cmdtp, int flag, srcaddr = simple_strtoul(argv[2], NULL, 16); srclen = simple_strtoul(argv[3], NULL, 16); + if (argc == 5) { + hashaddr = simple_strtoul(argv[4], NULL, 16); + flush_dcache_range(hashaddr, + hashaddr + roundup(ZYNQMP_SHA3_SIZE, + ARCH_DMA_MINALIGN)); + } else { + hashaddr = srcaddr; + } + /* Check srcaddr or srclen != 0 */ if (!srcaddr || !srclen) { puts("ERR: srcaddr & srclen should not be 0\n"); @@ -328,9 +337,10 @@ static int do_zynqmp_sha3(cmd_tbl_t *cmdtp, int flag, return CMD_RET_FAILURE; } - ret = xilinx_pm_request(PM_SECURE_SHA, upper_32_bits((ulong)srcaddr), - lower_32_bits((ulong)srcaddr), ZYNQMP_SHA3_SIZE, - ZYNQMP_SHA3_FINAL, ret_payload); + ret = xilinx_pm_request(PM_SECURE_SHA, upper_32_bits((ulong)hashaddr), + lower_32_bits((ulong)hashaddr), + ZYNQMP_SHA3_SIZE, ZYNQMP_SHA3_FINAL, + ret_payload); if (ret || ret_payload[1]) { printf("Failed: SHA FINAL status:0x%x, errcode:0x%x\n", ret, ret_payload[1]); @@ -347,7 +357,7 @@ static struct cmd_tbl cmd_zynqmp_sub[] = { U_BOOT_CMD_MKENT(mmio_write, 5, 0, do_zynqmp_mmio_write, "", ""), U_BOOT_CMD_MKENT(aes, 9, 0, do_zynqmp_aes, "", ""), U_BOOT_CMD_MKENT(rsa, 7, 0, do_zynqmp_rsa, "", ""), - U_BOOT_CMD_MKENT(sha3, 4, 0, do_zynqmp_sha3, "", ""), + U_BOOT_CMD_MKENT(sha3, 5, 0, do_zynqmp_sha3, "", ""), #ifdef CONFIG_DEFINE_TCM_OCM_MMAP U_BOOT_CMD_MKENT(tcminit, 3, 0, do_zynqmp_tcm_init, "", ""), #endif @@ -415,9 +425,10 @@ static char zynqmp_help_text[] = " exp : private key exponent for RSA decryption(4096 bits)\n" " public key exponent for RSA encryption(32 bits)\n" " rsaop : 0 for RSA Decryption, 1 for RSA Encryption\n" - "zynqmp sha3 srcaddr srclen\n" + "zynqmp sha3 srcaddr srclen [key_addr]\n" " Generates sha3 hash value for data blob at srcaddr and puts\n" " 48 bytes hash value into srcaddr\n" + " Optional key_addr can be specified for saving sha3 hash value\n" " Note: srcaddr/srclen should not be 0\n" ; #endif