├── .gitignore
├── .tool-versions
├── LICENSE
├── Makefile
├── README.md
├── crypto
├── crypto.go
└── crypto_test.go
├── go.mod
├── go.sum
├── script
└── run_tests.sh
├── secret
├── secret.go
└── secret_test.go
├── storage
├── path
│ └── path.go
├── storage.go
├── storage_test.go
└── storage_test_argon2id_input.json
├── vault
├── add
│ ├── add.go
│ └── add_test.go
├── delete
│ ├── delete.go
│ └── delete_test.go
├── edit
│ ├── edit.go
│ └── edit_test.go
├── list
│ ├── list.go
│ └── list_test.go
├── vault.go
├── vault_test.go
└── vault_test_argon2id_input.json
└── vendor
├── github.com
├── juju
│ └── fslock
│ │ ├── .gitignore
│ │ ├── LICENSE
│ │ ├── README.md
│ │ ├── fslock.go
│ │ ├── fslock_nix.go
│ │ └── fslock_windows.go
└── satori
│ └── go.uuid
│ ├── .travis.yml
│ ├── LICENSE
│ ├── README.md
│ ├── codec.go
│ ├── generator.go
│ ├── sql.go
│ └── uuid.go
├── golang.org
└── x
│ ├── crypto
│ ├── LICENSE
│ ├── PATENTS
│ ├── argon2
│ │ ├── argon2.go
│ │ ├── blake2b.go
│ │ ├── blamka_amd64.go
│ │ ├── blamka_amd64.s
│ │ ├── blamka_generic.go
│ │ └── blamka_ref.go
│ ├── blake2b
│ │ ├── blake2b.go
│ │ ├── blake2bAVX2_amd64.go
│ │ ├── blake2bAVX2_amd64.s
│ │ ├── blake2b_amd64.go
│ │ ├── blake2b_amd64.s
│ │ ├── blake2b_generic.go
│ │ ├── blake2b_ref.go
│ │ ├── blake2x.go
│ │ └── register.go
│ ├── internal
│ │ ├── alias
│ │ │ ├── alias.go
│ │ │ └── alias_purego.go
│ │ └── poly1305
│ │ │ ├── bits_compat.go
│ │ │ ├── bits_go1.13.go
│ │ │ ├── mac_noasm.go
│ │ │ ├── poly1305.go
│ │ │ ├── sum_amd64.go
│ │ │ ├── sum_amd64.s
│ │ │ ├── sum_generic.go
│ │ │ ├── sum_ppc64le.go
│ │ │ ├── sum_ppc64le.s
│ │ │ ├── sum_s390x.go
│ │ │ └── sum_s390x.s
│ ├── nacl
│ │ └── secretbox
│ │ │ └── secretbox.go
│ └── salsa20
│ │ └── salsa
│ │ ├── hsalsa20.go
│ │ ├── salsa208.go
│ │ ├── salsa20_amd64.go
│ │ ├── salsa20_amd64.s
│ │ ├── salsa20_noasm.go
│ │ └── salsa20_ref.go
│ └── sys
│ ├── LICENSE
│ ├── PATENTS
│ └── cpu
│ ├── asm_aix_ppc64.s
│ ├── byteorder.go
│ ├── cpu.go
│ ├── cpu_aix.go
│ ├── cpu_arm.go
│ ├── cpu_arm64.go
│ ├── cpu_arm64.s
│ ├── cpu_gc_arm64.go
│ ├── cpu_gc_s390x.go
│ ├── cpu_gc_x86.go
│ ├── cpu_gccgo_arm64.go
│ ├── cpu_gccgo_s390x.go
│ ├── cpu_gccgo_x86.c
│ ├── cpu_gccgo_x86.go
│ ├── cpu_linux.go
│ ├── cpu_linux_arm.go
│ ├── cpu_linux_arm64.go
│ ├── cpu_linux_mips64x.go
│ ├── cpu_linux_noinit.go
│ ├── cpu_linux_ppc64x.go
│ ├── cpu_linux_s390x.go
│ ├── cpu_loong64.go
│ ├── cpu_mips64x.go
│ ├── cpu_mipsx.go
│ ├── cpu_netbsd_arm64.go
│ ├── cpu_openbsd_arm64.go
│ ├── cpu_openbsd_arm64.s
│ ├── cpu_other_arm.go
│ ├── cpu_other_arm64.go
│ ├── cpu_other_mips64x.go
│ ├── cpu_other_ppc64x.go
│ ├── cpu_other_riscv64.go
│ ├── cpu_ppc64x.go
│ ├── cpu_riscv64.go
│ ├── cpu_s390x.go
│ ├── cpu_s390x.s
│ ├── cpu_wasm.go
│ ├── cpu_x86.go
│ ├── cpu_x86.s
│ ├── cpu_zos.go
│ ├── cpu_zos_s390x.go
│ ├── endian_big.go
│ ├── endian_little.go
│ ├── hwcap_linux.go
│ ├── parse.go
│ ├── proc_cpuinfo_linux.go
│ ├── runtime_auxv.go
│ ├── runtime_auxv_go121.go
│ ├── syscall_aix_gccgo.go
│ └── syscall_aix_ppc64_gc.go
└── modules.txt
/.gitignore:
--------------------------------------------------------------------------------
1 | /bin
2 | /dist
3 |
--------------------------------------------------------------------------------
/.tool-versions:
--------------------------------------------------------------------------------
1 | golang 1.20.3
2 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 Jarmo Pertman
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 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | PREFIX ?= ${GOPATH}
2 |
3 | all: test
4 |
5 | vendor:
6 | go mod vendor
7 | go mod tidy
8 |
9 | test: vendor
10 | script/run_tests.sh
11 |
12 | .PHONY: all test vendor
13 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # secrets
2 |
3 | **Secure** and simple passwords manager written in [Go](https://golang.org/). It aims to be *NYAPM* (Not Yet Another Password Manager), but tries to be different from others by following UNIX philosophy of doing only one thing and doing it well.
4 |
5 | ## Features
6 |
7 | * stores your secrets encrypted at rest;
8 | * secrets can be anything from passwords, 2FA backup codes, diary entries to private keys;
9 | * does not leak count nor nature of your secrets;
10 | * uses an alternative easy to use secure cryptography provided by [libsodium](https://download.libsodium.org/doc/) and [Argon2id](https://www.cryptolux.org/images/0/0d/Argon2.pdf);
11 | * supports multiple vaults with different passwords;
12 | * has [CLI](https://github.com/jarmo/secrets-cli) and [Web](https://github.com/jarmo/secrets-web) interface pre-built binaries for macOS, Linux and Windows, but can be compiled for many other platforms too due to usage of underlying Go language;
13 | * may be used as an independent Go library.
14 |
15 | ### Anti-Features
16 |
17 | * does not sync your secrets to any cloud - you have [complete control](https://palant.de/2019/03/18/should-you-be-concerned-about-lastpass-uploading-your-passwords-to-its-server/) over them;
18 | * does not allow to recover any passwords when vault password has been forgotten - there's no built-in backdoor;
19 | * does not [leak anything to 3rd parties](https://reports.exodus-privacy.eu.org/en/reports/165465/) - only you know about your secrets;
20 | * does not generate any passwords - use [proper tools](https://linux.die.net/man/1/pwgen) for that, but avoid [improper ones](http://seclists.org/oss-sec/2018/q1/11);
21 | * does not auto-fill any passwords anywhere (you [don't want](https://freedom-to-tinker.com/2017/12/27/no-boundaries-for-user-identities-web-trackers-exploit-browser-login-managers/) that anyway) - it's up to you how you will fill your passwords;
22 | * does not have any mobile apps nor browser plugins - less possible attack vectors;
23 | * does not [remove already existing features](https://discussions.agilebits.com/discussion/105305/standalone-local-vault-option-gone) - always possibility to create your own fork since it is an open-source software and will be like that.
24 |
25 | ## Is it secure?
26 |
27 | **Yes**, as long as its underlying cryptography is not broken. However, there are no 100% secure systems and there's no way to guarantee that. All in all, I'd say that using this is more secure than using any SaaS as a password manager because everything is under your control. The most secure system is not a software itself, but it's how and where you use it.
28 |
29 | ## Usage
30 |
31 | It is possible to use secrets from [command line](https://github.com/jarmo/secrets-cli), as a [self-hosted web application](https://github.com/jarmo/secrets-web)
32 | or as a library.
33 |
34 | ## Development
35 |
36 | Retrieve dependencies and run tests
37 |
38 | ```
39 | git clone https://github.com/jarmo/secrets.git
40 | cd secrets
41 | make
42 | ```
43 |
44 | ## Background Story
45 |
46 | I've used [LastPass](https://www.lastpass.com/) and [mitro](http://www.mitro.co/) in the past to store my secrets, but didn't feel too secure with either of them due to security vulnerabilities and/or one of them being shut down. I've got enough of switching between different managers and decided to write my own. I did write a version of **secrets** in Ruby a few years ago, but decided to give Go a try due to its portability features and here's the result. I've also decided to use a cryptographic library called libsodium, which is secure and has an easy API for avoiding making stupid mistakes.
47 |
--------------------------------------------------------------------------------
/crypto/crypto.go:
--------------------------------------------------------------------------------
1 | package crypto
2 |
3 | import (
4 | "encoding/base64"
5 | "crypto/rand"
6 | "encoding/json"
7 | "errors"
8 | "golang.org/x/crypto/argon2"
9 | "golang.org/x/crypto/nacl/secretbox"
10 | "github.com/jarmo/secrets/secret"
11 | )
12 |
13 | type argon2idParams struct {
14 | Time int
15 | Memory int
16 | Threads int
17 | }
18 |
19 | type Encrypted struct {
20 | Data string
21 | Nonce string
22 | Salt string
23 | Params map[string]int
24 | }
25 |
26 | func Encrypt(password []byte, secrets []secret.Secret) Encrypted {
27 | if encryptedSecretJSON, err := json.Marshal(secrets); err != nil {
28 | panic(err)
29 | } else {
30 | salt := GenerateRandomBytes(32)
31 | time := 3
32 | memory := 64*1024
33 | threads := 4
34 | secretKey := argon2idSecretKey(password, salt, argon2idParams{Time: time, Memory: memory, Threads: threads})
35 | var nonce [24]byte
36 | copy(nonce[:], GenerateRandomBytes(24))
37 |
38 | data := secretbox.Seal(nil, encryptedSecretJSON, &nonce, &secretKey)
39 | params := map[string]int{"Time": time, "Memory": memory, "Threads": threads}
40 | return Encrypted{
41 | Data: base64.StdEncoding.EncodeToString(data),
42 | Nonce: base64.StdEncoding.EncodeToString(nonce[:]),
43 | Salt: base64.StdEncoding.EncodeToString(salt),
44 | Params: params,
45 | }
46 | }
47 | }
48 |
49 | func Decrypt(password []byte, encryptedSecrets Encrypted) ([]secret.Secret, error) {
50 | salt, _ := base64.StdEncoding.DecodeString(encryptedSecrets.Salt)
51 | secretKey := secretKey(password, salt, encryptedSecrets.Params)
52 | data, _ := base64.StdEncoding.DecodeString(encryptedSecrets.Data)
53 | nonceBytes, _ := base64.StdEncoding.DecodeString(encryptedSecrets.Nonce)
54 | var nonce [24]byte
55 | copy(nonce[:], nonceBytes)
56 | var decryptedSecrets []secret.Secret
57 |
58 | if decryptedSecretsJSON, ok := secretbox.Open(nil, data, &nonce, &secretKey); !ok {
59 | return make([]secret.Secret, 0), errors.New("Invalid vault password!")
60 | } else if err := json.Unmarshal(decryptedSecretsJSON, &decryptedSecrets); err != nil {
61 | panic(err)
62 | }
63 |
64 | return decryptedSecrets, nil
65 | }
66 |
67 | func GenerateRandomBytes(length int) []byte {
68 | result := make([]byte, length)
69 | _, err := rand.Read(result)
70 | if err != nil {
71 | panic(err)
72 | }
73 |
74 | return result
75 | }
76 |
77 | func secretKey(password, salt []byte, params map[string]int) [32]byte {
78 | return argon2idSecretKey(
79 | password,
80 | []byte(salt),
81 | argon2idParams{Time: params["Time"], Memory: params["Memory"], Threads: params["Threads"]},
82 | )
83 | }
84 |
85 | func argon2idSecretKey(password, salt []byte, params argon2idParams) [32]byte {
86 | keyLength := 32
87 |
88 | secretKeyBytes := argon2.IDKey(
89 | password,
90 | salt,
91 | uint32(params.Time),
92 | uint32(params.Memory),
93 | uint8(params.Threads),
94 | uint32(keyLength),
95 | )
96 |
97 | var secretKey [32]byte
98 | copy(secretKey[:], secretKeyBytes)
99 |
100 | return secretKey
101 | }
102 |
103 |
--------------------------------------------------------------------------------
/crypto/crypto_test.go:
--------------------------------------------------------------------------------
1 | package crypto
2 |
3 | import (
4 | "testing"
5 | "fmt"
6 | "github.com/jarmo/secrets/secret"
7 | )
8 |
9 | func TestEncryption(t *testing.T) {
10 | secrets := []secret.Secret{secret.New("foo", "bar")}
11 | password := "secret-password"
12 |
13 | encryptedSecrets := Encrypt([]byte(password), secrets)
14 | decryptedSecrets, err := Decrypt([]byte(password), encryptedSecrets)
15 |
16 | if err != nil {
17 | t.Fatal(err)
18 | }
19 |
20 | if fmt.Sprintf("%v", decryptedSecrets) != fmt.Sprintf("%v", secrets) {
21 | t.Fatalf("Expected decrypted secrets to be '%s', but got '%s'", secrets, decryptedSecrets)
22 | }
23 | }
24 |
25 | func TestDecryption_WithInvalidPassword(t *testing.T) {
26 | secrets := []secret.Secret{secret.New("foo", "bar")}
27 | password := "secret-password"
28 |
29 | encryptedSecrets := Encrypt([]byte(password), secrets)
30 | decryptedSecrets, err := Decrypt([]byte("wrong-password"), encryptedSecrets)
31 |
32 | if len(decryptedSecrets) != 0 {
33 | t.Fatalf("Expected no secrets, but got: %v", decryptedSecrets)
34 | }
35 |
36 | if err.Error() != "Invalid vault password!" {
37 | t.Fatalf("Expected invalid password error message but got: %v", err)
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/go.mod:
--------------------------------------------------------------------------------
1 | module github.com/jarmo/secrets
2 |
3 | go 1.20
4 |
5 | require (
6 | github.com/juju/fslock v0.0.0-20160525022230-4d5c94c67b4b
7 | github.com/satori/go.uuid v1.2.0
8 | golang.org/x/crypto v0.8.0
9 | )
10 |
11 | require (
12 | golang.org/x/sys v0.7.0 // indirect
13 | gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
14 | )
15 |
--------------------------------------------------------------------------------
/go.sum:
--------------------------------------------------------------------------------
1 | github.com/juju/fslock v0.0.0-20160525022230-4d5c94c67b4b h1:FQ7+9fxhyp82ks9vAuyPzG0/vVbWwMwLJ+P6yJI5FN8=
2 | github.com/juju/fslock v0.0.0-20160525022230-4d5c94c67b4b/go.mod h1:HMcgvsgd0Fjj4XXDkbjdmlbI505rUPBs6WBMYg2pXks=
3 | github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
4 | github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
5 | github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
6 | github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
7 | github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
8 | github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
9 | github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
10 | golang.org/x/crypto v0.8.0 h1:pd9TJtTueMTVQXzk8E2XESSMQDj/U7OUu0PqJqPXQjQ=
11 | golang.org/x/crypto v0.8.0/go.mod h1:mRqEX+O9/h5TFCrQhkgjo2yKi0yYA+9ecGkdQoHrywE=
12 | golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU=
13 | golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
14 | gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
15 | gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
16 |
--------------------------------------------------------------------------------
/script/run_tests.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | set -o pipefail
4 | go test -mod=vendor -v ./... | sed ''/PASS/s//$(printf "\033[32mPASS\033[0m")/'' | sed ''/FAIL/s//$(printf "\033[31mFAIL\033[0m")/''
5 |
--------------------------------------------------------------------------------
/secret/secret.go:
--------------------------------------------------------------------------------
1 | package secret
2 |
3 | import (
4 | "fmt"
5 | "github.com/satori/go.uuid"
6 | )
7 |
8 | type Secret struct {
9 | Id uuid.UUID
10 | Name string
11 | Value string
12 | }
13 |
14 | func New(name, value string) Secret {
15 | return Secret{uuid.NewV4(), name, value}
16 | }
17 |
18 | func (secret Secret) String() string {
19 | return fmt.Sprintf(`
20 | [%s]
21 | %s
22 | %s`, secret.Id, secret.Name, secret.Value)
23 | }
24 |
--------------------------------------------------------------------------------
/secret/secret_test.go:
--------------------------------------------------------------------------------
1 | package secret
2 |
3 | import (
4 | "testing"
5 | "fmt"
6 | )
7 |
8 | func TestNew(t *testing.T) {
9 | result := New("secret-name", "secret-value")
10 | if result.Id.String() == "" {
11 | t.Fatal(fmt.Sprintf("Expected Id to be present: %v", result))
12 | }
13 | expectedSecret := Secret{result.Id, "secret-name", "secret-value"}
14 |
15 | if fmt.Sprintf("%v", result) != fmt.Sprintf("%v", expectedSecret) {
16 | t.Fatal(fmt.Sprintf("Expected secret to be '%v', but got '%v'", expectedSecret, result))
17 | }
18 | }
19 |
20 | func TestString(t *testing.T) {
21 | result := New("secret-name", "secret-value")
22 | expectedResult := fmt.Sprintf(`
23 | [%s]
24 | %s
25 | %s`, result.Id, result.Name, result.Value)
26 |
27 | if expectedResult != result.String() {
28 | t.Fatal(fmt.Sprintf("Expected output to be '%s', but got '%s'", expectedResult, result))
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/storage/path/path.go:
--------------------------------------------------------------------------------
1 | package path
2 |
3 | import (
4 | "encoding/json"
5 | "errors"
6 | "io/ioutil"
7 | "os"
8 | "strings"
9 | )
10 |
11 | type config struct {
12 | Path string
13 | Alias string
14 | }
15 |
16 | func Get(configurationPath, alias string) (string, error) {
17 | if configs, err := configurations(configurationPath); err == nil {
18 | if confByAlias := findByAlias(configs, alias); confByAlias != nil {
19 | return confByAlias.Path, nil
20 | } else {
21 | return "", errors.New("Vault not found!")
22 | }
23 | } else {
24 | return "", err
25 | }
26 | }
27 |
28 | func Store(configurationPath, vaultPath, vaultAlias string) string {
29 | conf, _ := configurations(configurationPath)
30 | conf = append(conf, config{Path: vaultPath, Alias: vaultAlias})
31 |
32 | if configJSON, err := json.MarshalIndent(conf, "", " "); err != nil {
33 | panic(err)
34 | } else if err := ioutil.WriteFile(configurationPath, configJSON, 0600); err != nil {
35 | panic(err)
36 | }
37 |
38 | return configurationPath
39 | }
40 |
41 | func configurations(path string) ([]config, error) {
42 | if configJSON, err := ioutil.ReadFile(path); os.IsNotExist(err) {
43 | return make([]config, 0), errors.New("Vault is not configured!")
44 | } else {
45 | var conf []config
46 | if err := json.Unmarshal(configJSON, &conf); err == nil {
47 | return conf, nil
48 | } else {
49 | return make([]config, 0), err
50 | }
51 | }
52 | }
53 |
54 | func findByAlias(configs []config, alias string) *config {
55 | for _, config := range configs {
56 | if strings.ToLower(config.Alias) == strings.ToLower(alias) {
57 | return &config
58 | }
59 | }
60 |
61 | return nil
62 | }
63 |
--------------------------------------------------------------------------------
/storage/storage.go:
--------------------------------------------------------------------------------
1 | package storage
2 |
3 | import (
4 | "encoding/json"
5 | "errors"
6 | "io/ioutil"
7 | "os"
8 | "time"
9 |
10 | "github.com/jarmo/secrets/crypto"
11 | "github.com/jarmo/secrets/secret"
12 | "github.com/juju/fslock"
13 | )
14 |
15 | func Read(path string, password []byte) ([]secret.Secret, error) {
16 | if encryptedSecretsJSON, err := ioutil.ReadFile(path); os.IsNotExist(err) {
17 | return make([]secret.Secret, 0), nil
18 | } else {
19 | var encryptedSecrets crypto.Encrypted
20 | if err := json.Unmarshal(encryptedSecretsJSON, &encryptedSecrets); err != nil {
21 | panic(err)
22 | }
23 |
24 | if secrets, err := crypto.Decrypt(password, encryptedSecrets); err != nil {
25 | return secrets, err
26 | } else {
27 | return secrets, nil
28 | }
29 | }
30 | }
31 |
32 | func Write(path string, password []byte, decryptedSecrets []secret.Secret) {
33 | if fileLock, err := lock(path); err != nil {
34 | panic(err)
35 | } else {
36 | defer fileLock.Unlock()
37 | }
38 |
39 | encryptedSecrets := crypto.Encrypt(password, decryptedSecrets)
40 |
41 | if encryptedSecretsJSON, err := json.MarshalIndent(encryptedSecrets, "", " "); err != nil {
42 | panic(err)
43 | } else if err := ioutil.WriteFile(path, encryptedSecretsJSON, 0600); err != nil {
44 | panic(err)
45 | }
46 | }
47 |
48 | func lock(path string) (*fslock.Lock, error) {
49 | lock := fslock.New(path)
50 | for i := 0; i < 5; i++ {
51 | err := lock.TryLock()
52 | if err == nil {
53 | return lock, nil
54 | }
55 | time.Sleep(100 * time.Millisecond)
56 | }
57 |
58 | return nil, errors.New("Failed to lock " + path)
59 | }
60 |
--------------------------------------------------------------------------------
/storage/storage_test.go:
--------------------------------------------------------------------------------
1 | package storage
2 |
3 | import (
4 | "testing"
5 | "fmt"
6 | "io/ioutil"
7 | "os"
8 | "encoding/json"
9 | "github.com/jarmo/secrets/secret"
10 | "github.com/jarmo/secrets/crypto"
11 | "github.com/satori/go.uuid"
12 | )
13 |
14 | func TestWrite(t *testing.T) {
15 | vaultPath, err := ioutil.TempFile("", "test-secrets-vault")
16 | if err != nil {
17 | t.Fatal(err)
18 | }
19 | vaultPathStr := vaultPath.Name()
20 | defer os.Remove(vaultPathStr)
21 |
22 | Write(vaultPathStr, []byte("secret-password"), secrets())
23 |
24 | fileInfo, err := os.Stat(vaultPathStr)
25 | if fileInfo.Mode() != 0600 {
26 | t.Fatal("Expected vault permissions to be -rw-------, but are:", fileInfo.Mode())
27 | }
28 |
29 | encryptedSecretsJSON, err := ioutil.ReadFile(vaultPathStr)
30 | if err != nil {
31 | t.Fatal(err)
32 | }
33 |
34 | var encryptedSecrets crypto.Encrypted
35 | err = json.Unmarshal(encryptedSecretsJSON, &encryptedSecrets)
36 |
37 | if err != nil {
38 | t.Fatal(err)
39 | }
40 | }
41 |
42 | func TestRead_UsingArgon2idKey(t *testing.T) {
43 | decryptedSecrets, err := Read("storage_test_argon2id_input.json", []byte("secret-password"))
44 |
45 | if err != nil {
46 | t.Fatal(err)
47 | }
48 |
49 | expectedSecrets := secrets()
50 | id1, _ := uuid.FromString("910fe994-f102-407e-a4bd-947444a2ecb1")
51 | expectedSecrets[0].Id = id1
52 | id2, _ := uuid.FromString("6acd0733-0f2c-4138-a4ad-9cc98b8b61cc")
53 | expectedSecrets[1].Id = id2
54 |
55 | if fmt.Sprintf("%v", decryptedSecrets) != fmt.Sprintf("%v", expectedSecrets) {
56 | t.Fatal(fmt.Sprintf("Expected decrypted secrets to be %s, but got %s", expectedSecrets, decryptedSecrets))
57 | }
58 | }
59 |
60 | func TestRead_WithInvalidPasswordUsingArgon2idKey(t *testing.T) {
61 | decryptedSecrets, err := Read("storage_test_argon2id_input.json", []byte("wrong-password"))
62 |
63 | if len(decryptedSecrets) != 0 {
64 | t.Fatal(fmt.Sprintf("Expected no secrets, but got: %v", decryptedSecrets))
65 | }
66 |
67 | if err.Error() != "Invalid vault password!" {
68 | t.Fatal(fmt.Sprintf("Expected invalid password error message but got: %v", err))
69 | }
70 | }
71 |
72 | func TestRead_NoVault(t *testing.T) {
73 | decryptedSecrets, err := Read("non-existing-file", []byte("secret-password"))
74 |
75 | if err != nil {
76 | t.Fatal(err)
77 | }
78 |
79 | if len(decryptedSecrets) != 0 {
80 | t.Fatal(fmt.Sprintf("Expected to have 0 secrets, but got: %d", len(decryptedSecrets)))
81 | }
82 | }
83 |
84 | func secrets() []secret.Secret {
85 | secret1 := secret.New("foo", "goo")
86 | secret2 := secret.New("baz", "boo")
87 | return []secret.Secret{secret1, secret2}
88 | }
89 |
--------------------------------------------------------------------------------
/storage/storage_test_argon2id_input.json:
--------------------------------------------------------------------------------
1 | {
2 | "Data": "ASvO5+d6UknTFU6JiUQvgclo6qV21UfWlabNXidoG9hx6eR0JgOaQ/9P9RKOyr0RQrTxrs7RRyxDqle4Zsa2bhZBD/+f4ZlK/9a+XPwhRCe7vzvGFASgm7CVsjPT74dpSeJf7ocbHJ0fnZy5KbwDHAa177tx5GwzrCsRkcvkpaUj23O5xOX8/SiYpAjf4qeGnLG82+Dy5OeEFMqWUniIDh+NBA==",
3 | "Nonce": "IkIlthu1Zp6n+18I7EvglK0Njgua+LmE",
4 | "Salt": "EMq4bsuuTpQNZiG2gEoNYseFQrCyHVd99nWJBP63u4E=",
5 | "Params": {
6 | "Memory": 65536,
7 | "Threads": 4,
8 | "Time": 1
9 | }
10 | }
--------------------------------------------------------------------------------
/vault/add/add.go:
--------------------------------------------------------------------------------
1 | package add
2 |
3 | import (
4 | "github.com/jarmo/secrets/secret"
5 | )
6 |
7 | func Execute(secrets []secret.Secret, name, value string) (secret.Secret, []secret.Secret) {
8 | newSecret := secret.New(name, value)
9 | return newSecret, append(secrets, newSecret)
10 | }
11 |
--------------------------------------------------------------------------------
/vault/add/add_test.go:
--------------------------------------------------------------------------------
1 | package add
2 |
3 | import (
4 | "testing"
5 | "fmt"
6 | "github.com/jarmo/secrets/secret"
7 | )
8 |
9 | func TestExecute(t *testing.T) {
10 | secret1 := secret.New("name-1", "value-1")
11 | secret2 := secret.New("name-2", "value-2")
12 | secrets := [...]secret.Secret{secret1, secret2}
13 |
14 | addedSecret, newSecrets := Execute(secrets[:], "new-secret-name", "new-secret-value")
15 | expectedAddedSecret := secret.Secret{addedSecret.Id, "new-secret-name", "new-secret-value"}
16 |
17 | if addedSecret != expectedAddedSecret {
18 | t.Fatal(fmt.Sprintf("Expected %s to be added, but was %s", expectedAddedSecret, addedSecret))
19 | }
20 |
21 | expectedNewSecrets := [...]secret.Secret{secret1, secret2, addedSecret}
22 |
23 | if fmt.Sprintf("%v", newSecrets) != fmt.Sprintf("%v", expectedNewSecrets) {
24 | t.Fatal(fmt.Sprintf("Expected new secrets to be %s, but got %s", expectedNewSecrets, newSecrets))
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/vault/delete/delete.go:
--------------------------------------------------------------------------------
1 | package delete
2 |
3 | import (
4 | "github.com/jarmo/secrets/secret"
5 | )
6 |
7 | func Execute(secrets []secret.Secret, index int) (secret.Secret, []secret.Secret) {
8 | deletedSecret := secrets[index]
9 | return deletedSecret, append(secrets[:index], secrets[index + 1:]...)
10 | }
11 |
--------------------------------------------------------------------------------
/vault/delete/delete_test.go:
--------------------------------------------------------------------------------
1 | package delete
2 |
3 | import (
4 | "testing"
5 | "fmt"
6 | "github.com/jarmo/secrets/secret"
7 | )
8 |
9 | func TestExecute(t *testing.T) {
10 | secret1 := secret.New("name-1", "value-1")
11 | secret2 := secret.New("name-2", "value-2")
12 | secret3 := secret.New("name-3", "value-3")
13 | secrets := [...]secret.Secret{secret1, secret2, secret3}
14 |
15 | deletedSecret, newSecrets := Execute(secrets[:], 1)
16 |
17 | if deletedSecret != secret2 {
18 | t.Fatal(fmt.Sprintf("Expected %s to be deleted, but was %s", secret2, deletedSecret))
19 | }
20 |
21 | expectedNewSecrets := [...]secret.Secret{secret1, secret3}
22 |
23 | if fmt.Sprintf("%v", newSecrets) != fmt.Sprintf("%v", expectedNewSecrets) {
24 | t.Fatal(fmt.Sprintf("Expected new secrets to be %s, but got %s", expectedNewSecrets, newSecrets))
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/vault/edit/edit.go:
--------------------------------------------------------------------------------
1 | package edit
2 |
3 | import (
4 | "github.com/jarmo/secrets/secret"
5 | )
6 |
7 | func Execute(secrets []secret.Secret, index int, newName, newValue string) (secret.Secret, []secret.Secret) {
8 | editedSecret := secrets[index]
9 | newSecret := secret.New(newName, newValue)
10 | newSecret.Id = editedSecret.Id
11 | secrets[index] = newSecret
12 | return newSecret, secrets
13 | }
14 |
15 |
--------------------------------------------------------------------------------
/vault/edit/edit_test.go:
--------------------------------------------------------------------------------
1 | package edit
2 |
3 | import (
4 | "testing"
5 | "fmt"
6 | "github.com/jarmo/secrets/secret"
7 | )
8 |
9 | func TestExecute(t *testing.T) {
10 | secret1 := secret.New("name-1", "value-1")
11 | secret2 := secret.New("name-2", "value-2")
12 | secret3 := secret.New("name-3", "value-3")
13 | secrets := [...]secret.Secret{secret1, secret2, secret3}
14 |
15 | editedSecret, newSecrets := Execute(secrets[:], 1, "new-secret-name", "new-secret-value")
16 |
17 | expectedEditedSecret := secret.Secret{secret2.Id, "new-secret-name", "new-secret-value"}
18 |
19 | if editedSecret != expectedEditedSecret {
20 | t.Fatal(fmt.Sprintf("Expected %s to be edited, but was %s", expectedEditedSecret, editedSecret))
21 | }
22 |
23 | expectedNewSecrets := [...]secret.Secret{secret1, expectedEditedSecret, secret3}
24 |
25 | if fmt.Sprintf("%v", newSecrets) != fmt.Sprintf("%v", expectedNewSecrets) {
26 | t.Fatal(fmt.Sprintf("Expected new secrets to be %s, but got %s", expectedNewSecrets, newSecrets))
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/vault/list/list.go:
--------------------------------------------------------------------------------
1 | package list
2 |
3 | import (
4 | "strings"
5 | "sort"
6 | "github.com/jarmo/secrets/secret"
7 | )
8 |
9 | func Execute(secrets []secret.Secret, filter string) []secret.Secret {
10 | var matches []secret.Secret
11 | for _, secret := range secrets {
12 | if secret.Id.String() == filter ||
13 | strings.Index(strings.ToLower(secret.Name), strings.ToLower(filter)) != -1 ||
14 | strings.Index(strings.ToLower(secret.Value), strings.ToLower(filter)) != -1 {
15 | matches = append(matches, secret)
16 | }
17 | }
18 |
19 | return sortByName(matches)
20 | }
21 |
22 | func sortByName(secrets []secret.Secret) []secret.Secret {
23 | sort.Slice(secrets, func(i, j int) bool { return strings.ToLower(secrets[i].Name) < strings.ToLower(secrets[j].Name) })
24 | return secrets
25 | }
26 |
--------------------------------------------------------------------------------
/vault/list/list_test.go:
--------------------------------------------------------------------------------
1 | package list
2 |
3 | import (
4 | "testing"
5 | "fmt"
6 | "github.com/jarmo/secrets/secret"
7 | )
8 |
9 | func TestExecute_WithNameFilter(t *testing.T) {
10 | secret1 := secret.New("foo", "goo")
11 | secret2 := secret.New("Baz", "boo")
12 | secret3 := secret.New("bar", "brr")
13 | secrets := [...]secret.Secret{secret1, secret2, secret3}
14 |
15 | listedSecrets := Execute(secrets[:], "ba")
16 |
17 | expectedListedSecrets := [...]secret.Secret{secret3, secret2}
18 |
19 | if fmt.Sprintf("%v", listedSecrets) != fmt.Sprintf("%v", expectedListedSecrets) {
20 | t.Fatal(fmt.Sprintf("Expected listed secrets to be %s, but got %s", expectedListedSecrets, listedSecrets))
21 | }
22 | }
23 |
24 | func TestExecute_WithValueFilter(t *testing.T) {
25 | secret1 := secret.New("foo", "goo")
26 | secret2 := secret.New("Baz", "boo")
27 | secret3 := secret.New("bar", "brr")
28 | secrets := [...]secret.Secret{secret1, secret2, secret3}
29 |
30 | listedSecrets := Execute(secrets[:], "boo")
31 |
32 | expectedListedSecrets := [...]secret.Secret{secret2}
33 |
34 | if fmt.Sprintf("%v", listedSecrets) != fmt.Sprintf("%v", expectedListedSecrets) {
35 | t.Fatal(fmt.Sprintf("Expected listed secrets to be %s, but got %s", expectedListedSecrets, listedSecrets))
36 | }
37 | }
38 |
39 | func TestExecute_WithIdFilter(t *testing.T) {
40 | secret1 := secret.New("foo", "goo")
41 | secret2 := secret.New("Baz", "boo")
42 | secret3 := secret.New("bar", "brr")
43 | secrets := [...]secret.Secret{secret1, secret2, secret3}
44 |
45 | listedSecrets := Execute(secrets[:], secret3.Id.String())
46 |
47 | expectedListedSecrets := [...]secret.Secret{secret3}
48 |
49 | if fmt.Sprintf("%v", listedSecrets) != fmt.Sprintf("%v", expectedListedSecrets) {
50 | t.Fatal(fmt.Sprintf("Expected listed secrets to be %s, but got %s", expectedListedSecrets, listedSecrets))
51 | }
52 | }
53 |
54 | func TestExecute_WithoutAnyFilter(t *testing.T) {
55 | secret1 := secret.New("foo", "goo")
56 | secret2 := secret.New("Baz", "boo")
57 | secret3 := secret.New("bar", "brr")
58 | secrets := [...]secret.Secret{secret1, secret2, secret3}
59 |
60 | listedSecrets := Execute(secrets[:], "")
61 |
62 | expectedListedSecrets := [...]secret.Secret{secret3, secret2, secret1}
63 |
64 | if fmt.Sprintf("%v", listedSecrets) != fmt.Sprintf("%v", expectedListedSecrets) {
65 | t.Fatal(fmt.Sprintf("Expected listed secrets to be %s, but got %s", expectedListedSecrets, listedSecrets))
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/vault/vault.go:
--------------------------------------------------------------------------------
1 | package vault
2 |
3 | import (
4 | "errors"
5 | "bytes"
6 | "github.com/jarmo/secrets/secret"
7 | "github.com/jarmo/secrets/storage"
8 | "github.com/jarmo/secrets/vault/add"
9 | "github.com/jarmo/secrets/vault/list"
10 | "github.com/jarmo/secrets/vault/delete"
11 | "github.com/jarmo/secrets/vault/edit"
12 | "github.com/satori/go.uuid"
13 | )
14 |
15 | func List(secrets []secret.Secret, filter string) []secret.Secret {
16 | return list.Execute(secrets, filter)
17 | }
18 |
19 | func Add(secrets []secret.Secret, name, value string) (secret.Secret, []secret.Secret) {
20 | newSecret, newSecrets := add.Execute(secrets, name, value)
21 | return newSecret, newSecrets
22 | }
23 |
24 | func Delete(secrets []secret.Secret, id uuid.UUID) (*secret.Secret, []secret.Secret, error) {
25 | existingSecretIndex := findIndexById(secrets, id)
26 | if existingSecretIndex == -1 {
27 | return nil, secrets, errors.New("Secret by specified id not found!")
28 | }
29 |
30 | deletedSecret, newSecrets := delete.Execute(secrets, existingSecretIndex)
31 | return &deletedSecret, newSecrets, nil
32 | }
33 |
34 | func Edit(secrets []secret.Secret, id uuid.UUID, newName, newValue string) (*secret.Secret, []secret.Secret, error) {
35 | existingSecretIndex := findIndexById(secrets, id)
36 | if existingSecretIndex == -1 {
37 | return nil, secrets, errors.New("Secret by specified id not found!")
38 | }
39 |
40 | editedSecret, newSecrets := edit.Execute(secrets, existingSecretIndex, newName, newValue)
41 | return &editedSecret, newSecrets, nil
42 | }
43 |
44 | func ChangePassword(storagePath string, currentPassword, newPassword, newPasswordConfirmation []byte) error {
45 | secrets, err := storage.Read(storagePath, currentPassword)
46 | if err != nil {
47 | return err
48 | }
49 |
50 | if !bytes.Equal(newPassword, newPasswordConfirmation) {
51 | return errors.New("Passwords do not match!")
52 | }
53 | storage.Write(storagePath, newPassword, secrets)
54 |
55 | return nil
56 | }
57 |
58 | func findIndexById(secrets []secret.Secret, id uuid.UUID) int {
59 | for index, secret := range secrets {
60 | if secret.Id == id {
61 | return index
62 | }
63 | }
64 |
65 | return -1
66 | }
67 |
--------------------------------------------------------------------------------
/vault/vault_test_argon2id_input.json:
--------------------------------------------------------------------------------
1 | {
2 | "Data": "RhKAHyjvwvDolCe0qbDQMsOs6z81VEpjtarGtQtBpKyY17bDn3fWH6X+jYl3OY9JpYVMExEc7DmXBA8gW3fqB2vIKdczr4I+S7zTRhEc+suYAcAhZyo/Zmb7beZ5NnKEYWk13/PXSuRZ4olDYAukg0dSSPyEgTnr7kLVx4+vGn39hktzoNsiVbgFzrVAAZMEBjzHZ7vhdquQguR9KKslqw7yYnKXR/0eVbDuQ44TGPSobqEtBk3cRY0qhhZJ81B+1nZFq+PcckcRkJjHCOU8zMqaawnsrV10wPXCm3uUtQZqFN+mWtEdA0xWfGoQIXaJbRHgyqE0PZznsXfzeQ55lju5p5Fww7X3K9aTNDUWbVYe1JX6za+heNIicuWxjLn/J6sxeBxGwZe3ZPE=",
3 | "Nonce": "fxKhRZVW7AzMdH0SnaAHCaJ3m+tpiPSE",
4 | "Salt": "KCqzFJrlfVAPH4ttJZGQM8a+hYUtdOcUT5ksfjtzDLI=",
5 | "Params": {
6 | "Memory": 65536,
7 | "Threads": 4,
8 | "Time": 1
9 | }
10 | }
--------------------------------------------------------------------------------
/vendor/github.com/juju/fslock/.gitignore:
--------------------------------------------------------------------------------
1 | # Compiled Object files, Static and Dynamic libs (Shared Objects)
2 | *.o
3 | *.a
4 | *.so
5 |
6 | # Folders
7 | _obj
8 | _test
9 |
10 | # Architecture specific extensions/prefixes
11 | *.[568vq]
12 | [568vq].out
13 |
14 | *.cgo1.go
15 | *.cgo2.c
16 | _cgo_defun.c
17 | _cgo_gotypes.go
18 | _cgo_export.*
19 |
20 | _testmain.go
21 |
22 | *.exe
23 | *.test
24 | *.prof
25 |
--------------------------------------------------------------------------------
/vendor/github.com/juju/fslock/README.md:
--------------------------------------------------------------------------------
1 |
2 | # fslock [](https://godoc.org/github.com/juju/fslock)
3 | fslock provides a cross-process mutex based on file locks that works on windows and *nix platforms.
4 |
5 |
6 | 
7 |
8 | image: [public domain](https://pixabay.com/en/encrypted-privacy-policy-445155/)
9 | (don't ask)
10 |
11 |
12 | fslock relies on LockFileEx on Windows and flock on \*nix systems. The timeout
13 | feature uses overlapped IO on Windows, but on \*nix platforms, timing out
14 | requires the use of a goroutine that will run until the lock is acquired,
15 | regardless of timeout. If you need to avoid this use of goroutines, poll
16 | TryLock in a loop.
17 |
18 |
19 |
20 | ## Variables
21 | ``` go
22 | var ErrLocked error = trylockError("fslock is already locked")
23 | ```
24 | ErrLocked indicates TryLock failed because the lock was already locked.
25 |
26 | ``` go
27 | var ErrTimeout error = timeoutError("lock timeout exceeded")
28 | ```
29 | ErrTimeout indicates that the lock attempt timed out.
30 |
31 |
32 | ## type Lock
33 | ``` go
34 | type Lock struct {
35 | // contains filtered or unexported fields
36 | }
37 | ```
38 | Lock implements cross-process locks using syscalls.
39 |
40 |
41 | ### func New
42 | ``` go
43 | func New(filename string) *Lock
44 | ```
45 | New returns a new lock around the given file.
46 |
47 |
48 | ### func (\*Lock) Lock
49 | ``` go
50 | func (l *Lock) Lock() error
51 | ```
52 | Lock locks the lock. This call will block until the lock is available.
53 |
54 | ### func (\*Lock) LockWithTimeout
55 | ``` go
56 | func (l *Lock) LockWithTimeout(timeout time.Duration) error
57 | ```
58 | LockWithTimeout tries to lock the lock until the timeout expires. If the
59 | timeout expires, this method will return ErrTimeout.
60 |
61 | ### func (\*Lock) TryLock
62 | ``` go
63 | func (l *Lock) TryLock() error
64 | ```
65 | TryLock attempts to lock the lock. This method will return ErrLocked
66 | immediately if the lock cannot be acquired.
67 |
68 | ### func (\*Lock) Unlock
69 | ``` go
70 | func (l *Lock) Unlock() error
71 | ```
72 | Unlock unlocks the lock.
73 |
74 |
75 |
--------------------------------------------------------------------------------
/vendor/github.com/juju/fslock/fslock.go:
--------------------------------------------------------------------------------
1 | // Copyright 2016 Canonical Ltd.
2 | // Licensed under the LGPLv3, see LICENCE file for details.
3 |
4 | // Package fslock provides a cross-process mutex based on file locks.
5 | //
6 | // It is built on top of flock for linux and darwin, and LockFileEx on Windows.
7 | package fslock
8 |
9 | // ErrTimeout indicates that the lock attempt timed out.
10 | var ErrTimeout error = timeoutError("lock timeout exceeded")
11 |
12 | type timeoutError string
13 |
14 | func (t timeoutError) Error() string {
15 | return string(t)
16 | }
17 | func (timeoutError) Timeout() bool {
18 | return true
19 | }
20 |
21 | // ErrLocked indicates TryLock failed because the lock was already locked.
22 | var ErrLocked error = trylockError("fslock is already locked")
23 |
24 | type trylockError string
25 |
26 | func (t trylockError) Error() string {
27 | return string(t)
28 | }
29 |
30 | func (trylockError) Temporary() bool {
31 | return true
32 | }
33 |
--------------------------------------------------------------------------------
/vendor/github.com/juju/fslock/fslock_nix.go:
--------------------------------------------------------------------------------
1 | // Copyright 2016 Canonical Ltd.
2 | // Licensed under the LGPLv3, see LICENCE file for details.
3 |
4 | // +build darwin dragonfly freebsd linux netbsd openbsd
5 |
6 | package fslock
7 |
8 | import (
9 | "syscall"
10 | "time"
11 | )
12 |
13 | // Lock implements cross-process locks using syscalls.
14 | // This implementation is based on flock syscall.
15 | type Lock struct {
16 | filename string
17 | fd int
18 | }
19 |
20 | // New returns a new lock around the given file.
21 | func New(filename string) *Lock {
22 | return &Lock{filename: filename}
23 | }
24 |
25 | // Lock locks the lock. This call will block until the lock is available.
26 | func (l *Lock) Lock() error {
27 | if err := l.open(); err != nil {
28 | return err
29 | }
30 | return syscall.Flock(l.fd, syscall.LOCK_EX)
31 | }
32 |
33 | // TryLock attempts to lock the lock. This method will return ErrLocked
34 | // immediately if the lock cannot be acquired.
35 | func (l *Lock) TryLock() error {
36 | if err := l.open(); err != nil {
37 | return err
38 | }
39 | err := syscall.Flock(l.fd, syscall.LOCK_EX|syscall.LOCK_NB)
40 | if err != nil {
41 | syscall.Close(l.fd)
42 | }
43 | if err == syscall.EWOULDBLOCK {
44 | return ErrLocked
45 | }
46 | return err
47 | }
48 |
49 | func (l *Lock) open() error {
50 | fd, err := syscall.Open(l.filename, syscall.O_CREAT|syscall.O_RDONLY, 0600)
51 | if err != nil {
52 | return err
53 | }
54 | l.fd = fd
55 | return nil
56 | }
57 |
58 | // Unlock unlocks the lock.
59 | func (l *Lock) Unlock() error {
60 | return syscall.Close(l.fd)
61 | }
62 |
63 | // LockWithTimeout tries to lock the lock until the timeout expires. If the
64 | // timeout expires, this method will return ErrTimeout.
65 | func (l *Lock) LockWithTimeout(timeout time.Duration) error {
66 | if err := l.open(); err != nil {
67 | return err
68 | }
69 | result := make(chan error)
70 | cancel := make(chan struct{})
71 | go func() {
72 | err := syscall.Flock(l.fd, syscall.LOCK_EX)
73 | select {
74 | case <-cancel:
75 | // Timed out, cleanup if necessary.
76 | syscall.Flock(l.fd, syscall.LOCK_UN)
77 | syscall.Close(l.fd)
78 | case result <- err:
79 | }
80 | }()
81 | select {
82 | case err := <-result:
83 | return err
84 | case <-time.After(timeout):
85 | close(cancel)
86 | return ErrTimeout
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/vendor/github.com/juju/fslock/fslock_windows.go:
--------------------------------------------------------------------------------
1 | // Copyright 2016 Canonical Ltd.
2 | // Licensed under the LGPLv3, see LICENCE file for details.
3 |
4 | package fslock
5 |
6 | import (
7 | "log"
8 | "syscall"
9 | "time"
10 | "unsafe"
11 | )
12 |
13 | var (
14 | modkernel32 = syscall.NewLazyDLL("kernel32.dll")
15 | procLockFileEx = modkernel32.NewProc("LockFileEx")
16 | procCreateEventW = modkernel32.NewProc("CreateEventW")
17 | )
18 |
19 | const (
20 | lockfileExclusiveLock = 2
21 | fileFlagNormal = 0x00000080
22 | )
23 |
24 | func init() {
25 | log.SetFlags(log.Lmicroseconds | log.Ldate)
26 | }
27 |
28 | // Lock implements cross-process locks using syscalls.
29 | // This implementation is based on LockFileEx syscall.
30 | type Lock struct {
31 | filename string
32 | handle syscall.Handle
33 | }
34 |
35 | // New returns a new lock around the given file.
36 | func New(filename string) *Lock {
37 | return &Lock{filename: filename}
38 | }
39 |
40 | // TryLock attempts to lock the lock. This method will return ErrLocked
41 | // immediately if the lock cannot be acquired.
42 | func (l *Lock) TryLock() error {
43 | err := l.LockWithTimeout(0)
44 | if err == ErrTimeout {
45 | // in our case, timing out immediately just means it was already locked.
46 | return ErrLocked
47 | }
48 | return err
49 | }
50 |
51 | // Lock locks the lock. This call will block until the lock is available.
52 | func (l *Lock) Lock() error {
53 | return l.LockWithTimeout(-1)
54 | }
55 |
56 | // Unlock unlocks the lock.
57 | func (l *Lock) Unlock() error {
58 | return syscall.Close(l.handle)
59 | }
60 |
61 | // LockWithTimeout tries to lock the lock until the timeout expires. If the
62 | // timeout expires, this method will return ErrTimeout.
63 | func (l *Lock) LockWithTimeout(timeout time.Duration) (err error) {
64 | name, err := syscall.UTF16PtrFromString(l.filename)
65 | if err != nil {
66 | return err
67 | }
68 |
69 | // Open for asynchronous I/O so that we can timeout waiting for the lock.
70 | // Also open shared so that other processes can open the file (but will
71 | // still need to lock it).
72 | handle, err := syscall.CreateFile(
73 | name,
74 | syscall.GENERIC_READ,
75 | syscall.FILE_SHARE_READ,
76 | nil,
77 | syscall.OPEN_ALWAYS,
78 | syscall.FILE_FLAG_OVERLAPPED|fileFlagNormal,
79 | 0)
80 | if err != nil {
81 | return err
82 | }
83 | l.handle = handle
84 | defer func() {
85 | if err != nil {
86 | syscall.Close(handle)
87 | }
88 | }()
89 |
90 | millis := uint32(syscall.INFINITE)
91 | if timeout >= 0 {
92 | millis = uint32(timeout.Nanoseconds() / 1000000)
93 | }
94 |
95 | ol, err := newOverlapped()
96 | if err != nil {
97 | return err
98 | }
99 | defer syscall.CloseHandle(ol.HEvent)
100 | err = lockFileEx(handle, lockfileExclusiveLock, 0, 1, 0, ol)
101 | if err == nil {
102 | return nil
103 | }
104 |
105 | // ERROR_IO_PENDING is expected when we're waiting on an asychronous event
106 | // to occur.
107 | if err != syscall.ERROR_IO_PENDING {
108 | return err
109 | }
110 | s, err := syscall.WaitForSingleObject(ol.HEvent, millis)
111 |
112 | switch s {
113 | case syscall.WAIT_OBJECT_0:
114 | // success!
115 | return nil
116 | case syscall.WAIT_TIMEOUT:
117 | return ErrTimeout
118 | default:
119 | return err
120 | }
121 | }
122 |
123 | // newOverlapped creates a structure used to track asynchronous
124 | // I/O requests that have been issued.
125 | func newOverlapped() (*syscall.Overlapped, error) {
126 | event, err := createEvent(nil, true, false, nil)
127 | if err != nil {
128 | return nil, err
129 | }
130 | return &syscall.Overlapped{HEvent: event}, nil
131 | }
132 |
133 | func lockFileEx(h syscall.Handle, flags, reserved, locklow, lockhigh uint32, ol *syscall.Overlapped) (err error) {
134 | r1, _, e1 := syscall.Syscall6(procLockFileEx.Addr(), 6, uintptr(h), uintptr(flags), uintptr(reserved), uintptr(locklow), uintptr(lockhigh), uintptr(unsafe.Pointer(ol)))
135 | if r1 == 0 {
136 | if e1 != 0 {
137 | err = error(e1)
138 | } else {
139 | err = syscall.EINVAL
140 | }
141 | }
142 | return
143 | }
144 |
145 | func createEvent(sa *syscall.SecurityAttributes, manualReset bool, initialState bool, name *uint16) (handle syscall.Handle, err error) {
146 | var _p0 uint32
147 | if manualReset {
148 | _p0 = 1
149 | }
150 | var _p1 uint32
151 | if initialState {
152 | _p1 = 1
153 | }
154 |
155 | r0, _, e1 := syscall.Syscall6(procCreateEventW.Addr(), 4, uintptr(unsafe.Pointer(sa)), uintptr(_p0), uintptr(_p1), uintptr(unsafe.Pointer(name)), 0, 0)
156 | handle = syscall.Handle(r0)
157 | if handle == syscall.InvalidHandle {
158 | if e1 != 0 {
159 | err = error(e1)
160 | } else {
161 | err = syscall.EINVAL
162 | }
163 | }
164 | return
165 | }
166 |
--------------------------------------------------------------------------------
/vendor/github.com/satori/go.uuid/.travis.yml:
--------------------------------------------------------------------------------
1 | language: go
2 | sudo: false
3 | go:
4 | - 1.2
5 | - 1.3
6 | - 1.4
7 | - 1.5
8 | - 1.6
9 | - 1.7
10 | - 1.8
11 | - 1.9
12 | - tip
13 | matrix:
14 | allow_failures:
15 | - go: tip
16 | fast_finish: true
17 | before_install:
18 | - go get github.com/mattn/goveralls
19 | - go get golang.org/x/tools/cmd/cover
20 | script:
21 | - $HOME/gopath/bin/goveralls -service=travis-ci
22 | notifications:
23 | email: false
24 |
--------------------------------------------------------------------------------
/vendor/github.com/satori/go.uuid/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (C) 2013-2018 by Maxim Bublis
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining
4 | a copy of this software and associated documentation files (the
5 | "Software"), to deal in the Software without restriction, including
6 | without limitation the rights to use, copy, modify, merge, publish,
7 | distribute, sublicense, and/or sell copies of the Software, and to
8 | permit persons to whom the Software is furnished to do so, subject to
9 | the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be
12 | included in all copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
--------------------------------------------------------------------------------
/vendor/github.com/satori/go.uuid/README.md:
--------------------------------------------------------------------------------
1 | # UUID package for Go language
2 |
3 | [](https://travis-ci.org/satori/go.uuid)
4 | [](https://coveralls.io/github/satori/go.uuid)
5 | [](http://godoc.org/github.com/satori/go.uuid)
6 |
7 | This package provides pure Go implementation of Universally Unique Identifier (UUID). Supported both creation and parsing of UUIDs.
8 |
9 | With 100% test coverage and benchmarks out of box.
10 |
11 | Supported versions:
12 | * Version 1, based on timestamp and MAC address (RFC 4122)
13 | * Version 2, based on timestamp, MAC address and POSIX UID/GID (DCE 1.1)
14 | * Version 3, based on MD5 hashing (RFC 4122)
15 | * Version 4, based on random numbers (RFC 4122)
16 | * Version 5, based on SHA-1 hashing (RFC 4122)
17 |
18 | ## Installation
19 |
20 | Use the `go` command:
21 |
22 | $ go get github.com/satori/go.uuid
23 |
24 | ## Requirements
25 |
26 | UUID package requires Go >= 1.2.
27 |
28 | ## Example
29 |
30 | ```go
31 | package main
32 |
33 | import (
34 | "fmt"
35 | "github.com/satori/go.uuid"
36 | )
37 |
38 | func main() {
39 | // Creating UUID Version 4
40 | u1 := uuid.NewV4()
41 | fmt.Printf("UUIDv4: %s\n", u1)
42 |
43 | // Parsing UUID from string input
44 | u2, err := uuid.FromString("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
45 | if err != nil {
46 | fmt.Printf("Something gone wrong: %s", err)
47 | }
48 | fmt.Printf("Successfully parsed: %s", u2)
49 | }
50 | ```
51 |
52 | ## Documentation
53 |
54 | [Documentation](http://godoc.org/github.com/satori/go.uuid) is hosted at GoDoc project.
55 |
56 | ## Links
57 | * [RFC 4122](http://tools.ietf.org/html/rfc4122)
58 | * [DCE 1.1: Authentication and Security Services](http://pubs.opengroup.org/onlinepubs/9696989899/chap5.htm#tagcjh_08_02_01_01)
59 |
60 | ## Copyright
61 |
62 | Copyright (C) 2013-2018 by Maxim Bublis .
63 |
64 | UUID package released under MIT License.
65 | See [LICENSE](https://github.com/satori/go.uuid/blob/master/LICENSE) for details.
66 |
--------------------------------------------------------------------------------
/vendor/github.com/satori/go.uuid/codec.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2013-2018 by Maxim Bublis
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining
4 | // a copy of this software and associated documentation files (the
5 | // "Software"), to deal in the Software without restriction, including
6 | // without limitation the rights to use, copy, modify, merge, publish,
7 | // distribute, sublicense, and/or sell copies of the Software, and to
8 | // permit persons to whom the Software is furnished to do so, subject to
9 | // the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be
12 | // included in all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
22 | package uuid
23 |
24 | import (
25 | "bytes"
26 | "encoding/hex"
27 | "fmt"
28 | )
29 |
30 | // FromBytes returns UUID converted from raw byte slice input.
31 | // It will return error if the slice isn't 16 bytes long.
32 | func FromBytes(input []byte) (u UUID, err error) {
33 | err = u.UnmarshalBinary(input)
34 | return
35 | }
36 |
37 | // FromBytesOrNil returns UUID converted from raw byte slice input.
38 | // Same behavior as FromBytes, but returns a Nil UUID on error.
39 | func FromBytesOrNil(input []byte) UUID {
40 | uuid, err := FromBytes(input)
41 | if err != nil {
42 | return Nil
43 | }
44 | return uuid
45 | }
46 |
47 | // FromString returns UUID parsed from string input.
48 | // Input is expected in a form accepted by UnmarshalText.
49 | func FromString(input string) (u UUID, err error) {
50 | err = u.UnmarshalText([]byte(input))
51 | return
52 | }
53 |
54 | // FromStringOrNil returns UUID parsed from string input.
55 | // Same behavior as FromString, but returns a Nil UUID on error.
56 | func FromStringOrNil(input string) UUID {
57 | uuid, err := FromString(input)
58 | if err != nil {
59 | return Nil
60 | }
61 | return uuid
62 | }
63 |
64 | // MarshalText implements the encoding.TextMarshaler interface.
65 | // The encoding is the same as returned by String.
66 | func (u UUID) MarshalText() (text []byte, err error) {
67 | text = []byte(u.String())
68 | return
69 | }
70 |
71 | // UnmarshalText implements the encoding.TextUnmarshaler interface.
72 | // Following formats are supported:
73 | // "6ba7b810-9dad-11d1-80b4-00c04fd430c8",
74 | // "{6ba7b810-9dad-11d1-80b4-00c04fd430c8}",
75 | // "urn:uuid:6ba7b810-9dad-11d1-80b4-00c04fd430c8"
76 | // "6ba7b8109dad11d180b400c04fd430c8"
77 | // ABNF for supported UUID text representation follows:
78 | // uuid := canonical | hashlike | braced | urn
79 | // plain := canonical | hashlike
80 | // canonical := 4hexoct '-' 2hexoct '-' 2hexoct '-' 6hexoct
81 | // hashlike := 12hexoct
82 | // braced := '{' plain '}'
83 | // urn := URN ':' UUID-NID ':' plain
84 | // URN := 'urn'
85 | // UUID-NID := 'uuid'
86 | // 12hexoct := 6hexoct 6hexoct
87 | // 6hexoct := 4hexoct 2hexoct
88 | // 4hexoct := 2hexoct 2hexoct
89 | // 2hexoct := hexoct hexoct
90 | // hexoct := hexdig hexdig
91 | // hexdig := '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' |
92 | // 'a' | 'b' | 'c' | 'd' | 'e' | 'f' |
93 | // 'A' | 'B' | 'C' | 'D' | 'E' | 'F'
94 | func (u *UUID) UnmarshalText(text []byte) (err error) {
95 | switch len(text) {
96 | case 32:
97 | return u.decodeHashLike(text)
98 | case 36:
99 | return u.decodeCanonical(text)
100 | case 38:
101 | return u.decodeBraced(text)
102 | case 41:
103 | fallthrough
104 | case 45:
105 | return u.decodeURN(text)
106 | default:
107 | return fmt.Errorf("uuid: incorrect UUID length: %s", text)
108 | }
109 | }
110 |
111 | // decodeCanonical decodes UUID string in format
112 | // "6ba7b810-9dad-11d1-80b4-00c04fd430c8".
113 | func (u *UUID) decodeCanonical(t []byte) (err error) {
114 | if t[8] != '-' || t[13] != '-' || t[18] != '-' || t[23] != '-' {
115 | return fmt.Errorf("uuid: incorrect UUID format %s", t)
116 | }
117 |
118 | src := t[:]
119 | dst := u[:]
120 |
121 | for i, byteGroup := range byteGroups {
122 | if i > 0 {
123 | src = src[1:] // skip dash
124 | }
125 | _, err = hex.Decode(dst[:byteGroup/2], src[:byteGroup])
126 | if err != nil {
127 | return
128 | }
129 | src = src[byteGroup:]
130 | dst = dst[byteGroup/2:]
131 | }
132 |
133 | return
134 | }
135 |
136 | // decodeHashLike decodes UUID string in format
137 | // "6ba7b8109dad11d180b400c04fd430c8".
138 | func (u *UUID) decodeHashLike(t []byte) (err error) {
139 | src := t[:]
140 | dst := u[:]
141 |
142 | if _, err = hex.Decode(dst, src); err != nil {
143 | return err
144 | }
145 | return
146 | }
147 |
148 | // decodeBraced decodes UUID string in format
149 | // "{6ba7b810-9dad-11d1-80b4-00c04fd430c8}" or in format
150 | // "{6ba7b8109dad11d180b400c04fd430c8}".
151 | func (u *UUID) decodeBraced(t []byte) (err error) {
152 | l := len(t)
153 |
154 | if t[0] != '{' || t[l-1] != '}' {
155 | return fmt.Errorf("uuid: incorrect UUID format %s", t)
156 | }
157 |
158 | return u.decodePlain(t[1 : l-1])
159 | }
160 |
161 | // decodeURN decodes UUID string in format
162 | // "urn:uuid:6ba7b810-9dad-11d1-80b4-00c04fd430c8" or in format
163 | // "urn:uuid:6ba7b8109dad11d180b400c04fd430c8".
164 | func (u *UUID) decodeURN(t []byte) (err error) {
165 | total := len(t)
166 |
167 | urn_uuid_prefix := t[:9]
168 |
169 | if !bytes.Equal(urn_uuid_prefix, urnPrefix) {
170 | return fmt.Errorf("uuid: incorrect UUID format: %s", t)
171 | }
172 |
173 | return u.decodePlain(t[9:total])
174 | }
175 |
176 | // decodePlain decodes UUID string in canonical format
177 | // "6ba7b810-9dad-11d1-80b4-00c04fd430c8" or in hash-like format
178 | // "6ba7b8109dad11d180b400c04fd430c8".
179 | func (u *UUID) decodePlain(t []byte) (err error) {
180 | switch len(t) {
181 | case 32:
182 | return u.decodeHashLike(t)
183 | case 36:
184 | return u.decodeCanonical(t)
185 | default:
186 | return fmt.Errorf("uuid: incorrrect UUID length: %s", t)
187 | }
188 | }
189 |
190 | // MarshalBinary implements the encoding.BinaryMarshaler interface.
191 | func (u UUID) MarshalBinary() (data []byte, err error) {
192 | data = u.Bytes()
193 | return
194 | }
195 |
196 | // UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.
197 | // It will return error if the slice isn't 16 bytes long.
198 | func (u *UUID) UnmarshalBinary(data []byte) (err error) {
199 | if len(data) != Size {
200 | err = fmt.Errorf("uuid: UUID must be exactly 16 bytes long, got %d bytes", len(data))
201 | return
202 | }
203 | copy(u[:], data)
204 |
205 | return
206 | }
207 |
--------------------------------------------------------------------------------
/vendor/github.com/satori/go.uuid/generator.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2013-2018 by Maxim Bublis
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining
4 | // a copy of this software and associated documentation files (the
5 | // "Software"), to deal in the Software without restriction, including
6 | // without limitation the rights to use, copy, modify, merge, publish,
7 | // distribute, sublicense, and/or sell copies of the Software, and to
8 | // permit persons to whom the Software is furnished to do so, subject to
9 | // the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be
12 | // included in all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
22 | package uuid
23 |
24 | import (
25 | "crypto/md5"
26 | "crypto/rand"
27 | "crypto/sha1"
28 | "encoding/binary"
29 | "hash"
30 | "net"
31 | "os"
32 | "sync"
33 | "time"
34 | )
35 |
36 | // Difference in 100-nanosecond intervals between
37 | // UUID epoch (October 15, 1582) and Unix epoch (January 1, 1970).
38 | const epochStart = 122192928000000000
39 |
40 | var (
41 | global = newDefaultGenerator()
42 |
43 | epochFunc = unixTimeFunc
44 | posixUID = uint32(os.Getuid())
45 | posixGID = uint32(os.Getgid())
46 | )
47 |
48 | // NewV1 returns UUID based on current timestamp and MAC address.
49 | func NewV1() UUID {
50 | return global.NewV1()
51 | }
52 |
53 | // NewV2 returns DCE Security UUID based on POSIX UID/GID.
54 | func NewV2(domain byte) UUID {
55 | return global.NewV2(domain)
56 | }
57 |
58 | // NewV3 returns UUID based on MD5 hash of namespace UUID and name.
59 | func NewV3(ns UUID, name string) UUID {
60 | return global.NewV3(ns, name)
61 | }
62 |
63 | // NewV4 returns random generated UUID.
64 | func NewV4() UUID {
65 | return global.NewV4()
66 | }
67 |
68 | // NewV5 returns UUID based on SHA-1 hash of namespace UUID and name.
69 | func NewV5(ns UUID, name string) UUID {
70 | return global.NewV5(ns, name)
71 | }
72 |
73 | // Generator provides interface for generating UUIDs.
74 | type Generator interface {
75 | NewV1() UUID
76 | NewV2(domain byte) UUID
77 | NewV3(ns UUID, name string) UUID
78 | NewV4() UUID
79 | NewV5(ns UUID, name string) UUID
80 | }
81 |
82 | // Default generator implementation.
83 | type generator struct {
84 | storageOnce sync.Once
85 | storageMutex sync.Mutex
86 |
87 | lastTime uint64
88 | clockSequence uint16
89 | hardwareAddr [6]byte
90 | }
91 |
92 | func newDefaultGenerator() Generator {
93 | return &generator{}
94 | }
95 |
96 | // NewV1 returns UUID based on current timestamp and MAC address.
97 | func (g *generator) NewV1() UUID {
98 | u := UUID{}
99 |
100 | timeNow, clockSeq, hardwareAddr := g.getStorage()
101 |
102 | binary.BigEndian.PutUint32(u[0:], uint32(timeNow))
103 | binary.BigEndian.PutUint16(u[4:], uint16(timeNow>>32))
104 | binary.BigEndian.PutUint16(u[6:], uint16(timeNow>>48))
105 | binary.BigEndian.PutUint16(u[8:], clockSeq)
106 |
107 | copy(u[10:], hardwareAddr)
108 |
109 | u.SetVersion(V1)
110 | u.SetVariant(VariantRFC4122)
111 |
112 | return u
113 | }
114 |
115 | // NewV2 returns DCE Security UUID based on POSIX UID/GID.
116 | func (g *generator) NewV2(domain byte) UUID {
117 | u := UUID{}
118 |
119 | timeNow, clockSeq, hardwareAddr := g.getStorage()
120 |
121 | switch domain {
122 | case DomainPerson:
123 | binary.BigEndian.PutUint32(u[0:], posixUID)
124 | case DomainGroup:
125 | binary.BigEndian.PutUint32(u[0:], posixGID)
126 | }
127 |
128 | binary.BigEndian.PutUint16(u[4:], uint16(timeNow>>32))
129 | binary.BigEndian.PutUint16(u[6:], uint16(timeNow>>48))
130 | binary.BigEndian.PutUint16(u[8:], clockSeq)
131 | u[9] = domain
132 |
133 | copy(u[10:], hardwareAddr)
134 |
135 | u.SetVersion(V2)
136 | u.SetVariant(VariantRFC4122)
137 |
138 | return u
139 | }
140 |
141 | // NewV3 returns UUID based on MD5 hash of namespace UUID and name.
142 | func (g *generator) NewV3(ns UUID, name string) UUID {
143 | u := newFromHash(md5.New(), ns, name)
144 | u.SetVersion(V3)
145 | u.SetVariant(VariantRFC4122)
146 |
147 | return u
148 | }
149 |
150 | // NewV4 returns random generated UUID.
151 | func (g *generator) NewV4() UUID {
152 | u := UUID{}
153 | g.safeRandom(u[:])
154 | u.SetVersion(V4)
155 | u.SetVariant(VariantRFC4122)
156 |
157 | return u
158 | }
159 |
160 | // NewV5 returns UUID based on SHA-1 hash of namespace UUID and name.
161 | func (g *generator) NewV5(ns UUID, name string) UUID {
162 | u := newFromHash(sha1.New(), ns, name)
163 | u.SetVersion(V5)
164 | u.SetVariant(VariantRFC4122)
165 |
166 | return u
167 | }
168 |
169 | func (g *generator) initStorage() {
170 | g.initClockSequence()
171 | g.initHardwareAddr()
172 | }
173 |
174 | func (g *generator) initClockSequence() {
175 | buf := make([]byte, 2)
176 | g.safeRandom(buf)
177 | g.clockSequence = binary.BigEndian.Uint16(buf)
178 | }
179 |
180 | func (g *generator) initHardwareAddr() {
181 | interfaces, err := net.Interfaces()
182 | if err == nil {
183 | for _, iface := range interfaces {
184 | if len(iface.HardwareAddr) >= 6 {
185 | copy(g.hardwareAddr[:], iface.HardwareAddr)
186 | return
187 | }
188 | }
189 | }
190 |
191 | // Initialize hardwareAddr randomly in case
192 | // of real network interfaces absence
193 | g.safeRandom(g.hardwareAddr[:])
194 |
195 | // Set multicast bit as recommended in RFC 4122
196 | g.hardwareAddr[0] |= 0x01
197 | }
198 |
199 | func (g *generator) safeRandom(dest []byte) {
200 | if _, err := rand.Read(dest); err != nil {
201 | panic(err)
202 | }
203 | }
204 |
205 | // Returns UUID v1/v2 storage state.
206 | // Returns epoch timestamp, clock sequence, and hardware address.
207 | func (g *generator) getStorage() (uint64, uint16, []byte) {
208 | g.storageOnce.Do(g.initStorage)
209 |
210 | g.storageMutex.Lock()
211 | defer g.storageMutex.Unlock()
212 |
213 | timeNow := epochFunc()
214 | // Clock changed backwards since last UUID generation.
215 | // Should increase clock sequence.
216 | if timeNow <= g.lastTime {
217 | g.clockSequence++
218 | }
219 | g.lastTime = timeNow
220 |
221 | return timeNow, g.clockSequence, g.hardwareAddr[:]
222 | }
223 |
224 | // Returns difference in 100-nanosecond intervals between
225 | // UUID epoch (October 15, 1582) and current time.
226 | // This is default epoch calculation function.
227 | func unixTimeFunc() uint64 {
228 | return epochStart + uint64(time.Now().UnixNano()/100)
229 | }
230 |
231 | // Returns UUID based on hashing of namespace UUID and name.
232 | func newFromHash(h hash.Hash, ns UUID, name string) UUID {
233 | u := UUID{}
234 | h.Write(ns[:])
235 | h.Write([]byte(name))
236 | copy(u[:], h.Sum(nil))
237 |
238 | return u
239 | }
240 |
--------------------------------------------------------------------------------
/vendor/github.com/satori/go.uuid/sql.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2013-2018 by Maxim Bublis
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining
4 | // a copy of this software and associated documentation files (the
5 | // "Software"), to deal in the Software without restriction, including
6 | // without limitation the rights to use, copy, modify, merge, publish,
7 | // distribute, sublicense, and/or sell copies of the Software, and to
8 | // permit persons to whom the Software is furnished to do so, subject to
9 | // the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be
12 | // included in all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
22 | package uuid
23 |
24 | import (
25 | "database/sql/driver"
26 | "fmt"
27 | )
28 |
29 | // Value implements the driver.Valuer interface.
30 | func (u UUID) Value() (driver.Value, error) {
31 | return u.String(), nil
32 | }
33 |
34 | // Scan implements the sql.Scanner interface.
35 | // A 16-byte slice is handled by UnmarshalBinary, while
36 | // a longer byte slice or a string is handled by UnmarshalText.
37 | func (u *UUID) Scan(src interface{}) error {
38 | switch src := src.(type) {
39 | case []byte:
40 | if len(src) == Size {
41 | return u.UnmarshalBinary(src)
42 | }
43 | return u.UnmarshalText(src)
44 |
45 | case string:
46 | return u.UnmarshalText([]byte(src))
47 | }
48 |
49 | return fmt.Errorf("uuid: cannot convert %T to UUID", src)
50 | }
51 |
52 | // NullUUID can be used with the standard sql package to represent a
53 | // UUID value that can be NULL in the database
54 | type NullUUID struct {
55 | UUID UUID
56 | Valid bool
57 | }
58 |
59 | // Value implements the driver.Valuer interface.
60 | func (u NullUUID) Value() (driver.Value, error) {
61 | if !u.Valid {
62 | return nil, nil
63 | }
64 | // Delegate to UUID Value function
65 | return u.UUID.Value()
66 | }
67 |
68 | // Scan implements the sql.Scanner interface.
69 | func (u *NullUUID) Scan(src interface{}) error {
70 | if src == nil {
71 | u.UUID, u.Valid = Nil, false
72 | return nil
73 | }
74 |
75 | // Delegate to UUID Scan function
76 | u.Valid = true
77 | return u.UUID.Scan(src)
78 | }
79 |
--------------------------------------------------------------------------------
/vendor/github.com/satori/go.uuid/uuid.go:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2013-2018 by Maxim Bublis
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining
4 | // a copy of this software and associated documentation files (the
5 | // "Software"), to deal in the Software without restriction, including
6 | // without limitation the rights to use, copy, modify, merge, publish,
7 | // distribute, sublicense, and/or sell copies of the Software, and to
8 | // permit persons to whom the Software is furnished to do so, subject to
9 | // the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be
12 | // included in all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
22 | // Package uuid provides implementation of Universally Unique Identifier (UUID).
23 | // Supported versions are 1, 3, 4 and 5 (as specified in RFC 4122) and
24 | // version 2 (as specified in DCE 1.1).
25 | package uuid
26 |
27 | import (
28 | "bytes"
29 | "encoding/hex"
30 | )
31 |
32 | // Size of a UUID in bytes.
33 | const Size = 16
34 |
35 | // UUID representation compliant with specification
36 | // described in RFC 4122.
37 | type UUID [Size]byte
38 |
39 | // UUID versions
40 | const (
41 | _ byte = iota
42 | V1
43 | V2
44 | V3
45 | V4
46 | V5
47 | )
48 |
49 | // UUID layout variants.
50 | const (
51 | VariantNCS byte = iota
52 | VariantRFC4122
53 | VariantMicrosoft
54 | VariantFuture
55 | )
56 |
57 | // UUID DCE domains.
58 | const (
59 | DomainPerson = iota
60 | DomainGroup
61 | DomainOrg
62 | )
63 |
64 | // String parse helpers.
65 | var (
66 | urnPrefix = []byte("urn:uuid:")
67 | byteGroups = []int{8, 4, 4, 4, 12}
68 | )
69 |
70 | // Nil is special form of UUID that is specified to have all
71 | // 128 bits set to zero.
72 | var Nil = UUID{}
73 |
74 | // Predefined namespace UUIDs.
75 | var (
76 | NamespaceDNS = Must(FromString("6ba7b810-9dad-11d1-80b4-00c04fd430c8"))
77 | NamespaceURL = Must(FromString("6ba7b811-9dad-11d1-80b4-00c04fd430c8"))
78 | NamespaceOID = Must(FromString("6ba7b812-9dad-11d1-80b4-00c04fd430c8"))
79 | NamespaceX500 = Must(FromString("6ba7b814-9dad-11d1-80b4-00c04fd430c8"))
80 | )
81 |
82 | // Equal returns true if u1 and u2 equals, otherwise returns false.
83 | func Equal(u1 UUID, u2 UUID) bool {
84 | return bytes.Equal(u1[:], u2[:])
85 | }
86 |
87 | // Version returns algorithm version used to generate UUID.
88 | func (u UUID) Version() byte {
89 | return u[6] >> 4
90 | }
91 |
92 | // Variant returns UUID layout variant.
93 | func (u UUID) Variant() byte {
94 | switch {
95 | case (u[8] >> 7) == 0x00:
96 | return VariantNCS
97 | case (u[8] >> 6) == 0x02:
98 | return VariantRFC4122
99 | case (u[8] >> 5) == 0x06:
100 | return VariantMicrosoft
101 | case (u[8] >> 5) == 0x07:
102 | fallthrough
103 | default:
104 | return VariantFuture
105 | }
106 | }
107 |
108 | // Bytes returns bytes slice representation of UUID.
109 | func (u UUID) Bytes() []byte {
110 | return u[:]
111 | }
112 |
113 | // Returns canonical string representation of UUID:
114 | // xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.
115 | func (u UUID) String() string {
116 | buf := make([]byte, 36)
117 |
118 | hex.Encode(buf[0:8], u[0:4])
119 | buf[8] = '-'
120 | hex.Encode(buf[9:13], u[4:6])
121 | buf[13] = '-'
122 | hex.Encode(buf[14:18], u[6:8])
123 | buf[18] = '-'
124 | hex.Encode(buf[19:23], u[8:10])
125 | buf[23] = '-'
126 | hex.Encode(buf[24:], u[10:])
127 |
128 | return string(buf)
129 | }
130 |
131 | // SetVersion sets version bits.
132 | func (u *UUID) SetVersion(v byte) {
133 | u[6] = (u[6] & 0x0f) | (v << 4)
134 | }
135 |
136 | // SetVariant sets variant bits.
137 | func (u *UUID) SetVariant(v byte) {
138 | switch v {
139 | case VariantNCS:
140 | u[8] = (u[8]&(0xff>>1) | (0x00 << 7))
141 | case VariantRFC4122:
142 | u[8] = (u[8]&(0xff>>2) | (0x02 << 6))
143 | case VariantMicrosoft:
144 | u[8] = (u[8]&(0xff>>3) | (0x06 << 5))
145 | case VariantFuture:
146 | fallthrough
147 | default:
148 | u[8] = (u[8]&(0xff>>3) | (0x07 << 5))
149 | }
150 | }
151 |
152 | // Must is a helper that wraps a call to a function returning (UUID, error)
153 | // and panics if the error is non-nil. It is intended for use in variable
154 | // initializations such as
155 | // var packageUUID = uuid.Must(uuid.FromString("123e4567-e89b-12d3-a456-426655440000"));
156 | func Must(u UUID, err error) UUID {
157 | if err != nil {
158 | panic(err)
159 | }
160 | return u
161 | }
162 |
--------------------------------------------------------------------------------
/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/argon2/blake2b.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 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 argon2
6 |
7 | import (
8 | "encoding/binary"
9 | "hash"
10 |
11 | "golang.org/x/crypto/blake2b"
12 | )
13 |
14 | // blake2bHash computes an arbitrary long hash value of in
15 | // and writes the hash to out.
16 | func blake2bHash(out []byte, in []byte) {
17 | var b2 hash.Hash
18 | if n := len(out); n < blake2b.Size {
19 | b2, _ = blake2b.New(n, nil)
20 | } else {
21 | b2, _ = blake2b.New512(nil)
22 | }
23 |
24 | var buffer [blake2b.Size]byte
25 | binary.LittleEndian.PutUint32(buffer[:4], uint32(len(out)))
26 | b2.Write(buffer[:4])
27 | b2.Write(in)
28 |
29 | if len(out) <= blake2b.Size {
30 | b2.Sum(out[:0])
31 | return
32 | }
33 |
34 | outLen := len(out)
35 | b2.Sum(buffer[:0])
36 | b2.Reset()
37 | copy(out, buffer[:32])
38 | out = out[32:]
39 | for len(out) > blake2b.Size {
40 | b2.Write(buffer[:])
41 | b2.Sum(buffer[:0])
42 | copy(out, buffer[:32])
43 | out = out[32:]
44 | b2.Reset()
45 | }
46 |
47 | if outLen%blake2b.Size > 0 { // outLen > 64
48 | r := ((outLen + 31) / 32) - 2 // ⌈τ /32⌉-2
49 | b2, _ = blake2b.New(outLen-32*r, nil)
50 | }
51 | b2.Write(buffer[:])
52 | b2.Sum(out[:0])
53 | }
54 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/crypto/argon2/blamka_amd64.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 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 | //go:build amd64 && gc && !purego
6 | // +build amd64,gc,!purego
7 |
8 | package argon2
9 |
10 | import "golang.org/x/sys/cpu"
11 |
12 | func init() {
13 | useSSE4 = cpu.X86.HasSSE41
14 | }
15 |
16 | //go:noescape
17 | func mixBlocksSSE2(out, a, b, c *block)
18 |
19 | //go:noescape
20 | func xorBlocksSSE2(out, a, b, c *block)
21 |
22 | //go:noescape
23 | func blamkaSSE4(b *block)
24 |
25 | func processBlockSSE(out, in1, in2 *block, xor bool) {
26 | var t block
27 | mixBlocksSSE2(&t, in1, in2, &t)
28 | if useSSE4 {
29 | blamkaSSE4(&t)
30 | } else {
31 | for i := 0; i < blockLength; i += 16 {
32 | blamkaGeneric(
33 | &t[i+0], &t[i+1], &t[i+2], &t[i+3],
34 | &t[i+4], &t[i+5], &t[i+6], &t[i+7],
35 | &t[i+8], &t[i+9], &t[i+10], &t[i+11],
36 | &t[i+12], &t[i+13], &t[i+14], &t[i+15],
37 | )
38 | }
39 | for i := 0; i < blockLength/8; i += 2 {
40 | blamkaGeneric(
41 | &t[i], &t[i+1], &t[16+i], &t[16+i+1],
42 | &t[32+i], &t[32+i+1], &t[48+i], &t[48+i+1],
43 | &t[64+i], &t[64+i+1], &t[80+i], &t[80+i+1],
44 | &t[96+i], &t[96+i+1], &t[112+i], &t[112+i+1],
45 | )
46 | }
47 | }
48 | if xor {
49 | xorBlocksSSE2(out, in1, in2, &t)
50 | } else {
51 | mixBlocksSSE2(out, in1, in2, &t)
52 | }
53 | }
54 |
55 | func processBlock(out, in1, in2 *block) {
56 | processBlockSSE(out, in1, in2, false)
57 | }
58 |
59 | func processBlockXOR(out, in1, in2 *block) {
60 | processBlockSSE(out, in1, in2, true)
61 | }
62 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/crypto/argon2/blamka_amd64.s:
--------------------------------------------------------------------------------
1 | // Copyright 2017 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 | //go:build amd64 && gc && !purego
6 | // +build amd64,gc,!purego
7 |
8 | #include "textflag.h"
9 |
10 | DATA ·c40<>+0x00(SB)/8, $0x0201000706050403
11 | DATA ·c40<>+0x08(SB)/8, $0x0a09080f0e0d0c0b
12 | GLOBL ·c40<>(SB), (NOPTR+RODATA), $16
13 |
14 | DATA ·c48<>+0x00(SB)/8, $0x0100070605040302
15 | DATA ·c48<>+0x08(SB)/8, $0x09080f0e0d0c0b0a
16 | GLOBL ·c48<>(SB), (NOPTR+RODATA), $16
17 |
18 | #define SHUFFLE(v2, v3, v4, v5, v6, v7, t1, t2) \
19 | MOVO v4, t1; \
20 | MOVO v5, v4; \
21 | MOVO t1, v5; \
22 | MOVO v6, t1; \
23 | PUNPCKLQDQ v6, t2; \
24 | PUNPCKHQDQ v7, v6; \
25 | PUNPCKHQDQ t2, v6; \
26 | PUNPCKLQDQ v7, t2; \
27 | MOVO t1, v7; \
28 | MOVO v2, t1; \
29 | PUNPCKHQDQ t2, v7; \
30 | PUNPCKLQDQ v3, t2; \
31 | PUNPCKHQDQ t2, v2; \
32 | PUNPCKLQDQ t1, t2; \
33 | PUNPCKHQDQ t2, v3
34 |
35 | #define SHUFFLE_INV(v2, v3, v4, v5, v6, v7, t1, t2) \
36 | MOVO v4, t1; \
37 | MOVO v5, v4; \
38 | MOVO t1, v5; \
39 | MOVO v2, t1; \
40 | PUNPCKLQDQ v2, t2; \
41 | PUNPCKHQDQ v3, v2; \
42 | PUNPCKHQDQ t2, v2; \
43 | PUNPCKLQDQ v3, t2; \
44 | MOVO t1, v3; \
45 | MOVO v6, t1; \
46 | PUNPCKHQDQ t2, v3; \
47 | PUNPCKLQDQ v7, t2; \
48 | PUNPCKHQDQ t2, v6; \
49 | PUNPCKLQDQ t1, t2; \
50 | PUNPCKHQDQ t2, v7
51 |
52 | #define HALF_ROUND(v0, v1, v2, v3, v4, v5, v6, v7, t0, c40, c48) \
53 | MOVO v0, t0; \
54 | PMULULQ v2, t0; \
55 | PADDQ v2, v0; \
56 | PADDQ t0, v0; \
57 | PADDQ t0, v0; \
58 | PXOR v0, v6; \
59 | PSHUFD $0xB1, v6, v6; \
60 | MOVO v4, t0; \
61 | PMULULQ v6, t0; \
62 | PADDQ v6, v4; \
63 | PADDQ t0, v4; \
64 | PADDQ t0, v4; \
65 | PXOR v4, v2; \
66 | PSHUFB c40, v2; \
67 | MOVO v0, t0; \
68 | PMULULQ v2, t0; \
69 | PADDQ v2, v0; \
70 | PADDQ t0, v0; \
71 | PADDQ t0, v0; \
72 | PXOR v0, v6; \
73 | PSHUFB c48, v6; \
74 | MOVO v4, t0; \
75 | PMULULQ v6, t0; \
76 | PADDQ v6, v4; \
77 | PADDQ t0, v4; \
78 | PADDQ t0, v4; \
79 | PXOR v4, v2; \
80 | MOVO v2, t0; \
81 | PADDQ v2, t0; \
82 | PSRLQ $63, v2; \
83 | PXOR t0, v2; \
84 | MOVO v1, t0; \
85 | PMULULQ v3, t0; \
86 | PADDQ v3, v1; \
87 | PADDQ t0, v1; \
88 | PADDQ t0, v1; \
89 | PXOR v1, v7; \
90 | PSHUFD $0xB1, v7, v7; \
91 | MOVO v5, t0; \
92 | PMULULQ v7, t0; \
93 | PADDQ v7, v5; \
94 | PADDQ t0, v5; \
95 | PADDQ t0, v5; \
96 | PXOR v5, v3; \
97 | PSHUFB c40, v3; \
98 | MOVO v1, t0; \
99 | PMULULQ v3, t0; \
100 | PADDQ v3, v1; \
101 | PADDQ t0, v1; \
102 | PADDQ t0, v1; \
103 | PXOR v1, v7; \
104 | PSHUFB c48, v7; \
105 | MOVO v5, t0; \
106 | PMULULQ v7, t0; \
107 | PADDQ v7, v5; \
108 | PADDQ t0, v5; \
109 | PADDQ t0, v5; \
110 | PXOR v5, v3; \
111 | MOVO v3, t0; \
112 | PADDQ v3, t0; \
113 | PSRLQ $63, v3; \
114 | PXOR t0, v3
115 |
116 | #define LOAD_MSG_0(block, off) \
117 | MOVOU 8*(off+0)(block), X0; \
118 | MOVOU 8*(off+2)(block), X1; \
119 | MOVOU 8*(off+4)(block), X2; \
120 | MOVOU 8*(off+6)(block), X3; \
121 | MOVOU 8*(off+8)(block), X4; \
122 | MOVOU 8*(off+10)(block), X5; \
123 | MOVOU 8*(off+12)(block), X6; \
124 | MOVOU 8*(off+14)(block), X7
125 |
126 | #define STORE_MSG_0(block, off) \
127 | MOVOU X0, 8*(off+0)(block); \
128 | MOVOU X1, 8*(off+2)(block); \
129 | MOVOU X2, 8*(off+4)(block); \
130 | MOVOU X3, 8*(off+6)(block); \
131 | MOVOU X4, 8*(off+8)(block); \
132 | MOVOU X5, 8*(off+10)(block); \
133 | MOVOU X6, 8*(off+12)(block); \
134 | MOVOU X7, 8*(off+14)(block)
135 |
136 | #define LOAD_MSG_1(block, off) \
137 | MOVOU 8*off+0*8(block), X0; \
138 | MOVOU 8*off+16*8(block), X1; \
139 | MOVOU 8*off+32*8(block), X2; \
140 | MOVOU 8*off+48*8(block), X3; \
141 | MOVOU 8*off+64*8(block), X4; \
142 | MOVOU 8*off+80*8(block), X5; \
143 | MOVOU 8*off+96*8(block), X6; \
144 | MOVOU 8*off+112*8(block), X7
145 |
146 | #define STORE_MSG_1(block, off) \
147 | MOVOU X0, 8*off+0*8(block); \
148 | MOVOU X1, 8*off+16*8(block); \
149 | MOVOU X2, 8*off+32*8(block); \
150 | MOVOU X3, 8*off+48*8(block); \
151 | MOVOU X4, 8*off+64*8(block); \
152 | MOVOU X5, 8*off+80*8(block); \
153 | MOVOU X6, 8*off+96*8(block); \
154 | MOVOU X7, 8*off+112*8(block)
155 |
156 | #define BLAMKA_ROUND_0(block, off, t0, t1, c40, c48) \
157 | LOAD_MSG_0(block, off); \
158 | HALF_ROUND(X0, X1, X2, X3, X4, X5, X6, X7, t0, c40, c48); \
159 | SHUFFLE(X2, X3, X4, X5, X6, X7, t0, t1); \
160 | HALF_ROUND(X0, X1, X2, X3, X4, X5, X6, X7, t0, c40, c48); \
161 | SHUFFLE_INV(X2, X3, X4, X5, X6, X7, t0, t1); \
162 | STORE_MSG_0(block, off)
163 |
164 | #define BLAMKA_ROUND_1(block, off, t0, t1, c40, c48) \
165 | LOAD_MSG_1(block, off); \
166 | HALF_ROUND(X0, X1, X2, X3, X4, X5, X6, X7, t0, c40, c48); \
167 | SHUFFLE(X2, X3, X4, X5, X6, X7, t0, t1); \
168 | HALF_ROUND(X0, X1, X2, X3, X4, X5, X6, X7, t0, c40, c48); \
169 | SHUFFLE_INV(X2, X3, X4, X5, X6, X7, t0, t1); \
170 | STORE_MSG_1(block, off)
171 |
172 | // func blamkaSSE4(b *block)
173 | TEXT ·blamkaSSE4(SB), 4, $0-8
174 | MOVQ b+0(FP), AX
175 |
176 | MOVOU ·c40<>(SB), X10
177 | MOVOU ·c48<>(SB), X11
178 |
179 | BLAMKA_ROUND_0(AX, 0, X8, X9, X10, X11)
180 | BLAMKA_ROUND_0(AX, 16, X8, X9, X10, X11)
181 | BLAMKA_ROUND_0(AX, 32, X8, X9, X10, X11)
182 | BLAMKA_ROUND_0(AX, 48, X8, X9, X10, X11)
183 | BLAMKA_ROUND_0(AX, 64, X8, X9, X10, X11)
184 | BLAMKA_ROUND_0(AX, 80, X8, X9, X10, X11)
185 | BLAMKA_ROUND_0(AX, 96, X8, X9, X10, X11)
186 | BLAMKA_ROUND_0(AX, 112, X8, X9, X10, X11)
187 |
188 | BLAMKA_ROUND_1(AX, 0, X8, X9, X10, X11)
189 | BLAMKA_ROUND_1(AX, 2, X8, X9, X10, X11)
190 | BLAMKA_ROUND_1(AX, 4, X8, X9, X10, X11)
191 | BLAMKA_ROUND_1(AX, 6, X8, X9, X10, X11)
192 | BLAMKA_ROUND_1(AX, 8, X8, X9, X10, X11)
193 | BLAMKA_ROUND_1(AX, 10, X8, X9, X10, X11)
194 | BLAMKA_ROUND_1(AX, 12, X8, X9, X10, X11)
195 | BLAMKA_ROUND_1(AX, 14, X8, X9, X10, X11)
196 | RET
197 |
198 | // func mixBlocksSSE2(out, a, b, c *block)
199 | TEXT ·mixBlocksSSE2(SB), 4, $0-32
200 | MOVQ out+0(FP), DX
201 | MOVQ a+8(FP), AX
202 | MOVQ b+16(FP), BX
203 | MOVQ a+24(FP), CX
204 | MOVQ $128, BP
205 |
206 | loop:
207 | MOVOU 0(AX), X0
208 | MOVOU 0(BX), X1
209 | MOVOU 0(CX), X2
210 | PXOR X1, X0
211 | PXOR X2, X0
212 | MOVOU X0, 0(DX)
213 | ADDQ $16, AX
214 | ADDQ $16, BX
215 | ADDQ $16, CX
216 | ADDQ $16, DX
217 | SUBQ $2, BP
218 | JA loop
219 | RET
220 |
221 | // func xorBlocksSSE2(out, a, b, c *block)
222 | TEXT ·xorBlocksSSE2(SB), 4, $0-32
223 | MOVQ out+0(FP), DX
224 | MOVQ a+8(FP), AX
225 | MOVQ b+16(FP), BX
226 | MOVQ a+24(FP), CX
227 | MOVQ $128, BP
228 |
229 | loop:
230 | MOVOU 0(AX), X0
231 | MOVOU 0(BX), X1
232 | MOVOU 0(CX), X2
233 | MOVOU 0(DX), X3
234 | PXOR X1, X0
235 | PXOR X2, X0
236 | PXOR X3, X0
237 | MOVOU X0, 0(DX)
238 | ADDQ $16, AX
239 | ADDQ $16, BX
240 | ADDQ $16, CX
241 | ADDQ $16, DX
242 | SUBQ $2, BP
243 | JA loop
244 | RET
245 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/crypto/argon2/blamka_generic.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 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 argon2
6 |
7 | var useSSE4 bool
8 |
9 | func processBlockGeneric(out, in1, in2 *block, xor bool) {
10 | var t block
11 | for i := range t {
12 | t[i] = in1[i] ^ in2[i]
13 | }
14 | for i := 0; i < blockLength; i += 16 {
15 | blamkaGeneric(
16 | &t[i+0], &t[i+1], &t[i+2], &t[i+3],
17 | &t[i+4], &t[i+5], &t[i+6], &t[i+7],
18 | &t[i+8], &t[i+9], &t[i+10], &t[i+11],
19 | &t[i+12], &t[i+13], &t[i+14], &t[i+15],
20 | )
21 | }
22 | for i := 0; i < blockLength/8; i += 2 {
23 | blamkaGeneric(
24 | &t[i], &t[i+1], &t[16+i], &t[16+i+1],
25 | &t[32+i], &t[32+i+1], &t[48+i], &t[48+i+1],
26 | &t[64+i], &t[64+i+1], &t[80+i], &t[80+i+1],
27 | &t[96+i], &t[96+i+1], &t[112+i], &t[112+i+1],
28 | )
29 | }
30 | if xor {
31 | for i := range t {
32 | out[i] ^= in1[i] ^ in2[i] ^ t[i]
33 | }
34 | } else {
35 | for i := range t {
36 | out[i] = in1[i] ^ in2[i] ^ t[i]
37 | }
38 | }
39 | }
40 |
41 | func blamkaGeneric(t00, t01, t02, t03, t04, t05, t06, t07, t08, t09, t10, t11, t12, t13, t14, t15 *uint64) {
42 | v00, v01, v02, v03 := *t00, *t01, *t02, *t03
43 | v04, v05, v06, v07 := *t04, *t05, *t06, *t07
44 | v08, v09, v10, v11 := *t08, *t09, *t10, *t11
45 | v12, v13, v14, v15 := *t12, *t13, *t14, *t15
46 |
47 | v00 += v04 + 2*uint64(uint32(v00))*uint64(uint32(v04))
48 | v12 ^= v00
49 | v12 = v12>>32 | v12<<32
50 | v08 += v12 + 2*uint64(uint32(v08))*uint64(uint32(v12))
51 | v04 ^= v08
52 | v04 = v04>>24 | v04<<40
53 |
54 | v00 += v04 + 2*uint64(uint32(v00))*uint64(uint32(v04))
55 | v12 ^= v00
56 | v12 = v12>>16 | v12<<48
57 | v08 += v12 + 2*uint64(uint32(v08))*uint64(uint32(v12))
58 | v04 ^= v08
59 | v04 = v04>>63 | v04<<1
60 |
61 | v01 += v05 + 2*uint64(uint32(v01))*uint64(uint32(v05))
62 | v13 ^= v01
63 | v13 = v13>>32 | v13<<32
64 | v09 += v13 + 2*uint64(uint32(v09))*uint64(uint32(v13))
65 | v05 ^= v09
66 | v05 = v05>>24 | v05<<40
67 |
68 | v01 += v05 + 2*uint64(uint32(v01))*uint64(uint32(v05))
69 | v13 ^= v01
70 | v13 = v13>>16 | v13<<48
71 | v09 += v13 + 2*uint64(uint32(v09))*uint64(uint32(v13))
72 | v05 ^= v09
73 | v05 = v05>>63 | v05<<1
74 |
75 | v02 += v06 + 2*uint64(uint32(v02))*uint64(uint32(v06))
76 | v14 ^= v02
77 | v14 = v14>>32 | v14<<32
78 | v10 += v14 + 2*uint64(uint32(v10))*uint64(uint32(v14))
79 | v06 ^= v10
80 | v06 = v06>>24 | v06<<40
81 |
82 | v02 += v06 + 2*uint64(uint32(v02))*uint64(uint32(v06))
83 | v14 ^= v02
84 | v14 = v14>>16 | v14<<48
85 | v10 += v14 + 2*uint64(uint32(v10))*uint64(uint32(v14))
86 | v06 ^= v10
87 | v06 = v06>>63 | v06<<1
88 |
89 | v03 += v07 + 2*uint64(uint32(v03))*uint64(uint32(v07))
90 | v15 ^= v03
91 | v15 = v15>>32 | v15<<32
92 | v11 += v15 + 2*uint64(uint32(v11))*uint64(uint32(v15))
93 | v07 ^= v11
94 | v07 = v07>>24 | v07<<40
95 |
96 | v03 += v07 + 2*uint64(uint32(v03))*uint64(uint32(v07))
97 | v15 ^= v03
98 | v15 = v15>>16 | v15<<48
99 | v11 += v15 + 2*uint64(uint32(v11))*uint64(uint32(v15))
100 | v07 ^= v11
101 | v07 = v07>>63 | v07<<1
102 |
103 | v00 += v05 + 2*uint64(uint32(v00))*uint64(uint32(v05))
104 | v15 ^= v00
105 | v15 = v15>>32 | v15<<32
106 | v10 += v15 + 2*uint64(uint32(v10))*uint64(uint32(v15))
107 | v05 ^= v10
108 | v05 = v05>>24 | v05<<40
109 |
110 | v00 += v05 + 2*uint64(uint32(v00))*uint64(uint32(v05))
111 | v15 ^= v00
112 | v15 = v15>>16 | v15<<48
113 | v10 += v15 + 2*uint64(uint32(v10))*uint64(uint32(v15))
114 | v05 ^= v10
115 | v05 = v05>>63 | v05<<1
116 |
117 | v01 += v06 + 2*uint64(uint32(v01))*uint64(uint32(v06))
118 | v12 ^= v01
119 | v12 = v12>>32 | v12<<32
120 | v11 += v12 + 2*uint64(uint32(v11))*uint64(uint32(v12))
121 | v06 ^= v11
122 | v06 = v06>>24 | v06<<40
123 |
124 | v01 += v06 + 2*uint64(uint32(v01))*uint64(uint32(v06))
125 | v12 ^= v01
126 | v12 = v12>>16 | v12<<48
127 | v11 += v12 + 2*uint64(uint32(v11))*uint64(uint32(v12))
128 | v06 ^= v11
129 | v06 = v06>>63 | v06<<1
130 |
131 | v02 += v07 + 2*uint64(uint32(v02))*uint64(uint32(v07))
132 | v13 ^= v02
133 | v13 = v13>>32 | v13<<32
134 | v08 += v13 + 2*uint64(uint32(v08))*uint64(uint32(v13))
135 | v07 ^= v08
136 | v07 = v07>>24 | v07<<40
137 |
138 | v02 += v07 + 2*uint64(uint32(v02))*uint64(uint32(v07))
139 | v13 ^= v02
140 | v13 = v13>>16 | v13<<48
141 | v08 += v13 + 2*uint64(uint32(v08))*uint64(uint32(v13))
142 | v07 ^= v08
143 | v07 = v07>>63 | v07<<1
144 |
145 | v03 += v04 + 2*uint64(uint32(v03))*uint64(uint32(v04))
146 | v14 ^= v03
147 | v14 = v14>>32 | v14<<32
148 | v09 += v14 + 2*uint64(uint32(v09))*uint64(uint32(v14))
149 | v04 ^= v09
150 | v04 = v04>>24 | v04<<40
151 |
152 | v03 += v04 + 2*uint64(uint32(v03))*uint64(uint32(v04))
153 | v14 ^= v03
154 | v14 = v14>>16 | v14<<48
155 | v09 += v14 + 2*uint64(uint32(v09))*uint64(uint32(v14))
156 | v04 ^= v09
157 | v04 = v04>>63 | v04<<1
158 |
159 | *t00, *t01, *t02, *t03 = v00, v01, v02, v03
160 | *t04, *t05, *t06, *t07 = v04, v05, v06, v07
161 | *t08, *t09, *t10, *t11 = v08, v09, v10, v11
162 | *t12, *t13, *t14, *t15 = v12, v13, v14, v15
163 | }
164 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/crypto/argon2/blamka_ref.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 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 | //go:build !amd64 || purego || !gc
6 | // +build !amd64 purego !gc
7 |
8 | package argon2
9 |
10 | func processBlock(out, in1, in2 *block) {
11 | processBlockGeneric(out, in1, in2, false)
12 | }
13 |
14 | func processBlockXOR(out, in1, in2 *block) {
15 | processBlockGeneric(out, in1, in2, true)
16 | }
17 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/crypto/blake2b/blake2bAVX2_amd64.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 | //go:build go1.7 && amd64 && gc && !purego
6 | // +build go1.7,amd64,gc,!purego
7 |
8 | package blake2b
9 |
10 | import "golang.org/x/sys/cpu"
11 |
12 | func init() {
13 | useAVX2 = cpu.X86.HasAVX2
14 | useAVX = cpu.X86.HasAVX
15 | useSSE4 = cpu.X86.HasSSE41
16 | }
17 |
18 | //go:noescape
19 | func hashBlocksAVX2(h *[8]uint64, c *[2]uint64, flag uint64, blocks []byte)
20 |
21 | //go:noescape
22 | func hashBlocksAVX(h *[8]uint64, c *[2]uint64, flag uint64, blocks []byte)
23 |
24 | //go:noescape
25 | func hashBlocksSSE4(h *[8]uint64, c *[2]uint64, flag uint64, blocks []byte)
26 |
27 | func hashBlocks(h *[8]uint64, c *[2]uint64, flag uint64, blocks []byte) {
28 | switch {
29 | case useAVX2:
30 | hashBlocksAVX2(h, c, flag, blocks)
31 | case useAVX:
32 | hashBlocksAVX(h, c, flag, blocks)
33 | case useSSE4:
34 | hashBlocksSSE4(h, c, flag, blocks)
35 | default:
36 | hashBlocksGeneric(h, c, flag, blocks)
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/crypto/blake2b/blake2b_amd64.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 | //go:build !go1.7 && amd64 && gc && !purego
6 | // +build !go1.7,amd64,gc,!purego
7 |
8 | package blake2b
9 |
10 | import "golang.org/x/sys/cpu"
11 |
12 | func init() {
13 | useSSE4 = cpu.X86.HasSSE41
14 | }
15 |
16 | //go:noescape
17 | func hashBlocksSSE4(h *[8]uint64, c *[2]uint64, flag uint64, blocks []byte)
18 |
19 | func hashBlocks(h *[8]uint64, c *[2]uint64, flag uint64, blocks []byte) {
20 | if useSSE4 {
21 | hashBlocksSSE4(h, c, flag, blocks)
22 | } else {
23 | hashBlocksGeneric(h, c, flag, blocks)
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/crypto/blake2b/blake2b_generic.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 blake2b
6 |
7 | import (
8 | "encoding/binary"
9 | "math/bits"
10 | )
11 |
12 | // the precomputed values for BLAKE2b
13 | // there are 12 16-byte arrays - one for each round
14 | // the entries are calculated from the sigma constants.
15 | var precomputed = [12][16]byte{
16 | {0, 2, 4, 6, 1, 3, 5, 7, 8, 10, 12, 14, 9, 11, 13, 15},
17 | {14, 4, 9, 13, 10, 8, 15, 6, 1, 0, 11, 5, 12, 2, 7, 3},
18 | {11, 12, 5, 15, 8, 0, 2, 13, 10, 3, 7, 9, 14, 6, 1, 4},
19 | {7, 3, 13, 11, 9, 1, 12, 14, 2, 5, 4, 15, 6, 10, 0, 8},
20 | {9, 5, 2, 10, 0, 7, 4, 15, 14, 11, 6, 3, 1, 12, 8, 13},
21 | {2, 6, 0, 8, 12, 10, 11, 3, 4, 7, 15, 1, 13, 5, 14, 9},
22 | {12, 1, 14, 4, 5, 15, 13, 10, 0, 6, 9, 8, 7, 3, 2, 11},
23 | {13, 7, 12, 3, 11, 14, 1, 9, 5, 15, 8, 2, 0, 4, 6, 10},
24 | {6, 14, 11, 0, 15, 9, 3, 8, 12, 13, 1, 10, 2, 7, 4, 5},
25 | {10, 8, 7, 1, 2, 4, 6, 5, 15, 9, 3, 13, 11, 14, 12, 0},
26 | {0, 2, 4, 6, 1, 3, 5, 7, 8, 10, 12, 14, 9, 11, 13, 15}, // equal to the first
27 | {14, 4, 9, 13, 10, 8, 15, 6, 1, 0, 11, 5, 12, 2, 7, 3}, // equal to the second
28 | }
29 |
30 | func hashBlocksGeneric(h *[8]uint64, c *[2]uint64, flag uint64, blocks []byte) {
31 | var m [16]uint64
32 | c0, c1 := c[0], c[1]
33 |
34 | for i := 0; i < len(blocks); {
35 | c0 += BlockSize
36 | if c0 < BlockSize {
37 | c1++
38 | }
39 |
40 | v0, v1, v2, v3, v4, v5, v6, v7 := h[0], h[1], h[2], h[3], h[4], h[5], h[6], h[7]
41 | v8, v9, v10, v11, v12, v13, v14, v15 := iv[0], iv[1], iv[2], iv[3], iv[4], iv[5], iv[6], iv[7]
42 | v12 ^= c0
43 | v13 ^= c1
44 | v14 ^= flag
45 |
46 | for j := range m {
47 | m[j] = binary.LittleEndian.Uint64(blocks[i:])
48 | i += 8
49 | }
50 |
51 | for j := range precomputed {
52 | s := &(precomputed[j])
53 |
54 | v0 += m[s[0]]
55 | v0 += v4
56 | v12 ^= v0
57 | v12 = bits.RotateLeft64(v12, -32)
58 | v8 += v12
59 | v4 ^= v8
60 | v4 = bits.RotateLeft64(v4, -24)
61 | v1 += m[s[1]]
62 | v1 += v5
63 | v13 ^= v1
64 | v13 = bits.RotateLeft64(v13, -32)
65 | v9 += v13
66 | v5 ^= v9
67 | v5 = bits.RotateLeft64(v5, -24)
68 | v2 += m[s[2]]
69 | v2 += v6
70 | v14 ^= v2
71 | v14 = bits.RotateLeft64(v14, -32)
72 | v10 += v14
73 | v6 ^= v10
74 | v6 = bits.RotateLeft64(v6, -24)
75 | v3 += m[s[3]]
76 | v3 += v7
77 | v15 ^= v3
78 | v15 = bits.RotateLeft64(v15, -32)
79 | v11 += v15
80 | v7 ^= v11
81 | v7 = bits.RotateLeft64(v7, -24)
82 |
83 | v0 += m[s[4]]
84 | v0 += v4
85 | v12 ^= v0
86 | v12 = bits.RotateLeft64(v12, -16)
87 | v8 += v12
88 | v4 ^= v8
89 | v4 = bits.RotateLeft64(v4, -63)
90 | v1 += m[s[5]]
91 | v1 += v5
92 | v13 ^= v1
93 | v13 = bits.RotateLeft64(v13, -16)
94 | v9 += v13
95 | v5 ^= v9
96 | v5 = bits.RotateLeft64(v5, -63)
97 | v2 += m[s[6]]
98 | v2 += v6
99 | v14 ^= v2
100 | v14 = bits.RotateLeft64(v14, -16)
101 | v10 += v14
102 | v6 ^= v10
103 | v6 = bits.RotateLeft64(v6, -63)
104 | v3 += m[s[7]]
105 | v3 += v7
106 | v15 ^= v3
107 | v15 = bits.RotateLeft64(v15, -16)
108 | v11 += v15
109 | v7 ^= v11
110 | v7 = bits.RotateLeft64(v7, -63)
111 |
112 | v0 += m[s[8]]
113 | v0 += v5
114 | v15 ^= v0
115 | v15 = bits.RotateLeft64(v15, -32)
116 | v10 += v15
117 | v5 ^= v10
118 | v5 = bits.RotateLeft64(v5, -24)
119 | v1 += m[s[9]]
120 | v1 += v6
121 | v12 ^= v1
122 | v12 = bits.RotateLeft64(v12, -32)
123 | v11 += v12
124 | v6 ^= v11
125 | v6 = bits.RotateLeft64(v6, -24)
126 | v2 += m[s[10]]
127 | v2 += v7
128 | v13 ^= v2
129 | v13 = bits.RotateLeft64(v13, -32)
130 | v8 += v13
131 | v7 ^= v8
132 | v7 = bits.RotateLeft64(v7, -24)
133 | v3 += m[s[11]]
134 | v3 += v4
135 | v14 ^= v3
136 | v14 = bits.RotateLeft64(v14, -32)
137 | v9 += v14
138 | v4 ^= v9
139 | v4 = bits.RotateLeft64(v4, -24)
140 |
141 | v0 += m[s[12]]
142 | v0 += v5
143 | v15 ^= v0
144 | v15 = bits.RotateLeft64(v15, -16)
145 | v10 += v15
146 | v5 ^= v10
147 | v5 = bits.RotateLeft64(v5, -63)
148 | v1 += m[s[13]]
149 | v1 += v6
150 | v12 ^= v1
151 | v12 = bits.RotateLeft64(v12, -16)
152 | v11 += v12
153 | v6 ^= v11
154 | v6 = bits.RotateLeft64(v6, -63)
155 | v2 += m[s[14]]
156 | v2 += v7
157 | v13 ^= v2
158 | v13 = bits.RotateLeft64(v13, -16)
159 | v8 += v13
160 | v7 ^= v8
161 | v7 = bits.RotateLeft64(v7, -63)
162 | v3 += m[s[15]]
163 | v3 += v4
164 | v14 ^= v3
165 | v14 = bits.RotateLeft64(v14, -16)
166 | v9 += v14
167 | v4 ^= v9
168 | v4 = bits.RotateLeft64(v4, -63)
169 |
170 | }
171 |
172 | h[0] ^= v0 ^ v8
173 | h[1] ^= v1 ^ v9
174 | h[2] ^= v2 ^ v10
175 | h[3] ^= v3 ^ v11
176 | h[4] ^= v4 ^ v12
177 | h[5] ^= v5 ^ v13
178 | h[6] ^= v6 ^ v14
179 | h[7] ^= v7 ^ v15
180 | }
181 | c[0], c[1] = c0, c1
182 | }
183 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/crypto/blake2b/blake2b_ref.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 | //go:build !amd64 || purego || !gc
6 | // +build !amd64 purego !gc
7 |
8 | package blake2b
9 |
10 | func hashBlocks(h *[8]uint64, c *[2]uint64, flag uint64, blocks []byte) {
11 | hashBlocksGeneric(h, c, flag, blocks)
12 | }
13 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/crypto/blake2b/blake2x.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 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 blake2b
6 |
7 | import (
8 | "encoding/binary"
9 | "errors"
10 | "io"
11 | )
12 |
13 | // XOF defines the interface to hash functions that
14 | // support arbitrary-length output.
15 | type XOF interface {
16 | // Write absorbs more data into the hash's state. It panics if called
17 | // after Read.
18 | io.Writer
19 |
20 | // Read reads more output from the hash. It returns io.EOF if the limit
21 | // has been reached.
22 | io.Reader
23 |
24 | // Clone returns a copy of the XOF in its current state.
25 | Clone() XOF
26 |
27 | // Reset resets the XOF to its initial state.
28 | Reset()
29 | }
30 |
31 | // OutputLengthUnknown can be used as the size argument to NewXOF to indicate
32 | // the length of the output is not known in advance.
33 | const OutputLengthUnknown = 0
34 |
35 | // magicUnknownOutputLength is a magic value for the output size that indicates
36 | // an unknown number of output bytes.
37 | const magicUnknownOutputLength = (1 << 32) - 1
38 |
39 | // maxOutputLength is the absolute maximum number of bytes to produce when the
40 | // number of output bytes is unknown.
41 | const maxOutputLength = (1 << 32) * 64
42 |
43 | // NewXOF creates a new variable-output-length hash. The hash either produce a
44 | // known number of bytes (1 <= size < 2**32-1), or an unknown number of bytes
45 | // (size == OutputLengthUnknown). In the latter case, an absolute limit of
46 | // 256GiB applies.
47 | //
48 | // A non-nil key turns the hash into a MAC. The key must between
49 | // zero and 32 bytes long.
50 | func NewXOF(size uint32, key []byte) (XOF, error) {
51 | if len(key) > Size {
52 | return nil, errKeySize
53 | }
54 | if size == magicUnknownOutputLength {
55 | // 2^32-1 indicates an unknown number of bytes and thus isn't a
56 | // valid length.
57 | return nil, errors.New("blake2b: XOF length too large")
58 | }
59 | if size == OutputLengthUnknown {
60 | size = magicUnknownOutputLength
61 | }
62 | x := &xof{
63 | d: digest{
64 | size: Size,
65 | keyLen: len(key),
66 | },
67 | length: size,
68 | }
69 | copy(x.d.key[:], key)
70 | x.Reset()
71 | return x, nil
72 | }
73 |
74 | type xof struct {
75 | d digest
76 | length uint32
77 | remaining uint64
78 | cfg, root, block [Size]byte
79 | offset int
80 | nodeOffset uint32
81 | readMode bool
82 | }
83 |
84 | func (x *xof) Write(p []byte) (n int, err error) {
85 | if x.readMode {
86 | panic("blake2b: write to XOF after read")
87 | }
88 | return x.d.Write(p)
89 | }
90 |
91 | func (x *xof) Clone() XOF {
92 | clone := *x
93 | return &clone
94 | }
95 |
96 | func (x *xof) Reset() {
97 | x.cfg[0] = byte(Size)
98 | binary.LittleEndian.PutUint32(x.cfg[4:], uint32(Size)) // leaf length
99 | binary.LittleEndian.PutUint32(x.cfg[12:], x.length) // XOF length
100 | x.cfg[17] = byte(Size) // inner hash size
101 |
102 | x.d.Reset()
103 | x.d.h[1] ^= uint64(x.length) << 32
104 |
105 | x.remaining = uint64(x.length)
106 | if x.remaining == magicUnknownOutputLength {
107 | x.remaining = maxOutputLength
108 | }
109 | x.offset, x.nodeOffset = 0, 0
110 | x.readMode = false
111 | }
112 |
113 | func (x *xof) Read(p []byte) (n int, err error) {
114 | if !x.readMode {
115 | x.d.finalize(&x.root)
116 | x.readMode = true
117 | }
118 |
119 | if x.remaining == 0 {
120 | return 0, io.EOF
121 | }
122 |
123 | n = len(p)
124 | if uint64(n) > x.remaining {
125 | n = int(x.remaining)
126 | p = p[:n]
127 | }
128 |
129 | if x.offset > 0 {
130 | blockRemaining := Size - x.offset
131 | if n < blockRemaining {
132 | x.offset += copy(p, x.block[x.offset:])
133 | x.remaining -= uint64(n)
134 | return
135 | }
136 | copy(p, x.block[x.offset:])
137 | p = p[blockRemaining:]
138 | x.offset = 0
139 | x.remaining -= uint64(blockRemaining)
140 | }
141 |
142 | for len(p) >= Size {
143 | binary.LittleEndian.PutUint32(x.cfg[8:], x.nodeOffset)
144 | x.nodeOffset++
145 |
146 | x.d.initConfig(&x.cfg)
147 | x.d.Write(x.root[:])
148 | x.d.finalize(&x.block)
149 |
150 | copy(p, x.block[:])
151 | p = p[Size:]
152 | x.remaining -= uint64(Size)
153 | }
154 |
155 | if todo := len(p); todo > 0 {
156 | if x.remaining < uint64(Size) {
157 | x.cfg[0] = byte(x.remaining)
158 | }
159 | binary.LittleEndian.PutUint32(x.cfg[8:], x.nodeOffset)
160 | x.nodeOffset++
161 |
162 | x.d.initConfig(&x.cfg)
163 | x.d.Write(x.root[:])
164 | x.d.finalize(&x.block)
165 |
166 | x.offset = copy(p, x.block[:todo])
167 | x.remaining -= uint64(todo)
168 | }
169 | return
170 | }
171 |
172 | func (d *digest) initConfig(cfg *[Size]byte) {
173 | d.offset, d.c[0], d.c[1] = 0, 0, 0
174 | for i := range d.h {
175 | d.h[i] = iv[i] ^ binary.LittleEndian.Uint64(cfg[i*8:])
176 | }
177 | }
178 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/crypto/blake2b/register.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 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 | //go:build go1.9
6 | // +build go1.9
7 |
8 | package blake2b
9 |
10 | import (
11 | "crypto"
12 | "hash"
13 | )
14 |
15 | func init() {
16 | newHash256 := func() hash.Hash {
17 | h, _ := New256(nil)
18 | return h
19 | }
20 | newHash384 := func() hash.Hash {
21 | h, _ := New384(nil)
22 | return h
23 | }
24 |
25 | newHash512 := func() hash.Hash {
26 | h, _ := New512(nil)
27 | return h
28 | }
29 |
30 | crypto.RegisterHash(crypto.BLAKE2b_256, newHash256)
31 | crypto.RegisterHash(crypto.BLAKE2b_384, newHash384)
32 | crypto.RegisterHash(crypto.BLAKE2b_512, newHash512)
33 | }
34 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/crypto/internal/alias/alias.go:
--------------------------------------------------------------------------------
1 | // Copyright 2018 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 | //go:build !purego
6 | // +build !purego
7 |
8 | // Package alias implements memory aliasing tests.
9 | package alias
10 |
11 | import "unsafe"
12 |
13 | // AnyOverlap reports whether x and y share memory at any (not necessarily
14 | // corresponding) index. The memory beyond the slice length is ignored.
15 | func AnyOverlap(x, y []byte) bool {
16 | return len(x) > 0 && len(y) > 0 &&
17 | uintptr(unsafe.Pointer(&x[0])) <= uintptr(unsafe.Pointer(&y[len(y)-1])) &&
18 | uintptr(unsafe.Pointer(&y[0])) <= uintptr(unsafe.Pointer(&x[len(x)-1]))
19 | }
20 |
21 | // InexactOverlap reports whether x and y share memory at any non-corresponding
22 | // index. The memory beyond the slice length is ignored. Note that x and y can
23 | // have different lengths and still not have any inexact overlap.
24 | //
25 | // InexactOverlap can be used to implement the requirements of the crypto/cipher
26 | // AEAD, Block, BlockMode and Stream interfaces.
27 | func InexactOverlap(x, y []byte) bool {
28 | if len(x) == 0 || len(y) == 0 || &x[0] == &y[0] {
29 | return false
30 | }
31 | return AnyOverlap(x, y)
32 | }
33 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/crypto/internal/alias/alias_purego.go:
--------------------------------------------------------------------------------
1 | // Copyright 2018 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 | //go:build purego
6 | // +build purego
7 |
8 | // Package alias implements memory aliasing tests.
9 | package alias
10 |
11 | // This is the Google App Engine standard variant based on reflect
12 | // because the unsafe package and cgo are disallowed.
13 |
14 | import "reflect"
15 |
16 | // AnyOverlap reports whether x and y share memory at any (not necessarily
17 | // corresponding) index. The memory beyond the slice length is ignored.
18 | func AnyOverlap(x, y []byte) bool {
19 | return len(x) > 0 && len(y) > 0 &&
20 | reflect.ValueOf(&x[0]).Pointer() <= reflect.ValueOf(&y[len(y)-1]).Pointer() &&
21 | reflect.ValueOf(&y[0]).Pointer() <= reflect.ValueOf(&x[len(x)-1]).Pointer()
22 | }
23 |
24 | // InexactOverlap reports whether x and y share memory at any non-corresponding
25 | // index. The memory beyond the slice length is ignored. Note that x and y can
26 | // have different lengths and still not have any inexact overlap.
27 | //
28 | // InexactOverlap can be used to implement the requirements of the crypto/cipher
29 | // AEAD, Block, BlockMode and Stream interfaces.
30 | func InexactOverlap(x, y []byte) bool {
31 | if len(x) == 0 || len(y) == 0 || &x[0] == &y[0] {
32 | return false
33 | }
34 | return AnyOverlap(x, y)
35 | }
36 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/crypto/internal/poly1305/bits_compat.go:
--------------------------------------------------------------------------------
1 | // Copyright 2019 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 | //go:build !go1.13
6 | // +build !go1.13
7 |
8 | package poly1305
9 |
10 | // Generic fallbacks for the math/bits intrinsics, copied from
11 | // src/math/bits/bits.go. They were added in Go 1.12, but Add64 and Sum64 had
12 | // variable time fallbacks until Go 1.13.
13 |
14 | func bitsAdd64(x, y, carry uint64) (sum, carryOut uint64) {
15 | sum = x + y + carry
16 | carryOut = ((x & y) | ((x | y) &^ sum)) >> 63
17 | return
18 | }
19 |
20 | func bitsSub64(x, y, borrow uint64) (diff, borrowOut uint64) {
21 | diff = x - y - borrow
22 | borrowOut = ((^x & y) | (^(x ^ y) & diff)) >> 63
23 | return
24 | }
25 |
26 | func bitsMul64(x, y uint64) (hi, lo uint64) {
27 | const mask32 = 1<<32 - 1
28 | x0 := x & mask32
29 | x1 := x >> 32
30 | y0 := y & mask32
31 | y1 := y >> 32
32 | w0 := x0 * y0
33 | t := x1*y0 + w0>>32
34 | w1 := t & mask32
35 | w2 := t >> 32
36 | w1 += x0 * y1
37 | hi = x1*y1 + w2 + w1>>32
38 | lo = x * y
39 | return
40 | }
41 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/crypto/internal/poly1305/bits_go1.13.go:
--------------------------------------------------------------------------------
1 | // Copyright 2019 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 | //go:build go1.13
6 | // +build go1.13
7 |
8 | package poly1305
9 |
10 | import "math/bits"
11 |
12 | func bitsAdd64(x, y, carry uint64) (sum, carryOut uint64) {
13 | return bits.Add64(x, y, carry)
14 | }
15 |
16 | func bitsSub64(x, y, borrow uint64) (diff, borrowOut uint64) {
17 | return bits.Sub64(x, y, borrow)
18 | }
19 |
20 | func bitsMul64(x, y uint64) (hi, lo uint64) {
21 | return bits.Mul64(x, y)
22 | }
23 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/crypto/internal/poly1305/mac_noasm.go:
--------------------------------------------------------------------------------
1 | // Copyright 2018 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 | //go:build (!amd64 && !ppc64le && !s390x) || !gc || purego
6 | // +build !amd64,!ppc64le,!s390x !gc purego
7 |
8 | package poly1305
9 |
10 | type mac struct{ macGeneric }
11 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/crypto/internal/poly1305/poly1305.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 poly1305 implements Poly1305 one-time message authentication code as
6 | // specified in https://cr.yp.to/mac/poly1305-20050329.pdf.
7 | //
8 | // Poly1305 is a fast, one-time authentication function. It is infeasible for an
9 | // attacker to generate an authenticator for a message without the key. However, a
10 | // key must only be used for a single message. Authenticating two different
11 | // messages with the same key allows an attacker to forge authenticators for other
12 | // messages with the same key.
13 | //
14 | // Poly1305 was originally coupled with AES in order to make Poly1305-AES. AES was
15 | // used with a fixed key in order to generate one-time keys from an nonce.
16 | // However, in this package AES isn't used and the one-time key is specified
17 | // directly.
18 | package poly1305
19 |
20 | import "crypto/subtle"
21 |
22 | // TagSize is the size, in bytes, of a poly1305 authenticator.
23 | const TagSize = 16
24 |
25 | // Sum generates an authenticator for msg using a one-time key and puts the
26 | // 16-byte result into out. Authenticating two different messages with the same
27 | // key allows an attacker to forge messages at will.
28 | func Sum(out *[16]byte, m []byte, key *[32]byte) {
29 | h := New(key)
30 | h.Write(m)
31 | h.Sum(out[:0])
32 | }
33 |
34 | // Verify returns true if mac is a valid authenticator for m with the given key.
35 | func Verify(mac *[16]byte, m []byte, key *[32]byte) bool {
36 | var tmp [16]byte
37 | Sum(&tmp, m, key)
38 | return subtle.ConstantTimeCompare(tmp[:], mac[:]) == 1
39 | }
40 |
41 | // New returns a new MAC computing an authentication
42 | // tag of all data written to it with the given key.
43 | // This allows writing the message progressively instead
44 | // of passing it as a single slice. Common users should use
45 | // the Sum function instead.
46 | //
47 | // The key must be unique for each message, as authenticating
48 | // two different messages with the same key allows an attacker
49 | // to forge messages at will.
50 | func New(key *[32]byte) *MAC {
51 | m := &MAC{}
52 | initialize(key, &m.macState)
53 | return m
54 | }
55 |
56 | // MAC is an io.Writer computing an authentication tag
57 | // of the data written to it.
58 | //
59 | // MAC cannot be used like common hash.Hash implementations,
60 | // because using a poly1305 key twice breaks its security.
61 | // Therefore writing data to a running MAC after calling
62 | // Sum or Verify causes it to panic.
63 | type MAC struct {
64 | mac // platform-dependent implementation
65 |
66 | finalized bool
67 | }
68 |
69 | // Size returns the number of bytes Sum will return.
70 | func (h *MAC) Size() int { return TagSize }
71 |
72 | // Write adds more data to the running message authentication code.
73 | // It never returns an error.
74 | //
75 | // It must not be called after the first call of Sum or Verify.
76 | func (h *MAC) Write(p []byte) (n int, err error) {
77 | if h.finalized {
78 | panic("poly1305: write to MAC after Sum or Verify")
79 | }
80 | return h.mac.Write(p)
81 | }
82 |
83 | // Sum computes the authenticator of all data written to the
84 | // message authentication code.
85 | func (h *MAC) Sum(b []byte) []byte {
86 | var mac [TagSize]byte
87 | h.mac.Sum(&mac)
88 | h.finalized = true
89 | return append(b, mac[:]...)
90 | }
91 |
92 | // Verify returns whether the authenticator of all data written to
93 | // the message authentication code matches the expected value.
94 | func (h *MAC) Verify(expected []byte) bool {
95 | var mac [TagSize]byte
96 | h.mac.Sum(&mac)
97 | h.finalized = true
98 | return subtle.ConstantTimeCompare(expected, mac[:]) == 1
99 | }
100 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/crypto/internal/poly1305/sum_amd64.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 | //go:build gc && !purego
6 | // +build gc,!purego
7 |
8 | package poly1305
9 |
10 | //go:noescape
11 | func update(state *macState, msg []byte)
12 |
13 | // mac is a wrapper for macGeneric that redirects calls that would have gone to
14 | // updateGeneric to update.
15 | //
16 | // Its Write and Sum methods are otherwise identical to the macGeneric ones, but
17 | // using function pointers would carry a major performance cost.
18 | type mac struct{ macGeneric }
19 |
20 | func (h *mac) Write(p []byte) (int, error) {
21 | nn := len(p)
22 | if h.offset > 0 {
23 | n := copy(h.buffer[h.offset:], p)
24 | if h.offset+n < TagSize {
25 | h.offset += n
26 | return nn, nil
27 | }
28 | p = p[n:]
29 | h.offset = 0
30 | update(&h.macState, h.buffer[:])
31 | }
32 | if n := len(p) - (len(p) % TagSize); n > 0 {
33 | update(&h.macState, p[:n])
34 | p = p[n:]
35 | }
36 | if len(p) > 0 {
37 | h.offset += copy(h.buffer[h.offset:], p)
38 | }
39 | return nn, nil
40 | }
41 |
42 | func (h *mac) Sum(out *[16]byte) {
43 | state := h.macState
44 | if h.offset > 0 {
45 | update(&state, h.buffer[:h.offset])
46 | }
47 | finalize(out, &state.h, &state.s)
48 | }
49 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/crypto/internal/poly1305/sum_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 | //go:build gc && !purego
6 | // +build gc,!purego
7 |
8 | #include "textflag.h"
9 |
10 | #define POLY1305_ADD(msg, h0, h1, h2) \
11 | ADDQ 0(msg), h0; \
12 | ADCQ 8(msg), h1; \
13 | ADCQ $1, h2; \
14 | LEAQ 16(msg), msg
15 |
16 | #define POLY1305_MUL(h0, h1, h2, r0, r1, t0, t1, t2, t3) \
17 | MOVQ r0, AX; \
18 | MULQ h0; \
19 | MOVQ AX, t0; \
20 | MOVQ DX, t1; \
21 | MOVQ r0, AX; \
22 | MULQ h1; \
23 | ADDQ AX, t1; \
24 | ADCQ $0, DX; \
25 | MOVQ r0, t2; \
26 | IMULQ h2, t2; \
27 | ADDQ DX, t2; \
28 | \
29 | MOVQ r1, AX; \
30 | MULQ h0; \
31 | ADDQ AX, t1; \
32 | ADCQ $0, DX; \
33 | MOVQ DX, h0; \
34 | MOVQ r1, t3; \
35 | IMULQ h2, t3; \
36 | MOVQ r1, AX; \
37 | MULQ h1; \
38 | ADDQ AX, t2; \
39 | ADCQ DX, t3; \
40 | ADDQ h0, t2; \
41 | ADCQ $0, t3; \
42 | \
43 | MOVQ t0, h0; \
44 | MOVQ t1, h1; \
45 | MOVQ t2, h2; \
46 | ANDQ $3, h2; \
47 | MOVQ t2, t0; \
48 | ANDQ $0xFFFFFFFFFFFFFFFC, t0; \
49 | ADDQ t0, h0; \
50 | ADCQ t3, h1; \
51 | ADCQ $0, h2; \
52 | SHRQ $2, t3, t2; \
53 | SHRQ $2, t3; \
54 | ADDQ t2, h0; \
55 | ADCQ t3, h1; \
56 | ADCQ $0, h2
57 |
58 | // func update(state *[7]uint64, msg []byte)
59 | TEXT ·update(SB), $0-32
60 | MOVQ state+0(FP), DI
61 | MOVQ msg_base+8(FP), SI
62 | MOVQ msg_len+16(FP), R15
63 |
64 | MOVQ 0(DI), R8 // h0
65 | MOVQ 8(DI), R9 // h1
66 | MOVQ 16(DI), R10 // h2
67 | MOVQ 24(DI), R11 // r0
68 | MOVQ 32(DI), R12 // r1
69 |
70 | CMPQ R15, $16
71 | JB bytes_between_0_and_15
72 |
73 | loop:
74 | POLY1305_ADD(SI, R8, R9, R10)
75 |
76 | multiply:
77 | POLY1305_MUL(R8, R9, R10, R11, R12, BX, CX, R13, R14)
78 | SUBQ $16, R15
79 | CMPQ R15, $16
80 | JAE loop
81 |
82 | bytes_between_0_and_15:
83 | TESTQ R15, R15
84 | JZ done
85 | MOVQ $1, BX
86 | XORQ CX, CX
87 | XORQ R13, R13
88 | ADDQ R15, SI
89 |
90 | flush_buffer:
91 | SHLQ $8, BX, CX
92 | SHLQ $8, BX
93 | MOVB -1(SI), R13
94 | XORQ R13, BX
95 | DECQ SI
96 | DECQ R15
97 | JNZ flush_buffer
98 |
99 | ADDQ BX, R8
100 | ADCQ CX, R9
101 | ADCQ $0, R10
102 | MOVQ $16, R15
103 | JMP multiply
104 |
105 | done:
106 | MOVQ R8, 0(DI)
107 | MOVQ R9, 8(DI)
108 | MOVQ R10, 16(DI)
109 | RET
110 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/crypto/internal/poly1305/sum_ppc64le.go:
--------------------------------------------------------------------------------
1 | // Copyright 2019 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 | //go:build gc && !purego
6 | // +build gc,!purego
7 |
8 | package poly1305
9 |
10 | //go:noescape
11 | func update(state *macState, msg []byte)
12 |
13 | // mac is a wrapper for macGeneric that redirects calls that would have gone to
14 | // updateGeneric to update.
15 | //
16 | // Its Write and Sum methods are otherwise identical to the macGeneric ones, but
17 | // using function pointers would carry a major performance cost.
18 | type mac struct{ macGeneric }
19 |
20 | func (h *mac) Write(p []byte) (int, error) {
21 | nn := len(p)
22 | if h.offset > 0 {
23 | n := copy(h.buffer[h.offset:], p)
24 | if h.offset+n < TagSize {
25 | h.offset += n
26 | return nn, nil
27 | }
28 | p = p[n:]
29 | h.offset = 0
30 | update(&h.macState, h.buffer[:])
31 | }
32 | if n := len(p) - (len(p) % TagSize); n > 0 {
33 | update(&h.macState, p[:n])
34 | p = p[n:]
35 | }
36 | if len(p) > 0 {
37 | h.offset += copy(h.buffer[h.offset:], p)
38 | }
39 | return nn, nil
40 | }
41 |
42 | func (h *mac) Sum(out *[16]byte) {
43 | state := h.macState
44 | if h.offset > 0 {
45 | update(&state, h.buffer[:h.offset])
46 | }
47 | finalize(out, &state.h, &state.s)
48 | }
49 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/crypto/internal/poly1305/sum_ppc64le.s:
--------------------------------------------------------------------------------
1 | // Copyright 2019 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 | //go:build gc && !purego
6 | // +build gc,!purego
7 |
8 | #include "textflag.h"
9 |
10 | // This was ported from the amd64 implementation.
11 |
12 | #define POLY1305_ADD(msg, h0, h1, h2, t0, t1, t2) \
13 | MOVD (msg), t0; \
14 | MOVD 8(msg), t1; \
15 | MOVD $1, t2; \
16 | ADDC t0, h0, h0; \
17 | ADDE t1, h1, h1; \
18 | ADDE t2, h2; \
19 | ADD $16, msg
20 |
21 | #define POLY1305_MUL(h0, h1, h2, r0, r1, t0, t1, t2, t3, t4, t5) \
22 | MULLD r0, h0, t0; \
23 | MULLD r0, h1, t4; \
24 | MULHDU r0, h0, t1; \
25 | MULHDU r0, h1, t5; \
26 | ADDC t4, t1, t1; \
27 | MULLD r0, h2, t2; \
28 | ADDZE t5; \
29 | MULHDU r1, h0, t4; \
30 | MULLD r1, h0, h0; \
31 | ADD t5, t2, t2; \
32 | ADDC h0, t1, t1; \
33 | MULLD h2, r1, t3; \
34 | ADDZE t4, h0; \
35 | MULHDU r1, h1, t5; \
36 | MULLD r1, h1, t4; \
37 | ADDC t4, t2, t2; \
38 | ADDE t5, t3, t3; \
39 | ADDC h0, t2, t2; \
40 | MOVD $-4, t4; \
41 | MOVD t0, h0; \
42 | MOVD t1, h1; \
43 | ADDZE t3; \
44 | ANDCC $3, t2, h2; \
45 | AND t2, t4, t0; \
46 | ADDC t0, h0, h0; \
47 | ADDE t3, h1, h1; \
48 | SLD $62, t3, t4; \
49 | SRD $2, t2; \
50 | ADDZE h2; \
51 | OR t4, t2, t2; \
52 | SRD $2, t3; \
53 | ADDC t2, h0, h0; \
54 | ADDE t3, h1, h1; \
55 | ADDZE h2
56 |
57 | DATA ·poly1305Mask<>+0x00(SB)/8, $0x0FFFFFFC0FFFFFFF
58 | DATA ·poly1305Mask<>+0x08(SB)/8, $0x0FFFFFFC0FFFFFFC
59 | GLOBL ·poly1305Mask<>(SB), RODATA, $16
60 |
61 | // func update(state *[7]uint64, msg []byte)
62 | TEXT ·update(SB), $0-32
63 | MOVD state+0(FP), R3
64 | MOVD msg_base+8(FP), R4
65 | MOVD msg_len+16(FP), R5
66 |
67 | MOVD 0(R3), R8 // h0
68 | MOVD 8(R3), R9 // h1
69 | MOVD 16(R3), R10 // h2
70 | MOVD 24(R3), R11 // r0
71 | MOVD 32(R3), R12 // r1
72 |
73 | CMP R5, $16
74 | BLT bytes_between_0_and_15
75 |
76 | loop:
77 | POLY1305_ADD(R4, R8, R9, R10, R20, R21, R22)
78 |
79 | multiply:
80 | POLY1305_MUL(R8, R9, R10, R11, R12, R16, R17, R18, R14, R20, R21)
81 | ADD $-16, R5
82 | CMP R5, $16
83 | BGE loop
84 |
85 | bytes_between_0_and_15:
86 | CMP R5, $0
87 | BEQ done
88 | MOVD $0, R16 // h0
89 | MOVD $0, R17 // h1
90 |
91 | flush_buffer:
92 | CMP R5, $8
93 | BLE just1
94 |
95 | MOVD $8, R21
96 | SUB R21, R5, R21
97 |
98 | // Greater than 8 -- load the rightmost remaining bytes in msg
99 | // and put into R17 (h1)
100 | MOVD (R4)(R21), R17
101 | MOVD $16, R22
102 |
103 | // Find the offset to those bytes
104 | SUB R5, R22, R22
105 | SLD $3, R22
106 |
107 | // Shift to get only the bytes in msg
108 | SRD R22, R17, R17
109 |
110 | // Put 1 at high end
111 | MOVD $1, R23
112 | SLD $3, R21
113 | SLD R21, R23, R23
114 | OR R23, R17, R17
115 |
116 | // Remainder is 8
117 | MOVD $8, R5
118 |
119 | just1:
120 | CMP R5, $8
121 | BLT less8
122 |
123 | // Exactly 8
124 | MOVD (R4), R16
125 |
126 | CMP R17, $0
127 |
128 | // Check if we've already set R17; if not
129 | // set 1 to indicate end of msg.
130 | BNE carry
131 | MOVD $1, R17
132 | BR carry
133 |
134 | less8:
135 | MOVD $0, R16 // h0
136 | MOVD $0, R22 // shift count
137 | CMP R5, $4
138 | BLT less4
139 | MOVWZ (R4), R16
140 | ADD $4, R4
141 | ADD $-4, R5
142 | MOVD $32, R22
143 |
144 | less4:
145 | CMP R5, $2
146 | BLT less2
147 | MOVHZ (R4), R21
148 | SLD R22, R21, R21
149 | OR R16, R21, R16
150 | ADD $16, R22
151 | ADD $-2, R5
152 | ADD $2, R4
153 |
154 | less2:
155 | CMP R5, $0
156 | BEQ insert1
157 | MOVBZ (R4), R21
158 | SLD R22, R21, R21
159 | OR R16, R21, R16
160 | ADD $8, R22
161 |
162 | insert1:
163 | // Insert 1 at end of msg
164 | MOVD $1, R21
165 | SLD R22, R21, R21
166 | OR R16, R21, R16
167 |
168 | carry:
169 | // Add new values to h0, h1, h2
170 | ADDC R16, R8
171 | ADDE R17, R9
172 | ADDZE R10, R10
173 | MOVD $16, R5
174 | ADD R5, R4
175 | BR multiply
176 |
177 | done:
178 | // Save h0, h1, h2 in state
179 | MOVD R8, 0(R3)
180 | MOVD R9, 8(R3)
181 | MOVD R10, 16(R3)
182 | RET
183 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/crypto/internal/poly1305/sum_s390x.go:
--------------------------------------------------------------------------------
1 | // Copyright 2018 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 | //go:build gc && !purego
6 | // +build gc,!purego
7 |
8 | package poly1305
9 |
10 | import (
11 | "golang.org/x/sys/cpu"
12 | )
13 |
14 | // updateVX is an assembly implementation of Poly1305 that uses vector
15 | // instructions. It must only be called if the vector facility (vx) is
16 | // available.
17 | //
18 | //go:noescape
19 | func updateVX(state *macState, msg []byte)
20 |
21 | // mac is a replacement for macGeneric that uses a larger buffer and redirects
22 | // calls that would have gone to updateGeneric to updateVX if the vector
23 | // facility is installed.
24 | //
25 | // A larger buffer is required for good performance because the vector
26 | // implementation has a higher fixed cost per call than the generic
27 | // implementation.
28 | type mac struct {
29 | macState
30 |
31 | buffer [16 * TagSize]byte // size must be a multiple of block size (16)
32 | offset int
33 | }
34 |
35 | func (h *mac) Write(p []byte) (int, error) {
36 | nn := len(p)
37 | if h.offset > 0 {
38 | n := copy(h.buffer[h.offset:], p)
39 | if h.offset+n < len(h.buffer) {
40 | h.offset += n
41 | return nn, nil
42 | }
43 | p = p[n:]
44 | h.offset = 0
45 | if cpu.S390X.HasVX {
46 | updateVX(&h.macState, h.buffer[:])
47 | } else {
48 | updateGeneric(&h.macState, h.buffer[:])
49 | }
50 | }
51 |
52 | tail := len(p) % len(h.buffer) // number of bytes to copy into buffer
53 | body := len(p) - tail // number of bytes to process now
54 | if body > 0 {
55 | if cpu.S390X.HasVX {
56 | updateVX(&h.macState, p[:body])
57 | } else {
58 | updateGeneric(&h.macState, p[:body])
59 | }
60 | }
61 | h.offset = copy(h.buffer[:], p[body:]) // copy tail bytes - can be 0
62 | return nn, nil
63 | }
64 |
65 | func (h *mac) Sum(out *[TagSize]byte) {
66 | state := h.macState
67 | remainder := h.buffer[:h.offset]
68 |
69 | // Use the generic implementation if we have 2 or fewer blocks left
70 | // to sum. The vector implementation has a higher startup time.
71 | if cpu.S390X.HasVX && len(remainder) > 2*TagSize {
72 | updateVX(&state, remainder)
73 | } else if len(remainder) > 0 {
74 | updateGeneric(&state, remainder)
75 | }
76 | finalize(out, &state.h, &state.s)
77 | }
78 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/crypto/nacl/secretbox/secretbox.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 | /*
6 | Package secretbox encrypts and authenticates small messages.
7 |
8 | Secretbox uses XSalsa20 and Poly1305 to encrypt and authenticate messages with
9 | secret-key cryptography. The length of messages is not hidden.
10 |
11 | It is the caller's responsibility to ensure the uniqueness of nonces—for
12 | example, by using nonce 1 for the first message, nonce 2 for the second
13 | message, etc. Nonces are long enough that randomly generated nonces have
14 | negligible risk of collision.
15 |
16 | Messages should be small because:
17 |
18 | 1. The whole message needs to be held in memory to be processed.
19 |
20 | 2. Using large messages pressures implementations on small machines to decrypt
21 | and process plaintext before authenticating it. This is very dangerous, and
22 | this API does not allow it, but a protocol that uses excessive message sizes
23 | might present some implementations with no other choice.
24 |
25 | 3. Fixed overheads will be sufficiently amortised by messages as small as 8KB.
26 |
27 | 4. Performance may be improved by working with messages that fit into data caches.
28 |
29 | Thus large amounts of data should be chunked so that each message is small.
30 | (Each message still needs a unique nonce.) If in doubt, 16KB is a reasonable
31 | chunk size.
32 |
33 | This package is interoperable with NaCl: https://nacl.cr.yp.to/secretbox.html.
34 | */
35 | package secretbox // import "golang.org/x/crypto/nacl/secretbox"
36 |
37 | import (
38 | "golang.org/x/crypto/internal/alias"
39 | "golang.org/x/crypto/internal/poly1305"
40 | "golang.org/x/crypto/salsa20/salsa"
41 | )
42 |
43 | // Overhead is the number of bytes of overhead when boxing a message.
44 | const Overhead = poly1305.TagSize
45 |
46 | // setup produces a sub-key and Salsa20 counter given a nonce and key.
47 | func setup(subKey *[32]byte, counter *[16]byte, nonce *[24]byte, key *[32]byte) {
48 | // We use XSalsa20 for encryption so first we need to generate a
49 | // key and nonce with HSalsa20.
50 | var hNonce [16]byte
51 | copy(hNonce[:], nonce[:])
52 | salsa.HSalsa20(subKey, &hNonce, key, &salsa.Sigma)
53 |
54 | // The final 8 bytes of the original nonce form the new nonce.
55 | copy(counter[:], nonce[16:])
56 | }
57 |
58 | // sliceForAppend takes a slice and a requested number of bytes. It returns a
59 | // slice with the contents of the given slice followed by that many bytes and a
60 | // second slice that aliases into it and contains only the extra bytes. If the
61 | // original slice has sufficient capacity then no allocation is performed.
62 | func sliceForAppend(in []byte, n int) (head, tail []byte) {
63 | if total := len(in) + n; cap(in) >= total {
64 | head = in[:total]
65 | } else {
66 | head = make([]byte, total)
67 | copy(head, in)
68 | }
69 | tail = head[len(in):]
70 | return
71 | }
72 |
73 | // Seal appends an encrypted and authenticated copy of message to out, which
74 | // must not overlap message. The key and nonce pair must be unique for each
75 | // distinct message and the output will be Overhead bytes longer than message.
76 | func Seal(out, message []byte, nonce *[24]byte, key *[32]byte) []byte {
77 | var subKey [32]byte
78 | var counter [16]byte
79 | setup(&subKey, &counter, nonce, key)
80 |
81 | // The Poly1305 key is generated by encrypting 32 bytes of zeros. Since
82 | // Salsa20 works with 64-byte blocks, we also generate 32 bytes of
83 | // keystream as a side effect.
84 | var firstBlock [64]byte
85 | salsa.XORKeyStream(firstBlock[:], firstBlock[:], &counter, &subKey)
86 |
87 | var poly1305Key [32]byte
88 | copy(poly1305Key[:], firstBlock[:])
89 |
90 | ret, out := sliceForAppend(out, len(message)+poly1305.TagSize)
91 | if alias.AnyOverlap(out, message) {
92 | panic("nacl: invalid buffer overlap")
93 | }
94 |
95 | // We XOR up to 32 bytes of message with the keystream generated from
96 | // the first block.
97 | firstMessageBlock := message
98 | if len(firstMessageBlock) > 32 {
99 | firstMessageBlock = firstMessageBlock[:32]
100 | }
101 |
102 | tagOut := out
103 | out = out[poly1305.TagSize:]
104 | for i, x := range firstMessageBlock {
105 | out[i] = firstBlock[32+i] ^ x
106 | }
107 | message = message[len(firstMessageBlock):]
108 | ciphertext := out
109 | out = out[len(firstMessageBlock):]
110 |
111 | // Now encrypt the rest.
112 | counter[8] = 1
113 | salsa.XORKeyStream(out, message, &counter, &subKey)
114 |
115 | var tag [poly1305.TagSize]byte
116 | poly1305.Sum(&tag, ciphertext, &poly1305Key)
117 | copy(tagOut, tag[:])
118 |
119 | return ret
120 | }
121 |
122 | // Open authenticates and decrypts a box produced by Seal and appends the
123 | // message to out, which must not overlap box. The output will be Overhead
124 | // bytes smaller than box.
125 | func Open(out, box []byte, nonce *[24]byte, key *[32]byte) ([]byte, bool) {
126 | if len(box) < Overhead {
127 | return nil, false
128 | }
129 |
130 | var subKey [32]byte
131 | var counter [16]byte
132 | setup(&subKey, &counter, nonce, key)
133 |
134 | // The Poly1305 key is generated by encrypting 32 bytes of zeros. Since
135 | // Salsa20 works with 64-byte blocks, we also generate 32 bytes of
136 | // keystream as a side effect.
137 | var firstBlock [64]byte
138 | salsa.XORKeyStream(firstBlock[:], firstBlock[:], &counter, &subKey)
139 |
140 | var poly1305Key [32]byte
141 | copy(poly1305Key[:], firstBlock[:])
142 | var tag [poly1305.TagSize]byte
143 | copy(tag[:], box)
144 |
145 | if !poly1305.Verify(&tag, box[poly1305.TagSize:], &poly1305Key) {
146 | return nil, false
147 | }
148 |
149 | ret, out := sliceForAppend(out, len(box)-Overhead)
150 | if alias.AnyOverlap(out, box) {
151 | panic("nacl: invalid buffer overlap")
152 | }
153 |
154 | // We XOR up to 32 bytes of box with the keystream generated from
155 | // the first block.
156 | box = box[Overhead:]
157 | firstMessageBlock := box
158 | if len(firstMessageBlock) > 32 {
159 | firstMessageBlock = firstMessageBlock[:32]
160 | }
161 | for i, x := range firstMessageBlock {
162 | out[i] = firstBlock[32+i] ^ x
163 | }
164 |
165 | box = box[len(firstMessageBlock):]
166 | out = out[len(firstMessageBlock):]
167 |
168 | // Now decrypt the rest.
169 | counter[8] = 1
170 | salsa.XORKeyStream(out, box, &counter, &subKey)
171 |
172 | return ret, true
173 | }
174 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/crypto/salsa20/salsa/hsalsa20.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 salsa provides low-level access to functions in the Salsa family.
6 | package salsa // import "golang.org/x/crypto/salsa20/salsa"
7 |
8 | import "math/bits"
9 |
10 | // Sigma is the Salsa20 constant for 256-bit keys.
11 | var Sigma = [16]byte{'e', 'x', 'p', 'a', 'n', 'd', ' ', '3', '2', '-', 'b', 'y', 't', 'e', ' ', 'k'}
12 |
13 | // HSalsa20 applies the HSalsa20 core function to a 16-byte input in, 32-byte
14 | // key k, and 16-byte constant c, and puts the result into the 32-byte array
15 | // out.
16 | func HSalsa20(out *[32]byte, in *[16]byte, k *[32]byte, c *[16]byte) {
17 | x0 := uint32(c[0]) | uint32(c[1])<<8 | uint32(c[2])<<16 | uint32(c[3])<<24
18 | x1 := uint32(k[0]) | uint32(k[1])<<8 | uint32(k[2])<<16 | uint32(k[3])<<24
19 | x2 := uint32(k[4]) | uint32(k[5])<<8 | uint32(k[6])<<16 | uint32(k[7])<<24
20 | x3 := uint32(k[8]) | uint32(k[9])<<8 | uint32(k[10])<<16 | uint32(k[11])<<24
21 | x4 := uint32(k[12]) | uint32(k[13])<<8 | uint32(k[14])<<16 | uint32(k[15])<<24
22 | x5 := uint32(c[4]) | uint32(c[5])<<8 | uint32(c[6])<<16 | uint32(c[7])<<24
23 | x6 := uint32(in[0]) | uint32(in[1])<<8 | uint32(in[2])<<16 | uint32(in[3])<<24
24 | x7 := uint32(in[4]) | uint32(in[5])<<8 | uint32(in[6])<<16 | uint32(in[7])<<24
25 | x8 := uint32(in[8]) | uint32(in[9])<<8 | uint32(in[10])<<16 | uint32(in[11])<<24
26 | x9 := uint32(in[12]) | uint32(in[13])<<8 | uint32(in[14])<<16 | uint32(in[15])<<24
27 | x10 := uint32(c[8]) | uint32(c[9])<<8 | uint32(c[10])<<16 | uint32(c[11])<<24
28 | x11 := uint32(k[16]) | uint32(k[17])<<8 | uint32(k[18])<<16 | uint32(k[19])<<24
29 | x12 := uint32(k[20]) | uint32(k[21])<<8 | uint32(k[22])<<16 | uint32(k[23])<<24
30 | x13 := uint32(k[24]) | uint32(k[25])<<8 | uint32(k[26])<<16 | uint32(k[27])<<24
31 | x14 := uint32(k[28]) | uint32(k[29])<<8 | uint32(k[30])<<16 | uint32(k[31])<<24
32 | x15 := uint32(c[12]) | uint32(c[13])<<8 | uint32(c[14])<<16 | uint32(c[15])<<24
33 |
34 | for i := 0; i < 20; i += 2 {
35 | u := x0 + x12
36 | x4 ^= bits.RotateLeft32(u, 7)
37 | u = x4 + x0
38 | x8 ^= bits.RotateLeft32(u, 9)
39 | u = x8 + x4
40 | x12 ^= bits.RotateLeft32(u, 13)
41 | u = x12 + x8
42 | x0 ^= bits.RotateLeft32(u, 18)
43 |
44 | u = x5 + x1
45 | x9 ^= bits.RotateLeft32(u, 7)
46 | u = x9 + x5
47 | x13 ^= bits.RotateLeft32(u, 9)
48 | u = x13 + x9
49 | x1 ^= bits.RotateLeft32(u, 13)
50 | u = x1 + x13
51 | x5 ^= bits.RotateLeft32(u, 18)
52 |
53 | u = x10 + x6
54 | x14 ^= bits.RotateLeft32(u, 7)
55 | u = x14 + x10
56 | x2 ^= bits.RotateLeft32(u, 9)
57 | u = x2 + x14
58 | x6 ^= bits.RotateLeft32(u, 13)
59 | u = x6 + x2
60 | x10 ^= bits.RotateLeft32(u, 18)
61 |
62 | u = x15 + x11
63 | x3 ^= bits.RotateLeft32(u, 7)
64 | u = x3 + x15
65 | x7 ^= bits.RotateLeft32(u, 9)
66 | u = x7 + x3
67 | x11 ^= bits.RotateLeft32(u, 13)
68 | u = x11 + x7
69 | x15 ^= bits.RotateLeft32(u, 18)
70 |
71 | u = x0 + x3
72 | x1 ^= bits.RotateLeft32(u, 7)
73 | u = x1 + x0
74 | x2 ^= bits.RotateLeft32(u, 9)
75 | u = x2 + x1
76 | x3 ^= bits.RotateLeft32(u, 13)
77 | u = x3 + x2
78 | x0 ^= bits.RotateLeft32(u, 18)
79 |
80 | u = x5 + x4
81 | x6 ^= bits.RotateLeft32(u, 7)
82 | u = x6 + x5
83 | x7 ^= bits.RotateLeft32(u, 9)
84 | u = x7 + x6
85 | x4 ^= bits.RotateLeft32(u, 13)
86 | u = x4 + x7
87 | x5 ^= bits.RotateLeft32(u, 18)
88 |
89 | u = x10 + x9
90 | x11 ^= bits.RotateLeft32(u, 7)
91 | u = x11 + x10
92 | x8 ^= bits.RotateLeft32(u, 9)
93 | u = x8 + x11
94 | x9 ^= bits.RotateLeft32(u, 13)
95 | u = x9 + x8
96 | x10 ^= bits.RotateLeft32(u, 18)
97 |
98 | u = x15 + x14
99 | x12 ^= bits.RotateLeft32(u, 7)
100 | u = x12 + x15
101 | x13 ^= bits.RotateLeft32(u, 9)
102 | u = x13 + x12
103 | x14 ^= bits.RotateLeft32(u, 13)
104 | u = x14 + x13
105 | x15 ^= bits.RotateLeft32(u, 18)
106 | }
107 | out[0] = byte(x0)
108 | out[1] = byte(x0 >> 8)
109 | out[2] = byte(x0 >> 16)
110 | out[3] = byte(x0 >> 24)
111 |
112 | out[4] = byte(x5)
113 | out[5] = byte(x5 >> 8)
114 | out[6] = byte(x5 >> 16)
115 | out[7] = byte(x5 >> 24)
116 |
117 | out[8] = byte(x10)
118 | out[9] = byte(x10 >> 8)
119 | out[10] = byte(x10 >> 16)
120 | out[11] = byte(x10 >> 24)
121 |
122 | out[12] = byte(x15)
123 | out[13] = byte(x15 >> 8)
124 | out[14] = byte(x15 >> 16)
125 | out[15] = byte(x15 >> 24)
126 |
127 | out[16] = byte(x6)
128 | out[17] = byte(x6 >> 8)
129 | out[18] = byte(x6 >> 16)
130 | out[19] = byte(x6 >> 24)
131 |
132 | out[20] = byte(x7)
133 | out[21] = byte(x7 >> 8)
134 | out[22] = byte(x7 >> 16)
135 | out[23] = byte(x7 >> 24)
136 |
137 | out[24] = byte(x8)
138 | out[25] = byte(x8 >> 8)
139 | out[26] = byte(x8 >> 16)
140 | out[27] = byte(x8 >> 24)
141 |
142 | out[28] = byte(x9)
143 | out[29] = byte(x9 >> 8)
144 | out[30] = byte(x9 >> 16)
145 | out[31] = byte(x9 >> 24)
146 | }
147 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/crypto/salsa20/salsa/salsa208.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 salsa
6 |
7 | import "math/bits"
8 |
9 | // Core208 applies the Salsa20/8 core function to the 64-byte array in and puts
10 | // the result into the 64-byte array out. The input and output may be the same array.
11 | func Core208(out *[64]byte, in *[64]byte) {
12 | j0 := uint32(in[0]) | uint32(in[1])<<8 | uint32(in[2])<<16 | uint32(in[3])<<24
13 | j1 := uint32(in[4]) | uint32(in[5])<<8 | uint32(in[6])<<16 | uint32(in[7])<<24
14 | j2 := uint32(in[8]) | uint32(in[9])<<8 | uint32(in[10])<<16 | uint32(in[11])<<24
15 | j3 := uint32(in[12]) | uint32(in[13])<<8 | uint32(in[14])<<16 | uint32(in[15])<<24
16 | j4 := uint32(in[16]) | uint32(in[17])<<8 | uint32(in[18])<<16 | uint32(in[19])<<24
17 | j5 := uint32(in[20]) | uint32(in[21])<<8 | uint32(in[22])<<16 | uint32(in[23])<<24
18 | j6 := uint32(in[24]) | uint32(in[25])<<8 | uint32(in[26])<<16 | uint32(in[27])<<24
19 | j7 := uint32(in[28]) | uint32(in[29])<<8 | uint32(in[30])<<16 | uint32(in[31])<<24
20 | j8 := uint32(in[32]) | uint32(in[33])<<8 | uint32(in[34])<<16 | uint32(in[35])<<24
21 | j9 := uint32(in[36]) | uint32(in[37])<<8 | uint32(in[38])<<16 | uint32(in[39])<<24
22 | j10 := uint32(in[40]) | uint32(in[41])<<8 | uint32(in[42])<<16 | uint32(in[43])<<24
23 | j11 := uint32(in[44]) | uint32(in[45])<<8 | uint32(in[46])<<16 | uint32(in[47])<<24
24 | j12 := uint32(in[48]) | uint32(in[49])<<8 | uint32(in[50])<<16 | uint32(in[51])<<24
25 | j13 := uint32(in[52]) | uint32(in[53])<<8 | uint32(in[54])<<16 | uint32(in[55])<<24
26 | j14 := uint32(in[56]) | uint32(in[57])<<8 | uint32(in[58])<<16 | uint32(in[59])<<24
27 | j15 := uint32(in[60]) | uint32(in[61])<<8 | uint32(in[62])<<16 | uint32(in[63])<<24
28 |
29 | x0, x1, x2, x3, x4, x5, x6, x7, x8 := j0, j1, j2, j3, j4, j5, j6, j7, j8
30 | x9, x10, x11, x12, x13, x14, x15 := j9, j10, j11, j12, j13, j14, j15
31 |
32 | for i := 0; i < 8; i += 2 {
33 | u := x0 + x12
34 | x4 ^= bits.RotateLeft32(u, 7)
35 | u = x4 + x0
36 | x8 ^= bits.RotateLeft32(u, 9)
37 | u = x8 + x4
38 | x12 ^= bits.RotateLeft32(u, 13)
39 | u = x12 + x8
40 | x0 ^= bits.RotateLeft32(u, 18)
41 |
42 | u = x5 + x1
43 | x9 ^= bits.RotateLeft32(u, 7)
44 | u = x9 + x5
45 | x13 ^= bits.RotateLeft32(u, 9)
46 | u = x13 + x9
47 | x1 ^= bits.RotateLeft32(u, 13)
48 | u = x1 + x13
49 | x5 ^= bits.RotateLeft32(u, 18)
50 |
51 | u = x10 + x6
52 | x14 ^= bits.RotateLeft32(u, 7)
53 | u = x14 + x10
54 | x2 ^= bits.RotateLeft32(u, 9)
55 | u = x2 + x14
56 | x6 ^= bits.RotateLeft32(u, 13)
57 | u = x6 + x2
58 | x10 ^= bits.RotateLeft32(u, 18)
59 |
60 | u = x15 + x11
61 | x3 ^= bits.RotateLeft32(u, 7)
62 | u = x3 + x15
63 | x7 ^= bits.RotateLeft32(u, 9)
64 | u = x7 + x3
65 | x11 ^= bits.RotateLeft32(u, 13)
66 | u = x11 + x7
67 | x15 ^= bits.RotateLeft32(u, 18)
68 |
69 | u = x0 + x3
70 | x1 ^= bits.RotateLeft32(u, 7)
71 | u = x1 + x0
72 | x2 ^= bits.RotateLeft32(u, 9)
73 | u = x2 + x1
74 | x3 ^= bits.RotateLeft32(u, 13)
75 | u = x3 + x2
76 | x0 ^= bits.RotateLeft32(u, 18)
77 |
78 | u = x5 + x4
79 | x6 ^= bits.RotateLeft32(u, 7)
80 | u = x6 + x5
81 | x7 ^= bits.RotateLeft32(u, 9)
82 | u = x7 + x6
83 | x4 ^= bits.RotateLeft32(u, 13)
84 | u = x4 + x7
85 | x5 ^= bits.RotateLeft32(u, 18)
86 |
87 | u = x10 + x9
88 | x11 ^= bits.RotateLeft32(u, 7)
89 | u = x11 + x10
90 | x8 ^= bits.RotateLeft32(u, 9)
91 | u = x8 + x11
92 | x9 ^= bits.RotateLeft32(u, 13)
93 | u = x9 + x8
94 | x10 ^= bits.RotateLeft32(u, 18)
95 |
96 | u = x15 + x14
97 | x12 ^= bits.RotateLeft32(u, 7)
98 | u = x12 + x15
99 | x13 ^= bits.RotateLeft32(u, 9)
100 | u = x13 + x12
101 | x14 ^= bits.RotateLeft32(u, 13)
102 | u = x14 + x13
103 | x15 ^= bits.RotateLeft32(u, 18)
104 | }
105 | x0 += j0
106 | x1 += j1
107 | x2 += j2
108 | x3 += j3
109 | x4 += j4
110 | x5 += j5
111 | x6 += j6
112 | x7 += j7
113 | x8 += j8
114 | x9 += j9
115 | x10 += j10
116 | x11 += j11
117 | x12 += j12
118 | x13 += j13
119 | x14 += j14
120 | x15 += j15
121 |
122 | out[0] = byte(x0)
123 | out[1] = byte(x0 >> 8)
124 | out[2] = byte(x0 >> 16)
125 | out[3] = byte(x0 >> 24)
126 |
127 | out[4] = byte(x1)
128 | out[5] = byte(x1 >> 8)
129 | out[6] = byte(x1 >> 16)
130 | out[7] = byte(x1 >> 24)
131 |
132 | out[8] = byte(x2)
133 | out[9] = byte(x2 >> 8)
134 | out[10] = byte(x2 >> 16)
135 | out[11] = byte(x2 >> 24)
136 |
137 | out[12] = byte(x3)
138 | out[13] = byte(x3 >> 8)
139 | out[14] = byte(x3 >> 16)
140 | out[15] = byte(x3 >> 24)
141 |
142 | out[16] = byte(x4)
143 | out[17] = byte(x4 >> 8)
144 | out[18] = byte(x4 >> 16)
145 | out[19] = byte(x4 >> 24)
146 |
147 | out[20] = byte(x5)
148 | out[21] = byte(x5 >> 8)
149 | out[22] = byte(x5 >> 16)
150 | out[23] = byte(x5 >> 24)
151 |
152 | out[24] = byte(x6)
153 | out[25] = byte(x6 >> 8)
154 | out[26] = byte(x6 >> 16)
155 | out[27] = byte(x6 >> 24)
156 |
157 | out[28] = byte(x7)
158 | out[29] = byte(x7 >> 8)
159 | out[30] = byte(x7 >> 16)
160 | out[31] = byte(x7 >> 24)
161 |
162 | out[32] = byte(x8)
163 | out[33] = byte(x8 >> 8)
164 | out[34] = byte(x8 >> 16)
165 | out[35] = byte(x8 >> 24)
166 |
167 | out[36] = byte(x9)
168 | out[37] = byte(x9 >> 8)
169 | out[38] = byte(x9 >> 16)
170 | out[39] = byte(x9 >> 24)
171 |
172 | out[40] = byte(x10)
173 | out[41] = byte(x10 >> 8)
174 | out[42] = byte(x10 >> 16)
175 | out[43] = byte(x10 >> 24)
176 |
177 | out[44] = byte(x11)
178 | out[45] = byte(x11 >> 8)
179 | out[46] = byte(x11 >> 16)
180 | out[47] = byte(x11 >> 24)
181 |
182 | out[48] = byte(x12)
183 | out[49] = byte(x12 >> 8)
184 | out[50] = byte(x12 >> 16)
185 | out[51] = byte(x12 >> 24)
186 |
187 | out[52] = byte(x13)
188 | out[53] = byte(x13 >> 8)
189 | out[54] = byte(x13 >> 16)
190 | out[55] = byte(x13 >> 24)
191 |
192 | out[56] = byte(x14)
193 | out[57] = byte(x14 >> 8)
194 | out[58] = byte(x14 >> 16)
195 | out[59] = byte(x14 >> 24)
196 |
197 | out[60] = byte(x15)
198 | out[61] = byte(x15 >> 8)
199 | out[62] = byte(x15 >> 16)
200 | out[63] = byte(x15 >> 24)
201 | }
202 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/crypto/salsa20/salsa/salsa20_amd64.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 | //go:build amd64 && !purego && gc
6 | // +build amd64,!purego,gc
7 |
8 | package salsa
9 |
10 | //go:noescape
11 |
12 | // salsa2020XORKeyStream is implemented in salsa20_amd64.s.
13 | func salsa2020XORKeyStream(out, in *byte, n uint64, nonce, key *byte)
14 |
15 | // XORKeyStream crypts bytes from in to out using the given key and counters.
16 | // In and out must overlap entirely or not at all. Counter
17 | // contains the raw salsa20 counter bytes (both nonce and block counter).
18 | func XORKeyStream(out, in []byte, counter *[16]byte, key *[32]byte) {
19 | if len(in) == 0 {
20 | return
21 | }
22 | _ = out[len(in)-1]
23 | salsa2020XORKeyStream(&out[0], &in[0], uint64(len(in)), &counter[0], &key[0])
24 | }
25 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/crypto/salsa20/salsa/salsa20_noasm.go:
--------------------------------------------------------------------------------
1 | // Copyright 2019 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 | //go:build !amd64 || purego || !gc
6 | // +build !amd64 purego !gc
7 |
8 | package salsa
9 |
10 | // XORKeyStream crypts bytes from in to out using the given key and counters.
11 | // In and out must overlap entirely or not at all. Counter
12 | // contains the raw salsa20 counter bytes (both nonce and block counter).
13 | func XORKeyStream(out, in []byte, counter *[16]byte, key *[32]byte) {
14 | genericXORKeyStream(out, in, counter, key)
15 | }
16 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/crypto/salsa20/salsa/salsa20_ref.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 salsa
6 |
7 | import "math/bits"
8 |
9 | const rounds = 20
10 |
11 | // core applies the Salsa20 core function to 16-byte input in, 32-byte key k,
12 | // and 16-byte constant c, and puts the result into 64-byte array out.
13 | func core(out *[64]byte, in *[16]byte, k *[32]byte, c *[16]byte) {
14 | j0 := uint32(c[0]) | uint32(c[1])<<8 | uint32(c[2])<<16 | uint32(c[3])<<24
15 | j1 := uint32(k[0]) | uint32(k[1])<<8 | uint32(k[2])<<16 | uint32(k[3])<<24
16 | j2 := uint32(k[4]) | uint32(k[5])<<8 | uint32(k[6])<<16 | uint32(k[7])<<24
17 | j3 := uint32(k[8]) | uint32(k[9])<<8 | uint32(k[10])<<16 | uint32(k[11])<<24
18 | j4 := uint32(k[12]) | uint32(k[13])<<8 | uint32(k[14])<<16 | uint32(k[15])<<24
19 | j5 := uint32(c[4]) | uint32(c[5])<<8 | uint32(c[6])<<16 | uint32(c[7])<<24
20 | j6 := uint32(in[0]) | uint32(in[1])<<8 | uint32(in[2])<<16 | uint32(in[3])<<24
21 | j7 := uint32(in[4]) | uint32(in[5])<<8 | uint32(in[6])<<16 | uint32(in[7])<<24
22 | j8 := uint32(in[8]) | uint32(in[9])<<8 | uint32(in[10])<<16 | uint32(in[11])<<24
23 | j9 := uint32(in[12]) | uint32(in[13])<<8 | uint32(in[14])<<16 | uint32(in[15])<<24
24 | j10 := uint32(c[8]) | uint32(c[9])<<8 | uint32(c[10])<<16 | uint32(c[11])<<24
25 | j11 := uint32(k[16]) | uint32(k[17])<<8 | uint32(k[18])<<16 | uint32(k[19])<<24
26 | j12 := uint32(k[20]) | uint32(k[21])<<8 | uint32(k[22])<<16 | uint32(k[23])<<24
27 | j13 := uint32(k[24]) | uint32(k[25])<<8 | uint32(k[26])<<16 | uint32(k[27])<<24
28 | j14 := uint32(k[28]) | uint32(k[29])<<8 | uint32(k[30])<<16 | uint32(k[31])<<24
29 | j15 := uint32(c[12]) | uint32(c[13])<<8 | uint32(c[14])<<16 | uint32(c[15])<<24
30 |
31 | x0, x1, x2, x3, x4, x5, x6, x7, x8 := j0, j1, j2, j3, j4, j5, j6, j7, j8
32 | x9, x10, x11, x12, x13, x14, x15 := j9, j10, j11, j12, j13, j14, j15
33 |
34 | for i := 0; i < rounds; i += 2 {
35 | u := x0 + x12
36 | x4 ^= bits.RotateLeft32(u, 7)
37 | u = x4 + x0
38 | x8 ^= bits.RotateLeft32(u, 9)
39 | u = x8 + x4
40 | x12 ^= bits.RotateLeft32(u, 13)
41 | u = x12 + x8
42 | x0 ^= bits.RotateLeft32(u, 18)
43 |
44 | u = x5 + x1
45 | x9 ^= bits.RotateLeft32(u, 7)
46 | u = x9 + x5
47 | x13 ^= bits.RotateLeft32(u, 9)
48 | u = x13 + x9
49 | x1 ^= bits.RotateLeft32(u, 13)
50 | u = x1 + x13
51 | x5 ^= bits.RotateLeft32(u, 18)
52 |
53 | u = x10 + x6
54 | x14 ^= bits.RotateLeft32(u, 7)
55 | u = x14 + x10
56 | x2 ^= bits.RotateLeft32(u, 9)
57 | u = x2 + x14
58 | x6 ^= bits.RotateLeft32(u, 13)
59 | u = x6 + x2
60 | x10 ^= bits.RotateLeft32(u, 18)
61 |
62 | u = x15 + x11
63 | x3 ^= bits.RotateLeft32(u, 7)
64 | u = x3 + x15
65 | x7 ^= bits.RotateLeft32(u, 9)
66 | u = x7 + x3
67 | x11 ^= bits.RotateLeft32(u, 13)
68 | u = x11 + x7
69 | x15 ^= bits.RotateLeft32(u, 18)
70 |
71 | u = x0 + x3
72 | x1 ^= bits.RotateLeft32(u, 7)
73 | u = x1 + x0
74 | x2 ^= bits.RotateLeft32(u, 9)
75 | u = x2 + x1
76 | x3 ^= bits.RotateLeft32(u, 13)
77 | u = x3 + x2
78 | x0 ^= bits.RotateLeft32(u, 18)
79 |
80 | u = x5 + x4
81 | x6 ^= bits.RotateLeft32(u, 7)
82 | u = x6 + x5
83 | x7 ^= bits.RotateLeft32(u, 9)
84 | u = x7 + x6
85 | x4 ^= bits.RotateLeft32(u, 13)
86 | u = x4 + x7
87 | x5 ^= bits.RotateLeft32(u, 18)
88 |
89 | u = x10 + x9
90 | x11 ^= bits.RotateLeft32(u, 7)
91 | u = x11 + x10
92 | x8 ^= bits.RotateLeft32(u, 9)
93 | u = x8 + x11
94 | x9 ^= bits.RotateLeft32(u, 13)
95 | u = x9 + x8
96 | x10 ^= bits.RotateLeft32(u, 18)
97 |
98 | u = x15 + x14
99 | x12 ^= bits.RotateLeft32(u, 7)
100 | u = x12 + x15
101 | x13 ^= bits.RotateLeft32(u, 9)
102 | u = x13 + x12
103 | x14 ^= bits.RotateLeft32(u, 13)
104 | u = x14 + x13
105 | x15 ^= bits.RotateLeft32(u, 18)
106 | }
107 | x0 += j0
108 | x1 += j1
109 | x2 += j2
110 | x3 += j3
111 | x4 += j4
112 | x5 += j5
113 | x6 += j6
114 | x7 += j7
115 | x8 += j8
116 | x9 += j9
117 | x10 += j10
118 | x11 += j11
119 | x12 += j12
120 | x13 += j13
121 | x14 += j14
122 | x15 += j15
123 |
124 | out[0] = byte(x0)
125 | out[1] = byte(x0 >> 8)
126 | out[2] = byte(x0 >> 16)
127 | out[3] = byte(x0 >> 24)
128 |
129 | out[4] = byte(x1)
130 | out[5] = byte(x1 >> 8)
131 | out[6] = byte(x1 >> 16)
132 | out[7] = byte(x1 >> 24)
133 |
134 | out[8] = byte(x2)
135 | out[9] = byte(x2 >> 8)
136 | out[10] = byte(x2 >> 16)
137 | out[11] = byte(x2 >> 24)
138 |
139 | out[12] = byte(x3)
140 | out[13] = byte(x3 >> 8)
141 | out[14] = byte(x3 >> 16)
142 | out[15] = byte(x3 >> 24)
143 |
144 | out[16] = byte(x4)
145 | out[17] = byte(x4 >> 8)
146 | out[18] = byte(x4 >> 16)
147 | out[19] = byte(x4 >> 24)
148 |
149 | out[20] = byte(x5)
150 | out[21] = byte(x5 >> 8)
151 | out[22] = byte(x5 >> 16)
152 | out[23] = byte(x5 >> 24)
153 |
154 | out[24] = byte(x6)
155 | out[25] = byte(x6 >> 8)
156 | out[26] = byte(x6 >> 16)
157 | out[27] = byte(x6 >> 24)
158 |
159 | out[28] = byte(x7)
160 | out[29] = byte(x7 >> 8)
161 | out[30] = byte(x7 >> 16)
162 | out[31] = byte(x7 >> 24)
163 |
164 | out[32] = byte(x8)
165 | out[33] = byte(x8 >> 8)
166 | out[34] = byte(x8 >> 16)
167 | out[35] = byte(x8 >> 24)
168 |
169 | out[36] = byte(x9)
170 | out[37] = byte(x9 >> 8)
171 | out[38] = byte(x9 >> 16)
172 | out[39] = byte(x9 >> 24)
173 |
174 | out[40] = byte(x10)
175 | out[41] = byte(x10 >> 8)
176 | out[42] = byte(x10 >> 16)
177 | out[43] = byte(x10 >> 24)
178 |
179 | out[44] = byte(x11)
180 | out[45] = byte(x11 >> 8)
181 | out[46] = byte(x11 >> 16)
182 | out[47] = byte(x11 >> 24)
183 |
184 | out[48] = byte(x12)
185 | out[49] = byte(x12 >> 8)
186 | out[50] = byte(x12 >> 16)
187 | out[51] = byte(x12 >> 24)
188 |
189 | out[52] = byte(x13)
190 | out[53] = byte(x13 >> 8)
191 | out[54] = byte(x13 >> 16)
192 | out[55] = byte(x13 >> 24)
193 |
194 | out[56] = byte(x14)
195 | out[57] = byte(x14 >> 8)
196 | out[58] = byte(x14 >> 16)
197 | out[59] = byte(x14 >> 24)
198 |
199 | out[60] = byte(x15)
200 | out[61] = byte(x15 >> 8)
201 | out[62] = byte(x15 >> 16)
202 | out[63] = byte(x15 >> 24)
203 | }
204 |
205 | // genericXORKeyStream is the generic implementation of XORKeyStream to be used
206 | // when no assembly implementation is available.
207 | func genericXORKeyStream(out, in []byte, counter *[16]byte, key *[32]byte) {
208 | var block [64]byte
209 | var counterCopy [16]byte
210 | copy(counterCopy[:], counter[:])
211 |
212 | for len(in) >= 64 {
213 | core(&block, &counterCopy, key, &Sigma)
214 | for i, x := range block {
215 | out[i] = in[i] ^ x
216 | }
217 | u := uint32(1)
218 | for i := 8; i < 16; i++ {
219 | u += uint32(counterCopy[i])
220 | counterCopy[i] = byte(u)
221 | u >>= 8
222 | }
223 | in = in[64:]
224 | out = out[64:]
225 | }
226 |
227 | if len(in) > 0 {
228 | core(&block, &counterCopy, key, &Sigma)
229 | for i, v := range in {
230 | out[i] = v ^ block[i]
231 | }
232 | }
233 | }
234 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/sys/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/sys/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/sys/cpu/asm_aix_ppc64.s:
--------------------------------------------------------------------------------
1 | // Copyright 2018 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 | //go:build gc
6 | // +build gc
7 |
8 | #include "textflag.h"
9 |
10 | //
11 | // System calls for ppc64, AIX are implemented in runtime/syscall_aix.go
12 | //
13 |
14 | TEXT ·syscall6(SB),NOSPLIT,$0-88
15 | JMP syscall·syscall6(SB)
16 |
17 | TEXT ·rawSyscall6(SB),NOSPLIT,$0-88
18 | JMP syscall·rawSyscall6(SB)
19 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/sys/cpu/byteorder.go:
--------------------------------------------------------------------------------
1 | // Copyright 2019 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 cpu
6 |
7 | import (
8 | "runtime"
9 | )
10 |
11 | // byteOrder is a subset of encoding/binary.ByteOrder.
12 | type byteOrder interface {
13 | Uint32([]byte) uint32
14 | Uint64([]byte) uint64
15 | }
16 |
17 | type littleEndian struct{}
18 | type bigEndian struct{}
19 |
20 | func (littleEndian) Uint32(b []byte) uint32 {
21 | _ = b[3] // bounds check hint to compiler; see golang.org/issue/14808
22 | return uint32(b[0]) | uint32(b[1])<<8 | uint32(b[2])<<16 | uint32(b[3])<<24
23 | }
24 |
25 | func (littleEndian) Uint64(b []byte) uint64 {
26 | _ = b[7] // bounds check hint to compiler; see golang.org/issue/14808
27 | return uint64(b[0]) | uint64(b[1])<<8 | uint64(b[2])<<16 | uint64(b[3])<<24 |
28 | uint64(b[4])<<32 | uint64(b[5])<<40 | uint64(b[6])<<48 | uint64(b[7])<<56
29 | }
30 |
31 | func (bigEndian) Uint32(b []byte) uint32 {
32 | _ = b[3] // bounds check hint to compiler; see golang.org/issue/14808
33 | return uint32(b[3]) | uint32(b[2])<<8 | uint32(b[1])<<16 | uint32(b[0])<<24
34 | }
35 |
36 | func (bigEndian) Uint64(b []byte) uint64 {
37 | _ = b[7] // bounds check hint to compiler; see golang.org/issue/14808
38 | return uint64(b[7]) | uint64(b[6])<<8 | uint64(b[5])<<16 | uint64(b[4])<<24 |
39 | uint64(b[3])<<32 | uint64(b[2])<<40 | uint64(b[1])<<48 | uint64(b[0])<<56
40 | }
41 |
42 | // hostByteOrder returns littleEndian on little-endian machines and
43 | // bigEndian on big-endian machines.
44 | func hostByteOrder() byteOrder {
45 | switch runtime.GOARCH {
46 | case "386", "amd64", "amd64p32",
47 | "alpha",
48 | "arm", "arm64",
49 | "loong64",
50 | "mipsle", "mips64le", "mips64p32le",
51 | "nios2",
52 | "ppc64le",
53 | "riscv", "riscv64",
54 | "sh":
55 | return littleEndian{}
56 | case "armbe", "arm64be",
57 | "m68k",
58 | "mips", "mips64", "mips64p32",
59 | "ppc", "ppc64",
60 | "s390", "s390x",
61 | "shbe",
62 | "sparc", "sparc64":
63 | return bigEndian{}
64 | }
65 | panic("unknown architecture")
66 | }
67 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/sys/cpu/cpu_aix.go:
--------------------------------------------------------------------------------
1 | // Copyright 2019 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 | //go:build aix
6 | // +build aix
7 |
8 | package cpu
9 |
10 | const (
11 | // getsystemcfg constants
12 | _SC_IMPL = 2
13 | _IMPL_POWER8 = 0x10000
14 | _IMPL_POWER9 = 0x20000
15 | )
16 |
17 | func archInit() {
18 | impl := getsystemcfg(_SC_IMPL)
19 | if impl&_IMPL_POWER8 != 0 {
20 | PPC64.IsPOWER8 = true
21 | }
22 | if impl&_IMPL_POWER9 != 0 {
23 | PPC64.IsPOWER8 = true
24 | PPC64.IsPOWER9 = true
25 | }
26 |
27 | Initialized = true
28 | }
29 |
30 | func getsystemcfg(label int) (n uint64) {
31 | r0, _ := callgetsystemcfg(label)
32 | n = uint64(r0)
33 | return
34 | }
35 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/sys/cpu/cpu_arm.go:
--------------------------------------------------------------------------------
1 | // Copyright 2018 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 cpu
6 |
7 | const cacheLineSize = 32
8 |
9 | // HWCAP/HWCAP2 bits.
10 | // These are specific to Linux.
11 | const (
12 | hwcap_SWP = 1 << 0
13 | hwcap_HALF = 1 << 1
14 | hwcap_THUMB = 1 << 2
15 | hwcap_26BIT = 1 << 3
16 | hwcap_FAST_MULT = 1 << 4
17 | hwcap_FPA = 1 << 5
18 | hwcap_VFP = 1 << 6
19 | hwcap_EDSP = 1 << 7
20 | hwcap_JAVA = 1 << 8
21 | hwcap_IWMMXT = 1 << 9
22 | hwcap_CRUNCH = 1 << 10
23 | hwcap_THUMBEE = 1 << 11
24 | hwcap_NEON = 1 << 12
25 | hwcap_VFPv3 = 1 << 13
26 | hwcap_VFPv3D16 = 1 << 14
27 | hwcap_TLS = 1 << 15
28 | hwcap_VFPv4 = 1 << 16
29 | hwcap_IDIVA = 1 << 17
30 | hwcap_IDIVT = 1 << 18
31 | hwcap_VFPD32 = 1 << 19
32 | hwcap_LPAE = 1 << 20
33 | hwcap_EVTSTRM = 1 << 21
34 |
35 | hwcap2_AES = 1 << 0
36 | hwcap2_PMULL = 1 << 1
37 | hwcap2_SHA1 = 1 << 2
38 | hwcap2_SHA2 = 1 << 3
39 | hwcap2_CRC32 = 1 << 4
40 | )
41 |
42 | func initOptions() {
43 | options = []option{
44 | {Name: "pmull", Feature: &ARM.HasPMULL},
45 | {Name: "sha1", Feature: &ARM.HasSHA1},
46 | {Name: "sha2", Feature: &ARM.HasSHA2},
47 | {Name: "swp", Feature: &ARM.HasSWP},
48 | {Name: "thumb", Feature: &ARM.HasTHUMB},
49 | {Name: "thumbee", Feature: &ARM.HasTHUMBEE},
50 | {Name: "tls", Feature: &ARM.HasTLS},
51 | {Name: "vfp", Feature: &ARM.HasVFP},
52 | {Name: "vfpd32", Feature: &ARM.HasVFPD32},
53 | {Name: "vfpv3", Feature: &ARM.HasVFPv3},
54 | {Name: "vfpv3d16", Feature: &ARM.HasVFPv3D16},
55 | {Name: "vfpv4", Feature: &ARM.HasVFPv4},
56 | {Name: "half", Feature: &ARM.HasHALF},
57 | {Name: "26bit", Feature: &ARM.Has26BIT},
58 | {Name: "fastmul", Feature: &ARM.HasFASTMUL},
59 | {Name: "fpa", Feature: &ARM.HasFPA},
60 | {Name: "edsp", Feature: &ARM.HasEDSP},
61 | {Name: "java", Feature: &ARM.HasJAVA},
62 | {Name: "iwmmxt", Feature: &ARM.HasIWMMXT},
63 | {Name: "crunch", Feature: &ARM.HasCRUNCH},
64 | {Name: "neon", Feature: &ARM.HasNEON},
65 | {Name: "idivt", Feature: &ARM.HasIDIVT},
66 | {Name: "idiva", Feature: &ARM.HasIDIVA},
67 | {Name: "lpae", Feature: &ARM.HasLPAE},
68 | {Name: "evtstrm", Feature: &ARM.HasEVTSTRM},
69 | {Name: "aes", Feature: &ARM.HasAES},
70 | {Name: "crc32", Feature: &ARM.HasCRC32},
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/sys/cpu/cpu_arm64.go:
--------------------------------------------------------------------------------
1 | // Copyright 2019 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 cpu
6 |
7 | import "runtime"
8 |
9 | // cacheLineSize is used to prevent false sharing of cache lines.
10 | // We choose 128 because Apple Silicon, a.k.a. M1, has 128-byte cache line size.
11 | // It doesn't cost much and is much more future-proof.
12 | const cacheLineSize = 128
13 |
14 | func initOptions() {
15 | options = []option{
16 | {Name: "fp", Feature: &ARM64.HasFP},
17 | {Name: "asimd", Feature: &ARM64.HasASIMD},
18 | {Name: "evstrm", Feature: &ARM64.HasEVTSTRM},
19 | {Name: "aes", Feature: &ARM64.HasAES},
20 | {Name: "fphp", Feature: &ARM64.HasFPHP},
21 | {Name: "jscvt", Feature: &ARM64.HasJSCVT},
22 | {Name: "lrcpc", Feature: &ARM64.HasLRCPC},
23 | {Name: "pmull", Feature: &ARM64.HasPMULL},
24 | {Name: "sha1", Feature: &ARM64.HasSHA1},
25 | {Name: "sha2", Feature: &ARM64.HasSHA2},
26 | {Name: "sha3", Feature: &ARM64.HasSHA3},
27 | {Name: "sha512", Feature: &ARM64.HasSHA512},
28 | {Name: "sm3", Feature: &ARM64.HasSM3},
29 | {Name: "sm4", Feature: &ARM64.HasSM4},
30 | {Name: "sve", Feature: &ARM64.HasSVE},
31 | {Name: "crc32", Feature: &ARM64.HasCRC32},
32 | {Name: "atomics", Feature: &ARM64.HasATOMICS},
33 | {Name: "asimdhp", Feature: &ARM64.HasASIMDHP},
34 | {Name: "cpuid", Feature: &ARM64.HasCPUID},
35 | {Name: "asimrdm", Feature: &ARM64.HasASIMDRDM},
36 | {Name: "fcma", Feature: &ARM64.HasFCMA},
37 | {Name: "dcpop", Feature: &ARM64.HasDCPOP},
38 | {Name: "asimddp", Feature: &ARM64.HasASIMDDP},
39 | {Name: "asimdfhm", Feature: &ARM64.HasASIMDFHM},
40 | }
41 | }
42 |
43 | func archInit() {
44 | switch runtime.GOOS {
45 | case "freebsd":
46 | readARM64Registers()
47 | case "linux", "netbsd", "openbsd":
48 | doinit()
49 | default:
50 | // Many platforms don't seem to allow reading these registers.
51 | setMinimalFeatures()
52 | }
53 | }
54 |
55 | // setMinimalFeatures fakes the minimal ARM64 features expected by
56 | // TestARM64minimalFeatures.
57 | func setMinimalFeatures() {
58 | ARM64.HasASIMD = true
59 | ARM64.HasFP = true
60 | }
61 |
62 | func readARM64Registers() {
63 | Initialized = true
64 |
65 | parseARM64SystemRegisters(getisar0(), getisar1(), getpfr0())
66 | }
67 |
68 | func parseARM64SystemRegisters(isar0, isar1, pfr0 uint64) {
69 | // ID_AA64ISAR0_EL1
70 | switch extractBits(isar0, 4, 7) {
71 | case 1:
72 | ARM64.HasAES = true
73 | case 2:
74 | ARM64.HasAES = true
75 | ARM64.HasPMULL = true
76 | }
77 |
78 | switch extractBits(isar0, 8, 11) {
79 | case 1:
80 | ARM64.HasSHA1 = true
81 | }
82 |
83 | switch extractBits(isar0, 12, 15) {
84 | case 1:
85 | ARM64.HasSHA2 = true
86 | case 2:
87 | ARM64.HasSHA2 = true
88 | ARM64.HasSHA512 = true
89 | }
90 |
91 | switch extractBits(isar0, 16, 19) {
92 | case 1:
93 | ARM64.HasCRC32 = true
94 | }
95 |
96 | switch extractBits(isar0, 20, 23) {
97 | case 2:
98 | ARM64.HasATOMICS = true
99 | }
100 |
101 | switch extractBits(isar0, 28, 31) {
102 | case 1:
103 | ARM64.HasASIMDRDM = true
104 | }
105 |
106 | switch extractBits(isar0, 32, 35) {
107 | case 1:
108 | ARM64.HasSHA3 = true
109 | }
110 |
111 | switch extractBits(isar0, 36, 39) {
112 | case 1:
113 | ARM64.HasSM3 = true
114 | }
115 |
116 | switch extractBits(isar0, 40, 43) {
117 | case 1:
118 | ARM64.HasSM4 = true
119 | }
120 |
121 | switch extractBits(isar0, 44, 47) {
122 | case 1:
123 | ARM64.HasASIMDDP = true
124 | }
125 |
126 | // ID_AA64ISAR1_EL1
127 | switch extractBits(isar1, 0, 3) {
128 | case 1:
129 | ARM64.HasDCPOP = true
130 | }
131 |
132 | switch extractBits(isar1, 12, 15) {
133 | case 1:
134 | ARM64.HasJSCVT = true
135 | }
136 |
137 | switch extractBits(isar1, 16, 19) {
138 | case 1:
139 | ARM64.HasFCMA = true
140 | }
141 |
142 | switch extractBits(isar1, 20, 23) {
143 | case 1:
144 | ARM64.HasLRCPC = true
145 | }
146 |
147 | // ID_AA64PFR0_EL1
148 | switch extractBits(pfr0, 16, 19) {
149 | case 0:
150 | ARM64.HasFP = true
151 | case 1:
152 | ARM64.HasFP = true
153 | ARM64.HasFPHP = true
154 | }
155 |
156 | switch extractBits(pfr0, 20, 23) {
157 | case 0:
158 | ARM64.HasASIMD = true
159 | case 1:
160 | ARM64.HasASIMD = true
161 | ARM64.HasASIMDHP = true
162 | }
163 |
164 | switch extractBits(pfr0, 32, 35) {
165 | case 1:
166 | ARM64.HasSVE = true
167 | }
168 | }
169 |
170 | func extractBits(data uint64, start, end uint) uint {
171 | return (uint)(data>>start) & ((1 << (end - start + 1)) - 1)
172 | }
173 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/sys/cpu/cpu_arm64.s:
--------------------------------------------------------------------------------
1 | // Copyright 2019 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 | //go:build gc
6 | // +build gc
7 |
8 | #include "textflag.h"
9 |
10 | // func getisar0() uint64
11 | TEXT ·getisar0(SB),NOSPLIT,$0-8
12 | // get Instruction Set Attributes 0 into x0
13 | // mrs x0, ID_AA64ISAR0_EL1 = d5380600
14 | WORD $0xd5380600
15 | MOVD R0, ret+0(FP)
16 | RET
17 |
18 | // func getisar1() uint64
19 | TEXT ·getisar1(SB),NOSPLIT,$0-8
20 | // get Instruction Set Attributes 1 into x0
21 | // mrs x0, ID_AA64ISAR1_EL1 = d5380620
22 | WORD $0xd5380620
23 | MOVD R0, ret+0(FP)
24 | RET
25 |
26 | // func getpfr0() uint64
27 | TEXT ·getpfr0(SB),NOSPLIT,$0-8
28 | // get Processor Feature Register 0 into x0
29 | // mrs x0, ID_AA64PFR0_EL1 = d5380400
30 | WORD $0xd5380400
31 | MOVD R0, ret+0(FP)
32 | RET
33 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/sys/cpu/cpu_gc_arm64.go:
--------------------------------------------------------------------------------
1 | // Copyright 2019 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 | //go:build gc
6 | // +build gc
7 |
8 | package cpu
9 |
10 | func getisar0() uint64
11 | func getisar1() uint64
12 | func getpfr0() uint64
13 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/sys/cpu/cpu_gc_s390x.go:
--------------------------------------------------------------------------------
1 | // Copyright 2019 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 | //go:build gc
6 | // +build gc
7 |
8 | package cpu
9 |
10 | // haveAsmFunctions reports whether the other functions in this file can
11 | // be safely called.
12 | func haveAsmFunctions() bool { return true }
13 |
14 | // The following feature detection functions are defined in cpu_s390x.s.
15 | // They are likely to be expensive to call so the results should be cached.
16 | func stfle() facilityList
17 | func kmQuery() queryResult
18 | func kmcQuery() queryResult
19 | func kmctrQuery() queryResult
20 | func kmaQuery() queryResult
21 | func kimdQuery() queryResult
22 | func klmdQuery() queryResult
23 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/sys/cpu/cpu_gc_x86.go:
--------------------------------------------------------------------------------
1 | // Copyright 2018 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 | //go:build (386 || amd64 || amd64p32) && gc
6 | // +build 386 amd64 amd64p32
7 | // +build gc
8 |
9 | package cpu
10 |
11 | // cpuid is implemented in cpu_x86.s for gc compiler
12 | // and in cpu_gccgo.c for gccgo.
13 | func cpuid(eaxArg, ecxArg uint32) (eax, ebx, ecx, edx uint32)
14 |
15 | // xgetbv with ecx = 0 is implemented in cpu_x86.s for gc compiler
16 | // and in cpu_gccgo.c for gccgo.
17 | func xgetbv() (eax, edx uint32)
18 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/sys/cpu/cpu_gccgo_arm64.go:
--------------------------------------------------------------------------------
1 | // Copyright 2019 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 | //go:build gccgo
6 | // +build gccgo
7 |
8 | package cpu
9 |
10 | func getisar0() uint64 { return 0 }
11 | func getisar1() uint64 { return 0 }
12 | func getpfr0() uint64 { return 0 }
13 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/sys/cpu/cpu_gccgo_s390x.go:
--------------------------------------------------------------------------------
1 | // Copyright 2019 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 | //go:build gccgo
6 | // +build gccgo
7 |
8 | package cpu
9 |
10 | // haveAsmFunctions reports whether the other functions in this file can
11 | // be safely called.
12 | func haveAsmFunctions() bool { return false }
13 |
14 | // TODO(mundaym): the following feature detection functions are currently
15 | // stubs. See https://golang.org/cl/162887 for how to fix this.
16 | // They are likely to be expensive to call so the results should be cached.
17 | func stfle() facilityList { panic("not implemented for gccgo") }
18 | func kmQuery() queryResult { panic("not implemented for gccgo") }
19 | func kmcQuery() queryResult { panic("not implemented for gccgo") }
20 | func kmctrQuery() queryResult { panic("not implemented for gccgo") }
21 | func kmaQuery() queryResult { panic("not implemented for gccgo") }
22 | func kimdQuery() queryResult { panic("not implemented for gccgo") }
23 | func klmdQuery() queryResult { panic("not implemented for gccgo") }
24 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/sys/cpu/cpu_gccgo_x86.c:
--------------------------------------------------------------------------------
1 | // Copyright 2018 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 | //go:build (386 || amd64 || amd64p32) && gccgo
6 | // +build 386 amd64 amd64p32
7 | // +build gccgo
8 |
9 | #include
10 | #include
11 | #include
12 |
13 | // Need to wrap __get_cpuid_count because it's declared as static.
14 | int
15 | gccgoGetCpuidCount(uint32_t leaf, uint32_t subleaf,
16 | uint32_t *eax, uint32_t *ebx,
17 | uint32_t *ecx, uint32_t *edx)
18 | {
19 | return __get_cpuid_count(leaf, subleaf, eax, ebx, ecx, edx);
20 | }
21 |
22 | #pragma GCC diagnostic ignored "-Wunknown-pragmas"
23 | #pragma GCC push_options
24 | #pragma GCC target("xsave")
25 | #pragma clang attribute push (__attribute__((target("xsave"))), apply_to=function)
26 |
27 | // xgetbv reads the contents of an XCR (Extended Control Register)
28 | // specified in the ECX register into registers EDX:EAX.
29 | // Currently, the only supported value for XCR is 0.
30 | void
31 | gccgoXgetbv(uint32_t *eax, uint32_t *edx)
32 | {
33 | uint64_t v = _xgetbv(0);
34 | *eax = v & 0xffffffff;
35 | *edx = v >> 32;
36 | }
37 |
38 | #pragma clang attribute pop
39 | #pragma GCC pop_options
40 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/sys/cpu/cpu_gccgo_x86.go:
--------------------------------------------------------------------------------
1 | // Copyright 2018 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 | //go:build (386 || amd64 || amd64p32) && gccgo
6 | // +build 386 amd64 amd64p32
7 | // +build gccgo
8 |
9 | package cpu
10 |
11 | //extern gccgoGetCpuidCount
12 | func gccgoGetCpuidCount(eaxArg, ecxArg uint32, eax, ebx, ecx, edx *uint32)
13 |
14 | func cpuid(eaxArg, ecxArg uint32) (eax, ebx, ecx, edx uint32) {
15 | var a, b, c, d uint32
16 | gccgoGetCpuidCount(eaxArg, ecxArg, &a, &b, &c, &d)
17 | return a, b, c, d
18 | }
19 |
20 | //extern gccgoXgetbv
21 | func gccgoXgetbv(eax, edx *uint32)
22 |
23 | func xgetbv() (eax, edx uint32) {
24 | var a, d uint32
25 | gccgoXgetbv(&a, &d)
26 | return a, d
27 | }
28 |
29 | // gccgo doesn't build on Darwin, per:
30 | // https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/gcc.rb#L76
31 | func darwinSupportsAVX512() bool {
32 | return false
33 | }
34 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/sys/cpu/cpu_linux.go:
--------------------------------------------------------------------------------
1 | // Copyright 2018 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 | //go:build !386 && !amd64 && !amd64p32 && !arm64
6 | // +build !386,!amd64,!amd64p32,!arm64
7 |
8 | package cpu
9 |
10 | func archInit() {
11 | if err := readHWCAP(); err != nil {
12 | return
13 | }
14 | doinit()
15 | Initialized = true
16 | }
17 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/sys/cpu/cpu_linux_arm.go:
--------------------------------------------------------------------------------
1 | // Copyright 2019 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 cpu
6 |
7 | func doinit() {
8 | ARM.HasSWP = isSet(hwCap, hwcap_SWP)
9 | ARM.HasHALF = isSet(hwCap, hwcap_HALF)
10 | ARM.HasTHUMB = isSet(hwCap, hwcap_THUMB)
11 | ARM.Has26BIT = isSet(hwCap, hwcap_26BIT)
12 | ARM.HasFASTMUL = isSet(hwCap, hwcap_FAST_MULT)
13 | ARM.HasFPA = isSet(hwCap, hwcap_FPA)
14 | ARM.HasVFP = isSet(hwCap, hwcap_VFP)
15 | ARM.HasEDSP = isSet(hwCap, hwcap_EDSP)
16 | ARM.HasJAVA = isSet(hwCap, hwcap_JAVA)
17 | ARM.HasIWMMXT = isSet(hwCap, hwcap_IWMMXT)
18 | ARM.HasCRUNCH = isSet(hwCap, hwcap_CRUNCH)
19 | ARM.HasTHUMBEE = isSet(hwCap, hwcap_THUMBEE)
20 | ARM.HasNEON = isSet(hwCap, hwcap_NEON)
21 | ARM.HasVFPv3 = isSet(hwCap, hwcap_VFPv3)
22 | ARM.HasVFPv3D16 = isSet(hwCap, hwcap_VFPv3D16)
23 | ARM.HasTLS = isSet(hwCap, hwcap_TLS)
24 | ARM.HasVFPv4 = isSet(hwCap, hwcap_VFPv4)
25 | ARM.HasIDIVA = isSet(hwCap, hwcap_IDIVA)
26 | ARM.HasIDIVT = isSet(hwCap, hwcap_IDIVT)
27 | ARM.HasVFPD32 = isSet(hwCap, hwcap_VFPD32)
28 | ARM.HasLPAE = isSet(hwCap, hwcap_LPAE)
29 | ARM.HasEVTSTRM = isSet(hwCap, hwcap_EVTSTRM)
30 | ARM.HasAES = isSet(hwCap2, hwcap2_AES)
31 | ARM.HasPMULL = isSet(hwCap2, hwcap2_PMULL)
32 | ARM.HasSHA1 = isSet(hwCap2, hwcap2_SHA1)
33 | ARM.HasSHA2 = isSet(hwCap2, hwcap2_SHA2)
34 | ARM.HasCRC32 = isSet(hwCap2, hwcap2_CRC32)
35 | }
36 |
37 | func isSet(hwc uint, value uint) bool {
38 | return hwc&value != 0
39 | }
40 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/sys/cpu/cpu_linux_arm64.go:
--------------------------------------------------------------------------------
1 | // Copyright 2018 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 cpu
6 |
7 | import (
8 | "strings"
9 | "syscall"
10 | )
11 |
12 | // HWCAP/HWCAP2 bits. These are exposed by Linux.
13 | const (
14 | hwcap_FP = 1 << 0
15 | hwcap_ASIMD = 1 << 1
16 | hwcap_EVTSTRM = 1 << 2
17 | hwcap_AES = 1 << 3
18 | hwcap_PMULL = 1 << 4
19 | hwcap_SHA1 = 1 << 5
20 | hwcap_SHA2 = 1 << 6
21 | hwcap_CRC32 = 1 << 7
22 | hwcap_ATOMICS = 1 << 8
23 | hwcap_FPHP = 1 << 9
24 | hwcap_ASIMDHP = 1 << 10
25 | hwcap_CPUID = 1 << 11
26 | hwcap_ASIMDRDM = 1 << 12
27 | hwcap_JSCVT = 1 << 13
28 | hwcap_FCMA = 1 << 14
29 | hwcap_LRCPC = 1 << 15
30 | hwcap_DCPOP = 1 << 16
31 | hwcap_SHA3 = 1 << 17
32 | hwcap_SM3 = 1 << 18
33 | hwcap_SM4 = 1 << 19
34 | hwcap_ASIMDDP = 1 << 20
35 | hwcap_SHA512 = 1 << 21
36 | hwcap_SVE = 1 << 22
37 | hwcap_ASIMDFHM = 1 << 23
38 | )
39 |
40 | // linuxKernelCanEmulateCPUID reports whether we're running
41 | // on Linux 4.11+. Ideally we'd like to ask the question about
42 | // whether the current kernel contains
43 | // https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=77c97b4ee21290f5f083173d957843b615abbff2
44 | // but the version number will have to do.
45 | func linuxKernelCanEmulateCPUID() bool {
46 | var un syscall.Utsname
47 | syscall.Uname(&un)
48 | var sb strings.Builder
49 | for _, b := range un.Release[:] {
50 | if b == 0 {
51 | break
52 | }
53 | sb.WriteByte(byte(b))
54 | }
55 | major, minor, _, ok := parseRelease(sb.String())
56 | return ok && (major > 4 || major == 4 && minor >= 11)
57 | }
58 |
59 | func doinit() {
60 | if err := readHWCAP(); err != nil {
61 | // We failed to read /proc/self/auxv. This can happen if the binary has
62 | // been given extra capabilities(7) with /bin/setcap.
63 | //
64 | // When this happens, we have two options. If the Linux kernel is new
65 | // enough (4.11+), we can read the arm64 registers directly which'll
66 | // trap into the kernel and then return back to userspace.
67 | //
68 | // But on older kernels, such as Linux 4.4.180 as used on many Synology
69 | // devices, calling readARM64Registers (specifically getisar0) will
70 | // cause a SIGILL and we'll die. So for older kernels, parse /proc/cpuinfo
71 | // instead.
72 | //
73 | // See golang/go#57336.
74 | if linuxKernelCanEmulateCPUID() {
75 | readARM64Registers()
76 | } else {
77 | readLinuxProcCPUInfo()
78 | }
79 | return
80 | }
81 |
82 | // HWCAP feature bits
83 | ARM64.HasFP = isSet(hwCap, hwcap_FP)
84 | ARM64.HasASIMD = isSet(hwCap, hwcap_ASIMD)
85 | ARM64.HasEVTSTRM = isSet(hwCap, hwcap_EVTSTRM)
86 | ARM64.HasAES = isSet(hwCap, hwcap_AES)
87 | ARM64.HasPMULL = isSet(hwCap, hwcap_PMULL)
88 | ARM64.HasSHA1 = isSet(hwCap, hwcap_SHA1)
89 | ARM64.HasSHA2 = isSet(hwCap, hwcap_SHA2)
90 | ARM64.HasCRC32 = isSet(hwCap, hwcap_CRC32)
91 | ARM64.HasATOMICS = isSet(hwCap, hwcap_ATOMICS)
92 | ARM64.HasFPHP = isSet(hwCap, hwcap_FPHP)
93 | ARM64.HasASIMDHP = isSet(hwCap, hwcap_ASIMDHP)
94 | ARM64.HasCPUID = isSet(hwCap, hwcap_CPUID)
95 | ARM64.HasASIMDRDM = isSet(hwCap, hwcap_ASIMDRDM)
96 | ARM64.HasJSCVT = isSet(hwCap, hwcap_JSCVT)
97 | ARM64.HasFCMA = isSet(hwCap, hwcap_FCMA)
98 | ARM64.HasLRCPC = isSet(hwCap, hwcap_LRCPC)
99 | ARM64.HasDCPOP = isSet(hwCap, hwcap_DCPOP)
100 | ARM64.HasSHA3 = isSet(hwCap, hwcap_SHA3)
101 | ARM64.HasSM3 = isSet(hwCap, hwcap_SM3)
102 | ARM64.HasSM4 = isSet(hwCap, hwcap_SM4)
103 | ARM64.HasASIMDDP = isSet(hwCap, hwcap_ASIMDDP)
104 | ARM64.HasSHA512 = isSet(hwCap, hwcap_SHA512)
105 | ARM64.HasSVE = isSet(hwCap, hwcap_SVE)
106 | ARM64.HasASIMDFHM = isSet(hwCap, hwcap_ASIMDFHM)
107 | }
108 |
109 | func isSet(hwc uint, value uint) bool {
110 | return hwc&value != 0
111 | }
112 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/sys/cpu/cpu_linux_mips64x.go:
--------------------------------------------------------------------------------
1 | // Copyright 2020 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 | //go:build linux && (mips64 || mips64le)
6 | // +build linux
7 | // +build mips64 mips64le
8 |
9 | package cpu
10 |
11 | // HWCAP bits. These are exposed by the Linux kernel 5.4.
12 | const (
13 | // CPU features
14 | hwcap_MIPS_MSA = 1 << 1
15 | )
16 |
17 | func doinit() {
18 | // HWCAP feature bits
19 | MIPS64X.HasMSA = isSet(hwCap, hwcap_MIPS_MSA)
20 | }
21 |
22 | func isSet(hwc uint, value uint) bool {
23 | return hwc&value != 0
24 | }
25 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/sys/cpu/cpu_linux_noinit.go:
--------------------------------------------------------------------------------
1 | // Copyright 2019 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 | //go:build linux && !arm && !arm64 && !mips64 && !mips64le && !ppc64 && !ppc64le && !s390x
6 | // +build linux,!arm,!arm64,!mips64,!mips64le,!ppc64,!ppc64le,!s390x
7 |
8 | package cpu
9 |
10 | func doinit() {}
11 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/sys/cpu/cpu_linux_ppc64x.go:
--------------------------------------------------------------------------------
1 | // Copyright 2018 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 | //go:build linux && (ppc64 || ppc64le)
6 | // +build linux
7 | // +build ppc64 ppc64le
8 |
9 | package cpu
10 |
11 | // HWCAP/HWCAP2 bits. These are exposed by the kernel.
12 | const (
13 | // ISA Level
14 | _PPC_FEATURE2_ARCH_2_07 = 0x80000000
15 | _PPC_FEATURE2_ARCH_3_00 = 0x00800000
16 |
17 | // CPU features
18 | _PPC_FEATURE2_DARN = 0x00200000
19 | _PPC_FEATURE2_SCV = 0x00100000
20 | )
21 |
22 | func doinit() {
23 | // HWCAP2 feature bits
24 | PPC64.IsPOWER8 = isSet(hwCap2, _PPC_FEATURE2_ARCH_2_07)
25 | PPC64.IsPOWER9 = isSet(hwCap2, _PPC_FEATURE2_ARCH_3_00)
26 | PPC64.HasDARN = isSet(hwCap2, _PPC_FEATURE2_DARN)
27 | PPC64.HasSCV = isSet(hwCap2, _PPC_FEATURE2_SCV)
28 | }
29 |
30 | func isSet(hwc uint, value uint) bool {
31 | return hwc&value != 0
32 | }
33 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/sys/cpu/cpu_linux_s390x.go:
--------------------------------------------------------------------------------
1 | // Copyright 2019 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 cpu
6 |
7 | const (
8 | // bit mask values from /usr/include/bits/hwcap.h
9 | hwcap_ZARCH = 2
10 | hwcap_STFLE = 4
11 | hwcap_MSA = 8
12 | hwcap_LDISP = 16
13 | hwcap_EIMM = 32
14 | hwcap_DFP = 64
15 | hwcap_ETF3EH = 256
16 | hwcap_VX = 2048
17 | hwcap_VXE = 8192
18 | )
19 |
20 | func initS390Xbase() {
21 | // test HWCAP bit vector
22 | has := func(featureMask uint) bool {
23 | return hwCap&featureMask == featureMask
24 | }
25 |
26 | // mandatory
27 | S390X.HasZARCH = has(hwcap_ZARCH)
28 |
29 | // optional
30 | S390X.HasSTFLE = has(hwcap_STFLE)
31 | S390X.HasLDISP = has(hwcap_LDISP)
32 | S390X.HasEIMM = has(hwcap_EIMM)
33 | S390X.HasETF3EH = has(hwcap_ETF3EH)
34 | S390X.HasDFP = has(hwcap_DFP)
35 | S390X.HasMSA = has(hwcap_MSA)
36 | S390X.HasVX = has(hwcap_VX)
37 | if S390X.HasVX {
38 | S390X.HasVXE = has(hwcap_VXE)
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/sys/cpu/cpu_loong64.go:
--------------------------------------------------------------------------------
1 | // Copyright 2022 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 | //go:build loong64
6 | // +build loong64
7 |
8 | package cpu
9 |
10 | const cacheLineSize = 64
11 |
12 | func initOptions() {
13 | }
14 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/sys/cpu/cpu_mips64x.go:
--------------------------------------------------------------------------------
1 | // Copyright 2018 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 | //go:build mips64 || mips64le
6 | // +build mips64 mips64le
7 |
8 | package cpu
9 |
10 | const cacheLineSize = 32
11 |
12 | func initOptions() {
13 | options = []option{
14 | {Name: "msa", Feature: &MIPS64X.HasMSA},
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/sys/cpu/cpu_mipsx.go:
--------------------------------------------------------------------------------
1 | // Copyright 2018 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 | //go:build mips || mipsle
6 | // +build mips mipsle
7 |
8 | package cpu
9 |
10 | const cacheLineSize = 32
11 |
12 | func initOptions() {}
13 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/sys/cpu/cpu_netbsd_arm64.go:
--------------------------------------------------------------------------------
1 | // Copyright 2020 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 cpu
6 |
7 | import (
8 | "syscall"
9 | "unsafe"
10 | )
11 |
12 | // Minimal copy of functionality from x/sys/unix so the cpu package can call
13 | // sysctl without depending on x/sys/unix.
14 |
15 | const (
16 | _CTL_QUERY = -2
17 |
18 | _SYSCTL_VERS_1 = 0x1000000
19 | )
20 |
21 | var _zero uintptr
22 |
23 | func sysctl(mib []int32, old *byte, oldlen *uintptr, new *byte, newlen uintptr) (err error) {
24 | var _p0 unsafe.Pointer
25 | if len(mib) > 0 {
26 | _p0 = unsafe.Pointer(&mib[0])
27 | } else {
28 | _p0 = unsafe.Pointer(&_zero)
29 | }
30 | _, _, errno := syscall.Syscall6(
31 | syscall.SYS___SYSCTL,
32 | uintptr(_p0),
33 | uintptr(len(mib)),
34 | uintptr(unsafe.Pointer(old)),
35 | uintptr(unsafe.Pointer(oldlen)),
36 | uintptr(unsafe.Pointer(new)),
37 | uintptr(newlen))
38 | if errno != 0 {
39 | return errno
40 | }
41 | return nil
42 | }
43 |
44 | type sysctlNode struct {
45 | Flags uint32
46 | Num int32
47 | Name [32]int8
48 | Ver uint32
49 | __rsvd uint32
50 | Un [16]byte
51 | _sysctl_size [8]byte
52 | _sysctl_func [8]byte
53 | _sysctl_parent [8]byte
54 | _sysctl_desc [8]byte
55 | }
56 |
57 | func sysctlNodes(mib []int32) ([]sysctlNode, error) {
58 | var olen uintptr
59 |
60 | // Get a list of all sysctl nodes below the given MIB by performing
61 | // a sysctl for the given MIB with CTL_QUERY appended.
62 | mib = append(mib, _CTL_QUERY)
63 | qnode := sysctlNode{Flags: _SYSCTL_VERS_1}
64 | qp := (*byte)(unsafe.Pointer(&qnode))
65 | sz := unsafe.Sizeof(qnode)
66 | if err := sysctl(mib, nil, &olen, qp, sz); err != nil {
67 | return nil, err
68 | }
69 |
70 | // Now that we know the size, get the actual nodes.
71 | nodes := make([]sysctlNode, olen/sz)
72 | np := (*byte)(unsafe.Pointer(&nodes[0]))
73 | if err := sysctl(mib, np, &olen, qp, sz); err != nil {
74 | return nil, err
75 | }
76 |
77 | return nodes, nil
78 | }
79 |
80 | func nametomib(name string) ([]int32, error) {
81 | // Split name into components.
82 | var parts []string
83 | last := 0
84 | for i := 0; i < len(name); i++ {
85 | if name[i] == '.' {
86 | parts = append(parts, name[last:i])
87 | last = i + 1
88 | }
89 | }
90 | parts = append(parts, name[last:])
91 |
92 | mib := []int32{}
93 | // Discover the nodes and construct the MIB OID.
94 | for partno, part := range parts {
95 | nodes, err := sysctlNodes(mib)
96 | if err != nil {
97 | return nil, err
98 | }
99 | for _, node := range nodes {
100 | n := make([]byte, 0)
101 | for i := range node.Name {
102 | if node.Name[i] != 0 {
103 | n = append(n, byte(node.Name[i]))
104 | }
105 | }
106 | if string(n) == part {
107 | mib = append(mib, int32(node.Num))
108 | break
109 | }
110 | }
111 | if len(mib) != partno+1 {
112 | return nil, err
113 | }
114 | }
115 |
116 | return mib, nil
117 | }
118 |
119 | // aarch64SysctlCPUID is struct aarch64_sysctl_cpu_id from NetBSD's
120 | type aarch64SysctlCPUID struct {
121 | midr uint64 /* Main ID Register */
122 | revidr uint64 /* Revision ID Register */
123 | mpidr uint64 /* Multiprocessor Affinity Register */
124 | aa64dfr0 uint64 /* A64 Debug Feature Register 0 */
125 | aa64dfr1 uint64 /* A64 Debug Feature Register 1 */
126 | aa64isar0 uint64 /* A64 Instruction Set Attribute Register 0 */
127 | aa64isar1 uint64 /* A64 Instruction Set Attribute Register 1 */
128 | aa64mmfr0 uint64 /* A64 Memory Model Feature Register 0 */
129 | aa64mmfr1 uint64 /* A64 Memory Model Feature Register 1 */
130 | aa64mmfr2 uint64 /* A64 Memory Model Feature Register 2 */
131 | aa64pfr0 uint64 /* A64 Processor Feature Register 0 */
132 | aa64pfr1 uint64 /* A64 Processor Feature Register 1 */
133 | aa64zfr0 uint64 /* A64 SVE Feature ID Register 0 */
134 | mvfr0 uint32 /* Media and VFP Feature Register 0 */
135 | mvfr1 uint32 /* Media and VFP Feature Register 1 */
136 | mvfr2 uint32 /* Media and VFP Feature Register 2 */
137 | pad uint32
138 | clidr uint64 /* Cache Level ID Register */
139 | ctr uint64 /* Cache Type Register */
140 | }
141 |
142 | func sysctlCPUID(name string) (*aarch64SysctlCPUID, error) {
143 | mib, err := nametomib(name)
144 | if err != nil {
145 | return nil, err
146 | }
147 |
148 | out := aarch64SysctlCPUID{}
149 | n := unsafe.Sizeof(out)
150 | _, _, errno := syscall.Syscall6(
151 | syscall.SYS___SYSCTL,
152 | uintptr(unsafe.Pointer(&mib[0])),
153 | uintptr(len(mib)),
154 | uintptr(unsafe.Pointer(&out)),
155 | uintptr(unsafe.Pointer(&n)),
156 | uintptr(0),
157 | uintptr(0))
158 | if errno != 0 {
159 | return nil, errno
160 | }
161 | return &out, nil
162 | }
163 |
164 | func doinit() {
165 | cpuid, err := sysctlCPUID("machdep.cpu0.cpu_id")
166 | if err != nil {
167 | setMinimalFeatures()
168 | return
169 | }
170 | parseARM64SystemRegisters(cpuid.aa64isar0, cpuid.aa64isar1, cpuid.aa64pfr0)
171 |
172 | Initialized = true
173 | }
174 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/sys/cpu/cpu_openbsd_arm64.go:
--------------------------------------------------------------------------------
1 | // Copyright 2022 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 cpu
6 |
7 | import (
8 | "syscall"
9 | "unsafe"
10 | )
11 |
12 | // Minimal copy of functionality from x/sys/unix so the cpu package can call
13 | // sysctl without depending on x/sys/unix.
14 |
15 | const (
16 | // From OpenBSD's sys/sysctl.h.
17 | _CTL_MACHDEP = 7
18 |
19 | // From OpenBSD's machine/cpu.h.
20 | _CPU_ID_AA64ISAR0 = 2
21 | _CPU_ID_AA64ISAR1 = 3
22 | )
23 |
24 | // Implemented in the runtime package (runtime/sys_openbsd3.go)
25 | func syscall_syscall6(fn, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err syscall.Errno)
26 |
27 | //go:linkname syscall_syscall6 syscall.syscall6
28 |
29 | func sysctl(mib []uint32, old *byte, oldlen *uintptr, new *byte, newlen uintptr) (err error) {
30 | _, _, errno := syscall_syscall6(libc_sysctl_trampoline_addr, uintptr(unsafe.Pointer(&mib[0])), uintptr(len(mib)), uintptr(unsafe.Pointer(old)), uintptr(unsafe.Pointer(oldlen)), uintptr(unsafe.Pointer(new)), uintptr(newlen))
31 | if errno != 0 {
32 | return errno
33 | }
34 | return nil
35 | }
36 |
37 | var libc_sysctl_trampoline_addr uintptr
38 |
39 | //go:cgo_import_dynamic libc_sysctl sysctl "libc.so"
40 |
41 | func sysctlUint64(mib []uint32) (uint64, bool) {
42 | var out uint64
43 | nout := unsafe.Sizeof(out)
44 | if err := sysctl(mib, (*byte)(unsafe.Pointer(&out)), &nout, nil, 0); err != nil {
45 | return 0, false
46 | }
47 | return out, true
48 | }
49 |
50 | func doinit() {
51 | setMinimalFeatures()
52 |
53 | // Get ID_AA64ISAR0 and ID_AA64ISAR1 from sysctl.
54 | isar0, ok := sysctlUint64([]uint32{_CTL_MACHDEP, _CPU_ID_AA64ISAR0})
55 | if !ok {
56 | return
57 | }
58 | isar1, ok := sysctlUint64([]uint32{_CTL_MACHDEP, _CPU_ID_AA64ISAR1})
59 | if !ok {
60 | return
61 | }
62 | parseARM64SystemRegisters(isar0, isar1, 0)
63 |
64 | Initialized = true
65 | }
66 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/sys/cpu/cpu_openbsd_arm64.s:
--------------------------------------------------------------------------------
1 | // Copyright 2022 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 | #include "textflag.h"
6 |
7 | TEXT libc_sysctl_trampoline<>(SB),NOSPLIT,$0-0
8 | JMP libc_sysctl(SB)
9 |
10 | GLOBL ·libc_sysctl_trampoline_addr(SB), RODATA, $8
11 | DATA ·libc_sysctl_trampoline_addr(SB)/8, $libc_sysctl_trampoline<>(SB)
12 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/sys/cpu/cpu_other_arm.go:
--------------------------------------------------------------------------------
1 | // Copyright 2020 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 | //go:build !linux && arm
6 | // +build !linux,arm
7 |
8 | package cpu
9 |
10 | func archInit() {}
11 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/sys/cpu/cpu_other_arm64.go:
--------------------------------------------------------------------------------
1 | // Copyright 2019 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 | //go:build !linux && !netbsd && !openbsd && arm64
6 | // +build !linux,!netbsd,!openbsd,arm64
7 |
8 | package cpu
9 |
10 | func doinit() {}
11 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/sys/cpu/cpu_other_mips64x.go:
--------------------------------------------------------------------------------
1 | // Copyright 2020 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 | //go:build !linux && (mips64 || mips64le)
6 | // +build !linux
7 | // +build mips64 mips64le
8 |
9 | package cpu
10 |
11 | func archInit() {
12 | Initialized = true
13 | }
14 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/sys/cpu/cpu_other_ppc64x.go:
--------------------------------------------------------------------------------
1 | // Copyright 2022 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 | //go:build !aix && !linux && (ppc64 || ppc64le)
6 | // +build !aix
7 | // +build !linux
8 | // +build ppc64 ppc64le
9 |
10 | package cpu
11 |
12 | func archInit() {
13 | PPC64.IsPOWER8 = true
14 | Initialized = true
15 | }
16 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/sys/cpu/cpu_other_riscv64.go:
--------------------------------------------------------------------------------
1 | // Copyright 2022 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 | //go:build !linux && riscv64
6 | // +build !linux,riscv64
7 |
8 | package cpu
9 |
10 | func archInit() {
11 | Initialized = true
12 | }
13 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/sys/cpu/cpu_ppc64x.go:
--------------------------------------------------------------------------------
1 | // Copyright 2020 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 | //go:build ppc64 || ppc64le
6 | // +build ppc64 ppc64le
7 |
8 | package cpu
9 |
10 | const cacheLineSize = 128
11 |
12 | func initOptions() {
13 | options = []option{
14 | {Name: "darn", Feature: &PPC64.HasDARN},
15 | {Name: "scv", Feature: &PPC64.HasSCV},
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/sys/cpu/cpu_riscv64.go:
--------------------------------------------------------------------------------
1 | // Copyright 2019 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 | //go:build riscv64
6 | // +build riscv64
7 |
8 | package cpu
9 |
10 | const cacheLineSize = 32
11 |
12 | func initOptions() {}
13 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/sys/cpu/cpu_s390x.go:
--------------------------------------------------------------------------------
1 | // Copyright 2020 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 cpu
6 |
7 | const cacheLineSize = 256
8 |
9 | func initOptions() {
10 | options = []option{
11 | {Name: "zarch", Feature: &S390X.HasZARCH, Required: true},
12 | {Name: "stfle", Feature: &S390X.HasSTFLE, Required: true},
13 | {Name: "ldisp", Feature: &S390X.HasLDISP, Required: true},
14 | {Name: "eimm", Feature: &S390X.HasEIMM, Required: true},
15 | {Name: "dfp", Feature: &S390X.HasDFP},
16 | {Name: "etf3eh", Feature: &S390X.HasETF3EH},
17 | {Name: "msa", Feature: &S390X.HasMSA},
18 | {Name: "aes", Feature: &S390X.HasAES},
19 | {Name: "aescbc", Feature: &S390X.HasAESCBC},
20 | {Name: "aesctr", Feature: &S390X.HasAESCTR},
21 | {Name: "aesgcm", Feature: &S390X.HasAESGCM},
22 | {Name: "ghash", Feature: &S390X.HasGHASH},
23 | {Name: "sha1", Feature: &S390X.HasSHA1},
24 | {Name: "sha256", Feature: &S390X.HasSHA256},
25 | {Name: "sha3", Feature: &S390X.HasSHA3},
26 | {Name: "sha512", Feature: &S390X.HasSHA512},
27 | {Name: "vx", Feature: &S390X.HasVX},
28 | {Name: "vxe", Feature: &S390X.HasVXE},
29 | }
30 | }
31 |
32 | // bitIsSet reports whether the bit at index is set. The bit index
33 | // is in big endian order, so bit index 0 is the leftmost bit.
34 | func bitIsSet(bits []uint64, index uint) bool {
35 | return bits[index/64]&((1<<63)>>(index%64)) != 0
36 | }
37 |
38 | // facility is a bit index for the named facility.
39 | type facility uint8
40 |
41 | const (
42 | // mandatory facilities
43 | zarch facility = 1 // z architecture mode is active
44 | stflef facility = 7 // store-facility-list-extended
45 | ldisp facility = 18 // long-displacement
46 | eimm facility = 21 // extended-immediate
47 |
48 | // miscellaneous facilities
49 | dfp facility = 42 // decimal-floating-point
50 | etf3eh facility = 30 // extended-translation 3 enhancement
51 |
52 | // cryptography facilities
53 | msa facility = 17 // message-security-assist
54 | msa3 facility = 76 // message-security-assist extension 3
55 | msa4 facility = 77 // message-security-assist extension 4
56 | msa5 facility = 57 // message-security-assist extension 5
57 | msa8 facility = 146 // message-security-assist extension 8
58 | msa9 facility = 155 // message-security-assist extension 9
59 |
60 | // vector facilities
61 | vx facility = 129 // vector facility
62 | vxe facility = 135 // vector-enhancements 1
63 | vxe2 facility = 148 // vector-enhancements 2
64 | )
65 |
66 | // facilityList contains the result of an STFLE call.
67 | // Bits are numbered in big endian order so the
68 | // leftmost bit (the MSB) is at index 0.
69 | type facilityList struct {
70 | bits [4]uint64
71 | }
72 |
73 | // Has reports whether the given facilities are present.
74 | func (s *facilityList) Has(fs ...facility) bool {
75 | if len(fs) == 0 {
76 | panic("no facility bits provided")
77 | }
78 | for _, f := range fs {
79 | if !bitIsSet(s.bits[:], uint(f)) {
80 | return false
81 | }
82 | }
83 | return true
84 | }
85 |
86 | // function is the code for the named cryptographic function.
87 | type function uint8
88 |
89 | const (
90 | // KM{,A,C,CTR} function codes
91 | aes128 function = 18 // AES-128
92 | aes192 function = 19 // AES-192
93 | aes256 function = 20 // AES-256
94 |
95 | // K{I,L}MD function codes
96 | sha1 function = 1 // SHA-1
97 | sha256 function = 2 // SHA-256
98 | sha512 function = 3 // SHA-512
99 | sha3_224 function = 32 // SHA3-224
100 | sha3_256 function = 33 // SHA3-256
101 | sha3_384 function = 34 // SHA3-384
102 | sha3_512 function = 35 // SHA3-512
103 | shake128 function = 36 // SHAKE-128
104 | shake256 function = 37 // SHAKE-256
105 |
106 | // KLMD function codes
107 | ghash function = 65 // GHASH
108 | )
109 |
110 | // queryResult contains the result of a Query function
111 | // call. Bits are numbered in big endian order so the
112 | // leftmost bit (the MSB) is at index 0.
113 | type queryResult struct {
114 | bits [2]uint64
115 | }
116 |
117 | // Has reports whether the given functions are present.
118 | func (q *queryResult) Has(fns ...function) bool {
119 | if len(fns) == 0 {
120 | panic("no function codes provided")
121 | }
122 | for _, f := range fns {
123 | if !bitIsSet(q.bits[:], uint(f)) {
124 | return false
125 | }
126 | }
127 | return true
128 | }
129 |
130 | func doinit() {
131 | initS390Xbase()
132 |
133 | // We need implementations of stfle, km and so on
134 | // to detect cryptographic features.
135 | if !haveAsmFunctions() {
136 | return
137 | }
138 |
139 | // optional cryptographic functions
140 | if S390X.HasMSA {
141 | aes := []function{aes128, aes192, aes256}
142 |
143 | // cipher message
144 | km, kmc := kmQuery(), kmcQuery()
145 | S390X.HasAES = km.Has(aes...)
146 | S390X.HasAESCBC = kmc.Has(aes...)
147 | if S390X.HasSTFLE {
148 | facilities := stfle()
149 | if facilities.Has(msa4) {
150 | kmctr := kmctrQuery()
151 | S390X.HasAESCTR = kmctr.Has(aes...)
152 | }
153 | if facilities.Has(msa8) {
154 | kma := kmaQuery()
155 | S390X.HasAESGCM = kma.Has(aes...)
156 | }
157 | }
158 |
159 | // compute message digest
160 | kimd := kimdQuery() // intermediate (no padding)
161 | klmd := klmdQuery() // last (padding)
162 | S390X.HasSHA1 = kimd.Has(sha1) && klmd.Has(sha1)
163 | S390X.HasSHA256 = kimd.Has(sha256) && klmd.Has(sha256)
164 | S390X.HasSHA512 = kimd.Has(sha512) && klmd.Has(sha512)
165 | S390X.HasGHASH = kimd.Has(ghash) // KLMD-GHASH does not exist
166 | sha3 := []function{
167 | sha3_224, sha3_256, sha3_384, sha3_512,
168 | shake128, shake256,
169 | }
170 | S390X.HasSHA3 = kimd.Has(sha3...) && klmd.Has(sha3...)
171 | }
172 | }
173 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/sys/cpu/cpu_s390x.s:
--------------------------------------------------------------------------------
1 | // Copyright 2019 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 | //go:build gc
6 | // +build gc
7 |
8 | #include "textflag.h"
9 |
10 | // func stfle() facilityList
11 | TEXT ·stfle(SB), NOSPLIT|NOFRAME, $0-32
12 | MOVD $ret+0(FP), R1
13 | MOVD $3, R0 // last doubleword index to store
14 | XC $32, (R1), (R1) // clear 4 doublewords (32 bytes)
15 | WORD $0xb2b01000 // store facility list extended (STFLE)
16 | RET
17 |
18 | // func kmQuery() queryResult
19 | TEXT ·kmQuery(SB), NOSPLIT|NOFRAME, $0-16
20 | MOVD $0, R0 // set function code to 0 (KM-Query)
21 | MOVD $ret+0(FP), R1 // address of 16-byte return value
22 | WORD $0xB92E0024 // cipher message (KM)
23 | RET
24 |
25 | // func kmcQuery() queryResult
26 | TEXT ·kmcQuery(SB), NOSPLIT|NOFRAME, $0-16
27 | MOVD $0, R0 // set function code to 0 (KMC-Query)
28 | MOVD $ret+0(FP), R1 // address of 16-byte return value
29 | WORD $0xB92F0024 // cipher message with chaining (KMC)
30 | RET
31 |
32 | // func kmctrQuery() queryResult
33 | TEXT ·kmctrQuery(SB), NOSPLIT|NOFRAME, $0-16
34 | MOVD $0, R0 // set function code to 0 (KMCTR-Query)
35 | MOVD $ret+0(FP), R1 // address of 16-byte return value
36 | WORD $0xB92D4024 // cipher message with counter (KMCTR)
37 | RET
38 |
39 | // func kmaQuery() queryResult
40 | TEXT ·kmaQuery(SB), NOSPLIT|NOFRAME, $0-16
41 | MOVD $0, R0 // set function code to 0 (KMA-Query)
42 | MOVD $ret+0(FP), R1 // address of 16-byte return value
43 | WORD $0xb9296024 // cipher message with authentication (KMA)
44 | RET
45 |
46 | // func kimdQuery() queryResult
47 | TEXT ·kimdQuery(SB), NOSPLIT|NOFRAME, $0-16
48 | MOVD $0, R0 // set function code to 0 (KIMD-Query)
49 | MOVD $ret+0(FP), R1 // address of 16-byte return value
50 | WORD $0xB93E0024 // compute intermediate message digest (KIMD)
51 | RET
52 |
53 | // func klmdQuery() queryResult
54 | TEXT ·klmdQuery(SB), NOSPLIT|NOFRAME, $0-16
55 | MOVD $0, R0 // set function code to 0 (KLMD-Query)
56 | MOVD $ret+0(FP), R1 // address of 16-byte return value
57 | WORD $0xB93F0024 // compute last message digest (KLMD)
58 | RET
59 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/sys/cpu/cpu_wasm.go:
--------------------------------------------------------------------------------
1 | // Copyright 2019 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 | //go:build wasm
6 | // +build wasm
7 |
8 | package cpu
9 |
10 | // We're compiling the cpu package for an unknown (software-abstracted) CPU.
11 | // Make CacheLinePad an empty struct and hope that the usual struct alignment
12 | // rules are good enough.
13 |
14 | const cacheLineSize = 0
15 |
16 | func initOptions() {}
17 |
18 | func archInit() {}
19 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/sys/cpu/cpu_x86.go:
--------------------------------------------------------------------------------
1 | // Copyright 2018 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 | //go:build 386 || amd64 || amd64p32
6 | // +build 386 amd64 amd64p32
7 |
8 | package cpu
9 |
10 | import "runtime"
11 |
12 | const cacheLineSize = 64
13 |
14 | func initOptions() {
15 | options = []option{
16 | {Name: "adx", Feature: &X86.HasADX},
17 | {Name: "aes", Feature: &X86.HasAES},
18 | {Name: "avx", Feature: &X86.HasAVX},
19 | {Name: "avx2", Feature: &X86.HasAVX2},
20 | {Name: "avx512", Feature: &X86.HasAVX512},
21 | {Name: "avx512f", Feature: &X86.HasAVX512F},
22 | {Name: "avx512cd", Feature: &X86.HasAVX512CD},
23 | {Name: "avx512er", Feature: &X86.HasAVX512ER},
24 | {Name: "avx512pf", Feature: &X86.HasAVX512PF},
25 | {Name: "avx512vl", Feature: &X86.HasAVX512VL},
26 | {Name: "avx512bw", Feature: &X86.HasAVX512BW},
27 | {Name: "avx512dq", Feature: &X86.HasAVX512DQ},
28 | {Name: "avx512ifma", Feature: &X86.HasAVX512IFMA},
29 | {Name: "avx512vbmi", Feature: &X86.HasAVX512VBMI},
30 | {Name: "avx512vnniw", Feature: &X86.HasAVX5124VNNIW},
31 | {Name: "avx5124fmaps", Feature: &X86.HasAVX5124FMAPS},
32 | {Name: "avx512vpopcntdq", Feature: &X86.HasAVX512VPOPCNTDQ},
33 | {Name: "avx512vpclmulqdq", Feature: &X86.HasAVX512VPCLMULQDQ},
34 | {Name: "avx512vnni", Feature: &X86.HasAVX512VNNI},
35 | {Name: "avx512gfni", Feature: &X86.HasAVX512GFNI},
36 | {Name: "avx512vaes", Feature: &X86.HasAVX512VAES},
37 | {Name: "avx512vbmi2", Feature: &X86.HasAVX512VBMI2},
38 | {Name: "avx512bitalg", Feature: &X86.HasAVX512BITALG},
39 | {Name: "avx512bf16", Feature: &X86.HasAVX512BF16},
40 | {Name: "bmi1", Feature: &X86.HasBMI1},
41 | {Name: "bmi2", Feature: &X86.HasBMI2},
42 | {Name: "cx16", Feature: &X86.HasCX16},
43 | {Name: "erms", Feature: &X86.HasERMS},
44 | {Name: "fma", Feature: &X86.HasFMA},
45 | {Name: "osxsave", Feature: &X86.HasOSXSAVE},
46 | {Name: "pclmulqdq", Feature: &X86.HasPCLMULQDQ},
47 | {Name: "popcnt", Feature: &X86.HasPOPCNT},
48 | {Name: "rdrand", Feature: &X86.HasRDRAND},
49 | {Name: "rdseed", Feature: &X86.HasRDSEED},
50 | {Name: "sse3", Feature: &X86.HasSSE3},
51 | {Name: "sse41", Feature: &X86.HasSSE41},
52 | {Name: "sse42", Feature: &X86.HasSSE42},
53 | {Name: "ssse3", Feature: &X86.HasSSSE3},
54 |
55 | // These capabilities should always be enabled on amd64:
56 | {Name: "sse2", Feature: &X86.HasSSE2, Required: runtime.GOARCH == "amd64"},
57 | }
58 | }
59 |
60 | func archInit() {
61 |
62 | Initialized = true
63 |
64 | maxID, _, _, _ := cpuid(0, 0)
65 |
66 | if maxID < 1 {
67 | return
68 | }
69 |
70 | _, _, ecx1, edx1 := cpuid(1, 0)
71 | X86.HasSSE2 = isSet(26, edx1)
72 |
73 | X86.HasSSE3 = isSet(0, ecx1)
74 | X86.HasPCLMULQDQ = isSet(1, ecx1)
75 | X86.HasSSSE3 = isSet(9, ecx1)
76 | X86.HasFMA = isSet(12, ecx1)
77 | X86.HasCX16 = isSet(13, ecx1)
78 | X86.HasSSE41 = isSet(19, ecx1)
79 | X86.HasSSE42 = isSet(20, ecx1)
80 | X86.HasPOPCNT = isSet(23, ecx1)
81 | X86.HasAES = isSet(25, ecx1)
82 | X86.HasOSXSAVE = isSet(27, ecx1)
83 | X86.HasRDRAND = isSet(30, ecx1)
84 |
85 | var osSupportsAVX, osSupportsAVX512 bool
86 | // For XGETBV, OSXSAVE bit is required and sufficient.
87 | if X86.HasOSXSAVE {
88 | eax, _ := xgetbv()
89 | // Check if XMM and YMM registers have OS support.
90 | osSupportsAVX = isSet(1, eax) && isSet(2, eax)
91 |
92 | if runtime.GOOS == "darwin" {
93 | // Darwin doesn't save/restore AVX-512 mask registers correctly across signal handlers.
94 | // Since users can't rely on mask register contents, let's not advertise AVX-512 support.
95 | // See issue 49233.
96 | osSupportsAVX512 = false
97 | } else {
98 | // Check if OPMASK and ZMM registers have OS support.
99 | osSupportsAVX512 = osSupportsAVX && isSet(5, eax) && isSet(6, eax) && isSet(7, eax)
100 | }
101 | }
102 |
103 | X86.HasAVX = isSet(28, ecx1) && osSupportsAVX
104 |
105 | if maxID < 7 {
106 | return
107 | }
108 |
109 | _, ebx7, ecx7, edx7 := cpuid(7, 0)
110 | X86.HasBMI1 = isSet(3, ebx7)
111 | X86.HasAVX2 = isSet(5, ebx7) && osSupportsAVX
112 | X86.HasBMI2 = isSet(8, ebx7)
113 | X86.HasERMS = isSet(9, ebx7)
114 | X86.HasRDSEED = isSet(18, ebx7)
115 | X86.HasADX = isSet(19, ebx7)
116 |
117 | X86.HasAVX512 = isSet(16, ebx7) && osSupportsAVX512 // Because avx-512 foundation is the core required extension
118 | if X86.HasAVX512 {
119 | X86.HasAVX512F = true
120 | X86.HasAVX512CD = isSet(28, ebx7)
121 | X86.HasAVX512ER = isSet(27, ebx7)
122 | X86.HasAVX512PF = isSet(26, ebx7)
123 | X86.HasAVX512VL = isSet(31, ebx7)
124 | X86.HasAVX512BW = isSet(30, ebx7)
125 | X86.HasAVX512DQ = isSet(17, ebx7)
126 | X86.HasAVX512IFMA = isSet(21, ebx7)
127 | X86.HasAVX512VBMI = isSet(1, ecx7)
128 | X86.HasAVX5124VNNIW = isSet(2, edx7)
129 | X86.HasAVX5124FMAPS = isSet(3, edx7)
130 | X86.HasAVX512VPOPCNTDQ = isSet(14, ecx7)
131 | X86.HasAVX512VPCLMULQDQ = isSet(10, ecx7)
132 | X86.HasAVX512VNNI = isSet(11, ecx7)
133 | X86.HasAVX512GFNI = isSet(8, ecx7)
134 | X86.HasAVX512VAES = isSet(9, ecx7)
135 | X86.HasAVX512VBMI2 = isSet(6, ecx7)
136 | X86.HasAVX512BITALG = isSet(12, ecx7)
137 |
138 | eax71, _, _, _ := cpuid(7, 1)
139 | X86.HasAVX512BF16 = isSet(5, eax71)
140 | }
141 | }
142 |
143 | func isSet(bitpos uint, value uint32) bool {
144 | return value&(1<> 63))
18 | )
19 |
20 | // For those platforms don't have a 'cpuid' equivalent we use HWCAP/HWCAP2
21 | // These are initialized in cpu_$GOARCH.go
22 | // and should not be changed after they are initialized.
23 | var hwCap uint
24 | var hwCap2 uint
25 |
26 | func readHWCAP() error {
27 | // For Go 1.21+, get auxv from the Go runtime.
28 | if a := getAuxv(); len(a) > 0 {
29 | for len(a) >= 2 {
30 | tag, val := a[0], uint(a[1])
31 | a = a[2:]
32 | switch tag {
33 | case _AT_HWCAP:
34 | hwCap = val
35 | case _AT_HWCAP2:
36 | hwCap2 = val
37 | }
38 | }
39 | return nil
40 | }
41 |
42 | buf, err := ioutil.ReadFile(procAuxv)
43 | if err != nil {
44 | // e.g. on android /proc/self/auxv is not accessible, so silently
45 | // ignore the error and leave Initialized = false. On some
46 | // architectures (e.g. arm64) doinit() implements a fallback
47 | // readout and will set Initialized = true again.
48 | return err
49 | }
50 | bo := hostByteOrder()
51 | for len(buf) >= 2*(uintSize/8) {
52 | var tag, val uint
53 | switch uintSize {
54 | case 32:
55 | tag = uint(bo.Uint32(buf[0:]))
56 | val = uint(bo.Uint32(buf[4:]))
57 | buf = buf[8:]
58 | case 64:
59 | tag = uint(bo.Uint64(buf[0:]))
60 | val = uint(bo.Uint64(buf[8:]))
61 | buf = buf[16:]
62 | }
63 | switch tag {
64 | case _AT_HWCAP:
65 | hwCap = val
66 | case _AT_HWCAP2:
67 | hwCap2 = val
68 | }
69 | }
70 | return nil
71 | }
72 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/sys/cpu/parse.go:
--------------------------------------------------------------------------------
1 | // Copyright 2022 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 cpu
6 |
7 | import "strconv"
8 |
9 | // parseRelease parses a dot-separated version number. It follows the semver
10 | // syntax, but allows the minor and patch versions to be elided.
11 | //
12 | // This is a copy of the Go runtime's parseRelease from
13 | // https://golang.org/cl/209597.
14 | func parseRelease(rel string) (major, minor, patch int, ok bool) {
15 | // Strip anything after a dash or plus.
16 | for i := 0; i < len(rel); i++ {
17 | if rel[i] == '-' || rel[i] == '+' {
18 | rel = rel[:i]
19 | break
20 | }
21 | }
22 |
23 | next := func() (int, bool) {
24 | for i := 0; i < len(rel); i++ {
25 | if rel[i] == '.' {
26 | ver, err := strconv.Atoi(rel[:i])
27 | rel = rel[i+1:]
28 | return ver, err == nil
29 | }
30 | }
31 | ver, err := strconv.Atoi(rel)
32 | rel = ""
33 | return ver, err == nil
34 | }
35 | if major, ok = next(); !ok || rel == "" {
36 | return
37 | }
38 | if minor, ok = next(); !ok || rel == "" {
39 | return
40 | }
41 | patch, ok = next()
42 | return
43 | }
44 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/sys/cpu/proc_cpuinfo_linux.go:
--------------------------------------------------------------------------------
1 | // Copyright 2022 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 | //go:build linux && arm64
6 | // +build linux,arm64
7 |
8 | package cpu
9 |
10 | import (
11 | "errors"
12 | "io"
13 | "os"
14 | "strings"
15 | )
16 |
17 | func readLinuxProcCPUInfo() error {
18 | f, err := os.Open("/proc/cpuinfo")
19 | if err != nil {
20 | return err
21 | }
22 | defer f.Close()
23 |
24 | var buf [1 << 10]byte // enough for first CPU
25 | n, err := io.ReadFull(f, buf[:])
26 | if err != nil && err != io.ErrUnexpectedEOF {
27 | return err
28 | }
29 | in := string(buf[:n])
30 | const features = "\nFeatures : "
31 | i := strings.Index(in, features)
32 | if i == -1 {
33 | return errors.New("no CPU features found")
34 | }
35 | in = in[i+len(features):]
36 | if i := strings.Index(in, "\n"); i != -1 {
37 | in = in[:i]
38 | }
39 | m := map[string]*bool{}
40 |
41 | initOptions() // need it early here; it's harmless to call twice
42 | for _, o := range options {
43 | m[o.Name] = o.Feature
44 | }
45 | // The EVTSTRM field has alias "evstrm" in Go, but Linux calls it "evtstrm".
46 | m["evtstrm"] = &ARM64.HasEVTSTRM
47 |
48 | for _, f := range strings.Fields(in) {
49 | if p, ok := m[f]; ok {
50 | *p = true
51 | }
52 | }
53 | return nil
54 | }
55 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/sys/cpu/runtime_auxv.go:
--------------------------------------------------------------------------------
1 | // Copyright 2023 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 cpu
6 |
7 | // getAuxvFn is non-nil on Go 1.21+ (via runtime_auxv_go121.go init)
8 | // on platforms that use auxv.
9 | var getAuxvFn func() []uintptr
10 |
11 | func getAuxv() []uintptr {
12 | if getAuxvFn == nil {
13 | return nil
14 | }
15 | return getAuxvFn()
16 | }
17 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/sys/cpu/runtime_auxv_go121.go:
--------------------------------------------------------------------------------
1 | // Copyright 2023 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 | //go:build go1.21
6 | // +build go1.21
7 |
8 | package cpu
9 |
10 | import (
11 | _ "unsafe" // for linkname
12 | )
13 |
14 | //go:linkname runtime_getAuxv runtime.getAuxv
15 | func runtime_getAuxv() []uintptr
16 |
17 | func init() {
18 | getAuxvFn = runtime_getAuxv
19 | }
20 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/sys/cpu/syscall_aix_gccgo.go:
--------------------------------------------------------------------------------
1 | // Copyright 2020 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 | // Recreate a getsystemcfg syscall handler instead of
6 | // using the one provided by x/sys/unix to avoid having
7 | // the dependency between them. (See golang.org/issue/32102)
8 | // Moreover, this file will be used during the building of
9 | // gccgo's libgo and thus must not used a CGo method.
10 |
11 | //go:build aix && gccgo
12 | // +build aix,gccgo
13 |
14 | package cpu
15 |
16 | import (
17 | "syscall"
18 | )
19 |
20 | //extern getsystemcfg
21 | func gccgoGetsystemcfg(label uint32) (r uint64)
22 |
23 | func callgetsystemcfg(label int) (r1 uintptr, e1 syscall.Errno) {
24 | r1 = uintptr(gccgoGetsystemcfg(uint32(label)))
25 | e1 = syscall.GetErrno()
26 | return
27 | }
28 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/sys/cpu/syscall_aix_ppc64_gc.go:
--------------------------------------------------------------------------------
1 | // Copyright 2019 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 | // Minimal copy of x/sys/unix so the cpu package can make a
6 | // system call on AIX without depending on x/sys/unix.
7 | // (See golang.org/issue/32102)
8 |
9 | //go:build aix && ppc64 && gc
10 | // +build aix,ppc64,gc
11 |
12 | package cpu
13 |
14 | import (
15 | "syscall"
16 | "unsafe"
17 | )
18 |
19 | //go:cgo_import_dynamic libc_getsystemcfg getsystemcfg "libc.a/shr_64.o"
20 |
21 | //go:linkname libc_getsystemcfg libc_getsystemcfg
22 |
23 | type syscallFunc uintptr
24 |
25 | var libc_getsystemcfg syscallFunc
26 |
27 | type errno = syscall.Errno
28 |
29 | // Implemented in runtime/syscall_aix.go.
30 | func rawSyscall6(trap, nargs, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err errno)
31 | func syscall6(trap, nargs, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err errno)
32 |
33 | func callgetsystemcfg(label int) (r1 uintptr, e1 errno) {
34 | r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_getsystemcfg)), 1, uintptr(label), 0, 0, 0, 0, 0)
35 | return
36 | }
37 |
--------------------------------------------------------------------------------
/vendor/modules.txt:
--------------------------------------------------------------------------------
1 | # github.com/juju/fslock v0.0.0-20160525022230-4d5c94c67b4b
2 | ## explicit
3 | github.com/juju/fslock
4 | # github.com/satori/go.uuid v1.2.0
5 | ## explicit
6 | github.com/satori/go.uuid
7 | # golang.org/x/crypto v0.8.0
8 | ## explicit; go 1.17
9 | golang.org/x/crypto/argon2
10 | golang.org/x/crypto/blake2b
11 | golang.org/x/crypto/internal/alias
12 | golang.org/x/crypto/internal/poly1305
13 | golang.org/x/crypto/nacl/secretbox
14 | golang.org/x/crypto/salsa20/salsa
15 | # golang.org/x/sys v0.7.0
16 | ## explicit; go 1.17
17 | golang.org/x/sys/cpu
18 | # gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c
19 | ## explicit; go 1.11
20 |
--------------------------------------------------------------------------------