From d735ed95c88c2e2acc532ac2008e1f4522e2329e Mon Sep 17 00:00:00 2001 From: orignal Date: Wed, 20 Dec 2017 13:25:33 -0500 Subject: [PATCH] correct hash for gost --- pattern.c | 9 +++++++-- util.c | 19 ++++++++++++------- util.h | 2 +- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/pattern.c b/pattern.c index 5eb67b4..2765678 100644 --- a/pattern.c +++ b/pattern.c @@ -1766,8 +1766,13 @@ vg_regex_test(vg_exec_context_t *vxcp) BN_init(&bnrem); /* Hash the hash and write the four byte check code */ - SHA256(vxcp->vxc_binres, 21, hash1); - SHA256(hash1, sizeof(hash1), hash2); + if (vxcp->vxc_vc->vc_pubkeytype == 38) // gostcoin + gostd_hash (hash2, vxcp->vxc_binres, 21); + else + { + SHA256(vxcp->vxc_binres, 21, hash1); + SHA256(hash1, sizeof(hash1), hash2); + } memcpy(&vxcp->vxc_binres[21], hash2, 4); bn = &vxcp->vxc_bntmp; diff --git a/util.c b/util.c index 397ea66..7df8e7e 100644 --- a/util.c +++ b/util.c @@ -125,12 +125,12 @@ vg_b58_encode_check(void *buf, size_t len, char *result, int gost) memcpy(binres, buf, len); if (gost) + gostd_hash (hash2, binres, len); + else { SHA256(binres, len, hash1); SHA256(hash1, sizeof(hash1), hash2); } - else - gostd_hash (hash2, binres, len); memcpy(&binres[len], hash2, 4); BN_bin2bn(binres, len + 4, bn); @@ -166,7 +166,7 @@ vg_b58_encode_check(void *buf, size_t len, char *result, int gost) (((c) == '\r') || ((c) == '\n') || ((c) == ' ') || ((c) == '\t')) int -vg_b58_decode_check(const char *input, void *buf, size_t len) +vg_b58_decode_check(const char *input, void *buf, size_t len, int gost) { int i, l, c; unsigned char *xbuf = NULL; @@ -218,8 +218,13 @@ vg_b58_decode_check(const char *input, void *buf, size_t len) /* Check the hash code */ l -= 4; - SHA256(xbuf, l, hash1); - SHA256(hash1, sizeof(hash1), hash2); + if (gost) + gostd_hash (hash2, xbuf, l); + else + { + SHA256(xbuf, l, hash1); + SHA256(hash1, sizeof(hash1), hash2); + } if (memcmp(hash2, xbuf + l, 4)) goto out; @@ -353,7 +358,7 @@ vg_decode_privkey(const char *b58encoded, EC_KEY *pkey, int *addrtype) unsigned char ecpriv[48]; int res; - res = vg_b58_decode_check(b58encoded, ecpriv, sizeof(ecpriv)); + res = vg_b58_decode_check(b58encoded, ecpriv, sizeof(ecpriv), 0); if (res != 33) return 0; @@ -717,7 +722,7 @@ vg_protect_decode_privkey(EC_KEY *pkey, int *keytype, int restype; int res; - res = vg_b58_decode_check(encoded, ecenc, sizeof(ecenc)); + res = vg_b58_decode_check(encoded, ecenc, sizeof(ecenc), 0); if ((res < 2) || (res > sizeof(ecenc))) return 0; diff --git a/util.h b/util.h index aeb7d58..cc85246 100644 --- a/util.h +++ b/util.h @@ -34,7 +34,7 @@ extern void dumphex(const unsigned char *src, size_t len); extern void dumpbn(const BIGNUM *bn); extern void vg_b58_encode_check(void *buf, size_t len, char *result, int gost); -extern int vg_b58_decode_check(const char *input, void *buf, size_t len); +extern int vg_b58_decode_check(const char *input, void *buf, size_t len, int gost); extern void vg_encode_address(const EC_POINT *ppoint, const EC_GROUP *pgroup, int addrtype, char *result);