2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-06-25 23:02:38 +00:00
qpdf/libqpdf/qpdf/Pl_AES_PDF.hh
Jay Berkenbilt 5d4cad9c02 ABI change: fix use of off_t, size_t, and integer types
Significantly improve the code's use of off_t for file offsets, size_t
for memory sizes, and integer types in cases where there has to be
compatibility with external interfaces.  Rework sections of the code
that would have prevented qpdf from working on files larger than 2 (or
maybe 4) GB in size.
2012-06-20 15:20:26 -04:00

56 lines
1.4 KiB
C++

#ifndef __PL_AES_PDF_HH__
#define __PL_AES_PDF_HH__
#include <qpdf/Pipeline.hh>
#include <qpdf/qpdf-config.h>
#ifdef HAVE_STDINT_H
# include <stdint.h>
#endif
// This pipeline implements AES-128 with CBC and block padding as
// specified in the PDF specification.
class Pl_AES_PDF: public Pipeline
{
public:
// key_data should be a pointer to key_size bytes of data
static unsigned int const key_size = 16;
QPDF_DLL
Pl_AES_PDF(char const* identifier, Pipeline* next,
bool encrypt, unsigned char const key[key_size]);
QPDF_DLL
virtual ~Pl_AES_PDF();
QPDF_DLL
virtual void write(unsigned char* data, size_t len);
QPDF_DLL
virtual void finish();
// For testing only; PDF always uses CBC
QPDF_DLL
void disableCBC();
// For testing only: use a fixed initialization vector for CBC
QPDF_DLL
static void useStaticIV();
private:
void flush(bool discard_padding);
void initializeVector();
static unsigned int const buf_size = 16;
static bool use_static_iv;
bool encrypt;
bool cbc_mode;
bool first;
size_t offset; // offset into memory buffer
unsigned char key[key_size];
uint32_t rk[key_size + 28];
unsigned char inbuf[buf_size];
unsigned char outbuf[buf_size];
unsigned char cbc_block[buf_size];
unsigned int nrounds;
};
#endif // __PL_AES_PDF_HH__