Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
z
Binary file not shown.

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
k
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
�'Q����
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
�0�O�

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(z):C>?R�
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(z):CJR�
Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
��
Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

44 changes: 27 additions & 17 deletions tests/fuzz/fuzz-bech32.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "config.h"
#include <assert.h>

#include <common/utils.h>
#include <common/bech32.h>
#include <stdint.h>
#include <string.h>
Expand All @@ -25,34 +25,45 @@ void run(const uint8_t *data, size_t size)
/* Buffer size is defined in each function's doc comment. */
benc = data[0] ? BECH32_ENCODING_BECH32 : BECH32_ENCODING_BECH32M;
bech32_str_cap = (size - 1) + strlen(hrp_inv) + 8;
bech32_str = malloc(bech32_str_cap);
bech32_str = tal_arr(tmpctx, char, bech32_str_cap);
if (bech32_encode(bech32_str, hrp_inv, data + 1, size - 1,
bech32_str_cap, benc) == 1) {
hrp_out = malloc(strlen(bech32_str) - 6);
data_out = malloc(strlen(bech32_str) - 8);
hrp_out = tal_arr(tmpctx, char, strlen(bech32_str) - 6);
data_out = tal_arr(tmpctx, uint8_t, strlen(bech32_str) - 8);

benc_decoded = bech32_decode(hrp_out, data_out, &data_out_len,
bech32_str, bech32_str_cap);
assert(benc_decoded == benc);
assert(strcmp(hrp_inv, hrp_out) == 0);
assert(data_out_len == size - 1);
assert(memcmp(data_out, data + 1, data_out_len) == 0);

free(hrp_out);
free(data_out);
}
free(bech32_str);

data_out = malloc(size);
/* Convert data to 5-bit values (0-31) */
u8 *five_bit_data = tal_dup_arr(tmpctx, u8, data, size, 0);
for (size_t i = 0; i < size; i++)
five_bit_data[i] &= 0x1F;

/* This is also used as part of sign and check message. */
data_out_len = 0;
bech32_convert_bits(data_out, &data_out_len, 8, data, size, 5, 1);
u8 *eight_bit_data = tal_arr(tmpctx, u8, size);
size_t eight_bit_len = 0;
/* Convert 5-to-8 without padding */
if (bech32_convert_bits(eight_bit_data, &eight_bit_len, 8,
five_bit_data, size, 5, 0)) {
u8 *five_bit_deconv = tal_arr(tmpctx, u8, size);
size_t five_bit_deconv_len = 0;
/* Convert 8-to-5 with padding */
if (bech32_convert_bits(five_bit_deconv, &five_bit_deconv_len, 5,
eight_bit_data, eight_bit_len, 8, 1)) {
assert(five_bit_deconv_len == size);
assert(memcmp(five_bit_data, five_bit_deconv, five_bit_deconv_len) == 0);
}
}

data_out = tal_arr(tmpctx, uint8_t, size);
data_out_len = 0;
bech32_convert_bits(data_out, &data_out_len, 8, data, size, 5, 0);

addr = malloc(73 + strlen(hrp_addr));
for (int wit_version = 0; wit_version < 2; ++wit_version) {
addr = tal_arr(tmpctx, char, 73 + strlen(hrp_addr));
for (int wit_version = 0; wit_version <= 16; ++wit_version) {
if (segwit_addr_encode(addr, hrp_addr, wit_version, data,
size) == 0)
continue;
Expand All @@ -63,7 +74,6 @@ void run(const uint8_t *data, size_t size)
assert(data_out_len == size);
assert(memcmp(data_out, data, data_out_len) == 0);
}
free(addr);

free(data_out);
clean_tmpctx();
}