MD4 and DES for unicode strings (samba passwd file manipulation)

Arcady Genkin agenkin at cdf.toronto.edu
Wed Sep 4 00:17:05 EDT 2002


I'd like to manipulate on Samba's password file from Python in order
to set/change samba passwords.  Samba stores the password encrypted
two ways: with DES algorithm, and hashed with MD4[1].  I found and
installed 'pycrypto' module[2], which provides the above algorithms.
And yet I can't create the right crypted strings:

  >>> from Crypto.Hash import MD4
  >>> 
  >>> m = MD4.new()
  >>> m.update( u'111222333' )
  >>> m.hexdigest().upper()
  'A672E5EDFDAD90A15228E0AEC2AA9161'
  >>> # SAMBA-encoded password "111222333":
  >>> samba
  'B66B458E27BD714F99A05EE3C479FBF1'

Perhaps the problem lies with Unicode encoding?  Samba's man page (see
the link below) says that the string is obtained by taking MD4 hash on
the password, represented as a string of 16-bit little-endian unicode
characters.

Any other ideas?  Any help greatly appreciated.

Footnotes: 
[1]  http://www.samba.org/samba/docs/man/smbpasswd.5.html
[2]  http://www.amk.ca/python/code/crypto.html

-- 
Arcady Genkin : CDF sysadmin : http://cdf.toronto.edu/~agenkin/contact.html

guilt is the cause of more disauders
than history's most obscene marorders                       (E.E. Cummings)



More information about the Python-list mailing list