MCPcopy Create free account
hub / github.com/DISTRHO/Cardinal / crypthead

Function crypthead

deps/unzipfx/crypt.c:231–262  ·  view source on GitHub ↗

* Write encryption header to file zfile using the password passwd * and the cyclic redundancy check crc. */

(passwd, crc, zfile)

Source from the content-addressed store, hash-verified

229 * and the cyclic redundancy check crc.
230 */
231void crypthead(passwd, crc, zfile)
232 ZCONST char *passwd; /* password string */
233 ulg crc; /* crc of file being encrypted */
234 FILE *zfile; /* where to write header */
235{
236 int n; /* index in random header */
237 int t; /* temporary */
238 int c; /* random byte */
239 uch header[RAND_HEAD_LEN]; /* random header */
240 static unsigned calls = 0; /* ensure different random header each time */
241
242 /* First generate RAND_HEAD_LEN-2 random bytes. We encrypt the
243 * output of rand() to get less predictability, since rand() is
244 * often poorly implemented.
245 */
246 if (++calls == 1) {
247 srand((unsigned)time(NULL) ^ ZCR_SEED2);
248 }
249 init_keys(passwd);
250 for (n = 0; n < RAND_HEAD_LEN-2; n++) {
251 c = (rand() >> 7) & 0xff;
252 header[n] = (uch)zencode(c, t);
253 }
254 /* Encrypt random header (last two bytes is high word of crc) */
255 init_keys(passwd);
256 for (n = 0; n < RAND_HEAD_LEN-2; n++) {
257 header[n] = (uch)zencode(header[n], t);
258 }
259 header[RAND_HEAD_LEN-2] = (uch)zencode((int)(crc >> 16) & 0xff, t);
260 header[RAND_HEAD_LEN-1] = (uch)zencode((int)(crc >> 24) & 0xff, t);
261 fwrite(header, 1, RAND_HEAD_LEN, f);
262}
263
264
265#ifdef UTIL

Callers 1

zipcloakFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected