From 82d0cd7adc327a582b7e0c4be46220320edc8e64 Mon Sep 17 00:00:00 2001 From: cyclone <34043806+cyclone-github@users.noreply.github.com> Date: Fri, 1 Nov 2024 16:48:24 -0500 Subject: [PATCH] Added Several Modes, Fixed CPU Thread Defaults https://github.com/cyclone-github/hashgen/issues/4 --- go.mod | 4 ++-- go.sum | 8 ++++---- hashgen.go | 45 +++++++++++++++++++++++++++++++++++++-------- 3 files changed, 43 insertions(+), 14 deletions(-) diff --git a/go.mod b/go.mod index 7a33e7e..2fcee2b 100644 --- a/go.mod +++ b/go.mod @@ -2,6 +2,6 @@ module hashgen go 1.22.4 -require golang.org/x/crypto v0.26.0 +require golang.org/x/crypto v0.28.0 -require golang.org/x/sys v0.23.0 // indirect +require golang.org/x/sys v0.26.0 // indirect diff --git a/go.sum b/go.sum index c203622..25fba75 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,4 @@ -golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw= -golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54= -golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM= -golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= \ No newline at end of file +golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw= +golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U= +golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo= +golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= diff --git a/hashgen.go b/hashgen.go index 2385c85..5eb6065 100644 --- a/hashgen.go +++ b/hashgen.go @@ -51,8 +51,9 @@ v2023-11-04.1330-threaded; added reporting when encountering HEX decoding errors v2024-08-24.2000-threaded; added mode "morsecode" which follows ITU-R M.1677-1 standard -v2024-11-01.1530-threaded; - added thread flag "-t" to allow user to specity CPU threads, ex: -t 16 +v2024-11-01.1630-threaded; + added thread flag "-t" to allow user to specity CPU threads, ex: -t 16 // fixed default to use max CPU threads + added modes: sha2-224, sha2-384, sha2-512-224, sha2-512-256, keccak-256, keccak-512 */ func versionFunc() { @@ -89,16 +90,20 @@ func helpFunc() { "plaintext \t 99999 \t (can be used to dehex wordlist)\n" + "ripemd-160 \t 6000\n" + "sha1 \t\t 100\n" + - //"sha2-224 \t 1300\n" + - //"sha2-384 \t 10800\n" + + "sha2-224 \t 1300\n" + + "sha2-384 \t 10800\n" + "sha2-256 \t 1400\n" + "sha2-512 \t 1700\n" + - //"sha2-512-224\n" + - //"sha2-512-256\n" + + "sha2-512-224\n" + + "sha2-512-256\n" + "sha3-224 \t 17300\n" + "sha3-256 \t 17400\n" + "sha3-384 \t 17500\n" + - "sha3-512 \t 17600\n" + "sha3-512 \t 17600\n" + + //"keccak-224\t 17700\n" + + "keccak-256\t 17800\n" + + //"keccak-384\t 17900\n" + + "keccak-512\t 18000\n" fmt.Fprintln(os.Stderr, str) os.Exit(0) } @@ -222,12 +227,28 @@ func hashBytes(hashFunc string, data []byte) string { case "sha1", "100": h := sha1.Sum(data) return hex.EncodeToString(h[:]) + case "sha2-224", "sha2_224", "sha2224", "sha224", "1300": + h := sha256.New224() + h.Write(data) + return hex.EncodeToString(h.Sum(nil)) case "sha2-256", "sha2_256", "sha2256", "sha256", "1400": h := sha256.Sum256(data) return hex.EncodeToString(h[:]) + case "sha2-384", "sha384", "10800": + h := sha512.New384() + h.Write(data) + return hex.EncodeToString(h.Sum(nil)) case "sha2-512", "sha2_512", "sha2512", "sha512", "1700": h := sha512.Sum512(data) return hex.EncodeToString(h[:]) + case "sha2-512-224", "sha512_224", "sha512224": + h := sha512.New512_224() + h.Write(data) + return hex.EncodeToString(h.Sum(nil)) + case "sha2-512-256", "sha512_256", "sha512256": + h := sha512.New512_256() + h.Write(data) + return hex.EncodeToString(h.Sum(nil)) case "ripemd-160", "ripemd_160", "ripemd160", "6000": h := ripemd160.New() h.Write(data) @@ -248,6 +269,14 @@ func hashBytes(hashFunc string, data []byte) string { h := sha3.New512() h.Write(data) return hex.EncodeToString(h.Sum(nil)) + case "keccak-256", "keccak256", "17800": + h := sha3.NewLegacyKeccak256() + h.Write(data) + return hex.EncodeToString(h.Sum(nil)) + case "keccak-512", "keccak512", "18000": + h := sha3.NewLegacyKeccak512() + h.Write(data) + return hex.EncodeToString(h.Sum(nil)) case "11500": // hashcat compatible crc32 mode const hcCRCPad = ":00000000" h := crc32.ChecksumIEEE(data) @@ -479,7 +508,7 @@ func main() { // thread sanity check (can't use <= 0 or > available CPU threads) if numThreads <= 0 { - numThreads = 1 + numThreads = maxThreads } else if numThreads > maxThreads { numThreads = maxThreads }