All of lore.kernel.org
 help / color / mirror / Atom feed
From: Heiko Schocher <hs@nabladev.com>
To: U-Boot Mailing List <u-boot@lists.denx.de>
Cc: Ilias Apalodimas <ilias.apalodimas@linaro.org>,
	Heiko Schocher <hs@nabladev.com>,
	Heinrich Schuchardt <xypron.glpk@gmx.de>,
	Jerome Forissier <jerome.forissier@linaro.org>,
	Mattijs Korpershoek <mkorpershoek@kernel.org>,
	Tom Rini <trini@konsulko.com>
Subject: [PATCH v2 3/5] test: cmd: hash: add unit test for sm3_256
Date: Tue, 11 Nov 2025 06:48:10 +0100	[thread overview]
Message-ID: <20251111054813.1966-4-hs@nabladev.com> (raw)
In-Reply-To: <20251111054813.1966-1-hs@nabladev.com>

add simple test for sm3 256 hash

Signed-off-by: Heiko Schocher <hs@nabladev.com>
---
I wonder why this tests are under DM and not under CMD
Should we move them to CMD ?

Ignored checkpatch warnings for too long lines.

(no changes since v1)

 test/cmd/hash.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/test/cmd/hash.c b/test/cmd/hash.c
index bb96380c351..3f7f64d27d3 100644
--- a/test/cmd/hash.c
+++ b/test/cmd/hash.c
@@ -103,3 +103,49 @@ static int dm_test_cmd_hash_sha256(struct unit_test_state *uts)
 	return 0;
 }
 DM_TEST(dm_test_cmd_hash_sha256, UTF_CONSOLE);
+
+static int dm_test_cmd_hash_sm3_256(struct unit_test_state *uts)
+{
+	const char *sum = "1ab21d8355cfa17f8e61194831e81a8f22bec8c728fefb747ed035eb5082aa2b";
+
+	if (!CONFIG_IS_ENABLED(SM3)) {
+		ut_assert(run_command("hash sm3_256 $loadaddr 0", 0));
+
+		return 0;
+	}
+
+	ut_assertok(run_command("hash sm3_256 $loadaddr 0", 0));
+	console_record_readline(uts->actual_str, sizeof(uts->actual_str));
+	ut_asserteq_ptr(uts->actual_str,
+			strstr(uts->actual_str, "sm3_256 for "));
+	ut_assert(strstr(uts->actual_str, sum));
+	ut_assert_console_end();
+
+	ut_assertok(run_command("hash sm3_256 $loadaddr 0 foo; echo $foo", 0));
+	console_record_readline(uts->actual_str, sizeof(uts->actual_str));
+	ut_asserteq_ptr(uts->actual_str,
+			strstr(uts->actual_str, "sm3_256 for "));
+	ut_assert(strstr(uts->actual_str, sum));
+	ut_assertok(ut_check_console_line(uts, sum));
+
+	if (!CONFIG_IS_ENABLED(HASH_VERIFY)) {
+		ut_assert(run_command("hash -v sm3_256 $loadaddr 0 foo", 0));
+		ut_assertok(ut_check_console_line(uts,
+						  "hash - compute hash message digest"));
+
+		return 0;
+	}
+
+	ut_assertok(run_command("hash -v sm3_256 $loadaddr 0 foo", 0));
+	ut_assert_console_end();
+
+	env_set("foo",
+		"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
+	ut_assert(run_command("hash -v sm3_256 $loadaddr 0 foo", 0));
+	console_record_readline(uts->actual_str, sizeof(uts->actual_str));
+	ut_assert(strstr(uts->actual_str, "!="));
+	ut_assert_console_end();
+
+	return 0;
+}
+DM_TEST(dm_test_cmd_hash_sm3_256, UTF_CONSOLE);
-- 
2.20.1


  parent reply	other threads:[~2025-11-11  5:48 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-11  5:48 [PATCH v2 0/5] Add support for SM3 secure hash Heiko Schocher
2025-11-11  5:48 ` [PATCH v2 1/5] lib: Import rol32 function from Linux Heiko Schocher
2025-11-11  9:07   ` Ilias Apalodimas
2025-11-11  5:48 ` [PATCH v2 2/5] lib: implement sm3 256 hash Heiko Schocher
2025-11-11  9:47   ` Ilias Apalodimas
2025-11-12  5:05     ` Heiko Schocher
2025-11-11  5:48 ` Heiko Schocher [this message]
2025-11-11  6:39   ` [PATCH v2 3/5] test: cmd: hash: add unit test for sm3_256 Heinrich Schuchardt
2025-11-12  4:44     ` Heiko Schocher
2025-11-11  5:48 ` [PATCH v2 4/5] tpm2: add sm3 256 hash support Heiko Schocher
2025-11-11  9:34   ` Ilias Apalodimas
2025-11-11  9:38     ` Ilias Apalodimas
2025-11-12  4:46     ` Heiko Schocher
2025-11-11  5:48 ` [PATCH v2 5/5] test: cmd: fix a typo in md5 test Heiko Schocher
2025-11-11  8:57   ` Ilias Apalodimas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251111054813.1966-4-hs@nabladev.com \
    --to=hs@nabladev.com \
    --cc=ilias.apalodimas@linaro.org \
    --cc=jerome.forissier@linaro.org \
    --cc=mkorpershoek@kernel.org \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    --cc=xypron.glpk@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.