@@ -51,10 +51,12 @@ v2023-11-04.1330-threaded;
51
51
added reporting when encountering HEX decoding errors
52
52
v2024-08-24.2000-threaded;
53
53
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
54
56
*/
55
57
56
58
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" )
58
60
}
59
61
60
62
// help function
@@ -266,6 +268,8 @@ func hashBytes(hashFunc string, data []byte) string {
266
268
return hex .EncodeToString (b )
267
269
case "ntlm" , "1000" :
268
270
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
269
273
input := utf16 .Encode ([]rune (string (data ))) // convert byte slice to string, then to rune slice
270
274
if err := binary .Write (h , binary .LittleEndian , input ); err != nil {
271
275
panic ("Failed NTLM hashing" )
@@ -311,10 +315,9 @@ func processChunk(chunk []byte, count *int64, hexErrorCount *int64, hashFunc str
311
315
}
312
316
313
317
// 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 ) {
315
319
const readBufferSize = 1024 * 1024 // read buffer
316
320
const writeBufferSize = 2 * readBufferSize // write buffer (larger than read buffer)
317
- numGoroutines := runtime .NumCPU () // use all available CPU threads
318
321
319
322
var linesHashed int64 = 0
320
323
var procWg sync.WaitGroup
@@ -445,6 +448,7 @@ func main() {
445
448
inputFile := flag .String ("w" , "" , "Input file to process (use 'stdin' to read from standard input)" )
446
449
outputFile := flag .String ("o" , "" , "Output file to write hashes to (use 'stdout' to print to console)" )
447
450
hashPlainOutput := flag .Bool ("hashplain" , false , "Enable hashplain output (hash:plain)" )
451
+ threads := flag .Int ("t" , 0 , "Number of CPU threads to use" )
448
452
version := flag .Bool ("version" , false , "Program version:" )
449
453
cyclone := flag .Bool ("cyclone" , false , "hashgen" )
450
454
help := flag .Bool ("help" , false , "Prints help:" )
@@ -469,9 +473,20 @@ func main() {
469
473
helpFunc ()
470
474
}
471
475
472
- runtime .GOMAXPROCS (runtime .NumCPU ()) // Use all available CPU threads
476
+ // determine CPU threads to use
477
+ numThreads := * threads
478
+ maxThreads := runtime .NumCPU ()
473
479
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 )
475
490
}
476
491
477
492
// base64 decode function used for displaying encoded messages
0 commit comments