Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/wranders/go-argon2

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/wranders/go-argon2

  • v0.1.0
  • Source
  • Go
  • Socket score

Version published
Created
Source

go-argon2

  • Install
  • What is go-argon2 and how do I use it
  • Interface
  • Configuration
  • License

Install

go get github.com/wranders/go-argon2

What is go-argon2 and how do I use it

This package is a interface for the argon2 key derivation function using golang.org/x/crypto/argon2, aiming to provide the simplest interface.

The Hasher is what creates password hashes and is configured directly or generated from a comma-separated key-value string (perfect for storage in configuration files).

The Matches function generates parameters from the provided hash, so the Hasher is not needed.

package main

import "github.com/wranders/go-argon2"

var hasher *argon2.Hasher

func main() {
    hasherSettings := "f=argon2id,s=16,k=32,m=65536,t=3,p=2"
    hasher, _ := argon2.NewHasherFromString(hasherSettings)
}

func HashPassword(password string) (string, error) {
    return hasher.Create(password)
}

func PaswordMatches(password, hash string) (bool, error) {
    return argon2.Matches(password, hash)
}

And that's it!

If you prefer to configure the Hasher directly:

var hasher *argon2.Hasher

import "github.com/wranders/go-argon2"

func main() {
    hasher = &argon2.Hasher{
        Form:        argon2.FormID,
        SaltLength:  16,
        KeyLength:   32,
        Memory:      65536,
        Iterations:  3,
        Parallelism: 2,
    }
}

func HashPassword(password string) (string, error) {
    return hasher.Create(password)
}

func PaswordMatches(password, hash string) (bool, error) {
    return argon2.Matches(password, hash)
}

Interface

const (
    FormI Form = iota + 1   //argon2i
    FormID                  //argon2id
)

type Form int

type Hasher struct {
    Form            Form
    Iterations      uint32
    KeyLength       uint32
    Memory          uint32
    Parallelism     uint8
    SaltLength      uint32
}

func Matches(string, string) (bool, error) {}
func NewHasherFromString(string) (*Hasher, error) {}
func (*Hasher) Create(string) (string, error) {}
//Errors
type ErrIncompatibleVersion struct {}
type ErrInvalidForm struct{}
type ErrInvalidHash struct{}
type ErrInvalidHasherConfiguration struct{}
type ErrUnknownSetting struct {}
type ErrUnsupportedExpr struct {}

Configuration

Creating a Hasher from a settings string is simple:

KeyValueMeaning
fstringForm (argon2i or argon2id) (argon2d unsupported)
suint32Salt Length (bytes)
kuint32Key Length (bytes)
muint32 or ExpressionMemory (kibibytes)
tuint32# Iterations over memory
puint8Parallelism (number of threads)
f=[string],s=[uint32],k=[uint32],m=[uint32|expr],t=[uint32],p=[uint8]

Note: Keys can be in any order, as long as they're all there

Memory can be any unsigned 32-bit number (0 - 4294967295), but expressions must evaluate between that range. The upper limit would use just under 550 GB of memory, to keep things in perspective.

+, -, *, /, (, ), and space are the only valid non-numeric characters in memory expressions.

f=argon2i,s=16,k=32,m=64*1024,t=3,p=2

f=argon2i,s=16,k=32,m=((64*1024) + (20-10))/2,t=3,p=2

Both are valid for use with NewHasherFromString. Expressions remove the need to pre-calculate kibibyte values.


License

Copyright © 2020 W Anders

Licensed under MIT License

FAQs

Package last updated on 28 Feb 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc