knop_crypthash - using hashed password, salt, and cost

1 view
Skip to first unread message

Steve Piercy - Website Builder

unread,
Jul 9, 2015, 4:18:56 AM7/9/15
to knop-p...@googlegroups.com
I'm doing a code review in knop_user -> login and its
dependencies. There's a code block that leaves me scratching my head.
https://github.com/knop-project/knop/blob/master/knop9/knoplibs/knop_user.lasso#L436-L442

if(knop_crypthash(#_password,
-hash = string(#db -> field(.'passwordfield')),
-salt = knop_blowfish(-string = #db ->
field(.'saltfield'), -mode = 'D'),
-cost = (.'costfield' -> size ? integer(#db ->
field(.'costfield')) | .'costsize'),
-cipher = (.'encrypt_cipher')) == true) => {

#validlogin = true
}

...and the source for knop_crypthash:
https://github.com/knop-project/knop/blob/master/knop9/knoplibs/knop_utils.lasso#L482-L563

From this I've tried to reverse engineer how passwords should
be stored (and other bits used for knop_user -> login), but I
have not been successful. It looks like knop_blowfish is used
to encrypt the salt and store that in the database. Then on
login, the value in the saltfield is decrypted with
knop_blowfish and passed into the -salt argument for knop_crypthash.

When I tried storing the password like that and try
authentication with the -cost parameter, knop_user -> login
always fails. All other knop_user -> login methods that do not
use -cost work for me.

If anyone has this working (Rick Draper, Jolle Carlestam),
please share a code sample of how you create a user record with
its fields for username, password (hashed), saltfield,
costfield, and any other relevant bits.

Also include whether anything more elaborate than knop_user ->
login('u', 'p') is called.

Finally, is there a reason that knop_blowfish is used here? In
Bil Corry's original post on the topic, he didn't mention using
blowfish. Here's a gist I threw together to test it.

Bil's post
http://lasso.2283332.n4.nabble.com/encryption-tt3140901.html#a3140908

My gist.
https://gist.github.com/stevepiercy/acf9d559e596e57f7c3a

Thanks in advance.

--steve

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Steve Piercy Website Builder Soquel, CA
<w...@StevePiercy.com> <http://www.StevePiercy.com/>

Bil Corry

unread,
Jul 11, 2015, 3:38:23 AM7/11/15
to Steve Piercy - Website Builder, knop-p...@googlegroups.com
Looking at the code, blowfish is used for the salt, not the hash, which is fine.  The hash is RIPEMD160, which is also fine:


You'll want cost working, that's important in case your hashes are stolen.

I also noticed SHA1 is the default when a cipher isn't specified:


SHA1 is on the way out, it should be SHA2 (e.g. SHA-256, SHA-512, etc).


- Bil



--
You received this message because you are subscribed to the Google Groups "knop-project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to knop-project...@googlegroups.com.
To post to this group, send email to knop-p...@googlegroups.com.
Visit this group at http://groups.google.com/group/knop-project.
To view this discussion on the web visit https://groups.google.com/d/msgid/knop-project/r422Ps-1085i-BAC72554BB144FCE9390547897A03C19%40ip30.192-168-0.rfc1918.steadfastdns.net.
For more options, visit https://groups.google.com/d/optout.

Steve Piercy

unread,
Jul 11, 2015, 4:34:41 AM7/11/15
to knop-p...@googlegroups.com
I forgot to follow up, I worked it out with some helpful
guidance from Jolle.

I use RIPEMD160 when hashing. Also I have some revisions for
Knop that I need to merge, one of which is using RIPEMD160 as
the default.

I assumed cost was working in your implementation in
lp_crypt_hash. Is this not done correctly?
http://lasso.2283332.n4.nabble.com/encryption-tt3140901.html#a3140908

In my implementation, I specify a cost as a random integer
between 20 and 2000 (instead of the default 20), and store the
value in the database. I got that idea from another post.
http://lasso.2283332.n4.nabble.com/Encrypted-data-tt3305756.html#a3308152

And other practices from this post. Yes, I'm stalking you Bil. :P
http://lasso.2283332.n4.nabble.com/Looking-for-input-Authentication-tt3131137.html#a3131138

I have been soaking up crypto stuff from those who have
implemented it in Python.
https://pypi.python.org/pypi/bcrypt/2.0.0
https://pypi.python.org/pypi/scrypt/

I have no idea where Lasso is in that regard.

--steve


On 7/11/15 at 9:38 AM, b...@corry.biz (Bil Corry) pronounced:
------------------------
Steve Piercy, Soquel, CA

Reply all
Reply to author
Forward
0 new messages