MCPcopy Create free account
hub / github.com/DreamSourceLab/DSView / crypthead

Function crypthead

common/minizip/crypt.h:90–129  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

88# endif
89
90static int crypthead(const char* passwd, /* password string */
91 unsigned char* buf, /* where to write header */
92 int bufSize,
93 unsigned long* pkeys,
94 const z_crc_t* pcrc_32_tab,
95 unsigned long crcForCrypting)
96{
97 int n; /* index in random header */
98 int t; /* temporary */
99 int c; /* random byte */
100 unsigned char header[RAND_HEAD_LEN-2]; /* random header */
101 static unsigned calls = 0; /* ensure different random header each time */
102
103 if (bufSize<RAND_HEAD_LEN)
104 return 0;
105
106 /* First generate RAND_HEAD_LEN-2 random bytes. We encrypt the
107 * output of rand() to get less predictability, since rand() is
108 * often poorly implemented.
109 */
110 if (++calls == 1)
111 {
112 srand((unsigned)(time(NULL) ^ ZCR_SEED2));
113 }
114 init_keys(passwd, pkeys, pcrc_32_tab);
115 for (n = 0; n < RAND_HEAD_LEN-2; n++)
116 {
117 c = (rand() >> 7) & 0xff;
118 header[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, c, t);
119 }
120 /* Encrypt random header (last two bytes is high word of crc) */
121 init_keys(passwd, pkeys, pcrc_32_tab);
122 for (n = 0; n < RAND_HEAD_LEN-2; n++)
123 {
124 buf[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t);
125 }
126 buf[n++] = (unsigned char)zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t);
127 buf[n++] = (unsigned char)zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t);
128 return n;
129}
130
131#endif

Callers 1

zip.cFile · 0.85

Calls 1

init_keysFunction · 0.85

Tested by

no test coverage detected