Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
go-common
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ai3
go-common
Commits
b4364e84
Commit
b4364e84
authored
5 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
Add Argon2 benchmarks
parent
679daf44
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pwhash/password.go
+21
-0
21 additions, 0 deletions
pwhash/password.go
pwhash/password_test.go
+35
-1
35 additions, 1 deletion
pwhash/password_test.go
with
56 additions
and
1 deletion
pwhash/password.go
+
21
−
0
View file @
b4364e84
// Package pwhash provides a simple interface to hashed passwords with
// support for multiple hashing algorithms.
//
// The format is the well-known dollar-separated field string,
// extended with optional algorithm-specific parameters:
//
// $id[$params...]$salt$encrypted
//
// We extend 'id' beyond the values supported by the libc crypt(3)
// function with the following hashing algorithms:
//
// Scrypt (id '$s$'), in which case the parameters are N, R and P.
//
// Argon2 (id '$a2$'), with parameters time, memory and threads. To
// tune Argon2 parameters, you can run the benchmarks in this package:
// the parameterized benchmarks are named with
// time/memory(MB)/threads. For nicer results:
//
// go test -bench=Argon2 -run=none . 2>&1 | \
// awk '/^Bench/ {ops=1000000000 / $3; print $1 " " ops " ops/sec"}'
//
package
pwhash
import
(
...
...
This diff is collapsed.
Click to expand it.
pwhash/password_test.go
+
35
−
1
View file @
b4364e84
package
pwhash
import
"testing"
import
(
"fmt"
"testing"
)
func
TestArgon2
(
t
*
testing
.
T
)
{
testImpl
(
t
,
NewArgon2
())
...
...
@@ -57,3 +60,34 @@ func testImpl(t *testing.T, h PasswordHash) {
}
}
}
func
BenchmarkArgon2
(
b
*
testing
.
B
)
{
var
testParams
[]
argon2Params
for
iTime
:=
1
;
iTime
<=
5
;
iTime
++
{
for
iThreads
:=
1
;
iThreads
<=
8
;
iThreads
*=
2
{
for
iMem
:=
1
;
iMem
<=
16
;
iMem
*=
2
{
testParams
=
append
(
testParams
,
argon2Params
{
Time
:
uint32
(
iTime
),
Memory
:
uint32
(
iMem
*
1024
),
Threads
:
uint8
(
iThreads
),
})
}
}
}
goodPw
:=
"good password"
badPw
:=
"definitely not the good password"
for
_
,
tp
:=
range
testParams
{
name
:=
fmt
.
Sprintf
(
"%d/%d/%d"
,
tp
.
Time
,
tp
.
Memory
,
tp
.
Threads
)
b
.
Run
(
name
,
func
(
b
*
testing
.
B
)
{
h
:=
NewArgon2WithParams
(
tp
.
Time
,
tp
.
Memory
,
tp
.
Threads
)
encPw
:=
h
.
Encrypt
(
goodPw
)
b
.
ResetTimer
()
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
h
.
ComparePassword
(
encPw
,
badPw
)
// nolint
}
})
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment