23 #include "../detail/openssl.hpp"    25 #include <boost/lexical_cast.hpp>    36     , 
m_sink(BIO_new(BIO_s_mem()))
    52                          const uint8_t* key, 
size_t keyLen,
    53                          const uint8_t* iv, 
size_t ivLen)
    58     initializeAesCbc(key, keyLen, iv, ivLen, op);
    62                                 boost::lexical_cast<std::string>(algo) + 
" is not supported"));
    67 BlockCipher::preTransform()
    73 BlockCipher::convert(
const uint8_t* data, 
size_t dataLen)
    78   int wLen = BIO_write(m_impl->m_cipher, data, dataLen);
    81     if (!BIO_should_retry(m_impl->m_cipher)) {
    83       BOOST_THROW_EXCEPTION(
Error(
getIndex(), 
"Failed to accept more input"));
    94 BlockCipher::finalize()
    96   if (BIO_flush(m_impl->m_cipher) != 1)
    99   while (!isConverterEmpty()) {
   108 BlockCipher::fillOutputBuffer()
   110   int nRead = BIO_pending(m_impl->m_sink);
   115   auto buffer = make_unique<OBuffer>(nRead);
   116   int rLen = BIO_read(m_impl->m_sink, &(*buffer)[0], nRead);
   121     buffer->erase(buffer->begin() + rLen, buffer->end());
   126 BlockCipher::isConverterEmpty()
 const   128   return (BIO_pending(m_impl->m_sink) <= 0);
   132 BlockCipher::initializeAesCbc(
const uint8_t* key, 
size_t keyLen,
   133                               const uint8_t* iv, 
size_t ivLen,
   137     BOOST_THROW_EXCEPTION(
Error(
getIndex(), 
"Key length must be the same as IV length"));
   139   const EVP_CIPHER* cipherType = 
nullptr;
   142     cipherType = EVP_aes_128_cbc();
   145     cipherType = EVP_aes_192_cbc();
   148     cipherType = EVP_aes_256_cbc();
   151     BOOST_THROW_EXCEPTION(
Error(
getIndex(), 
"Key length is not supported"));
   153   BIO_set_cipher(m_impl->m_cipher, cipherType, key, iv, static_cast<int>(op));
   156 unique_ptr<Transform>
   158             const uint8_t* key, 
size_t keyLen,
   159             const uint8_t* iv, 
size_t ivLen)
   161   return make_unique<BlockCipher>(algo, op, key, keyLen, iv, ivLen);
 Copyright (c) 2011-2015 Regents of the University of California.