This is an archive of the discontinued LLVM Phabricator instance.

[lib/Fuzzer] Add SHA1 implementation from public domain.
ClosedPublic

Authored by kcc on May 12 2015, 10:36 PM.

Details

Summary

This adds a SHA1 implementation taken from public domain code.
The change is trivial, but as it involves third-party code I'd like
a second pair of eyes before commit.

LibFuzzer can not use SHA1 from openssl because openssl may not be available
and because we may be fuzzing openssl itself.
Using sha1sum via a pipe is too slow.

Diff Detail

Event Timeline

kcc updated this revision to Diff 25659.May 12 2015, 10:36 PM
kcc retitled this revision from to [lib/Fuzzer] Add SHA1 implementation from public domain..
kcc updated this object.
kcc edited the test plan for this revision. (Show Details)
kcc added a reviewer: chandlerc.
kcc added a subscriber: Unknown Object (MLST).

I guess it would be nice if this lived in support alongside MD5.h

kcc added a comment.May 13 2015, 7:12 AM

Not at all nice. I want to keep libFuzzer independent from the rest of LLVM.
It does *rely* on the rest of LLVM (because it needs instrumentation) but it can be compiled w/o
the rest of LLVM code. This is a very important trait for me.

chandlerc added inline comments.May 14 2015, 10:03 AM
lib/Fuzzer/CMakeLists.txt
13

This should be spelled FuzzerSHA1.cpp

lib/Fuzzer/FuzzerInternal.h
47–49

The comment isn't helping here. Again, please spell it 'SHA1' instead of 'Sha1'.

Also, array arguments with a size doesn't really make sense. They're just pointers in C++. I would either use a pointer or use a reference to an array of the given size.

lib/Fuzzer/FuzzerSha1.cpp
1–9 ↗(On Diff #25659)

Please use a normal LLVM style header and formatting. In particular please explain why this is here and not in lib/Support, etc.

14 ↗(On Diff #25659)

It would seem better to put this in an anonymous namespace and include the FuzzerInternal.h to define the ComputeSHA1 function in the fuzzer namespace.

221–225 ↗(On Diff #25659)

I really don't like this approach. Why not just write a normal LLVM unittest for this (or other parts of the Fuzzer library)?

kcc updated this revision to Diff 25784.May 14 2015, 10:28 AM

addressed comments

kcc added a comment.May 14 2015, 10:28 AM

done all, PTAL

lib/Fuzzer/CMakeLists.txt
13

done

lib/Fuzzer/FuzzerInternal.h
47–49

Improved the comment, spelling and types.

lib/Fuzzer/FuzzerSha1.cpp
1–9 ↗(On Diff #25659)

done

14 ↗(On Diff #25659)

done

221–225 ↗(On Diff #25659)

This is from the original code.
I've removed this part and added a unit test to test/FuzzerUnittest.cpp

kcc updated this revision to Diff 25785.May 14 2015, 10:29 AM

fix comment

chandlerc accepted this revision.May 14 2015, 3:38 PM
chandlerc edited edge metadata.

Looks good. Minor comment below.

lib/Fuzzer/FuzzerSHA1.cpp
10–13

I'd go ahead and say its been placed in the public domain so no one panics when reading it.

198–199

You can just define it:

void fuzzer::ComputeSHA1(...) {

Saves you namespace boilerplate. Not a big deal either way though.

This revision is now accepted and ready to land.May 14 2015, 3:38 PM
kcc updated this revision to Diff 25822.May 14 2015, 3:44 PM
kcc edited edge metadata.

addressed last comments

kcc closed this revision.May 14 2015, 3:45 PM