mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-01 01:32:34 +01:00
Rename perturb to permute.
Perturb is a bit stretched for this, permute is better. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
8d31902785
commit
63986e5b2d
5 changed files with 35 additions and 35 deletions
2
Makefile
2
Makefile
|
@ -5,7 +5,7 @@ PROTOCC:=protoc-c
|
||||||
|
|
||||||
PROGRAMS := open-channel open-anchor-sig leak-anchor-sigs
|
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
|
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
|
||||||
|
|
||||||
|
|
6
anchor.c
6
anchor.c
|
@ -2,7 +2,7 @@
|
||||||
#include "bitcoin_tx.h"
|
#include "bitcoin_tx.h"
|
||||||
#include "overflows.h"
|
#include "overflows.h"
|
||||||
#include "pkt.h"
|
#include "pkt.h"
|
||||||
#include "perturb.h"
|
#include "permute_tx.h"
|
||||||
#include "bitcoin_script.h"
|
#include "bitcoin_script.h"
|
||||||
|
|
||||||
struct bitcoin_tx *anchor_tx_create(const tal_t *ctx,
|
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
|
else
|
||||||
outmap = NULL;
|
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);
|
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);
|
outmap);
|
||||||
return tx;
|
return tx;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#include "perturb.h"
|
#include "permute_tx.h"
|
||||||
#include <ccan/crypto/sha256/sha256.h>
|
#include <ccan/crypto/sha256/sha256.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -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,
|
static void init_rand(struct sha256 *h, size_t *randidx,
|
||||||
uint64_t seed1, uint64_t seed2,
|
uint64_t seed1, uint64_t seed2,
|
||||||
uint64_t transaction_num,
|
uint64_t transaction_num,
|
||||||
enum perturb_style style)
|
enum permute_style style)
|
||||||
{
|
{
|
||||||
struct sha256_ctx shactx;
|
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,
|
struct bitcoin_tx_input *inputs,
|
||||||
size_t num_inputs,
|
size_t num_inputs,
|
||||||
size_t *map)
|
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));
|
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. */
|
/* Now, Fisher-Yates shuffle, but using SHA256 as "random" source. */
|
||||||
for (i = 0; i + 1 < num_inputs; i++) {
|
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;
|
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,
|
struct bitcoin_tx_output *outputs,
|
||||||
size_t num_outputs,
|
size_t num_outputs,
|
||||||
size_t *map)
|
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));
|
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. */
|
/* Now, Fisher-Yates shuffle, but using SHA256 as "random" source. */
|
||||||
for (i = 0; i + 1 < num_outputs; i++) {
|
for (i = 0; i + 1 < num_outputs; i++) {
|
25
permute_tx.h
Normal file
25
permute_tx.h
Normal file
|
@ -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 */
|
25
perturb.h
25
perturb.h
|
@ -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 */
|
|
Loading…
Add table
Reference in a new issue