Re: Hashing a password
- From: Baho Utot <baho-utot@xxxxxxxxxxx>
- Date: Mon, 24 Mar 2008 17:28:25 -0400
On Sun, 23 Mar 2008 16:44:24 -0700, Joshua B wrote:
I'm trying to hash a password given the password entered as a string and
a hashkey that I'm given from elsewhere. Here are the instructions I
have for doing the hashing:
"Receive a single line, turn it into bytes. This is the password hashing
key. It's 32 bytes long."
"For each character pw[i] in the password, compute (pw[i] - 0x20) ^
hashkey[i] + 0x20."
This is how I read the key:
$hashkey = fgets($this->socket);
Then I call my hash function:
$hashpw = $this->hashPassword($password, $hashkey);
private function hashPassword($password, $hashkey) {
$stop = strlen($password);
if ($stop > strlen($hashkey)) {
$stop = strlen($hashkey);
}
You only need to check to see if $password is less than or equal to 32 as
the hash key is 32 bytes long.
$hashpw = "";
for ($i = 0; $i < $stop; $i++) {
$hashpw[$i] = (($password[$i] - 0x20) ^ $hashkey[$i]) +
0x20;
}
return $hashpw;
}
Only that doesn't seem to work. I'm assuming it's maybe not treating
the characters correctly when moving stuff around, but I don't know
enough about how PHP does that to know. I've tried a few different
things but nothing seems to work. (Work as in, when I send $hashpw out
it's rejected as being an invalid password. I'm using a simple test so
I know it's not an issue of typing the wrong password.)
Any ideas?
What language was this originally written in?
If written in C
"For each character pw[i] in the password, compute (pw[i] - 0x20) ^
hashkey[i] + 0x20."
And if I recall correctly:
(pw[i] - 0x20) -- "Strip ASCII bias"
^ hashkey[i] -- Bitwise exclusive OR
+ 0x20 -- Return value to ASCII
I take it that the hash key is some 8 bit binary code?
I would try using an array for hashpw instead of a string value, a
string value in PHP may be larger than 8 bits, It could be platform
dependent, possibly being 16 or 32 bits long. That would make the XOR
return some invalid result, ie promoting an 8 bit value (hash key) to a
16 bit value before doing the XOR.
Another thing you may want to try is to copy the operands into a numeric
variable then preform the XOR operation back into a numeric variable,
then place the result back into the string. I don't know how PHP is
massaging the string to integer to string conversions.
Manipulating a passwords with a simple XOR is not very secure. It is
only better than almost no security.
--
Tayo'y Mga Pinoy
.
- Follow-Ups:
- Re: Hashing a password
- From: Joshua B
- Re: Hashing a password
- References:
- Hashing a password
- From: Joshua B
- Hashing a password
- Prev by Date: Re: Getting ascii value of a char
- Next by Date: Re: Displaying PHP code
- Previous by thread: Re: Hashing a password
- Next by thread: Re: Hashing a password
- Index(es):
Relevant Pages
|