ARX  1.0
The next-generation open source augmented reality toolkit.
Loading...
Searching...
No Matches
crypt.h
Go to the documentation of this file.
1/* crypt.h -- base code for traditional PKWARE encryption
2 Version 1.2.0, September 16th, 2017
3
4 Copyright (C) 2012-2017 Nathan Moinvaziri
5 https://github.com/nmoinvaz/minizip
6 Copyright (C) 1998-2005 Gilles Vollant
7 Modifications for Info-ZIP crypting
8 http://www.winimage.com/zLibDll/minizip.html
9 Copyright (C) 2003 Terry Thorsen
10
11 This code is a modified version of crypting code in Info-ZIP distribution
12
13 Copyright (C) 1990-2000 Info-ZIP. All rights reserved.
14
15 This program is distributed under the terms of the same license as zlib.
16 See the accompanying LICENSE file for the full text of the license.
17*/
18
19#ifndef _MINICRYPT_H
20#define _MINICRYPT_H
21
22#if ZLIB_VERNUM < 0x1270
23typedef unsigned long z_crc_t;
24#endif
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30#define RAND_HEAD_LEN 12
31
32/***************************************************************************/
33
34#define zdecode(pkeys,pcrc_32_tab,c) \
35 (update_keys(pkeys,pcrc_32_tab, c ^= decrypt_byte(pkeys)))
36
37#define zencode(pkeys,pcrc_32_tab,c,t) \
38 (t = decrypt_byte(pkeys), update_keys(pkeys,pcrc_32_tab,c), t^(c))
39
40/***************************************************************************/
41
42/* Return the next byte in the pseudo-random sequence */
43uint8_t decrypt_byte(uint32_t *pkeys);
44
45/* Update the encryption keys with the next byte of plain text */
46uint8_t update_keys(uint32_t *pkeys, const z_crc_t *pcrc_32_tab, int32_t c);
47
48/* Initialize the encryption keys and the random header according to the given password. */
49void init_keys(const char *passwd, uint32_t *pkeys, const z_crc_t *pcrc_32_tab);
50
51#ifndef NOCRYPT
52/* Generate cryptographically secure random numbers */
53int cryptrand(unsigned char *buf, unsigned int len);
54
55/* Create encryption header */
56int crypthead(const char *passwd, uint8_t *buf, int buf_size, uint32_t *pkeys,
57 const z_crc_t *pcrc_32_tab, uint8_t verify1, uint8_t verify2);
58#endif
59
60/***************************************************************************/
61
62#ifdef __cplusplus
63}
64#endif
65
66#endif
unsigned long z_crc_t
Definition: crypt.h:23
int crypthead(const char *passwd, uint8_t *buf, int buf_size, uint32_t *pkeys, const z_crc_t *pcrc_32_tab, uint8_t verify1, uint8_t verify2)
Definition: crypt.c:119
uint8_t update_keys(uint32_t *pkeys, const z_crc_t *pcrc_32_tab, int32_t c)
Definition: crypt.c:61
int cryptrand(unsigned char *buf, unsigned int len)
Definition: crypt.c:88
void init_keys(const char *passwd, uint32_t *pkeys, const z_crc_t *pcrc_32_tab)
Definition: crypt.c:73
uint8_t decrypt_byte(uint32_t *pkeys)
Definition: crypt.c:51