Debian Codegraph @

libs/pplib/pplib-src/src/ppcrypt.h

raw
1
2 #ifndef PP_CRYPT_H
3 #define PP_CRYPT_H
4
5 #include "ppfilter.h"
6 #include "utilcrypt.h"
7 #include "utilcryptdef.h"
8
9 #define PPCRYPT_MAX_PASSWORD 127
10 #define PPCRYPT_MAX_KEY 32
11
12 typedef struct {
13 ppuint algorithm_variant; /* /V entry of encrypt dict */
14 ppuint algorithm_revision; /* /R entry of encrypt dict */
15 ppint permissions; /* /P entry of encrypt dict */
16 ppdict *map; /* /CF filters map of encrypt dict */
17 uint8_t userpass[PPCRYPT_MAX_PASSWORD]; /* user password */
18 size_t userpasslength; /* user password length */
19 uint8_t ownerpass[PPCRYPT_MAX_PASSWORD]; /* owner password */
20 size_t ownerpasslength; /* owner password length */
21 uint8_t filekey[PPCRYPT_MAX_KEY+5+4]; /* file key with an extra space for salt */
22 size_t filekeylength; /* key length; usually 5, 16 or 32 bytes */
23 uint8_t cryptkey[PPCRYPT_MAX_KEY]; /* crypt key for a recent reference */
24 size_t cryptkeylength; /* crypt key length; usually keylength + 5 */
25 //ppstring *cryptkeystring; /* todo: cached cryptkey string for V5, where all refs has the same */
26 ppref *ref; /* recent reference */
27 union { /* cached crypt states for strings encrypted/decrypted with the same key */
28 struct {
29 rc4_state rc4state;
30 rc4_map rc4map;
31 rc4_map rc4copy;
32 };
33 struct {
34 aes_state aesstate;
35 aes_keyblock aeskeyblock;
36 uint8_t ivcopy[16];
37 };
38 };
39 int flags;
40 } ppcrypt;
41
42 #define PPCRYPT_NO_METADATA (1<<0)
43 #define PPCRYPT_USER_PASSWORD (1<<1)
44 #define PPCRYPT_OWNER_PASSWORD (1<<2)
45 #define PPCRYPT_STREAM_RC4 (1<<3)
46 #define PPCRYPT_STRING_RC4 (1<<4)
47 #define PPCRYPT_STREAM_AES (1<<5)
48 #define PPCRYPT_STRING_AES (1<<6)
49 #define PPCRYPT_UNREADABLE_PERMISSIONS (1<<7)
50
51 #define PPCRYPT_STREAM (PPCRYPT_STREAM_AES|PPCRYPT_STREAM_RC4)
52 #define PPCRYPT_STRING (PPCRYPT_STRING_AES|PPCRYPT_STRING_RC4)
53 #define PPCRYPT_RC4 (PPCRYPT_STREAM_RC4|PPCRYPT_STRING_RC4)
54 #define PPCRYPT_AES (PPCRYPT_STREAM_AES|PPCRYPT_STRING_AES)
55
56 #define PPCRYPT_INFO_AES (1<<0)
57 #define PPCRYPT_INFO_RC4 (1<<1)
58 #define PPCRYPT_INFO_MD (1<<2)
59 #define PPCRYPT_INFO_NOMD (1<<3)
60
61 ppcrypt_status ppdoc_crypt_init (ppdoc *pdf, const void *userpass, size_t userpasslength, const void *ownerpass, size_t ownerpasslength);
62 int ppstring_decrypt (ppcrypt *crypt, const void *input, size_t size, void *output, size_t *newsize);
63
64 #define ppcrypt_start_ref(crypt, r) ((crypt)->ref = r, (crypt)->cryptkeylength = 0)
65 #define ppcrypt_end_ref(crypt) ((crypt)->ref = NULL, (crypt)->cryptkeylength = 0)
66 #define ppcrypt_ref(pdf, crypt) ((crypt = (pdf)->crypt) != NULL && crypt->ref != NULL)
67
68 int ppcrypt_type (ppcrypt *crypt, ppname *cryptname, ppuint *length, int *cryptflags);
69 ppstring * ppcrypt_stmkey (ppcrypt *crypt, ppref *ref, int aes, ppheap *heap);
70
71 #endif