From 160cea3f655913b370650f93b0c8f6c1bd163e32 Mon Sep 17 00:00:00 2001 From: Hans Nilsson Date: Tue, 14 May 2019 17:01:17 +0200 Subject: crypto: MAC nif unifying HMAC, CMAC and POLY1305 into one nif using the EVP_DigestSign interface. This enables acceleration if available in lower layers, that is, in cryptolib and lower. However, for older cryptolibs the old HMAC and CMAC low-level interfaces are used, but moved from hmac.c and cmac.c into mac.c. --- lib/crypto/src/crypto.erl | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'lib/crypto/src') diff --git a/lib/crypto/src/crypto.erl b/lib/crypto/src/crypto.erl index 169c0f2e91..fd4b9df5e0 100644 --- a/lib/crypto/src/crypto.erl +++ b/lib/crypto/src/crypto.erl @@ -62,7 +62,8 @@ crypto_one_time_aead/6, crypto_one_time_aead/7, crypto_dyn_iv_init/3, crypto_dyn_iv_update/3, - supports/1 + supports/1, + mac/3, mac/4, mac/5 ]). @@ -602,6 +603,19 @@ hash_final(Context) -> %%% %%%================================================================ +mac(Type, SubType, Key, Data, MacLength) -> + erlang:binary_part(mac(Type, SubType, Key, Data), 0, MacLength). + +mac(poly1305, _, Key, Data) -> mac_nif(poly1305, undefined, Key, Data); +mac(Type, SubType, Key, Data) -> mac_nif(Type, SubType, Key, Data). + +mac(poly1305, Key, Data) -> mac(poly1305, undefined, Key, Data). + + + +mac_nif(_Type, _SubType, _Key, _Data) -> ?nif_stub. + + %%%---- HMAC -type hmac_hash_algorithm() :: sha1() | sha2() | sha3() | compatibility_only_hash(). -- cgit v1.2.3