├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── examples ├── REDAME.md └── test-rpc.go ├── go.mod ├── go.sum ├── netconf ├── events.go ├── message │ ├── commit.go │ ├── common.go │ ├── copy-config.go │ ├── edit-config.go │ ├── get.go │ ├── getconfig.go │ ├── hello.go │ ├── lock.go │ ├── notification.go │ ├── rpc.go │ ├── session.go │ ├── unlock.go │ └── validate.go ├── operations.go ├── session.go ├── sessionfactory.go ├── transport.go └── transport_ssh.go ├── tests ├── RPCReply_test.go ├── message_test.go └── resources │ └── junos-rpc-reply.xml └── vendor ├── golang.org └── x │ ├── crypto │ ├── AUTHORS │ ├── CONTRIBUTORS │ ├── LICENSE │ ├── PATENTS │ ├── blowfish │ │ ├── block.go │ │ ├── cipher.go │ │ └── const.go │ ├── chacha20 │ │ ├── chacha_arm64.go │ │ ├── chacha_arm64.s │ │ ├── chacha_generic.go │ │ ├── chacha_noasm.go │ │ ├── chacha_ppc64le.go │ │ ├── chacha_ppc64le.s │ │ ├── chacha_s390x.go │ │ ├── chacha_s390x.s │ │ └── xor.go │ ├── curve25519 │ │ ├── curve25519.go │ │ └── internal │ │ │ └── field │ │ │ ├── README │ │ │ ├── fe.go │ │ │ ├── fe_amd64.go │ │ │ ├── fe_amd64.s │ │ │ ├── fe_amd64_noasm.go │ │ │ ├── fe_arm64.go │ │ │ ├── fe_arm64.s │ │ │ ├── fe_arm64_noasm.go │ │ │ ├── fe_generic.go │ │ │ ├── sync.checkpoint │ │ │ └── sync.sh │ ├── ed25519 │ │ ├── ed25519.go │ │ ├── ed25519_go113.go │ │ └── internal │ │ │ └── edwards25519 │ │ │ ├── const.go │ │ │ └── edwards25519.go │ ├── internal │ │ ├── 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 │ │ └── subtle │ │ │ ├── aliasing.go │ │ │ └── aliasing_purego.go │ └── ssh │ │ ├── buffer.go │ │ ├── certs.go │ │ ├── channel.go │ │ ├── cipher.go │ │ ├── client.go │ │ ├── client_auth.go │ │ ├── common.go │ │ ├── connection.go │ │ ├── doc.go │ │ ├── handshake.go │ │ ├── internal │ │ └── bcrypt_pbkdf │ │ │ └── bcrypt_pbkdf.go │ │ ├── kex.go │ │ ├── keys.go │ │ ├── mac.go │ │ ├── messages.go │ │ ├── mux.go │ │ ├── server.go │ │ ├── session.go │ │ ├── ssh_gss.go │ │ ├── streamlocal.go │ │ ├── tcpip.go │ │ └── transport.go │ └── sys │ ├── AUTHORS │ ├── CONTRIBUTORS │ ├── 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_mips64x.go │ ├── cpu_mipsx.go │ ├── cpu_netbsd_arm64.go │ ├── cpu_other_arm.go │ ├── cpu_other_arm64.go │ ├── cpu_other_mips64x.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 │ ├── hwcap_linux.go │ ├── syscall_aix_gccgo.go │ └── syscall_aix_ppc64_gc.go └── modules.txt /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | go: 4 | - "1.16" 5 | - tip 6 | 7 | matrix: 8 | fast_finish: true 9 | allow_failures: 10 | - go: tip 11 | 12 | install: go get -d -v -t ./... && go build -v ./... 13 | 14 | script: 15 | - test -z $(gofmt -s -l $GO_FILES) # Fail if a .go file hasn't been formatted with gofmt 16 | - go vet ./... # go vet is the official Go static analyzer 17 | - golint ./... # one last linter 18 | - go test -v ./... -race -coverprofile=coverage.txt -covermode=atomic # Run all the tests with the race detector enabled and report to codecov 19 | 20 | before_script: 21 | - cd netconf 22 | - GO_FILES=$(find . -iname '*.go' -type f) # All the .go files, 23 | - go get -u golang.org/x/lint/golint # Linter 24 | 25 | after_success: 26 | - bash <(curl -s https://codecov.io/bash) -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | > :heavy_exclamation_mark: *Red Hat does not provide commercial support for the content of these repos* 2 | 3 | ```bash 4 | ############################################################################# 5 | DISCLAIMER: THESE ARE UNSUPPORTED COMMUNITY TOOLS. 6 | 7 | THE REFERENCES ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 8 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 9 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 10 | ############################################################################# 11 | ``` 12 | 13 | # NETCONF 14 | 15 | [![GoDoc](https://godoc.org/github.com/openshift-telco/go-netconf-client?status.svg)](https://godoc.org/github.com/openshift-telco/go-netconf-client) 16 | [![Report Card](https://goreportcard.com/badge/github.com/openshift-telco/go-netconf-client)](https://goreportcard.com/report/github.com/openshift-telco/go-netconf-client) 17 | 18 | This library is a simple NETCONF client : 19 | - [RFC6241](http://tools.ietf.org/html/rfc6241): **Network Configuration Protocol (NETCONF)** 20 | - Support for the following RPC: `lock`, `unlock`, `edit-config`, `comit`, `validate`,`get`, `get-config` 21 | - Support for custom RPC 22 | - [RFC6242](http://tools.ietf.org/html/rfc6242): **Using the NETCONF Protocol over Secure Shell (SSH)** 23 | - Support for username/password 24 | - Support for pub key 25 | - [RFC5277](https://datatracker.ietf.org/doc/html/rfc5277): **NETCONF Event Notifications** 26 | - Support for `create-subscription` 27 | - No support for notification filtering 28 | - Partially [RFC8641](https://datatracker.ietf.org/doc/html/rfc8641) and [RFC8639](https://datatracker.ietf.org/doc/html/rfc8639): **Subscription to YANG Notifications for Datastore Updates** 29 | - Support for `establish-subscription` 30 | - No support for `delete-subscription` 31 | 32 | #### Install 33 | 34 | - ` go get github.com/openshift-telco/go-netconf-client@v1.0.6` 35 | 36 | #### Examples 37 | 38 | - See example in the `examples/` directory 39 | 40 | #### Links 41 | This client is an adaptation of the code taken from: 42 | - https://github.com/andaru/netconf 43 | - https://github.com/Juniper/go-netconf 44 | -------------------------------------------------------------------------------- /examples/REDAME.md: -------------------------------------------------------------------------------- 1 | ## Testing 2 | 3 | In order to test the NETCONF client, we are using a NETCONF simulator. 4 | 5 | The NETCONF simulator is a Java project provided by [Pantheon Technologies](https://github.com/PANTHEONtech) 6 | 7 | It requires Java and Maven to be built. 8 | 9 | Here are the steps to get the simulator, and emulate 200 devices. 10 | 11 | **Clone the repository** 12 | ~~~ 13 | git clone https://github.com/PANTHEONtech/lighty-netconf-simulator.git 14 | ~~~ 15 | **Compile the repository** 16 | ~~~ 17 | mvn clean install 18 | ~~~ 19 | **Run the simulator** 20 | ~~~ 21 | // RPC tests 22 | java -jar lighty-netconf-simulator/examples/devices/lighty-toaster-multiple-devices/target/lighty-toaster-multiple-devices-15.0.1-SNAPSHOT.jar --starting-port 20000 --device-count 200 --thread-pool-size 200 23 | 24 | // Notification tests 25 | java -jar lighty-netconf-simulator/examples/devices/lighty-notifications-device/target/lighty-notifications-device-15.0.1-SNAPSHOT.jar 12346 26 | ~~~ -------------------------------------------------------------------------------- /examples/test-rpc.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | "log/slog" 7 | "os" 8 | "time" 9 | 10 | "github.com/openshift-telco/go-netconf-client/netconf" 11 | "github.com/openshift-telco/go-netconf-client/netconf/message" 12 | "golang.org/x/crypto/ssh" 13 | ) 14 | 15 | func main() { 16 | 17 | // java -jar lighty-notifications-device-15.0.1-SNAPSHOT.jar 12345 18 | testNotification() 19 | 20 | // java -jar lighty-toaster-multiple-devices-15.0.1-SNAPSHOT.jar --starting-port 20000 --device-count 200 --thread-pool-size 200 21 | //testRPC() 22 | 23 | time.Sleep(10 * time.Second) 24 | } 25 | 26 | func testNotification() { 27 | 28 | notificationSession := createSession(12346) 29 | 30 | callback := func(event netconf.Event) { 31 | reply := event.Notification() 32 | println(reply.RawReply) 33 | } 34 | err := notificationSession.CreateNotificationStream(1, "", "", "", callback) 35 | if err != nil { 36 | panic("fail") 37 | } 38 | 39 | triggerNotification := " \n 0\n 5\n 1\n just simple notification\n " 40 | rpc := message.NewRPC(triggerNotification) 41 | notificationSession.SyncRPC(rpc, 1) 42 | 43 | err = notificationSession.CreateNotificationStream(1, "", "", "", callback) 44 | if err == nil { 45 | panic("must fail") 46 | } 47 | 48 | d := message.NewCloseSession() 49 | notificationSession.AsyncRPC(d, defaultLogRpcReplyCallback(d.MessageID)) 50 | 51 | notificationSession.Listener.Remove(message.NetconfNotificationStreamHandler) 52 | notificationSession.Listener.WaitForMessages() 53 | 54 | notificationSession.Close() 55 | } 56 | 57 | func testRPC() { 58 | for i := 0; i < 2; i++ { 59 | i := i 60 | go func() { 61 | number := 20000 + i 62 | session := createSession(number) 63 | defer session.Close() 64 | execRPC(session) 65 | }() 66 | } 67 | } 68 | 69 | // Execute all types of RPC against the device 70 | // Add a 100ms delay after each RPC to leave enough time for the device to reply 71 | // Else, too many request and things get bad. 72 | func execRPC(session *netconf.Session) { 73 | 74 | // Get Config 75 | g := message.NewGetConfig(message.DatastoreRunning, message.FilterTypeSubtree, "") 76 | session.AsyncRPC(g, defaultLogRpcReplyCallback(g.MessageID)) 77 | time.Sleep(100 * time.Millisecond) 78 | 79 | // Get 80 | gt := message.NewGet("", "") 81 | session.AsyncRPC(gt, defaultLogRpcReplyCallback(gt.MessageID)) 82 | time.Sleep(100 * time.Millisecond) 83 | 84 | // Lock 85 | l := message.NewLock(message.DatastoreCandidate) 86 | session.AsyncRPC(l, defaultLogRpcReplyCallback(l.MessageID)) 87 | time.Sleep(100 * time.Millisecond) 88 | 89 | // EditConfig 90 | data := "\n 750\n" 91 | e := message.NewEditConfig(message.DatastoreCandidate, message.DefaultOperationTypeMerge, data) 92 | session.AsyncRPC(e, defaultLogRpcReplyCallback(e.MessageID)) 93 | time.Sleep(100 * time.Millisecond) 94 | 95 | // Commit 96 | c := message.NewCommit() 97 | session.AsyncRPC(c, defaultLogRpcReplyCallback(c.MessageID)) 98 | time.Sleep(100 * time.Millisecond) 99 | 100 | // Unlock 101 | u := message.NewUnlock(message.DatastoreCandidate) 102 | session.AsyncRPC(u, defaultLogRpcReplyCallback(u.MessageID)) 103 | time.Sleep(100 * time.Millisecond) 104 | 105 | // RPC 106 | d := " \n 9\n frozen-waffle\n " 107 | rpc := message.NewRPC(d) 108 | session.AsyncRPC(rpc, defaultLogRpcReplyCallback(rpc.MessageID)) 109 | time.Sleep(100 * time.Millisecond) 110 | 111 | // RPCs 112 | rpc0 := message.NewGetConfig(message.DatastoreRunning, "", "") 113 | reply, _ := session.SyncRPC(rpc0, 1) 114 | println(fmt.Printf("blabla %s\n", reply.RawReply)) 115 | 116 | rpc2 := message.NewRPC(d) 117 | syncRPC, _ := session.SyncRPC(rpc2, 1) 118 | println(fmt.Printf("blabla %s\n", syncRPC.RawReply)) 119 | 120 | rpc3 := message.NewRPC(d) 121 | session.SyncRPC(rpc3, 1) 122 | rpc4 := message.NewRPC(d) 123 | session.SyncRPC(rpc4, 1) 124 | 125 | // Close Session 126 | d2 := message.NewCloseSession() 127 | session.AsyncRPC(d2, defaultLogRpcReplyCallback(d2.MessageID)) 128 | 129 | session.Listener.WaitForMessages() 130 | } 131 | 132 | func createSession(port int) *netconf.Session { 133 | sshConfig := &ssh.ClientConfig{ 134 | User: "admin", 135 | Auth: []ssh.AuthMethod{ssh.Password("admin")}, 136 | HostKeyCallback: ssh.InsecureIgnoreHostKey(), 137 | } 138 | 139 | logger := slog.New(slog.NewJSONHandler(os.Stdout, nil)) 140 | s, err := netconf.NewSessionFromSSHConfig(fmt.Sprintf("127.0.0.1:%d", port), sshConfig, netconf.WithSessionLogger(logger)) 141 | if err != nil { 142 | log.Fatal(err) 143 | } 144 | 145 | capabilities := netconf.DefaultCapabilities 146 | err = s.SendHello(&message.Hello{Capabilities: capabilities}) 147 | if err != nil { 148 | log.Fatal(err) 149 | } 150 | 151 | return s 152 | } 153 | 154 | func defaultLogRpcReplyCallback(eventId string) netconf.Callback { 155 | return func(event netconf.Event) { 156 | reply := event.RPCReply() 157 | if reply == nil { 158 | println("Failed to execute RPC") 159 | } 160 | if event.EventID() == eventId { 161 | println("Successfully executed RPC") 162 | println(reply.RawReply) 163 | } 164 | } 165 | } 166 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/openshift-telco/go-netconf-client 2 | 3 | go 1.22.2 4 | 5 | require golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 6 | 7 | require golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e // indirect 8 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 h1:7I4JAnoQBe7ZtJcBaYHi5UtiO8tQHbUSXxL+pnGRANg= 2 | golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= 3 | golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e h1:WUoyKPm6nCo1BnNUvPGnFG3T5DUVem42yDJZZ4CNxMA= 4 | golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 5 | golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E= 6 | golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= 7 | -------------------------------------------------------------------------------- /netconf/events.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2021. Alexis de Talhouët 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package netconf 18 | 19 | import ( 20 | "github.com/openshift-telco/go-netconf-client/netconf/message" 21 | "time" 22 | ) 23 | 24 | /** 25 | This file is meant to provide all the necessary tooling to support callback mechanism. 26 | It is to be used to subscribe listeners when NETCONF RPCs or Notifications are sent, in 27 | order to process their response. 28 | */ 29 | 30 | // Names of event types 31 | var eventTypeStrings = [...]string{ 32 | "rpc-reply", "notification", 33 | } 34 | 35 | // EventType is an enumeration of the kind of events that can occur. 36 | type EventType uint16 37 | 38 | // String returns the name of event types 39 | func (t EventType) String() string { 40 | return eventTypeStrings[t] 41 | } 42 | 43 | // Callback is a function that can receive events. 44 | type Callback func(Event) 45 | 46 | // Dispatcher objects can register callbacks for specific events, then when 47 | // those events occur, dispatch them its according callback functions. 48 | type Dispatcher struct { 49 | callbacks map[string]Callback 50 | } 51 | 52 | // init a dispatcher creating the callbacks map. 53 | func (d *Dispatcher) init() { 54 | d.callbacks = make(map[string]Callback) 55 | } 56 | 57 | // Register a callback function for the specified eventID. 58 | func (d *Dispatcher) Register(eventID string, callback Callback) { 59 | d.callbacks[eventID] = callback 60 | } 61 | 62 | // Remove a callback function for the specified eventID. 63 | func (d *Dispatcher) Remove(eventID string) { 64 | delete(d.callbacks, eventID) 65 | } 66 | 67 | // WaitForMessages waits for all messages in the queue to be processed 68 | // TODO support timeout 69 | func (d *Dispatcher) WaitForMessages() { 70 | for len(d.callbacks) != 0 { 71 | time.Sleep(1 * time.Second) 72 | } 73 | } 74 | 75 | // Dispatch an event by triggering its associated callback. 76 | // FIXME manage errors 77 | func (d *Dispatcher) Dispatch(eventID string, eventType EventType, value interface{}) { 78 | // Create the event 79 | e := &event{ 80 | eventID: eventID, 81 | value: value, 82 | } 83 | 84 | // Dispatch the event to the callback 85 | callback := d.callbacks[eventID] 86 | if callback == nil { 87 | return 88 | } 89 | callback(e) 90 | 91 | // In case of rpc-reply, auto-remove registration 92 | // If it is a notification, we need to keep the registration active 93 | // as we can have still receive notification related to the subscriptionID 94 | switch eventType.String() { 95 | case "rpc-reply": 96 | d.Remove(eventID) 97 | case "notification": 98 | // NOOP 99 | } 100 | } 101 | 102 | // Event represents actions that occur during NETCONF exchange. Listeners can 103 | // register callbacks with event handlers when creating a new RPC. 104 | type Event interface { 105 | EventID() string 106 | Value() interface{} 107 | RPCReply() *message.RPCReply 108 | Notification() *message.Notification 109 | } 110 | 111 | // event is an internal implementation of the Event interface. 112 | type event struct { 113 | eventID string 114 | value interface{} 115 | } 116 | 117 | // EventID returns the eventID 118 | func (e *event) EventID() string { 119 | return e.eventID 120 | } 121 | 122 | // Value returns the current value associated with the event. 123 | func (e *event) Value() interface{} { 124 | return e.value 125 | } 126 | 127 | // RPCReply returns an RPCReply from the associated value. 128 | func (e *event) RPCReply() *message.RPCReply { 129 | r, ok := e.value.(*message.RPCReply) 130 | if ok { 131 | return r 132 | } 133 | return nil 134 | } 135 | 136 | // Notification returns a Notification from the associated value. 137 | func (e *event) Notification() *message.Notification { 138 | n, ok := e.value.(*message.Notification) 139 | if ok { 140 | return n 141 | } 142 | return nil 143 | } 144 | -------------------------------------------------------------------------------- /netconf/message/commit.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2021. Alexis de Talhouët 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package message 18 | 19 | // Commit represents the NETCONF `commit` message. 20 | // https://datatracker.ietf.org/doc/html/rfc6241#section-8.3.4.1 21 | type Commit struct { 22 | RPC 23 | Commit interface{} `xml:"commit"` 24 | } 25 | 26 | // NewCommit can be used to create a `commit` message. 27 | func NewCommit() *Commit { 28 | var rpc Commit 29 | rpc.Commit = "" 30 | rpc.MessageID = uuid() 31 | return &rpc 32 | } 33 | -------------------------------------------------------------------------------- /netconf/message/common.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2021. Alexis de Talhouët 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package message 18 | 19 | import ( 20 | "crypto/rand" 21 | "encoding/xml" 22 | "fmt" 23 | "io" 24 | ) 25 | 26 | const ( 27 | // FilterTypeSubtree represent the filter for get operation 28 | FilterTypeSubtree string = "subtree" 29 | // DatastoreStartup represents the startup datastore 30 | DatastoreStartup string = "startup" 31 | // DatastoreRunning represents the running datastore 32 | DatastoreRunning string = "running" 33 | // DatastoreCandidate represents the candidate datastore 34 | DatastoreCandidate string = "candidate" 35 | // NetconfVersion10 is the XMLNS representing NETCONF 1.0 version 36 | NetconfVersion10 string = "urn:ietf:params:netconf:base:1.0" 37 | // NetconfVersion11 is the XMLNS representing NETCONF 1.1 version 38 | NetconfVersion11 string = "urn:ietf:params:netconf:base:1.1" 39 | ) 40 | 41 | // Filter represents the filter parameter of `get` message. 42 | // Find examples here: https://datatracker.ietf.org/doc/html/rfc6241#section-6.4 43 | type Filter struct { 44 | XMLName xml.Name `xml:"filter,omitempty"` 45 | // Type defines the filter to use. Defaults to "subtree" and can support "XPath" if the server supports it. 46 | Type string `xml:"type,attr,omitempty"` 47 | Data interface{} `xml:",innerxml"` 48 | } 49 | 50 | // Datastore represents a NETCONF data store element 51 | type Datastore struct { 52 | Candidate interface{} `xml:"candidate,omitempty"` 53 | Running interface{} `xml:"running,omitempty"` 54 | Startup interface{} `xml:"startup,omitempty"` 55 | } 56 | 57 | // datastore returns a Datastore object populated with appropriate datastoreType 58 | func datastore(datastoreType string) *Datastore { 59 | validateDatastore(datastoreType) 60 | switch datastoreType { 61 | case DatastoreStartup: 62 | return &Datastore{Startup: ""} 63 | case DatastoreRunning: 64 | return &Datastore{Running: ""} 65 | case DatastoreCandidate: 66 | return &Datastore{Candidate: ""} 67 | } 68 | return nil // should never get there 69 | } 70 | 71 | // uuid generates a "good enough" uuid 72 | func uuid() string { 73 | b := make([]byte, 16) 74 | _, _ = io.ReadFull(rand.Reader, b) 75 | b[6] = (b[6] & 0x0f) | 0x40 76 | b[8] = (b[8] & 0x3f) | 0x80 77 | return fmt.Sprintf("%x-%x-%x-%x-%x", b[0:4], b[4:6], b[6:8], b[8:10], b[10:]) 78 | } 79 | 80 | // ValidateXML checks a provided string can be properly unmarshall in the specified struct 81 | func ValidateXML(data string, dataStruct interface{}) { 82 | err := xml.Unmarshal([]byte(data), &dataStruct) 83 | if err != nil { 84 | panic(fmt.Errorf("provided XML is not valid: %s. \n%s", data, err)) 85 | } 86 | } 87 | 88 | // validateDatastore checks the provided string is a supported Datastore 89 | func validateDatastore(datastore string) { 90 | switch datastore { 91 | case DatastoreStartup: 92 | return 93 | case DatastoreRunning: 94 | return 95 | case DatastoreCandidate: 96 | return 97 | } 98 | panic( 99 | fmt.Errorf( 100 | "provided datastore is not valid: %s. Expecting `%s` or `%s`", datastore, DatastoreRunning, 101 | DatastoreCandidate, 102 | ), 103 | ) 104 | } 105 | 106 | // validateFilterType checks the provided string is a supported FilterType 107 | func validateFilterType(filterType string) { 108 | switch filterType { 109 | case FilterTypeSubtree: 110 | return 111 | } 112 | panic( 113 | fmt.Errorf("provided filterType is not valid: %s. Expecting `%s`", filterType, FilterTypeSubtree), 114 | ) 115 | } 116 | -------------------------------------------------------------------------------- /netconf/message/copy-config.go: -------------------------------------------------------------------------------- 1 | package message 2 | 3 | // CopyConfig represents the NETCONF `copy-config` operation. 4 | // https://datatracker.ietf.org/doc/html/rfc6241#section-7.3 5 | type CopyConfig struct { 6 | RPC 7 | Target *Datastore `xml:"copy-config>target"` 8 | Source *Datastore `xml:"copy-config>source"` 9 | } 10 | 11 | // NewCopyConfig can be used to create a `copy-config` message. 12 | func NewCopyConfig(target string, source string) *CopyConfig { 13 | var rpc CopyConfig 14 | rpc.Target = datastore(target) 15 | rpc.Source = datastore(source) 16 | rpc.MessageID = uuid() 17 | return &rpc 18 | } 19 | -------------------------------------------------------------------------------- /netconf/message/edit-config.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2021. Alexis de Talhouët 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package message 18 | 19 | import "fmt" 20 | 21 | const ( 22 | // DefaultOperationTypeMerge represents the default operation to apply when doing an edit-config operation 23 | DefaultOperationTypeMerge string = "merge" 24 | // DefaultOperationTypeReplace represents the default operation to apply when doing an edit-config operation 25 | DefaultOperationTypeReplace string = "replace" 26 | // DefaultOperationTypeNone represents the default operation to apply when doing an edit-config operation 27 | DefaultOperationTypeNone string = "none" 28 | ) 29 | 30 | // EditConfig represents the NETCONF `edit-config` operation. 31 | // https://datatracker.ietf.org/doc/html/rfc6241#section-7.2 32 | type EditConfig struct { 33 | RPC 34 | Target *Datastore `xml:"edit-config>target"` 35 | DefaultOperation string `xml:"edit-config>default-operation,omitempty"` 36 | Config *config `xml:"edit-config>config"` 37 | } 38 | 39 | type config struct { 40 | Config interface{} `xml:",innerxml"` 41 | } 42 | 43 | // NewEditConfig can be used to create a `edit-config` message. 44 | func NewEditConfig(datastoreType string, operationType string, data string) *EditConfig { 45 | ValidateXML(data, config{}) 46 | validDefaultOperation(operationType) 47 | 48 | var rpc EditConfig 49 | rpc.Target = datastore(datastoreType) 50 | rpc.DefaultOperation = operationType 51 | rpc.Config = &config{Config: data} 52 | rpc.MessageID = uuid() 53 | return &rpc 54 | } 55 | 56 | func validDefaultOperation(operation string) { 57 | switch operation { 58 | case DefaultOperationTypeMerge: 59 | return 60 | case DefaultOperationTypeReplace: 61 | return 62 | case DefaultOperationTypeNone: 63 | return 64 | } 65 | panic( 66 | fmt.Errorf( 67 | "provided operation is not valid: %s. Expecting either `%s`, `%s`, or `%s`", operation, 68 | DefaultOperationTypeMerge, DefaultOperationTypeNone, DefaultOperationTypeReplace, 69 | ), 70 | ) 71 | } 72 | -------------------------------------------------------------------------------- /netconf/message/get.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2021. Alexis de Talhouët 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package message 18 | 19 | // Get represents the NETCONF `get` message. 20 | // https://datatracker.ietf.org/doc/html/rfc6241#section-7.7 21 | type Get struct { 22 | RPC 23 | Get struct { 24 | Filter *Filter `xml:"filter"` 25 | } `xml:"get"` 26 | } 27 | 28 | // NewGet can be used to create a `get` message. 29 | func NewGet(filterType string, data string) *Get { 30 | var rpc Get 31 | if data != "" { 32 | ValidateXML(data, Filter{}) 33 | validateFilterType(filterType) 34 | 35 | filter := Filter{ 36 | Type: filterType, 37 | Data: data, 38 | } 39 | rpc.Get.Filter = &filter 40 | } 41 | rpc.MessageID = uuid() 42 | return &rpc 43 | } 44 | -------------------------------------------------------------------------------- /netconf/message/getconfig.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2021. Alexis de Talhouët 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package message 18 | 19 | // GetConfig represents the NETCONF `get-config` message. 20 | // https://datatracker.ietf.org/doc/html/rfc6241#section-7.1 21 | type GetConfig struct { 22 | RPC 23 | Source *Datastore `xml:"get-config>source"` 24 | Filter *Filter `xml:"get-config>filter"` 25 | } 26 | 27 | // NewGetConfig can be used to create a `get-config` message. 28 | func NewGetConfig(datastoreType string, filterType string, filterData string) *GetConfig { 29 | var rpc GetConfig 30 | if filterData != "" { 31 | ValidateXML(filterData, Filter{}) 32 | validateFilterType(filterType) 33 | 34 | filter := Filter{ 35 | Type: filterType, 36 | Data: filterData, 37 | } 38 | rpc.Filter = &filter 39 | } 40 | rpc.Source = datastore(datastoreType) 41 | rpc.MessageID = uuid() 42 | return &rpc 43 | } 44 | -------------------------------------------------------------------------------- /netconf/message/hello.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2021. Alexis de Talhouët 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package message 18 | 19 | import "encoding/xml" 20 | 21 | // Hello is the message sent when a new NETCONF session is established. 22 | // https://datatracker.ietf.org/doc/html/rfc6241#section-8.1 23 | type Hello struct { 24 | XMLName xml.Name `xml:"urn:ietf:params:xml:ns:netconf:base:1.0 hello"` 25 | Capabilities []string `xml:"capabilities>capability"` 26 | SessionID int `xml:"session-id,omitempty"` 27 | } 28 | -------------------------------------------------------------------------------- /netconf/message/lock.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2021. Alexis de Talhouët 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package message 18 | 19 | // Lock represents the NETCONF `lock` message. 20 | // https://datatracker.ietf.org/doc/html/rfc6241#section-7.5 21 | type Lock struct { 22 | RPC 23 | Target *Datastore `xml:"lock>target"` 24 | } 25 | 26 | // NewLock can be used to create a `lock` message. 27 | func NewLock(datastoreType string) *Lock { 28 | var rpc Lock 29 | rpc.Target = datastore(datastoreType) 30 | rpc.MessageID = uuid() 31 | return &rpc 32 | } 33 | -------------------------------------------------------------------------------- /netconf/message/notification.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2021. Alexis de Talhouët 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package message 18 | 19 | import "encoding/xml" 20 | 21 | const ( 22 | // NetconfNotificationXmlns is the XMLNS for the YANG model supporting NETCONF notification 23 | NetconfNotificationXmlns = "urn:ietf:params:xml:ns:netconf:notification:1.0" 24 | // NetconfNotificationStreamHandler identifies the callback registration for a `create-subscription` 25 | NetconfNotificationStreamHandler = "DEFAULT_NOTIFICATION_STREAM" 26 | NotificationMessageRegex = ".*notification" 27 | ) 28 | 29 | // Notification defines a reply to a Notification 30 | type Notification struct { 31 | XMLName xml.Name `xml:"notification"` 32 | XMLNS string `xml:"xmlns,attr"` 33 | EventTime string `xml:"eventTime"` 34 | EventData string `xml:"eventData,omitempty"` 35 | // The ietf-yang-push model cisco is using isn't following rfc8641, hence accommodating here. 36 | // https://github.com/YangModels/yang/blob/master/vendor/cisco/xe/1761/ietf-yang-push.yang#L367 37 | SubscriptionIDCisco string `xml:"push-update>subscription-id,omitempty"` 38 | SubscriptionID string `xml:"push-update>id,omitempty"` 39 | RawReply string `xml:"-"` 40 | Data string `xml:",innerxml"` 41 | } 42 | 43 | // GetSubscriptionID returns the subscriptionID 44 | func (notification *Notification) GetSubscriptionID() string { 45 | if notification.SubscriptionID != "" { 46 | return notification.SubscriptionID 47 | } 48 | if notification.SubscriptionIDCisco != "" { 49 | return notification.SubscriptionIDCisco 50 | } 51 | return "" 52 | } 53 | 54 | // NewNotification creates an instance of an Notification based on what was received 55 | func NewNotification(rawXML []byte) (*Notification, error) { 56 | reply := &Notification{} 57 | reply.RawReply = string(rawXML) 58 | 59 | if err := xml.Unmarshal(rawXML, reply); err != nil { 60 | return nil, err 61 | } 62 | 63 | return reply, nil 64 | } 65 | 66 | // CreateSubscription represents the NETCONF `create-subscription` message. 67 | // https://datatracker.ietf.org/doc/html/rfc5277#section-2.1.1 68 | type CreateSubscription struct { 69 | RPC 70 | Subscription CreateSubscriptionData `xml:"create-subscription"` 71 | } 72 | 73 | // CreateSubscriptionData is the struct to create a `create-subscription` message 74 | type CreateSubscriptionData struct { 75 | XMLNS string `xml:"xmlns,attr"` 76 | Stream string `xml:"stream,omitempty"` // default is NETCONF 77 | StartTime string `xml:"startTime,omitempty"` 78 | StopTime string `xml:"stopTime,omitempty"` 79 | } 80 | 81 | // NewCreateSubscriptionDefault can be used to create a `create-subscription` message for the NETCONF stream. 82 | func NewCreateSubscriptionDefault() *CreateSubscription { 83 | var rpc CreateSubscription 84 | var sub = &CreateSubscriptionData{ 85 | NetconfNotificationXmlns, "", "", "", 86 | } 87 | rpc.Subscription = *sub 88 | rpc.MessageID = uuid() 89 | return &rpc 90 | } 91 | 92 | // NewCreateSubscription can be used to create a `create-subscription` message. 93 | func NewCreateSubscription(stopTime string, startTime string, stream string) *CreateSubscription { 94 | var rpc CreateSubscription 95 | var sub = &CreateSubscriptionData{ 96 | NetconfNotificationXmlns, stream, startTime, stopTime, 97 | } 98 | rpc.Subscription = *sub 99 | rpc.MessageID = uuid() 100 | return &rpc 101 | } 102 | 103 | // EstablishSubscription represents the NETCONF `establish-subscription` message. 104 | // https://datatracker.ietf.org/doc/html/rfc8639#section-2.4.2 105 | // FIXME very very weak implementation: there is no validation made on the schema 106 | type EstablishSubscription struct { 107 | RPC 108 | Data string `xml:",innerxml"` 109 | } 110 | 111 | // NewEstablishSubscription can be used to create a `establish-subscription` message. 112 | func NewEstablishSubscription(data string) *EstablishSubscription { 113 | var rpc EstablishSubscription 114 | rpc.Data = data 115 | rpc.MessageID = uuid() 116 | return &rpc 117 | } 118 | -------------------------------------------------------------------------------- /netconf/message/rpc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2021. Alexis de Talhouët 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package message 18 | 19 | import ( 20 | "encoding/xml" 21 | "fmt" 22 | ) 23 | 24 | const RpcReplyRegex = ".*rpc-reply" 25 | 26 | // RPCMethod defines the interface for creating an RPC method. 27 | // This is mostly a marker interface to abstract all RPCs 28 | type RPCMethod interface { 29 | GetMessageID() string 30 | } 31 | 32 | // RPC is used as a wrapper for any sent RPC 33 | type RPC struct { 34 | XMLName xml.Name `xml:"urn:ietf:params:xml:ns:netconf:base:1.0 rpc"` 35 | MessageID string `xml:"message-id,attr"` 36 | Data interface{} `xml:",innerxml"` 37 | } 38 | 39 | // GetMessageID returns the message-id of the RPC 40 | func (rpc *RPC) GetMessageID() string { 41 | return rpc.MessageID 42 | } 43 | 44 | // NewRPC formats an RPC message 45 | func NewRPC(data interface{}) *RPC { 46 | reply := &RPC{} 47 | reply.MessageID = uuid() 48 | reply.Data = data 49 | 50 | return reply 51 | } 52 | 53 | // RPCError defines an error reply to a RPC request 54 | type RPCError struct { 55 | Type string `xml:"error-type"` 56 | Tag string `xml:"error-tag"` 57 | Severity string `xml:"error-severity"` 58 | Path string `xml:"error-path"` 59 | Message string `xml:"error-message"` 60 | Info string `xml:",innerxml"` 61 | } 62 | 63 | // Error generates a string representation of the provided RPC error 64 | func (re *RPCError) Error() string { 65 | return fmt.Sprintf("netconf rpc [%s] '%s'", re.Severity, re.Message) 66 | } 67 | 68 | // RPCReply defines a reply to a RPC request 69 | type RPCReply struct { 70 | XMLName xml.Name `xml:"rpc-reply"` //urn:ietf:params:xml:ns:netconf:base:1.0 71 | MessageID string `xml:"message-id,attr"` 72 | Errors []RPCError `xml:"rpc-error,omitempty"` 73 | Data string `xml:",innerxml"` 74 | Ok bool `xml:"ok,omitempty"` 75 | RawReply string `xml:"-"` 76 | // this is in the case we are receiving a reply to a NETCONF notification subscription 77 | SubscriptionID string `xml:"subscription-id,omitempty"` 78 | } 79 | 80 | // NewRPCReply creates an instance of an RPCReply based on what was received 81 | func NewRPCReply(rawXML []byte) (*RPCReply, error) { 82 | reply := &RPCReply{} 83 | reply.RawReply = string(rawXML) 84 | 85 | if err := xml.Unmarshal(rawXML, reply); err != nil { 86 | return nil, err 87 | } 88 | 89 | return reply, nil 90 | } 91 | -------------------------------------------------------------------------------- /netconf/message/session.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2021. Alexis de Talhouët 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package message 18 | 19 | // CloseSession represents the NETCONF `close-session` message. 20 | // https://datatracker.ietf.org/doc/html/rfc6241#section-7.8 21 | type CloseSession struct { 22 | RPC 23 | CloseSession interface{} `xml:"close-session"` 24 | } 25 | 26 | // NewCloseSession can be used to create a `close-session` message. 27 | func NewCloseSession() *CloseSession { 28 | var rpc CloseSession 29 | rpc.CloseSession = "" 30 | rpc.MessageID = uuid() 31 | return &rpc 32 | } 33 | 34 | // KillSession represents the NETCONF `kill-session` message. 35 | // https://datatracker.ietf.org/doc/html/rfc6241#section-7.8 36 | type KillSession struct { 37 | RPC 38 | SessionID string `xml:"kill-session>session-id"` 39 | } 40 | 41 | // NewKillSession can be used to create a `kill-session` message. 42 | func NewKillSession(sessionID string) *KillSession { 43 | var rpc KillSession 44 | rpc.SessionID = sessionID 45 | rpc.MessageID = uuid() 46 | return &rpc 47 | } 48 | -------------------------------------------------------------------------------- /netconf/message/unlock.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2021. Alexis de Talhouët 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package message 18 | 19 | // Unlock represents the NETCONF `unlock` message. 20 | // https://datatracker.ietf.org/doc/html/rfc6241#section-7.6 21 | type Unlock struct { 22 | RPC 23 | Target *Datastore `xml:"unlock>target"` 24 | } 25 | 26 | // NewUnlock can be used to create a `unlock` message. 27 | func NewUnlock(datastoreType string) *Unlock { 28 | var rpc Unlock 29 | rpc.Target = datastore(datastoreType) 30 | rpc.MessageID = uuid() 31 | return &rpc 32 | } 33 | -------------------------------------------------------------------------------- /netconf/message/validate.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2021. Alexis de Talhouët 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package message 18 | 19 | // Validate represents the NETCONF `validate` message. 20 | // https://datatracker.ietf.org/doc/html/rfc6241#section-8.6.4.1 21 | type Validate struct { 22 | RPC 23 | Source *Datastore `xml:"validate>source"` 24 | } 25 | 26 | // NewValidate can be used to create a `lock` message. 27 | func NewValidate(datastoreType string) *Validate { 28 | var rpc Validate 29 | rpc.Source = datastore(datastoreType) 30 | rpc.MessageID = uuid() 31 | return &rpc 32 | } 33 | -------------------------------------------------------------------------------- /netconf/operations.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2021. Alexis de Talhouët 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package netconf 18 | 19 | import ( 20 | "encoding/xml" 21 | "errors" 22 | "fmt" 23 | "time" 24 | 25 | "github.com/openshift-telco/go-netconf-client/netconf/message" 26 | ) 27 | 28 | // CreateNotificationStream is a convenient method to create a notification stream registration. 29 | // TODO limitation - for now, we can only register one stream per session, because when a notification is received 30 | // there is no way to attribute it to a specific stream 31 | func (session *Session) CreateNotificationStream( 32 | timeout int32, stopTime string, startTime string, stream string, callback Callback, 33 | ) error { 34 | if session.IsNotificationStreamCreated { 35 | return fmt.Errorf( 36 | "there is already an active notification stream subscription. " + 37 | "A session can only support one notification stream at the time", 38 | ) 39 | } 40 | session.Listener.Register(message.NetconfNotificationStreamHandler, callback) 41 | sub := message.NewCreateSubscription(stopTime, startTime, stream) 42 | rpc, err := session.SyncRPC(sub, timeout) 43 | if err != nil { 44 | errMsg := "fail to create notification stream" 45 | if rpc != nil && len(rpc.Errors) != 0 { 46 | errMsg += fmt.Sprintf(" with errors: %s", rpc.Errors) 47 | } 48 | return fmt.Errorf("%s: %w", errMsg, err) 49 | } 50 | session.IsNotificationStreamCreated = true 51 | return nil 52 | } 53 | 54 | // AsyncRPC is used to send an RPC method and receive the response asynchronously. 55 | func (session *Session) AsyncRPC(operation message.RPCMethod, callback Callback) error { 56 | 57 | // get XML payload 58 | request, err := marshall(operation) 59 | if err != nil { 60 | return err 61 | } 62 | 63 | // register the listener for the message 64 | session.Listener.Register(operation.GetMessageID(), callback) 65 | 66 | session.logger.Info("Sending RPC") 67 | err = session.Transport.Send(request) 68 | if err != nil { 69 | return err 70 | } 71 | 72 | return nil 73 | } 74 | 75 | // SyncRPC is used to execute an RPC method and receive the response synchronously 76 | func (session *Session) SyncRPC(operation message.RPCMethod, timeout int32) (*message.RPCReply, error) { 77 | 78 | // get XML payload 79 | request, err := marshall(operation) 80 | if err != nil { 81 | return nil, err 82 | } 83 | 84 | // setup and register callback 85 | reply := make(chan message.RPCReply, 1) 86 | callback := func(event Event) { 87 | reply <- *event.RPCReply() 88 | session.logger.Info("Successfully executed RPC") 89 | } 90 | session.Listener.Register(operation.GetMessageID(), callback) 91 | 92 | // send rpc 93 | session.logger.Info("Sending RPC") 94 | err = session.Transport.Send(request) 95 | if err != nil { 96 | return nil, err 97 | } 98 | 99 | select { 100 | case res := <-reply: 101 | return &res, nil 102 | case <-time.After(time.Duration(timeout) * time.Second): 103 | return nil, errors.New("timeout while executing request") 104 | } 105 | } 106 | 107 | func marshall(operation interface{}) ([]byte, error) { 108 | request, err := xml.Marshal(operation) 109 | if err != nil { 110 | return nil, err 111 | } 112 | 113 | header := []byte(xml.Header) 114 | request = append(header, request...) 115 | return request, nil 116 | } 117 | -------------------------------------------------------------------------------- /netconf/session.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013-2018, Juniper Networks, Inc. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found here 4 | // https://github.com/Juniper/go-netconf/blob/master/LICENSE. 5 | 6 | // The content has been modified from the original version, but the initial code 7 | // remains from Juniper Networks, following above licence. 8 | 9 | package netconf 10 | 11 | import ( 12 | "context" 13 | "encoding/xml" 14 | "io" 15 | "log/slog" 16 | "regexp" 17 | "strings" 18 | 19 | "github.com/openshift-telco/go-netconf-client/netconf/message" 20 | ) 21 | 22 | // DefaultCapabilities sets the default capabilities of the client library. 23 | var DefaultCapabilities = []string{ 24 | message.NetconfVersion10, 25 | message.NetconfVersion11, 26 | } 27 | 28 | type Logger interface { 29 | Info(string, ...any) 30 | Warn(string, ...any) 31 | Error(string, ...any) 32 | InfoContext(context.Context, string, ...any) 33 | WarnContext(context.Context, string, ...any) 34 | ErrorContext(context.Context, string, ...any) 35 | } 36 | 37 | // SessionOption allow optional configuration for the session. 38 | type SessionOption func(*Session) 39 | 40 | // Session represents a NETCONF sessions with a remote NETCONF server. 41 | type Session struct { 42 | Transport Transport 43 | SessionID int 44 | Capabilities []string 45 | IsClosed bool 46 | Listener *Dispatcher 47 | IsNotificationStreamCreated bool 48 | logger Logger 49 | } 50 | 51 | // NewSession creates a new NETCONF session using the provided transport layer. 52 | func NewSession(t Transport, options ...SessionOption) *Session { 53 | s := new(Session) 54 | for _, opt := range options { 55 | opt(s) 56 | } 57 | 58 | if s.logger == nil { 59 | s.logger = slog.New(slog.NewJSONHandler(io.Discard, nil)) 60 | } 61 | 62 | s.Transport = t 63 | 64 | // Receive server Hello message 65 | serverHello, _ := s.ReceiveHello() 66 | s.SessionID = serverHello.SessionID 67 | s.Capabilities = serverHello.Capabilities 68 | 69 | s.Listener = &Dispatcher{} 70 | s.Listener.init() 71 | 72 | return s 73 | } 74 | 75 | // WithSessionLogger set the session logger provided in the session option. 76 | func WithSessionLogger(logger Logger) SessionOption { 77 | return func(s *Session) { 78 | s.logger = logger 79 | } 80 | } 81 | 82 | // SendHello send the initial message through NETCONF to advertise supported capability. 83 | func (session *Session) SendHello(hello *message.Hello) error { 84 | val, err := xml.Marshal(hello) 85 | if err != nil { 86 | return err 87 | } 88 | 89 | header := []byte(xml.Header) 90 | val = append(header, val...) 91 | err = session.Transport.Send(val) 92 | 93 | // Set Transport version after sending hello-message, 94 | // so the hello-message is sent using netconf:1.0 framing 95 | session.Transport.SetVersion("v1.0") 96 | for _, capability := range session.Capabilities { 97 | if strings.Contains(capability, message.NetconfVersion11) { 98 | session.Transport.SetVersion("v1.1") 99 | break 100 | } 101 | } 102 | 103 | // FIXME shouldn't be in SendHello function 104 | // Once the hello-message exchange is done, start listening to incoming messages 105 | session.listen() 106 | 107 | return err 108 | } 109 | 110 | // ReceiveHello is the first message received when connecting to a NETCONF server. 111 | // It provides the supported capabilities of the server. 112 | func (session *Session) ReceiveHello() (*message.Hello, error) { 113 | session.IsClosed = false 114 | 115 | hello := new(message.Hello) 116 | 117 | val, err := session.Transport.Receive() 118 | if err != nil { 119 | return hello, err 120 | } 121 | 122 | err = xml.Unmarshal(val, hello) 123 | return hello, err 124 | } 125 | 126 | // Close is used to close and end a session 127 | func (session *Session) Close() error { 128 | session.IsClosed = true 129 | return session.Transport.Close() 130 | } 131 | 132 | // Listen starts a goroutine that listen to incoming messages and dispatch them as they are processed. 133 | func (session *Session) listen() { 134 | go func() { 135 | for ok := true; ok; ok = !session.IsClosed { 136 | rawXML, err := session.Transport.Receive() 137 | if err != nil { 138 | // What should we do here? 139 | continue 140 | } 141 | var rawReply = string(rawXML) 142 | isRpcReply, err := regexp.MatchString(message.RpcReplyRegex, rawReply) 143 | if err != nil { 144 | session.logger.Error("failed to match RPCReply", 145 | "rawReply", rawReply, 146 | "err", err, 147 | ) 148 | continue 149 | } 150 | 151 | if isRpcReply { 152 | rpcReply, err := message.NewRPCReply(rawXML) 153 | if err != nil { 154 | session.logger.Error("failed to marshall message into an RPCReply", 155 | "err", err, 156 | ) 157 | continue 158 | } 159 | session.Listener.Dispatch(rpcReply.MessageID, 0, rpcReply) 160 | continue 161 | } 162 | 163 | isNotification, err := regexp.MatchString(message.NotificationMessageRegex, rawReply) 164 | if err != nil { 165 | session.logger.Error("failed to match notification", 166 | "rawReply", rawReply, 167 | "err", err, 168 | ) 169 | continue 170 | } 171 | if isNotification { 172 | notification, err := message.NewNotification(rawXML) 173 | if err != nil { 174 | session.logger.Error("failed to marshall message into an Notification", 175 | "err", err, 176 | ) 177 | continue 178 | } 179 | // In case we are using straight create-subscription, there is no way to discern who is the owner 180 | // of the received notification, hence we use a default handler. 181 | if notification.GetSubscriptionID() == "" { 182 | session.Listener.Dispatch(message.NetconfNotificationStreamHandler, 1, notification) 183 | } else { 184 | session.Listener.Dispatch(notification.GetSubscriptionID(), 1, notification) 185 | } 186 | continue 187 | } 188 | 189 | session.logger.Error("unknown received message", 190 | "rawXML", rawXML, 191 | ) 192 | } 193 | session.logger.Info("exit receiving loop") 194 | }() 195 | } 196 | -------------------------------------------------------------------------------- /netconf/sessionfactory.go: -------------------------------------------------------------------------------- 1 | package netconf 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "time" 7 | 8 | "golang.org/x/crypto/ssh" 9 | ) 10 | 11 | // NewSessionFromSSHConfig established a NETCONF session connecting to the target using ssh client configuration. 12 | func NewSessionFromSSHConfig(target string, config *ssh.ClientConfig, options ...SessionOption) (*Session, error) { 13 | t, err := DialSSH(target, config) 14 | if err != nil { 15 | return nil, fmt.Errorf("DialSSHTimeout: %w", err) 16 | } 17 | 18 | s := NewSession(t, options...) 19 | 20 | return s, nil 21 | } 22 | 23 | // NewSessionFromSSHConfigTimeout established a NETCONF session connecting to the target using ssh client configuration with timeout. 24 | func NewSessionFromSSHConfigTimeout(ctx context.Context, target string, config *ssh.ClientConfig, timeout time.Duration, options ...SessionOption) (*Session, error) { 25 | t, err := DialSSHTimeout(target, config, timeout) 26 | if err != nil { 27 | return nil, fmt.Errorf("DialSSHTimeout: %w", err) 28 | } 29 | 30 | s := NewSession(t, options...) 31 | 32 | return s, nil 33 | } 34 | 35 | // NewSessionFromSSHClient established a NETCONF session over a given ssh client. 36 | func NewSessionFromSSHClient(ctx context.Context, client *ssh.Client, options ...SessionOption) (*Session, error) { 37 | t, err := NoDialSSH(client) 38 | if err != nil { 39 | return nil, fmt.Errorf("NoDialSSH: %w", err) 40 | } 41 | 42 | s := NewSession(t, options...) 43 | 44 | return s, nil 45 | } 46 | -------------------------------------------------------------------------------- /netconf/transport_ssh.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013-2018, Juniper Networks, Inc. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found here 4 | // https://github.com/Juniper/go-netconf/blob/master/LICENSE. 5 | 6 | // The content has been modified from the original version, but the initial code 7 | // remains from Juniper Networks, following above licence. 8 | 9 | package netconf 10 | 11 | import ( 12 | "crypto/x509" 13 | "encoding/pem" 14 | "fmt" 15 | "net" 16 | "os" 17 | "strings" 18 | "time" 19 | 20 | "golang.org/x/crypto/ssh" 21 | ) 22 | 23 | const ( 24 | // sshDefaultPort is the default SSH port used when communicating with 25 | // NETCONF 26 | sshDefaultPort = 830 27 | // sshNetconfSubsystem sets the SSH subsystem to NETCONF 28 | sshNetconfSubsystem = "netconf" 29 | ) 30 | 31 | // TransportSSH maintains the information necessary to communicate with the 32 | // remote device over SSH 33 | type TransportSSH struct { 34 | transportBasicIO 35 | sshClient *ssh.Client 36 | sshSession *ssh.Session 37 | } 38 | 39 | // Close closes an existing SSH session and socket if they exist. 40 | func (t *TransportSSH) Close() error { 41 | // If TransportSSH is nil ignore closing ssh session 42 | if t == nil { 43 | return nil 44 | } 45 | 46 | // Close the SSH Session if we have one 47 | if t.sshSession != nil { 48 | if err := t.sshSession.Close(); err != nil { 49 | // If we receive an error when trying to close the session, then 50 | // lets try to close the socket, otherwise it will be left open 51 | err := t.sshClient.Close() 52 | if err != nil { 53 | return err 54 | } 55 | return err 56 | } 57 | } 58 | 59 | // Close the socket 60 | if t.sshClient != nil { 61 | return t.sshClient.Close() 62 | } 63 | return fmt.Errorf("no connection to close") 64 | } 65 | 66 | // Dial connects and establishes SSH sessions 67 | // 68 | // target can be an IP address (e.g.) 172.16.1.1 which utilizes the default 69 | // NETCONF over SSH port of 830. Target can also specify a port with the 70 | // following format : 0 { 166 | return nil, fmt.Errorf("pem: unable to decode file %s", file) 167 | } 168 | 169 | if x509.IsEncryptedPEMBlock(block) { 170 | b, err := x509.DecryptPEMBlock(block, []byte(passphrase)) 171 | if err != nil { 172 | return nil, err 173 | } 174 | buf = pem.EncodeToMemory(&pem.Block{ 175 | Type: block.Type, 176 | Bytes: b, 177 | }) 178 | } 179 | 180 | key, err := ssh.ParsePrivateKey(buf) 181 | if err != nil { 182 | return nil, err 183 | } 184 | return &ssh.ClientConfig{ 185 | User: user, 186 | Auth: []ssh.AuthMethod{ 187 | ssh.PublicKeys(key), 188 | }, 189 | }, nil 190 | 191 | } 192 | 193 | func connToTransport(conn net.Conn, config *ssh.ClientConfig) (*TransportSSH, error) { 194 | c, channel, reqs, err := ssh.NewClientConn(conn, conn.RemoteAddr().String(), config) 195 | if err != nil { 196 | return nil, err 197 | } 198 | 199 | t := &TransportSSH{} 200 | t.sshClient = ssh.NewClient(c, channel, reqs) 201 | 202 | err = t.setupSession() 203 | if err != nil { 204 | return nil, err 205 | } 206 | 207 | return t, nil 208 | } 209 | 210 | type deadlineConn struct { 211 | net.Conn 212 | timeout time.Duration 213 | } 214 | 215 | func (c *deadlineConn) Read(b []byte) (n int, err error) { 216 | _ = c.SetReadDeadline(time.Now().Add(c.timeout)) 217 | return c.Conn.Read(b) 218 | } 219 | 220 | func (c *deadlineConn) Write(b []byte) (n int, err error) { 221 | _ = c.SetWriteDeadline(time.Now().Add(c.timeout)) 222 | return c.Conn.Write(b) 223 | } 224 | 225 | func (t *TransportSSH) setupSession() error { 226 | var err error 227 | 228 | t.sshSession, err = t.sshClient.NewSession() 229 | if err != nil { 230 | return err 231 | } 232 | 233 | writer, err := t.sshSession.StdinPipe() 234 | if err != nil { 235 | return err 236 | } 237 | 238 | reader, err := t.sshSession.StdoutPipe() 239 | if err != nil { 240 | return err 241 | } 242 | 243 | t.ReadWriteCloser = NewReadWriteCloser(reader, writer) 244 | return t.sshSession.RequestSubsystem(sshNetconfSubsystem) 245 | } 246 | -------------------------------------------------------------------------------- /tests/RPCReply_test.go: -------------------------------------------------------------------------------- 1 | package tests 2 | 3 | import ( 4 | "encoding/xml" 5 | "os" 6 | "regexp" 7 | "testing" 8 | 9 | "github.com/openshift-telco/go-netconf-client/netconf/message" 10 | ) 11 | 12 | func TestRPCReply(t *testing.T) { 13 | 14 | input, err := os.ReadFile("resources/junos-rpc-reply.xml") 15 | if err != nil { 16 | t.Fatalf("failed to read resources: %v", err) 17 | } 18 | 19 | // validate we can create RPCReply when it's encapsulated in a xmlns 20 | reply, err := message.NewRPCReply(input) 21 | if err != nil { 22 | t.Fatalf("failed to unmarshal rpc reply: %v", err) 23 | } 24 | 25 | // validate we can marshall the created RPCReply 26 | output, err := xml.Marshal(reply) 27 | if err != nil { 28 | t.Fatalf("failed to marshal rpc reply: %v", err) 29 | } 30 | 31 | if string(input) != string(output) { 32 | t.Errorf("got %q, \nwanted %q", string(input), string(output)) 33 | } 34 | 35 | _, e := regexp.MatchString(message.RpcReplyRegex, string(input)) 36 | if e != nil { 37 | t.Errorf("failed to parse rpc-reply with regex") 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /tests/resources/junos-rpc-reply.xml: -------------------------------------------------------------------------------- 1 | 4 | 6 | 7 | et-0/1/5 8 | up 9 | up 10 | TEST_Description 11 | 12 | 13 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/AUTHORS: -------------------------------------------------------------------------------- 1 | # This source code refers to The Go Authors for copyright purposes. 2 | # The master list of authors is in the main Go distribution, 3 | # visible at https://tip.golang.org/AUTHORS. 4 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | # This source code was written by the Go contributors. 2 | # The master list of contributors is in the main Go distribution, 3 | # visible at https://tip.golang.org/CONTRIBUTORS. 4 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009 The Go Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/PATENTS: -------------------------------------------------------------------------------- 1 | Additional IP Rights Grant (Patents) 2 | 3 | "This implementation" means the copyrightable works distributed by 4 | Google as part of the Go project. 5 | 6 | Google hereby grants to You a perpetual, worldwide, non-exclusive, 7 | no-charge, royalty-free, irrevocable (except as stated in this section) 8 | patent license to make, have made, use, offer to sell, sell, import, 9 | transfer and otherwise run, modify and propagate the contents of this 10 | implementation of Go, where such license applies only to those patent 11 | claims, both currently owned or controlled by Google and acquired in 12 | the future, licensable by Google that are necessarily infringed by this 13 | implementation of Go. This grant does not include claims that would be 14 | infringed only as a consequence of further modification of this 15 | implementation. If you or your agent or exclusive licensee institute or 16 | order or agree to the institution of patent litigation against any 17 | entity (including a cross-claim or counterclaim in a lawsuit) alleging 18 | that this implementation of Go or any code incorporated within this 19 | implementation of Go constitutes direct or contributory patent 20 | infringement, or inducement of patent infringement, then any patent 21 | rights granted to you under this License for this implementation of Go 22 | shall terminate as of the date such litigation is filed. 23 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/blowfish/block.go: -------------------------------------------------------------------------------- 1 | // Copyright 2010 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 blowfish 6 | 7 | // getNextWord returns the next big-endian uint32 value from the byte slice 8 | // at the given position in a circular manner, updating the position. 9 | func getNextWord(b []byte, pos *int) uint32 { 10 | var w uint32 11 | j := *pos 12 | for i := 0; i < 4; i++ { 13 | w = w<<8 | uint32(b[j]) 14 | j++ 15 | if j >= len(b) { 16 | j = 0 17 | } 18 | } 19 | *pos = j 20 | return w 21 | } 22 | 23 | // ExpandKey performs a key expansion on the given *Cipher. Specifically, it 24 | // performs the Blowfish algorithm's key schedule which sets up the *Cipher's 25 | // pi and substitution tables for calls to Encrypt. This is used, primarily, 26 | // by the bcrypt package to reuse the Blowfish key schedule during its 27 | // set up. It's unlikely that you need to use this directly. 28 | func ExpandKey(key []byte, c *Cipher) { 29 | j := 0 30 | for i := 0; i < 18; i++ { 31 | // Using inlined getNextWord for performance. 32 | var d uint32 33 | for k := 0; k < 4; k++ { 34 | d = d<<8 | uint32(key[j]) 35 | j++ 36 | if j >= len(key) { 37 | j = 0 38 | } 39 | } 40 | c.p[i] ^= d 41 | } 42 | 43 | var l, r uint32 44 | for i := 0; i < 18; i += 2 { 45 | l, r = encryptBlock(l, r, c) 46 | c.p[i], c.p[i+1] = l, r 47 | } 48 | 49 | for i := 0; i < 256; i += 2 { 50 | l, r = encryptBlock(l, r, c) 51 | c.s0[i], c.s0[i+1] = l, r 52 | } 53 | for i := 0; i < 256; i += 2 { 54 | l, r = encryptBlock(l, r, c) 55 | c.s1[i], c.s1[i+1] = l, r 56 | } 57 | for i := 0; i < 256; i += 2 { 58 | l, r = encryptBlock(l, r, c) 59 | c.s2[i], c.s2[i+1] = l, r 60 | } 61 | for i := 0; i < 256; i += 2 { 62 | l, r = encryptBlock(l, r, c) 63 | c.s3[i], c.s3[i+1] = l, r 64 | } 65 | } 66 | 67 | // This is similar to ExpandKey, but folds the salt during the key 68 | // schedule. While ExpandKey is essentially expandKeyWithSalt with an all-zero 69 | // salt passed in, reusing ExpandKey turns out to be a place of inefficiency 70 | // and specializing it here is useful. 71 | func expandKeyWithSalt(key []byte, salt []byte, c *Cipher) { 72 | j := 0 73 | for i := 0; i < 18; i++ { 74 | c.p[i] ^= getNextWord(key, &j) 75 | } 76 | 77 | j = 0 78 | var l, r uint32 79 | for i := 0; i < 18; i += 2 { 80 | l ^= getNextWord(salt, &j) 81 | r ^= getNextWord(salt, &j) 82 | l, r = encryptBlock(l, r, c) 83 | c.p[i], c.p[i+1] = l, r 84 | } 85 | 86 | for i := 0; i < 256; i += 2 { 87 | l ^= getNextWord(salt, &j) 88 | r ^= getNextWord(salt, &j) 89 | l, r = encryptBlock(l, r, c) 90 | c.s0[i], c.s0[i+1] = l, r 91 | } 92 | 93 | for i := 0; i < 256; i += 2 { 94 | l ^= getNextWord(salt, &j) 95 | r ^= getNextWord(salt, &j) 96 | l, r = encryptBlock(l, r, c) 97 | c.s1[i], c.s1[i+1] = l, r 98 | } 99 | 100 | for i := 0; i < 256; i += 2 { 101 | l ^= getNextWord(salt, &j) 102 | r ^= getNextWord(salt, &j) 103 | l, r = encryptBlock(l, r, c) 104 | c.s2[i], c.s2[i+1] = l, r 105 | } 106 | 107 | for i := 0; i < 256; i += 2 { 108 | l ^= getNextWord(salt, &j) 109 | r ^= getNextWord(salt, &j) 110 | l, r = encryptBlock(l, r, c) 111 | c.s3[i], c.s3[i+1] = l, r 112 | } 113 | } 114 | 115 | func encryptBlock(l, r uint32, c *Cipher) (uint32, uint32) { 116 | xl, xr := l, r 117 | xl ^= c.p[0] 118 | xr ^= ((c.s0[byte(xl>>24)] + c.s1[byte(xl>>16)]) ^ c.s2[byte(xl>>8)]) + c.s3[byte(xl)] ^ c.p[1] 119 | xl ^= ((c.s0[byte(xr>>24)] + c.s1[byte(xr>>16)]) ^ c.s2[byte(xr>>8)]) + c.s3[byte(xr)] ^ c.p[2] 120 | xr ^= ((c.s0[byte(xl>>24)] + c.s1[byte(xl>>16)]) ^ c.s2[byte(xl>>8)]) + c.s3[byte(xl)] ^ c.p[3] 121 | xl ^= ((c.s0[byte(xr>>24)] + c.s1[byte(xr>>16)]) ^ c.s2[byte(xr>>8)]) + c.s3[byte(xr)] ^ c.p[4] 122 | xr ^= ((c.s0[byte(xl>>24)] + c.s1[byte(xl>>16)]) ^ c.s2[byte(xl>>8)]) + c.s3[byte(xl)] ^ c.p[5] 123 | xl ^= ((c.s0[byte(xr>>24)] + c.s1[byte(xr>>16)]) ^ c.s2[byte(xr>>8)]) + c.s3[byte(xr)] ^ c.p[6] 124 | xr ^= ((c.s0[byte(xl>>24)] + c.s1[byte(xl>>16)]) ^ c.s2[byte(xl>>8)]) + c.s3[byte(xl)] ^ c.p[7] 125 | xl ^= ((c.s0[byte(xr>>24)] + c.s1[byte(xr>>16)]) ^ c.s2[byte(xr>>8)]) + c.s3[byte(xr)] ^ c.p[8] 126 | xr ^= ((c.s0[byte(xl>>24)] + c.s1[byte(xl>>16)]) ^ c.s2[byte(xl>>8)]) + c.s3[byte(xl)] ^ c.p[9] 127 | xl ^= ((c.s0[byte(xr>>24)] + c.s1[byte(xr>>16)]) ^ c.s2[byte(xr>>8)]) + c.s3[byte(xr)] ^ c.p[10] 128 | xr ^= ((c.s0[byte(xl>>24)] + c.s1[byte(xl>>16)]) ^ c.s2[byte(xl>>8)]) + c.s3[byte(xl)] ^ c.p[11] 129 | xl ^= ((c.s0[byte(xr>>24)] + c.s1[byte(xr>>16)]) ^ c.s2[byte(xr>>8)]) + c.s3[byte(xr)] ^ c.p[12] 130 | xr ^= ((c.s0[byte(xl>>24)] + c.s1[byte(xl>>16)]) ^ c.s2[byte(xl>>8)]) + c.s3[byte(xl)] ^ c.p[13] 131 | xl ^= ((c.s0[byte(xr>>24)] + c.s1[byte(xr>>16)]) ^ c.s2[byte(xr>>8)]) + c.s3[byte(xr)] ^ c.p[14] 132 | xr ^= ((c.s0[byte(xl>>24)] + c.s1[byte(xl>>16)]) ^ c.s2[byte(xl>>8)]) + c.s3[byte(xl)] ^ c.p[15] 133 | xl ^= ((c.s0[byte(xr>>24)] + c.s1[byte(xr>>16)]) ^ c.s2[byte(xr>>8)]) + c.s3[byte(xr)] ^ c.p[16] 134 | xr ^= c.p[17] 135 | return xr, xl 136 | } 137 | 138 | func decryptBlock(l, r uint32, c *Cipher) (uint32, uint32) { 139 | xl, xr := l, r 140 | xl ^= c.p[17] 141 | xr ^= ((c.s0[byte(xl>>24)] + c.s1[byte(xl>>16)]) ^ c.s2[byte(xl>>8)]) + c.s3[byte(xl)] ^ c.p[16] 142 | xl ^= ((c.s0[byte(xr>>24)] + c.s1[byte(xr>>16)]) ^ c.s2[byte(xr>>8)]) + c.s3[byte(xr)] ^ c.p[15] 143 | xr ^= ((c.s0[byte(xl>>24)] + c.s1[byte(xl>>16)]) ^ c.s2[byte(xl>>8)]) + c.s3[byte(xl)] ^ c.p[14] 144 | xl ^= ((c.s0[byte(xr>>24)] + c.s1[byte(xr>>16)]) ^ c.s2[byte(xr>>8)]) + c.s3[byte(xr)] ^ c.p[13] 145 | xr ^= ((c.s0[byte(xl>>24)] + c.s1[byte(xl>>16)]) ^ c.s2[byte(xl>>8)]) + c.s3[byte(xl)] ^ c.p[12] 146 | xl ^= ((c.s0[byte(xr>>24)] + c.s1[byte(xr>>16)]) ^ c.s2[byte(xr>>8)]) + c.s3[byte(xr)] ^ c.p[11] 147 | xr ^= ((c.s0[byte(xl>>24)] + c.s1[byte(xl>>16)]) ^ c.s2[byte(xl>>8)]) + c.s3[byte(xl)] ^ c.p[10] 148 | xl ^= ((c.s0[byte(xr>>24)] + c.s1[byte(xr>>16)]) ^ c.s2[byte(xr>>8)]) + c.s3[byte(xr)] ^ c.p[9] 149 | xr ^= ((c.s0[byte(xl>>24)] + c.s1[byte(xl>>16)]) ^ c.s2[byte(xl>>8)]) + c.s3[byte(xl)] ^ c.p[8] 150 | xl ^= ((c.s0[byte(xr>>24)] + c.s1[byte(xr>>16)]) ^ c.s2[byte(xr>>8)]) + c.s3[byte(xr)] ^ c.p[7] 151 | xr ^= ((c.s0[byte(xl>>24)] + c.s1[byte(xl>>16)]) ^ c.s2[byte(xl>>8)]) + c.s3[byte(xl)] ^ c.p[6] 152 | xl ^= ((c.s0[byte(xr>>24)] + c.s1[byte(xr>>16)]) ^ c.s2[byte(xr>>8)]) + c.s3[byte(xr)] ^ c.p[5] 153 | xr ^= ((c.s0[byte(xl>>24)] + c.s1[byte(xl>>16)]) ^ c.s2[byte(xl>>8)]) + c.s3[byte(xl)] ^ c.p[4] 154 | xl ^= ((c.s0[byte(xr>>24)] + c.s1[byte(xr>>16)]) ^ c.s2[byte(xr>>8)]) + c.s3[byte(xr)] ^ c.p[3] 155 | xr ^= ((c.s0[byte(xl>>24)] + c.s1[byte(xl>>16)]) ^ c.s2[byte(xl>>8)]) + c.s3[byte(xl)] ^ c.p[2] 156 | xl ^= ((c.s0[byte(xr>>24)] + c.s1[byte(xr>>16)]) ^ c.s2[byte(xr>>8)]) + c.s3[byte(xr)] ^ c.p[1] 157 | xr ^= c.p[0] 158 | return xr, xl 159 | } 160 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/blowfish/cipher.go: -------------------------------------------------------------------------------- 1 | // Copyright 2010 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 blowfish implements Bruce Schneier's Blowfish encryption algorithm. 6 | // 7 | // Blowfish is a legacy cipher and its short block size makes it vulnerable to 8 | // birthday bound attacks (see https://sweet32.info). It should only be used 9 | // where compatibility with legacy systems, not security, is the goal. 10 | // 11 | // Deprecated: any new system should use AES (from crypto/aes, if necessary in 12 | // an AEAD mode like crypto/cipher.NewGCM) or XChaCha20-Poly1305 (from 13 | // golang.org/x/crypto/chacha20poly1305). 14 | package blowfish // import "golang.org/x/crypto/blowfish" 15 | 16 | // The code is a port of Bruce Schneier's C implementation. 17 | // See https://www.schneier.com/blowfish.html. 18 | 19 | import "strconv" 20 | 21 | // The Blowfish block size in bytes. 22 | const BlockSize = 8 23 | 24 | // A Cipher is an instance of Blowfish encryption using a particular key. 25 | type Cipher struct { 26 | p [18]uint32 27 | s0, s1, s2, s3 [256]uint32 28 | } 29 | 30 | type KeySizeError int 31 | 32 | func (k KeySizeError) Error() string { 33 | return "crypto/blowfish: invalid key size " + strconv.Itoa(int(k)) 34 | } 35 | 36 | // NewCipher creates and returns a Cipher. 37 | // The key argument should be the Blowfish key, from 1 to 56 bytes. 38 | func NewCipher(key []byte) (*Cipher, error) { 39 | var result Cipher 40 | if k := len(key); k < 1 || k > 56 { 41 | return nil, KeySizeError(k) 42 | } 43 | initCipher(&result) 44 | ExpandKey(key, &result) 45 | return &result, nil 46 | } 47 | 48 | // NewSaltedCipher creates a returns a Cipher that folds a salt into its key 49 | // schedule. For most purposes, NewCipher, instead of NewSaltedCipher, is 50 | // sufficient and desirable. For bcrypt compatibility, the key can be over 56 51 | // bytes. 52 | func NewSaltedCipher(key, salt []byte) (*Cipher, error) { 53 | if len(salt) == 0 { 54 | return NewCipher(key) 55 | } 56 | var result Cipher 57 | if k := len(key); k < 1 { 58 | return nil, KeySizeError(k) 59 | } 60 | initCipher(&result) 61 | expandKeyWithSalt(key, salt, &result) 62 | return &result, nil 63 | } 64 | 65 | // BlockSize returns the Blowfish block size, 8 bytes. 66 | // It is necessary to satisfy the Block interface in the 67 | // package "crypto/cipher". 68 | func (c *Cipher) BlockSize() int { return BlockSize } 69 | 70 | // Encrypt encrypts the 8-byte buffer src using the key k 71 | // and stores the result in dst. 72 | // Note that for amounts of data larger than a block, 73 | // it is not safe to just call Encrypt on successive blocks; 74 | // instead, use an encryption mode like CBC (see crypto/cipher/cbc.go). 75 | func (c *Cipher) Encrypt(dst, src []byte) { 76 | l := uint32(src[0])<<24 | uint32(src[1])<<16 | uint32(src[2])<<8 | uint32(src[3]) 77 | r := uint32(src[4])<<24 | uint32(src[5])<<16 | uint32(src[6])<<8 | uint32(src[7]) 78 | l, r = encryptBlock(l, r, c) 79 | dst[0], dst[1], dst[2], dst[3] = byte(l>>24), byte(l>>16), byte(l>>8), byte(l) 80 | dst[4], dst[5], dst[6], dst[7] = byte(r>>24), byte(r>>16), byte(r>>8), byte(r) 81 | } 82 | 83 | // Decrypt decrypts the 8-byte buffer src using the key k 84 | // and stores the result in dst. 85 | func (c *Cipher) Decrypt(dst, src []byte) { 86 | l := uint32(src[0])<<24 | uint32(src[1])<<16 | uint32(src[2])<<8 | uint32(src[3]) 87 | r := uint32(src[4])<<24 | uint32(src[5])<<16 | uint32(src[6])<<8 | uint32(src[7]) 88 | l, r = decryptBlock(l, r, c) 89 | dst[0], dst[1], dst[2], dst[3] = byte(l>>24), byte(l>>16), byte(l>>8), byte(l) 90 | dst[4], dst[5], dst[6], dst[7] = byte(r>>24), byte(r>>16), byte(r>>8), byte(r) 91 | } 92 | 93 | func initCipher(c *Cipher) { 94 | copy(c.p[0:], p[0:]) 95 | copy(c.s0[0:], s0[0:]) 96 | copy(c.s1[0:], s1[0:]) 97 | copy(c.s2[0:], s2[0:]) 98 | copy(c.s3[0:], s3[0:]) 99 | } 100 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/chacha20/chacha_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 | //go:build go1.11 && gc && !purego 6 | // +build go1.11,gc,!purego 7 | 8 | package chacha20 9 | 10 | const bufSize = 256 11 | 12 | //go:noescape 13 | func xorKeyStreamVX(dst, src []byte, key *[8]uint32, nonce *[3]uint32, counter *uint32) 14 | 15 | func (c *Cipher) xorKeyStreamBlocks(dst, src []byte) { 16 | xorKeyStreamVX(dst, src, &c.key, &c.nonce, &c.counter) 17 | } 18 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/chacha20/chacha_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 (!arm64 && !s390x && !ppc64le) || (arm64 && !go1.11) || !gc || purego 6 | // +build !arm64,!s390x,!ppc64le arm64,!go1.11 !gc purego 7 | 8 | package chacha20 9 | 10 | const bufSize = blockSize 11 | 12 | func (s *Cipher) xorKeyStreamBlocks(dst, src []byte) { 13 | s.xorKeyStreamBlocksGeneric(dst, src) 14 | } 15 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/chacha20/chacha_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 chacha20 9 | 10 | const bufSize = 256 11 | 12 | //go:noescape 13 | func chaCha20_ctr32_vsx(out, inp *byte, len int, key *[8]uint32, counter *uint32) 14 | 15 | func (c *Cipher) xorKeyStreamBlocks(dst, src []byte) { 16 | chaCha20_ctr32_vsx(&dst[0], &src[0], len(src), &c.key, &c.counter) 17 | } 18 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/chacha20/chacha_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 chacha20 9 | 10 | import "golang.org/x/sys/cpu" 11 | 12 | var haveAsm = cpu.S390X.HasVX 13 | 14 | const bufSize = 256 15 | 16 | // xorKeyStreamVX is an assembly implementation of XORKeyStream. It must only 17 | // be called when the vector facility is available. Implementation in asm_s390x.s. 18 | //go:noescape 19 | func xorKeyStreamVX(dst, src []byte, key *[8]uint32, nonce *[3]uint32, counter *uint32) 20 | 21 | func (c *Cipher) xorKeyStreamBlocks(dst, src []byte) { 22 | if cpu.S390X.HasVX { 23 | xorKeyStreamVX(dst, src, &c.key, &c.nonce, &c.counter) 24 | } else { 25 | c.xorKeyStreamBlocksGeneric(dst, src) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/chacha20/chacha_s390x.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 && !purego 6 | // +build gc,!purego 7 | 8 | #include "go_asm.h" 9 | #include "textflag.h" 10 | 11 | // This is an implementation of the ChaCha20 encryption algorithm as 12 | // specified in RFC 7539. It uses vector instructions to compute 13 | // 4 keystream blocks in parallel (256 bytes) which are then XORed 14 | // with the bytes in the input slice. 15 | 16 | GLOBL ·constants<>(SB), RODATA|NOPTR, $32 17 | // BSWAP: swap bytes in each 4-byte element 18 | DATA ·constants<>+0x00(SB)/4, $0x03020100 19 | DATA ·constants<>+0x04(SB)/4, $0x07060504 20 | DATA ·constants<>+0x08(SB)/4, $0x0b0a0908 21 | DATA ·constants<>+0x0c(SB)/4, $0x0f0e0d0c 22 | // J0: [j0, j1, j2, j3] 23 | DATA ·constants<>+0x10(SB)/4, $0x61707865 24 | DATA ·constants<>+0x14(SB)/4, $0x3320646e 25 | DATA ·constants<>+0x18(SB)/4, $0x79622d32 26 | DATA ·constants<>+0x1c(SB)/4, $0x6b206574 27 | 28 | #define BSWAP V5 29 | #define J0 V6 30 | #define KEY0 V7 31 | #define KEY1 V8 32 | #define NONCE V9 33 | #define CTR V10 34 | #define M0 V11 35 | #define M1 V12 36 | #define M2 V13 37 | #define M3 V14 38 | #define INC V15 39 | #define X0 V16 40 | #define X1 V17 41 | #define X2 V18 42 | #define X3 V19 43 | #define X4 V20 44 | #define X5 V21 45 | #define X6 V22 46 | #define X7 V23 47 | #define X8 V24 48 | #define X9 V25 49 | #define X10 V26 50 | #define X11 V27 51 | #define X12 V28 52 | #define X13 V29 53 | #define X14 V30 54 | #define X15 V31 55 | 56 | #define NUM_ROUNDS 20 57 | 58 | #define ROUND4(a0, a1, a2, a3, b0, b1, b2, b3, c0, c1, c2, c3, d0, d1, d2, d3) \ 59 | VAF a1, a0, a0 \ 60 | VAF b1, b0, b0 \ 61 | VAF c1, c0, c0 \ 62 | VAF d1, d0, d0 \ 63 | VX a0, a2, a2 \ 64 | VX b0, b2, b2 \ 65 | VX c0, c2, c2 \ 66 | VX d0, d2, d2 \ 67 | VERLLF $16, a2, a2 \ 68 | VERLLF $16, b2, b2 \ 69 | VERLLF $16, c2, c2 \ 70 | VERLLF $16, d2, d2 \ 71 | VAF a2, a3, a3 \ 72 | VAF b2, b3, b3 \ 73 | VAF c2, c3, c3 \ 74 | VAF d2, d3, d3 \ 75 | VX a3, a1, a1 \ 76 | VX b3, b1, b1 \ 77 | VX c3, c1, c1 \ 78 | VX d3, d1, d1 \ 79 | VERLLF $12, a1, a1 \ 80 | VERLLF $12, b1, b1 \ 81 | VERLLF $12, c1, c1 \ 82 | VERLLF $12, d1, d1 \ 83 | VAF a1, a0, a0 \ 84 | VAF b1, b0, b0 \ 85 | VAF c1, c0, c0 \ 86 | VAF d1, d0, d0 \ 87 | VX a0, a2, a2 \ 88 | VX b0, b2, b2 \ 89 | VX c0, c2, c2 \ 90 | VX d0, d2, d2 \ 91 | VERLLF $8, a2, a2 \ 92 | VERLLF $8, b2, b2 \ 93 | VERLLF $8, c2, c2 \ 94 | VERLLF $8, d2, d2 \ 95 | VAF a2, a3, a3 \ 96 | VAF b2, b3, b3 \ 97 | VAF c2, c3, c3 \ 98 | VAF d2, d3, d3 \ 99 | VX a3, a1, a1 \ 100 | VX b3, b1, b1 \ 101 | VX c3, c1, c1 \ 102 | VX d3, d1, d1 \ 103 | VERLLF $7, a1, a1 \ 104 | VERLLF $7, b1, b1 \ 105 | VERLLF $7, c1, c1 \ 106 | VERLLF $7, d1, d1 107 | 108 | #define PERMUTE(mask, v0, v1, v2, v3) \ 109 | VPERM v0, v0, mask, v0 \ 110 | VPERM v1, v1, mask, v1 \ 111 | VPERM v2, v2, mask, v2 \ 112 | VPERM v3, v3, mask, v3 113 | 114 | #define ADDV(x, v0, v1, v2, v3) \ 115 | VAF x, v0, v0 \ 116 | VAF x, v1, v1 \ 117 | VAF x, v2, v2 \ 118 | VAF x, v3, v3 119 | 120 | #define XORV(off, dst, src, v0, v1, v2, v3) \ 121 | VLM off(src), M0, M3 \ 122 | PERMUTE(BSWAP, v0, v1, v2, v3) \ 123 | VX v0, M0, M0 \ 124 | VX v1, M1, M1 \ 125 | VX v2, M2, M2 \ 126 | VX v3, M3, M3 \ 127 | VSTM M0, M3, off(dst) 128 | 129 | #define SHUFFLE(a, b, c, d, t, u, v, w) \ 130 | VMRHF a, c, t \ // t = {a[0], c[0], a[1], c[1]} 131 | VMRHF b, d, u \ // u = {b[0], d[0], b[1], d[1]} 132 | VMRLF a, c, v \ // v = {a[2], c[2], a[3], c[3]} 133 | VMRLF b, d, w \ // w = {b[2], d[2], b[3], d[3]} 134 | VMRHF t, u, a \ // a = {a[0], b[0], c[0], d[0]} 135 | VMRLF t, u, b \ // b = {a[1], b[1], c[1], d[1]} 136 | VMRHF v, w, c \ // c = {a[2], b[2], c[2], d[2]} 137 | VMRLF v, w, d // d = {a[3], b[3], c[3], d[3]} 138 | 139 | // func xorKeyStreamVX(dst, src []byte, key *[8]uint32, nonce *[3]uint32, counter *uint32) 140 | TEXT ·xorKeyStreamVX(SB), NOSPLIT, $0 141 | MOVD $·constants<>(SB), R1 142 | MOVD dst+0(FP), R2 // R2=&dst[0] 143 | LMG src+24(FP), R3, R4 // R3=&src[0] R4=len(src) 144 | MOVD key+48(FP), R5 // R5=key 145 | MOVD nonce+56(FP), R6 // R6=nonce 146 | MOVD counter+64(FP), R7 // R7=counter 147 | 148 | // load BSWAP and J0 149 | VLM (R1), BSWAP, J0 150 | 151 | // setup 152 | MOVD $95, R0 153 | VLM (R5), KEY0, KEY1 154 | VLL R0, (R6), NONCE 155 | VZERO M0 156 | VLEIB $7, $32, M0 157 | VSRLB M0, NONCE, NONCE 158 | 159 | // initialize counter values 160 | VLREPF (R7), CTR 161 | VZERO INC 162 | VLEIF $1, $1, INC 163 | VLEIF $2, $2, INC 164 | VLEIF $3, $3, INC 165 | VAF INC, CTR, CTR 166 | VREPIF $4, INC 167 | 168 | chacha: 169 | VREPF $0, J0, X0 170 | VREPF $1, J0, X1 171 | VREPF $2, J0, X2 172 | VREPF $3, J0, X3 173 | VREPF $0, KEY0, X4 174 | VREPF $1, KEY0, X5 175 | VREPF $2, KEY0, X6 176 | VREPF $3, KEY0, X7 177 | VREPF $0, KEY1, X8 178 | VREPF $1, KEY1, X9 179 | VREPF $2, KEY1, X10 180 | VREPF $3, KEY1, X11 181 | VLR CTR, X12 182 | VREPF $1, NONCE, X13 183 | VREPF $2, NONCE, X14 184 | VREPF $3, NONCE, X15 185 | 186 | MOVD $(NUM_ROUNDS/2), R1 187 | 188 | loop: 189 | ROUND4(X0, X4, X12, X8, X1, X5, X13, X9, X2, X6, X14, X10, X3, X7, X15, X11) 190 | ROUND4(X0, X5, X15, X10, X1, X6, X12, X11, X2, X7, X13, X8, X3, X4, X14, X9) 191 | 192 | ADD $-1, R1 193 | BNE loop 194 | 195 | // decrement length 196 | ADD $-256, R4 197 | 198 | // rearrange vectors 199 | SHUFFLE(X0, X1, X2, X3, M0, M1, M2, M3) 200 | ADDV(J0, X0, X1, X2, X3) 201 | SHUFFLE(X4, X5, X6, X7, M0, M1, M2, M3) 202 | ADDV(KEY0, X4, X5, X6, X7) 203 | SHUFFLE(X8, X9, X10, X11, M0, M1, M2, M3) 204 | ADDV(KEY1, X8, X9, X10, X11) 205 | VAF CTR, X12, X12 206 | SHUFFLE(X12, X13, X14, X15, M0, M1, M2, M3) 207 | ADDV(NONCE, X12, X13, X14, X15) 208 | 209 | // increment counters 210 | VAF INC, CTR, CTR 211 | 212 | // xor keystream with plaintext 213 | XORV(0*64, R2, R3, X0, X4, X8, X12) 214 | XORV(1*64, R2, R3, X1, X5, X9, X13) 215 | XORV(2*64, R2, R3, X2, X6, X10, X14) 216 | XORV(3*64, R2, R3, X3, X7, X11, X15) 217 | 218 | // increment pointers 219 | MOVD $256(R2), R2 220 | MOVD $256(R3), R3 221 | 222 | CMPBNE R4, $0, chacha 223 | 224 | VSTEF $0, CTR, (R7) 225 | RET 226 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/chacha20/xor.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 src the LICENSE file. 4 | 5 | package chacha20 6 | 7 | import "runtime" 8 | 9 | // Platforms that have fast unaligned 32-bit little endian accesses. 10 | const unaligned = runtime.GOARCH == "386" || 11 | runtime.GOARCH == "amd64" || 12 | runtime.GOARCH == "arm64" || 13 | runtime.GOARCH == "ppc64le" || 14 | runtime.GOARCH == "s390x" 15 | 16 | // addXor reads a little endian uint32 from src, XORs it with (a + b) and 17 | // places the result in little endian byte order in dst. 18 | func addXor(dst, src []byte, a, b uint32) { 19 | _, _ = src[3], dst[3] // bounds check elimination hint 20 | if unaligned { 21 | // The compiler should optimize this code into 22 | // 32-bit unaligned little endian loads and stores. 23 | // TODO: delete once the compiler does a reliably 24 | // good job with the generic code below. 25 | // See issue #25111 for more details. 26 | v := uint32(src[0]) 27 | v |= uint32(src[1]) << 8 28 | v |= uint32(src[2]) << 16 29 | v |= uint32(src[3]) << 24 30 | v ^= a + b 31 | dst[0] = byte(v) 32 | dst[1] = byte(v >> 8) 33 | dst[2] = byte(v >> 16) 34 | dst[3] = byte(v >> 24) 35 | } else { 36 | a += b 37 | dst[0] = src[0] ^ byte(a) 38 | dst[1] = src[1] ^ byte(a>>8) 39 | dst[2] = src[2] ^ byte(a>>16) 40 | dst[3] = src[3] ^ byte(a>>24) 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/curve25519/curve25519.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 curve25519 provides an implementation of the X25519 function, which 6 | // performs scalar multiplication on the elliptic curve known as Curve25519. 7 | // See RFC 7748. 8 | package curve25519 // import "golang.org/x/crypto/curve25519" 9 | 10 | import ( 11 | "crypto/subtle" 12 | "fmt" 13 | 14 | "golang.org/x/crypto/curve25519/internal/field" 15 | ) 16 | 17 | // ScalarMult sets dst to the product scalar * point. 18 | // 19 | // Deprecated: when provided a low-order point, ScalarMult will set dst to all 20 | // zeroes, irrespective of the scalar. Instead, use the X25519 function, which 21 | // will return an error. 22 | func ScalarMult(dst, scalar, point *[32]byte) { 23 | var e [32]byte 24 | 25 | copy(e[:], scalar[:]) 26 | e[0] &= 248 27 | e[31] &= 127 28 | e[31] |= 64 29 | 30 | var x1, x2, z2, x3, z3, tmp0, tmp1 field.Element 31 | x1.SetBytes(point[:]) 32 | x2.One() 33 | x3.Set(&x1) 34 | z3.One() 35 | 36 | swap := 0 37 | for pos := 254; pos >= 0; pos-- { 38 | b := e[pos/8] >> uint(pos&7) 39 | b &= 1 40 | swap ^= int(b) 41 | x2.Swap(&x3, swap) 42 | z2.Swap(&z3, swap) 43 | swap = int(b) 44 | 45 | tmp0.Subtract(&x3, &z3) 46 | tmp1.Subtract(&x2, &z2) 47 | x2.Add(&x2, &z2) 48 | z2.Add(&x3, &z3) 49 | z3.Multiply(&tmp0, &x2) 50 | z2.Multiply(&z2, &tmp1) 51 | tmp0.Square(&tmp1) 52 | tmp1.Square(&x2) 53 | x3.Add(&z3, &z2) 54 | z2.Subtract(&z3, &z2) 55 | x2.Multiply(&tmp1, &tmp0) 56 | tmp1.Subtract(&tmp1, &tmp0) 57 | z2.Square(&z2) 58 | 59 | z3.Mult32(&tmp1, 121666) 60 | x3.Square(&x3) 61 | tmp0.Add(&tmp0, &z3) 62 | z3.Multiply(&x1, &z2) 63 | z2.Multiply(&tmp1, &tmp0) 64 | } 65 | 66 | x2.Swap(&x3, swap) 67 | z2.Swap(&z3, swap) 68 | 69 | z2.Invert(&z2) 70 | x2.Multiply(&x2, &z2) 71 | copy(dst[:], x2.Bytes()) 72 | } 73 | 74 | // ScalarBaseMult sets dst to the product scalar * base where base is the 75 | // standard generator. 76 | // 77 | // It is recommended to use the X25519 function with Basepoint instead, as 78 | // copying into fixed size arrays can lead to unexpected bugs. 79 | func ScalarBaseMult(dst, scalar *[32]byte) { 80 | ScalarMult(dst, scalar, &basePoint) 81 | } 82 | 83 | const ( 84 | // ScalarSize is the size of the scalar input to X25519. 85 | ScalarSize = 32 86 | // PointSize is the size of the point input to X25519. 87 | PointSize = 32 88 | ) 89 | 90 | // Basepoint is the canonical Curve25519 generator. 91 | var Basepoint []byte 92 | 93 | var basePoint = [32]byte{9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} 94 | 95 | func init() { Basepoint = basePoint[:] } 96 | 97 | func checkBasepoint() { 98 | if subtle.ConstantTimeCompare(Basepoint, []byte{ 99 | 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 100 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 101 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 102 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 103 | }) != 1 { 104 | panic("curve25519: global Basepoint value was modified") 105 | } 106 | } 107 | 108 | // X25519 returns the result of the scalar multiplication (scalar * point), 109 | // according to RFC 7748, Section 5. scalar, point and the return value are 110 | // slices of 32 bytes. 111 | // 112 | // scalar can be generated at random, for example with crypto/rand. point should 113 | // be either Basepoint or the output of another X25519 call. 114 | // 115 | // If point is Basepoint (but not if it's a different slice with the same 116 | // contents) a precomputed implementation might be used for performance. 117 | func X25519(scalar, point []byte) ([]byte, error) { 118 | // Outline the body of function, to let the allocation be inlined in the 119 | // caller, and possibly avoid escaping to the heap. 120 | var dst [32]byte 121 | return x25519(&dst, scalar, point) 122 | } 123 | 124 | func x25519(dst *[32]byte, scalar, point []byte) ([]byte, error) { 125 | var in [32]byte 126 | if l := len(scalar); l != 32 { 127 | return nil, fmt.Errorf("bad scalar length: %d, expected %d", l, 32) 128 | } 129 | if l := len(point); l != 32 { 130 | return nil, fmt.Errorf("bad point length: %d, expected %d", l, 32) 131 | } 132 | copy(in[:], scalar) 133 | if &point[0] == &Basepoint[0] { 134 | checkBasepoint() 135 | ScalarBaseMult(dst, &in) 136 | } else { 137 | var base, zero [32]byte 138 | copy(base[:], point) 139 | ScalarMult(dst, &in, &base) 140 | if subtle.ConstantTimeCompare(dst[:], zero[:]) == 1 { 141 | return nil, fmt.Errorf("bad input point: low order point") 142 | } 143 | } 144 | return dst[:], nil 145 | } 146 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/curve25519/internal/field/README: -------------------------------------------------------------------------------- 1 | This package is kept in sync with crypto/ed25519/internal/edwards25519/field in 2 | the standard library. 3 | 4 | If there are any changes in the standard library that need to be synced to this 5 | package, run sync.sh. It will not overwrite any local changes made since the 6 | previous sync, so it's ok to land changes in this package first, and then sync 7 | to the standard library later. 8 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/curve25519/internal/field/fe_amd64.go: -------------------------------------------------------------------------------- 1 | // Code generated by command: go run fe_amd64_asm.go -out ../fe_amd64.s -stubs ../fe_amd64.go -pkg field. DO NOT EDIT. 2 | 3 | // +build amd64,gc,!purego 4 | 5 | package field 6 | 7 | // feMul sets out = a * b. It works like feMulGeneric. 8 | //go:noescape 9 | func feMul(out *Element, a *Element, b *Element) 10 | 11 | // feSquare sets out = a * a. It works like feSquareGeneric. 12 | //go:noescape 13 | func feSquare(out *Element, a *Element) 14 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/curve25519/internal/field/fe_amd64.s: -------------------------------------------------------------------------------- 1 | // Code generated by command: go run fe_amd64_asm.go -out ../fe_amd64.s -stubs ../fe_amd64.go -pkg field. DO NOT EDIT. 2 | 3 | //go:build amd64 && gc && !purego 4 | // +build amd64,gc,!purego 5 | 6 | #include "textflag.h" 7 | 8 | // func feMul(out *Element, a *Element, b *Element) 9 | TEXT ·feMul(SB), NOSPLIT, $0-24 10 | MOVQ a+8(FP), CX 11 | MOVQ b+16(FP), BX 12 | 13 | // r0 = a0×b0 14 | MOVQ (CX), AX 15 | MULQ (BX) 16 | MOVQ AX, DI 17 | MOVQ DX, SI 18 | 19 | // r0 += 19×a1×b4 20 | MOVQ 8(CX), AX 21 | IMUL3Q $0x13, AX, AX 22 | MULQ 32(BX) 23 | ADDQ AX, DI 24 | ADCQ DX, SI 25 | 26 | // r0 += 19×a2×b3 27 | MOVQ 16(CX), AX 28 | IMUL3Q $0x13, AX, AX 29 | MULQ 24(BX) 30 | ADDQ AX, DI 31 | ADCQ DX, SI 32 | 33 | // r0 += 19×a3×b2 34 | MOVQ 24(CX), AX 35 | IMUL3Q $0x13, AX, AX 36 | MULQ 16(BX) 37 | ADDQ AX, DI 38 | ADCQ DX, SI 39 | 40 | // r0 += 19×a4×b1 41 | MOVQ 32(CX), AX 42 | IMUL3Q $0x13, AX, AX 43 | MULQ 8(BX) 44 | ADDQ AX, DI 45 | ADCQ DX, SI 46 | 47 | // r1 = a0×b1 48 | MOVQ (CX), AX 49 | MULQ 8(BX) 50 | MOVQ AX, R9 51 | MOVQ DX, R8 52 | 53 | // r1 += a1×b0 54 | MOVQ 8(CX), AX 55 | MULQ (BX) 56 | ADDQ AX, R9 57 | ADCQ DX, R8 58 | 59 | // r1 += 19×a2×b4 60 | MOVQ 16(CX), AX 61 | IMUL3Q $0x13, AX, AX 62 | MULQ 32(BX) 63 | ADDQ AX, R9 64 | ADCQ DX, R8 65 | 66 | // r1 += 19×a3×b3 67 | MOVQ 24(CX), AX 68 | IMUL3Q $0x13, AX, AX 69 | MULQ 24(BX) 70 | ADDQ AX, R9 71 | ADCQ DX, R8 72 | 73 | // r1 += 19×a4×b2 74 | MOVQ 32(CX), AX 75 | IMUL3Q $0x13, AX, AX 76 | MULQ 16(BX) 77 | ADDQ AX, R9 78 | ADCQ DX, R8 79 | 80 | // r2 = a0×b2 81 | MOVQ (CX), AX 82 | MULQ 16(BX) 83 | MOVQ AX, R11 84 | MOVQ DX, R10 85 | 86 | // r2 += a1×b1 87 | MOVQ 8(CX), AX 88 | MULQ 8(BX) 89 | ADDQ AX, R11 90 | ADCQ DX, R10 91 | 92 | // r2 += a2×b0 93 | MOVQ 16(CX), AX 94 | MULQ (BX) 95 | ADDQ AX, R11 96 | ADCQ DX, R10 97 | 98 | // r2 += 19×a3×b4 99 | MOVQ 24(CX), AX 100 | IMUL3Q $0x13, AX, AX 101 | MULQ 32(BX) 102 | ADDQ AX, R11 103 | ADCQ DX, R10 104 | 105 | // r2 += 19×a4×b3 106 | MOVQ 32(CX), AX 107 | IMUL3Q $0x13, AX, AX 108 | MULQ 24(BX) 109 | ADDQ AX, R11 110 | ADCQ DX, R10 111 | 112 | // r3 = a0×b3 113 | MOVQ (CX), AX 114 | MULQ 24(BX) 115 | MOVQ AX, R13 116 | MOVQ DX, R12 117 | 118 | // r3 += a1×b2 119 | MOVQ 8(CX), AX 120 | MULQ 16(BX) 121 | ADDQ AX, R13 122 | ADCQ DX, R12 123 | 124 | // r3 += a2×b1 125 | MOVQ 16(CX), AX 126 | MULQ 8(BX) 127 | ADDQ AX, R13 128 | ADCQ DX, R12 129 | 130 | // r3 += a3×b0 131 | MOVQ 24(CX), AX 132 | MULQ (BX) 133 | ADDQ AX, R13 134 | ADCQ DX, R12 135 | 136 | // r3 += 19×a4×b4 137 | MOVQ 32(CX), AX 138 | IMUL3Q $0x13, AX, AX 139 | MULQ 32(BX) 140 | ADDQ AX, R13 141 | ADCQ DX, R12 142 | 143 | // r4 = a0×b4 144 | MOVQ (CX), AX 145 | MULQ 32(BX) 146 | MOVQ AX, R15 147 | MOVQ DX, R14 148 | 149 | // r4 += a1×b3 150 | MOVQ 8(CX), AX 151 | MULQ 24(BX) 152 | ADDQ AX, R15 153 | ADCQ DX, R14 154 | 155 | // r4 += a2×b2 156 | MOVQ 16(CX), AX 157 | MULQ 16(BX) 158 | ADDQ AX, R15 159 | ADCQ DX, R14 160 | 161 | // r4 += a3×b1 162 | MOVQ 24(CX), AX 163 | MULQ 8(BX) 164 | ADDQ AX, R15 165 | ADCQ DX, R14 166 | 167 | // r4 += a4×b0 168 | MOVQ 32(CX), AX 169 | MULQ (BX) 170 | ADDQ AX, R15 171 | ADCQ DX, R14 172 | 173 | // First reduction chain 174 | MOVQ $0x0007ffffffffffff, AX 175 | SHLQ $0x0d, DI, SI 176 | SHLQ $0x0d, R9, R8 177 | SHLQ $0x0d, R11, R10 178 | SHLQ $0x0d, R13, R12 179 | SHLQ $0x0d, R15, R14 180 | ANDQ AX, DI 181 | IMUL3Q $0x13, R14, R14 182 | ADDQ R14, DI 183 | ANDQ AX, R9 184 | ADDQ SI, R9 185 | ANDQ AX, R11 186 | ADDQ R8, R11 187 | ANDQ AX, R13 188 | ADDQ R10, R13 189 | ANDQ AX, R15 190 | ADDQ R12, R15 191 | 192 | // Second reduction chain (carryPropagate) 193 | MOVQ DI, SI 194 | SHRQ $0x33, SI 195 | MOVQ R9, R8 196 | SHRQ $0x33, R8 197 | MOVQ R11, R10 198 | SHRQ $0x33, R10 199 | MOVQ R13, R12 200 | SHRQ $0x33, R12 201 | MOVQ R15, R14 202 | SHRQ $0x33, R14 203 | ANDQ AX, DI 204 | IMUL3Q $0x13, R14, R14 205 | ADDQ R14, DI 206 | ANDQ AX, R9 207 | ADDQ SI, R9 208 | ANDQ AX, R11 209 | ADDQ R8, R11 210 | ANDQ AX, R13 211 | ADDQ R10, R13 212 | ANDQ AX, R15 213 | ADDQ R12, R15 214 | 215 | // Store output 216 | MOVQ out+0(FP), AX 217 | MOVQ DI, (AX) 218 | MOVQ R9, 8(AX) 219 | MOVQ R11, 16(AX) 220 | MOVQ R13, 24(AX) 221 | MOVQ R15, 32(AX) 222 | RET 223 | 224 | // func feSquare(out *Element, a *Element) 225 | TEXT ·feSquare(SB), NOSPLIT, $0-16 226 | MOVQ a+8(FP), CX 227 | 228 | // r0 = l0×l0 229 | MOVQ (CX), AX 230 | MULQ (CX) 231 | MOVQ AX, SI 232 | MOVQ DX, BX 233 | 234 | // r0 += 38×l1×l4 235 | MOVQ 8(CX), AX 236 | IMUL3Q $0x26, AX, AX 237 | MULQ 32(CX) 238 | ADDQ AX, SI 239 | ADCQ DX, BX 240 | 241 | // r0 += 38×l2×l3 242 | MOVQ 16(CX), AX 243 | IMUL3Q $0x26, AX, AX 244 | MULQ 24(CX) 245 | ADDQ AX, SI 246 | ADCQ DX, BX 247 | 248 | // r1 = 2×l0×l1 249 | MOVQ (CX), AX 250 | SHLQ $0x01, AX 251 | MULQ 8(CX) 252 | MOVQ AX, R8 253 | MOVQ DX, DI 254 | 255 | // r1 += 38×l2×l4 256 | MOVQ 16(CX), AX 257 | IMUL3Q $0x26, AX, AX 258 | MULQ 32(CX) 259 | ADDQ AX, R8 260 | ADCQ DX, DI 261 | 262 | // r1 += 19×l3×l3 263 | MOVQ 24(CX), AX 264 | IMUL3Q $0x13, AX, AX 265 | MULQ 24(CX) 266 | ADDQ AX, R8 267 | ADCQ DX, DI 268 | 269 | // r2 = 2×l0×l2 270 | MOVQ (CX), AX 271 | SHLQ $0x01, AX 272 | MULQ 16(CX) 273 | MOVQ AX, R10 274 | MOVQ DX, R9 275 | 276 | // r2 += l1×l1 277 | MOVQ 8(CX), AX 278 | MULQ 8(CX) 279 | ADDQ AX, R10 280 | ADCQ DX, R9 281 | 282 | // r2 += 38×l3×l4 283 | MOVQ 24(CX), AX 284 | IMUL3Q $0x26, AX, AX 285 | MULQ 32(CX) 286 | ADDQ AX, R10 287 | ADCQ DX, R9 288 | 289 | // r3 = 2×l0×l3 290 | MOVQ (CX), AX 291 | SHLQ $0x01, AX 292 | MULQ 24(CX) 293 | MOVQ AX, R12 294 | MOVQ DX, R11 295 | 296 | // r3 += 2×l1×l2 297 | MOVQ 8(CX), AX 298 | IMUL3Q $0x02, AX, AX 299 | MULQ 16(CX) 300 | ADDQ AX, R12 301 | ADCQ DX, R11 302 | 303 | // r3 += 19×l4×l4 304 | MOVQ 32(CX), AX 305 | IMUL3Q $0x13, AX, AX 306 | MULQ 32(CX) 307 | ADDQ AX, R12 308 | ADCQ DX, R11 309 | 310 | // r4 = 2×l0×l4 311 | MOVQ (CX), AX 312 | SHLQ $0x01, AX 313 | MULQ 32(CX) 314 | MOVQ AX, R14 315 | MOVQ DX, R13 316 | 317 | // r4 += 2×l1×l3 318 | MOVQ 8(CX), AX 319 | IMUL3Q $0x02, AX, AX 320 | MULQ 24(CX) 321 | ADDQ AX, R14 322 | ADCQ DX, R13 323 | 324 | // r4 += l2×l2 325 | MOVQ 16(CX), AX 326 | MULQ 16(CX) 327 | ADDQ AX, R14 328 | ADCQ DX, R13 329 | 330 | // First reduction chain 331 | MOVQ $0x0007ffffffffffff, AX 332 | SHLQ $0x0d, SI, BX 333 | SHLQ $0x0d, R8, DI 334 | SHLQ $0x0d, R10, R9 335 | SHLQ $0x0d, R12, R11 336 | SHLQ $0x0d, R14, R13 337 | ANDQ AX, SI 338 | IMUL3Q $0x13, R13, R13 339 | ADDQ R13, SI 340 | ANDQ AX, R8 341 | ADDQ BX, R8 342 | ANDQ AX, R10 343 | ADDQ DI, R10 344 | ANDQ AX, R12 345 | ADDQ R9, R12 346 | ANDQ AX, R14 347 | ADDQ R11, R14 348 | 349 | // Second reduction chain (carryPropagate) 350 | MOVQ SI, BX 351 | SHRQ $0x33, BX 352 | MOVQ R8, DI 353 | SHRQ $0x33, DI 354 | MOVQ R10, R9 355 | SHRQ $0x33, R9 356 | MOVQ R12, R11 357 | SHRQ $0x33, R11 358 | MOVQ R14, R13 359 | SHRQ $0x33, R13 360 | ANDQ AX, SI 361 | IMUL3Q $0x13, R13, R13 362 | ADDQ R13, SI 363 | ANDQ AX, R8 364 | ADDQ BX, R8 365 | ANDQ AX, R10 366 | ADDQ DI, R10 367 | ANDQ AX, R12 368 | ADDQ R9, R12 369 | ANDQ AX, R14 370 | ADDQ R11, R14 371 | 372 | // Store output 373 | MOVQ out+0(FP), AX 374 | MOVQ SI, (AX) 375 | MOVQ R8, 8(AX) 376 | MOVQ R10, 16(AX) 377 | MOVQ R12, 24(AX) 378 | MOVQ R14, 32(AX) 379 | RET 380 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/curve25519/internal/field/fe_amd64_noasm.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 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 || !gc || purego 6 | // +build !amd64 !gc purego 7 | 8 | package field 9 | 10 | func feMul(v, x, y *Element) { feMulGeneric(v, x, y) } 11 | 12 | func feSquare(v, x *Element) { feSquareGeneric(v, x) } 13 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/curve25519/internal/field/fe_arm64.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 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 arm64 && gc && !purego 6 | // +build arm64,gc,!purego 7 | 8 | package field 9 | 10 | //go:noescape 11 | func carryPropagate(v *Element) 12 | 13 | func (v *Element) carryPropagate() *Element { 14 | carryPropagate(v) 15 | return v 16 | } 17 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/curve25519/internal/field/fe_arm64.s: -------------------------------------------------------------------------------- 1 | // Copyright (c) 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 arm64 && gc && !purego 6 | // +build arm64,gc,!purego 7 | 8 | #include "textflag.h" 9 | 10 | // carryPropagate works exactly like carryPropagateGeneric and uses the 11 | // same AND, ADD, and LSR+MADD instructions emitted by the compiler, but 12 | // avoids loading R0-R4 twice and uses LDP and STP. 13 | // 14 | // See https://golang.org/issues/43145 for the main compiler issue. 15 | // 16 | // func carryPropagate(v *Element) 17 | TEXT ·carryPropagate(SB),NOFRAME|NOSPLIT,$0-8 18 | MOVD v+0(FP), R20 19 | 20 | LDP 0(R20), (R0, R1) 21 | LDP 16(R20), (R2, R3) 22 | MOVD 32(R20), R4 23 | 24 | AND $0x7ffffffffffff, R0, R10 25 | AND $0x7ffffffffffff, R1, R11 26 | AND $0x7ffffffffffff, R2, R12 27 | AND $0x7ffffffffffff, R3, R13 28 | AND $0x7ffffffffffff, R4, R14 29 | 30 | ADD R0>>51, R11, R11 31 | ADD R1>>51, R12, R12 32 | ADD R2>>51, R13, R13 33 | ADD R3>>51, R14, R14 34 | // R4>>51 * 19 + R10 -> R10 35 | LSR $51, R4, R21 36 | MOVD $19, R22 37 | MADD R22, R10, R21, R10 38 | 39 | STP (R10, R11), 0(R20) 40 | STP (R12, R13), 16(R20) 41 | MOVD R14, 32(R20) 42 | 43 | RET 44 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/curve25519/internal/field/fe_arm64_noasm.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 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 !arm64 || !gc || purego 6 | // +build !arm64 !gc purego 7 | 8 | package field 9 | 10 | func (v *Element) carryPropagate() *Element { 11 | return v.carryPropagateGeneric() 12 | } 13 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/curve25519/internal/field/sync.checkpoint: -------------------------------------------------------------------------------- 1 | b0c49ae9f59d233526f8934262c5bbbe14d4358d 2 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/curve25519/internal/field/sync.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | set -euo pipefail 3 | 4 | cd "$(git rev-parse --show-toplevel)" 5 | 6 | STD_PATH=src/crypto/ed25519/internal/edwards25519/field 7 | LOCAL_PATH=curve25519/internal/field 8 | LAST_SYNC_REF=$(cat $LOCAL_PATH/sync.checkpoint) 9 | 10 | git fetch https://go.googlesource.com/go master 11 | 12 | if git diff --quiet $LAST_SYNC_REF:$STD_PATH FETCH_HEAD:$STD_PATH; then 13 | echo "No changes." 14 | else 15 | NEW_REF=$(git rev-parse FETCH_HEAD | tee $LOCAL_PATH/sync.checkpoint) 16 | echo "Applying changes from $LAST_SYNC_REF to $NEW_REF..." 17 | git diff $LAST_SYNC_REF:$STD_PATH FETCH_HEAD:$STD_PATH | \ 18 | git apply -3 --directory=$LOCAL_PATH 19 | fi 20 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/ed25519/ed25519.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 | // In Go 1.13, the ed25519 package was promoted to the standard library as 6 | // crypto/ed25519, and this package became a wrapper for the standard library one. 7 | // 8 | //go:build !go1.13 9 | // +build !go1.13 10 | 11 | // Package ed25519 implements the Ed25519 signature algorithm. See 12 | // https://ed25519.cr.yp.to/. 13 | // 14 | // These functions are also compatible with the “Ed25519” function defined in 15 | // RFC 8032. However, unlike RFC 8032's formulation, this package's private key 16 | // representation includes a public key suffix to make multiple signing 17 | // operations with the same key more efficient. This package refers to the RFC 18 | // 8032 private key as the “seed”. 19 | package ed25519 20 | 21 | // This code is a port of the public domain, “ref10” implementation of ed25519 22 | // from SUPERCOP. 23 | 24 | import ( 25 | "bytes" 26 | "crypto" 27 | cryptorand "crypto/rand" 28 | "crypto/sha512" 29 | "errors" 30 | "io" 31 | "strconv" 32 | 33 | "golang.org/x/crypto/ed25519/internal/edwards25519" 34 | ) 35 | 36 | const ( 37 | // PublicKeySize is the size, in bytes, of public keys as used in this package. 38 | PublicKeySize = 32 39 | // PrivateKeySize is the size, in bytes, of private keys as used in this package. 40 | PrivateKeySize = 64 41 | // SignatureSize is the size, in bytes, of signatures generated and verified by this package. 42 | SignatureSize = 64 43 | // SeedSize is the size, in bytes, of private key seeds. These are the private key representations used by RFC 8032. 44 | SeedSize = 32 45 | ) 46 | 47 | // PublicKey is the type of Ed25519 public keys. 48 | type PublicKey []byte 49 | 50 | // PrivateKey is the type of Ed25519 private keys. It implements crypto.Signer. 51 | type PrivateKey []byte 52 | 53 | // Public returns the PublicKey corresponding to priv. 54 | func (priv PrivateKey) Public() crypto.PublicKey { 55 | publicKey := make([]byte, PublicKeySize) 56 | copy(publicKey, priv[32:]) 57 | return PublicKey(publicKey) 58 | } 59 | 60 | // Seed returns the private key seed corresponding to priv. It is provided for 61 | // interoperability with RFC 8032. RFC 8032's private keys correspond to seeds 62 | // in this package. 63 | func (priv PrivateKey) Seed() []byte { 64 | seed := make([]byte, SeedSize) 65 | copy(seed, priv[:32]) 66 | return seed 67 | } 68 | 69 | // Sign signs the given message with priv. 70 | // Ed25519 performs two passes over messages to be signed and therefore cannot 71 | // handle pre-hashed messages. Thus opts.HashFunc() must return zero to 72 | // indicate the message hasn't been hashed. This can be achieved by passing 73 | // crypto.Hash(0) as the value for opts. 74 | func (priv PrivateKey) Sign(rand io.Reader, message []byte, opts crypto.SignerOpts) (signature []byte, err error) { 75 | if opts.HashFunc() != crypto.Hash(0) { 76 | return nil, errors.New("ed25519: cannot sign hashed message") 77 | } 78 | 79 | return Sign(priv, message), nil 80 | } 81 | 82 | // GenerateKey generates a public/private key pair using entropy from rand. 83 | // If rand is nil, crypto/rand.Reader will be used. 84 | func GenerateKey(rand io.Reader) (PublicKey, PrivateKey, error) { 85 | if rand == nil { 86 | rand = cryptorand.Reader 87 | } 88 | 89 | seed := make([]byte, SeedSize) 90 | if _, err := io.ReadFull(rand, seed); err != nil { 91 | return nil, nil, err 92 | } 93 | 94 | privateKey := NewKeyFromSeed(seed) 95 | publicKey := make([]byte, PublicKeySize) 96 | copy(publicKey, privateKey[32:]) 97 | 98 | return publicKey, privateKey, nil 99 | } 100 | 101 | // NewKeyFromSeed calculates a private key from a seed. It will panic if 102 | // len(seed) is not SeedSize. This function is provided for interoperability 103 | // with RFC 8032. RFC 8032's private keys correspond to seeds in this 104 | // package. 105 | func NewKeyFromSeed(seed []byte) PrivateKey { 106 | if l := len(seed); l != SeedSize { 107 | panic("ed25519: bad seed length: " + strconv.Itoa(l)) 108 | } 109 | 110 | digest := sha512.Sum512(seed) 111 | digest[0] &= 248 112 | digest[31] &= 127 113 | digest[31] |= 64 114 | 115 | var A edwards25519.ExtendedGroupElement 116 | var hBytes [32]byte 117 | copy(hBytes[:], digest[:]) 118 | edwards25519.GeScalarMultBase(&A, &hBytes) 119 | var publicKeyBytes [32]byte 120 | A.ToBytes(&publicKeyBytes) 121 | 122 | privateKey := make([]byte, PrivateKeySize) 123 | copy(privateKey, seed) 124 | copy(privateKey[32:], publicKeyBytes[:]) 125 | 126 | return privateKey 127 | } 128 | 129 | // Sign signs the message with privateKey and returns a signature. It will 130 | // panic if len(privateKey) is not PrivateKeySize. 131 | func Sign(privateKey PrivateKey, message []byte) []byte { 132 | if l := len(privateKey); l != PrivateKeySize { 133 | panic("ed25519: bad private key length: " + strconv.Itoa(l)) 134 | } 135 | 136 | h := sha512.New() 137 | h.Write(privateKey[:32]) 138 | 139 | var digest1, messageDigest, hramDigest [64]byte 140 | var expandedSecretKey [32]byte 141 | h.Sum(digest1[:0]) 142 | copy(expandedSecretKey[:], digest1[:]) 143 | expandedSecretKey[0] &= 248 144 | expandedSecretKey[31] &= 63 145 | expandedSecretKey[31] |= 64 146 | 147 | h.Reset() 148 | h.Write(digest1[32:]) 149 | h.Write(message) 150 | h.Sum(messageDigest[:0]) 151 | 152 | var messageDigestReduced [32]byte 153 | edwards25519.ScReduce(&messageDigestReduced, &messageDigest) 154 | var R edwards25519.ExtendedGroupElement 155 | edwards25519.GeScalarMultBase(&R, &messageDigestReduced) 156 | 157 | var encodedR [32]byte 158 | R.ToBytes(&encodedR) 159 | 160 | h.Reset() 161 | h.Write(encodedR[:]) 162 | h.Write(privateKey[32:]) 163 | h.Write(message) 164 | h.Sum(hramDigest[:0]) 165 | var hramDigestReduced [32]byte 166 | edwards25519.ScReduce(&hramDigestReduced, &hramDigest) 167 | 168 | var s [32]byte 169 | edwards25519.ScMulAdd(&s, &hramDigestReduced, &expandedSecretKey, &messageDigestReduced) 170 | 171 | signature := make([]byte, SignatureSize) 172 | copy(signature[:], encodedR[:]) 173 | copy(signature[32:], s[:]) 174 | 175 | return signature 176 | } 177 | 178 | // Verify reports whether sig is a valid signature of message by publicKey. It 179 | // will panic if len(publicKey) is not PublicKeySize. 180 | func Verify(publicKey PublicKey, message, sig []byte) bool { 181 | if l := len(publicKey); l != PublicKeySize { 182 | panic("ed25519: bad public key length: " + strconv.Itoa(l)) 183 | } 184 | 185 | if len(sig) != SignatureSize || sig[63]&224 != 0 { 186 | return false 187 | } 188 | 189 | var A edwards25519.ExtendedGroupElement 190 | var publicKeyBytes [32]byte 191 | copy(publicKeyBytes[:], publicKey) 192 | if !A.FromBytes(&publicKeyBytes) { 193 | return false 194 | } 195 | edwards25519.FeNeg(&A.X, &A.X) 196 | edwards25519.FeNeg(&A.T, &A.T) 197 | 198 | h := sha512.New() 199 | h.Write(sig[:32]) 200 | h.Write(publicKey[:]) 201 | h.Write(message) 202 | var digest [64]byte 203 | h.Sum(digest[:0]) 204 | 205 | var hReduced [32]byte 206 | edwards25519.ScReduce(&hReduced, &digest) 207 | 208 | var R edwards25519.ProjectiveGroupElement 209 | var s [32]byte 210 | copy(s[:], sig[32:]) 211 | 212 | // https://tools.ietf.org/html/rfc8032#section-5.1.7 requires that s be in 213 | // the range [0, order) in order to prevent signature malleability. 214 | if !edwards25519.ScMinimal(&s) { 215 | return false 216 | } 217 | 218 | edwards25519.GeDoubleScalarMultVartime(&R, &hReduced, &A, &s) 219 | 220 | var checkR [32]byte 221 | R.ToBytes(&checkR) 222 | return bytes.Equal(sig[:32], checkR[:]) 223 | } 224 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/ed25519/ed25519_go113.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 ed25519 implements the Ed25519 signature algorithm. See 9 | // https://ed25519.cr.yp.to/. 10 | // 11 | // These functions are also compatible with the “Ed25519” function defined in 12 | // RFC 8032. However, unlike RFC 8032's formulation, this package's private key 13 | // representation includes a public key suffix to make multiple signing 14 | // operations with the same key more efficient. This package refers to the RFC 15 | // 8032 private key as the “seed”. 16 | // 17 | // Beginning with Go 1.13, the functionality of this package was moved to the 18 | // standard library as crypto/ed25519. This package only acts as a compatibility 19 | // wrapper. 20 | package ed25519 21 | 22 | import ( 23 | "crypto/ed25519" 24 | "io" 25 | ) 26 | 27 | const ( 28 | // PublicKeySize is the size, in bytes, of public keys as used in this package. 29 | PublicKeySize = 32 30 | // PrivateKeySize is the size, in bytes, of private keys as used in this package. 31 | PrivateKeySize = 64 32 | // SignatureSize is the size, in bytes, of signatures generated and verified by this package. 33 | SignatureSize = 64 34 | // SeedSize is the size, in bytes, of private key seeds. These are the private key representations used by RFC 8032. 35 | SeedSize = 32 36 | ) 37 | 38 | // PublicKey is the type of Ed25519 public keys. 39 | // 40 | // This type is an alias for crypto/ed25519's PublicKey type. 41 | // See the crypto/ed25519 package for the methods on this type. 42 | type PublicKey = ed25519.PublicKey 43 | 44 | // PrivateKey is the type of Ed25519 private keys. It implements crypto.Signer. 45 | // 46 | // This type is an alias for crypto/ed25519's PrivateKey type. 47 | // See the crypto/ed25519 package for the methods on this type. 48 | type PrivateKey = ed25519.PrivateKey 49 | 50 | // GenerateKey generates a public/private key pair using entropy from rand. 51 | // If rand is nil, crypto/rand.Reader will be used. 52 | func GenerateKey(rand io.Reader) (PublicKey, PrivateKey, error) { 53 | return ed25519.GenerateKey(rand) 54 | } 55 | 56 | // NewKeyFromSeed calculates a private key from a seed. It will panic if 57 | // len(seed) is not SeedSize. This function is provided for interoperability 58 | // with RFC 8032. RFC 8032's private keys correspond to seeds in this 59 | // package. 60 | func NewKeyFromSeed(seed []byte) PrivateKey { 61 | return ed25519.NewKeyFromSeed(seed) 62 | } 63 | 64 | // Sign signs the message with privateKey and returns a signature. It will 65 | // panic if len(privateKey) is not PrivateKeySize. 66 | func Sign(privateKey PrivateKey, message []byte) []byte { 67 | return ed25519.Sign(privateKey, message) 68 | } 69 | 70 | // Verify reports whether sig is a valid signature of message by publicKey. It 71 | // will panic if len(publicKey) is not PublicKeySize. 72 | func Verify(publicKey PublicKey, message, sig []byte) bool { 73 | return ed25519.Verify(publicKey, message, sig) 74 | } 75 | -------------------------------------------------------------------------------- /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 | //go:noescape 18 | func updateVX(state *macState, msg []byte) 19 | 20 | // mac is a replacement for macGeneric that uses a larger buffer and redirects 21 | // calls that would have gone to updateGeneric to updateVX if the vector 22 | // facility is installed. 23 | // 24 | // A larger buffer is required for good performance because the vector 25 | // implementation has a higher fixed cost per call than the generic 26 | // implementation. 27 | type mac struct { 28 | macState 29 | 30 | buffer [16 * TagSize]byte // size must be a multiple of block size (16) 31 | offset int 32 | } 33 | 34 | func (h *mac) Write(p []byte) (int, error) { 35 | nn := len(p) 36 | if h.offset > 0 { 37 | n := copy(h.buffer[h.offset:], p) 38 | if h.offset+n < len(h.buffer) { 39 | h.offset += n 40 | return nn, nil 41 | } 42 | p = p[n:] 43 | h.offset = 0 44 | if cpu.S390X.HasVX { 45 | updateVX(&h.macState, h.buffer[:]) 46 | } else { 47 | updateGeneric(&h.macState, h.buffer[:]) 48 | } 49 | } 50 | 51 | tail := len(p) % len(h.buffer) // number of bytes to copy into buffer 52 | body := len(p) - tail // number of bytes to process now 53 | if body > 0 { 54 | if cpu.S390X.HasVX { 55 | updateVX(&h.macState, p[:body]) 56 | } else { 57 | updateGeneric(&h.macState, p[:body]) 58 | } 59 | } 60 | h.offset = copy(h.buffer[:], p[body:]) // copy tail bytes - can be 0 61 | return nn, nil 62 | } 63 | 64 | func (h *mac) Sum(out *[TagSize]byte) { 65 | state := h.macState 66 | remainder := h.buffer[:h.offset] 67 | 68 | // Use the generic implementation if we have 2 or fewer blocks left 69 | // to sum. The vector implementation has a higher startup time. 70 | if cpu.S390X.HasVX && len(remainder) > 2*TagSize { 71 | updateVX(&state, remainder) 72 | } else if len(remainder) > 0 { 73 | updateGeneric(&state, remainder) 74 | } 75 | finalize(out, &state.h, &state.s) 76 | } 77 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/internal/subtle/aliasing.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 subtle implements functions that are often useful in cryptographic 9 | // code but require careful thought to use correctly. 10 | package subtle // import "golang.org/x/crypto/internal/subtle" 11 | 12 | import "unsafe" 13 | 14 | // AnyOverlap reports whether x and y share memory at any (not necessarily 15 | // corresponding) index. The memory beyond the slice length is ignored. 16 | func AnyOverlap(x, y []byte) bool { 17 | return len(x) > 0 && len(y) > 0 && 18 | uintptr(unsafe.Pointer(&x[0])) <= uintptr(unsafe.Pointer(&y[len(y)-1])) && 19 | uintptr(unsafe.Pointer(&y[0])) <= uintptr(unsafe.Pointer(&x[len(x)-1])) 20 | } 21 | 22 | // InexactOverlap reports whether x and y share memory at any non-corresponding 23 | // index. The memory beyond the slice length is ignored. Note that x and y can 24 | // have different lengths and still not have any inexact overlap. 25 | // 26 | // InexactOverlap can be used to implement the requirements of the crypto/cipher 27 | // AEAD, Block, BlockMode and Stream interfaces. 28 | func InexactOverlap(x, y []byte) bool { 29 | if len(x) == 0 || len(y) == 0 || &x[0] == &y[0] { 30 | return false 31 | } 32 | return AnyOverlap(x, y) 33 | } 34 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/internal/subtle/aliasing_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 subtle implements functions that are often useful in cryptographic 9 | // code but require careful thought to use correctly. 10 | package subtle // import "golang.org/x/crypto/internal/subtle" 11 | 12 | // This is the Google App Engine standard variant based on reflect 13 | // because the unsafe package and cgo are disallowed. 14 | 15 | import "reflect" 16 | 17 | // AnyOverlap reports whether x and y share memory at any (not necessarily 18 | // corresponding) index. The memory beyond the slice length is ignored. 19 | func AnyOverlap(x, y []byte) bool { 20 | return len(x) > 0 && len(y) > 0 && 21 | reflect.ValueOf(&x[0]).Pointer() <= reflect.ValueOf(&y[len(y)-1]).Pointer() && 22 | reflect.ValueOf(&y[0]).Pointer() <= reflect.ValueOf(&x[len(x)-1]).Pointer() 23 | } 24 | 25 | // InexactOverlap reports whether x and y share memory at any non-corresponding 26 | // index. The memory beyond the slice length is ignored. Note that x and y can 27 | // have different lengths and still not have any inexact overlap. 28 | // 29 | // InexactOverlap can be used to implement the requirements of the crypto/cipher 30 | // AEAD, Block, BlockMode and Stream interfaces. 31 | func InexactOverlap(x, y []byte) bool { 32 | if len(x) == 0 || len(y) == 0 || &x[0] == &y[0] { 33 | return false 34 | } 35 | return AnyOverlap(x, y) 36 | } 37 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/ssh/buffer.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 ssh 6 | 7 | import ( 8 | "io" 9 | "sync" 10 | ) 11 | 12 | // buffer provides a linked list buffer for data exchange 13 | // between producer and consumer. Theoretically the buffer is 14 | // of unlimited capacity as it does no allocation of its own. 15 | type buffer struct { 16 | // protects concurrent access to head, tail and closed 17 | *sync.Cond 18 | 19 | head *element // the buffer that will be read first 20 | tail *element // the buffer that will be read last 21 | 22 | closed bool 23 | } 24 | 25 | // An element represents a single link in a linked list. 26 | type element struct { 27 | buf []byte 28 | next *element 29 | } 30 | 31 | // newBuffer returns an empty buffer that is not closed. 32 | func newBuffer() *buffer { 33 | e := new(element) 34 | b := &buffer{ 35 | Cond: newCond(), 36 | head: e, 37 | tail: e, 38 | } 39 | return b 40 | } 41 | 42 | // write makes buf available for Read to receive. 43 | // buf must not be modified after the call to write. 44 | func (b *buffer) write(buf []byte) { 45 | b.Cond.L.Lock() 46 | e := &element{buf: buf} 47 | b.tail.next = e 48 | b.tail = e 49 | b.Cond.Signal() 50 | b.Cond.L.Unlock() 51 | } 52 | 53 | // eof closes the buffer. Reads from the buffer once all 54 | // the data has been consumed will receive io.EOF. 55 | func (b *buffer) eof() { 56 | b.Cond.L.Lock() 57 | b.closed = true 58 | b.Cond.Signal() 59 | b.Cond.L.Unlock() 60 | } 61 | 62 | // Read reads data from the internal buffer in buf. Reads will block 63 | // if no data is available, or until the buffer is closed. 64 | func (b *buffer) Read(buf []byte) (n int, err error) { 65 | b.Cond.L.Lock() 66 | defer b.Cond.L.Unlock() 67 | 68 | for len(buf) > 0 { 69 | // if there is data in b.head, copy it 70 | if len(b.head.buf) > 0 { 71 | r := copy(buf, b.head.buf) 72 | buf, b.head.buf = buf[r:], b.head.buf[r:] 73 | n += r 74 | continue 75 | } 76 | // if there is a next buffer, make it the head 77 | if len(b.head.buf) == 0 && b.head != b.tail { 78 | b.head = b.head.next 79 | continue 80 | } 81 | 82 | // if at least one byte has been copied, return 83 | if n > 0 { 84 | break 85 | } 86 | 87 | // if nothing was read, and there is nothing outstanding 88 | // check to see if the buffer is closed. 89 | if b.closed { 90 | err = io.EOF 91 | break 92 | } 93 | // out of buffers, wait for producer 94 | b.Cond.Wait() 95 | } 96 | return 97 | } 98 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/ssh/connection.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package ssh 6 | 7 | import ( 8 | "fmt" 9 | "net" 10 | ) 11 | 12 | // OpenChannelError is returned if the other side rejects an 13 | // OpenChannel request. 14 | type OpenChannelError struct { 15 | Reason RejectionReason 16 | Message string 17 | } 18 | 19 | func (e *OpenChannelError) Error() string { 20 | return fmt.Sprintf("ssh: rejected: %s (%s)", e.Reason, e.Message) 21 | } 22 | 23 | // ConnMetadata holds metadata for the connection. 24 | type ConnMetadata interface { 25 | // User returns the user ID for this connection. 26 | User() string 27 | 28 | // SessionID returns the session hash, also denoted by H. 29 | SessionID() []byte 30 | 31 | // ClientVersion returns the client's version string as hashed 32 | // into the session ID. 33 | ClientVersion() []byte 34 | 35 | // ServerVersion returns the server's version string as hashed 36 | // into the session ID. 37 | ServerVersion() []byte 38 | 39 | // RemoteAddr returns the remote address for this connection. 40 | RemoteAddr() net.Addr 41 | 42 | // LocalAddr returns the local address for this connection. 43 | LocalAddr() net.Addr 44 | } 45 | 46 | // Conn represents an SSH connection for both server and client roles. 47 | // Conn is the basis for implementing an application layer, such 48 | // as ClientConn, which implements the traditional shell access for 49 | // clients. 50 | type Conn interface { 51 | ConnMetadata 52 | 53 | // SendRequest sends a global request, and returns the 54 | // reply. If wantReply is true, it returns the response status 55 | // and payload. See also RFC4254, section 4. 56 | SendRequest(name string, wantReply bool, payload []byte) (bool, []byte, error) 57 | 58 | // OpenChannel tries to open an channel. If the request is 59 | // rejected, it returns *OpenChannelError. On success it returns 60 | // the SSH Channel and a Go channel for incoming, out-of-band 61 | // requests. The Go channel must be serviced, or the 62 | // connection will hang. 63 | OpenChannel(name string, data []byte) (Channel, <-chan *Request, error) 64 | 65 | // Close closes the underlying network connection 66 | Close() error 67 | 68 | // Wait blocks until the connection has shut down, and returns the 69 | // error causing the shutdown. 70 | Wait() error 71 | 72 | // TODO(hanwen): consider exposing: 73 | // RequestKeyChange 74 | // Disconnect 75 | } 76 | 77 | // DiscardRequests consumes and rejects all requests from the 78 | // passed-in channel. 79 | func DiscardRequests(in <-chan *Request) { 80 | for req := range in { 81 | if req.WantReply { 82 | req.Reply(false, nil) 83 | } 84 | } 85 | } 86 | 87 | // A connection represents an incoming connection. 88 | type connection struct { 89 | transport *handshakeTransport 90 | sshConn 91 | 92 | // The connection protocol. 93 | *mux 94 | } 95 | 96 | func (c *connection) Close() error { 97 | return c.sshConn.conn.Close() 98 | } 99 | 100 | // sshconn provides net.Conn metadata, but disallows direct reads and 101 | // writes. 102 | type sshConn struct { 103 | conn net.Conn 104 | 105 | user string 106 | sessionID []byte 107 | clientVersion []byte 108 | serverVersion []byte 109 | } 110 | 111 | func dup(src []byte) []byte { 112 | dst := make([]byte, len(src)) 113 | copy(dst, src) 114 | return dst 115 | } 116 | 117 | func (c *sshConn) User() string { 118 | return c.user 119 | } 120 | 121 | func (c *sshConn) RemoteAddr() net.Addr { 122 | return c.conn.RemoteAddr() 123 | } 124 | 125 | func (c *sshConn) Close() error { 126 | return c.conn.Close() 127 | } 128 | 129 | func (c *sshConn) LocalAddr() net.Addr { 130 | return c.conn.LocalAddr() 131 | } 132 | 133 | func (c *sshConn) SessionID() []byte { 134 | return dup(c.sessionID) 135 | } 136 | 137 | func (c *sshConn) ClientVersion() []byte { 138 | return dup(c.clientVersion) 139 | } 140 | 141 | func (c *sshConn) ServerVersion() []byte { 142 | return dup(c.serverVersion) 143 | } 144 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/ssh/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | /* 6 | Package ssh implements an SSH client and server. 7 | 8 | SSH is a transport security protocol, an authentication protocol and a 9 | family of application protocols. The most typical application level 10 | protocol is a remote shell and this is specifically implemented. However, 11 | the multiplexed nature of SSH is exposed to users that wish to support 12 | others. 13 | 14 | References: 15 | [PROTOCOL.certkeys]: http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/usr.bin/ssh/PROTOCOL.certkeys?rev=HEAD 16 | [SSH-PARAMETERS]: http://www.iana.org/assignments/ssh-parameters/ssh-parameters.xml#ssh-parameters-1 17 | 18 | This package does not fall under the stability promise of the Go language itself, 19 | so its API may be changed when pressing needs arise. 20 | */ 21 | package ssh // import "golang.org/x/crypto/ssh" 22 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/ssh/internal/bcrypt_pbkdf/bcrypt_pbkdf.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 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 bcrypt_pbkdf implements bcrypt_pbkdf(3) from OpenBSD. 6 | // 7 | // See https://flak.tedunangst.com/post/bcrypt-pbkdf and 8 | // https://cvsweb.openbsd.org/cgi-bin/cvsweb/src/lib/libutil/bcrypt_pbkdf.c. 9 | package bcrypt_pbkdf 10 | 11 | import ( 12 | "crypto/sha512" 13 | "errors" 14 | "golang.org/x/crypto/blowfish" 15 | ) 16 | 17 | const blockSize = 32 18 | 19 | // Key derives a key from the password, salt and rounds count, returning a 20 | // []byte of length keyLen that can be used as cryptographic key. 21 | func Key(password, salt []byte, rounds, keyLen int) ([]byte, error) { 22 | if rounds < 1 { 23 | return nil, errors.New("bcrypt_pbkdf: number of rounds is too small") 24 | } 25 | if len(password) == 0 { 26 | return nil, errors.New("bcrypt_pbkdf: empty password") 27 | } 28 | if len(salt) == 0 || len(salt) > 1<<20 { 29 | return nil, errors.New("bcrypt_pbkdf: bad salt length") 30 | } 31 | if keyLen > 1024 { 32 | return nil, errors.New("bcrypt_pbkdf: keyLen is too large") 33 | } 34 | 35 | numBlocks := (keyLen + blockSize - 1) / blockSize 36 | key := make([]byte, numBlocks*blockSize) 37 | 38 | h := sha512.New() 39 | h.Write(password) 40 | shapass := h.Sum(nil) 41 | 42 | shasalt := make([]byte, 0, sha512.Size) 43 | cnt, tmp := make([]byte, 4), make([]byte, blockSize) 44 | for block := 1; block <= numBlocks; block++ { 45 | h.Reset() 46 | h.Write(salt) 47 | cnt[0] = byte(block >> 24) 48 | cnt[1] = byte(block >> 16) 49 | cnt[2] = byte(block >> 8) 50 | cnt[3] = byte(block) 51 | h.Write(cnt) 52 | bcryptHash(tmp, shapass, h.Sum(shasalt)) 53 | 54 | out := make([]byte, blockSize) 55 | copy(out, tmp) 56 | for i := 2; i <= rounds; i++ { 57 | h.Reset() 58 | h.Write(tmp) 59 | bcryptHash(tmp, shapass, h.Sum(shasalt)) 60 | for j := 0; j < len(out); j++ { 61 | out[j] ^= tmp[j] 62 | } 63 | } 64 | 65 | for i, v := range out { 66 | key[i*numBlocks+(block-1)] = v 67 | } 68 | } 69 | return key[:keyLen], nil 70 | } 71 | 72 | var magic = []byte("OxychromaticBlowfishSwatDynamite") 73 | 74 | func bcryptHash(out, shapass, shasalt []byte) { 75 | c, err := blowfish.NewSaltedCipher(shapass, shasalt) 76 | if err != nil { 77 | panic(err) 78 | } 79 | for i := 0; i < 64; i++ { 80 | blowfish.ExpandKey(shasalt, c) 81 | blowfish.ExpandKey(shapass, c) 82 | } 83 | copy(out, magic) 84 | for i := 0; i < 32; i += 8 { 85 | for j := 0; j < 64; j++ { 86 | c.Encrypt(out[i:i+8], out[i:i+8]) 87 | } 88 | } 89 | // Swap bytes due to different endianness. 90 | for i := 0; i < 32; i += 4 { 91 | out[i+3], out[i+2], out[i+1], out[i] = out[i], out[i+1], out[i+2], out[i+3] 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/ssh/mac.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 ssh 6 | 7 | // Message authentication support 8 | 9 | import ( 10 | "crypto/hmac" 11 | "crypto/sha1" 12 | "crypto/sha256" 13 | "hash" 14 | ) 15 | 16 | type macMode struct { 17 | keySize int 18 | etm bool 19 | new func(key []byte) hash.Hash 20 | } 21 | 22 | // truncatingMAC wraps around a hash.Hash and truncates the output digest to 23 | // a given size. 24 | type truncatingMAC struct { 25 | length int 26 | hmac hash.Hash 27 | } 28 | 29 | func (t truncatingMAC) Write(data []byte) (int, error) { 30 | return t.hmac.Write(data) 31 | } 32 | 33 | func (t truncatingMAC) Sum(in []byte) []byte { 34 | out := t.hmac.Sum(in) 35 | return out[:len(in)+t.length] 36 | } 37 | 38 | func (t truncatingMAC) Reset() { 39 | t.hmac.Reset() 40 | } 41 | 42 | func (t truncatingMAC) Size() int { 43 | return t.length 44 | } 45 | 46 | func (t truncatingMAC) BlockSize() int { return t.hmac.BlockSize() } 47 | 48 | var macModes = map[string]*macMode{ 49 | "hmac-sha2-256-etm@openssh.com": {32, true, func(key []byte) hash.Hash { 50 | return hmac.New(sha256.New, key) 51 | }}, 52 | "hmac-sha2-256": {32, false, func(key []byte) hash.Hash { 53 | return hmac.New(sha256.New, key) 54 | }}, 55 | "hmac-sha1": {20, false, func(key []byte) hash.Hash { 56 | return hmac.New(sha1.New, key) 57 | }}, 58 | "hmac-sha1-96": {20, false, func(key []byte) hash.Hash { 59 | return truncatingMAC{12, hmac.New(sha1.New, key)} 60 | }}, 61 | } 62 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/ssh/ssh_gss.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package ssh 6 | 7 | import ( 8 | "encoding/asn1" 9 | "errors" 10 | ) 11 | 12 | var krb5OID []byte 13 | 14 | func init() { 15 | krb5OID, _ = asn1.Marshal(krb5Mesh) 16 | } 17 | 18 | // GSSAPIClient provides the API to plug-in GSSAPI authentication for client logins. 19 | type GSSAPIClient interface { 20 | // InitSecContext initiates the establishment of a security context for GSS-API between the 21 | // ssh client and ssh server. Initially the token parameter should be specified as nil. 22 | // The routine may return a outputToken which should be transferred to 23 | // the ssh server, where the ssh server will present it to 24 | // AcceptSecContext. If no token need be sent, InitSecContext will indicate this by setting 25 | // needContinue to false. To complete the context 26 | // establishment, one or more reply tokens may be required from the ssh 27 | // server;if so, InitSecContext will return a needContinue which is true. 28 | // In this case, InitSecContext should be called again when the 29 | // reply token is received from the ssh server, passing the reply 30 | // token to InitSecContext via the token parameters. 31 | // See RFC 2743 section 2.2.1 and RFC 4462 section 3.4. 32 | InitSecContext(target string, token []byte, isGSSDelegCreds bool) (outputToken []byte, needContinue bool, err error) 33 | // GetMIC generates a cryptographic MIC for the SSH2 message, and places 34 | // the MIC in a token for transfer to the ssh server. 35 | // The contents of the MIC field are obtained by calling GSS_GetMIC() 36 | // over the following, using the GSS-API context that was just 37 | // established: 38 | // string session identifier 39 | // byte SSH_MSG_USERAUTH_REQUEST 40 | // string user name 41 | // string service 42 | // string "gssapi-with-mic" 43 | // See RFC 2743 section 2.3.1 and RFC 4462 3.5. 44 | GetMIC(micFiled []byte) ([]byte, error) 45 | // Whenever possible, it should be possible for 46 | // DeleteSecContext() calls to be successfully processed even 47 | // if other calls cannot succeed, thereby enabling context-related 48 | // resources to be released. 49 | // In addition to deleting established security contexts, 50 | // gss_delete_sec_context must also be able to delete "half-built" 51 | // security contexts resulting from an incomplete sequence of 52 | // InitSecContext()/AcceptSecContext() calls. 53 | // See RFC 2743 section 2.2.3. 54 | DeleteSecContext() error 55 | } 56 | 57 | // GSSAPIServer provides the API to plug in GSSAPI authentication for server logins. 58 | type GSSAPIServer interface { 59 | // AcceptSecContext allows a remotely initiated security context between the application 60 | // and a remote peer to be established by the ssh client. The routine may return a 61 | // outputToken which should be transferred to the ssh client, 62 | // where the ssh client will present it to InitSecContext. 63 | // If no token need be sent, AcceptSecContext will indicate this 64 | // by setting the needContinue to false. To 65 | // complete the context establishment, one or more reply tokens may be 66 | // required from the ssh client. if so, AcceptSecContext 67 | // will return a needContinue which is true, in which case it 68 | // should be called again when the reply token is received from the ssh 69 | // client, passing the token to AcceptSecContext via the 70 | // token parameters. 71 | // The srcName return value is the authenticated username. 72 | // See RFC 2743 section 2.2.2 and RFC 4462 section 3.4. 73 | AcceptSecContext(token []byte) (outputToken []byte, srcName string, needContinue bool, err error) 74 | // VerifyMIC verifies that a cryptographic MIC, contained in the token parameter, 75 | // fits the supplied message is received from the ssh client. 76 | // See RFC 2743 section 2.3.2. 77 | VerifyMIC(micField []byte, micToken []byte) error 78 | // Whenever possible, it should be possible for 79 | // DeleteSecContext() calls to be successfully processed even 80 | // if other calls cannot succeed, thereby enabling context-related 81 | // resources to be released. 82 | // In addition to deleting established security contexts, 83 | // gss_delete_sec_context must also be able to delete "half-built" 84 | // security contexts resulting from an incomplete sequence of 85 | // InitSecContext()/AcceptSecContext() calls. 86 | // See RFC 2743 section 2.2.3. 87 | DeleteSecContext() error 88 | } 89 | 90 | var ( 91 | // OpenSSH supports Kerberos V5 mechanism only for GSS-API authentication, 92 | // so we also support the krb5 mechanism only. 93 | // See RFC 1964 section 1. 94 | krb5Mesh = asn1.ObjectIdentifier{1, 2, 840, 113554, 1, 2, 2} 95 | ) 96 | 97 | // The GSS-API authentication method is initiated when the client sends an SSH_MSG_USERAUTH_REQUEST 98 | // See RFC 4462 section 3.2. 99 | type userAuthRequestGSSAPI struct { 100 | N uint32 101 | OIDS []asn1.ObjectIdentifier 102 | } 103 | 104 | func parseGSSAPIPayload(payload []byte) (*userAuthRequestGSSAPI, error) { 105 | n, rest, ok := parseUint32(payload) 106 | if !ok { 107 | return nil, errors.New("parse uint32 failed") 108 | } 109 | s := &userAuthRequestGSSAPI{ 110 | N: n, 111 | OIDS: make([]asn1.ObjectIdentifier, n), 112 | } 113 | for i := 0; i < int(n); i++ { 114 | var ( 115 | desiredMech []byte 116 | err error 117 | ) 118 | desiredMech, rest, ok = parseString(rest) 119 | if !ok { 120 | return nil, errors.New("parse string failed") 121 | } 122 | if rest, err = asn1.Unmarshal(desiredMech, &s.OIDS[i]); err != nil { 123 | return nil, err 124 | } 125 | 126 | } 127 | return s, nil 128 | } 129 | 130 | // See RFC 4462 section 3.6. 131 | func buildMIC(sessionID string, username string, service string, authMethod string) []byte { 132 | out := make([]byte, 0, 0) 133 | out = appendString(out, sessionID) 134 | out = append(out, msgUserAuthRequest) 135 | out = appendString(out, username) 136 | out = appendString(out, service) 137 | out = appendString(out, authMethod) 138 | return out 139 | } 140 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/ssh/streamlocal.go: -------------------------------------------------------------------------------- 1 | package ssh 2 | 3 | import ( 4 | "errors" 5 | "io" 6 | "net" 7 | ) 8 | 9 | // streamLocalChannelOpenDirectMsg is a struct used for SSH_MSG_CHANNEL_OPEN message 10 | // with "direct-streamlocal@openssh.com" string. 11 | // 12 | // See openssh-portable/PROTOCOL, section 2.4. connection: Unix domain socket forwarding 13 | // https://github.com/openssh/openssh-portable/blob/master/PROTOCOL#L235 14 | type streamLocalChannelOpenDirectMsg struct { 15 | socketPath string 16 | reserved0 string 17 | reserved1 uint32 18 | } 19 | 20 | // forwardedStreamLocalPayload is a struct used for SSH_MSG_CHANNEL_OPEN message 21 | // with "forwarded-streamlocal@openssh.com" string. 22 | type forwardedStreamLocalPayload struct { 23 | SocketPath string 24 | Reserved0 string 25 | } 26 | 27 | // streamLocalChannelForwardMsg is a struct used for SSH2_MSG_GLOBAL_REQUEST message 28 | // with "streamlocal-forward@openssh.com"/"cancel-streamlocal-forward@openssh.com" string. 29 | type streamLocalChannelForwardMsg struct { 30 | socketPath string 31 | } 32 | 33 | // ListenUnix is similar to ListenTCP but uses a Unix domain socket. 34 | func (c *Client) ListenUnix(socketPath string) (net.Listener, error) { 35 | c.handleForwardsOnce.Do(c.handleForwards) 36 | m := streamLocalChannelForwardMsg{ 37 | socketPath, 38 | } 39 | // send message 40 | ok, _, err := c.SendRequest("streamlocal-forward@openssh.com", true, Marshal(&m)) 41 | if err != nil { 42 | return nil, err 43 | } 44 | if !ok { 45 | return nil, errors.New("ssh: streamlocal-forward@openssh.com request denied by peer") 46 | } 47 | ch := c.forwards.add(&net.UnixAddr{Name: socketPath, Net: "unix"}) 48 | 49 | return &unixListener{socketPath, c, ch}, nil 50 | } 51 | 52 | func (c *Client) dialStreamLocal(socketPath string) (Channel, error) { 53 | msg := streamLocalChannelOpenDirectMsg{ 54 | socketPath: socketPath, 55 | } 56 | ch, in, err := c.OpenChannel("direct-streamlocal@openssh.com", Marshal(&msg)) 57 | if err != nil { 58 | return nil, err 59 | } 60 | go DiscardRequests(in) 61 | return ch, err 62 | } 63 | 64 | type unixListener struct { 65 | socketPath string 66 | 67 | conn *Client 68 | in <-chan forward 69 | } 70 | 71 | // Accept waits for and returns the next connection to the listener. 72 | func (l *unixListener) Accept() (net.Conn, error) { 73 | s, ok := <-l.in 74 | if !ok { 75 | return nil, io.EOF 76 | } 77 | ch, incoming, err := s.newCh.Accept() 78 | if err != nil { 79 | return nil, err 80 | } 81 | go DiscardRequests(incoming) 82 | 83 | return &chanConn{ 84 | Channel: ch, 85 | laddr: &net.UnixAddr{ 86 | Name: l.socketPath, 87 | Net: "unix", 88 | }, 89 | raddr: &net.UnixAddr{ 90 | Name: "@", 91 | Net: "unix", 92 | }, 93 | }, nil 94 | } 95 | 96 | // Close closes the listener. 97 | func (l *unixListener) Close() error { 98 | // this also closes the listener. 99 | l.conn.forwards.remove(&net.UnixAddr{Name: l.socketPath, Net: "unix"}) 100 | m := streamLocalChannelForwardMsg{ 101 | l.socketPath, 102 | } 103 | ok, _, err := l.conn.SendRequest("cancel-streamlocal-forward@openssh.com", true, Marshal(&m)) 104 | if err == nil && !ok { 105 | err = errors.New("ssh: cancel-streamlocal-forward@openssh.com failed") 106 | } 107 | return err 108 | } 109 | 110 | // Addr returns the listener's network address. 111 | func (l *unixListener) Addr() net.Addr { 112 | return &net.UnixAddr{ 113 | Name: l.socketPath, 114 | Net: "unix", 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/AUTHORS: -------------------------------------------------------------------------------- 1 | # This source code refers to The Go Authors for copyright purposes. 2 | # The master list of authors is in the main Go distribution, 3 | # visible at http://tip.golang.org/AUTHORS. 4 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | # This source code was written by the Go contributors. 2 | # The master list of contributors is in the main Go distribution, 3 | # visible at http://tip.golang.org/CONTRIBUTORS. 4 | -------------------------------------------------------------------------------- /vendor/golang.org/x/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 | "mipsle", "mips64le", "mips64p32le", 50 | "nios2", 51 | "ppc64le", 52 | "riscv", "riscv64", 53 | "sh": 54 | return littleEndian{} 55 | case "armbe", "arm64be", 56 | "m68k", 57 | "mips", "mips64", "mips64p32", 58 | "ppc", "ppc64", 59 | "s390", "s390x", 60 | "shbe", 61 | "sparc", "sparc64": 62 | return bigEndian{} 63 | } 64 | panic("unknown architecture") 65 | } 66 | -------------------------------------------------------------------------------- /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 | const cacheLineSize = 64 10 | 11 | func initOptions() { 12 | options = []option{ 13 | {Name: "fp", Feature: &ARM64.HasFP}, 14 | {Name: "asimd", Feature: &ARM64.HasASIMD}, 15 | {Name: "evstrm", Feature: &ARM64.HasEVTSTRM}, 16 | {Name: "aes", Feature: &ARM64.HasAES}, 17 | {Name: "fphp", Feature: &ARM64.HasFPHP}, 18 | {Name: "jscvt", Feature: &ARM64.HasJSCVT}, 19 | {Name: "lrcpc", Feature: &ARM64.HasLRCPC}, 20 | {Name: "pmull", Feature: &ARM64.HasPMULL}, 21 | {Name: "sha1", Feature: &ARM64.HasSHA1}, 22 | {Name: "sha2", Feature: &ARM64.HasSHA2}, 23 | {Name: "sha3", Feature: &ARM64.HasSHA3}, 24 | {Name: "sha512", Feature: &ARM64.HasSHA512}, 25 | {Name: "sm3", Feature: &ARM64.HasSM3}, 26 | {Name: "sm4", Feature: &ARM64.HasSM4}, 27 | {Name: "sve", Feature: &ARM64.HasSVE}, 28 | {Name: "crc32", Feature: &ARM64.HasCRC32}, 29 | {Name: "atomics", Feature: &ARM64.HasATOMICS}, 30 | {Name: "asimdhp", Feature: &ARM64.HasASIMDHP}, 31 | {Name: "cpuid", Feature: &ARM64.HasCPUID}, 32 | {Name: "asimrdm", Feature: &ARM64.HasASIMDRDM}, 33 | {Name: "fcma", Feature: &ARM64.HasFCMA}, 34 | {Name: "dcpop", Feature: &ARM64.HasDCPOP}, 35 | {Name: "asimddp", Feature: &ARM64.HasASIMDDP}, 36 | {Name: "asimdfhm", Feature: &ARM64.HasASIMDFHM}, 37 | } 38 | } 39 | 40 | func archInit() { 41 | switch runtime.GOOS { 42 | case "freebsd": 43 | readARM64Registers() 44 | case "linux", "netbsd": 45 | doinit() 46 | default: 47 | // Most platforms don't seem to allow reading these registers. 48 | // 49 | // OpenBSD: 50 | // See https://golang.org/issue/31746 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 | 19 | // darwinSupportsAVX512 is implemented in cpu_x86.s for gc compiler 20 | // and in cpu_gccgo_x86.go for gccgo. 21 | func darwinSupportsAVX512() bool 22 | -------------------------------------------------------------------------------- /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 | // +build 386 amd64 amd64p32 6 | // +build gccgo 7 | 8 | #include 9 | #include 10 | 11 | // Need to wrap __get_cpuid_count because it's declared as static. 12 | int 13 | gccgoGetCpuidCount(uint32_t leaf, uint32_t subleaf, 14 | uint32_t *eax, uint32_t *ebx, 15 | uint32_t *ecx, uint32_t *edx) 16 | { 17 | return __get_cpuid_count(leaf, subleaf, eax, ebx, ecx, edx); 18 | } 19 | 20 | // xgetbv reads the contents of an XCR (Extended Control Register) 21 | // specified in the ECX register into registers EDX:EAX. 22 | // Currently, the only supported value for XCR is 0. 23 | // 24 | // TODO: Replace with a better alternative: 25 | // 26 | // #include 27 | // 28 | // #pragma GCC target("xsave") 29 | // 30 | // void gccgoXgetbv(uint32_t *eax, uint32_t *edx) { 31 | // unsigned long long x = _xgetbv(0); 32 | // *eax = x & 0xffffffff; 33 | // *edx = (x >> 32) & 0xffffffff; 34 | // } 35 | // 36 | // Note that _xgetbv is defined starting with GCC 8. 37 | void 38 | gccgoXgetbv(uint32_t *eax, uint32_t *edx) 39 | { 40 | __asm(" xorl %%ecx, %%ecx\n" 41 | " xgetbv" 42 | : "=a"(*eax), "=d"(*edx)); 43 | } 44 | -------------------------------------------------------------------------------- /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 | // HWCAP/HWCAP2 bits. These are exposed by Linux. 8 | const ( 9 | hwcap_FP = 1 << 0 10 | hwcap_ASIMD = 1 << 1 11 | hwcap_EVTSTRM = 1 << 2 12 | hwcap_AES = 1 << 3 13 | hwcap_PMULL = 1 << 4 14 | hwcap_SHA1 = 1 << 5 15 | hwcap_SHA2 = 1 << 6 16 | hwcap_CRC32 = 1 << 7 17 | hwcap_ATOMICS = 1 << 8 18 | hwcap_FPHP = 1 << 9 19 | hwcap_ASIMDHP = 1 << 10 20 | hwcap_CPUID = 1 << 11 21 | hwcap_ASIMDRDM = 1 << 12 22 | hwcap_JSCVT = 1 << 13 23 | hwcap_FCMA = 1 << 14 24 | hwcap_LRCPC = 1 << 15 25 | hwcap_DCPOP = 1 << 16 26 | hwcap_SHA3 = 1 << 17 27 | hwcap_SM3 = 1 << 18 28 | hwcap_SM4 = 1 << 19 29 | hwcap_ASIMDDP = 1 << 20 30 | hwcap_SHA512 = 1 << 21 31 | hwcap_SVE = 1 << 22 32 | hwcap_ASIMDFHM = 1 << 23 33 | ) 34 | 35 | func doinit() { 36 | if err := readHWCAP(); err != nil { 37 | // failed to read /proc/self/auxv, try reading registers directly 38 | readARM64Registers() 39 | return 40 | } 41 | 42 | // HWCAP feature bits 43 | ARM64.HasFP = isSet(hwCap, hwcap_FP) 44 | ARM64.HasASIMD = isSet(hwCap, hwcap_ASIMD) 45 | ARM64.HasEVTSTRM = isSet(hwCap, hwcap_EVTSTRM) 46 | ARM64.HasAES = isSet(hwCap, hwcap_AES) 47 | ARM64.HasPMULL = isSet(hwCap, hwcap_PMULL) 48 | ARM64.HasSHA1 = isSet(hwCap, hwcap_SHA1) 49 | ARM64.HasSHA2 = isSet(hwCap, hwcap_SHA2) 50 | ARM64.HasCRC32 = isSet(hwCap, hwcap_CRC32) 51 | ARM64.HasATOMICS = isSet(hwCap, hwcap_ATOMICS) 52 | ARM64.HasFPHP = isSet(hwCap, hwcap_FPHP) 53 | ARM64.HasASIMDHP = isSet(hwCap, hwcap_ASIMDHP) 54 | ARM64.HasCPUID = isSet(hwCap, hwcap_CPUID) 55 | ARM64.HasASIMDRDM = isSet(hwCap, hwcap_ASIMDRDM) 56 | ARM64.HasJSCVT = isSet(hwCap, hwcap_JSCVT) 57 | ARM64.HasFCMA = isSet(hwCap, hwcap_FCMA) 58 | ARM64.HasLRCPC = isSet(hwCap, hwcap_LRCPC) 59 | ARM64.HasDCPOP = isSet(hwCap, hwcap_DCPOP) 60 | ARM64.HasSHA3 = isSet(hwCap, hwcap_SHA3) 61 | ARM64.HasSM3 = isSet(hwCap, hwcap_SM3) 62 | ARM64.HasSM4 = isSet(hwCap, hwcap_SM4) 63 | ARM64.HasASIMDDP = isSet(hwCap, hwcap_ASIMDDP) 64 | ARM64.HasSHA512 = isSet(hwCap, hwcap_SHA512) 65 | ARM64.HasSVE = isSet(hwCap, hwcap_SVE) 66 | ARM64.HasASIMDFHM = isSet(hwCap, hwcap_ASIMDFHM) 67 | } 68 | 69 | func isSet(hwc uint, value uint) bool { 70 | return hwc&value != 0 71 | } 72 | -------------------------------------------------------------------------------- /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_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_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 && arm64 6 | // +build !linux,!netbsd,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_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: "erms", Feature: &X86.HasERMS}, 43 | {Name: "fma", Feature: &X86.HasFMA}, 44 | {Name: "osxsave", Feature: &X86.HasOSXSAVE}, 45 | {Name: "pclmulqdq", Feature: &X86.HasPCLMULQDQ}, 46 | {Name: "popcnt", Feature: &X86.HasPOPCNT}, 47 | {Name: "rdrand", Feature: &X86.HasRDRAND}, 48 | {Name: "rdseed", Feature: &X86.HasRDSEED}, 49 | {Name: "sse3", Feature: &X86.HasSSE3}, 50 | {Name: "sse41", Feature: &X86.HasSSE41}, 51 | {Name: "sse42", Feature: &X86.HasSSE42}, 52 | {Name: "ssse3", Feature: &X86.HasSSSE3}, 53 | 54 | // These capabilities should always be enabled on amd64: 55 | {Name: "sse2", Feature: &X86.HasSSE2, Required: runtime.GOARCH == "amd64"}, 56 | } 57 | } 58 | 59 | func archInit() { 60 | 61 | Initialized = true 62 | 63 | maxID, _, _, _ := cpuid(0, 0) 64 | 65 | if maxID < 1 { 66 | return 67 | } 68 | 69 | _, _, ecx1, edx1 := cpuid(1, 0) 70 | X86.HasSSE2 = isSet(26, edx1) 71 | 72 | X86.HasSSE3 = isSet(0, ecx1) 73 | X86.HasPCLMULQDQ = isSet(1, ecx1) 74 | X86.HasSSSE3 = isSet(9, ecx1) 75 | X86.HasFMA = isSet(12, ecx1) 76 | X86.HasSSE41 = isSet(19, ecx1) 77 | X86.HasSSE42 = isSet(20, ecx1) 78 | X86.HasPOPCNT = isSet(23, ecx1) 79 | X86.HasAES = isSet(25, ecx1) 80 | X86.HasOSXSAVE = isSet(27, ecx1) 81 | X86.HasRDRAND = isSet(30, ecx1) 82 | 83 | var osSupportsAVX, osSupportsAVX512 bool 84 | // For XGETBV, OSXSAVE bit is required and sufficient. 85 | if X86.HasOSXSAVE { 86 | eax, _ := xgetbv() 87 | // Check if XMM and YMM registers have OS support. 88 | osSupportsAVX = isSet(1, eax) && isSet(2, eax) 89 | 90 | if runtime.GOOS == "darwin" { 91 | // Check darwin commpage for AVX512 support. Necessary because: 92 | // https://github.com/apple/darwin-xnu/blob/0a798f6738bc1db01281fc08ae024145e84df927/osfmk/i386/fpu.c#L175-L201 93 | osSupportsAVX512 = osSupportsAVX && darwinSupportsAVX512() 94 | } else { 95 | // Check if OPMASK and ZMM registers have OS support. 96 | osSupportsAVX512 = osSupportsAVX && isSet(5, eax) && isSet(6, eax) && isSet(7, eax) 97 | } 98 | } 99 | 100 | X86.HasAVX = isSet(28, ecx1) && osSupportsAVX 101 | 102 | if maxID < 7 { 103 | return 104 | } 105 | 106 | _, ebx7, ecx7, edx7 := cpuid(7, 0) 107 | X86.HasBMI1 = isSet(3, ebx7) 108 | X86.HasAVX2 = isSet(5, ebx7) && osSupportsAVX 109 | X86.HasBMI2 = isSet(8, ebx7) 110 | X86.HasERMS = isSet(9, ebx7) 111 | X86.HasRDSEED = isSet(18, ebx7) 112 | X86.HasADX = isSet(19, ebx7) 113 | 114 | X86.HasAVX512 = isSet(16, ebx7) && osSupportsAVX512 // Because avx-512 foundation is the core required extension 115 | if X86.HasAVX512 { 116 | X86.HasAVX512F = true 117 | X86.HasAVX512CD = isSet(28, ebx7) 118 | X86.HasAVX512ER = isSet(27, ebx7) 119 | X86.HasAVX512PF = isSet(26, ebx7) 120 | X86.HasAVX512VL = isSet(31, ebx7) 121 | X86.HasAVX512BW = isSet(30, ebx7) 122 | X86.HasAVX512DQ = isSet(17, ebx7) 123 | X86.HasAVX512IFMA = isSet(21, ebx7) 124 | X86.HasAVX512VBMI = isSet(1, ecx7) 125 | X86.HasAVX5124VNNIW = isSet(2, edx7) 126 | X86.HasAVX5124FMAPS = isSet(3, edx7) 127 | X86.HasAVX512VPOPCNTDQ = isSet(14, ecx7) 128 | X86.HasAVX512VPCLMULQDQ = isSet(10, ecx7) 129 | X86.HasAVX512VNNI = isSet(11, ecx7) 130 | X86.HasAVX512GFNI = isSet(8, ecx7) 131 | X86.HasAVX512VAES = isSet(9, ecx7) 132 | X86.HasAVX512VBMI2 = isSet(6, ecx7) 133 | X86.HasAVX512BITALG = isSet(12, ecx7) 134 | 135 | eax71, _, _, _ := cpuid(7, 1) 136 | X86.HasAVX512BF16 = isSet(5, eax71) 137 | } 138 | } 139 | 140 | func isSet(bitpos uint, value uint32) bool { 141 | 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 | buf, err := ioutil.ReadFile(procAuxv) 28 | if err != nil { 29 | // e.g. on android /proc/self/auxv is not accessible, so silently 30 | // ignore the error and leave Initialized = false. On some 31 | // architectures (e.g. arm64) doinit() implements a fallback 32 | // readout and will set Initialized = true again. 33 | return err 34 | } 35 | bo := hostByteOrder() 36 | for len(buf) >= 2*(uintSize/8) { 37 | var tag, val uint 38 | switch uintSize { 39 | case 32: 40 | tag = uint(bo.Uint32(buf[0:])) 41 | val = uint(bo.Uint32(buf[4:])) 42 | buf = buf[8:] 43 | case 64: 44 | tag = uint(bo.Uint64(buf[0:])) 45 | val = uint(bo.Uint64(buf[8:])) 46 | buf = buf[16:] 47 | } 48 | switch tag { 49 | case _AT_HWCAP: 50 | hwCap = val 51 | case _AT_HWCAP2: 52 | hwCap2 = val 53 | } 54 | } 55 | return nil 56 | } 57 | -------------------------------------------------------------------------------- /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 | // Morever, 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 | # golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 2 | ## explicit 3 | golang.org/x/crypto/blowfish 4 | golang.org/x/crypto/chacha20 5 | golang.org/x/crypto/curve25519 6 | golang.org/x/crypto/curve25519/internal/field 7 | golang.org/x/crypto/ed25519 8 | golang.org/x/crypto/ed25519/internal/edwards25519 9 | golang.org/x/crypto/internal/poly1305 10 | golang.org/x/crypto/internal/subtle 11 | golang.org/x/crypto/ssh 12 | golang.org/x/crypto/ssh/internal/bcrypt_pbkdf 13 | # golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 14 | ## explicit 15 | # golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e 16 | ## explicit 17 | golang.org/x/sys/cpu 18 | # golang.org/x/tools v0.1.7 19 | ## explicit 20 | --------------------------------------------------------------------------------