3 libcontrac is an implementation of the Apple/Google Contact Tracing API.
5 See the draft specs: https://www.apple.com/covid19/contacttracing/
9 If you have autoconf you can install as follows.
23 #include "contrac/contrac.h"
24 #include "contrac/rpi.h"
25 #include "contrac/dtk.h"
26 #include "contrac/rpi_list.h"
27 #include "contrac/rpi_list.h"
28 #include "contrac/matches.h"
31 ### Broadcasting and uploading keys
33 Most of the functionality is managed through the opaque `Contrac` structure.
35 Create and initialise the structure as follows. The update call updates the
36 Daily Tracing Key and Rolling Proximity Identifier based on the current time.
39 Contrac * contrac = contrac_new();
40 // Generates a random Tracing Key if one hasn't yet been set
41 contrac_update_current_time(data);
44 Get the Rolling Proximity Identifier for broadcast in Bluetooth beacons.
46 // Returns a buffer containing RPI_SIZE bytes of data
47 unsigned char const * 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 unsigned char const * 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 // Add bytes captured at a given time to the list
63 rpi_list_add_beacon(rpis, captured_bytes, time_interval_number);
66 Construct a list of DTKs using data downloaded from a Diagnosis Server.
68 DtkList * dtks = dtk_list_new();
69 // Add data downloaded from a Diagnosis Server to the list
70 dtk_list_add_diagnosis(dtks, dtk_bytes, day_number);
73 Having collected these two lists any matches can be tested for as follows.
76 MatchList * matches = match_list_new();
77 match_list_find_matches(matches, rpis, dtks);
79 if (match_list_count(matches) > 0) {
80 printf("Exposure identified, follow medical advice\n");
88 match_list_delete(matches);
89 rpi_list_delete(rpis);
90 dtk_list_delete(dtks);
91 contrac_delete(contrac);
96 Copyright (c) David Llewellyn-Jones, 2020
98 libcontrac is released under the GPL v2 Licence. Read COPYING for information on the license.
102 More information can be found at: https://www.flypig.co.uk/contrac
104 The source code can be obtained from git:
106 git clone git@www.flypig.org.uk:libcontrac
109 I can be contacted via one of the following.
111 * My website: https://www.flypig.co.uk
112 * Email: at david@flypig.co.uk