X-Git-Url: http://wagner.pp.ru/gitweb/?a=blobdiff_plain;f=gost_ec_sign.c;h=c3e1e016e84bc85ca38b243cea034507fb0fc958;hb=286a33984c698f2efa98dd06995c7d734569409c;hp=38c50ac8cd668f0a7ddaebb3c3fccd36e696bb64;hpb=cba16944bff9d8c5dcf37be641822cd3de6d2ec1;p=openssl-gost%2Fengine.git diff --git a/gost_ec_sign.c b/gost_ec_sign.c index 38c50ac..c3e1e01 100644 --- a/gost_ec_sign.c +++ b/gost_ec_sign.c @@ -7,7 +7,6 @@ * Requires OpenSSL 1.0.0+ for compilation * **********************************************************************/ #include "gost_lcl.h" -#include "gost_params.h" #include #include #include @@ -24,6 +23,21 @@ void dump_dsa_sig(const char *message, DSA_SIG *sig); # define dump_dsa_sig(a,b) #endif +/* Convert little-endian byte array into bignum */ +BIGNUM *hashsum2bn(const unsigned char *dgst, int len) +{ + unsigned char buf[64]; + int i; + + if (len > sizeof(buf)) + return NULL; + + for (i = 0; i < len; i++) { + buf[len - i - 1] = dgst[i]; + } + return BN_bin2bn(buf, len, NULL); +} + static R3410_ec_params *gost_nid2params(int nid) { R3410_ec_params *params; @@ -123,7 +137,7 @@ int fill_GOST_EC_params(EC_KEY *eckey, int nid) goto end; } ok = 1; -end: + end: if (P) EC_POINT_free(P); if (grp) @@ -161,7 +175,7 @@ DSA_SIG *gost_ec_sign(const unsigned char *dgst, int dlen, EC_KEY *eckey) md = hashsum2bn(dgst, dlen); newsig = DSA_SIG_new(); if (!newsig || !md) { - GOSTerr(GOST_F_GOST_EC_SIGN, GOST_R_NO_MEMORY); + GOSTerr(GOST_F_GOST_EC_SIGN, ERR_R_MALLOC_FAILURE); goto err; } group = EC_KEY_get0_group(eckey); @@ -204,8 +218,7 @@ DSA_SIG *gost_ec_sign(const unsigned char *dgst, int dlen, EC_KEY *eckey) do { do { if (!BN_rand_range(k, order)) { - GOSTerr(GOST_F_GOST_EC_SIGN, - GOST_R_RANDOM_NUMBER_GENERATOR_FAILED); + GOSTerr(GOST_F_GOST_EC_SIGN, GOST_R_RNG_ERROR); goto err; } /* @@ -301,7 +314,7 @@ int gost_ec_verify(const unsigned char *dgst, int dgst_len, OPENSSL_assert(dgst != NULL && sig != NULL && group != NULL); if (!(ctx = BN_CTX_new())) { - GOSTerr(GOST_F_GOST_EC_VERIFY, GOST_R_NO_MEMORY); + GOSTerr(GOST_F_GOST_EC_VERIFY, ERR_R_MALLOC_FAILURE); return 0; } @@ -349,8 +362,7 @@ int gost_ec_verify(const unsigned char *dgst, int dgst_len, goto err; } v = BN_mod_inverse(v, e, order, ctx); - if (!v - || !BN_mod_mul(z1, sig->s, v, order, ctx) + if (!v || !BN_mod_mul(z1, sig->s, v, order, ctx) || !BN_sub(tmp, order, sig->r) || !BN_mod_mul(z2, tmp, v, order, ctx)) { GOSTerr(GOST_F_GOST_EC_VERIFY, ERR_R_INTERNAL_ERROR); @@ -488,8 +500,7 @@ int gost_ec_keygen(EC_KEY *ec) do { if (!BN_rand_range(d, order)) { - GOSTerr(GOST_F_GOST_EC_KEYGEN, - GOST_R_RANDOM_NUMBER_GENERATOR_FAILED); + GOSTerr(GOST_F_GOST_EC_KEYGEN, GOST_R_RNG_ERROR); goto end; } } @@ -501,11 +512,11 @@ int gost_ec_keygen(EC_KEY *ec) } ok = 1; -end: + end: if (d) BN_free(d); if (order) BN_free(order); - + return (ok) ? gost_ec_compute_public(ec) : 0; }