-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathu2f.h
More file actions
125 lines (95 loc) · 3.38 KB
/
u2f.h
File metadata and controls
125 lines (95 loc) · 3.38 KB
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
/*
* u2f.h
*
* Created on: Jan 26, 2016
* Author: pp
*/
#ifndef _U2F_H_
#define _U2F_H_
#include <stdint.h>
#define SW_NO_ERROR 0x00
#define SW_CONDITIONS_NOT_SATISFIED 0x01
#define SW_WRONG_DATA 0x02
#define U2F_EC_FMT_UNCOMPRESSED 0x04
#define U2F_EC_POINT_SIZE 32
#define U2F_EC_PUBKEY_SIZE 65
#define U2F_APDU_SIZE 7
#define U2F_CHALLENGE_SIZE 32
#define U2F_APPLICATION_SIZE 32
#define U2F_KEY_HANDLE_SIZE 4
#define U2F_REGISTER_REQUEST_SIZE (U2F_CHALLENGE_SIZE+U2F_APPLICATION_SIZE)
#define U2F_MAX_REQUEST_PAYLOAD (1 + U2F_CHALLENGE_SIZE+U2F_APPLICATION_SIZE + 1 + U2F_KEY_HANDLE_SIZE)
// U2F native commands
#define U2F_REGISTER 0x01
#define U2F_AUTHENTICATE 0x02
#define U2F_VERSION 0x03
#define U2F_VENDOR_FIRST 0xc0
#define U2F_VENDOR_LAST 0xff
// U2F_CMD_REGISTER command defines
#define U2F_REGISTER_ID 0x05
#define U2F_REGISTER_HASH_ID 0x00
struct u2f_request_apdu
{
uint8_t cla;
uint8_t ins;
uint8_t p1;
uint8_t p2;
uint8_t LC1;
uint8_t LC2;
uint8_t LC3;
uint8_t payload[U2F_MAX_REQUEST_PAYLOAD];
};
struct u2f_ec_point
{
uint8_t fmt;
uint8_t x[U2F_EC_POINT_SIZE];
uint8_t y[U2F_EC_POINT_SIZE];
};
struct u2f_register_request
{
uint8_t chal[U2F_CHALLENGE_SIZE];
uint8_t app[U2F_APPLICATION_SIZE];
};
void u2f_request(struct u2f_request_apdu* req);
// Command status responses
#define U2F_SW_NO_ERROR 0x9000
#define U2F_SW_WRONG_DATA 0x6984
#define U2F_SW_CONDITIONS_NOT_SATISFIED 0x6985
#define U2F_SW_INS_NOT_SUPPORTED 0x6d00
/* IMPLEMENTATION specific functions that must be implemented by user */
#define U2F_ATTESTATION_HANDLE ((uint8_t *)"\x00\x00\x00\x00")
#define U2F_ATTESTATION_CERT_SIZE 374
// callback for u2f to send back response data
// @buf data to write back
// @len length of buf in bytes
void u2f_response_writeback(uint8_t * buf, uint8_t len);
// callback when u2f finishes and will
// indicate when all buffer data, if any, should be written
void u2f_response_flush();
// callback when u2f starts a new transaction
void u2f_response_start();
// Return 0 if user provides feedback, -1 if not
// This should block as long as it needs to get feedback
// before failing.
int8_t u2f_get_user_feedback();
// callback for u2f to start a sha256 hash
void u2f_sha256_start();
// callback for u2f to add data to started sha256 state
// @buf data to update hash with
// @len length of buf in bytes
void u2f_sha256_update(uint8_t * buf, uint8_t len);
// callback for u2f to havest hash from
// @buf final data to update hash with
// @len length of buf in bytes
void u2f_sha256_finish(uint8_t * buf, uint8_t len);
// callback for u2f to compute signature on the previously computed sha256 digest
// @dest atleast 64 bytes to write back signature R and S values
// @handle for the private key to use
void u2f_ecdsa_sign(uint8_t * dest, uint8_t * handle);
// callback to get a new key handle
// @handle location to write the key handle (should be U2F_KEY_HANDLE_SIZE bytes long)
// @pubkey location to write the public key R & S (64 bytes)
void u2f_new_keypair(uint8_t * handle, uint8_t * pubkey);
// method to return pointer to attestation cert
uint8_t * u2f_get_attestation_cert();
#endif /* U2F_H_ */