libcontrac
A library for contact tracing
|
Daily Tracing Key functionality. More...
Files | |
file | dtk.c |
Daily Tracing Key functionality. | |
file | dtk.h |
Daily Tracing Key functionality. | |
Data Structures | |
struct | Dtk |
The structure used to represent a Daily Tracing Key. More... | |
Macros | |
#define | DTK_INFO_PREFIX "CT-DTK" |
#define | DTK_SIZE (16) |
#define | DTK_SIZE_BASE64 (24) |
Functions | |
Dtk * | dtk_new () |
void | dtk_delete (Dtk *data) |
bool | dtk_generate_daily_key (Dtk *data, Contrac const *contrac, uint32_t day_number) |
unsigned char const * | dtk_get_daily_key (Dtk const *data) |
uint32_t | dtk_get_day_number (Dtk const *data) |
void | dtk_assign (Dtk *data, unsigned char const *dtk_bytes, uint32_t day_number) |
Daily Tracing Key functionality.
This class is used to generate and manage the Daily Tracing Key (DTK). It's largely internal. The functionality from Contrac should generally be used in preference to this.
#define DTK_INFO_PREFIX "CT-DTK" |
Used internally.
This is the prefix for the Info parameter provided to the HKDF and used to generate the DTK.
#define DTK_SIZE (16) |
The size in bytes of a DTK in binary format.
#define DTK_SIZE_BASE64 (24) |
The size in bytes of a DTK in base64 format, not including the null terminator.
void dtk_assign | ( | Dtk * | data, |
unsigned char const * | dtk_bytes, | ||
uint32_t | day_number | ||
) |
Populates the data structure.
Allows the DTK and day number values of the object to be set explicitly.
For internal use. To set the DTK it generally makes more sense to use one of eiher contrac_set_day_number() or contrac_update_current_time() instead.
The dtk_bytes buffer passed in must contain exactly DTK_SIZE (16) bytes of data. It doen't have to be null terminated.
data | The context object to work with. |
dtk_bytes | The DTK value to set, in binary format. |
day_number | The day number to associate with this DTK. |
void dtk_delete | ( | Dtk * | data | ) |
Deletes an instance of the class, freeing up the memory allocated to it.
data | The instance to free. |
bool dtk_generate_daily_key | ( | Dtk * | data, |
Contrac const * | contrac, | ||
uint32_t | day_number | ||
) |
Generates a Daily Tracing Key based on the day number provided.
The operation may fail under certain circumstances, such as if the HKDF operation fails for some reason.
For internal use. It generally makes more sense to use the contrac_set_day_number() function instead.
data | The context object to work with. |
day_number | The day number to use to generate the key. |
unsigned char const * dtk_get_daily_key | ( | Dtk const * | data | ) |
Gets the Daily Tracing Key for the device in binary format.
For internal use. It generally makes more sense to use the contrac_get_daily_key() function instead.
This allows the Daily Tracing Key to be extracted. The Daily Tracing Key should be kept secret (to maintain privacy) until a positive test is confirmed, at which point the user may choose to upload the key to a Diagnosis Server, so that others can be notified.
The buffer returned will contain exactly DTK_SIZE (16) bytes of data in binary format. This may therefore contain null bytes, and the buffer will not necessarily be null terminated. Future operations may cause the data to change, so the caller should make a copy of the buffer rather than keeping a pointer to it.
data | The context object to work with. |
uint32_t dtk_get_day_number | ( | Dtk const * | data | ) |
Gets the day number that applies to the current DTK.
For internal use. It generally makes more sense to use the contrac_get_day_number() function instead.
data | The context object to work with. |
Dtk * dtk_new | ( | ) |
Creates a new instance of the class.