Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ if (APPLE)
endif()
project(pdfraster C)

if (MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4")
endif()
if (CMAKE_COMPILER_IS_GNUCC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror")
endif()

set(PDFRASTER_SHARED_LIB pdfraster)
set(PDFRASTER_STATIC_LIB pdfraster_static)
set(DEMO_RASTER_ENCODER demo_raster_encoder)
Expand Down Expand Up @@ -37,7 +46,7 @@ file(GLOB PDFRAS_ENCRYPTION_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/pdfras_encryption/

file(GLOB COMMON_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/common/*.h")
file(GLOB PDFRAS_READER_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/pdfras_reader/*.h")
file(GLOB PDFRAS_WRITER_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/pdfras_writer/*.h")
#file(GLOB PDFRAS_WRITER_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/pdfras_writer/*.h")
file(GLOB ICC_PROFILE_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/icc_profile/*.h")
file(GLOB PDFRAS_DISIG_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/pdfras_digitalsignature/*.h")
file(GLOB PDFRAS_ENCRYPTION_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/pdfras_encryption/*.h")
Expand Down Expand Up @@ -86,3 +95,5 @@ install(FILES ${COMMON_HEADERS}
${ICC_PROFILE_HEADERS}
${PDFRAS_DISIG_HEADERS}
${PDFRAS_ENCRYPTION_HEADERS} DESTINATION "include/pdfraster")

set_property(TARGET ${PDFRASTER_SHARED_LIB} ${PDFRASTER_STATIC_LIB} ${DEMO_RASTER_ENCODER} PROPERTY C_STANDARD 99)
4 changes: 3 additions & 1 deletion demo_raster_encoder/demo_raster_encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,13 @@ static char XMP_metadata[4096] = "\
<rdf:Description rdf:about=\"\" xmlns:xapMM=\"http://ns.adobe.com/xap/1.0/mm/\"><xapMM:DocumentID>uuid:42646CE2-2A6C-482A-BC04-030FDD35E676</xapMM:DocumentID>\
</rdf:Description>\
"
/*
//// Tag file as PDF/A-1b
//"\
//"
// <rdf:Description rdf:about=\"\" xmlns:pdfaid=\"http://www.aiim.org/pdfa/ns/id/\" pdfaid:part=\"1\" pdfaid:conformance=\"B\">\
// </rdf:Description>\
//"
*/
"\
</rdf:RDF>\
</x:xmpmeta>\n\
Expand Down
16 changes: 8 additions & 8 deletions pdfras_encryption/aes_crypter.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@

#define IV_LEN 16

pduint32 pdfras_aes_encrypt_data(const char* key, const pduint32 key_len, const char* data_in, const pdint32 in_len, char* data_out) {
pduint32 pdfras_aes_encrypt_data(const unsigned char* key, const pduint32 key_len, const unsigned char* data_in, const pdint32 in_len, unsigned char* data_out) {
if (data_in == NULL || data_out == NULL)
return -1;

char iv[IV_LEN];
unsigned char iv[IV_LEN];
pdfras_generate_random_bytes(iv, IV_LEN);

EVP_CIPHER_CTX* cipher = EVP_CIPHER_CTX_new();
Expand All @@ -41,10 +41,10 @@ pduint32 pdfras_aes_encrypt_data(const char* key, const pduint32 key_len, const
return out_len + padded_len;
}

void pdfras_generate_random_bytes(char* buf, pdint32 buf_len) {
void pdfras_generate_random_bytes(unsigned char* buf, pdint32 buf_len) {
if (RAND_bytes(buf, buf_len) == 0) {
// try pseudo random generator
if (RAND_pseudo_bytes(buf, buf_len) == 0) {
if (RAND_bytes(buf, buf_len) == 0) {
pdint32 i;
// ok, openssl failed to generate random nums
srand((unsigned int)time(NULL));
Expand All @@ -55,15 +55,15 @@ void pdfras_generate_random_bytes(char* buf, pdint32 buf_len) {
}
}

pduint32 pdfras_aes_decrypt_data(const char* key, const pduint32 key_len, const char* data_in, const pdint32 in_len, char* data_out) {
pduint32 pdfras_aes_decrypt_data(const unsigned char* key, const pduint32 key_len, const unsigned char* data_in, const pdint32 in_len, unsigned char* data_out) {
if (data_in == NULL || data_out == NULL)
return -1;

EVP_CIPHER_CTX* cipher = EVP_CIPHER_CTX_new();
if (!cipher)
return -1;

char iv[IV_LEN];
unsigned char iv[IV_LEN];
memcpy(iv, data_in, IV_LEN);

if (key_len <= 16)
Expand All @@ -88,7 +88,7 @@ pduint32 pdfras_aes_decrypt_data(const char* key, const pduint32 key_len, const
return out_len;
}

pduint32 pdfras_aes_decrypt_encryption_key(const char* key, const pduint32 key_len, const char* data_in, const pdint32 in_len, char* data_out) {
pduint32 pdfras_aes_decrypt_encryption_key(const unsigned char* key, const pduint32 key_len, const unsigned char* data_in, const pdint32 in_len, unsigned char* data_out) {
if (data_in == NULL || data_out == NULL)
return -1;

Expand All @@ -97,7 +97,7 @@ pduint32 pdfras_aes_decrypt_encryption_key(const char* key, const pduint32 key_l

EVP_CIPHER_CTX* cipher = EVP_CIPHER_CTX_new();

char iv[IV_LEN];
unsigned char iv[IV_LEN];
memset(iv, 0, IV_LEN);

EVP_DecryptInit_ex(cipher, EVP_aes_256_cbc(), NULL, key, iv);
Expand Down
8 changes: 4 additions & 4 deletions pdfras_encryption/aes_crypter.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ extern "C" {

#include "PdfPlatform.h"

extern pduint32 pdfras_aes_encrypt_data(const char* key, const pduint32 key_len, const char* data_in, const pdint32 in_len, char* data_out);
extern void pdfras_generate_random_bytes(char* buf, pdint32 buf_len);
extern pduint32 pdfras_aes_decrypt_data(const char* key, const pduint32 key_len, const char* data_in, const pdint32 in_len, char* data_out);
extern pduint32 pdfras_aes_decrypt_encryption_key(const char* key, const pduint32 key_len, const char* data_in, const pdint32 in_len, char* data_out);
extern pduint32 pdfras_aes_encrypt_data(const unsigned char* key, const pduint32 key_len, const unsigned char* data_in, const pdint32 in_len, unsigned char* data_out);
extern void pdfras_generate_random_bytes(unsigned char* buf, pdint32 buf_len);
extern pduint32 pdfras_aes_decrypt_data(const unsigned char* key, const pduint32 key_len, const unsigned char* data_in, const pdint32 in_len, unsigned char* data_out);
extern pduint32 pdfras_aes_decrypt_encryption_key(const unsigned char* key, const pduint32 key_len, const unsigned char* data_in, const pdint32 in_len, unsigned char* data_out);

#ifdef __cplusplus
}
Expand Down
Loading