suit.h
1 /*
2  * Copyright (C) 2019 Koen Zandberg
3  * 2019 Kaspar Schleiser <kaspar@schleiser.de>
4  *
5  * This file is subject to the terms and conditions of the GNU Lesser
6  * General Public License v2.1. See the file LICENSE in the top level
7  * directory for more details.
8  */
22 #ifndef SUIT_V4_SUIT_H
23 #define SUIT_V4_SUIT_H
24 
25 #include <stddef.h>
26 #include <stdint.h>
27 
28 #include "cose/sign.h"
29 #include "nanocbor/nanocbor.h"
30 #include "uuid.h"
31 #include "riotboot/flashwrite.h"
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
40 #ifndef SUIT_COSE_BUF_SIZE
41 #define SUIT_COSE_BUF_SIZE (512U)
42 #endif
43 
47 #define SUIT_V4_COMPONENT_MAX (1U)
48 
52 #define SUIT_MANIFEST_VERSION (4)
53 
60 #define SUIT_VERSION (1)
61 
65 typedef enum {
66  SUIT_OK = 0,
75 
82 typedef enum {
88 
95 typedef enum {
101 
108 enum {
112 };
113 
117 typedef struct {
118  uint32_t size;
119  nanocbor_value_t identifier;
120  nanocbor_value_t url;
121  nanocbor_value_t digest;
123 
127 typedef struct {
128  cose_sign_dec_t verify;
129  const uint8_t *buf;
130  size_t len;
131  uint32_t validated;
132  uint32_t state;
136  unsigned components_len;
140  uint8_t validation_buf[SUIT_COSE_BUF_SIZE];
141  cose_key_t *key;
142  char *urlbuf;
143  size_t urlbuf_len;
145 
149 #define SUIT_MANIFEST_HAVE_COMPONENTS (0x1)
150 
153 #define SUIT_MANIFEST_HAVE_IMAGE (0x2)
154 
168 int suit_v4_parse(suit_v4_manifest_t *manifest, const uint8_t *buf, size_t len);
169 
179 
189 int suit_cbor_map_iterate_init(nanocbor_value_t *map, nanocbor_value_t *it);
190 
201 int suit_cbor_map_iterate(nanocbor_value_t *it, nanocbor_value_t *key, nanocbor_value_t *value);
202 
212 int suit_cbor_get_int32(nanocbor_value_t *it, int32_t *out);
213 
224 int suit_cbor_get_uint(nanocbor_value_t *it, unsigned *out);
225 
236 int suit_cbor_get_uint32(nanocbor_value_t *it, uint32_t *out);
237 
248 int suit_cbor_get_string(nanocbor_value_t *it, const uint8_t **buf, size_t *len);
249 
260 int suit_cbor_subparse(nanocbor_value_t *bseq, nanocbor_value_t *it);
261 
274 int suit_flashwrite_helper(void *arg, size_t offset, uint8_t *buf, size_t len,
275  int more);
276 
277 #ifdef __cplusplus
278 }
279 #endif
280 
281 #endif /* SUIT_V4_SUIT_H */
282 
int suit_cbor_get_uint(nanocbor_value_t *it, unsigned *out)
Get cbor value as unsigned.
Unsupported SUIT feature detected.
Definition: suit.h:68
Unexpected CBOR structure detected.
Definition: suit.h:67
Unable to verify signature.
Definition: suit.h:73
Identifier component.
Definition: suit.h:109
riotboot_flashwrite_t * writer
Pointer to the riotboot flash writer.
Definition: suit.h:138
int suit_cbor_map_iterate(nanocbor_value_t *it, nanocbor_value_t *key, nanocbor_value_t *value)
Iterate over a cbor map container.
Installed firmware digest.
Definition: suit.h:97
int suit_cbor_get_string(nanocbor_value_t *it, const uint8_t **buf, size_t *len)
Get cbor value as string.
size_t urlbuf_len
Length of the manifest url.
Definition: suit.h:143
int suit_cbor_get_uint32(nanocbor_value_t *it, uint32_t *out)
Get cbor value as unsigned long.
uint32_t state
bitfield holding state information
Definition: suit.h:132
RFC 4122 UUID functions
#define SUIT_COSE_BUF_SIZE
Buffer size used for Cose.
Definition: suit.h:41
SHA384.
Definition: suit.h:85
unsigned components_len
Current number of components.
Definition: suit.h:136
No digest algo supplied.
Definition: suit.h:83
riotboot flash writing module
int suit_v4_policy_check(suit_v4_manifest_t *manifest)
Check a manifest policy.
Digest component.
Definition: suit.h:111
suit_v4_digest_t
SUIT payload digest algorithms.
Definition: suit.h:82
SHA512.
Definition: suit.h:86
nanocbor_value_t identifier
Identifier.
Definition: suit.h:119
size_t len
length of the manifest
Definition: suit.h:130
int suit_cbor_get_int32(nanocbor_value_t *it, int32_t *out)
Get cbor value as int32_t.
suit_v4_error_t
SUIT error codes.
Definition: suit.h:65
suit_v4_digest_type_t
SUIT payload digest types.
Definition: suit.h:95
Size component.
Definition: suit.h:110
#define SUIT_V4_COMPONENT_MAX
Maximum number of components used for SUIT v4.
Definition: suit.h:47
Manifest parsed and validated.
Definition: suit.h:66
int suit_cbor_map_iterate_init(nanocbor_value_t *map, nanocbor_value_t *it)
Initialize a cbor iterator for SUIT cbor map container parsing.
cose_sign_dec_t verify
COSE signature validation struct.
Definition: suit.h:128
nanocbor_value_t digest
Digest.
Definition: suit.h:121
SUIT v4 component struct.
Definition: suit.h:117
uint32_t validated
bitfield of validated policies
Definition: suit.h:131
int suit_flashwrite_helper(void *arg, size_t offset, uint8_t *buf, size_t len, int more)
Helper function for writing bytes on flash a specified offset.
Ciphertext digest.
Definition: suit.h:98
const uint8_t * buf
ptr to the buffer of the manifest
Definition: suit.h:129
Pre-image digest.
Definition: suit.h:99
Sequence number less or equal to current sequence number.
Definition: suit.h:71
int suit_cbor_subparse(nanocbor_value_t *bseq, nanocbor_value_t *it)
Parser a cbor subsequence.
uint32_t size
Size.
Definition: suit.h:118
Conditionals evaluate to false.
Definition: suit.h:70
cose_key_t * key
Ptr to the public key for validation.
Definition: suit.h:141
Raw payload digest.
Definition: suit.h:96
int32_t component_current
Current component index.
Definition: suit.h:137
SUIT manifest struct.
Definition: suit.h:127
Unsupported manifest features detected.
Definition: suit.h:69
firmware update state structure
Definition: flashwrite.h:63
int suit_v4_parse(suit_v4_manifest_t *manifest, const uint8_t *buf, size_t len)
Parse a manifest.
nanocbor_value_t url
Url.
Definition: suit.h:120
char * urlbuf
Buffer containing the manifest url.
Definition: suit.h:142
SHA256.
Definition: suit.h:84