Basically, `devtools/reduce-includes.sh */*.c`. Build time from make clean (RUST=0) (includes building external libs): Before: real 0m38.944000-40.416000(40.1131+/-0.4)s user 3m6.790000-17.159000(15.0571+/-2.8)s sys 0m35.304000-37.336000(36.8942+/-0.57)s After: real 0m37.872000-39.974000(39.5466+/-0.59)s user 3m1.211000-14.968000(12.4556+/-3.9)s sys 0m35.008000-36.830000(36.4143+/-0.5)s Build time after touch config.vars (RUST=0): Before: real 0m19.831000-21.862000(21.5528+/-0.58)s user 2m15.361000-30.731000(28.4798+/-4.4)s sys 0m21.056000-22.339000(22.0346+/-0.35)s After: real 0m18.384000-21.307000(20.8605+/-0.92)s user 2m5.585000-26.843000(23.6017+/-6.7)s sys 0m19.650000-22.003000(21.4943+/-0.69)s Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
47 lines
1.2 KiB
C
47 lines
1.2 KiB
C
#include "config.h"
|
|
#include <bitcoin/privkey.h>
|
|
#include <common/bolt12_id.h>
|
|
#include <common/utils.h>
|
|
|
|
/* Given a base secret, an easy one-way function is SHA(base || input) */
|
|
static void hash_from_base(const struct secret *base_secret,
|
|
const void *input,
|
|
size_t input_len,
|
|
struct sha256 *hash)
|
|
{
|
|
struct sha256_ctx shactx;
|
|
|
|
sha256_init(&shactx);
|
|
sha256_update(&shactx, base_secret, sizeof(*base_secret));
|
|
sha256_update(&shactx, input, input_len);
|
|
sha256_done(&shactx, hash);
|
|
}
|
|
|
|
void bolt12_path_secret(const struct secret *base_secret,
|
|
const struct sha256 *payment_hash,
|
|
struct secret *path_secret)
|
|
{
|
|
struct sha256 hash;
|
|
hash_from_base(base_secret, payment_hash, sizeof(*payment_hash), &hash);
|
|
|
|
CROSS_TYPE_ASSIGNMENT(path_secret, &hash);
|
|
}
|
|
|
|
u8 *bolt12_path_id(const tal_t *ctx,
|
|
const struct secret *base_secret,
|
|
const struct sha256 *payment_hash)
|
|
{
|
|
struct secret path_secret;
|
|
bolt12_path_secret(base_secret, payment_hash, &path_secret);
|
|
|
|
return (u8 *)tal_dup(ctx, struct secret, &path_secret);
|
|
}
|
|
|
|
void bolt12_alias_tweak(const struct secret *base_secret,
|
|
const void *input,
|
|
size_t input_len,
|
|
struct sha256 *tweak)
|
|
{
|
|
hash_from_base(base_secret, input, input_len, tweak);
|
|
}
|