Virgil IoT KIT
provision-structs.h
Go to the documentation of this file.
1 // Copyright (C) 2015-2020 Virgil Security, Inc.
2 //
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // (1) Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 //
12 // (2) Redistributions in binary form must reproduce the above copyright
13 // notice, this list of conditions and the following disclaimer in
14 // the documentation and/or other materials provided with the
15 // distribution.
16 //
17 // (3) Neither the name of the copyright holder nor the names of its
18 // contributors may be used to endorse or promote products derived from
19 // this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR
22 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 // DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
25 // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29 // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
30 // IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 // POSSIBILITY OF SUCH DAMAGE.
32 //
33 // Lead Maintainer: Virgil Security Inc. <support@virgilsecurity.com>
34 
75 #ifndef VS_IOT_PROVISION_STRUCTS_H
76 #define VS_IOT_PROVISION_STRUCTS_H
77 
79 #include <trust_list-config.h>
80 
81 #ifdef __cplusplus
82 namespace VirgilIoTKit {
83 extern "C" {
84 #endif
85 
86 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
87 #define HTONL_IN_COMPILE_TIME(val) \
88  (uint32_t)(((uint32_t)val & 0xFF) << 24 | ((uint32_t)val & 0xFF00) << 8 | ((uint32_t)val & 0xFF0000) >> 8 | \
89  ((uint32_t)val & 0xFF000000) >> 24)
90 #else
91 #define HTONL_IN_COMPILE_TIME(val) (val)
92 #endif
93 
94 // Macro used to do htons in compile time
95 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
96 #define HTONS_IN_COMPILE_TIME(val) (uint16_t)(((uint16_t)val & 0xFF) << 8 | ((uint16_t)val & 0xFF00) >> 8)
97 #else
98 #define HTONS_IN_COMPILE_TIME(val) (val)
99 #endif
100 
105 #define VS_START_EPOCH (1420070400)
106 
108 #define VS_DEVICE_SERIAL_SIZE (32)
109 
111 #define VS_DEVICE_MANUFACTURE_ID_SIZE (16)
112 
114 #define VS_DEVICE_TYPE_SIZE (4)
115 
121 
128 
135 
136 #pragma GCC diagnostic push
137 #pragma GCC diagnostic ignored "-Wmultichar"
138 
141 
143 typedef enum {
161 #pragma GCC diagnostic pop
162 
164 typedef enum {
175 
177 typedef enum {
189 } vs_key_type_e;
190 
192 typedef struct __attribute__((__packed__)) {
193  uint8_t signer_type;
194  uint8_t ec_type;
195  uint8_t hash_type;
196  uint8_t raw_sign_pubkey[];
198 } vs_sign_t;
199 
201 typedef struct __attribute__((__packed__)) {
202  uint8_t key_type;
203  uint8_t ec_type;
204  uint16_t meta_data_sz;
205  uint8_t meta_and_pubkey[];
206 } vs_pubkey_t;
207 
209 typedef struct __attribute__((__packed__)) {
210  uint32_t start_date;
211  uint32_t expire_date;
214 
216 typedef struct __attribute__((__packed__)) {
217  uint8_t major;
218  uint8_t minor;
219  uint8_t patch;
220  uint32_t build;
221  uint32_t timestamp;
223 
225 typedef struct __attribute__((__packed__)) {
230 
236 typedef struct {
237  int last_pos;
239  uint8_t element_buf[VS_TL_STORAGE_MAX_PART_SIZE];
241 
249 
254 typedef struct {
257 
258 #ifdef __cplusplus
259 } // extern "C"
260 } // namespace VirgilIoTKit
261 #endif
262 
263 #endif // VS_IOT_PROVISION_STRUCTS_H
vs_device_manufacture_id_t
uint8_t vs_device_manufacture_id_t[VS_DEVICE_MANUFACTURE_ID_SIZE]
Manufacture ID type.
Definition: provision-structs.h:120
VS_PRVS_SGNP
@ VS_PRVS_SGNP
Signature of own public key (by private key VS_PRVS_PBDM)
Definition: provision-structs.h:145
VS_PRVS_PBF2
@ VS_PRVS_PBF2
Set Firmware Key 2.
Definition: provision-structs.h:153
VS_PRVS_DNID
@ VS_PRVS_DNID
Discover Not Initialized Devices.
Definition: provision-structs.h:144
vs_pubkey_dated_t
Public key with date information.
Definition: provision-structs.h:209
VS_PRVS_ASGN
@ VS_PRVS_ASGN
Action SiGN data.
Definition: provision-structs.h:159
VS_PRVS_TLH
@ VS_PRVS_TLH
Set Trust List Header.
Definition: provision-structs.h:154
vs_provision_tl_find_ctx_t::key_type
vs_key_type_e key_type
Definition: provision-structs.h:238
VS_PROVISION_PBT1
@ VS_PROVISION_PBT1
Definition: provision-structs.h:170
vs_provision_events_t::tl_ver_info_cb
vs_file_ver_info_cb_t tl_ver_info_cb
Definition: provision-structs.h:255
vs_key_type_e
vs_key_type_e
Key type.
Definition: provision-structs.h:177
vs_snap_prvs_element_e
vs_snap_prvs_element_e
Provision operations.
Definition: provision-structs.h:143
vs_pubkey_t::ec_type
uint8_t ec_type
vs_secmodule_keypair_type_e
Definition: provision-structs.h:203
vs_file_info_t
File information.
Definition: provision-structs.h:225
VS_KEY_FIRMWARE
@ VS_KEY_FIRMWARE
Firmware key.
Definition: provision-structs.h:181
VS_PRVS_TLF
@ VS_PRVS_TLF
Set Trust List Footer.
Definition: provision-structs.h:156
VS_PROVISION_PBF1
@ VS_PROVISION_PBF1
Definition: provision-structs.h:172
VS_PRVS_PBR2
@ VS_PRVS_PBR2
Set Recovery Key 2.
Definition: provision-structs.h:147
VS_PRVS_PBA2
@ VS_PRVS_PBA2
Set Auth Key 2.
Definition: provision-structs.h:149
VS_PROVISION_PBR2
@ VS_PROVISION_PBR2
Definition: provision-structs.h:167
VS_DEVICE_MANUFACTURE_ID_SIZE
#define VS_DEVICE_MANUFACTURE_ID_SIZE
Manufacture ID size.
Definition: provision-structs.h:111
VS_PROVISION_SGNP
@ VS_PROVISION_SGNP
Definition: provision-structs.h:165
vs_pubkey_dated_t::expire_date
uint32_t expire_date
Expiration date.
Definition: provision-structs.h:211
VS_DEVICE_TYPE_SIZE
#define VS_DEVICE_TYPE_SIZE
Device type size.
Definition: provision-structs.h:114
VS_PRVS_DEVI
@ VS_PRVS_DEVI
Get DEVice Info.
Definition: provision-structs.h:157
VS_PRVS_PBF1
@ VS_PRVS_PBF1
Set Firmware Key 1.
Definition: provision-structs.h:152
vs_prvs_t
vs_prvs_t
PRVS SNAP service code.
Definition: provision-structs.h:140
VS_PRVS_PBT2
@ VS_PRVS_PBT2
Set Trust List 2.
Definition: provision-structs.h:151
vs_file_version_t
File version information.
Definition: provision-structs.h:216
vs_file_info_t::device_type
vs_device_type_t device_type
Device type.
Definition: provision-structs.h:227
VS_KEY_FIRMWARE_INTERNAL
@ VS_KEY_FIRMWARE_INTERNAL
Firmware internal key.
Definition: provision-structs.h:185
vs_device_type_t
uint8_t vs_device_type_t[VS_DEVICE_TYPE_SIZE]
Device type.
Definition: provision-structs.h:127
vs_file_ver_info_cb_t
void(* vs_file_ver_info_cb_t)(vs_file_version_t ver)
Callback function to inform system about current version of file.
Definition: provision-structs.h:248
VS_KEY_RECOVERY
@ VS_KEY_RECOVERY
Recovery key.
Definition: provision-structs.h:178
VS_PRVS_PBA1
@ VS_PRVS_PBA1
Set Auth Key 1.
Definition: provision-structs.h:148
vs_sign_t::signer_type
uint8_t signer_type
vs_key_type_e
Definition: provision-structs.h:193
VS_KEY_IOT_DEVICE
@ VS_KEY_IOT_DEVICE
Key of IoT device.
Definition: provision-structs.h:183
vs_pubkey_dated_t::pubkey
vs_pubkey_t pubkey
Public key.
Definition: provision-structs.h:212
VS_KEY_AUTH
@ VS_KEY_AUTH
Authentication key.
Definition: provision-structs.h:179
status_code.h
Status codes and macroses.
vs_file_info_t::version
vs_file_version_t version
File version.
Definition: provision-structs.h:228
vs_sign_t::ec_type
uint8_t ec_type
vs_secmodule_keypair_type_e
Definition: provision-structs.h:194
vs_provision_tl_find_ctx_t
Find context.
Definition: provision-structs.h:236
vs_sign_t::hash_type
uint8_t hash_type
vs_secmodule_hash_type_e
Definition: provision-structs.h:195
VS_PRVS_PBT1
@ VS_PRVS_PBT1
Set Trust List Key 1.
Definition: provision-structs.h:150
VS_KEY_AUTH_INTERNAL
@ VS_KEY_AUTH_INTERNAL
Authentication internal key.
Definition: provision-structs.h:186
VS_PRVS_PBR1
@ VS_PRVS_PBR1
Set Recovery Key 1.
Definition: provision-structs.h:146
VS_PROVISION_PBA1
@ VS_PROVISION_PBA1
Definition: provision-structs.h:168
HTONL_IN_COMPILE_TIME
#define HTONL_IN_COMPILE_TIME(val)
Definition: provision-structs.h:87
vs_file_version_t::patch
uint8_t patch
Patch number.
Definition: provision-structs.h:219
VS_KEY_TRUSTLIST
@ VS_KEY_TRUSTLIST
Trust List key.
Definition: provision-structs.h:180
vs_provision_tl_find_ctx_t::last_pos
int last_pos
Definition: provision-structs.h:237
VS_KEY_CLOUD
@ VS_KEY_CLOUD
Cloud key.
Definition: provision-structs.h:187
vs_pubkey_t::key_type
uint8_t key_type
vs_key_type_e
Definition: provision-structs.h:202
VS_PROVISION_PBT2
@ VS_PROVISION_PBT2
Definition: provision-structs.h:171
VS_PROVISION_PBA2
@ VS_PROVISION_PBA2
Definition: provision-structs.h:169
vs_file_info_t::manufacture_id
vs_device_manufacture_id_t manufacture_id
Manufacture ID.
Definition: provision-structs.h:226
VS_KEY_USER_DEVICE
@ VS_KEY_USER_DEVICE
Key ofr user device.
Definition: provision-structs.h:184
vs_pubkey_dated_t::start_date
uint32_t start_date
Start date.
Definition: provision-structs.h:210
vs_provision_element_id_e
vs_provision_element_id_e
Element ID.
Definition: provision-structs.h:164
VS_TL_STORAGE_MAX_PART_SIZE
#define VS_TL_STORAGE_MAX_PART_SIZE
Maximum size of each part of TrustList.
Definition: config/pc/trust_list-config.h:58
vs_file_version_t::timestamp
uint32_t timestamp
The number of seconds since VS_START_EPOCH.
Definition: provision-structs.h:221
VS_KEY_UNSUPPORTED
@ VS_KEY_UNSUPPORTED
Unsupported key.
Definition: provision-structs.h:188
VS_KEY_FACTORY
@ VS_KEY_FACTORY
Factory key.
Definition: provision-structs.h:182
VS_PRVS_ASAV
@ VS_PRVS_ASAV
Action SAVe provision.
Definition: provision-structs.h:158
vs_provision_events_t
Container of pointers to callback functions for Provision Events.
Definition: provision-structs.h:254
vs_pubkey_t::meta_data_sz
uint16_t meta_data_sz
Meta data size.
Definition: provision-structs.h:204
vs_pubkey_t
Public key type.
Definition: provision-structs.h:201
VS_DEVICE_SERIAL_SIZE
#define VS_DEVICE_SERIAL_SIZE
Device serial ID size.
Definition: provision-structs.h:108
vs_file_version_t::major
uint8_t major
Major version number.
Definition: provision-structs.h:217
VS_PROVISION_PBR1
@ VS_PROVISION_PBR1
Definition: provision-structs.h:166
vs_sign_t
Signature type.
Definition: provision-structs.h:192
VS_PROVISION_PBF2
@ VS_PROVISION_PBF2
Definition: provision-structs.h:173
VS_PRVS_SERVICE_ID
@ VS_PRVS_SERVICE_ID
Definition: provision-structs.h:140
vs_file_version_t::build
uint32_t build
Build number.
Definition: provision-structs.h:220
vs_device_serial_t
uint8_t vs_device_serial_t[VS_DEVICE_SERIAL_SIZE]
Device serial number type.
Definition: provision-structs.h:134
vs_file_version_t::minor
uint8_t minor
Minor version number.
Definition: provision-structs.h:218
VS_PRVS_TLC
@ VS_PRVS_TLC
Set Trust List Chunk.
Definition: provision-structs.h:155