Реализовать защиту Lab7 и проверку отзыва worker

This commit is contained in:
R0flyan
2026-11-27 21:53:26 +03:00
parent 20afc2c790
commit 2fa513f56c
68 changed files with 6767 additions and 64 deletions
+43
View File
@@ -0,0 +1,43 @@
package main
import "testing"
func TestArgonProfiles(t *testing.T) {
for _, test := range []struct {
name, hash string
match, upgrade bool
}{
{"current", hashPassword("test-password"), true, false},
{"legacy", makePasswordHash("test-password", argonLegacy, 19*1024, 2), true, true},
{"other password", hashPassword("other-password"), false, false},
{"unsupported parameters", "$argon2id$v=19$m=999999999,t=10,p=50$abcd$efgh", false, false},
} {
t.Run(test.name, func(t *testing.T) {
match, upgrade := verifyPassword(test.hash, "test-password")
if match != test.match || upgrade != test.upgrade {
t.Fatalf("verify = (%v, %v), want (%v, %v)", match, upgrade, test.match, test.upgrade)
}
})
}
}
func BenchmarkArgonVerification(b *testing.B) {
for _, test := range []struct {
name, params string
memory, rounds uint32
}{
{"19MiB-2", argonLegacy, 19 * 1024, 2},
{"64MiB-3", argonCurrent, 64 * 1024, 3},
} {
b.Run(test.name, func(b *testing.B) {
hash := makePasswordHash("benchmark-password", test.params, test.memory, test.rounds)
b.ReportAllocs()
b.ResetTimer()
for range b.N {
if valid, _ := verifyPassword(hash, "benchmark-password"); !valid {
b.Fatal("benchmark hash rejected")
}
}
})
}
}