go_scrypt_kdf

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2021 License: MIT Imports: 9 Imported by: 5

README

go-scrypt-kdf

Build Status Go Report Card Go Reference

This package is a port of the scrypt-kdf nodejs library to Go.

Usage

package main

import (
    gsk "github.com/gryffyn/go-scrypt-kdf"
)

func main() {
    derivedKey, err := gsk.Kdf("password", gsk.DefaultParams)
    valid := gsk.Verify(derivedKey, "password") // true
    invalid := gsk.Verify(derivedKey, "not_password") // false
}

Format

Outputs a 96 byte []byte. Uses the Tarsnap format.

scrypt encrypted data format
----------------------------

offset	length
0	6	"scrypt"
6	1	scrypt data file version number (== 0)
7	1	log2(N) (must be between 1 and 63 inclusive)
8	4	r (big-endian integer; must satisfy r * p < 2^30)
12	4	p (big-endian integer; must satisfy r * p < 2^30)
16	32	salt
48	16	first 16 bytes of SHA256(bytes 0 .. 47)
64	32	HMAC-SHA256(bytes 0 .. 63)
96	X	data xor AES256-CTR key stream generated with nonce == 0
96+X	32	HMAC-SHA256(bytes 0 .. 96 + (X - 1))

License

Original repo license can be found here.

Licensed MIT, see LICENSE for details.

Documentation

Overview

Package go_scrypt_kdf implements the scrypt-kdf NPM package in Go.

Index

Constants

This section is empty.

Variables

View Source
var DefaultParams = Params{LogN: 15, R: 8, P: 1}

DefaultParams are a set of sane defaults for scrypt.

Functions

func Kdf

func Kdf(password []byte, params Params) ([]byte, error)

Kdf derives a key from password with the given parameters.

func Verify

func Verify(key, attempt []byte) (bool, error)

Verify checks the given key against an attempted password.

Types

type Params

type Params struct {
	LogN uint8
	R    uint32
	P    uint32
}

Params defines the parameters for the scrypt algorithm.

Jump to

Keyboard shortcuts

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