forked from ElementsProject/lightning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
blinding.c
39 lines (34 loc) · 977 Bytes
/
blinding.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <bitcoin/privkey.h>
#include <bitcoin/pubkey.h>
#include <common/blinding.h>
#include <common/utils.h>
void blinding_hash_e_and_ss(const struct pubkey *e,
const struct secret *ss,
struct sha256 *sha)
{
u8 der[PUBKEY_CMPR_LEN];
struct sha256_ctx shactx;
pubkey_to_der(der, e);
sha256_init(&shactx);
sha256_update(&shactx, der, sizeof(der));
sha256_update(&shactx, ss->data, sizeof(ss->data));
sha256_done(&shactx, sha);
}
/* E(i+1) = H(E(i) || ss(i)) * E(i) */
bool blinding_next_pubkey(const struct pubkey *pk,
const struct sha256 *h,
struct pubkey *next)
{
*next = *pk;
return secp256k1_ec_pubkey_tweak_mul(secp256k1_ctx, &next->pubkey,
h->u.u8) == 1;
}
/* e(i+1) = H(E(i) || ss(i)) * e(i) */
bool blinding_next_privkey(const struct privkey *e,
const struct sha256 *h,
struct privkey *next)
{
*next = *e;
return secp256k1_ec_privkey_tweak_mul(secp256k1_ctx, next->secret.data,
h->u.u8) == 1;
}