-
Notifications
You must be signed in to change notification settings - Fork 0
/
secure-ubitcoin.cpp
54 lines (40 loc) · 1.03 KB
/
secure-ubitcoin.cpp
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// SPDX-License-Identifier: MIT
// SPDX-FileCopyrightText: 2023 SASANO Takayoshi <[email protected]>
#include <string.h>
#include "Bitcoin.h"
extern "C" {
#include "platform.h"
#include "secure.h"
}
uint8_t seckey[32], pubkey[32], uid[16];
static PrivateKey *private_key;
static PublicKey public_key;
extern "C" uint32_t random32(void)
{
uint32_t v;
random_fill_buf(&v, sizeof(v));
return v;
}
int secure_make_signature(uint8_t *sig, uint8_t *msg)
{
SchnorrSignature signature = private_key->schnorr_sign(msg);
signature.serialize(sig, 64);
return 0;
}
int secure_make_shared_secret(uint8_t *sec, uint8_t *pub, int publen)
{
/* pub comes with "04" prefix */
PublicKey peerpubkey(pub + 1, false);
private_key->ecdh(peerpubkey, sec, false);
return 0;
}
int secure_engine_initialize(void)
{
private_key = new PrivateKey(seckey);
public_key = private_key->publicKey();
public_key.x(pubkey, sizeof(pubkey));
/* create uuid from pubkey */
for (int i = 0; i < sizeof(uid); i++)
uid[i] = pubkey[i] ^ pubkey[i + sizeof(uid)];
return 0;
}