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  */
30 #ifndef SUIT_H
31 #define SUIT_H
32 
33 #include <stddef.h>
34 #include <stdint.h>
35 
36 #include "cose/sign.h"
37 #include "nanocbor/nanocbor.h"
38 #include "uuid.h"
39 #include "riotboot/flashwrite.h"
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
48 #ifndef SUIT_COSE_BUF_SIZE
49 #define SUIT_COSE_BUF_SIZE (180U)
50 #endif
51 
55 #define SUIT_COMPONENT_MAX (1U)
56 
63 #define SUIT_VERSION (1)
64 
68 #define SUIT_STATE_COSE_AUTHENTICATED (1 << 1)
69 
73 #define SUIT_STATE_FULLY_AUTHENTICATED (1 << 2)
74 
78 typedef enum {
79  SUIT_OK = 0,
88 } suit_error_t;
89 
96 typedef enum {
101 } suit_digest_t;
102 
109 typedef enum {
115 
122 enum {
126 };
127 
131 typedef struct {
132  uint32_t size;
133  nanocbor_value_t identifier;
134  nanocbor_value_t url;
135  nanocbor_value_t digest;
137 
141 typedef struct {
142  const uint8_t *buf;
143  size_t len;
144  const uint8_t *cose_payload;
146  uint32_t validated;
147  uint32_t state;
150  unsigned components_len;
151  uint32_t component_current;
154  uint8_t validation_buf[SUIT_COSE_BUF_SIZE];
155  char *urlbuf;
156  size_t urlbuf_len;
158 
162 #define SUIT_MANIFEST_HAVE_COMPONENTS (0x1)
163 
166 #define SUIT_MANIFEST_HAVE_IMAGE (0x2)
167 
181 int suit_parse(suit_manifest_t *manifest, const uint8_t *buf, size_t len);
182 
191 int suit_policy_check(suit_manifest_t *manifest);
192 
205 int suit_flashwrite_helper(void *arg, size_t offset, uint8_t *buf, size_t len,
206  int more);
207 
208 #ifdef __cplusplus
209 }
210 #endif
211 
212 #endif /* SUIT_H */
213 
suit_error_t
SUIT error codes.
Definition: suit.h:78
uint32_t state
bitfield holding state information
Definition: suit.h:147
Unable to verify signature.
Definition: suit.h:86
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.
suit_digest_t
SUIT payload digest algorithms.
Definition: suit.h:96
suit_digest_type_t
SUIT payload digest types.
Definition: suit.h:109
char * urlbuf
Buffer containing the manifest url.
Definition: suit.h:155
const uint8_t * buf
ptr to the buffer of the manifest
Definition: suit.h:142
int suit_policy_check(suit_manifest_t *manifest)
Check a manifest policy.
size_t cose_payload_len
length of the COSE payload
Definition: suit.h:145
Digest component.
Definition: suit.h:125
unsigned components_len
Current number of components.
Definition: suit.h:150
nanocbor_value_t url
Url.
Definition: suit.h:134
RFC 4122 UUID functions
No digest algo supplied.
Definition: suit.h:97
Pre-image digest.
Definition: suit.h:113
riotboot flash writing module
int suit_parse(suit_manifest_t *manifest, const uint8_t *buf, size_t len)
Parse a manifest.
size_t len
length of the manifest
Definition: suit.h:143
size_t urlbuf_len
Length of the manifest url.
Definition: suit.h:156
#define SUIT_COSE_BUF_SIZE
Buffer size used for Cose.
Definition: suit.h:49
Identifier component.
Definition: suit.h:123
uint32_t component_current
Current component index.
Definition: suit.h:151
SUIT manifest struct.
Definition: suit.h:141
#define SUIT_COMPONENT_MAX
Maximum number of components supported in a SUIT manifest.
Definition: suit.h:55
Size component.
Definition: suit.h:124
SHA512.
Definition: suit.h:100
SUIT component struct.
Definition: suit.h:131
Unexpected CBOR structure detected.
Definition: suit.h:80
Raw payload digest.
Definition: suit.h:110
Ciphertext digest.
Definition: suit.h:112
SHA256.
Definition: suit.h:98
Manifest parsed and validated.
Definition: suit.h:79
Unsupported SUIT feature detected.
Definition: suit.h:81
riotboot_flashwrite_t * writer
Pointer to the riotboot flash writer.
Definition: suit.h:152
const uint8_t * cose_payload
ptr to the payload of the COSE sign
Definition: suit.h:144
Installed firmware digest.
Definition: suit.h:111
uint32_t size
Size.
Definition: suit.h:132
nanocbor_value_t identifier
Identifier.
Definition: suit.h:133
Sequence number less or equal to current sequence number.
Definition: suit.h:84
Unsupported features detected.
Definition: suit.h:82
Conditionals evaluate to false.
Definition: suit.h:83
SHA384.
Definition: suit.h:99
firmware update state structure
Definition: flashwrite.h:66
nanocbor_value_t digest
Digest.
Definition: suit.h:135
uint32_t validated
bitfield of validated policies
Definition: suit.h:146
Digest mismatch with COSE and SUIT.
Definition: suit.h:87