X-Git-Url: http://wagner.pp.ru/gitweb/?a=blobdiff_plain;f=gost_ec_sign.c;h=ba12783959e36ec31b1ea1c98da1678c78ed30df;hb=d370b91c2fa5a5e81ce7a3ab710349f14dd9ed9e;hp=e1cfbf5d32b4a4199f93ce1f4bbd5b3ad02eb264;hpb=12be7c21781eba9f7a37762e7e307571225c6c47;p=openssl-gost%2Fengine.git diff --git a/gost_ec_sign.c b/gost_ec_sign.c index e1cfbf5..ba12783 100644 --- a/gost_ec_sign.c +++ b/gost_ec_sign.c @@ -16,7 +16,7 @@ extern void dump_signature(const char *message, const unsigned char *buffer, size_t len); -void dump_dsa_sig(const char *message, DSA_SIG *sig); +void dump_dsa_sig(const char *message, ECDSA_SIG *sig); #else # define dump_signature(a,b,c) @@ -42,6 +42,18 @@ static R3410_ec_params *gost_nid2params(int nid) { R3410_ec_params *params; + /* Map tc26-2012 256-bit parameters to cp-2001 parameters */ + switch (nid) { + case NID_id_tc26_gost_3410_2012_256_paramSetB: + nid = NID_id_GostR3410_2001_CryptoPro_A_ParamSet; + break; + case NID_id_tc26_gost_3410_2012_256_paramSetC: + nid = NID_id_GostR3410_2001_CryptoPro_B_ParamSet; + break; + case NID_id_tc26_gost_3410_2012_256_paramSetD: + nid = NID_id_GostR3410_2001_CryptoPro_C_ParamSet; + } + /* Search nid in 2012 paramset */ params = R3410_2012_512_paramset; while (params->nid != NID_undef) { @@ -124,7 +136,7 @@ int fill_GOST_EC_params(EC_KEY *eckey, int nid) if (!BN_hex2bn(&x, params->x) || !BN_hex2bn(&y, params->y) - || !EC_POINT_set_affine_coordinates_GFp(grp, P, x, y, ctx) + || !EC_POINT_set_affine_coordinates(grp, P, x, y, ctx) || !BN_hex2bn(&q, params->q)) { GOSTerr(GOST_F_FILL_GOST_EC_PARAMS, ERR_R_INTERNAL_ERROR); goto end; @@ -151,12 +163,12 @@ int fill_GOST_EC_params(EC_KEY *eckey, int nid) } /* - * Computes gost_ec signature as DSA_SIG structure + * Computes gost_ec signature as ECDSA_SIG structure * */ -DSA_SIG *gost_ec_sign(const unsigned char *dgst, int dlen, EC_KEY *eckey) +ECDSA_SIG *gost_ec_sign(const unsigned char *dgst, int dlen, EC_KEY *eckey) { - DSA_SIG *newsig = NULL, *ret = NULL; + ECDSA_SIG *newsig = NULL, *ret = NULL; BIGNUM *md = NULL; BIGNUM *order = NULL; const EC_GROUP *group; @@ -179,7 +191,7 @@ DSA_SIG *gost_ec_sign(const unsigned char *dgst, int dlen, EC_KEY *eckey) BN_CTX_start(ctx); OPENSSL_assert(dlen == 32 || dlen == 64); md = hashsum2bn(dgst, dlen); - newsig = DSA_SIG_new(); + newsig = ECDSA_SIG_new(); if (!newsig || !md) { GOSTerr(GOST_F_GOST_EC_SIGN, ERR_R_MALLOC_FAILURE); goto err; @@ -247,7 +259,7 @@ DSA_SIG *gost_ec_sign(const unsigned char *dgst, int dlen, EC_KEY *eckey) GOSTerr(GOST_F_GOST_EC_SIGN, ERR_R_MALLOC_FAILURE); goto err; } - if (!EC_POINT_get_affine_coordinates_GFp(group, C, X, NULL, ctx)) { + if (!EC_POINT_get_affine_coordinates(group, C, X, NULL, ctx)) { GOSTerr(GOST_F_GOST_EC_SIGN, ERR_R_EC_LIB); goto err; } @@ -285,7 +297,7 @@ DSA_SIG *gost_ec_sign(const unsigned char *dgst, int dlen, EC_KEY *eckey) GOSTerr(GOST_F_GOST_EC_SIGN, ERR_R_MALLOC_FAILURE); goto err; } - DSA_SIG_set0(newsig, new_r, new_s); + ECDSA_SIG_set0(newsig, new_r, new_s); ret = newsig; err: @@ -296,7 +308,7 @@ DSA_SIG *gost_ec_sign(const unsigned char *dgst, int dlen, EC_KEY *eckey) if (md) BN_free(md); if (!ret && newsig) { - DSA_SIG_free(newsig); + ECDSA_SIG_free(newsig); } return ret; } @@ -306,7 +318,7 @@ DSA_SIG *gost_ec_sign(const unsigned char *dgst, int dlen, EC_KEY *eckey) * */ int gost_ec_verify(const unsigned char *dgst, int dgst_len, - DSA_SIG *sig, EC_KEY *ec) + ECDSA_SIG *sig, EC_KEY *ec) { BN_CTX *ctx; const EC_GROUP *group = (ec) ? EC_KEY_get0_group(ec) : NULL; @@ -345,7 +357,7 @@ int gost_ec_verify(const unsigned char *dgst, int dgst_len, goto err; } - DSA_SIG_get0(sig, &sig_r, &sig_s); + ECDSA_SIG_get0(sig, &sig_r, &sig_s); if (BN_is_zero(sig_s) || BN_is_zero(sig_r) || (BN_cmp(sig_s, order) >= 1) || (BN_cmp(sig_r, order) >= 1)) { @@ -394,7 +406,7 @@ int gost_ec_verify(const unsigned char *dgst, int dgst_len, GOSTerr(GOST_F_GOST_EC_VERIFY, ERR_R_EC_LIB); goto err; } - if (!EC_POINT_get_affine_coordinates_GFp(group, C, X, NULL, ctx)) { + if (!EC_POINT_get_affine_coordinates(group, C, X, NULL, ctx)) { GOSTerr(GOST_F_GOST_EC_VERIFY, ERR_R_EC_LIB); goto err; }