From 63986e5b2dd67e33aa1d180e1867ca9f03e45723 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 29 May 2015 12:59:09 +0930 Subject: [PATCH] Rename perturb to permute. Perturb is a bit stretched for this, permute is better. Signed-off-by: Rusty Russell --- Makefile | 2 +- anchor.c | 6 +++--- perturb.c => permute_tx.c | 12 ++++++------ permute_tx.h | 25 +++++++++++++++++++++++++ perturb.h | 25 ------------------------- 5 files changed, 35 insertions(+), 35 deletions(-) rename perturb.c => permute_tx.c (92%) create mode 100644 permute_tx.h delete mode 100644 perturb.h diff --git a/Makefile b/Makefile index 6071010ab..d44b3b4ca 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ PROTOCC:=protoc-c PROGRAMS := open-channel open-anchor-sig leak-anchor-sigs -HELPER_OBJS := base58.o lightning.pb-c.o shadouble.o pkt.o bitcoin_script.o perturb.o signature.o bitcoin_tx.o bitcoin_address.o anchor.o +HELPER_OBJS := base58.o lightning.pb-c.o shadouble.o pkt.o bitcoin_script.o permute_tx.o signature.o bitcoin_tx.o bitcoin_address.o anchor.o CCAN_OBJS := ccan-crypto-sha256.o ccan-crypto-shachain.o ccan-err.o ccan-tal.o ccan-tal-str.o ccan-take.o ccan-list.o ccan-str.o ccan-opt-helpers.o ccan-opt.o ccan-opt-parse.o ccan-opt-usage.o ccan-read_write_all.o ccan-str-hex.o ccan-tal-grab_file.o ccan-noerr.o diff --git a/anchor.c b/anchor.c index 04ba2fa50..a3449356c 100644 --- a/anchor.c +++ b/anchor.c @@ -2,7 +2,7 @@ #include "bitcoin_tx.h" #include "overflows.h" #include "pkt.h" -#include "perturb.h" +#include "permute_tx.h" #include "bitcoin_script.h" struct bitcoin_tx *anchor_tx_create(const tal_t *ctx, @@ -81,9 +81,9 @@ struct bitcoin_tx *anchor_tx_create(const tal_t *ctx, else outmap = NULL; - perturb_inputs(o1->seed, o2->seed, 0, tx->input, tx->input_count, + permute_inputs(o1->seed, o2->seed, 0, tx->input, tx->input_count, inmap); - perturb_outputs(o1->seed, o2->seed, 0, tx->output, tx->output_count, + permute_outputs(o1->seed, o2->seed, 0, tx->output, tx->output_count, outmap); return tx; } diff --git a/perturb.c b/permute_tx.c similarity index 92% rename from perturb.c rename to permute_tx.c index 078ae9aef..0eed1825a 100644 --- a/perturb.c +++ b/permute_tx.c @@ -1,4 +1,4 @@ -#include "perturb.h" +#include "permute_tx.h" #include #include #include @@ -16,7 +16,7 @@ static u32 get_next_rand(struct sha256 *h, size_t *randidx) static void init_rand(struct sha256 *h, size_t *randidx, uint64_t seed1, uint64_t seed2, uint64_t transaction_num, - enum perturb_style style) + enum permute_style style) { struct sha256_ctx shactx; @@ -93,7 +93,7 @@ static void swap_inputs(struct bitcoin_tx_input *inputs, size_t *map, } } -void perturb_inputs(uint64_t seed1, uint64_t seed2, uint64_t tx_num, +void permute_inputs(uint64_t seed1, uint64_t seed2, uint64_t tx_num, struct bitcoin_tx_input *inputs, size_t num_inputs, size_t *map) @@ -110,7 +110,7 @@ void perturb_inputs(uint64_t seed1, uint64_t seed2, uint64_t tx_num, i, i + find_best_in(inputs + i, num_inputs - i)); } - init_rand(&h, &randidx, seed1, seed2, tx_num, PERTURB_INPUT_STYLE); + init_rand(&h, &randidx, seed1, seed2, tx_num, PERMUTE_INPUT_STYLE); /* Now, Fisher-Yates shuffle, but using SHA256 as "random" source. */ for (i = 0; i + 1 < num_inputs; i++) { @@ -159,7 +159,7 @@ static size_t find_best_out(struct bitcoin_tx_output *outputs, size_t num) return best; } -void perturb_outputs(uint64_t seed1, uint64_t seed2, size_t tx_num, +void permute_outputs(uint64_t seed1, uint64_t seed2, size_t tx_num, struct bitcoin_tx_output *outputs, size_t num_outputs, size_t *map) @@ -176,7 +176,7 @@ void perturb_outputs(uint64_t seed1, uint64_t seed2, size_t tx_num, i, i + find_best_out(outputs + i, num_outputs - i)); } - init_rand(&h, &randidx, seed1, seed2, tx_num, PERTURB_OUTPUT_STYLE); + init_rand(&h, &randidx, seed1, seed2, tx_num, PERMUTE_OUTPUT_STYLE); /* Now, Fisher-Yates shuffle, but using SHA256 as "random" source. */ for (i = 0; i + 1 < num_outputs; i++) { diff --git a/permute_tx.h b/permute_tx.h new file mode 100644 index 000000000..3683205fe --- /dev/null +++ b/permute_tx.h @@ -0,0 +1,25 @@ +#ifndef LIGHTNING_PERMUTE_TX_H +#define LIGHTNING_PERMUTE_TX_H +#include "bitcoin_tx.h" + +/* Given the two seeds, permute the transaction inputs. + * map[0] is set to the new index of input 0, etc. + */ +void permute_inputs(uint64_t seed1, uint64_t seed2, + size_t transaction_num, + struct bitcoin_tx_input *inputs, + size_t num_inputs, + size_t *map); + +void permute_outputs(uint64_t seed1, uint64_t seed2, + size_t transaction_num, + struct bitcoin_tx_output *outputs, + size_t num_outputs, + size_t *map); + +enum permute_style { + PERMUTE_INPUT_STYLE = 0, + PERMUTE_OUTPUT_STYLE = 1 +}; + +#endif /* LIGHTNING_PERMUTE_TX_H */ diff --git a/perturb.h b/perturb.h deleted file mode 100644 index 9072c3fb5..000000000 --- a/perturb.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef LIGHTNING_PERTURB_H -#define LIGHTNING_PERTURB_H -#include "bitcoin_tx.h" - -/* Given the two seeds, perturb the transaction inputs. - * map[0] is set to the new index of input 0, etc. - */ -void perturb_inputs(uint64_t seed1, uint64_t seed2, - size_t transaction_num, - struct bitcoin_tx_input *inputs, - size_t num_inputs, - size_t *map); - -void perturb_outputs(uint64_t seed1, uint64_t seed2, - size_t transaction_num, - struct bitcoin_tx_output *outputs, - size_t num_outputs, - size_t *map); - -enum perturb_style { - PERTURB_INPUT_STYLE = 0, - PERTURB_OUTPUT_STYLE = 1 -}; - -#endif /* LIGHTNING_PERTURB_H */