Rework MerkleIntegritySourceStream.
This cuts down on the number of copies and fixes some other bits: - Add a fuzzer. - Document a place where the original implementation did not match the specification. (The final record's size is a little iffy. We probably want a small spec tweak.) - Use a streaming SHA-256 implementation, rather than making a copy to stick the 0 or 1 in the hash. - If there is no more room in the output (the consumer may be issuing smaller reads), stop processing input. There is no need to make a copy of the entire input. MerkleIntegeritySourceStream only needs to buffer at most one record. (Ideally we wouldn't even do and instead coordinate with the base class's read buffer, but that would require tweaking the FilteredSourceStream interface. This CL addresses the easy stuff.) - Fix O(N^2) behavior if the caller issues tiny reads in the buffered output. - If the record is entirely in the input buffer (common case), don't make a copy to extract it. - If the output fits entirely in the output buffer (common case), don't make a copy to return it. - Flesh out missing tests, based on code coverage tools and important security checks (notably truncation). (For others trying to repeat the coverage bits: this file was unfortunately placed in //content rather than //net, so I wasn't able to get the coverage tools to work without hacking it into net_unittests locally. It seems the X server dependency is problematic for tools/code_coverage?? Also content_unittests is huge.) - s/MI-256/MI-SHA256/. There are other 256-bit hashes. Bug: 814591 Change-Id: If927d3f49085a5bec31939846c9a55f8903da34a Reviewed-on: https://chromium-review.googlesource.com/981798Reviewed-by:Yutaka Hirano <yhirano@chromium.org> Reviewed-by:
Matt Menke <mmenke@chromium.org> Reviewed-by:
Max Moroz <mmoroz@chromium.org> Commit-Queue: David Benjamin <davidben@chromium.org> Cr-Commit-Position: refs/heads/master@{#547874}
Showing
This diff is collapsed.
This diff is collapsed.
Please register or sign in to comment