add Litecoin address and compressed address support
This commit is contained in:
44
util.c
44
util.c
@@ -259,6 +259,30 @@ vg_encode_address(const EC_POINT *ppoint, const EC_GROUP *pgroup,
|
||||
vg_b58_encode_check(binres, sizeof(binres), result);
|
||||
}
|
||||
|
||||
void
|
||||
vg_encode_address_compressed(const EC_POINT *ppoint, const EC_GROUP *pgroup,
|
||||
int addrtype, char *result)
|
||||
{
|
||||
unsigned char eckey_buf[128], *pend;
|
||||
unsigned char binres[21] = {0,};
|
||||
unsigned char hash1[32];
|
||||
|
||||
pend = eckey_buf;
|
||||
|
||||
EC_POINT_point2oct(pgroup,
|
||||
ppoint,
|
||||
POINT_CONVERSION_COMPRESSED,
|
||||
eckey_buf,
|
||||
sizeof(eckey_buf),
|
||||
NULL);
|
||||
pend = eckey_buf + 0x21;
|
||||
binres[0] = addrtype;
|
||||
SHA256(eckey_buf, pend - eckey_buf, hash1);
|
||||
RIPEMD160(hash1, sizeof(hash1), &binres[1]);
|
||||
|
||||
vg_b58_encode_check(binres, sizeof(binres), result);
|
||||
}
|
||||
|
||||
void
|
||||
vg_encode_script_address(const EC_POINT *ppoint, const EC_GROUP *pgroup,
|
||||
int addrtype, char *result)
|
||||
@@ -306,6 +330,26 @@ vg_encode_privkey(const EC_KEY *pkey, int addrtype, char *result)
|
||||
vg_b58_encode_check(eckey_buf, 33, result);
|
||||
}
|
||||
|
||||
void
|
||||
vg_encode_privkey_compressed(const EC_KEY *pkey, int addrtype, char *result)
|
||||
{
|
||||
unsigned char eckey_buf[128];
|
||||
const BIGNUM *bn;
|
||||
int nbytes;
|
||||
|
||||
bn = EC_KEY_get0_private_key(pkey);
|
||||
|
||||
eckey_buf[0] = addrtype;
|
||||
nbytes = BN_num_bytes(bn);
|
||||
assert(nbytes <= 32);
|
||||
if (nbytes < 32)
|
||||
memset(eckey_buf + 1, 0, 32 - nbytes);
|
||||
BN_bn2bin(bn, &eckey_buf[33 - nbytes]);
|
||||
eckey_buf[nbytes+1] = 1;
|
||||
|
||||
vg_b58_encode_check(eckey_buf, 34, result);
|
||||
}
|
||||
|
||||
int
|
||||
vg_set_privkey(const BIGNUM *bnpriv, EC_KEY *pkey)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user