├── FORMAT.md ├── INSTALL.md ├── LICENSE ├── NOTICE ├── README.md ├── archive.go ├── archive ├── archive.go ├── archive_test.go ├── reader.go ├── verify.go └── writer.go ├── archive_test.go ├── args.go ├── binary ├── binary.go └── binary_test.go ├── bytesize.go ├── circle.yml ├── create.go ├── extract.go ├── filter.go ├── key.go ├── key_test.go ├── keygen.go ├── list.go ├── main.go └── vendor ├── github.com ├── codahale │ └── sss │ │ ├── LICENSE │ │ ├── README.md │ │ ├── gf256.go │ │ ├── gf256_test.go │ │ ├── polynomial.go │ │ ├── polynomial_test.go │ │ ├── sss.go │ │ └── sss_test.go ├── dchest │ └── blake2b │ │ ├── README │ │ ├── blake2b.go │ │ ├── blake2b_test.go │ │ └── block.go ├── jessevdk │ └── go-flags │ │ ├── LICENSE │ │ ├── README.md │ │ ├── arg.go │ │ ├── arg_test.go │ │ ├── assert_test.go │ │ ├── check_crosscompile.sh │ │ ├── closest.go │ │ ├── command.go │ │ ├── command_test.go │ │ ├── completion.go │ │ ├── completion_test.go │ │ ├── convert.go │ │ ├── convert_test.go │ │ ├── error.go │ │ ├── example_test.go │ │ ├── flags.go │ │ ├── group.go │ │ ├── group_test.go │ │ ├── help.go │ │ ├── help_test.go │ │ ├── ini.go │ │ ├── ini_test.go │ │ ├── long_test.go │ │ ├── man.go │ │ ├── marshal_test.go │ │ ├── multitag.go │ │ ├── option.go │ │ ├── options_test.go │ │ ├── optstyle_other.go │ │ ├── optstyle_windows.go │ │ ├── parser.go │ │ ├── parser_test.go │ │ ├── pointer_test.go │ │ ├── short_test.go │ │ ├── tag_test.go │ │ ├── termsize.go │ │ ├── termsize_linux.go │ │ ├── termsize_nosysioctl.go │ │ ├── termsize_other.go │ │ ├── termsize_unix.go │ │ └── unknown_test.go ├── klauspost │ ├── compress │ │ ├── LICENSE │ │ ├── README.md │ │ ├── flate │ │ │ ├── asm_test.go │ │ │ ├── copy.go │ │ │ ├── copy_test.go │ │ │ ├── crc32_amd64.go │ │ │ ├── crc32_amd64.s │ │ │ ├── crc32_noasm.go │ │ │ ├── deflate.go │ │ │ ├── deflate_test.go │ │ │ ├── fixedhuff.go │ │ │ ├── flate_test.go │ │ │ ├── gen.go │ │ │ ├── huffman_bit_writer.go │ │ │ ├── huffman_bit_writer_test.go │ │ │ ├── huffman_code.go │ │ │ ├── inflate.go │ │ │ ├── inflate_test.go │ │ │ ├── reader_test.go │ │ │ ├── reverse_bits.go │ │ │ ├── snappy.go │ │ │ ├── testdata │ │ │ │ ├── huffman-null-max.dyn.expect │ │ │ │ ├── huffman-null-max.dyn.expect-noinput │ │ │ │ ├── huffman-null-max.golden │ │ │ │ ├── huffman-null-max.in │ │ │ │ ├── huffman-null-max.wb.expect │ │ │ │ ├── huffman-null-max.wb.expect-noinput │ │ │ │ ├── huffman-pi.dyn.expect │ │ │ │ ├── huffman-pi.dyn.expect-noinput │ │ │ │ ├── huffman-pi.golden │ │ │ │ ├── huffman-pi.in │ │ │ │ ├── huffman-pi.wb.expect │ │ │ │ ├── huffman-pi.wb.expect-noinput │ │ │ │ ├── huffman-rand-1k.dyn.expect │ │ │ │ ├── huffman-rand-1k.dyn.expect-noinput │ │ │ │ ├── huffman-rand-1k.golden │ │ │ │ ├── huffman-rand-1k.in │ │ │ │ ├── huffman-rand-1k.wb.expect │ │ │ │ ├── huffman-rand-1k.wb.expect-noinput │ │ │ │ ├── huffman-rand-limit.dyn.expect │ │ │ │ ├── huffman-rand-limit.dyn.expect-noinput │ │ │ │ ├── huffman-rand-limit.golden │ │ │ │ ├── huffman-rand-limit.in │ │ │ │ ├── huffman-rand-limit.wb.expect │ │ │ │ ├── huffman-rand-limit.wb.expect-noinput │ │ │ │ ├── huffman-rand-max.golden │ │ │ │ ├── huffman-rand-max.in │ │ │ │ ├── huffman-shifts.dyn.expect │ │ │ │ ├── huffman-shifts.dyn.expect-noinput │ │ │ │ ├── huffman-shifts.golden │ │ │ │ ├── huffman-shifts.in │ │ │ │ ├── huffman-shifts.wb.expect │ │ │ │ ├── huffman-shifts.wb.expect-noinput │ │ │ │ ├── huffman-text-shift.dyn.expect │ │ │ │ ├── huffman-text-shift.dyn.expect-noinput │ │ │ │ ├── huffman-text-shift.golden │ │ │ │ ├── huffman-text-shift.in │ │ │ │ ├── huffman-text-shift.wb.expect │ │ │ │ ├── huffman-text-shift.wb.expect-noinput │ │ │ │ ├── huffman-text.dyn.expect │ │ │ │ ├── huffman-text.dyn.expect-noinput │ │ │ │ ├── huffman-text.golden │ │ │ │ ├── huffman-text.in │ │ │ │ ├── huffman-text.wb.expect │ │ │ │ ├── huffman-text.wb.expect-noinput │ │ │ │ ├── huffman-zero.dyn.expect │ │ │ │ ├── huffman-zero.dyn.expect-noinput │ │ │ │ ├── huffman-zero.golden │ │ │ │ ├── huffman-zero.in │ │ │ │ ├── huffman-zero.wb.expect │ │ │ │ ├── huffman-zero.wb.expect-noinput │ │ │ │ ├── null-long-match.dyn.expect-noinput │ │ │ │ └── null-long-match.wb.expect-noinput │ │ │ ├── token.go │ │ │ └── writer_test.go │ │ ├── gzip │ │ │ ├── gunzip.go │ │ │ ├── gunzip_test.go │ │ │ ├── gzip.go │ │ │ ├── gzip_test.go │ │ │ └── testdata │ │ │ │ ├── issue6550.gz │ │ │ │ └── test.json │ │ └── testdata │ │ │ ├── Mark.Twain-Tom.Sawyer.txt │ │ │ ├── e.txt │ │ │ └── pi.txt │ ├── cpuid │ │ ├── LICENSE │ │ ├── README.md │ │ ├── cpuid.go │ │ ├── cpuid_386.s │ │ ├── cpuid_amd64.s │ │ ├── cpuid_test.go │ │ ├── detect_intel.go │ │ ├── detect_ref.go │ │ ├── generate.go │ │ ├── mockcpu_test.go │ │ ├── private-gen.go │ │ ├── private │ │ │ ├── README.md │ │ │ ├── cpuid.go │ │ │ ├── cpuid_386.s │ │ │ ├── cpuid_amd64.s │ │ │ ├── cpuid_detect_intel.go │ │ │ ├── cpuid_detect_ref.go │ │ │ └── cpuid_test.go │ │ └── testdata │ │ │ ├── cpuid_data.zip │ │ │ └── getall.go │ └── crc32 │ │ ├── LICENSE │ │ ├── README.md │ │ ├── crc32.go │ │ ├── crc32_amd64.go │ │ ├── crc32_amd64.s │ │ ├── crc32_amd64p32.go │ │ ├── crc32_amd64p32.s │ │ ├── crc32_generic.go │ │ ├── crc32_test.go │ │ └── example_test.go ├── magical │ └── argon2 │ │ ├── README.md │ │ ├── api.go │ │ ├── api_test.go │ │ ├── argon2.go │ │ ├── argon2_test.go │ │ ├── round.go │ │ └── round.py └── wg │ └── ecies │ ├── aead.go │ ├── aead_test.go │ ├── box.go │ ├── box_test.go │ ├── chacha20poly1305 │ ├── chacha20poly1305.go │ └── chacha20poly1305_test.go │ ├── cipher.go │ ├── doc.go │ ├── ecdh.go │ ├── ecdh_test.go │ ├── vendor │ ├── github.com │ │ └── dchest │ │ │ └── blake2b │ │ │ ├── README │ │ │ ├── blake2b.go │ │ │ ├── blake2b_test.go │ │ │ └── block.go │ ├── golang.org │ │ └── x │ │ │ └── crypto │ │ │ ├── AUTHORS │ │ │ ├── CONTRIBUTORS │ │ │ ├── LICENSE │ │ │ ├── PATENTS │ │ │ ├── README │ │ │ └── curve25519 │ │ │ ├── const_amd64.s │ │ │ ├── cswap_amd64.s │ │ │ ├── curve25519.go │ │ │ ├── curve25519_test.go │ │ │ ├── doc.go │ │ │ ├── freeze_amd64.s │ │ │ ├── ladderstep_amd64.s │ │ │ ├── mont25519_amd64.go │ │ │ ├── mul_amd64.s │ │ │ └── square_amd64.s │ └── schwanenlied.me │ │ └── yawning │ │ ├── chacha20 │ │ ├── LICENSE │ │ ├── README.md │ │ ├── chacha20.go │ │ ├── chacha20_amd64.go │ │ ├── chacha20_amd64.py │ │ ├── chacha20_amd64.s │ │ ├── chacha20_ref.go │ │ └── chacha20_test.go │ │ ├── poly1305 │ │ ├── README.md │ │ ├── poly1305.go │ │ ├── poly1305_32.go │ │ └── poly1305_test.go │ │ └── x448 │ │ ├── LICENSE.txt │ │ ├── README.md │ │ ├── x448.go │ │ ├── x448_ref.go │ │ └── x448_test.go │ └── xchacha20poly1305 │ ├── xchacha20poly1305.go │ └── xchacha20poly1305_test.go └── golang.org └── x └── crypto ├── AUTHORS ├── CONTRIBUTORS ├── LICENSE ├── PATENTS ├── README └── ssh └── terminal ├── util.go ├── util_bsd.go ├── util_linux.go ├── util_plan9.go ├── util_test.go └── util_windows.go /FORMAT.md: -------------------------------------------------------------------------------- 1 | # arc - disk format 2 | 3 | arc archives are tar archives compressed with gzip and then encrypted 4 | with the XChaCha20 + Poly1305 authenticated encryption mode using a 5 | key derived in one of three ways: 6 | 7 | 1. from a password using the Argon2 KDF 8 | 2. from a static-ephemeral ECDH key exchange 9 | 3. from a random key split into n shards 10 | 11 | The on-disk format begins with a 1-byte disk format version V followed 12 | by a 1-byte archive type T, then a type-specific number of bytes, a 13 | 16-byte Poly1305 authentication tag, a 24-byte cryptographically secure 14 | random nonce, and finally the encrypted data. 15 | 16 | All numbers are stored in little-endian format. 17 | 18 | ## Password Archive Format 19 | 20 | The 32-byte XChaCha20Poly1305 key is generated by applying the Argon2 21 | KDF to a user-supplied password and 32 bytes of cryptographically 22 | secure random salt. 23 | 24 | T = 1 25 | I = uint32 number of iterations 26 | M = uint32 memory usage 27 | 28 | ┌─┬─┬────┬────┬───────────────────────────────┐ 29 | │V│T│I │M │Salt │ 30 | ├─┴─┴────┴────┴─┬───────────────────────┬─────┴─────────────┐ 31 | │Tag │Nonce │Data···············│ 32 | ├───────────────┴───────────────────────┴───────────────────┤ 33 | │···························································│ 34 | └───────────────────────────────────────────────────────────┘ 35 | 36 | ## Curve448 Archive Format 37 | 38 | The 32-byte XChaCha20Poly1305 key results from applying BLAKE2b to the 39 | shared secret derived from a X448 ECDH key exchange with an ephemeral 40 | private key and static public key. The corresponding ephemeral public 41 | key is embedded in the archive. 42 | 43 | T = 2 44 | 45 | ┌─┬─┬───────────────────────────────────────────────────────┐ 46 | │V│T│Ephemeral Public Key │ 47 | ├─┴─┴───────────┬───────────────────────┬───────────────────┤ 48 | │Tag │Nonce │Data···············│ 49 | ├───────────────┴───────────────────────┴───────────────────┤ 50 | │···························································│ 51 | └───────────────────────────────────────────────────────────┘ 52 | 53 | ## Shard Archive Format 54 | 55 | The 32-byte XChaCha20Poly1305 key is cryptographically secure random 56 | bytes split into n shards using Shamir's Secret Sharing algorithm. 57 | One archive is generated for each n and k archives must be present to 58 | recreate the key and decrypt the archive. 59 | 60 | T = 3 61 | n = shard number 62 | 63 | ┌─┬─┬─┬───────────────────────────────┐ 64 | │V│T│n│Shard │ 65 | ├─┴─┴─┴─────────┬─────────────────────┴─┬───────────────────┐ 66 | │Tag │Nonce │Data···············│ 67 | ├───────────────┴───────────────────────┴───────────────────┤ 68 | │···························································│ 69 | └───────────────────────────────────────────────────────────┘ 70 | 71 | ## Curve448 Key Format 72 | 73 | arc curve448 public and private keys are encrypted with XChaCha20+ 74 | Poly1305 using a key derived from applying the Argon2 KDF to a 75 | password and 32 bytes of cryptographically secure random salt. 76 | 77 | T = public = 1, private = 2 78 | I = uint32 number of iterations 79 | M = uint32 memory usage 80 | 81 | ┌─┬─┬────┬────┬───────────────────────────────┐ 82 | │V│T│I │M │Salt │ 83 | ├─┴─┴────┴────┴─┬───────────────────────┬─────┴─────────────┐ 84 | │Tag │Nonce │Key················│ 85 | ├───────────────┴───────────────────────┴───────────────────┤ 86 | │···························································│ 87 | └───────────────────────────────────────────────────────────┘ 88 | 89 | Private keys use a user-supplied password while public keys use an 90 | empty string. 91 | -------------------------------------------------------------------------------- /INSTALL.md: -------------------------------------------------------------------------------- 1 | # arc - build instructions 2 | 3 | arc is written in Go and all dependencies are vendored so building can be 4 | as simple as running `go get github.com/wg/arc` or checking out the code 5 | into a Go workspace and running `go install github.com/wg/arc`. 6 | 7 | Building an executable that is identical to a released binary requires a 8 | number of conditions be met: 9 | 10 | 1. the Go toolchain version must be identical 11 | 2. GOROOT, GOPATH and PWD must be identical 12 | 3. the path separator character must be "/" 13 | 14 | The Go compiler creates executables with debug information containing 15 | filesystem paths of all packages used to build the executable as well as 16 | the working directory. Aside from that its output is deterministic, even 17 | when cross compiling. 18 | -------------------------------------------------------------------------------- /archive/archive.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 - Will Glozer. All rights reserved. 2 | 3 | package archive 4 | 5 | import ( 6 | "crypto/rand" 7 | "crypto/subtle" 8 | "io" 9 | 10 | "github.com/wg/ecies/xchacha20poly1305" 11 | ) 12 | 13 | const KeySize = xchacha20poly1305.KeySize 14 | 15 | type Archive struct { 16 | xchacha20poly1305.XChaCha20Poly1305 17 | tag [xchacha20poly1305.TagSize]byte 18 | io.Reader 19 | io.Writer 20 | } 21 | 22 | func NewArchiveFromReader(r io.Reader, key []byte) (*Archive, error) { 23 | var nonce [xchacha20poly1305.NonceSize]byte 24 | a := &Archive{Reader: r} 25 | 26 | if _, err := io.ReadFull(r, a.tag[:]); err != nil { 27 | return nil, err 28 | } 29 | 30 | if _, err := io.ReadFull(r, nonce[:]); err != nil { 31 | return nil, err 32 | } 33 | 34 | err := a.Init(key, nonce[:]) 35 | return a, err 36 | } 37 | 38 | func NewArchiveForWriter(w io.Writer, key []byte) (*Archive, error) { 39 | var nonce [xchacha20poly1305.NonceSize]byte 40 | a := &Archive{Writer: w} 41 | 42 | if _, err := rand.Read(nonce[:]); err != nil { 43 | return nil, err 44 | } 45 | 46 | if err := a.Init(key, nonce[:]); err != nil { 47 | return nil, err 48 | } 49 | 50 | if _, err := w.Write(a.tag[:]); err != nil { 51 | return nil, err 52 | } 53 | 54 | if _, err := w.Write(nonce[:]); err != nil { 55 | return nil, err 56 | } 57 | 58 | return a, nil 59 | } 60 | 61 | func (a *Archive) Read(b []byte) (int, error) { 62 | n, err := a.Reader.Read(b) 63 | a.Decrypt(b[:n], b[:n]) 64 | return n, err 65 | } 66 | 67 | func (a *Archive) Write(b []byte) (int, error) { 68 | a.Encrypt(b, b) 69 | return a.Writer.Write(b) 70 | } 71 | 72 | func (a *Archive) Verify() bool { 73 | var tag [xchacha20poly1305.TagSize]byte 74 | a.Tag(tag[:0]) 75 | return subtle.ConstantTimeCompare(a.tag[:], tag[:]) == 1 76 | } 77 | -------------------------------------------------------------------------------- /archive/archive_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 - Will Glozer. All rights reserved. 2 | 3 | package archive 4 | 5 | import ( 6 | "archive/tar" 7 | "bytes" 8 | "crypto/rand" 9 | "io" 10 | "io/ioutil" 11 | "testing" 12 | ) 13 | 14 | func TestCreateArchive(t *testing.T) { 15 | entries := []*tar.Header{ 16 | {Name: "foo", Size: 0}, 17 | {Name: "bar", Size: 1<<16 - 1}, 18 | {Name: "baz", Size: 64}, 19 | } 20 | key := randomKey() 21 | 22 | buf, dat, err := createArchive(key, entries) 23 | if err != nil { 24 | t.Fatal(err) 25 | } 26 | 27 | r, err := NewReader(buf, key) 28 | if err != nil { 29 | t.Fatal(err) 30 | } 31 | 32 | for i, e := range entries { 33 | switch next, err := r.Next(); { 34 | case err != nil: 35 | t.Fatal(err) 36 | case e.Name != next.Name: 37 | t.Fatalf("expected entry name %s got %s", e.Name, next.Name) 38 | case e.Size != next.Size: 39 | t.Fatalf("expected entry size %d got %d", e.Size, next.Size) 40 | } 41 | 42 | switch b, err := ioutil.ReadAll(r); { 43 | case err != nil: 44 | t.Fatal(err) 45 | case int(e.Size) != len(b): 46 | t.Fatalf("expected to read %d bytes got %d", e.Size, len(b)) 47 | case !bytes.Equal(b, dat[i]): 48 | t.Fatalf("expected content '%v' got '%v'", b, dat[i]) 49 | } 50 | } 51 | 52 | if !r.Verify() { 53 | t.Fatal("archive verify failed") 54 | } 55 | } 56 | 57 | func TestVerifyArchive(t *testing.T) { 58 | entries := []*tar.Header{ 59 | {Name: "foo", Size: 32}, 60 | {Name: "bar", Size: 64}, 61 | } 62 | key := randomKey() 63 | 64 | buf, _, err := createArchive(key, entries) 65 | if err != nil { 66 | t.Fatal(err) 67 | } 68 | 69 | if valid, _ := Verify(buf, key); !valid { 70 | t.Fatal("archive verify failed") 71 | } 72 | } 73 | 74 | func TestVerifyFailWrongKey(t *testing.T) { 75 | entries := []*tar.Header{ 76 | {Name: "foo", Size: 32}, 77 | {Name: "bar", Size: 64}, 78 | } 79 | key := randomKey() 80 | 81 | buf, _, err := createArchive(key, entries) 82 | if err != nil { 83 | t.Fatal(err) 84 | } 85 | 86 | key[0] = ^key[0] 87 | 88 | if valid, _ := Verify(buf, key); valid { 89 | t.Fatal("verified invalid archive") 90 | } 91 | } 92 | 93 | func TestVerifyFailByteFlip(t *testing.T) { 94 | entries := []*tar.Header{ 95 | {Name: "foo", Size: 32}, 96 | {Name: "bar", Size: 64}, 97 | } 98 | key := randomKey() 99 | 100 | buf, _, err := createArchive(key, entries) 101 | if err != nil { 102 | t.Fatal(err) 103 | } 104 | 105 | archive := buf.Bytes() 106 | for i, b := range archive { 107 | archive[i] = ^archive[i] 108 | 109 | r := bytes.NewReader(archive) 110 | if valid, _ := Verify(r, key); valid { 111 | t.Fatal("verified invalid archive at", i) 112 | } 113 | 114 | archive[i] = b 115 | } 116 | } 117 | 118 | func TestWriterInvariants(t *testing.T) { 119 | _, _, err := createArchive(make([]byte, 31), nil) 120 | if err == nil { 121 | t.Fatalf("created archive with 31 byte key") 122 | } 123 | } 124 | 125 | func createArchive(key []byte, entries []*tar.Header) (*Buffer, [][]byte, error) { 126 | buf := &Buffer{} 127 | 128 | arc, err := NewWriter(buf, key) 129 | if err != nil { 130 | return nil, nil, err 131 | } 132 | 133 | dat := make([][]byte, len(entries)) 134 | 135 | for i, e := range entries { 136 | err := arc.Add(e) 137 | if err != nil { 138 | return nil, nil, err 139 | } 140 | 141 | dat[i] = make([]byte, e.Size) 142 | _, err = rand.Read(dat[i]) 143 | if err != nil { 144 | return nil, nil, err 145 | } 146 | 147 | err = arc.Copy(bytes.NewReader(dat[i]), e.Size) 148 | if err != nil { 149 | return nil, nil, err 150 | } 151 | } 152 | 153 | tag, _ := arc.Finish() 154 | copy(buf.Bytes()[0:16], tag) 155 | 156 | return buf, dat, nil 157 | } 158 | 159 | type Buffer struct { 160 | bytes.Buffer 161 | } 162 | 163 | func randomKey() []byte { 164 | key := make([]byte, 32) 165 | _, err := io.ReadFull(rand.Reader, key) 166 | if err != nil { 167 | panic(err) 168 | } 169 | return key 170 | } 171 | -------------------------------------------------------------------------------- /archive/reader.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 - Will Glozer. All rights reserved. 2 | 3 | package archive 4 | 5 | import ( 6 | "archive/tar" 7 | "compress/gzip" 8 | "io" 9 | ) 10 | 11 | type Reader struct { 12 | archiver *tar.Reader 13 | compressor *gzip.Reader 14 | archive *Archive 15 | } 16 | 17 | func NewReader(r io.Reader, key []byte) (*Reader, error) { 18 | archive, err := NewArchiveFromReader(r, key) 19 | if err != nil { 20 | return nil, err 21 | } 22 | 23 | compressor, err := gzip.NewReader(archive) 24 | if err != nil { 25 | return nil, err 26 | } 27 | 28 | archiver := tar.NewReader(compressor) 29 | 30 | return &Reader{ 31 | archiver: archiver, 32 | compressor: compressor, 33 | archive: archive, 34 | }, nil 35 | } 36 | 37 | func (r *Reader) Next() (*tar.Header, error) { 38 | return r.archiver.Next() 39 | } 40 | 41 | func (r *Reader) Read(b []byte) (int, error) { 42 | return r.archiver.Read(b) 43 | } 44 | 45 | func (r *Reader) Verify() bool { 46 | return r.archive.Verify() 47 | } 48 | -------------------------------------------------------------------------------- /archive/verify.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 - Will Glozer. All rights reserved. 2 | 3 | package archive 4 | 5 | import ( 6 | "io" 7 | "io/ioutil" 8 | ) 9 | 10 | func Verify(r io.Reader, key []byte) (bool, error) { 11 | archive, err := NewArchiveFromReader(r, key) 12 | if err != nil { 13 | return false, err 14 | } 15 | 16 | _, err = io.Copy(ioutil.Discard, archive) 17 | if err != nil { 18 | return false, err 19 | } 20 | 21 | return archive.Verify(), nil 22 | } 23 | -------------------------------------------------------------------------------- /archive/writer.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 - Will Glozer. All rights reserved. 2 | 3 | package archive 4 | 5 | import ( 6 | "archive/tar" 7 | "errors" 8 | "io" 9 | 10 | "github.com/klauspost/compress/gzip" 11 | ) 12 | 13 | var ( 14 | ErrShortCopy = errors.New("archive: short copy") 15 | ) 16 | 17 | type Writer struct { 18 | archiver *tar.Writer 19 | compressor *gzip.Writer 20 | archive *Archive 21 | } 22 | 23 | func NewWriter(w io.Writer, key []byte) (*Writer, error) { 24 | archive, err := NewArchiveForWriter(w, key) 25 | if err != nil { 26 | return nil, err 27 | } 28 | 29 | compressor := gzip.NewWriter(archive) 30 | archiver := tar.NewWriter(compressor) 31 | 32 | return &Writer{ 33 | archiver: archiver, 34 | compressor: compressor, 35 | archive: archive, 36 | }, nil 37 | } 38 | 39 | func (w *Writer) Add(header *tar.Header) error { 40 | return w.archiver.WriteHeader(header) 41 | } 42 | 43 | func (w *Writer) Copy(r io.Reader, size int64) error { 44 | switch n, err := io.Copy(w.archiver, r); { 45 | case err != nil: 46 | return err 47 | case n < size: 48 | return ErrShortCopy 49 | } 50 | return w.archiver.Flush() 51 | } 52 | 53 | func (w *Writer) Finish() ([]byte, error) { 54 | if err := w.archiver.Close(); err != nil { 55 | return nil, err 56 | } 57 | 58 | if err := w.compressor.Close(); err != nil { 59 | return nil, err 60 | } 61 | 62 | return w.archive.Tag(nil), nil 63 | } 64 | -------------------------------------------------------------------------------- /binary/binary.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 - Will Glozer. All rights reserved. 2 | 3 | package binary 4 | 5 | import ( 6 | "encoding/binary" 7 | "io" 8 | "reflect" 9 | ) 10 | 11 | type ByteOrder binary.ByteOrder 12 | 13 | var ( 14 | BE ByteOrder = binary.BigEndian 15 | LE ByteOrder = binary.LittleEndian 16 | ) 17 | 18 | func Write(w io.Writer, order ByteOrder, data interface{}) error { 19 | v := reflect.Indirect(reflect.ValueOf(data)) 20 | t := v.Type() 21 | 22 | out := make([]byte, size(v, t)) 23 | buf := out 24 | 25 | for i := 0; i < t.NumField(); i++ { 26 | v := v.Field(i) 27 | t := v.Type() 28 | 29 | if skip(v, t) { 30 | continue 31 | } 32 | 33 | switch t.Kind() { 34 | case reflect.Int8: 35 | buf[0] = byte(v.Int()) 36 | case reflect.Uint8: 37 | buf[0] = byte(v.Uint()) 38 | case reflect.Int16: 39 | order.PutUint16(buf, uint16(v.Int())) 40 | case reflect.Uint16: 41 | order.PutUint16(buf, uint16(v.Uint())) 42 | case reflect.Int32: 43 | order.PutUint32(buf, uint32(v.Int())) 44 | case reflect.Uint32: 45 | order.PutUint32(buf, uint32(v.Uint())) 46 | case reflect.Int64: 47 | order.PutUint64(buf, uint64(v.Int())) 48 | case reflect.Uint64: 49 | order.PutUint64(buf, uint64(v.Uint())) 50 | case reflect.Array: 51 | copy(buf, v.Slice(0, v.Len()).Bytes()) 52 | } 53 | 54 | buf = buf[t.Size():] 55 | } 56 | 57 | _, err := w.Write(out) 58 | return err 59 | } 60 | 61 | func Read(r io.Reader, order ByteOrder, data interface{}) error { 62 | v := reflect.Indirect(reflect.ValueOf(data)) 63 | t := v.Type() 64 | 65 | buf := make([]byte, size(v, t)) 66 | 67 | _, err := io.ReadFull(r, buf) 68 | if err != nil { 69 | return err 70 | } 71 | 72 | for i := 0; i < t.NumField(); i++ { 73 | v := v.Field(i) 74 | t := v.Type() 75 | 76 | if skip(v, t) { 77 | continue 78 | } 79 | 80 | switch t.Kind() { 81 | case reflect.Int8: 82 | v.SetInt(int64(buf[0])) 83 | case reflect.Uint8: 84 | v.SetUint(uint64(buf[0])) 85 | case reflect.Int16: 86 | v.SetInt(int64(order.Uint16(buf))) 87 | case reflect.Uint16: 88 | v.SetUint(uint64(order.Uint16(buf))) 89 | case reflect.Int32: 90 | v.SetInt(int64(order.Uint32(buf))) 91 | case reflect.Uint32: 92 | v.SetUint(uint64(order.Uint32(buf))) 93 | case reflect.Int64: 94 | v.SetInt(int64(order.Uint64(buf))) 95 | case reflect.Uint64: 96 | v.SetUint(uint64(order.Uint64(buf))) 97 | case reflect.Array: 98 | reflect.Copy(v, reflect.ValueOf(buf)) 99 | } 100 | 101 | buf = buf[t.Size():] 102 | } 103 | 104 | return nil 105 | } 106 | 107 | func size(v reflect.Value, t reflect.Type) uintptr { 108 | size := uintptr(0) 109 | 110 | for i := 0; i < t.NumField(); i++ { 111 | v := v.Field(i) 112 | t := v.Type() 113 | if !skip(v, t) { 114 | size += t.Size() 115 | } 116 | } 117 | 118 | return size 119 | } 120 | 121 | func skip(v reflect.Value, t reflect.Type) bool { 122 | if !v.CanSet() { 123 | return true 124 | } 125 | 126 | switch t.Kind() { 127 | case reflect.Int8, reflect.Uint8: 128 | return false 129 | case reflect.Int16, reflect.Uint16: 130 | return false 131 | case reflect.Int32, reflect.Uint32: 132 | return false 133 | case reflect.Int64, reflect.Uint64: 134 | return false 135 | case reflect.Array: 136 | return t.Elem().Size() != 1 137 | } 138 | 139 | return true 140 | } 141 | -------------------------------------------------------------------------------- /binary/binary_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 - Will Glozer. All rights reserved. 2 | 3 | package binary 4 | 5 | import ( 6 | "bytes" 7 | "encoding/binary" 8 | "math" 9 | "reflect" 10 | "testing" 11 | ) 12 | 13 | func TestBinaryArray(t *testing.T) { 14 | type Values struct { 15 | Byte byte 16 | Array [3]byte 17 | Int64 int64 18 | } 19 | 20 | in := &Values{1, [3]byte{2, 3, 4}, 0xAC00BD00} 21 | 22 | buf := &bytes.Buffer{} 23 | out := &Values{} 24 | 25 | if err := Write(buf, binary.LittleEndian, in); err != nil { 26 | t.Fatal(err) 27 | } 28 | 29 | if err := Read(buf, binary.LittleEndian, out); err != nil { 30 | t.Fatal(err) 31 | } 32 | 33 | if !reflect.DeepEqual(in, out) { 34 | t.Fatalf("round trip serialization failed") 35 | } 36 | } 37 | 38 | func TestBinaryMinMax(t *testing.T) { 39 | type Values struct { 40 | MinInt8 int8 41 | MaxInt8 int8 42 | MaxUint8 uint8 43 | MinInt16 int16 44 | MaxInt16 int16 45 | MaxUint16 uint16 46 | MinInt32 int32 47 | MaxInt32 int32 48 | MaxUint32 uint32 49 | MinInt64 int64 50 | MaxInt64 int64 51 | MaxUint64 uint64 52 | } 53 | 54 | in := &Values{ 55 | MinInt8: math.MinInt8, 56 | MaxInt8: math.MaxInt8, 57 | MaxUint8: 1<<8 - 1, 58 | MinInt16: math.MinInt16, 59 | MaxInt16: math.MaxInt16, 60 | MaxUint16: 1<<16 - 1, 61 | MinInt32: math.MinInt32, 62 | MaxInt32: math.MaxInt32, 63 | MaxUint32: 1<<32 - 1, 64 | MinInt64: math.MinInt64, 65 | MaxInt64: math.MaxInt64, 66 | MaxUint64: 1<<64 - 1, 67 | } 68 | 69 | out := &Values{} 70 | buf := &bytes.Buffer{} 71 | 72 | if err := Write(buf, binary.LittleEndian, in); err != nil { 73 | t.Fatal(err) 74 | } 75 | 76 | if err := Read(buf, binary.LittleEndian, out); err != nil { 77 | t.Fatal(err) 78 | } 79 | 80 | if !reflect.DeepEqual(in, out) { 81 | t.Fatalf("round trip serialization failed") 82 | } 83 | } 84 | 85 | func TestBinaryByteOrder(t *testing.T) { 86 | type Values struct { 87 | Uint16 uint16 88 | Uint32 uint32 89 | Uint64 uint64 90 | } 91 | 92 | in := &Values{ 93 | Uint16: 0x1234, 94 | Uint32: 0x12345678, 95 | Uint64: 0x1234567890ABCDEF, 96 | } 97 | 98 | little := []byte{0xEF, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12} 99 | 100 | buf := &bytes.Buffer{} 101 | 102 | if err := Write(buf, binary.LittleEndian, in); err != nil { 103 | t.Fatal(err) 104 | } 105 | 106 | if !bytes.Equal(buf.Bytes()[0:2], little[6:8]) { 107 | t.Fatalf("uint16 little endian incorrect") 108 | } 109 | 110 | if !bytes.Equal(buf.Bytes()[2:6], little[4:8]) { 111 | t.Fatalf("uint32 little endian incorrect") 112 | } 113 | 114 | if !bytes.Equal(buf.Bytes()[6:14], little[0:8]) { 115 | t.Fatalf("uint64 little endian incorrect") 116 | } 117 | buf.Reset() 118 | 119 | big := []byte{0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF} 120 | 121 | if err := Write(buf, binary.BigEndian, in); err != nil { 122 | t.Fatal(err) 123 | } 124 | 125 | if !bytes.Equal(buf.Bytes()[0:2], big[0:2]) { 126 | t.Fatalf("uint16 big endian incorrect") 127 | } 128 | 129 | if !bytes.Equal(buf.Bytes()[2:6], big[0:4]) { 130 | t.Fatalf("uint32 big endian incorrect") 131 | } 132 | 133 | if !bytes.Equal(buf.Bytes()[6:14], big[0:8]) { 134 | t.Fatalf("uint64 big endian incorrect") 135 | } 136 | 137 | } 138 | 139 | func TestBinarySkip(t *testing.T) { 140 | type Values struct { 141 | A byte 142 | B string 143 | C int32 144 | D []byte 145 | e byte 146 | } 147 | 148 | in := &Values{1, "foo", 0xABCDEF, []byte("bar"), 2} 149 | 150 | out := &Values{} 151 | buf := &bytes.Buffer{} 152 | 153 | if err := Write(buf, binary.LittleEndian, in); err != nil { 154 | t.Fatal(err) 155 | } 156 | 157 | if err := Read(buf, binary.LittleEndian, out); err != nil { 158 | t.Fatal(err) 159 | } 160 | 161 | in.B = "" 162 | in.D = nil 163 | in.e = 0 164 | 165 | if !reflect.DeepEqual(in, out) { 166 | t.Fatal("round trip serialization failed") 167 | } 168 | } 169 | -------------------------------------------------------------------------------- /bytesize.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package main 6 | 7 | import "fmt" 8 | 9 | type ByteSize float64 10 | 11 | const ( 12 | _ = iota // ignore first value by assigning to blank identifier 13 | KB ByteSize = 1 << (10 * iota) 14 | MB 15 | GB 16 | TB 17 | PB 18 | EB 19 | ZB 20 | YB 21 | ) 22 | 23 | func (b ByteSize) String() string { 24 | switch { 25 | case b >= YB: 26 | return fmt.Sprintf("%.2fY", b/YB) 27 | case b >= ZB: 28 | return fmt.Sprintf("%.2fZ", b/ZB) 29 | case b >= EB: 30 | return fmt.Sprintf("%.2fE", b/EB) 31 | case b >= PB: 32 | return fmt.Sprintf("%.2fP", b/PB) 33 | case b >= TB: 34 | return fmt.Sprintf("%.2fT", b/TB) 35 | case b >= GB: 36 | return fmt.Sprintf("%.2fG", b/GB) 37 | case b >= MB: 38 | return fmt.Sprintf("%.2fM", b/MB) 39 | case b >= KB: 40 | return fmt.Sprintf("%.2fK", b/KB) 41 | } 42 | return fmt.Sprintf("%.2fB", b) 43 | } 44 | -------------------------------------------------------------------------------- /circle.yml: -------------------------------------------------------------------------------- 1 | machine: 2 | environment: 3 | GOPATH: /go 4 | PROJECT: $CIRCLE_PROJECT_REPONAME 5 | IMPORT: github.com/$CIRCLE_PROJECT_USERNAME/$PROJECT 6 | GOPKG: go1.6.2.linux-amd64.tar.gz 7 | 8 | checkout: 9 | post: 10 | - sudo mkdir -p $GOPATH 11 | - sudo chown $USER $GOPATH 12 | - mkdir -p $GOPATH/src/$IMPORT 13 | - cp -r * $GOPATH/src/$IMPORT 14 | 15 | dependencies: 16 | pre: 17 | - sudo rm -rf /usr/local/go 18 | - curl -O https://storage.googleapis.com/golang/$GOPKG 19 | - sudo tar -xf $GOPKG -C /usr/local 20 | override: 21 | - echo 'export GOPATH=$GOPATH' >> ~/.circlerc 22 | 23 | test: 24 | pre: 25 | - go version 26 | - go env 27 | override: 28 | - go test -v -race $IMPORT/... 29 | post: 30 | - cd /go && GOOS=darwin GOARCH=amd64 go build -o $CIRCLE_ARTIFACTS/darwin/amd64/$PROJECT $IMPORT 31 | - cd /go && GOOS=freebsd GOARCH=amd64 go build -o $CIRCLE_ARTIFACTS/freebsd/amd64/$PROJECT $IMPORT 32 | - cd /go && GOOS=linux GOARCH=amd64 go build -o $CIRCLE_ARTIFACTS/linux/amd64/$PROJECT $IMPORT 33 | - cd /go && GOOS=windows GOARCH=amd64 go build -o $CIRCLE_ARTIFACTS/windows/amd64/$PROJECT.exe $IMPORT 34 | - find $CIRCLE_ARTIFACTS -type f -exec shasum -a 256 {} \; | tee $CIRCLE_ARTIFACTS/sha256.txt 35 | -------------------------------------------------------------------------------- /create.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 - Will Glozer. All rights reserved. 2 | 3 | package main 4 | 5 | import ( 6 | "archive/tar" 7 | "fmt" 8 | "io" 9 | "os" 10 | "path/filepath" 11 | 12 | "github.com/wg/arc/archive" 13 | ) 14 | 15 | func (c *Cmd) Create(arc *archive.Writer, names ...string) error { 16 | headers, errors := Scan(names) 17 | for header := range headers { 18 | name := header.Name 19 | size := header.Size 20 | 21 | err := arc.Add(header) 22 | if err != nil { 23 | return err 24 | } 25 | 26 | if header.Typeflag == tar.TypeReg { 27 | r, err := os.Open(name) 28 | if err != nil { 29 | return err 30 | } 31 | 32 | err = arc.Copy(r, size) 33 | r.Close() 34 | 35 | if err != nil { 36 | return err 37 | } 38 | } 39 | 40 | if c.Verbose > 0 { 41 | fmt.Println("a", name) 42 | } 43 | } 44 | 45 | select { 46 | case err := <-errors: 47 | return err 48 | default: 49 | return nil 50 | } 51 | } 52 | 53 | func Scan(names []string) (<-chan *tar.Header, <-chan error) { 54 | headers := make(chan *tar.Header, 64) 55 | errors := make(chan error) 56 | 57 | go func() { 58 | err := scan(names, headers) 59 | close(headers) 60 | if err != nil { 61 | errors <- err 62 | } 63 | }() 64 | 65 | return headers, errors 66 | } 67 | 68 | func scan(names []string, headers chan<- *tar.Header) error { 69 | for _, name := range names { 70 | info, err := os.Lstat(name) 71 | if err != nil { 72 | return err 73 | } 74 | 75 | mode := info.Mode() 76 | link := "" 77 | 78 | if !mode.IsRegular() && mode&(os.ModeDir|os.ModeSymlink) == 0 { 79 | continue 80 | } 81 | 82 | if mode&os.ModeSymlink != 0 { 83 | link, err = os.Readlink(name) 84 | if err != nil { 85 | return err 86 | } 87 | } 88 | 89 | header, err := tar.FileInfoHeader(info, link) 90 | if err != nil { 91 | return err 92 | } 93 | 94 | header.Name = name 95 | headers <- header 96 | 97 | if mode.IsDir() { 98 | dir, err := os.Open(name) 99 | if err != nil { 100 | return err 101 | } 102 | 103 | for err == nil { 104 | names, err = dir.Readdirnames(64) 105 | if err != nil { 106 | break 107 | } 108 | 109 | for i, n := range names { 110 | names[i] = filepath.Join(name, n) 111 | } 112 | 113 | err = scan(names, headers) 114 | } 115 | dir.Close() 116 | 117 | if err != nil && err != io.EOF { 118 | return err 119 | } 120 | } 121 | } 122 | return nil 123 | } 124 | -------------------------------------------------------------------------------- /extract.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 - Will Glozer. All rights reserved. 2 | 3 | package main 4 | 5 | import ( 6 | "archive/tar" 7 | "fmt" 8 | "io" 9 | "os" 10 | "path/filepath" 11 | "time" 12 | 13 | "github.com/wg/arc/archive" 14 | ) 15 | 16 | func (c *Cmd) Extract(arc *RegexFilter) error { 17 | mtimes := map[string]time.Time{} 18 | 19 | for arc.Next() { 20 | h := arc.Header 21 | 22 | name := h.Name 23 | mode := os.FileMode(h.Mode) 24 | 25 | var err error 26 | switch h.Typeflag { 27 | case tar.TypeReg, tar.TypeRegA: 28 | err = extract(name, mode, h.Size, arc) 29 | case tar.TypeDir: 30 | err = os.Mkdir(name, mode) 31 | case tar.TypeSymlink: 32 | err = os.Symlink(h.Linkname, name) 33 | } 34 | 35 | var action string 36 | switch { 37 | case os.IsExist(err): 38 | action = "-" 39 | case err != nil: 40 | return err 41 | default: 42 | action = "x" 43 | } 44 | 45 | if c.Verbose > 0 { 46 | fmt.Println(action, name) 47 | } 48 | 49 | mtimes[name] = h.ModTime 50 | } 51 | 52 | switch { 53 | case arc.Error != nil: 54 | return arc.Error 55 | case !arc.Verify(): 56 | return ErrVerifyFailed 57 | } 58 | 59 | ctime := time.Now() 60 | for name, mtime := range mtimes { 61 | err := os.Chtimes(name, ctime, mtime) 62 | if err != nil { 63 | return err 64 | } 65 | } 66 | 67 | return nil 68 | } 69 | 70 | func extract(path string, mode os.FileMode, size int64, r io.Reader) error { 71 | err := os.MkdirAll(filepath.Dir(path), 0) 72 | if err != nil { 73 | return err 74 | } 75 | 76 | f, err := os.OpenFile(path, os.O_EXCL|os.O_CREATE|os.O_WRONLY, mode) 77 | if err != nil { 78 | return err 79 | } 80 | defer f.Close() 81 | 82 | switch n, err := io.Copy(f, r); { 83 | case err != nil: 84 | return err 85 | case n < size: 86 | return archive.ErrShortCopy 87 | } 88 | 89 | return nil 90 | } 91 | -------------------------------------------------------------------------------- /filter.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 - Will Glozer. All rights reserved. 2 | 3 | package main 4 | 5 | import ( 6 | "archive/tar" 7 | "io" 8 | "regexp" 9 | "strings" 10 | 11 | "github.com/wg/arc/archive" 12 | ) 13 | 14 | type RegexFilter struct { 15 | Header *tar.Header 16 | Error error 17 | regex *regexp.Regexp 18 | *archive.Reader 19 | } 20 | 21 | func NewRegexFilter(r *archive.Reader, paths ...string) (*RegexFilter, error) { 22 | regex, err := regexp.Compile(strings.Join(paths, "|")) 23 | return &RegexFilter{ 24 | regex: regex, 25 | Reader: r, 26 | }, err 27 | } 28 | 29 | func (f *RegexFilter) Next() bool { 30 | for { 31 | switch header, err := f.Reader.Next(); { 32 | case err == io.EOF: 33 | return false 34 | case err != nil: 35 | f.Error = err 36 | return false 37 | case f.regex.MatchString(header.Name): 38 | f.Header = header 39 | return true 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /key.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 - Will Glozer. All rights reserved. 2 | 3 | package main 4 | 5 | import ( 6 | "crypto/rand" 7 | "crypto/subtle" 8 | "errors" 9 | "io" 10 | 11 | "github.com/dchest/blake2b" 12 | "github.com/magical/argon2" 13 | "github.com/wg/arc/binary" 14 | "github.com/wg/ecies" 15 | "github.com/wg/ecies/xchacha20poly1305" 16 | ) 17 | 18 | const ( 19 | Public = 0x01 20 | Private = 0x02 21 | NonSize = xchacha20poly1305.NonceSize 22 | TagSize = xchacha20poly1305.TagSize 23 | ) 24 | 25 | type ( 26 | PublicKey [56]byte 27 | PrivateKey [56]byte 28 | ) 29 | 30 | type KeyContainer struct { 31 | Version byte 32 | Type byte 33 | Iterations uint32 34 | Memory uint32 35 | Salt [32]byte 36 | Tag [TagSize]byte 37 | Nonce [NonSize]byte 38 | Key [56]byte 39 | Password []byte 40 | File io.ReadWriteCloser 41 | } 42 | 43 | var ( 44 | ErrInvalidPublicKey = errors.New("invalid public key") 45 | ErrInvalidPrivateKey = errors.New("invalid private key") 46 | ) 47 | 48 | func GenerateKeypair() (*PublicKey, *PrivateKey, error) { 49 | var public, private [56]byte 50 | err := ecies.GenerateCurve448Key(rand.Reader, &public, &private) 51 | return (*PublicKey)(&public), (*PrivateKey)(&private), err 52 | } 53 | 54 | func ComputeSharedKey(public *PublicKey, private *PrivateKey, size uint8) ([]byte, error) { 55 | hash, err := blake2b.New(&blake2b.Config{Size: size}) 56 | if err != nil { 57 | return nil, err 58 | } 59 | 60 | var secret [56]byte 61 | err = ecies.X448(&secret, (*[56]byte)(public), (*[56]byte)(private)) 62 | hash.Write(secret[:]) 63 | 64 | for i := range secret { 65 | secret[i] = 0 66 | } 67 | 68 | return hash.Sum(nil), err 69 | } 70 | 71 | func (private *PrivateKey) Zero() { 72 | for i := range private { 73 | private[i] = 0 74 | } 75 | } 76 | 77 | func NewKeyContainer(file io.ReadWriteCloser, password []byte, iterations, memory uint32) *KeyContainer { 78 | return &KeyContainer{ 79 | Version: 1, 80 | Iterations: iterations, 81 | Memory: memory, 82 | Password: password, 83 | File: file, 84 | } 85 | } 86 | 87 | func (c *KeyContainer) ReadPublicKey(key *PublicKey) error { 88 | return c.read(Public, (*[56]byte)(key)) 89 | } 90 | 91 | func (c *KeyContainer) WritePublicKey(key *PublicKey) error { 92 | return c.write(Public, (*[56]byte)(key)) 93 | } 94 | 95 | func (c *KeyContainer) ReadPrivateKey(key *PrivateKey) error { 96 | return c.read(Private, (*[56]byte)(key)) 97 | } 98 | 99 | func (c *KeyContainer) WritePrivateKey(key *PrivateKey) error { 100 | return c.write(Private, (*[56]byte)(key)) 101 | } 102 | 103 | func (c *KeyContainer) Close() error { 104 | return c.File.Close() 105 | } 106 | 107 | func (c *KeyContainer) read(t byte, key *[56]byte) error { 108 | switch err := binary.Read(c.File, binary.LE, c); { 109 | case err != nil: 110 | return err 111 | case c.Type != t && t == Public: 112 | return ErrInvalidPublicKey 113 | case c.Type != t && t == Private: 114 | return ErrInvalidPrivateKey 115 | } 116 | 117 | var tag [TagSize]byte 118 | x, err := c.cipher() 119 | if err != nil { 120 | return err 121 | } 122 | 123 | x.Decrypt(key[:], c.Key[:]) 124 | x.Tag(tag[:0]) 125 | 126 | if subtle.ConstantTimeCompare(c.Tag[:], tag[:]) != 1 { 127 | return ErrInvalidPrivateKey 128 | } 129 | 130 | return nil 131 | } 132 | 133 | func (c *KeyContainer) write(t byte, key *[56]byte) error { 134 | c.Type = t 135 | 136 | if _, err := rand.Read(c.Salt[:]); err != nil { 137 | return err 138 | } 139 | 140 | if _, err := rand.Read(c.Nonce[:]); err != nil { 141 | return err 142 | } 143 | 144 | x, err := c.cipher() 145 | if err != nil { 146 | return err 147 | } 148 | 149 | x.Encrypt(c.Key[:], key[:]) 150 | x.Tag(c.Tag[:0]) 151 | 152 | return binary.Write(c.File, binary.LE, c) 153 | } 154 | 155 | func (c *KeyContainer) cipher() (*xchacha20poly1305.XChaCha20Poly1305, error) { 156 | var ( 157 | salt = c.Salt[:] 158 | iterations = int(c.Iterations) 159 | memory = int64(c.Memory) 160 | keySize = xchacha20poly1305.KeySize 161 | ) 162 | 163 | key, err := argon2.Key(c.Password, salt, iterations, 1, memory, keySize) 164 | if err != nil { 165 | return nil, err 166 | } 167 | 168 | x := &xchacha20poly1305.XChaCha20Poly1305{} 169 | return x, x.Init(key[:], c.Nonce[:]) 170 | } 171 | -------------------------------------------------------------------------------- /key_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 - Will Glozer. All rights reserved. 2 | 3 | package main 4 | 5 | import ( 6 | "bytes" 7 | "testing" 8 | 9 | "github.com/magical/argon2" 10 | "github.com/wg/arc/binary" 11 | "github.com/wg/ecies/xchacha20poly1305" 12 | ) 13 | 14 | func TestPublicKeyFormat(t *testing.T) { 15 | p, _ := keypair(t) 16 | b, c := StorePublicKey(t, p) 17 | 18 | if b.buffer[1] != Public { 19 | t.Fatal("serialized type incorrect") 20 | } 21 | 22 | CheckKeyFormat(t, (*[56]byte)(p), b, c) 23 | } 24 | 25 | func TestPrivateKeyFormat(t *testing.T) { 26 | _, p := keypair(t) 27 | b, c := StorePrivateKey(t, p) 28 | 29 | if b.buffer[1] != Private { 30 | t.Fatal("serialized type incorrect") 31 | } 32 | 33 | CheckKeyFormat(t, (*[56]byte)(p), b, c) 34 | } 35 | 36 | func CheckKeyFormat(t *testing.T, k *[56]byte, b *Buffer, c *KeyContainer) { 37 | key, err := argon2.Key(c.Password, c.Salt[:], int(c.Iterations), 1, int64(c.Memory), KeySize) 38 | if err != nil { 39 | t.Fatal("password key derivation failed", err) 40 | } 41 | 42 | x := xchacha20poly1305.XChaCha20Poly1305{} 43 | if err := x.Init(key, c.Nonce[:]); err != nil { 44 | t.Fatal(err) 45 | } 46 | 47 | dst := [56]byte{} 48 | tag := [TagSize]byte{} 49 | 50 | x.Decrypt(dst[:], c.Key[:]) 51 | x.Tag(tag[:0]) 52 | 53 | if !bytes.Equal(k[:], dst[:]) { 54 | t.Fatal("decrypted key incorrect") 55 | } 56 | 57 | if !bytes.Equal(tag[:], c.Tag[:]) { 58 | t.Fatal("authentication tag incorrect") 59 | } 60 | 61 | if binary.LE.Uint32(b.buffer[2:6]) != c.Iterations { 62 | t.Fatal("serialized iterations incorrect") 63 | } 64 | 65 | if binary.LE.Uint32(b.buffer[6:10]) != c.Memory { 66 | t.Fatal("serialized memory incorrect") 67 | } 68 | 69 | if !bytes.Equal(b.buffer[10:42], c.Salt[:]) { 70 | t.Fatal("serialized salt incorrect") 71 | } 72 | 73 | if !bytes.Equal(b.buffer[42:58], tag[:]) { 74 | t.Fatal("serialized tag incorrect") 75 | } 76 | 77 | if !bytes.Equal(b.buffer[58:82], c.Nonce[:]) { 78 | t.Fatal("serialized nonce incorrect") 79 | } 80 | } 81 | 82 | func TestPublicPrivateKeypair(t *testing.T) { 83 | pub, priv := keypair(t) 84 | 85 | shared0, err := ComputeSharedKey(pub, priv, KeySize) 86 | if err != nil { 87 | t.Fatal(err) 88 | } 89 | 90 | _, puc := StorePublicKey(t, pub) 91 | _, prc := StorePrivateKey(t, priv) 92 | 93 | priv.Zero() 94 | 95 | if err := puc.ReadPublicKey(pub); err != nil { 96 | t.Fatal("failed to load public key", err) 97 | } 98 | 99 | if err := prc.ReadPrivateKey(priv); err != nil { 100 | t.Fatal("failed to load private key", err) 101 | } 102 | 103 | shared1, err := ComputeSharedKey(pub, priv, KeySize) 104 | if err != nil { 105 | t.Fatal(err) 106 | } 107 | 108 | if !bytes.Equal(shared0, shared1) { 109 | t.Fatal("serialized keys incorrect") 110 | } 111 | } 112 | 113 | func TestWrongKeyType(t *testing.T) { 114 | pub, priv := keypair(t) 115 | 116 | _, pubc := StorePublicKey(t, pub) 117 | _, privc := StorePrivateKey(t, priv) 118 | 119 | if err := pubc.ReadPrivateKey(priv); err != ErrInvalidPrivateKey { 120 | t.Fatal("loaded public key as private key") 121 | } 122 | 123 | if err := privc.ReadPublicKey(pub); err != ErrInvalidPublicKey { 124 | t.Fatal("loaded private key as public key") 125 | } 126 | } 127 | 128 | func StorePublicKey(t *testing.T, key *PublicKey) (*Buffer, *KeyContainer) { 129 | b := &Buffer{} 130 | c := NewKeyContainer(b, []byte(""), 1, 8) 131 | 132 | if err := c.WritePublicKey(key); err != nil { 133 | t.Fatal("failed to store public key", err) 134 | } 135 | 136 | b.Rewind() 137 | 138 | return b, c 139 | } 140 | 141 | func StorePrivateKey(t *testing.T, key *PrivateKey) (*Buffer, *KeyContainer) { 142 | b := &Buffer{} 143 | c := NewKeyContainer(b, []byte("secret"), 1, 8) 144 | 145 | if err := c.WritePrivateKey(key); err != nil { 146 | t.Fatal("failed to store private key", err) 147 | } 148 | 149 | b.Rewind() 150 | 151 | return b, c 152 | } 153 | -------------------------------------------------------------------------------- /keygen.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 - Will Glozer. All rights reserved. 2 | 3 | package main 4 | 5 | func (c *Cmd) Keygen(puc *KeyContainer, prc *KeyContainer) error { 6 | public, private, err := GenerateKeypair() 7 | if err != nil { 8 | return err 9 | } 10 | 11 | if err = puc.WritePublicKey(public); err != nil { 12 | return err 13 | } 14 | 15 | if err = prc.WritePrivateKey(private); err != nil { 16 | return err 17 | } 18 | 19 | return nil 20 | } 21 | -------------------------------------------------------------------------------- /list.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 - Will Glozer. All rights reserved. 2 | 3 | package main 4 | 5 | import ( 6 | "archive/tar" 7 | "errors" 8 | "fmt" 9 | "os" 10 | ) 11 | 12 | var ( 13 | ErrVerifyFailed = errors.New("archive: verify failed") 14 | ErrNoEntryFound = errors.New("archive: no entry found") 15 | ) 16 | 17 | func (c *Cmd) List(arc *RegexFilter) error { 18 | matches := 0 19 | 20 | for arc.Next() { 21 | h := arc.Header 22 | switch { 23 | case c.Verbose > 0: 24 | const layout = "%s %-6d %-6d %8s %s %s\n" 25 | mode := mode(h) 26 | size := size(h) 27 | date := h.ModTime.Format("2006-01-02 15:04") 28 | name := name(h) 29 | fmt.Printf(layout, mode, h.Uid, h.Gid, size, date, name) 30 | default: 31 | fmt.Println(h.Name) 32 | } 33 | matches++ 34 | } 35 | 36 | switch { 37 | case arc.Error != nil: 38 | return arc.Error 39 | case !arc.Verify(): 40 | return ErrVerifyFailed 41 | case matches == 0: 42 | return ErrNoEntryFound 43 | } 44 | 45 | return nil 46 | } 47 | 48 | func mode(h *tar.Header) string { 49 | mode := os.FileMode(h.Mode) 50 | switch h.Typeflag { 51 | case tar.TypeDir: 52 | mode |= os.ModeDir 53 | case tar.TypeSymlink: 54 | mode |= os.ModeSymlink 55 | } 56 | return mode.String() 57 | } 58 | 59 | func size(h *tar.Header) string { 60 | if h.Size == 0 { 61 | return "0" 62 | } 63 | return ByteSize(h.Size).String() 64 | } 65 | 66 | func name(h *tar.Header) string { 67 | name := h.Name 68 | if h.Typeflag == tar.TypeSymlink { 69 | name += " -> " + h.Linkname 70 | } 71 | return name 72 | } 73 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 - Will Glozer. All rights reserved. 2 | 3 | package main 4 | 5 | import ( 6 | "fmt" 7 | "os" 8 | 9 | "github.com/wg/arc/archive" 10 | ) 11 | 12 | type Cmd struct { 13 | Op interface{} 14 | Archiver Archiver 15 | Verbose int 16 | Names []string 17 | Private *KeyContainer 18 | Public *KeyContainer 19 | } 20 | 21 | func main() { 22 | c, err := NewCommand() 23 | if err != nil { 24 | fmt.Println(err) 25 | os.Exit(1) 26 | } 27 | 28 | switch op := c.Op.(type) { 29 | case func(*archive.Writer, ...string) error: 30 | arc := c.createArchive() 31 | err = op(arc.Writer, c.Names...) 32 | defer arc.Close() 33 | case func(*RegexFilter) error: 34 | arc, filter := c.filterArchive() 35 | err = op(filter) 36 | defer arc.Close() 37 | case func(*KeyContainer, *KeyContainer) error: 38 | err = op(c.Public, c.Private) 39 | defer c.Public.Close() 40 | defer c.Private.Close() 41 | } 42 | 43 | if err != nil { 44 | c.Fatal(err) 45 | } 46 | } 47 | 48 | func (c *Cmd) createArchive() *Writer { 49 | arc, err := c.Archiver.Writer() 50 | if err != nil { 51 | c.Fatal(err) 52 | } 53 | return arc 54 | } 55 | 56 | func (c *Cmd) filterArchive() (*Reader, *RegexFilter) { 57 | arc, err := c.Archiver.Reader() 58 | if err != nil { 59 | c.Fatal(err) 60 | } 61 | 62 | f, err := NewRegexFilter(arc.Reader, c.Names...) 63 | if err != nil { 64 | c.Fatal(err) 65 | } 66 | 67 | return arc, f 68 | } 69 | 70 | func (c *Cmd) Fatal(v ...interface{}) { 71 | fmt.Println(v...) 72 | os.Exit(1) 73 | } 74 | -------------------------------------------------------------------------------- /vendor/github.com/codahale/sss/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Coda Hale 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /vendor/github.com/codahale/sss/README.md: -------------------------------------------------------------------------------- 1 | # sss (Shamir's Secret Sharing) 2 | 3 | [![Build Status](https://travis-ci.org/codahale/sss.png?branch=master)](https://travis-ci.org/codahale/sss) 4 | 5 | A pure Go implementation of 6 | [Shamir's Secret Sharing algorithm](http://en.wikipedia.org/wiki/Shamir's_Secret_Sharing) 7 | over GF(2^8). 8 | 9 | Inspired by @hbs's [Python implementation](https://github.com/hbs/PySSSS). 10 | 11 | For documentation, check [godoc](http://godoc.org/github.com/codahale/sss). 12 | -------------------------------------------------------------------------------- /vendor/github.com/codahale/sss/gf256.go: -------------------------------------------------------------------------------- 1 | package sss 2 | 3 | func mul(e, a byte) byte { 4 | if e == 0 || a == 0 { 5 | return 0 6 | } 7 | return exp[(int(log[e])+int(log[a]))%255] 8 | } 9 | 10 | func div(e, a byte) byte { 11 | if a == 0 { 12 | panic("div by zero") 13 | } 14 | 15 | if e == 0 { 16 | return 0 17 | } 18 | 19 | p := (int(log[e]) - int(log[a])) % 255 20 | if p < 0 { 21 | p += 255 22 | } 23 | 24 | return exp[p] 25 | } 26 | 27 | const ( 28 | fieldSize = 256 // 2^8 29 | ) 30 | 31 | var ( 32 | // 0x11b prime polynomial and 0x03 as generator 33 | exp = [fieldSize]byte{ 34 | 0x01, 0x03, 0x05, 0x0f, 0x11, 0x33, 0x55, 0xff, 0x1a, 0x2e, 0x72, 0x96, 35 | 0xa1, 0xf8, 0x13, 0x35, 0x5f, 0xe1, 0x38, 0x48, 0xd8, 0x73, 0x95, 0xa4, 36 | 0xf7, 0x02, 0x06, 0x0a, 0x1e, 0x22, 0x66, 0xaa, 0xe5, 0x34, 0x5c, 0xe4, 37 | 0x37, 0x59, 0xeb, 0x26, 0x6a, 0xbe, 0xd9, 0x70, 0x90, 0xab, 0xe6, 0x31, 38 | 0x53, 0xf5, 0x04, 0x0c, 0x14, 0x3c, 0x44, 0xcc, 0x4f, 0xd1, 0x68, 0xb8, 39 | 0xd3, 0x6e, 0xb2, 0xcd, 0x4c, 0xd4, 0x67, 0xa9, 0xe0, 0x3b, 0x4d, 0xd7, 40 | 0x62, 0xa6, 0xf1, 0x08, 0x18, 0x28, 0x78, 0x88, 0x83, 0x9e, 0xb9, 0xd0, 41 | 0x6b, 0xbd, 0xdc, 0x7f, 0x81, 0x98, 0xb3, 0xce, 0x49, 0xdb, 0x76, 0x9a, 42 | 0xb5, 0xc4, 0x57, 0xf9, 0x10, 0x30, 0x50, 0xf0, 0x0b, 0x1d, 0x27, 0x69, 43 | 0xbb, 0xd6, 0x61, 0xa3, 0xfe, 0x19, 0x2b, 0x7d, 0x87, 0x92, 0xad, 0xec, 44 | 0x2f, 0x71, 0x93, 0xae, 0xe9, 0x20, 0x60, 0xa0, 0xfb, 0x16, 0x3a, 0x4e, 45 | 0xd2, 0x6d, 0xb7, 0xc2, 0x5d, 0xe7, 0x32, 0x56, 0xfa, 0x15, 0x3f, 0x41, 46 | 0xc3, 0x5e, 0xe2, 0x3d, 0x47, 0xc9, 0x40, 0xc0, 0x5b, 0xed, 0x2c, 0x74, 47 | 0x9c, 0xbf, 0xda, 0x75, 0x9f, 0xba, 0xd5, 0x64, 0xac, 0xef, 0x2a, 0x7e, 48 | 0x82, 0x9d, 0xbc, 0xdf, 0x7a, 0x8e, 0x89, 0x80, 0x9b, 0xb6, 0xc1, 0x58, 49 | 0xe8, 0x23, 0x65, 0xaf, 0xea, 0x25, 0x6f, 0xb1, 0xc8, 0x43, 0xc5, 0x54, 50 | 0xfc, 0x1f, 0x21, 0x63, 0xa5, 0xf4, 0x07, 0x09, 0x1b, 0x2d, 0x77, 0x99, 51 | 0xb0, 0xcb, 0x46, 0xca, 0x45, 0xcf, 0x4a, 0xde, 0x79, 0x8b, 0x86, 0x91, 52 | 0xa8, 0xe3, 0x3e, 0x42, 0xc6, 0x51, 0xf3, 0x0e, 0x12, 0x36, 0x5a, 0xee, 53 | 0x29, 0x7b, 0x8d, 0x8c, 0x8f, 0x8a, 0x85, 0x94, 0xa7, 0xf2, 0x0d, 0x17, 54 | 0x39, 0x4b, 0xdd, 0x7c, 0x84, 0x97, 0xa2, 0xfd, 0x1c, 0x24, 0x6c, 0xb4, 55 | 0xc7, 0x52, 0xf6, 0x01, 56 | } 57 | log = [fieldSize]byte{ 58 | 0x00, 0x00, 0x19, 0x01, 0x32, 0x02, 0x1a, 0xc6, 0x4b, 0xc7, 0x1b, 0x68, 59 | 0x33, 0xee, 0xdf, 0x03, 0x64, 0x04, 0xe0, 0x0e, 0x34, 0x8d, 0x81, 0xef, 60 | 0x4c, 0x71, 0x08, 0xc8, 0xf8, 0x69, 0x1c, 0xc1, 0x7d, 0xc2, 0x1d, 0xb5, 61 | 0xf9, 0xb9, 0x27, 0x6a, 0x4d, 0xe4, 0xa6, 0x72, 0x9a, 0xc9, 0x09, 0x78, 62 | 0x65, 0x2f, 0x8a, 0x05, 0x21, 0x0f, 0xe1, 0x24, 0x12, 0xf0, 0x82, 0x45, 63 | 0x35, 0x93, 0xda, 0x8e, 0x96, 0x8f, 0xdb, 0xbd, 0x36, 0xd0, 0xce, 0x94, 64 | 0x13, 0x5c, 0xd2, 0xf1, 0x40, 0x46, 0x83, 0x38, 0x66, 0xdd, 0xfd, 0x30, 65 | 0xbf, 0x06, 0x8b, 0x62, 0xb3, 0x25, 0xe2, 0x98, 0x22, 0x88, 0x91, 0x10, 66 | 0x7e, 0x6e, 0x48, 0xc3, 0xa3, 0xb6, 0x1e, 0x42, 0x3a, 0x6b, 0x28, 0x54, 67 | 0xfa, 0x85, 0x3d, 0xba, 0x2b, 0x79, 0x0a, 0x15, 0x9b, 0x9f, 0x5e, 0xca, 68 | 0x4e, 0xd4, 0xac, 0xe5, 0xf3, 0x73, 0xa7, 0x57, 0xaf, 0x58, 0xa8, 0x50, 69 | 0xf4, 0xea, 0xd6, 0x74, 0x4f, 0xae, 0xe9, 0xd5, 0xe7, 0xe6, 0xad, 0xe8, 70 | 0x2c, 0xd7, 0x75, 0x7a, 0xeb, 0x16, 0x0b, 0xf5, 0x59, 0xcb, 0x5f, 0xb0, 71 | 0x9c, 0xa9, 0x51, 0xa0, 0x7f, 0x0c, 0xf6, 0x6f, 0x17, 0xc4, 0x49, 0xec, 72 | 0xd8, 0x43, 0x1f, 0x2d, 0xa4, 0x76, 0x7b, 0xb7, 0xcc, 0xbb, 0x3e, 0x5a, 73 | 0xfb, 0x60, 0xb1, 0x86, 0x3b, 0x52, 0xa1, 0x6c, 0xaa, 0x55, 0x29, 0x9d, 74 | 0x97, 0xb2, 0x87, 0x90, 0x61, 0xbe, 0xdc, 0xfc, 0xbc, 0x95, 0xcf, 0xcd, 75 | 0x37, 0x3f, 0x5b, 0xd1, 0x53, 0x39, 0x84, 0x3c, 0x41, 0xa2, 0x6d, 0x47, 76 | 0x14, 0x2a, 0x9e, 0x5d, 0x56, 0xf2, 0xd3, 0xab, 0x44, 0x11, 0x92, 0xd9, 77 | 0x23, 0x20, 0x2e, 0x89, 0xb4, 0x7c, 0xb8, 0x26, 0x77, 0x99, 0xe3, 0xa5, 78 | 0x67, 0x4a, 0xed, 0xde, 0xc5, 0x31, 0xfe, 0x18, 0x0d, 0x63, 0x8c, 0x80, 79 | 0xc0, 0xf7, 0x70, 0x07, 80 | } 81 | ) 82 | -------------------------------------------------------------------------------- /vendor/github.com/codahale/sss/gf256_test.go: -------------------------------------------------------------------------------- 1 | package sss 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestMul(t *testing.T) { 8 | if v, want := mul(90, 21), byte(254); v != want { 9 | t.Errorf("Was %v, but expected %v", v, want) 10 | } 11 | } 12 | 13 | func TestDiv(t *testing.T) { 14 | if v, want := div(90, 21), byte(189); v != want { 15 | t.Errorf("Was %v, but expected %v", v, want) 16 | } 17 | } 18 | 19 | func TestDivZero(t *testing.T) { 20 | if v, want := div(0, 2), byte(0); v != want { 21 | t.Errorf("Was %v, but expected %v", v, want) 22 | } 23 | } 24 | 25 | func TestDivByZero(t *testing.T) { 26 | defer func() { 27 | m := recover() 28 | if m != "div by zero" { 29 | t.Error(m) 30 | } 31 | }() 32 | 33 | div(2, 0) 34 | t.Error("Shouldn't have been able to divide those") 35 | } 36 | -------------------------------------------------------------------------------- /vendor/github.com/codahale/sss/polynomial.go: -------------------------------------------------------------------------------- 1 | package sss 2 | 3 | import "io" 4 | 5 | // the degree of the polynomial 6 | func degree(p []byte) int { 7 | return len(p) - 1 8 | } 9 | 10 | // evaluate the polynomial at the given point 11 | func eval(p []byte, x byte) (result byte) { 12 | // Horner's scheme 13 | for i := 1; i <= len(p); i++ { 14 | result = mul(result, x) ^ p[len(p)-i] 15 | } 16 | return 17 | } 18 | 19 | // generates a random n-degree polynomial w/ a given x-intercept 20 | func generate(degree byte, x byte, rand io.Reader) ([]byte, error) { 21 | result := make([]byte, degree+1) 22 | result[0] = x 23 | 24 | buf := make([]byte, degree-1) 25 | if _, err := io.ReadFull(rand, buf); err != nil { 26 | return nil, err 27 | } 28 | 29 | for i := byte(1); i < degree; i++ { 30 | result[i] = buf[i-1] 31 | } 32 | 33 | // the Nth term can't be zero, or else it's a (N-1) degree polynomial 34 | for { 35 | buf = make([]byte, 1) 36 | if _, err := io.ReadFull(rand, buf); err != nil { 37 | return nil, err 38 | } 39 | 40 | if buf[0] != 0 { 41 | result[degree] = buf[0] 42 | return result, nil 43 | } 44 | } 45 | } 46 | 47 | // an input/output pair 48 | type pair struct { 49 | x, y byte 50 | } 51 | 52 | // Lagrange interpolation 53 | func interpolate(points []pair, x byte) (value byte) { 54 | for i, a := range points { 55 | weight := byte(1) 56 | for j, b := range points { 57 | if i != j { 58 | top := x ^ b.x 59 | bottom := a.x ^ b.x 60 | factor := div(top, bottom) 61 | weight = mul(weight, factor) 62 | } 63 | } 64 | value = value ^ mul(weight, a.y) 65 | } 66 | return 67 | } 68 | -------------------------------------------------------------------------------- /vendor/github.com/codahale/sss/polynomial_test.go: -------------------------------------------------------------------------------- 1 | package sss 2 | 3 | import ( 4 | "bytes" 5 | "testing" 6 | ) 7 | 8 | var ( 9 | p = []byte{1, 0, 2, 3} 10 | p2 = []byte{70, 32, 6} 11 | ) 12 | 13 | func TestDegree(t *testing.T) { 14 | if v, want := degree(p), 3; v != want { 15 | t.Errorf("Was %v, but expected %v", v, want) 16 | } 17 | } 18 | 19 | func TestEval(t *testing.T) { 20 | if v, want := eval(p, 2), byte(17); v != want { 21 | t.Errorf("Was %v, but expected %v", v, want) 22 | } 23 | } 24 | 25 | func TestGenerate(t *testing.T) { 26 | b := []byte{1, 2, 3} 27 | 28 | expected := []byte{10, 1, 2, 3} 29 | actual, err := generate(3, 10, bytes.NewReader(b)) 30 | if err != nil { 31 | t.Error(err) 32 | } 33 | 34 | if !bytes.Equal(actual, expected) { 35 | t.Errorf("Was %v, but expected %v", actual, expected) 36 | } 37 | } 38 | 39 | func TestGenerateEOF(t *testing.T) { 40 | b := []byte{1} 41 | 42 | p, err := generate(3, 10, bytes.NewReader(b)) 43 | if p != nil { 44 | t.Errorf("Was %v, but expected an error", p) 45 | } 46 | 47 | if err == nil { 48 | t.Error("No error returned") 49 | } 50 | } 51 | 52 | func TestGeneratePolyEOFFullSize(t *testing.T) { 53 | b := []byte{1, 2, 0, 0, 0, 0} 54 | 55 | p, err := generate(3, 10, bytes.NewReader(b)) 56 | if p != nil { 57 | t.Errorf("Was %v, but xpected an error", p) 58 | } 59 | 60 | if err == nil { 61 | t.Error("No error returned") 62 | } 63 | } 64 | 65 | func TestGenerateFullSize(t *testing.T) { 66 | b := []byte{1, 2, 0, 4} 67 | 68 | expected := []byte{10, 1, 2, 4} 69 | actual, err := generate(3, 10, bytes.NewReader(b)) 70 | if err != nil { 71 | t.Error(err) 72 | } 73 | 74 | if !bytes.Equal(actual, expected) { 75 | t.Errorf("Was %v but expected %v", actual, expected) 76 | } 77 | } 78 | 79 | func TestInterpolate(t *testing.T) { 80 | in := []pair{ 81 | pair{x: 1, y: 1}, 82 | pair{x: 2, y: 2}, 83 | pair{x: 3, y: 3}, 84 | } 85 | 86 | if v, want := interpolate(in, 0), byte(0); v != want { 87 | t.Errorf("Was %v, but expected %v", v, want) 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /vendor/github.com/codahale/sss/sss.go: -------------------------------------------------------------------------------- 1 | // Package sss implements Shamir's Secret Sharing algorithm over GF(2^8). 2 | // 3 | // Shamir's Secret Sharing algorithm allows you to securely share a secret with 4 | // N people, allowing the recovery of that secret if K of those people combine 5 | // their shares. 6 | // 7 | // It begins by encoding a secret as a number (e.g., 42), and generating N 8 | // random polynomial equations of degree K-1 which have an X-intercept equal to 9 | // the secret. Given K=3, the following equations might be generated: 10 | // 11 | // f1(x) = 78x^2 + 19x + 42 12 | // f2(x) = 128x^2 + 171x + 42 13 | // f3(x) = 121x^2 + 3x + 42 14 | // f4(x) = 91x^2 + 95x + 42 15 | // etc. 16 | // 17 | // These polynomials are then evaluated for values of X > 0: 18 | // 19 | // f1(1) = 139 20 | // f2(2) = 896 21 | // f3(3) = 1140 22 | // f4(4) = 1783 23 | // etc. 24 | // 25 | // These (x, y) pairs are the shares given to the parties. In order to combine 26 | // shares to recover the secret, these (x, y) pairs are used as the input points 27 | // for Lagrange interpolation, which produces a polynomial which matches the 28 | // given points. This polynomial can be evaluated for f(0), producing the secret 29 | // value--the common x-intercept for all the generated polynomials. 30 | // 31 | // If fewer than K shares are combined, the interpolated polynomial will be 32 | // wrong, and the result of f(0) will not be the secret. 33 | // 34 | // This package constructs polynomials over the field GF(2^8) for each byte of 35 | // the secret, allowing for fast splitting and combining of anything which can 36 | // be encoded as bytes. 37 | // 38 | // This package has not been audited by cryptography or security professionals. 39 | package sss 40 | 41 | import ( 42 | "crypto/rand" 43 | "errors" 44 | ) 45 | 46 | var ( 47 | // ErrInvalidCount is returned when the count parameter is invalid. 48 | ErrInvalidCount = errors.New("N must be > 1") 49 | // ErrInvalidThreshold is returned when the threshold parameter is invalid. 50 | ErrInvalidThreshold = errors.New("K must be > 1") 51 | ) 52 | 53 | // Split the given secret into N shares of which K are required to recover the 54 | // secret. Returns a map of share IDs (1-255) to shares. 55 | func Split(n, k byte, secret []byte) (map[byte][]byte, error) { 56 | if n <= 1 { 57 | return nil, ErrInvalidCount 58 | } 59 | 60 | if k <= 1 { 61 | return nil, ErrInvalidThreshold 62 | } 63 | 64 | shares := make(map[byte][]byte, n) 65 | 66 | for _, b := range secret { 67 | p, err := generate(k-1, b, rand.Reader) 68 | if err != nil { 69 | return nil, err 70 | } 71 | 72 | for x := byte(1); x <= n; x++ { 73 | shares[x] = append(shares[x], eval(p, x)) 74 | } 75 | } 76 | 77 | return shares, nil 78 | } 79 | 80 | // Combine the given shares into the original secret. 81 | // 82 | // N.B.: There is no way to know whether the returned value is, in fact, the 83 | // original secret. 84 | func Combine(shares map[byte][]byte) []byte { 85 | var secret []byte 86 | for _, v := range shares { 87 | secret = make([]byte, len(v)) 88 | break 89 | } 90 | 91 | points := make([]pair, len(shares)) 92 | for i := range secret { 93 | p := 0 94 | for k, v := range shares { 95 | points[p] = pair{x: k, y: v[i]} 96 | p++ 97 | } 98 | secret[i] = interpolate(points, 0) 99 | } 100 | 101 | return secret 102 | } 103 | -------------------------------------------------------------------------------- /vendor/github.com/codahale/sss/sss_test.go: -------------------------------------------------------------------------------- 1 | package sss 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func Example() { 8 | secret := "well hello there!" // our secret 9 | n := byte(30) // create 30 shares 10 | k := byte(2) // require 2 of them to combine 11 | 12 | shares, err := Split(n, k, []byte(secret)) // split into 30 shares 13 | if err != nil { 14 | fmt.Println(err) 15 | return 16 | } 17 | 18 | // select a random subset of the total shares 19 | subset := make(map[byte][]byte, k) 20 | for x, y := range shares { // just iterate since maps are randomized 21 | subset[x] = y 22 | if len(subset) == int(k) { 23 | break 24 | } 25 | } 26 | 27 | // combine two shares and recover the secret 28 | recovered := string(Combine(subset)) 29 | fmt.Println(recovered) 30 | 31 | // Output: well hello there! 32 | } 33 | -------------------------------------------------------------------------------- /vendor/github.com/dchest/blake2b/README: -------------------------------------------------------------------------------- 1 | Go implementation of BLAKE2b collision-resistant cryptographic hash function 2 | created by Jean-Philippe Aumasson, Samuel Neves, Zooko Wilcox-O'Hearn, and 3 | Christian Winnerlein (https://blake2.net). 4 | 5 | INSTALLATION 6 | 7 | $ go get github.com/dchest/blake2b 8 | 9 | 10 | DOCUMENTATION 11 | 12 | See http://godoc.org/github.com/dchest/blake2b 13 | 14 | 15 | PUBLIC DOMAIN DEDICATION 16 | 17 | Written in 2012 by Dmitry Chestnykh. 18 | 19 | To the extent possible under law, the author have dedicated all copyright 20 | and related and neighboring rights to this software to the public domain 21 | worldwide. This software is distributed without any warranty. 22 | http://creativecommons.org/publicdomain/zero/1.0/ 23 | 24 | -------------------------------------------------------------------------------- /vendor/github.com/jessevdk/go-flags/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 Jesse van den Kieboom. All rights reserved. 2 | Redistribution and use in source and binary forms, with or without 3 | modification, are permitted provided that the following conditions are 4 | met: 5 | 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above 9 | copyright notice, this list of conditions and the following disclaimer 10 | in the documentation and/or other materials provided with the 11 | distribution. 12 | * Neither the name of Google Inc. nor the names of its 13 | contributors may be used to endorse or promote products derived from 14 | this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | -------------------------------------------------------------------------------- /vendor/github.com/jessevdk/go-flags/arg.go: -------------------------------------------------------------------------------- 1 | package flags 2 | 3 | import ( 4 | "reflect" 5 | ) 6 | 7 | // Arg represents a positional argument on the command line. 8 | type Arg struct { 9 | // The name of the positional argument (used in the help) 10 | Name string 11 | 12 | // A description of the positional argument (used in the help) 13 | Description string 14 | 15 | // Whether a positional argument is required 16 | Required int 17 | 18 | value reflect.Value 19 | tag multiTag 20 | } 21 | 22 | func (a *Arg) isRemaining() bool { 23 | return a.value.Type().Kind() == reflect.Slice 24 | } 25 | -------------------------------------------------------------------------------- /vendor/github.com/jessevdk/go-flags/arg_test.go: -------------------------------------------------------------------------------- 1 | package flags 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestPositional(t *testing.T) { 8 | var opts = struct { 9 | Value bool `short:"v"` 10 | 11 | Positional struct { 12 | Command int 13 | Filename string 14 | Rest []string 15 | } `positional-args:"yes" required:"yes"` 16 | }{} 17 | 18 | p := NewParser(&opts, Default) 19 | ret, err := p.ParseArgs([]string{"10", "arg_test.go", "a", "b"}) 20 | 21 | if err != nil { 22 | t.Fatalf("Unexpected error: %v", err) 23 | return 24 | } 25 | 26 | if opts.Positional.Command != 10 { 27 | t.Fatalf("Expected opts.Positional.Command to be 10, but got %v", opts.Positional.Command) 28 | } 29 | 30 | if opts.Positional.Filename != "arg_test.go" { 31 | t.Fatalf("Expected opts.Positional.Filename to be \"arg_test.go\", but got %v", opts.Positional.Filename) 32 | } 33 | 34 | assertStringArray(t, opts.Positional.Rest, []string{"a", "b"}) 35 | assertStringArray(t, ret, []string{}) 36 | } 37 | 38 | func TestPositionalRequired(t *testing.T) { 39 | var opts = struct { 40 | Value bool `short:"v"` 41 | 42 | Positional struct { 43 | Command int 44 | Filename string 45 | Rest []string 46 | } `positional-args:"yes" required:"yes"` 47 | }{} 48 | 49 | p := NewParser(&opts, None) 50 | _, err := p.ParseArgs([]string{"10"}) 51 | 52 | assertError(t, err, ErrRequired, "the required argument `Filename` was not provided") 53 | } 54 | 55 | func TestPositionalRequiredRest1Fail(t *testing.T) { 56 | var opts = struct { 57 | Value bool `short:"v"` 58 | 59 | Positional struct { 60 | Rest []string `required:"yes"` 61 | } `positional-args:"yes"` 62 | }{} 63 | 64 | p := NewParser(&opts, None) 65 | _, err := p.ParseArgs([]string{}) 66 | 67 | assertError(t, err, ErrRequired, "the required argument `Rest (at least 1 argument)` was not provided") 68 | } 69 | 70 | func TestPositionalRequiredRest1Pass(t *testing.T) { 71 | var opts = struct { 72 | Value bool `short:"v"` 73 | 74 | Positional struct { 75 | Rest []string `required:"yes"` 76 | } `positional-args:"yes"` 77 | }{} 78 | 79 | p := NewParser(&opts, None) 80 | _, err := p.ParseArgs([]string{"rest1"}) 81 | 82 | if err != nil { 83 | t.Fatalf("Unexpected error: %v", err) 84 | return 85 | } 86 | 87 | if len(opts.Positional.Rest) != 1 { 88 | t.Fatalf("Expected 1 positional rest argument") 89 | } 90 | 91 | assertString(t, opts.Positional.Rest[0], "rest1") 92 | } 93 | 94 | func TestPositionalRequiredRest2Fail(t *testing.T) { 95 | var opts = struct { 96 | Value bool `short:"v"` 97 | 98 | Positional struct { 99 | Rest []string `required:"2"` 100 | } `positional-args:"yes"` 101 | }{} 102 | 103 | p := NewParser(&opts, None) 104 | _, err := p.ParseArgs([]string{"rest1"}) 105 | 106 | assertError(t, err, ErrRequired, "the required argument `Rest (at least 2 arguments, but got only 1)` was not provided") 107 | } 108 | 109 | func TestPositionalRequiredRest2Pass(t *testing.T) { 110 | var opts = struct { 111 | Value bool `short:"v"` 112 | 113 | Positional struct { 114 | Rest []string `required:"2"` 115 | } `positional-args:"yes"` 116 | }{} 117 | 118 | p := NewParser(&opts, None) 119 | _, err := p.ParseArgs([]string{"rest1", "rest2", "rest3"}) 120 | 121 | if err != nil { 122 | t.Fatalf("Unexpected error: %v", err) 123 | return 124 | } 125 | 126 | if len(opts.Positional.Rest) != 3 { 127 | t.Fatalf("Expected 3 positional rest argument") 128 | } 129 | 130 | assertString(t, opts.Positional.Rest[0], "rest1") 131 | assertString(t, opts.Positional.Rest[1], "rest2") 132 | assertString(t, opts.Positional.Rest[2], "rest3") 133 | } 134 | -------------------------------------------------------------------------------- /vendor/github.com/jessevdk/go-flags/check_crosscompile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | echo '# linux arm7' 6 | GOARM=7 GOARCH=arm GOOS=linux go build 7 | echo '# linux arm5' 8 | GOARM=5 GOARCH=arm GOOS=linux go build 9 | echo '# windows 386' 10 | GOARCH=386 GOOS=windows go build 11 | echo '# windows amd64' 12 | GOARCH=amd64 GOOS=windows go build 13 | echo '# darwin' 14 | GOARCH=amd64 GOOS=darwin go build 15 | echo '# freebsd' 16 | GOARCH=amd64 GOOS=freebsd go build 17 | -------------------------------------------------------------------------------- /vendor/github.com/jessevdk/go-flags/closest.go: -------------------------------------------------------------------------------- 1 | package flags 2 | 3 | func levenshtein(s string, t string) int { 4 | if len(s) == 0 { 5 | return len(t) 6 | } 7 | 8 | if len(t) == 0 { 9 | return len(s) 10 | } 11 | 12 | dists := make([][]int, len(s)+1) 13 | for i := range dists { 14 | dists[i] = make([]int, len(t)+1) 15 | dists[i][0] = i 16 | } 17 | 18 | for j := range t { 19 | dists[0][j] = j 20 | } 21 | 22 | for i, sc := range s { 23 | for j, tc := range t { 24 | if sc == tc { 25 | dists[i+1][j+1] = dists[i][j] 26 | } else { 27 | dists[i+1][j+1] = dists[i][j] + 1 28 | if dists[i+1][j] < dists[i+1][j+1] { 29 | dists[i+1][j+1] = dists[i+1][j] + 1 30 | } 31 | if dists[i][j+1] < dists[i+1][j+1] { 32 | dists[i+1][j+1] = dists[i][j+1] + 1 33 | } 34 | } 35 | } 36 | } 37 | 38 | return dists[len(s)][len(t)] 39 | } 40 | 41 | func closestChoice(cmd string, choices []string) (string, int) { 42 | if len(choices) == 0 { 43 | return "", 0 44 | } 45 | 46 | mincmd := -1 47 | mindist := -1 48 | 49 | for i, c := range choices { 50 | l := levenshtein(cmd, c) 51 | 52 | if mincmd < 0 || l < mindist { 53 | mindist = l 54 | mincmd = i 55 | } 56 | } 57 | 58 | return choices[mincmd], mindist 59 | } 60 | -------------------------------------------------------------------------------- /vendor/github.com/jessevdk/go-flags/convert_test.go: -------------------------------------------------------------------------------- 1 | package flags 2 | 3 | import ( 4 | "testing" 5 | "time" 6 | ) 7 | 8 | func expectConvert(t *testing.T, o *Option, expected string) { 9 | s, err := convertToString(o.value, o.tag) 10 | 11 | if err != nil { 12 | t.Errorf("Unexpected error: %v", err) 13 | return 14 | } 15 | 16 | assertString(t, s, expected) 17 | } 18 | 19 | func TestConvertToString(t *testing.T) { 20 | d, _ := time.ParseDuration("1h2m4s") 21 | 22 | var opts = struct { 23 | String string `long:"string"` 24 | 25 | Int int `long:"int"` 26 | Int8 int8 `long:"int8"` 27 | Int16 int16 `long:"int16"` 28 | Int32 int32 `long:"int32"` 29 | Int64 int64 `long:"int64"` 30 | 31 | Uint uint `long:"uint"` 32 | Uint8 uint8 `long:"uint8"` 33 | Uint16 uint16 `long:"uint16"` 34 | Uint32 uint32 `long:"uint32"` 35 | Uint64 uint64 `long:"uint64"` 36 | 37 | Float32 float32 `long:"float32"` 38 | Float64 float64 `long:"float64"` 39 | 40 | Duration time.Duration `long:"duration"` 41 | 42 | Bool bool `long:"bool"` 43 | 44 | IntSlice []int `long:"int-slice"` 45 | IntFloatMap map[int]float64 `long:"int-float-map"` 46 | 47 | PtrBool *bool `long:"ptr-bool"` 48 | Interface interface{} `long:"interface"` 49 | 50 | Int32Base int32 `long:"int32-base" base:"16"` 51 | Uint32Base uint32 `long:"uint32-base" base:"16"` 52 | }{ 53 | "string", 54 | 55 | -2, 56 | -1, 57 | 0, 58 | 1, 59 | 2, 60 | 61 | 1, 62 | 2, 63 | 3, 64 | 4, 65 | 5, 66 | 67 | 1.2, 68 | -3.4, 69 | 70 | d, 71 | true, 72 | 73 | []int{-3, 4, -2}, 74 | map[int]float64{-2: 4.5}, 75 | 76 | new(bool), 77 | float32(5.2), 78 | 79 | -5823, 80 | 4232, 81 | } 82 | 83 | p := NewNamedParser("test", Default) 84 | grp, _ := p.AddGroup("test group", "", &opts) 85 | 86 | expects := []string{ 87 | "string", 88 | "-2", 89 | "-1", 90 | "0", 91 | "1", 92 | "2", 93 | 94 | "1", 95 | "2", 96 | "3", 97 | "4", 98 | "5", 99 | 100 | "1.2", 101 | "-3.4", 102 | 103 | "1h2m4s", 104 | "true", 105 | 106 | "[-3, 4, -2]", 107 | "{-2:4.5}", 108 | 109 | "false", 110 | "5.2", 111 | 112 | "-16bf", 113 | "1088", 114 | } 115 | 116 | for i, v := range grp.Options() { 117 | expectConvert(t, v, expects[i]) 118 | } 119 | } 120 | 121 | func TestConvertToStringInvalidIntBase(t *testing.T) { 122 | var opts = struct { 123 | Int int `long:"int" base:"no"` 124 | }{ 125 | 2, 126 | } 127 | 128 | p := NewNamedParser("test", Default) 129 | grp, _ := p.AddGroup("test group", "", &opts) 130 | o := grp.Options()[0] 131 | 132 | _, err := convertToString(o.value, o.tag) 133 | 134 | if err != nil { 135 | err = newErrorf(ErrMarshal, "%v", err) 136 | } 137 | 138 | assertError(t, err, ErrMarshal, "strconv.ParseInt: parsing \"no\": invalid syntax") 139 | } 140 | 141 | func TestConvertToStringInvalidUintBase(t *testing.T) { 142 | var opts = struct { 143 | Uint uint `long:"uint" base:"no"` 144 | }{ 145 | 2, 146 | } 147 | 148 | p := NewNamedParser("test", Default) 149 | grp, _ := p.AddGroup("test group", "", &opts) 150 | o := grp.Options()[0] 151 | 152 | _, err := convertToString(o.value, o.tag) 153 | 154 | if err != nil { 155 | err = newErrorf(ErrMarshal, "%v", err) 156 | } 157 | 158 | assertError(t, err, ErrMarshal, "strconv.ParseInt: parsing \"no\": invalid syntax") 159 | } 160 | -------------------------------------------------------------------------------- /vendor/github.com/jessevdk/go-flags/error.go: -------------------------------------------------------------------------------- 1 | package flags 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | // ErrorType represents the type of error. 8 | type ErrorType uint 9 | 10 | const ( 11 | // ErrUnknown indicates a generic error. 12 | ErrUnknown ErrorType = iota 13 | 14 | // ErrExpectedArgument indicates that an argument was expected. 15 | ErrExpectedArgument 16 | 17 | // ErrUnknownFlag indicates an unknown flag. 18 | ErrUnknownFlag 19 | 20 | // ErrUnknownGroup indicates an unknown group. 21 | ErrUnknownGroup 22 | 23 | // ErrMarshal indicates a marshalling error while converting values. 24 | ErrMarshal 25 | 26 | // ErrHelp indicates that the built-in help was shown (the error 27 | // contains the help message). 28 | ErrHelp 29 | 30 | // ErrNoArgumentForBool indicates that an argument was given for a 31 | // boolean flag (which don't not take any arguments). 32 | ErrNoArgumentForBool 33 | 34 | // ErrRequired indicates that a required flag was not provided. 35 | ErrRequired 36 | 37 | // ErrShortNameTooLong indicates that a short flag name was specified, 38 | // longer than one character. 39 | ErrShortNameTooLong 40 | 41 | // ErrDuplicatedFlag indicates that a short or long flag has been 42 | // defined more than once 43 | ErrDuplicatedFlag 44 | 45 | // ErrTag indicates an error while parsing flag tags. 46 | ErrTag 47 | 48 | // ErrCommandRequired indicates that a command was required but not 49 | // specified 50 | ErrCommandRequired 51 | 52 | // ErrUnknownCommand indicates that an unknown command was specified. 53 | ErrUnknownCommand 54 | 55 | // ErrInvalidChoice indicates an invalid option value which only allows 56 | // a certain number of choices. 57 | ErrInvalidChoice 58 | 59 | // ErrInvalidTag indicates an invalid tag or invalid use of an existing tag 60 | ErrInvalidTag 61 | ) 62 | 63 | func (e ErrorType) String() string { 64 | switch e { 65 | case ErrUnknown: 66 | return "unknown" 67 | case ErrExpectedArgument: 68 | return "expected argument" 69 | case ErrUnknownFlag: 70 | return "unknown flag" 71 | case ErrUnknownGroup: 72 | return "unknown group" 73 | case ErrMarshal: 74 | return "marshal" 75 | case ErrHelp: 76 | return "help" 77 | case ErrNoArgumentForBool: 78 | return "no argument for bool" 79 | case ErrRequired: 80 | return "required" 81 | case ErrShortNameTooLong: 82 | return "short name too long" 83 | case ErrDuplicatedFlag: 84 | return "duplicated flag" 85 | case ErrTag: 86 | return "tag" 87 | case ErrCommandRequired: 88 | return "command required" 89 | case ErrUnknownCommand: 90 | return "unknown command" 91 | case ErrInvalidChoice: 92 | return "invalid choice" 93 | case ErrInvalidTag: 94 | return "invalid tag" 95 | } 96 | 97 | return "unrecognized error type" 98 | } 99 | 100 | // Error represents a parser error. The error returned from Parse is of this 101 | // type. The error contains both a Type and Message. 102 | type Error struct { 103 | // The type of error 104 | Type ErrorType 105 | 106 | // The error message 107 | Message string 108 | } 109 | 110 | // Error returns the error's message 111 | func (e *Error) Error() string { 112 | return e.Message 113 | } 114 | 115 | func newError(tp ErrorType, message string) *Error { 116 | return &Error{ 117 | Type: tp, 118 | Message: message, 119 | } 120 | } 121 | 122 | func newErrorf(tp ErrorType, format string, args ...interface{}) *Error { 123 | return newError(tp, fmt.Sprintf(format, args...)) 124 | } 125 | 126 | func wrapError(err error) *Error { 127 | ret, ok := err.(*Error) 128 | 129 | if !ok { 130 | return newError(ErrUnknown, err.Error()) 131 | } 132 | 133 | return ret 134 | } 135 | -------------------------------------------------------------------------------- /vendor/github.com/jessevdk/go-flags/example_test.go: -------------------------------------------------------------------------------- 1 | // Example of use of the flags package. 2 | package flags 3 | 4 | import ( 5 | "fmt" 6 | "os/exec" 7 | ) 8 | 9 | func Example() { 10 | var opts struct { 11 | // Slice of bool will append 'true' each time the option 12 | // is encountered (can be set multiple times, like -vvv) 13 | Verbose []bool `short:"v" long:"verbose" description:"Show verbose debug information"` 14 | 15 | // Example of automatic marshalling to desired type (uint) 16 | Offset uint `long:"offset" description:"Offset"` 17 | 18 | // Example of a callback, called each time the option is found. 19 | Call func(string) `short:"c" description:"Call phone number"` 20 | 21 | // Example of a required flag 22 | Name string `short:"n" long:"name" description:"A name" required:"true"` 23 | 24 | // Example of a value name 25 | File string `short:"f" long:"file" description:"A file" value-name:"FILE"` 26 | 27 | // Example of a pointer 28 | Ptr *int `short:"p" description:"A pointer to an integer"` 29 | 30 | // Example of a slice of strings 31 | StringSlice []string `short:"s" description:"A slice of strings"` 32 | 33 | // Example of a slice of pointers 34 | PtrSlice []*string `long:"ptrslice" description:"A slice of pointers to string"` 35 | 36 | // Example of a map 37 | IntMap map[string]int `long:"intmap" description:"A map from string to int"` 38 | 39 | // Example of a filename (useful for completion) 40 | Filename Filename `long:"filename" description:"A filename"` 41 | 42 | // Example of positional arguments 43 | Args struct { 44 | Id string 45 | Num int 46 | Rest []string 47 | } `positional-args:"yes" required:"yes"` 48 | } 49 | 50 | // Callback which will invoke callto: to call a number. 51 | // Note that this works just on OS X (and probably only with 52 | // Skype) but it shows the idea. 53 | opts.Call = func(num string) { 54 | cmd := exec.Command("open", "callto:"+num) 55 | cmd.Start() 56 | cmd.Process.Release() 57 | } 58 | 59 | // Make some fake arguments to parse. 60 | args := []string{ 61 | "-vv", 62 | "--offset=5", 63 | "-n", "Me", 64 | "-p", "3", 65 | "-s", "hello", 66 | "-s", "world", 67 | "--ptrslice", "hello", 68 | "--ptrslice", "world", 69 | "--intmap", "a:1", 70 | "--intmap", "b:5", 71 | "--filename", "hello.go", 72 | "id", 73 | "10", 74 | "remaining1", 75 | "remaining2", 76 | } 77 | 78 | // Parse flags from `args'. Note that here we use flags.ParseArgs for 79 | // the sake of making a working example. Normally, you would simply use 80 | // flags.Parse(&opts) which uses os.Args 81 | _, err := ParseArgs(&opts, args) 82 | 83 | if err != nil { 84 | panic(err) 85 | } 86 | 87 | fmt.Printf("Verbosity: %v\n", opts.Verbose) 88 | fmt.Printf("Offset: %d\n", opts.Offset) 89 | fmt.Printf("Name: %s\n", opts.Name) 90 | fmt.Printf("Ptr: %d\n", *opts.Ptr) 91 | fmt.Printf("StringSlice: %v\n", opts.StringSlice) 92 | fmt.Printf("PtrSlice: [%v %v]\n", *opts.PtrSlice[0], *opts.PtrSlice[1]) 93 | fmt.Printf("IntMap: [a:%v b:%v]\n", opts.IntMap["a"], opts.IntMap["b"]) 94 | fmt.Printf("Filename: %v\n", opts.Filename) 95 | fmt.Printf("Args.Id: %s\n", opts.Args.Id) 96 | fmt.Printf("Args.Num: %d\n", opts.Args.Num) 97 | fmt.Printf("Args.Rest: %v\n", opts.Args.Rest) 98 | 99 | // Output: Verbosity: [true true] 100 | // Offset: 5 101 | // Name: Me 102 | // Ptr: 3 103 | // StringSlice: [hello world] 104 | // PtrSlice: [hello world] 105 | // IntMap: [a:1 b:5] 106 | // Filename: hello.go 107 | // Args.Id: id 108 | // Args.Num: 10 109 | // Args.Rest: [remaining1 remaining2] 110 | } 111 | -------------------------------------------------------------------------------- /vendor/github.com/jessevdk/go-flags/long_test.go: -------------------------------------------------------------------------------- 1 | package flags 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestLong(t *testing.T) { 8 | var opts = struct { 9 | Value bool `long:"value"` 10 | }{} 11 | 12 | ret := assertParseSuccess(t, &opts, "--value") 13 | 14 | assertStringArray(t, ret, []string{}) 15 | 16 | if !opts.Value { 17 | t.Errorf("Expected Value to be true") 18 | } 19 | } 20 | 21 | func TestLongArg(t *testing.T) { 22 | var opts = struct { 23 | Value string `long:"value"` 24 | }{} 25 | 26 | ret := assertParseSuccess(t, &opts, "--value", "value") 27 | 28 | assertStringArray(t, ret, []string{}) 29 | assertString(t, opts.Value, "value") 30 | } 31 | 32 | func TestLongArgEqual(t *testing.T) { 33 | var opts = struct { 34 | Value string `long:"value"` 35 | }{} 36 | 37 | ret := assertParseSuccess(t, &opts, "--value=value") 38 | 39 | assertStringArray(t, ret, []string{}) 40 | assertString(t, opts.Value, "value") 41 | } 42 | 43 | func TestLongDefault(t *testing.T) { 44 | var opts = struct { 45 | Value string `long:"value" default:"value"` 46 | }{} 47 | 48 | ret := assertParseSuccess(t, &opts) 49 | 50 | assertStringArray(t, ret, []string{}) 51 | assertString(t, opts.Value, "value") 52 | } 53 | 54 | func TestLongOptional(t *testing.T) { 55 | var opts = struct { 56 | Value string `long:"value" optional:"yes" optional-value:"value"` 57 | }{} 58 | 59 | ret := assertParseSuccess(t, &opts, "--value") 60 | 61 | assertStringArray(t, ret, []string{}) 62 | assertString(t, opts.Value, "value") 63 | } 64 | 65 | func TestLongOptionalArg(t *testing.T) { 66 | var opts = struct { 67 | Value string `long:"value" optional:"yes" optional-value:"value"` 68 | }{} 69 | 70 | ret := assertParseSuccess(t, &opts, "--value", "no") 71 | 72 | assertStringArray(t, ret, []string{"no"}) 73 | assertString(t, opts.Value, "value") 74 | } 75 | 76 | func TestLongOptionalArgEqual(t *testing.T) { 77 | var opts = struct { 78 | Value string `long:"value" optional:"yes" optional-value:"value"` 79 | }{} 80 | 81 | ret := assertParseSuccess(t, &opts, "--value=value", "no") 82 | 83 | assertStringArray(t, ret, []string{"no"}) 84 | assertString(t, opts.Value, "value") 85 | } 86 | -------------------------------------------------------------------------------- /vendor/github.com/jessevdk/go-flags/marshal_test.go: -------------------------------------------------------------------------------- 1 | package flags 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | ) 7 | 8 | type marshalled string 9 | 10 | func (m *marshalled) UnmarshalFlag(value string) error { 11 | if value == "yes" { 12 | *m = "true" 13 | } else if value == "no" { 14 | *m = "false" 15 | } else { 16 | return fmt.Errorf("`%s' is not a valid value, please specify `yes' or `no'", value) 17 | } 18 | 19 | return nil 20 | } 21 | 22 | func (m marshalled) MarshalFlag() (string, error) { 23 | if m == "true" { 24 | return "yes", nil 25 | } 26 | 27 | return "no", nil 28 | } 29 | 30 | type marshalledError bool 31 | 32 | func (m marshalledError) MarshalFlag() (string, error) { 33 | return "", newErrorf(ErrMarshal, "Failed to marshal") 34 | } 35 | 36 | func TestUnmarshal(t *testing.T) { 37 | var opts = struct { 38 | Value marshalled `short:"v"` 39 | }{} 40 | 41 | ret := assertParseSuccess(t, &opts, "-v=yes") 42 | 43 | assertStringArray(t, ret, []string{}) 44 | 45 | if opts.Value != "true" { 46 | t.Errorf("Expected Value to be \"true\"") 47 | } 48 | } 49 | 50 | func TestUnmarshalDefault(t *testing.T) { 51 | var opts = struct { 52 | Value marshalled `short:"v" default:"yes"` 53 | }{} 54 | 55 | ret := assertParseSuccess(t, &opts) 56 | 57 | assertStringArray(t, ret, []string{}) 58 | 59 | if opts.Value != "true" { 60 | t.Errorf("Expected Value to be \"true\"") 61 | } 62 | } 63 | 64 | func TestUnmarshalOptional(t *testing.T) { 65 | var opts = struct { 66 | Value marshalled `short:"v" optional:"yes" optional-value:"yes"` 67 | }{} 68 | 69 | ret := assertParseSuccess(t, &opts, "-v") 70 | 71 | assertStringArray(t, ret, []string{}) 72 | 73 | if opts.Value != "true" { 74 | t.Errorf("Expected Value to be \"true\"") 75 | } 76 | } 77 | 78 | func TestUnmarshalError(t *testing.T) { 79 | var opts = struct { 80 | Value marshalled `short:"v"` 81 | }{} 82 | 83 | assertParseFail(t, ErrMarshal, fmt.Sprintf("invalid argument for flag `%cv' (expected flags.marshalled): `invalid' is not a valid value, please specify `yes' or `no'", defaultShortOptDelimiter), &opts, "-vinvalid") 84 | } 85 | 86 | func TestMarshalError(t *testing.T) { 87 | var opts = struct { 88 | Value marshalledError `short:"v"` 89 | }{} 90 | 91 | p := NewParser(&opts, Default) 92 | o := p.Command.Groups()[0].Options()[0] 93 | 94 | _, err := convertToString(o.value, o.tag) 95 | 96 | assertError(t, err, ErrMarshal, "Failed to marshal") 97 | } 98 | -------------------------------------------------------------------------------- /vendor/github.com/jessevdk/go-flags/multitag.go: -------------------------------------------------------------------------------- 1 | package flags 2 | 3 | import ( 4 | "strconv" 5 | ) 6 | 7 | type multiTag struct { 8 | value string 9 | cache map[string][]string 10 | } 11 | 12 | func newMultiTag(v string) multiTag { 13 | return multiTag{ 14 | value: v, 15 | } 16 | } 17 | 18 | func (x *multiTag) scan() (map[string][]string, error) { 19 | v := x.value 20 | 21 | ret := make(map[string][]string) 22 | 23 | // This is mostly copied from reflect.StructTag.Get 24 | for v != "" { 25 | i := 0 26 | 27 | // Skip whitespace 28 | for i < len(v) && v[i] == ' ' { 29 | i++ 30 | } 31 | 32 | v = v[i:] 33 | 34 | if v == "" { 35 | break 36 | } 37 | 38 | // Scan to colon to find key 39 | i = 0 40 | 41 | for i < len(v) && v[i] != ' ' && v[i] != ':' && v[i] != '"' { 42 | i++ 43 | } 44 | 45 | if i >= len(v) { 46 | return nil, newErrorf(ErrTag, "expected `:' after key name, but got end of tag (in `%v`)", x.value) 47 | } 48 | 49 | if v[i] != ':' { 50 | return nil, newErrorf(ErrTag, "expected `:' after key name, but got `%v' (in `%v`)", v[i], x.value) 51 | } 52 | 53 | if i+1 >= len(v) { 54 | return nil, newErrorf(ErrTag, "expected `\"' to start tag value at end of tag (in `%v`)", x.value) 55 | } 56 | 57 | if v[i+1] != '"' { 58 | return nil, newErrorf(ErrTag, "expected `\"' to start tag value, but got `%v' (in `%v`)", v[i+1], x.value) 59 | } 60 | 61 | name := v[:i] 62 | v = v[i+1:] 63 | 64 | // Scan quoted string to find value 65 | i = 1 66 | 67 | for i < len(v) && v[i] != '"' { 68 | if v[i] == '\n' { 69 | return nil, newErrorf(ErrTag, "unexpected newline in tag value `%v' (in `%v`)", name, x.value) 70 | } 71 | 72 | if v[i] == '\\' { 73 | i++ 74 | } 75 | i++ 76 | } 77 | 78 | if i >= len(v) { 79 | return nil, newErrorf(ErrTag, "expected end of tag value `\"' at end of tag (in `%v`)", x.value) 80 | } 81 | 82 | val, err := strconv.Unquote(v[:i+1]) 83 | 84 | if err != nil { 85 | return nil, newErrorf(ErrTag, "Malformed value of tag `%v:%v` => %v (in `%v`)", name, v[:i+1], err, x.value) 86 | } 87 | 88 | v = v[i+1:] 89 | 90 | ret[name] = append(ret[name], val) 91 | } 92 | 93 | return ret, nil 94 | } 95 | 96 | func (x *multiTag) Parse() error { 97 | vals, err := x.scan() 98 | x.cache = vals 99 | 100 | return err 101 | } 102 | 103 | func (x *multiTag) cached() map[string][]string { 104 | if x.cache == nil { 105 | cache, _ := x.scan() 106 | 107 | if cache == nil { 108 | cache = make(map[string][]string) 109 | } 110 | 111 | x.cache = cache 112 | } 113 | 114 | return x.cache 115 | } 116 | 117 | func (x *multiTag) Get(key string) string { 118 | c := x.cached() 119 | 120 | if v, ok := c[key]; ok { 121 | return v[len(v)-1] 122 | } 123 | 124 | return "" 125 | } 126 | 127 | func (x *multiTag) GetMany(key string) []string { 128 | c := x.cached() 129 | return c[key] 130 | } 131 | 132 | func (x *multiTag) Set(key string, value string) { 133 | c := x.cached() 134 | c[key] = []string{value} 135 | } 136 | 137 | func (x *multiTag) SetMany(key string, value []string) { 138 | c := x.cached() 139 | c[key] = value 140 | } 141 | -------------------------------------------------------------------------------- /vendor/github.com/jessevdk/go-flags/options_test.go: -------------------------------------------------------------------------------- 1 | package flags 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestPassDoubleDash(t *testing.T) { 8 | var opts = struct { 9 | Value bool `short:"v"` 10 | }{} 11 | 12 | p := NewParser(&opts, PassDoubleDash) 13 | ret, err := p.ParseArgs([]string{"-v", "--", "-v", "-g"}) 14 | 15 | if err != nil { 16 | t.Fatalf("Unexpected error: %v", err) 17 | return 18 | } 19 | 20 | if !opts.Value { 21 | t.Errorf("Expected Value to be true") 22 | } 23 | 24 | assertStringArray(t, ret, []string{"-v", "-g"}) 25 | } 26 | 27 | func TestPassAfterNonOption(t *testing.T) { 28 | var opts = struct { 29 | Value bool `short:"v"` 30 | }{} 31 | 32 | p := NewParser(&opts, PassAfterNonOption) 33 | ret, err := p.ParseArgs([]string{"-v", "arg", "-v", "-g"}) 34 | 35 | if err != nil { 36 | t.Fatalf("Unexpected error: %v", err) 37 | return 38 | } 39 | 40 | if !opts.Value { 41 | t.Errorf("Expected Value to be true") 42 | } 43 | 44 | assertStringArray(t, ret, []string{"arg", "-v", "-g"}) 45 | } 46 | -------------------------------------------------------------------------------- /vendor/github.com/jessevdk/go-flags/optstyle_other.go: -------------------------------------------------------------------------------- 1 | // +build !windows 2 | 3 | package flags 4 | 5 | import ( 6 | "strings" 7 | ) 8 | 9 | const ( 10 | defaultShortOptDelimiter = '-' 11 | defaultLongOptDelimiter = "--" 12 | defaultNameArgDelimiter = '=' 13 | ) 14 | 15 | func argumentStartsOption(arg string) bool { 16 | return len(arg) > 0 && arg[0] == '-' 17 | } 18 | 19 | func argumentIsOption(arg string) bool { 20 | if len(arg) > 1 && arg[0] == '-' && arg[1] != '-' { 21 | return true 22 | } 23 | 24 | if len(arg) > 2 && arg[0] == '-' && arg[1] == '-' && arg[2] != '-' { 25 | return true 26 | } 27 | 28 | return false 29 | } 30 | 31 | // stripOptionPrefix returns the option without the prefix and whether or 32 | // not the option is a long option or not. 33 | func stripOptionPrefix(optname string) (prefix string, name string, islong bool) { 34 | if strings.HasPrefix(optname, "--") { 35 | return "--", optname[2:], true 36 | } else if strings.HasPrefix(optname, "-") { 37 | return "-", optname[1:], false 38 | } 39 | 40 | return "", optname, false 41 | } 42 | 43 | // splitOption attempts to split the passed option into a name and an argument. 44 | // When there is no argument specified, nil will be returned for it. 45 | func splitOption(prefix string, option string, islong bool) (string, string, *string) { 46 | pos := strings.Index(option, "=") 47 | 48 | if (islong && pos >= 0) || (!islong && pos == 1) { 49 | rest := option[pos+1:] 50 | return option[:pos], "=", &rest 51 | } 52 | 53 | return option, "", nil 54 | } 55 | 56 | // addHelpGroup adds a new group that contains default help parameters. 57 | func (c *Command) addHelpGroup(showHelp func() error) *Group { 58 | var help struct { 59 | ShowHelp func() error `short:"h" long:"help" description:"Show this help message"` 60 | } 61 | 62 | help.ShowHelp = showHelp 63 | ret, _ := c.AddGroup("Help Options", "", &help) 64 | ret.isBuiltinHelp = true 65 | 66 | return ret 67 | } 68 | -------------------------------------------------------------------------------- /vendor/github.com/jessevdk/go-flags/optstyle_windows.go: -------------------------------------------------------------------------------- 1 | package flags 2 | 3 | import ( 4 | "strings" 5 | ) 6 | 7 | // Windows uses a front slash for both short and long options. Also it uses 8 | // a colon for name/argument delimter. 9 | const ( 10 | defaultShortOptDelimiter = '/' 11 | defaultLongOptDelimiter = "/" 12 | defaultNameArgDelimiter = ':' 13 | ) 14 | 15 | func argumentStartsOption(arg string) bool { 16 | return len(arg) > 0 && (arg[0] == '-' || arg[0] == '/') 17 | } 18 | 19 | func argumentIsOption(arg string) bool { 20 | // Windows-style options allow front slash for the option 21 | // delimiter. 22 | if len(arg) > 1 && arg[0] == '/' { 23 | return true 24 | } 25 | 26 | if len(arg) > 1 && arg[0] == '-' && arg[1] != '-' { 27 | return true 28 | } 29 | 30 | if len(arg) > 2 && arg[0] == '-' && arg[1] == '-' && arg[2] != '-' { 31 | return true 32 | } 33 | 34 | return false 35 | } 36 | 37 | // stripOptionPrefix returns the option without the prefix and whether or 38 | // not the option is a long option or not. 39 | func stripOptionPrefix(optname string) (prefix string, name string, islong bool) { 40 | // Determine if the argument is a long option or not. Windows 41 | // typically supports both long and short options with a single 42 | // front slash as the option delimiter, so handle this situation 43 | // nicely. 44 | possplit := 0 45 | 46 | if strings.HasPrefix(optname, "--") { 47 | possplit = 2 48 | islong = true 49 | } else if strings.HasPrefix(optname, "-") { 50 | possplit = 1 51 | islong = false 52 | } else if strings.HasPrefix(optname, "/") { 53 | possplit = 1 54 | islong = len(optname) > 2 55 | } 56 | 57 | return optname[:possplit], optname[possplit:], islong 58 | } 59 | 60 | // splitOption attempts to split the passed option into a name and an argument. 61 | // When there is no argument specified, nil will be returned for it. 62 | func splitOption(prefix string, option string, islong bool) (string, string, *string) { 63 | if len(option) == 0 { 64 | return option, "", nil 65 | } 66 | 67 | // Windows typically uses a colon for the option name and argument 68 | // delimiter while POSIX typically uses an equals. Support both styles, 69 | // but don't allow the two to be mixed. That is to say /foo:bar and 70 | // --foo=bar are acceptable, but /foo=bar and --foo:bar are not. 71 | var pos int 72 | var sp string 73 | 74 | if prefix == "/" { 75 | sp = ":" 76 | pos = strings.Index(option, sp) 77 | } else if len(prefix) > 0 { 78 | sp = "=" 79 | pos = strings.Index(option, sp) 80 | } 81 | 82 | if (islong && pos >= 0) || (!islong && pos == 1) { 83 | rest := option[pos+1:] 84 | return option[:pos], sp, &rest 85 | } 86 | 87 | return option, "", nil 88 | } 89 | 90 | // addHelpGroup adds a new group that contains default help parameters. 91 | func (c *Command) addHelpGroup(showHelp func() error) *Group { 92 | // Windows CLI applications typically use /? for help, so make both 93 | // that available as well as the POSIX style h and help. 94 | var help struct { 95 | ShowHelpWindows func() error `short:"?" description:"Show this help message"` 96 | ShowHelpPosix func() error `short:"h" long:"help" description:"Show this help message"` 97 | } 98 | 99 | help.ShowHelpWindows = showHelp 100 | help.ShowHelpPosix = showHelp 101 | 102 | ret, _ := c.AddGroup("Help Options", "", &help) 103 | ret.isBuiltinHelp = true 104 | 105 | return ret 106 | } 107 | -------------------------------------------------------------------------------- /vendor/github.com/jessevdk/go-flags/pointer_test.go: -------------------------------------------------------------------------------- 1 | package flags 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestPointerBool(t *testing.T) { 8 | var opts = struct { 9 | Value *bool `short:"v"` 10 | }{} 11 | 12 | ret := assertParseSuccess(t, &opts, "-v") 13 | 14 | assertStringArray(t, ret, []string{}) 15 | 16 | if !*opts.Value { 17 | t.Errorf("Expected Value to be true") 18 | } 19 | } 20 | 21 | func TestPointerString(t *testing.T) { 22 | var opts = struct { 23 | Value *string `short:"v"` 24 | }{} 25 | 26 | ret := assertParseSuccess(t, &opts, "-v", "value") 27 | 28 | assertStringArray(t, ret, []string{}) 29 | assertString(t, *opts.Value, "value") 30 | } 31 | 32 | func TestPointerSlice(t *testing.T) { 33 | var opts = struct { 34 | Value *[]string `short:"v"` 35 | }{} 36 | 37 | ret := assertParseSuccess(t, &opts, "-v", "value1", "-v", "value2") 38 | 39 | assertStringArray(t, ret, []string{}) 40 | assertStringArray(t, *opts.Value, []string{"value1", "value2"}) 41 | } 42 | 43 | func TestPointerMap(t *testing.T) { 44 | var opts = struct { 45 | Value *map[string]int `short:"v"` 46 | }{} 47 | 48 | ret := assertParseSuccess(t, &opts, "-v", "k1:2", "-v", "k2:-5") 49 | 50 | assertStringArray(t, ret, []string{}) 51 | 52 | if v, ok := (*opts.Value)["k1"]; !ok { 53 | t.Errorf("Expected key \"k1\" to exist") 54 | } else if v != 2 { 55 | t.Errorf("Expected \"k1\" to be 2, but got %#v", v) 56 | } 57 | 58 | if v, ok := (*opts.Value)["k2"]; !ok { 59 | t.Errorf("Expected key \"k2\" to exist") 60 | } else if v != -5 { 61 | t.Errorf("Expected \"k2\" to be -5, but got %#v", v) 62 | } 63 | } 64 | 65 | type PointerGroup struct { 66 | Value bool `short:"v"` 67 | } 68 | 69 | func TestPointerGroup(t *testing.T) { 70 | var opts = struct { 71 | Group *PointerGroup `group:"Group Options"` 72 | }{} 73 | 74 | ret := assertParseSuccess(t, &opts, "-v") 75 | 76 | assertStringArray(t, ret, []string{}) 77 | 78 | if !opts.Group.Value { 79 | t.Errorf("Expected Group.Value to be true") 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /vendor/github.com/jessevdk/go-flags/tag_test.go: -------------------------------------------------------------------------------- 1 | package flags 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestTagMissingColon(t *testing.T) { 8 | var opts = struct { 9 | Value bool `short` 10 | }{} 11 | 12 | assertParseFail(t, ErrTag, "expected `:' after key name, but got end of tag (in `short`)", &opts, "") 13 | } 14 | 15 | func TestTagMissingValue(t *testing.T) { 16 | var opts = struct { 17 | Value bool `short:` 18 | }{} 19 | 20 | assertParseFail(t, ErrTag, "expected `\"' to start tag value at end of tag (in `short:`)", &opts, "") 21 | } 22 | 23 | func TestTagMissingQuote(t *testing.T) { 24 | var opts = struct { 25 | Value bool `short:"v` 26 | }{} 27 | 28 | assertParseFail(t, ErrTag, "expected end of tag value `\"' at end of tag (in `short:\"v`)", &opts, "") 29 | } 30 | 31 | func TestTagNewline(t *testing.T) { 32 | var opts = struct { 33 | Value bool `long:"verbose" description:"verbose 34 | something"` 35 | }{} 36 | 37 | assertParseFail(t, ErrTag, "unexpected newline in tag value `description' (in `long:\"verbose\" description:\"verbose\nsomething\"`)", &opts, "") 38 | } 39 | -------------------------------------------------------------------------------- /vendor/github.com/jessevdk/go-flags/termsize.go: -------------------------------------------------------------------------------- 1 | // +build !windows,!plan9,!solaris 2 | 3 | package flags 4 | 5 | import ( 6 | "syscall" 7 | "unsafe" 8 | ) 9 | 10 | type winsize struct { 11 | row, col uint16 12 | xpixel, ypixel uint16 13 | } 14 | 15 | func getTerminalColumns() int { 16 | ws := winsize{} 17 | 18 | if tIOCGWINSZ != 0 { 19 | syscall.Syscall(syscall.SYS_IOCTL, 20 | uintptr(0), 21 | uintptr(tIOCGWINSZ), 22 | uintptr(unsafe.Pointer(&ws))) 23 | 24 | return int(ws.col) 25 | } 26 | 27 | return 80 28 | } 29 | -------------------------------------------------------------------------------- /vendor/github.com/jessevdk/go-flags/termsize_linux.go: -------------------------------------------------------------------------------- 1 | // +build linux 2 | 3 | package flags 4 | 5 | const ( 6 | tIOCGWINSZ = 0x5413 7 | ) 8 | -------------------------------------------------------------------------------- /vendor/github.com/jessevdk/go-flags/termsize_nosysioctl.go: -------------------------------------------------------------------------------- 1 | // +build windows plan9 solaris 2 | 3 | package flags 4 | 5 | func getTerminalColumns() int { 6 | return 80 7 | } 8 | -------------------------------------------------------------------------------- /vendor/github.com/jessevdk/go-flags/termsize_other.go: -------------------------------------------------------------------------------- 1 | // +build !darwin,!freebsd,!netbsd,!openbsd,!linux 2 | 3 | package flags 4 | 5 | const ( 6 | tIOCGWINSZ = 0 7 | ) 8 | -------------------------------------------------------------------------------- /vendor/github.com/jessevdk/go-flags/termsize_unix.go: -------------------------------------------------------------------------------- 1 | // +build darwin freebsd netbsd openbsd 2 | 3 | package flags 4 | 5 | const ( 6 | tIOCGWINSZ = 0x40087468 7 | ) 8 | -------------------------------------------------------------------------------- /vendor/github.com/jessevdk/go-flags/unknown_test.go: -------------------------------------------------------------------------------- 1 | package flags 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestUnknownFlags(t *testing.T) { 8 | var opts = struct { 9 | Verbose []bool `short:"v" long:"verbose" description:"Verbose output"` 10 | }{} 11 | 12 | args := []string{ 13 | "-f", 14 | } 15 | 16 | p := NewParser(&opts, 0) 17 | args, err := p.ParseArgs(args) 18 | 19 | if err == nil { 20 | t.Fatal("Expected error for unknown argument") 21 | } 22 | } 23 | 24 | func TestIgnoreUnknownFlags(t *testing.T) { 25 | var opts = struct { 26 | Verbose []bool `short:"v" long:"verbose" description:"Verbose output"` 27 | }{} 28 | 29 | args := []string{ 30 | "hello", 31 | "world", 32 | "-v", 33 | "--foo=bar", 34 | "--verbose", 35 | "-f", 36 | } 37 | 38 | p := NewParser(&opts, IgnoreUnknown) 39 | args, err := p.ParseArgs(args) 40 | 41 | if err != nil { 42 | t.Fatal(err) 43 | } 44 | 45 | exargs := []string{ 46 | "hello", 47 | "world", 48 | "--foo=bar", 49 | "-f", 50 | } 51 | 52 | issame := (len(args) == len(exargs)) 53 | 54 | if issame { 55 | for i := 0; i < len(args); i++ { 56 | if args[i] != exargs[i] { 57 | issame = false 58 | break 59 | } 60 | } 61 | } 62 | 63 | if !issame { 64 | t.Fatalf("Expected %v but got %v", exargs, args) 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /vendor/github.com/klauspost/compress/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 The Go Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /vendor/github.com/klauspost/compress/flate/copy.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package flate 6 | 7 | // forwardCopy is like the built-in copy function except that it always goes 8 | // forward from the start, even if the dst and src overlap. 9 | // It is equivalent to: 10 | // for i := 0; i < n; i++ { 11 | // mem[dst+i] = mem[src+i] 12 | // } 13 | func forwardCopy(mem []byte, dst, src, n int) { 14 | if dst <= src { 15 | copy(mem[dst:dst+n], mem[src:src+n]) 16 | return 17 | } 18 | for { 19 | if dst >= src+n { 20 | copy(mem[dst:dst+n], mem[src:src+n]) 21 | return 22 | } 23 | // There is some forward overlap. The destination 24 | // will be filled with a repeated pattern of mem[src:src+k]. 25 | // We copy one instance of the pattern here, then repeat. 26 | // Each time around this loop k will double. 27 | k := dst - src 28 | copy(mem[dst:dst+k], mem[src:src+k]) 29 | n -= k 30 | dst += k 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /vendor/github.com/klauspost/compress/flate/copy_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package flate 6 | 7 | import ( 8 | "testing" 9 | ) 10 | 11 | func TestForwardCopy(t *testing.T) { 12 | testCases := []struct { 13 | dst0, dst1 int 14 | src0, src1 int 15 | want string 16 | }{ 17 | {0, 9, 0, 9, "012345678"}, 18 | {0, 5, 4, 9, "45678"}, 19 | {4, 9, 0, 5, "01230"}, 20 | {1, 6, 3, 8, "34567"}, 21 | {3, 8, 1, 6, "12121"}, 22 | {0, 9, 3, 6, "345"}, 23 | {3, 6, 0, 9, "012"}, 24 | {1, 6, 0, 9, "00000"}, 25 | {0, 4, 7, 8, "7"}, 26 | {0, 1, 6, 8, "6"}, 27 | {4, 4, 6, 9, ""}, 28 | {2, 8, 6, 6, ""}, 29 | {0, 0, 0, 0, ""}, 30 | } 31 | for _, tc := range testCases { 32 | b := []byte("0123456789") 33 | n := tc.dst1 - tc.dst0 34 | if tc.src1-tc.src0 < n { 35 | n = tc.src1 - tc.src0 36 | } 37 | forwardCopy(b, tc.dst0, tc.src0, n) 38 | got := string(b[tc.dst0 : tc.dst0+n]) 39 | if got != tc.want { 40 | t.Errorf("dst=b[%d:%d], src=b[%d:%d]: got %q, want %q", 41 | tc.dst0, tc.dst1, tc.src0, tc.src1, got, tc.want) 42 | } 43 | // Check that the bytes outside of dst[:n] were not modified. 44 | for i, x := range b { 45 | if i >= tc.dst0 && i < tc.dst0+n { 46 | continue 47 | } 48 | if int(x) != '0'+i { 49 | t.Errorf("dst=b[%d:%d], src=b[%d:%d]: copy overrun at b[%d]: got '%c', want '%c'", 50 | tc.dst0, tc.dst1, tc.src0, tc.src1, i, x, '0'+i) 51 | } 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /vendor/github.com/klauspost/compress/flate/crc32_amd64.go: -------------------------------------------------------------------------------- 1 | //+build !noasm 2 | //+build !appengine 3 | 4 | // Copyright 2015, Klaus Post, see LICENSE for details. 5 | 6 | package flate 7 | 8 | import ( 9 | "github.com/klauspost/cpuid" 10 | ) 11 | 12 | // crc32sse returns a hash for the first 4 bytes of the slice 13 | // len(a) must be >= 4. 14 | //go:noescape 15 | func crc32sse(a []byte) hash 16 | 17 | // crc32sseAll calculates hashes for each 4-byte set in a. 18 | // dst must be east len(a) - 4 in size. 19 | // The size is not checked by the assembly. 20 | //go:noescape 21 | func crc32sseAll(a []byte, dst []hash) 22 | 23 | // matchLenSSE4 returns the number of matching bytes in a and b 24 | // up to length 'max'. Both slices must be at least 'max' 25 | // bytes in size. 26 | // It uses the PCMPESTRI SSE 4.2 instruction. 27 | //go:noescape 28 | func matchLenSSE4(a, b []byte, max int) int 29 | 30 | // histogram accumulates a histogram of b in h. 31 | // h must be at least 256 entries in length, 32 | // and must be cleared before calling this function. 33 | //go:noescape 34 | func histogram(b []byte, h []int32) 35 | 36 | // Detect SSE 4.2 feature. 37 | func init() { 38 | useSSE42 = cpuid.CPU.SSE42() 39 | } 40 | -------------------------------------------------------------------------------- /vendor/github.com/klauspost/compress/flate/crc32_noasm.go: -------------------------------------------------------------------------------- 1 | //+build !amd64 noasm appengine 2 | 3 | // Copyright 2015, Klaus Post, see LICENSE for details. 4 | 5 | package flate 6 | 7 | func init() { 8 | useSSE42 = false 9 | } 10 | 11 | // crc32sse should never be called. 12 | func crc32sse(a []byte) hash { 13 | panic("no assembler") 14 | } 15 | 16 | // crc32sseAll should never be called. 17 | func crc32sseAll(a []byte, dst []hash) { 18 | panic("no assembler") 19 | } 20 | 21 | // matchLenSSE4 should never be called. 22 | func matchLenSSE4(a, b []byte, max int) int { 23 | panic("no assembler") 24 | return 0 25 | } 26 | 27 | // histogram accumulates a histogram of b in h. 28 | // h must be at least 256 entries in length, 29 | // and must be cleared before calling this function. 30 | func histogram(b []byte, h []int32) { 31 | for _, t := range b { 32 | h[t]++ 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /vendor/github.com/klauspost/compress/flate/reader_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package flate 6 | 7 | import ( 8 | "bytes" 9 | "io" 10 | "io/ioutil" 11 | "runtime" 12 | "strings" 13 | "testing" 14 | ) 15 | 16 | func TestNlitOutOfRange(t *testing.T) { 17 | // Trying to decode this bogus flate data, which has a Huffman table 18 | // with nlit=288, should not panic. 19 | io.Copy(ioutil.Discard, NewReader(strings.NewReader( 20 | "\xfc\xfe\x36\xe7\x5e\x1c\xef\xb3\x55\x58\x77\xb6\x56\xb5\x43\xf4"+ 21 | "\x6f\xf2\xd2\xe6\x3d\x99\xa0\x85\x8c\x48\xeb\xf8\xda\x83\x04\x2a"+ 22 | "\x75\xc4\xf8\x0f\x12\x11\xb9\xb4\x4b\x09\xa0\xbe\x8b\x91\x4c"))) 23 | } 24 | 25 | const ( 26 | digits = iota 27 | twain 28 | ) 29 | 30 | var testfiles = []string{ 31 | // Digits is the digits of the irrational number e. Its decimal representation 32 | // does not repeat, but there are only 10 possible digits, so it should be 33 | // reasonably compressible. 34 | digits: "../testdata/e.txt", 35 | // Twain is Project Gutenberg's edition of Mark Twain's classic English novel. 36 | twain: "../testdata/Mark.Twain-Tom.Sawyer.txt", 37 | } 38 | 39 | func benchmarkDecode(b *testing.B, testfile, level, n int) { 40 | b.ReportAllocs() 41 | b.StopTimer() 42 | b.SetBytes(int64(n)) 43 | buf0, err := ioutil.ReadFile(testfiles[testfile]) 44 | if err != nil { 45 | b.Fatal(err) 46 | } 47 | if len(buf0) == 0 { 48 | b.Fatalf("test file %q has no data", testfiles[testfile]) 49 | } 50 | compressed := new(bytes.Buffer) 51 | w, err := NewWriter(compressed, level) 52 | if err != nil { 53 | b.Fatal(err) 54 | } 55 | for i := 0; i < n; i += len(buf0) { 56 | if len(buf0) > n-i { 57 | buf0 = buf0[:n-i] 58 | } 59 | io.Copy(w, bytes.NewReader(buf0)) 60 | } 61 | w.Close() 62 | buf1 := compressed.Bytes() 63 | buf0, compressed, w = nil, nil, nil 64 | runtime.GC() 65 | b.StartTimer() 66 | for i := 0; i < b.N; i++ { 67 | io.Copy(ioutil.Discard, NewReader(bytes.NewReader(buf1))) 68 | } 69 | } 70 | 71 | // These short names are so that gofmt doesn't break the BenchmarkXxx function 72 | // bodies below over multiple lines. 73 | const ( 74 | constant = ConstantCompression 75 | speed = BestSpeed 76 | default_ = DefaultCompression 77 | compress = BestCompression 78 | ) 79 | 80 | func BenchmarkDecodeDigitsSpeed1e4(b *testing.B) { benchmarkDecode(b, digits, speed, 1e4) } 81 | func BenchmarkDecodeDigitsSpeed1e5(b *testing.B) { benchmarkDecode(b, digits, speed, 1e5) } 82 | func BenchmarkDecodeDigitsSpeed1e6(b *testing.B) { benchmarkDecode(b, digits, speed, 1e6) } 83 | func BenchmarkDecodeDigitsDefault1e4(b *testing.B) { benchmarkDecode(b, digits, default_, 1e4) } 84 | func BenchmarkDecodeDigitsDefault1e5(b *testing.B) { benchmarkDecode(b, digits, default_, 1e5) } 85 | func BenchmarkDecodeDigitsDefault1e6(b *testing.B) { benchmarkDecode(b, digits, default_, 1e6) } 86 | func BenchmarkDecodeDigitsCompress1e4(b *testing.B) { benchmarkDecode(b, digits, compress, 1e4) } 87 | func BenchmarkDecodeDigitsCompress1e5(b *testing.B) { benchmarkDecode(b, digits, compress, 1e5) } 88 | func BenchmarkDecodeDigitsCompress1e6(b *testing.B) { benchmarkDecode(b, digits, compress, 1e6) } 89 | func BenchmarkDecodeTwainSpeed1e4(b *testing.B) { benchmarkDecode(b, twain, speed, 1e4) } 90 | func BenchmarkDecodeTwainSpeed1e5(b *testing.B) { benchmarkDecode(b, twain, speed, 1e5) } 91 | func BenchmarkDecodeTwainSpeed1e6(b *testing.B) { benchmarkDecode(b, twain, speed, 1e6) } 92 | func BenchmarkDecodeTwainDefault1e4(b *testing.B) { benchmarkDecode(b, twain, default_, 1e4) } 93 | func BenchmarkDecodeTwainDefault1e5(b *testing.B) { benchmarkDecode(b, twain, default_, 1e5) } 94 | func BenchmarkDecodeTwainDefault1e6(b *testing.B) { benchmarkDecode(b, twain, default_, 1e6) } 95 | func BenchmarkDecodeTwainCompress1e4(b *testing.B) { benchmarkDecode(b, twain, compress, 1e4) } 96 | func BenchmarkDecodeTwainCompress1e5(b *testing.B) { benchmarkDecode(b, twain, compress, 1e5) } 97 | func BenchmarkDecodeTwainCompress1e6(b *testing.B) { benchmarkDecode(b, twain, compress, 1e6) } 98 | -------------------------------------------------------------------------------- /vendor/github.com/klauspost/compress/flate/reverse_bits.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package flate 6 | 7 | var reverseByte = [256]byte{ 8 | 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0, 9 | 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0, 10 | 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8, 11 | 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8, 12 | 0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4, 13 | 0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4, 14 | 0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec, 15 | 0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc, 16 | 0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2, 17 | 0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2, 18 | 0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea, 19 | 0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa, 20 | 0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6, 21 | 0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6, 22 | 0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee, 23 | 0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe, 24 | 0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1, 25 | 0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1, 26 | 0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9, 27 | 0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9, 28 | 0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5, 29 | 0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5, 30 | 0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed, 31 | 0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd, 32 | 0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3, 33 | 0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3, 34 | 0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb, 35 | 0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb, 36 | 0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7, 37 | 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7, 38 | 0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef, 39 | 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff, 40 | } 41 | 42 | func reverseUint16(v uint16) uint16 { 43 | return uint16(reverseByte[v>>8]) | uint16(reverseByte[v&0xFF])<<8 44 | } 45 | 46 | func reverseBits(number uint16, bitLength byte) uint16 { 47 | return reverseUint16(number << uint8(16-bitLength)) 48 | } 49 | -------------------------------------------------------------------------------- /vendor/github.com/klauspost/compress/flate/testdata/huffman-null-max.dyn.expect: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wg/arc/cdd799359b6f7050fc5e3aa128bf1776a95a8a68/vendor/github.com/klauspost/compress/flate/testdata/huffman-null-max.dyn.expect -------------------------------------------------------------------------------- /vendor/github.com/klauspost/compress/flate/testdata/huffman-null-max.dyn.expect-noinput: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wg/arc/cdd799359b6f7050fc5e3aa128bf1776a95a8a68/vendor/github.com/klauspost/compress/flate/testdata/huffman-null-max.dyn.expect-noinput -------------------------------------------------------------------------------- /vendor/github.com/klauspost/compress/flate/testdata/huffman-null-max.golden: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wg/arc/cdd799359b6f7050fc5e3aa128bf1776a95a8a68/vendor/github.com/klauspost/compress/flate/testdata/huffman-null-max.golden -------------------------------------------------------------------------------- /vendor/github.com/klauspost/compress/flate/testdata/huffman-null-max.wb.expect: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wg/arc/cdd799359b6f7050fc5e3aa128bf1776a95a8a68/vendor/github.com/klauspost/compress/flate/testdata/huffman-null-max.wb.expect -------------------------------------------------------------------------------- /vendor/github.com/klauspost/compress/flate/testdata/huffman-null-max.wb.expect-noinput: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wg/arc/cdd799359b6f7050fc5e3aa128bf1776a95a8a68/vendor/github.com/klauspost/compress/flate/testdata/huffman-null-max.wb.expect-noinput -------------------------------------------------------------------------------- /vendor/github.com/klauspost/compress/flate/testdata/huffman-pi.dyn.expect: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wg/arc/cdd799359b6f7050fc5e3aa128bf1776a95a8a68/vendor/github.com/klauspost/compress/flate/testdata/huffman-pi.dyn.expect -------------------------------------------------------------------------------- /vendor/github.com/klauspost/compress/flate/testdata/huffman-pi.dyn.expect-noinput: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wg/arc/cdd799359b6f7050fc5e3aa128bf1776a95a8a68/vendor/github.com/klauspost/compress/flate/testdata/huffman-pi.dyn.expect-noinput -------------------------------------------------------------------------------- /vendor/github.com/klauspost/compress/flate/testdata/huffman-pi.golden: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wg/arc/cdd799359b6f7050fc5e3aa128bf1776a95a8a68/vendor/github.com/klauspost/compress/flate/testdata/huffman-pi.golden -------------------------------------------------------------------------------- /vendor/github.com/klauspost/compress/flate/testdata/huffman-pi.in: -------------------------------------------------------------------------------- 1 | 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420198938095257201065485863278865936153381827968230301952035301852968995773622599413891249721775283479131515574857242454150695950829533116861727855889075098381754637464939319255060400927701671139009848824012858361603563707660104710181942955596198946767837449448255379774726847104047534646208046684259069491293313677028989152104752162056966024058038150193511253382430035587640247496473263914199272604269922796782354781636009341721641219924586315030286182974555706749838505494588586926995690927210797509302955321165344987202755960236480665499119881834797753566369807426542527862551818417574672890977772793800081647060016145249192173217214772350141441973568548161361157352552133475741849468438523323907394143334547762416862518983569485562099219222184272550254256887671790494601653466804988627232791786085784383827967976681454100953883786360950680064225125205117392984896084128488626945604241965285022210661186306744278622039194945047123713786960956364371917287467764657573962413890865832645995813390478027590099465764078951269468398352595709825822620522489407726719478268482601476990902640136394437455305068203496252451749399651431429809190659250937221696461515709858387410597885959772975498930161753928468138268683868942774155991855925245953959431049972524680845987273644695848653836736222626099124608051243884390451244136549762780797715691435997700129616089441694868555848406353422072225828488648158456028506016842739452267467678895252138522549954666727823986456596116354886230577456498035593634568174324112515076069479451096596094025228879710893145669136867228748940560101503308617928680920874760917824938589009714909675985261365549781893129784821682998948722658804857564014270477555132379641451523746234364542858444795265867821051141354735739523113427166102135969536231442952484937187110145765403590279934403742007310578539062198387447808478489683321445713868751943506430218453191048481005370614680674919278191197939952061419663428754440643745123718192179998391015919561814675142691239748940907186494231961567945208095146550225231603881930142093762137855956638937787083039069792077346722182562599661501421503068038447734549202605414665925201497442850732518666002132434088190710486331734649651453905796268561005508106658796998163574736384052571459102897064140110971206280439039759515677157700420337869936007230558763176359421873125147120532928191826186125867321579198414848829164470609575270695722091756711672291098169091528017350671274858322287183520935396572512108357915136988209144421006751033467110314126711136990865851639831501970165151168517143765761835155650884909989859982387345528331635507647918535893226185489632132933089857064204675259070915481416549859461637180 -------------------------------------------------------------------------------- /vendor/github.com/klauspost/compress/flate/testdata/huffman-pi.wb.expect: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wg/arc/cdd799359b6f7050fc5e3aa128bf1776a95a8a68/vendor/github.com/klauspost/compress/flate/testdata/huffman-pi.wb.expect -------------------------------------------------------------------------------- /vendor/github.com/klauspost/compress/flate/testdata/huffman-pi.wb.expect-noinput: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wg/arc/cdd799359b6f7050fc5e3aa128bf1776a95a8a68/vendor/github.com/klauspost/compress/flate/testdata/huffman-pi.wb.expect-noinput -------------------------------------------------------------------------------- /vendor/github.com/klauspost/compress/flate/testdata/huffman-rand-1k.dyn.expect: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wg/arc/cdd799359b6f7050fc5e3aa128bf1776a95a8a68/vendor/github.com/klauspost/compress/flate/testdata/huffman-rand-1k.dyn.expect -------------------------------------------------------------------------------- /vendor/github.com/klauspost/compress/flate/testdata/huffman-rand-1k.dyn.expect-noinput: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wg/arc/cdd799359b6f7050fc5e3aa128bf1776a95a8a68/vendor/github.com/klauspost/compress/flate/testdata/huffman-rand-1k.dyn.expect-noinput -------------------------------------------------------------------------------- /vendor/github.com/klauspost/compress/flate/testdata/huffman-rand-1k.golden: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wg/arc/cdd799359b6f7050fc5e3aa128bf1776a95a8a68/vendor/github.com/klauspost/compress/flate/testdata/huffman-rand-1k.golden -------------------------------------------------------------------------------- /vendor/github.com/klauspost/compress/flate/testdata/huffman-rand-1k.in: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wg/arc/cdd799359b6f7050fc5e3aa128bf1776a95a8a68/vendor/github.com/klauspost/compress/flate/testdata/huffman-rand-1k.in -------------------------------------------------------------------------------- /vendor/github.com/klauspost/compress/flate/testdata/huffman-rand-1k.wb.expect: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wg/arc/cdd799359b6f7050fc5e3aa128bf1776a95a8a68/vendor/github.com/klauspost/compress/flate/testdata/huffman-rand-1k.wb.expect -------------------------------------------------------------------------------- /vendor/github.com/klauspost/compress/flate/testdata/huffman-rand-1k.wb.expect-noinput: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wg/arc/cdd799359b6f7050fc5e3aa128bf1776a95a8a68/vendor/github.com/klauspost/compress/flate/testdata/huffman-rand-1k.wb.expect-noinput -------------------------------------------------------------------------------- /vendor/github.com/klauspost/compress/flate/testdata/huffman-rand-limit.dyn.expect: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wg/arc/cdd799359b6f7050fc5e3aa128bf1776a95a8a68/vendor/github.com/klauspost/compress/flate/testdata/huffman-rand-limit.dyn.expect -------------------------------------------------------------------------------- /vendor/github.com/klauspost/compress/flate/testdata/huffman-rand-limit.dyn.expect-noinput: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wg/arc/cdd799359b6f7050fc5e3aa128bf1776a95a8a68/vendor/github.com/klauspost/compress/flate/testdata/huffman-rand-limit.dyn.expect-noinput -------------------------------------------------------------------------------- /vendor/github.com/klauspost/compress/flate/testdata/huffman-rand-limit.golden: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wg/arc/cdd799359b6f7050fc5e3aa128bf1776a95a8a68/vendor/github.com/klauspost/compress/flate/testdata/huffman-rand-limit.golden -------------------------------------------------------------------------------- /vendor/github.com/klauspost/compress/flate/testdata/huffman-rand-limit.in: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wg/arc/cdd799359b6f7050fc5e3aa128bf1776a95a8a68/vendor/github.com/klauspost/compress/flate/testdata/huffman-rand-limit.in -------------------------------------------------------------------------------- /vendor/github.com/klauspost/compress/flate/testdata/huffman-rand-limit.wb.expect: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wg/arc/cdd799359b6f7050fc5e3aa128bf1776a95a8a68/vendor/github.com/klauspost/compress/flate/testdata/huffman-rand-limit.wb.expect -------------------------------------------------------------------------------- /vendor/github.com/klauspost/compress/flate/testdata/huffman-rand-limit.wb.expect-noinput: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wg/arc/cdd799359b6f7050fc5e3aa128bf1776a95a8a68/vendor/github.com/klauspost/compress/flate/testdata/huffman-rand-limit.wb.expect-noinput -------------------------------------------------------------------------------- /vendor/github.com/klauspost/compress/flate/testdata/huffman-rand-max.golden: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wg/arc/cdd799359b6f7050fc5e3aa128bf1776a95a8a68/vendor/github.com/klauspost/compress/flate/testdata/huffman-rand-max.golden -------------------------------------------------------------------------------- /vendor/github.com/klauspost/compress/flate/testdata/huffman-rand-max.in: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wg/arc/cdd799359b6f7050fc5e3aa128bf1776a95a8a68/vendor/github.com/klauspost/compress/flate/testdata/huffman-rand-max.in -------------------------------------------------------------------------------- /vendor/github.com/klauspost/compress/flate/testdata/huffman-shifts.dyn.expect: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wg/arc/cdd799359b6f7050fc5e3aa128bf1776a95a8a68/vendor/github.com/klauspost/compress/flate/testdata/huffman-shifts.dyn.expect -------------------------------------------------------------------------------- /vendor/github.com/klauspost/compress/flate/testdata/huffman-shifts.dyn.expect-noinput: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wg/arc/cdd799359b6f7050fc5e3aa128bf1776a95a8a68/vendor/github.com/klauspost/compress/flate/testdata/huffman-shifts.dyn.expect-noinput -------------------------------------------------------------------------------- /vendor/github.com/klauspost/compress/flate/testdata/huffman-shifts.golden: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wg/arc/cdd799359b6f7050fc5e3aa128bf1776a95a8a68/vendor/github.com/klauspost/compress/flate/testdata/huffman-shifts.golden -------------------------------------------------------------------------------- /vendor/github.com/klauspost/compress/flate/testdata/huffman-shifts.wb.expect: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wg/arc/cdd799359b6f7050fc5e3aa128bf1776a95a8a68/vendor/github.com/klauspost/compress/flate/testdata/huffman-shifts.wb.expect -------------------------------------------------------------------------------- /vendor/github.com/klauspost/compress/flate/testdata/huffman-shifts.wb.expect-noinput: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wg/arc/cdd799359b6f7050fc5e3aa128bf1776a95a8a68/vendor/github.com/klauspost/compress/flate/testdata/huffman-shifts.wb.expect-noinput -------------------------------------------------------------------------------- /vendor/github.com/klauspost/compress/flate/testdata/huffman-text-shift.dyn.expect: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wg/arc/cdd799359b6f7050fc5e3aa128bf1776a95a8a68/vendor/github.com/klauspost/compress/flate/testdata/huffman-text-shift.dyn.expect -------------------------------------------------------------------------------- /vendor/github.com/klauspost/compress/flate/testdata/huffman-text-shift.dyn.expect-noinput: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wg/arc/cdd799359b6f7050fc5e3aa128bf1776a95a8a68/vendor/github.com/klauspost/compress/flate/testdata/huffman-text-shift.dyn.expect-noinput -------------------------------------------------------------------------------- /vendor/github.com/klauspost/compress/flate/testdata/huffman-text-shift.golden: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wg/arc/cdd799359b6f7050fc5e3aa128bf1776a95a8a68/vendor/github.com/klauspost/compress/flate/testdata/huffman-text-shift.golden -------------------------------------------------------------------------------- /vendor/github.com/klauspost/compress/flate/testdata/huffman-text-shift.in: -------------------------------------------------------------------------------- 1 | //Copyright2009ThGoAuthor.Allrightrrvd. 2 | //UofthiourccodigovrndbyBSD-tyl 3 | //licnthtcnbfoundinthLICENSEfil. 4 | 5 | pckgmin 6 | 7 | import"o" 8 | 9 | funcmin(){ 10 | vrb=mk([]byt,65535) 11 | f,_:=o.Crt("huffmn-null-mx.in") 12 | f.Writ(b) 13 | } 14 | ABCDEFGHIJKLMNOPQRSTUVXxyz!"#¤%&/?" -------------------------------------------------------------------------------- /vendor/github.com/klauspost/compress/flate/testdata/huffman-text-shift.wb.expect: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wg/arc/cdd799359b6f7050fc5e3aa128bf1776a95a8a68/vendor/github.com/klauspost/compress/flate/testdata/huffman-text-shift.wb.expect -------------------------------------------------------------------------------- /vendor/github.com/klauspost/compress/flate/testdata/huffman-text-shift.wb.expect-noinput: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wg/arc/cdd799359b6f7050fc5e3aa128bf1776a95a8a68/vendor/github.com/klauspost/compress/flate/testdata/huffman-text-shift.wb.expect-noinput -------------------------------------------------------------------------------- /vendor/github.com/klauspost/compress/flate/testdata/huffman-text.dyn.expect: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wg/arc/cdd799359b6f7050fc5e3aa128bf1776a95a8a68/vendor/github.com/klauspost/compress/flate/testdata/huffman-text.dyn.expect -------------------------------------------------------------------------------- /vendor/github.com/klauspost/compress/flate/testdata/huffman-text.dyn.expect-noinput: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wg/arc/cdd799359b6f7050fc5e3aa128bf1776a95a8a68/vendor/github.com/klauspost/compress/flate/testdata/huffman-text.dyn.expect-noinput -------------------------------------------------------------------------------- /vendor/github.com/klauspost/compress/flate/testdata/huffman-text.golden: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wg/arc/cdd799359b6f7050fc5e3aa128bf1776a95a8a68/vendor/github.com/klauspost/compress/flate/testdata/huffman-text.golden -------------------------------------------------------------------------------- /vendor/github.com/klauspost/compress/flate/testdata/huffman-text.in: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package main 6 | 7 | import "os" 8 | 9 | func main() { 10 | var b = make([]byte, 65535) 11 | f, _ := os.Create("huffman-null-max.in") 12 | f.Write(b) 13 | } 14 | -------------------------------------------------------------------------------- /vendor/github.com/klauspost/compress/flate/testdata/huffman-text.wb.expect: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wg/arc/cdd799359b6f7050fc5e3aa128bf1776a95a8a68/vendor/github.com/klauspost/compress/flate/testdata/huffman-text.wb.expect -------------------------------------------------------------------------------- /vendor/github.com/klauspost/compress/flate/testdata/huffman-text.wb.expect-noinput: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wg/arc/cdd799359b6f7050fc5e3aa128bf1776a95a8a68/vendor/github.com/klauspost/compress/flate/testdata/huffman-text.wb.expect-noinput -------------------------------------------------------------------------------- /vendor/github.com/klauspost/compress/flate/testdata/huffman-zero.dyn.expect: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wg/arc/cdd799359b6f7050fc5e3aa128bf1776a95a8a68/vendor/github.com/klauspost/compress/flate/testdata/huffman-zero.dyn.expect -------------------------------------------------------------------------------- /vendor/github.com/klauspost/compress/flate/testdata/huffman-zero.dyn.expect-noinput: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wg/arc/cdd799359b6f7050fc5e3aa128bf1776a95a8a68/vendor/github.com/klauspost/compress/flate/testdata/huffman-zero.dyn.expect-noinput -------------------------------------------------------------------------------- /vendor/github.com/klauspost/compress/flate/testdata/huffman-zero.golden: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wg/arc/cdd799359b6f7050fc5e3aa128bf1776a95a8a68/vendor/github.com/klauspost/compress/flate/testdata/huffman-zero.golden -------------------------------------------------------------------------------- /vendor/github.com/klauspost/compress/flate/testdata/huffman-zero.in: -------------------------------------------------------------------------------- 1 | 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -------------------------------------------------------------------------------- /vendor/github.com/klauspost/compress/flate/testdata/huffman-zero.wb.expect: -------------------------------------------------------------------------------- 1 | 2$ -------------------------------------------------------------------------------- /vendor/github.com/klauspost/compress/flate/testdata/huffman-zero.wb.expect-noinput: -------------------------------------------------------------------------------- 1 | 2$ -------------------------------------------------------------------------------- /vendor/github.com/klauspost/compress/flate/testdata/null-long-match.dyn.expect-noinput: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wg/arc/cdd799359b6f7050fc5e3aa128bf1776a95a8a68/vendor/github.com/klauspost/compress/flate/testdata/null-long-match.dyn.expect-noinput -------------------------------------------------------------------------------- /vendor/github.com/klauspost/compress/flate/testdata/null-long-match.wb.expect-noinput: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wg/arc/cdd799359b6f7050fc5e3aa128bf1776a95a8a68/vendor/github.com/klauspost/compress/flate/testdata/null-long-match.wb.expect-noinput -------------------------------------------------------------------------------- /vendor/github.com/klauspost/compress/flate/token.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package flate 6 | 7 | const ( 8 | // 2 bits: type 0 = literal 1=EOF 2=Match 3=Unused 9 | // 8 bits: xlength = length - MIN_MATCH_LENGTH 10 | // 22 bits xoffset = offset - MIN_OFFSET_SIZE, or literal 11 | lengthShift = 22 12 | offsetMask = 1< pair into a match token. 79 | func matchToken(xlength uint32, xoffset uint32) token { 80 | return token(matchType + xlength<> lengthShift) } 93 | 94 | func lengthCode(len uint32) uint32 { return lengthCodes[len] } 95 | 96 | // Returns the offset code corresponding to a specific offset 97 | func offsetCode(off uint32) uint32 { 98 | if off < uint32(len(offsetCodes)) { 99 | return offsetCodes[off] 100 | } else if off>>7 < uint32(len(offsetCodes)) { 101 | return offsetCodes[off>>7] + 14 102 | } else { 103 | return offsetCodes[off>>14] + 28 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /vendor/github.com/klauspost/compress/flate/writer_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package flate 6 | 7 | import ( 8 | "io/ioutil" 9 | "runtime" 10 | "testing" 11 | ) 12 | 13 | func benchmarkEncoder(b *testing.B, testfile, level, n int) { 14 | b.StopTimer() 15 | b.SetBytes(int64(n)) 16 | buf0, err := ioutil.ReadFile(testfiles[testfile]) 17 | if err != nil { 18 | b.Fatal(err) 19 | } 20 | if len(buf0) == 0 { 21 | b.Fatalf("test file %q has no data", testfiles[testfile]) 22 | } 23 | buf1 := make([]byte, n) 24 | for i := 0; i < n; i += len(buf0) { 25 | if len(buf0) > n-i { 26 | buf0 = buf0[:n-i] 27 | } 28 | copy(buf1[i:], buf0) 29 | } 30 | buf0 = nil 31 | runtime.GC() 32 | w, err := NewWriter(ioutil.Discard, level) 33 | b.StartTimer() 34 | for i := 0; i < b.N; i++ { 35 | w.Reset(ioutil.Discard) 36 | _, err = w.Write(buf1) 37 | if err != nil { 38 | b.Fatal(err) 39 | } 40 | err = w.Close() 41 | if err != nil { 42 | b.Fatal(err) 43 | } 44 | } 45 | } 46 | 47 | func BenchmarkEncodeDigitsConstant1e4(b *testing.B) { benchmarkEncoder(b, digits, constant, 1e4) } 48 | func BenchmarkEncodeDigitsConstant1e5(b *testing.B) { benchmarkEncoder(b, digits, constant, 1e5) } 49 | func BenchmarkEncodeDigitsConstant1e6(b *testing.B) { benchmarkEncoder(b, digits, constant, 1e6) } 50 | func BenchmarkEncodeDigitsSpeed1e4(b *testing.B) { benchmarkEncoder(b, digits, speed, 1e4) } 51 | func BenchmarkEncodeDigitsSpeed1e5(b *testing.B) { benchmarkEncoder(b, digits, speed, 1e5) } 52 | func BenchmarkEncodeDigitsSpeed1e6(b *testing.B) { benchmarkEncoder(b, digits, speed, 1e6) } 53 | func BenchmarkEncodeDigitsDefault1e4(b *testing.B) { benchmarkEncoder(b, digits, default_, 1e4) } 54 | func BenchmarkEncodeDigitsDefault1e5(b *testing.B) { benchmarkEncoder(b, digits, default_, 1e5) } 55 | func BenchmarkEncodeDigitsDefault1e6(b *testing.B) { benchmarkEncoder(b, digits, default_, 1e6) } 56 | func BenchmarkEncodeDigitsCompress1e4(b *testing.B) { benchmarkEncoder(b, digits, compress, 1e4) } 57 | func BenchmarkEncodeDigitsCompress1e5(b *testing.B) { benchmarkEncoder(b, digits, compress, 1e5) } 58 | func BenchmarkEncodeDigitsCompress1e6(b *testing.B) { benchmarkEncoder(b, digits, compress, 1e6) } 59 | func BenchmarkEncodeTwainConstant1e4(b *testing.B) { benchmarkEncoder(b, twain, constant, 1e4) } 60 | func BenchmarkEncodeTwainConstant1e5(b *testing.B) { benchmarkEncoder(b, twain, constant, 1e5) } 61 | func BenchmarkEncodeTwainConstant1e6(b *testing.B) { benchmarkEncoder(b, twain, constant, 1e6) } 62 | func BenchmarkEncodeTwainSpeed1e4(b *testing.B) { benchmarkEncoder(b, twain, speed, 1e4) } 63 | func BenchmarkEncodeTwainSpeed1e5(b *testing.B) { benchmarkEncoder(b, twain, speed, 1e5) } 64 | func BenchmarkEncodeTwainSpeed1e6(b *testing.B) { benchmarkEncoder(b, twain, speed, 1e6) } 65 | func BenchmarkEncodeTwainDefault1e4(b *testing.B) { benchmarkEncoder(b, twain, default_, 1e4) } 66 | func BenchmarkEncodeTwainDefault1e5(b *testing.B) { benchmarkEncoder(b, twain, default_, 1e5) } 67 | func BenchmarkEncodeTwainDefault1e6(b *testing.B) { benchmarkEncoder(b, twain, default_, 1e6) } 68 | func BenchmarkEncodeTwainCompress1e4(b *testing.B) { benchmarkEncoder(b, twain, compress, 1e4) } 69 | func BenchmarkEncodeTwainCompress1e5(b *testing.B) { benchmarkEncoder(b, twain, compress, 1e5) } 70 | func BenchmarkEncodeTwainCompress1e6(b *testing.B) { benchmarkEncoder(b, twain, compress, 1e6) } 71 | -------------------------------------------------------------------------------- /vendor/github.com/klauspost/compress/gzip/testdata/issue6550.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wg/arc/cdd799359b6f7050fc5e3aa128bf1776a95a8a68/vendor/github.com/klauspost/compress/gzip/testdata/issue6550.gz -------------------------------------------------------------------------------- /vendor/github.com/klauspost/cpuid/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Klaus Post 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /vendor/github.com/klauspost/cpuid/cpuid_386.s: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015 Klaus Post, released under MIT License. See LICENSE file. 2 | 3 | // +build 386,!gccgo 4 | 5 | // func asmCpuid(op uint32) (eax, ebx, ecx, edx uint32) 6 | TEXT ·asmCpuid(SB), 7, $0 7 | XORL CX, CX 8 | MOVL op+0(FP), AX 9 | CPUID 10 | MOVL AX, eax+4(FP) 11 | MOVL BX, ebx+8(FP) 12 | MOVL CX, ecx+12(FP) 13 | MOVL DX, edx+16(FP) 14 | RET 15 | 16 | // func asmCpuidex(op, op2 uint32) (eax, ebx, ecx, edx uint32) 17 | TEXT ·asmCpuidex(SB), 7, $0 18 | MOVL op+0(FP), AX 19 | MOVL op2+4(FP), CX 20 | CPUID 21 | MOVL AX, eax+8(FP) 22 | MOVL BX, ebx+12(FP) 23 | MOVL CX, ecx+16(FP) 24 | MOVL DX, edx+20(FP) 25 | RET 26 | 27 | // func xgetbv(index uint32) (eax, edx uint32) 28 | TEXT ·asmXgetbv(SB), 7, $0 29 | MOVL index+0(FP), CX 30 | BYTE $0x0f; BYTE $0x01; BYTE $0xd0 // XGETBV 31 | MOVL AX, eax+4(FP) 32 | MOVL DX, edx+8(FP) 33 | RET 34 | 35 | // func asmRdtscpAsm() (eax, ebx, ecx, edx uint32) 36 | TEXT ·asmRdtscpAsm(SB), 7, $0 37 | BYTE $0x0F; BYTE $0x01; BYTE $0xF9 // RDTSCP 38 | MOVL AX, eax+0(FP) 39 | MOVL BX, ebx+4(FP) 40 | MOVL CX, ecx+8(FP) 41 | MOVL DX, edx+12(FP) 42 | RET 43 | -------------------------------------------------------------------------------- /vendor/github.com/klauspost/cpuid/cpuid_amd64.s: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015 Klaus Post, released under MIT License. See LICENSE file. 2 | 3 | //+build amd64,!gccgo 4 | 5 | // func asmCpuid(op uint32) (eax, ebx, ecx, edx uint32) 6 | TEXT ·asmCpuid(SB), 7, $0 7 | XORQ CX, CX 8 | MOVL op+0(FP), AX 9 | CPUID 10 | MOVL AX, eax+8(FP) 11 | MOVL BX, ebx+12(FP) 12 | MOVL CX, ecx+16(FP) 13 | MOVL DX, edx+20(FP) 14 | RET 15 | 16 | // func asmCpuidex(op, op2 uint32) (eax, ebx, ecx, edx uint32) 17 | TEXT ·asmCpuidex(SB), 7, $0 18 | MOVL op+0(FP), AX 19 | MOVL op2+4(FP), CX 20 | CPUID 21 | MOVL AX, eax+8(FP) 22 | MOVL BX, ebx+12(FP) 23 | MOVL CX, ecx+16(FP) 24 | MOVL DX, edx+20(FP) 25 | RET 26 | 27 | // func asmXgetbv(index uint32) (eax, edx uint32) 28 | TEXT ·asmXgetbv(SB), 7, $0 29 | MOVL index+0(FP), CX 30 | BYTE $0x0f; BYTE $0x01; BYTE $0xd0 // XGETBV 31 | MOVL AX, eax+8(FP) 32 | MOVL DX, edx+12(FP) 33 | RET 34 | 35 | // func asmRdtscpAsm() (eax, ebx, ecx, edx uint32) 36 | TEXT ·asmRdtscpAsm(SB), 7, $0 37 | BYTE $0x0F; BYTE $0x01; BYTE $0xF9 // RDTSCP 38 | MOVL AX, eax+0(FP) 39 | MOVL BX, ebx+4(FP) 40 | MOVL CX, ecx+8(FP) 41 | MOVL DX, edx+12(FP) 42 | RET 43 | -------------------------------------------------------------------------------- /vendor/github.com/klauspost/cpuid/detect_intel.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015 Klaus Post, released under MIT License. See LICENSE file. 2 | 3 | // +build 386,!gccgo amd64,!gccgo 4 | 5 | package cpuid 6 | 7 | func asmCpuid(op uint32) (eax, ebx, ecx, edx uint32) 8 | func asmCpuidex(op, op2 uint32) (eax, ebx, ecx, edx uint32) 9 | func asmXgetbv(index uint32) (eax, edx uint32) 10 | func asmRdtscpAsm() (eax, ebx, ecx, edx uint32) 11 | 12 | func initCPU() { 13 | cpuid = asmCpuid 14 | cpuidex = asmCpuidex 15 | xgetbv = asmXgetbv 16 | rdtscpAsm = asmRdtscpAsm 17 | } 18 | -------------------------------------------------------------------------------- /vendor/github.com/klauspost/cpuid/detect_ref.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015 Klaus Post, released under MIT License. See LICENSE file. 2 | 3 | // +build !amd64,!386 gccgo 4 | 5 | package cpuid 6 | 7 | func initCPU() { 8 | cpuid = func(op uint32) (eax, ebx, ecx, edx uint32) { 9 | return 0, 0, 0, 0 10 | } 11 | 12 | cpuidex = func(op, op2 uint32) (eax, ebx, ecx, edx uint32) { 13 | return 0, 0, 0, 0 14 | } 15 | 16 | xgetbv = func(index uint32) (eax, edx uint32) { 17 | return 0, 0 18 | } 19 | 20 | rdtscpAsm = func() (eax, ebx, ecx, edx uint32) { 21 | return 0, 0, 0, 0 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /vendor/github.com/klauspost/cpuid/generate.go: -------------------------------------------------------------------------------- 1 | package cpuid 2 | 3 | //go:generate go run private-gen.go 4 | -------------------------------------------------------------------------------- /vendor/github.com/klauspost/cpuid/private/README.md: -------------------------------------------------------------------------------- 1 | # cpuid private 2 | 3 | This is a specially converted of the cpuid package, so it can be included in 4 | a package without exporting anything. 5 | 6 | Package home: https://github.com/klauspost/cpuid 7 | -------------------------------------------------------------------------------- /vendor/github.com/klauspost/cpuid/private/cpuid_386.s: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015 Klaus Post, released under MIT License. See LICENSE file. 2 | 3 | // +build 386,!gccgo 4 | 5 | // func asmCpuid(op uint32) (eax, ebx, ecx, edx uint32) 6 | TEXT ·asmCpuid(SB), 7, $0 7 | XORL CX, CX 8 | MOVL op+0(FP), AX 9 | CPUID 10 | MOVL AX, eax+4(FP) 11 | MOVL BX, ebx+8(FP) 12 | MOVL CX, ecx+12(FP) 13 | MOVL DX, edx+16(FP) 14 | RET 15 | 16 | // func asmCpuidex(op, op2 uint32) (eax, ebx, ecx, edx uint32) 17 | TEXT ·asmCpuidex(SB), 7, $0 18 | MOVL op+0(FP), AX 19 | MOVL op2+4(FP), CX 20 | CPUID 21 | MOVL AX, eax+8(FP) 22 | MOVL BX, ebx+12(FP) 23 | MOVL CX, ecx+16(FP) 24 | MOVL DX, edx+20(FP) 25 | RET 26 | 27 | // func xgetbv(index uint32) (eax, edx uint32) 28 | TEXT ·asmXgetbv(SB), 7, $0 29 | MOVL index+0(FP), CX 30 | BYTE $0x0f; BYTE $0x01; BYTE $0xd0 // XGETBV 31 | MOVL AX, eax+4(FP) 32 | MOVL DX, edx+8(FP) 33 | RET 34 | 35 | // func asmRdtscpAsm() (eax, ebx, ecx, edx uint32) 36 | TEXT ·asmRdtscpAsm(SB), 7, $0 37 | BYTE $0x0F; BYTE $0x01; BYTE $0xF9 // RDTSCP 38 | MOVL AX, eax+0(FP) 39 | MOVL BX, ebx+4(FP) 40 | MOVL CX, ecx+8(FP) 41 | MOVL DX, edx+12(FP) 42 | RET 43 | -------------------------------------------------------------------------------- /vendor/github.com/klauspost/cpuid/private/cpuid_amd64.s: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015 Klaus Post, released under MIT License. See LICENSE file. 2 | 3 | //+build amd64,!gccgo 4 | 5 | // func asmCpuid(op uint32) (eax, ebx, ecx, edx uint32) 6 | TEXT ·asmCpuid(SB), 7, $0 7 | XORQ CX, CX 8 | MOVL op+0(FP), AX 9 | CPUID 10 | MOVL AX, eax+8(FP) 11 | MOVL BX, ebx+12(FP) 12 | MOVL CX, ecx+16(FP) 13 | MOVL DX, edx+20(FP) 14 | RET 15 | 16 | // func asmCpuidex(op, op2 uint32) (eax, ebx, ecx, edx uint32) 17 | TEXT ·asmCpuidex(SB), 7, $0 18 | MOVL op+0(FP), AX 19 | MOVL op2+4(FP), CX 20 | CPUID 21 | MOVL AX, eax+8(FP) 22 | MOVL BX, ebx+12(FP) 23 | MOVL CX, ecx+16(FP) 24 | MOVL DX, edx+20(FP) 25 | RET 26 | 27 | // func asmXgetbv(index uint32) (eax, edx uint32) 28 | TEXT ·asmXgetbv(SB), 7, $0 29 | MOVL index+0(FP), CX 30 | BYTE $0x0f; BYTE $0x01; BYTE $0xd0 // XGETBV 31 | MOVL AX, eax+8(FP) 32 | MOVL DX, edx+12(FP) 33 | RET 34 | 35 | // func asmRdtscpAsm() (eax, ebx, ecx, edx uint32) 36 | TEXT ·asmRdtscpAsm(SB), 7, $0 37 | BYTE $0x0F; BYTE $0x01; BYTE $0xF9 // RDTSCP 38 | MOVL AX, eax+0(FP) 39 | MOVL BX, ebx+4(FP) 40 | MOVL CX, ecx+8(FP) 41 | MOVL DX, edx+12(FP) 42 | RET 43 | -------------------------------------------------------------------------------- /vendor/github.com/klauspost/cpuid/private/cpuid_detect_intel.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015 Klaus Post, released under MIT License. See LICENSE file. 2 | 3 | // +build 386,!gccgo amd64,!gccgo 4 | 5 | package cpuid 6 | 7 | func asmCpuid(op uint32) (eax, ebx, ecx, edx uint32) 8 | func asmCpuidex(op, op2 uint32) (eax, ebx, ecx, edx uint32) 9 | func asmXgetbv(index uint32) (eax, edx uint32) 10 | func asmRdtscpAsm() (eax, ebx, ecx, edx uint32) 11 | 12 | func initCPU() { 13 | cpuid = asmCpuid 14 | cpuidex = asmCpuidex 15 | xgetbv = asmXgetbv 16 | rdtscpAsm = asmRdtscpAsm 17 | } 18 | -------------------------------------------------------------------------------- /vendor/github.com/klauspost/cpuid/private/cpuid_detect_ref.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015 Klaus Post, released under MIT License. See LICENSE file. 2 | 3 | // +build !amd64,!386 gccgo 4 | 5 | package cpuid 6 | 7 | func initCPU() { 8 | cpuid = func(op uint32) (eax, ebx, ecx, edx uint32) { 9 | return 0, 0, 0, 0 10 | } 11 | 12 | cpuidex = func(op, op2 uint32) (eax, ebx, ecx, edx uint32) { 13 | return 0, 0, 0, 0 14 | } 15 | 16 | xgetbv = func(index uint32) (eax, edx uint32) { 17 | return 0, 0 18 | } 19 | 20 | rdtscpAsm = func() (eax, ebx, ecx, edx uint32) { 21 | return 0, 0, 0, 0 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /vendor/github.com/klauspost/cpuid/testdata/cpuid_data.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wg/arc/cdd799359b6f7050fc5e3aa128bf1776a95a8a68/vendor/github.com/klauspost/cpuid/testdata/cpuid_data.zip -------------------------------------------------------------------------------- /vendor/github.com/klauspost/cpuid/testdata/getall.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "archive/zip" 5 | _ "bytes" 6 | "fmt" 7 | "golang.org/x/net/html" 8 | "io" 9 | "net/http" 10 | "os" 11 | "strings" 12 | ) 13 | 14 | // Download all CPUID dumps from http://users.atw.hu/instlatx64/ 15 | func main() { 16 | resp, err := http.Get("http://users.atw.hu/instlatx64/?") 17 | if err != nil { 18 | panic(err) 19 | } 20 | 21 | node, err := html.Parse(resp.Body) 22 | if err != nil { 23 | panic(err) 24 | } 25 | 26 | file, err := os.Create("cpuid_data.zip") 27 | if err != nil { 28 | panic(err) 29 | } 30 | defer file.Close() 31 | gw := zip.NewWriter(file) 32 | 33 | var f func(*html.Node) 34 | f = func(n *html.Node) { 35 | if n.Type == html.ElementNode && n.Data == "a" { 36 | for _, a := range n.Attr { 37 | if a.Key == "href" { 38 | err := ParseURL(a.Val, gw) 39 | if err != nil { 40 | panic(err) 41 | } 42 | break 43 | } 44 | } 45 | } 46 | for c := n.FirstChild; c != nil; c = c.NextSibling { 47 | f(c) 48 | } 49 | } 50 | 51 | f(node) 52 | err = gw.Close() 53 | if err != nil { 54 | panic(err) 55 | } 56 | } 57 | 58 | func ParseURL(s string, gw *zip.Writer) error { 59 | if strings.Contains(s, "CPUID.txt") { 60 | fmt.Println("Adding", "http://users.atw.hu/instlatx64/"+s) 61 | resp, err := http.Get("http://users.atw.hu/instlatx64/" + s) 62 | if err != nil { 63 | fmt.Println("Error getting ", s, ":", err) 64 | } 65 | defer resp.Body.Close() 66 | w, err := gw.Create(s) 67 | if err != nil { 68 | return err 69 | } 70 | 71 | _, err = io.Copy(w, resp.Body) 72 | if err != nil { 73 | return err 74 | } 75 | } 76 | return nil 77 | } 78 | -------------------------------------------------------------------------------- /vendor/github.com/klauspost/crc32/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 The Go Authors. All rights reserved. 2 | Copyright (c) 2015 Klaus Post 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above 11 | copyright notice, this list of conditions and the following disclaimer 12 | in the documentation and/or other materials provided with the 13 | distribution. 14 | * Neither the name of Google Inc. nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | -------------------------------------------------------------------------------- /vendor/github.com/klauspost/crc32/crc32_amd64.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !appengine,!gccgo 6 | 7 | package crc32 8 | 9 | // This file contains the code to call the SSE 4.2 version of the Castagnoli 10 | // and IEEE CRC. 11 | 12 | // haveSSE41/haveSSE42/haveCLMUL are defined in crc_amd64.s and use 13 | // CPUID to test for SSE 4.1, 4.2 and CLMUL support. 14 | func haveSSE41() bool 15 | func haveSSE42() bool 16 | func haveCLMUL() bool 17 | 18 | // castagnoliSSE42 is defined in crc_amd64.s and uses the SSE4.2 CRC32 19 | // instruction. 20 | //go:noescape 21 | func castagnoliSSE42(crc uint32, p []byte) uint32 22 | 23 | // ieeeCLMUL is defined in crc_amd64.s and uses the PCLMULQDQ 24 | // instruction as well as SSE 4.1. 25 | //go:noescape 26 | func ieeeCLMUL(crc uint32, p []byte) uint32 27 | 28 | var sse42 = haveSSE42() 29 | var useFastIEEE = haveCLMUL() && haveSSE41() 30 | 31 | func updateCastagnoli(crc uint32, p []byte) uint32 { 32 | if sse42 { 33 | return castagnoliSSE42(crc, p) 34 | } 35 | // only use slicing-by-8 when input is >= 16 Bytes 36 | if len(p) >= 16 { 37 | return updateSlicingBy8(crc, castagnoliTable8, p) 38 | } 39 | return update(crc, castagnoliTable, p) 40 | } 41 | 42 | func updateIEEE(crc uint32, p []byte) uint32 { 43 | if useFastIEEE && len(p) >= 64 { 44 | left := len(p) & 15 45 | do := len(p) - left 46 | crc = ^ieeeCLMUL(^crc, p[:do]) 47 | if left > 0 { 48 | crc = update(crc, IEEETable, p[do:]) 49 | } 50 | return crc 51 | } 52 | 53 | // only use slicing-by-8 when input is >= 16 Bytes 54 | if len(p) >= 16 { 55 | ieeeTable8Once.Do(func() { 56 | ieeeTable8 = makeTable8(IEEE) 57 | }) 58 | return updateSlicingBy8(crc, ieeeTable8, p) 59 | } 60 | 61 | return update(crc, IEEETable, p) 62 | } 63 | -------------------------------------------------------------------------------- /vendor/github.com/klauspost/crc32/crc32_amd64p32.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !appengine,!gccgo 6 | 7 | package crc32 8 | 9 | // This file contains the code to call the SSE 4.2 version of the Castagnoli 10 | // CRC. 11 | 12 | // haveSSE42 is defined in crc_amd64p32.s and uses CPUID to test for SSE 4.2 13 | // support. 14 | func haveSSE42() bool 15 | 16 | // castagnoliSSE42 is defined in crc_amd64.s and uses the SSE4.2 CRC32 17 | // instruction. 18 | //go:noescape 19 | func castagnoliSSE42(crc uint32, p []byte) uint32 20 | 21 | var sse42 = haveSSE42() 22 | 23 | func updateCastagnoli(crc uint32, p []byte) uint32 { 24 | if sse42 { 25 | return castagnoliSSE42(crc, p) 26 | } 27 | return update(crc, castagnoliTable, p) 28 | } 29 | 30 | func updateIEEE(crc uint32, p []byte) uint32 { 31 | // only use slicing-by-8 when input is >= 4KB 32 | if len(p) >= 4096 { 33 | ieeeTable8Once.Do(func() { 34 | ieeeTable8 = makeTable8(IEEE) 35 | }) 36 | return updateSlicingBy8(crc, ieeeTable8, p) 37 | } 38 | 39 | return update(crc, IEEETable, p) 40 | } 41 | -------------------------------------------------------------------------------- /vendor/github.com/klauspost/crc32/crc32_amd64p32.s: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build gc 6 | 7 | #define NOSPLIT 4 8 | #define RODATA 8 9 | 10 | // func castagnoliSSE42(crc uint32, p []byte) uint32 11 | TEXT ·castagnoliSSE42(SB), NOSPLIT, $0 12 | MOVL crc+0(FP), AX // CRC value 13 | MOVL p+4(FP), SI // data pointer 14 | MOVL p_len+8(FP), CX // len(p) 15 | 16 | NOTL AX 17 | 18 | // If there's less than 8 bytes to process, we do it byte-by-byte. 19 | CMPQ CX, $8 20 | JL cleanup 21 | 22 | // Process individual bytes until the input is 8-byte aligned. 23 | startup: 24 | MOVQ SI, BX 25 | ANDQ $7, BX 26 | JZ aligned 27 | 28 | CRC32B (SI), AX 29 | DECQ CX 30 | INCQ SI 31 | JMP startup 32 | 33 | aligned: 34 | // The input is now 8-byte aligned and we can process 8-byte chunks. 35 | CMPQ CX, $8 36 | JL cleanup 37 | 38 | CRC32Q (SI), AX 39 | ADDQ $8, SI 40 | SUBQ $8, CX 41 | JMP aligned 42 | 43 | cleanup: 44 | // We may have some bytes left over that we process one at a time. 45 | CMPQ CX, $0 46 | JE done 47 | 48 | CRC32B (SI), AX 49 | INCQ SI 50 | DECQ CX 51 | JMP cleanup 52 | 53 | done: 54 | NOTL AX 55 | MOVL AX, ret+16(FP) 56 | RET 57 | 58 | // func haveSSE42() bool 59 | TEXT ·haveSSE42(SB), NOSPLIT, $0 60 | XORQ AX, AX 61 | INCL AX 62 | CPUID 63 | SHRQ $20, CX 64 | ANDQ $1, CX 65 | MOVB CX, ret+0(FP) 66 | RET 67 | 68 | -------------------------------------------------------------------------------- /vendor/github.com/klauspost/crc32/crc32_generic.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !amd64,!amd64p32 appengine gccgo 6 | 7 | package crc32 8 | 9 | // This file contains the generic version of updateCastagnoli which does 10 | // slicing-by-8, or uses the fallback for very small sizes. 11 | 12 | func updateCastagnoli(crc uint32, p []byte) uint32 { 13 | // only use slicing-by-8 when input is >= 16 Bytes 14 | if len(p) >= 16 { 15 | return updateSlicingBy8(crc, castagnoliTable8, p) 16 | } 17 | return update(crc, castagnoliTable, p) 18 | } 19 | 20 | func updateIEEE(crc uint32, p []byte) uint32 { 21 | // only use slicing-by-8 when input is >= 16 Bytes 22 | if len(p) >= 16 { 23 | ieeeTable8Once.Do(func() { 24 | ieeeTable8 = makeTable8(IEEE) 25 | }) 26 | return updateSlicingBy8(crc, ieeeTable8, p) 27 | } 28 | return update(crc, IEEETable, p) 29 | } 30 | -------------------------------------------------------------------------------- /vendor/github.com/klauspost/crc32/example_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package crc32_test 6 | 7 | import ( 8 | "fmt" 9 | "hash/crc32" 10 | ) 11 | 12 | func ExampleMakeTable() { 13 | // In this package, the CRC polynomial is represented in reversed notation, 14 | // or LSB-first representation. 15 | // 16 | // LSB-first representation is a hexadecimal number with n bits, in which the 17 | // most significant bit represents the coefficient of x⁰ and the least significant 18 | // bit represents the coefficient of xⁿ⁻¹ (the coefficient for xⁿ is implicit). 19 | // 20 | // For example, CRC32-Q, as defined by the following polynomial, 21 | // x³²+ x³¹+ x²⁴+ x²²+ x¹⁶+ x¹⁴+ x⁸+ x⁷+ x⁵+ x³+ x¹+ x⁰ 22 | // has the reversed notation 0b11010101100000101000001010000001, so the value 23 | // that should be passed to MakeTable is 0xD5828281. 24 | crc32q := crc32.MakeTable(0xD5828281) 25 | fmt.Printf("%08x\n", crc32.Checksum([]byte("Hello world"), crc32q)) 26 | // Output: 27 | // 2964d064 28 | } 29 | -------------------------------------------------------------------------------- /vendor/github.com/magical/argon2/README.md: -------------------------------------------------------------------------------- 1 | Go implementation of the Argon2 password hashing scheme 2 | designed by Alex Biryukov, Daniel Dinu, and Dmitry Khovratovich. 3 | 4 | Documentation 5 | ------------- 6 | 7 | See . 8 | 9 | License 10 | ------- 11 | 12 | Copyright © 2015 Andrew Ekstedt 13 | All rights reserved. 14 | 15 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 16 | 17 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 18 | 19 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 22 | -------------------------------------------------------------------------------- /vendor/github.com/magical/argon2/api.go: -------------------------------------------------------------------------------- 1 | // Package argon2 implements version 1.3 of the Argon2 password hashing scheme 2 | // designed by Alex Biryukov, Daniel Dinu, and Dmitry Khovratovich, 3 | // as specified in the document 4 | // 5 | // https://github.com/P-H-C/phc-winner-argon2/raw/54617af02de0055b90e39c4204058bb9a84c2b78/argon2-specs.pdf 6 | // 7 | // Warning: This package is currently unstable; Argon2 has not yet been 8 | // finalized and is still undergoing design tweaks. 9 | package argon2 10 | 11 | import "errors" 12 | 13 | const ( 14 | maxPar = 255 15 | 16 | maxIter = 1<<32 - 1 17 | 18 | minMemory = 8 19 | maxMemory = 1<<32 - 1 20 | 21 | minSalt = 8 22 | maxSalt = 1<<32 - 1 23 | maxPassword = 1<<32 - 1 24 | ) 25 | 26 | // Key derives a key from the password, salt, and cost parameters. 27 | // 28 | // The salt must be at least 8 bytes long. 29 | // 30 | // Mem is the amount of memory to use in kibibytes. 31 | // Mem must be at least 8*p, and will be rounded to a multiple of 4*p. 32 | func Key(password, salt []byte, n, par int, mem int64, keyLen int) ([]byte, error) { 33 | if int64(len(password)) > maxPassword { 34 | return nil, errors.New("argon: password too long") 35 | } 36 | 37 | if len(salt) < minSalt { 38 | return nil, errors.New("argon: salt too short") 39 | } else if int64(len(salt)) > maxSalt { 40 | return nil, errors.New("argon: salt too long") 41 | } 42 | 43 | if n < 1 || int64(n) > maxIter { 44 | return nil, errors.New("argon: invalid n") 45 | } 46 | 47 | if par < 1 || par > maxPar { 48 | return nil, errors.New("argon: invalid par") 49 | } 50 | 51 | if mem < minMemory || mem > maxMemory { 52 | return nil, errors.New("argon: invalid mem") 53 | } 54 | 55 | // Round down to a multiple of 4 * par 56 | mem = mem / (4 * int64(par)) * (4 * int64(par)) 57 | 58 | if mem < 8*int64(par) { 59 | mem = 8 * int64(par) 60 | } 61 | 62 | // TODO: test keyLen 63 | 64 | output := make([]byte, keyLen) 65 | argon2(output, password, salt, nil, nil, uint32(par), uint32(mem), uint32(n), nil) 66 | return output, nil 67 | } 68 | -------------------------------------------------------------------------------- /vendor/github.com/magical/argon2/api_test.go: -------------------------------------------------------------------------------- 1 | package argon2 2 | 3 | import ( 4 | "fmt" 5 | "strings" 6 | "testing" 7 | ) 8 | 9 | var zeros [16]byte 10 | var ones = [8]byte{1, 1, 1, 1, 1, 1, 1, 1} 11 | 12 | // Fake salt function for the example 13 | func randomSalt() []byte { 14 | return ones[:8] 15 | } 16 | 17 | func ExampleKey() { 18 | pw := []byte("hunter2") 19 | salt := randomSalt() 20 | 21 | key, err := Key(pw, salt, 3, 1, 8, 32) 22 | if err != nil { 23 | fmt.Println(err) 24 | return 25 | } 26 | 27 | fmt.Printf("%x", key) 28 | // Output: c5dd631f4e715853e0354326c56f7c3aac983e5d86f7fb02f935899c38690f9e 29 | } 30 | 31 | func TestKeyErr(t *testing.T) { 32 | pw := zeros[:] 33 | salt := ones[:] 34 | 35 | want := "salt too short" 36 | _, err := Key(pw, salt[:1], 3, 1, 8, 8) 37 | if err == nil { 38 | t.Errorf("got nil error, expected %q", want) 39 | } else if !strings.Contains(err.Error(), want) { 40 | t.Errorf("got %q, expected %q", err, want) 41 | } 42 | 43 | want = "invalid par" 44 | _, err = Key(pw, salt, 3, 256, 8, 8) 45 | if err == nil { 46 | t.Errorf("got nil error, expected %q", want) 47 | } else if !strings.Contains(err.Error(), want) { 48 | t.Errorf("got %q, expected %q", err, want) 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /vendor/github.com/magical/argon2/round.py: -------------------------------------------------------------------------------- 1 | print("package argon2") 2 | print() 3 | print("func block(z, a, b *[128]uint64) {") 4 | 5 | for i in range(128): 6 | print("\tz[%d] = a[%d] ^ b[%d]" % (i, i, i)) 7 | 8 | for b in range(0, 128, 16): 9 | print("\t_P(" + ", ".join("&z[%d]" % i for i in range(b, b+16)) + ")") 10 | 11 | for b in range(0, 16, 2): 12 | print("\t_P(" + ", ".join("&z[%d], &z[%d]" % (i, i+1) for i in range(b, 128, 16)) + ")") 13 | 14 | for i in range(128): 15 | print("\tz[%d] ^= a[%d] ^ b[%d]" % (i, i, i)) 16 | 17 | print("}") 18 | print() 19 | print("func _P("+", ".join("p%d" % i for i in range(16))+" *uint64) {") 20 | for i in range(16): 21 | print("\tvar v%d = *p%d" % (i, i)) 22 | print("\tvar t uint64") 23 | 24 | def G(a, b, c, d): 25 | print("\tt = uint64(uint32(%s)) * uint64(uint32(%s))" % (a, b)) 26 | print("\t%s = %s + %s + t*2" % (a, a, b)) 27 | print("\t%s = %s ^ %s" % (d, d, a)) 28 | print("\t%s = %s>>32 | %s<<32" % (d, d, d)) 29 | print("\tt = uint64(uint32(%s)) * uint64(uint32(%s))" % (c, d)) 30 | print("\t%s = %s + %s + t*2" % (c, c, d)) 31 | print("\t%s = %s ^ %s" % (b, b, c)) 32 | print("\t%s = %s>>24 | %s<<40" % (b, b, b)) 33 | print("\tt = uint64(uint32(%s)) * uint64(uint32(%s))" % (a, b)) 34 | print("\t%s = %s + %s + t*2" % (a, a, b)) 35 | print("\t%s = %s ^ %s" % (d, d, a)) 36 | print("\t%s = %s>>16 | %s<<48" % (d, d, d)) 37 | print("\tt = uint64(uint32(%s)) * uint64(uint32(%s))" % (c, d)) 38 | print("\t%s = %s + %s + t*2" % (c, c, d)) 39 | print("\t%s = %s ^ %s" % (b, b, c)) 40 | print("\t%s = %s>>63 | %s<<1" % (b, b, b)) 41 | 42 | G("v0", "v4", "v8", "v12") 43 | G("v1", "v5", "v9", "v13") 44 | G("v2", "v6", "v10", "v14") 45 | G("v3", "v7", "v11", "v15") 46 | G("v0", "v5", "v10", "v15") 47 | G("v1", "v6", "v11", "v12") 48 | G("v2", "v7", "v8", "v13") 49 | G("v3", "v4", "v9", "v14") 50 | 51 | for i in range(16): 52 | print("\t*p%d = v%d" % (i, i)) 53 | 54 | print("}") 55 | -------------------------------------------------------------------------------- /vendor/github.com/wg/ecies/aead.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 - Will Glozer. All rights reserved. 2 | 3 | package ecies 4 | 5 | import ( 6 | "crypto/cipher" 7 | "crypto/subtle" 8 | "errors" 9 | 10 | "github.com/wg/ecies/chacha20poly1305" 11 | "github.com/wg/ecies/xchacha20poly1305" 12 | ) 13 | 14 | var ( 15 | ErrInvalidKeySize = errors.New("cipher: invalid key length") 16 | ErrAuthFailed = errors.New("cipher: message auth failed") 17 | ) 18 | 19 | type AEAD struct { 20 | key []byte 21 | nonceSize int 22 | tagSize int 23 | Cipher 24 | } 25 | 26 | func NewXChaCha20Poly1305(key []byte) (cipher.AEAD, error) { 27 | if len(key) != xchacha20poly1305.KeySize { 28 | return nil, ErrInvalidKeySize 29 | } 30 | 31 | core := &xchacha20poly1305.XChaCha20Poly1305{} 32 | 33 | return &AEAD{ 34 | key: key, 35 | nonceSize: xchacha20poly1305.NonceSize, 36 | tagSize: xchacha20poly1305.TagSize, 37 | Cipher: core, 38 | }, nil 39 | } 40 | 41 | func NewChaCha20Poly1305(key []byte) (cipher.AEAD, error) { 42 | if len(key) != chacha20poly1305.KeySize { 43 | return nil, ErrInvalidKeySize 44 | } 45 | 46 | core := &chacha20poly1305.ChaCha20Poly1305{} 47 | 48 | return &AEAD{ 49 | key: key, 50 | nonceSize: chacha20poly1305.NonceSize, 51 | tagSize: chacha20poly1305.TagSize, 52 | Cipher: core, 53 | }, nil 54 | } 55 | 56 | func (a *AEAD) NonceSize() int { 57 | return a.nonceSize 58 | } 59 | 60 | func (a *AEAD) Overhead() int { 61 | return a.tagSize 62 | } 63 | 64 | func (a *AEAD) Open(dst, nonce, src, aad []byte) ([]byte, error) { 65 | err := a.Init(a.key, nonce) 66 | if err != nil { 67 | return nil, err 68 | } 69 | 70 | n := len(src) - a.tagSize 71 | dst, ret := extend(dst, n) 72 | src, tag := src[:n], src[n:] 73 | 74 | a.Auth(aad) 75 | a.Decrypt(dst, src) 76 | 77 | if subtle.ConstantTimeCompare(tag, a.Tag(nil)) != 1 { 78 | return nil, ErrAuthFailed 79 | } 80 | 81 | return ret, nil 82 | } 83 | 84 | func (a *AEAD) Seal(dst, nonce, src, aad []byte) []byte { 85 | err := a.Init(a.key, nonce) 86 | if err != nil { 87 | panic(err) 88 | } 89 | 90 | n := len(src) + a.tagSize 91 | dst, ret := extend(dst, n) 92 | tag := dst[len(src):] 93 | 94 | a.Auth(aad) 95 | a.Encrypt(dst, src) 96 | a.Tag(tag[:0]) 97 | 98 | return ret 99 | } 100 | 101 | func extend(dst []byte, n int) ([]byte, []byte) { 102 | if len(dst) < n { 103 | dst = append(dst, make([]byte, n)...) 104 | } 105 | return dst, dst[:n] 106 | } 107 | -------------------------------------------------------------------------------- /vendor/github.com/wg/ecies/aead_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 - Will Glozer. All rights reserved. 2 | 3 | package ecies 4 | 5 | import ( 6 | "bytes" 7 | "testing" 8 | ) 9 | 10 | func TestRFC7539(t *testing.T) { 11 | plaintext := []byte{ 12 | 0x4c, 0x61, 0x64, 0x69, 0x65, 0x73, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x47, 0x65, 0x6e, 0x74, 0x6c, 13 | 0x65, 0x6d, 0x65, 0x6e, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6c, 0x61, 0x73, 14 | 0x73, 0x20, 0x6f, 0x66, 0x20, 0x27, 0x39, 0x39, 0x3a, 0x20, 0x49, 0x66, 0x20, 0x49, 0x20, 0x63, 15 | 0x6f, 0x75, 0x6c, 0x64, 0x20, 0x6f, 0x66, 0x66, 0x65, 0x72, 0x20, 0x79, 0x6f, 0x75, 0x20, 0x6f, 16 | 0x6e, 0x6c, 0x79, 0x20, 0x6f, 0x6e, 0x65, 0x20, 0x74, 0x69, 0x70, 0x20, 0x66, 0x6f, 0x72, 0x20, 17 | 0x74, 0x68, 0x65, 0x20, 0x66, 0x75, 0x74, 0x75, 0x72, 0x65, 0x2c, 0x20, 0x73, 0x75, 0x6e, 0x73, 18 | 0x63, 0x72, 0x65, 0x65, 0x6e, 0x20, 0x77, 0x6f, 0x75, 0x6c, 0x64, 0x20, 0x62, 0x65, 0x20, 0x69, 19 | 0x74, 0x2e, 20 | } 21 | 22 | aad := []byte{ 23 | 0x50, 0x51, 0x52, 0x53, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 24 | } 25 | 26 | key := []byte{ 27 | 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 28 | 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 29 | } 30 | 31 | nonce := []byte{ 32 | 0x07, 0x00, 0x00, 0x00, 33 | 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 34 | } 35 | 36 | ciphertext := []byte{ 37 | 0xd3, 0x1a, 0x8d, 0x34, 0x64, 0x8e, 0x60, 0xdb, 0x7b, 0x86, 0xaf, 0xbc, 0x53, 0xef, 0x7e, 0xc2, 38 | 0xa4, 0xad, 0xed, 0x51, 0x29, 0x6e, 0x08, 0xfe, 0xa9, 0xe2, 0xb5, 0xa7, 0x36, 0xee, 0x62, 0xd6, 39 | 0x3d, 0xbe, 0xa4, 0x5e, 0x8c, 0xa9, 0x67, 0x12, 0x82, 0xfa, 0xfb, 0x69, 0xda, 0x92, 0x72, 0x8b, 40 | 0x1a, 0x71, 0xde, 0x0a, 0x9e, 0x06, 0x0b, 0x29, 0x05, 0xd6, 0xa5, 0xb6, 0x7e, 0xcd, 0x3b, 0x36, 41 | 0x92, 0xdd, 0xbd, 0x7f, 0x2d, 0x77, 0x8b, 0x8c, 0x98, 0x03, 0xae, 0xe3, 0x28, 0x09, 0x1b, 0x58, 42 | 0xfa, 0xb3, 0x24, 0xe4, 0xfa, 0xd6, 0x75, 0x94, 0x55, 0x85, 0x80, 0x8b, 0x48, 0x31, 0xd7, 0xbc, 43 | 0x3f, 0xf4, 0xde, 0xf0, 0x8e, 0x4b, 0x7a, 0x9d, 0xe5, 0x76, 0xd2, 0x65, 0x86, 0xce, 0xc6, 0x4b, 44 | 0x61, 0x16, 45 | } 46 | 47 | tag := []byte{ 48 | 0x1a, 0xe1, 0x0b, 0x59, 0x4f, 0x09, 0xe2, 0x6a, 0x7e, 0x90, 0x2e, 0xcb, 0xd0, 0x60, 0x06, 0x91, 49 | } 50 | 51 | aead, err := NewChaCha20Poly1305(key) 52 | if err != nil { 53 | t.Fatal(err) 54 | } 55 | 56 | sealed := aead.Seal(nil, nonce, plaintext, aad) 57 | if !bytes.Equal(sealed, append(ciphertext, tag...)) { 58 | t.Fatal("Seal: ciphertext|tag incorrect") 59 | } 60 | 61 | opened, err := aead.Open(nil, nonce, append(ciphertext, tag...), aad) 62 | if err != nil { 63 | t.Fatal(err) 64 | } 65 | 66 | if !bytes.Equal(opened, plaintext) { 67 | t.Fatal("Open: plaintext incorrect") 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /vendor/github.com/wg/ecies/box.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 - Will Glozer. All rights reserved. 2 | 3 | package ecies 4 | 5 | import ( 6 | "crypto/subtle" 7 | "errors" 8 | 9 | "github.com/dchest/blake2b" 10 | "github.com/wg/ecies/xchacha20poly1305" 11 | ) 12 | 13 | var ( 14 | ErrBoxAuthFailed = errors.New("box: message auth failed") 15 | ErrBoxTooSmall = errors.New("box: destination too small") 16 | ErrBoxInvariant = errors.New("box: invariant violation") 17 | ) 18 | 19 | type Box struct { 20 | key [xchacha20poly1305.KeySize]byte 21 | xchacha20poly1305.XChaCha20Poly1305 22 | } 23 | 24 | func NewX25519XChaCha20Poly1305(publicKey, privateKey *[32]byte) (*Box, error) { 25 | var secret [32]byte 26 | if err := X25519(&secret, publicKey, privateKey); err != nil { 27 | return nil, err 28 | } 29 | return newXChaCha20Poly1305Box(secret[:]) 30 | } 31 | 32 | func NewX448XChaCha20Poly1305(publicKey, privateKey *[56]byte) (*Box, error) { 33 | var secret [56]byte 34 | if err := X448(&secret, publicKey, privateKey); err != nil { 35 | return nil, err 36 | } 37 | return newXChaCha20Poly1305Box(secret[:]) 38 | } 39 | 40 | func (b *Box) Seal(dst, msg, nonce []byte) error { 41 | if cap(dst) < len(msg)+xchacha20poly1305.TagSize { 42 | return ErrBoxTooSmall 43 | } 44 | 45 | if err := b.Init(b.key[:], nonce); err != nil { 46 | return err 47 | } 48 | 49 | n := len(msg) 50 | b.Encrypt(dst, msg) 51 | b.Tag(dst[n:n]) 52 | 53 | return nil 54 | } 55 | 56 | func (b *Box) Open(dst, msg, nonce []byte) error { 57 | if cap(dst) < len(msg)-xchacha20poly1305.TagSize { 58 | return ErrBoxTooSmall 59 | } 60 | 61 | if err := b.Init(b.key[:], nonce); err != nil { 62 | return err 63 | } 64 | 65 | n := len(msg) - xchacha20poly1305.TagSize 66 | msg, tag := msg[:n], msg[n:] 67 | b.Decrypt(dst, msg) 68 | 69 | if subtle.ConstantTimeCompare(tag, b.Tag(nil)) != 1 { 70 | return ErrBoxAuthFailed 71 | } 72 | 73 | return nil 74 | } 75 | 76 | func newXChaCha20Poly1305Box(secret []byte) (*Box, error) { 77 | h, err := blake2b.New(&blake2b.Config{ 78 | Size: xchacha20poly1305.KeySize, 79 | }) 80 | 81 | if err != nil { 82 | return nil, ErrBoxInvariant 83 | } 84 | 85 | box := &Box{} 86 | h.Write(secret) 87 | h.Sum(box.key[:0]) 88 | 89 | return box, nil 90 | } 91 | -------------------------------------------------------------------------------- /vendor/github.com/wg/ecies/box_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 - Will Glozer. All rights reserved. 2 | 3 | package ecies 4 | 5 | import ( 6 | "bytes" 7 | "crypto/rand" 8 | "testing" 9 | 10 | "github.com/dchest/blake2b" 11 | "github.com/wg/ecies/xchacha20poly1305" 12 | ) 13 | 14 | func TestXChaCha20Poly1305KeySetup(t *testing.T) { 15 | secret := []byte("secret") 16 | 17 | cfg := blake2b.Config{Size: xchacha20poly1305.KeySize} 18 | hash, err := blake2b.New(&cfg) 19 | if err != nil { 20 | t.Fatal(err) 21 | } 22 | 23 | hash.Write(secret) 24 | key := hash.Sum(nil) 25 | 26 | box, err := newXChaCha20Poly1305Box(secret) 27 | if err != nil { 28 | t.Fatal(err) 29 | } 30 | 31 | if !bytes.Equal(box.key[:], key) { 32 | t.Fatal("box key initialization incorrect") 33 | } 34 | } 35 | 36 | func TestXChaCha20Poly1305Box(t *testing.T) { 37 | const tagSize = xchacha20poly1305.TagSize 38 | 39 | var ( 40 | key [xchacha20poly1305.KeySize]byte 41 | nonce [xchacha20poly1305.NonceSize]byte 42 | msg [64]byte 43 | raw [len(msg) + tagSize]byte 44 | sealed [len(msg) + tagSize]byte 45 | opened [len(msg) + tagSize]byte 46 | box Box 47 | ) 48 | 49 | rand.Read(key[:]) 50 | rand.Read(nonce[:]) 51 | rand.Read(msg[:]) 52 | copy(box.key[:], key[:]) 53 | 54 | c := xchacha20poly1305.New(&key, &nonce) 55 | c.Encrypt(raw[:], msg[:]) 56 | c.Tag(raw[len(msg):len(msg)]) 57 | 58 | err := box.Seal(sealed[:], msg[:], nonce[:]) 59 | if err != nil { 60 | t.Fatal(err) 61 | } 62 | 63 | if !bytes.Equal(sealed[:len(msg)], raw[:len(msg)]) { 64 | t.Fatal("sealed ciphertext != raw ciphertext") 65 | } 66 | 67 | if !bytes.Equal(sealed[len(msg):], raw[len(msg):]) { 68 | t.Fatal("sealed auth tag != raw auth tag") 69 | } 70 | 71 | err = box.Open(opened[:], sealed[:], nonce[:]) 72 | if err != nil { 73 | t.Fatal(err) 74 | } 75 | 76 | if !bytes.Equal(opened[:len(msg)], msg[:]) { 77 | t.Fatal("opened plaintext != original plaintext") 78 | } 79 | } 80 | 81 | func TestXChaCha20Poly1305BoxInPlace(t *testing.T) { 82 | const tagSize = xchacha20poly1305.TagSize 83 | 84 | var ( 85 | key [xchacha20poly1305.KeySize]byte 86 | nonce [xchacha20poly1305.NonceSize]byte 87 | msg [64]byte 88 | raw [len(msg) + tagSize]byte 89 | dst [len(msg) + tagSize]byte 90 | box Box 91 | ) 92 | 93 | rand.Read(key[:]) 94 | rand.Read(nonce[:]) 95 | rand.Read(msg[:]) 96 | copy(dst[:], msg[:]) 97 | copy(box.key[:], key[:]) 98 | 99 | c := xchacha20poly1305.New(&key, &nonce) 100 | c.Encrypt(raw[:], msg[:]) 101 | c.Tag(raw[len(msg):len(msg)]) 102 | 103 | err := box.Seal(dst[:], dst[:len(msg)], nonce[:]) 104 | if err != nil { 105 | t.Fatal(err) 106 | } 107 | 108 | if !bytes.Equal(dst[:len(msg)], raw[:len(msg)]) { 109 | t.Fatal("sealed ciphertext != raw ciphertext") 110 | } 111 | 112 | if !bytes.Equal(dst[len(msg):], raw[len(msg):]) { 113 | t.Fatal("sealed auth tag != raw auth tag") 114 | } 115 | 116 | err = box.Open(dst[:], dst[:], nonce[:]) 117 | if err != nil { 118 | t.Fatal(err) 119 | } 120 | 121 | if !bytes.Equal(dst[:len(msg)], msg[:]) { 122 | t.Fatal("opened plaintext != original plaintext") 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /vendor/github.com/wg/ecies/chacha20poly1305/chacha20poly1305.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 - Will Glozer. All rights reserved. 2 | 3 | // Package chacha20poly1305 implements the AEAD_CHACHA20_POLY1305 4 | // construction as specified in RFC 7539. 5 | package chacha20poly1305 6 | 7 | import ( 8 | "encoding/binary" 9 | 10 | "schwanenlied.me/yawning/chacha20" 11 | "schwanenlied.me/yawning/poly1305" 12 | ) 13 | 14 | const ( 15 | KeySize = chacha20.KeySize 16 | NonceSize = chacha20.INonceSize 17 | TagSize = poly1305.Size 18 | ) 19 | 20 | var padding [16]byte 21 | 22 | type ChaCha20Poly1305 struct { 23 | a, n uint64 24 | chacha20.Cipher 25 | poly1305.Poly1305 26 | } 27 | 28 | func New(key *[KeySize]byte, nonce *[NonceSize]byte) *ChaCha20Poly1305 { 29 | x := &ChaCha20Poly1305{} 30 | x.Init(key[:], nonce[:]) 31 | return x 32 | } 33 | 34 | func (x *ChaCha20Poly1305) Init(key, nonce []byte) error { 35 | err := x.ReKey(key, nonce) 36 | if err == nil { 37 | x.initPoly1305() 38 | x.Seek(1) 39 | x.a = 0 40 | x.n = 0 41 | } 42 | return err 43 | } 44 | 45 | func (x *ChaCha20Poly1305) Auth(src []byte) { 46 | if n := len(src); n > 0 { 47 | x.Poly1305.Write(src) 48 | x.a = uint64(n) 49 | x.Poly1305.Write(padding[:16-n%16]) 50 | } 51 | } 52 | 53 | func (x *ChaCha20Poly1305) Decrypt(dst, src []byte) { 54 | x.Poly1305.Write(src) 55 | x.XORKeyStream(dst, src) 56 | x.n += uint64(len(src)) 57 | } 58 | 59 | func (x *ChaCha20Poly1305) Encrypt(dst, src []byte) { 60 | n := len(src) 61 | x.XORKeyStream(dst, src) 62 | x.Poly1305.Write(dst[:n]) 63 | x.n += uint64(n) 64 | } 65 | 66 | func (x *ChaCha20Poly1305) Tag(b []byte) []byte { 67 | var lengths [16]byte 68 | binary.LittleEndian.PutUint64(lengths[0:], uint64(x.a)) 69 | binary.LittleEndian.PutUint64(lengths[8:], uint64(x.n)) 70 | x.Poly1305.Write(padding[:16-x.n%16]) 71 | x.Poly1305.Write(lengths[:]) 72 | return x.Poly1305.Sum(b) 73 | } 74 | 75 | func (x *ChaCha20Poly1305) Reset() { 76 | x.Cipher.Reset() 77 | } 78 | 79 | func (x *ChaCha20Poly1305) TagSize() int { 80 | return TagSize 81 | } 82 | 83 | func (x *ChaCha20Poly1305) initPoly1305() { 84 | var key [poly1305.KeySize]byte 85 | x.KeyStream(key[:]) 86 | x.Poly1305.Init(key[:]) 87 | for i := range key { 88 | key[i] = 0 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /vendor/github.com/wg/ecies/cipher.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 - Will Glozer. All rights reserved. 2 | 3 | package ecies 4 | 5 | type Cipher interface { 6 | Init(key, nonce []byte) error 7 | Auth(src []byte) 8 | Decrypt(dst, src []byte) 9 | Encrypt(dst, src []byte) 10 | Tag(tag []byte) []byte 11 | Reset() 12 | TagSize() int 13 | } 14 | -------------------------------------------------------------------------------- /vendor/github.com/wg/ecies/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 - Will Glozer. All rights reserved. 2 | 3 | /* 4 | Package ecies provides a convenient interface to a number of Elliptic Curve 5 | Integrated Encryption Schemes and their corresponding primitives: Curve25519, 6 | Curve448 AKA Ed448-Goldilocks, XChaCha20, Poly1305, and BLAKE2b. 7 | 8 | This package has not been subject to peer review and the specific algorithm 9 | combinations have not been standardized. 10 | 11 | The cryptographic core is provided by Yawning Angel's excellent open-source x448, 12 | ChaCha20, and Poly1305 libraries, but any mistakes are the fault of Will Glozer. 13 | */ 14 | package ecies 15 | -------------------------------------------------------------------------------- /vendor/github.com/wg/ecies/ecdh.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 - Will Glozer. All rights reserved. 2 | 3 | package ecies 4 | 5 | import ( 6 | "errors" 7 | "io" 8 | 9 | "golang.org/x/crypto/curve25519" 10 | "schwanenlied.me/yawning/x448" 11 | ) 12 | 13 | var ErrX448 = errors.New("curve448: key exchange failed") 14 | 15 | func GenerateCurve25519Key(rand io.Reader, public, private *[32]byte) error { 16 | _, err := io.ReadFull(rand, private[:]) 17 | if err != nil { 18 | return err 19 | } 20 | curve25519.ScalarBaseMult(public, private) 21 | return nil 22 | } 23 | 24 | func GenerateCurve448Key(rand io.Reader, public, private *[56]byte) error { 25 | _, err := io.ReadFull(rand, private[:]) 26 | if err != nil { 27 | return err 28 | } 29 | x448.ScalarBaseMult(public, private) 30 | return nil 31 | } 32 | 33 | func X25519(secret, public, private *[32]byte) error { 34 | curve25519.ScalarMult(secret, private, public) 35 | return nil 36 | } 37 | 38 | func X448(secret, public, private *[56]byte) error { 39 | if x448.ScalarMult(secret, private, public) != 0 { 40 | return ErrX448 41 | } 42 | return nil 43 | } 44 | -------------------------------------------------------------------------------- /vendor/github.com/wg/ecies/vendor/github.com/dchest/blake2b/README: -------------------------------------------------------------------------------- 1 | Go implementation of BLAKE2b collision-resistant cryptographic hash function 2 | created by Jean-Philippe Aumasson, Samuel Neves, Zooko Wilcox-O'Hearn, and 3 | Christian Winnerlein (https://blake2.net). 4 | 5 | INSTALLATION 6 | 7 | $ go get github.com/dchest/blake2b 8 | 9 | 10 | DOCUMENTATION 11 | 12 | See http://godoc.org/github.com/dchest/blake2b 13 | 14 | 15 | PUBLIC DOMAIN DEDICATION 16 | 17 | Written in 2012 by Dmitry Chestnykh. 18 | 19 | To the extent possible under law, the author have dedicated all copyright 20 | and related and neighboring rights to this software to the public domain 21 | worldwide. This software is distributed without any warranty. 22 | http://creativecommons.org/publicdomain/zero/1.0/ 23 | 24 | -------------------------------------------------------------------------------- /vendor/github.com/wg/ecies/vendor/golang.org/x/crypto/AUTHORS: -------------------------------------------------------------------------------- 1 | # This source code refers to The Go Authors for copyright purposes. 2 | # The master list of authors is in the main Go distribution, 3 | # visible at http://tip.golang.org/AUTHORS. 4 | -------------------------------------------------------------------------------- /vendor/github.com/wg/ecies/vendor/golang.org/x/crypto/CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | # This source code was written by the Go contributors. 2 | # The master list of contributors is in the main Go distribution, 3 | # visible at http://tip.golang.org/CONTRIBUTORS. 4 | -------------------------------------------------------------------------------- /vendor/github.com/wg/ecies/vendor/golang.org/x/crypto/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009 The Go Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /vendor/github.com/wg/ecies/vendor/golang.org/x/crypto/PATENTS: -------------------------------------------------------------------------------- 1 | Additional IP Rights Grant (Patents) 2 | 3 | "This implementation" means the copyrightable works distributed by 4 | Google as part of the Go project. 5 | 6 | Google hereby grants to You a perpetual, worldwide, non-exclusive, 7 | no-charge, royalty-free, irrevocable (except as stated in this section) 8 | patent license to make, have made, use, offer to sell, sell, import, 9 | transfer and otherwise run, modify and propagate the contents of this 10 | implementation of Go, where such license applies only to those patent 11 | claims, both currently owned or controlled by Google and acquired in 12 | the future, licensable by Google that are necessarily infringed by this 13 | implementation of Go. This grant does not include claims that would be 14 | infringed only as a consequence of further modification of this 15 | implementation. If you or your agent or exclusive licensee institute or 16 | order or agree to the institution of patent litigation against any 17 | entity (including a cross-claim or counterclaim in a lawsuit) alleging 18 | that this implementation of Go or any code incorporated within this 19 | implementation of Go constitutes direct or contributory patent 20 | infringement, or inducement of patent infringement, then any patent 21 | rights granted to you under this License for this implementation of Go 22 | shall terminate as of the date such litigation is filed. 23 | -------------------------------------------------------------------------------- /vendor/github.com/wg/ecies/vendor/golang.org/x/crypto/README: -------------------------------------------------------------------------------- 1 | This repository holds supplementary Go cryptography libraries. 2 | 3 | To submit changes to this repository, see http://golang.org/doc/contribute.html. 4 | -------------------------------------------------------------------------------- /vendor/github.com/wg/ecies/vendor/golang.org/x/crypto/curve25519/const_amd64.s: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // This code was translated into a form compatible with 6a from the public 6 | // domain sources in SUPERCOP: http://bench.cr.yp.to/supercop.html 7 | 8 | // +build amd64,!gccgo,!appengine 9 | 10 | DATA ·REDMASK51(SB)/8, $0x0007FFFFFFFFFFFF 11 | GLOBL ·REDMASK51(SB), 8, $8 12 | 13 | DATA ·_121666_213(SB)/8, $996687872 14 | GLOBL ·_121666_213(SB), 8, $8 15 | 16 | DATA ·_2P0(SB)/8, $0xFFFFFFFFFFFDA 17 | GLOBL ·_2P0(SB), 8, $8 18 | 19 | DATA ·_2P1234(SB)/8, $0xFFFFFFFFFFFFE 20 | GLOBL ·_2P1234(SB), 8, $8 21 | -------------------------------------------------------------------------------- /vendor/github.com/wg/ecies/vendor/golang.org/x/crypto/curve25519/cswap_amd64.s: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // This code was translated into a form compatible with 6a from the public 6 | // domain sources in SUPERCOP: http://bench.cr.yp.to/supercop.html 7 | 8 | // +build amd64,!gccgo,!appengine 9 | 10 | // func cswap(inout *[5]uint64, v uint64) 11 | TEXT ·cswap(SB),7,$0 12 | MOVQ inout+0(FP),DI 13 | MOVQ v+8(FP),SI 14 | 15 | CMPQ SI,$1 16 | MOVQ 0(DI),SI 17 | MOVQ 80(DI),DX 18 | MOVQ 8(DI),CX 19 | MOVQ 88(DI),R8 20 | MOVQ SI,R9 21 | CMOVQEQ DX,SI 22 | CMOVQEQ R9,DX 23 | MOVQ CX,R9 24 | CMOVQEQ R8,CX 25 | CMOVQEQ R9,R8 26 | MOVQ SI,0(DI) 27 | MOVQ DX,80(DI) 28 | MOVQ CX,8(DI) 29 | MOVQ R8,88(DI) 30 | MOVQ 16(DI),SI 31 | MOVQ 96(DI),DX 32 | MOVQ 24(DI),CX 33 | MOVQ 104(DI),R8 34 | MOVQ SI,R9 35 | CMOVQEQ DX,SI 36 | CMOVQEQ R9,DX 37 | MOVQ CX,R9 38 | CMOVQEQ R8,CX 39 | CMOVQEQ R9,R8 40 | MOVQ SI,16(DI) 41 | MOVQ DX,96(DI) 42 | MOVQ CX,24(DI) 43 | MOVQ R8,104(DI) 44 | MOVQ 32(DI),SI 45 | MOVQ 112(DI),DX 46 | MOVQ 40(DI),CX 47 | MOVQ 120(DI),R8 48 | MOVQ SI,R9 49 | CMOVQEQ DX,SI 50 | CMOVQEQ R9,DX 51 | MOVQ CX,R9 52 | CMOVQEQ R8,CX 53 | CMOVQEQ R9,R8 54 | MOVQ SI,32(DI) 55 | MOVQ DX,112(DI) 56 | MOVQ CX,40(DI) 57 | MOVQ R8,120(DI) 58 | MOVQ 48(DI),SI 59 | MOVQ 128(DI),DX 60 | MOVQ 56(DI),CX 61 | MOVQ 136(DI),R8 62 | MOVQ SI,R9 63 | CMOVQEQ DX,SI 64 | CMOVQEQ R9,DX 65 | MOVQ CX,R9 66 | CMOVQEQ R8,CX 67 | CMOVQEQ R9,R8 68 | MOVQ SI,48(DI) 69 | MOVQ DX,128(DI) 70 | MOVQ CX,56(DI) 71 | MOVQ R8,136(DI) 72 | MOVQ 64(DI),SI 73 | MOVQ 144(DI),DX 74 | MOVQ 72(DI),CX 75 | MOVQ 152(DI),R8 76 | MOVQ SI,R9 77 | CMOVQEQ DX,SI 78 | CMOVQEQ R9,DX 79 | MOVQ CX,R9 80 | CMOVQEQ R8,CX 81 | CMOVQEQ R9,R8 82 | MOVQ SI,64(DI) 83 | MOVQ DX,144(DI) 84 | MOVQ CX,72(DI) 85 | MOVQ R8,152(DI) 86 | MOVQ DI,AX 87 | MOVQ SI,DX 88 | RET 89 | -------------------------------------------------------------------------------- /vendor/github.com/wg/ecies/vendor/golang.org/x/crypto/curve25519/curve25519_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package curve25519 6 | 7 | import ( 8 | "fmt" 9 | "testing" 10 | ) 11 | 12 | const expectedHex = "89161fde887b2b53de549af483940106ecc114d6982daa98256de23bdf77661a" 13 | 14 | func TestBaseScalarMult(t *testing.T) { 15 | var a, b [32]byte 16 | in := &a 17 | out := &b 18 | a[0] = 1 19 | 20 | for i := 0; i < 200; i++ { 21 | ScalarBaseMult(out, in) 22 | in, out = out, in 23 | } 24 | 25 | result := fmt.Sprintf("%x", in[:]) 26 | if result != expectedHex { 27 | t.Errorf("incorrect result: got %s, want %s", result, expectedHex) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /vendor/github.com/wg/ecies/vendor/golang.org/x/crypto/curve25519/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package curve25519 provides an implementation of scalar multiplication on 6 | // the elliptic curve known as curve25519. See http://cr.yp.to/ecdh.html 7 | package curve25519 // import "golang.org/x/crypto/curve25519" 8 | 9 | // basePoint is the x coordinate of the generator of the curve. 10 | var basePoint = [32]byte{9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} 11 | 12 | // ScalarMult sets dst to the product in*base where dst and base are the x 13 | // coordinates of group points and all values are in little-endian form. 14 | func ScalarMult(dst, in, base *[32]byte) { 15 | scalarMult(dst, in, base) 16 | } 17 | 18 | // ScalarBaseMult sets dst to the product in*base where dst and base are the x 19 | // coordinates of group points, base is the standard generator and all values 20 | // are in little-endian form. 21 | func ScalarBaseMult(dst, in *[32]byte) { 22 | ScalarMult(dst, in, &basePoint) 23 | } 24 | -------------------------------------------------------------------------------- /vendor/github.com/wg/ecies/vendor/golang.org/x/crypto/curve25519/freeze_amd64.s: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // This code was translated into a form compatible with 6a from the public 6 | // domain sources in SUPERCOP: http://bench.cr.yp.to/supercop.html 7 | 8 | // +build amd64,!gccgo,!appengine 9 | 10 | // func freeze(inout *[5]uint64) 11 | TEXT ·freeze(SB),7,$96-8 12 | MOVQ inout+0(FP), DI 13 | 14 | MOVQ SP,R11 15 | MOVQ $31,CX 16 | NOTQ CX 17 | ANDQ CX,SP 18 | ADDQ $32,SP 19 | 20 | MOVQ R11,0(SP) 21 | MOVQ R12,8(SP) 22 | MOVQ R13,16(SP) 23 | MOVQ R14,24(SP) 24 | MOVQ R15,32(SP) 25 | MOVQ BX,40(SP) 26 | MOVQ BP,48(SP) 27 | MOVQ 0(DI),SI 28 | MOVQ 8(DI),DX 29 | MOVQ 16(DI),CX 30 | MOVQ 24(DI),R8 31 | MOVQ 32(DI),R9 32 | MOVQ ·REDMASK51(SB),AX 33 | MOVQ AX,R10 34 | SUBQ $18,R10 35 | MOVQ $3,R11 36 | REDUCELOOP: 37 | MOVQ SI,R12 38 | SHRQ $51,R12 39 | ANDQ AX,SI 40 | ADDQ R12,DX 41 | MOVQ DX,R12 42 | SHRQ $51,R12 43 | ANDQ AX,DX 44 | ADDQ R12,CX 45 | MOVQ CX,R12 46 | SHRQ $51,R12 47 | ANDQ AX,CX 48 | ADDQ R12,R8 49 | MOVQ R8,R12 50 | SHRQ $51,R12 51 | ANDQ AX,R8 52 | ADDQ R12,R9 53 | MOVQ R9,R12 54 | SHRQ $51,R12 55 | ANDQ AX,R9 56 | IMUL3Q $19,R12,R12 57 | ADDQ R12,SI 58 | SUBQ $1,R11 59 | JA REDUCELOOP 60 | MOVQ $1,R12 61 | CMPQ R10,SI 62 | CMOVQLT R11,R12 63 | CMPQ AX,DX 64 | CMOVQNE R11,R12 65 | CMPQ AX,CX 66 | CMOVQNE R11,R12 67 | CMPQ AX,R8 68 | CMOVQNE R11,R12 69 | CMPQ AX,R9 70 | CMOVQNE R11,R12 71 | NEGQ R12 72 | ANDQ R12,AX 73 | ANDQ R12,R10 74 | SUBQ R10,SI 75 | SUBQ AX,DX 76 | SUBQ AX,CX 77 | SUBQ AX,R8 78 | SUBQ AX,R9 79 | MOVQ SI,0(DI) 80 | MOVQ DX,8(DI) 81 | MOVQ CX,16(DI) 82 | MOVQ R8,24(DI) 83 | MOVQ R9,32(DI) 84 | MOVQ 0(SP),R11 85 | MOVQ 8(SP),R12 86 | MOVQ 16(SP),R13 87 | MOVQ 24(SP),R14 88 | MOVQ 32(SP),R15 89 | MOVQ 40(SP),BX 90 | MOVQ 48(SP),BP 91 | MOVQ R11,SP 92 | MOVQ DI,AX 93 | MOVQ SI,DX 94 | RET 95 | -------------------------------------------------------------------------------- /vendor/github.com/wg/ecies/vendor/golang.org/x/crypto/curve25519/mul_amd64.s: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // This code was translated into a form compatible with 6a from the public 6 | // domain sources in SUPERCOP: http://bench.cr.yp.to/supercop.html 7 | 8 | // +build amd64,!gccgo,!appengine 9 | 10 | // func mul(dest, a, b *[5]uint64) 11 | TEXT ·mul(SB),0,$128-24 12 | MOVQ dest+0(FP), DI 13 | MOVQ a+8(FP), SI 14 | MOVQ b+16(FP), DX 15 | 16 | MOVQ SP,R11 17 | MOVQ $31,CX 18 | NOTQ CX 19 | ANDQ CX,SP 20 | ADDQ $32,SP 21 | 22 | MOVQ R11,0(SP) 23 | MOVQ R12,8(SP) 24 | MOVQ R13,16(SP) 25 | MOVQ R14,24(SP) 26 | MOVQ R15,32(SP) 27 | MOVQ BX,40(SP) 28 | MOVQ BP,48(SP) 29 | MOVQ DI,56(SP) 30 | MOVQ DX,CX 31 | MOVQ 24(SI),DX 32 | IMUL3Q $19,DX,AX 33 | MOVQ AX,64(SP) 34 | MULQ 16(CX) 35 | MOVQ AX,R8 36 | MOVQ DX,R9 37 | MOVQ 32(SI),DX 38 | IMUL3Q $19,DX,AX 39 | MOVQ AX,72(SP) 40 | MULQ 8(CX) 41 | ADDQ AX,R8 42 | ADCQ DX,R9 43 | MOVQ 0(SI),AX 44 | MULQ 0(CX) 45 | ADDQ AX,R8 46 | ADCQ DX,R9 47 | MOVQ 0(SI),AX 48 | MULQ 8(CX) 49 | MOVQ AX,R10 50 | MOVQ DX,R11 51 | MOVQ 0(SI),AX 52 | MULQ 16(CX) 53 | MOVQ AX,R12 54 | MOVQ DX,R13 55 | MOVQ 0(SI),AX 56 | MULQ 24(CX) 57 | MOVQ AX,R14 58 | MOVQ DX,R15 59 | MOVQ 0(SI),AX 60 | MULQ 32(CX) 61 | MOVQ AX,BX 62 | MOVQ DX,BP 63 | MOVQ 8(SI),AX 64 | MULQ 0(CX) 65 | ADDQ AX,R10 66 | ADCQ DX,R11 67 | MOVQ 8(SI),AX 68 | MULQ 8(CX) 69 | ADDQ AX,R12 70 | ADCQ DX,R13 71 | MOVQ 8(SI),AX 72 | MULQ 16(CX) 73 | ADDQ AX,R14 74 | ADCQ DX,R15 75 | MOVQ 8(SI),AX 76 | MULQ 24(CX) 77 | ADDQ AX,BX 78 | ADCQ DX,BP 79 | MOVQ 8(SI),DX 80 | IMUL3Q $19,DX,AX 81 | MULQ 32(CX) 82 | ADDQ AX,R8 83 | ADCQ DX,R9 84 | MOVQ 16(SI),AX 85 | MULQ 0(CX) 86 | ADDQ AX,R12 87 | ADCQ DX,R13 88 | MOVQ 16(SI),AX 89 | MULQ 8(CX) 90 | ADDQ AX,R14 91 | ADCQ DX,R15 92 | MOVQ 16(SI),AX 93 | MULQ 16(CX) 94 | ADDQ AX,BX 95 | ADCQ DX,BP 96 | MOVQ 16(SI),DX 97 | IMUL3Q $19,DX,AX 98 | MULQ 24(CX) 99 | ADDQ AX,R8 100 | ADCQ DX,R9 101 | MOVQ 16(SI),DX 102 | IMUL3Q $19,DX,AX 103 | MULQ 32(CX) 104 | ADDQ AX,R10 105 | ADCQ DX,R11 106 | MOVQ 24(SI),AX 107 | MULQ 0(CX) 108 | ADDQ AX,R14 109 | ADCQ DX,R15 110 | MOVQ 24(SI),AX 111 | MULQ 8(CX) 112 | ADDQ AX,BX 113 | ADCQ DX,BP 114 | MOVQ 64(SP),AX 115 | MULQ 24(CX) 116 | ADDQ AX,R10 117 | ADCQ DX,R11 118 | MOVQ 64(SP),AX 119 | MULQ 32(CX) 120 | ADDQ AX,R12 121 | ADCQ DX,R13 122 | MOVQ 32(SI),AX 123 | MULQ 0(CX) 124 | ADDQ AX,BX 125 | ADCQ DX,BP 126 | MOVQ 72(SP),AX 127 | MULQ 16(CX) 128 | ADDQ AX,R10 129 | ADCQ DX,R11 130 | MOVQ 72(SP),AX 131 | MULQ 24(CX) 132 | ADDQ AX,R12 133 | ADCQ DX,R13 134 | MOVQ 72(SP),AX 135 | MULQ 32(CX) 136 | ADDQ AX,R14 137 | ADCQ DX,R15 138 | MOVQ ·REDMASK51(SB),SI 139 | SHLQ $13,R9:R8 140 | ANDQ SI,R8 141 | SHLQ $13,R11:R10 142 | ANDQ SI,R10 143 | ADDQ R9,R10 144 | SHLQ $13,R13:R12 145 | ANDQ SI,R12 146 | ADDQ R11,R12 147 | SHLQ $13,R15:R14 148 | ANDQ SI,R14 149 | ADDQ R13,R14 150 | SHLQ $13,BP:BX 151 | ANDQ SI,BX 152 | ADDQ R15,BX 153 | IMUL3Q $19,BP,DX 154 | ADDQ DX,R8 155 | MOVQ R8,DX 156 | SHRQ $51,DX 157 | ADDQ R10,DX 158 | MOVQ DX,CX 159 | SHRQ $51,DX 160 | ANDQ SI,R8 161 | ADDQ R12,DX 162 | MOVQ DX,R9 163 | SHRQ $51,DX 164 | ANDQ SI,CX 165 | ADDQ R14,DX 166 | MOVQ DX,AX 167 | SHRQ $51,DX 168 | ANDQ SI,R9 169 | ADDQ BX,DX 170 | MOVQ DX,R10 171 | SHRQ $51,DX 172 | ANDQ SI,AX 173 | IMUL3Q $19,DX,DX 174 | ADDQ DX,R8 175 | ANDQ SI,R10 176 | MOVQ R8,0(DI) 177 | MOVQ CX,8(DI) 178 | MOVQ R9,16(DI) 179 | MOVQ AX,24(DI) 180 | MOVQ R10,32(DI) 181 | MOVQ 0(SP),R11 182 | MOVQ 8(SP),R12 183 | MOVQ 16(SP),R13 184 | MOVQ 24(SP),R14 185 | MOVQ 32(SP),R15 186 | MOVQ 40(SP),BX 187 | MOVQ 48(SP),BP 188 | MOVQ R11,SP 189 | MOVQ DI,AX 190 | MOVQ SI,DX 191 | RET 192 | -------------------------------------------------------------------------------- /vendor/github.com/wg/ecies/vendor/golang.org/x/crypto/curve25519/square_amd64.s: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // This code was translated into a form compatible with 6a from the public 6 | // domain sources in SUPERCOP: http://bench.cr.yp.to/supercop.html 7 | 8 | // +build amd64,!gccgo,!appengine 9 | 10 | // func square(out, in *[5]uint64) 11 | TEXT ·square(SB),7,$96-16 12 | MOVQ out+0(FP), DI 13 | MOVQ in+8(FP), SI 14 | 15 | MOVQ SP,R11 16 | MOVQ $31,CX 17 | NOTQ CX 18 | ANDQ CX,SP 19 | ADDQ $32, SP 20 | 21 | MOVQ R11,0(SP) 22 | MOVQ R12,8(SP) 23 | MOVQ R13,16(SP) 24 | MOVQ R14,24(SP) 25 | MOVQ R15,32(SP) 26 | MOVQ BX,40(SP) 27 | MOVQ BP,48(SP) 28 | MOVQ 0(SI),AX 29 | MULQ 0(SI) 30 | MOVQ AX,CX 31 | MOVQ DX,R8 32 | MOVQ 0(SI),AX 33 | SHLQ $1,AX 34 | MULQ 8(SI) 35 | MOVQ AX,R9 36 | MOVQ DX,R10 37 | MOVQ 0(SI),AX 38 | SHLQ $1,AX 39 | MULQ 16(SI) 40 | MOVQ AX,R11 41 | MOVQ DX,R12 42 | MOVQ 0(SI),AX 43 | SHLQ $1,AX 44 | MULQ 24(SI) 45 | MOVQ AX,R13 46 | MOVQ DX,R14 47 | MOVQ 0(SI),AX 48 | SHLQ $1,AX 49 | MULQ 32(SI) 50 | MOVQ AX,R15 51 | MOVQ DX,BX 52 | MOVQ 8(SI),AX 53 | MULQ 8(SI) 54 | ADDQ AX,R11 55 | ADCQ DX,R12 56 | MOVQ 8(SI),AX 57 | SHLQ $1,AX 58 | MULQ 16(SI) 59 | ADDQ AX,R13 60 | ADCQ DX,R14 61 | MOVQ 8(SI),AX 62 | SHLQ $1,AX 63 | MULQ 24(SI) 64 | ADDQ AX,R15 65 | ADCQ DX,BX 66 | MOVQ 8(SI),DX 67 | IMUL3Q $38,DX,AX 68 | MULQ 32(SI) 69 | ADDQ AX,CX 70 | ADCQ DX,R8 71 | MOVQ 16(SI),AX 72 | MULQ 16(SI) 73 | ADDQ AX,R15 74 | ADCQ DX,BX 75 | MOVQ 16(SI),DX 76 | IMUL3Q $38,DX,AX 77 | MULQ 24(SI) 78 | ADDQ AX,CX 79 | ADCQ DX,R8 80 | MOVQ 16(SI),DX 81 | IMUL3Q $38,DX,AX 82 | MULQ 32(SI) 83 | ADDQ AX,R9 84 | ADCQ DX,R10 85 | MOVQ 24(SI),DX 86 | IMUL3Q $19,DX,AX 87 | MULQ 24(SI) 88 | ADDQ AX,R9 89 | ADCQ DX,R10 90 | MOVQ 24(SI),DX 91 | IMUL3Q $38,DX,AX 92 | MULQ 32(SI) 93 | ADDQ AX,R11 94 | ADCQ DX,R12 95 | MOVQ 32(SI),DX 96 | IMUL3Q $19,DX,AX 97 | MULQ 32(SI) 98 | ADDQ AX,R13 99 | ADCQ DX,R14 100 | MOVQ ·REDMASK51(SB),SI 101 | SHLQ $13,R8:CX 102 | ANDQ SI,CX 103 | SHLQ $13,R10:R9 104 | ANDQ SI,R9 105 | ADDQ R8,R9 106 | SHLQ $13,R12:R11 107 | ANDQ SI,R11 108 | ADDQ R10,R11 109 | SHLQ $13,R14:R13 110 | ANDQ SI,R13 111 | ADDQ R12,R13 112 | SHLQ $13,BX:R15 113 | ANDQ SI,R15 114 | ADDQ R14,R15 115 | IMUL3Q $19,BX,DX 116 | ADDQ DX,CX 117 | MOVQ CX,DX 118 | SHRQ $51,DX 119 | ADDQ R9,DX 120 | ANDQ SI,CX 121 | MOVQ DX,R8 122 | SHRQ $51,DX 123 | ADDQ R11,DX 124 | ANDQ SI,R8 125 | MOVQ DX,R9 126 | SHRQ $51,DX 127 | ADDQ R13,DX 128 | ANDQ SI,R9 129 | MOVQ DX,AX 130 | SHRQ $51,DX 131 | ADDQ R15,DX 132 | ANDQ SI,AX 133 | MOVQ DX,R10 134 | SHRQ $51,DX 135 | IMUL3Q $19,DX,DX 136 | ADDQ DX,CX 137 | ANDQ SI,R10 138 | MOVQ CX,0(DI) 139 | MOVQ R8,8(DI) 140 | MOVQ R9,16(DI) 141 | MOVQ AX,24(DI) 142 | MOVQ R10,32(DI) 143 | MOVQ 0(SP),R11 144 | MOVQ 8(SP),R12 145 | MOVQ 16(SP),R13 146 | MOVQ 24(SP),R14 147 | MOVQ 32(SP),R15 148 | MOVQ 40(SP),BX 149 | MOVQ 48(SP),BP 150 | MOVQ R11,SP 151 | MOVQ DI,AX 152 | MOVQ SI,DX 153 | RET 154 | -------------------------------------------------------------------------------- /vendor/github.com/wg/ecies/vendor/schwanenlied.me/yawning/chacha20/README.md: -------------------------------------------------------------------------------- 1 | ### chacha20 - ChaCha20 2 | #### Yawning Angel (yawning at schwanenlied dot me) 3 | 4 | Yet another Go ChaCha20 implementation. Everything else I found was slow, 5 | didn't support all the variants I need to use, or relied on cgo to go fast. 6 | 7 | Features: 8 | 9 | * 20 round, 256 bit key only. Everything else is pointless and stupid. 10 | * IETF 96 bit nonce variant. 11 | * XChaCha 24 byte nonce variant. 12 | * SSE2 and AVX2 support on amd64 targets. 13 | * Incremental encrypt/decrypt support, unlike golang.org/x/crypto/salsa20. 14 | 15 | -------------------------------------------------------------------------------- /vendor/github.com/wg/ecies/vendor/schwanenlied.me/yawning/chacha20/chacha20_amd64.go: -------------------------------------------------------------------------------- 1 | // chacha20_amd64.go - AMD64 optimized chacha20. 2 | // 3 | // To the extent possible under law, Yawning Angel has waived all copyright 4 | // and related or neighboring rights to chacha20, using the Creative 5 | // Commons "CC0" public domain dedication. See LICENSE or 6 | // for full details. 7 | 8 | // +build amd64,!gccgo,!appengine 9 | 10 | package chacha20 11 | 12 | import ( 13 | "math" 14 | ) 15 | 16 | var usingAVX2 = false 17 | 18 | func blocksAmd64SSE2(x *uint32, inp, outp *byte, nrBlocks uint) 19 | 20 | func blocksAmd64AVX2(x *uint32, inp, outp *byte, nrBlocks uint) 21 | 22 | func cpuidAmd64(cpuidParams *uint32) 23 | 24 | func xgetbv0Amd64(xcrVec *uint32) 25 | 26 | func blocksAmd64(x *[stateSize]uint32, in []byte, out []byte, nrBlocks int, isIetf bool) { 27 | // Probably unneeded, but stating this explicitly simplifies the assembly. 28 | if nrBlocks == 0 { 29 | return 30 | } 31 | 32 | if isIetf { 33 | var totalBlocks uint64 34 | totalBlocks = uint64(x[8]) + uint64(nrBlocks) 35 | if totalBlocks > math.MaxUint32 { 36 | panic("chacha20: Exceeded keystream per nonce limit") 37 | } 38 | } 39 | 40 | if in == nil { 41 | for i := range out { 42 | out[i] = 0 43 | } 44 | in = out 45 | } 46 | 47 | // Pointless to call the AVX2 code for just a single block, since half of 48 | // the output gets discarded... 49 | if usingAVX2 && nrBlocks > 1 { 50 | blocksAmd64AVX2(&x[0], &in[0], &out[0], uint(nrBlocks)) 51 | } else { 52 | blocksAmd64SSE2(&x[0], &in[0], &out[0], uint(nrBlocks)) 53 | } 54 | } 55 | 56 | func supportsAVX2() bool { 57 | // https://software.intel.com/en-us/articles/how-to-detect-new-instruction-support-in-the-4th-generation-intel-core-processor-family 58 | const ( 59 | osXsaveBit = 1 << 27 60 | avx2Bit = 1 << 5 61 | ) 62 | 63 | // Check to see if CPUID actually supports the leaf that indicates AVX2. 64 | // CPUID.(EAX=0H, ECX=0H) >= 7 65 | regs := [4]uint32{0x00} 66 | cpuidAmd64(®s[0]) 67 | if regs[0] < 7 { 68 | return false 69 | } 70 | 71 | // Check to see if the OS knows how to save/restore XMM/YMM state. 72 | // CPUID.(EAX=01H, ECX=0H):ECX.OSXSAVE[bit 27]==1 73 | regs = [4]uint32{0x01} 74 | cpuidAmd64(®s[0]) 75 | if regs[2]&osXsaveBit == 0 { 76 | return false 77 | } 78 | xcrRegs := [2]uint32{} 79 | xgetbv0Amd64(&xcrRegs[0]) 80 | if xcrRegs[0]&6 != 6 { 81 | return false 82 | } 83 | 84 | // Check for AVX2 support. 85 | // CPUID.(EAX=07H, ECX=0H):EBX.AVX2[bit 5]==1 86 | regs = [4]uint32{0x07} 87 | cpuidAmd64(®s[0]) 88 | return regs[1]&avx2Bit != 0 89 | } 90 | 91 | func init() { 92 | blocksFn = blocksAmd64 93 | usingVectors = true 94 | usingAVX2 = supportsAVX2() 95 | } 96 | -------------------------------------------------------------------------------- /vendor/github.com/wg/ecies/vendor/schwanenlied.me/yawning/poly1305/README.md: -------------------------------------------------------------------------------- 1 | ### poly1305: Go Poly1305 2 | #### Yawning Angel (yawning at schwanenlied dot me) 3 | 4 | Poly1305 implements the Poly1305 MAC algorithm, exposing a saner interface than 5 | the one provided by golang.org/x/crypto/poly1305. In particular it exposes a 6 | object that implements a hash.Hash interface. 7 | 8 | The implementation is based on the Public Domain poly1305-donna by Andrew 9 | Moon. 10 | 11 | | Implementation | 64 byte | 1024 byte | 12 | | -------------------- | ------------ | ----------- | 13 | | go.crypto (ref) | 94.51 MB/s | 187.67 MB/s | 14 | | go.crypto (amd64) | 540.68 MB/s | 909.97 MB/s | 15 | | go poly1305-donna-32 | 425.40 MB/s | 715.23 MB/s | 16 | 17 | Note: All numbers on a i5-4250U, and to be taken with a huge grain of salt. 18 | -------------------------------------------------------------------------------- /vendor/github.com/wg/ecies/vendor/schwanenlied.me/yawning/x448/LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2011 Stanford University. 4 | Copyright (c) 2014-2015 Cryptography Research, Inc. 5 | Copyright (c) 2015 Yawning Angel. 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | -------------------------------------------------------------------------------- /vendor/github.com/wg/ecies/vendor/schwanenlied.me/yawning/x448/README.md: -------------------------------------------------------------------------------- 1 | ### x448 - curve448 ECDH 2 | #### Yawning Angel (yawning at schwanenlied dot me) 3 | 4 | A straight forward port of Michael Hamburg's x448 code to Go lang. 5 | 6 | See: https://www.rfc-editor.org/rfc/rfc7748.txt 7 | 8 | If you're familiar with how to use golang.org/x/crypto/curve25519, you will be 9 | right at home with using x448, since the functions are the same. Generate a 10 | random secret key, ScalarBaseMult() to get the public key, etc etc etc. 11 | 12 | Both routines return 0 on success, -1 on failure which MUST be checked, and 13 | the handshake aborted on failure. 14 | -------------------------------------------------------------------------------- /vendor/github.com/wg/ecies/vendor/schwanenlied.me/yawning/x448/x448.go: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2011 Stanford University. 4 | // Copyright (c) 2014-2015 Cryptography Research, Inc. 5 | // Copyright (c) 2015 Yawning Angel. 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in 15 | // all copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | // THE SOFTWARE. 24 | 25 | // Package x448 provides an implementation of scalar multiplication on the 26 | // elliptic curve known as curve448. 27 | // 28 | // See https://tools.ietf.org/html/draft-irtf-cfrg-curves-11 29 | package x448 // import "git.schwanenlied.me/yawning/x448.git" 30 | 31 | const ( 32 | x448Bytes = 56 33 | edwardsD = -39081 34 | ) 35 | 36 | var basePoint = [56]byte{ 37 | 5, 0, 0, 0, 0, 0, 38 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 39 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 40 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 41 | } 42 | 43 | func ScalarMult(out, scalar, base *[56]byte) int { 44 | var x1, x2, z2, x3, z3, t1, t2 gf 45 | x1.deser(base) 46 | x2.cpy(&one) 47 | z2.cpy(&zero) 48 | x3.cpy(&x1) 49 | z3.cpy(&one) 50 | 51 | var swap limbUint 52 | 53 | for t := int(448 - 1); t >= 0; t-- { 54 | sb := scalar[t/8] 55 | 56 | // Scalar conditioning. 57 | if t/8 == 0 { 58 | sb &= 0xFC 59 | } else if t/8 == x448Bytes-1 { 60 | sb |= 0x80 61 | } 62 | 63 | kT := (limbUint)((sb >> ((uint)(t) % 8)) & 1) 64 | kT = -kT // Set to all 0s or all 1s 65 | 66 | swap ^= kT 67 | x2.condSwap(&x3, swap) 68 | z2.condSwap(&z3, swap) 69 | swap = kT 70 | 71 | t1.add(&x2, &z2) // A = x2 + z2 72 | t2.sub(&x2, &z2) // B = x2 - z2 73 | z2.sub(&x3, &z3) // D = x3 - z3 74 | x2.mul(&t1, &z2) // DA 75 | z2.add(&z3, &x3) // C = x3 + z3 76 | x3.mul(&t2, &z2) // CB 77 | z3.sub(&x2, &x3) // DA-CB 78 | z2.sqr(&z3) // (DA-CB)^2 79 | z3.mul(&x1, &z2) // z3 = x1(DA-CB)^2 80 | z2.add(&x2, &x3) // (DA+CB) 81 | x3.sqr(&z2) // x3 = (DA+CB)^2 82 | 83 | z2.sqr(&t1) // AA = A^2 84 | t1.sqr(&t2) // BB = B^2 85 | x2.mul(&z2, &t1) // x2 = AA*BB 86 | t2.sub(&z2, &t1) // E = AA-BB 87 | 88 | t1.mlw(&t2, -edwardsD) // E*-d = a24*E 89 | t1.add(&t1, &z2) // AA + a24*E 90 | z2.mul(&t2, &t1) // z2 = E(AA+a24*E) 91 | } 92 | 93 | // Finish 94 | x2.condSwap(&x3, swap) 95 | z2.condSwap(&x3, swap) 96 | z2.inv(&z2) 97 | x1.mul(&x2, &z2) 98 | x1.ser(out) 99 | 100 | // As with X25519, both sides MUST check, without leaking extra 101 | // information about the value of K, whether the resulting shared K is 102 | // the all-zero value and abort if so. 103 | var nz limbSint 104 | for _, v := range out { 105 | nz |= (limbSint)(v) 106 | } 107 | nz = (nz - 1) >> 8 // 0 = succ, -1 = fail 108 | 109 | // return value: 0 = succ, -1 = fail 110 | return (int)(nz) 111 | } 112 | 113 | func ScalarBaseMult(out, scalar *[56]byte) int { 114 | return ScalarMult(out, scalar, &basePoint) 115 | } 116 | -------------------------------------------------------------------------------- /vendor/github.com/wg/ecies/xchacha20poly1305/xchacha20poly1305.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 - Will Glozer. All rights reserved. 2 | 3 | // Package xchacha20poly1305 implements an AEAD construction 4 | // similar to NaCl's xsalsa20poly1305 secretbox, but using 5 | // XChaCha20 instead of XSalsa20. 6 | package xchacha20poly1305 7 | 8 | import ( 9 | "schwanenlied.me/yawning/chacha20" 10 | "schwanenlied.me/yawning/poly1305" 11 | ) 12 | 13 | const ( 14 | KeySize = chacha20.KeySize 15 | NonceSize = chacha20.XNonceSize 16 | TagSize = poly1305.Size 17 | ) 18 | 19 | type XChaCha20Poly1305 struct { 20 | chacha20.Cipher 21 | poly1305.Poly1305 22 | } 23 | 24 | func New(key *[KeySize]byte, nonce *[NonceSize]byte) *XChaCha20Poly1305 { 25 | x := &XChaCha20Poly1305{} 26 | x.Init(key[:], nonce[:]) 27 | return x 28 | } 29 | 30 | func (x *XChaCha20Poly1305) Init(key, nonce []byte) error { 31 | err := x.ReKey(key, nonce) 32 | if err == nil { 33 | x.initPoly1305() 34 | x.Seek(1) 35 | } 36 | return err 37 | } 38 | 39 | func (x *XChaCha20Poly1305) Auth(src []byte) { 40 | if len(src) > 0 { 41 | x.Poly1305.Write(src) 42 | } 43 | } 44 | 45 | func (x *XChaCha20Poly1305) Decrypt(dst, src []byte) { 46 | x.Poly1305.Write(src) 47 | x.XORKeyStream(dst, src) 48 | } 49 | 50 | func (x *XChaCha20Poly1305) Encrypt(dst, src []byte) { 51 | n := len(src) 52 | x.XORKeyStream(dst, src) 53 | x.Poly1305.Write(dst[:n]) 54 | } 55 | 56 | func (x *XChaCha20Poly1305) Tag(b []byte) []byte { 57 | return x.Poly1305.Sum(b) 58 | } 59 | 60 | func (x *XChaCha20Poly1305) Reset() { 61 | x.Cipher.Reset() 62 | } 63 | 64 | func (x *XChaCha20Poly1305) TagSize() int { 65 | return TagSize 66 | } 67 | 68 | func (x *XChaCha20Poly1305) initPoly1305() { 69 | var key [poly1305.KeySize]byte 70 | x.KeyStream(key[:]) 71 | x.Poly1305.Init(key[:]) 72 | for i := range key { 73 | key[i] = 0 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /vendor/github.com/wg/ecies/xchacha20poly1305/xchacha20poly1305_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 - Will Glozer. All rights reserved. 2 | 3 | package xchacha20poly1305 4 | 5 | import ( 6 | "bytes" 7 | "testing" 8 | ) 9 | 10 | // plaintext & key from RFC 7539 with the 12-byte nonce repeated twice and 11 | // expected ciphertext derived from the SUPERCOP chacha20 reference impl. 12 | func TestXChaCha20(t *testing.T) { 13 | plaintext := []byte{ 14 | 0x4c, 0x61, 0x64, 0x69, 0x65, 0x73, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x47, 0x65, 0x6e, 0x74, 0x6c, 15 | 0x65, 0x6d, 0x65, 0x6e, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6c, 0x61, 0x73, 16 | 0x73, 0x20, 0x6f, 0x66, 0x20, 0x27, 0x39, 0x39, 0x3a, 0x20, 0x49, 0x66, 0x20, 0x49, 0x20, 0x63, 17 | 0x6f, 0x75, 0x6c, 0x64, 0x20, 0x6f, 0x66, 0x66, 0x65, 0x72, 0x20, 0x79, 0x6f, 0x75, 0x20, 0x6f, 18 | 0x6e, 0x6c, 0x79, 0x20, 0x6f, 0x6e, 0x65, 0x20, 0x74, 0x69, 0x70, 0x20, 0x66, 0x6f, 0x72, 0x20, 19 | 0x74, 0x68, 0x65, 0x20, 0x66, 0x75, 0x74, 0x75, 0x72, 0x65, 0x2c, 0x20, 0x73, 0x75, 0x6e, 0x73, 20 | 0x63, 0x72, 0x65, 0x65, 0x6e, 0x20, 0x77, 0x6f, 0x75, 0x6c, 0x64, 0x20, 0x62, 0x65, 0x20, 0x69, 21 | 0x74, 0x2e, 22 | } 23 | 24 | key := []byte{ 25 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 26 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 27 | } 28 | 29 | nonce := []byte{ 30 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4a, 0x00, 0x00, 0x00, 0x00, 31 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4a, 0x00, 0x00, 0x00, 0x00, 32 | } 33 | 34 | ciphertext := []byte{ 35 | 0x15, 0x62, 0x3c, 0xe5, 0x14, 0x3a, 0xd8, 0xc8, 0x46, 0x79, 0x0b, 0xc3, 0x8c, 0x5e, 0x81, 0x50, 36 | 0x85, 0x1c, 0xd4, 0xa5, 0x30, 0xf5, 0xfa, 0xb8, 0x02, 0xe6, 0x1e, 0x87, 0x52, 0x91, 0x57, 0x9f, 37 | 0x40, 0x0b, 0x2c, 0x57, 0x79, 0x95, 0xdf, 0x0c, 0xbc, 0xd9, 0x71, 0x30, 0x30, 0xad, 0x64, 0xee, 38 | 0x93, 0x7d, 0xd2, 0xfa, 0x5c, 0x48, 0xff, 0xda, 0x7c, 0x91, 0xd1, 0x5b, 0xc3, 0x41, 0x3e, 0x33, 39 | 0x55, 0x1d, 0x10, 0x97, 0x73, 0x0e, 0x40, 0x51, 0x4a, 0x1f, 0xf9, 0x04, 0xee, 0xb0, 0xe6, 0xd2, 40 | 0x2a, 0x42, 0x79, 0xc0, 0xee, 0xe1, 0xb4, 0x92, 0x9c, 0x5a, 0xe4, 0x24, 0x21, 0xe0, 0x0f, 0x3e, 41 | 0x3b, 0xa3, 0x0c, 0x7b, 0x7a, 0xa3, 0xfa, 0x0f, 0x9d, 0x7b, 0x69, 0xc4, 0x7f, 0xdf, 0x6d, 0xe5, 42 | 0x35, 0xa3, 43 | } 44 | 45 | tag := []byte{ 46 | 0x80, 0xdf, 0x98, 0xf1, 0xff, 0x1d, 0xc9, 0xc8, 0xdd, 0x08, 0xeb, 0xf8, 0x45, 0x1c, 0x8b, 0xd2, 47 | } 48 | 49 | c := XChaCha20Poly1305{} 50 | 51 | err := c.Init(key, nonce) 52 | if err != nil { 53 | t.Fatal(err) 54 | } 55 | 56 | c.Encrypt(plaintext, plaintext) 57 | 58 | if !bytes.Equal(plaintext, ciphertext) { 59 | t.Fatal("encrypted plaintext != expected ciphertext") 60 | } 61 | 62 | if !bytes.Equal(c.Tag(nil), tag) { 63 | t.Fatal("actual tag != expected tag") 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/AUTHORS: -------------------------------------------------------------------------------- 1 | # This source code refers to The Go Authors for copyright purposes. 2 | # The master list of authors is in the main Go distribution, 3 | # visible at http://tip.golang.org/AUTHORS. 4 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | # This source code was written by the Go contributors. 2 | # The master list of contributors is in the main Go distribution, 3 | # visible at http://tip.golang.org/CONTRIBUTORS. 4 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009 The Go Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/PATENTS: -------------------------------------------------------------------------------- 1 | Additional IP Rights Grant (Patents) 2 | 3 | "This implementation" means the copyrightable works distributed by 4 | Google as part of the Go project. 5 | 6 | Google hereby grants to You a perpetual, worldwide, non-exclusive, 7 | no-charge, royalty-free, irrevocable (except as stated in this section) 8 | patent license to make, have made, use, offer to sell, sell, import, 9 | transfer and otherwise run, modify and propagate the contents of this 10 | implementation of Go, where such license applies only to those patent 11 | claims, both currently owned or controlled by Google and acquired in 12 | the future, licensable by Google that are necessarily infringed by this 13 | implementation of Go. This grant does not include claims that would be 14 | infringed only as a consequence of further modification of this 15 | implementation. If you or your agent or exclusive licensee institute or 16 | order or agree to the institution of patent litigation against any 17 | entity (including a cross-claim or counterclaim in a lawsuit) alleging 18 | that this implementation of Go or any code incorporated within this 19 | implementation of Go constitutes direct or contributory patent 20 | infringement, or inducement of patent infringement, then any patent 21 | rights granted to you under this License for this implementation of Go 22 | shall terminate as of the date such litigation is filed. 23 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/README: -------------------------------------------------------------------------------- 1 | This repository holds supplementary Go cryptography libraries. 2 | 3 | To submit changes to this repository, see http://golang.org/doc/contribute.html. 4 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/ssh/terminal/util_bsd.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build darwin dragonfly freebsd netbsd openbsd 6 | 7 | package terminal 8 | 9 | import "syscall" 10 | 11 | const ioctlReadTermios = syscall.TIOCGETA 12 | const ioctlWriteTermios = syscall.TIOCSETA 13 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/ssh/terminal/util_linux.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package terminal 6 | 7 | // These constants are declared here, rather than importing 8 | // them from the syscall package as some syscall packages, even 9 | // on linux, for example gccgo, do not declare them. 10 | const ioctlReadTermios = 0x5401 // syscall.TCGETS 11 | const ioctlWriteTermios = 0x5402 // syscall.TCSETS 12 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/ssh/terminal/util_plan9.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package terminal provides support functions for dealing with terminals, as 6 | // commonly found on UNIX systems. 7 | // 8 | // Putting a terminal into raw mode is the most common requirement: 9 | // 10 | // oldState, err := terminal.MakeRaw(0) 11 | // if err != nil { 12 | // panic(err) 13 | // } 14 | // defer terminal.Restore(0, oldState) 15 | package terminal 16 | 17 | import ( 18 | "fmt" 19 | "runtime" 20 | ) 21 | 22 | type State struct{} 23 | 24 | // IsTerminal returns true if the given file descriptor is a terminal. 25 | func IsTerminal(fd int) bool { 26 | return false 27 | } 28 | 29 | // MakeRaw put the terminal connected to the given file descriptor into raw 30 | // mode and returns the previous state of the terminal so that it can be 31 | // restored. 32 | func MakeRaw(fd int) (*State, error) { 33 | return nil, fmt.Errorf("terminal: MakeRaw not implemented on %s/%s", runtime.GOOS, runtime.GOARCH) 34 | } 35 | 36 | // GetState returns the current state of a terminal which may be useful to 37 | // restore the terminal after a signal. 38 | func GetState(fd int) (*State, error) { 39 | return nil, fmt.Errorf("terminal: GetState not implemented on %s/%s", runtime.GOOS, runtime.GOARCH) 40 | } 41 | 42 | // Restore restores the terminal connected to the given file descriptor to a 43 | // previous state. 44 | func Restore(fd int, state *State) error { 45 | return fmt.Errorf("terminal: Restore not implemented on %s/%s", runtime.GOOS, runtime.GOARCH) 46 | } 47 | 48 | // GetSize returns the dimensions of the given terminal. 49 | func GetSize(fd int) (width, height int, err error) { 50 | return 0, 0, fmt.Errorf("terminal: GetSize not implemented on %s/%s", runtime.GOOS, runtime.GOARCH) 51 | } 52 | 53 | // ReadPassword reads a line of input from a terminal without local echo. This 54 | // is commonly used for inputting passwords and other sensitive data. The slice 55 | // returned does not include the \n. 56 | func ReadPassword(fd int) ([]byte, error) { 57 | return nil, fmt.Errorf("terminal: ReadPassword not implemented on %s/%s", runtime.GOOS, runtime.GOARCH) 58 | } 59 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/ssh/terminal/util_test.go: -------------------------------------------------------------------------------- 1 | package terminal 2 | --------------------------------------------------------------------------------