2009-10-17 03:14:47 +00:00
|
|
|
#ifndef __PL_AES_PDF_HH__
|
|
|
|
#define __PL_AES_PDF_HH__
|
|
|
|
|
|
|
|
#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
|
|
|
|
2009-10-17 15:01:20 +00:00
|
|
|
// This pipeline implements AES-128 with CBC and block padding as
|
|
|
|
// specified in the PDF specification.
|
|
|
|
|
2009-10-21 00:27:24 +00:00
|
|
|
class Pl_AES_PDF: public Pipeline
|
2009-10-17 03:14:47 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
// key_data should be a pointer to key_size bytes of data
|
|
|
|
static unsigned int const key_size = 16;
|
2009-10-21 01:45:13 +00:00
|
|
|
QPDF_DLL
|
2009-10-17 03:14:47 +00:00
|
|
|
Pl_AES_PDF(char const* identifier, Pipeline* next,
|
2009-10-17 23:37:55 +00:00
|
|
|
bool encrypt, unsigned char const key[key_size]);
|
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();
|
|
|
|
|
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
|
2009-10-17 15:01:20 +00:00
|
|
|
unsigned char key[key_size];
|
|
|
|
uint32_t rk[key_size + 28];
|
|
|
|
unsigned char inbuf[buf_size];
|
|
|
|
unsigned char outbuf[buf_size];
|
2009-10-17 18:54:51 +00:00
|
|
|
unsigned char cbc_block[buf_size];
|
2009-10-17 15:01:20 +00:00
|
|
|
unsigned int nrounds;
|
2009-10-17 03:14:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // __PL_AES_PDF_HH__
|