]> git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/crypto/CryptoContextPool.h
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / librbd / crypto / CryptoContextPool.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_CRYPTO_CONTEXT_POOL_H
5 #define CEPH_LIBRBD_CRYPTO_CRYPTO_CONTEXT_POOL_H
6
7 #include "librbd/crypto/DataCryptor.h"
8 #include "common/allocator.h"
9 #include "include/ceph_assert.h"
10 #include <boost/lockfree/queue.hpp>
11
12 namespace librbd {
13 namespace crypto {
14
15 template <typename T>
16 class CryptoContextPool : public DataCryptor<T> {
17
18 public:
19 CryptoContextPool(DataCryptor<T>* data_cryptor, uint32_t pool_size);
20 ~CryptoContextPool();
21
22 T* get_context(CipherMode mode) override;
23 void return_context(T* ctx, CipherMode mode) override;
24
25 inline uint32_t get_block_size() const override {
26 return m_data_cryptor->get_block_size();
27 }
28 inline uint32_t get_iv_size() const override {
29 return m_data_cryptor->get_iv_size();
30 }
31 inline int get_key_length() const override {
32 return m_data_cryptor->get_key_length();
33 }
34 inline const unsigned char* get_key() const override {
35 return m_data_cryptor->get_key();
36 }
37 inline int init_context(T* ctx, const unsigned char* iv,
38 uint32_t iv_length) const override {
39 return m_data_cryptor->init_context(ctx, iv, iv_length);
40 }
41 inline int update_context(T* ctx, const unsigned char* in,
42 unsigned char* out,
43 uint32_t len) const override {
44 return m_data_cryptor->update_context(ctx, in, out, len);
45 }
46
47 typedef boost::lockfree::queue<
48 T*,
49 boost::lockfree::allocator<ceph::allocator<void>>> ContextQueue;
50
51 private:
52 DataCryptor<T>* m_data_cryptor;
53 ContextQueue m_encrypt_contexts;
54 ContextQueue m_decrypt_contexts;
55
56 inline ContextQueue& get_contexts(CipherMode mode) {
57 switch(mode) {
58 case CIPHER_MODE_ENC:
59 return m_encrypt_contexts;
60 case CIPHER_MODE_DEC:
61 return m_decrypt_contexts;
62 default:
63 ceph_assert(false);
64 }
65 }
66 };
67
68 } // namespace crypto
69 } // namespace librbd
70
71 #endif // CEPH_LIBRBD_CRYPTO_CRYPTO_CONTEXT_POOL_H