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 "include/ceph_assert.h"
9 #include <boost/lockfree/queue.hpp>
15 class CryptoContextPool
: public DataCryptor
<T
> {
18 CryptoContextPool(DataCryptor
<T
>* data_cryptor
, uint32_t pool_size
);
21 T
* get_context(CipherMode mode
) override
;
22 void return_context(T
* ctx
, CipherMode mode
) override
;
24 inline uint32_t get_block_size() const override
{
25 return m_data_cryptor
->get_block_size();
27 inline uint32_t get_iv_size() const override
{
28 return m_data_cryptor
->get_iv_size();
30 inline int get_key_length() const override
{
31 return m_data_cryptor
->get_key_length();
33 inline const unsigned char* get_key() const override
{
34 return m_data_cryptor
->get_key();
36 inline int init_context(T
* ctx
, const unsigned char* iv
,
37 uint32_t iv_length
) const override
{
38 return m_data_cryptor
->init_context(ctx
, iv
, iv_length
);
40 inline int update_context(T
* ctx
, const unsigned char* in
,
42 uint32_t len
) const override
{
43 return m_data_cryptor
->update_context(ctx
, in
, out
, len
);
46 using ContextQueue
= boost::lockfree::queue
<T
*>;
49 DataCryptor
<T
>* m_data_cryptor
;
50 ContextQueue m_encrypt_contexts
;
51 ContextQueue m_decrypt_contexts
;
53 inline ContextQueue
& get_contexts(CipherMode mode
) {
56 return m_encrypt_contexts
;
58 return m_decrypt_contexts
;
68 #endif // CEPH_LIBRBD_CRYPTO_CRYPTO_CONTEXT_POOL_H