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.
uint32_t
fz_crc32 (
uint32_t sum,
const void *data,
size_t n
)
CRC-32/ISO-HDLC checksum
uint32_t
fz_crc32c (
uint32_t sum,
const void *data,
size_t n
)
CRC-32/ISCSI checksum (aka CRC32-Castagnoli)
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.
void
fz_md5_init (
fz_md5 *state
)
MD5 initialization. Begins an MD5 operation, writing a new context.
Never throws an exception.
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.
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.
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.
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.
void
fz_sha256_init (
fz_sha256 *state
)
SHA256 initialization. Begins an SHA256 operation, initialising the supplied context.
Never throws an exception.
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.
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.
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.
void
fz_sha512_init (
fz_sha512 *state
)
SHA512 initialization. Begins an SHA512 operation, initialising the supplied context.
Never throws an exception.
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.
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.
typedef fz_sha512 fz_sha384
void
fz_sha384_init (
fz_sha384 *state
)
SHA384 initialization. Begins an SHA384 operation, initialising the supplied context.
Never throws an exception.
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.
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.
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.
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.
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.
void
fz_arc4_final (
fz_arc4 *state
)
RC4 finalization. Zero the context.
Never throws an exception.
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.
#define FZ_AES_DECRYPT 0
#define FZ_AES_ENCRYPT 1
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.
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.
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.
struct fz_chacha20 {
uint32_t s[16];
}
The ChaCha20 state is a vector of sixteen 32-bit words. Word 12 is the block counter.
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.
void
fz_chacha20_encrypt (
fz_chacha20 *seed,
unsigned char *dst,
const unsigned char *src,
uint32_t size
)
Encrypt bytes with ChaCha20 stream cipher.