home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / Networking / SambaManager / smbencrypt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-03-10  |  2.0 KB  |  84 lines

  1. /* 
  2.    Unix SMB/Netbios implementation.
  3.    Version 1.9.
  4.    SMB parameters and setup
  5.    Copyright (C) Andrew Tridgell 1992-1997
  6.    Modified by Jeremy Allison 1995.
  7.    
  8.    This program is free software; you can redistribute it and/or modify
  9.    it under the terms of the GNU General Public License as published by
  10.    the Free Software Foundation; either version 2 of the License, or
  11.    (at your option) any later version.
  12.    
  13.    This program is distributed in the hope that it will be useful,
  14.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.    GNU General Public License for more details.
  17.    
  18.    You should have received a copy of the GNU General Public License
  19.    along with this program; if not, write to the Free Software
  20.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.      
  22.      This was stolen and modified from the samba distribution.
  23.      You will most probably already have samba if you are using this software.
  24. */
  25.  
  26. #include "byteorder.h"
  27. #include "cryptdefs.h"
  28.  
  29. /* Routines for Windows NT MD4 Hash functions. */
  30. static int _my_wcslen(int16 *str)
  31. {
  32.     int len = 0;
  33.     while(*str++ != 0)
  34.         len++;
  35.     return len;
  36. }
  37.  
  38. /*
  39.  * Convert a string into an NT UNICODE string.
  40.  * Note that regardless of processor type 
  41.  * this must be in intel (little-endian)
  42.  * format.
  43.  */
  44.  
  45. static int _my_mbstowcs(int16 *dst, uchar *src, int len)
  46. {
  47.     int i;
  48.     int16 val;
  49.  
  50.     for(i = 0; i < len; i++) {
  51.         val = *src;
  52.         SSVAL(dst,0,val);
  53.         dst++;
  54.         src++;
  55.         if(val == 0)
  56.             break;
  57.     }
  58.     return i;
  59. }
  60.  
  61. /* 
  62.  * Creates the MD4 Hash of the users password in NT UNICODE.
  63.  */
  64.  
  65. void E_md4hash(uchar *passwd, uchar *p16)
  66. {
  67.     int len;
  68.     int16 wpwd[129];
  69.     
  70.     /* Password cannot be longer than 128 characters */
  71.     len = strlen((char *)passwd);
  72.     if(len > 128)
  73.         len = 128;
  74.     /* Password must be converted to NT unicode */
  75.     _my_mbstowcs(wpwd, passwd, len);
  76.     wpwd[len] = 0; /* Ensure string is null terminated */
  77.     /* Calculate length in bytes */
  78.     len = _my_wcslen(wpwd) * sizeof(int16);
  79.  
  80.     mdfour(p16, (unsigned char *)wpwd, len);
  81. }
  82.  
  83.  
  84.