2 NNCP -- Node to Node copy, utilities for store-and-forward data exchange
3 Copyright (C) 2016-2023 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 General Public License as published by
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 General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 // Calculate MTH hash of the file
31 "go.cypherpunks.ru/nncp/v8"
35 fmt.Fprint(os.Stderr, "nncp-hash -- calculate MTH hash of the file\n\n")
36 fmt.Fprintf(os.Stderr, "Usage: %s [-file ...] [-seek X] [-debug] [-progress] [options]\nOptions:\n", os.Args[0])
42 fn = flag.String("file", "", "Read the file instead of stdin")
43 seek = flag.Uint64("seek", 0, "Seek the file, hash, rewind, hash remaining")
44 forceFat = flag.Bool("force-fat", false, "Force MTHFat implementation usage")
45 showPrgrs = flag.Bool("progress", false, "Progress showing")
46 debug = flag.Bool("debug", false, "Print MTH steps calculations")
47 version = flag.Bool("version", false, "Print version information")
48 warranty = flag.Bool("warranty", false, "Print warranty information")
50 log.SetFlags(log.Lshortfile)
54 fmt.Println(nncp.Warranty)
58 fmt.Println(nncp.VersionGet())
68 fd, err = os.Open(*fn)
80 fmt.Println("Leaf BLAKE3 key:", hex.EncodeToString(nncp.MTHLeafKey[:]))
81 fmt.Println("Node BLAKE3 key:", hex.EncodeToString(nncp.MTHNodeKey[:]))
84 var debugger sync.WaitGroup
85 startDebug := func(events chan nncp.MTHEvent) {
88 for e := range events {
89 fmt.Println(e.String())
94 copier := func(w io.Writer) error {
95 _, err := nncp.CopyProgressed(
96 w, bufio.NewReaderSize(fd, nncp.MTHBlockSize), "hash",
97 nncp.LEs{{K: "Pkt", V: *fn}, {K: "FullSize", V: size - int64(*seek)}},
105 mth := nncp.MTHFatNew()
107 startDebug(mth.Events())
110 if err = copier(mth); err != nil {
115 mth := nncp.MTHSeqNew(size, int64(*seek))
117 startDebug(mth.Events())
121 log.Fatalln("-file is required with -seek")
123 if _, err = fd.Seek(int64(*seek), io.SeekStart); err != nil {
127 if err = copier(mth); err != nil {
131 if _, err = fd.Seek(0, io.SeekStart); err != nil {
134 if _, err = mth.PreaddFrom(
135 bufio.NewReaderSize(fd, nncp.MTHBlockSize),
144 fmt.Println(hex.EncodeToString(sum))