From a1b0571d9d02dcf66484f2408c923265b1a7b1ab Mon Sep 17 00:00:00 2001 From: Aizen Date: Mon, 7 Oct 2024 07:53:37 +0200 Subject: [PATCH] default to higher entropy output --- cmd/genpw/cli.go | 5 ++++- cryptipass.go | 7 +++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/cmd/genpw/cli.go b/cmd/genpw/cli.go index cc745d5..de9b8b9 100644 --- a/cmd/genpw/cli.go +++ b/cmd/genpw/cli.go @@ -17,7 +17,6 @@ type Passphrase struct { } func main() { - g := cryptipass.NewInstance() f_pattern := flag.String("p", "W.w.w", `pattern used to generate passphrase e.g. try: -p WWW20dd @@ -28,7 +27,11 @@ func main() { - 's' symbol, 'd' digit. `) passwords := flag.Uint64("n", 6, "number of passwords to generate") + depth := flag.Uint64("d", 3, "markov chain depth, higher values lead to more plausible words but lower entropy") flag.Parse() + + g := cryptipass.NewCustomInstance(cryptipass.WordListEFF(), int(*depth)) + pattern := *f_pattern w := tabwriter.NewWriter(os.Stdout, 1, 1, 4, ' ', 0) diff --git a/cryptipass.go b/cryptipass.go index 7e0211e..2583ac4 100644 --- a/cryptipass.go +++ b/cryptipass.go @@ -42,6 +42,9 @@ import ( // If the random seed cannot be read from the crypto/rand source, the function // will log a fatal error and terminate the application. func NewCustomInstance(tokens []string, chain_depth int) *Generator { + if chain_depth < 1 { + panic("chain depths cannot be below 1") + } rng := new_chacha8_rng() g := new(Generator) g.Rng = rng @@ -83,8 +86,8 @@ func NewInstance() *Generator { var global_jump_table Generator func init() { - global_jump_table.depth = 3 - global_jump_table.jump_table = distill(WordListEFF(), 3) + global_jump_table.depth = 2 + global_jump_table.jump_table = distill(WordListEFF(), 2) } // GenPassphrase generates a passphrase composed of a specified number of words.