MuPDF X.Y.Z

fitz/crypt.h

Index

typedef

struct

macro

function

Crypt

CRC-32 checksums

These can be called sequentially to compute the checksum over separate chunks of data, by passing the return value from one to the next. Pass 0 as the starting value.

function fz_crc32

uint32_t
fz_crc32 (
        uint32_t sum,
        const void *data,
        size_t n
)

CRC-32/ISO-HDLC checksum

function fz_crc32c

uint32_t
fz_crc32c (
        uint32_t sum,
        const void *data,
        size_t n
)

CRC-32/ISCSI checksum (aka CRC32-Castagnoli)

MD5 digests

struct fz_md5

struct fz_md5
{
        uint32_t lo, hi;
        uint32_t a, b, c, d;
        unsigned char buffer[64];
}

Structure definition is public to enable stack based allocation. Do not access the members directly.

function fz_md5_init

void
fz_md5_init (
        fz_md5 *state
)

MD5 initialization. Begins an MD5 operation, writing a new context.

Never throws an exception.

function fz_md5_update

void
fz_md5_update (
        fz_md5 *state,
        const unsigned char *input,
        size_t inlen
)

MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context.

Never throws an exception.

function fz_md5_update_int64

void
fz_md5_update_int64 (
        fz_md5 *state,
        int64_t i
)

MD5 block update operation. Continues an MD5 message-digest operation, processing an int64, and updating the context.

Never throws an exception.

function fz_md5_final

void
fz_md5_final (
        fz_md5 *state,
        unsigned char digest[16]
)

MD5 finalization. Ends an MD5 message-digest operation, writing the message digest and zeroizing the context.

Never throws an exception.

SHA-256 digests

struct fz_sha256

struct fz_sha256
{
        unsigned int state[8];
        unsigned int count[2];
        union {
                unsigned char u8[64];
                unsigned int u32[16];
        } buffer;
}

Structure definition is public to enable stack based allocation. Do not access the members directly.

function fz_sha256_init

void
fz_sha256_init (
        fz_sha256 *state
)

SHA256 initialization. Begins an SHA256 operation, initialising the supplied context.

Never throws an exception.

function fz_sha256_update

void
fz_sha256_update (
        fz_sha256 *state,
        const unsigned char *input,
        size_t inlen
)

SHA256 block update operation. Continues an SHA256 message- digest operation, processing another message block, and updating the context.

Never throws an exception.

function fz_sha256_final

void
fz_sha256_final (
        fz_sha256 *state,
        unsigned char digest[32]
)

MD5 finalization. Ends an MD5 message-digest operation, writing the message digest and zeroizing the context.

Never throws an exception.

SHA-512 digests

struct fz_sha512

struct fz_sha512
{
        uint64_t state[8];
        unsigned int count[2];
        union {
                unsigned char u8[128];
                uint64_t u64[16];
        } buffer;
}

Structure definition is public to enable stack based allocation. Do not access the members directly.

function fz_sha512_init

void
fz_sha512_init (
        fz_sha512 *state
)

SHA512 initialization. Begins an SHA512 operation, initialising the supplied context.

Never throws an exception.

function fz_sha512_update

void
fz_sha512_update (
        fz_sha512 *state,
        const unsigned char *input,
        size_t inlen
)

SHA512 block update operation. Continues an SHA512 message- digest operation, processing another message block, and updating the context.

Never throws an exception.

function fz_sha512_final

void
fz_sha512_final (
        fz_sha512 *state,
        unsigned char digest[64]
)

SHA512 finalization. Ends an SHA512 message-digest operation, writing the message digest and zeroizing the context.

Never throws an exception.

SHA-384 digests

typedef fz_sha384

typedef fz_sha512 fz_sha384

function fz_sha384_init

void
fz_sha384_init (
        fz_sha384 *state
)

SHA384 initialization. Begins an SHA384 operation, initialising the supplied context.

Never throws an exception.

function fz_sha384_update

void
fz_sha384_update (
        fz_sha384 *state,
        const unsigned char *input,
        size_t inlen
)

SHA384 block update operation. Continues an SHA384 message- digest operation, processing another message block, and updating the context.

Never throws an exception.

function fz_sha384_final

void
fz_sha384_final (
        fz_sha384 *state,
        unsigned char digest[64]
)

SHA384 finalization. Ends an SHA384 message-digest operation, writing the message digest and zeroizing the context.

Never throws an exception.

RC4 crypto

struct fz_arc4

struct fz_arc4
{
        unsigned x;
        unsigned y;
        unsigned char state[256];
}

Structure definition is public to enable stack based allocation. Do not access the members directly.

function fz_arc4_init

void
fz_arc4_init (
        fz_arc4 *state,
        const unsigned char *key,
        size_t len
)

RC4 initialization. Begins an RC4 operation, writing a new context.

Never throws an exception.

function fz_arc4_encrypt

void
fz_arc4_encrypt (
        fz_arc4 *state,
        unsigned char *dest,
        const unsigned char *src,
        size_t len
)

RC4 block encrypt operation; encrypt src into dst (both of length len) updating the RC4 state as we go.

Never throws an exception.

function fz_arc4_final

void
fz_arc4_final (
        fz_arc4 *state
)

RC4 finalization. Zero the context.

Never throws an exception.

AES block cipher implementation from XYSSL

struct fz_aes

struct fz_aes
{
        int nr; /* number of rounds */
        uint32_t *rk; /* AES round keys */
        uint32_t buf[68]; /* unaligned data */
}

Structure definitions are public to enable stack based allocation. Do not access the members directly.

macro FZ_AES_DECRYPT

#define FZ_AES_DECRYPT 0

macro FZ_AES_ENCRYPT

#define FZ_AES_ENCRYPT 1

function fz_aes_setkey_enc

int
fz_aes_setkey_enc (
        fz_aes *ctx,
        const unsigned char *key,
        int keysize
)

AES encryption initialization. Fills in the supplied context and prepares for encryption using the given key.

Returns non-zero for error (key size other than 128/192/256).

Never throws an exception.

function fz_aes_setkey_dec

int
fz_aes_setkey_dec (
        fz_aes *ctx,
        const unsigned char *key,
        int keysize
)

AES decryption initialization. Fills in the supplied context and prepares for decryption using the given key.

Returns non-zero for error (key size other than 128/192/256).

Never throws an exception.

function fz_aes_crypt_cbc

void
fz_aes_crypt_cbc (
        fz_aes *ctx,
        int mode,
        size_t length,
        unsigned char iv[16],
        const unsigned char *input,
        unsigned char *output
)

AES block processing. Encrypts or Decrypts (according to mode, which must match what was initially set up) length bytes (which must be a multiple of 16), using (and modifying) the insertion vector iv, reading from input, and writing to output.

Never throws an exception.

ChaCha20 stream cipher (RFC 7539)

struct fz_chacha20

struct fz_chacha20 {
        uint32_t s[16];
}

The ChaCha20 state is a vector of sixteen 32-bit words. Word 12 is the block counter.

function fz_chacha20_init

void
fz_chacha20_init (
        fz_chacha20 *stm,
        unsigned char *key,
        unsigned char *nonce,
        uint32_t counter
)

Setup ChaCha20 stream cipher with 256-bit key, 96-bit nonce, and counter.

function fz_chacha20_encrypt

void
fz_chacha20_encrypt (
        fz_chacha20 *seed,
        unsigned char *dst,
        const unsigned char *src,
        uint32_t size
)

Encrypt bytes with ChaCha20 stream cipher.