MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / ENC_crypt

Function ENC_crypt

src/common/enc.cpp:462–601  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

460
461
462void ENC_crypt(TEXT* buf, size_t bufSize, const TEXT* key, const TEXT* setting)
463{
464 fb_assert(bufSize >= RESULT_SIZE);
465 Firebird::MutexLockGuard guard(cryptMutex, "ENC_crypt");
466
467 int t;
468 int num_iter, salt_size;
469 C_block keyblock;
470
471 for (SLONG i = 0; i < 8; i++)
472 {
473 if ((t = 2 * (unsigned char) (*key)) != 0)
474 key++;
475 keyblock.b[i] = t;
476 }
477 if (des_setkey(keyblock.b)) // also initializes "a64toi"
478 {
479 buf[0] = 0;
480 return;
481 }
482
483 char* encp = buf;
484 switch (*setting)
485 {
486 case _PASSWORD_EFMT1:
487 // Involve the rest of the password 8 characters at a time.
488 while (*key)
489 {
490 if (des_cipher(&keyblock, &keyblock, 0L, 1))
491 {
492 buf[0] = 0;
493 return;
494 }
495 for (SLONG i = 0; i < 8; i++)
496 {
497 if ((t = 2 * (unsigned char) (*key)) != 0)
498 key++;
499 keyblock.b[i] ^= t;
500 }
501 if (des_setkey(keyblock.b))
502 {
503 buf[0] = 0;
504 return;
505 }
506 }
507
508 *encp++ = *setting++;
509
510 // get iteration count
511 num_iter = 0;
512 for (SLONG i = 4; --i >= 0;)
513 {
514 if ((t = (unsigned char) setting[i]) == '\0')
515 t = '.';
516 encp[i] = t;
517 num_iter = (num_iter << 6) | a64toi[t];
518 }
519 setting += 4;

Callers 3

ServerAuthMethod · 0.85
authenticateMethod · 0.85
authenticateMethod · 0.85

Calls 2

des_setkeyFunction · 0.85
des_cipherFunction · 0.85

Tested by

no test coverage detected