Documentation
¶
Overview ¶
Package password is a probably paranoid utility library for securly hashing and encrypting passwords based on the Dropbox method. This implementation uses Blake2b, Scrypt and XSalsa20-Poly1305 (via NaCl SecretBox) to create secure password hashes that are also encrypted using a master passphrase. If the master passphrase is lost you will lose access to all passwords encrypted with it so store is securely, my recommendation is that you store it as an environmental variable or in a config file to avoid storing it in source code.
Index ¶
- Variables
- func Benchmark(params ScryptParams) (seconds float64, err error)
- func GetHashVersion(ciphertext string) (version int, err error)
- func GetMasterVersion(ciphertext string) (version int, err error)
- func Hash(userpass, masterpass string, version int, ...) (pwHashOut string, err error)
- func UpdateMaster(newMaster, oldMaster string, newVersion int, ciphertext string, ...) (pwHashOut string, err error)
- func Verify(userpass, masterpass, ciphertext string) error
- type ScryptParams
Constants ¶
This section is empty.
Variables ¶
var ( // ErrCiphertextVer indicates version sub-string mismatch normally; ex. "secBoxv1" ErrCiphertextVer = errors.New("Nonmatched ciphertext version") // ErrCiphertextFormat indicates input is not in expected format ErrCiphertextFormat = errors.New("Ciphertext input format not as expected") // ErrInvalidVersionUpdate indicates new version given not oldVersion + 1 or greater ErrInvalidVersionUpdate = errors.New("Invalid new version int, new master passphrase version must be greater than previous") // ErrPassphraseHashMismatch indicates invalid passphrase for supplied ciphertext ErrPassphraseHashMismatch = errors.New("Passphrase hash does not match supplied ciphertext") // ErrPassphraseLength indicates supplied passphrase is not at least MinLength ErrPassphraseLength = errors.New("Passphrase must be at least MinLength") // ErrSecretBoxDecryptFail indicates SecretBox decryption could not be completed ErrSecretBoxDecryptFail = errors.New("SecretBox decryption failed") // ErrScryptParamN indicates ScryptParams:N out of acceptable range ErrScryptParamN = errors.New("Given Scrypt (N) cost factor out of acceptable range") // ErrScryptParamR indicates ScryptParams:r out of acceptable range ErrScryptParamR = errors.New("Given Scrypt (r) cost factor out of acceptable range") // ErrScryptParamP indicates ScryptParams:p out of acceptable range ErrScryptParamP = errors.New("Given Scrypt (p) cost factor out of acceptable range") )
var ( // MinLength changes the minimum passphrase and master passphrase length accepted MinLength = 8 // DefaultParams defines Scrypt Parameters DefaultParams = ScryptParams{N: 16384, R: 8, P: 1} )
Functions ¶
func Benchmark ¶
func Benchmark(params ScryptParams) (seconds float64, err error)
Benchmark takes ScryptParams and returns the number of seconds elapsed as a float64 and error
func GetHashVersion ¶
GetHashVersion takes ciphertext string and returns goSecretBoxPassword version as int and error.
func GetMasterVersion ¶
GetMasterVersion takes ciphertext string and returns master passphrase version as int and error.
func Hash ¶
func Hash(userpass, masterpass string, version int, userparams, masterparams ScryptParams) (pwHashOut string, err error)
Hash takes passphrase ,masterpassphrase as strings, version indicator as int, and userparams and masterparams as ScryptParams and returns up to 225 char ciphertext string and error - ex. password.Hash("password1234", "masterpassphrase", 0, ScryptParams{N: 32768, R: 16, P: 1}, DefaultParams)
func UpdateMaster ¶
func UpdateMaster(newMaster, oldMaster string, newVersion int, ciphertext string, masterparams ScryptParams) (pwHashOut string, err error)
UpdateMaster takes new master passphrase, old master passphrase as string, new version as int, cipertext as string, and new ScryptParams. It returns and updated hash output string and error.
Types ¶
type ScryptParams ¶
ScryptParams sets the Scrypt devivation parameters used for hashing
func GetParams ¶
func GetParams(ciphertext string) (userParams, masterParams ScryptParams, err error)
GetParams takes ciphertext string, returns user and master parameters and error. This may be useful for upgrading.