Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Work at the byte level #15

Merged
merged 1 commit into from
Apr 20, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/comeonin/bcrypt.ex
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ defmodule Comeonin.Bcrypt do
"""
def hashpass(password, salt) when is_binary(salt) and is_binary(password) do
if byte_size(salt) == 29 do
hashpw(to_char_list(password), to_char_list(salt))
hashpw(:binary.bin_to_list(password), :binary.bin_to_list(salt))
else
raise ArgumentError, message: "The salt is the wrong length."
end
Expand Down Expand Up @@ -127,9 +127,9 @@ defmodule Comeonin.Bcrypt do
The check is performed in constant time to avoid timing attacks.
"""
def checkpw(password, hash) do
hashpw(to_char_list(password), to_char_list(hash))
|> to_char_list
|> Tools.secure_check(to_char_list(hash))
hashpw(:binary.bin_to_list(password), :binary.bin_to_list(hash))
|> :binary.bin_to_list
|> Tools.secure_check(:binary.bin_to_list(hash))
end

@doc """
Expand Down
6 changes: 3 additions & 3 deletions test/bcrypt_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ defmodule Comeonin.BcryptTest do
end

test "OpenBSD Bcrypt tests" do
[{"\xa3",
[{<<0xa3>>,
"$2b$05$/OK.fbVrR/bpIqNJ5ianF.",
"$2b$05$/OK.fbVrR/bpIqNJ5ianF.Sa7shbm4.OzKpvFnX1pQLmQW96oUlCq"},
{"\xa3",
{<<0xa3>>,
"$2a$05$/OK.fbVrR/bpIqNJ5ianF.",
"$2a$05$/OK.fbVrR/bpIqNJ5ianF.Sa7shbm4.OzKpvFnX1pQLmQW96oUlCq"},
{"\xff\xff\xa3",
{<<0xff, 0xff, 0xa3>>,
"$2b$05$/OK.fbVrR/bpIqNJ5ianF.",
"$2b$05$/OK.fbVrR/bpIqNJ5ianF.CE5elHaaO4EbggVDjb8P19RukzXSM3e"},
{"000000000000000000000000000000000000000000000000000000000000000000000000",
Expand Down