]> git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/crypto/luks/LUKSEncryptionFormat.h
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / librbd / crypto / luks / LUKSEncryptionFormat.h
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_ENCRYPTION_FORMAT_H
5 #define CEPH_LIBRBD_CRYPTO_LUKS_ENCRYPTION_FORMAT_H
6
7 #include <string_view>
8 #include "include/rbd/librbd.hpp"
9 #include "librbd/crypto/CryptoInterface.h"
10 #include "librbd/crypto/EncryptionFormat.h"
11
12 namespace librbd {
13
14 struct ImageCtx;
15
16 namespace crypto {
17 namespace luks {
18
19 template <typename ImageCtxT>
20 class EncryptionFormat : public crypto::EncryptionFormat<ImageCtxT> {
21 public:
22 void flatten(ImageCtxT* ictx, Context* on_finish) override;
23
24 CryptoInterface* get_crypto() override {
25 ceph_assert(m_crypto);
26 return m_crypto.get();
27 }
28
29 protected:
30 std::unique_ptr<CryptoInterface> m_crypto;
31 };
32
33 template <typename ImageCtxT>
34 class LUKSEncryptionFormat : public EncryptionFormat<ImageCtxT> {
35 public:
36 LUKSEncryptionFormat(std::string_view passphrase)
37 : m_passphrase(passphrase) {}
38
39 std::unique_ptr<crypto::EncryptionFormat<ImageCtxT>> clone() const override {
40 return std::make_unique<LUKSEncryptionFormat>(m_passphrase);
41 }
42
43 void format(ImageCtxT* ictx, Context* on_finish) override;
44 void load(ImageCtxT* ictx, std::string* detected_format_name,
45 Context* on_finish) override;
46
47 private:
48 std::string_view m_passphrase;
49 };
50
51 template <typename ImageCtxT>
52 class LUKS1EncryptionFormat : public EncryptionFormat<ImageCtxT> {
53 public:
54 LUKS1EncryptionFormat(encryption_algorithm_t alg, std::string_view passphrase)
55 : m_alg(alg), m_passphrase(passphrase) {}
56
57 std::unique_ptr<crypto::EncryptionFormat<ImageCtxT>> clone() const override {
58 return std::make_unique<LUKS1EncryptionFormat>(m_alg, m_passphrase);
59 }
60
61 void format(ImageCtxT* ictx, Context* on_finish) override;
62 void load(ImageCtxT* ictx, std::string* detected_format_name,
63 Context* on_finish) override;
64
65 private:
66 encryption_algorithm_t m_alg;
67 std::string_view m_passphrase;
68 };
69
70 template <typename ImageCtxT>
71 class LUKS2EncryptionFormat : public EncryptionFormat<ImageCtxT> {
72 public:
73 LUKS2EncryptionFormat(encryption_algorithm_t alg, std::string_view passphrase)
74 : m_alg(alg), m_passphrase(passphrase) {}
75
76 std::unique_ptr<crypto::EncryptionFormat<ImageCtxT>> clone() const override {
77 return std::make_unique<LUKS2EncryptionFormat>(m_alg, m_passphrase);
78 }
79
80 void format(ImageCtxT* ictx, Context* on_finish) override;
81 void load(ImageCtxT* ictx, std::string* detected_format_name,
82 Context* on_finish) override;
83
84 private:
85 encryption_algorithm_t m_alg;
86 std::string_view m_passphrase;
87 };
88
89 } // namespace luks
90 } // namespace crypto
91 } // namespace librbd
92
93 extern template class librbd::crypto::luks::LUKSEncryptionFormat<
94 librbd::ImageCtx>;
95 extern template class librbd::crypto::luks::LUKS1EncryptionFormat<
96 librbd::ImageCtx>;
97 extern template class librbd::crypto::luks::LUKS2EncryptionFormat<
98 librbd::ImageCtx>;
99
100 #endif // CEPH_LIBRBD_CRYPTO_LUKS_ENCRYPTION_FORMAT_H