Listing 2.6.
LM Hash Function


static const uchar SMB_LMHash_Magic[8] =
  { 'K', 'G', 'S', '!', '@', '#', '$', '%' };

uchar *smb_LMHash( const uchar *password, uchar *result )
  /* ---------------------------------------------------- **
   * Generate an LM Hash.
   * password - pointer to the raw password string.
   * result   - pointer to at least 16 bytes of memory
   *            into which the LM Hash will be written.
   * Returns a pointer to the LM Hash (== result).
   * ---------------------------------------------------- **
   */
  {
  uchar  tmp_pass[14] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
  uchar *hash;
  uchar  K1[7];
  uchar  K2[7];
  int    i;

  /* Copy at most 14 bytes of password to tmp_pass.
   * If the string is shorter, the unused bytes will
   * be nul-filled.
   */
  (void)strncpy( tmp_pass, password, 14 );

  /* Convert to upper-case.
   */
  for( i = 0; i < 14; i++ )
    tmp_pass[i] = toupper( tmp_pass[i] );

  /* Split tmp_pass into two 7-byte keys.
   */
  (void)memcpy( K1, tmp_pass, 7 );
  (void)memcpy( K2, (tmp_pass + 7), 7 );

  /* Use the keys to encrypt the 'magic' string.
   * Place each encrypted half into the result
   * buffer.
   */
  hash = DES( K1, SMB_LMHash_Magic );
  (void)memcpy( result, hash, 8 );
  hash = DES( K2, SMB_LMHash_Magic );
  (void)memcpy( (result + 8), hash, 8 );

  /* Return a pointer to the result.
   */
  return( result );
  } /* smb_LMHash */


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