Skip to content

Commit

Permalink
Merge pull request #80 from nooperation/0.1.1-dev_sizet-consistency
Browse files Browse the repository at this point in the history
(API Change) Fixed the truncation of size_t's to int's in some places
  • Loading branch information
michilumin authored Oct 4, 2022
2 parents 3c367d5 + a86e155 commit d3399f8
Show file tree
Hide file tree
Showing 43 changed files with 137 additions and 138 deletions.
2 changes: 1 addition & 1 deletion include/dogecoin/address.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ LIBDOGECOIN_API int verifyPrivPubKeypair(char* wif_privkey, char* p2pkh_pubkey,
LIBDOGECOIN_API int verifyHDMasterPubKeypair(char* wif_privkey_master, char* p2pkh_pubkey_master, bool is_testnet);

/* verify address based on length and checksum */
LIBDOGECOIN_API int verifyP2pkhAddress(char* p2pkh_pubkey, uint8_t len);
LIBDOGECOIN_API int verifyP2pkhAddress(char* p2pkh_pubkey, size_t len);

/* generate an extended hd public/private child address */
LIBDOGECOIN_API int getDerivedHDAddress(const char* masterkey, uint32_t account, bool ischange, uint32_t addressindex, char* outaddress, bool outprivkey);
Expand Down
4 changes: 2 additions & 2 deletions include/dogecoin/aes.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@

LIBDOGECOIN_BEGIN_DECL

LIBDOGECOIN_API int aes256_cbc_encrypt(const unsigned char aes_key[32], const unsigned char iv[AES_BLOCK_SIZE], const unsigned char* data, int size, int pad, unsigned char* out);
LIBDOGECOIN_API int aes256_cbc_decrypt(const unsigned char aes_key[32], const unsigned char iv[AES_BLOCK_SIZE], const unsigned char* data, int size, int pad, unsigned char* out);
LIBDOGECOIN_API size_t aes256_cbc_encrypt(const unsigned char aes_key[32], const unsigned char iv[AES_BLOCK_SIZE], const unsigned char* data, size_t size, int pad, unsigned char* out);
LIBDOGECOIN_API size_t aes256_cbc_decrypt(const unsigned char aes_key[32], const unsigned char iv[AES_BLOCK_SIZE], const unsigned char* data, size_t size, int pad, unsigned char* out);

LIBDOGECOIN_END_DECL

Expand Down
8 changes: 4 additions & 4 deletions include/dogecoin/base58.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@

LIBDOGECOIN_BEGIN_DECL

LIBDOGECOIN_API int dogecoin_base58_encode_check(const uint8_t* data, int datalen, char* str, int strsize);
LIBDOGECOIN_API int dogecoin_base58_decode_check(const char* str, uint8_t* data, size_t datalen);
LIBDOGECOIN_API size_t dogecoin_base58_encode_check(const uint8_t* data, size_t datalen, char* str, size_t strsize);
LIBDOGECOIN_API size_t dogecoin_base58_decode_check(const char* str, uint8_t* data, size_t datalen);

LIBDOGECOIN_API int dogecoin_base58_encode(char* b58, size_t* b58sz, const void* data, size_t binsz);
LIBDOGECOIN_API int dogecoin_base58_decode(void* bin, size_t* binszp, const char* b58, size_t b58sz);

LIBDOGECOIN_API dogecoin_bool dogecoin_p2pkh_addr_from_hash160(const uint160 hashin, const dogecoin_chainparams* chain, char *addrout, int len);
LIBDOGECOIN_API dogecoin_bool dogecoin_p2sh_addr_from_hash160(const uint160 hashin, const dogecoin_chainparams* chain, char* addrout, int len);
LIBDOGECOIN_API dogecoin_bool dogecoin_p2pkh_addr_from_hash160(const uint160 hashin, const dogecoin_chainparams* chain, char* addrout, size_t len);
LIBDOGECOIN_API dogecoin_bool dogecoin_p2sh_addr_from_hash160(const uint160 hashin, const dogecoin_chainparams* chain, char* addrout, size_t len);

LIBDOGECOIN_END_DECL

Expand Down
6 changes: 3 additions & 3 deletions include/dogecoin/bip32.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ LIBDOGECOIN_API dogecoin_bool dogecoin_hdnode_public_ckd(dogecoin_hdnode* inout,
LIBDOGECOIN_API dogecoin_bool dogecoin_hdnode_from_seed(const uint8_t* seed, int seed_len, dogecoin_hdnode* out);
LIBDOGECOIN_API dogecoin_bool dogecoin_hdnode_private_ckd(dogecoin_hdnode* inout, uint32_t i);
LIBDOGECOIN_API void dogecoin_hdnode_fill_public_key(dogecoin_hdnode* node);
LIBDOGECOIN_API void dogecoin_hdnode_serialize_public(const dogecoin_hdnode* node, const dogecoin_chainparams* chain, char* str, int strsize);
LIBDOGECOIN_API void dogecoin_hdnode_serialize_private(const dogecoin_hdnode* node, const dogecoin_chainparams* chain, char* str, int strsize);
LIBDOGECOIN_API void dogecoin_hdnode_serialize_public(const dogecoin_hdnode* node, const dogecoin_chainparams* chain, char* str, size_t strsize);
LIBDOGECOIN_API void dogecoin_hdnode_serialize_private(const dogecoin_hdnode* node, const dogecoin_chainparams* chain, char* str, size_t strsize);

/* gives out the raw sha256/ripemd160 hash */
LIBDOGECOIN_API void dogecoin_hdnode_get_hash160(const dogecoin_hdnode* node, uint160 hash160_out);
LIBDOGECOIN_API void dogecoin_hdnode_get_p2pkh_address(const dogecoin_hdnode* node, const dogecoin_chainparams* chain, char* str, int strsize);
LIBDOGECOIN_API void dogecoin_hdnode_get_p2pkh_address(const dogecoin_hdnode* node, const dogecoin_chainparams* chain, char* str, size_t strsize);
LIBDOGECOIN_API dogecoin_bool dogecoin_hdnode_get_pub_hex(const dogecoin_hdnode* node, char* str, size_t* strsize);
LIBDOGECOIN_API dogecoin_bool dogecoin_hdnode_deserialize(const char* str, const dogecoin_chainparams* chain, dogecoin_hdnode* node);

Expand Down
2 changes: 1 addition & 1 deletion include/dogecoin/key.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ LIBDOGECOIN_API dogecoin_bool dogecoin_key_sign_hash_compact_recoverable(const d
LIBDOGECOIN_API dogecoin_bool dogecoin_key_sign_recover_pubkey(const unsigned char* sig, const uint256 hash, int recid, dogecoin_pubkey* pubkey);

//verifies a DER encoded signature with given pubkey and return true if valid
LIBDOGECOIN_API dogecoin_bool dogecoin_pubkey_verify_sig(const dogecoin_pubkey* pubkey, const uint256 hash, unsigned char* sigder, int len);
LIBDOGECOIN_API dogecoin_bool dogecoin_pubkey_verify_sig(const dogecoin_pubkey* pubkey, const uint256 hash, unsigned char* sigder, size_t len);

LIBDOGECOIN_API dogecoin_bool dogecoin_pubkey_getaddr_p2pkh(const dogecoin_pubkey* pubkey, const dogecoin_chainparams* chain, char* addrout);

Expand Down
2 changes: 1 addition & 1 deletion include/dogecoin/libdogecoin.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ int verifyPrivPubKeypair(char* wif_privkey, char* p2pkh_pubkey, bool is_testnet)
int verifyHDMasterPubKeypair(char* wif_privkey_master, char* p2pkh_pubkey_master, bool is_testnet);

/* verify that a dogecoin address is valid. */
int verifyP2pkhAddress(char* p2pkh_pubkey, uint8_t len);
int verifyP2pkhAddress(char* p2pkh_pubkey, size_t len);


/*transaction creation functions - builds a dogecoin transaction
Expand Down
2 changes: 1 addition & 1 deletion include/dogecoin/mem.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ LIBDOGECOIN_API void* dogecoin_realloc(void* ptr, size_t size);
LIBDOGECOIN_API void dogecoin_free(void* ptr);

LIBDOGECOIN_API errno_t memset_safe(volatile void *v, rsize_t smax, int c, rsize_t n);
LIBDOGECOIN_API void* memcpy_safe(void* destination, const void* source, unsigned int count);
LIBDOGECOIN_API void* memcpy_safe(void* destination, const void* source, size_t count);
LIBDOGECOIN_API volatile void* dogecoin_mem_zero(volatile void* dst, size_t len);

LIBDOGECOIN_API uint32_t* dogecoin_uint32_vla(size_t size);
Expand Down
2 changes: 1 addition & 1 deletion include/dogecoin/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ LIBDOGECOIN_API void dogecoin_node_connection_state_changed(dogecoin_node* node)
/* =================================== */

LIBDOGECOIN_API dogecoin_bool dogecoin_node_group_add_peers_by_ip_or_seed(dogecoin_node_group *group, const char *ips);
LIBDOGECOIN_API int dogecoin_get_peers_from_dns(const char* seed, vector* ips_out, int port, int family);
LIBDOGECOIN_API size_t dogecoin_get_peers_from_dns(const char* seed, vector* ips_out, int port, int family);

struct broadcast_ctx {
const dogecoin_tx* tx;
Expand Down
4 changes: 2 additions & 2 deletions include/dogecoin/sha2.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ LIBDOGECOIN_API void sha512_write(sha512_context*, const uint8_t*, size_t);
LIBDOGECOIN_API void sha512_finalize(sha512_context*, uint8_t[SHA512_DIGEST_LENGTH]);
LIBDOGECOIN_API void sha512_raw(const uint8_t*, size_t, uint8_t[SHA512_DIGEST_LENGTH]);

LIBDOGECOIN_API void hmac_sha256(const uint8_t* key, const uint32_t keylen, const uint8_t* msg, const uint32_t msglen, uint8_t* hmac);
LIBDOGECOIN_API void hmac_sha512(const uint8_t* key, const uint32_t keylen, const uint8_t* msg, const uint32_t msglen, uint8_t* hmac);
LIBDOGECOIN_API void hmac_sha256(const uint8_t* key, const size_t keylen, const uint8_t* msg, const size_t msglen, uint8_t* hmac);
LIBDOGECOIN_API void hmac_sha512(const uint8_t* key, const size_t keylen, const uint8_t* msg, const size_t msglen, uint8_t* hmac);

LIBDOGECOIN_END_DECL

Expand Down
4 changes: 2 additions & 2 deletions include/dogecoin/tx.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ LIBDOGECOIN_API void dogecoin_tx_serialize(cstring* s, const dogecoin_tx* tx);

LIBDOGECOIN_API void dogecoin_tx_hash(const dogecoin_tx* tx, uint256 hashout);

LIBDOGECOIN_API dogecoin_bool dogecoin_tx_sighash(const dogecoin_tx* tx_to, const cstring* fromPubKey, unsigned int in_num, int hashtype, uint256 hash);
LIBDOGECOIN_API dogecoin_bool dogecoin_tx_sighash(const dogecoin_tx* tx_to, const cstring* fromPubKey, size_t in_num, int hashtype, uint256 hash);

LIBDOGECOIN_API dogecoin_bool dogecoin_tx_add_address_out(dogecoin_tx* tx, const dogecoin_chainparams* chain, int64_t amount, const char* address);
LIBDOGECOIN_API dogecoin_bool dogecoin_tx_add_p2sh_hash160_out(dogecoin_tx* tx, int64_t amount, uint160 hash160);
Expand All @@ -125,7 +125,7 @@ enum dogecoin_tx_sign_result {
DOGECOIN_SIGN_OK = 1,
};
const char* dogecoin_tx_sign_result_to_str(const enum dogecoin_tx_sign_result result);
enum dogecoin_tx_sign_result dogecoin_tx_sign_input(dogecoin_tx* tx_in_out, const cstring* script, const dogecoin_key* privkey, int inputindex, int sighashtype, uint8_t* sigcompact_out, uint8_t* sigder_out, int* sigder_len);
enum dogecoin_tx_sign_result dogecoin_tx_sign_input(dogecoin_tx* tx_in_out, const cstring* script, const dogecoin_key* privkey, size_t inputindex, int sighashtype, uint8_t* sigcompact_out, uint8_t* sigder_out, size_t* sigder_len);

LIBDOGECOIN_END_DECL

Expand Down
6 changes: 3 additions & 3 deletions include/dogecoin/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@
LIBDOGECOIN_BEGIN_DECL

LIBDOGECOIN_API void utils_clear_buffers(void);
LIBDOGECOIN_API void utils_hex_to_bin(const char* str, unsigned char* out, int inLen, int* outLen);
LIBDOGECOIN_API void utils_hex_to_bin(const char* str, unsigned char* out, size_t inLen, size_t* outLen);
LIBDOGECOIN_API void utils_bin_to_hex(unsigned char* bin_in, size_t inlen, char* hex_out);
LIBDOGECOIN_API uint8_t* utils_hex_to_uint8(const char* str);
LIBDOGECOIN_API char* utils_uint8_to_hex(const uint8_t* bin, size_t l);
LIBDOGECOIN_API void utils_reverse_hex(char* h, int len);
LIBDOGECOIN_API void utils_reverse_hex(char* h, size_t len);
LIBDOGECOIN_API void utils_uint256_sethex(char* psz, uint8_t* out);
LIBDOGECOIN_API void* safe_malloc(size_t size);
LIBDOGECOIN_API void dogecoin_cheap_random_bytes(uint8_t* buf, uint32_t len);
LIBDOGECOIN_API void dogecoin_cheap_random_bytes(uint8_t* buf, size_t len);
LIBDOGECOIN_API void dogecoin_get_default_datadir(cstring* path_out);
LIBDOGECOIN_API void dogecoin_file_commit(FILE* file);
LIBDOGECOIN_API void print_image(FILE *fptr);
Expand Down
2 changes: 1 addition & 1 deletion src/address.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ int verifyHDMasterPubKeypair(char* wif_privkey_master, char* p2pkh_pubkey_master
*
* @return 1 if it is a valid Dogecoin address, 0 otherwise.
*/
int verifyP2pkhAddress(char* p2pkh_pubkey, uint8_t len)
int verifyP2pkhAddress(char* p2pkh_pubkey, size_t len)
{
if (!p2pkh_pubkey || !len) return false;
/* check length */
Expand Down
8 changes: 4 additions & 4 deletions src/aes.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
#include <dogecoin/ctaes.h>
#include <dogecoin/mem.h>

int aes256_cbc_encrypt(const unsigned char aes_key[32], const unsigned char iv[AES_BLOCK_SIZE], const unsigned char* data, int size, int pad, unsigned char* out)
size_t aes256_cbc_encrypt(const unsigned char aes_key[32], const unsigned char iv[AES_BLOCK_SIZE], const unsigned char* data, size_t size, int pad, unsigned char* out)
{
int written = 0;
size_t written = 0;
int padsize = size % AES_BLOCK_SIZE;
unsigned char mixed[AES_BLOCK_SIZE];

Expand Down Expand Up @@ -64,10 +64,10 @@ int aes256_cbc_encrypt(const unsigned char aes_key[32], const unsigned char iv[A
return written;
}

int aes256_cbc_decrypt(const unsigned char aes_key[32], const unsigned char iv[AES_BLOCK_SIZE], const unsigned char* data, int size, int pad, unsigned char* out)
size_t aes256_cbc_decrypt(const unsigned char aes_key[32], const unsigned char iv[AES_BLOCK_SIZE], const unsigned char* data, size_t size, int pad, unsigned char* out)
{
unsigned char padsize = 0;
int written = 0;
size_t written = 0;
int fail = 0;
const unsigned char* prev = iv;

Expand Down
12 changes: 6 additions & 6 deletions src/base58.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,9 @@ int dogecoin_base58_encode(char* b58, size_t* b58sz, const void* data, size_t bi
return true;
}

int dogecoin_base58_encode_check(const uint8_t* data, int datalen, char* str, int strsize)
size_t dogecoin_base58_encode_check(const uint8_t* data, size_t datalen, char* str, size_t strsize)
{
int ret;
size_t ret;
if (datalen > 128) {
return 0;
}
Expand All @@ -219,9 +219,9 @@ int dogecoin_base58_encode_check(const uint8_t* data, int datalen, char* str, in
return ret;
}

int dogecoin_base58_decode_check(const char* str, uint8_t* data, size_t datalen)
size_t dogecoin_base58_decode_check(const char* str, uint8_t* data, size_t datalen)
{
int ret, i;
size_t ret, i;
for (i = 0; str[i] && i < 1024; i++){};
size_t strl = i;
/* buffer needs to be at least the strsize, will be used
Expand All @@ -243,7 +243,7 @@ int dogecoin_base58_decode_check(const char* str, uint8_t* data, size_t datalen)
return ret;
}

dogecoin_bool dogecoin_p2pkh_addr_from_hash160(const uint160 hashin, const dogecoin_chainparams* chain, char *addrout, int len) {
dogecoin_bool dogecoin_p2pkh_addr_from_hash160(const uint160 hashin, const dogecoin_chainparams* chain, char *addrout, size_t len) {
uint8_t hash160[sizeof(uint160)+1];
hash160[0] = chain->b58prefix_pubkey_address;
memcpy_safe(hash160 + 1, hashin, sizeof(uint160));
Expand All @@ -252,7 +252,7 @@ dogecoin_bool dogecoin_p2pkh_addr_from_hash160(const uint160 hashin, const dogec
}

dogecoin_bool dogecoin_p2sh_addr_from_hash160(const uint160 hashin, const dogecoin_chainparams* chain, char* addrout,
int len)
size_t len)
{
uint8_t hash160[sizeof(uint160) + 1];
hash160[0] = chain->b58prefix_script_address;
Expand Down
8 changes: 4 additions & 4 deletions src/bip32.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ void dogecoin_hdnode_fill_public_key(dogecoin_hdnode* node)
*
* @return Nothing.
*/
static void dogecoin_hdnode_serialize(const dogecoin_hdnode* node, uint32_t version, char use_public, char* str, int strsize)
static void dogecoin_hdnode_serialize(const dogecoin_hdnode* node, uint32_t version, char use_public, char* str, size_t strsize)
{
uint8_t node_data[78];
write_be(node_data, version);
Expand Down Expand Up @@ -329,7 +329,7 @@ static void dogecoin_hdnode_serialize(const dogecoin_hdnode* node, uint32_t vers
*
* @return Nothing.
*/
void dogecoin_hdnode_serialize_public(const dogecoin_hdnode* node, const dogecoin_chainparams* chain, char* str, int strsize)
void dogecoin_hdnode_serialize_public(const dogecoin_hdnode* node, const dogecoin_chainparams* chain, char* str, size_t strsize)
{
dogecoin_hdnode_serialize(node, chain->b58prefix_bip32_pubkey, 1, str, strsize);
}
Expand All @@ -346,7 +346,7 @@ void dogecoin_hdnode_serialize_public(const dogecoin_hdnode* node, const dogecoi
*
* @return Nothing.
*/
void dogecoin_hdnode_serialize_private(const dogecoin_hdnode* node, const dogecoin_chainparams* chain, char* str, int strsize)
void dogecoin_hdnode_serialize_private(const dogecoin_hdnode* node, const dogecoin_chainparams* chain, char* str, size_t strsize)
{
dogecoin_hdnode_serialize(node, chain->b58prefix_bip32_privkey, 0, str, strsize);
}
Expand Down Expand Up @@ -382,7 +382,7 @@ void dogecoin_hdnode_get_hash160(const dogecoin_hdnode* node, uint160 hash160_ou
*
* @return Nothing.
*/
void dogecoin_hdnode_get_p2pkh_address(const dogecoin_hdnode* node, const dogecoin_chainparams* chain, char* str, int strsize)
void dogecoin_hdnode_get_p2pkh_address(const dogecoin_hdnode* node, const dogecoin_chainparams* chain, char* str, size_t strsize)
{
uint8_t hash160[sizeof(uint160) + 1];
hash160[0] = chain->b58prefix_pubkey_address;
Expand Down
2 changes: 1 addition & 1 deletion src/cli/sendtx.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ int main(int argc, char* argv[]) {
return showError("Transaction in invalid or to large.\n");
}
uint8_t* data_bin = dogecoin_malloc(strlen(data) / 2 + 1);
int outlen = 0;
size_t outlen = 0;
utils_hex_to_bin(data, data_bin, strlen(data), &outlen);

dogecoin_tx* tx = dogecoin_tx_new();
Expand Down
8 changes: 4 additions & 4 deletions src/cli/such.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void broadcasting_menu(int txindex, int is_testnet) {
printf("Transaction in invalid or to large.\n");
}
uint8_t* data_bin = dogecoin_malloc(strlen(raw_hexadecimal_tx) / 2 + 1);
int outlen = 0;
size_t outlen = 0;
utils_hex_to_bin(raw_hexadecimal_tx, data_bin, strlen(raw_hexadecimal_tx), &outlen);

/* Deserializing the transaction and broadcasting it to the network. */
Expand Down Expand Up @@ -851,7 +851,7 @@ int main(int argc, char* argv[])
//deserialize transaction
dogecoin_tx* tx = dogecoin_tx_new();
uint8_t* data_bin = dogecoin_malloc(strlen(txhex) / 2 + 1);
int outlen = 0;
size_t outlen = 0;
utils_hex_to_bin(txhex, data_bin, strlen(txhex), &outlen);
if (!dogecoin_tx_deserialize(data_bin, outlen, tx, NULL)) {
dogecoin_free(data_bin);
Expand Down Expand Up @@ -904,7 +904,7 @@ int main(int argc, char* argv[])
}
if (sign) {
uint8_t sigcompact[64] = { 0 };
int sigderlen = 74 + 1; //&hashtype
size_t sigderlen = 74 + 1; //&hashtype
uint8_t sigder_plus_hashtype[75] = { 0 };
enum dogecoin_tx_sign_result res = dogecoin_tx_sign_input(tx, script, &key, inputindex, sighashtype, sigcompact, sigder_plus_hashtype, &sigderlen);
cstr_free(script, true);
Expand Down Expand Up @@ -941,7 +941,7 @@ int main(int argc, char* argv[])
return showError("Missing signature or invalid length (use hex, 128 chars == 64 bytes)\n");
}

int outlen = 0;
size_t outlen = 0;
uint8_t sig_comp[65];
printf("%s\n", scripthex);
utils_hex_to_bin(scripthex, sig_comp, 128, &outlen);
Expand Down
2 changes: 1 addition & 1 deletion src/cli/tool.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ dogecoin_bool addresses_from_pubkey(const dogecoin_chainparams* chain, const cha
dogecoin_pubkey_init(&pubkey);
pubkey.compressed = 1;
size_t outlen = 0;
utils_hex_to_bin(pubkey_hex, pubkey.pubkey, strlen(pubkey_hex), (int*)&outlen);
utils_hex_to_bin(pubkey_hex, pubkey.pubkey, strlen(pubkey_hex), &outlen);
assert(dogecoin_pubkey_is_valid(&pubkey) == 1);
dogecoin_pubkey_getaddr_p2pkh(&pubkey, chain, p2pkh_address);
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/key.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ dogecoin_bool dogecoin_key_sign_recover_pubkey(const unsigned char* sig, const u
return 1;
}

dogecoin_bool dogecoin_pubkey_verify_sig(const dogecoin_pubkey* pubkey, const uint256 hash, unsigned char* sigder, int len)
dogecoin_bool dogecoin_pubkey_verify_sig(const dogecoin_pubkey* pubkey, const uint256 hash, unsigned char* sigder, size_t len)
{
return dogecoin_ecc_verify_sig(pubkey->pubkey, pubkey->compressed, hash, sigder, len);
}
Expand Down
10 changes: 5 additions & 5 deletions src/koinu.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const char* conversion_type_to_str(const enum conversion_type type)
}
}

int check_length(char* string) {
size_t check_length(char* string) {
// set max length for all string inputs to 20 to account for total supply in 2022
// (currently 132.67 billion dogecoin) + 1e8 koinu passing UINT64_MAX 184467440737
// in 9.854916426 years (2032) with output of 5,256,000,000 mined dogecoins per year
Expand All @@ -83,7 +83,7 @@ int check_length(char* string) {
// set max length for all string inputs to 21 to account for total supply passing
// 1T in ~180 years from 2022. this limit will be valid for the next 1980 years so
// make sure to update in year 4002. :)
int integer_length = strlen(string);
size_t integer_length = strlen(string);
if (integer_length > 22) return false;
else return integer_length;
}
Expand Down Expand Up @@ -147,7 +147,7 @@ int koinu_to_coins_str(uint64_t koinu, char* str) {

if (length < 9) {
string(koinu, str);
int l = str ? strlen(str) : 0;
size_t l = str ? strlen(str) : 0;
char* swap = dogecoin_char_vla(l + 1);
memcpy_safe(swap, str, l + 1);
for (; i < target; i++) {
Expand Down Expand Up @@ -176,14 +176,14 @@ int koinu_to_coins_str(uint64_t koinu, char* str) {

uint64_t coins_to_koinu_str(char* coins) {
if (coins[0] == '-') return false;
int length = check_length(coins);
size_t length = check_length(coins);
if (!length) return false;

char *end, dogecoin_string[21], koinu_string[9];
dogecoin_mem_zero(dogecoin_string, 21);
dogecoin_mem_zero(koinu_string, 9);

int i = 0, j = 0, mantissa_length = 0;
size_t i = 0, j = 0, mantissa_length = 0;
for (; i < length; i++) {
dogecoin_string[i] = coins[i];
if (coins[i] == '.') {
Expand Down
Loading

0 comments on commit d3399f8

Please sign in to comment.