aboutsummaryrefslogtreecommitdiff
path: root/trunnel/stfe.trunnel
blob: 8a26d92c324ce1f0c859768f78b46b03a59e012b (plain)
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/* always POST for consistency? */

const MAGIC_V1 = 0x535446455f5f5631; /* "STFE__V1" */

const T_GET_ENTRIES_V1 = 1;
const T_GET_PROOF_BY_HASH_V1 = 2;
const T_GET_CONSISTENCY_PROOF_V1 = 3;

const T_ENTRIES_V1 = 4;
const T_INCLUSION_PROOF_V1 = 5;
const T_CONSISTENCY_PROOF_V1 = 6;
const T_SIGNED_TREE_HEAD_V1 = 7;

struct req_get_entries_v1 {
  u64 start_size;
  u64 end_size;
};

struct req_get_proof_by_hash_v1 {
  u64 tree_size;
  u8 leaf_hash[32];
};

struct req_get_consistency_proof_v1 {
  u64 old_size;
  u64 new_size;
};

struct request_v1 {
  u64 magic IN [ MAGIC_V1 ];
  u64 format IN [ T_GET_ENTRIES_V1, T_GET_PROOF_BY_HASH_V1, T_GET_CONSISTENCY_PROOF_V1 ];

  union request[format] {
    T_GET_ENTRIES_V1: struct req_get_entries_v1 get_entries;
    T_GET_PROOF_BY_HASH_V1: struct req_get_proof_by_hash_v1 get_proof_by_hash;
    T_GET_CONSISTENCY_PROOF_V1: struct req_get_consistency_proof_v1 get_consistency_proof;
    default: fail;
  };
}	    

struct sigident_ed25519 {
  u8 signature[64];
  u8 identifier[32];
};

struct hash {
  u8 hash[32];
};

struct signed_checksum32_ed25519 {
  u8 checksum[32];
  u64 length IN [ 1..128 ];
  u8 identifier[length];
  u8 signature[64];
  u8 namespace[32];
};

struct entries_v1 {
  u64 magic IN [ MAGIC_V1 ];
  u64 format IN [ T_ENTRIES_V1 ];
  u64 n_items;
  struct signed_checksum32_ed25519 checksums[n_items];
};

struct inclusion_proof_v1 {
  u64 magic IN [ MAGIC_V1 ];
  u64 format IN [ T_INCLUSION_PROOF_V1 ];
  u8 identifier[32];
  u64 tree_size;
  u64 leaf_index;
  u64 n_items;
  struct hash hashes[n_items];
};

struct consistency_proof_v1 {
  u64 magic IN [ MAGIC_V1 ];
  u64 format IN [ T_CONSISTENCY_PROOF_V1 ];
  u8 identifier[32];
  u64 old_size;
  u64 new_size;
  u64 n_items;
  struct hash hashes[n_items];
};

struct signed_tree_head_v1 {
  u64 magic IN [ MAGIC_V1 ];
  u64 format IN [ T_SIGNED_TREE_HEAD_V1 ];
  u64 timestamp;
  u64 tree_size;
  u8 root_hash[32];
  u64 n_items;
  struct sigident_ed25519 signatures[n_items];
};