MCPcopy Create free account
hub / github.com/ObEngine/ObEngine / crypthead

Function crypthead

extlibs/minizip/include/minizip/crypt.h:91–130  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

zip.cFile · 0.85

Calls 1

init_keysFunction · 0.85

Tested by

no test coverage detected