Skip to content

Commit cc61f02

Browse files
Addressed #4
1 parent a1250e8 commit cc61f02

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

.deepsource.toml

-7
This file was deleted.

hashgen.go

+20-5
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,12 @@ v2023-11-04.1330-threaded;
5151
added reporting when encountering HEX decoding errors
5252
v2024-08-24.2000-threaded;
5353
added mode "morsecode" which follows ITU-R M.1677-1 standard
54+
v2024-11-01.1530-threaded;
55+
added thread flag "-t" to allow user to specity CPU threads, ex: -t 16
5456
*/
5557

5658
func versionFunc() {
57-
fmt.Fprintln(os.Stderr, "Cyclone hash generator v2024-08-24.2000-threaded")
59+
fmt.Fprintln(os.Stderr, "Cyclone hash generator v2024-11-01.1530-threaded")
5860
}
5961

6062
// help function
@@ -266,6 +268,8 @@ func hashBytes(hashFunc string, data []byte) string {
266268
return hex.EncodeToString(b)
267269
case "ntlm", "1000":
268270
h := md4.New()
271+
// convert byte slice to string assuming UTF-8, then encode as UTF-16LE
272+
// this may not work as expected if plaintext contains non-ASCII/UTF-8 encoding
269273
input := utf16.Encode([]rune(string(data))) // convert byte slice to string, then to rune slice
270274
if err := binary.Write(h, binary.LittleEndian, input); err != nil {
271275
panic("Failed NTLM hashing")
@@ -311,10 +315,9 @@ func processChunk(chunk []byte, count *int64, hexErrorCount *int64, hashFunc str
311315
}
312316

313317
// process logic
314-
func startProc(hashFunc string, inputFile string, outputPath string, hashPlainOutput bool) {
318+
func startProc(hashFunc string, inputFile string, outputPath string, hashPlainOutput bool, numGoroutines int) {
315319
const readBufferSize = 1024 * 1024 // read buffer
316320
const writeBufferSize = 2 * readBufferSize // write buffer (larger than read buffer)
317-
numGoroutines := runtime.NumCPU() // use all available CPU threads
318321

319322
var linesHashed int64 = 0
320323
var procWg sync.WaitGroup
@@ -445,6 +448,7 @@ func main() {
445448
inputFile := flag.String("w", "", "Input file to process (use 'stdin' to read from standard input)")
446449
outputFile := flag.String("o", "", "Output file to write hashes to (use 'stdout' to print to console)")
447450
hashPlainOutput := flag.Bool("hashplain", false, "Enable hashplain output (hash:plain)")
451+
threads := flag.Int("t", 0, "Number of CPU threads to use")
448452
version := flag.Bool("version", false, "Program version:")
449453
cyclone := flag.Bool("cyclone", false, "hashgen")
450454
help := flag.Bool("help", false, "Prints help:")
@@ -469,9 +473,20 @@ func main() {
469473
helpFunc()
470474
}
471475

472-
runtime.GOMAXPROCS(runtime.NumCPU()) // Use all available CPU threads
476+
// determine CPU threads to use
477+
numThreads := *threads
478+
maxThreads := runtime.NumCPU()
473479

474-
startProc(*hashFunc, *inputFile, *outputFile, *hashPlainOutput)
480+
// thread sanity check (can't use <= 0 or > available CPU threads)
481+
if numThreads <= 0 {
482+
numThreads = 1
483+
} else if numThreads > maxThreads {
484+
numThreads = maxThreads
485+
}
486+
487+
runtime.GOMAXPROCS(numThreads) // set CPU threads
488+
489+
startProc(*hashFunc, *inputFile, *outputFile, *hashPlainOutput, numThreads)
475490
}
476491

477492
// base64 decode function used for displaying encoded messages

0 commit comments

Comments
 (0)