summaryrefslogtreecommitdiffstats
path: root/src/librbd/crypto/luks/LUKSEncryptionFormat.cc
blob: 1f92cf0f72849f0449f4e1dd25625b828205b6a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab

#include "LUKSEncryptionFormat.h"
#include "common/dout.h"
#include "common/errno.h"
#include "include/compat.h"
#include "librbd/crypto/luks/FlattenRequest.h"
#include "librbd/crypto/luks/FormatRequest.h"
#include "librbd/crypto/luks/LoadRequest.h"

#define dout_subsys ceph_subsys_rbd
#undef dout_prefix
#define dout_prefix *_dout << "librbd::crypto::luks::LUKSEncryptionFormat:: " \
                           << this << " " << __func__ << ": "

namespace librbd {
namespace crypto {
namespace luks {

template <typename I>
void EncryptionFormat<I>::flatten(I* image_ctx, Context* on_finish) {
  auto req = luks::FlattenRequest<I>::create(image_ctx, on_finish);
  req->send();
}

template <typename I>
void LUKSEncryptionFormat<I>::format(I* image_ctx, Context* on_finish) {
  lderr(image_ctx->cct) << "explicit LUKS version required for format" << dendl;
  on_finish->complete(-EINVAL);
}

template <typename I>
void LUKSEncryptionFormat<I>::load(I* image_ctx,
                                   std::string* detected_format_name,
                                   Context* on_finish) {
  auto req = luks::LoadRequest<I>::create(image_ctx, RBD_ENCRYPTION_FORMAT_LUKS,
                                          m_passphrase, &this->m_crypto,
                                          detected_format_name, on_finish);
  req->send();
}

template <typename I>
void LUKS1EncryptionFormat<I>::format(I* image_ctx, Context* on_finish) {
  auto req = luks::FormatRequest<I>::create(
      image_ctx, RBD_ENCRYPTION_FORMAT_LUKS1, m_alg, m_passphrase,
      &this->m_crypto, on_finish, false);
  req->send();
}

template <typename I>
void LUKS1EncryptionFormat<I>::load(I* image_ctx,
                                    std::string* detected_format_name,
                                    Context* on_finish) {
  auto req = luks::LoadRequest<I>::create(
      image_ctx, RBD_ENCRYPTION_FORMAT_LUKS1, m_passphrase, &this->m_crypto,
      detected_format_name, on_finish);
  req->send();
}

template <typename I>
void LUKS2EncryptionFormat<I>::format(I* image_ctx, Context* on_finish) {
  auto req = luks::FormatRequest<I>::create(
      image_ctx, RBD_ENCRYPTION_FORMAT_LUKS2, m_alg, m_passphrase,
      &this->m_crypto, on_finish, false);
  req->send();
}

template <typename I>
void LUKS2EncryptionFormat<I>::load(I* image_ctx,
                                    std::string* detected_format_name,
                                    Context* on_finish) {
  auto req = luks::LoadRequest<I>::create(
      image_ctx, RBD_ENCRYPTION_FORMAT_LUKS2, m_passphrase, &this->m_crypto,
      detected_format_name, on_finish);
  req->send();
}

} // namespace luks
} // namespace crypto
} // namespace librbd

template class librbd::crypto::luks::LUKSEncryptionFormat<librbd::ImageCtx>;
template class librbd::crypto::luks::LUKS1EncryptionFormat<librbd::ImageCtx>;
template class librbd::crypto::luks::LUKS2EncryptionFormat<librbd::ImageCtx>;