+static int pkey_sm2_digest_custom(EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx)
+{
+ uint8_t z[EVP_MAX_MD_SIZE];
+ SM2_PKEY_CTX *sctx = ctx->data;
+ EC_KEY *ec = ctx->pkey->pkey.ec;
+ const EVP_MD *md = EVP_MD_CTX_md(mctx);
+
+ if (sctx->id == NULL) {
+ /* XXX:
+ * currently we reject all null-ID for SM2, but this needs
+ * more considerations and discussion since the specifications
+ * on SM2 are not clear on null-ID
+ */
+ return 0;
+ }
+
+ /* get hashed prefix of tbs message */
+ if (!sm2_compute_userid_digest(z, md, sctx->id, sctx->id_len, ec))
+ return 0;
+
+ return EVP_DigestUpdate(mctx, z, EVP_MD_size(md));
+}
+