Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/chttpd/src/chttpd.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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) ->
Expand Down
79 changes: 0 additions & 79 deletions src/couch/src/couch_crypto.erl

This file was deleted.

2 changes: 1 addition & 1 deletion src/couch/src/couch_db.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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) ->
Expand Down
2 changes: 1 addition & 1 deletion src/couch/src/couch_db_updater.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1465,7 +1465,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)).

default_security_object(<<"shards/", _/binary>>) ->
case config:get("couchdb", "default_security", "everyone") of
Expand Down
8 changes: 4 additions & 4 deletions src/couch/src/couch_file.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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) ->
Expand Down Expand Up @@ -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};
_ ->
Expand Down Expand Up @@ -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)).
Expand Down Expand Up @@ -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}.


Expand Down
2 changes: 1 addition & 1 deletion src/couch/src/couch_hotp.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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) +
Expand Down
2 changes: 1 addition & 1 deletion src/couch/src/couch_httpd.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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) ->
Expand Down
6 changes: 3 additions & 3 deletions src/couch/src/couch_httpd_auth.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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")),
Expand Down Expand Up @@ -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()).
Expand Down
4 changes: 2 additions & 2 deletions src/couch/src/couch_native_process.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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) ->
Expand Down
8 changes: 4 additions & 4 deletions src/couch/src/couch_passwords.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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().
Expand All @@ -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"),
Expand Down Expand Up @@ -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)).

Expand Down
2 changes: 1 addition & 1 deletion src/couch/src/couch_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
28 changes: 14 additions & 14 deletions src/couch/src/couch_stream.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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).
Expand Down Expand Up @@ -134,21 +134,21 @@ 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) ->
foldl_decode(DecFun, Fd, [Pos|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) ->
Expand Down Expand Up @@ -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(
Expand All @@ -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
Expand All @@ -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,

Expand Down Expand Up @@ -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};
Expand Down
2 changes: 1 addition & 1 deletion src/couch/test/couch_auth_cache_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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]),
Expand Down
6 changes: 3 additions & 3 deletions src/couch/test/couchdb_attachments_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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"}
],
Expand All @@ -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"},
Expand Down
2 changes: 1 addition & 1 deletion src/couch_epi/src/couch_epi_data.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Loading