1/* 2 Copyright (c) 1990-2000 Info-ZIP. All rights reserved. 3 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 8*/ 9/* 10 crypt.h (full version) by Info-ZIP. Last revised: [see CR_VERSION_DATE] 11 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.) 16 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. 22 */ 23 24#ifndef __crypt_h /* don't include more than once */ 25#define __crypt_h 26 27#ifdef CRYPT 28# undef CRYPT 29#endif 30/* 31 Logic of selecting "full crypt" code: 32 a) default behaviour: 33 - dummy crypt code when used to compile Zip 34 (because we do not distribute encrypting versions of Zip from US 35 servers) 36 - dummy crypt code when compiling UnZipSFX stub, to minimize size 37 - full crypt code when used to compile UnZip and fUnZip 38 b) USE_CRYPT defined: 39 - always full crypt code 40 c) NO_CRYPT defined: 41 - never full crypt code 42 NO_CRYPT takes precedence over USE_CRYPT 43 */ 44#if defined(NO_CRYPT) 45# define CRYPT 0 /* dummy version */ 46#else 47#if defined(USE_CRYPT) 48# define CRYPT 1 /* full version */ 49#else 50#if (!defined(ZIP) && !defined(SFX)) 51# define CRYPT 1 /* full version */ 52#else 53# define CRYPT 0 /* dummy version */ 54#endif 55#endif /* ?USE_CRYPT */ 56#endif /* ?NO_CRYPT */ 57 58#if CRYPT 59/* full version */ 60 61#ifdef CR_BETA 62# undef CR_BETA /* this is not a beta release */ 63#endif 64 65#define CR_MAJORVER 2 66#define CR_MINORVER 9 67#ifdef CR_BETA 68# define CR_BETA_VER "a BETA" 69# define CR_VERSION_DATE "05 May 2000" /* last real code change */ 70#else 71# define CR_BETA_VER "" 72# define CR_VERSION_DATE "05 May 2000" /* 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