1SmbHash(3)            User Contributed Perl Documentation           SmbHash(3)
2
3
4

NAME

6       Crypt::SmbHash - Perl-only implementation of lanman and nt md4 hash
7       functions, for use in Samba style smbpasswd entries
8

SYNOPSIS

10         use Crypt::SmbHash;
11
12         ntlmgen SCALAR, LMSCALAR, NTSCALAR;
13

DESCRIPTION

15       This module generates Lanman and NT MD4 style password hashes, using
16       perl-only code for portability. The module aids in the administration
17       of Samba style systems.
18
19       In the Samba distribution, authentication is referred to a private
20       smbpasswd file. Entries have similar forms to the following:
21
22       username:unixuid:LM:NT
23
24       Where LM and NT are one-way password hashes of the same password.
25
26       ntlmgen generates the hashes given in the first argument, and places
27       the result in the second and third arguments.
28
29       Example: To generate a smbpasswd entry:
30
31          #!/usr/local/bin/perl
32          use Crypt::SmbHash;
33          $username = $ARGV[0];
34          $password = $ARGV[1];
35          if ( !$password ) {
36                  print "Not enough arguments\n";
37                  print "Usage: $0 username password\n";
38                  exit 1;
39          }
40          $uid = (getpwnam($username))[2];
41          my ($login,undef,$uid) = getpwnam($ARGV[0]);
42          ntlmgen $password, $lm, $nt;
43          printf "%s:%d:%s:%s:[%-11s]:LCT-%08X\n", $login, $uid, $lm, $nt, "U", time;
44
45       ntlmgen returns returns the hash values in a list context, so the
46       alternative method of using it is:
47
48          ( $lm, $nt ) = ntlmgen $password;
49
50       The functions lmhash and nthash are used by ntlmgen to generate the
51       hashes, and are available when requested:
52
53          use Crypt::SmbHash qw(lmhash nthash)
54          $lm = lmhash($pass);
55          $nt = nthash($pass);
56
57       If Encoding is available (part of perl-5.8) the $pass argument to
58       ntlmgen, lmhash and nthash must be a perl string. In double use this:
59
60          use Crypt::SmbHash qw(ntlmgen lmhash nthash);
61          use Encode;
62          ( $lm, $nt ) = ntlmgen decode('iso-8859-1', $pass);
63          $lm = lmhash(decode_utf8($pass), $pwenc);
64          $nt = nthash(decode_utf8($pass));
65
66       The $pwenc parameter to lmhash() is optional and defaults to
67       'iso-8859-1'.  It specifies the encoding to which the password is
68       encoded before hashing.
69

MD4

71       The algorithm used in nthash requires the md4 algorithm. This algorithm
72       is included in this module for completeness, but because it is written
73       in all-perl code ( rather than in C ), it's not very quick.
74
75       However if you have the Digest::MD4 module installed, Crypt::SmbHash
76       will try to use that module instead, making it much faster.
77
78       A simple test compared calling nthash without Digest::MD4 installed,
79       and with, this showed that using nthash on a system with Digest::MD4
80       installed proved to be over 90 times faster.
81

AUTHOR

83       Ported from Samba by Benjamin Kuit <lt>bj@it.uts.edu.au<gt>.
84
85       Samba is Copyright(C) Andrew Tridgell 1997-1998
86
87       Because this module is a direct port of code within the Samba
88       distribution, it follows the same license, that is:
89
90          This program is free software; you can redistribute it and/or modify
91          it under the terms of the GNU General Public License as published by
92          the Free Software Foundation; either version 2 of the License, or
93          (at your option) any later version.
94
95          This program is distributed in the hope that it will be useful,
96          but WITHOUT ANY WARRANTY; without even the implied warranty of
97          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
98          GNU General Public License for more details.
99
100
101
102perl v5.32.0                      2020-07-28                        SmbHash(3)
Impressum