summaryrefslogtreecommitdiff
path: root/test/cmd
diff options
context:
space:
mode:
authorTom Rini <[email protected]>2025-12-04 09:39:11 -0600
committerTom Rini <[email protected]>2025-12-04 09:39:11 -0600
commit33750d8d88d519a6ec90da689776d8afccccf2c4 (patch)
treef7cd1fdbdd7c88eec85a1d1fbb566c8689c85d33 /test/cmd
parent8eed8a355843897258c3f22727b32abe95464b08 (diff)
parentb30557b3b46c5162cb88a57907c517ed95557239 (diff)
Merge patch series "Add support for SM3 secure hash"
Heiko Schocher <[email protected]> says: Add SM3 secure hash, as specified by OSCCA GM/T 0004-2012 SM3 and described at https://datatracker.ietf.org/doc/html/draft-sca-cfrg-sm3-02 TPMv2 defines hash algo sm3_256, which is currently not supported and prevented TPMv2 chip with newer firmware to work with U-Boot. Seen this on a ST33TPHF2XI2C u-boot=> tpm2 init u-boot=> tpm2 autostart tpm2_get_pcr_info: too many pcrs: 5 Error: -90 u-boot=> Implement sm3 hash, so we can fix this problem. Link: https://lore.kernel.org/r/[email protected]
Diffstat (limited to 'test/cmd')
-rw-r--r--test/cmd/hash.c49
1 files changed, 48 insertions, 1 deletions
diff --git a/test/cmd/hash.c b/test/cmd/hash.c
index bb96380c351..99895982f67 100644
--- a/test/cmd/hash.c
+++ b/test/cmd/hash.c
@@ -9,6 +9,7 @@
#include <env.h>
#include <dm.h>
#include <dm/test.h>
+#include <test/cmd.h>
#include <test/test.h>
#include <test/ut.h>
@@ -38,7 +39,7 @@ static int dm_test_cmd_hash_md5(struct unit_test_state *uts)
"d41d8cd98f00b204e9800998ecf8427e"));
if (!CONFIG_IS_ENABLED(HASH_VERIFY)) {
- ut_assert(run_command("hash -v sha256 $loadaddr 0 foo", 0));
+ ut_assert(run_command("hash -v md5 $loadaddr 0 foo", 0));
ut_assertok(ut_check_console_line(
uts, "hash - compute hash message digest"));
@@ -103,3 +104,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 cmd_test_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;
+}
+CMD_TEST(cmd_test_hash_sm3_256, UTF_CONSOLE);