#include "rcs_defs.hh"
Include dependency graph for crypt2.hh:
This graph shows which files directly or indirectly include this file:
Go to the source code of this file.
Functions | |
RCS_EXPORT char * | rcs_crypt (const char *key, const char *passwd) |
|
Definition at line 611 of file crypt2.cc. Referenced by TCPMEM::login(), STCPMEM::login(), and RPCMEM::login().
00612 { 00613 // rcs_print("encrypting %s with %s\n", original, salt); 00614 unsigned int i, y, u; 00615 00616 if (strlen (salt) < 2) 00617 return NULL; 00618 00619 static unsigned char buffer[256]; 00620 memset (buffer, 0, 256); 00621 00622 unsigned char charZero = (unsigned char) salt[(0)]; 00623 unsigned char charOne = (unsigned char) salt[(1)]; 00624 00625 buffer[0] = charZero; 00626 buffer[1] = charOne; 00627 00628 unsigned int Eswap0 = con_salt[(unsigned int) charZero]; 00629 unsigned int Eswap1 = con_salt[(unsigned int) charOne] << 4; 00630 00631 unsigned char key[8]; 00632 00633 for (i = 0; i < 8; i++) 00634 key[i] = (char) 0; 00635 00636 #ifdef DEBUG_CRYPT 00637 printf ("original = %s\n", original); 00638 #endif 00639 00640 for (i = 0; i < 8 && i < strlen (original); i++) 00641 { 00642 unsigned int iChar = (unsigned int) original[(i)]; 00643 00644 key[i] = (unsigned char) (iChar << 1); 00645 } 00646 #ifdef DEBUG_CRYPT 00647 printf ("key = "); 00648 for (int jj = 0; jj < 8; jj++) 00649 { 00650 if (jj % 8 == 0) 00651 { 00652 printf ("\n"); 00653 } 00654 printf (" %8.8X ", key[jj]); 00655 } 00656 printf ("\n"); 00657 #endif 00658 00659 unsigned int *schedule = des_set_key (key); 00660 #ifdef DEBUG_CRYPT 00661 printf ("schedule = "); 00662 for (int ii = 0; ii < ITERATIONS * 2; ii++) 00663 { 00664 if (ii % 8 == 0) 00665 { 00666 printf ("\n"); 00667 } 00668 printf (" %8.8X ", schedule[ii]); 00669 } 00670 printf ("\n"); 00671 #endif 00672 00673 unsigned int *out = body (schedule, Eswap0, Eswap1); 00674 #ifdef DEBUG_CRYPT 00675 printf ("out = "); 00676 for (int iii = 0; iii < 2; iii++) 00677 { 00678 printf (" %8.8X ", out[iii]); 00679 } 00680 printf ("\n"); 00681 #endif 00682 00683 unsigned char b[9]; 00684 00685 intToFourChars (out[0], b, 0); 00686 intToFourChars (out[1], b, 4); 00687 b[8] = 0; 00688 00689 for (i = 2, y = 0, u = 0x80; i < 13; i++) 00690 { 00691 for (unsigned int j = 0, c = 0; j < 6; j++) 00692 { 00693 c <<= 1; 00694 00695 if (((unsigned int) b[y] & u) != 0) 00696 c |= 1; 00697 00698 u = u >> 1; 00699 00700 if (u == 0) 00701 { 00702 y++; 00703 u = 0x80; 00704 } 00705 buffer[i] = (unsigned char) cov_2char[c]; 00706 } 00707 } 00708 return ((char *) buffer); 00709 } |