| 364 | **********************************************************************/ |
| 365 | |
| 366 | void msDecryptStringWithKey(const unsigned char *key, const char *in, char *out) |
| 367 | { |
| 368 | ms_uint32 v[4], w[4]; |
| 369 | const ms_uint32 *k; |
| 370 | int last_block = MS_FALSE; |
| 371 | |
| 372 | /* Casting the key this way is safe only as long as longs are 4 bytes |
| 373 | * on this platform */ |
| 374 | assert(sizeof(ms_uint32) == 4); |
| 375 | k = (const ms_uint32 *) key; |
| 376 | |
| 377 | while(!last_block) |
| 378 | { |
| 379 | int i; |
| 380 | /* decipher() takes v[2] (64 bits) as input. |
| 381 | * Copy bytes from in[] to the v[2] input array (pair of 4 bytes) |
| 382 | * v[] is padded with zeros if string doesn't align with 8 bytes |
| 383 | */ |
| 384 | v[0] = 0; |
| 385 | v[1] = 0; |
| 386 | |
| 387 | if (msHexDecode(in, (unsigned char *)v, 8) != 4) |
| 388 | last_block = MS_TRUE; |
| 389 | else |
| 390 | { |
| 391 | in += 8; |
| 392 | if (msHexDecode(in, (unsigned char *)(v+1), 8) != 4) |
| 393 | last_block = MS_TRUE; |
| 394 | else |
| 395 | in += 8; |
| 396 | } |
| 397 | |
| 398 | /* Do the actual decryption */ |
| 399 | decipher(v, w, k); |
| 400 | |
| 401 | /* Copy the results to out[] */ |
| 402 | for(i=0; i<2; i++) |
| 403 | { |
| 404 | *out++ = (w[i] & 0x000000ff); |
| 405 | *out++ = (w[i] & 0x0000ff00) >> 8; |
| 406 | *out++ = (w[i] & 0x00ff0000) >> 16; |
| 407 | *out++ = (w[i] & 0xff000000) >> 24; |
| 408 | } |
| 409 | |
| 410 | if (*in == '\0') |
| 411 | last_block = MS_TRUE; |
| 412 | } |
| 413 | |
| 414 | /* Make sure output is 0-terminated */ |
| 415 | *out = '\0'; |
| 416 | } |
| 417 | |
| 418 | /********************************************************************** |
| 419 | * msDecryptStringTokens() |
no test coverage detected