Skip to content

Commit 3d66ae4

Browse files
author
Torbjorn Tornkvist
committed
Improving the encryption of the shared key by adding a salt.
1 parent 45f446e commit 3d66ae4

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

ebin/ehotp.app

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
[{description, "Erlang Hash based One Time Password system."},
44
{vsn, "0.1.0"},
55
{mod, {ehotp_app, []}},
6-
{env, [{backend, ehotp_ets} % ehotp_(ets | mnesia | couchdb)
6+
{env, [{backend, ehotp_ets} % ehotp_(ets | mnesia | couchdb)
7+
,{salt, "guard this with your life"} % used to encrypt the shared keys
78
]},
89
{modules, [ehotp
910
,ehotp_app

src/ehotp.erl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,13 @@ generate_random_key() ->
100100
%%% @doc Encrypt (lock) the key using the Pin code.
101101
%%%
102102
lock_key(Pin, Key) when is_binary(Key) ->
103-
Pin2 = Pin*Pin*Pin,
104-
PinB = crypto:sha_mac(<<Pin:16>>, <<Pin2:32>>),
103+
Salt = integer_to_list(Pin*Pin) ++ ehotp_app:get_env(salt, ""),
104+
lock_key(Pin, Key, list_to_binary(Salt)).
105+
106+
lock_key(Pin, Key, Salt) when is_list(Salt) ->
107+
lock_key(Pin, Key, list_to_binary(Salt));
108+
lock_key(Pin, Key, Salt) when is_binary(Key), is_binary(Salt) ->
109+
PinB = crypto:sha_mac(<<Pin:16>>, <<Salt/binary>>),
105110
crypto:exor(PinB, Key).
106111

107112
%%% @doc Decrypt (unlock) the key using the Pin code.

0 commit comments

Comments
 (0)