17#ifndef MBED_DEVICEKEY_H
18#define MBED_DEVICEKEY_H
22#include "platform/NonCopyable.h"
24#define DEVICEKEY_ENABLED 1
29#undef DEVICEKEY_ENABLED
30#define DEVICEKEY_ENABLED 0
33#if (DEVICEKEY_ENABLED) || defined(DOXYGEN_ONLY)
41#define DEVICE_KEY_16BYTE 16
42#define DEVICE_KEY_32BYTE 32
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,
97 int generate_derived_key(
const unsigned char *isalt,
size_t isalt_size,
unsigned char *output, uint16_t ikey_type);
130 int read_key_from_kvstore(uint32_t *output,
size_t &size);
137 int write_key_to_kvstore(uint32_t *input,
size_t isize);
149 int get_derived_key(uint32_t *ikey_buff,
size_t ikey_size,
const unsigned char *isalt,
size_t isalt_size,
150 unsigned char *output, uint32_t ikey_type);
Use this singleton if you need to derive a new key from the device root of trust.
int generate_root_of_trust(size_t key_size=16)
Generate Root of Trust.
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.
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.
Prevents generation of copy constructor and copy assignment operator in derived classes.