Skip to content

Commit 121cf7c

Browse files
2.0 release (#1)
* allow for custom RNGs and for isolation of instances of Cryptipass * move certification process to tests * add custom patterns for password generation * distill markov chain dynamically, allowing for custom languages (word-lists) * add examples, simplify and streamline readme
1 parent 5c16201 commit 121cf7c

File tree

13 files changed

+721
-19656
lines changed

13 files changed

+721
-19656
lines changed

README.md

+67-34
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,113 @@
1-
# Cryptipass
2-
NOTE: **We also have a [CLI](cmd/genpw) available for non-library uses.**
3-
Cryptipass is a Go package designed to generate secure passphrases composed of human-readable words. The passphrases are generated with a focus on both security (through entropy) and usability by combining cryptographic randomness and customizable word generation strategies.
1+
# cryptipass
2+
3+
[![Go Report Card](https://goreportcard.com/badge/github.com/francescoalemanno/cryptipass)](https://goreportcard.com/report/github.com/francescoalemanno/cryptipass)
4+
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)
5+
[![GoDoc](https://godoc.org/github.com/francescoalemanno/cryptipass?status.svg)](https://pkg.go.dev/github.com/francescoalemanno/cryptipass)
6+
7+
**cryptipass** is a flexible, high-entropy passphrase generator that creates secure, pronounceable passwords using a probabilistic model. It's designed for security-conscious developers who need memorable yet strong passphrases.
8+
9+
---
410

511
## Features
612

7-
- **Cryptographically secure randomization**: Uses `crypto/rand` for generating random data to seed the passphrase generation process, ensuring the highest level of security.
8-
- **Customizable passphrase length**: The number of words in the passphrase can be controlled by the user.
9-
- **Entropy calculation**: Provides an exact evaluation of the total entropy for the generated passphrase, helping users understand the strength of their passphrase.
10-
- **Configurable word lengths**: Words within the passphrase can vary in length, ensuring better randomness and complexity.
13+
- **Pronounceable Passwords**: Generates words based on real-world token patterns, making them easy to remember.
14+
- **Highly Customizable**: Define your own word list or use pre-defined patterns like symbols, numbers, and mixed-case letters.
15+
- **Secure Randomness**: Uses cryptographic-grade randomness (`crypto/rand`) for generating passphrases.
16+
- **Entropy Analysis**: Built-in entropy calculations and certification to ensure high randomness and strength.
17+
- **Pattern-Based Generation**: Control password structure using customizable patterns (e.g., words, digits, symbols).
18+
19+
---
1120

1221
## Installation
1322

14-
To use the `cryptipass` package in your project, you need to install it using Go's package management:
23+
To install `cryptipass`, use `go get`:
1524

1625
```bash
1726
go get github.com/francescoalemanno/cryptipass
1827
```
1928

20-
Then import it in your Go files:
29+
Then, import it into your project:
2130

2231
```go
2332
import "github.com/francescoalemanno/cryptipass"
2433
```
2534

26-
## Usage
35+
NOTE: **We also have a [CLI](cmd/genpw) available for non-library uses.**
2736

28-
### Generate a Passphrase
37+
---
2938

30-
The primary function of the `cryptipass` package is to generate secure passphrases. You can generate a new passphrase using the `NewPassphrase` function. You can specify how many words you want in the passphrase, and the function returns the passphrase and its total entropy.
39+
## Quick Start
3140

32-
Example:
41+
Here's how to generate a passphrase using the default word style:
3342

3443
```go
3544
package main
3645

3746
import (
3847
"fmt"
39-
"cryptipass"
48+
"github.com/francescoalemanno/cryptipass"
4049
)
4150

4251
func main() {
43-
passphrase, entropy := cryptipass.NewPassphrase(5)
44-
fmt.Printf("Passphrase: %s\n", passphrase)
45-
fmt.Printf("Entropy: %.2f bits\n", entropy)
52+
// Create a new cryptipass generator
53+
gen := cryptipass.NewInstance()
54+
55+
// Generate a 4-word passphrase
56+
passphrase, entropy := gen.GenPassphrase(4)
57+
58+
fmt.Println("Passphrase:", passphrase) //e.g. netica.peroundl.opantmene.symnals
59+
fmt.Println("Entropy:", entropy)
4660
}
4761
```
4862

49-
### Example Output:
63+
Want more control over the pattern? Use `GenFromPattern`:
5064

65+
```go
66+
// Generate a password with pattern: Word-Number-Symbol
67+
pass, entropy := gen.GenFromPattern("w-d-s") // eg. opantmene-4-%
68+
fmt.Println("Generated Password:", pass)
5169
```
52-
Passphrase: jesside.flyperm.aunsis.dertsy
53-
Entropy: 97.63 bits
54-
```
5570

56-
### Word Generation
71+
Possible patterns are formed by combining:
72+
- 'w' lowercase word, 'W' for uppercase word.
73+
- 'c' a lowercase character, 'C' a uppercase character.
74+
- 's' symbol, 'd' digit.
75+
76+
other symbols are interpolated in the final password and to interpolate one of the reserved symbols use escaping with "\".
77+
78+
---
5779

58-
Internally, the package uses a series of functions to generate words of varying lengths. Each word contributes a certain amount of entropy, calculated during the generation process.
80+
## Custom Word Lists
5981

60-
- `GenMixWord()`: Generates a random word of mixed length, returning both the word and its entropy.
61-
- `GenWord(n int)`: Generates a word of exactly `n` characters.
62-
- `PickLength()`: Picks a random length for a word.
63-
- `PickNext()`: Generates the next part of a word based on the current string.
82+
You can customize the word style by creating a new instance from your own token set:
6483

65-
## Notes
84+
```go
85+
myTokens := []string{"alpha", "bravo", "charlie", "delta"}
86+
gen := cryptipass.NewCustomInstance(myTokens, 1) //instead of 1, try 2,3,4 to see the tradeoff between fidelity to the wordlist and entropy gain.
6687

67-
- The package seeds the random number generator with `crypto/rand`, making it cryptographically secure. In scenarios where cryptographic security is not necessary and faster execution is preferred, the package also provides an alternative (commented out) `PCG` random number generator.
68-
- The entropy provided in the output is a measure of how unpredictable the passphrase is. The higher the entropy, the more secure the passphrase is.
88+
pass, entropy := gen.GenPassphrase(3)
89+
fmt.Println("Custom Passphrase:", pass) //e.g. alphar.bravo.delta
90+
fmt.Println("Entropy:", entropy)
91+
```
6992

70-
## Contributing
93+
---
94+
95+
## Documentation
7196

72-
Contributions are welcome! If you encounter any issues or have feature suggestions, feel free to open an issue or a pull request on the GitHub repository.
97+
Full API documentation is available at [GoDoc](https://pkg.go.dev/github.com/francescoalemanno/cryptipass).
98+
99+
---
73100

74101
## License
75102

76-
This project is licensed under the MIT License.
103+
`cryptipass` is licensed under the MIT License. See [LICENSE](LICENSE) for details.
104+
105+
---
106+
107+
## Contributing
108+
109+
Contributions, issues, and feature requests are welcome! Feel free to check out [issues](https://github.com/francescoalemanno/cryptipass/issues) or open a pull request.
77110

78111
---
79112

80-
Happy coding and stay secure with Cryptipass!
113+
**cryptipass** – Secure, flexible, and pronounceable passphrases for your Go applications.

cmd/genpw/README.md

+62-53
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,104 @@
1-
# genpw - CryptiPass CLI
1+
# genpw
22

3-
`genpw` is a simple command-line interface (CLI) for generating high-entropy, pronounceable passphrases using the CryptiPass library. It allows users to specify the number of words in each passphrase and the number of passphrases to generate, making it easy to quickly create secure, human-friendly passwords directly from the terminal.
4-
5-
This tool is part of the [CryptiPass](https://github.com/francescoalemanno/cryptipass) project and resides in the `cmd/genpw` subdirectory.
3+
**genpw** is a command-line tool that generates secure, pronounceable passwords and passphrases using customizable patterns. Built on top of the `cryptipass` library, **genpw** provides flexible options for creating memorable, yet strong passphrases with high entropy, making it ideal for secure applications, authentication, and more.
64

75
## Features
86

9-
- **Generate Secure Passphrases**: Easily generate high-entropy, pronounceable passphrases with customizable length.
10-
- **Customizable Output**: Control the number of words per passphrase and how many passphrases you want to generate.
11-
- **Lightweight and Easy to Use**: Simple CLI flags for ease of use and quick password generation.
7+
- Generate secure, pronounceable passwords.
8+
- Customizable patterns for letters, numbers, symbols, and word formats.
9+
- Visual strength meter for each generated passphrase.
10+
- Cryptographic random number generator for secure randomness.
11+
- High entropy and randomness assurance.
12+
13+
---
1214

1315
## Installation
1416

15-
To install the `genpw` CLI, first ensure you have Go installed. Then run:
17+
To install **genpw**, use `go install`:
1618

1719
```bash
1820
go install github.com/francescoalemanno/cryptipass/cmd/genpw@latest
1921
```
2022

21-
This will install the `genpw` binary in your `$GOPATH/bin` directory.
23+
Ensure `$GOPATH/bin` is added to your `PATH` to run the command directly.
24+
25+
---
2226

2327
## Usage
2428

25-
Once installed, you can generate passphrases by running `genpw` with the following options:
29+
You can generate a set of passwords with the desired pattern using the following command:
2630

31+
```bash
32+
genpw -p [PATTERN] -n [NUMBER OF PASSWORDS]
2733
```
28-
Usage: genpw [flags]
2934

30-
Flags:
31-
-p uint
32-
number of passwords to generate (default 4)
33-
-w uint
34-
number of words per password (default 4)
35+
### Pattern Options
3536

36-
-c run entropy certification algorithm (for developers)
37-
```
37+
- **w**: lowercase word.
38+
- **W**: uppercase word.
39+
- **c**: lowercase character.
40+
- **C**: uppercase character.
41+
- **d**: digit.
42+
- **s**: symbol.
3843

39-
### Example Commands
44+
### Example
4045

41-
1. **Generate 4 passphrases with 4 words each** (default):
46+
Generate 6 passphrases using a pattern of three words (with one capitalized), a two-digit number, and two lowercase characters:
4247

4348
```bash
44-
genpw
49+
genpw -p "W.w.w.ddcc" -n 6
4550
```
4651

47-
This will output something like:
48-
49-
```
50-
ENTROPY | PASSPHRASE
51-
+++++++++++++++|++++++++++++++++++++++++++++++++
52-
65.57 | ammud.ruffl.ummi.shing
53-
82.76 | epavoi.hakeyer.bles.monfin
54-
82.91 | everap.gighte.clap.baselec
55-
85.93 | stash.laxor.surevida.dexqy
52+
Sample output:
53+
54+
```bash
55+
Passphrase Log10(Guesses) Log2Entropy Strength
56+
57+
Mortw.retainish.quater.66es 21.49 72.40 [===========.]
58+
Defamito.repeac.stateryb.91he 23.75 79.90 [============]
59+
Grazi.subsider.pravi.83de 20.14 67.92 [==========..]
60+
Alishin.dumpedial.prayingin.45po 23.85 80.23 [============]
61+
Atoryone.imputt.moodly.76op 19.66 66.32 [==========..]
62+
Hurred.buffyeare.uphonetin.97co 23.22 78.12 [============]
5663
```
5764

58-
2. **Generate 2 passphrases with 6 words each**:
65+
### Parameters
5966

60-
```bash
61-
genpw -w 6 -p 2
62-
```
67+
- **`-p`**: Define the pattern for password generation (default: `W.w.w`).
68+
- **`-n`**: Specify the number of passwords to generate (default: `6`).
6369

64-
The output might look like:
70+
---
6571

66-
```
67-
ENTROPY | PASSPHRASE
68-
+++++++++++++++|++++++++++++++++++++++++++++++++
69-
119.97 | tubse.stnew.critedi.priu.bugger.crokess
70-
136.65 | stedin.overjan.gifteto.overepr.comiz.unrupee
71-
```
72+
## Password Strength
7273

73-
### Entropy Considerations
74+
Each generated passphrase includes a strength meter, represented by a bar between `0` and `12` characters, where `=` indicates strength and `.` indicates relative weakness.
7475

75-
Each word generated by CryptiPass has on average more than 21 bits of entropy. For example:
76-
- A 4-word passphrase has roughly 84 bits of entropy.
77-
- A 6-word passphrase has approximately 126 bits of entropy.
76+
- **Log10(Guesses)**: The estimated number of guesses (in log10 scale) required to crack the password.
77+
- **Log2Entropy**: The entropy (in bits) of the passphrase, reflecting its unpredictability.
7878

79-
This makes the passphrases highly secure, even against brute-force attacks.
79+
---
8080

81-
## Certification (Debug/Development Mode)
81+
## Customization
8282

83-
For debugging or testing purposes, the `certify` function can be used to track the entropy of generated words over large runs, it has to be used if another vocabulary is distilled into random rules for the software.
83+
You can define your own patterns to create passphrases tailored to your security and usability needs. Patterns can be mixed and matched to create combinations of words, digits, symbols, and characters, offering high flexibility.
8484

85-
## Contributing
85+
Examples:
8686

87-
Contributions are welcome! Please open an issue or submit a pull request via the [main repository](https://github.com/francescoalemanno/cryptipass).
87+
- **Pattern**: `"wW.d.s"`
88+
- Output: lowercase word, uppercase word, digit, and symbol.
89+
90+
```bash
91+
genpw -p "wW.d.s" -n 4
92+
```
93+
94+
---
8895

8996
## License
9097

91-
This tool is open-source and licensed under the MIT License.
98+
**genpw** is licensed under the MIT License. See the [LICENSE](LICENSE) file for more information.
9299

93-
## Contact
100+
---
101+
102+
## Contributing
94103

95-
For any questions, issues, or suggestions, please visit the [issue tracker](https://github.com/francescoalemanno/cryptipass/issues) on GitHub.
104+
Contributions are welcome! Feel free to open an issue or submit a pull request for bug fixes, new features, or improvements.

0 commit comments

Comments
 (0)