Imported Upstream version 2.6.1
[platform/upstream/cryptsetup.git] / tests / fuzz / plain_json_proto_to_luks2_converter.h
1 /*
2  * cryptsetup LUKS2 custom mutator fuzz target
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 #ifndef LUKS2_PROTO_CONVERTER_H_
23 #define LUKS2_PROTO_CONVERTER_H_
24
25 #include <sstream>
26 #include <string>
27 #include <json-c/json.h>
28
29 #include "LUKS2_plain_JSON.pb.h"
30 extern "C" {
31 #include "crypto_backend/crypto_backend.h"
32 }
33
34 namespace json_proto {
35
36 class LUKS2ProtoConverter {
37   public:
38     ~LUKS2ProtoConverter();
39     void create_jobj(const LUKS2_both_headers &headers, uint64_t hdr_size);
40     void convert(const LUKS2_both_headers &headers, int fd);
41     void create_jobj(const LUKS2_both_headers &headers);
42     void emit_luks2_binary_header(const LUKS2_header &header_proto, int fd, uint64_t offset, uint64_t seqid, const std::string &json_text);
43
44     void set_write_headers_only(bool headers_only);
45
46     const uint8_t *get_out_buffer();
47     size_t get_out_size();
48
49     static const uint64_t KEYSLOTS_SIZE = 3 * 1024 * 1024;
50     static const uint64_t DATA_SIZE = 16 * 1024 * 1024;
51   private:
52     bool write_headers_only = false;
53     struct crypt_hash *hd = NULL;
54 };
55
56 }  // namespace LUKS2_proto
57
58 #endif  // LUKS2_PROTO_CONVERTER_H_