libcontrac
A library for contact tracing
Files | Data Structures | Macros | Functions
Daily Tracing Key

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)
 

Detailed Description

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.

Macro Definition Documentation

◆ DTK_INFO_PREFIX

#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.

◆ DTK_SIZE

#define DTK_SIZE   (16)

The size in bytes of a DTK in binary format.

◆ DTK_SIZE_BASE64

#define DTK_SIZE_BASE64   (24)

The size in bytes of a DTK in base64 format, not including the null terminator.

Function Documentation

◆ dtk_assign()

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.

Parameters
dataThe context object to work with.
dtk_bytesThe DTK value to set, in binary format.
day_numberThe day number to associate with this DTK.

◆ dtk_delete()

void dtk_delete ( Dtk *  data)

Deletes an instance of the class, freeing up the memory allocated to it.

Parameters
dataThe instance to free.

◆ dtk_generate_daily_key()

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.

Parameters
dataThe context object to work with.
day_numberThe day number to use to generate the key.
Returns
true if the operation completed successfully, false otherwise.

◆ dtk_get_daily_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.

Parameters
dataThe context object to work with.
Returns
The Daily Tracing Key in binary format, not null terminated.

◆ dtk_get_day_number()

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.

Parameters
dataThe context object to work with.
Returns
The day number stored in the object..

◆ dtk_new()

Dtk * dtk_new ( )

Creates a new instance of the class.

Returns
The newly created object.