added iOS source code
[wl-app.git] / iOS / Pods / SSZipArchive / SSZipArchive / minizip / crypt.h
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
23 typedef unsigned long z_crc_t;
24 #endif
25
26 #ifdef __cplusplus
27 extern "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 */
43 uint8_t decrypt_byte(uint32_t *pkeys);
44
45 /* Update the encryption keys with the next byte of plain text */
46 uint8_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. */
49 void init_keys(const char *passwd, uint32_t *pkeys, const z_crc_t *pcrc_32_tab);
50
51 /* Generate cryptographically secure random numbers */
52 int cryptrand(unsigned char *buf, unsigned int len);
53
54 /* Create encryption header */
55 int crypthead(const char *passwd, uint8_t *buf, int buf_size, uint32_t *pkeys,
56     const z_crc_t *pcrc_32_tab, uint8_t verify1, uint8_t verify2);
57
58 /***************************************************************************/
59
60 #ifdef __cplusplus
61 }
62 #endif
63
64 #endif