summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorHans Nilsson <hans@erlang.org>2021-11-10 11:51:37 +0100
committerHans Nilsson <hans@erlang.org>2021-11-11 12:02:00 +0100
commit542d01c7b55223a3b204e3296ab790a5efbef682 (patch)
tree301e9e67fab60677656986a9a64c5cc80ba9b681 /lib
parentdbabb65d843184e3dec353e452135b5c734c043d (diff)
downloaderlang-542d01c7b55223a3b204e3296ab790a5efbef682.tar.gz
crypto: Cipher aliases could be present even if the aliased cipher was missing
Diffstat (limited to 'lib')
-rw-r--r--lib/crypto/c_src/cipher.c13
-rw-r--r--lib/crypto/src/crypto.erl43
2 files changed, 42 insertions, 14 deletions
diff --git a/lib/crypto/c_src/cipher.c b/lib/crypto/c_src/cipher.c
index d2942ef8f5..fbda4a688d 100644
--- a/lib/crypto/c_src/cipher.c
+++ b/lib/crypto/c_src/cipher.c
@@ -361,18 +361,5 @@ ERL_NIF_TERM cipher_types_as_list(ErlNifEnv* env)
}
}
- /* Add aliases: */
-#ifdef HAVE_GCM
- hd = enif_make_list_cell(env, atom_aes_gcm, hd);
-#endif
- hd = enif_make_list_cell(env, atom_aes_ecb, hd);
- hd = enif_make_list_cell(env, atom_aes_ctr, hd);
- hd = enif_make_list_cell(env, atom_aes_cfb8, hd);
- hd = enif_make_list_cell(env, atom_aes_cfb128, hd);
-#ifdef HAVE_CCM
- hd = enif_make_list_cell(env, atom_aes_ccm, hd);
-#endif
- hd = enif_make_list_cell(env, atom_aes_cbc, hd);
-
return hd;
}
diff --git a/lib/crypto/src/crypto.erl b/lib/crypto/src/crypto.erl
index 2646abbf86..0233c73f48 100644
--- a/lib/crypto/src/crypto.erl
+++ b/lib/crypto/src/crypto.erl
@@ -526,7 +526,7 @@ supports() ->
supports(hashs) -> hash_algorithms();
supports(public_keys) -> pubkey_algorithms();
-supports(ciphers) -> cipher_algorithms();
+supports(ciphers) -> add_cipher_aliases(cipher_algorithms());
supports(macs) -> mac_algorithms();
supports(curves) -> curve_algorithms();
supports(rsa_opts) -> rsa_opts_algorithms().
@@ -985,6 +985,16 @@ cipher_info_nif(_Type) -> ?nif_stub.
%%% Cipher aliases
%%%
+add_cipher_aliases(Ciphers) ->
+ Ciphers ++
+ lists:usort(
+ lists:foldl(fun(C, Acc) ->
+ case alias1_rev(C) of
+ C -> Acc;
+ A -> [A|Acc]
+ end
+ end, [], Ciphers)).
+
alias(aes_cbc, Key) -> alias1(aes_cbc, iolist_size(Key));
alias(aes_cfb8, Key) -> alias1(aes_cfb8, iolist_size(Key));
alias(aes_cfb128, Key) -> alias1(aes_cfb128, iolist_size(Key));
@@ -1025,6 +1035,37 @@ alias1(aes_ccm, 32) -> aes_256_ccm;
alias1(Alg, _) -> Alg.
+
+alias1_rev(aes_128_cbc) -> aes_cbc;
+alias1_rev(aes_192_cbc) -> aes_cbc;
+alias1_rev(aes_256_cbc) -> aes_cbc;
+
+alias1_rev(aes_128_cfb8) -> aes_cfb8;
+alias1_rev(aes_192_cfb8) -> aes_cfb8;
+alias1_rev(aes_256_cfb8) -> aes_cfb8;
+
+alias1_rev(aes_128_cfb128) -> aes_cfb128;
+alias1_rev(aes_192_cfb128) -> aes_cfb128;
+alias1_rev(aes_256_cfb128) -> aes_cfb128;
+
+alias1_rev(aes_128_ctr) -> aes_ctr;
+alias1_rev(aes_192_ctr) -> aes_ctr;
+alias1_rev(aes_256_ctr) -> aes_ctr;
+
+alias1_rev(aes_128_ecb) -> aes_ecb;
+alias1_rev(aes_192_ecb) -> aes_ecb;
+alias1_rev(aes_256_ecb) -> aes_ecb;
+
+alias1_rev(aes_128_gcm) -> aes_gcm;
+alias1_rev(aes_192_gcm) -> aes_gcm;
+alias1_rev(aes_256_gcm) -> aes_gcm;
+
+alias1_rev(aes_128_ccm) -> aes_ccm;
+alias1_rev(aes_192_ccm) -> aes_ccm;
+alias1_rev(aes_256_ccm) -> aes_ccm;
+
+alias1_rev(C) -> C.
+
%%%================================================================
%%%
%%% RAND - pseudo random numbers using RN_ and BN_ functions in crypto lib