MCPcopy Index your code
hub / github.com/MapServer/MapServer / msEncryptStringWithKey

Function msEncryptStringWithKey

mapcrypto.c:304–355  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

302 **********************************************************************/
303
304void msEncryptStringWithKey(const unsigned char *key, const char *in, char *out)
305{
306 ms_uint32 v[4], w[4];
307 const ms_uint32 *k;
308 int last_block = MS_FALSE;
309
310 /* Casting the key this way is safe only as long as longs are 4 bytes
311 * on this platform */
312 assert(sizeof(ms_uint32) == 4);
313 k = (const ms_uint32 *) key;
314
315 while(!last_block)
316 {
317 int i, j;
318 /* encipher() takes v[2] (64 bits) as input.
319 * Copy bytes from in[] to the v[2] input array (pair of 4 bytes)
320 * v[] is padded with zeros if string doesn't align with 8 bytes
321 */
322 v[0] = 0;
323 v[1] = 0;
324 for(i=0; !last_block && i<2; i++)
325 {
326 for(j=0; j<4; j++)
327 {
328 if (*in == '\0')
329 {
330 last_block = MS_TRUE;
331 break;
332 }
333
334 v[i] |= *in << (j*8);
335 in++;
336 }
337 }
338
339 if (*in == '\0')
340 last_block = MS_TRUE;
341
342 /* Do the actual encryption */
343 encipher(v, w, k);
344
345 /* Append hex-encoded bytes to output, 4 bytes at a time */
346 msHexEncode((unsigned char *)w, out, 4);
347 out += 8;
348 msHexEncode((unsigned char *)(w+1), out, 4);
349 out += 8;
350
351 }
352
353 /* Make sure output is 0-terminated */
354 *out = '\0';
355}
356
357/**********************************************************************
358 * msDecryptStringWithKey()

Callers 2

mainFunction · 0.85
mainFunction · 0.85

Calls 2

encipherFunction · 0.85
msHexEncodeFunction · 0.85

Tested by

no test coverage detected