lib: sm3: coverity fix and add documentation
cover lib: sm3: coverity fix and add documentation
patch "lib: sm3: fix coverity error" fixes a Coerity scan error, which is a good catch, as this part is from linux [1].
Running some hashes with this change and I see no problems, or wrong hashes [2] (Hashes calculated with the help of the webpage [3].
Patch 2 adds the missing documentation for the new sm3sum command which missed his way into mainline.
Azure build:
https://dev.azure.com/hs0298/hs/_build/results?buildId=197&view=results
[1]
https://elixir.bootlin.com/linux/v6.14/source/include/crypto/sm3_base.h#L86
[2]
│ ├─[helios-uboot] tftpb ${tftpp}/abb1.txt
│ │ ## ethernet@30bf0000 Waiting for PHY auto negotiation to complete....... done
│ │ ## Using ethernet@30bf0000 device
│ │ ## TFTP from server 192.168.3.1; our IP address is 192.168.3.41
│ │ ## Filename '20260106/abb1.txt'.
│ │ ## Load address: 0x50000000
│ │ ## Loading: ################################################## 3 Bytes
│ │ ## 0 Bytes/s
│ │ ## done
│ │ ## Bytes transferred = 3 (3 hex)
│ ├─[helios-uboot] md.b ${loadaddr} ${filesize}
│ │ ## 50000000: 41 42 42 ABB
│ ├─[helios-uboot] sm3sum ${loadaddr} ${filesize}
│ │ ## sm3_256 for 50000000 ... 50000002 ==> 2f2e2c6e076ebff98112d96081a9714d783eb6d8ea46a16fbfdc3b589f1c374b
│ ├─[helios-uboot] tftpb ${tftpp}/abb2.txt
│ │ ## Using ethernet@30bf0000 device
│ │ ## TFTP from server 192.168.3.1; our IP address is 192.168.3.41
│ │ ## Filename '20260106/abb2.txt'.
│ │ ## Load address: 0x50000000
│ │ ## Loading: ################################################## 52 Bytes
│ │ ## 4.9 KiB/s
│ │ ## done
│ │ ## Bytes transferred = 52 (34 hex)
│ ├─[helios-uboot] md.b ${loadaddr} ${filesize}
│ │ ## 50000000: 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f 50 ABCDEFGHIJKLMNOP
│ │ ## 50000010: 51 52 53 54 55 56 57 58 59 5a 61 62 63 64 65 66 QRSTUVWXYZabcdef
│ │ ## 50000020: 67 68 69 6a 6b 6c 6d 6e 6f 70 71 72 73 74 75 76 ghijklmnopqrstuv
│ │ ## 50000030: 77 78 79 7a wxyz
│ ├─[helios-uboot] sm3sum ${loadaddr} ${filesize}
│ │ ## sm3_256 for 50000000 ... 50000033 ==> e5e13e8215fe8eff7dcfd9375f3c3ff0674bd979dcd192539afc3562d45f1a5e
│ ├─[helios-uboot] tftpb ${tftpp}/abb3.txt
│ │ ## Using ethernet@30bf0000 device
│ │ ## TFTP from server 192.168.3.1; our IP address is 192.168.3.41
│ │ ## Filename '20260106/abb3.txt'.
│ │ ## Load address: 0x50000000
│ │ ## Loading: ################################################## 510 Bytes
│ │ ## 49.8 KiB/s
│ │ ## done
│ │ ## Bytes transferred = 510 (1fe hex)
│ ├─[helios-uboot] md.b ${loadaddr} ${filesize}
│ │ ## 50000000: 53 4d 33 20 69 73 20 61 20 63 72 79 70 74 6f 67 SM3 is a cryptog
│ │ ## 50000010: 72 61 70 68 69 63 20 68 61 73 68 20 66 75 6e 63 raphic hash func
│ │ ## 50000020: 74 69 6f 6e 20 70 75 62 6c 69 73 68 65 64 20 62 tion published b
│ │ ## 50000030: 79 20 74 68 65 20 53 74 61 74 65 20 43 72 79 70 y the State Cryp
│ │ ## 50000040: 74 6f 67 72 61 70 68 79 20 41 64 6d 69 6e 69 73 tography Adminis
│ │ ## 50000050: 74 72 61 74 69 6f 6e 20 6f 66 20 43 68 69 6e 61 tration of China
│ │ ## 50000060: 20 61 6e 64 20 69 73 20 61 6c 73 6f 20 6b 6e 6f and is also kno
│ │ ## 50000070: 77 6e 20 61 73 20 74 68 65 20 63 6f 6d 6d 65 72 wn as the commer
│ │ ## 50000080: 63 69 61 6c 20 63 72 79 70 74 6f 67 72 61 70 68 cial cryptograph
│ │ ## 50000090: 69 63 20 53 4d 33 20 61 6c 67 6f 72 69 74 68 6d ic SM3 algorithm
│ │ ## 500000a0: 2e 20 54 68 65 20 22 53 4d 22 20 72 65 70 72 65 . The "SM" repre
│ │ ## 500000b0: 73 65 6e 74 73 20 22 63 6f 6d 6d 65 72 63 69 61 sents "commercia
│ │ ## 500000c0: 6c 20 63 72 79 70 74 6f 67 72 61 70 68 79 2c 22 l cryptography,"
│ │ ## 500000d0: 20 77 68 69 63 68 20 72 65 66 65 72 73 20 74 6f which refers to
│ │ ## 500000e0: 20 63 72 79 70 74 6f 67 72 61 70 68 69 63 20 74 cryptographic t
│ │ ## 500000f0: 65 63 68 6e 6f 6c 6f 67 79 20 66 6f 72 20 63 6f echnology for co
│ │ ## 50000100: 6d 6d 65 72 63 69 61 6c 20 75 73 65 20 74 68 61 mmercial use tha
│ │ ## 50000110: 74 20 64 6f 65 73 20 6e 6f 74 20 69 6e 76 6f 6c t does not invol
│ │ ## 50000120: 76 65 20 73 74 61 74 65 20 73 65 63 72 65 74 73 ve state secrets
│ │ ## 50000130: 2e 20 49 74 20 69 73 20 62 61 73 65 64 20 6f 6e . It is based on
│ │ ## 50000140: 20 74 68 65 20 65 6c 6c 69 70 74 69 63 20 63 75 the elliptic cu
│ │ ## 50000150: 72 76 65 20 64 69 73 63 72 65 74 65 20 6c 6f 67 rve discrete log
│ │ ## 50000160: 61 72 69 74 68 6d 20 70 72 6f 62 6c 65 6d 20 61 arithm problem a
│ │ ## 50000170: 6e 64 20 69 73 20 75 73 65 64 20 74 6f 20 72 65 nd is used to re
│ │ ## 50000180: 70 6c 61 63 65 20 69 6e 73 65 63 75 72 65 20 68 place insecure h
│ │ ## 50000190: 61 73 68 20 61 6c 67 6f 72 69 74 68 6d 73 20 73 ash algorithms s
│ │ ## 500001a0: 75 63 68 20 61 73 20 4d 44 35 20 61 6e 64 20 53 uch as MD5 and S
│ │ ## 500001b0: 48 41 2d 31 2e 20 54 68 65 20 6f 75 74 70 75 74 HA-1. The output
│ │ ## 500001c0: 20 6c 65 6e 67 74 68 20 6f 66 20 74 68 65 20 53 length of the S
│ │ ## 500001d0: 4d 33 20 61 6c 67 6f 72 69 74 68 6d 20 69 73 20 M3 algorithm is
│ │ ## 500001e0: 32 35 36 20 62 69 74 73 2c 20 74 68 65 20 73 61 256 bits, the sa
│ │ ## 500001f0: 6d 65 20 61 73 20 53 48 41 2d 32 35 36 2e me as SHA-256.
│ ├─[helios-uboot] sm3sum ${loadaddr} ${filesize}
│ │ ## sm3_256 for 50000000 ... 500001fd ==> 53ce46ca129071694bac8007680573d83b941ea156ce46d9cc45a648c1b7e291
│ ├─Entering interactive shell...
│ ├─Press CTRL+] three times within 1 second to exit.u-boot=>
[3] https://www.toolhelper.cn/en/DigestAlgorithm/SM3
Heiko Schocher (2):
lib: sm3: fix coverity error
doc_ cmd: add documentation for sm3sum
doc/usage/cmd/sm3sum.rst | 117 +++++++++++++++++++++++++++++++++++++++ lib/sm3.c | 2 +- 2 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 doc/usage/cmd/sm3sum.rst
Signature · 3 lines
2.20.1 base-commit: c344087025a4c296468a1d5aeb61078a58baa59e
PATCH 1/2 lib: sm3: fix coverity error
Coverity scan reported:
CID 449815: Memory - illegal accesses (OVERRUN)
Overrunning array of 64 bytes at byte offset 64 by dereferencing pointer "sctx->buffer + partial". [Note: The source code implementation of the function has been overridden by a builtin model.]
In line: 252
memset(sctx->buffer + partial, 0, SM3_BLOCK_SIZE - partial);
The respective line should be:
memset(sctx->buffer + partial, 0, SM3_BLOCK_SIZE - partial - 1);
as partial gets incremented by one before.
---
lib/sm3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/sm3.c +1 -1
@@ -249,7 +249,7 @@ void sm3_final(struct sm3_context *sctx, uint8_t output[SM3_DIGEST_SIZE]) sctx->buffer[partial++] =0x80 ;if (partial > bit_offset) { -memset (sctx->buffer + partial,0 ,SM3_BLOCK_SIZE - partial); +memset (sctx->buffer + partial,0 ,SM3_BLOCK_SIZE - partial -1 ); partial =0 ;sm3_block (sctx, sctx->buffer,1 ,W );
Signature · 1 line
2.20.1
Re: [PATCH v1 1/2] lib: sm3: fix coverity error
Quoted 11 lines · Heiko Schocher
Coverity scan reported:
CID 449815: Memory - illegal accesses (OVERRUN)
Overrunning array of 64 bytes at byte offset 64 by dereferencing pointer "sctx->buffer+ partial". [Note: The source code implementation of the function has been overridden by a builtin model.]In line: 252
memset(sctx->buffer + partial, 0, SM3_BLOCK_SIZE - partial);
Quoted 8 lines
The respective line should be:
memset(sctx->buffer + partial, 0, SM3_BLOCK_SIZE - partial - 1);as partial gets incremented by one before.
Signed-off-by Heiko Schocher <[email protected]>---
Quoted 20 lines
lib/sm3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)lib/sm3.c +1
-2@@ -249,7 +249,7 @@ void sm3_final(struct sm3_context *sctx, uint8_t output[SM3_DIGEST_SIZE]) sctx->buffer[partial++] =0x80 ;if (partial > bit_offset) { -memset (sctx->buffer + partial,0 ,SM3_BLOCK_SIZE - partial); +memset (sctx->buffer + partial,0 ,SM3_BLOCK_SIZE - partial -1 ); partial =0 ;sm3_block (sctx, sctx->buffer,1 ,W ); --2.20.1
PATCH 2/2 doc_ cmd: add documentation for sm3sum
In reply to Heiko Schocheradd documentation for sm3sum command.
---
doc/usage/cmd/sm3sum.rst | 117 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 doc/usage/cmd/sm3sum.rst
doc/usage/cmd/sm3sum.rst new file +117 -0
@@ -0,0 +1,117 @@ +.. SPDX-License-Identifier: GPL-2.0+: + Copyright 2025 Nabladev + Written by Heiko Schocher <[email protected]> + +.. index:: + single: sm3sum (command) + +sm3sum command +============== + +Synopsis +-------- + +:: + + sm3sum - compute SM3 message digest + + Usage: + sm3sum address count [[*]sum] + - compute SM3 message digest [save to sum] + sm3sum -v address count [*]sum + - verify sm3sum of memory area + + +Description +----------- + +The sm3sum command calculates the SM3_256 Hash from a +address with length of count bytes. If the -v option is +passed to the command, it compares the calculated hash +with the hash found at address sum. + +The SM3 secure hash, is calculated as specified by OSCCA GM/T +0004-2012 SM3 and described at + +https://datatracker.ietf.org/doc/html/draft-sca-cfrg-sm3-02 + +Parameters +---------- + +address + address from where the sm3 hash is calculated + +count + length in bytes of memory area for which the sm3 hash is calculated + +sum + address of hash to which the calculated hash gets stored + + or if "-v" option is passed: + + address of hash with which the calculated hash gets compared. + +Example +------- + +create some data + +:: + + u-boot=> mw 0x0000000100000000 0x426f6f46 1 + u-boot=> md.b 0x0000000100000000 4 + 00000000: 46 6f 6f 42 FooB + +and calculate the sm3sum from address and store it in environment +variable hashval + +:: + + u-boot=> sm3sum 0x0000000100000000 4 hashval + sm3_256 for 100000000 ... 100000003 ==> cdf49da4e33017bf2d9fe87b885d80c9a7c920be7e10ffb8c89036a1eb1503b7 + u-boot=> print hashval + hashval=cdf49da4e33017bf2d9fe87b885d80c9a7c920be7e10ffb8c89036a1eb1503b7 + u-boot=> + +or calculate sm3sum from address and store it at address sum + +:: + + u-boot=> sm3sum 0x0000000100000000 4 *0x0000000110000000 + sm3_256 for 100000000 ... 100000003 ==> cdf49da4e33017bf2d9fe87b885d80c9a7c920be7e10ffb8c89036a1eb1503b7 + +and now check if this hash is a valid sm3sum with "-v" option + +:: + + u-boot=> sm3sum -v 0x0000000100000000 4 *0x0000000110000000 + u-boot=> echo $? + 0 + +example with wrong hash + +:: + + u-boot=> sm3sum -v 0x0000000100000000 4 *0x0000000110000004 + sm3_256 for 100000000 ... 100000003 ==> cdf49da4e33017bf2d9fe87b885d80c9a7c920be7e10ffb8c89036a1eb1503b7 != e33017bf2d9fe87b885d80c9a7c920be7e10ffb8c89036a1eb1503b7ffffffff ** ERROR ** + u-boot=> + + +Configuration +------------- + +Enable the sm3sum command via Kconfig option CONFIG_CMD_SM3SUM. +The "-v" option is separate enabled through Kconfig option +CONFIG_SM3SUM_VERIFY. + + +Return value +------------ + +The return value $? is true (0) if the hash is calculated or if +the created hash is the same as the hash stored in memory at +address sum. + +The return value is false (1) if there is a problem with +calculating the hash, or if the hash is not the same as +the hash stored ar address sum.
Signature · 1 line
2.20.1
Re: [PATCH v1 2/2] doc_ cmd: add documentation for sm3sum
Hi Heiko,
Typo in title, should be doc: and not doc_.
Quoted 15 lines · Heiko Schocher
add documentation for sm3sum command.
Signed-off-by Heiko Schocher <[email protected]>---
doc/usage/cmd/sm3sum.rst | 117 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+)create mode 100644
doc/usage/cmd/sm3sum.rstdoc/usage/cmd/sm3sum.rst new file +0
-0
doc/usage/cmd/sm3sum.rst line 1
Quoted 1 line
doc/usage/cmd/sm3sum.rst new file +1
-0@@ -0,0 +1,117 @@ +.. SPDX-License-Identifier: GPL-2.0+:
Use the canonical version:
GPL-2.0-or-later
c.f. https://spdx.org/licenses/GPL-2.0-or-later.html
(Do not end it with a colon either).
doc/usage/cmd/sm3sum.rst line 2
Quoted 1 line
doc/usage/cmd/sm3sum.rst new file +1
-0+ Copyright 2025 Nabladev
Seems like we typically use a new comment for this line
.. Copyright 2025 Nabladev
I **think** the copyright should use the name of the legal entity (so likely "Nabla Software Engineering GmbH"). But IANAL and I personally don't care :)
Quoted 16 lines
doc/usage/cmd/sm3sum.rst new file +16
-0+ Written by Heiko Schocher <[email protected]> + +.. index:: + single: sm3sum (command) + +sm3sum command +============== + +Synopsis +-------- + +:: + + sm3sum - compute SM3 message digest + + Usage:
doc/usage/cmd/sm3sum.rst line 28
Quoted 10 lines
doc/usage/cmd/sm3sum.rst new file +10
-0+ sm3sum address count [[*]sum] + - compute SM3 message digest [save to sum] + sm3sum -v address count [*]sum + - verify sm3sum of memory area + + +Description +----------- + +The sm3sum command calculates the SM3_256 Hash from a
Are there variants of SM3? From what I understood, it's "equivalent" to sha256 in terms of security and efficiency, but it's SM3, just that?
doc/usage/cmd/sm3sum.rst line 29
Quoted 1 line
doc/usage/cmd/sm3sum.rst new file +1
-0+address with length of count bytes. If the -v option is
Can suggest:
"""
calculates the SM3 hash of data of ``count`` bytes at address ``address``. """
which highlights which parts of the command must be specific by the user.
s/-v/``-v``/
doc/usage/cmd/sm3sum.rst line 32
Quoted 3 lines
doc/usage/cmd/sm3sum.rst new file +3
-0+passed to the command, it compares the calculated hash +with the hash found at address sum. +
s/sum/``sum``/.
doc/usage/cmd/sm3sum.rst line 33
Quoted 1 line
doc/usage/cmd/sm3sum.rst new file +1
-0+The SM3 secure hash, is calculated as specified by OSCCA GM/T
s/,//
doc/usage/cmd/sm3sum.rst line 42
Quoted 9 lines
doc/usage/cmd/sm3sum.rst new file +9
-0+0004-2012 SM3 and described at + +https://datatracker.ietf.org/doc/html/draft-sca-cfrg-sm3-02 + +Parameters +---------- + +address + address from where the sm3 hash is calculated
How is this value parsed? Is it deducted from the string (e.g. starts with 0x or contains hex digits = hex, starts with 0, octal, otherwise decimal), or is it a forced base? This needs to be specified.
doc/usage/cmd/sm3sum.rst line 48
Quoted 6 lines
doc/usage/cmd/sm3sum.rst new file +6
-0+ +count + length in bytes of memory area for which the sm3 hash is calculated + +sum + address of hash to which the calculated hash gets stored
This is only true if you sum starts with "*" no? Otherwise it's the name of the environment variable where to store the checksum?
doc/usage/cmd/sm3sum.rst line 50
Quoted 2 lines
doc/usage/cmd/sm3sum.rst new file +2
-0+ + or if "-v" option is passed:
s/"-v"/``-v``/
doc/usage/cmd/sm3sum.rst line 58
Quoted 8 lines
doc/usage/cmd/sm3sum.rst new file +8
-0+ + address of hash with which the calculated hash gets compared. + +Example +------- + +create some data +
+at address ``0x0000000100000000``
(do we need the leading zeroes?)
doc/usage/cmd/sm3sum.rst line 65
Quoted 7 lines
doc/usage/cmd/sm3sum.rst new file +7
-0+:: + + u-boot=> mw 0x0000000100000000 0x426f6f46 1 + u-boot=> md.b 0x0000000100000000 4 + 00000000: 46 6f 6f 42 FooB + +and calculate the sm3sum from address and store it in environment
s/from address/of 4 bytes starting from address ``0x0000000100000000``/
doc/usage/cmd/sm3sum.rst line 67
Quoted 2 lines
doc/usage/cmd/sm3sum.rst new file +2
-0+variable hashval +
s/hashval/``hashval``/
doc/usage/cmd/sm3sum.rst line 76
Quoted 9 lines
doc/usage/cmd/sm3sum.rst new file +9
-0+:: + + u-boot=> sm3sum 0x0000000100000000 4 hashval + sm3_256 for 100000000 ... 100000003 ==> cdf49da4e33017bf2d9fe87b885d80c9a7c920be7e10ffb8c89036a1eb1503b7 + u-boot=> print hashval + hashval=cdf49da4e33017bf2d9fe87b885d80c9a7c920be7e10ffb8c89036a1eb1503b7 + u-boot=> + +or calculate sm3sum from address and store it at address sum
s/from address/of 4 bytes starting from address ``0x0000000100000000``/
s/sum/``0x0000000110000000``/
doc/usage/cmd/sm3sum.rst line 83
Quoted 7 lines
doc/usage/cmd/sm3sum.rst new file +7
-0+ +:: + + u-boot=> sm3sum 0x0000000100000000 4 *0x0000000110000000 + sm3_256 for 100000000 ... 100000003 ==> cdf49da4e33017bf2d9fe87b885d80c9a7c920be7e10ffb8c89036a1eb1503b7 + +and now check if this hash is a valid sm3sum with "-v" option
s/is a valid sm3sum/is the expected sm3sum hash value/
s/"-v"/``-v``/
Quoted 10 lines
doc/usage/cmd/sm3sum.rst new file +10
-0+ +:: + + u-boot=> sm3sum -v 0x0000000100000000 4 *0x0000000110000000 + u-boot=> echo $? + 0 + +example with wrong hash + +::
doc/usage/cmd/sm3sum.rst line 103
Quoted 10 lines
doc/usage/cmd/sm3sum.rst new file +10
-0+ + u-boot=> sm3sum -v 0x0000000100000000 4 *0x0000000110000004 + sm3_256 for 100000000 ... 100000003 ==> cdf49da4e33017bf2d9fe87b885d80c9a7c920be7e10ffb8c89036a1eb1503b7 != e33017bf2d9fe87b885d80c9a7c920be7e10ffb8c89036a1eb1503b7ffffffff ** ERROR ** + u-boot=> + + +Configuration +------------- + +Enable the sm3sum command via Kconfig option CONFIG_CMD_SM3SUM.
s/CONFIG_CMD_SM3SUM/``CONFIG_CMD_SM3SUM``/
doc/usage/cmd/sm3sum.rst line 104
Quoted 1 line
doc/usage/cmd/sm3sum.rst new file +1
-0+The "-v" option is separate enabled through Kconfig option
s/"-v"/``-v``/
doc/usage/cmd/sm3sum.rst line 105
Quoted 1 line
doc/usage/cmd/sm3sum.rst new file +1
-0+CONFIG_SM3SUM_VERIFY.
s/CONFIG_SM3SUM_VERIFY/``CONFIG_SM3SUM_VERIFY``/
doc/usage/cmd/sm3sum.rst line 117
Quoted 12 lines
doc/usage/cmd/sm3sum.rst new file +12
-0+ + +Return value +------------ + +The return value $? is true (0) if the hash is calculated or if +the created hash is the same as the hash stored in memory at +address sum. + +The return value is false (1) if there is a problem with +calculating the hash, or if the hash is not the same as +the hash stored ar address sum.
This matches the expectations I got from reading https://docs.u-boot.org/en/latest/usage/cmdline.html#general-rules (point 3). So I would simply remove the return value section in this patch here.
Cheers,
Quentin
Re: [PATCH v1 2/2] doc_ cmd: add documentation for sm3sum
Hello Quentin,
sorry for long delay...
Quoted 24 lines · Quentin Schulz
Hi Heiko,
Typo in title, should be doc: and not
doc_.Quoted 15 lines · Heiko Schocher
add documentation for sm3sum command.
Signed-off-by Heiko Schocher <[email protected]>---
doc/usage/cmd/sm3sum.rst| 117 +++++++++++++++++++++++++++++++++++++++1 file changed, 117 insertions(+)create mode 100644
doc/usage/cmd/sm3sum.rstdoc/usage/cmd/sm3sum.rst new file +0
-0doc/usage/cmd/sm3sum.rst line 1
Quoted 1 line
doc/usage/cmd/sm3sum.rst new file +1
-0@@ -0,0 +1,117 @@ +.. SPDX-License-Identifier: GPL-2.0+:Use the canonical version:
Quoted 5 lines
GPL-2.0-or-later
c.f. https://spdx.org/licenses/GPL-2.0-or-later.html
(Do not end it with a colon either).
okay, but I just copied from other files... for example doc/usage/cmd/dm.rst:
1 .. SPDX-License-Identifier: GPL-2.0+:
2
So of course I change it... but does that mean, we should fix all other files too?
Quoted 6 lines
doc/usage/cmd/sm3sum.rst line 2
Quoted 2 lines
doc/usage/cmd/sm3sum.rst new file +1
-0+ Copyright 2025 NabladevSeems like we typically use a new comment for this line
.. Copyright 2025 Nabladev
Fixed.
Quoted 22 lines
I **think** the copyright should use the name of the legal entity (so likely "Nabla Software Engineering GmbH"). But IANAL and I personally don't care :)
Quoted 20 lines
doc/usage/cmd/sm3sum.rst new file +20
-0+ Written by Heiko Schocher <[email protected]> + +.. index:: + single: sm3sum (command) + +sm3sum command +============== + +Synopsis +-------- + +:: + + sm3sum - compute SM3 message digest + + Usage: + sm3sum address count [[*]sum] + - compute SM3 message digest [save to sum] + sm3sum -v address count [*]sum + - verify sm3sum of memory area
Quoted 8 lines
doc/usage/cmd/sm3sum.rst line 28
Quoted 6 lines
doc/usage/cmd/sm3sum.rst new file +6
-0+ + +Description +----------- + +The sm3sum command calculates the SM3_256 Hash from aAre there variants of SM3? From what I understood, it's "equivalent" to sha256 in terms of security and efficiency, but it's SM3, just that?
As I know, there is only sm3_256 hash. If you look for example into include/tpm-v2.h
33 #define TPM2_SM3_256_DIGEST_SIZE 32
[...]
277 TPM2_ALG_SM3_256 = 0x12,
[...]
301 #define TCG2_BOOT_HASH_ALG_SM3_256 0x00000010
Quoted 5 lines
doc/usage/cmd/sm3sum.rst line 29
Quoted 2 lines
doc/usage/cmd/sm3sum.rst new file +1
-0+address with length of count bytes. If the -v option isCan suggest:
Quoted 7 lines
"""
calculates the SM3 hash of data of ``count`` bytes at address ``address``. """which highlights which parts of the command must be specific by the user.
s/-v/``-v``/
done.
Quoted 6 lines
doc/usage/cmd/sm3sum.rst line 32
Quoted 4 lines
doc/usage/cmd/sm3sum.rst new file +3
-0+passed to the command, it compares the calculated hash +with the hash found at address sum. +s/sum/``sum``/.
done.
Quoted 4 lines
doc/usage/cmd/sm3sum.rst line 33
Quoted 2 lines
doc/usage/cmd/sm3sum.rst new file +1
-0+The SM3 secure hash, is calculated as specified by OSCCA GM/Ts/,//
done.
Quoted 12 lines
doc/usage/cmd/sm3sum.rst line 42
Quoted 10 lines
doc/usage/cmd/sm3sum.rst new file +9
-0+0004-2012 SM3 and described at + +https://datatracker.ietf.org/doc/html/draft-sca-cfrg-sm3-02 + +Parameters +---------- + +address + address from where the sm3 hash is calculatedHow is this value parsed? Is it deducted from the string (e.g. starts with 0x or contains hex digits = hex, starts with 0, octal, otherwise decimal), or is it a forced base? This needs to be specified.
It is at the end from hextoul(), so it is at the end "hex"...
I added the line
Hexadecimal string, 0x prefix optional.
Quoted 3 lines
doc/usage/cmd/sm3sum.rst line 45
Quoted 3 lines
doc/usage/cmd/sm3sum.rst new file +3
-0+ +count + length in bytes of memory area for which the sm3 hash is calculated
same here hextoul() used...
Quoted 5 lines
doc/usage/cmd/sm3sum.rst line 48
Quoted 3 lines
doc/usage/cmd/sm3sum.rst new file +3
-0+ +sum + address of hash to which the calculated hash gets storedThis is only true if you sum starts with "*" no? Otherwise it's the name of the environment variable where to store the checksum?
correct, good catch, see the examples.
Quoted 5 lines
doc/usage/cmd/sm3sum.rst line 50
Quoted 3 lines
doc/usage/cmd/sm3sum.rst new file +2
-0+ + or if "-v" option is passed:s/"-v"/``-v``/
done.
Quoted 12 lines
doc/usage/cmd/sm3sum.rst line 58
Quoted 9 lines
doc/usage/cmd/sm3sum.rst new file +8
-0+ + address of hash with which the calculated hash gets compared. + +Example +------- + +create some data ++at address ``0x0000000100000000``
Quoted 1 line
(do we need the leading zeroes?)
removed them.
Quoted 10 lines
doc/usage/cmd/sm3sum.rst line 65
Quoted 8 lines
doc/usage/cmd/sm3sum.rst new file +7
-0+:: + + u-boot=> mw 0x0000000100000000 0x426f6f46 1 + u-boot=> md.b 0x0000000100000000 4 + 00000000: 46 6f 6f 42 FooB + +and calculate the sm3sum from address and store it in environments/from address/of 4 bytes starting from address ``0x0000000100000000``/
done.
Quoted 5 lines
doc/usage/cmd/sm3sum.rst line 67
Quoted 3 lines
doc/usage/cmd/sm3sum.rst new file +2
-0+variable hashval +s/hashval/``hashval``/
done.
Quoted 14 lines
doc/usage/cmd/sm3sum.rst
Quoted 11 lines
doc/usage/cmd/sm3sum.rst new file +4
-0+:: + + u-boot=> sm3sum 0x0000000100000000 4 hashval + sm3_256 for 100000000 ... 100000003 ==>
cdf49da4e33017bf2d9fe87b885d80c9a7c920be7e10ffb8c89036a1eb1503b7+ u-boot=> print hashval
+ hashval=cdf49da4e33017bf2d9fe87b885d80c9a7c920be7e10ffb8c89036a1eb1503b7 + u-boot=>doc/usage/cmd/sm3sum.rst new file +2
-0+ +or calculate sm3sum from address and store it at address sums/from address/of 4 bytes starting from address ``0x0000000100000000``/
Quoted 1 line
s/sum/``0x0000000110000000``/
done.
Quoted 11 lines
doc/usage/cmd/sm3sum.rst
Quoted 9 lines
doc/usage/cmd/sm3sum.rst new file +5
-0+ +:: + + u-boot=> sm3sum 0x0000000100000000 4 *0x0000000110000000 + sm3_256 for 100000000 ... 100000003 ==>
cdf49da4e33017bf2d9fe87b885d80c9a7c920be7e10ffb8c89036a1eb1503b7doc/usage/cmd/sm3sum.rst new file +2
-0+ +and now check if this hash is a valid sm3sum with "-v" options/is a valid sm3sum/is the expected sm3sum hash value/
done.
Quoted 17 lines
s/"-v"/``-v``/
Quoted 15 lines
doc/usage/cmd/sm3sum.rst new file +13
-0+ +:: + + u-boot=> sm3sum -v 0x0000000100000000 4 *0x0000000110000000 + u-boot=> echo $? + 0 + +example with wrong hash + +:: + + u-boot=> sm3sum -v 0x0000000100000000 4 *0x0000000110000004 + sm3_256 for 100000000 ... 100000003 ==>
cdf49da4e33017bf2d9fe87b885d80c9a7c920be7e10ffb8c89036a1eb1503b7!=e33017bf2d9fe87b885d80c9a7c920be7e10ffb8c89036a1eb1503b7ffffffff** ERROR ** + u-boot=>
Quoted 8 lines
doc/usage/cmd/sm3sum.rst line 103
Quoted 6 lines
doc/usage/cmd/sm3sum.rst new file +6
-0+ + +Configuration +------------- + +Enable the sm3sum command via Kconfig option CONFIG_CMD_SM3SUM.s/CONFIG_CMD_SM3SUM/``CONFIG_CMD_SM3SUM``/
done.
Quoted 4 lines
Quoted 2 lines
+The "-v" option is separate enabled through
Kconfigoptions/"-v"/``-v``/
done.
Quoted 4 lines
Quoted 2 lines
+CONFIG_SM3SUM_VERIFY.
s/CONFIG_SM3SUM_VERIFY/``CONFIG_SM3SUM_VERIFY``/
done.
Quoted 15 lines
doc/usage/cmd/sm3sum.rst line 117
Quoted 13 lines
doc/usage/cmd/sm3sum.rst new file +12
-0+ + +Return value +------------ + +The return value $? is true (0) if the hash is calculated or if +the created hash is the same as the hash stored in memory at +address sum. + +The return value is false (1) if there is a problem with +calculating the hash, or if the hash is not the same as +the hash stored ar address sum.This matches the expectations I got from reading https://docs.u-boot.org/en/latest/usage/cmdline.html#general-rules (point 3). So I would simply remove the return value section in this patch here.
removed.
Many thanks for your input!
Azure build runs, if fine, I send v2...
bye,
Heiko
Signature · 5 lines
Nabla Software Engineering HRB 40522 Augsburg Phone: +49 821 45592596 E-Mail: [email protected] Geschäftsführer : Stefano Babic
Re: [PATCH v1 2/2] doc_ cmd: add documentation for sm3sum
Hi Heiko,
Quoted 10 lines · Heiko Schocher
Hello Quentin,
sorry for long delay...
Quoted 5 lines · Quentin Schulz
Hi Heiko,
Typo in title, should be doc: and not
doc_.On 1/6/26 3:14 PM, Heiko Schocher wrote:
[...]
Quoted 16 lines
Quoted 10 lines
doc/usage/cmd/sm3sum.rst line 1
Quoted 7 lines
doc/usage/cmd/sm3sum.rst new file +1
-0@@ -0,0 +1,117 @@ +.. SPDX-License-Identifier: GPL-2.0+:Use the canonical version:
Quoted 5 lines
GPL-2.0-or-later
c.f. https://eur02.safelinks.protection.outlook.com/? url=https%3A%2F%2Fspdx.org%2Flicenses%2FGPL-2.0-or- later.html&data=05%7C02%7Cquentin.schulz%40cherry.de%7C752a802f23394270c5f808de5996472c%7C5e0e1b5221b54e7b83bb514ec460677e%7C0%7C0%7C639046699157004614%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=hFPbf2cm4pcD17T8ORnYC%2FL9VOWm2s%2B8Ebnb6TMjru8%3D&reserved=0
(Do not end it with a colon either).
Quoted 8 lines
okay, but I just copied from other files... for example
doc/usage/cmd/dm.rst:
1 .. SPDX-License-Identifier: GPL-2.0+:
2So of course I change it... but does that mean, we should fix all other files too?
It's unnecessary churn so I would say no. Considering I had other comments on the patch, I allowed myself this nitpick but if that was the only thing I was bothered with I wouldn't have told you. It's still clear we're talking about the -or-later version of the license. The biggest issue would be with GPL-2.0 or GPLv2 for example because it isn't clear if it's the -only version of the -or-later version since it matches none of the SPDX license identifier.
I don't think Tom will want a patch to change all SPDX-License-Identifier from GPL-2.0+ to GPL-2.0-or-later but maybe I'm wrong :)
[...]
Quoted 7 lines
Quoted 6 lines
doc/usage/cmd/sm3sum.rst line 28
Quoted 4 lines
doc/usage/cmd/sm3sum.rst new file +4
-0+Description +----------- + +The sm3sum command calculates the SM3_256 Hash from aAre there variants of SM3? From what I understood, it's "equivalent" to sha256 in terms of security and efficiency, but it's SM3, just that?
Quoted 8 lines
As I know, there is only
sm3_256hash. If you look for example intoinclude/tpm-v2.h
33 #defineTPM2_SM3_256_DIGEST_SIZE32
[...]
277 TPM2_ALG_SM3_256 =0x12,
[...]
301 #defineTCG2_BOOT_HASH_ALG_SM3_2560x00000010
So I would say we should use ``SM3`` here, instead of ``SM3_256``?
Cheers,
Quentin
Re: [PATCH v1 2/2] doc_ cmd: add documentation for sm3sum
Hello Quentin,
Quoted 36 lines · Quentin Schulz
Hi Heiko,
Quoted 10 lines · Heiko Schocher
Hello Quentin,
sorry for long delay...
Quoted 5 lines · Quentin Schulz
Hi Heiko,
Typo in title, should be doc: and not
doc_.On 1/6/26 3:14 PM, Heiko Schocher wrote:
[...]
Quoted 22 lines
Quoted 10 lines
doc/usage/cmd/sm3sum.rst line 1
Quoted 7 lines
doc/usage/cmd/sm3sum.rst new file +1
-0@@ -0,0 +1,117 @@ +.. SPDX-License-Identifier: GPL-2.0+:Use the canonical version:
Quoted 6 lines
GPL-2.0-or-later
c.f. https://eur02.safelinks.protection.outlook.com/? url=https%3A%2F%2Fspdx.org%2Flicenses%2FGPL-2.0-or- later.html&data=05%7C02%7Cquentin.schulz%40cherry.de%7C752a802f23394270c5f808de5996472c%7C5e0e1b5221b54e7b83bb514ec460677e%7C0%7C0%7C639046699157004614%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=hFPbf2cm4pcD17T8ORnYC%2FL9VOWm2s%2B8Ebnb6TMjru8%3D&reserved=0
(Do not end it with a colon either).
okay, but I just copied from other files... for example
doc/usage/cmd/dm.rst:
1 .. SPDX-License-Identifier: GPL-2.0+:
2
Quoted 8 lines
Quoted 3 lines
So of course I change it... but does that mean, we should fix all other files too?
It's unnecessary churn so I would say no. Considering I had other comments on the patch, I allowed myself this nitpick but if that was the only thing I was bothered with I wouldn't have told you. It's still clear we're talking about the -or-later version of the license. The biggest issue would be with GPL-2.0 or GPLv2 for example because it isn't clear if it's the -only version of the -or-later version since it matches none of the SPDX license identifier.
I don't think Tom will want a patch to change all SPDX-License-Identifier from GPL-2.0+ to GPL-2.0-or-later but maybe I'm wrong :)
I think not :-P
What is with ending ":" ... above example has also the ending ":" I removed it as you suggested...
Quoted 19 lines
[...]
Quoted 7 lines
Quoted 6 lines
doc/usage/cmd/sm3sum.rst line 28
Quoted 4 lines
doc/usage/cmd/sm3sum.rst new file +4
-0+Description +----------- + +The sm3sum command calculates the SM3_256 Hash from aAre there variants of SM3? From what I understood, it's "equivalent" to sha256 in terms of security and efficiency, but it's SM3, just that?
Quoted 8 lines
As I know, there is only
sm3_256hash. If you look for example intoinclude/tpm-v2.h
33 #defineTPM2_SM3_256_DIGEST_SIZE32
[...]
277 TPM2_ALG_SM3_256 =0x12,
[...]
301 #defineTCG2_BOOT_HASH_ALG_SM3_2560x00000010
Quoted 1 line
So I would say we should use ``SM3`` here, instead of ``SM3_256``?
No, as linux also use the same define, see linux base:
* 6c790212c588 - (HEAD -> master, origin/master, origin/HEAD) Merge tag 'devicetree-fixes-for-6.19-3' of git://git.kernel.org/pub/scm/linux/kernel/git/robh/linux
include/linux/tpm.h:
55 TPM_ALG_SM3_256 = 0x0012,
Thanks!
bye,
Heiko
Quoted 3 lines
Cheers,
Quentin
Signature · 5 lines
Nabla Software Engineering HRB 40522 Augsburg Phone: +49 821 45592596 E-Mail: [email protected] Geschäftsführer : Stefano Babic
Re: [PATCH v1 2/2] doc_ cmd: add documentation for sm3sum
Hi Heiko,
Quoted 44 lines · Heiko Schocher
Hello Quentin,
Quoted 41 lines · Quentin Schulz
Hi Heiko,
Quoted 10 lines · Heiko Schocher
Hello Quentin,
sorry for long delay...
Quoted 5 lines · Quentin Schulz
Hi Heiko,
Typo in title, should be doc: and not
doc_.On 1/6/26 3:14 PM, Heiko Schocher wrote:
[...]
Quoted 16 lines
Quoted 10 lines
doc/usage/cmd/sm3sum.rst line 1
Quoted 7 lines
doc/usage/cmd/sm3sum.rst new file +1
-0@@ -0,0 +1,117 @@ +.. SPDX-License-Identifier: GPL-2.0+:Use the canonical version:
Quoted 5 lines
GPL-2.0-or-later
c.f. https://eur02.safelinks.protection.outlook.com/? url=https%3A%2F%2Fspdx.org%2Flicenses%2FGPL-2.0-or- later.html&data=05%7C02%7Cquentin.schulz%40cherry.de%7C752a802f23394270c5f808de5996472c%7C5e0e1b5221b54e7b83bb514ec460677e%7C0%7C0%7C639046699157004614%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=hFPbf2cm4pcD17T8ORnYC%2FL9VOWm2s%2B8Ebnb6TMjru8%3D&reserved=0
(Do not end it with a colon either).
Quoted 8 lines
okay, but I just copied from other files... for example
doc/usage/cmd/dm.rst:
1 .. SPDX-License-Identifier: GPL-2.0+:
2So of course I change it... but does that mean, we should fix all other files too?
It's unnecessary churn so I would say no. Considering I had other comments on the patch, I allowed myself this nitpick but if that was the only thing I was bothered with I wouldn't have told you. It's still clear we're talking about the -or-later version of the license. The biggest issue would be with GPL-2.0 or GPLv2 for example because it isn't clear if it's the -only version of the -or-later version since it matches none of the SPDX license identifier.
https://spdx.github.io/spdx-spec/v3.0.1/annexes/spdx-license-expressions/#simple-license-expressions
specifies we can have the short form identifier with a unary + operator to mean -or-later, so this seems fine actually.
Quoted 7 lines
Quoted 1 line
I don't think Tom will want a patch to change all SPDX-License- Identifier from GPL-2.0+ to GPL-2.0-or-later but maybe I'm wrong :)
I think not :-P
What is with ending ":" ... above example has also the ending ":" I removed it as you suggested...
Ah. I don't think this is valid.
https://spdx.github.io/spdx-spec/v3.0.1/annexes/spdx-license-expressions/#overview has the exact syntax of a license expression.
https://spdx.github.io/using/license-id-in-source/ specifies how it should look like in code and I don't see a trailing colon. Whether that will trip license parsers remains unknown.
I think *this* specifically should be fine for a doc/-wide patch.
I think this may stem from editor plugins automatically adding colons at the end of a string started with ".. " as that's the start of a directive in rST? Or maybe the first contributor made a mistake and everybody copy-pasted it :)
The kernel doesn't have any of this kind of strings and it specifies how to specify the license for rST files here:
https://elixir.bootlin.com/linux/v6.18.6/source/Documentation/process/license-rules.rst#L80
Quoted 19 lines
Quoted 19 lines
[...]
Quoted 15 lines
Quoted 6 lines
doc/usage/cmd/sm3sum.rst line 28
Quoted 4 lines
doc/usage/cmd/sm3sum.rst new file +4
-0+Description +----------- + +The sm3sum command calculates the SM3_256 Hash from aAre there variants of SM3? From what I understood, it's "equivalent" to sha256 in terms of security and efficiency, but it's SM3, just that?
As I know, there is only
sm3_256hash. If you look for example intoinclude/tpm-v2.h
33 #defineTPM2_SM3_256_DIGEST_SIZE32
[...]
277 TPM2_ALG_SM3_256 =0x12,
[...]
301 #defineTCG2_BOOT_HASH_ALG_SM3_2560x00000010
Quoted 8 lines
Quoted 1 line
So I would say we should use ``SM3`` here, instead of ``SM3_256``?
No, as linux also use the same define, see linux base:
*6c790212c588- (HEAD -> master, origin/master, origin/HEAD) Merge tag 'devicetree-fixes-for-6.19-3' ofgit://git.kernel.org/pub/scm/linux/kernel/git/robh/linuxinclude/linux/tpm.h:
55 TPM_ALG_SM3_256 =0x0012,
/me shrugs
No strong opinion.
Cheers,
Quentin