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 like this:
18 You can also run the unit tests and build the
19 [documentation](https://www.flypig.co.uk/docs/libcontrac/):
29 #include "contrac/contrac.h"
30 #include "contrac/rpi.h"
31 #include "contrac/dtk.h"
32 #include "contrac/rpi_list.h"
33 #include "contrac/rpi_list.h"
34 #include "contrac/matches.h"
37 ### Broadcasting and uploading keys
39 Most of the functionality is managed through the opaque `Contrac` structure.
41 Create and initialise the structure as follows. The update call updates the
42 Daily Tracing Key and Rolling Proximity Identifier based on the current time.
45 Contrac * contrac = contrac_new();
46 // Generates a random Tracing Key if one hasn't yet been set
47 contrac_update_current_time(data);
50 Get the Rolling Proximity Identifier for broadcast in Bluetooth beacons.
52 // Returns a buffer containing RPI_SIZE bytes of data
53 unsigned char const * rpi = contrac_get_proximity_id(contrac);
56 Get the Daily Tracing Key to upload to a Diagnosis Server in case of a positive
59 // Returns a buffer containing DTK_SIZE bytes of data
60 unsigned char const * dtk = contrac_get_daily_key(contrac);
63 ### Receiving and matching keys
65 Add RPIs captured via Bluetooth to an RPI list.
67 RpiList * rpis = rpi_list_new();
68 // Add bytes captured at a given time to the list
69 rpi_list_add_beacon(rpis, captured_bytes, time_interval_number);
72 Construct a list of DTKs using data downloaded from a Diagnosis Server.
74 DtkList * dtks = dtk_list_new();
75 // Add data downloaded from a Diagnosis Server to the list
76 dtk_list_add_diagnosis(dtks, dtk_bytes, day_number);
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 Library home page: https://www.flypig.co.uk/contrac
110 API documentation: https://www.flypig.co.uk/docs/libcontrac/
112 Source code from git:
114 git clone git@www.flypig.org.uk:libcontrac
117 I can be contacted via one of the following.
119 * My website: https://www.flypig.co.uk
120 * Email: at david@flypig.co.uk