Imported Upstream version 2.6.1
[platform/upstream/cryptsetup.git] / tests / fuzz / LUKS2_plain_JSON.proto
1 /*
2  * cryptsetup LUKS2 custom mutator
3  *
4  * Copyright (C) 2022-2023 Daniel Zatovic <daniel.zatovic@gmail.com>
5  * Copyright (C) 2022-2023 Red Hat, Inc. All rights reserved.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21
22 syntax = "proto2";
23
24 package json_proto;
25
26 // ---------------------------------------------------------------------------
27 // ----------------------------- GENERIC OBJECTS -----------------------------
28 // ---------------------------------------------------------------------------
29
30 message object_id {
31   oneof id {
32     // int_id will be mapped to range -16 to 16 (mod 33)
33     // this way iy should be easier to generate valid
34     // object cross-references
35     uint32 int_id = 1;
36     string string_id = 2;
37   }
38 }
39
40 message string_uint64 {
41   required bool negative = 1;
42   oneof number {
43     uint32 uint_num = 2;
44     string string_num = 3;
45   }
46 }
47
48 enum hash_algorithm {
49   HASH_ALG_SHA1 = 1;
50   HASH_ALG_SHA256 = 2;
51 }
52
53
54 // ---------------------------------------------------------------------------
55 // ----------------------------- BINARY HEADER -------------------------------
56 // ---------------------------------------------------------------------------
57
58 enum luks2_magic {
59   INVALID = 0;
60   FIRST = 1;
61   SECOND = 2;
62 }
63
64 enum luks_version {
65   ONE = 1;
66   TWO = 2;
67   THREE = 3;
68 }
69
70 // we limit the size to 64KiB to make the fuzzing faster
71 // because the checksum needs to be calculated for the whole image
72 enum hdr_size {
73   size_16_KB  = 16384;
74   size_32_KB  = 32768;
75   size_64_KB  = 65536;
76 //  size_128_KB = 131072;
77 //  size_256_KB = 262144;
78 //  size_512_KB = 524288;
79 //  size_1_MB   = 1048576;
80 //  size_2_MB   = 2097152;
81 //  size_4_MB   = 4194304;
82 }
83
84 enum seqid_description {
85   PRIMARY_GREATER = 0;
86   SECONDARY_GREATER = 1;
87   EQUAL = 2;
88 }
89
90 // message luks2_hdr_disk {
91 // char         magic[LUKS2_MAGIC_L];
92 // //uint16_t   version;        /* Version 2 */
93 // uint64_t     hdr_size;       /* in bytes, including JSON area */
94 // uint64_t     seqid;          /* increased on every update */
95 // char         label[LUKS2_LABEL_L];
96 // char         checksum_alg[LUKS2_CHECKSUM_ALG_L];
97 // uint8_t              salt[LUKS2_SALT_L]; /* unique for every header/offset */
98 // char         uuid[LUKS2_UUID_L];
99 // char         subsystem[LUKS2_LABEL_L]; /* owner subsystem label */
100 // uint64_t     hdr_offset;     /* offset from device start in bytes */
101 // char         _padding[184];
102 // uint8_t              csum[LUKS2_CHECKSUM_L];
103 // }
104 message LUKS2_header {
105   required luks_version version = 1;
106   required luks2_magic magic = 2;
107   required hdr_size hdr_size = 3;
108   required bool use_correct_checksum = 4;
109
110   optional uint64 selected_offset = 5;
111 }
112
113 message LUKS2_both_headers {
114   required LUKS2_header primary_header = 1;
115   required LUKS2_header secondary_header = 2;
116
117   required seqid_description seqid = 3;
118   required JsonObject json_area = 4;
119 }
120
121 message JsonObject {
122   required string name = 1;
123   required JsonValue value = 2;
124 }
125
126 message JsonValue {
127   oneof value {
128     // Json value types:
129
130     // null: null, will be used when 'oneof' contains nothing
131
132     // object: another json object of any type
133     JsonObject object_value = 1;
134
135     // array: an array of values
136     ArrayValue array_value = 2;
137
138     // number: can be an integer, a float, an exponent
139     NumberValue number_value = 3;
140
141     // string: unicode string
142     StringValue string_value = 4;
143
144     // boolean: true or talse
145     BooleanValue boolean_value = 5;
146   }
147 }
148
149 message ArrayValue {
150   repeated JsonValue value = 1;
151 }
152
153 message NumberInteger {
154   required int64 value = 1;
155 }
156
157 message NumberFloat {
158   required double value = 1;
159 }
160
161 message NumberExponent {
162   required int32 base = 1;
163   required int32 exponent = 2;
164   required bool use_uppercase = 3;
165 }
166
167 message NumberExponentFrac {
168   required float base = 1;
169   required int32 exponent = 2;
170   required bool use_uppercase = 3;
171 }
172
173 message NumberValue {
174   required NumberInteger integer_value = 1;
175
176   // integer_value is used when oneof field below has nothing.
177   oneof value {
178     NumberFloat float_value = 2;
179     NumberExponent exponent_value = 3;
180     NumberExponentFrac exponent_frac_value = 4;
181   }
182 }
183
184 message StringValue {
185   required string value = 1;
186 }
187
188 message BooleanValue {
189   required bool value = 1;
190 }