-
Notifications
You must be signed in to change notification settings - Fork 2
/
boe.h
executable file
·162 lines (146 loc) · 4.71 KB
/
boe.h
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
// Copyright 2018 The go-hpb Authors
// This file is part of the go-hpb.
//
// The go-hpb is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-hpb is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-hpb. If not, see <http://www.gnu.org/licenses/>.
#ifndef BOE_H
#define BOE_H
#include <stdint.h>
typedef struct BoeErr{
int ecode;
char emsg[100];
unsigned char bfree;
}BoeErr;
BoeErr *BOE_OK;
BoeErr *BOE_HASH_TIME_LIMIT;
typedef int (*BoeUpgradeCallback)(int,char*);
typedef int (*BoeValidSignCallback)(unsigned char *pub, unsigned char *sig, void *param, int param_len);
void boe_err_free(BoeErr *e);
BoeErr* boe_init(void);
BoeErr* boe_test_init(char *ethname);
BoeErr* boe_release(void);
BoeErr* boe_reg_update_callback(BoeUpgradeCallback func);
BoeErr* boe_get_hw_version(unsigned char *H);
BoeErr* boe_get_m_version(unsigned char *M);
BoeErr* boe_get_version(unsigned char *H, unsigned char *M, unsigned char *F, unsigned char *D);
BoeErr* boe_upgrade(unsigned char *image, int imagelen);
BoeErr* boe_upgrade_abort(void);
/*
* check board is connected.
*/
BoeErr* boe_hw_check(void);
BoeErr* boe_hw_connect(void);
BoeErr* boe_reg_random_read(unsigned char *string);
/*
* let board reboot.
*/
BoeErr* boe_reboot(void);
/*
* bind serial number to board.
* in: 20 bytes serial number.
*/
BoeErr* boe_set_boesn(unsigned char *sn);
/*
*
* bind account to board.
* in: 42 bytes account address.
*/
BoeErr* boe_set_bind_account(unsigned char *baccount);
/*
* get random from board.
* out: r, 32 bytes random.
*/
BoeErr* boe_get_random(unsigned char *r);
/*
* get sn from board.
* out: sn, 20 bytes sn.
*/
BoeErr* boe_get_boesn(unsigned char *sn);
/*
* get account info from board.
* out: account, 42 bytes account address.
*/
BoeErr* boe_get_bind_account(unsigned char *account);
/*
* do signature for hardware authentication.
* in: p_random, 32 bytes random
* out: sig, 64 bytes signature.
* return :
* BOE_OK is sign successed.
*
*/
BoeErr* boe_hw_sign(unsigned char *p_random, unsigned char *sig);
/*
* do signature for hardware authentication.
* in: p_random, 32 bytes random
* out: sig, 64 bytes signature.
* return :
* BOE_OK is sign successed.
*
*/
BoeErr* boe_hw_sign_with_hid(unsigned char *p_random, unsigned char *sig);
/*
* do signature verify.
* p_random: 32 bytes random.
* hid : string.
* pubkey : 64 bytes pubkey.
* sig : 64 bytes signature.
*
* return:
* BOE_OK is verify passed.
*
*/
BoeErr* boe_p256_verify_with_hid(unsigned char *p_random, unsigned char *hid, unsigned char *pubkey, unsigned char *sig);
/*
* do signature verify.
* p_random: 32 bytes random.
* pubkey : 64 bytes pubkey.
* sig : 64 bytes signature.
*
* return:
* BOE_OK is verify passed.
*
*/
BoeErr* boe_p256_verify(unsigned char *random, unsigned char *pubkey, unsigned char *signature);
/*
* get a random for consensus.
* in: hash, 32 bytes hash.
* out: nexthash. 32 bytes hash.
*/
BoeErr* boe_get_s_random(unsigned char *hash, unsigned char *nexthash);
/*
* The new version random hash, instead of boe_get_s_random.
*/
BoeErr* boe_get_n_random(unsigned char *hash, unsigned char *nexthash);
/*
* recover pubkey. if boe board is working, use hardware to do it. else will use soft alghorim.
*/
BoeErr* boe_check_random(unsigned char *hash, unsigned char *nexthash);
/*
*check random. if boe board is working, use hardware to do it. else will use soft alghorim.
*/
BoeErr* boe_valid_sign(unsigned char *sig, unsigned char *pub);
BoeErr* boe_valid_sign_recover_pub_async(unsigned char *sig, unsigned char *param, int paramlen);
BoeErr* boe_valid_sign_callback(BoeValidSignCallback func);
BoeErr* boe_genkey(unsigned char *pubkey);
BoeErr* boe_get_pubkey(unsigned char *pubkey);
BoeErr* boe_lock_pk(void);
BoeErr* boe_hw_verify(unsigned char *hash, unsigned char *signature, unsigned char *pubkey);
BoeErr* boe_set_mac(unsigned char *mac);
BoeErr* boe_get_mac(unsigned char *mac);
BoeErr* boe_phy_read(unsigned int reg, unsigned int *val);
BoeErr* boe_phy_shd_read(unsigned int reg, unsigned int shadow, unsigned int *val);
BoeErr* boe_reg_read(unsigned int reg, unsigned int *val);
BoeErr* boe_reg_write(unsigned int reg, unsigned int val);
BoeErr* boe_reg_random_read(unsigned char *string);
#endif /*BOE_H*/