2018-08-12 18:07:22 +00:00
|
|
|
#ifndef PL_AES_PDF_HH
|
|
|
|
#define PL_AES_PDF_HH
|
2009-10-17 03:14:47 +00:00
|
|
|
|
|
|
|
#include <qpdf/Pipeline.hh>
|
2009-10-20 02:46:41 +00:00
|
|
|
#include <qpdf/qpdf-config.h>
|
2009-12-14 02:35:31 +00:00
|
|
|
#ifdef HAVE_STDINT_H
|
|
|
|
# include <stdint.h>
|
|
|
|
#endif
|
2009-10-17 03:14:47 +00:00
|
|
|
|
2012-12-28 02:37:57 +00:00
|
|
|
// This pipeline implements AES-128 and AES-256 with CBC and block
|
|
|
|
// padding as specified in the PDF specification.
|
2009-10-17 15:01:20 +00:00
|
|
|
|
2009-10-21 00:27:24 +00:00
|
|
|
class Pl_AES_PDF: public Pipeline
|
2009-10-17 03:14:47 +00:00
|
|
|
{
|
|
|
|
public:
|
2009-10-21 01:45:13 +00:00
|
|
|
QPDF_DLL
|
2012-12-28 02:37:57 +00:00
|
|
|
// key should be a pointer to key_bytes bytes of data
|
2009-10-17 03:14:47 +00:00
|
|
|
Pl_AES_PDF(char const* identifier, Pipeline* next,
|
2019-06-21 03:35:23 +00:00
|
|
|
bool encrypt, unsigned char const* key,
|
|
|
|
size_t key_bytes);
|
2009-10-21 01:45:13 +00:00
|
|
|
QPDF_DLL
|
2009-10-17 03:14:47 +00:00
|
|
|
virtual ~Pl_AES_PDF();
|
|
|
|
|
2009-10-21 01:45:13 +00:00
|
|
|
QPDF_DLL
|
2012-06-20 15:20:57 +00:00
|
|
|
virtual void write(unsigned char* data, size_t len);
|
2009-10-21 01:45:13 +00:00
|
|
|
QPDF_DLL
|
2009-10-17 03:14:47 +00:00
|
|
|
virtual void finish();
|
|
|
|
|
2012-12-28 02:37:57 +00:00
|
|
|
// Use zero initialization vector; needed for AESV3
|
|
|
|
QPDF_DLL
|
|
|
|
void useZeroIV();
|
|
|
|
// Disable padding; needed for AESV3
|
|
|
|
QPDF_DLL
|
|
|
|
void disablePadding();
|
2012-12-29 15:43:46 +00:00
|
|
|
// Specify an initialization vector, which will not be included in
|
|
|
|
// the output.
|
|
|
|
QPDF_DLL
|
|
|
|
void setIV(unsigned char const* iv, size_t bytes);
|
2012-12-28 02:37:57 +00:00
|
|
|
|
2009-10-17 18:54:51 +00:00
|
|
|
// For testing only; PDF always uses CBC
|
2009-10-21 01:45:13 +00:00
|
|
|
QPDF_DLL
|
2009-10-17 18:54:51 +00:00
|
|
|
void disableCBC();
|
2009-10-19 00:36:51 +00:00
|
|
|
// For testing only: use a fixed initialization vector for CBC
|
2009-10-21 01:45:13 +00:00
|
|
|
QPDF_DLL
|
2009-10-19 00:36:51 +00:00
|
|
|
static void useStaticIV();
|
2009-10-17 18:54:51 +00:00
|
|
|
|
2009-10-17 03:14:47 +00:00
|
|
|
private:
|
|
|
|
void flush(bool discard_padding);
|
2009-10-17 18:54:51 +00:00
|
|
|
void initializeVector();
|
2009-10-17 03:14:47 +00:00
|
|
|
|
2009-10-17 15:01:20 +00:00
|
|
|
static unsigned int const buf_size = 16;
|
2009-10-19 00:36:51 +00:00
|
|
|
static bool use_static_iv;
|
2009-10-17 15:01:20 +00:00
|
|
|
|
2009-10-17 03:14:47 +00:00
|
|
|
bool encrypt;
|
2009-10-17 18:54:51 +00:00
|
|
|
bool cbc_mode;
|
|
|
|
bool first;
|
2012-06-20 15:20:57 +00:00
|
|
|
size_t offset; // offset into memory buffer
|
2019-06-22 18:24:49 +00:00
|
|
|
PointerHolder<unsigned char> key;
|
|
|
|
PointerHolder<uint32_t> rk;
|
2009-10-17 15:01:20 +00:00
|
|
|
unsigned char inbuf[buf_size];
|
|
|
|
unsigned char outbuf[buf_size];
|
2009-10-17 18:54:51 +00:00
|
|
|
unsigned char cbc_block[buf_size];
|
2012-12-29 15:43:46 +00:00
|
|
|
unsigned char specified_iv[buf_size];
|
2009-10-17 15:01:20 +00:00
|
|
|
unsigned int nrounds;
|
2012-12-28 02:37:57 +00:00
|
|
|
bool use_zero_iv;
|
2012-12-29 15:43:46 +00:00
|
|
|
bool use_specified_iv;
|
2012-12-28 02:37:57 +00:00
|
|
|
bool disable_padding;
|
2009-10-17 03:14:47 +00:00
|
|
|
};
|
|
|
|
|
2018-08-12 18:07:22 +00:00
|
|
|
#endif // PL_AES_PDF_HH
|