diff options
author | Robert Newson <rnewson@apache.org> | 2017-07-16 15:36:11 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-16 15:36:11 +0100 |
commit | d3a5a71752f87e1f07f316c433e0cdb7fa78b804 (patch) | |
tree | b8f130d547d13196c935020aa1fa05ac57bc488e | |
parent | de0634f7abc06b59deea9e1fe3495de2b3c8d2af (diff) | |
parent | 9e56cf334c33d4cdb96acbfca9cc9461e2b658aa (diff) | |
download | couchdb-d3a5a71752f87e1f07f316c433e0cdb7fa78b804.tar.gz |
Merge pull request #681 from apache/remove-couch-crypto
Remove couch_crypto
25 files changed, 59 insertions, 146 deletions
diff --git a/src/chttpd/src/chttpd.erl b/src/chttpd/src/chttpd.erl index ea92e0397..b9ac59b5d 100644 --- a/src/chttpd/src/chttpd.erl +++ b/src/chttpd/src/chttpd.erl @@ -665,7 +665,7 @@ doc_etag(#doc{id=Id, body=Body, revs={Start, [DiskRev|_]}}) -> couch_httpd:doc_etag(Id, Body, {Start, DiskRev}). make_etag(Term) -> - <<SigInt:128/integer>> = couch_crypto:hash(md5, term_to_binary(Term)), + <<SigInt:128/integer>> = crypto:hash(md5, term_to_binary(Term)), list_to_binary(io_lib:format("\"~.36B\"",[SigInt])). etag_match(Req, CurrentEtag) when is_binary(CurrentEtag) -> diff --git a/src/couch/src/couch_crypto.erl b/src/couch/src/couch_crypto.erl deleted file mode 100644 index ccf98774a..000000000 --- a/src/couch/src/couch_crypto.erl +++ /dev/null @@ -1,79 +0,0 @@ -% Licensed under the Apache License, Version 2.0 (the "License"); you may not -% use this file except in compliance with the License. You may obtain a copy of -% the License at -% -% http://www.apache.org/licenses/LICENSE-2.0 -% -% Unless required by applicable law or agreed to in writing, software -% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -% License for the specific language governing permissions and limitations under -% the License. - --module(couch_crypto). - --export([hash/2, hash_init/1, hash_update/3, hash_final/2]). --export([hmac/3]). - --compile([nowarn_deprecated_function]). - -hash(Alg, Data) -> - case {Alg, erlang:function_exported(crypto, hash, 2)} of - {_, true} -> - crypto:hash(Alg, Data); - {sha, false} -> - crypto:sha(Data); - {md5, false} -> - crypto:md5(Data); - {Alg, false} -> - throw({unsupported, Alg}) - end. - -hash_init(Alg) -> - case {Alg, erlang:function_exported(crypto, hash_init, 1)} of - {_, true} -> - crypto:hash_init(Alg); - {sha, false} -> - crypto:sha_init(); - {md5, false} -> - crypto:md5_init(); - {Alg, false} -> - throw({unsupported, Alg}) - end. - - -hash_update(Alg, Context, Data) -> - case {Alg, erlang:function_exported(crypto, hash_update, 2)} of - {_, true} -> - crypto:hash_update(Context, Data); - {sha, false} -> - crypto:sha_update(Context, Data); - {md5, false} -> - crypto:md5_update(Context, Data); - {Alg, false} -> - throw({unsupported, Alg}) - end. - - -hash_final(Alg, Context) -> - case {Alg, erlang:function_exported(crypto, hash_final, 1)} of - {_, true} -> - crypto:hash_final(Context); - {sha, false} -> - crypto:sha_final(Context); - {md5, false} -> - crypto:md5_final(Context); - {Alg, false} -> - throw({unsupported, Alg}) - end. - - -hmac(Alg, Key, Data) -> - case {Alg, erlang:function_exported(crypto, hmac, 3)} of - {_, true} -> - crypto:hmac(Alg, Key, Data); - {sha, false} -> - crypto:sha_mac(Key, Data); - {Alg, false} -> - throw({unsupported, Alg}) - end. diff --git a/src/couch/src/couch_db.erl b/src/couch/src/couch_db.erl index e4e3a8b34..51c81724d 100644 --- a/src/couch/src/couch_db.erl +++ b/src/couch/src/couch_db.erl @@ -884,7 +884,7 @@ new_revid(#doc{body=Body0, revs={OldStart,OldRevs}, atts=Atts, deleted=Deleted}) ?l2b(integer_to_list(couch_util:rand32())); Atts2 -> OldRev = case OldRevs of [] -> 0; [OldRev0|_] -> OldRev0 end, - couch_crypto:hash(md5, term_to_binary([Deleted, OldStart, OldRev, Body, Atts2], [{minor_version, 1}])) + crypto:hash(md5, term_to_binary([Deleted, OldStart, OldRev, Body, Atts2], [{minor_version, 1}])) end. new_revs([], OutBuckets, IdRevsAcc) -> diff --git a/src/couch/src/couch_db_updater.erl b/src/couch/src/couch_db_updater.erl index 277f2b535..8a0fb8cfd 100644 --- a/src/couch/src/couch_db_updater.erl +++ b/src/couch/src/couch_db_updater.erl @@ -1473,7 +1473,7 @@ make_doc_summary(#db{compression = Comp}, {Body0, Atts0}) -> couch_compress:compress(Atts0, Comp) end, SummaryBin = ?term_to_bin({Body, Atts}), - couch_file:assemble_file_chunk(SummaryBin, couch_crypto:hash(md5, SummaryBin)). + couch_file:assemble_file_chunk(SummaryBin, crypto:hash(md5, SummaryBin)). get_meta_body_size(Meta, Summary) -> diff --git a/src/couch/src/couch_file.erl b/src/couch/src/couch_file.erl index 8df462b05..acd4fda78 100644 --- a/src/couch/src/couch_file.erl +++ b/src/couch/src/couch_file.erl @@ -132,7 +132,7 @@ append_binary(Fd, Bin) -> append_binary_md5(Fd, Bin) -> ioq:call(Fd, - {append_bin, assemble_file_chunk(Bin, couch_crypto:hash(md5, Bin))}, + {append_bin, assemble_file_chunk(Bin, crypto:hash(md5, Bin))}, erlang:get(io_priority)). append_raw_chunk(Fd, Chunk) -> @@ -175,7 +175,7 @@ pread_iolist(Fd, Pos) -> {ok, IoList, <<>>} -> {ok, IoList}; {ok, IoList, Md5} -> - case couch_crypto:hash(md5, IoList) of + case crypto:hash(md5, IoList) of Md5 -> {ok, IoList}; _ -> @@ -329,7 +329,7 @@ read_header(Fd) -> write_header(Fd, Data) -> Bin = term_to_binary(Data), - Md5 = couch_crypto:hash(md5, Bin), + Md5 = crypto:hash(md5, Bin), % now we assemble the final header binary and write to disk FinalBin = <<Md5/binary, Bin/binary>>, ioq:call(Fd, {write_header, FinalBin}, erlang:get(io_priority)). @@ -557,7 +557,7 @@ load_header(Fd, Pos, HeaderLen, RestBlock) -> end, <<Md5Sig:16/binary, HeaderBin/binary>> = iolist_to_binary(remove_block_prefixes(?PREFIX_SIZE, RawBin)), - Md5Sig = couch_crypto:hash(md5, HeaderBin), + Md5Sig = crypto:hash(md5, HeaderBin), {ok, HeaderBin}. diff --git a/src/couch/src/couch_hotp.erl b/src/couch/src/couch_hotp.erl index 9d965be02..9a620fa87 100644 --- a/src/couch/src/couch_hotp.erl +++ b/src/couch/src/couch_hotp.erl @@ -16,7 +16,7 @@ generate(Alg, Key, Counter, OutputLen) when is_atom(Alg), is_binary(Key), is_integer(Counter), is_integer(OutputLen) -> - Hmac = couch_crypto:hmac(Alg, Key, <<Counter:64>>), + Hmac = crypto:hmac(Alg, Key, <<Counter:64>>), Offset = binary:last(Hmac) band 16#f, Code = ((binary:at(Hmac, Offset) band 16#7f) bsl 24) + diff --git a/src/couch/src/couch_httpd.erl b/src/couch/src/couch_httpd.erl index 456e82ef5..95b707447 100644 --- a/src/couch/src/couch_httpd.erl +++ b/src/couch/src/couch_httpd.erl @@ -620,7 +620,7 @@ rev_etag({Start, DiskRev}) -> <<$", Rev/binary, $">>. make_etag(Term) -> - <<SigInt:128/integer>> = couch_crypto:hash(md5, term_to_binary(Term)), + <<SigInt:128/integer>> = crypto:hash(md5, term_to_binary(Term)), iolist_to_binary([$", io_lib:format("~.36B", [SigInt]), $"]). etag_match(Req, CurrentEtag) when is_binary(CurrentEtag) -> diff --git a/src/couch/src/couch_httpd_auth.erl b/src/couch/src/couch_httpd_auth.erl index ec7ede1f3..51a83e7e4 100644 --- a/src/couch/src/couch_httpd_auth.erl +++ b/src/couch/src/couch_httpd_auth.erl @@ -170,7 +170,7 @@ proxy_auth_user(Req) -> undefined -> Req#httpd{user_ctx=#user_ctx{name=?l2b(UserName), roles=Roles}}; Secret -> - ExpectedToken = couch_util:to_hex(couch_crypto:hmac(sha, Secret, UserName)), + ExpectedToken = couch_util:to_hex(crypto:hmac(sha, Secret, UserName)), case header_value(Req, XHeaderToken) of Token when Token == ExpectedToken -> Req#httpd{user_ctx=#user_ctx{name=?l2b(UserName), @@ -214,7 +214,7 @@ cookie_authentication_handler(#httpd{mochi_req=MochiReq}=Req, AuthModule) -> {ok, UserProps, _AuthCtx} -> UserSalt = couch_util:get_value(<<"salt">>, UserProps, <<"">>), FullSecret = <<Secret/binary, UserSalt/binary>>, - ExpectedHash = couch_crypto:hmac(sha, FullSecret, User ++ ":" ++ TimeStr), + ExpectedHash = crypto:hmac(sha, FullSecret, User ++ ":" ++ TimeStr), Hash = ?l2b(HashStr), Timeout = list_to_integer( config:get("couch_httpd_auth", "timeout", "600")), @@ -262,7 +262,7 @@ cookie_auth_header(_Req, _Headers) -> []. cookie_auth_cookie(Req, User, Secret, TimeStamp) -> SessionData = User ++ ":" ++ erlang:integer_to_list(TimeStamp, 16), - Hash = couch_crypto:hmac(sha, Secret, SessionData), + Hash = crypto:hmac(sha, Secret, SessionData), mochiweb_cookies:cookie("AuthSession", couch_util:encodeBase64Url(SessionData ++ ":" ++ ?b2l(Hash)), [{path, "/"}] ++ cookie_scheme(Req) ++ max_age()). diff --git a/src/couch/src/couch_native_process.erl b/src/couch/src/couch_native_process.erl index 7f6ea7d33..6d66c936b 100644 --- a/src/couch/src/couch_native_process.erl +++ b/src/couch/src/couch_native_process.erl @@ -351,11 +351,11 @@ bindings(State, Sig, DDoc) -> % thanks to erlview, via: % http://erlang.org/pipermail/erlang-questions/2003-November/010544.html makefun(State, Source) -> - Sig = couch_crypto:hash(md5, Source), + Sig = crypto:hash(md5, Source), BindFuns = bindings(State, Sig), {Sig, makefun(State, Source, BindFuns)}. makefun(State, Source, {DDoc}) -> - Sig = couch_crypto:hash(md5, lists:flatten([Source, term_to_binary(DDoc)])), + Sig = crypto:hash(md5, lists:flatten([Source, term_to_binary(DDoc)])), BindFuns = bindings(State, Sig, {DDoc}), {Sig, makefun(State, Source, BindFuns)}; makefun(_State, Source, BindFuns) when is_list(BindFuns) -> diff --git a/src/couch/src/couch_passwords.erl b/src/couch/src/couch_passwords.erl index 1e7de158a..677ef6559 100644 --- a/src/couch/src/couch_passwords.erl +++ b/src/couch/src/couch_passwords.erl @@ -23,7 +23,7 @@ %% legacy scheme, not used for new passwords. -spec simple(binary(), binary()) -> binary(). simple(Password, Salt) when is_binary(Password), is_binary(Salt) -> - ?l2b(couch_util:to_hex(couch_crypto:hash(sha, <<Password/binary, Salt/binary>>))). + ?l2b(couch_util:to_hex(crypto:hash(sha, <<Password/binary, Salt/binary>>))). %% CouchDB utility functions -spec hash_admin_password(binary() | list()) -> binary(). @@ -36,7 +36,7 @@ hash_admin_password(ClearPassword) when is_binary(ClearPassword) -> hash_admin_password("simple", ClearPassword) -> % deprecated Salt = couch_uuids:random(), - Hash = couch_crypto:hash(sha, <<ClearPassword/binary, Salt/binary>>), + Hash = crypto:hash(sha, <<ClearPassword/binary, Salt/binary>>), ?l2b("-hashed-" ++ couch_util:to_hex(Hash) ++ "," ++ ?b2l(Salt)); hash_admin_password("pbkdf2", ClearPassword) -> Iterations = config:get("couch_httpd_auth", "iterations", "10000"), @@ -98,12 +98,12 @@ pbkdf2(_Password, _Salt, Iterations, _BlockIndex, Iteration, _Prev, Acc) when Iteration > Iterations -> Acc; pbkdf2(Password, Salt, Iterations, BlockIndex, 1, _Prev, _Acc) -> - InitialBlock = couch_crypto:hmac(sha, Password, + InitialBlock = crypto:hmac(sha, Password, <<Salt/binary,BlockIndex:32/integer>>), pbkdf2(Password, Salt, Iterations, BlockIndex, 2, InitialBlock, InitialBlock); pbkdf2(Password, Salt, Iterations, BlockIndex, Iteration, Prev, Acc) -> - Next = couch_crypto:hmac(sha, Password, Prev), + Next = crypto:hmac(sha, Password, Prev), pbkdf2(Password, Salt, Iterations, BlockIndex, Iteration + 1, Next, crypto:exor(Next, Acc)). diff --git a/src/couch/src/couch_server.erl b/src/couch/src/couch_server.erl index a115125a0..24016e05c 100644 --- a/src/couch/src/couch_server.erl +++ b/src/couch/src/couch_server.erl @@ -153,7 +153,7 @@ is_admin(User, ClearPwd) -> case config:get("admins", User) of "-hashed-" ++ HashedPwdAndSalt -> [HashedPwd, Salt] = string:tokens(HashedPwdAndSalt, ","), - couch_util:to_hex(couch_crypto:hash(sha, ClearPwd ++ Salt)) == HashedPwd; + couch_util:to_hex(crypto:hash(sha, ClearPwd ++ Salt)) == HashedPwd; _Else -> false end. diff --git a/src/couch/src/couch_stream.erl b/src/couch/src/couch_stream.erl index 7da422baa..eb64484df 100644 --- a/src/couch/src/couch_stream.erl +++ b/src/couch/src/couch_stream.erl @@ -73,7 +73,7 @@ foldl(Fd, [Pos|Rest], Fun, Acc) -> foldl(Fd, PosList, <<>>, Fun, Acc) -> foldl(Fd, PosList, Fun, Acc); foldl(Fd, PosList, Md5, Fun, Acc) -> - foldl(Fd, PosList, Md5, couch_crypto:hash_init(md5), Fun, Acc). + foldl(Fd, PosList, Md5, crypto:hash_init(md5), Fun, Acc). foldl_decode(Fd, PosList, Md5, Enc, Fun, Acc) -> {DecDataFun, DecEndFun} = case Enc of @@ -83,25 +83,25 @@ foldl_decode(Fd, PosList, Md5, Enc, Fun, Acc) -> identity_enc_dec_funs() end, Result = foldl_decode( - DecDataFun, Fd, PosList, Md5, couch_crypto:hash_init(md5), Fun, Acc + DecDataFun, Fd, PosList, Md5, crypto:hash_init(md5), Fun, Acc ), DecEndFun(), Result. foldl(_Fd, [], Md5, Md5Acc, _Fun, Acc) -> - Md5 = couch_crypto:hash_final(md5, Md5Acc), + Md5 = crypto:hash_final(Md5Acc), Acc; foldl(Fd, [{Pos, _Size}], Md5, Md5Acc, Fun, Acc) -> % 0110 UPGRADE CODE foldl(Fd, [Pos], Md5, Md5Acc, Fun, Acc); foldl(Fd, [Pos], Md5, Md5Acc, Fun, Acc) -> {ok, Bin} = couch_file:pread_iolist(Fd, Pos), - Md5 = couch_crypto:hash_final(md5, couch_crypto:hash_update(md5, Md5Acc, Bin)), + Md5 = crypto:hash_final(crypto:hash_update(Md5Acc, Bin)), Fun(Bin, Acc); foldl(Fd, [{Pos, _Size}|Rest], Md5, Md5Acc, Fun, Acc) -> foldl(Fd, [Pos|Rest], Md5, Md5Acc, Fun, Acc); foldl(Fd, [Pos|Rest], Md5, Md5Acc, Fun, Acc) -> {ok, Bin} = couch_file:pread_iolist(Fd, Pos), - foldl(Fd, Rest, Md5, couch_crypto:hash_update(md5, Md5Acc, Bin), Fun, Fun(Bin, Acc)). + foldl(Fd, Rest, Md5, crypto:hash_update(Md5Acc, Bin), Fun, Fun(Bin, Acc)). range_foldl(Fd, PosList, From, To, Fun, Acc) -> range_foldl(Fd, PosList, From, To, 0, Fun, Acc). @@ -134,13 +134,13 @@ clip(Value, Lo, Hi) -> end. foldl_decode(_DecFun, _Fd, [], Md5, Md5Acc, _Fun, Acc) -> - Md5 = couch_crypto:hash_final(md5, Md5Acc), + Md5 = crypto:hash_final(Md5Acc), Acc; foldl_decode(DecFun, Fd, [{Pos, _Size}], Md5, Md5Acc, Fun, Acc) -> foldl_decode(DecFun, Fd, [Pos], Md5, Md5Acc, Fun, Acc); foldl_decode(DecFun, Fd, [Pos], Md5, Md5Acc, Fun, Acc) -> {ok, EncBin} = couch_file:pread_iolist(Fd, Pos), - Md5 = couch_crypto:hash_final(md5, couch_crypto:hash_update(md5, Md5Acc, EncBin)), + Md5 = crypto:hash_final(crypto:hash_update(Md5Acc, EncBin)), Bin = DecFun(EncBin), Fun(Bin, Acc); foldl_decode(DecFun, Fd, [{Pos, _Size}|Rest], Md5, Md5Acc, Fun, Acc) -> @@ -148,7 +148,7 @@ foldl_decode(DecFun, Fd, [{Pos, _Size}|Rest], Md5, Md5Acc, Fun, Acc) -> foldl_decode(DecFun, Fd, [Pos|Rest], Md5, Md5Acc, Fun, Acc) -> {ok, EncBin} = couch_file:pread_iolist(Fd, Pos), Bin = DecFun(EncBin), - Md5Acc2 = couch_crypto:hash_update(md5, Md5Acc, EncBin), + Md5Acc2 = crypto:hash_update(Md5Acc, EncBin), foldl_decode(DecFun, Fd, Rest, Md5, Md5Acc2, Fun, Fun(Bin, Acc)). gzip_init(Options) -> @@ -210,8 +210,8 @@ init({Fd, OpenerPid, OpenerPriority, Options}) -> {ok, #stream{ fd=Fd, opener_monitor=erlang:monitor(process, OpenerPid), - md5=couch_crypto:hash_init(md5), - identity_md5=couch_crypto:hash_init(md5), + md5=crypto:hash_init(md5), + identity_md5=crypto:hash_init(md5), encoding_fun=EncodingFun, end_encoding_fun=EndEncodingFun, max_buffer=couch_util:get_value( @@ -237,7 +237,7 @@ handle_call({write, Bin}, _From, Stream) -> encoding_fun = EncodingFun} = Stream, if BinSize + BufferLen > Max -> WriteBin = lists:reverse(Buffer, [Bin]), - IdenMd5_2 = couch_crypto:hash_update(md5, IdenMd5, WriteBin), + IdenMd5_2 = crypto:hash_update(IdenMd5, WriteBin), case EncodingFun(WriteBin) of [] -> % case where the encoder did some internal buffering @@ -248,7 +248,7 @@ handle_call({write, Bin}, _From, Stream) -> WriteBin2 -> {ok, Pos, _} = couch_file:append_binary(Fd, WriteBin2), WrittenLen2 = WrittenLen + iolist_size(WriteBin2), - Md5_2 = couch_crypto:hash_update(md5, Md5, WriteBin2), + Md5_2 = crypto:hash_update(Md5, WriteBin2), Written2 = [{Pos, iolist_size(WriteBin2)}|Written] end, @@ -280,9 +280,9 @@ handle_call(close, _From, Stream) -> end_encoding_fun = EndEncodingFun} = Stream, WriteBin = lists:reverse(Buffer), - IdenMd5Final = couch_crypto:hash_final(md5, couch_crypto:hash_update(md5, IdenMd5, WriteBin)), + IdenMd5Final = crypto:hash_final(crypto:hash_update(IdenMd5, WriteBin)), WriteBin2 = EncodingFun(WriteBin) ++ EndEncodingFun(), - Md5Final = couch_crypto:hash_final(md5, couch_crypto:hash_update(md5, Md5, WriteBin2)), + Md5Final = crypto:hash_final(crypto:hash_update(Md5, WriteBin2)), Result = case WriteBin2 of [] -> {lists:reverse(Written), WrittenLen, IdenLen, Md5Final, IdenMd5Final}; diff --git a/src/couch/test/couch_auth_cache_tests.erl b/src/couch/test/couch_auth_cache_tests.erl index 76179dea0..26596559f 100644 --- a/src/couch/test/couch_auth_cache_tests.erl +++ b/src/couch/test/couch_auth_cache_tests.erl @@ -260,7 +260,7 @@ update_user_doc(DbName, UserName, Password, Rev) -> {ok, couch_doc:rev_to_str(NewRev)}. hash_password(Password) -> - ?l2b(couch_util:to_hex(couch_crypto:hash(sha, iolist_to_binary([Password, ?SALT])))). + ?l2b(couch_util:to_hex(crypto:hash(sha, iolist_to_binary([Password, ?SALT])))). shutdown_db(DbName) -> {ok, AuthDb} = couch_db:open_int(DbName, [?ADMIN_CTX]), diff --git a/src/couch/test/couchdb_attachments_tests.erl b/src/couch/test/couchdb_attachments_tests.erl index 11493a81a..88f53a189 100644 --- a/src/couch/test/couchdb_attachments_tests.erl +++ b/src/couch/test/couchdb_attachments_tests.erl @@ -207,7 +207,7 @@ should_upload_attachment_with_valid_md5_header({Host, DbName}) -> Headers = [ {"Content-Length", "34"}, {"Content-Type", "text/plain"}, - {"Content-MD5", ?b2l(base64:encode(couch_crypto:hash(md5, Body)))}, + {"Content-MD5", ?b2l(base64:encode(crypto:hash(md5, Body)))}, {"Host", Host} ], {ok, Code, Json} = request("PUT", AttUrl, Headers, Body), @@ -223,7 +223,7 @@ should_upload_attachment_by_chunks_with_valid_md5_header({Host, DbName}) -> Body = [chunked_body([Part1, Part2]), "\r\n"], Headers = [ {"Content-Type", "text/plain"}, - {"Content-MD5", ?b2l(base64:encode(couch_crypto:hash(md5, AttData)))}, + {"Content-MD5", ?b2l(base64:encode(crypto:hash(md5, AttData)))}, {"Host", Host}, {"Transfer-Encoding", "chunked"} ], @@ -238,7 +238,7 @@ should_upload_attachment_by_chunks_with_valid_md5_trailer({Host, DbName}) -> AttData = <<"We all live in a yellow submarine!">>, <<Part1:21/binary, Part2:13/binary>> = AttData, Body = [chunked_body([Part1, Part2]), - "Content-MD5: ", base64:encode(couch_crypto:hash(md5, AttData)), + "Content-MD5: ", base64:encode(crypto:hash(md5, AttData)), "\r\n\r\n"], Headers = [ {"Content-Type", "text/plain"}, diff --git a/src/couch_epi/src/couch_epi_data.erl b/src/couch_epi/src/couch_epi_data.erl index 937048273..93e39f69d 100644 --- a/src/couch_epi/src/couch_epi_data.erl +++ b/src/couch_epi/src/couch_epi_data.erl @@ -111,4 +111,4 @@ definitions({module, Modules}) -> hash_of_file(FilePath) -> {ok, Data} = file:read_file(FilePath), - couch_epi_util:md5(Data). + crypto:hash(md5, Data). diff --git a/src/couch_epi/src/couch_epi_util.erl b/src/couch_epi/src/couch_epi_util.erl index 5020fba08..e99db4668 100644 --- a/src/couch_epi/src/couch_epi_util.erl +++ b/src/couch_epi/src/couch_epi_util.erl @@ -12,7 +12,7 @@ -module(couch_epi_util). --export([module_version/1, hash/1, md5/1, module_exists/1]). +-export([module_version/1, hash/1, module_exists/1]). -compile([nowarn_deprecated_function]). @@ -22,16 +22,8 @@ module_version(Module) -> VSNs. hash(Term) -> - <<SigInt:128/integer>> = md5(term_to_binary(Term)), + <<SigInt:128/integer>> = crypto:hash(md5, term_to_binary(Term)), lists:flatten(io_lib:format("\"~.36B\"",[SigInt])). -md5(Data) -> - case erlang:function_exported(crypto, hash, 2) of - true -> - crypto:hash(md5, Data); - false -> - crypto:md5(Data) - end. - module_exists(Module) -> erlang:function_exported(Module, module_info, 0). diff --git a/src/couch_index/test/couch_index_ddoc_updated_tests.erl b/src/couch_index/test/couch_index_ddoc_updated_tests.erl index 007f5692b..f42c9a29a 100644 --- a/src/couch_index/test/couch_index_ddoc_updated_tests.erl +++ b/src/couch_index/test/couch_index_ddoc_updated_tests.erl @@ -118,7 +118,7 @@ fake_index() -> (idx_name, {_DbName, DDoc}) -> DDoc#doc.id; (signature, {_DbName, DDoc}) -> - couch_crypto:hash(md5, term_to_binary(DDoc)); + crypto:hash(md5, term_to_binary(DDoc)); (update_seq, Seq) -> Seq end). diff --git a/src/couch_mrview/src/couch_mrview.erl b/src/couch_mrview/src/couch_mrview.erl index 037391965..ff43c6187 100644 --- a/src/couch_mrview/src/couch_mrview.erl +++ b/src/couch_mrview/src/couch_mrview.erl @@ -217,7 +217,7 @@ query_all_docs(Db, Args, Callback, Acc) when is_list(Args) -> query_all_docs(Db, Args0, Callback, Acc) -> Sig = couch_util:with_db(Db, fun(WDb) -> {ok, Info} = couch_db:get_db_info(WDb), - couch_index_util:hexsig(couch_crypto:hash(md5, term_to_binary(Info))) + couch_index_util:hexsig(crypto:hash(md5, term_to_binary(Info))) end), Args1 = Args0#mrargs{view_type=map}, Args2 = couch_mrview_util:validate_args(Args1), diff --git a/src/couch_mrview/src/couch_mrview_util.erl b/src/couch_mrview/src/couch_mrview_util.erl index 632522240..4bbb7cb92 100644 --- a/src/couch_mrview/src/couch_mrview_util.erl +++ b/src/couch_mrview/src/couch_mrview_util.erl @@ -148,7 +148,7 @@ ddoc_to_mrst(DbName, #doc{id=Id, body={Fields}}) -> keyseq_indexed=KeySeqIndexed }, SigInfo = {Views, Language, DesignOpts, couch_index_util:sort_lib(Lib)}, - {ok, IdxState#mrst{sig=couch_crypto:hash(md5, term_to_binary(SigInfo))}}. + {ok, IdxState#mrst{sig=crypto:hash(md5, term_to_binary(SigInfo))}}. set_view_type(_Args, _ViewName, []) -> @@ -194,7 +194,7 @@ view_sig(Db, State, View, #mrargs{include_docs=true}=Args) -> keyseq_indexed=KeySeqIndexed } = State, Term = view_sig_term(BaseSig, UpdateSeq, PurgeSeq, KeySeqIndexed, SeqIndexed), - couch_index_util:hexsig(couch_crypto:hash(md5, term_to_binary(Term))); + couch_index_util:hexsig(crypto:hash(md5, term_to_binary(Term))); view_sig(Db, State, {_Nth, _Lang, View}, Args) -> view_sig(Db, State, View, Args); view_sig(_Db, State, View, Args0) -> @@ -208,7 +208,7 @@ view_sig(_Db, State, View, Args0) -> extra=[] }, Term = view_sig_term(Sig, UpdateSeq, PurgeSeq, KeySeqIndexed, SeqIndexed, Args), - couch_index_util:hexsig(couch_crypto:hash(md5, term_to_binary(Term))). + couch_index_util:hexsig(crypto:hash(md5, term_to_binary(Term))). view_sig_term(BaseSig, UpdateSeq, PurgeSeq, false, false) -> {BaseSig, UpdateSeq, PurgeSeq}; @@ -983,7 +983,7 @@ sig_vsn_12x(State) -> {ViewInfo, State#mrst.language, State#mrst.design_opts, couch_index_util:sort_lib(State#mrst.lib)} end, - couch_crypto:hash(md5, term_to_binary(SigData)). + crypto:hash(md5, term_to_binary(SigData)). old_view_format(View) -> { diff --git a/src/couch_plugins/src/couch_plugins.erl b/src/couch_plugins/src/couch_plugins.erl index c3ac946fd..139a878bf 100644 --- a/src/couch_plugins/src/couch_plugins.erl +++ b/src/couch_plugins/src/couch_plugins.erl @@ -231,7 +231,7 @@ do_verify_checksum(Filename, Checksum) -> couch_log:debug("Checking Filename: ~s", [Filename]), case file:read_file(Filename) of {ok, Data} -> - ComputedChecksum = binary_to_list(base64:encode(couch_crypto:hash(sha, Data))), + ComputedChecksum = binary_to_list(base64:encode(crypto:hash(sha, Data))), case ComputedChecksum of Checksum -> ok; _Else -> diff --git a/src/couch_replicator/src/couch_replicator_ids.erl b/src/couch_replicator/src/couch_replicator_ids.erl index 7f26db757..cbfe82afb 100644 --- a/src/couch_replicator/src/couch_replicator_ids.erl +++ b/src/couch_replicator/src/couch_replicator_ids.erl @@ -100,7 +100,7 @@ maybe_append_filters(Base, {error, FilterParseError} -> throw({error, FilterParseError}) end, - couch_util:to_hex(couch_crypto:hash(md5, term_to_binary(Base2))). + couch_util:to_hex(crypto:hash(md5, term_to_binary(Base2))). maybe_append_options(Options, RepOptions) -> diff --git a/src/couch_replicator/test/couch_replicator_many_leaves_tests.erl b/src/couch_replicator/test/couch_replicator_many_leaves_tests.erl index a6999bd8e..3b804c40e 100644 --- a/src/couch_replicator/test/couch_replicator_many_leaves_tests.erl +++ b/src/couch_replicator/test/couch_replicator_many_leaves_tests.erl @@ -141,7 +141,7 @@ add_doc_siblings(Db, _DocId, 0, AccDocs, AccRevs) -> add_doc_siblings(Db, DocId, NumLeaves, AccDocs, AccRevs) -> Value = ?l2b(?i2l(NumLeaves)), - Rev = couch_crypto:hash(md5, Value), + Rev = crypto:hash(md5, Value), Doc = #doc{ id = DocId, revs = {1, [Rev]}, diff --git a/src/couch_replicator/test/couch_replicator_test_helper.erl b/src/couch_replicator/test/couch_replicator_test_helper.erl index bbca0ae9c..f87c7636b 100644 --- a/src/couch_replicator/test/couch_replicator_test_helper.erl +++ b/src/couch_replicator/test/couch_replicator_test_helper.erl @@ -93,16 +93,16 @@ find_att([Att | Rest], Name) -> att_md5(Att) -> Md50 = couch_att:foldl( Att, - fun(Chunk, Acc) -> couch_crypto:hash_update(md5, Acc, Chunk) end, - couch_crypto:hash_init(md5)), - couch_crypto:hash_final(md5, Md50). + fun(Chunk, Acc) -> crypto:hash_update(Acc, Chunk) end, + crypto:hash_init(md5)), + crypto:hash_final(Md50). att_decoded_md5(Att) -> Md50 = couch_att:foldl_decode( Att, - fun(Chunk, Acc) -> couch_crypto:hash_update(md5, Acc, Chunk) end, - couch_crypto:hash_init(md5)), - couch_crypto:hash_final(md5, Md50). + fun(Chunk, Acc) -> crypto:hash_update(Acc, Chunk) end, + crypto:hash_init(md5)), + crypto:hash_final(Md50). db_url(DbName) -> iolist_to_binary([ diff --git a/src/mango/src/mango_idx.erl b/src/mango/src/mango_idx.erl index bc88b970c..c330702b1 100644 --- a/src/mango/src/mango_idx.erl +++ b/src/mango/src/mango_idx.erl @@ -347,7 +347,7 @@ get_idx_name(Idx, Opts) -> gen_name(Idx, Opts0) -> Opts = lists:usort(Opts0), TermBin = term_to_binary({Idx, Opts}), - Sha = couch_crypto:hash(sha, TermBin), + Sha = crypto:hash(sha, TermBin), mango_util:enc_hex(Sha). diff --git a/src/mem3/src/mem3_rep.erl b/src/mem3/src/mem3_rep.erl index db09d3658..826604ab1 100644 --- a/src/mem3/src/mem3_rep.erl +++ b/src/mem3/src/mem3_rep.erl @@ -106,8 +106,8 @@ make_local_id(#shard{node=SourceNode}, #shard{node=TargetNode}, Filter) -> make_local_id(SourceThing, TargetThing, Filter) -> - S = couch_util:encodeBase64Url(couch_crypto:hash(md5, term_to_binary(SourceThing))), - T = couch_util:encodeBase64Url(couch_crypto:hash(md5, term_to_binary(TargetThing))), + S = couch_util:encodeBase64Url(crypto:hash(md5, term_to_binary(SourceThing))), + T = couch_util:encodeBase64Url(crypto:hash(md5, term_to_binary(TargetThing))), F = case is_function(Filter) of true -> {new_uniq, Hash} = erlang:fun_info(Filter, new_uniq), @@ -341,7 +341,7 @@ update_locals(Acc) -> find_repl_doc(SrcDb, TgtUUIDPrefix) -> SrcUUID = couch_db:get_uuid(SrcDb), - S = couch_util:encodeBase64Url(couch_crypto:hash(md5, term_to_binary(SrcUUID))), + S = couch_util:encodeBase64Url(crypto:hash(md5, term_to_binary(SrcUUID))), DocIdPrefix = <<"_local/shard-sync-", S/binary, "-">>, FoldFun = fun({DocId, {Rev0, {BodyProps}}}, _, _) -> TgtUUID = couch_util:get_value(<<"target_uuid">>, BodyProps, <<>>), |