Skip to content

drop pbkdf2 dependency - #61

Open
hmmr wants to merge 2 commits into
OpenRiak:openriak-3.4from
TI-Tokyo:tiot/openriak-3.4/get-rid-of-pbkdf2
Open

drop pbkdf2 dependency#61
hmmr wants to merge 2 commits into
OpenRiak:openriak-3.4from
TI-Tokyo:tiot/openriak-3.4/get-rid-of-pbkdf2

Conversation

@hmmr

@hmmr hmmr commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Since OTP-24.2, crypto app has pbkdf2_hmac/5, thus allowing us to drop an external dependency on pbkdf2. See OpenRiak/erlang-pbkdf2#1 for more context.

Comment thread src/riak_core_pw_auth.erl Outdated
HashedPass = crypto:pbkdf2_hmac(
HashFunction, BinaryPass, Salt, HashIterations, ?KEY_LENGTH),
HexPass = to_hex(HashedPass),
HexPass == HashedPassword.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine, but I'm wondering if we should do something closer to compare_secure to avoid shortcut logic for timing attacks.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compare_secure/2 is back.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice.

Comment thread src/riak_core_pw_auth.erl Outdated
HexPass = to_hex(HashedPass),
HexPass == HashedPassword.

to_hex(Data) when is_binary(Data) ->

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing this hex representation is equivalent to pbkdf2:to_hex so passwords from previous versions will also match.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this to_hex/1 was copied from pbkdf2.erl verbatim.

To verify, I built riak with erlang-pbkdf2 temporarily re-enabled, and ran:

(dev1@127.0.0.1)10> {ok, Hash, pbkdf2, sha, Salt, Iters} = riak_core_pw_auth:hash_password(<<"fafa">>).  %% uses native OTP crypto:pbkdf2_hmac/5
{ok,<<"3a05b03656286ed258fd0df5fd0ddad63e5e20ed">>,pbkdf2,
    sha,
    <<131,5,17,87,63,138,121,45,48,19,72,134,171,100,202,11>>,
    65536}
(dev1@127.0.0.1)11> {ok, Hash2} = pbkdf2:pbkdf2(sha, <<"fafa">>, Salt, Iters).
{ok,<<58,5,176,54,86,40,110,210,88,253,13,245,253,13,218,
      214,62,94,32,237>>}
(dev1@127.0.0.1)12> pbkdf2:to_hex(Hash2) == Hash.
true

@hmmr

hmmr commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

More generally, while we are at it, do we want to expose salt length, digest and other items in riak.conf, to honor Jared Morrow's TODO remarks from 2013?

@WarpEngineer

Copy link
Copy Markdown
Member

No, I would say if we do that, it should be in advanced.config and should be a separate ticket from this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants