Skip to content

Commit

Permalink
Use the built-in crypto:pbkdf2_hmac function
Browse files Browse the repository at this point in the history
The fix to make `crypto:pbkdf2_hmac/5` yield properly is now in all the supported
Erlang/OTP versions, so we can switch to use it [1].

This also removes the build dependency on OpenSSL dev package.

[1] erlang/otp#8174
  • Loading branch information
nickva committed May 13, 2024
1 parent 105cf01 commit ada5135
Show file tree
Hide file tree
Showing 17 changed files with 10 additions and 1,338 deletions.
7 changes: 6 additions & 1 deletion rebar.config.script
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,15 @@ BadErlang = fun(Ver) ->
end
end.

% crypto:pbkdf2_hmac/5 was blocking schedulers in
% versions < 24.3.4.17, < 25.3.2.10 and < 26.2.3
%
case VerList of
% Leave example around if we have to exlude specific versions
% [22, 0, N | _] when N < 5 -> BadErlang(VerString);
[24, 3, 4, N | _] when N < 17 -> BadErlang(VerString);
[25, 3, 2, N | _] when N < 10 -> BadErlang(VerString);
[26, 2, N | _] when N < 3 -> BadErlang(VerString);
_ -> ok
end.

Expand Down Expand Up @@ -116,7 +122,6 @@ SubDirs = [
"src/chttpd",
"src/couch",
"src/couch_event",
"src/fast_pbkdf2",
"src/mem3",
"src/couch_index",
"src/couch_mrview",
Expand Down
6 changes: 2 additions & 4 deletions rel/reltool.config
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@

%% extra
nouveau,
recon,
fast_pbkdf2
recon
]},
{rel, "start_clean", "", [kernel, stdlib]},
{boot_rel, "couchdb"},
Expand Down Expand Up @@ -130,8 +129,7 @@

%% extra
{app, nouveau, [{incl_cond, include}]},
{app, recon, [{incl_cond, include}]},
{app, fast_pbkdf2, [{incl_cond, include}]}
{app, recon, [{incl_cond, include}]}
]}.

{overlay_vars, "couchdb.config"}.
Expand Down
1 change: 0 additions & 1 deletion src/couch/src/couch.app.src
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
% Upstream deps
ibrowse,
mochiweb,
fast_pbkdf2,

% ASF deps
couch_epi,
Expand Down
2 changes: 1 addition & 1 deletion src/couch/src/couch_passwords.erl
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ pbkdf2(PRF, Password, Salt, Iterations, KeyLen) when
KeyLen > 0
->
couch_stats:increment_counter([couchdb, password_hashing_slow]),
DerivedKey = fast_pbkdf2:pbkdf2(PRF, Password, Salt, Iterations, KeyLen),
DerivedKey = crypto:pbkdf2_hmac(PRF, Password, Salt, Iterations, KeyLen),
couch_util:to_hex_bin(DerivedKey);
pbkdf2(PRF, Password, Salt, Iterations, KeyLen) when
is_atom(PRF),
Expand Down
2 changes: 1 addition & 1 deletion src/couch/src/couch_passwords_cache.erl
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@ insert(AuthModule, UserName, Password, Salt) when

hash(Password, Salt) ->
couch_stats:increment_counter([couchdb, password_hashing_fast]),
fast_pbkdf2:pbkdf2(sha256, Password, Salt, ?FAST_ITERATIONS, ?SHA256_OUTPUT_LEN).
crypto:pbkdf2_hmac(sha256, Password, Salt, ?FAST_ITERATIONS, ?SHA256_OUTPUT_LEN).
30 changes: 0 additions & 30 deletions src/fast_pbkdf2/.gitignore

This file was deleted.

191 changes: 0 additions & 191 deletions src/fast_pbkdf2/LICENSE

This file was deleted.

58 changes: 0 additions & 58 deletions src/fast_pbkdf2/README.md

This file was deleted.

36 changes: 0 additions & 36 deletions src/fast_pbkdf2/benchmarks/bench.ex

This file was deleted.

Loading

0 comments on commit ada5135

Please sign in to comment.