@@ -55,7 +55,7 @@ client_step(State, ServerResponse) ->
5555 R = proplists :get_value (<<" r" >>, SResp ),
5656 S = base64 :decode (proplists :get_value (<<" s" >>, SResp )),
5757 Nonce = State # sasl_state .nonce ,
58- NonceSize = size (Nonce ),
58+ NonceSize = byte_size (Nonce ),
5959 case R of
6060 <<Nonce :NonceSize /binary , _ /binary >> ->
6161 ClientMsg1 = client_first_message_bare (
@@ -67,20 +67,20 @@ client_step(State, ServerResponse) ->
6767 ServerResponse /binary , " ," ,
6868 ClientMsg2 /binary >>,
6969 Password = State # sasl_state .password ,
70- SaltedPassword = scram : salted_password (
70+ SaltedPassword = salted_password (
7171 sha256 , Password , S , I ),
7272 ClientKey =
73- scram : client_key (sha256 , SaltedPassword ),
74- StoredKey = scram : stored_key (sha256 , ClientKey ),
73+ client_key (sha256 , SaltedPassword ),
74+ StoredKey = stored_key (sha256 , ClientKey ),
7575 ClientSignature =
76- scram : client_signature (sha256 , StoredKey , AuthMessage ),
76+ client_signature (sha256 , StoredKey , AuthMessage ),
7777 ClientProof =
7878 crypto :exor (ClientKey , ClientSignature ),
7979 P = base64 :encode (ClientProof ),
8080 Msg = <<ClientMsg2 /binary , " ,p=" , P /binary >>,
8181 ServerKey =
82- scram : server_key (sha256 , SaltedPassword ),
83- V = scram : server_signature (sha256 , ServerKey , AuthMessage ),
82+ server_key (sha256 , SaltedPassword ),
83+ V = server_signature (sha256 , ServerKey , AuthMessage ),
8484 {ok , Msg , State # sasl_state {nonce = R , verify = V }};
8585 _ ->
8686 {error , " Bad SASL server nonce" }
@@ -140,3 +140,30 @@ parse4(<<C, Cs/binary>>, Key, Val, Ts) ->
140140parse4 (<<>>, Key , Val , Ts ) ->
141141 parse1 (<<>>, <<>>, [{Key , Val } | Ts ]).
142142
143+ salted_password (Algo , Password , Salt , IterationCount ) ->
144+ hi (Algo , stringprep :resourceprep (Password ), Salt , IterationCount ).
145+
146+ client_key (Algo , SaltedPassword ) ->
147+ crypto :mac (hmac , Algo , SaltedPassword , <<" Client Key" >>).
148+
149+ stored_key (Algo , ClientKey ) -> crypto :hash (Algo , ClientKey ).
150+
151+ server_key (Algo , SaltedPassword ) ->
152+ crypto :mac (hmac , Algo , SaltedPassword , <<" Server Key" >>).
153+
154+ client_signature (Algo , StoredKey , AuthMessage ) ->
155+ crypto :mac (hmac , Algo , StoredKey , AuthMessage ).
156+
157+ server_signature (Algo , ServerKey , AuthMessage ) ->
158+ crypto :mac (hmac , Algo , ServerKey , AuthMessage ).
159+
160+ hi (Algo , Password , Salt , IterationCount ) ->
161+ U1 = crypto :mac (hmac , Algo , Password , <<Salt /binary , 0 , 0 , 0 , 1 >>),
162+ crypto :exor (U1 , hi_round (Algo , Password , U1 , IterationCount - 1 )).
163+
164+ hi_round (Algo , Password , UPrev , 1 ) ->
165+ crypto :mac (hmac , Algo , Password , UPrev );
166+ hi_round (Algo , Password , UPrev , IterationCount ) ->
167+ U = crypto :mac (hmac , Algo , Password , UPrev ),
168+ crypto :exor (U , hi_round (Algo , Password , U , IterationCount - 1 )).
169+
0 commit comments