- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 334
Add SHA-512 Hashing Sink #113
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
Comments
Opened PR as #114 |
Thanks @terrorbyte! This looks very good. One thing I don't see here, despite your heading, is a use case. Is there some real-world user problem that needs to be solved specifically using SHA-512 hashing, rather than just "some arbitrary reasonably secure hash"? If so, we can mention it in the documentation and explain when to use this. |
For the first bit, here are some very common use case scenarios where I run into SHA-512:
As for personal use cases, I do a lot of automation and scripting in my penetration testing work which can often include checksums for software downloads, custom protocols for package signatures, TLS handshakes, database hashes of clients and people I am testing (given, this is bad practice), and even simple integrity checks. It is certainly "less common" and often times has little benefit to most cryptographic operations, but it's something that I end up running into regularly. |
That's great—could you give an example of the kind of program that you'd like to write with It strikes me that perhaps it would be most flexible to simply provide a script.Echo("data").Hash().Stdout() but also: script.Echo("secret password").Hash(sha512.New()).Stdout() |
Here is a quick hacky example of one such common workflow that I have to do using a package main
import (
"fmt"
"io"
"net/http"
"os"
"strings"
"github.com/bitfield/script"
)
func main() {
fullURLFile := "https://artifacts.elastic.co/downloads/kibana/kibana-8.1.3-amd64.deb"
file, err := os.Create("kibana.deb")
if err != nil {
fmt.Printf(err.Error(), os.Stderr)
os.Exit(1)
}
client := http.Client{}
resp, err := client.Get(fullURLFile)
if err != nil {
fmt.Printf(err.Error(), os.Stderr)
os.Exit(1)
}
_, err = io.Copy(file, resp.Body)
file.Close()
resp.Body.Close()
respSha, err := client.Get(fullURLFile + ".sha512")
if err != nil {
fmt.Printf(err.Error(), os.Stderr)
os.Exit(1)
}
shaSumFile, err := io.ReadAll(respSha.Body)
if err != nil {
fmt.Printf(err.Error(), os.Stderr)
os.Exit(1)
}
respSha.Body.Close()
shaSum := strings.Split(string(shaSumFile), " ")[0]
fmt.Println("> " + shaSum)
script.Echo("kibana.deb").SHA512Sums().Stdout()
} This should output:
|
As for the API design part, I am of two minds in this regard. First, I do foresee it becoming pretty common place to utilize other generic hashing algorithms and utilizing the generic Second, I don't think having a "default" hash actually makes logical sense in the context of hashing algorithms, because you are rarely using them in optionally and are explicitly dictated which ones to use. For example I'm given specific hashes for checksums and applying the concept of "hashing" to it could mean many different things. If anything, it might be a bit more cumbersome, but the algorithm structure used now might be in line with real use case vs the proposed "optional argument". I'd rather see |
While sha-256 is considered secure unless data is salted most passwords can be cracked easily using online tools such as dcode.fr |
No one indicated using any of these for password hashes, and if they do they are not reading modern guidance from the last 20 years. Hashing algorithms are used in many more places than just password hashes, please take a moment to read my examples. For the record, I build password cracking machines and regularly compete in competitions. From a cracking perspective there is only fractional differences between SHA-256 and SHA-512 algorithms cracking speeds in the real world. If you are using any SHA algorithm for password storage without many rounds, salt, and cost factors you are doing something horribly wrong. Modern |
@bitfield What's the status of this? Can I pick it up? |
Sure! The consensus API proposal seems to be something like:
|
@terrorbyte what do you think of the changes in #215? Do they solve the problem for you? |
I think that using the Good work @mahadzaryab1 |
Use Case
Currently SHA-256 is the only supported hashing algorithm (and there is some engineering design decisions in #39), this PR creates a SHA-512 sink that works identically the the current SHA-256 design but just with the
crypto/sha512
library imported and the same functions applied.Tests
As per the contributor guidelines I ran also created all the tests and test data. Here is the following output:
One note, in the original patchset I added a
testdata/sha512Sum.input.txt
file that has the same content astestdata/sha256Sum.input.txt
. This was to meet the contribution guidelines, but I think that it could be beneficial to generalize the test data to work with arbitrary hashing functions (ie something liketestdata/hashSum.input.txt
).Documentation
I updated the docs as well to match the SHA-256 functions. I am happy to add some more README examples for both the functions if need be.
The text was updated successfully, but these errors were encountered: