Listing 2.7.
LM Response Function


uchar *smb_LMResponse( const uchar *LMHash,
                             uchar *chal,
                             uchar *resp )
  /* ---------------------------------------------------- **
   * Generate an LM Response
   * LMHash - pointer to the LM Hash of the password.
   * chal   - Pointer to the challenge.
   * resp   - pointer to at least 24 bytes of memory
   *          into which the LM response will be written.
   * Returns a pointer to the LM response (== resp).
   * ---------------------------------------------------- **
   */
  {
  uchar  P21[21];
  uchar  K[7];
  uchar *result;
  int    i;

  /* Copy the LM Hash to P21 and pad with nuls to 21 bytes.
   */
  (void)memcpy( P21, LMHash, 16 );
  (void)memset( (P21 + 16), 0, 5 );

  /* A compact method of splitting P21 into three keys,
   * generating a DES encryption of the challenge for
   * each key, and combining the results.
   * (i * 7) will give 0, 7, 14 and
   * (i * 8) will give 0, 8, 16.
   */
  for( i = 0; i < 3; i++ )
    {
    (void)memcpy( K, (P21 + (i * 7)) , 7 );
    result = DES( K, chal );
    (void)memcpy( (resp + (i * 8)), result, 8 );
    }

  /* Return the response.
   */
  return( resp );
  } /* smb_LMResponse */


$Revision: 1.3 $
$Date: 2003/01/04 18:55:20 $
[W3C Validated] Copyright © 2002-2003 Christopher R. Hertel 
Released under the terms of the LGPL