aboutsummaryrefslogtreecommitdiffstats
path: root/lib/crypto/src
diff options
context:
space:
mode:
authorHans Nilsson <[email protected]>2018-09-10 14:37:15 +0200
committerHans Nilsson <[email protected]>2018-09-14 12:18:22 +0200
commitf11391139c4165e8541a52d45cd1525343a83927 (patch)
tree125f19f0753ac75b674af6bb173baca2b7fc7ad8 /lib/crypto/src
parent51dcd166c58bf371da4c85250c8d76c27b4148da (diff)
downloadotp-f11391139c4165e8541a52d45cd1525343a83927.tar.gz
otp-f11391139c4165e8541a52d45cd1525343a83927.tar.bz2
otp-f11391139c4165e8541a52d45cd1525343a83927.zip
crypto: Generalize aes_gcm_(de|en)crypt nifs
The EVP_CIPHER_CTX interface aims at enabling using the same code for many ciphers. Since we are going to add aes_ccm which is similar to aes_gcm, this commit is a preparation. It creates the aead_(de|en)crypt nifs and removes the old ones.
Diffstat (limited to 'lib/crypto/src')
-rw-r--r--lib/crypto/src/crypto.erl20
1 files changed, 9 insertions, 11 deletions
diff --git a/lib/crypto/src/crypto.erl b/lib/crypto/src/crypto.erl
index c64586897e..cb281aac42 100644
--- a/lib/crypto/src/crypto.erl
+++ b/lib/crypto/src/crypto.erl
@@ -518,9 +518,9 @@ block_encrypt(des3_cfb, Key0, Ivec, PlainText) ->
block_encrypt(aes_ige256, Key, Ivec, PlainText) ->
notsup_to_error(aes_ige_crypt_nif(Key, Ivec, PlainText, true));
block_encrypt(aes_gcm, Key, Ivec, {AAD, PlainText}) ->
- aes_gcm_encrypt(Key, Ivec, AAD, PlainText);
+ aead_encrypt(Key, Ivec, AAD, PlainText);
block_encrypt(aes_gcm, Key, Ivec, {AAD, PlainText, TagLength}) ->
- aes_gcm_encrypt(Key, Ivec, AAD, PlainText, TagLength);
+ aead_encrypt(Key, Ivec, AAD, PlainText, TagLength);
block_encrypt(chacha20_poly1305, Key, Ivec, {AAD, PlainText}) ->
chacha20_poly1305_encrypt(Key, Ivec, AAD, PlainText).
@@ -551,8 +551,8 @@ block_decrypt(des3_cfb, Key0, Ivec, Data) ->
block_crypt_nif(des_ede3_cfb, Key, Ivec, Data, false);
block_decrypt(aes_ige256, Key, Ivec, Data) ->
notsup_to_error(aes_ige_crypt_nif(Key, Ivec, Data, false));
-block_decrypt(aes_gcm, Key, Ivec, {AAD, Data, Tag}) ->
- aes_gcm_decrypt(Key, Ivec, AAD, Data, Tag);
+block_decrypt(Type, Key, Ivec, {AAD, Data, Tag}) when Type =:= aes_gcm ->
+ aead_decrypt(Type, Key, Ivec, AAD, Data, Tag);
block_decrypt(chacha20_poly1305, Key, Ivec, {AAD, Data, Tag}) ->
chacha20_poly1305_decrypt(Key, Ivec, AAD, Data, Tag).
@@ -577,10 +577,8 @@ next_iv(Type, Data) when is_binary(Data) ->
IVecSize = case Type of
des_cbc -> 8;
des3_cbc -> 8;
- blowfish_cbc -> 8;
aes_cbc -> 16;
- aes_ige -> 32; % For compatibility if someone has bug-adapted code
- aes_ige256 -> 32 % The name used in block_encrypt et al
+ aes_ige -> 32
end,
{_, IVec} = split_binary(Data, size(Data) - IVecSize),
IVec;
@@ -1606,10 +1604,10 @@ check_des3_key(Key) ->
%% AES - in Galois/Counter Mode (GCM)
%%
%% The default tag length is EVP_GCM_TLS_TAG_LEN(16),
-aes_gcm_encrypt(Key, Ivec, AAD, In) ->
- aes_gcm_encrypt(Key, Ivec, AAD, In, 16).
-aes_gcm_encrypt(_Key, _Ivec, _AAD, _In, _TagLength) -> ?nif_stub.
-aes_gcm_decrypt(_Key, _Ivec, _AAD, _In, _Tag) -> ?nif_stub.
+aead_encrypt(Type=aes_gcm, Key, Ivec, AAD, In) -> aead_encrypt(Type, Key, Ivec, AAD, In, 16).
+
+aead_encrypt(_Type, _Key, _Ivec, _AAD, _In, _TagLength) -> ?nif_stub.
+aead_decrypt(_Type, _Key, _Ivec, _AAD, _In, _Tag) -> ?nif_stub.
%%
%% Chacha20/Ppoly1305