X-Git-Url: http://www.git.cypherpunks.ru/?p=balloon.git;a=blobdiff_plain;f=cmd%2Fballoon%2Fmain.go;h=ba3be01338e123aa63c689a7d23985954f732ae0;hp=7ba57af5b83d9b80bc878f6a4c395170efcc7a03;hb=cb214daf358024d6ceaaa314cfddf0e59003e79b;hpb=9bfd570d5e1ab019901595b8948b912cc559f1e2 diff --git a/cmd/balloon/main.go b/cmd/balloon/main.go index 7ba57af..ba3be01 100644 --- a/cmd/balloon/main.go +++ b/cmd/balloon/main.go @@ -1,10 +1,32 @@ +/* +balloon -- Balloon password hashing function +Copyright (C) 2016-2019 Sergey Matveev + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as +the Free Software Foundation, version 3 of the License. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this program. If not, see +. +*/ + package main import ( + "crypto/rand" "crypto/sha512" + "encoding/base64" "encoding/hex" "flag" "fmt" + "io" + "os" "go.cypherpunks.ru/balloon" ) @@ -13,12 +35,31 @@ func main() { s := flag.Int("s", 1<<18, "Space cost, number of hash-sized blocks") t := flag.Int("t", 2, "Time cost, rounds") p := flag.Int("p", 4, "Number of threads") - saltHex := flag.String("salt", "deadbabe", "Salt, hexadecimal") + saltHex := flag.String("salt", "", "Salt, hexadecimal, optional") passwd := flag.String("passwd", "", "Password") + flag.Usage = func() { + fmt.Fprintf(os.Stderr, "balloon -- Strengthen password with Balloon+SHA512\n\n") + flag.PrintDefaults() + } flag.Parse() - salt, err := hex.DecodeString(*saltHex) + var salt []byte + var err error + if len(*saltHex) == 0 { + salt = make([]byte, 8) + _, err = io.ReadFull(rand.Reader, salt) + } else { + salt, err = hex.DecodeString(*saltHex) + } if err != nil { panic(err) } - fmt.Println(hex.EncodeToString(balloon.H(sha512.New, []byte(*passwd), salt, *s, *t, *p))) + fmt.Println("Salt:", hex.EncodeToString(salt)) + h := balloon.H(sha512.New, []byte(*passwd), salt, *s, *t, *p) + fmt.Println("Hash:", hex.EncodeToString(h)) + fmt.Printf( + "Encoded: $balloon$h=sha512,s=%d,t=%d,p=%d$%s$%s\n", + *s, *t, *p, + base64.RawStdEncoding.EncodeToString(salt), + base64.RawStdEncoding.EncodeToString(h), + ) }