psa_crypto_cbor_encoder.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2023 HAW Hamburg
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
9 #pragma once
10 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
28 
33 #define CBOR_BUF_SIZE_START ( 1 + /* Array encoding */ \
34  1 + /* Array encoding */ \
35  1 + sizeof(psa_key_id_t) + \
36  1 + sizeof(psa_key_type_t) + \
37  1 + sizeof(psa_key_bits_t) + \
38  1 + sizeof(psa_key_lifetime_t) + \
39  1 + /* Array encoding */ \
40  1 + sizeof(psa_key_usage_t) + \
41  1 + sizeof(psa_algorithm_t) \
42  )
43 
44 #if PSA_SINGLE_KEY_COUNT
49 #define CBOR_BUF_SIZE_SINGLE_KEY ( CBOR_BUF_SIZE_START + \
50  3 + /* Bytestring encoding and size */ \
51  PSA_MAX_KEY_DATA_SIZE \
52  )
53 #endif /* PSA_SINGLE_KEY_COUNT */
54 
55 #if PSA_ASYMMETRIC_KEYPAIR_COUNT
60 #define CBOR_BUF_SIZE_KEY_PAIR ( CBOR_BUF_SIZE_START + \
61  1 + \
62  3 + PSA_BITS_TO_BYTES(PSA_MAX_PRIV_KEY_SIZE) + \
63  3 + PSA_EXPORT_PUBLIC_KEY_MAX_SIZE \
64  )
65 #endif /* PSA_ASYMMETRIC_KEYPAIR_COUNT */
66 
67 #if PSA_PROTECTED_KEY_COUNT && IS_USED(MODULE_PSA_ASYMMETRIC)
72 #define CBOR_BUF_SIZE_PROT_KEY ( CBOR_BUF_SIZE_START + \
73  1 + \
74  1 + sizeof(psa_key_slot_number_t) + \
75  3 + PSA_EXPORT_PUBLIC_KEY_MAX_SIZE \
76  )
77 #elif PSA_PROTECTED_KEY_COUNT
82 #define CBOR_BUF_SIZE_PROT_KEY ( CBOR_BUF_SIZE_START + \
83  1 + \
84  1 + sizeof(psa_key_slot_number_t) \
85  )
86 #endif /* PSA_PROTECTED_KEY_COUNT */
87 
117  size_t output_len, size_t *output_size);
118 
129  size_t cbor_buf_size);
130 
141  size_t cbor_buf_size);
142 
143 #ifdef __cplusplus
144 }
145 #endif
146 
psa_status_t psa_decode_key_slot_data(psa_key_slot_t *slot, uint8_t *cbor_buf, size_t cbor_buf_size)
Decode CBOR encoded key data and write to PSA key slot.
psa_status_t psa_decode_key_attributes(psa_key_attributes_t *attr, uint8_t *cbor_buf, size_t cbor_buf_size)
Decode CBOR PSA key attributes.
psa_status_t psa_encode_key_slot(psa_key_slot_t *slot, uint8_t *output, size_t output_len, size_t *output_size)
Encodes a basic key slot in CBOR.
int32_t psa_status_t
Status code type used for all PSA Certified APIs.
Definition: error.h:40
PSA key slot management function declarations.
Structure storing key attributes.
Definition: attributes.h:51
Structure of a virtual key slot in local memory.