1 // GoCheese -- Python private package repository and caching proxy
2 // Copyright (C) 2019-2024 Elena Balakhonova <balakhonova_e@riseup.net>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, version 3 of the License.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program. If not, see <http://www.gnu.org/licenses/>.
25 "golang.org/x/crypto/argon2"
28 type Argon2iAuthData struct {
37 func (ad Argon2iAuthData) Auth(password string) bool {
38 hashedPassword := argon2.Key(
44 uint32(len(ad.password)),
46 return bytes.Equal(hashedPassword, ad.password)
49 func parseArgon2i(params string) (Auther, error) {
50 var time, memory uint32
53 var saltAndPasswordUnitedB64 string
56 "v=%d$m=%d,t=%d,p=%d$%s",
61 &saltAndPasswordUnitedB64,
63 if n != 5 || err != nil {
64 return nil, fmt.Errorf("argon2i parameters %q have wrong format", params)
66 if version != argon2.Version {
67 return nil, errors.New("unsupported argon2i version")
69 saltAndPasswordSplittedB64 := strings.Split(saltAndPasswordUnitedB64, "$")
70 salt, err := base64.RawStdEncoding.DecodeString(saltAndPasswordSplittedB64[0])
72 return nil, errors.New("invalid salt format")
74 password, err := base64.RawStdEncoding.DecodeString(saltAndPasswordSplittedB64[1])
76 return nil, errors.New("invalid password format")
78 return Argon2iAuthData{