mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-17 19:00:58 +00:00
chore(crypto): remove graphene base58 functions as they are not used anywhere
[no changelog]
This commit is contained in:
parent
745be6eaa3
commit
cba74272e1
@ -86,7 +86,6 @@ endif
|
||||
CFLAGS += -I.
|
||||
CFLAGS += -I..
|
||||
CFLAGS += -DUSE_ETHEREUM=1
|
||||
CFLAGS += -DUSE_GRAPHENE=1
|
||||
CFLAGS += -DUSE_KECCAK=1
|
||||
CFLAGS += -DUSE_MONERO=1
|
||||
CFLAGS += -DUSE_NEM=1
|
||||
|
@ -219,56 +219,3 @@ int base58_decode_check(const char *str, HasherType hasher_type, uint8_t *data,
|
||||
memcpy(data, nd, res - 4);
|
||||
return res - 4;
|
||||
}
|
||||
|
||||
#if USE_GRAPHENE
|
||||
int b58gphcheck(const void *bin, size_t binsz, const char *base58str) {
|
||||
unsigned char buf[32] = {0};
|
||||
const uint8_t *binc = bin;
|
||||
unsigned i = 0;
|
||||
if (binsz < 4) return -4;
|
||||
ripemd160(bin, binsz - 4, buf); // No double SHA256, but a single RIPEMD160
|
||||
if (memcmp(&binc[binsz - 4], buf, 4)) return -1;
|
||||
|
||||
// Check number of zeros is correct AFTER verifying checksum (to avoid
|
||||
// possibility of accessing base58str beyond the end)
|
||||
for (i = 0; binc[i] == '\0' && base58str[i] == '1'; ++i) {
|
||||
} // Just finding the end of zeros, nothing to do in loop
|
||||
if (binc[i] == '\0' || base58str[i] == '1') return -3;
|
||||
|
||||
return binc[0];
|
||||
}
|
||||
|
||||
int base58gph_encode_check(const uint8_t *data, int datalen, char *str,
|
||||
int strsize) {
|
||||
if (datalen > 128) {
|
||||
return 0;
|
||||
}
|
||||
uint8_t buf[datalen + 32];
|
||||
memset(buf, 0, sizeof(buf));
|
||||
uint8_t *hash = buf + datalen;
|
||||
memcpy(buf, data, datalen);
|
||||
ripemd160(data, datalen, hash); // No double SHA256, but a single RIPEMD160
|
||||
size_t res = strsize;
|
||||
bool success = b58enc(str, &res, buf, datalen + 4);
|
||||
memzero(buf, sizeof(buf));
|
||||
return success ? res : 0;
|
||||
}
|
||||
|
||||
int base58gph_decode_check(const char *str, uint8_t *data, int datalen) {
|
||||
if (datalen > 128) {
|
||||
return 0;
|
||||
}
|
||||
uint8_t d[datalen + 4];
|
||||
memset(d, 0, sizeof(d));
|
||||
size_t res = datalen + 4;
|
||||
if (b58tobin(d, &res, str) != true) {
|
||||
return 0;
|
||||
}
|
||||
uint8_t *nd = d + datalen + 4 - res;
|
||||
if (b58gphcheck(nd, res, str) < 0) {
|
||||
return 0;
|
||||
}
|
||||
memcpy(data, nd, res - 4);
|
||||
return res - 4;
|
||||
}
|
||||
#endif
|
||||
|
@ -43,11 +43,4 @@ int b58check(const void *bin, size_t binsz, HasherType hasher_type,
|
||||
const char *base58str);
|
||||
bool b58enc(char *b58, size_t *b58sz, const void *data, size_t binsz);
|
||||
|
||||
#if USE_GRAPHENE
|
||||
int base58gph_encode_check(const uint8_t *data, int datalen, char *str,
|
||||
int strsize);
|
||||
int base58gph_decode_check(const char *str, uint8_t *data, int datalen);
|
||||
int b58gphcheck(const void *bin, size_t binsz, const char *base58str);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -815,61 +815,6 @@ int fuzz_aes(void) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fuzz_b58gph_encode_decode(void) {
|
||||
// note: encode and decode functions have an internal limit of 128
|
||||
#define BASE58_GPH_MAX_INPUT_LEN 130
|
||||
|
||||
if (fuzzer_length < 1 + 1 + BASE58_GPH_MAX_INPUT_LEN) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// use a flexible output buffer target size
|
||||
uint8_t chosen_outlen = 0;
|
||||
memcpy(&chosen_outlen, fuzzer_input(1), 1);
|
||||
if (chosen_outlen > BASE58_GPH_MAX_INPUT_LEN) {
|
||||
return 0;
|
||||
}
|
||||
// use a flexible input buffer target size
|
||||
uint8_t chosen_inlen = 0;
|
||||
memcpy(&chosen_inlen, fuzzer_input(1), 1);
|
||||
if (chosen_inlen > BASE58_GPH_MAX_INPUT_LEN) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// TODO idea: switch to malloc()'ed buffers for better out of bounds access
|
||||
// detection?
|
||||
|
||||
uint8_t encode_in_buffer[BASE58_GPH_MAX_INPUT_LEN] = {0};
|
||||
// with null termination
|
||||
char decode_in_buffer[BASE58_GPH_MAX_INPUT_LEN + 1] = {0};
|
||||
char out_buffer[BASE58_GPH_MAX_INPUT_LEN] = {0};
|
||||
|
||||
memcpy(&encode_in_buffer, fuzzer_input(chosen_inlen), chosen_inlen);
|
||||
memcpy(&decode_in_buffer, &encode_in_buffer, chosen_inlen);
|
||||
|
||||
int ret = 0;
|
||||
ret = base58gph_encode_check(encode_in_buffer, chosen_inlen, out_buffer,
|
||||
chosen_outlen);
|
||||
|
||||
if (ret != 0) {
|
||||
// successful encode, try decode
|
||||
uint8_t dummy_buffer[BASE58_GPH_MAX_INPUT_LEN] = {0};
|
||||
ret = base58gph_decode_check(out_buffer, (uint8_t *)&dummy_buffer,
|
||||
chosen_outlen);
|
||||
if (ret == 0) {
|
||||
// mark as exception
|
||||
// TODO POTENTIAL BUG - followup
|
||||
// crash();
|
||||
}
|
||||
}
|
||||
|
||||
// do a second operation with the same input, without relationship to the
|
||||
// previously computed output
|
||||
base58gph_decode_check(decode_in_buffer, (uint8_t *)&out_buffer,
|
||||
chosen_outlen);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fuzz_chacha_drbg(void) {
|
||||
#define CHACHA_DRBG_ENTROPY_LENGTH 32
|
||||
#define CHACHA_DRBG_RESEED_LENGTH 32
|
||||
@ -1233,9 +1178,6 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||
fuzz_aes();
|
||||
#endif
|
||||
break;
|
||||
case 19:
|
||||
fuzz_b58gph_encode_decode();
|
||||
break;
|
||||
case 22:
|
||||
fuzz_chacha_drbg();
|
||||
break;
|
||||
|
@ -66,11 +66,6 @@
|
||||
#define USE_ETHEREUM 0
|
||||
#endif
|
||||
|
||||
// support Graphene operations (STEEM, BitShares)
|
||||
#ifndef USE_GRAPHENE
|
||||
#define USE_GRAPHENE 0
|
||||
#endif
|
||||
|
||||
// support NEM operations
|
||||
#ifndef USE_NEM
|
||||
#define USE_NEM 0
|
||||
|
@ -1202,47 +1202,6 @@ START_TEST(test_base58) {
|
||||
}
|
||||
END_TEST
|
||||
|
||||
#if USE_GRAPHENE
|
||||
|
||||
// Graphene Base85CheckEncoding
|
||||
START_TEST(test_base58gph) {
|
||||
static const char *base58_vector[] = {
|
||||
"02e649f63f8e8121345fd7f47d0d185a3ccaa843115cd2e9392dcd9b82263bc680",
|
||||
"6dumtt9swxCqwdPZBGXh9YmHoEjFFnNfwHaTqRbQTghGAY2gRz",
|
||||
"021c7359cd885c0e319924d97e3980206ad64387aff54908241125b3a88b55ca16",
|
||||
"5725vivYpuFWbeyTifZ5KevnHyqXCi5hwHbNU9cYz1FHbFXCxX",
|
||||
"02f561e0b57a552df3fa1df2d87a906b7a9fc33a83d5d15fa68a644ecb0806b49a",
|
||||
"6kZKHSuxqAwdCYsMvwTcipoTsNE2jmEUNBQufGYywpniBKXWZK",
|
||||
"03e7595c3e6b58f907bee951dc29796f3757307e700ecf3d09307a0cc4a564eba3",
|
||||
"8b82mpnH8YX1E9RHnU2a2YgLTZ8ooevEGP9N15c1yFqhoBvJur",
|
||||
0,
|
||||
0,
|
||||
};
|
||||
const char **raw = base58_vector;
|
||||
const char **str = base58_vector + 1;
|
||||
uint8_t rawn[34];
|
||||
char strn[53];
|
||||
int r;
|
||||
while (*raw && *str) {
|
||||
int len = strlen(*raw) / 2;
|
||||
|
||||
memcpy(rawn, fromhex(*raw), len);
|
||||
r = base58gph_encode_check(rawn, len, strn, sizeof(strn));
|
||||
ck_assert_int_eq((size_t)r, strlen(*str) + 1);
|
||||
ck_assert_str_eq(strn, *str);
|
||||
|
||||
r = base58gph_decode_check(strn, rawn, len);
|
||||
ck_assert_int_eq(r, len);
|
||||
ck_assert_mem_eq(rawn, fromhex(*raw), len);
|
||||
|
||||
raw += 2;
|
||||
str += 2;
|
||||
}
|
||||
}
|
||||
END_TEST
|
||||
|
||||
#endif
|
||||
|
||||
START_TEST(test_bignum_divmod) {
|
||||
uint32_t r;
|
||||
int i;
|
||||
@ -9525,12 +9484,6 @@ Suite *test_suite(void) {
|
||||
tcase_add_test(tc, test_base58);
|
||||
suite_add_tcase(s, tc);
|
||||
|
||||
#if USE_GRAPHENE
|
||||
tc = tcase_create("base58gph");
|
||||
tcase_add_test(tc, test_base58gph);
|
||||
suite_add_tcase(s, tc);
|
||||
#endif
|
||||
|
||||
tc = tcase_create("bignum_divmod");
|
||||
tcase_add_test(tc, test_bignum_divmod);
|
||||
suite_add_tcase(s, tc);
|
||||
|
Loading…
Reference in New Issue
Block a user