package kdbx import ( "encoding/hex" "testing" ) // RFC 9106 section 5: p=4, T=32, m=32, t=3, v=0x13, with a secret key and // associated data. func TestArgon2RFC9106Vectors(t *testing.T) { password := repeat(0x01, 32) salt := repeat(0x02, 16) secret := repeat(0x03, 8) assoc := repeat(0x04, 12) for _, tc := range []struct { name string variant int want string }{ {"argon2d", argon2d, "512b391b6f1162975371d3091973429" + "4f868e3be3984f3c1a13a4db9fabe4acb"}, {"argon2i", argon2i, "c814d9d1dc7f37aa13f0d77f2494bda1" + "c8de6b016dd388d29952a4c4672b6ce8"}, {"argon2id", argon2id, "0d640df58d78766c08c037a34a8b53c9" + "d01ef0452d75b65eb52520e96b01e659"}, } { got, err := argon2Full(password, salt, secret, assoc, 3, 32, 4, 32, tc.variant) if err != nil { t.Fatalf("%s: %v", tc.name, err) } if hex.EncodeToString(got) != tc.want { t.Errorf("%s =\n%x\nwant\n%s", tc.name, got, tc.want) } } } func TestArgon2RefusesAbsurdMemory(t *testing.T) { if _, err := argon2Key([]byte("x"), repeat(0, 16), 1, argon2MaxMemory+1, 1, 32, argon2d); err == nil { t.Fatal("a file asking for unbounded memory was accepted") } } func repeat(b byte, n int) []byte { out := make([]byte, n) for i := range out { out[i] = b } return out }