]> Cypherpunks.ru repositories - balloon.git/blob - cmd/balloon/main.go
-help mentions SHA512 hash
[balloon.git] / cmd / balloon / main.go
1 /*
2 balloon -- Balloon password hashing function
3 Copyright (C) 2016-2019 Sergey Matveev <stargrave@stargrave.org>
4
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.
8
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.
13
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/>.
17 */
18
19 package main
20
21 import (
22         "crypto/rand"
23         "crypto/sha512"
24         "encoding/hex"
25         "flag"
26         "fmt"
27         "io"
28         "os"
29
30         "go.cypherpunks.ru/balloon"
31 )
32
33 func main() {
34         s := flag.Int("s", 1<<18, "Space cost, number of hash-sized blocks")
35         t := flag.Int("t", 2, "Time cost, rounds")
36         p := flag.Int("p", 4, "Number of threads")
37         saltHex := flag.String("salt", "", "Salt, hexadecimal, optional")
38         passwd := flag.String("passwd", "", "Password")
39         flag.Usage = func() {
40                 fmt.Fprintf(os.Stderr, "balloon -- Strengthen password with Balloon+SHA512\n\n")
41                 flag.PrintDefaults()
42         }
43         flag.Parse()
44         var salt []byte
45         var err error
46         if len(*saltHex) == 0 {
47                 salt = make([]byte, 8)
48                 _, err = io.ReadFull(rand.Reader, salt)
49         } else {
50                 salt, err = hex.DecodeString(*saltHex)
51         }
52         if err != nil {
53                 panic(err)
54         }
55         fmt.Println(hex.EncodeToString(balloon.H(sha512.New, []byte(*passwd), salt, *s, *t, *p)))
56 }