├── cmd
└── solsha3
│ └── main.go
├── .travis.yml
├── go.mod
├── .goreleaser.yml
├── vendor
├── golang.org
│ └── x
│ │ ├── sys
│ │ ├── AUTHORS
│ │ ├── CONTRIBUTORS
│ │ ├── cpu
│ │ │ ├── cpu_zos.go
│ │ │ ├── cpu_other_arm.go
│ │ │ ├── cpu_other_arm64.go
│ │ │ ├── cpu_riscv64.go
│ │ │ ├── cpu_gc_arm64.go
│ │ │ ├── cpu_mipsx.go
│ │ │ ├── cpu_other_mips64x.go
│ │ │ ├── cpu_gccgo_arm64.go
│ │ │ ├── cpu_linux_noinit.go
│ │ │ ├── cpu_mips64x.go
│ │ │ ├── cpu_linux.go
│ │ │ ├── cpu_ppc64x.go
│ │ │ ├── asm_aix_ppc64.s
│ │ │ ├── cpu_wasm.go
│ │ │ ├── cpu_gc_x86.go
│ │ │ ├── cpu_linux_mips64x.go
│ │ │ ├── cpu_x86.s
│ │ │ ├── cpu_aix.go
│ │ │ ├── cpu_zos_s390x.go
│ │ │ ├── cpu_gc_s390x.go
│ │ │ ├── cpu_gccgo_x86.go
│ │ │ ├── syscall_aix_gccgo.go
│ │ │ ├── cpu_arm64.s
│ │ │ ├── cpu_linux_ppc64x.go
│ │ │ ├── cpu_linux_s390x.go
│ │ │ ├── cpu_gccgo_s390x.go
│ │ │ ├── syscall_aix_ppc64_gc.go
│ │ │ ├── cpu_gccgo_x86.c
│ │ │ ├── hwcap_linux.go
│ │ │ ├── cpu_linux_arm.go
│ │ │ ├── byteorder.go
│ │ │ ├── cpu_s390x.s
│ │ │ ├── cpu_linux_arm64.go
│ │ │ ├── cpu_arm.go
│ │ │ ├── cpu_arm64.go
│ │ │ ├── cpu_x86.go
│ │ │ ├── cpu_netbsd_arm64.go
│ │ │ └── cpu_s390x.go
│ │ ├── PATENTS
│ │ └── LICENSE
│ │ └── crypto
│ │ ├── AUTHORS
│ │ ├── CONTRIBUTORS
│ │ ├── sha3
│ │ ├── keccakf_amd64.go
│ │ ├── register.go
│ │ ├── shake_generic.go
│ │ ├── xor.go
│ │ ├── xor_generic.go
│ │ ├── hashes_generic.go
│ │ ├── sha3_s390x.s
│ │ ├── xor_unaligned.go
│ │ ├── hashes.go
│ │ ├── doc.go
│ │ ├── shake.go
│ │ ├── sha3.go
│ │ ├── sha3_s390x.go
│ │ └── keccakf.go
│ │ ├── PATENTS
│ │ └── LICENSE
├── modules.txt
└── github.com
│ └── ethereum
│ └── go-ethereum
│ ├── common
│ ├── big.go
│ ├── path.go
│ ├── test_utils.go
│ ├── debug.go
│ ├── size.go
│ ├── format.go
│ ├── math
│ │ ├── integer.go
│ │ └── big.go
│ ├── bytes.go
│ └── hexutil
│ │ ├── hexutil.go
│ │ └── json.go
│ └── COPYING.LESSER
├── .editorconfig
├── .gitignore
├── Makefile
├── example
├── legacy_array_example.go
├── bytes_example.go
├── simple_example.go
├── legacy_usage_example.go
├── usage_example.go
└── js
│ └── test.js
├── string.go
├── bool.go
├── string_test.go
├── bool_test.go
├── address.go
├── LICENSE.md
├── address_test.go
├── solsha3.go
├── README.md
├── bytes_test.go
├── util.go
├── bytes.go
├── uint_test.go
└── solsha3_test.go
/cmd/solsha3/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | func main() {
4 | // TODO
5 | }
6 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: go
2 |
3 | go:
4 | - "1.11.x"
5 | - "master"
6 |
7 | script:
8 | - go get ./
9 | - make test
10 |
--------------------------------------------------------------------------------
/go.mod:
--------------------------------------------------------------------------------
1 | module github.com/miguelmota/go-solidity-sha3
2 |
3 | go 1.16
4 |
5 | require (
6 | github.com/ethereum/go-ethereum v1.10.3
7 | golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a
8 | )
9 |
--------------------------------------------------------------------------------
/.goreleaser.yml:
--------------------------------------------------------------------------------
1 | builds:
2 | - main: ./cmd/solsha3/main.go
3 | goos:
4 | - windows
5 | - linux
6 | goarch:
7 | - 386
8 | - amd64
9 | - arm
10 | - arm64
11 |
--------------------------------------------------------------------------------
/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/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 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | charset = utf-8
5 | end_of_line = lf
6 | insert_final_newline = true
7 | trim_trailing_whitespace = true
8 |
9 | [*.sol]
10 | indent_style = space
11 | indent_size = 2
12 |
13 | [*.js]
14 | indent_style = space
15 | indent_size = 2
16 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Binaries for programs and plugins
2 | *.exe
3 | *.dll
4 | *.so
5 | *.dylib
6 |
7 | # Test binary, build with `go test -c`
8 | *.test
9 |
10 | # Output of the go coverage tool, specifically when used with LiteIDE
11 | *.out
12 |
13 | .DS_Store
14 |
15 | dist
16 | bin
17 | build
18 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/sys/cpu/cpu_zos.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 | func archInit() {
8 | doinit()
9 | Initialized = true
10 | }
11 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | @echo "no default"
3 |
4 | .PHONY: test
5 | test:
6 | @go test -v `go list ./... | grep -v example` $(ARGS) && echo "ALL PASS" || echo "FAILURE"
7 |
8 | .PHONY: deps
9 | deps:
10 | @GO111MODULE=on go mod vendor
11 |
12 | .PHONY: release
13 | release:
14 | @rm -rf dist
15 | @goreleaser
16 |
--------------------------------------------------------------------------------
/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_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_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_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 |
--------------------------------------------------------------------------------
/example/legacy_array_example.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "encoding/hex"
5 | "fmt"
6 |
7 | "github.com/miguelmota/go-solidity-sha3"
8 | )
9 |
10 | func main() {
11 | hash := solsha3.SoliditySHA3(
12 | solsha3.Uint8Array([3]uint{1, 2, 3}),
13 | )
14 |
15 | fmt.Println(hex.EncodeToString(hash)) // 6e0c627900b24bd432fe7b1f713f1b0744091a646a9fe4a65a18dfed21f2949c
16 | }
17 |
--------------------------------------------------------------------------------
/example/bytes_example.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "encoding/hex"
5 | "fmt"
6 |
7 | "github.com/miguelmota/go-solidity-sha3"
8 | )
9 |
10 | func main() {
11 | hash := solsha3.SoliditySHA3(
12 | solsha3.Bytes4([]byte{0xe0, 0xb6, 0xfc, 0xfc}),
13 | )
14 |
15 | fmt.Println(hex.EncodeToString(hash)) // 0xa1204967c3aa63863e35064a313503edf747e6de2721e9dec149014654fddbba
16 | }
17 |
--------------------------------------------------------------------------------
/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_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/modules.txt:
--------------------------------------------------------------------------------
1 | # github.com/ethereum/go-ethereum v1.10.3
2 | ## explicit
3 | github.com/ethereum/go-ethereum/common
4 | github.com/ethereum/go-ethereum/common/hexutil
5 | github.com/ethereum/go-ethereum/common/math
6 | # golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a
7 | ## explicit
8 | golang.org/x/crypto/sha3
9 | # golang.org/x/sys v0.0.0-20210420205809-ac73e9fd8988
10 | golang.org/x/sys/cpu
11 |
--------------------------------------------------------------------------------
/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/crypto/sha3/keccakf_amd64.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | //go:build amd64 && !purego && gc
6 | // +build amd64,!purego,gc
7 |
8 | package sha3
9 |
10 | // This function is implemented in keccakf_amd64.s.
11 |
12 | //go:noescape
13 |
14 | func keccakF1600(a *[25]uint64)
15 |
--------------------------------------------------------------------------------
/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_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_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/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 | // +build gc
6 |
7 | #include "textflag.h"
8 |
9 | //
10 | // System calls for ppc64, AIX are implemented in runtime/syscall_aix.go
11 | //
12 |
13 | TEXT ·syscall6(SB),NOSPLIT,$0-88
14 | JMP syscall·syscall6(SB)
15 |
16 | TEXT ·rawSyscall6(SB),NOSPLIT,$0-88
17 | JMP syscall·rawSyscall6(SB)
18 |
--------------------------------------------------------------------------------
/example/simple_example.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "encoding/hex"
5 | "fmt"
6 |
7 | "github.com/miguelmota/go-solidity-sha3"
8 | )
9 |
10 | func main() {
11 | hash := solsha3.SoliditySHA3(
12 | // types
13 | []string{"address", "uint256"},
14 |
15 | // values
16 | []interface{}{
17 | "0x935F7770265D0797B621c49A5215849c333Cc3ce",
18 | "100000000000000000",
19 | },
20 | )
21 |
22 | fmt.Println(hex.EncodeToString(hash)) // 0a3844b522d9e3a837ae56d4c57d668feb26325834bf4ba49e153d84ed7ad53d
23 | }
24 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/crypto/sha3/register.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 | //go:build go1.4
6 | // +build go1.4
7 |
8 | package sha3
9 |
10 | import (
11 | "crypto"
12 | )
13 |
14 | func init() {
15 | crypto.RegisterHash(crypto.SHA3_224, New224)
16 | crypto.RegisterHash(crypto.SHA3_256, New256)
17 | crypto.RegisterHash(crypto.SHA3_384, New384)
18 | crypto.RegisterHash(crypto.SHA3_512, New512)
19 | }
20 |
--------------------------------------------------------------------------------
/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_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 |
--------------------------------------------------------------------------------
/string.go:
--------------------------------------------------------------------------------
1 | package solsha3
2 |
3 | import "reflect"
4 |
5 | // String string
6 | func String(input interface{}) []byte {
7 | switch v := input.(type) {
8 | case []byte:
9 | return v
10 | case string:
11 | return []byte(v)
12 | }
13 |
14 | if isArray(input) {
15 | return StringArray(input)
16 | }
17 |
18 | return []byte("")
19 | }
20 |
21 | // StringArray string
22 | func StringArray(input interface{}) []byte {
23 | var values []byte
24 | s := reflect.ValueOf(input)
25 | for i := 0; i < s.Len(); i++ {
26 | val := s.Index(i).Interface()
27 | result := String(val)
28 | values = append(values, result...)
29 | }
30 | return values
31 | }
32 |
--------------------------------------------------------------------------------
/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/crypto/sha3/shake_generic.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | //go:build !gc || purego || !s390x
6 | // +build !gc purego !s390x
7 |
8 | package sha3
9 |
10 | // newShake128Asm returns an assembly implementation of SHAKE-128 if available,
11 | // otherwise it returns nil.
12 | func newShake128Asm() ShakeHash {
13 | return nil
14 | }
15 |
16 | // newShake256Asm returns an assembly implementation of SHAKE-256 if available,
17 | // otherwise it returns nil.
18 | func newShake256Asm() ShakeHash {
19 | return nil
20 | }
21 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/sys/cpu/cpu_x86.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 | // +build 386 amd64 amd64p32
6 | // +build gc
7 |
8 | #include "textflag.h"
9 |
10 | // func cpuid(eaxArg, ecxArg uint32) (eax, ebx, ecx, edx uint32)
11 | TEXT ·cpuid(SB), NOSPLIT, $0-24
12 | MOVL eaxArg+0(FP), AX
13 | MOVL ecxArg+4(FP), CX
14 | CPUID
15 | MOVL AX, eax+8(FP)
16 | MOVL BX, ebx+12(FP)
17 | MOVL CX, ecx+16(FP)
18 | MOVL DX, edx+20(FP)
19 | RET
20 |
21 | // func xgetbv() (eax, edx uint32)
22 | TEXT ·xgetbv(SB),NOSPLIT,$0-8
23 | MOVL $0, CX
24 | XGETBV
25 | MOVL AX, eax+0(FP)
26 | MOVL DX, edx+4(FP)
27 | RET
28 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/crypto/sha3/xor.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | //go:build (!amd64 && !386 && !ppc64le) || purego
6 | // +build !amd64,!386,!ppc64le purego
7 |
8 | package sha3
9 |
10 | // A storageBuf is an aligned array of maxRate bytes.
11 | type storageBuf [maxRate]byte
12 |
13 | func (b *storageBuf) asBytes() *[maxRate]byte {
14 | return (*[maxRate]byte)(b)
15 | }
16 |
17 | var (
18 | xorIn = xorInGeneric
19 | copyOut = copyOutGeneric
20 | xorInUnaligned = xorInGeneric
21 | copyOutUnaligned = copyOutGeneric
22 | )
23 |
24 | const xorImplementationUnaligned = "generic"
25 |
--------------------------------------------------------------------------------
/bool.go:
--------------------------------------------------------------------------------
1 | package solsha3
2 |
3 | import (
4 | "reflect"
5 |
6 | "github.com/ethereum/go-ethereum/common"
7 | )
8 |
9 | // Bool bool
10 | func Bool(input interface{}) []byte {
11 | switch v := input.(type) {
12 | case bool:
13 | if v {
14 | return []byte{0x1}
15 | }
16 | return []byte{0x0}
17 | }
18 |
19 | if isArray(input) {
20 | return BoolArray(input)
21 | }
22 |
23 | return []byte{0x0}
24 | }
25 |
26 | // BoolArray bool array
27 | func BoolArray(input interface{}) []byte {
28 | var values []byte
29 | s := reflect.ValueOf(input)
30 | for i := 0; i < s.Len(); i++ {
31 | val := s.Index(i).Interface()
32 | result := common.LeftPadBytes(Bool(val), 32)
33 | values = append(values, result...)
34 | }
35 | return values
36 | }
37 |
--------------------------------------------------------------------------------
/example/legacy_usage_example.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "encoding/hex"
5 | "fmt"
6 | "math/big"
7 |
8 | "github.com/miguelmota/go-solidity-sha3"
9 | )
10 |
11 | func main() {
12 | hash := solsha3.SoliditySHA3(
13 | solsha3.Address("0x12459c951127e0c374ff9105dda097662a027093"),
14 | solsha3.Uint256(big.NewInt(100)),
15 | solsha3.String("foo"),
16 | solsha3.Bytes32("bar"),
17 | solsha3.Bool(true),
18 | )
19 |
20 | fmt.Println(hex.EncodeToString(hash)) // 417a4c44724701ba79bb363151dff48909bc058a2c75a81e9cf5208ae4699369
21 |
22 | hash2 := solsha3.SoliditySHA3WithPrefix(
23 | solsha3.String("hello"),
24 | )
25 |
26 | fmt.Println(hex.EncodeToString(hash2)) // 50b2c43fd39106bafbba0da34fc430e1f91e3c96ea2acee2bc34119f92b37750
27 | }
28 |
--------------------------------------------------------------------------------
/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.IsPOWER9 = true
24 | }
25 |
26 | Initialized = true
27 | }
28 |
29 | func getsystemcfg(label int) (n uint64) {
30 | r0, _ := callgetsystemcfg(label)
31 | n = uint64(r0)
32 | return
33 | }
34 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/sys/cpu/cpu_zos_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 | func initS390Xbase() {
8 | // get the facilities list
9 | facilities := stfle()
10 |
11 | // mandatory
12 | S390X.HasZARCH = facilities.Has(zarch)
13 | S390X.HasSTFLE = facilities.Has(stflef)
14 | S390X.HasLDISP = facilities.Has(ldisp)
15 | S390X.HasEIMM = facilities.Has(eimm)
16 |
17 | // optional
18 | S390X.HasETF3EH = facilities.Has(etf3eh)
19 | S390X.HasDFP = facilities.Has(dfp)
20 | S390X.HasMSA = facilities.Has(msa)
21 | S390X.HasVX = facilities.Has(vx)
22 | if S390X.HasVX {
23 | S390X.HasVXE = facilities.Has(vxe)
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/example/usage_example.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "encoding/hex"
5 | "fmt"
6 |
7 | "github.com/miguelmota/go-solidity-sha3"
8 | )
9 |
10 | func main() {
11 | types := []string{"address", "bytes1", "uint8[]", "bytes32", "uint256", "address[]", "uint32"}
12 | values := []interface{}{
13 | "0x935F7770265D0797B621c49A5215849c333Cc3ce",
14 | "0xa",
15 | []uint8{128, 255},
16 | "0x4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45",
17 | "100000000000000000",
18 | []string{
19 | "0x13D94859b23AF5F610aEfC2Ae5254D4D7E3F191a",
20 | "0x473029549e9d898142a169d7234c59068EDcBB33",
21 | },
22 | 123456789,
23 | }
24 |
25 | hash := solsha3.SoliditySHA3(types, values)
26 |
27 | fmt.Println(hex.EncodeToString(hash)) // ad390a98c1c32cdb1f046f6887a4109f12290b690127e6e15da4ca210235510e
28 | }
29 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/crypto/sha3/xor_generic.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package sha3
6 |
7 | import "encoding/binary"
8 |
9 | // xorInGeneric xors the bytes in buf into the state; it
10 | // makes no non-portable assumptions about memory layout
11 | // or alignment.
12 | func xorInGeneric(d *state, buf []byte) {
13 | n := len(buf) / 8
14 |
15 | for i := 0; i < n; i++ {
16 | a := binary.LittleEndian.Uint64(buf)
17 | d.a[i] ^= a
18 | buf = buf[8:]
19 | }
20 | }
21 |
22 | // copyOutGeneric copies ulint64s to a byte buffer.
23 | func copyOutGeneric(d *state, b []byte) {
24 | for i := 0; len(b) >= 8; i++ {
25 | binary.LittleEndian.PutUint64(b, d.a[i])
26 | b = b[8:]
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/string_test.go:
--------------------------------------------------------------------------------
1 | package solsha3
2 |
3 | import (
4 | "encoding/hex"
5 | "fmt"
6 | "testing"
7 | )
8 |
9 | func TestString(t *testing.T) {
10 | t.Run("string", func(t *testing.T) {
11 | for i, tt := range []struct {
12 | in []byte
13 | out string
14 | }{
15 | {
16 | SoliditySHA3(
17 | []string{"string"},
18 | "somedata",
19 | ),
20 | "fb763c3da6141a6a1464a68583e30d9a77bb999b1f1c491992dcfac7738ecfb4",
21 | },
22 | {
23 | SoliditySHA3(
24 | []string{"string[]"},
25 | []string{"a", "b", "c"},
26 | ),
27 | "4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45",
28 | },
29 | } {
30 | t.Run(fmt.Sprintf("%v", i), func(t *testing.T) {
31 | got := hex.EncodeToString(tt.in)
32 | if got != tt.out {
33 | t.Errorf("want %v, got %v", tt.out, got)
34 | }
35 | })
36 | }
37 | })
38 | }
39 |
--------------------------------------------------------------------------------
/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/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 | // +build gc
6 |
7 | #include "textflag.h"
8 |
9 | // func getisar0() uint64
10 | TEXT ·getisar0(SB),NOSPLIT,$0-8
11 | // get Instruction Set Attributes 0 into x0
12 | // mrs x0, ID_AA64ISAR0_EL1 = d5380600
13 | WORD $0xd5380600
14 | MOVD R0, ret+0(FP)
15 | RET
16 |
17 | // func getisar1() uint64
18 | TEXT ·getisar1(SB),NOSPLIT,$0-8
19 | // get Instruction Set Attributes 1 into x0
20 | // mrs x0, ID_AA64ISAR1_EL1 = d5380620
21 | WORD $0xd5380620
22 | MOVD R0, ret+0(FP)
23 | RET
24 |
25 | // func getpfr0() uint64
26 | TEXT ·getpfr0(SB),NOSPLIT,$0-8
27 | // get Processor Feature Register 0 into x0
28 | // mrs x0, ID_AA64PFR0_EL1 = d5380400
29 | WORD $0xd5380400
30 | MOVD R0, ret+0(FP)
31 | RET
32 |
--------------------------------------------------------------------------------
/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/crypto/sha3/hashes_generic.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | //go:build !gc || purego || !s390x
6 | // +build !gc purego !s390x
7 |
8 | package sha3
9 |
10 | import (
11 | "hash"
12 | )
13 |
14 | // new224Asm returns an assembly implementation of SHA3-224 if available,
15 | // otherwise it returns nil.
16 | func new224Asm() hash.Hash { return nil }
17 |
18 | // new256Asm returns an assembly implementation of SHA3-256 if available,
19 | // otherwise it returns nil.
20 | func new256Asm() hash.Hash { return nil }
21 |
22 | // new384Asm returns an assembly implementation of SHA3-384 if available,
23 | // otherwise it returns nil.
24 | func new384Asm() hash.Hash { return nil }
25 |
26 | // new512Asm returns an assembly implementation of SHA3-512 if available,
27 | // otherwise it returns nil.
28 | func new512Asm() hash.Hash { return nil }
29 |
--------------------------------------------------------------------------------
/bool_test.go:
--------------------------------------------------------------------------------
1 | package solsha3
2 |
3 | import (
4 | "encoding/hex"
5 | "fmt"
6 | "testing"
7 | )
8 |
9 | func TestBool(t *testing.T) {
10 | t.Run("bool", func(t *testing.T) {
11 | for i, tt := range []struct {
12 | in []byte
13 | out string
14 | }{
15 | {
16 | SoliditySHA3(
17 | []string{"bool"},
18 | true,
19 | ),
20 | "5fe7f977e71dba2ea1a68e21057beebb9be2ac30c6410aa38d4f3fbe41dcffd2",
21 | },
22 | {
23 | SoliditySHA3(
24 | []string{"bool"},
25 | false,
26 | ),
27 | "bc36789e7a1e281436464229828f817d6612f7b477d66591ff96a9e064bcc98a",
28 | },
29 | {
30 | SoliditySHA3(
31 | []string{"bool[]"},
32 | [3]bool{true, false, true},
33 | ),
34 | "5c6090c0461491a2941743bda5c3658bf1ea53bbd3edcde54e16205e18b45792",
35 | },
36 | } {
37 | t.Run(fmt.Sprintf("%v", i), func(t *testing.T) {
38 | got := hex.EncodeToString(tt.in)
39 | if got != tt.out {
40 | t.Errorf("want %v, got %v", tt.out, got)
41 | }
42 | })
43 | }
44 | })
45 | }
46 |
--------------------------------------------------------------------------------
/address.go:
--------------------------------------------------------------------------------
1 | package solsha3
2 |
3 | import (
4 | "encoding/hex"
5 | "reflect"
6 |
7 | "github.com/ethereum/go-ethereum/common"
8 | )
9 |
10 | // Address address
11 | func Address(input interface{}) []byte {
12 | switch v := input.(type) {
13 | case common.Address:
14 | return v.Bytes()[:]
15 | case string:
16 | v = removeHexPrefix(v)
17 | if v == "" || v == "0" {
18 | return []byte{0}
19 | }
20 |
21 | v = evenLengthHex(v)
22 | decoded, err := hex.DecodeString(v)
23 | if err != nil {
24 | panic(err)
25 | }
26 |
27 | return decoded
28 | case []byte:
29 | return v
30 | }
31 |
32 | if isArray(input) {
33 | return AddressArray(input)
34 | }
35 |
36 | return common.HexToAddress("").Bytes()[:]
37 | }
38 |
39 | // AddressArray address
40 | func AddressArray(input interface{}) []byte {
41 | var values []byte
42 | s := reflect.ValueOf(input)
43 | for i := 0; i < s.Len(); i++ {
44 | val := s.Index(i).Interface()
45 | result := common.LeftPadBytes(Address(val), 32)
46 | values = append(values, result...)
47 | }
48 | return values
49 | }
50 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | MIT license
2 |
3 | Copyright (C) 2015 Miguel Mota
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | this software and associated documentation files (the "Software"), to deal in
7 | the Software without restriction, including without limitation the rights to
8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9 | of the Software, and to permit persons to whom the Software is furnished to do
10 | so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/crypto/sha3/sha3_s390x.s:
--------------------------------------------------------------------------------
1 | // Copyright 2017 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | //go:build gc && !purego
6 | // +build gc,!purego
7 |
8 | #include "textflag.h"
9 |
10 | // func kimd(function code, chain *[200]byte, src []byte)
11 | TEXT ·kimd(SB), NOFRAME|NOSPLIT, $0-40
12 | MOVD function+0(FP), R0
13 | MOVD chain+8(FP), R1
14 | LMG src+16(FP), R2, R3 // R2=base, R3=len
15 |
16 | continue:
17 | WORD $0xB93E0002 // KIMD --, R2
18 | BVS continue // continue if interrupted
19 | MOVD $0, R0 // reset R0 for pre-go1.8 compilers
20 | RET
21 |
22 | // func klmd(function code, chain *[200]byte, dst, src []byte)
23 | TEXT ·klmd(SB), NOFRAME|NOSPLIT, $0-64
24 | // TODO: SHAKE support
25 | MOVD function+0(FP), R0
26 | MOVD chain+8(FP), R1
27 | LMG dst+16(FP), R2, R3 // R2=base, R3=len
28 | LMG src+40(FP), R4, R5 // R4=base, R5=len
29 |
30 | continue:
31 | WORD $0xB93F0024 // KLMD R2, R4
32 | BVS continue // continue if interrupted
33 | MOVD $0, R0 // reset R0 for pre-go1.8 compilers
34 | RET
35 |
--------------------------------------------------------------------------------
/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/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/github.com/ethereum/go-ethereum/common/big.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The go-ethereum Authors
2 | // This file is part of the go-ethereum library.
3 | //
4 | // The go-ethereum library is free software: you can redistribute it and/or modify
5 | // it under the terms of the GNU Lesser General Public License as published by
6 | // the Free Software Foundation, either version 3 of the License, or
7 | // (at your option) any later version.
8 | //
9 | // The go-ethereum library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU Lesser General Public License for more details.
13 | //
14 | // You should have received a copy of the GNU Lesser General Public License
15 | // along with the go-ethereum library. If not, see .
16 |
17 | package common
18 |
19 | import "math/big"
20 |
21 | // Common big integers often used
22 | var (
23 | Big1 = big.NewInt(1)
24 | Big2 = big.NewInt(2)
25 | Big3 = big.NewInt(3)
26 | Big0 = big.NewInt(0)
27 | Big32 = big.NewInt(32)
28 | Big256 = big.NewInt(256)
29 | Big257 = big.NewInt(257)
30 | )
31 |
--------------------------------------------------------------------------------
/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/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/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/hwcap_linux.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 | "io/ioutil"
9 | )
10 |
11 | const (
12 | _AT_HWCAP = 16
13 | _AT_HWCAP2 = 26
14 |
15 | procAuxv = "/proc/self/auxv"
16 |
17 | uintSize = int(32 << (^uint(0) >> 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 |
--------------------------------------------------------------------------------
/address_test.go:
--------------------------------------------------------------------------------
1 | package solsha3
2 |
3 | import (
4 | "encoding/hex"
5 | "fmt"
6 | "testing"
7 |
8 | "github.com/ethereum/go-ethereum/common"
9 | )
10 |
11 | func TestAddress(t *testing.T) {
12 | t.Run("address", func(t *testing.T) {
13 | for i, tt := range []struct {
14 | in []byte
15 | out string
16 | }{
17 | {
18 | SoliditySHA3(
19 | []string{"address"},
20 | "0x0",
21 | ),
22 | "bc36789e7a1e281436464229828f817d6612f7b477d66591ff96a9e064bcc98a",
23 | },
24 | {
25 | SoliditySHA3(
26 | []string{"address"},
27 | "0x0a",
28 | ),
29 |
30 | "0ef9d8f8804d174666011a394cab7901679a8944d24249fd148a6a36071151f8",
31 | },
32 | {
33 | SoliditySHA3(
34 | []string{"address"},
35 | "0x12459c951127e0c374ff9105dda097662a027092",
36 | ),
37 | "4b998b071d7bb74aee1ce2cdcc268cb0f6409b4a3387fc915617ec08415298ad",
38 | },
39 | {
40 | SoliditySHA3(
41 | []string{"address"},
42 | common.HexToAddress("0x12459c951127e0c374ff9105dda097662a027092"),
43 | ),
44 | "4b998b071d7bb74aee1ce2cdcc268cb0f6409b4a3387fc915617ec08415298ad",
45 | },
46 | {
47 | SoliditySHA3(
48 | []string{"string[]"},
49 | []string{"a", "b", "c"},
50 | ),
51 | "4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45",
52 | },
53 | } {
54 | t.Run(fmt.Sprintf("%v", i), func(t *testing.T) {
55 | got := hex.EncodeToString(tt.in)
56 | if got != tt.out {
57 | t.Errorf("want %v, got %v", tt.out, got)
58 | }
59 | })
60 | }
61 | })
62 | }
63 |
--------------------------------------------------------------------------------
/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/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/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/sha3/xor_unaligned.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | //go:build (amd64 || 386 || ppc64le) && !purego
6 | // +build amd64 386 ppc64le
7 | // +build !purego
8 |
9 | package sha3
10 |
11 | import "unsafe"
12 |
13 | // A storageBuf is an aligned array of maxRate bytes.
14 | type storageBuf [maxRate / 8]uint64
15 |
16 | func (b *storageBuf) asBytes() *[maxRate]byte {
17 | return (*[maxRate]byte)(unsafe.Pointer(b))
18 | }
19 |
20 | // xorInUnaligned uses unaligned reads and writes to update d.a to contain d.a
21 | // XOR buf.
22 | func xorInUnaligned(d *state, buf []byte) {
23 | n := len(buf)
24 | bw := (*[maxRate / 8]uint64)(unsafe.Pointer(&buf[0]))[: n/8 : n/8]
25 | if n >= 72 {
26 | d.a[0] ^= bw[0]
27 | d.a[1] ^= bw[1]
28 | d.a[2] ^= bw[2]
29 | d.a[3] ^= bw[3]
30 | d.a[4] ^= bw[4]
31 | d.a[5] ^= bw[5]
32 | d.a[6] ^= bw[6]
33 | d.a[7] ^= bw[7]
34 | d.a[8] ^= bw[8]
35 | }
36 | if n >= 104 {
37 | d.a[9] ^= bw[9]
38 | d.a[10] ^= bw[10]
39 | d.a[11] ^= bw[11]
40 | d.a[12] ^= bw[12]
41 | }
42 | if n >= 136 {
43 | d.a[13] ^= bw[13]
44 | d.a[14] ^= bw[14]
45 | d.a[15] ^= bw[15]
46 | d.a[16] ^= bw[16]
47 | }
48 | if n >= 144 {
49 | d.a[17] ^= bw[17]
50 | }
51 | if n >= 168 {
52 | d.a[18] ^= bw[18]
53 | d.a[19] ^= bw[19]
54 | d.a[20] ^= bw[20]
55 | }
56 | }
57 |
58 | func copyOutUnaligned(d *state, buf []byte) {
59 | ab := (*[maxRate]uint8)(unsafe.Pointer(&d.a[0]))
60 | copy(buf, ab[:])
61 | }
62 |
63 | var (
64 | xorIn = xorInUnaligned
65 | copyOut = copyOutUnaligned
66 | )
67 |
68 | const xorImplementationUnaligned = "unaligned"
69 |
--------------------------------------------------------------------------------
/vendor/github.com/ethereum/go-ethereum/common/path.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The go-ethereum Authors
2 | // This file is part of the go-ethereum library.
3 | //
4 | // The go-ethereum library is free software: you can redistribute it and/or modify
5 | // it under the terms of the GNU Lesser General Public License as published by
6 | // the Free Software Foundation, either version 3 of the License, or
7 | // (at your option) any later version.
8 | //
9 | // The go-ethereum library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU Lesser General Public License for more details.
13 | //
14 | // You should have received a copy of the GNU Lesser General Public License
15 | // along with the go-ethereum library. If not, see .
16 |
17 | package common
18 |
19 | import (
20 | "fmt"
21 | "os"
22 | "path/filepath"
23 | "runtime"
24 | )
25 |
26 | // MakeName creates a node name that follows the ethereum convention
27 | // for such names. It adds the operation system name and Go runtime version
28 | // the name.
29 | func MakeName(name, version string) string {
30 | return fmt.Sprintf("%s/v%s/%s/%s", name, version, runtime.GOOS, runtime.Version())
31 | }
32 |
33 | // FileExist checks if a file exists at filePath.
34 | func FileExist(filePath string) bool {
35 | _, err := os.Stat(filePath)
36 | if err != nil && os.IsNotExist(err) {
37 | return false
38 | }
39 |
40 | return true
41 | }
42 |
43 | // AbsolutePath returns datadir + filename, or filename if it is absolute.
44 | func AbsolutePath(datadir string, filename string) string {
45 | if filepath.IsAbs(filename) {
46 | return filename
47 | }
48 | return filepath.Join(datadir, filename)
49 | }
50 |
--------------------------------------------------------------------------------
/example/js/test.js:
--------------------------------------------------------------------------------
1 | const ethers = require('ethers')
2 |
3 | //console.log(ethers.utils.solidityKeccak256([ 'uint8[]' ], [ [1,2,3] ] ))
4 | //console.log(ethers.utils.solidityKeccak256([ 'bool[]' ], [ [true, false, true] ] ))
5 | //console.log(ethers.utils.solidityKeccak256([ 'int8[]' ], [ [1,2,3] ] ))
6 |
7 | //console.log(ethers.utils.solidityKeccak256([ 'string[]' ], [ ['a', 'b', 'c'] ] ))
8 |
9 | //console.log(ethers.utils.solidityKeccak256([ 'address[]' ], [ ['0xa', '0xb', '0xc'] ] ))
10 |
11 | //console.log(ethers.utils.solidityKeccak256([ 'address' ], [ '0xa'] ))
12 | //console.log(ethers.utils.solidityKeccak256([ 'address' ], [ '0x0'] ))
13 |
14 |
15 | //console.log(ethers.utils.solidityKeccak256([ 'bytes32' ], [ '0x4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45' ] ))
16 | //console.log(ethers.utils.solidityKeccak256([ 'bytes1' ], [ '0x4' ] ))
17 | //console.log(ethers.utils.solidityKeccak256(['bytes32'],['0x0a00000000000000000000000000000000000000000000000000000000000000']))
18 |
19 | //var msgDigest = ethers.utils.keccak256(Buffer.from('abc'));
20 |
21 | //console.log(msgDigest.toString())
22 |
23 | //console.log(ethers.utils.solidityKeccak256(['address', 'uint256'],['0x935F7770265D0797B621c49A5215849c333Cc3ce', '100000000000000000']))
24 |
25 | /*
26 | console.log(ethers.utils.solidityKeccak256([
27 | 'address', 'bytes1', 'uint8[]', 'bytes32', 'uint256', 'address[]', 'uint32' ],
28 | [
29 | '0x935F7770265D0797B621c49A5215849c333Cc3ce',
30 | '0xa',
31 | [128, 255],
32 | '0x4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45',
33 | '100000000000000000',
34 | [
35 | '0x13D94859b23AF5F610aEfC2Ae5254D4D7E3F191a',
36 | '0x473029549e9d898142a169d7234c59068EDcBB33'
37 | ],
38 | 123456789
39 | ]
40 | ))
41 | // 0xad390a98c1c32cdb1f046f6887a4109f12290b690127e6e15da4ca210235510e
42 | */
43 |
--------------------------------------------------------------------------------
/vendor/github.com/ethereum/go-ethereum/common/test_utils.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The go-ethereum Authors
2 | // This file is part of the go-ethereum library.
3 | //
4 | // The go-ethereum library is free software: you can redistribute it and/or modify
5 | // it under the terms of the GNU Lesser General Public License as published by
6 | // the Free Software Foundation, either version 3 of the License, or
7 | // (at your option) any later version.
8 | //
9 | // The go-ethereum library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU Lesser General Public License for more details.
13 | //
14 | // You should have received a copy of the GNU Lesser General Public License
15 | // along with the go-ethereum library. If not, see .
16 |
17 | package common
18 |
19 | import (
20 | "encoding/json"
21 | "fmt"
22 | "io/ioutil"
23 | )
24 |
25 | // LoadJSON reads the given file and unmarshals its content.
26 | func LoadJSON(file string, val interface{}) error {
27 | content, err := ioutil.ReadFile(file)
28 | if err != nil {
29 | return err
30 | }
31 | if err := json.Unmarshal(content, val); err != nil {
32 | if syntaxerr, ok := err.(*json.SyntaxError); ok {
33 | line := findLine(content, syntaxerr.Offset)
34 | return fmt.Errorf("JSON syntax error at %v:%v: %v", file, line, err)
35 | }
36 | return fmt.Errorf("JSON unmarshal error in %v: %v", file, err)
37 | }
38 | return nil
39 | }
40 |
41 | // findLine returns the line number for the given offset into data.
42 | func findLine(data []byte, offset int64) (line int) {
43 | line = 1
44 | for i, r := range string(data) {
45 | if int64(i) >= offset {
46 | return
47 | }
48 | if r == '\n' {
49 | line++
50 | }
51 | }
52 | return
53 | }
54 |
--------------------------------------------------------------------------------
/vendor/github.com/ethereum/go-ethereum/common/debug.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The go-ethereum Authors
2 | // This file is part of the go-ethereum library.
3 | //
4 | // The go-ethereum library is free software: you can redistribute it and/or modify
5 | // it under the terms of the GNU Lesser General Public License as published by
6 | // the Free Software Foundation, either version 3 of the License, or
7 | // (at your option) any later version.
8 | //
9 | // The go-ethereum library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU Lesser General Public License for more details.
13 | //
14 | // You should have received a copy of the GNU Lesser General Public License
15 | // along with the go-ethereum library. If not, see .
16 |
17 | package common
18 |
19 | import (
20 | "fmt"
21 | "os"
22 | "runtime"
23 | "runtime/debug"
24 | "strings"
25 | )
26 |
27 | // Report gives off a warning requesting the user to submit an issue to the github tracker.
28 | func Report(extra ...interface{}) {
29 | fmt.Fprintln(os.Stderr, "You've encountered a sought after, hard to reproduce bug. Please report this to the developers <3 https://github.com/ethereum/go-ethereum/issues")
30 | fmt.Fprintln(os.Stderr, extra...)
31 |
32 | _, file, line, _ := runtime.Caller(1)
33 | fmt.Fprintf(os.Stderr, "%v:%v\n", file, line)
34 |
35 | debug.PrintStack()
36 |
37 | fmt.Fprintln(os.Stderr, "#### BUG! PLEASE REPORT ####")
38 | }
39 |
40 | // PrintDepricationWarning prinst the given string in a box using fmt.Println.
41 | func PrintDepricationWarning(str string) {
42 | line := strings.Repeat("#", len(str)+4)
43 | emptyLine := strings.Repeat(" ", len(str))
44 | fmt.Printf(`
45 | %s
46 | # %s #
47 | # %s #
48 | # %s #
49 | %s
50 |
51 | `, line, emptyLine, str, emptyLine, line)
52 | }
53 |
--------------------------------------------------------------------------------
/solsha3.go:
--------------------------------------------------------------------------------
1 | package solsha3
2 |
3 | import (
4 | "fmt"
5 |
6 | "golang.org/x/crypto/sha3"
7 | )
8 |
9 | // SoliditySHA3 solidity sha3
10 | func SoliditySHA3(data ...interface{}) []byte {
11 | types, ok := data[0].([]string)
12 | if len(data) > 1 && ok {
13 | rest := data[1:]
14 | if len(rest) == len(types) {
15 | return solsha3(types, data[1:]...)
16 | }
17 | iface, ok := data[1].([]interface{})
18 | if ok {
19 | return solsha3(types, iface...)
20 | }
21 | }
22 |
23 | var v [][]byte
24 | for _, item := range data {
25 | b := parseBytes(item, -1)
26 | v = append(v, b)
27 | }
28 | return solsha3Legacy(v...)
29 | }
30 |
31 | // solsha3Legacy solidity sha3
32 | func solsha3Legacy(data ...[]byte) []byte {
33 | hash := sha3.NewLegacyKeccak256()
34 | bs := concatByteSlices(data...)
35 |
36 | hash.Write(bs)
37 | return hash.Sum(nil)
38 | }
39 |
40 | // SoliditySHA3WithPrefix solidity sha3 with prefix
41 | func SoliditySHA3WithPrefix(data []byte) []byte {
42 | result := SoliditySHA3(
43 | concatByteSlices(
44 | []byte(fmt.Sprintf("\x19Ethereum Signed Message:\n%v", len(data))),
45 | data,
46 | ),
47 | )
48 |
49 | return result
50 | }
51 |
52 | // ConcatByteSlices concat byte slices
53 | func ConcatByteSlices(arrays ...[]byte) []byte {
54 | return concatByteSlices(arrays...)
55 | }
56 |
57 | // solsha3 solidity sha3
58 | func solsha3(types []string, values ...interface{}) []byte {
59 | var b [][]byte
60 | for i, typ := range types {
61 | b = append(b, pack(typ, values[i], false))
62 | }
63 |
64 | hash := sha3.NewLegacyKeccak256()
65 | bs := concatByteSlices(b...)
66 | hash.Write(bs)
67 | return hash.Sum(nil)
68 | }
69 |
70 | // Pack ...
71 | func Pack(types []string, values []interface{}) []byte {
72 | if len(types) != len(values) {
73 | panic("type/value count mismatch")
74 | }
75 |
76 | var tight [][]byte
77 | for i, typ := range types {
78 | tight = append(tight, pack(typ, values[i], false))
79 | }
80 |
81 | return concatByteSlices(tight...)
82 | }
83 |
--------------------------------------------------------------------------------
/vendor/github.com/ethereum/go-ethereum/common/size.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The go-ethereum Authors
2 | // This file is part of the go-ethereum library.
3 | //
4 | // The go-ethereum library is free software: you can redistribute it and/or modify
5 | // it under the terms of the GNU Lesser General Public License as published by
6 | // the Free Software Foundation, either version 3 of the License, or
7 | // (at your option) any later version.
8 | //
9 | // The go-ethereum library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU Lesser General Public License for more details.
13 | //
14 | // You should have received a copy of the GNU Lesser General Public License
15 | // along with the go-ethereum library. If not, see .
16 |
17 | package common
18 |
19 | import (
20 | "fmt"
21 | )
22 |
23 | // StorageSize is a wrapper around a float value that supports user friendly
24 | // formatting.
25 | type StorageSize float64
26 |
27 | // String implements the stringer interface.
28 | func (s StorageSize) String() string {
29 | if s > 1099511627776 {
30 | return fmt.Sprintf("%.2f TiB", s/1099511627776)
31 | } else if s > 1073741824 {
32 | return fmt.Sprintf("%.2f GiB", s/1073741824)
33 | } else if s > 1048576 {
34 | return fmt.Sprintf("%.2f MiB", s/1048576)
35 | } else if s > 1024 {
36 | return fmt.Sprintf("%.2f KiB", s/1024)
37 | } else {
38 | return fmt.Sprintf("%.2f B", s)
39 | }
40 | }
41 |
42 | // TerminalString implements log.TerminalStringer, formatting a string for console
43 | // output during logging.
44 | func (s StorageSize) TerminalString() string {
45 | if s > 1099511627776 {
46 | return fmt.Sprintf("%.2fTiB", s/1099511627776)
47 | } else if s > 1073741824 {
48 | return fmt.Sprintf("%.2fGiB", s/1073741824)
49 | } else if s > 1048576 {
50 | return fmt.Sprintf("%.2fMiB", s/1048576)
51 | } else if s > 1024 {
52 | return fmt.Sprintf("%.2fKiB", s/1024)
53 | } else {
54 | return fmt.Sprintf("%.2fB", s)
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/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_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 | // +build gc
6 |
7 | #include "textflag.h"
8 |
9 | // func stfle() facilityList
10 | TEXT ·stfle(SB), NOSPLIT|NOFRAME, $0-32
11 | MOVD $ret+0(FP), R1
12 | MOVD $3, R0 // last doubleword index to store
13 | XC $32, (R1), (R1) // clear 4 doublewords (32 bytes)
14 | WORD $0xb2b01000 // store facility list extended (STFLE)
15 | RET
16 |
17 | // func kmQuery() queryResult
18 | TEXT ·kmQuery(SB), NOSPLIT|NOFRAME, $0-16
19 | MOVD $0, R0 // set function code to 0 (KM-Query)
20 | MOVD $ret+0(FP), R1 // address of 16-byte return value
21 | WORD $0xB92E0024 // cipher message (KM)
22 | RET
23 |
24 | // func kmcQuery() queryResult
25 | TEXT ·kmcQuery(SB), NOSPLIT|NOFRAME, $0-16
26 | MOVD $0, R0 // set function code to 0 (KMC-Query)
27 | MOVD $ret+0(FP), R1 // address of 16-byte return value
28 | WORD $0xB92F0024 // cipher message with chaining (KMC)
29 | RET
30 |
31 | // func kmctrQuery() queryResult
32 | TEXT ·kmctrQuery(SB), NOSPLIT|NOFRAME, $0-16
33 | MOVD $0, R0 // set function code to 0 (KMCTR-Query)
34 | MOVD $ret+0(FP), R1 // address of 16-byte return value
35 | WORD $0xB92D4024 // cipher message with counter (KMCTR)
36 | RET
37 |
38 | // func kmaQuery() queryResult
39 | TEXT ·kmaQuery(SB), NOSPLIT|NOFRAME, $0-16
40 | MOVD $0, R0 // set function code to 0 (KMA-Query)
41 | MOVD $ret+0(FP), R1 // address of 16-byte return value
42 | WORD $0xb9296024 // cipher message with authentication (KMA)
43 | RET
44 |
45 | // func kimdQuery() queryResult
46 | TEXT ·kimdQuery(SB), NOSPLIT|NOFRAME, $0-16
47 | MOVD $0, R0 // set function code to 0 (KIMD-Query)
48 | MOVD $ret+0(FP), R1 // address of 16-byte return value
49 | WORD $0xB93E0024 // compute intermediate message digest (KIMD)
50 | RET
51 |
52 | // func klmdQuery() queryResult
53 | TEXT ·klmdQuery(SB), NOSPLIT|NOFRAME, $0-16
54 | MOVD $0, R0 // set function code to 0 (KLMD-Query)
55 | MOVD $ret+0(FP), R1 // address of 16-byte return value
56 | WORD $0xB93F0024 // compute last message digest (KLMD)
57 | RET
58 |
--------------------------------------------------------------------------------
/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_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/github.com/ethereum/go-ethereum/common/format.go:
--------------------------------------------------------------------------------
1 | // Copyright 2016 The go-ethereum Authors
2 | // This file is part of the go-ethereum library.
3 | //
4 | // The go-ethereum library is free software: you can redistribute it and/or modify
5 | // it under the terms of the GNU Lesser General Public License as published by
6 | // the Free Software Foundation, either version 3 of the License, or
7 | // (at your option) any later version.
8 | //
9 | // The go-ethereum library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU Lesser General Public License for more details.
13 | //
14 | // You should have received a copy of the GNU Lesser General Public License
15 | // along with the go-ethereum library. If not, see .
16 |
17 | package common
18 |
19 | import (
20 | "fmt"
21 | "regexp"
22 | "strings"
23 | "time"
24 | )
25 |
26 | // PrettyDuration is a pretty printed version of a time.Duration value that cuts
27 | // the unnecessary precision off from the formatted textual representation.
28 | type PrettyDuration time.Duration
29 |
30 | var prettyDurationRe = regexp.MustCompile(`\.[0-9]+`)
31 |
32 | // String implements the Stringer interface, allowing pretty printing of duration
33 | // values rounded to three decimals.
34 | func (d PrettyDuration) String() string {
35 | label := fmt.Sprintf("%v", time.Duration(d))
36 | if match := prettyDurationRe.FindString(label); len(match) > 4 {
37 | label = strings.Replace(label, match, match[:4], 1)
38 | }
39 | return label
40 | }
41 |
42 | // PrettyAge is a pretty printed version of a time.Duration value that rounds
43 | // the values up to a single most significant unit, days/weeks/years included.
44 | type PrettyAge time.Time
45 |
46 | // ageUnits is a list of units the age pretty printing uses.
47 | var ageUnits = []struct {
48 | Size time.Duration
49 | Symbol string
50 | }{
51 | {12 * 30 * 24 * time.Hour, "y"},
52 | {30 * 24 * time.Hour, "mo"},
53 | {7 * 24 * time.Hour, "w"},
54 | {24 * time.Hour, "d"},
55 | {time.Hour, "h"},
56 | {time.Minute, "m"},
57 | {time.Second, "s"},
58 | }
59 |
60 | // String implements the Stringer interface, allowing pretty printing of duration
61 | // values rounded to the most significant time unit.
62 | func (t PrettyAge) String() string {
63 | // Calculate the time difference and handle the 0 cornercase
64 | diff := time.Since(time.Time(t))
65 | if diff < time.Second {
66 | return "0"
67 | }
68 | // Accumulate a precision of 3 components before returning
69 | result, prec := "", 0
70 |
71 | for _, unit := range ageUnits {
72 | if diff > unit.Size {
73 | result = fmt.Sprintf("%s%d%s", result, diff/unit.Size, unit.Symbol)
74 | diff %= unit.Size
75 |
76 | if prec += 1; prec >= 3 {
77 | break
78 | }
79 | }
80 | }
81 | return result
82 | }
83 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/crypto/sha3/hashes.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 sha3
6 |
7 | // This file provides functions for creating instances of the SHA-3
8 | // and SHAKE hash functions, as well as utility functions for hashing
9 | // bytes.
10 |
11 | import (
12 | "hash"
13 | )
14 |
15 | // New224 creates a new SHA3-224 hash.
16 | // Its generic security strength is 224 bits against preimage attacks,
17 | // and 112 bits against collision attacks.
18 | func New224() hash.Hash {
19 | if h := new224Asm(); h != nil {
20 | return h
21 | }
22 | return &state{rate: 144, outputLen: 28, dsbyte: 0x06}
23 | }
24 |
25 | // New256 creates a new SHA3-256 hash.
26 | // Its generic security strength is 256 bits against preimage attacks,
27 | // and 128 bits against collision attacks.
28 | func New256() hash.Hash {
29 | if h := new256Asm(); h != nil {
30 | return h
31 | }
32 | return &state{rate: 136, outputLen: 32, dsbyte: 0x06}
33 | }
34 |
35 | // New384 creates a new SHA3-384 hash.
36 | // Its generic security strength is 384 bits against preimage attacks,
37 | // and 192 bits against collision attacks.
38 | func New384() hash.Hash {
39 | if h := new384Asm(); h != nil {
40 | return h
41 | }
42 | return &state{rate: 104, outputLen: 48, dsbyte: 0x06}
43 | }
44 |
45 | // New512 creates a new SHA3-512 hash.
46 | // Its generic security strength is 512 bits against preimage attacks,
47 | // and 256 bits against collision attacks.
48 | func New512() hash.Hash {
49 | if h := new512Asm(); h != nil {
50 | return h
51 | }
52 | return &state{rate: 72, outputLen: 64, dsbyte: 0x06}
53 | }
54 |
55 | // NewLegacyKeccak256 creates a new Keccak-256 hash.
56 | //
57 | // Only use this function if you require compatibility with an existing cryptosystem
58 | // that uses non-standard padding. All other users should use New256 instead.
59 | func NewLegacyKeccak256() hash.Hash { return &state{rate: 136, outputLen: 32, dsbyte: 0x01} }
60 |
61 | // NewLegacyKeccak512 creates a new Keccak-512 hash.
62 | //
63 | // Only use this function if you require compatibility with an existing cryptosystem
64 | // that uses non-standard padding. All other users should use New512 instead.
65 | func NewLegacyKeccak512() hash.Hash { return &state{rate: 72, outputLen: 64, dsbyte: 0x01} }
66 |
67 | // Sum224 returns the SHA3-224 digest of the data.
68 | func Sum224(data []byte) (digest [28]byte) {
69 | h := New224()
70 | h.Write(data)
71 | h.Sum(digest[:0])
72 | return
73 | }
74 |
75 | // Sum256 returns the SHA3-256 digest of the data.
76 | func Sum256(data []byte) (digest [32]byte) {
77 | h := New256()
78 | h.Write(data)
79 | h.Sum(digest[:0])
80 | return
81 | }
82 |
83 | // Sum384 returns the SHA3-384 digest of the data.
84 | func Sum384(data []byte) (digest [48]byte) {
85 | h := New384()
86 | h.Write(data)
87 | h.Sum(digest[:0])
88 | return
89 | }
90 |
91 | // Sum512 returns the SHA3-512 digest of the data.
92 | func Sum512(data []byte) (digest [64]byte) {
93 | h := New512()
94 | h.Write(data)
95 | h.Sum(digest[:0])
96 | return
97 | }
98 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 | # go-solidity-sha3
10 |
11 | > Generate Solidity SHA3 (Keccak256) hashes in Go.
12 |
13 | [](https://raw.githubusercontent.com/miguelmota/go-solidity-sha3/master/LICENSE.md)
14 | [](https://travis-ci.org/miguelmota/go-solidity-sha3)
15 | [](https://goreportcard.com/report/github.com/miguelmota/go-solidity-sha3)
16 | [](https://godoc.org/github.com/miguelmota/go-solidity-sha3)
17 | [](#contributing)
18 |
19 | This package is the Go equivalent of `require('ethers').utils.solidityKeccak256` [NPM module](https://www.npmjs.com/package/ethers).
20 |
21 | ## Install
22 |
23 | ```bash
24 | go get github.com/miguelmota/go-solidity-sha3
25 | ```
26 |
27 | ## Documentation
28 |
29 | [Documentation on GoDoc](https://godoc.org/github.com/miguelmota/go-solidity-sha3)
30 |
31 | ## Getting started
32 |
33 | Simple example:
34 |
35 | ```go
36 | package main
37 |
38 | import (
39 | "encoding/hex"
40 | "fmt"
41 |
42 | "github.com/miguelmota/go-solidity-sha3"
43 | )
44 |
45 | func main() {
46 | hash := solsha3.SoliditySHA3(
47 | // types
48 | []string{"address", "uint256"},
49 |
50 | // values
51 | []interface{}{
52 | "0x935F7770265D0797B621c49A5215849c333Cc3ce",
53 | "100000000000000000",
54 | },
55 | )
56 |
57 | fmt.Println(hex.EncodeToString(hash))
58 | }
59 | ```
60 |
61 | Output:
62 |
63 | ```bash
64 | 0a3844b522d9e3a837ae56d4c57d668feb26325834bf4ba49e153d84ed7ad53d
65 | ```
66 |
67 | More complex example:
68 |
69 | ```go
70 | package main
71 |
72 | import (
73 | "encoding/hex"
74 | "fmt"
75 |
76 | "github.com/miguelmota/go-solidity-sha3"
77 | )
78 |
79 | func main() {
80 | types := []string{"address", "bytes1", "uint8[]", "bytes32", "uint256", "address[]", "uint32"}
81 | values := []interface{}{
82 | "0x935F7770265D0797B621c49A5215849c333Cc3ce",
83 | "0xa",
84 | []uint8{128, 255},
85 | "0x4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45",
86 | "100000000000000000",
87 | []string{
88 | "0x13D94859b23AF5F610aEfC2Ae5254D4D7E3F191a",
89 | "0x473029549e9d898142a169d7234c59068EDcBB33",
90 | },
91 | 123456789,
92 | }
93 |
94 | hash := solsha3.SoliditySHA3(types, values)
95 |
96 | fmt.Println(hex.EncodeToString(hash))
97 | }
98 | ```
99 |
100 | Output:
101 |
102 | ```bash
103 | ad390a98c1c32cdb1f046f6887a4109f12290b690127e6e15da4ca210235510e
104 | ```
105 |
106 | ## Contributing
107 |
108 | Pull requests are welcome!
109 |
110 | For contributions please create a new branch and submit a pull request for review.
111 |
112 | ## License
113 |
114 | MIT
115 |
--------------------------------------------------------------------------------
/vendor/github.com/ethereum/go-ethereum/common/math/integer.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 The go-ethereum Authors
2 | // This file is part of the go-ethereum library.
3 | //
4 | // The go-ethereum library is free software: you can redistribute it and/or modify
5 | // it under the terms of the GNU Lesser General Public License as published by
6 | // the Free Software Foundation, either version 3 of the License, or
7 | // (at your option) any later version.
8 | //
9 | // The go-ethereum library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU Lesser General Public License for more details.
13 | //
14 | // You should have received a copy of the GNU Lesser General Public License
15 | // along with the go-ethereum library. If not, see .
16 |
17 | package math
18 |
19 | import (
20 | "fmt"
21 | "math/bits"
22 | "strconv"
23 | )
24 |
25 | // Integer limit values.
26 | const (
27 | MaxInt8 = 1<<7 - 1
28 | MinInt8 = -1 << 7
29 | MaxInt16 = 1<<15 - 1
30 | MinInt16 = -1 << 15
31 | MaxInt32 = 1<<31 - 1
32 | MinInt32 = -1 << 31
33 | MaxInt64 = 1<<63 - 1
34 | MinInt64 = -1 << 63
35 | MaxUint8 = 1<<8 - 1
36 | MaxUint16 = 1<<16 - 1
37 | MaxUint32 = 1<<32 - 1
38 | MaxUint64 = 1<<64 - 1
39 | )
40 |
41 | // HexOrDecimal64 marshals uint64 as hex or decimal.
42 | type HexOrDecimal64 uint64
43 |
44 | // UnmarshalText implements encoding.TextUnmarshaler.
45 | func (i *HexOrDecimal64) UnmarshalText(input []byte) error {
46 | int, ok := ParseUint64(string(input))
47 | if !ok {
48 | return fmt.Errorf("invalid hex or decimal integer %q", input)
49 | }
50 | *i = HexOrDecimal64(int)
51 | return nil
52 | }
53 |
54 | // MarshalText implements encoding.TextMarshaler.
55 | func (i HexOrDecimal64) MarshalText() ([]byte, error) {
56 | return []byte(fmt.Sprintf("%#x", uint64(i))), nil
57 | }
58 |
59 | // ParseUint64 parses s as an integer in decimal or hexadecimal syntax.
60 | // Leading zeros are accepted. The empty string parses as zero.
61 | func ParseUint64(s string) (uint64, bool) {
62 | if s == "" {
63 | return 0, true
64 | }
65 | if len(s) >= 2 && (s[:2] == "0x" || s[:2] == "0X") {
66 | v, err := strconv.ParseUint(s[2:], 16, 64)
67 | return v, err == nil
68 | }
69 | v, err := strconv.ParseUint(s, 10, 64)
70 | return v, err == nil
71 | }
72 |
73 | // MustParseUint64 parses s as an integer and panics if the string is invalid.
74 | func MustParseUint64(s string) uint64 {
75 | v, ok := ParseUint64(s)
76 | if !ok {
77 | panic("invalid unsigned 64 bit integer: " + s)
78 | }
79 | return v
80 | }
81 |
82 | // SafeSub returns x-y and checks for overflow.
83 | func SafeSub(x, y uint64) (uint64, bool) {
84 | diff, borrowOut := bits.Sub64(x, y, 0)
85 | return diff, borrowOut != 0
86 | }
87 |
88 | // SafeAdd returns x+y and checks for overflow.
89 | func SafeAdd(x, y uint64) (uint64, bool) {
90 | sum, carryOut := bits.Add64(x, y, 0)
91 | return sum, carryOut != 0
92 | }
93 |
94 | // SafeMul returns x*y and checks for overflow.
95 | func SafeMul(x, y uint64) (uint64, bool) {
96 | hi, lo := bits.Mul64(x, y)
97 | return lo, hi != 0
98 | }
99 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/crypto/sha3/doc.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 sha3 implements the SHA-3 fixed-output-length hash functions and
6 | // the SHAKE variable-output-length hash functions defined by FIPS-202.
7 | //
8 | // Both types of hash function use the "sponge" construction and the Keccak
9 | // permutation. For a detailed specification see http://keccak.noekeon.org/
10 | //
11 | //
12 | // Guidance
13 | //
14 | // If you aren't sure what function you need, use SHAKE256 with at least 64
15 | // bytes of output. The SHAKE instances are faster than the SHA3 instances;
16 | // the latter have to allocate memory to conform to the hash.Hash interface.
17 | //
18 | // If you need a secret-key MAC (message authentication code), prepend the
19 | // secret key to the input, hash with SHAKE256 and read at least 32 bytes of
20 | // output.
21 | //
22 | //
23 | // Security strengths
24 | //
25 | // The SHA3-x (x equals 224, 256, 384, or 512) functions have a security
26 | // strength against preimage attacks of x bits. Since they only produce "x"
27 | // bits of output, their collision-resistance is only "x/2" bits.
28 | //
29 | // The SHAKE-256 and -128 functions have a generic security strength of 256 and
30 | // 128 bits against all attacks, provided that at least 2x bits of their output
31 | // is used. Requesting more than 64 or 32 bytes of output, respectively, does
32 | // not increase the collision-resistance of the SHAKE functions.
33 | //
34 | //
35 | // The sponge construction
36 | //
37 | // A sponge builds a pseudo-random function from a public pseudo-random
38 | // permutation, by applying the permutation to a state of "rate + capacity"
39 | // bytes, but hiding "capacity" of the bytes.
40 | //
41 | // A sponge starts out with a zero state. To hash an input using a sponge, up
42 | // to "rate" bytes of the input are XORed into the sponge's state. The sponge
43 | // is then "full" and the permutation is applied to "empty" it. This process is
44 | // repeated until all the input has been "absorbed". The input is then padded.
45 | // The digest is "squeezed" from the sponge in the same way, except that output
46 | // is copied out instead of input being XORed in.
47 | //
48 | // A sponge is parameterized by its generic security strength, which is equal
49 | // to half its capacity; capacity + rate is equal to the permutation's width.
50 | // Since the KeccakF-1600 permutation is 1600 bits (200 bytes) wide, this means
51 | // that the security strength of a sponge instance is equal to (1600 - bitrate) / 2.
52 | //
53 | //
54 | // Recommendations
55 | //
56 | // The SHAKE functions are recommended for most new uses. They can produce
57 | // output of arbitrary length. SHAKE256, with an output length of at least
58 | // 64 bytes, provides 256-bit security against all attacks. The Keccak team
59 | // recommends it for most applications upgrading from SHA2-512. (NIST chose a
60 | // much stronger, but much slower, sponge instance for SHA3-512.)
61 | //
62 | // The SHA-3 functions are "drop-in" replacements for the SHA-2 functions.
63 | // They produce output of the same length, with the same security strengths
64 | // against all attacks. This means, in particular, that SHA3-256 only has
65 | // 128-bit collision resistance, because its output length is 32 bytes.
66 | package sha3 // import "golang.org/x/crypto/sha3"
67 |
--------------------------------------------------------------------------------
/vendor/github.com/ethereum/go-ethereum/common/bytes.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The go-ethereum Authors
2 | // This file is part of the go-ethereum library.
3 | //
4 | // The go-ethereum library is free software: you can redistribute it and/or modify
5 | // it under the terms of the GNU Lesser General Public License as published by
6 | // the Free Software Foundation, either version 3 of the License, or
7 | // (at your option) any later version.
8 | //
9 | // The go-ethereum library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU Lesser General Public License for more details.
13 | //
14 | // You should have received a copy of the GNU Lesser General Public License
15 | // along with the go-ethereum library. If not, see .
16 |
17 | // Package common contains various helper functions.
18 | package common
19 |
20 | import (
21 | "encoding/hex"
22 | )
23 |
24 | // FromHex returns the bytes represented by the hexadecimal string s.
25 | // s may be prefixed with "0x".
26 | func FromHex(s string) []byte {
27 | if has0xPrefix(s) {
28 | s = s[2:]
29 | }
30 | if len(s)%2 == 1 {
31 | s = "0" + s
32 | }
33 | return Hex2Bytes(s)
34 | }
35 |
36 | // CopyBytes returns an exact copy of the provided bytes.
37 | func CopyBytes(b []byte) (copiedBytes []byte) {
38 | if b == nil {
39 | return nil
40 | }
41 | copiedBytes = make([]byte, len(b))
42 | copy(copiedBytes, b)
43 |
44 | return
45 | }
46 |
47 | // has0xPrefix validates str begins with '0x' or '0X'.
48 | func has0xPrefix(str string) bool {
49 | return len(str) >= 2 && str[0] == '0' && (str[1] == 'x' || str[1] == 'X')
50 | }
51 |
52 | // isHexCharacter returns bool of c being a valid hexadecimal.
53 | func isHexCharacter(c byte) bool {
54 | return ('0' <= c && c <= '9') || ('a' <= c && c <= 'f') || ('A' <= c && c <= 'F')
55 | }
56 |
57 | // isHex validates whether each byte is valid hexadecimal string.
58 | func isHex(str string) bool {
59 | if len(str)%2 != 0 {
60 | return false
61 | }
62 | for _, c := range []byte(str) {
63 | if !isHexCharacter(c) {
64 | return false
65 | }
66 | }
67 | return true
68 | }
69 |
70 | // Bytes2Hex returns the hexadecimal encoding of d.
71 | func Bytes2Hex(d []byte) string {
72 | return hex.EncodeToString(d)
73 | }
74 |
75 | // Hex2Bytes returns the bytes represented by the hexadecimal string str.
76 | func Hex2Bytes(str string) []byte {
77 | h, _ := hex.DecodeString(str)
78 | return h
79 | }
80 |
81 | // Hex2BytesFixed returns bytes of a specified fixed length flen.
82 | func Hex2BytesFixed(str string, flen int) []byte {
83 | h, _ := hex.DecodeString(str)
84 | if len(h) == flen {
85 | return h
86 | }
87 | if len(h) > flen {
88 | return h[len(h)-flen:]
89 | }
90 | hh := make([]byte, flen)
91 | copy(hh[flen-len(h):flen], h)
92 | return hh
93 | }
94 |
95 | // RightPadBytes zero-pads slice to the right up to length l.
96 | func RightPadBytes(slice []byte, l int) []byte {
97 | if l <= len(slice) {
98 | return slice
99 | }
100 |
101 | padded := make([]byte, l)
102 | copy(padded, slice)
103 |
104 | return padded
105 | }
106 |
107 | // LeftPadBytes zero-pads slice to the left up to length l.
108 | func LeftPadBytes(slice []byte, l int) []byte {
109 | if l <= len(slice) {
110 | return slice
111 | }
112 |
113 | padded := make([]byte, l)
114 | copy(padded[l-len(slice):], slice)
115 |
116 | return padded
117 | }
118 |
119 | // TrimLeftZeroes returns a subslice of s without leading zeroes
120 | func TrimLeftZeroes(s []byte) []byte {
121 | idx := 0
122 | for ; idx < len(s); idx++ {
123 | if s[idx] != 0 {
124 | break
125 | }
126 | }
127 | return s[idx:]
128 | }
129 |
130 | // TrimRightZeroes returns a subslice of s without trailing zeroes
131 | func TrimRightZeroes(s []byte) []byte {
132 | idx := len(s)
133 | for ; idx > 0; idx-- {
134 | if s[idx-1] != 0 {
135 | break
136 | }
137 | }
138 | return s[:idx]
139 | }
140 |
--------------------------------------------------------------------------------
/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_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 | // Check if OPMASK and ZMM registers have OS support.
91 | osSupportsAVX512 = osSupportsAVX && isSet(5, eax) && isSet(6, eax) && isSet(7, eax)
92 | }
93 |
94 | X86.HasAVX = isSet(28, ecx1) && osSupportsAVX
95 |
96 | if maxID < 7 {
97 | return
98 | }
99 |
100 | _, ebx7, ecx7, edx7 := cpuid(7, 0)
101 | X86.HasBMI1 = isSet(3, ebx7)
102 | X86.HasAVX2 = isSet(5, ebx7) && osSupportsAVX
103 | X86.HasBMI2 = isSet(8, ebx7)
104 | X86.HasERMS = isSet(9, ebx7)
105 | X86.HasRDSEED = isSet(18, ebx7)
106 | X86.HasADX = isSet(19, ebx7)
107 |
108 | X86.HasAVX512 = isSet(16, ebx7) && osSupportsAVX512 // Because avx-512 foundation is the core required extension
109 | if X86.HasAVX512 {
110 | X86.HasAVX512F = true
111 | X86.HasAVX512CD = isSet(28, ebx7)
112 | X86.HasAVX512ER = isSet(27, ebx7)
113 | X86.HasAVX512PF = isSet(26, ebx7)
114 | X86.HasAVX512VL = isSet(31, ebx7)
115 | X86.HasAVX512BW = isSet(30, ebx7)
116 | X86.HasAVX512DQ = isSet(17, ebx7)
117 | X86.HasAVX512IFMA = isSet(21, ebx7)
118 | X86.HasAVX512VBMI = isSet(1, ecx7)
119 | X86.HasAVX5124VNNIW = isSet(2, edx7)
120 | X86.HasAVX5124FMAPS = isSet(3, edx7)
121 | X86.HasAVX512VPOPCNTDQ = isSet(14, ecx7)
122 | X86.HasAVX512VPCLMULQDQ = isSet(10, ecx7)
123 | X86.HasAVX512VNNI = isSet(11, ecx7)
124 | X86.HasAVX512GFNI = isSet(8, ecx7)
125 | X86.HasAVX512VAES = isSet(9, ecx7)
126 | X86.HasAVX512VBMI2 = isSet(6, ecx7)
127 | X86.HasAVX512BITALG = isSet(12, ecx7)
128 |
129 | eax71, _, _, _ := cpuid(7, 1)
130 | X86.HasAVX512BF16 = isSet(5, eax71)
131 | }
132 | }
133 |
134 | func isSet(bitpos uint, value uint32) bool {
135 | return value&(1< 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 |
--------------------------------------------------------------------------------
/bytes_test.go:
--------------------------------------------------------------------------------
1 | package solsha3
2 |
3 | import (
4 | "encoding/hex"
5 | "fmt"
6 | "testing"
7 | )
8 |
9 | func TestBytes(t *testing.T) {
10 | t.Run("bytes1", func(t *testing.T) {
11 | for i, tt := range []struct {
12 | in []byte
13 | out string
14 | }{
15 | {
16 | SoliditySHA3(
17 | Bytes1("0x5"),
18 | ),
19 | "dbb8d0f4c497851a5043c6363657698cb1387682cac2f786c731f8936109d795",
20 | },
21 | } {
22 | t.Run(fmt.Sprintf("%v", i), func(t *testing.T) {
23 | got := hex.EncodeToString(tt.in)
24 | if got != tt.out {
25 | t.Errorf("want %v, got %v", tt.out, got)
26 | }
27 | })
28 | }
29 | })
30 |
31 | t.Run("bytes2", func(t *testing.T) {
32 | for i, tt := range []struct {
33 | in []byte
34 | out string
35 | }{
36 | {
37 | SoliditySHA3(
38 | Bytes2("0x1234"),
39 | ),
40 | "56570de287d73cd1cb6092bb8fdee6173974955fdef345ae579ee9f475ea7432",
41 | },
42 | } {
43 | t.Run(fmt.Sprintf("%v", i), func(t *testing.T) {
44 | got := hex.EncodeToString(tt.in)
45 | if got != tt.out {
46 | t.Errorf("want %v, got %v", tt.out, got)
47 | }
48 | })
49 | }
50 | })
51 |
52 | t.Run("bytes4", func(t *testing.T) {
53 | for i, tt := range []struct {
54 | in []byte
55 | out string
56 | }{
57 | {
58 | SoliditySHA3(
59 | Bytes4("0xe0b6fcfc"),
60 | ),
61 | "a1204967c3aa63863e35064a313503edf747e6de2721e9dec149014654fddbba",
62 | },
63 | {
64 | SoliditySHA3(
65 | [4]byte{0xe0, 0xb6, 0xfc, 0xfc},
66 | ),
67 | "a1204967c3aa63863e35064a313503edf747e6de2721e9dec149014654fddbba",
68 | },
69 | } {
70 | t.Run(fmt.Sprintf("%v", i), func(t *testing.T) {
71 | got := hex.EncodeToString(tt.in)
72 | if got != tt.out {
73 | t.Errorf("want %v, got %v", tt.out, got)
74 | }
75 | })
76 | }
77 | })
78 |
79 | t.Run("bytes16", func(t *testing.T) {
80 | for i, tt := range []struct {
81 | in []byte
82 | out string
83 | }{
84 | {
85 | SoliditySHA3(
86 | Bytes4("0x12341234123412341234123412341234"),
87 | ),
88 | "0dd1e9e300f81dfb0638f199ac3dd3d605009475579a3925bb903909bd6ff1e0",
89 | },
90 | } {
91 | t.Run(fmt.Sprintf("%v", i), func(t *testing.T) {
92 | got := hex.EncodeToString(tt.in)
93 | if got != tt.out {
94 | t.Errorf("want %v, got %v", tt.out, got)
95 | }
96 | })
97 | }
98 | })
99 |
100 | t.Run("bytes32", func(t *testing.T) {
101 | for i, tt := range []struct {
102 | in []byte
103 | out string
104 | }{
105 | {
106 | SoliditySHA3(
107 | Bytes32("somedata"),
108 | ),
109 | "5de179cfd5920200431577c32d9c35e2b0bc5d8eaae3534e8146da8ab45be70b",
110 | },
111 | {
112 | SoliditySHA3(
113 | Bytes32("a"),
114 | ),
115 | "294587bf977c4010a60dbad811c63531f90f6ec512975bc6c9a93f8f361cad72",
116 | },
117 | {
118 | SoliditySHA3(
119 | Bytes32([32]byte{'a'}),
120 | ),
121 | "294587bf977c4010a60dbad811c63531f90f6ec512975bc6c9a93f8f361cad72",
122 | },
123 | } {
124 | t.Run(fmt.Sprintf("%v", i), func(t *testing.T) {
125 | got := hex.EncodeToString(tt.in)
126 | if got != tt.out {
127 | t.Errorf("want %v, got %v", tt.out, got)
128 | }
129 | })
130 | }
131 | })
132 |
133 | t.Run("bytes32", func(t *testing.T) {
134 | for i, tt := range []struct {
135 | in func() []byte
136 | out string
137 | }{
138 | {
139 | func() []byte {
140 | in := make([]byte, 32)
141 | copy(in[:], []byte("somedata"))
142 | return SoliditySHA3(
143 | []string{"bytes32"},
144 | in,
145 | )
146 | },
147 | "5de179cfd5920200431577c32d9c35e2b0bc5d8eaae3534e8146da8ab45be70b",
148 | },
149 | {
150 | func() []byte {
151 | in := make([]byte, 32)
152 | copy(in[:], []byte("a"))
153 | return SoliditySHA3(
154 | []string{"bytes32"},
155 | in,
156 | )
157 | },
158 | "294587bf977c4010a60dbad811c63531f90f6ec512975bc6c9a93f8f361cad72",
159 | },
160 | {
161 | func() []byte {
162 | return SoliditySHA3(
163 | []string{"bytes32"},
164 | [32]byte{'a'},
165 | )
166 | },
167 | "294587bf977c4010a60dbad811c63531f90f6ec512975bc6c9a93f8f361cad72",
168 | },
169 | {
170 | func() []byte {
171 | return SoliditySHA3(
172 | []string{"bytes32"},
173 | [32]byte{0x0a},
174 | )
175 | },
176 | "cee931476953956236065da391361912c6a45bc675f9f4e63b8d7bff037b43ae",
177 | },
178 | {
179 | func() []byte {
180 | return SoliditySHA3(
181 | []string{"bytes32"},
182 | "0xa000000000000000000000000000000000000000000000000000000000000000",
183 | )
184 | },
185 | "2c2171a229511a789fd39fbdea82b2f459f0d6f700e745d01bf69d70230ea3d7",
186 | },
187 | {
188 | func() []byte {
189 | return SoliditySHA3(
190 | []string{"bytes1"},
191 | "0x04",
192 | )
193 | },
194 | "f343681465b9efe82c933c3e8748c70cb8aa06539c361de20f72eac04e766393",
195 | },
196 | } {
197 | t.Run(fmt.Sprintf("%v", i), func(t *testing.T) {
198 | got := hex.EncodeToString(tt.in())
199 | if got != tt.out {
200 | t.Errorf("want %v, got %v", tt.out, got)
201 | }
202 | })
203 | }
204 | })
205 | }
206 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/util.go:
--------------------------------------------------------------------------------
1 | package solsha3
2 |
3 | import (
4 | "encoding/hex"
5 | "fmt"
6 | "reflect"
7 | "regexp"
8 | "strconv"
9 | "strings"
10 |
11 | "github.com/ethereum/go-ethereum/common"
12 | )
13 |
14 | var zeros = "0000000000000000000000000000000000000000000000000000000000000000"
15 |
16 | func concatByteSlices(arrays ...[]byte) []byte {
17 | var result []byte
18 |
19 | for _, b := range arrays {
20 | result = append(result, b...)
21 | }
22 |
23 | return result
24 | }
25 |
26 | func isArray(value interface{}) bool {
27 | return reflect.TypeOf(value).Kind() == reflect.Array ||
28 | reflect.TypeOf(value).Kind() == reflect.Slice
29 | }
30 |
31 | func padZeros(value []byte, width int) []byte {
32 | return common.LeftPadBytes(value, width)
33 | }
34 |
35 | func pack(typ string, value interface{}, _isArray bool) []byte {
36 | switch typ {
37 | case "address":
38 | if _isArray {
39 | return padZeros(Address(value), 32)
40 | }
41 |
42 | return Address(value)
43 | case "string":
44 | return String(value)
45 | case "bool":
46 | if _isArray {
47 | return padZeros(Bool(value), 32)
48 | }
49 |
50 | return Bool(value)
51 | }
52 |
53 | regexNumber := regexp.MustCompile(`^(u?int)([0-9]*)$`)
54 | matches := regexNumber.FindAllStringSubmatch(typ, -1)
55 | if len(matches) > 0 {
56 | match := matches[0]
57 | var err error
58 | size := 256
59 | if len(match) > 1 {
60 | //signed = match[1] == "int"
61 | }
62 | if len(match) > 2 {
63 | size, err = strconv.Atoi(match[2])
64 | if err != nil {
65 | panic(err)
66 | }
67 | }
68 |
69 | _ = size
70 | if (size%8 != 0) || size == 0 || size > 256 {
71 | panic("invalid number type " + typ)
72 | }
73 |
74 | if _isArray {
75 | size = 256
76 | }
77 |
78 | var v []byte
79 | if strings.HasPrefix(typ, "int8") {
80 | v = Int8(value)
81 | } else if strings.HasPrefix(typ, "int16") {
82 | v = Int16(value)
83 | } else if strings.HasPrefix(typ, "int32") {
84 | v = Int32(value)
85 | } else if strings.HasPrefix(typ, "int64") {
86 | v = Int64(value)
87 | } else if strings.HasPrefix(typ, "int128") {
88 | v = Int128(value)
89 | } else if strings.HasPrefix(typ, "int256") {
90 | v = Int256(value)
91 | } else if strings.HasPrefix(typ, "uint8") {
92 | v = Uint8(value)
93 | } else if strings.HasPrefix(typ, "uint16") {
94 | v = Uint16(value)
95 | } else if strings.HasPrefix(typ, "uint32") {
96 | v = Uint32(value)
97 | } else if strings.HasPrefix(typ, "uint128") {
98 | v = Uint128(value)
99 | } else if strings.HasPrefix(typ, "uint64") {
100 | v = Uint64(value)
101 | } else if strings.HasPrefix(typ, "uint256") {
102 | v = Uint256(value)
103 | }
104 | return padZeros(v, size/8)
105 | }
106 |
107 | regexBytes := regexp.MustCompile(`^bytes([0-9]+)$`)
108 | matches = regexBytes.FindAllStringSubmatch(typ, -1)
109 | if len(matches) > 0 {
110 | match := matches[0]
111 |
112 | byteLen, err := strconv.Atoi(match[1])
113 | if err != nil {
114 | panic(err)
115 | }
116 |
117 | strSize := strconv.Itoa(byteLen)
118 | if strSize != match[1] || byteLen == 0 || byteLen > 32 {
119 | panic("invalid number type " + typ)
120 | }
121 |
122 | if _isArray {
123 | s := reflect.ValueOf(value)
124 | v := s.Index(0).Bytes()
125 | z := make([]byte, 64)
126 | copy(z[:], v[:])
127 | return z[:]
128 | }
129 |
130 | str, isString := value.(string)
131 | if isString && isHex(str) {
132 | s := removeHexPrefix(str)
133 | if len(s)%2 == 1 {
134 | s = "0" + s
135 | }
136 | hexb, err := hex.DecodeString(s)
137 | if err != nil {
138 | panic(err)
139 | }
140 | z := make([]byte, byteLen)
141 | copy(z[:], hexb)
142 | return z
143 | } else if isString {
144 | s := reflect.ValueOf(value)
145 | z := make([]byte, byteLen)
146 | copy(z[:], s.Bytes())
147 | return z
148 | }
149 |
150 | s := reflect.ValueOf(value)
151 | z := make([]byte, byteLen)
152 | b := make([]byte, s.Len())
153 | for i := 0; i < s.Len(); i++ {
154 | ifc := s.Index(i).Interface()
155 | v, ok := ifc.(byte)
156 | if ok {
157 | b[i] = v
158 | } else {
159 | v, ok := ifc.(string)
160 | if ok {
161 | v = removeHexPrefix(v)
162 | if len(v)%2 == 1 {
163 | v = "0" + v
164 | }
165 | decoded, err := hex.DecodeString(v)
166 | if err != nil {
167 | panic(err)
168 | }
169 | b[i] = decoded[0]
170 | }
171 | }
172 |
173 | }
174 | copy(z[:], b[:])
175 | return z
176 | }
177 |
178 | regexArray := regexp.MustCompile(`^(.*)\[([0-9]*)\]$`)
179 | matches = regexArray.FindAllStringSubmatch(typ, -1)
180 | if len(matches) > 0 {
181 | match := matches[0]
182 |
183 | _ = match
184 | if isArray(value) {
185 | baseType := match[1]
186 | k := reflect.ValueOf(value)
187 | count := k.Len()
188 | var err error
189 | if len(match) > 1 && match[2] != "" {
190 | count, err = strconv.Atoi(match[2])
191 | if err != nil {
192 | panic(err)
193 | }
194 | }
195 | if count != k.Len() {
196 | panic("invalid value for " + typ)
197 | }
198 |
199 | var result [][]byte
200 | for i := 0; i < k.Len(); i++ {
201 | val := k.Index(i).Interface()
202 |
203 | result = append(result, pack(baseType, val, true))
204 | }
205 |
206 | return concatByteSlices(result...)
207 | }
208 | }
209 | return nil
210 | }
211 |
212 | func removeHexPrefix(str string) string {
213 | return strings.TrimPrefix(str, "0x")
214 | }
215 |
216 | func isHex(str string) bool {
217 | return strings.HasPrefix(str, "0x")
218 | }
219 |
220 | func stringToBytes(str string) []byte {
221 | if isHex(str) {
222 | str = evenLengthHex(removeHexPrefix(str))
223 | } else {
224 | str = fmt.Sprintf("%0x", str)
225 | }
226 |
227 | hexb, _ := hex.DecodeString(str)
228 | return hexb
229 | }
230 |
231 | func evenLengthHex(v string) string {
232 | if len(v)%2 == 1 {
233 | v = "0" + v
234 | }
235 | return v
236 | }
237 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/crypto/sha3/shake.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 sha3
6 |
7 | // This file defines the ShakeHash interface, and provides
8 | // functions for creating SHAKE and cSHAKE instances, as well as utility
9 | // functions for hashing bytes to arbitrary-length output.
10 | //
11 | //
12 | // SHAKE implementation is based on FIPS PUB 202 [1]
13 | // cSHAKE implementations is based on NIST SP 800-185 [2]
14 | //
15 | // [1] https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.202.pdf
16 | // [2] https://doi.org/10.6028/NIST.SP.800-185
17 |
18 | import (
19 | "encoding/binary"
20 | "io"
21 | )
22 |
23 | // ShakeHash defines the interface to hash functions that
24 | // support arbitrary-length output.
25 | type ShakeHash interface {
26 | // Write absorbs more data into the hash's state. It panics if input is
27 | // written to it after output has been read from it.
28 | io.Writer
29 |
30 | // Read reads more output from the hash; reading affects the hash's
31 | // state. (ShakeHash.Read is thus very different from Hash.Sum)
32 | // It never returns an error.
33 | io.Reader
34 |
35 | // Clone returns a copy of the ShakeHash in its current state.
36 | Clone() ShakeHash
37 |
38 | // Reset resets the ShakeHash to its initial state.
39 | Reset()
40 | }
41 |
42 | // cSHAKE specific context
43 | type cshakeState struct {
44 | *state // SHA-3 state context and Read/Write operations
45 |
46 | // initBlock is the cSHAKE specific initialization set of bytes. It is initialized
47 | // by newCShake function and stores concatenation of N followed by S, encoded
48 | // by the method specified in 3.3 of [1].
49 | // It is stored here in order for Reset() to be able to put context into
50 | // initial state.
51 | initBlock []byte
52 | }
53 |
54 | // Consts for configuring initial SHA-3 state
55 | const (
56 | dsbyteShake = 0x1f
57 | dsbyteCShake = 0x04
58 | rate128 = 168
59 | rate256 = 136
60 | )
61 |
62 | func bytepad(input []byte, w int) []byte {
63 | // leftEncode always returns max 9 bytes
64 | buf := make([]byte, 0, 9+len(input)+w)
65 | buf = append(buf, leftEncode(uint64(w))...)
66 | buf = append(buf, input...)
67 | padlen := w - (len(buf) % w)
68 | return append(buf, make([]byte, padlen)...)
69 | }
70 |
71 | func leftEncode(value uint64) []byte {
72 | var b [9]byte
73 | binary.BigEndian.PutUint64(b[1:], value)
74 | // Trim all but last leading zero bytes
75 | i := byte(1)
76 | for i < 8 && b[i] == 0 {
77 | i++
78 | }
79 | // Prepend number of encoded bytes
80 | b[i-1] = 9 - i
81 | return b[i-1:]
82 | }
83 |
84 | func newCShake(N, S []byte, rate int, dsbyte byte) ShakeHash {
85 | c := cshakeState{state: &state{rate: rate, dsbyte: dsbyte}}
86 |
87 | // leftEncode returns max 9 bytes
88 | c.initBlock = make([]byte, 0, 9*2+len(N)+len(S))
89 | c.initBlock = append(c.initBlock, leftEncode(uint64(len(N)*8))...)
90 | c.initBlock = append(c.initBlock, N...)
91 | c.initBlock = append(c.initBlock, leftEncode(uint64(len(S)*8))...)
92 | c.initBlock = append(c.initBlock, S...)
93 | c.Write(bytepad(c.initBlock, c.rate))
94 | return &c
95 | }
96 |
97 | // Reset resets the hash to initial state.
98 | func (c *cshakeState) Reset() {
99 | c.state.Reset()
100 | c.Write(bytepad(c.initBlock, c.rate))
101 | }
102 |
103 | // Clone returns copy of a cSHAKE context within its current state.
104 | func (c *cshakeState) Clone() ShakeHash {
105 | b := make([]byte, len(c.initBlock))
106 | copy(b, c.initBlock)
107 | return &cshakeState{state: c.clone(), initBlock: b}
108 | }
109 |
110 | // Clone returns copy of SHAKE context within its current state.
111 | func (c *state) Clone() ShakeHash {
112 | return c.clone()
113 | }
114 |
115 | // NewShake128 creates a new SHAKE128 variable-output-length ShakeHash.
116 | // Its generic security strength is 128 bits against all attacks if at
117 | // least 32 bytes of its output are used.
118 | func NewShake128() ShakeHash {
119 | if h := newShake128Asm(); h != nil {
120 | return h
121 | }
122 | return &state{rate: rate128, dsbyte: dsbyteShake}
123 | }
124 |
125 | // NewShake256 creates a new SHAKE256 variable-output-length ShakeHash.
126 | // Its generic security strength is 256 bits against all attacks if
127 | // at least 64 bytes of its output are used.
128 | func NewShake256() ShakeHash {
129 | if h := newShake256Asm(); h != nil {
130 | return h
131 | }
132 | return &state{rate: rate256, dsbyte: dsbyteShake}
133 | }
134 |
135 | // NewCShake128 creates a new instance of cSHAKE128 variable-output-length ShakeHash,
136 | // a customizable variant of SHAKE128.
137 | // N is used to define functions based on cSHAKE, it can be empty when plain cSHAKE is
138 | // desired. S is a customization byte string used for domain separation - two cSHAKE
139 | // computations on same input with different S yield unrelated outputs.
140 | // When N and S are both empty, this is equivalent to NewShake128.
141 | func NewCShake128(N, S []byte) ShakeHash {
142 | if len(N) == 0 && len(S) == 0 {
143 | return NewShake128()
144 | }
145 | return newCShake(N, S, rate128, dsbyteCShake)
146 | }
147 |
148 | // NewCShake256 creates a new instance of cSHAKE256 variable-output-length ShakeHash,
149 | // a customizable variant of SHAKE256.
150 | // N is used to define functions based on cSHAKE, it can be empty when plain cSHAKE is
151 | // desired. S is a customization byte string used for domain separation - two cSHAKE
152 | // computations on same input with different S yield unrelated outputs.
153 | // When N and S are both empty, this is equivalent to NewShake256.
154 | func NewCShake256(N, S []byte) ShakeHash {
155 | if len(N) == 0 && len(S) == 0 {
156 | return NewShake256()
157 | }
158 | return newCShake(N, S, rate256, dsbyteCShake)
159 | }
160 |
161 | // ShakeSum128 writes an arbitrary-length digest of data into hash.
162 | func ShakeSum128(hash, data []byte) {
163 | h := NewShake128()
164 | h.Write(data)
165 | h.Read(hash)
166 | }
167 |
168 | // ShakeSum256 writes an arbitrary-length digest of data into hash.
169 | func ShakeSum256(hash, data []byte) {
170 | h := NewShake256()
171 | h.Write(data)
172 | h.Read(hash)
173 | }
174 |
--------------------------------------------------------------------------------
/bytes.go:
--------------------------------------------------------------------------------
1 | package solsha3
2 |
3 | import (
4 | "github.com/ethereum/go-ethereum/common"
5 | )
6 |
7 | // Byte byte
8 | func Byte(input interface{}) []byte {
9 | return Bytes1(input)
10 | }
11 |
12 | // Bytes1 bytes1
13 | func Bytes1(input interface{}) []byte {
14 | return parseBytes(input, 1)
15 | }
16 |
17 | // Bytes2 bytes2
18 | func Bytes2(input interface{}) []byte {
19 | return parseBytes(input, 2)
20 | }
21 |
22 | // Bytes3 bytes3
23 | func Bytes3(input interface{}) []byte {
24 | return parseBytes(input, 3)
25 | }
26 |
27 | // Bytes4 bytes4
28 | func Bytes4(input interface{}) []byte {
29 | return parseBytes(input, 4)
30 | }
31 |
32 | // Bytes5 bytes5
33 | func Bytes5(input interface{}) []byte {
34 | return parseBytes(input, 5)
35 | }
36 |
37 | // Bytes6 bytes6
38 | func Bytes6(input interface{}) []byte {
39 | return parseBytes(input, 6)
40 | }
41 |
42 | // Bytes7 bytes7
43 | func Bytes7(input interface{}) []byte {
44 | return parseBytes(input, 7)
45 | }
46 |
47 | // Bytes8 bytes8
48 | func Bytes8(input interface{}) []byte {
49 | return parseBytes(input, 8)
50 | }
51 |
52 | // Bytes9 bytes9
53 | func Bytes9(input interface{}) []byte {
54 | return parseBytes(input, 9)
55 | }
56 |
57 | // Bytes10 bytes10
58 | func Bytes10(input interface{}) []byte {
59 | return parseBytes(input, 10)
60 | }
61 |
62 |
63 | // Bytes11 bytes11
64 | func Bytes11(input interface{}) []byte {
65 | return parseBytes(input, 11)
66 | }
67 |
68 | // Bytes12 bytes12
69 | func Bytes12(input interface{}) []byte {
70 | return parseBytes(input, 12)
71 | }
72 |
73 | // Bytes13 bytes13
74 | func Bytes13(input interface{}) []byte {
75 | return parseBytes(input, 13)
76 | }
77 |
78 | // Bytes14 bytes14
79 | func Bytes14(input interface{}) []byte {
80 | return parseBytes(input, 14)
81 | }
82 |
83 | // Bytes15 bytes15
84 | func Bytes15(input interface{}) []byte {
85 | return parseBytes(input, 15)
86 | }
87 |
88 | // Bytes16 bytes16
89 | func Bytes16(input interface{}) []byte {
90 | return parseBytes(input, 16)
91 | }
92 |
93 | // Bytes17 bytes17
94 | func Bytes17(input interface{}) []byte {
95 | return parseBytes(input, 17)
96 | }
97 |
98 | // Bytes18 bytes18
99 | func Bytes18(input interface{}) []byte {
100 | return parseBytes(input, 18)
101 | }
102 |
103 | // Bytes19 bytes19
104 | func Bytes19(input interface{}) []byte {
105 | return parseBytes(input, 19)
106 | }
107 |
108 | // Bytes20 bytes20
109 | func Bytes20(input interface{}) []byte {
110 | return parseBytes(input, 20)
111 | }
112 |
113 | // Bytes21 bytes21
114 | func Bytes21(input interface{}) []byte {
115 | return parseBytes(input, 21)
116 | }
117 |
118 | // Bytes22 bytes22
119 | func Bytes22(input interface{}) []byte {
120 | return parseBytes(input, 22)
121 | }
122 |
123 | // Bytes23 bytes23
124 | func Bytes23(input interface{}) []byte {
125 | return parseBytes(input, 23)
126 | }
127 |
128 | // Bytes24 bytes24
129 | func Bytes24(input interface{}) []byte {
130 | return parseBytes(input, 24)
131 | }
132 |
133 | // Bytes25 bytes25
134 | func Bytes25(input interface{}) []byte {
135 | return parseBytes(input, 25)
136 | }
137 |
138 | // Bytes26 bytes26
139 | func Bytes26(input interface{}) []byte {
140 | return parseBytes(input, 26)
141 | }
142 |
143 | // Bytes27 bytes27
144 | func Bytes27(input interface{}) []byte {
145 | return parseBytes(input, 27)
146 | }
147 |
148 | // Bytes28 bytes28
149 | func Bytes28(input interface{}) []byte {
150 | return parseBytes(input, 28)
151 | }
152 |
153 | // Bytes29 bytes29
154 | func Bytes29(input interface{}) []byte {
155 | return parseBytes(input, 29)
156 | }
157 |
158 | // Bytes30 bytes30
159 | func Bytes30(input interface{}) []byte {
160 | return parseBytes(input, 30)
161 | }
162 |
163 | // Bytes31 bytes31
164 | func Bytes31(input interface{}) []byte {
165 | return parseBytes(input, 31)
166 | }
167 |
168 | // Bytes32 bytes32
169 | func Bytes32(input interface{}) []byte {
170 | return parseBytes(input, 32)
171 | }
172 |
173 | func rightPadBytes(v []byte, byteLen int) []byte {
174 | if byteLen == -1 {
175 | return v
176 | }
177 | return common.RightPadBytes(v[:], byteLen)
178 | }
179 |
180 | func parseBytes(input interface{}, byteLen int) []byte {
181 | switch v := input.(type) {
182 | case [1]byte:
183 | return rightPadBytes(v[:], byteLen)
184 | case [2]byte:
185 | return rightPadBytes(v[:], byteLen)
186 | case [3]byte:
187 | return rightPadBytes(v[:], byteLen)
188 | case [4]byte:
189 | return rightPadBytes(v[:], byteLen)
190 | case [5]byte:
191 | return rightPadBytes(v[:], byteLen)
192 | case [6]byte:
193 | return rightPadBytes(v[:], byteLen)
194 | case [7]byte:
195 | return rightPadBytes(v[:], byteLen)
196 | case [8]byte:
197 | return rightPadBytes(v[:], byteLen)
198 | case [9]byte:
199 | return rightPadBytes(v[:], byteLen)
200 | case [10]byte:
201 | return rightPadBytes(v[:], byteLen)
202 | case [11]byte:
203 | return rightPadBytes(v[:], byteLen)
204 | case [12]byte:
205 | return rightPadBytes(v[:], byteLen)
206 | case [13]byte:
207 | return rightPadBytes(v[:], byteLen)
208 | case [14]byte:
209 | return rightPadBytes(v[:], byteLen)
210 | case [15]byte:
211 | return rightPadBytes(v[:], byteLen)
212 | case [16]byte:
213 | return rightPadBytes(v[:], byteLen)
214 | case [17]byte:
215 | return rightPadBytes(v[:], byteLen)
216 | case [18]byte:
217 | return rightPadBytes(v[:], byteLen)
218 | case [19]byte:
219 | return rightPadBytes(v[:], byteLen)
220 | case [20]byte:
221 | return rightPadBytes(v[:], byteLen)
222 | case [21]byte:
223 | return rightPadBytes(v[:], byteLen)
224 | case [22]byte:
225 | return rightPadBytes(v[:], byteLen)
226 | case [23]byte:
227 | return rightPadBytes(v[:], byteLen)
228 | case [24]byte:
229 | return rightPadBytes(v[:], byteLen)
230 | case [25]byte:
231 | return rightPadBytes(v[:], byteLen)
232 | case [26]byte:
233 | return rightPadBytes(v[:], byteLen)
234 | case [27]byte:
235 | return rightPadBytes(v[:], byteLen)
236 | case [28]byte:
237 | return rightPadBytes(v[:], byteLen)
238 | case [29]byte:
239 | return rightPadBytes(v[:], byteLen)
240 | case [30]byte:
241 | return rightPadBytes(v[:], byteLen)
242 | case [31]byte:
243 | return rightPadBytes(v[:], byteLen)
244 | case [32]byte:
245 | return rightPadBytes(v[:], byteLen)
246 | case []byte:
247 | return rightPadBytes(v, byteLen)
248 | case string:
249 | hexb := stringToBytes(v)
250 | h := common.RightPadBytes(hexb, byteLen)
251 | return h
252 | default:
253 | return rightPadBytes([]byte(""), byteLen)
254 | }
255 | }
256 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/crypto/sha3/sha3.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 sha3
6 |
7 | // spongeDirection indicates the direction bytes are flowing through the sponge.
8 | type spongeDirection int
9 |
10 | const (
11 | // spongeAbsorbing indicates that the sponge is absorbing input.
12 | spongeAbsorbing spongeDirection = iota
13 | // spongeSqueezing indicates that the sponge is being squeezed.
14 | spongeSqueezing
15 | )
16 |
17 | const (
18 | // maxRate is the maximum size of the internal buffer. SHAKE-256
19 | // currently needs the largest buffer.
20 | maxRate = 168
21 | )
22 |
23 | type state struct {
24 | // Generic sponge components.
25 | a [25]uint64 // main state of the hash
26 | buf []byte // points into storage
27 | rate int // the number of bytes of state to use
28 |
29 | // dsbyte contains the "domain separation" bits and the first bit of
30 | // the padding. Sections 6.1 and 6.2 of [1] separate the outputs of the
31 | // SHA-3 and SHAKE functions by appending bitstrings to the message.
32 | // Using a little-endian bit-ordering convention, these are "01" for SHA-3
33 | // and "1111" for SHAKE, or 00000010b and 00001111b, respectively. Then the
34 | // padding rule from section 5.1 is applied to pad the message to a multiple
35 | // of the rate, which involves adding a "1" bit, zero or more "0" bits, and
36 | // a final "1" bit. We merge the first "1" bit from the padding into dsbyte,
37 | // giving 00000110b (0x06) and 00011111b (0x1f).
38 | // [1] http://csrc.nist.gov/publications/drafts/fips-202/fips_202_draft.pdf
39 | // "Draft FIPS 202: SHA-3 Standard: Permutation-Based Hash and
40 | // Extendable-Output Functions (May 2014)"
41 | dsbyte byte
42 |
43 | storage storageBuf
44 |
45 | // Specific to SHA-3 and SHAKE.
46 | outputLen int // the default output size in bytes
47 | state spongeDirection // whether the sponge is absorbing or squeezing
48 | }
49 |
50 | // BlockSize returns the rate of sponge underlying this hash function.
51 | func (d *state) BlockSize() int { return d.rate }
52 |
53 | // Size returns the output size of the hash function in bytes.
54 | func (d *state) Size() int { return d.outputLen }
55 |
56 | // Reset clears the internal state by zeroing the sponge state and
57 | // the byte buffer, and setting Sponge.state to absorbing.
58 | func (d *state) Reset() {
59 | // Zero the permutation's state.
60 | for i := range d.a {
61 | d.a[i] = 0
62 | }
63 | d.state = spongeAbsorbing
64 | d.buf = d.storage.asBytes()[:0]
65 | }
66 |
67 | func (d *state) clone() *state {
68 | ret := *d
69 | if ret.state == spongeAbsorbing {
70 | ret.buf = ret.storage.asBytes()[:len(ret.buf)]
71 | } else {
72 | ret.buf = ret.storage.asBytes()[d.rate-cap(d.buf) : d.rate]
73 | }
74 |
75 | return &ret
76 | }
77 |
78 | // permute applies the KeccakF-1600 permutation. It handles
79 | // any input-output buffering.
80 | func (d *state) permute() {
81 | switch d.state {
82 | case spongeAbsorbing:
83 | // If we're absorbing, we need to xor the input into the state
84 | // before applying the permutation.
85 | xorIn(d, d.buf)
86 | d.buf = d.storage.asBytes()[:0]
87 | keccakF1600(&d.a)
88 | case spongeSqueezing:
89 | // If we're squeezing, we need to apply the permutatin before
90 | // copying more output.
91 | keccakF1600(&d.a)
92 | d.buf = d.storage.asBytes()[:d.rate]
93 | copyOut(d, d.buf)
94 | }
95 | }
96 |
97 | // pads appends the domain separation bits in dsbyte, applies
98 | // the multi-bitrate 10..1 padding rule, and permutes the state.
99 | func (d *state) padAndPermute(dsbyte byte) {
100 | if d.buf == nil {
101 | d.buf = d.storage.asBytes()[:0]
102 | }
103 | // Pad with this instance's domain-separator bits. We know that there's
104 | // at least one byte of space in d.buf because, if it were full,
105 | // permute would have been called to empty it. dsbyte also contains the
106 | // first one bit for the padding. See the comment in the state struct.
107 | d.buf = append(d.buf, dsbyte)
108 | zerosStart := len(d.buf)
109 | d.buf = d.storage.asBytes()[:d.rate]
110 | for i := zerosStart; i < d.rate; i++ {
111 | d.buf[i] = 0
112 | }
113 | // This adds the final one bit for the padding. Because of the way that
114 | // bits are numbered from the LSB upwards, the final bit is the MSB of
115 | // the last byte.
116 | d.buf[d.rate-1] ^= 0x80
117 | // Apply the permutation
118 | d.permute()
119 | d.state = spongeSqueezing
120 | d.buf = d.storage.asBytes()[:d.rate]
121 | copyOut(d, d.buf)
122 | }
123 |
124 | // Write absorbs more data into the hash's state. It produces an error
125 | // if more data is written to the ShakeHash after writing
126 | func (d *state) Write(p []byte) (written int, err error) {
127 | if d.state != spongeAbsorbing {
128 | panic("sha3: write to sponge after read")
129 | }
130 | if d.buf == nil {
131 | d.buf = d.storage.asBytes()[:0]
132 | }
133 | written = len(p)
134 |
135 | for len(p) > 0 {
136 | if len(d.buf) == 0 && len(p) >= d.rate {
137 | // The fast path; absorb a full "rate" bytes of input and apply the permutation.
138 | xorIn(d, p[:d.rate])
139 | p = p[d.rate:]
140 | keccakF1600(&d.a)
141 | } else {
142 | // The slow path; buffer the input until we can fill the sponge, and then xor it in.
143 | todo := d.rate - len(d.buf)
144 | if todo > len(p) {
145 | todo = len(p)
146 | }
147 | d.buf = append(d.buf, p[:todo]...)
148 | p = p[todo:]
149 |
150 | // If the sponge is full, apply the permutation.
151 | if len(d.buf) == d.rate {
152 | d.permute()
153 | }
154 | }
155 | }
156 |
157 | return
158 | }
159 |
160 | // Read squeezes an arbitrary number of bytes from the sponge.
161 | func (d *state) Read(out []byte) (n int, err error) {
162 | // If we're still absorbing, pad and apply the permutation.
163 | if d.state == spongeAbsorbing {
164 | d.padAndPermute(d.dsbyte)
165 | }
166 |
167 | n = len(out)
168 |
169 | // Now, do the squeezing.
170 | for len(out) > 0 {
171 | n := copy(out, d.buf)
172 | d.buf = d.buf[n:]
173 | out = out[n:]
174 |
175 | // Apply the permutation if we've squeezed the sponge dry.
176 | if len(d.buf) == 0 {
177 | d.permute()
178 | }
179 | }
180 |
181 | return
182 | }
183 |
184 | // Sum applies padding to the hash state and then squeezes out the desired
185 | // number of output bytes.
186 | func (d *state) Sum(in []byte) []byte {
187 | // Make a copy of the original hash so that caller can keep writing
188 | // and summing.
189 | dup := d.clone()
190 | hash := make([]byte, dup.outputLen)
191 | dup.Read(hash)
192 | return append(in, hash...)
193 | }
194 |
--------------------------------------------------------------------------------
/uint_test.go:
--------------------------------------------------------------------------------
1 | package solsha3
2 |
3 | import (
4 | "encoding/hex"
5 | "fmt"
6 | "math/big"
7 | "testing"
8 | )
9 |
10 | func TestUint(t *testing.T) {
11 | t.Run("uint/int", func(t *testing.T) {
12 | for i, tt := range []struct {
13 | in []byte
14 | out string
15 | }{
16 | {
17 | SoliditySHA3(
18 | Uint256(big.NewInt(100)),
19 | ),
20 | "26700e13983fefbd9cf16da2ed70fa5c6798ac55062a4803121a869731e308d2",
21 | },
22 | {
23 | SoliditySHA3(
24 | Uint256("100"),
25 | ),
26 | "26700e13983fefbd9cf16da2ed70fa5c6798ac55062a4803121a869731e308d2",
27 | },
28 | {
29 | SoliditySHA3(
30 | Uint128(big.NewInt(100)),
31 | ),
32 | "e676e20e5d612283600da1ff24a86bdbc07d286dfe8e6afba02988c485a6749d",
33 | },
34 | {
35 | SoliditySHA3(
36 | Uint64(100),
37 | ),
38 | "dc961d2e5d46532f7b9f65afdb640c5284dfb1a947abf2b23758931400995e0f",
39 | },
40 | {
41 | SoliditySHA3(
42 | Uint32(100),
43 | ),
44 | "f01681d2220bfea4bb888a5543db8c0916274ddb1ea93b144c042c01d8164c95",
45 | },
46 | {
47 | SoliditySHA3(
48 | Uint16(100),
49 | ),
50 | "2ce80d2bc0bfe54c2499d066ac958c02304ce64ca318ae19a4636c32d583429c",
51 | },
52 | {
53 | SoliditySHA3(
54 | Uint8(100),
55 | ),
56 | "f1918e8562236eb17adc8502332f4c9c82bc14e19bfc0aa10ab674ff75b3d2f3",
57 | },
58 | {
59 | SoliditySHA3(
60 | Uint8([3]uint8{1, 2, 3}),
61 | ),
62 | "6e0c627900b24bd432fe7b1f713f1b0744091a646a9fe4a65a18dfed21f2949c",
63 | },
64 | {
65 | SoliditySHA3(
66 | Uint8([]uint8{1, 2, 3}),
67 | ),
68 | "6e0c627900b24bd432fe7b1f713f1b0744091a646a9fe4a65a18dfed21f2949c",
69 | },
70 | {
71 | SoliditySHA3(
72 | Int256(big.NewInt(100)),
73 | ),
74 | "26700e13983fefbd9cf16da2ed70fa5c6798ac55062a4803121a869731e308d2",
75 | },
76 | {
77 | SoliditySHA3(
78 | Int128(big.NewInt(100)),
79 | ),
80 | "e676e20e5d612283600da1ff24a86bdbc07d286dfe8e6afba02988c485a6749d",
81 | },
82 | {
83 | SoliditySHA3(
84 | Int64(100),
85 | ),
86 | "dc961d2e5d46532f7b9f65afdb640c5284dfb1a947abf2b23758931400995e0f",
87 | },
88 | {
89 | SoliditySHA3(
90 | Int32(100),
91 | ),
92 | "f01681d2220bfea4bb888a5543db8c0916274ddb1ea93b144c042c01d8164c95",
93 | },
94 | {
95 | SoliditySHA3(
96 | Int16(100),
97 | ),
98 | "2ce80d2bc0bfe54c2499d066ac958c02304ce64ca318ae19a4636c32d583429c",
99 | },
100 | {
101 | SoliditySHA3(
102 | Int16(-1000),
103 | ),
104 | "779c8f2f6090bb23de632d95b8edb88a9473562dbe3910f0cefdd2b3d969d4da",
105 | },
106 | {
107 | SoliditySHA3(
108 | Int8(100),
109 | ),
110 | "f1918e8562236eb17adc8502332f4c9c82bc14e19bfc0aa10ab674ff75b3d2f3",
111 | },
112 | {
113 | SoliditySHA3(
114 | Int8([3]int8{1, 2, 3}),
115 | ),
116 | "6e0c627900b24bd432fe7b1f713f1b0744091a646a9fe4a65a18dfed21f2949c",
117 | },
118 | {
119 | SoliditySHA3(
120 | Int8(-100),
121 | ),
122 | "26ce63779ce95adee31308d97bf37df2920dcdbb38c8db0620241fe2f08c8ed9",
123 | },
124 | } {
125 | t.Run(fmt.Sprintf("%v", i), func(t *testing.T) {
126 | got := hex.EncodeToString(tt.in)
127 | if got != tt.out {
128 | t.Errorf("want %v, got %v", tt.out, got)
129 | }
130 | })
131 | }
132 | })
133 |
134 | t.Run("uint/int", func(t *testing.T) {
135 | for i, tt := range []struct {
136 | in []byte
137 | out string
138 | }{
139 | {
140 | SoliditySHA3(
141 | []string{"uint256"},
142 | big.NewInt(100),
143 | ),
144 | "26700e13983fefbd9cf16da2ed70fa5c6798ac55062a4803121a869731e308d2",
145 | },
146 | {
147 | SoliditySHA3(
148 | []string{"uint256"},
149 | "100",
150 | ),
151 | "26700e13983fefbd9cf16da2ed70fa5c6798ac55062a4803121a869731e308d2",
152 | },
153 | {
154 | SoliditySHA3(
155 | []string{"uint128"},
156 | big.NewInt(100),
157 | ),
158 | "e676e20e5d612283600da1ff24a86bdbc07d286dfe8e6afba02988c485a6749d",
159 | },
160 | {
161 | SoliditySHA3(
162 | []string{"uint64"},
163 | 100,
164 | ),
165 | "dc961d2e5d46532f7b9f65afdb640c5284dfb1a947abf2b23758931400995e0f",
166 | },
167 | {
168 | SoliditySHA3(
169 | []string{"uint32"},
170 | 100,
171 | ),
172 | "f01681d2220bfea4bb888a5543db8c0916274ddb1ea93b144c042c01d8164c95",
173 | },
174 | {
175 | SoliditySHA3(
176 | []string{"uint16"},
177 | 100,
178 | ),
179 | "2ce80d2bc0bfe54c2499d066ac958c02304ce64ca318ae19a4636c32d583429c",
180 | },
181 | {
182 | SoliditySHA3(
183 | []string{"uint8"},
184 | 100,
185 | ),
186 | "f1918e8562236eb17adc8502332f4c9c82bc14e19bfc0aa10ab674ff75b3d2f3",
187 | },
188 | {
189 | SoliditySHA3(
190 | Uint8([3]uint8{1, 2, 3}),
191 | ),
192 | "6e0c627900b24bd432fe7b1f713f1b0744091a646a9fe4a65a18dfed21f2949c",
193 | },
194 | {
195 | SoliditySHA3(
196 | Uint8([]uint8{1, 2, 3}),
197 | ),
198 | "6e0c627900b24bd432fe7b1f713f1b0744091a646a9fe4a65a18dfed21f2949c",
199 | },
200 | {
201 | SoliditySHA3(
202 | []string{"int256"},
203 | big.NewInt(100),
204 | ),
205 | "26700e13983fefbd9cf16da2ed70fa5c6798ac55062a4803121a869731e308d2",
206 | },
207 | {
208 | SoliditySHA3(
209 | []string{"int128"},
210 | big.NewInt(100),
211 | ),
212 | "e676e20e5d612283600da1ff24a86bdbc07d286dfe8e6afba02988c485a6749d",
213 | },
214 | {
215 | SoliditySHA3(
216 | []string{"int64"},
217 | 100,
218 | ),
219 | "dc961d2e5d46532f7b9f65afdb640c5284dfb1a947abf2b23758931400995e0f",
220 | },
221 | {
222 | SoliditySHA3(
223 | []string{"int32"},
224 | 100,
225 | ),
226 | "f01681d2220bfea4bb888a5543db8c0916274ddb1ea93b144c042c01d8164c95",
227 | },
228 | {
229 | SoliditySHA3(
230 | []string{"int16"},
231 | 100,
232 | ),
233 | "2ce80d2bc0bfe54c2499d066ac958c02304ce64ca318ae19a4636c32d583429c",
234 | },
235 | {
236 | SoliditySHA3(
237 | []string{"int16"},
238 | -1000,
239 | ),
240 | "779c8f2f6090bb23de632d95b8edb88a9473562dbe3910f0cefdd2b3d969d4da",
241 | },
242 | {
243 | SoliditySHA3(
244 | []string{"int8"},
245 | 100,
246 | ),
247 | "f1918e8562236eb17adc8502332f4c9c82bc14e19bfc0aa10ab674ff75b3d2f3",
248 | },
249 | {
250 | SoliditySHA3(
251 | Int8([3]int8{1, 2, 3}),
252 | ),
253 | "6e0c627900b24bd432fe7b1f713f1b0744091a646a9fe4a65a18dfed21f2949c",
254 | },
255 | {
256 | SoliditySHA3(
257 | []string{"int8"},
258 | -100,
259 | ),
260 | "26ce63779ce95adee31308d97bf37df2920dcdbb38c8db0620241fe2f08c8ed9",
261 | },
262 | } {
263 | t.Run(fmt.Sprintf("%v", i), func(t *testing.T) {
264 | got := hex.EncodeToString(tt.in)
265 | if got != tt.out {
266 | t.Errorf("want %v, got %v", tt.out, got)
267 | }
268 | })
269 | }
270 | })
271 | }
272 |
--------------------------------------------------------------------------------
/solsha3_test.go:
--------------------------------------------------------------------------------
1 | package solsha3
2 |
3 | import (
4 | "encoding/hex"
5 | "fmt"
6 | "testing"
7 |
8 | "github.com/ethereum/go-ethereum/common"
9 | )
10 |
11 | func TestSolSha3Legacy(t *testing.T) {
12 | t.Run("address", func(t *testing.T) {
13 | for i, tt := range []struct {
14 | in []byte
15 | out string
16 | }{
17 | {
18 | SoliditySHA3(Address(0)),
19 | "5380c7b7ae81a58eb98d9c78de4a1fd7fd9535fc953ed2be602daaa41767312a",
20 | },
21 | {
22 | SoliditySHA3(Address("0x0a")),
23 |
24 | "0ef9d8f8804d174666011a394cab7901679a8944d24249fd148a6a36071151f8",
25 | },
26 | {
27 | SoliditySHA3(Address("0x12459c951127e0c374ff9105dda097662a027092")),
28 | "4b998b071d7bb74aee1ce2cdcc268cb0f6409b4a3387fc915617ec08415298ad",
29 | },
30 | {
31 | SoliditySHA3(
32 | Address(
33 | common.HexToAddress("0x12459c951127e0c374ff9105dda097662a027092"),
34 | ),
35 | ),
36 | "4b998b071d7bb74aee1ce2cdcc268cb0f6409b4a3387fc915617ec08415298ad",
37 | },
38 | {
39 | SoliditySHA3(Address([]string{"0x0a", "0x0b", "0x0c"})),
40 |
41 | "63f3beae5de2bbda3d06f2c0158ccedcdce66256efcf2f49930ca1c6976979df",
42 | },
43 | } {
44 | t.Run(fmt.Sprintf("%v", i), func(t *testing.T) {
45 | got := hex.EncodeToString(tt.in)
46 | if got != tt.out {
47 | t.Errorf("want %v, got %v", tt.out, got)
48 | }
49 | })
50 | }
51 | })
52 |
53 | t.Run("string", func(t *testing.T) {
54 | for i, tt := range []struct {
55 | in []byte
56 | out string
57 | }{
58 | {
59 | SoliditySHA3(
60 | String("somedata"),
61 | ),
62 | "fb763c3da6141a6a1464a68583e30d9a77bb999b1f1c491992dcfac7738ecfb4",
63 | },
64 | {
65 | SoliditySHA3(
66 | String([]string{"a", "b", "c"}),
67 | ),
68 | "4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45",
69 | },
70 | } {
71 | t.Run(fmt.Sprintf("%v", i), func(t *testing.T) {
72 | got := hex.EncodeToString(tt.in)
73 | if got != tt.out {
74 | t.Errorf("want %v, got %v", tt.out, got)
75 | }
76 | })
77 | }
78 | })
79 |
80 | t.Run("bool", func(t *testing.T) {
81 | for i, tt := range []struct {
82 | in []byte
83 | out string
84 | }{
85 | {
86 | SoliditySHA3(
87 | Bool(true),
88 | ),
89 | "5fe7f977e71dba2ea1a68e21057beebb9be2ac30c6410aa38d4f3fbe41dcffd2",
90 | },
91 | {
92 | SoliditySHA3(
93 | Bool(false),
94 | ),
95 | "bc36789e7a1e281436464229828f817d6612f7b477d66591ff96a9e064bcc98a",
96 | },
97 | {
98 | SoliditySHA3(
99 | Bool([3]bool{true, false, true}),
100 | ),
101 | "5c6090c0461491a2941743bda5c3658bf1ea53bbd3edcde54e16205e18b45792",
102 | },
103 | } {
104 | t.Run(fmt.Sprintf("%v", i), func(t *testing.T) {
105 | got := hex.EncodeToString(tt.in)
106 | if got != tt.out {
107 | t.Errorf("want %v, got %v", tt.out, got)
108 | }
109 | })
110 | }
111 | })
112 |
113 | t.Run("prefix", func(t *testing.T) {
114 | msg := []byte("hello")
115 | for i, tt := range []struct {
116 | in []byte
117 | out string
118 | }{
119 | {
120 | SoliditySHA3WithPrefix(msg),
121 | "50b2c43fd39106bafbba0da34fc430e1f91e3c96ea2acee2bc34119f92b37750",
122 | },
123 | {
124 | SoliditySHA3(
125 | ConcatByteSlices(
126 | []byte(fmt.Sprintf("\x19Ethereum Signed Message:\n%v", len(msg))),
127 | msg,
128 | ),
129 | ),
130 | "50b2c43fd39106bafbba0da34fc430e1f91e3c96ea2acee2bc34119f92b37750",
131 | },
132 | } {
133 | t.Run(fmt.Sprintf("%v", i), func(t *testing.T) {
134 | got := hex.EncodeToString(tt.in)
135 | if got != tt.out {
136 | t.Errorf("want %v, got %v", tt.out, got)
137 | }
138 | })
139 | }
140 | })
141 | }
142 |
143 | func TestSolSha3(t *testing.T) {
144 | {
145 | hash := SoliditySHA3(
146 | []string{"uint8[]"},
147 | [3]uint8{1, 2, 3},
148 | )
149 |
150 | fmt.Println(hex.EncodeToString(hash))
151 | //6e0c627900b24bd432fe7b1f713f1b0744091a646a9fe4a65a18dfed21f2949c
152 |
153 | hash2 := SoliditySHA3(
154 | Uint8([3]uint8{1, 2, 3}),
155 | )
156 |
157 | fmt.Println(hex.EncodeToString(hash2))
158 | }
159 |
160 | {
161 | hash := SoliditySHA3(
162 | []string{"address"},
163 | "0x0a",
164 | )
165 |
166 | fmt.Println(hex.EncodeToString(hash))
167 |
168 | hash2 := SoliditySHA3(
169 | Address("0x0a"),
170 | )
171 | fmt.Println(hex.EncodeToString(hash2))
172 | }
173 |
174 | {
175 | hash := SoliditySHA3(
176 | []string{"uint16"},
177 | uint16(8),
178 | )
179 |
180 | fmt.Println(hex.EncodeToString(hash))
181 |
182 | hash2 := SoliditySHA3(
183 | Uint16(8),
184 | )
185 |
186 | fmt.Println(hex.EncodeToString(hash2))
187 | }
188 |
189 | {
190 | hash := SoliditySHA3(
191 | []string{"bytes32"},
192 | "0x4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45",
193 | )
194 |
195 | fmt.Println(hex.EncodeToString(hash))
196 |
197 | hash2 := SoliditySHA3(
198 | Bytes32("0x4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45"),
199 | )
200 |
201 | fmt.Println(hex.EncodeToString(hash2))
202 | }
203 |
204 | {
205 | hash := SoliditySHA3(
206 | []string{"address", "bytes1", "uint8[]", "bytes32", "uint256", "address[]", "uint32"},
207 | "0x935F7770265D0797B621c49A5215849c333Cc3ce",
208 | "0xa",
209 | []uint8{128, 255},
210 | "0x4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45",
211 | "100000000000000000",
212 | []string{
213 | "0x13D94859b23AF5F610aEfC2Ae5254D4D7E3F191a",
214 | "0x473029549e9d898142a169d7234c59068EDcBB33",
215 | },
216 | 123456789,
217 | )
218 |
219 | expected := "ad390a98c1c32cdb1f046f6887a4109f12290b690127e6e15da4ca210235510e"
220 | result := hex.EncodeToString(hash)
221 | if result != expected {
222 | t.Error(result, expected)
223 | }
224 | }
225 |
226 | {
227 | hash := SoliditySHA3(
228 | []string{"address", "uint256"},
229 | "0x935F7770265D0797B621c49A5215849c333Cc3ce",
230 | "100000000000000000",
231 | )
232 |
233 | expected := "0a3844b522d9e3a837ae56d4c57d668feb26325834bf4ba49e153d84ed7ad53d"
234 | result := hex.EncodeToString(hash)
235 | if result != expected {
236 | t.Error(result, expected)
237 | }
238 | }
239 |
240 | {
241 | hash := SoliditySHA3(
242 | []string{"address", "uint256"},
243 | "0x935F7770265D0797B621c49A5215849c333Cc3ce",
244 | "100000000000000000",
245 | )
246 |
247 | expected := "0a3844b522d9e3a837ae56d4c57d668feb26325834bf4ba49e153d84ed7ad53d"
248 | result := hex.EncodeToString(hash)
249 | if result != expected {
250 | t.Error(result, expected)
251 | }
252 | }
253 |
254 | {
255 | types := []string{"address", "uint256"}
256 | inputs := []interface{}{
257 | "0x935F7770265D0797B621c49A5215849c333Cc3ce",
258 | "100000000000000000",
259 | }
260 |
261 | hash := SoliditySHA3(types, inputs)
262 |
263 | expected := "0a3844b522d9e3a837ae56d4c57d668feb26325834bf4ba49e153d84ed7ad53d"
264 | result := hex.EncodeToString(hash)
265 | if result != expected {
266 | t.Error(result, expected)
267 | }
268 | }
269 | }
270 |
--------------------------------------------------------------------------------
/vendor/github.com/ethereum/go-ethereum/common/hexutil/hexutil.go:
--------------------------------------------------------------------------------
1 | // Copyright 2016 The go-ethereum Authors
2 | // This file is part of the go-ethereum library.
3 | //
4 | // The go-ethereum library is free software: you can redistribute it and/or modify
5 | // it under the terms of the GNU Lesser General Public License as published by
6 | // the Free Software Foundation, either version 3 of the License, or
7 | // (at your option) any later version.
8 | //
9 | // The go-ethereum library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU Lesser General Public License for more details.
13 | //
14 | // You should have received a copy of the GNU Lesser General Public License
15 | // along with the go-ethereum library. If not, see .
16 |
17 | /*
18 | Package hexutil implements hex encoding with 0x prefix.
19 | This encoding is used by the Ethereum RPC API to transport binary data in JSON payloads.
20 |
21 | Encoding Rules
22 |
23 | All hex data must have prefix "0x".
24 |
25 | For byte slices, the hex data must be of even length. An empty byte slice
26 | encodes as "0x".
27 |
28 | Integers are encoded using the least amount of digits (no leading zero digits). Their
29 | encoding may be of uneven length. The number zero encodes as "0x0".
30 | */
31 | package hexutil
32 |
33 | import (
34 | "encoding/hex"
35 | "fmt"
36 | "math/big"
37 | "strconv"
38 | )
39 |
40 | const uintBits = 32 << (uint64(^uint(0)) >> 63)
41 |
42 | // Errors
43 | var (
44 | ErrEmptyString = &decError{"empty hex string"}
45 | ErrSyntax = &decError{"invalid hex string"}
46 | ErrMissingPrefix = &decError{"hex string without 0x prefix"}
47 | ErrOddLength = &decError{"hex string of odd length"}
48 | ErrEmptyNumber = &decError{"hex string \"0x\""}
49 | ErrLeadingZero = &decError{"hex number with leading zero digits"}
50 | ErrUint64Range = &decError{"hex number > 64 bits"}
51 | ErrUintRange = &decError{fmt.Sprintf("hex number > %d bits", uintBits)}
52 | ErrBig256Range = &decError{"hex number > 256 bits"}
53 | )
54 |
55 | type decError struct{ msg string }
56 |
57 | func (err decError) Error() string { return err.msg }
58 |
59 | // Decode decodes a hex string with 0x prefix.
60 | func Decode(input string) ([]byte, error) {
61 | if len(input) == 0 {
62 | return nil, ErrEmptyString
63 | }
64 | if !has0xPrefix(input) {
65 | return nil, ErrMissingPrefix
66 | }
67 | b, err := hex.DecodeString(input[2:])
68 | if err != nil {
69 | err = mapError(err)
70 | }
71 | return b, err
72 | }
73 |
74 | // MustDecode decodes a hex string with 0x prefix. It panics for invalid input.
75 | func MustDecode(input string) []byte {
76 | dec, err := Decode(input)
77 | if err != nil {
78 | panic(err)
79 | }
80 | return dec
81 | }
82 |
83 | // Encode encodes b as a hex string with 0x prefix.
84 | func Encode(b []byte) string {
85 | enc := make([]byte, len(b)*2+2)
86 | copy(enc, "0x")
87 | hex.Encode(enc[2:], b)
88 | return string(enc)
89 | }
90 |
91 | // DecodeUint64 decodes a hex string with 0x prefix as a quantity.
92 | func DecodeUint64(input string) (uint64, error) {
93 | raw, err := checkNumber(input)
94 | if err != nil {
95 | return 0, err
96 | }
97 | dec, err := strconv.ParseUint(raw, 16, 64)
98 | if err != nil {
99 | err = mapError(err)
100 | }
101 | return dec, err
102 | }
103 |
104 | // MustDecodeUint64 decodes a hex string with 0x prefix as a quantity.
105 | // It panics for invalid input.
106 | func MustDecodeUint64(input string) uint64 {
107 | dec, err := DecodeUint64(input)
108 | if err != nil {
109 | panic(err)
110 | }
111 | return dec
112 | }
113 |
114 | // EncodeUint64 encodes i as a hex string with 0x prefix.
115 | func EncodeUint64(i uint64) string {
116 | enc := make([]byte, 2, 10)
117 | copy(enc, "0x")
118 | return string(strconv.AppendUint(enc, i, 16))
119 | }
120 |
121 | var bigWordNibbles int
122 |
123 | func init() {
124 | // This is a weird way to compute the number of nibbles required for big.Word.
125 | // The usual way would be to use constant arithmetic but go vet can't handle that.
126 | b, _ := new(big.Int).SetString("FFFFFFFFFF", 16)
127 | switch len(b.Bits()) {
128 | case 1:
129 | bigWordNibbles = 16
130 | case 2:
131 | bigWordNibbles = 8
132 | default:
133 | panic("weird big.Word size")
134 | }
135 | }
136 |
137 | // DecodeBig decodes a hex string with 0x prefix as a quantity.
138 | // Numbers larger than 256 bits are not accepted.
139 | func DecodeBig(input string) (*big.Int, error) {
140 | raw, err := checkNumber(input)
141 | if err != nil {
142 | return nil, err
143 | }
144 | if len(raw) > 64 {
145 | return nil, ErrBig256Range
146 | }
147 | words := make([]big.Word, len(raw)/bigWordNibbles+1)
148 | end := len(raw)
149 | for i := range words {
150 | start := end - bigWordNibbles
151 | if start < 0 {
152 | start = 0
153 | }
154 | for ri := start; ri < end; ri++ {
155 | nib := decodeNibble(raw[ri])
156 | if nib == badNibble {
157 | return nil, ErrSyntax
158 | }
159 | words[i] *= 16
160 | words[i] += big.Word(nib)
161 | }
162 | end = start
163 | }
164 | dec := new(big.Int).SetBits(words)
165 | return dec, nil
166 | }
167 |
168 | // MustDecodeBig decodes a hex string with 0x prefix as a quantity.
169 | // It panics for invalid input.
170 | func MustDecodeBig(input string) *big.Int {
171 | dec, err := DecodeBig(input)
172 | if err != nil {
173 | panic(err)
174 | }
175 | return dec
176 | }
177 |
178 | // EncodeBig encodes bigint as a hex string with 0x prefix.
179 | // The sign of the integer is ignored.
180 | func EncodeBig(bigint *big.Int) string {
181 | nbits := bigint.BitLen()
182 | if nbits == 0 {
183 | return "0x0"
184 | }
185 | return fmt.Sprintf("%#x", bigint)
186 | }
187 |
188 | func has0xPrefix(input string) bool {
189 | return len(input) >= 2 && input[0] == '0' && (input[1] == 'x' || input[1] == 'X')
190 | }
191 |
192 | func checkNumber(input string) (raw string, err error) {
193 | if len(input) == 0 {
194 | return "", ErrEmptyString
195 | }
196 | if !has0xPrefix(input) {
197 | return "", ErrMissingPrefix
198 | }
199 | input = input[2:]
200 | if len(input) == 0 {
201 | return "", ErrEmptyNumber
202 | }
203 | if len(input) > 1 && input[0] == '0' {
204 | return "", ErrLeadingZero
205 | }
206 | return input, nil
207 | }
208 |
209 | const badNibble = ^uint64(0)
210 |
211 | func decodeNibble(in byte) uint64 {
212 | switch {
213 | case in >= '0' && in <= '9':
214 | return uint64(in - '0')
215 | case in >= 'A' && in <= 'F':
216 | return uint64(in - 'A' + 10)
217 | case in >= 'a' && in <= 'f':
218 | return uint64(in - 'a' + 10)
219 | default:
220 | return badNibble
221 | }
222 | }
223 |
224 | func mapError(err error) error {
225 | if err, ok := err.(*strconv.NumError); ok {
226 | switch err.Err {
227 | case strconv.ErrRange:
228 | return ErrUint64Range
229 | case strconv.ErrSyntax:
230 | return ErrSyntax
231 | }
232 | }
233 | if _, ok := err.(hex.InvalidByteError); ok {
234 | return ErrSyntax
235 | }
236 | if err == hex.ErrLength {
237 | return ErrOddLength
238 | }
239 | return err
240 | }
241 |
--------------------------------------------------------------------------------
/vendor/github.com/ethereum/go-ethereum/common/math/big.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 The go-ethereum Authors
2 | // This file is part of the go-ethereum library.
3 | //
4 | // The go-ethereum library is free software: you can redistribute it and/or modify
5 | // it under the terms of the GNU Lesser General Public License as published by
6 | // the Free Software Foundation, either version 3 of the License, or
7 | // (at your option) any later version.
8 | //
9 | // The go-ethereum library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU Lesser General Public License for more details.
13 | //
14 | // You should have received a copy of the GNU Lesser General Public License
15 | // along with the go-ethereum library. If not, see .
16 |
17 | // Package math provides integer math utilities.
18 | package math
19 |
20 | import (
21 | "fmt"
22 | "math/big"
23 | )
24 |
25 | // Various big integer limit values.
26 | var (
27 | tt255 = BigPow(2, 255)
28 | tt256 = BigPow(2, 256)
29 | tt256m1 = new(big.Int).Sub(tt256, big.NewInt(1))
30 | tt63 = BigPow(2, 63)
31 | MaxBig256 = new(big.Int).Set(tt256m1)
32 | MaxBig63 = new(big.Int).Sub(tt63, big.NewInt(1))
33 | )
34 |
35 | const (
36 | // number of bits in a big.Word
37 | wordBits = 32 << (uint64(^big.Word(0)) >> 63)
38 | // number of bytes in a big.Word
39 | wordBytes = wordBits / 8
40 | )
41 |
42 | // HexOrDecimal256 marshals big.Int as hex or decimal.
43 | type HexOrDecimal256 big.Int
44 |
45 | // NewHexOrDecimal256 creates a new HexOrDecimal256
46 | func NewHexOrDecimal256(x int64) *HexOrDecimal256 {
47 | b := big.NewInt(x)
48 | h := HexOrDecimal256(*b)
49 | return &h
50 | }
51 |
52 | // UnmarshalText implements encoding.TextUnmarshaler.
53 | func (i *HexOrDecimal256) UnmarshalText(input []byte) error {
54 | bigint, ok := ParseBig256(string(input))
55 | if !ok {
56 | return fmt.Errorf("invalid hex or decimal integer %q", input)
57 | }
58 | *i = HexOrDecimal256(*bigint)
59 | return nil
60 | }
61 |
62 | // MarshalText implements encoding.TextMarshaler.
63 | func (i *HexOrDecimal256) MarshalText() ([]byte, error) {
64 | if i == nil {
65 | return []byte("0x0"), nil
66 | }
67 | return []byte(fmt.Sprintf("%#x", (*big.Int)(i))), nil
68 | }
69 |
70 | // Decimal256 unmarshals big.Int as a decimal string. When unmarshalling,
71 | // it however accepts either "0x"-prefixed (hex encoded) or non-prefixed (decimal)
72 | type Decimal256 big.Int
73 |
74 | // NewHexOrDecimal256 creates a new Decimal256
75 | func NewDecimal256(x int64) *Decimal256 {
76 | b := big.NewInt(x)
77 | d := Decimal256(*b)
78 | return &d
79 | }
80 |
81 | // UnmarshalText implements encoding.TextUnmarshaler.
82 | func (i *Decimal256) UnmarshalText(input []byte) error {
83 | bigint, ok := ParseBig256(string(input))
84 | if !ok {
85 | return fmt.Errorf("invalid hex or decimal integer %q", input)
86 | }
87 | *i = Decimal256(*bigint)
88 | return nil
89 | }
90 |
91 | // MarshalText implements encoding.TextMarshaler.
92 | func (i *Decimal256) MarshalText() ([]byte, error) {
93 | return []byte(i.String()), nil
94 | }
95 |
96 | // String implements Stringer.
97 | func (i *Decimal256) String() string {
98 | if i == nil {
99 | return "0"
100 | }
101 | return fmt.Sprintf("%#d", (*big.Int)(i))
102 | }
103 |
104 | // ParseBig256 parses s as a 256 bit integer in decimal or hexadecimal syntax.
105 | // Leading zeros are accepted. The empty string parses as zero.
106 | func ParseBig256(s string) (*big.Int, bool) {
107 | if s == "" {
108 | return new(big.Int), true
109 | }
110 | var bigint *big.Int
111 | var ok bool
112 | if len(s) >= 2 && (s[:2] == "0x" || s[:2] == "0X") {
113 | bigint, ok = new(big.Int).SetString(s[2:], 16)
114 | } else {
115 | bigint, ok = new(big.Int).SetString(s, 10)
116 | }
117 | if ok && bigint.BitLen() > 256 {
118 | bigint, ok = nil, false
119 | }
120 | return bigint, ok
121 | }
122 |
123 | // MustParseBig256 parses s as a 256 bit big integer and panics if the string is invalid.
124 | func MustParseBig256(s string) *big.Int {
125 | v, ok := ParseBig256(s)
126 | if !ok {
127 | panic("invalid 256 bit integer: " + s)
128 | }
129 | return v
130 | }
131 |
132 | // BigPow returns a ** b as a big integer.
133 | func BigPow(a, b int64) *big.Int {
134 | r := big.NewInt(a)
135 | return r.Exp(r, big.NewInt(b), nil)
136 | }
137 |
138 | // BigMax returns the larger of x or y.
139 | func BigMax(x, y *big.Int) *big.Int {
140 | if x.Cmp(y) < 0 {
141 | return y
142 | }
143 | return x
144 | }
145 |
146 | // BigMin returns the smaller of x or y.
147 | func BigMin(x, y *big.Int) *big.Int {
148 | if x.Cmp(y) > 0 {
149 | return y
150 | }
151 | return x
152 | }
153 |
154 | // FirstBitSet returns the index of the first 1 bit in v, counting from LSB.
155 | func FirstBitSet(v *big.Int) int {
156 | for i := 0; i < v.BitLen(); i++ {
157 | if v.Bit(i) > 0 {
158 | return i
159 | }
160 | }
161 | return v.BitLen()
162 | }
163 |
164 | // PaddedBigBytes encodes a big integer as a big-endian byte slice. The length
165 | // of the slice is at least n bytes.
166 | func PaddedBigBytes(bigint *big.Int, n int) []byte {
167 | if bigint.BitLen()/8 >= n {
168 | return bigint.Bytes()
169 | }
170 | ret := make([]byte, n)
171 | ReadBits(bigint, ret)
172 | return ret
173 | }
174 |
175 | // bigEndianByteAt returns the byte at position n,
176 | // in Big-Endian encoding
177 | // So n==0 returns the least significant byte
178 | func bigEndianByteAt(bigint *big.Int, n int) byte {
179 | words := bigint.Bits()
180 | // Check word-bucket the byte will reside in
181 | i := n / wordBytes
182 | if i >= len(words) {
183 | return byte(0)
184 | }
185 | word := words[i]
186 | // Offset of the byte
187 | shift := 8 * uint(n%wordBytes)
188 |
189 | return byte(word >> shift)
190 | }
191 |
192 | // Byte returns the byte at position n,
193 | // with the supplied padlength in Little-Endian encoding.
194 | // n==0 returns the MSB
195 | // Example: bigint '5', padlength 32, n=31 => 5
196 | func Byte(bigint *big.Int, padlength, n int) byte {
197 | if n >= padlength {
198 | return byte(0)
199 | }
200 | return bigEndianByteAt(bigint, padlength-1-n)
201 | }
202 |
203 | // ReadBits encodes the absolute value of bigint as big-endian bytes. Callers must ensure
204 | // that buf has enough space. If buf is too short the result will be incomplete.
205 | func ReadBits(bigint *big.Int, buf []byte) {
206 | i := len(buf)
207 | for _, d := range bigint.Bits() {
208 | for j := 0; j < wordBytes && i > 0; j++ {
209 | i--
210 | buf[i] = byte(d)
211 | d >>= 8
212 | }
213 | }
214 | }
215 |
216 | // U256 encodes as a 256 bit two's complement number. This operation is destructive.
217 | func U256(x *big.Int) *big.Int {
218 | return x.And(x, tt256m1)
219 | }
220 |
221 | // U256Bytes converts a big Int into a 256bit EVM number.
222 | // This operation is destructive.
223 | func U256Bytes(n *big.Int) []byte {
224 | return PaddedBigBytes(U256(n), 32)
225 | }
226 |
227 | // S256 interprets x as a two's complement number.
228 | // x must not exceed 256 bits (the result is undefined if it does) and is not modified.
229 | //
230 | // S256(0) = 0
231 | // S256(1) = 1
232 | // S256(2**255) = -2**255
233 | // S256(2**256-1) = -1
234 | func S256(x *big.Int) *big.Int {
235 | if x.Cmp(tt255) < 0 {
236 | return x
237 | }
238 | return new(big.Int).Sub(x, tt256)
239 | }
240 |
241 | // Exp implements exponentiation by squaring.
242 | // Exp returns a newly-allocated big integer and does not change
243 | // base or exponent. The result is truncated to 256 bits.
244 | //
245 | // Courtesy @karalabe and @chfast
246 | func Exp(base, exponent *big.Int) *big.Int {
247 | result := big.NewInt(1)
248 |
249 | for _, word := range exponent.Bits() {
250 | for i := 0; i < wordBits; i++ {
251 | if word&1 == 1 {
252 | U256(result.Mul(result, base))
253 | }
254 | U256(base.Mul(base, base))
255 | word >>= 1
256 | }
257 | }
258 | return result
259 | }
260 |
--------------------------------------------------------------------------------
/vendor/github.com/ethereum/go-ethereum/COPYING.LESSER:
--------------------------------------------------------------------------------
1 | GNU LESSER GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 |
9 | This version of the GNU Lesser General Public License incorporates
10 | the terms and conditions of version 3 of the GNU General Public
11 | License, supplemented by the additional permissions listed below.
12 |
13 | 0. Additional Definitions.
14 |
15 | As used herein, "this License" refers to version 3 of the GNU Lesser
16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU
17 | General Public License.
18 |
19 | "The Library" refers to a covered work governed by this License,
20 | other than an Application or a Combined Work as defined below.
21 |
22 | An "Application" is any work that makes use of an interface provided
23 | by the Library, but which is not otherwise based on the Library.
24 | Defining a subclass of a class defined by the Library is deemed a mode
25 | of using an interface provided by the Library.
26 |
27 | A "Combined Work" is a work produced by combining or linking an
28 | Application with the Library. The particular version of the Library
29 | with which the Combined Work was made is also called the "Linked
30 | Version".
31 |
32 | The "Minimal Corresponding Source" for a Combined Work means the
33 | Corresponding Source for the Combined Work, excluding any source code
34 | for portions of the Combined Work that, considered in isolation, are
35 | based on the Application, and not on the Linked Version.
36 |
37 | The "Corresponding Application Code" for a Combined Work means the
38 | object code and/or source code for the Application, including any data
39 | and utility programs needed for reproducing the Combined Work from the
40 | Application, but excluding the System Libraries of the Combined Work.
41 |
42 | 1. Exception to Section 3 of the GNU GPL.
43 |
44 | You may convey a covered work under sections 3 and 4 of this License
45 | without being bound by section 3 of the GNU GPL.
46 |
47 | 2. Conveying Modified Versions.
48 |
49 | If you modify a copy of the Library, and, in your modifications, a
50 | facility refers to a function or data to be supplied by an Application
51 | that uses the facility (other than as an argument passed when the
52 | facility is invoked), then you may convey a copy of the modified
53 | version:
54 |
55 | a) under this License, provided that you make a good faith effort to
56 | ensure that, in the event an Application does not supply the
57 | function or data, the facility still operates, and performs
58 | whatever part of its purpose remains meaningful, or
59 |
60 | b) under the GNU GPL, with none of the additional permissions of
61 | this License applicable to that copy.
62 |
63 | 3. Object Code Incorporating Material from Library Header Files.
64 |
65 | The object code form of an Application may incorporate material from
66 | a header file that is part of the Library. You may convey such object
67 | code under terms of your choice, provided that, if the incorporated
68 | material is not limited to numerical parameters, data structure
69 | layouts and accessors, or small macros, inline functions and templates
70 | (ten or fewer lines in length), you do both of the following:
71 |
72 | a) Give prominent notice with each copy of the object code that the
73 | Library is used in it and that the Library and its use are
74 | covered by this License.
75 |
76 | b) Accompany the object code with a copy of the GNU GPL and this license
77 | document.
78 |
79 | 4. Combined Works.
80 |
81 | You may convey a Combined Work under terms of your choice that,
82 | taken together, effectively do not restrict modification of the
83 | portions of the Library contained in the Combined Work and reverse
84 | engineering for debugging such modifications, if you also do each of
85 | the following:
86 |
87 | a) Give prominent notice with each copy of the Combined Work that
88 | the Library is used in it and that the Library and its use are
89 | covered by this License.
90 |
91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license
92 | document.
93 |
94 | c) For a Combined Work that displays copyright notices during
95 | execution, include the copyright notice for the Library among
96 | these notices, as well as a reference directing the user to the
97 | copies of the GNU GPL and this license document.
98 |
99 | d) Do one of the following:
100 |
101 | 0) Convey the Minimal Corresponding Source under the terms of this
102 | License, and the Corresponding Application Code in a form
103 | suitable for, and under terms that permit, the user to
104 | recombine or relink the Application with a modified version of
105 | the Linked Version to produce a modified Combined Work, in the
106 | manner specified by section 6 of the GNU GPL for conveying
107 | Corresponding Source.
108 |
109 | 1) Use a suitable shared library mechanism for linking with the
110 | Library. A suitable mechanism is one that (a) uses at run time
111 | a copy of the Library already present on the user's computer
112 | system, and (b) will operate properly with a modified version
113 | of the Library that is interface-compatible with the Linked
114 | Version.
115 |
116 | e) Provide Installation Information, but only if you would otherwise
117 | be required to provide such information under section 6 of the
118 | GNU GPL, and only to the extent that such information is
119 | necessary to install and execute a modified version of the
120 | Combined Work produced by recombining or relinking the
121 | Application with a modified version of the Linked Version. (If
122 | you use option 4d0, the Installation Information must accompany
123 | the Minimal Corresponding Source and Corresponding Application
124 | Code. If you use option 4d1, you must provide the Installation
125 | Information in the manner specified by section 6 of the GNU GPL
126 | for conveying Corresponding Source.)
127 |
128 | 5. Combined Libraries.
129 |
130 | You may place library facilities that are a work based on the
131 | Library side by side in a single library together with other library
132 | facilities that are not Applications and are not covered by this
133 | License, and convey such a combined library under terms of your
134 | choice, if you do both of the following:
135 |
136 | a) Accompany the combined library with a copy of the same work based
137 | on the Library, uncombined with any other library facilities,
138 | conveyed under the terms of this License.
139 |
140 | b) Give prominent notice with the combined library that part of it
141 | is a work based on the Library, and explaining where to find the
142 | accompanying uncombined form of the same work.
143 |
144 | 6. Revised Versions of the GNU Lesser General Public License.
145 |
146 | The Free Software Foundation may publish revised and/or new versions
147 | of the GNU Lesser General Public License from time to time. Such new
148 | versions will be similar in spirit to the present version, but may
149 | differ in detail to address new problems or concerns.
150 |
151 | Each version is given a distinguishing version number. If the
152 | Library as you received it specifies that a certain numbered version
153 | of the GNU Lesser General Public License "or any later version"
154 | applies to it, you have the option of following the terms and
155 | conditions either of that published version or of any later version
156 | published by the Free Software Foundation. If the Library as you
157 | received it does not specify a version number of the GNU Lesser
158 | General Public License, you may choose any version of the GNU Lesser
159 | General Public License ever published by the Free Software Foundation.
160 |
161 | If the Library as you received it specifies that a proxy can decide
162 | whether future versions of the GNU Lesser General Public License shall
163 | apply, that proxy's public statement of acceptance of any version is
164 | permanent authorization for you to choose that version for the
165 | Library.
166 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/crypto/sha3/sha3_s390x.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | //go:build gc && !purego
6 | // +build gc,!purego
7 |
8 | package sha3
9 |
10 | // This file contains code for using the 'compute intermediate
11 | // message digest' (KIMD) and 'compute last message digest' (KLMD)
12 | // instructions to compute SHA-3 and SHAKE hashes on IBM Z.
13 |
14 | import (
15 | "hash"
16 |
17 | "golang.org/x/sys/cpu"
18 | )
19 |
20 | // codes represent 7-bit KIMD/KLMD function codes as defined in
21 | // the Principles of Operation.
22 | type code uint64
23 |
24 | const (
25 | // function codes for KIMD/KLMD
26 | sha3_224 code = 32
27 | sha3_256 = 33
28 | sha3_384 = 34
29 | sha3_512 = 35
30 | shake_128 = 36
31 | shake_256 = 37
32 | nopad = 0x100
33 | )
34 |
35 | // kimd is a wrapper for the 'compute intermediate message digest' instruction.
36 | // src must be a multiple of the rate for the given function code.
37 | //go:noescape
38 | func kimd(function code, chain *[200]byte, src []byte)
39 |
40 | // klmd is a wrapper for the 'compute last message digest' instruction.
41 | // src padding is handled by the instruction.
42 | //go:noescape
43 | func klmd(function code, chain *[200]byte, dst, src []byte)
44 |
45 | type asmState struct {
46 | a [200]byte // 1600 bit state
47 | buf []byte // care must be taken to ensure cap(buf) is a multiple of rate
48 | rate int // equivalent to block size
49 | storage [3072]byte // underlying storage for buf
50 | outputLen int // output length if fixed, 0 if not
51 | function code // KIMD/KLMD function code
52 | state spongeDirection // whether the sponge is absorbing or squeezing
53 | }
54 |
55 | func newAsmState(function code) *asmState {
56 | var s asmState
57 | s.function = function
58 | switch function {
59 | case sha3_224:
60 | s.rate = 144
61 | s.outputLen = 28
62 | case sha3_256:
63 | s.rate = 136
64 | s.outputLen = 32
65 | case sha3_384:
66 | s.rate = 104
67 | s.outputLen = 48
68 | case sha3_512:
69 | s.rate = 72
70 | s.outputLen = 64
71 | case shake_128:
72 | s.rate = 168
73 | case shake_256:
74 | s.rate = 136
75 | default:
76 | panic("sha3: unrecognized function code")
77 | }
78 |
79 | // limit s.buf size to a multiple of s.rate
80 | s.resetBuf()
81 | return &s
82 | }
83 |
84 | func (s *asmState) clone() *asmState {
85 | c := *s
86 | c.buf = c.storage[:len(s.buf):cap(s.buf)]
87 | return &c
88 | }
89 |
90 | // copyIntoBuf copies b into buf. It will panic if there is not enough space to
91 | // store all of b.
92 | func (s *asmState) copyIntoBuf(b []byte) {
93 | bufLen := len(s.buf)
94 | s.buf = s.buf[:len(s.buf)+len(b)]
95 | copy(s.buf[bufLen:], b)
96 | }
97 |
98 | // resetBuf points buf at storage, sets the length to 0 and sets cap to be a
99 | // multiple of the rate.
100 | func (s *asmState) resetBuf() {
101 | max := (cap(s.storage) / s.rate) * s.rate
102 | s.buf = s.storage[:0:max]
103 | }
104 |
105 | // Write (via the embedded io.Writer interface) adds more data to the running hash.
106 | // It never returns an error.
107 | func (s *asmState) Write(b []byte) (int, error) {
108 | if s.state != spongeAbsorbing {
109 | panic("sha3: write to sponge after read")
110 | }
111 | length := len(b)
112 | for len(b) > 0 {
113 | if len(s.buf) == 0 && len(b) >= cap(s.buf) {
114 | // Hash the data directly and push any remaining bytes
115 | // into the buffer.
116 | remainder := len(b) % s.rate
117 | kimd(s.function, &s.a, b[:len(b)-remainder])
118 | if remainder != 0 {
119 | s.copyIntoBuf(b[len(b)-remainder:])
120 | }
121 | return length, nil
122 | }
123 |
124 | if len(s.buf) == cap(s.buf) {
125 | // flush the buffer
126 | kimd(s.function, &s.a, s.buf)
127 | s.buf = s.buf[:0]
128 | }
129 |
130 | // copy as much as we can into the buffer
131 | n := len(b)
132 | if len(b) > cap(s.buf)-len(s.buf) {
133 | n = cap(s.buf) - len(s.buf)
134 | }
135 | s.copyIntoBuf(b[:n])
136 | b = b[n:]
137 | }
138 | return length, nil
139 | }
140 |
141 | // Read squeezes an arbitrary number of bytes from the sponge.
142 | func (s *asmState) Read(out []byte) (n int, err error) {
143 | n = len(out)
144 |
145 | // need to pad if we were absorbing
146 | if s.state == spongeAbsorbing {
147 | s.state = spongeSqueezing
148 |
149 | // write hash directly into out if possible
150 | if len(out)%s.rate == 0 {
151 | klmd(s.function, &s.a, out, s.buf) // len(out) may be 0
152 | s.buf = s.buf[:0]
153 | return
154 | }
155 |
156 | // write hash into buffer
157 | max := cap(s.buf)
158 | if max > len(out) {
159 | max = (len(out)/s.rate)*s.rate + s.rate
160 | }
161 | klmd(s.function, &s.a, s.buf[:max], s.buf)
162 | s.buf = s.buf[:max]
163 | }
164 |
165 | for len(out) > 0 {
166 | // flush the buffer
167 | if len(s.buf) != 0 {
168 | c := copy(out, s.buf)
169 | out = out[c:]
170 | s.buf = s.buf[c:]
171 | continue
172 | }
173 |
174 | // write hash directly into out if possible
175 | if len(out)%s.rate == 0 {
176 | klmd(s.function|nopad, &s.a, out, nil)
177 | return
178 | }
179 |
180 | // write hash into buffer
181 | s.resetBuf()
182 | if cap(s.buf) > len(out) {
183 | s.buf = s.buf[:(len(out)/s.rate)*s.rate+s.rate]
184 | }
185 | klmd(s.function|nopad, &s.a, s.buf, nil)
186 | }
187 | return
188 | }
189 |
190 | // Sum appends the current hash to b and returns the resulting slice.
191 | // It does not change the underlying hash state.
192 | func (s *asmState) Sum(b []byte) []byte {
193 | if s.outputLen == 0 {
194 | panic("sha3: cannot call Sum on SHAKE functions")
195 | }
196 |
197 | // Copy the state to preserve the original.
198 | a := s.a
199 |
200 | // Hash the buffer. Note that we don't clear it because we
201 | // aren't updating the state.
202 | klmd(s.function, &a, nil, s.buf)
203 | return append(b, a[:s.outputLen]...)
204 | }
205 |
206 | // Reset resets the Hash to its initial state.
207 | func (s *asmState) Reset() {
208 | for i := range s.a {
209 | s.a[i] = 0
210 | }
211 | s.resetBuf()
212 | s.state = spongeAbsorbing
213 | }
214 |
215 | // Size returns the number of bytes Sum will return.
216 | func (s *asmState) Size() int {
217 | return s.outputLen
218 | }
219 |
220 | // BlockSize returns the hash's underlying block size.
221 | // The Write method must be able to accept any amount
222 | // of data, but it may operate more efficiently if all writes
223 | // are a multiple of the block size.
224 | func (s *asmState) BlockSize() int {
225 | return s.rate
226 | }
227 |
228 | // Clone returns a copy of the ShakeHash in its current state.
229 | func (s *asmState) Clone() ShakeHash {
230 | return s.clone()
231 | }
232 |
233 | // new224Asm returns an assembly implementation of SHA3-224 if available,
234 | // otherwise it returns nil.
235 | func new224Asm() hash.Hash {
236 | if cpu.S390X.HasSHA3 {
237 | return newAsmState(sha3_224)
238 | }
239 | return nil
240 | }
241 |
242 | // new256Asm returns an assembly implementation of SHA3-256 if available,
243 | // otherwise it returns nil.
244 | func new256Asm() hash.Hash {
245 | if cpu.S390X.HasSHA3 {
246 | return newAsmState(sha3_256)
247 | }
248 | return nil
249 | }
250 |
251 | // new384Asm returns an assembly implementation of SHA3-384 if available,
252 | // otherwise it returns nil.
253 | func new384Asm() hash.Hash {
254 | if cpu.S390X.HasSHA3 {
255 | return newAsmState(sha3_384)
256 | }
257 | return nil
258 | }
259 |
260 | // new512Asm returns an assembly implementation of SHA3-512 if available,
261 | // otherwise it returns nil.
262 | func new512Asm() hash.Hash {
263 | if cpu.S390X.HasSHA3 {
264 | return newAsmState(sha3_512)
265 | }
266 | return nil
267 | }
268 |
269 | // newShake128Asm returns an assembly implementation of SHAKE-128 if available,
270 | // otherwise it returns nil.
271 | func newShake128Asm() ShakeHash {
272 | if cpu.S390X.HasSHA3 {
273 | return newAsmState(shake_128)
274 | }
275 | return nil
276 | }
277 |
278 | // newShake256Asm returns an assembly implementation of SHAKE-256 if available,
279 | // otherwise it returns nil.
280 | func newShake256Asm() ShakeHash {
281 | if cpu.S390X.HasSHA3 {
282 | return newAsmState(shake_256)
283 | }
284 | return nil
285 | }
286 |
--------------------------------------------------------------------------------
/vendor/github.com/ethereum/go-ethereum/common/hexutil/json.go:
--------------------------------------------------------------------------------
1 | // Copyright 2016 The go-ethereum Authors
2 | // This file is part of the go-ethereum library.
3 | //
4 | // The go-ethereum library is free software: you can redistribute it and/or modify
5 | // it under the terms of the GNU Lesser General Public License as published by
6 | // the Free Software Foundation, either version 3 of the License, or
7 | // (at your option) any later version.
8 | //
9 | // The go-ethereum library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU Lesser General Public License for more details.
13 | //
14 | // You should have received a copy of the GNU Lesser General Public License
15 | // along with the go-ethereum library. If not, see .
16 |
17 | package hexutil
18 |
19 | import (
20 | "encoding/hex"
21 | "encoding/json"
22 | "fmt"
23 | "math/big"
24 | "reflect"
25 | "strconv"
26 | )
27 |
28 | var (
29 | bytesT = reflect.TypeOf(Bytes(nil))
30 | bigT = reflect.TypeOf((*Big)(nil))
31 | uintT = reflect.TypeOf(Uint(0))
32 | uint64T = reflect.TypeOf(Uint64(0))
33 | )
34 |
35 | // Bytes marshals/unmarshals as a JSON string with 0x prefix.
36 | // The empty slice marshals as "0x".
37 | type Bytes []byte
38 |
39 | // MarshalText implements encoding.TextMarshaler
40 | func (b Bytes) MarshalText() ([]byte, error) {
41 | result := make([]byte, len(b)*2+2)
42 | copy(result, `0x`)
43 | hex.Encode(result[2:], b)
44 | return result, nil
45 | }
46 |
47 | // UnmarshalJSON implements json.Unmarshaler.
48 | func (b *Bytes) UnmarshalJSON(input []byte) error {
49 | if !isString(input) {
50 | return errNonString(bytesT)
51 | }
52 | return wrapTypeError(b.UnmarshalText(input[1:len(input)-1]), bytesT)
53 | }
54 |
55 | // UnmarshalText implements encoding.TextUnmarshaler.
56 | func (b *Bytes) UnmarshalText(input []byte) error {
57 | raw, err := checkText(input, true)
58 | if err != nil {
59 | return err
60 | }
61 | dec := make([]byte, len(raw)/2)
62 | if _, err = hex.Decode(dec, raw); err != nil {
63 | err = mapError(err)
64 | } else {
65 | *b = dec
66 | }
67 | return err
68 | }
69 |
70 | // String returns the hex encoding of b.
71 | func (b Bytes) String() string {
72 | return Encode(b)
73 | }
74 |
75 | // ImplementsGraphQLType returns true if Bytes implements the specified GraphQL type.
76 | func (b Bytes) ImplementsGraphQLType(name string) bool { return name == "Bytes" }
77 |
78 | // UnmarshalGraphQL unmarshals the provided GraphQL query data.
79 | func (b *Bytes) UnmarshalGraphQL(input interface{}) error {
80 | var err error
81 | switch input := input.(type) {
82 | case string:
83 | data, err := Decode(input)
84 | if err != nil {
85 | return err
86 | }
87 | *b = data
88 | default:
89 | err = fmt.Errorf("unexpected type %T for Bytes", input)
90 | }
91 | return err
92 | }
93 |
94 | // UnmarshalFixedJSON decodes the input as a string with 0x prefix. The length of out
95 | // determines the required input length. This function is commonly used to implement the
96 | // UnmarshalJSON method for fixed-size types.
97 | func UnmarshalFixedJSON(typ reflect.Type, input, out []byte) error {
98 | if !isString(input) {
99 | return errNonString(typ)
100 | }
101 | return wrapTypeError(UnmarshalFixedText(typ.String(), input[1:len(input)-1], out), typ)
102 | }
103 |
104 | // UnmarshalFixedText decodes the input as a string with 0x prefix. The length of out
105 | // determines the required input length. This function is commonly used to implement the
106 | // UnmarshalText method for fixed-size types.
107 | func UnmarshalFixedText(typname string, input, out []byte) error {
108 | raw, err := checkText(input, true)
109 | if err != nil {
110 | return err
111 | }
112 | if len(raw)/2 != len(out) {
113 | return fmt.Errorf("hex string has length %d, want %d for %s", len(raw), len(out)*2, typname)
114 | }
115 | // Pre-verify syntax before modifying out.
116 | for _, b := range raw {
117 | if decodeNibble(b) == badNibble {
118 | return ErrSyntax
119 | }
120 | }
121 | hex.Decode(out, raw)
122 | return nil
123 | }
124 |
125 | // UnmarshalFixedUnprefixedText decodes the input as a string with optional 0x prefix. The
126 | // length of out determines the required input length. This function is commonly used to
127 | // implement the UnmarshalText method for fixed-size types.
128 | func UnmarshalFixedUnprefixedText(typname string, input, out []byte) error {
129 | raw, err := checkText(input, false)
130 | if err != nil {
131 | return err
132 | }
133 | if len(raw)/2 != len(out) {
134 | return fmt.Errorf("hex string has length %d, want %d for %s", len(raw), len(out)*2, typname)
135 | }
136 | // Pre-verify syntax before modifying out.
137 | for _, b := range raw {
138 | if decodeNibble(b) == badNibble {
139 | return ErrSyntax
140 | }
141 | }
142 | hex.Decode(out, raw)
143 | return nil
144 | }
145 |
146 | // Big marshals/unmarshals as a JSON string with 0x prefix.
147 | // The zero value marshals as "0x0".
148 | //
149 | // Negative integers are not supported at this time. Attempting to marshal them will
150 | // return an error. Values larger than 256bits are rejected by Unmarshal but will be
151 | // marshaled without error.
152 | type Big big.Int
153 |
154 | // MarshalText implements encoding.TextMarshaler
155 | func (b Big) MarshalText() ([]byte, error) {
156 | return []byte(EncodeBig((*big.Int)(&b))), nil
157 | }
158 |
159 | // UnmarshalJSON implements json.Unmarshaler.
160 | func (b *Big) UnmarshalJSON(input []byte) error {
161 | if !isString(input) {
162 | return errNonString(bigT)
163 | }
164 | return wrapTypeError(b.UnmarshalText(input[1:len(input)-1]), bigT)
165 | }
166 |
167 | // UnmarshalText implements encoding.TextUnmarshaler
168 | func (b *Big) UnmarshalText(input []byte) error {
169 | raw, err := checkNumberText(input)
170 | if err != nil {
171 | return err
172 | }
173 | if len(raw) > 64 {
174 | return ErrBig256Range
175 | }
176 | words := make([]big.Word, len(raw)/bigWordNibbles+1)
177 | end := len(raw)
178 | for i := range words {
179 | start := end - bigWordNibbles
180 | if start < 0 {
181 | start = 0
182 | }
183 | for ri := start; ri < end; ri++ {
184 | nib := decodeNibble(raw[ri])
185 | if nib == badNibble {
186 | return ErrSyntax
187 | }
188 | words[i] *= 16
189 | words[i] += big.Word(nib)
190 | }
191 | end = start
192 | }
193 | var dec big.Int
194 | dec.SetBits(words)
195 | *b = (Big)(dec)
196 | return nil
197 | }
198 |
199 | // ToInt converts b to a big.Int.
200 | func (b *Big) ToInt() *big.Int {
201 | return (*big.Int)(b)
202 | }
203 |
204 | // String returns the hex encoding of b.
205 | func (b *Big) String() string {
206 | return EncodeBig(b.ToInt())
207 | }
208 |
209 | // ImplementsGraphQLType returns true if Big implements the provided GraphQL type.
210 | func (b Big) ImplementsGraphQLType(name string) bool { return name == "BigInt" }
211 |
212 | // UnmarshalGraphQL unmarshals the provided GraphQL query data.
213 | func (b *Big) UnmarshalGraphQL(input interface{}) error {
214 | var err error
215 | switch input := input.(type) {
216 | case string:
217 | return b.UnmarshalText([]byte(input))
218 | case int32:
219 | var num big.Int
220 | num.SetInt64(int64(input))
221 | *b = Big(num)
222 | default:
223 | err = fmt.Errorf("unexpected type %T for BigInt", input)
224 | }
225 | return err
226 | }
227 |
228 | // Uint64 marshals/unmarshals as a JSON string with 0x prefix.
229 | // The zero value marshals as "0x0".
230 | type Uint64 uint64
231 |
232 | // MarshalText implements encoding.TextMarshaler.
233 | func (b Uint64) MarshalText() ([]byte, error) {
234 | buf := make([]byte, 2, 10)
235 | copy(buf, `0x`)
236 | buf = strconv.AppendUint(buf, uint64(b), 16)
237 | return buf, nil
238 | }
239 |
240 | // UnmarshalJSON implements json.Unmarshaler.
241 | func (b *Uint64) UnmarshalJSON(input []byte) error {
242 | if !isString(input) {
243 | return errNonString(uint64T)
244 | }
245 | return wrapTypeError(b.UnmarshalText(input[1:len(input)-1]), uint64T)
246 | }
247 |
248 | // UnmarshalText implements encoding.TextUnmarshaler
249 | func (b *Uint64) UnmarshalText(input []byte) error {
250 | raw, err := checkNumberText(input)
251 | if err != nil {
252 | return err
253 | }
254 | if len(raw) > 16 {
255 | return ErrUint64Range
256 | }
257 | var dec uint64
258 | for _, byte := range raw {
259 | nib := decodeNibble(byte)
260 | if nib == badNibble {
261 | return ErrSyntax
262 | }
263 | dec *= 16
264 | dec += nib
265 | }
266 | *b = Uint64(dec)
267 | return nil
268 | }
269 |
270 | // String returns the hex encoding of b.
271 | func (b Uint64) String() string {
272 | return EncodeUint64(uint64(b))
273 | }
274 |
275 | // ImplementsGraphQLType returns true if Uint64 implements the provided GraphQL type.
276 | func (b Uint64) ImplementsGraphQLType(name string) bool { return name == "Long" }
277 |
278 | // UnmarshalGraphQL unmarshals the provided GraphQL query data.
279 | func (b *Uint64) UnmarshalGraphQL(input interface{}) error {
280 | var err error
281 | switch input := input.(type) {
282 | case string:
283 | return b.UnmarshalText([]byte(input))
284 | case int32:
285 | *b = Uint64(input)
286 | default:
287 | err = fmt.Errorf("unexpected type %T for Long", input)
288 | }
289 | return err
290 | }
291 |
292 | // Uint marshals/unmarshals as a JSON string with 0x prefix.
293 | // The zero value marshals as "0x0".
294 | type Uint uint
295 |
296 | // MarshalText implements encoding.TextMarshaler.
297 | func (b Uint) MarshalText() ([]byte, error) {
298 | return Uint64(b).MarshalText()
299 | }
300 |
301 | // UnmarshalJSON implements json.Unmarshaler.
302 | func (b *Uint) UnmarshalJSON(input []byte) error {
303 | if !isString(input) {
304 | return errNonString(uintT)
305 | }
306 | return wrapTypeError(b.UnmarshalText(input[1:len(input)-1]), uintT)
307 | }
308 |
309 | // UnmarshalText implements encoding.TextUnmarshaler.
310 | func (b *Uint) UnmarshalText(input []byte) error {
311 | var u64 Uint64
312 | err := u64.UnmarshalText(input)
313 | if u64 > Uint64(^uint(0)) || err == ErrUint64Range {
314 | return ErrUintRange
315 | } else if err != nil {
316 | return err
317 | }
318 | *b = Uint(u64)
319 | return nil
320 | }
321 |
322 | // String returns the hex encoding of b.
323 | func (b Uint) String() string {
324 | return EncodeUint64(uint64(b))
325 | }
326 |
327 | func isString(input []byte) bool {
328 | return len(input) >= 2 && input[0] == '"' && input[len(input)-1] == '"'
329 | }
330 |
331 | func bytesHave0xPrefix(input []byte) bool {
332 | return len(input) >= 2 && input[0] == '0' && (input[1] == 'x' || input[1] == 'X')
333 | }
334 |
335 | func checkText(input []byte, wantPrefix bool) ([]byte, error) {
336 | if len(input) == 0 {
337 | return nil, nil // empty strings are allowed
338 | }
339 | if bytesHave0xPrefix(input) {
340 | input = input[2:]
341 | } else if wantPrefix {
342 | return nil, ErrMissingPrefix
343 | }
344 | if len(input)%2 != 0 {
345 | return nil, ErrOddLength
346 | }
347 | return input, nil
348 | }
349 |
350 | func checkNumberText(input []byte) (raw []byte, err error) {
351 | if len(input) == 0 {
352 | return nil, nil // empty strings are allowed
353 | }
354 | if !bytesHave0xPrefix(input) {
355 | return nil, ErrMissingPrefix
356 | }
357 | input = input[2:]
358 | if len(input) == 0 {
359 | return nil, ErrEmptyNumber
360 | }
361 | if len(input) > 1 && input[0] == '0' {
362 | return nil, ErrLeadingZero
363 | }
364 | return input, nil
365 | }
366 |
367 | func wrapTypeError(err error, typ reflect.Type) error {
368 | if _, ok := err.(*decError); ok {
369 | return &json.UnmarshalTypeError{Value: err.Error(), Type: typ}
370 | }
371 | return err
372 | }
373 |
374 | func errNonString(typ reflect.Type) error {
375 | return &json.UnmarshalTypeError{Value: "non-string", Type: typ}
376 | }
377 |
--------------------------------------------------------------------------------
/vendor/golang.org/x/crypto/sha3/keccakf.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 | //go:build !amd64 || purego || !gc
6 | // +build !amd64 purego !gc
7 |
8 | package sha3
9 |
10 | // rc stores the round constants for use in the ι step.
11 | var rc = [24]uint64{
12 | 0x0000000000000001,
13 | 0x0000000000008082,
14 | 0x800000000000808A,
15 | 0x8000000080008000,
16 | 0x000000000000808B,
17 | 0x0000000080000001,
18 | 0x8000000080008081,
19 | 0x8000000000008009,
20 | 0x000000000000008A,
21 | 0x0000000000000088,
22 | 0x0000000080008009,
23 | 0x000000008000000A,
24 | 0x000000008000808B,
25 | 0x800000000000008B,
26 | 0x8000000000008089,
27 | 0x8000000000008003,
28 | 0x8000000000008002,
29 | 0x8000000000000080,
30 | 0x000000000000800A,
31 | 0x800000008000000A,
32 | 0x8000000080008081,
33 | 0x8000000000008080,
34 | 0x0000000080000001,
35 | 0x8000000080008008,
36 | }
37 |
38 | // keccakF1600 applies the Keccak permutation to a 1600b-wide
39 | // state represented as a slice of 25 uint64s.
40 | func keccakF1600(a *[25]uint64) {
41 | // Implementation translated from Keccak-inplace.c
42 | // in the keccak reference code.
43 | var t, bc0, bc1, bc2, bc3, bc4, d0, d1, d2, d3, d4 uint64
44 |
45 | for i := 0; i < 24; i += 4 {
46 | // Combines the 5 steps in each round into 2 steps.
47 | // Unrolls 4 rounds per loop and spreads some steps across rounds.
48 |
49 | // Round 1
50 | bc0 = a[0] ^ a[5] ^ a[10] ^ a[15] ^ a[20]
51 | bc1 = a[1] ^ a[6] ^ a[11] ^ a[16] ^ a[21]
52 | bc2 = a[2] ^ a[7] ^ a[12] ^ a[17] ^ a[22]
53 | bc3 = a[3] ^ a[8] ^ a[13] ^ a[18] ^ a[23]
54 | bc4 = a[4] ^ a[9] ^ a[14] ^ a[19] ^ a[24]
55 | d0 = bc4 ^ (bc1<<1 | bc1>>63)
56 | d1 = bc0 ^ (bc2<<1 | bc2>>63)
57 | d2 = bc1 ^ (bc3<<1 | bc3>>63)
58 | d3 = bc2 ^ (bc4<<1 | bc4>>63)
59 | d4 = bc3 ^ (bc0<<1 | bc0>>63)
60 |
61 | bc0 = a[0] ^ d0
62 | t = a[6] ^ d1
63 | bc1 = t<<44 | t>>(64-44)
64 | t = a[12] ^ d2
65 | bc2 = t<<43 | t>>(64-43)
66 | t = a[18] ^ d3
67 | bc3 = t<<21 | t>>(64-21)
68 | t = a[24] ^ d4
69 | bc4 = t<<14 | t>>(64-14)
70 | a[0] = bc0 ^ (bc2 &^ bc1) ^ rc[i]
71 | a[6] = bc1 ^ (bc3 &^ bc2)
72 | a[12] = bc2 ^ (bc4 &^ bc3)
73 | a[18] = bc3 ^ (bc0 &^ bc4)
74 | a[24] = bc4 ^ (bc1 &^ bc0)
75 |
76 | t = a[10] ^ d0
77 | bc2 = t<<3 | t>>(64-3)
78 | t = a[16] ^ d1
79 | bc3 = t<<45 | t>>(64-45)
80 | t = a[22] ^ d2
81 | bc4 = t<<61 | t>>(64-61)
82 | t = a[3] ^ d3
83 | bc0 = t<<28 | t>>(64-28)
84 | t = a[9] ^ d4
85 | bc1 = t<<20 | t>>(64-20)
86 | a[10] = bc0 ^ (bc2 &^ bc1)
87 | a[16] = bc1 ^ (bc3 &^ bc2)
88 | a[22] = bc2 ^ (bc4 &^ bc3)
89 | a[3] = bc3 ^ (bc0 &^ bc4)
90 | a[9] = bc4 ^ (bc1 &^ bc0)
91 |
92 | t = a[20] ^ d0
93 | bc4 = t<<18 | t>>(64-18)
94 | t = a[1] ^ d1
95 | bc0 = t<<1 | t>>(64-1)
96 | t = a[7] ^ d2
97 | bc1 = t<<6 | t>>(64-6)
98 | t = a[13] ^ d3
99 | bc2 = t<<25 | t>>(64-25)
100 | t = a[19] ^ d4
101 | bc3 = t<<8 | t>>(64-8)
102 | a[20] = bc0 ^ (bc2 &^ bc1)
103 | a[1] = bc1 ^ (bc3 &^ bc2)
104 | a[7] = bc2 ^ (bc4 &^ bc3)
105 | a[13] = bc3 ^ (bc0 &^ bc4)
106 | a[19] = bc4 ^ (bc1 &^ bc0)
107 |
108 | t = a[5] ^ d0
109 | bc1 = t<<36 | t>>(64-36)
110 | t = a[11] ^ d1
111 | bc2 = t<<10 | t>>(64-10)
112 | t = a[17] ^ d2
113 | bc3 = t<<15 | t>>(64-15)
114 | t = a[23] ^ d3
115 | bc4 = t<<56 | t>>(64-56)
116 | t = a[4] ^ d4
117 | bc0 = t<<27 | t>>(64-27)
118 | a[5] = bc0 ^ (bc2 &^ bc1)
119 | a[11] = bc1 ^ (bc3 &^ bc2)
120 | a[17] = bc2 ^ (bc4 &^ bc3)
121 | a[23] = bc3 ^ (bc0 &^ bc4)
122 | a[4] = bc4 ^ (bc1 &^ bc0)
123 |
124 | t = a[15] ^ d0
125 | bc3 = t<<41 | t>>(64-41)
126 | t = a[21] ^ d1
127 | bc4 = t<<2 | t>>(64-2)
128 | t = a[2] ^ d2
129 | bc0 = t<<62 | t>>(64-62)
130 | t = a[8] ^ d3
131 | bc1 = t<<55 | t>>(64-55)
132 | t = a[14] ^ d4
133 | bc2 = t<<39 | t>>(64-39)
134 | a[15] = bc0 ^ (bc2 &^ bc1)
135 | a[21] = bc1 ^ (bc3 &^ bc2)
136 | a[2] = bc2 ^ (bc4 &^ bc3)
137 | a[8] = bc3 ^ (bc0 &^ bc4)
138 | a[14] = bc4 ^ (bc1 &^ bc0)
139 |
140 | // Round 2
141 | bc0 = a[0] ^ a[5] ^ a[10] ^ a[15] ^ a[20]
142 | bc1 = a[1] ^ a[6] ^ a[11] ^ a[16] ^ a[21]
143 | bc2 = a[2] ^ a[7] ^ a[12] ^ a[17] ^ a[22]
144 | bc3 = a[3] ^ a[8] ^ a[13] ^ a[18] ^ a[23]
145 | bc4 = a[4] ^ a[9] ^ a[14] ^ a[19] ^ a[24]
146 | d0 = bc4 ^ (bc1<<1 | bc1>>63)
147 | d1 = bc0 ^ (bc2<<1 | bc2>>63)
148 | d2 = bc1 ^ (bc3<<1 | bc3>>63)
149 | d3 = bc2 ^ (bc4<<1 | bc4>>63)
150 | d4 = bc3 ^ (bc0<<1 | bc0>>63)
151 |
152 | bc0 = a[0] ^ d0
153 | t = a[16] ^ d1
154 | bc1 = t<<44 | t>>(64-44)
155 | t = a[7] ^ d2
156 | bc2 = t<<43 | t>>(64-43)
157 | t = a[23] ^ d3
158 | bc3 = t<<21 | t>>(64-21)
159 | t = a[14] ^ d4
160 | bc4 = t<<14 | t>>(64-14)
161 | a[0] = bc0 ^ (bc2 &^ bc1) ^ rc[i+1]
162 | a[16] = bc1 ^ (bc3 &^ bc2)
163 | a[7] = bc2 ^ (bc4 &^ bc3)
164 | a[23] = bc3 ^ (bc0 &^ bc4)
165 | a[14] = bc4 ^ (bc1 &^ bc0)
166 |
167 | t = a[20] ^ d0
168 | bc2 = t<<3 | t>>(64-3)
169 | t = a[11] ^ d1
170 | bc3 = t<<45 | t>>(64-45)
171 | t = a[2] ^ d2
172 | bc4 = t<<61 | t>>(64-61)
173 | t = a[18] ^ d3
174 | bc0 = t<<28 | t>>(64-28)
175 | t = a[9] ^ d4
176 | bc1 = t<<20 | t>>(64-20)
177 | a[20] = bc0 ^ (bc2 &^ bc1)
178 | a[11] = bc1 ^ (bc3 &^ bc2)
179 | a[2] = bc2 ^ (bc4 &^ bc3)
180 | a[18] = bc3 ^ (bc0 &^ bc4)
181 | a[9] = bc4 ^ (bc1 &^ bc0)
182 |
183 | t = a[15] ^ d0
184 | bc4 = t<<18 | t>>(64-18)
185 | t = a[6] ^ d1
186 | bc0 = t<<1 | t>>(64-1)
187 | t = a[22] ^ d2
188 | bc1 = t<<6 | t>>(64-6)
189 | t = a[13] ^ d3
190 | bc2 = t<<25 | t>>(64-25)
191 | t = a[4] ^ d4
192 | bc3 = t<<8 | t>>(64-8)
193 | a[15] = bc0 ^ (bc2 &^ bc1)
194 | a[6] = bc1 ^ (bc3 &^ bc2)
195 | a[22] = bc2 ^ (bc4 &^ bc3)
196 | a[13] = bc3 ^ (bc0 &^ bc4)
197 | a[4] = bc4 ^ (bc1 &^ bc0)
198 |
199 | t = a[10] ^ d0
200 | bc1 = t<<36 | t>>(64-36)
201 | t = a[1] ^ d1
202 | bc2 = t<<10 | t>>(64-10)
203 | t = a[17] ^ d2
204 | bc3 = t<<15 | t>>(64-15)
205 | t = a[8] ^ d3
206 | bc4 = t<<56 | t>>(64-56)
207 | t = a[24] ^ d4
208 | bc0 = t<<27 | t>>(64-27)
209 | a[10] = bc0 ^ (bc2 &^ bc1)
210 | a[1] = bc1 ^ (bc3 &^ bc2)
211 | a[17] = bc2 ^ (bc4 &^ bc3)
212 | a[8] = bc3 ^ (bc0 &^ bc4)
213 | a[24] = bc4 ^ (bc1 &^ bc0)
214 |
215 | t = a[5] ^ d0
216 | bc3 = t<<41 | t>>(64-41)
217 | t = a[21] ^ d1
218 | bc4 = t<<2 | t>>(64-2)
219 | t = a[12] ^ d2
220 | bc0 = t<<62 | t>>(64-62)
221 | t = a[3] ^ d3
222 | bc1 = t<<55 | t>>(64-55)
223 | t = a[19] ^ d4
224 | bc2 = t<<39 | t>>(64-39)
225 | a[5] = bc0 ^ (bc2 &^ bc1)
226 | a[21] = bc1 ^ (bc3 &^ bc2)
227 | a[12] = bc2 ^ (bc4 &^ bc3)
228 | a[3] = bc3 ^ (bc0 &^ bc4)
229 | a[19] = bc4 ^ (bc1 &^ bc0)
230 |
231 | // Round 3
232 | bc0 = a[0] ^ a[5] ^ a[10] ^ a[15] ^ a[20]
233 | bc1 = a[1] ^ a[6] ^ a[11] ^ a[16] ^ a[21]
234 | bc2 = a[2] ^ a[7] ^ a[12] ^ a[17] ^ a[22]
235 | bc3 = a[3] ^ a[8] ^ a[13] ^ a[18] ^ a[23]
236 | bc4 = a[4] ^ a[9] ^ a[14] ^ a[19] ^ a[24]
237 | d0 = bc4 ^ (bc1<<1 | bc1>>63)
238 | d1 = bc0 ^ (bc2<<1 | bc2>>63)
239 | d2 = bc1 ^ (bc3<<1 | bc3>>63)
240 | d3 = bc2 ^ (bc4<<1 | bc4>>63)
241 | d4 = bc3 ^ (bc0<<1 | bc0>>63)
242 |
243 | bc0 = a[0] ^ d0
244 | t = a[11] ^ d1
245 | bc1 = t<<44 | t>>(64-44)
246 | t = a[22] ^ d2
247 | bc2 = t<<43 | t>>(64-43)
248 | t = a[8] ^ d3
249 | bc3 = t<<21 | t>>(64-21)
250 | t = a[19] ^ d4
251 | bc4 = t<<14 | t>>(64-14)
252 | a[0] = bc0 ^ (bc2 &^ bc1) ^ rc[i+2]
253 | a[11] = bc1 ^ (bc3 &^ bc2)
254 | a[22] = bc2 ^ (bc4 &^ bc3)
255 | a[8] = bc3 ^ (bc0 &^ bc4)
256 | a[19] = bc4 ^ (bc1 &^ bc0)
257 |
258 | t = a[15] ^ d0
259 | bc2 = t<<3 | t>>(64-3)
260 | t = a[1] ^ d1
261 | bc3 = t<<45 | t>>(64-45)
262 | t = a[12] ^ d2
263 | bc4 = t<<61 | t>>(64-61)
264 | t = a[23] ^ d3
265 | bc0 = t<<28 | t>>(64-28)
266 | t = a[9] ^ d4
267 | bc1 = t<<20 | t>>(64-20)
268 | a[15] = bc0 ^ (bc2 &^ bc1)
269 | a[1] = bc1 ^ (bc3 &^ bc2)
270 | a[12] = bc2 ^ (bc4 &^ bc3)
271 | a[23] = bc3 ^ (bc0 &^ bc4)
272 | a[9] = bc4 ^ (bc1 &^ bc0)
273 |
274 | t = a[5] ^ d0
275 | bc4 = t<<18 | t>>(64-18)
276 | t = a[16] ^ d1
277 | bc0 = t<<1 | t>>(64-1)
278 | t = a[2] ^ d2
279 | bc1 = t<<6 | t>>(64-6)
280 | t = a[13] ^ d3
281 | bc2 = t<<25 | t>>(64-25)
282 | t = a[24] ^ d4
283 | bc3 = t<<8 | t>>(64-8)
284 | a[5] = bc0 ^ (bc2 &^ bc1)
285 | a[16] = bc1 ^ (bc3 &^ bc2)
286 | a[2] = bc2 ^ (bc4 &^ bc3)
287 | a[13] = bc3 ^ (bc0 &^ bc4)
288 | a[24] = bc4 ^ (bc1 &^ bc0)
289 |
290 | t = a[20] ^ d0
291 | bc1 = t<<36 | t>>(64-36)
292 | t = a[6] ^ d1
293 | bc2 = t<<10 | t>>(64-10)
294 | t = a[17] ^ d2
295 | bc3 = t<<15 | t>>(64-15)
296 | t = a[3] ^ d3
297 | bc4 = t<<56 | t>>(64-56)
298 | t = a[14] ^ d4
299 | bc0 = t<<27 | t>>(64-27)
300 | a[20] = bc0 ^ (bc2 &^ bc1)
301 | a[6] = bc1 ^ (bc3 &^ bc2)
302 | a[17] = bc2 ^ (bc4 &^ bc3)
303 | a[3] = bc3 ^ (bc0 &^ bc4)
304 | a[14] = bc4 ^ (bc1 &^ bc0)
305 |
306 | t = a[10] ^ d0
307 | bc3 = t<<41 | t>>(64-41)
308 | t = a[21] ^ d1
309 | bc4 = t<<2 | t>>(64-2)
310 | t = a[7] ^ d2
311 | bc0 = t<<62 | t>>(64-62)
312 | t = a[18] ^ d3
313 | bc1 = t<<55 | t>>(64-55)
314 | t = a[4] ^ d4
315 | bc2 = t<<39 | t>>(64-39)
316 | a[10] = bc0 ^ (bc2 &^ bc1)
317 | a[21] = bc1 ^ (bc3 &^ bc2)
318 | a[7] = bc2 ^ (bc4 &^ bc3)
319 | a[18] = bc3 ^ (bc0 &^ bc4)
320 | a[4] = bc4 ^ (bc1 &^ bc0)
321 |
322 | // Round 4
323 | bc0 = a[0] ^ a[5] ^ a[10] ^ a[15] ^ a[20]
324 | bc1 = a[1] ^ a[6] ^ a[11] ^ a[16] ^ a[21]
325 | bc2 = a[2] ^ a[7] ^ a[12] ^ a[17] ^ a[22]
326 | bc3 = a[3] ^ a[8] ^ a[13] ^ a[18] ^ a[23]
327 | bc4 = a[4] ^ a[9] ^ a[14] ^ a[19] ^ a[24]
328 | d0 = bc4 ^ (bc1<<1 | bc1>>63)
329 | d1 = bc0 ^ (bc2<<1 | bc2>>63)
330 | d2 = bc1 ^ (bc3<<1 | bc3>>63)
331 | d3 = bc2 ^ (bc4<<1 | bc4>>63)
332 | d4 = bc3 ^ (bc0<<1 | bc0>>63)
333 |
334 | bc0 = a[0] ^ d0
335 | t = a[1] ^ d1
336 | bc1 = t<<44 | t>>(64-44)
337 | t = a[2] ^ d2
338 | bc2 = t<<43 | t>>(64-43)
339 | t = a[3] ^ d3
340 | bc3 = t<<21 | t>>(64-21)
341 | t = a[4] ^ d4
342 | bc4 = t<<14 | t>>(64-14)
343 | a[0] = bc0 ^ (bc2 &^ bc1) ^ rc[i+3]
344 | a[1] = bc1 ^ (bc3 &^ bc2)
345 | a[2] = bc2 ^ (bc4 &^ bc3)
346 | a[3] = bc3 ^ (bc0 &^ bc4)
347 | a[4] = bc4 ^ (bc1 &^ bc0)
348 |
349 | t = a[5] ^ d0
350 | bc2 = t<<3 | t>>(64-3)
351 | t = a[6] ^ d1
352 | bc3 = t<<45 | t>>(64-45)
353 | t = a[7] ^ d2
354 | bc4 = t<<61 | t>>(64-61)
355 | t = a[8] ^ d3
356 | bc0 = t<<28 | t>>(64-28)
357 | t = a[9] ^ d4
358 | bc1 = t<<20 | t>>(64-20)
359 | a[5] = bc0 ^ (bc2 &^ bc1)
360 | a[6] = bc1 ^ (bc3 &^ bc2)
361 | a[7] = bc2 ^ (bc4 &^ bc3)
362 | a[8] = bc3 ^ (bc0 &^ bc4)
363 | a[9] = bc4 ^ (bc1 &^ bc0)
364 |
365 | t = a[10] ^ d0
366 | bc4 = t<<18 | t>>(64-18)
367 | t = a[11] ^ d1
368 | bc0 = t<<1 | t>>(64-1)
369 | t = a[12] ^ d2
370 | bc1 = t<<6 | t>>(64-6)
371 | t = a[13] ^ d3
372 | bc2 = t<<25 | t>>(64-25)
373 | t = a[14] ^ d4
374 | bc3 = t<<8 | t>>(64-8)
375 | a[10] = bc0 ^ (bc2 &^ bc1)
376 | a[11] = bc1 ^ (bc3 &^ bc2)
377 | a[12] = bc2 ^ (bc4 &^ bc3)
378 | a[13] = bc3 ^ (bc0 &^ bc4)
379 | a[14] = bc4 ^ (bc1 &^ bc0)
380 |
381 | t = a[15] ^ d0
382 | bc1 = t<<36 | t>>(64-36)
383 | t = a[16] ^ d1
384 | bc2 = t<<10 | t>>(64-10)
385 | t = a[17] ^ d2
386 | bc3 = t<<15 | t>>(64-15)
387 | t = a[18] ^ d3
388 | bc4 = t<<56 | t>>(64-56)
389 | t = a[19] ^ d4
390 | bc0 = t<<27 | t>>(64-27)
391 | a[15] = bc0 ^ (bc2 &^ bc1)
392 | a[16] = bc1 ^ (bc3 &^ bc2)
393 | a[17] = bc2 ^ (bc4 &^ bc3)
394 | a[18] = bc3 ^ (bc0 &^ bc4)
395 | a[19] = bc4 ^ (bc1 &^ bc0)
396 |
397 | t = a[20] ^ d0
398 | bc3 = t<<41 | t>>(64-41)
399 | t = a[21] ^ d1
400 | bc4 = t<<2 | t>>(64-2)
401 | t = a[22] ^ d2
402 | bc0 = t<<62 | t>>(64-62)
403 | t = a[23] ^ d3
404 | bc1 = t<<55 | t>>(64-55)
405 | t = a[24] ^ d4
406 | bc2 = t<<39 | t>>(64-39)
407 | a[20] = bc0 ^ (bc2 &^ bc1)
408 | a[21] = bc1 ^ (bc3 &^ bc2)
409 | a[22] = bc2 ^ (bc4 &^ bc3)
410 | a[23] = bc3 ^ (bc0 &^ bc4)
411 | a[24] = bc4 ^ (bc1 &^ bc0)
412 | }
413 | }
414 |
--------------------------------------------------------------------------------