Skip to content

Added SHA-512 Hashing #114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

terrorbyte
Copy link
Contributor

See #113 for discussion

Added a SHA-512 hashing mechanism modeled off of the SHA-256 tools. The majority of this code is nearly copy and pasted from the function with the SHA-512 crypto code. The tests have also been added and utilizes the SHA-512 openssl dgst, the only file added was a input file for SHA-512, though it is exactly the same as the 256 test file (I will bring up in the issue that it may be better to create just a generic file for hashing algorithms vs just for each one as per the nature of hashing algorithms).

All tests passed on my first run:

$ go test -v | grep -i sha512
=== RUN   TestSHA512Sums_OutputsCorrectHashForEachSpecifiedFile
=== PAUSE TestSHA512Sums_OutputsCorrectHashForEachSpecifiedFile
=== RUN   TestSHA512Sum_OutputsCorrectHash
=== PAUSE TestSHA512Sum_OutputsCorrectHash
=== CONT  TestSHA512Sum_OutputsCorrectHash
=== RUN   TestSHA512Sum_OutputsCorrectHash/for_no_data
=== RUN   TestSHA512Sum_OutputsCorrectHash/for_short_string
=== RUN   TestSHA512Sum_OutputsCorrectHash/for_string_containing_newline
--- PASS: TestSHA512Sum_OutputsCorrectHash (0.00s)
    --- PASS: TestSHA512Sum_OutputsCorrectHash/for_no_data (0.00s)
    --- PASS: TestSHA512Sum_OutputsCorrectHash/for_short_string (0.00s)
    --- PASS: TestSHA512Sum_OutputsCorrectHash/for_string_containing_newline (0.00s)
=== CONT  TestSHA512Sums_OutputsCorrectHashForEachSpecifiedFile
--- PASS: TestSHA512Sums_OutputsCorrectHashForEachSpecifiedFile (0.00s)
=== RUN   ExamplePipe_SHA512Sum
--- PASS: ExamplePipe_SHA512Sum (0.00s)
=== RUN   ExamplePipe_SHA512Sums
--- PASS: ExamplePipe_SHA512Sums (0.00s)

Added a SHA-512 hashing mechanism modeled off of the SHA-256 tools. The
majority of this code is nearly copy and pasted from the function with
the SHA-512 crypto code. The tests have also been added and utilizes the
SHA-512 `openssl dgst`, the only file added was a input file for
SHA-512, though it is exactly the same as the 256 test file (I will
bring up in the issue that it may be better to create just a generic
file for hashing algorithms vs just for each one as per the nature of
hashing algorithms).

All tests passed on my first run:

```
$ go test -v | grep -i sha512
=== RUN   TestSHA512Sums_OutputsCorrectHashForEachSpecifiedFile
=== PAUSE TestSHA512Sums_OutputsCorrectHashForEachSpecifiedFile
=== RUN   TestSHA512Sum_OutputsCorrectHash
=== PAUSE TestSHA512Sum_OutputsCorrectHash
=== CONT  TestSHA512Sum_OutputsCorrectHash
=== RUN   TestSHA512Sum_OutputsCorrectHash/for_no_data
=== RUN   TestSHA512Sum_OutputsCorrectHash/for_short_string
=== RUN   TestSHA512Sum_OutputsCorrectHash/for_string_containing_newline
--- PASS: TestSHA512Sum_OutputsCorrectHash (0.00s)
    --- PASS: TestSHA512Sum_OutputsCorrectHash/for_no_data (0.00s)
    --- PASS: TestSHA512Sum_OutputsCorrectHash/for_short_string (0.00s)
    --- PASS: TestSHA512Sum_OutputsCorrectHash/for_string_containing_newline (0.00s)
=== CONT  TestSHA512Sums_OutputsCorrectHashForEachSpecifiedFile
--- PASS: TestSHA512Sums_OutputsCorrectHashForEachSpecifiedFile (0.00s)
=== RUN   ExamplePipe_SHA512Sum
--- PASS: ExamplePipe_SHA512Sum (0.00s)
=== RUN   ExamplePipe_SHA512Sums
--- PASS: ExamplePipe_SHA512Sums (0.00s)
```
@bitfield
Copy link
Owner

bitfield commented Jun 2, 2022

Yes, this is great, but it seems a shame to duplicate all the SHA-256 code. Since both SHA-256 and SHA-512 implement Hasher, should we rewrite this to use common hashing code, but switch the hasher depending on the method called?

In other words, something like:

func (p *Pipe) SHA256Sum() (string, error) {
	return p.hash(sha256.New())
}

@bitfield
Copy link
Owner

I think this is superseded by #130, isn't it?

@bitfield bitfield closed this Aug 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants