/*
* Copyright 2006-2018 The OpenSSL Project Authors. All Rights Reserved.
*
- * Licensed under the OpenSSL license (the "License"). You may not use
+ * Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
if (sctx->id != NULL) {
dctx->id = OPENSSL_malloc(sctx->id_len);
if (dctx->id == NULL) {
+ SM2err(SM2_F_PKEY_SM2_COPY, ERR_R_MALLOC_FAILURE);
pkey_sm2_cleanup(dst);
return 0;
}
case EVP_PKEY_CTRL_SET1_ID:
if (p1 > 0) {
tmp_id = OPENSSL_malloc(p1);
- if (tmp_id == NULL)
+ if (tmp_id == NULL) {
+ SM2err(SM2_F_PKEY_SM2_CTRL, ERR_R_MALLOC_FAILURE);
return 0;
+ }
memcpy(tmp_id, p2, p1);
OPENSSL_free(smctx->id);
smctx->id = tmp_id;
SM2_PKEY_CTX *smctx = ctx->data;
EC_KEY *ec = ctx->pkey->pkey.ec;
const EVP_MD *md = EVP_MD_CTX_md(mctx);
+ int mdlen = EVP_MD_size(md);
if (!smctx->id_set) {
/*
return 0;
}
+ if (mdlen < 0) {
+ SM2err(SM2_F_PKEY_SM2_DIGEST_CUSTOM, SM2_R_INVALID_DIGEST);
+ return 0;
+ }
+
/* get hashed prefix 'z' of tbs message */
if (!sm2_compute_z_digest(z, md, smctx->id, smctx->id_len, ec))
return 0;
- return EVP_DigestUpdate(mctx, z, EVP_MD_size(md));
+ return EVP_DigestUpdate(mctx, z, (size_t)mdlen);
}
const EVP_PKEY_METHOD sm2_pkey_meth = {