Add support for SM3 hash algorithm though the PSA crypto hash APIs #874

Open
opened 2026-08-26 03:32:40 -05:00 by ronald-cron-arm · 0 comments
ronald-cron-arm commented 2026-08-26 03:32:40 -05:00 (Migrated from github.com)

Description

Add support for SM3, as specified by GB/T 32905-2016, through the PSA crypto hash APIs. This enables applications using Chinese cryptographic standards and provides the hash primitive needed by protocols such as SM2. Most convenient reference document in English: https://datatracker.ietf.org/doc/html/draft-sca-cfrg-sm3-01.

Scope

  • Define PSA_ALG_SM3, its output size, block size, and configuration option PSA_WANT_ALG_SM3.
  • Implement the PSA crypto driver hash interface, mainly:
    • tf_psa_crypto_sm3_setup()
    • tf_psa_crypto_sm3_update()
    • tf_psa_crypto_sm3_finish()
      The implementation is based on https://github.com/Mbed-TLS/mbedtls/pull/4492 and the contribution should be acknowledged by merging sm3.c and sm3.h as in the PR before to remove them and implement the PSA crypto driver oriented one.
  • Add support for SM3 in the built-in PSA hash driver psa_crypto_hash.c
  • Add SM3 to relevant build and test configurations.

Testing

  • Update the test framework as required.
  • Self-test: at least the two GB/T 32905-2016 test vectors (enough?)
  • Validate in test_suite_psa_crypto_hash with hash_finish, hash_verify and hash_multipart unit tests similarly to the other hashes.
  • In test_suite_psa_crypto, add "PSA hash setup/compute: good, SM3" test cases as present for example for SHA-512 algorithm.
  • In test_suite_psa_crypto_metadata, add a "Hash: SM3" test case similar to the ones for the other hash algorithms.
  • Update crypto-config-symmetric-only.h
  • Update the test configurations related to driver dispatch testing:
    • tests/configs/crypto_config_test_driver_extension.h (for libtestdriver1 build in Mbed TLS)
    • tests/configs/user-config-accel-hash.h
    • tests/configs/user-config-test-driver-extension.h
  • Update the all.sh component test_accel_hash

Out of scope

  • Integration with the legacy mbedtls_md interface.
  • Composition into HMAC, key derivation, RSA/ECDSA signatures.

Acceptance criteria

  • SM3 is usable through the PSA hash APIs when PSA_WANT_ALG_SM3 is enabled.
  • All SM3 test vectors and boundary tests pass.
  • Existing test suites remain unaffected.
### Description Add support for SM3, as specified by GB/T 32905-2016, through the PSA crypto hash APIs. This enables applications using Chinese cryptographic standards and provides the hash primitive needed by protocols such as SM2. Most convenient reference document in English: https://datatracker.ietf.org/doc/html/draft-sca-cfrg-sm3-01. ### Scope - Define `PSA_ALG_SM3`, its output size, block size, and configuration option `PSA_WANT_ALG_SM3`. - Implement the PSA crypto driver hash interface, mainly: - `tf_psa_crypto_sm3_setup()` - `tf_psa_crypto_sm3_update()` - `tf_psa_crypto_sm3_finish()` The implementation is based on `https://github.com/Mbed-TLS/mbedtls/pull/4492` and the contribution should be acknowledged by merging `sm3.c` and `sm3.h` as in the PR before to remove them and implement the PSA crypto driver oriented one. - Add support for SM3 in the built-in PSA hash driver `psa_crypto_hash.c` - Add SM3 to relevant build and test configurations. ### Testing - Update the test framework as required. - Self-test: at least the two GB/T 32905-2016 test vectors (enough?) - Validate in `test_suite_psa_crypto_hash` with hash_finish, hash_verify and hash_multipart unit tests similarly to the other hashes. - Use test vectors from GB/T 32905-2016 and GB/T 32918 as summarized in https://datatracker.ietf.org/doc/html/draft-sca-cfrg-sm3-01. - Empty and single-byte messages - Padding boundaries: 55, 56 and 57 bytes - Block boundaries: 63, 64 and 65 bytes - Multiple-block boundaries: 127, 128 and 129 bytes - In `test_suite_psa_crypto`, add "PSA hash setup/compute: good, SM3" test cases as present for example for SHA-512 algorithm. - In `test_suite_psa_crypto_metadata`, add a "Hash: SM3" test case similar to the ones for the other hash algorithms. - Update `crypto-config-symmetric-only.h` - Update the test configurations related to driver dispatch testing: - `tests/configs/crypto_config_test_driver_extension.h` (for libtestdriver1 build in Mbed TLS) - `tests/configs/user-config-accel-hash.h` - `tests/configs/user-config-test-driver-extension.h` - Update the all.sh component `test_accel_hash` ### Out of scope - Integration with the legacy mbedtls_md interface. - Composition into HMAC, key derivation, RSA/ECDSA signatures. ### Acceptance criteria - SM3 is usable through the PSA hash APIs when PSA_WANT_ALG_SM3 is enabled. - All SM3 test vectors and boundary tests pass. - Existing test suites remain unaffected.
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-Mbed-TLS/TF-PSA-Crypto#874
No description provided.