From patchwork Thu Apr 15 20:05:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Gagniuc X-Patchwork-Id: 1466761 X-Patchwork-Delegate: patrice.chotard@st.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=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=O+48F/q7; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (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 4FLr5G18wMz9sV5 for ; Fri, 16 Apr 2021 06:08:50 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B24B782064; Thu, 15 Apr 2021 22:08:02 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="O+48F/q7"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 175BA82026; Thu, 15 Apr 2021 22:07:36 +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=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ot1-x331.google.com (mail-ot1-x331.google.com [IPv6:2607:f8b0:4864:20::331]) (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 72FCB81FBE for ; Thu, 15 Apr 2021 22:07:27 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=mr.nuke.me@gmail.com Received: by mail-ot1-x331.google.com with SMTP id i16-20020a9d68d00000b0290286edfdfe9eso13103482oto.3 for ; Thu, 15 Apr 2021 13:07:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8+p8v1FYvbepgyTD+kp/Uh39d6f7EyDQMuq8NoEzwA4=; b=O+48F/q78A4s8SJKjxhDEKMu1KZ9TFD+DsE1+X/ngRvNjcGUfVZnDMaOs+/eTG1kum WFdxWI0lfOiy24skXLPPIBYK2IvIlTiu35po35jHInTGXB8DWj4sHF6VnlvzQuyP8mQh 2uhfn0JrYIZPTx/FiMMbzkHI6plcr4ZzRqmtv8ecsQnvApUa6O8cK5RbRs20Af2tSjJ/ Gd6oLV4KtXfZ0tyo377myIuk4B1gfgFN882NOC4jjBfAhk4b4BuofdRVt4VFwTDQyVft KORnAV+FnR1nkOMrDbDtfwvkdsqn+nI6vQQBWJqShPLjdSbx3YGAx1YbikCrxqNLESLU r5bQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8+p8v1FYvbepgyTD+kp/Uh39d6f7EyDQMuq8NoEzwA4=; b=bpX2cHVGB/GonCLaMDyVw4YI7vtaO65yjPPSi8KJASgvz7REus/wfO66KfGsCUeIjf 94wngrCvcrTjFMDOoiEzKhEYchh+y5puqsUA4ylMZa3Y+P5xjAg8vw2WdQhVJuxMHilw iC0kV1Dg6ocD6PYsiOTC1N9ddkusK4EJY/qyv4GD6FoQbp3+g3+YOol3BsXrjuyYRXlW lfAaFIBcddRmB1q94NbSJgQ4cZLQv7Had12aVD4pD8ePs0h40xAqUyYZVnxqoBujvuLu MMLmXdQAplXRHJzle0TBJonP9yF5kI3sQkP6v2IKFls6V1PaxzrxTX++VueouMRtS7mt h02A== X-Gm-Message-State: AOAM5309dIVaCjetu2BHHAEn2tYhCPydLUg0BcHxCvIs3O8w3kvR+f2C 0FbWUfbZ2n2Zn/GJM6Rr0RdHnLr8PXHpDA== X-Google-Smtp-Source: ABdhPJxpLlg6X3HEsMA5YEGk3+Iw9e91F+bP2MyB5ne4GIVlEPiBxk2E8lBQRXgCWBKx6yLTbF6JWw== X-Received: by 2002:a9d:66c8:: with SMTP id t8mr731902otm.173.1618517245845; Thu, 15 Apr 2021 13:07:25 -0700 (PDT) Received: from nuclearis2-1.gtech (c-98-195-139-126.hsd1.tx.comcast.net. [98.195.139.126]) by smtp.gmail.com with ESMTPSA id z9sm777049oos.16.2021.04.15.13.07.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Apr 2021 13:07:25 -0700 (PDT) From: Alexandru Gagniuc To: u-boot@lists.denx.de, trini@konsulko.com, patrick.delaunay@foss.st.com Cc: Alexandru Gagniuc , sjg@chromium.org, etienne.carriere@linaro.org Subject: [PATCH v4 6/6] test: dm: Add test for ECDSA UCLASS support Date: Thu, 15 Apr 2021 15:05:09 -0500 Message-Id: <20210415200509.2335046-7-mr.nuke.me@gmail.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210415200509.2335046-1-mr.nuke.me@gmail.com> References: <20210415200509.2335046-1-mr.nuke.me@gmail.com> 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.4 at phobos.denx.de X-Virus-Status: Clean This test verifies that ECDSA_UCLASS is implemented, and that ecdsa_verify() works as expected. The definition of "expected" is "does not find a device, and returns -ENODEV". The lack of a hardware-independent ECDSA implementation prevents us from having one in the sandbox, for now. Signed-off-by: Alexandru Gagniuc Reviewed-by: Simon Glass --- configs/sandbox_defconfig | 2 ++ test/dm/Makefile | 1 + test/dm/ecdsa.c | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 test/dm/ecdsa.c diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index c9318d4af5..4681a8c7a2 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -285,3 +285,5 @@ CONFIG_TEST_FDTDEC=y CONFIG_UNIT_TEST=y CONFIG_UT_TIME=y CONFIG_UT_DM=y +CONFIG_ECDSA=y +CONFIG_ECDSA_VERIFY=y diff --git a/test/dm/Makefile b/test/dm/Makefile index d54abb7341..65821d9db4 100644 --- a/test/dm/Makefile +++ b/test/dm/Makefile @@ -29,6 +29,7 @@ obj-$(CONFIG_CLK) += clk.o clk_ccf.o obj-$(CONFIG_CROS_EC) += cros_ec.o obj-$(CONFIG_DEVRES) += devres.o obj-$(CONFIG_VIDEO_MIPI_DSI) += dsi_host.o +obj-$(CONFIG_ECDSA_VERIFY) += ecdsa.o obj-$(CONFIG_DM_ETH) += eth.o obj-$(CONFIG_FIRMWARE) += firmware.o obj-$(CONFIG_DM_GPIO) += gpio.o diff --git a/test/dm/ecdsa.c b/test/dm/ecdsa.c new file mode 100644 index 0000000000..23d57dd47f --- /dev/null +++ b/test/dm/ecdsa.c @@ -0,0 +1,38 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#include +#include +#include +#include +#include + +/* + * Basic test of the ECDSA uclass and ecdsa_verify() + * + * ECDSA implementations in u-boot are hardware-dependent. Until we have a + * software implementation that can be compiled into the sandbox, all we can + * test is the uclass support. + * + * The uclass_get() test is redundant since ecdsa_verify() would also fail. We + * run both functions in order to isolate the cause more clearly. i.e. is + * ecdsa_verify() failing because the UCLASS is absent/broken? + */ +static int dm_test_ecdsa_verify(struct unit_test_state *uts) +{ + const struct ecdsa_ops *ops; + struct uclass *ucp; + + const struct checksum_algo algo = { + .checksum_len = 256, + }; + + struct image_sign_info info = { + .checksum = &algo, + }; + + ut_assertok(uclass_get(UCLASS_ECDSA, &ucp)); + ut_assertnonnull(ucp); + ut_assert(ecdsa_verify(&info, NULL, 0, NULL, 0) == -ENODEV); + return 0; +} +DM_TEST(dm_test_ecdsa_verify, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);