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 revolves around the opaque `Contrac` structure.
35 Create and initialise the structure as follows. The day and interval number
36 should be set appropriately.
39 Contrac * contrac = contrac_new();
40 contrac_generate_tracing_key(contrac);
41 contrac_set_day_number(contrac, 23);
42 contrac_set_time_interval_number(contrac, 76);
45 Get the Rolling Proximity Identifier for broadcast in Bluetooth beacons.
47 // Returns a buffer containing RPI_SIZE bytes of data
48 const unsigned char * rpi = contrac_get_proximity_id(contrac);
51 Get the Daily Tracing Key to upload to a Diagnosis Server in case of a positive
54 // Returns a buffer containing DTK_SIZE bytes of data
55 const unsigned char * dtk = contrac_get_daily_key(contrac);
58 ### Receiving and matching keys
60 Add RPIs captured via Bluetooth to an RPI list.
62 RpiList * rpis = rpi_list_new();
64 // Add bytes captured at a given time to the list
65 Rpi * rpi = rpi_new();
66 rpi_assign(rpi, captured_bytes, time_interval_number);
67 rpi_list_append(rpis, rpi);
70 Construct a list of DTKs from data downloaded from a Diagnosis Server.
72 DtkList * dtks = dtk_list_new();
74 // Add data downloaded from the server to the list
75 Dtk * dtk = dtk_new();
76 dtk_assign(dtk, dtk_bytes, day_number);
77 dtk_list_append(dtks, dtk);
80 Having collected these two lists any matches can be tested for as follows.
83 MatchList * matches = match_list_new();
84 match_list_find_matches(matches, rpis, dtks);
86 if (match_list_count(matches) > 0) {
87 printf("Exposure identified, follow medical advice\n");
95 match_list_delete(matches);
96 rpi_list_delete(rpis);
97 dtk_list_delete(dtks);
98 contrac_delete(contrac);
103 Copyright (c) David Llewellyn-Jones, 2020
105 libcontrac is released under the GPL v2 Licence. Read COPYING for information on the license.
109 More information can be found at: https://www.flypig.co.uk/contrac
111 The source code can be obtained from git:
113 git clone git@www.flypig.org.uk:libcontrac
116 I can be contacted via one of the following.
118 * My website: https://www.flypig.co.uk
119 * Email: at david@flypig.co.uk