17 #ifndef MBED_DEVICEKEY_H 18 #define MBED_DEVICEKEY_H 22 #include "platform/NonCopyable.h" 24 #define DEVICEKEY_ENABLED 1 28 #if !DEVICE_FLASH || !defined(COMPONENT_FLASHIAP) 29 #undef DEVICEKEY_ENABLED 30 #define DEVICEKEY_ENABLED 0 33 #if (DEVICEKEY_ENABLED) || defined(DOXYGEN_ONLY) 42 #define DEVICE_KEY_16BYTE 16 43 #define DEVICE_KEY_32BYTE 32 45 enum DeviceKeyStatus {
46 DEVICEKEY_SUCCESS = 0,
47 DEVICEKEY_INVALID_KEY_SIZE = -1,
48 DEVICEKEY_INVALID_KEY_TYPE = -2,
49 DEVICEKEY_SAVE_FAILED = -3,
50 DEVICEKEY_ALREADY_EXIST = -4,
51 DEVICEKEY_NOT_FOUND = -5,
52 DEVICEKEY_READ_FAILED = -6,
53 DEVICEKEY_KVSTORE_UNPREDICTED_ERROR = -7,
54 DEVICEKEY_ERR_CMAC_GENERIC_FAILURE = -8,
55 DEVICEKEY_BUFFER_TOO_SMALL = -9,
56 DEVICEKEY_NO_KEY_INJECTED = -10,
57 DEVICEKEY_INVALID_PARAM = -11,
58 DEVICEKEY_GENERATE_RANDOM_ERROR = -12,
101 int generate_derived_key(
const unsigned char *isalt,
size_t isalt_size,
unsigned char *output, uint16_t ikey_type);
134 int read_key_from_kvstore(uint32_t *output,
size_t &size);
141 int write_key_to_kvstore(uint32_t *input,
size_t isize);
153 int get_derived_key(uint32_t *ikey_buff,
size_t ikey_size,
const unsigned char *isalt,
size_t isalt_size,
154 unsigned char *output, uint32_t ikey_type);
static DeviceKey & get_instance()
As a singleton, return the single instance of the class.
int device_inject_root_of_trust(uint32_t *value, size_t isize)
Set a device key into the KVStore.
int generate_derived_key(const unsigned char *isalt, size_t isalt_size, unsigned char *output, uint16_t ikey_type)
Derive a new key based on the salt string.
Prevents generation of copy constructor and copy assignment operator in derived classes.
int generate_root_of_trust(size_t key_size=16)
Generate Root of Trust.