nickva commented on code in PR #4814:
URL: https://github.com/apache/couchdb/pull/4814#discussion_r1378380590


##########
src/couch/src/couch_passwords.erl:
##########
@@ -69,106 +68,74 @@ get_unhashed_admins() ->
             ({_User, "-pbkdf2-" ++ _}) ->
                 % already hashed
                 false;
+            ({_User, "-pbkdf2:sha-" ++ _}) ->
+                % already hashed
+                false;
+            ({_User, "-pbkdf2:sha224-" ++ _}) ->
+                % already hashed
+                false;
+            ({_User, "-pbkdf2:sha256-" ++ _}) ->
+                % already hashed
+                false;
+            ({_User, "-pbkdf2:sha384-" ++ _}) ->
+                % already hashed
+                false;
+            ({_User, "-pbkdf2:sha512-" ++ _}) ->
+                % already hashed
+                false;
             ({_User, _ClearPassword}) ->
                 true
         end,
         config:get("admins")
     ).
 
-%% Current scheme, much stronger.
--spec pbkdf2(binary(), binary(), integer()) -> binary().
-pbkdf2(Password, Salt, Iterations) when
+pbkdf2(Password, Salt, Iterations) ->
+    pbkdf2(sha, Password, Salt, Iterations).
+
+pbkdf2(PRF, Password, Salt, Iterations) when is_atom(PRF) ->
+    #{size := Size} = crypto:hash_info(PRF),
+    pbkdf2(PRF, Password, Salt, Iterations, Size);
+pbkdf2(Password, Salt, Iterations, KeyLen) ->
+    pbkdf2(sha, Password, Salt, Iterations, KeyLen).
+
+pbkdf2(PRF, Password, Salt, Iterations, KeyLen) when
+    is_atom(PRF),
     is_binary(Password),
     is_binary(Salt),
     is_integer(Iterations),
-    Iterations > 0
+    Iterations > 0,
+    KeyLen > 0
 ->
-    {ok, Result} = pbkdf2(Password, Salt, Iterations, ?SHA1_OUTPUT_LENGTH),
-    Result;
-pbkdf2(Password, Salt, Iterations) when
+    DerivedKey = fast_pbkdf2:pbkdf2(PRF, Password, Salt, Iterations, KeyLen),
+    couch_util:to_hex_bin(DerivedKey);
+pbkdf2(PRF, Password, Salt, Iterations, KeyLen) when
+    is_atom(PRF),
     is_binary(Salt),
     is_integer(Iterations),
-    Iterations > 0
+    Iterations > 0,
+    KeyLen > 0

Review Comment:
   Let's assert KeyLen is an integer.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@couchdb.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to