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_CRYPTO_CONTEXT_POOL_H
5 #define CEPH_LIBRBD_CRYPTO_CRYPTO_CONTEXT_POOL_H
7 #include "librbd/crypto/DataCryptor.h"
8 #include "common/allocator.h"
9 #include "include/ceph_assert.h"
10 #include <boost/lockfree/queue.hpp>
16 class CryptoContextPool
: public DataCryptor
<T
> {
19 CryptoContextPool(DataCryptor
<T
>* data_cryptor
, uint32_t pool_size
);
22 T
* get_context(CipherMode mode
) override
;
23 void return_context(T
* ctx
, CipherMode mode
) override
;
25 inline uint32_t get_block_size() const override
{
26 return m_data_cryptor
->get_block_size();
28 inline uint32_t get_iv_size() const override
{
29 return m_data_cryptor
->get_iv_size();
31 inline int get_key_length() const override
{
32 return m_data_cryptor
->get_key_length();
34 inline const unsigned char* get_key() const override
{
35 return m_data_cryptor
->get_key();
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
);
41 inline int update_context(T
* ctx
, const unsigned char* in
,
43 uint32_t len
) const override
{
44 return m_data_cryptor
->update_context(ctx
, in
, out
, len
);
47 typedef boost::lockfree::queue
<
49 boost::lockfree::allocator
<ceph::allocator
<void>>> ContextQueue
;
52 DataCryptor
<T
>* m_data_cryptor
;
53 ContextQueue m_encrypt_contexts
;
54 ContextQueue m_decrypt_contexts
;
56 inline ContextQueue
& get_contexts(CipherMode mode
) {
59 return m_encrypt_contexts
;
61 return m_decrypt_contexts
;
71 #endif // CEPH_LIBRBD_CRYPTO_CRYPTO_CONTEXT_POOL_H