On Wed, 26 Jun 2002, Alexandre Strube wrote:
> Ok, but my doubt is: how can radius correctly check that a hash
> corresponds to the password without knowing what salt was used to
> generate that hash?

Right, you just don't understand how crypt works.

Crypt is a one-way hash.  The salt is thrown away and irrelevant after the
creation fo the hash.

Crypt is a binary operator and in algebraic notation it goes like this (p
is plain-text, c is cyphertext, s is salt, @ is the crypt operator):

p @ s = c

p @ c = c

Dig?

So you don't need the salt.  If you has the plaintext with the crypt, you
get the crypt back... but only if the plaintext is the plaintext that was
used with the salt to create the crypt in the first place.

Here's a perl script that you can probably follow that will make
sense.  Note the difference in the two print statements.

#!/usr/bin/perl

# this is a subroutine that builds a salt.  Not too interesting.
sub salt {
 substr("./" . join("", "0".."9", "A".."Z", "a".."z"), int rand 64)
}

# seed the random number generator with something.
srand time;

# for input from stdin, line buffered
while (<>) {

# remove newlines when you hit enter.
   chomp; 

# create a new crypt based on the user's input and the salt.
   $newcrypt = crypt($_, salt.salt);

# Now crype the user's input against the crypt, rather than the salt.
   $secondcrypt = crypt($_, $newcrypt);

# print 'em both and compare!
   print "$newcrypt\n$secondcrypt \n";
}
__END__

See, you don't have to decrypt the password and then compare it to the
password submitted because that would mean the password could be decrypted
at any time.  And you don't have to crypt the password against the salt
every time and compare because then you could just reverse the operation
against the salt and generate the password from the crypt.  Instead, a
crypt is chosen such that when crypted with the plaintext, the crypt
itself is returned.

It's pretty clever.

J.
-- 
   -----------------
     Jeme A Brelin
    [EMAIL PROTECTED]
   -----------------
 [cc] counter-copyright
 http://www.openlaw.org


- 
List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html

Reply via email to