3 libcontrac is an implementation of the Contact Tracing API.
5 See the draft specs: https://www.apple.com/covid19/contacttracing/
9 If you have autoconf you can install as follows.
22 #include "contrac/contrac.h"
23 #include "contrac/rpi.h"
24 #include "contrac/dtk.h"
25 #include "contrac/rpi_list.h"
26 #include "contrac/rpi_list.h"
27 #include "contrac/matches.h"
30 ### Broadcasting and uploading keys
32 Most of the functionality revolves around the Conrac structure.
34 Create and initialise the structure as follows. The day and interval number
35 should be set appropriately.
38 Contrac * contrac = contrac_new();
39 contrac_generate_tracing_key(contrac);
40 contrac_set_day_number(contrac, 23);
41 contrac_set_time_interval_number(contrac, 76);
44 Get the Rolling Proxmity Identifier for broadcast in Bluetooth beacons.
46 // Returns a buffer containing RPI_SIZE bytes of data
47 const unsigned char * rpi = contrac_get_proximity_id(contrac);
50 Get the Daily Tracing Key to upload to a Diagnosis Server in case of a positive
53 // Returns a buffer containing DTK_SIZE bytes of data
54 const unsigned char * dtk = contrac_get_daily_key(contrac);
57 ### Receiving and matching keys
59 Add RPIs captured via Bluetooth to an RPI list.
61 RpiList * rpis = rpi_list_new();
62 Rpi * rpi = rpi_new();
64 // Add captured bytes at given time
65 rpi_assign(rpi, captured_bytes, time_interval_number);
66 rpi_list_append(rpis, rpi);
69 Construct a list of DTKs from data downloaded from a Diagnosis Server.
71 DtkList * dtks = dtk_list_new();
72 Dtk * dtk = dtk_new();
74 // Add data downloaded from the server
75 dtk_assign(dtk, dtk_bytes, day_number);
76 dtk_list_append(dtks, dtk);
79 Having collected these two lists any matches can be tested for as follows.
82 MatchList * matches = match_list_new();
83 match_list_find_matches(matches, rpis, dtks);
85 if (match_list_count(matches) > 0) {
86 printf("Exposure identified, follow medical advice\n");
94 match_list_delete(matches);
95 rpi_list_delete(rpis);
96 dtk_list_delete(dtks);
97 contrac_delete(contrac);
102 Copyright (c) David Llewellyn-Jones, 2020
104 libcontrac is released under the GPL v2 Licence. Read COPYING for information on the license.
108 More information can be found at: https://www.flypig.co.uk/contrac
110 The source code can be obtained from git:
112 git clone git@www.flypig.org.uk:libcontrac
114 I can be contacted via one of the following.
116 * My website: https://www.flypig.co.uk
117 * Email: at david@flypig.co.uk