16 #ifndef MBED_DEVICEKEY_H 17 #define MBED_DEVICEKEY_H 21 #include "platform/NonCopyable.h" 23 #define DEVICEKEY_ENABLED 1 27 #if !DEVICE_FLASH || !defined(COMPONENT_FLASHIAP) 28 #undef DEVICEKEY_ENABLED 29 #define DEVICEKEY_ENABLED 0 32 #if (DEVICEKEY_ENABLED) || defined(DOXYGEN_ONLY) 41 #define DEVICE_KEY_16BYTE 16 42 #define DEVICE_KEY_32BYTE 32 44 enum DeviceKeyStatus {
45 DEVICEKEY_SUCCESS = 0,
46 DEVICEKEY_INVALID_KEY_SIZE = -1,
47 DEVICEKEY_INVALID_KEY_TYPE = -2,
48 DEVICEKEY_SAVE_FAILED = -3,
49 DEVICEKEY_ALREADY_EXIST = -4,
50 DEVICEKEY_NOT_FOUND = -5,
51 DEVICEKEY_READ_FAILED = -6,
52 DEVICEKEY_KVSTORE_UNPREDICTED_ERROR = -7,
53 DEVICEKEY_ERR_CMAC_GENERIC_FAILURE = -8,
54 DEVICEKEY_BUFFER_TOO_SMALL = -9,
55 DEVICEKEY_NO_KEY_INJECTED = -10,
56 DEVICEKEY_INVALID_PARAM = -11,
57 DEVICEKEY_GENERATE_RANDOM_ERROR = -12,
100 int generate_derived_key(
const unsigned char *isalt,
size_t isalt_size,
unsigned char *output, uint16_t ikey_type);
120 int read_key_from_kvstore(uint32_t *output,
size_t &size);
127 int write_key_to_kvstore(uint32_t *input,
size_t isize);
139 int get_derived_key(uint32_t *ikey_buff,
size_t ikey_size,
const unsigned char *isalt,
size_t isalt_size,
140 unsigned char *output, uint32_t ikey_type);
151 int generate_key_by_random(uint32_t *output,
size_t size);
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.