Argon2id

用于 Go 的 Argon2id 密码散列和验证。『Argon2id password hashing and verification for Go』

  • 所有者: alexedwards/argon2id
  • 平台: Linux,Mac,Windows
  • 许可证: MIT License
  • 分类:
  • 主题:
  • 喜欢:
    0
      比较:

Github星跟踪图

Argon2id

This package provides a convenience wrapper around Go's argon2 implementation, making it simpler to securely hash and verify passwords using Argon2.

It enforces use of the Argon2id algorithm variant and cryptographically-secure random salts.

Usage

package main

import (
	"log"

	"github.com/alexedwards/argon2id"
)

func main() {
	// CreateHash returns a Argon2id hash of a plain-text password using the
	// provided algorithm parameters. The returned hash follows the format used
	// by the Argon2 reference C implementation and looks like this:
	// $argon2id$v=19$m=65536,t=3,p=2$c29tZXNhbHQ$RdescudvJCsgt3ub+b+dWRWJTmaaJObG
	hash, err := argon2id.CreateHash("pa$$word", argon2id.DefaultParams)
	if err != nil {
		log.Fatal(err)
	}

	// ComparePasswordAndHash performs a constant-time comparison between a
	// plain-text password and Argon2id hash, using the parameters and salt
	// contained in the hash. It returns true if they match, otherwise it returns
	// false.
	match, err := argon2id.ComparePasswordAndHash("pa$$word", hash)
	if err != nil {
		log.Fatal(err)
	}

	log.Printf("Match: %v", match)
}

Changing the Parameters

When creating a hash you can and should configure the parameters to be suitable for the environment that the code is running in. The parameters are:

  • Memory — The amount of memory used by the Argon2 algorithm (in kibibytes).
  • Iterations — The number of iterations (or passes) over the memory.
  • Parallelism — The number of threads (or lanes) used by the algorithm.
  • Salt length — Length of the random salt. 16 bytes is recommended for password hashing.
  • Key length — Length of the generated key (or password hash). 16 bytes or more is recommended.

The Memory and Iterations parameters control the computational cost of hashing the password. The higher these figures are, the greater the cost of generating the hash and the longer the runtime. It also follows that the greater the cost will be for any attacker trying to guess the password.

If the code is running on a machine with multiple cores, then you can decrease the runtime without reducing the cost by increasing the Parallelism parameter. This controls the number of threads that the work is spread across. Important note: Changing the value of the Parallelism parameter changes the hash output.

params := &argon2id.Params{
	Memory:      128 * 1024,
	Iterations:  4,
	Parallelism: 4,
	SaltLength:  16,
	KeyLength:   32,
}


hash, err := argon2id.CreateHash("pa$$word", params)
if err != nil {
	log.Fatal(err)
}

For guidance and an outline process for choosing appropriate parameters see https://tools.ietf.org/html/draft-irtf-cfrg-argon2-04#section-4.

主要指标

概览
名称与所有者alexedwards/argon2id
主编程语言Go
编程语言 (语言数: 1)
平台
许可证MIT License
所有者活动
创建于2018-12-12 16:47:36
推送于2023-12-05 22:03:52
最后一次提交2023-11-13 22:13:58
发布数1
最新版本名称v1.0.0 (发布于 2023-10-21 18:59:45)
第一版名称v1.0.0 (发布于 2023-10-21 18:59:45)
用户参与
星数520
关注者数9
派生数51
提交数32
已启用问题?
问题数16
打开的问题数3
拉请求数5
打开的拉请求数6
关闭的拉请求数5
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?