2 Copyright (c) 1990-2000 Info-ZIP. All rights reserved.
4 See the accompanying file LICENSE, version 2000-Apr-09 or later
5 (the contents of which are also included in zip.h) for terms of use.
6 If, for some reason, all these files are missing, the Info-ZIP license
7 also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
10 crypt.h (full version) by Info-ZIP. Last revised: [see CR_VERSION_DATE]
12 This encryption/decryption source code for Info-Zip software was
13 originally written in Europe. The whole source package can be
14 freely distributed, including from the USA. (Prior to January 2000,
15 re-export from the US was a violation of US law.)
17 NOTE on copyright history:
18 Previous versions of this source package (up to version 2.8) were
19 not copyrighted and put in the public domain. If you cannot comply
20 with the Info-Zip LICENSE, you may want to look for one of those
21 public domain versions.
24 #ifndef __crypt_h /* don't include more than once */
31 Logic of selecting "full crypt" code:
33 - dummy crypt code when used to compile Zip
34 (because we do not distribute encrypting versions of Zip from US
36 - dummy crypt code when compiling UnZipSFX stub, to minimize size
37 - full crypt code when used to compile UnZip and fUnZip
39 - always full crypt code
41 - never full crypt code
42 NO_CRYPT takes precedence over USE_CRYPT
45 # define CRYPT 0 /* dummy version */
47 #if defined(USE_CRYPT)
48 # define CRYPT 1 /* full version */
50 #if (!defined(ZIP) && !defined(SFX))
51 # define CRYPT 1 /* full version */
53 # define CRYPT 0 /* dummy version */
55 #endif /* ?USE_CRYPT */
56 #endif /* ?NO_CRYPT */
62 # undef CR_BETA /* this is not a beta release */
68 # define CR_BETA_VER "a BETA"
69 # define CR_VERSION_DATE "05 May 2000" /* last real code change */
71 # define CR_BETA_VER ""
72 # define CR_VERSION_DATE "05 May 2000" /* last public release date */
76 #ifndef __G /* UnZip only, for now (DLL stuff) */
84 #if defined(MSDOS) || defined(OS2) || defined(WIN32)
90 #if defined(DOS_OS2_W32) || defined(__human68k__)
91 # ifndef DOS_H68_OS2_W32
92 # define DOS_H68_OS2_W32
96 #if defined(VM_CMS) || defined(MVS)
102 /* To allow combining of Zip and UnZip static libraries in a single binary,
103 * the Zip and UnZip versions of the crypt core functions have to be named
107 # ifdef REALLY_SHORT_SYMS
108 # define decrypt_byte zdcrby
110 # define decrypt_byte zp_decrypt_byte
112 # define update_keys zp_update_keys
113 # define init_keys zp_init_keys
115 # ifdef REALLY_SHORT_SYMS
116 # define decrypt_byte dcrbyt
120 #define IZ_PWLEN 80 /* input buffer size for reading encryption key */
121 #ifndef PWLEN /* for compatibility with previous zcrypt release... */
122 # define PWLEN IZ_PWLEN
124 #define RAND_HEAD_LEN 12 /* length of encryption random header */
126 /* the crc_32_tab array has to be provided externally for the crypt calculus */
127 #ifndef CRC_32_TAB /* UnZip provides this in globals.h */
128 # if (!defined(USE_ZLIB) || defined(USE_OWN_CRCTAB))
129 extern ZCONST ulg near
*crc_32_tab
;
131 extern ZCONST ulg Far
*crc_32_tab
;
133 #endif /* !CRC_32_TAB */
135 /* encode byte c, using temp t. Warning: c must not have side effects. */
136 #define zencode(c,t) (t=decrypt_byte(__G), update_keys(c), t^(c))
138 /* decode byte c in place */
139 #define zdecode(c) update_keys(__G__ c ^= decrypt_byte(__G))
141 int decrypt_byte
OF((__GPRO
));
142 int update_keys
OF((__GPRO__
int c
));
143 void init_keys
OF((__GPRO__ ZCONST
char *passwd
));
146 void crypthead
OF((ZCONST
char *, ulg
, FILE *));
148 int zipcloak
OF((struct zlist far
*, FILE *, FILE *, ZCONST
char *));
149 int zipbare
OF((struct zlist far
*, FILE *, FILE *, ZCONST
char *));
151 unsigned zfwrite
OF((zvoid
*, extent
, extent
, FILE *));
156 #if (defined(UNZIP) && !defined(FUNZIP))
157 int decrypt
OF((__GPRO__ ZCONST
char *passwrd
));
161 extern int encrypted
;
166 (encrypted? update_keys(__G__ getc(G.in)^decrypt_byte(__G)) : getc(G.in))
175 #define zfwrite fwrite
178 #endif /* !__crypt_h */