Skip to content
This repository was archived by the owner on Nov 17, 2020. It is now read-only.

Commit a686a47

Browse files
committed
Fix rabbit_pbe for OTP-22
Some new ciphers have been added. Others will be added once crypto exposes an interface to get cipher information.
1 parent 35623e0 commit a686a47

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

src/rabbit_pbe.erl

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,15 @@
2323
%% Supported ciphers and hashes
2424

2525
supported_ciphers() ->
26-
NotSupportedByUs = [aes_ccm, aes_ctr, aes_ecb, aes_gcm,
26+
NotSupportedByUs = [%% These ciphers should be supported in a future version.
27+
aes_128_ccm, aes_192_ccm, aes_256_ccm,
28+
aes_128_ctr, aes_192_ctr, aes_256_ctr,
29+
aes_128_gcm, aes_192_gcm, aes_256_gcm,
2730
chacha20, chacha20_poly1305,
28-
blowfish_ecb, des_ecb, rc4],
31+
%% These are aliases that correspond to multiple ciphers.
32+
aes_ccm, aes_ctr, aes_gcm,
33+
%% These ciphers will never be supported.
34+
aes_ecb, blowfish_ecb, des_ecb, rc4],
2935
SupportedByCrypto = proplists:get_value(ciphers, crypto:supports()),
3036
lists:filter(fun(Cipher) ->
3137
not lists:member(Cipher, NotSupportedByUs)
@@ -89,7 +95,9 @@ make_key(Cipher, Hash, Iterations, PassPhrase, Salt) ->
8995
Key = pbdkdf2(PassPhrase, Salt, Iterations, key_length(Cipher),
9096
fun crypto:hmac/4, Hash, hash_length(Hash)),
9197
if
92-
Cipher =:= des3_cbc; Cipher =:= des3_cbf; Cipher =:= des3_cfb; Cipher =:= des_ede3 ->
98+
Cipher =:= des3_cbc; Cipher =:= des3_cbf; Cipher =:= des3_cfb;
99+
Cipher =:= des_ede3; Cipher =:= des_ede3_cbc;
100+
Cipher =:= des_ede3_cbf; Cipher =:= des_ede3_cfb ->
93101
<< A:8/binary, B:8/binary, C:8/binary >> = Key,
94102
[A, B, C];
95103
true ->
@@ -126,14 +134,19 @@ hash_length(sha3_256) -> 32;
126134
hash_length(sha384) -> 48;
127135
hash_length(sha3_384) -> 48;
128136
hash_length(sha512) -> 64;
129-
hash_length(sha3_512) -> 64.
137+
hash_length(sha3_512) -> 64;
138+
hash_length(blake2b) -> 64;
139+
hash_length(blake2s) -> 32.
130140

131141
iv_length(des_cbc) -> 8;
132142
iv_length(des_cfb) -> 8;
133143
iv_length(des3_cbc) -> 8;
134144
iv_length(des3_cbf) -> 8;
135145
iv_length(des3_cfb) -> 8;
136146
iv_length(des_ede3) -> 8;
147+
iv_length(des_ede3_cbf) -> 8;
148+
iv_length(des_ede3_cfb) -> 8;
149+
iv_length(des_ede3_cbc) -> 8;
137150
iv_length(blowfish_cbc) -> 8;
138151
iv_length(blowfish_cfb64) -> 8;
139152
iv_length(blowfish_ofb64) -> 8;
@@ -143,6 +156,9 @@ iv_length(aes_cbc128) -> 16;
143156
iv_length(aes_cfb8) -> 16;
144157
iv_length(aes_cfb128) -> 16;
145158
iv_length(aes_cbc256) -> 16;
159+
iv_length(aes_128_cbc) -> 16;
160+
iv_length(aes_192_cbc) -> 16;
161+
iv_length(aes_256_cbc) -> 16;
146162
iv_length(aes_ige256) -> 32.
147163

148164
key_length(des_cbc) -> 8;
@@ -151,6 +167,9 @@ key_length(des3_cbc) -> 24;
151167
key_length(des3_cbf) -> 24;
152168
key_length(des3_cfb) -> 24;
153169
key_length(des_ede3) -> 24;
170+
key_length(des_ede3_cbf) -> 24;
171+
key_length(des_ede3_cfb) -> 24;
172+
key_length(des_ede3_cbc) -> 24;
154173
key_length(blowfish_cbc) -> 16;
155174
key_length(blowfish_cfb64) -> 16;
156175
key_length(blowfish_ofb64) -> 16;
@@ -160,12 +179,18 @@ key_length(aes_cbc128) -> 16;
160179
key_length(aes_cfb8) -> 16;
161180
key_length(aes_cfb128) -> 16;
162181
key_length(aes_cbc256) -> 32;
182+
key_length(aes_128_cbc) -> 16;
183+
key_length(aes_192_cbc) -> 24;
184+
key_length(aes_256_cbc) -> 32;
163185
key_length(aes_ige256) -> 16.
164186

187+
block_size(aes_cbc) -> 32;
165188
block_size(aes_cbc256) -> 32;
166189
block_size(aes_cbc128) -> 32;
190+
block_size(aes_128_cbc) -> 32;
191+
block_size(aes_192_cbc) -> 32;
192+
block_size(aes_256_cbc) -> 32;
167193
block_size(aes_ige256) -> 32;
168-
block_size(aes_cbc) -> 32;
169194
block_size(_) -> 8.
170195

171196
%% The following was taken from OTP's lib/public_key/src/pubkey_pbe.erl

0 commit comments

Comments
 (0)