diceware

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 13, 2016 License: MIT Imports: 5 Imported by: 0

README

lukasma/diceware

Diceware passphrases in go. - by Lukas Malkmus

Build Status Coverage Status Go Report GoDoc Latest Release License


Table of Contents

  1. Introduction
  2. Features
  3. Installation
  4. Usage
  5. Contributing
  6. License
Introduction

Package diceware is a simple implementation of the diceware passphrase generation method. Instead of using the normal wordlists, it uses the computer-optimized diceword8k list. Furhtermore it utilizes go's crypto/rand library to generate true random passphrases.

Be advised, that the prefered way of generating diceware passphrases is to do it the old-school way by actually throwing real dices by hand. This is the only 100% secure way.

Features
  • Simple API
  • Only go standard library
  • Passphrases with choosable length
  • Diceware extras for stronger passphrases
  • Verify passphrases
Todo
  • Multiple word lists in multiple languages
  • Read word list from file/buffer (io.Reader)
Installation

The easiest way to install this package is to use go get:

go get -u -v github.com/LukasMa/diceware

Since this will pull the master branch, you should use a dependency manager like glide to be on the safe side and retrieve a tagged release.

Usage
Creation

Create a passphrase with default values (6 words, no extra):

p, err := diceware.NewPassphrase()
if err != nil {
    // ...
}
fmt.Println(p)

It is also possible to create a passphrase with more or less words. Please note that 6 words is a sensitiv default and less isn't recommended!

p, err := diceware.NewPassphrase(
    diceware.Words(7), // Passphrase with 7 words
)
if err != nil {
    // ...
}
fmt.Println(p)

Note! If you want to use less than 6 words, be sure to set the Validate option to false! Otherwise validation will fail!

Regeneration

All passphrases can be regenerated. This means the options you applied in the NewPassphrase() function are reused for the passphrase generation.

p.Regenerate()
fmt.Println(p)
Tips & Tricks
  • Passphrase implements the Stringer interface thus it can be passed to every function accepting this interface. For example fmt.Println().
  • The String() method isn't very "human friendly". Use the Humanize() method to print the passphrase with whitspace seperated words.
  • Passphrase strength can be improved by adding an extra. Do this by setting the Extra option: Extra(true)
Contributing

Please feel free to submit Pull Requests or Issues.

License

Copyright (c) 2016 Lukas Malkmus

Distributed under MIT License (The MIT License). See LICENSE for more information.

Documentation

Overview

Package diceware provides an implementation of the diceware passphrase generation method.

Index

Constants

View Source
const (
	// DefaultExtra is the default value for the extra character. An extra can
	// be added to a passphrase to increase security without adding another
	// word. It isn't required by default.
	DefaultExtra = false

	// DefaultWords is the default amount of words used to build a passphrase.
	// This is set to a sensitive default.
	// Ref: https://diceware.blogspot.de/2014/03/time-to-add-word.html
	DefaultWords = 6

	// DefaultValidate is the default value for the validation step.
	DefaultValidate = true

	// MinPhraseLength is the smallest amount of characters allowed in a
	// passphrase to pass the validation. Since generation is random, there is a
	// very small chance of getting a passphrase which has less than 17
	// characters in total which IS NOT considered save.
	// Ref: http://world.std.com/~reinhold/dicewarefaq.html#14characters
	MinPhraseLength = 17

	// MinWords is the required amount of words used to build a passphrase. This
	// values exists just for convenience and it IS NOT SAFE to use a one word
	// passphrase!
	MinWords = 1
)

Variables

View Source
var (
	// ErrInvalidWordCount is raised when the specified amount of words drops
	// below the MinWords constant.
	ErrInvalidWordCount = errors.New("The amount of words is invalid (drops below the value defined by MinWords)!")

	// ErrValidationFailed is raised when the generated passphrase doesn't met
	// the default security standards.
	ErrValidationFailed = errors.New("Invalid passphrase was generated! Use the Regenerate() method to trigger generation with the same settings.")
)

Functions

This section is empty.

Types

type Option

type Option func(p *Passphrase) error

An Option serves as a functional parameter which can be used to costumize the generation of the passphrase.

func Extra

func Extra(extra bool) Option

Extra is an Option that specifies whaether an extra will be added to the passphrase or not.

func Validate

func Validate(validate bool) Option

Validate is an Option that specifies whaether passphrase validation will be performed or not.

func Words

func Words(words int) Option

Words is an Option that defines the amount of words that should be picked for the new Passphrase.

type Passphrase

type Passphrase struct {
	// contains filtered or unexported fields
}

A Passphrase is a diceware passphrase. It is build from a handful of words that are randomly picked from a list of words. Ref: http://world.std.com/~reinhold/diceware.html

func NewPassphrase

func NewPassphrase(options ...Option) (*Passphrase, error)

NewPassphrase defines, generates, validates and returns a new diceware passphrase.

func (Passphrase) Humanize

func (p Passphrase) Humanize() string

Humanize will return a human readable string which has a whitspace between each word.

func (*Passphrase) Regenerate

func (p *Passphrase) Regenerate() error

Regenerate will generate the passphrase from scratch but keep the originally provided parameters.

func (Passphrase) String

func (p Passphrase) String() string

String implements the Stringer interface.

func (*Passphrase) Validate

func (p *Passphrase) Validate() bool

Validate verifies that the passphrase mets certain standards like a secure length and word count.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL