Support setting SM2 ID zero-length ID is allowed, but it's not allowed to skip the ID. Fixes: #6534 Reviewed-by: Tim Hudson <tjh@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/7113)
diff --git a/crypto/include/internal/evp_int.h b/crypto/include/internal/evp_int.h index 3264b3d..d86aed3 100644 --- a/crypto/include/internal/evp_int.h +++ b/crypto/include/internal/evp_int.h
@@ -10,6 +10,12 @@ #include <openssl/evp.h> #include "internal/refcount.h" +/* + * Don't free up md_ctx->pctx in EVP_MD_CTX_reset, use the reserved flag + * values in evp.h + */ +#define EVP_MD_CTX_FLAG_KEEP_PKEY_CTX 0x0400 + struct evp_pkey_ctx_st { /* Method associated with this operation */ const EVP_PKEY_METHOD *pmeth;
diff --git a/crypto/include/internal/sm2.h b/crypto/include/internal/sm2.h index 26a9066..5c5cd4b 100644 --- a/crypto/include/internal/sm2.h +++ b/crypto/include/internal/sm2.h
@@ -20,15 +20,14 @@ /* The default user id as specified in GM/T 0009-2012 */ # define SM2_DEFAULT_USERID "1234567812345678" -int sm2_compute_userid_digest(uint8_t *out, - const EVP_MD *digest, - const uint8_t *id, - const size_t id_len, - const EC_KEY *key); +int sm2_compute_z_digest(uint8_t *out, + const EVP_MD *digest, + const uint8_t *id, + const size_t id_len, + const EC_KEY *key); /* - * SM2 signature operation. Computes ZA (user id digest) and then signs - * H(ZA || msg) using SM2 + * SM2 signature operation. Computes Z and then signs H(Z || msg) using SM2 */ ECDSA_SIG *sm2_do_sign(const EC_KEY *key, const EVP_MD *digest,
diff --git a/crypto/include/internal/sm2err.h b/crypto/include/internal/sm2err.h index 9a7e2b6..4b8536d 100644 --- a/crypto/include/internal/sm2err.h +++ b/crypto/include/internal/sm2err.h
@@ -28,7 +28,7 @@ # define SM2_F_PKEY_SM2_INIT 111 # define SM2_F_PKEY_SM2_SIGN 112 # define SM2_F_SM2_COMPUTE_MSG_HASH 100 -# define SM2_F_SM2_COMPUTE_USERID_DIGEST 101 +# define SM2_F_SM2_COMPUTE_Z_DIGEST 113 # define SM2_F_SM2_DECRYPT 102 # define SM2_F_SM2_ENCRYPT 103 # define SM2_F_SM2_PLAINTEXT_SIZE 104 @@ -43,13 +43,13 @@ # define SM2_R_ASN1_ERROR 100 # define SM2_R_BAD_SIGNATURE 101 # define SM2_R_BUFFER_TOO_SMALL 107 +# define SM2_R_ID_TOO_LARGE 111 # define SM2_R_INVALID_CURVE 108 # define SM2_R_INVALID_DIGEST 102 # define SM2_R_INVALID_DIGEST_TYPE 103 # define SM2_R_INVALID_ENCODING 104 # define SM2_R_INVALID_FIELD 105 # define SM2_R_NO_PARAMETERS_SET 109 -# define SM2_R_USER_ID_TOO_LARGE 106 # endif #endif