e = BN_bin2bn(dgst, dgstlen, NULL);
if (e == NULL) {
- SM2err(SM2_F_SM2_INTERNAL_SIGN, ERR_R_BN_LIB);
+ SM2err(0, ERR_R_BN_LIB);
goto done;
}
s = sm2_sig_gen(eckey, e);
if (s == NULL) {
- SM2err(SM2_F_SM2_INTERNAL_SIGN, ERR_R_INTERNAL_ERROR);
+ SM2err(0, ERR_R_INTERNAL_ERROR);
goto done;
}
sigleni = i2d_ECDSA_SIG(s, &sig);
if (sigleni < 0) {
- SM2err(SM2_F_SM2_INTERNAL_SIGN, ERR_R_INTERNAL_ERROR);
+ SM2err(0, ERR_R_INTERNAL_ERROR);
goto done;
}
*siglen = (unsigned int)sigleni;
s = ECDSA_SIG_new();
if (s == NULL) {
- SM2err(SM2_F_SM2_INTERNAL_VERIFY, ERR_R_MALLOC_FAILURE);
+ SM2err(0, ERR_R_MALLOC_FAILURE);
goto done;
}
if (d2i_ECDSA_SIG(&s, &p, sig_len) == NULL) {
- SM2err(SM2_F_SM2_INTERNAL_VERIFY, SM2_R_INVALID_ENCODING);
+ SM2err(0, SM2_R_INVALID_ENCODING);
goto done;
}
/* Ensure signature uses DER and doesn't have trailing garbage */
derlen = i2d_ECDSA_SIG(s, &der);
if (derlen != sig_len || memcmp(sig, der, derlen) != 0) {
- SM2err(SM2_F_SM2_INTERNAL_VERIFY, SM2_R_INVALID_ENCODING);
+ SM2err(0, SM2_R_INVALID_ENCODING);
goto done;
}
e = BN_bin2bn(dgst, dgstlen, NULL);
if (e == NULL) {
- SM2err(SM2_F_SM2_INTERNAL_VERIFY, ERR_R_BN_LIB);
+ SM2err(0, ERR_R_BN_LIB);
goto done;
}
{
return DER_w_begin_sequence(pkt, cont)
/* No parameters (yet?) */
- /* It seems SM2 identifier is the same to id_ecPublidKey */
+ /* It seems SM2 identifier is the same as id_ecPublidKey */
&& DER_w_precompiled(pkt, -1, der_oid_id_ecPublicKey,
sizeof(der_oid_id_ecPublicKey))
&& DER_w_end_sequence(pkt, cont);
size_t id_len;
} PROV_SM2_CTX;
-/* TODO: it seems SM2 doesn't need this */
-static int sm2sig_get_md_nid(const EVP_MD *md)
-{
- /*
- * Because the EC library deals with NIDs, we need to translate.
- * We do so using EVP_MD_is_a(), and therefore need a name to NID
- * map.
- */
- static const OSSL_ITEM name_to_nid[] = {
- { NID_sm3, OSSL_DIGEST_NAME_SM3 },
- };
- size_t i;
- int mdnid = NID_undef;
-
- if (md == NULL)
- goto end;
-
- for (i = 0; i < OSSL_NELEM(name_to_nid); i++) {
- if (EVP_MD_is_a(md, name_to_nid[i].ptr)) {
- mdnid = (int)name_to_nid[i].id;
- break;
- }
- }
-
- if (mdnid == NID_undef)
- ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_DIGEST);
-
- end:
- return mdnid;
-}
-
static void *sm2sig_newctx(void *provctx, const char *propq)
{
PROV_SM2_CTX *ctx = OPENSSL_zalloc(sizeof(PROV_SM2_CTX));
void *ec)
{
PROV_SM2_CTX *ctx = (PROV_SM2_CTX *)vpsm2ctx;
- int md_nid = NID_undef;
+ int md_nid = NID_sm3;
WPACKET pkt;
int ret = 0;
return ret;
ctx->md = EVP_MD_fetch(ctx->libctx, mdname, ctx->propq);
- if ((md_nid = sm2sig_get_md_nid(ctx->md)) == NID_undef)
- goto error;
-
ctx->mdsize = EVP_MD_size(ctx->md);
ctx->mdctx = EVP_MD_CTX_new();
if (ctx->mdctx == NULL)