diff --git a/src/rncryptor.erl b/src/rncryptor.erl index bedf058..aca866f 100644 --- a/src/rncryptor.erl +++ b/src/rncryptor.erl @@ -58,8 +58,8 @@ -type rn_pw_cryptor() :: [rnheader() | salt64() | salt64() | aes_block() | binary() | hmac_sig()]. -type rn_key_cryptor() :: [rnheader() | aes_block() | binary() | hmac_sig()]. --type rncryptor() :: rn_pw_cryptor() | rn_key_cryptor(). --type rnpacket() :: [hmac_key() | rncryptor()]. +-type rncryptor() :: rn_pw_cryptor() | rn_key_cryptor() | binary(). +-type rnpacket() :: [hmac_key() | rncryptor()] | binary(). %%====================================================================================== %% @@ -138,7 +138,7 @@ encrypt_key(<>, <>, PaddedText = rncryptor_util:enpad(PlainText), CipherText = crypto:crypto_one_time(CipherIV, Key, IVec, PaddedText, true), Message = <>, - RNHmac = crypto:hmac(sha256, HmacKey, Message, ?HMAC_SHA256_SIZE), + RNHmac = crypto:macN(hmac, sha256, HmacKey, Message, ?HMAC_SHA256_SIZE), <>; encrypt_key(_Key, _IVec, _HmacKey, _PlainText) -> {error, "Invalid arguments"}. @@ -270,7 +270,7 @@ encrypt_pw(KdfSalt, KdfKey, IVec, HmacSalt, HmacKey, PlainText) -> PaddedText = rncryptor_util:enpad(PlainText), CipherText = crypto:crypto_one_time(CipherIV, KdfKey, IVec, PaddedText, true), RNData = <>, - RNHmac = crypto:hmac(sha256, HmacKey, RNData, ?HMAC_SHA256_SIZE), + RNHmac = crypto:macN(hmac, sha256, HmacKey, RNData, ?HMAC_SHA256_SIZE), <>. %%====================================================================================== @@ -346,7 +346,7 @@ hmac_challenge(HmacKey, RNCryptor) -> RNSize = erlang:byte_size(RNCryptor), RNData = erlang:binary_part(RNCryptor, {0, RNSize-?HMAC_SHA256_SIZE}), RNHmac = erlang:binary_part(RNCryptor, {RNSize, -?HMAC_SHA256_SIZE}), - Challenge = crypto:hmac(sha256, HmacKey, RNData, ?HMAC_SHA256_SIZE), + Challenge = crypto:macN(hmac, sha256, HmacKey, RNData, ?HMAC_SHA256_SIZE), case rncryptor_util:const_compare(RNHmac, Challenge) of true -> {ok, RNData}; diff --git a/src/rncryptor_kdf.erl b/src/rncryptor_kdf.erl index 415fd60..c60e731 100644 --- a/src/rncryptor_kdf.erl +++ b/src/rncryptor_kdf.erl @@ -82,7 +82,7 @@ pbkdf2(Password, Salt, Rounds, KeySize) -> %%====================================================================================== %% @private pbkdf2_key(Password, Salt, Rounds, KeySize, BlockNum, PassKey) -> - InitBlock = crypto:hmac(sha, Password, <>, ?PBKDF2_SHA1_SIZE), + InitBlock = crypto:macN(hmac, sha, Password, <>, ?PBKDF2_SHA1_SIZE), BlockKey = pbkdf2_block_key(Password, Rounds, 2, InitBlock, InitBlock), NumBlocks = rncryptor_util:ceil(KeySize / ?PBKDF2_SHA1_SIZE), case BlockNum =:= NumBlocks of @@ -97,7 +97,7 @@ pbkdf2_key(Password, Salt, Rounds, KeySize, BlockNum, PassKey) -> pbkdf2_block_key(_Password, Rounds, Round, _PrevBlock, Block) when Round > Rounds -> Block; pbkdf2_block_key(Password, Rounds, Round, PrevBlock, Block) -> - NextBlock = crypto:hmac(sha, Password, PrevBlock, ?PBKDF2_SHA1_SIZE), + NextBlock = crypto:macN(hmac, sha, Password, PrevBlock, ?PBKDF2_SHA1_SIZE), Block2 = crypto:exor(NextBlock, Block), pbkdf2_block_key(Password, Rounds, Round + 1, NextBlock, Block2).