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)    37 #define DEVICE_KEY_16BYTE 16    38 #define DEVICE_KEY_32BYTE 32    40 enum DeviceKeyStatus {
    41     DEVICEKEY_SUCCESS                     =  0,
    42     DEVICEKEY_INVALID_KEY_SIZE            = -1,
    43     DEVICEKEY_INVALID_KEY_TYPE            = -2,
    44     DEVICEKEY_SAVE_FAILED                 = -3,
    45     DEVICEKEY_ALREADY_EXIST               = -4,
    46     DEVICEKEY_NOT_FOUND                   = -5,
    47     DEVICEKEY_READ_FAILED                 = -6,
    48     DEVICEKEY_KVSTORE_UNPREDICTED_ERROR   = -7,
    49     DEVICEKEY_ERR_CMAC_GENERIC_FAILURE    = -8,
    50     DEVICEKEY_BUFFER_TOO_SMALL            = -9,
    51     DEVICEKEY_NO_KEY_INJECTED             = -10,
    52     DEVICEKEY_INVALID_PARAM               = -11,
    53     DEVICEKEY_GENERATE_RANDOM_ERROR       = -12,
    92     int generate_derived_key(
const unsigned char *isalt, 
size_t isalt_size, 
unsigned char *output, uint16_t ikey_type);
   112     int read_key_from_kvstore(uint32_t *output, 
size_t &size);
   119     int write_key_to_kvstore(uint32_t *input, 
size_t isize);
   131     int get_derived_key(uint32_t *ikey_buff, 
size_t ikey_size, 
const unsigned char *isalt, 
size_t isalt_size,
   132                         unsigned char *output, uint32_t ikey_type);
   143     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. 
 
Use this singleton if you need to derive a new key from the device root of trust. ...