1/*
2  Copyright (c) 1990-2006 Info-ZIP.  All rights reserved.
3
4  See the accompanying file LICENSE, version 2005-Feb-10 or later
5  (the contents of which are also included in (un)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
8*/
9/*
10  crypt.h (full version) by Info-ZIP.   Last revised:  [see CR_VERSION_DATE]
11
12  The main encryption/decryption source code for Info-Zip software was
13  originally written in Europe.  To the best of our knowledge, it can
14  be freely distributed in both source and object forms from any country,
15  including the USA under License Exception TSU of the U.S. Export
16  Administration Regulations (section 740.13(e)) of 6 June 2002.
17
18  NOTE on copyright history:
19  Previous versions of this source package (up to version 2.8) were
20  not copyrighted and put in the public domain.  If you cannot comply
21  with the Info-Zip LICENSE, you may want to look for one of those
22  public domain versions.
23 */
24
25#ifndef __crypt_h   /* don't include more than once */
26#define __crypt_h
27
28#ifdef CRYPT
29#  undef CRYPT
30#endif
31/*
32   Logic of selecting "full crypt" code:
33   a) default behaviour:
34      - dummy crypt code when compiling UnZipSFX stub, to minimize size
35      - full crypt code when used to compile Zip, UnZip and fUnZip
36   b) USE_CRYPT defined:
37      - always full crypt code
38   c) NO_CRYPT defined:
39      - never full crypt code
40   NO_CRYPT takes precedence over USE_CRYPT
41 */
42#if defined(NO_CRYPT)
43#  define CRYPT  0  /* dummy version */
44#else
45#if defined(USE_CRYPT)
46#  define CRYPT  1  /* full version */
47#else
48#if !defined(SFX)
49#  define CRYPT  1  /* full version for zip and main unzip */
50#else
51#  define CRYPT  0  /* dummy version for unzip sfx */
52#endif
53#endif /* ?USE_CRYPT */
54#endif /* ?NO_CRYPT */
55
56#if CRYPT
57/* full version */
58
59#ifdef CR_BETA
60#  undef CR_BETA    /* this is not a beta release */
61#endif
62
63#define CR_MAJORVER        2
64#define CR_MINORVER        91
65#ifdef CR_BETA
66#  define CR_BETA_VER      "a BETA"
67#  define CR_VERSION       "2.91a BETA"
68#  define CR_VERSION_DATE  "31 May 2006"       /* last real code change */
69#else
70#  define CR_BETA_VER      ""
71#  define CR_VERSION       "2.91"
72#  define CR_VERSION_DATE  "31 May 2006"       /* last public release date */
73#  define CR_RELEASE
74#endif
75
76#ifndef __G         /* UnZip only, for now (DLL stuff) */
77#  define __G
78#  define __G__
79#  define __GDEF
80#  define __GPRO    void
81#  define __GPRO__
82#endif
83
84#if defined(MSDOS) || defined(OS2) || defined(WIN32)
85#  ifndef DOS_OS2_W32
86#    define DOS_OS2_W32
87#  endif
88#endif
89
90#if defined(DOS_OS2_W32) || defined(__human68k__)
91#  ifndef DOS_H68_OS2_W32
92#    define DOS_H68_OS2_W32
93#  endif
94#endif
95
96#if defined(VM_CMS) || defined(MVS)
97#  ifndef CMS_MVS
98#    define CMS_MVS
99#  endif
100#endif
101
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
104 * differently.
105 */
106#ifdef ZIP
107#  ifdef REALLY_SHORT_SYMS
108#    define decrypt_byte   zdcrby
109#  else
110#    define decrypt_byte   zp_decrypt_byte
111#  endif
112#  define  update_keys     zp_update_keys
113#  define  init_keys       zp_init_keys
114#else /* !ZIP */
115#  ifdef REALLY_SHORT_SYMS
116#    define decrypt_byte   dcrbyt
117#  endif
118#endif /* ?ZIP */
119
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
123#endif
124#define RAND_HEAD_LEN  12       /* length of encryption random header */
125
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;
130# else
131   extern ZCONST ulg Far *crc_32_tab;
132# endif
133#endif /* !CRC_32_TAB */
134
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))
137
138/* decode byte c in place */
139#define zdecode(c)   update_keys(__G__ c ^= decrypt_byte(__G))
140
141int  decrypt_byte OF((__GPRO));
142int  update_keys OF((__GPRO__ int c));
143void init_keys OF((__GPRO__ ZCONST char *passwd));
144
145#ifdef ZIP
146   void crypthead OF((ZCONST char *, ulg, FILE *));
147#  ifdef UTIL
148     int zipcloak OF((struct zlist far *, FILE *, FILE *, ZCONST char *));
149     int zipbare OF((struct zlist far *, FILE *, FILE *, ZCONST char *));
150#  else
151     unsigned zfwrite OF((zvoid *, extent, extent, FILE *));
152     extern char *key;
153#  endif
154#endif /* ZIP */
155
156#if (defined(UNZIP) && !defined(FUNZIP))
157   int  decrypt OF((__GPRO__ ZCONST char *passwrd));
158#endif
159
160#ifdef FUNZIP
161   extern int encrypted;
162#  ifdef NEXTBYTE
163#    undef NEXTBYTE
164#  endif
165#  define NEXTBYTE \
166   (encrypted? update_keys(__G__ getc(G.in)^decrypt_byte(__G)) : getc(G.in))
167#endif /* FUNZIP */
168
169#else /* !CRYPT */
170/* dummy version */
171
172#define zencode
173#define zdecode
174
175#define zfwrite  fwrite
176
177#endif /* ?CRYPT */
178#endif /* !__crypt_h */
179