Crates.io | chbs |
lib.rs | chbs |
version | 0.1.1 |
source | src |
created_at | 2018-08-01 22:46:05.657008 |
updated_at | 2022-07-20 20:34:40.117883 |
description | A crate providing secure passphrase generation based on a wordlist |
homepage | https://gitlab.com/timvisee/chbs |
repository | https://gitlab.com/timvisee/chbs |
max_upload_size | |
id | 77019 |
size | 152,141 |
Note: this crate is still a work in progress, APIs might change until stabilisation
A secure, easy to use, configurable and extendable passphrase generation library based on a wordlist, generally known as diceware.
The name chbs
is short for the well known "correct horse battery staple"
password which originates from the XKCD comic shown above.
This library uses cryptographically secure randomization, and may be used for generating secret passphrases*.
std
)The following things need to be looked at before stabilization:
a
to 4
, o
to ()
)As the passphrase generation system in this crate is thoroughly abstracted it is important to understand how the concepts used in this crate work.
Here is what is required for passphrase generation:
Scheme
defines how a passphrase is generated. Passphrases are only
generated through a scheme.Scheme
contains components which represents how the passphrase is built up
and styled. Four kinds of components exist, defining the passphrase generation
steps. For some kinds one must be defined,
for other kinds any number is fine:
WordSetProvider
(1
required): provides a list of words to use in
a passphrase.WordStyler
(>=0
required): styles passphrase words, for example, to
capitalize.PhraseBuilder
(1
required): builds a phrase from a set of passphrase
words.PhraseStyler
(>=0
required): styles a whole passphrase.Things to understand:
The usual steps for generating a passphrase:
BasicConfig
.passphrase()
helper method may be used to generate a passphrase
with zero configuration for ease of use.See, it isn't too difficult, but allows great extensibility. You probably won't
use most of what this crate provides.
Take a look at BasicConfig
to see how to configure your first passphrase
generator.
Additional good-to-know things:
WordList
struct to hold a static wordlist, that may
use a built-in wordlist or loads a wordlist from a specified file.WordSampler
may be constructed based on a WordList
to allow randomized
word sampling in an uniform manner. Such a sampler is usually what is used as
word provider in a configuration struct.Here are some basic examples on how to use this crate.
Add chbs
as dependency in your Cargo.toml
first:
[dependencies]
chbs = "0.0.8"
Generate a passphrase with zero configuration using a helper function applying library defaults (passphrase.rs):
extern crate chbs;
use chbs::passphrase;
println!("Passphrase: {:?}", passphrase());
Run it using cargo run --example passphrase
.
Generating a passphrase with configuration is recommended, here is a basic
example (passphrase_config.rs
):
extern crate chbs;
use chbs::{config::BasicConfig, prelude::*, probability::Probability};
// Build a custom configuration to:
let mut config = BasicConfig::default();
config.words = 8;
config.separator = "-".into();
config.capitalize_first = Probability::from(0.33);
config.capitalize_words = Probability::half();
let mut scheme = config.to_scheme();
println!("Passphrase: {:?}", scheme.generate());
println!("Entropy: {:?}", scheme.entropy().bits());
Run it using cargo run --example passphrase_config
.
Use a word sampler to generate an infinite number of random words based on a wordlist (sampler.rs):
extern crate chbs;
use chbs::word::WordList;
let words = WordList::default();
let sampler = words.sampler().into_iter();
for word in sampler.take(8) {
println!("Sampled word: {:?}", word);
}
Run it using cargo run --example sampler
.
See all examples in the ./examples
directory.
This project is released under the MIT license. Check out the LICENSE file for more information.