Logo Search packages:      
Sourcecode: freetds version File versions

void tds_answer_challenge ( const char *  passwd,
const unsigned char *  challenge,
TDSANSWER *  answer 
)

Crypt a given password using schema required for NTLMv1 authentication

Parameters:
passwd clear text domain password
challenge challenge data given by server
answer buffer where to store crypted password

Definition at line 65 of file challenge.c.

References tds_answer_challenge().

Referenced by tds_answer_challenge().

{
#define MAX_PW_SZ 14
      int len;
      int i;
      static const des_cblock magic = { 0x4B, 0x47, 0x53, 0x21, 0x40, 0x23, 0x24, 0x25 };
      DES_KEY ks;
      unsigned char hash[24];
      unsigned char passwd_up[MAX_PW_SZ];
      unsigned char nt_pw[256];
      MD4_CTX context;

      memset(answer, 0, sizeof(TDSANSWER));

      /* convert password to upper and pad to 14 chars */
      memset(passwd_up, 0, MAX_PW_SZ);
      len = strlen(passwd);
      if (len > MAX_PW_SZ)
            len = MAX_PW_SZ;
      for (i = 0; i < len; i++)
            passwd_up[i] = toupper((unsigned char) passwd[i]);

      /* hash the first 7 characters */
      tds_convert_key(passwd_up, &ks);
      tds_des_ecb_encrypt(&magic, sizeof(magic), &ks, (hash + 0));

      /* hash the second 7 characters */
      tds_convert_key(passwd_up + 7, &ks);
      tds_des_ecb_encrypt(&magic, sizeof(magic), &ks, (hash + 8));

      memset(hash + 16, 0, 5);

      tds_encrypt_answer(hash, challenge, answer->lm_resp);

      /* NT resp */
      len = strlen(passwd);
      if (len > 128)
            len = 128;
      for (i = 0; i < len; ++i) {
            nt_pw[2 * i] = passwd[i];
            nt_pw[2 * i + 1] = 0;
      }

      MD4Init(&context);
      MD4Update(&context, nt_pw, len * 2);
      MD4Final(&context, hash);

      memset(hash + 16, 0, 5);
      tds_encrypt_answer(hash, challenge, answer->nt_resp);

      /* with security is best be pedantic */
      memset(&ks, 0, sizeof(ks));
      memset(hash, 0, sizeof(hash));
      memset(passwd_up, 0, sizeof(passwd_up));
      memset(nt_pw, 0, sizeof(nt_pw));
      memset(&context, 0, sizeof(context));
}


Generated by  Doxygen 1.6.0   Back to index