1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #ifndef CEPH_LIBRBD_CRYPTO_LUKS_ENCRYPTION_FORMAT_H
5 #define CEPH_LIBRBD_CRYPTO_LUKS_ENCRYPTION_FORMAT_H
8 #include "include/rbd/librbd.hpp"
9 #include "librbd/crypto/CryptoInterface.h"
10 #include "librbd/crypto/EncryptionFormat.h"
19 template <typename ImageCtxT
>
20 class EncryptionFormat
: public crypto::EncryptionFormat
<ImageCtxT
> {
22 void flatten(ImageCtxT
* ictx
, Context
* on_finish
) override
;
24 CryptoInterface
* get_crypto() override
{
25 ceph_assert(m_crypto
);
26 return m_crypto
.get();
30 std::unique_ptr
<CryptoInterface
> m_crypto
;
33 template <typename ImageCtxT
>
34 class LUKSEncryptionFormat
: public EncryptionFormat
<ImageCtxT
> {
36 LUKSEncryptionFormat(std::string_view passphrase
)
37 : m_passphrase(passphrase
) {}
39 std::unique_ptr
<crypto::EncryptionFormat
<ImageCtxT
>> clone() const override
{
40 return std::make_unique
<LUKSEncryptionFormat
>(m_passphrase
);
43 void format(ImageCtxT
* ictx
, Context
* on_finish
) override
;
44 void load(ImageCtxT
* ictx
, std::string
* detected_format_name
,
45 Context
* on_finish
) override
;
48 std::string_view m_passphrase
;
51 template <typename ImageCtxT
>
52 class LUKS1EncryptionFormat
: public EncryptionFormat
<ImageCtxT
> {
54 LUKS1EncryptionFormat(encryption_algorithm_t alg
, std::string_view passphrase
)
55 : m_alg(alg
), m_passphrase(passphrase
) {}
57 std::unique_ptr
<crypto::EncryptionFormat
<ImageCtxT
>> clone() const override
{
58 return std::make_unique
<LUKS1EncryptionFormat
>(m_alg
, m_passphrase
);
61 void format(ImageCtxT
* ictx
, Context
* on_finish
) override
;
62 void load(ImageCtxT
* ictx
, std::string
* detected_format_name
,
63 Context
* on_finish
) override
;
66 encryption_algorithm_t m_alg
;
67 std::string_view m_passphrase
;
70 template <typename ImageCtxT
>
71 class LUKS2EncryptionFormat
: public EncryptionFormat
<ImageCtxT
> {
73 LUKS2EncryptionFormat(encryption_algorithm_t alg
, std::string_view passphrase
)
74 : m_alg(alg
), m_passphrase(passphrase
) {}
76 std::unique_ptr
<crypto::EncryptionFormat
<ImageCtxT
>> clone() const override
{
77 return std::make_unique
<LUKS2EncryptionFormat
>(m_alg
, m_passphrase
);
80 void format(ImageCtxT
* ictx
, Context
* on_finish
) override
;
81 void load(ImageCtxT
* ictx
, std::string
* detected_format_name
,
82 Context
* on_finish
) override
;
85 encryption_algorithm_t m_alg
;
86 std::string_view m_passphrase
;
93 extern template class librbd::crypto::luks::LUKSEncryptionFormat
<
95 extern template class librbd::crypto::luks::LUKS1EncryptionFormat
<
97 extern template class librbd::crypto::luks::LUKS2EncryptionFormat
<
100 #endif // CEPH_LIBRBD_CRYPTO_LUKS_ENCRYPTION_FORMAT_H