mupdf
Loading...
Searching...
No Matches
crypt.h
Go to the documentation of this file.
1// Copyright (C) 2004-2025 Artifex Software, Inc.
2//
3// This file is part of MuPDF.
4//
5// MuPDF is free software: you can redistribute it and/or modify it under the
6// terms of the GNU Affero General Public License as published by the Free
7// Software Foundation, either version 3 of the License, or (at your option)
8// any later version.
9//
10// MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY
11// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12// FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
13// details.
14//
15// You should have received a copy of the GNU Affero General Public License
16// along with MuPDF. If not, see <https://www.gnu.org/licenses/agpl-3.0.en.html>
17//
18// Alternative licensing terms are available from the licensor.
19// For commercial licensing, see <https://www.artifex.com/> or contact
20// Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco,
21// CA 94129, USA, for further information.
22
23#ifndef MUPDF_FITZ_CRYPT_H
24#define MUPDF_FITZ_CRYPT_H
25
26#include "mupdf/fitz/system.h"
27
28/* md5 digests */
29
34typedef struct
35{
36 uint32_t lo, hi;
37 uint32_t a, b, c, d;
38 unsigned char buffer[64];
39} fz_md5;
40
47void fz_md5_init(fz_md5 *state);
48
56void fz_md5_update(fz_md5 *state, const unsigned char *input, size_t inlen);
57
64void fz_md5_update_int64(fz_md5 *state, int64_t i);
65
72void fz_md5_final(fz_md5 *state, unsigned char digest[16]);
73
74/* sha-256 digests */
75
80typedef struct
81{
82 unsigned int state[8];
83 unsigned int count[2];
84 union {
85 unsigned char u8[64];
86 unsigned int u32[16];
87 } buffer;
88} fz_sha256;
89
97
105void fz_sha256_update(fz_sha256 *state, const unsigned char *input, size_t inlen);
106
113void fz_sha256_final(fz_sha256 *state, unsigned char digest[32]);
114
115/* sha-512 digests */
116
121typedef struct
122{
123 uint64_t state[8];
124 unsigned int count[2];
125 union {
126 unsigned char u8[128];
127 uint64_t u64[16];
128 } buffer;
129} fz_sha512;
130
138
146void fz_sha512_update(fz_sha512 *state, const unsigned char *input, size_t inlen);
147
154void fz_sha512_final(fz_sha512 *state, unsigned char digest[64]);
155
156/* sha-384 digests */
157
159
167
175void fz_sha384_update(fz_sha384 *state, const unsigned char *input, size_t inlen);
176
183void fz_sha384_final(fz_sha384 *state, unsigned char digest[64]);
184
185/* arc4 crypto */
186
191typedef struct
192{
193 unsigned x;
194 unsigned y;
195 unsigned char state[256];
196} fz_arc4;
197
204void fz_arc4_init(fz_arc4 *state, const unsigned char *key, size_t len);
205
212void fz_arc4_encrypt(fz_arc4 *state, unsigned char *dest, const unsigned char *src, size_t len);
213
220
221/* AES block cipher implementation from XYSSL */
222
227typedef struct
228{
229 int nr; /* number of rounds */
230 uint32_t *rk; /* AES round keys */
231 uint32_t buf[68]; /* unaligned data */
232} fz_aes;
233
234#define FZ_AES_DECRYPT 0
235#define FZ_AES_ENCRYPT 1
236
245int fz_aes_setkey_enc(fz_aes *ctx, const unsigned char *key, int keysize);
246
255int fz_aes_setkey_dec(fz_aes *ctx, const unsigned char *key, int keysize);
256
265void fz_aes_crypt_cbc(fz_aes *ctx, int mode, size_t length,
266 unsigned char iv[16],
267 const unsigned char *input,
268 unsigned char *output );
269
270#endif
void fz_sha384_update(fz_sha384 *state, const unsigned char *input, size_t inlen)
void fz_md5_update(fz_md5 *state, const unsigned char *input, size_t inlen)
void fz_md5_update_int64(fz_md5 *state, int64_t i)
void fz_md5_init(fz_md5 *state)
void fz_sha512_init(fz_sha512 *state)
int fz_aes_setkey_enc(fz_aes *ctx, const unsigned char *key, int keysize)
int fz_aes_setkey_dec(fz_aes *ctx, const unsigned char *key, int keysize)
void fz_arc4_final(fz_arc4 *state)
void fz_md5_final(fz_md5 *state, unsigned char digest[16])
void fz_arc4_encrypt(fz_arc4 *state, unsigned char *dest, const unsigned char *src, size_t len)
void fz_sha384_final(fz_sha384 *state, unsigned char digest[64])
void fz_sha384_init(fz_sha384 *state)
void fz_arc4_init(fz_arc4 *state, const unsigned char *key, size_t len)
fz_sha512 fz_sha384
Definition crypt.h:158
void fz_aes_crypt_cbc(fz_aes *ctx, int mode, size_t length, unsigned char iv[16], const unsigned char *input, unsigned char *output)
void fz_sha256_init(fz_sha256 *state)
void fz_sha256_final(fz_sha256 *state, unsigned char digest[32])
void fz_sha256_update(fz_sha256 *state, const unsigned char *input, size_t inlen)
void fz_sha512_final(fz_sha512 *state, unsigned char digest[64])
void fz_sha512_update(fz_sha512 *state, const unsigned char *input, size_t inlen)
Definition crypt.h:228
int nr
Definition crypt.h:229
uint32_t buf[68]
Definition crypt.h:231
uint32_t * rk
Definition crypt.h:230
Definition crypt.h:192
unsigned y
Definition crypt.h:194
unsigned char state[256]
Definition crypt.h:195
unsigned x
Definition crypt.h:193
Definition crypt.h:35
uint32_t d
Definition crypt.h:37
uint32_t c
Definition crypt.h:37
uint32_t a
Definition crypt.h:37
uint32_t b
Definition crypt.h:37
uint32_t lo
Definition crypt.h:36
uint32_t hi
Definition crypt.h:36
unsigned char buffer[64]
Definition crypt.h:38
Definition crypt.h:81
unsigned char u8[64]
Definition crypt.h:85
unsigned int u32[16]
Definition crypt.h:86
unsigned int state[8]
Definition crypt.h:82
unsigned int count[2]
Definition crypt.h:83
Definition crypt.h:122
unsigned int count[2]
Definition crypt.h:124
uint64_t u64[16]
Definition crypt.h:127
unsigned char u8[128]
Definition crypt.h:126
uint64_t state[8]
Definition crypt.h:123