Browse Source

correct hash for gost

master
orignal 7 years ago
parent
commit
d735ed95c8
  1. 9
      pattern.c
  2. 19
      util.c
  3. 2
      util.h

9
pattern.c

@ -1766,8 +1766,13 @@ vg_regex_test(vg_exec_context_t *vxcp)
BN_init(&bnrem); BN_init(&bnrem);
/* Hash the hash and write the four byte check code */ /* Hash the hash and write the four byte check code */
SHA256(vxcp->vxc_binres, 21, hash1); if (vxcp->vxc_vc->vc_pubkeytype == 38) // gostcoin
SHA256(hash1, sizeof(hash1), hash2); 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); memcpy(&vxcp->vxc_binres[21], hash2, 4);
bn = &vxcp->vxc_bntmp; bn = &vxcp->vxc_bntmp;

19
util.c

@ -125,12 +125,12 @@ vg_b58_encode_check(void *buf, size_t len, char *result, int gost)
memcpy(binres, buf, len); memcpy(binres, buf, len);
if (gost) if (gost)
gostd_hash (hash2, binres, len);
else
{ {
SHA256(binres, len, hash1); SHA256(binres, len, hash1);
SHA256(hash1, sizeof(hash1), hash2); SHA256(hash1, sizeof(hash1), hash2);
} }
else
gostd_hash (hash2, binres, len);
memcpy(&binres[len], hash2, 4); memcpy(&binres[len], hash2, 4);
BN_bin2bn(binres, len + 4, bn); 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')) (((c) == '\r') || ((c) == '\n') || ((c) == ' ') || ((c) == '\t'))
int 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; int i, l, c;
unsigned char *xbuf = NULL; unsigned char *xbuf = NULL;
@ -218,8 +218,13 @@ vg_b58_decode_check(const char *input, void *buf, size_t len)
/* Check the hash code */ /* Check the hash code */
l -= 4; l -= 4;
SHA256(xbuf, l, hash1); if (gost)
SHA256(hash1, sizeof(hash1), hash2); gostd_hash (hash2, xbuf, l);
else
{
SHA256(xbuf, l, hash1);
SHA256(hash1, sizeof(hash1), hash2);
}
if (memcmp(hash2, xbuf + l, 4)) if (memcmp(hash2, xbuf + l, 4))
goto out; goto out;
@ -353,7 +358,7 @@ vg_decode_privkey(const char *b58encoded, EC_KEY *pkey, int *addrtype)
unsigned char ecpriv[48]; unsigned char ecpriv[48];
int res; int res;
res = vg_b58_decode_check(b58encoded, ecpriv, sizeof(ecpriv)); res = vg_b58_decode_check(b58encoded, ecpriv, sizeof(ecpriv), 0);
if (res != 33) if (res != 33)
return 0; return 0;
@ -717,7 +722,7 @@ vg_protect_decode_privkey(EC_KEY *pkey, int *keytype,
int restype; int restype;
int res; 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))) if ((res < 2) || (res > sizeof(ecenc)))
return 0; return 0;

2
util.h

@ -34,7 +34,7 @@ extern void dumphex(const unsigned char *src, size_t len);
extern void dumpbn(const BIGNUM *bn); extern void dumpbn(const BIGNUM *bn);
extern void vg_b58_encode_check(void *buf, size_t len, char *result, int gost); 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, extern void vg_encode_address(const EC_POINT *ppoint, const EC_GROUP *pgroup,
int addrtype, char *result); int addrtype, char *result);

Loading…
Cancel
Save