scrypt

package
Version: v1.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: 0

README

PHC Crypto - Scrypt

Go Reference

According to Wikipedia:

scrypt (pronounced "ess crypt") is a password-based key derivation function created by Colin Percival, originally for the Tarsnap online backup service. The algorithm was specifically designed to make it costly to perform large-scale custom hardware attacks by requiring large amounts of memory. In 2016, the scrypt algorithm was published by IETF as RFC 7914. A simplified version of scrypt is used as a proof-of-work scheme by a number of cryptocurrencies, first implemented by an anonymous programmer called ArtForz in Tenebrix and followed by Fairbrix and Litecoin soon after.

Configuration options

Key Type Default Notes
Cost int 32768 Iterations count (affects memory and CPU usage)
Rounds int 8 Block size (affects memory and CPU usage)
Parallelism int 1 Parallelism factor (threads to run in parallel - affects the memory, CPU usage).
KeyLen int 32 How many bytes to generate as output.
SaltLen int 16 Salt length in bytes

Usage with PHC Crypto

$ go get github.com/aldy505/phc-crypto
import (
  "fmt"
  "github.com/aldy505/phc-crypto"
)

func main() {
  crypto, err := phccrypto.Use(phccrypto.Scrypt, phccrypto.Config{
    Parallelism: 3,
  })
  if err != nil {
    fmt.Println(err)
  }

  hash, err := phccrypto.Hash("password")
  if err != nil {
    fmt.Println(err)
  }
  fmt.Println(hash) // $scrypt$v=0$p=3,ln=32768,r=8$64ecb15ec1aa81bc403a892efb2289ce$4fc8d3bc...

  verify, err := phccrypto.Verify(hash, "password")
  if err != nil {
    fmt.Println(err)
  }
  fmt.Println(verify) // true
}

Standalone usage

$ go get github.com/aldy505/phc-crypto/scrypt
import (
  "fmt"
  "github.com/aldy505/phc-crypto/scrypt"
)

func main() {

  hash, err := scrypt.Hash("password", scrypt.Config{
    Parallelism: 3,
  })
  if err != nil {
    fmt.Println(err)
  }
  fmt.Println(hash) // $scrypt$v=0$p=3,ln=32768,r=8$64ecb15ec1aa81bc403a892efb2289ce$4fc8d3bc...

  verify, err := scrypt.Verify(hash, "password")
  if err != nil {
    fmt.Println(err)
  }
  fmt.Println(verify) // true
}

Documentation

Index

Constants

View Source
const (
	// KEYLEN is how many bytes to generate as output.
	KEYLEN = 32
	// COST is the iterations count (affects memory and CPU usage).
	// Minimum for interactive login: 16384.
	// Ideal for file encryption: 1048576.
	COST = 32768
	// ROUNDS is the block size (affects memory and CPU usage).
	ROUNDS = 8
	// PARALLELISM is the parallelism factor (threads to run in parallel - affects the memory, CPU usage).
	PARALLELISM = 1
	// SALT_LENGTH is the default salth length in bytes.
	SALT_LENGTH = 16
)

Variables

This section is empty.

Functions

func Hash

func Hash(plain string, config Config) (string, error)

Hash creates a PHC-formatted hash with config provided

func Verify

func Verify(hash string, plain string) (bool, error)

Verify checks the hash if it's equal (by an algorithm) to plain text provided.

Types

type Config

type Config struct {
	Cost        int
	Rounds      int
	Parallelism int
	KeyLen      int
	SaltLen     int
}

Config initialize the config require to create a hash function

Source Files

Jump to

Keyboard shortcuts

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