Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
7858 views
1
#ifndef MUPDF_FITZ_CRYPT_H
2
#define MUPDF_FITZ_CRYPT_H
3
4
#include "mupdf/fitz/system.h"
5
6
/*
7
* Basic crypto functions.
8
* Independent of the rest of fitz.
9
* For further encapsulation in filters, or not.
10
*/
11
12
/* md5 digests */
13
14
typedef struct fz_md5_s fz_md5;
15
16
struct fz_md5_s
17
{
18
unsigned int state[4];
19
unsigned int count[2];
20
unsigned char buffer[64];
21
};
22
23
void fz_md5_init(fz_md5 *state);
24
void fz_md5_update(fz_md5 *state, const unsigned char *input, unsigned inlen);
25
void fz_md5_final(fz_md5 *state, unsigned char digest[16]);
26
27
/* sha-256 digests */
28
29
typedef struct fz_sha256_s fz_sha256;
30
31
struct fz_sha256_s
32
{
33
unsigned int state[8];
34
unsigned int count[2];
35
union {
36
unsigned char u8[64];
37
unsigned int u32[16];
38
} buffer;
39
};
40
41
void fz_sha256_init(fz_sha256 *state);
42
void fz_sha256_update(fz_sha256 *state, const unsigned char *input, unsigned int inlen);
43
void fz_sha256_final(fz_sha256 *state, unsigned char digest[32]);
44
45
/* sha-512 digests */
46
47
typedef struct fz_sha512_s fz_sha512;
48
49
struct fz_sha512_s
50
{
51
uint64_t state[8];
52
unsigned int count[2];
53
union {
54
unsigned char u8[128];
55
uint64_t u64[16];
56
} buffer;
57
};
58
59
void fz_sha512_init(fz_sha512 *state);
60
void fz_sha512_update(fz_sha512 *state, const unsigned char *input, unsigned int inlen);
61
void fz_sha512_final(fz_sha512 *state, unsigned char digest[64]);
62
63
/* sha-384 digests */
64
65
typedef struct fz_sha512_s fz_sha384;
66
67
void fz_sha384_init(fz_sha384 *state);
68
void fz_sha384_update(fz_sha384 *state, const unsigned char *input, unsigned int inlen);
69
void fz_sha384_final(fz_sha384 *state, unsigned char digest[64]);
70
71
/* arc4 crypto */
72
73
typedef struct fz_arc4_s fz_arc4;
74
75
struct fz_arc4_s
76
{
77
unsigned x;
78
unsigned y;
79
unsigned char state[256];
80
};
81
82
void fz_arc4_init(fz_arc4 *state, const unsigned char *key, unsigned len);
83
void fz_arc4_encrypt(fz_arc4 *state, unsigned char *dest, const unsigned char *src, unsigned len);
84
85
/* AES block cipher implementation from XYSSL */
86
87
typedef struct fz_aes_s fz_aes;
88
89
#define AES_DECRYPT 0
90
#define AES_ENCRYPT 1
91
92
struct fz_aes_s
93
{
94
int nr; /* number of rounds */
95
unsigned long *rk; /* AES round keys */
96
unsigned long buf[68]; /* unaligned data */
97
};
98
99
int aes_setkey_enc( fz_aes *ctx, const unsigned char *key, int keysize );
100
int aes_setkey_dec( fz_aes *ctx, const unsigned char *key, int keysize );
101
void aes_crypt_cbc( fz_aes *ctx, int mode, int length,
102
unsigned char iv[16],
103
const unsigned char *input,
104
unsigned char *output );
105
106
#endif
107
108