@@ -91,7 +91,7 @@ decrypt(Cipher, Hash, Iterations, Secret, {encrypted, Base64Binary}) ->
91
91
% % Generate a key from a secret.
92
92
93
93
make_key (Cipher , Hash , Iterations , Secret , Salt ) ->
94
- Key = pbdkdf2 (Secret , Salt , Iterations , key_length (Cipher ),
94
+ Key = pubkey_pbe : pbdkdf2 (Secret , Salt , Iterations , key_length (Cipher ),
95
95
fun hmac /4 , Hash , hash_length (Hash )),
96
96
if
97
97
Cipher =:= des3_cbc ; Cipher =:= des3_cbf ; Cipher =:= des3_cfb ;
@@ -129,42 +129,3 @@ key_length(Type) ->
129
129
130
130
block_size (Type ) ->
131
131
maps :get (block_size , crypto :cipher_info (Type )).
132
-
133
- % % The following was taken from OTP's lib/public_key/src/pubkey_pbe.erl
134
- % %
135
- % % This is an undocumented interface to password-based encryption algorithms.
136
- % % These functions have been copied here to stay compatible with R16B03.
137
-
138
- % %--------------------------------------------------------------------
139
- -spec pbdkdf2 (iodata (), iodata (), integer (), integer (), fun (), atom (), integer ())
140
- -> binary ().
141
- % %
142
- % % Description: Implements password based decryption key derive function 2.
143
- % % Exported mainly for testing purposes.
144
- % %--------------------------------------------------------------------
145
- pbdkdf2 (Password , Salt , Count , DerivedKeyLen , Prf , PrfHash , PrfOutputLen )->
146
- NumBlocks = ceiling (DerivedKeyLen / PrfOutputLen ),
147
- NumLastBlockOctets = DerivedKeyLen - (NumBlocks - 1 ) * PrfOutputLen ,
148
- blocks (NumBlocks , NumLastBlockOctets , 1 , Password , Salt ,
149
- Count , Prf , PrfHash , PrfOutputLen , <<>>).
150
-
151
- blocks (1 , N , Index , Password , Salt , Count , Prf , PrfHash , PrfLen , Acc ) ->
152
- <<XorSum :N /binary , _ /binary >> = xor_sum (Password , Salt , Count , Index , Prf , PrfHash , PrfLen ),
153
- <<Acc /binary , XorSum /binary >>;
154
- blocks (NumBlocks , N , Index , Password , Salt , Count , Prf , PrfHash , PrfLen , Acc ) ->
155
- XorSum = xor_sum (Password , Salt , Count , Index , Prf , PrfHash , PrfLen ),
156
- blocks (NumBlocks - 1 , N , Index + 1 , Password , Salt , Count , Prf , PrfHash ,
157
- PrfLen , <<Acc /binary , XorSum /binary >>).
158
-
159
- xor_sum (Password , Salt , Count , Index , Prf , PrfHash , PrfLen ) ->
160
- Result = Prf (PrfHash , Password , [Salt ,<<Index :32 /unsigned -big -integer >>], PrfLen ),
161
- do_xor_sum (Prf , PrfHash , PrfLen , Result , Password , Count - 1 , Result ).
162
-
163
- do_xor_sum (_ , _ , _ , _ , _ , 0 , Acc ) ->
164
- Acc ;
165
- do_xor_sum (Prf , PrfHash , PrfLen , Prev , Password , Count , Acc ) ->
166
- Result = Prf (PrfHash , Password , Prev , PrfLen ),
167
- do_xor_sum (Prf , PrfHash , PrfLen , Result , Password , Count - 1 , crypto :exor (Acc , Result )).
168
-
169
- ceiling (Float ) ->
170
- erlang :round (Float + 0.5 ).
0 commit comments