2 balloon -- Balloon password hashing function
3 Copyright (C) 2016-2019 Sergey Matveev <stargrave@stargrave.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 the Free Software Foundation, version 3 of the License.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with this program. If not, see
16 <http://www.gnu.org/licenses/>.
31 "go.cypherpunks.ru/balloon"
35 s := flag.Int("s", 1<<16, "Space cost, number of hash-sized blocks")
36 t := flag.Int("t", 3, "Time cost, rounds")
37 p := flag.Int("p", 1, "Number of threads")
38 saltHex := flag.String("salt", "", "Salt, hexadecimal, optional")
39 passwd := flag.String("passwd", "", "Password")
41 fmt.Fprintf(os.Stderr, "balloon -- Strengthen password with Balloon+SHA512\n\n")
47 if len(*saltHex) == 0 {
48 salt = make([]byte, 8)
49 _, err = io.ReadFull(rand.Reader, salt)
51 salt, err = hex.DecodeString(*saltHex)
56 fmt.Println("Salt:", hex.EncodeToString(salt))
57 h := balloon.H(sha512.New, []byte(*passwd), salt, *s, *t, *p)
58 fmt.Println("Hash:", hex.EncodeToString(h))
60 "Encoded: $balloon$h=sha512,s=%d,t=%d,p=%d$%s$%s\n",
62 base64.RawStdEncoding.EncodeToString(salt),
63 base64.RawStdEncoding.EncodeToString(h),