-
Notifications
You must be signed in to change notification settings - Fork 80
/
hazmat.h
70 lines (57 loc) · 2.41 KB
/
hazmat.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
* Low level API for Daan Sprenkels' Shamir secret sharing library
* Copyright (c) 2017 Daan Sprenkels <[email protected]>
*
* Usage of this API is hazardous and is only reserved for beings with a
* good understanding of the Shamir secret sharing scheme and who know how
* crypto code is implemented. If you are unsure about this, use the
* intermediate level API. You have been warned!
*/
#ifndef sss_HAZMAT_H_
#define sss_HAZMAT_H_
#include <inttypes.h>
#define sss_KEYSHARE_LEN 33 /* 1 + 32 */
/*
* One share of a cryptographic key which is shared using Shamir's
* the `sss_create_keyshares` function.
*/
typedef uint8_t sss_Keyshare[sss_KEYSHARE_LEN];
/*
* Share the secret given in `key` into `n` shares with a treshold value given
* in `k`. The resulting shares are written to `out`.
*
* The share generation that is done in this function is only secure if the key
* that is given is indeed a cryptographic key. This means that it should be
* randomly and uniformly generated string of 32 bytes.
*
* Also, for performance reasons, this function assumes that both `n` and `k`
* are *public* values.
*
* If you are looking for a function that *just* creates shares of arbitrary
* data, you should use the `sss_create_shares` function in `sss.h`.
*/
void sss_create_keyshares(sss_Keyshare *out,
const uint8_t key[32],
uint8_t n,
uint8_t k);
/*
* Combine the `k` shares provided in `shares` and write the resulting key to
* `key`. The amount of shares used to restore a secret may be larger than the
* threshold needed to restore them.
*
* This function does *not* do *any* checking for integrity. If any of the
* shares not original, this will result in an invalid resored value.
* All values written to `key` should be treated as secret. Even if some of the
* shares that were provided as input were incorrect, the resulting key *still*
* allows an attacker to gain information about the real key.
*
* This function treats `shares` and `key` as secret values. `k` is treated as
* a public value (for performance reasons).
*
* If you are looking for a function that combines shares of arbitrary
* data, you should use the `sss_combine_shares` function in `sss.h`.
*/
void sss_combine_keyshares(uint8_t key[32],
const sss_Keyshare *shares,
uint8_t k);
#endif /* sss_HAZMAT_H_ */