Haru Free PDF Library
hpdf_encrypt.h
Go to the documentation of this file.
1 /*
2  * << Haru Free PDF Library >> -- hpdf_encrypt.h
3  *
4  * URL: http://libharu.org
5  *
6  * Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
7  * Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
8  *
9  * Permission to use, copy, modify, distribute and sell this software
10  * and its documentation for any purpose is hereby granted without fee,
11  * provided that the above copyright notice appear in all copies and
12  * that both that copyright notice and this permission notice appear
13  * in supporting documentation.
14  * It is provided "as is" without express or implied warranty.
15  *
16  *------------------------------------------------------------------------------
17  *
18  * The code implements MD5 message-digest algorithm is based on the code
19  * written by Colin Plumb.
20  * The copyright of it is as follows.
21  *
22  * This code implements the MD5 message-digest algorithm.
23  * The algorithm is due to Ron Rivest. This code was
24  * written by Colin Plumb in 1993, no copyright is claimed.
25  * This code is in the public domain; do with it what you wish.
26  *
27  * Equivalent code is available from RSA Data Security, Inc.
28  * This code has been tested against that, and is equivalent,
29  * except that you don't need to include two pages of legalese
30  * with every copy.
31  *
32  * To compute the message digest of a chunk of bytes, declare an
33  * MD5Context structure, pass it to MD5Init, call MD5Update as
34  * needed on buffers full of bytes, and then call MD5Final, which
35  * will fill a supplied 16-byte array with the digest.
36  *
37  *---------------------------------------------------------------------------*/
38 
39 #ifndef HPDF_ENCRYPT_H
40 #define HPDF_ENCRYPT_H
41 
42 #include "hpdf_mmgr.h"
43 
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47 
48 /*----------------------------------------------------------------------------*/
49 /*----- encrypt-dict ---------------------------------------------------------*/
50 
51 #define HPDF_ID_LEN 16
52 #define HPDF_PASSWD_LEN 32
53 #define HPDF_ENCRYPT_KEY_MAX 16
54 #define HPDF_MD5_KEY_LEN 16
55 #define HPDF_PERMISSION_PAD 0xFFFFFFC0
56 #define HPDF_ARC4_BUF_SIZE 256
57 
58 
59 typedef struct HPDF_MD5Context
60 {
65 
66 
67 typedef struct _HPDF_ARC4_Ctx_Rec {
72 
73 
75 
76 typedef struct _HPDF_Encrypt_Rec {
78 
79  /* key_len must be a multiple of 8, and between 40 to 128 */
81 
82  /* owner-password (not encrypted) */
84 
85  /* user-password (not encrypted) */
87 
88  /* owner-password (encrypted) */
90 
91  /* user-password (encrypted) */
93 
100 
101 
102 void
104 
105 
106 void
108  const HPDF_BYTE *buf,
109  HPDF_UINT32 len);
110 
111 
112 void
114  struct HPDF_MD5Context *ctx);
115 
116 void
117 HPDF_PadOrTrancatePasswd (const char *pwd,
118  HPDF_BYTE *new_pwd);
119 
120 
121 void
123 
124 
125 void
127 
128 
129 void
131 
132 
133 void
135 
136 
137 void
139  HPDF_UINT32 object_id,
140  HPDF_UINT16 gen_no);
141 
142 
143 void
145 
146 
147 void
149  const HPDF_BYTE *src,
150  HPDF_BYTE *dst,
151  HPDF_UINT len);
152 
153 #ifdef __cplusplus
154 }
155 #endif /* __cplusplus */
156 
157 #endif /* _HPDF_ENCRYPT_H */
158 
159 
void HPDF_MD5Init(struct HPDF_MD5Context *ctx)
void HPDF_Encrypt_CreateEncryptionKey(HPDF_Encrypt attr)
#define HPDF_ARC4_BUF_SIZE
Definition: hpdf_encrypt.h:56
struct _HPDF_Encrypt_Rec HPDF_Encrypt_Rec
void HPDF_Encrypt_CryptBuf(HPDF_Encrypt attr, const HPDF_BYTE *src, HPDF_BYTE *dst, HPDF_UINT len)
void HPDF_MD5Update(struct HPDF_MD5Context *ctx, const HPDF_BYTE *buf, HPDF_UINT32 len)
void HPDF_Encrypt_CreateOwnerKey(HPDF_Encrypt attr)
void HPDF_Encrypt_InitKey(HPDF_Encrypt attr, HPDF_UINT32 object_id, HPDF_UINT16 gen_no)
void HPDF_MD5Final(HPDF_BYTE digest[16], struct HPDF_MD5Context *ctx)
void HPDF_PadOrTrancatePasswd(const char *pwd, HPDF_BYTE *new_pwd)
#define HPDF_ID_LEN
Definition: hpdf_encrypt.h:51
#define HPDF_MD5_KEY_LEN
Definition: hpdf_encrypt.h:54
void HPDF_Encrypt_CreateUserKey(HPDF_Encrypt attr)
#define HPDF_PASSWD_LEN
Definition: hpdf_encrypt.h:52
struct _HPDF_Encrypt_Rec * HPDF_Encrypt
Definition: hpdf_encrypt.h:74
void HPDF_Encrypt_Reset(HPDF_Encrypt attr)
struct _HPDF_ARC4_Ctx_Rec HPDF_ARC4_Ctx_Rec
struct HPDF_MD5Context HPDF_MD5_CTX
void HPDF_Encrypt_Init(HPDF_Encrypt attr)
signed int HPDF_INT
Definition: hpdf_types.h:44
unsigned short HPDF_UINT16
Definition: hpdf_types.h:63
unsigned int HPDF_UINT
Definition: hpdf_types.h:45
unsigned int HPDF_UINT32
Definition: hpdf_types.h:57
enum _HPDF_EncryptMode HPDF_EncryptMode
unsigned char HPDF_BYTE
Definition: hpdf_types.h:74
Definition: hpdf_encrypt.h:60
HPDF_BYTE in[64]
Definition: hpdf_encrypt.h:63
HPDF_UINT32 bits[2]
Definition: hpdf_encrypt.h:62
HPDF_UINT32 buf[4]
Definition: hpdf_encrypt.h:61
Definition: hpdf_encrypt.h:67
HPDF_BYTE idx2
Definition: hpdf_encrypt.h:69
HPDF_BYTE idx1
Definition: hpdf_encrypt.h:68
HPDF_BYTE state[HPDF_ARC4_BUF_SIZE]
Definition: hpdf_encrypt.h:70
Definition: hpdf_encrypt.h:76
HPDF_BYTE user_key[HPDF_PASSWD_LEN]
Definition: hpdf_encrypt.h:92
HPDF_BYTE md5_encryption_key[HPDF_MD5_KEY_LEN]
Definition: hpdf_encrypt.h:97
HPDF_INT permission
Definition: hpdf_encrypt.h:94
HPDF_ARC4_Ctx_Rec arc4ctx
Definition: hpdf_encrypt.h:98
HPDF_BYTE owner_passwd[HPDF_PASSWD_LEN]
Definition: hpdf_encrypt.h:83
HPDF_BYTE owner_key[HPDF_PASSWD_LEN]
Definition: hpdf_encrypt.h:89
HPDF_UINT key_len
Definition: hpdf_encrypt.h:80
HPDF_BYTE user_passwd[HPDF_PASSWD_LEN]
Definition: hpdf_encrypt.h:86
HPDF_BYTE encryption_key[HPDF_MD5_KEY_LEN+5]
Definition: hpdf_encrypt.h:96
HPDF_EncryptMode mode
Definition: hpdf_encrypt.h:77
HPDF_BYTE encrypt_id[HPDF_ID_LEN]
Definition: hpdf_encrypt.h:95