Skip to contentSkip to conversation

lib: sm3: coverity fix and add documentation

PATCH In review Heiko Schocher 3 participants 6 messages Jan 23 – Feb 11 Library code

lore
Share & tools
lore
#0 lore raw

v2 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.

rebased series to
commit 6b2d05748cf ("Merge tag 'u-boot-imx-master-20260117' of https://gitlab.denx.de/u-boot/custodians/u-boot-imx")

Azure build:
https://dev.azure.com/hs0298/hs/_build/results?buildId=205&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

Changes in v2:
rebased series to
commit 6b2d05748cf ("Merge tag 'u-boot-imx-master-20260117' of https://gitlab.denx.de/u-boot/custodians/u-boot-imx")
added Acked-by from Ilias
Added comments from Quentin
- fixed typo in commit subject
- fixed a lot of style and spelling issues
- added in parameters section the format of the input values
- removed section "Return value"

Heiko Schocher (2):
lib: sm3: fix coverity error
doc: cmd: add documentation for sm3sum

 doc/usage/cmd/sm3sum.rst | 112 +++++++++++++++++++++++++++++++++++++++
 lib/sm3.c                |   2 +-
 2 files changed, 113 insertions(+), 1 deletion(-)
 create mode 100644 doc/usage/cmd/sm3sum.rst
Signature · 3 lines
2.20.1

base-commit: 6b2d05748cf3cd6ba417a96c00602b0122e10af6
#1 lore raw

PATCH v2 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.

---

Changes in v2:
rebased series to
commit 6b2d05748cf ("Merge tag 'u-boot-imx-master-20260117' of https://gitlab.denx.de/u-boot/custodians/u-boot-imx")
added Acked-by from Ilias

 lib/sm3.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/sm3.c +1 -1
index 2a4e825481d..05880099703 100644
@@ -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
#2 lore raw

PATCH v2 2/2 doc: cmd: add documentation for sm3sum

In reply to Heiko Schocher

add documentation for sm3sum command.

---

Changes in v2:
Added comments from Quentin
- fixed typo in commit subject
- fixed a lot of style and spelling issues
- added in parameters section the format of the input values
- removed section "Return value"

 doc/usage/cmd/sm3sum.rst | 112 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 112 insertions(+)
 create mode 100644 doc/usage/cmd/sm3sum.rst
doc/usage/cmd/sm3sum.rst new file +112 -0
new file mode 100644
index 00000000000..2a3ee456395
@@ -0,0 +1,112 @@
+.. SPDX-License-Identifier: GPL-2.0-or-later
+.. Copyright Nabla Software Engineering GmbH
+   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 hash of data of ``count`` bytes
+at address ``address``. 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.
+    Hexadecimal string, 0x prefix optional.
+
+count
+    length in bytes of memory area for which the sm3 hash is calculated
+    Hexadecimal string, 0x prefix optional.
+
+sum
+    if it starts with ``*`` the string is interpreted as an address
+    in hexadecimal format to which the calculated hash gets stored.
+
+    else the string is interpreted as a name for an environment variable
+    in which the calculated hash is stored as string.
+
+    or if ``-v`` option is passed:
+
+    address of hash with which the calculated hash gets compared.
+
+Example
+-------
+
+create some data
+
+::
+
+    u-boot=> mw 0x100000000 0x426f6f46 1
+    u-boot=> md.b 0x100000000 4
+    00000000: 46 6f 6f 42                                      FooB
+
+and calculate the sm3sum of 4 bytes starting from address ``0x100000000``
+and store it in environment variable ``hashval``
+
+::
+
+    u-boot=> sm3sum 0x100000000 4 hashval
+    sm3_256 for 100000000 ... 100000003 ==> cdf49da4e33017bf2d9fe87b885d80c9a7c920be7e10ffb8c89036a1eb1503b7
+    u-boot=> print hashval
+    hashval=cdf49da4e33017bf2d9fe87b885d80c9a7c920be7e10ffb8c89036a1eb1503b7
+    u-boot=>
+
+or calculate sm3sum of 4 bytes starting from address ``0x100000000`` and
+store it at address ``0x110000000``
+
+::
+
+    u-boot=> sm3sum 0x100000000 4 *0x110000000
+    sm3_256 for 100000000 ... 100000003 ==> cdf49da4e33017bf2d9fe87b885d80c9a7c920be7e10ffb8c89036a1eb1503b7
+
+and now check if this hash is the expected sm3sum hash value with ``-v``
+option
+
+::
+
+    u-boot=> sm3sum -v 0x100000000 4 *0x110000000
+    u-boot=> echo $?
+    0
+
+example with wrong hash
+
+::
+
+    u-boot=> sm3sum -v 0x100000000 4 *0x110000004
+    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``.
Signature · 1 line
2.20.1
#4 lore raw
In reply to Heiko Schocher

Hello Tom,

this series fixes a coverity issue and adds the missing doc for the new sm3sum command... I got no further comments... may I ask, if it could be applied?

Thanks!

bye,
Heiko

Quoted 121 lines · Heiko Schocher

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.

rebased series to
commit 6b2d05748cf ("Merge tag 'u-boot-imx-master-20260117' of https://gitlab.denx.de/u-boot/custodians/u-boot-imx")

Azure build:
https://dev.azure.com/hs0298/hs/_build/results?buildId=205&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

Changes in v2:
rebased series to
commit 6b2d05748cf ("Merge tag 'u-boot-imx-master-20260117' of https://gitlab.denx.de/u-boot/custodians/u-boot-imx")
added Acked-by from Ilias
Added comments from Quentin
- fixed typo in commit subject
- fixed a lot of style and spelling issues
- added in parameters section the format of the input values
- removed section "Return value"

Heiko Schocher (2):
lib: sm3: fix coverity error
doc: cmd: add documentation for sm3sum

  doc/usage/cmd/sm3sum.rst | 112 +++++++++++++++++++++++++++++++++++++++
  lib/sm3.c                |   2 +-
  2 files changed, 113 insertions(+), 1 deletion(-)

create mode 100644 doc/usage/cmd/sm3sum.rst

Signature · 5 lines
Nabla Software Engineering
HRB 40522 Augsburg
Phone: +49 821 45592596
E-Mail: [email protected]
Geschäftsführer : Stefano Babic
#5 lore raw

Hi Heiko

Quoted 6 lines · Heiko Schocher

Hello Tom,

this series fixes a coverity issue and adds the missing doc for the new sm3sum command... I got no further comments... may I ask, if it could be applied?

Apologies, Tom was expecting me to send an PR and I missed that. I'll send one today

Cheers
/Ilias

Quoted 135 lines

Thanks!

bye,
Heiko

Quoted 112 lines · Heiko Schocher

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.

rebased series to
commit 6b2d05748cf ("Merge tag 'u-boot-imx-master-20260117' of https://gitlab.denx.de/u-boot/custodians/u-boot-imx")

Azure build:
https://dev.azure.com/hs0298/hs/_build/results?buildId=205&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

Changes in v2:
rebased series to
commit 6b2d05748cf ("Merge tag 'u-boot-imx-master-20260117' of https://gitlab.denx.de/u-boot/custodians/u-boot-imx")
added Acked-by from Ilias
Added comments from Quentin
- fixed typo in commit subject
- fixed a lot of style and spelling issues
- added in parameters section the format of the input values
- removed section "Return value"

Quoted 9 lines

Heiko Schocher (2):
lib: sm3: fix coverity error
doc: cmd: add documentation for sm3sum

  doc/usage/cmd/sm3sum.rst | 112 +++++++++++++++++++++++++++++++++++++++
  lib/sm3.c                |   2 +-
  2 files changed, 113 insertions(+), 1 deletion(-)

create mode 100644 doc/usage/cmd/sm3sum.rst

--
Nabla Software Engineering
HRB 40522 Augsburg
Phone: +49 821 45592596
E-Mail: [email protected]
Geschäftsführer : Stefano Babic