]> git.proxmox.com Git - ceph.git/blame - ceph/src/librbd/crypto/luks/LoadRequest.h
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / librbd / crypto / luks / LoadRequest.h
CommitLineData
f67539c2
TL
1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2// vim: ts=8 sw=2 smarttab
3
4#ifndef CEPH_LIBRBD_CRYPTO_LUKS_LOAD_REQUEST_H
5#define CEPH_LIBRBD_CRYPTO_LUKS_LOAD_REQUEST_H
6
1e59de90 7#include <string_view>
f67539c2
TL
8#include "include/rbd/librbd.hpp"
9#include "librbd/ImageCtx.h"
10#include "librbd/crypto/CryptoInterface.h"
11#include "librbd/crypto/luks/Header.h"
12
13namespace librbd {
14
15class ImageCtx;
16
17namespace crypto {
18namespace luks {
19
20// max header size in LUKS1/2 (excl. keyslots) is 4MB
21const uint64_t MAXIMUM_HEADER_SIZE = 4 * 1024 * 1024;
22// default header size in LUKS2 2 X 16KB + 1 X 256KB keyslot
23const uint64_t DEFAULT_INITIAL_READ_SIZE = 288 * 1024;
24
25template <typename I>
26class LoadRequest {
27public:
28 static LoadRequest* create(
1e59de90
TL
29 I* image_ctx, encryption_format_t format,
30 std::string_view passphrase,
31 std::unique_ptr<CryptoInterface>* result_crypto,
32 std::string* detected_format_name,
33 Context* on_finish) {
34 return new LoadRequest(image_ctx, format, passphrase, result_crypto,
35 detected_format_name, on_finish);
f67539c2
TL
36 }
37
38 LoadRequest(I* image_ctx, encryption_format_t format,
1e59de90
TL
39 std::string_view passphrase,
40 std::unique_ptr<CryptoInterface>* result_crypto,
41 std::string* detected_format_name, Context* on_finish);
f67539c2
TL
42 void send();
43 void finish(int r);
44 void set_initial_read_size(uint64_t read_size);
45
46private:
47 I* m_image_ctx;
48 encryption_format_t m_format;
1e59de90 49 std::string_view m_passphrase;
f67539c2
TL
50 Context* m_on_finish;
51 ceph::bufferlist m_bl;
1e59de90
TL
52 std::unique_ptr<CryptoInterface>* m_result_crypto;
53 std::string* m_detected_format_name;
f67539c2
TL
54 uint64_t m_initial_read_size;
55 Header m_header;
56 uint64_t m_offset;
57
58 void read(uint64_t end_offset, Context* on_finish);
59 bool handle_read(int r);
60 void handle_read_header(int r);
61 void handle_read_keyslots(int r);
62 void read_volume_key();
63};
64
65} // namespace luks
66} // namespace crypto
67} // namespace librbd
68
69extern template class librbd::crypto::luks::LoadRequest<librbd::ImageCtx>;
70
71#endif // CEPH_LIBRBD_CRYPTO_LUKS_LOAD_REQUEST_H