/src/qpdf/include/qpdf/QPDFCryptoImpl.hh
Line | Count | Source |
1 | | // Copyright (c) 2005-2021 Jay Berkenbilt |
2 | | // Copyright (c) 2022-2025 Jay Berkenbilt and Manfred Holger |
3 | | // |
4 | | // This file is part of qpdf. |
5 | | // |
6 | | // Licensed under the Apache License, Version 2.0 (the "License"); |
7 | | // you may not use this file except in compliance with the License. |
8 | | // You may obtain a copy of the License at |
9 | | // |
10 | | // http://www.apache.org/licenses/LICENSE-2.0 |
11 | | // |
12 | | // Unless required by applicable law or agreed to in writing, software |
13 | | // distributed under the License is distributed on an "AS IS" BASIS, |
14 | | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15 | | // See the License for the specific language governing permissions and |
16 | | // limitations under the License. |
17 | | // |
18 | | // Versions of qpdf prior to version 7 were released under the terms |
19 | | // of version 2.0 of the Artistic License. At your option, you may |
20 | | // continue to consider qpdf to be licensed under those terms. Please |
21 | | // see the manual for additional information. |
22 | | |
23 | | #ifndef QPDFCRYPTOIMPL_HH |
24 | | #define QPDFCRYPTOIMPL_HH |
25 | | |
26 | | #include <qpdf/DLL.h> |
27 | | #include <string> |
28 | | |
29 | | // This class is part of qpdf's pluggable crypto provider support. |
30 | | // Most users won't need to know or care about this class, but you can |
31 | | // use it if you want to supply your own crypto implementation. To do |
32 | | // so, provide an implementation of QPDFCryptoImpl, ensure that you |
33 | | // register it by calling QPDFCryptoProvider::registerImpl, and make |
34 | | // it the default by calling QPDFCryptoProvider::setDefaultProvider. |
35 | | class QPDF_DLL_CLASS QPDFCryptoImpl |
36 | | { |
37 | | public: |
38 | 407k | QPDFCryptoImpl() = default; |
39 | | |
40 | 407k | virtual ~QPDFCryptoImpl() = default; |
41 | | |
42 | | // Random Number Generation |
43 | | |
44 | | virtual void provideRandomData(unsigned char* data, size_t len) = 0; |
45 | | |
46 | | // Hashing |
47 | | |
48 | | typedef unsigned char MD5_Digest[16]; |
49 | | virtual void MD5_init() = 0; |
50 | | virtual void MD5_update(unsigned char const* data, size_t len) = 0; |
51 | | virtual void MD5_finalize() = 0; |
52 | | virtual void MD5_digest(MD5_Digest) = 0; |
53 | | |
54 | | virtual void SHA2_init(int bits) = 0; |
55 | | virtual void SHA2_update(unsigned char const* data, size_t len) = 0; |
56 | | virtual void SHA2_finalize() = 0; |
57 | | virtual std::string SHA2_digest() = 0; |
58 | | |
59 | | // Encryption/Decryption |
60 | | |
61 | | // QPDF must support RC4 to be able to work with older PDF files |
62 | | // and readers. Search for RC4 in README.md |
63 | | |
64 | | // key_len of -1 means treat key_data as a null-terminated string |
65 | | virtual void RC4_init(unsigned char const* key_data, int key_len = -1) = 0; |
66 | | // out_data = 0 means to encrypt/decrypt in place |
67 | | virtual void |
68 | | RC4_process(unsigned char const* in_data, size_t len, unsigned char* out_data = nullptr) = 0; |
69 | | virtual void RC4_finalize() = 0; |
70 | | |
71 | | static size_t constexpr rijndael_buf_size = 16; |
72 | | virtual void rijndael_init( |
73 | | bool encrypt, |
74 | | unsigned char const* key_data, |
75 | | size_t key_len, |
76 | | bool cbc_mode, |
77 | | unsigned char* cbc_block) = 0; |
78 | | virtual void rijndael_process(unsigned char* in_data, unsigned char* out_data) = 0; |
79 | | virtual void rijndael_finalize() = 0; |
80 | | }; |
81 | | |
82 | | #endif // QPDFCRYPTOIMPL_HH |