note 104529 deleted from function.sha1 by danbrown

From: Date: Tue, 21 Jun 2011 14:55:29 +0000
Subject: note 104529 deleted from function.sha1 by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-180807@lists.php.net to get a copy of this message
Note Submitter: grosbedo at gmail dot com ---- I just stumbled on these old comments and I would like to add some notes about the specifications and usage of obscure() function by mVamer and ranko84. First, the obscure() function should take 3 parameters : obscure($password, $salt = null, $algorythm = "sha1"); Secondly, to get a randomly salted hash for a password, just call : obscure($password); Thirdly, to verify a password (even one with a randomly generated password), you do NOT need to store the salt, just call the obscure function like this : obscure($password_to_check, $hash_of_the_good_password); As you may have noticed, we give the good password hash as the value for $salt. Indeed, the particularity of this function is that it will always generate different variations of one same password if you DON'T give a salt, but if you give one, it will give you the same salt, and it is here used to verify a password. So, basically, to verify if the password is good, just do : if (obscure($password_to_check, $good_hash) == $good_hash) { // Authentication is OK } else { // Authentication is wrong } As you can see, we don't verify directly the hash of $password because obscure() can generate several variations of a same password, but with $good_hash as the salt, it will either return the same hash if it is the good one, either a new hash. ---- Having said that, the 2 primary benefits of this obscure() function are : - The salt is never directly stored and is randomly generated at each call and for each password, and it is NEVER retrieved, - The length of the hash is always the same, and this can deceive a lot of attackers. And the primary problems : - Uses sha1 as default (which is no more considered to be secure), but you can easily change it to some other crypto algorithm (whirlpool or sha512 advised). - The snowball effect is very slow -> this means that when you change a character or add one to the password, the hash will have some sequences of characters, and you need to change more characters to get a really different hash. - Bear in mind that this function is public (so if you use it as it is, attackers may freely analyze the code and prepare their attacks). - This function was not made nor verified by a cryptanalyst, and I'm not one neither. A seemingly better alternative has since been proposed here by an Anonymous on 29-Oct-2009 with his function __hash() which is very configurable with custom __scramble() and __harvest(). But if you use it, be careful to use very good functions (not necessarily complex ones as he may have said), but cryptographically strong, and it is not easy to know what is and what is not. For such reasons, I personnally keep on using an alterated version of obscure(), but even as it is, it seems to me to be quite a good algorithm (bear in mind that nothing is unbreakable, but it can be challenging enough). If a cryptanalyst come accross this page, it would be very interesting to have his opinion about it.

« previous php.notes (#180807) next »