36 #ifndef __MINIZIP_CRYPT_H__ 37 #define __MINIZIP_CRYPT_H__ 39 #define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8)) 44 static int decrypt_byte(
unsigned long* pkeys,
const unsigned long* pcrc_32_tab)
50 temp = ((unsigned)(*(pkeys+2)) & 0xffff) | 2;
51 return (
int)(((temp * (temp ^ 1)) >> 8) & 0xff);
57 static int update_keys(
unsigned long* pkeys,
const unsigned long* pcrc_32_tab,
int c)
59 (*(pkeys+0)) = CRC32((*(pkeys+0)), c);
60 (*(pkeys+1)) += (*(pkeys+0)) & 0xff;
61 (*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1;
63 register int keyshift = (int)((*(pkeys+1)) >> 24);
64 (*(pkeys+2)) = CRC32((*(pkeys+2)), keyshift);
74 static void init_keys(
const char* passwd,
unsigned long* pkeys,
const unsigned long* pcrc_32_tab)
76 *(pkeys+0) = 305419896L;
77 *(pkeys+1) = 591751049L;
78 *(pkeys+2) = 878082192L;
79 while (*passwd !=
'\0')
81 update_keys(pkeys,pcrc_32_tab,(
int)*passwd);
86 #define zdecode(pkeys,pcrc_32_tab,c) \ 87 (update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys,pcrc_32_tab))) 89 #define zencode(pkeys,pcrc_32_tab,c,t) \ 90 (t = decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), t^(c)) 92 #ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED 94 #define RAND_HEAD_LEN 12 97 # define ZCR_SEED2 3141592654UL 100 static int crypthead(
const char* passwd,
103 unsigned long* pkeys,
104 const unsigned long* pcrc_32_tab,
105 unsigned long crcForCrypting)
110 unsigned char header[RAND_HEAD_LEN-2];
111 static unsigned calls = 0;
113 if (bufSize<RAND_HEAD_LEN)
124 srand((
unsigned)(time(NULL) ^ ZCR_SEED2));
126 init_keys(passwd, pkeys, pcrc_32_tab);
127 for (n = 0; n < RAND_HEAD_LEN-2; n++)
129 c = (rand() >> 7) & 0xff;
130 header[n] = (
unsigned char)zencode(pkeys, pcrc_32_tab, c, t);
133 init_keys(passwd, pkeys, pcrc_32_tab);
134 for (n = 0; n < RAND_HEAD_LEN-2; n++)
136 buf[n] = (
unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t);
138 buf[n++] = (
unsigned char)zencode(pkeys, pcrc_32_tab, (
int)(crcForCrypting >> 16) & 0xff, t);
139 buf[n++] = (
unsigned char)zencode(pkeys, pcrc_32_tab, (
int)(crcForCrypting >> 24) & 0xff, t);
145 #endif //__MINIZIP_CRYPT_H__