scrypt

package
v0.0.0-...-84afe4b Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2017 License: BSD-3-Clause Imports: 6 Imported by: 0

README

Usage

package main

import (
	"fmt"
	"log"

	"github.com/nbari/crypto/scrypt"
)

func main() {
	key, err := scrypt.Create("The quick brown fox jumps over the lazy dog", 64)
	if err != nil {
		log.Fatal(err)
	}

	ok, err := scrypt.Verify("The quick brown fox jumps over the lazy dog", key)
	if err != nil {
		log.Fatal(err)
	}

	if !ok {
		log.Fatal("Could not verify...")
		return
	}
}

Implementation Details

The scrypt call is invoked with these params:

N = 16384
r = 8
p = 1

The salt is randomly generated from the crypto/rand library which generates a cryptographically secure pseudorandom number.

The key returned is of this format:

array index starts from left.
<---keyLen---><---16---><--4--><--4--><--4-->
   password      salt      N      r      p

Based on https://github.com/agnivade/easy-scrypt/ just removing the SHA-256 hash.

Documentation

Index

Constants

View Source
const (
	N = 1 << 14
)

The recommended parameters for interactive logins as of 2009 are N=16384, r=8, p=1.

Variables

This section is empty.

Functions

func Create

func Create(password string, keyLen int) ([]byte, error)

Create derives a key from the password+pepper, salt, and cost parameters, returning a byte slice of length keyLen that can be used as cryptographic key.

pepper is taken from environment var SCRYPT_PEPPER

output format <---keylen---><----16----><--4--><--4--><--4-->

pass+pepper     salt       N      r      p

func Verify

func Verify(password string, dk []byte) (bool, error)

Verify compare password and derivated key

Types

This section is empty.

Jump to

Keyboard shortcuts

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