mnemonics

package module
v0.0.0-...-7b01a64 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2017 License: MIT Imports: 5 Imported by: 8

README

entropy-mnemonics

Build Status Documentation

mnemonics is a golang package that converts byte slices into human-friendly phrases. The primary purpose is to assist with the generation of cryptographically secure passwords. The threshold for a cryptographically secure password is between 128 and 256 bits, which when converted to base64 is 22-43 random characters. Random characters are both difficult to remember and subject to error when spoken or written down; slurring or sloppy handwriting can make it difficult to recover a password.

These considerations may seem strange to those who use password managers; why write down the password at all? The answer is: healthy paranoia. Retaining a physical copy of a password protects the user from disk failure and malware.

mnemonics solves these problems by converting byte slices into human-intelligible phrases. Take the following 128 bit example:

Hex:      a26a4821e36c7f7dccaa5484c080cefa
Base64:   ompIIeNsf33MqlSEwIDO+g==
Mnemonic: austere sniff aching hiding pact damp focus tacit timber pram left wonders

Though more verbose, the mnemonic phrase is less prone to human transcription errors.

The words are chosen from a dictionary of size 1626, such that a 12-word phrase corresponds to almost exactly 128 bits of entropy. Note that only the first few characters of each word need be unique; for the English dictionary, 3 characters are sufficient. This means that passphrases can be altered to make them more understandable or more easily memorized. For example, the phrase "austere sniff aching" could be changed to "austere sniff achoo" and the phrase would still decode correctly.

Full UTF-8 support is available for dictionaries, including input normalization for inputs with canonical equivalence.

Supported Dictionaries
  • English (prefix size: 3)
  • German (prefix size: 4)
  • Japanese (prefix size: 3)

Documentation

Overview

Package mnemonics is a package that converts []byte's into human-friendly phrases, using common words pulled from a dictionary. The dictionary size is 1626, and multiple languages are supported. Each dictionary supports modified phrases. Only the first few characters of each word are important. These characters form a unique prefix. For example, in the English dictionary, the unique prefix len (EnglishUniquePrefixLen) is 3, which means the word 'abbey' could be replaced with the word 'abbot', and the program would still run as expected.

The primary purpose of this library is creating human-friendly cryptographically secure passwords. A cryptographically secure password needs to contain between 128 and 256 bits of entropy. Humans are typically incapable of generating sufficiently secure passwords without a random number generator, and 256-bit random numbers tend to difficult to memorize and even to write down (a single mistake in the writing, or even a single somewhat sloppy character can render the backup useless).

By using a small set of common words instead of random numbers, copying errors are more easily spotted and memorization is also easier, without sacrificing password strength.

The mnemonics package does not have any functions for actually generating entropy, it just converts existing entropy into human-friendly phrases.

Index

Constants

View Source
const (
	// DictionarySize specifies the size of the dictionaries that are used by
	// the mnemonics package. All dictionaries are the same length so that the
	// same []byte can be encoded into multiple languages and all results will
	// resemble eachother.
	DictionarySize = 1626
)

Variables

This section is empty.

Functions

func FromPhrase

func FromPhrase(p Phrase, did DictionaryID) ([]byte, error)

FromPhrase converts an input phrase back to the original []byte.

func FromString

func FromString(str string, did DictionaryID) ([]byte, error)

FromString converts an input string into a phrase, and then calls 'FromPhrase'.

Types

type Dictionary

type Dictionary [DictionarySize]string

Dictionary is a DictionarySize list of words which can be used to create human-friendly entropy.

type DictionaryID

type DictionaryID string

DictionaryID is a type-safe identifier that indicates which dictionary should be used.

const (
	// English is an id pointing to the standard password dictionary for
	// english users.
	English DictionaryID = "english"

	// EnglishUniquePrefixLen indicates the number of letters needed to achieve
	// unique prefixes throughout the english dictionary. No two words in the
	// dictionary have the same prefix of len EnglishUniquePrefixLen.
	EnglishUniquePrefixLen = 3
)
const (
	// German is an id pointing to the standard password dictionary for german
	// users.
	German DictionaryID = "german"

	// GermanUniquePrefixLen indicates the number of letters needed to achieve
	// unique prefixes throughout the german dictionary. No two words in the
	// dictionary have the same prefix of len GermanUniquePrefixLen.
	GermanUniquePrefixLen = 4
)
const (
	// Japanese is an id pointing to the standard password dictionary for
	// Japanese users.
	Japanese DictionaryID = "japanese"

	// JapaneseUniquePrefixLen indicates the number of letters needed to
	// achieve unique prefixes throughout the Japanese dictionary. No two
	// words in the dictionary have the same prefix of len
	// JapaneseUniquePrefixLen.
	JapaneseUniquePrefixLen = 3
)

type Phrase

type Phrase []string

Phrase is the human readable version of a random []byte. Most typically, a phrase is displayed to the user using the String method.

func ToPhrase

func ToPhrase(entropy []byte, did DictionaryID) (Phrase, error)

ToPhrase converts an input []byte to a human-friendly phrase. The conversion is reversible.

func (Phrase) String

func (p Phrase) String() string

String combines a phrase into a single string by concatenating the individual words with space separation.

Jump to

Keyboard shortcuts

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