1 // balloon -- Balloon password hashing function
2 // Copyright (C) 2016-2024 Sergey Matveev <stargrave@stargrave.org>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Lesser General Public License as
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 Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this program. If not, see
15 // <http://www.gnu.org/licenses/>.
29 "go.cypherpunks.ru/balloon/v2"
33 s := flag.Int("s", 1<<16, "Space cost, number of hash-sized blocks")
34 t := flag.Int("t", 3, "Time cost, rounds")
35 p := flag.Int("p", 1, "Number of threads")
36 saltHex := flag.String("salt", "", "Salt, hexadecimal, optional")
37 passwd := flag.String("passwd", "", "Password")
39 fmt.Fprintf(os.Stderr, "balloon -- Strengthen password with Balloon+SHA512\n\n")
45 if len(*saltHex) == 0 {
46 salt = make([]byte, 8)
47 _, err = io.ReadFull(rand.Reader, salt)
49 salt, err = hex.DecodeString(*saltHex)
54 fmt.Println("Salt:", hex.EncodeToString(salt))
55 h := balloon.H(sha512.New, []byte(*passwd), salt, *s, *t, *p)
56 fmt.Println("Hash:", hex.EncodeToString(h))
58 "Encoded: $balloon$h=sha512,s=%d,t=%d,p=%d$%s$%s\n",
60 base64.RawStdEncoding.EncodeToString(salt),
61 base64.RawStdEncoding.EncodeToString(h),