├── test ├── python │ ├── .gitignore │ ├── requirements.txt │ └── test.sh ├── c │ ├── test.sh │ └── CMakeLists.txt └── test.sh ├── vendor ├── github.com │ ├── ethereum │ │ └── go-ethereum │ │ │ ├── crypto │ │ │ ├── secp256k1 │ │ │ │ ├── libsecp256k1 │ │ │ │ │ ├── autogen.sh │ │ │ │ │ ├── TODO │ │ │ │ │ ├── src │ │ │ │ │ │ ├── modules │ │ │ │ │ │ │ ├── ecdh │ │ │ │ │ │ │ │ ├── Makefile.am.include │ │ │ │ │ │ │ │ ├── main_impl.h │ │ │ │ │ │ │ │ └── tests_impl.h │ │ │ │ │ │ │ └── recovery │ │ │ │ │ │ │ │ └── Makefile.am.include │ │ │ │ │ │ ├── java │ │ │ │ │ │ │ ├── org_bitcoin_Secp256k1Context.c │ │ │ │ │ │ │ ├── org_bitcoin_Secp256k1Context.h │ │ │ │ │ │ │ ├── org │ │ │ │ │ │ │ │ └── bitcoin │ │ │ │ │ │ │ │ │ ├── NativeSecp256k1Util.java │ │ │ │ │ │ │ │ │ └── Secp256k1Context.java │ │ │ │ │ │ │ └── org_bitcoin_NativeSecp256k1.h │ │ │ │ │ │ ├── scalar_low.h │ │ │ │ │ │ ├── ecmult_const.h │ │ │ │ │ │ ├── num_gmp.h │ │ │ │ │ │ ├── num_impl.h │ │ │ │ │ │ ├── scalar_8x32.h │ │ │ │ │ │ ├── scalar_4x64.h │ │ │ │ │ │ ├── basic-config.h │ │ │ │ │ │ ├── ecdsa.h │ │ │ │ │ │ ├── eckey.h │ │ │ │ │ │ ├── ecmult.h │ │ │ │ │ │ ├── testrand.h │ │ │ │ │ │ ├── bench_sign.c │ │ │ │ │ │ ├── hash.h │ │ │ │ │ │ ├── bench_ecdh.c │ │ │ │ │ │ ├── field_5x52.h │ │ │ │ │ │ ├── bench.h │ │ │ │ │ │ ├── field_10x26.h │ │ │ │ │ │ ├── bench_recover.c │ │ │ │ │ │ ├── ecmult_gen.h │ │ │ │ │ │ ├── gen_context.c │ │ │ │ │ │ ├── bench_schnorr_verify.c │ │ │ │ │ │ ├── num.h │ │ │ │ │ │ ├── util.h │ │ │ │ │ │ ├── eckey_impl.h │ │ │ │ │ │ ├── scalar_low_impl.h │ │ │ │ │ │ ├── bench_verify.c │ │ │ │ │ │ └── testrand_impl.h │ │ │ │ │ ├── libsecp256k1.pc.in │ │ │ │ │ ├── COPYING │ │ │ │ │ ├── include │ │ │ │ │ │ └── secp256k1_ecdh.h │ │ │ │ │ ├── build-aux │ │ │ │ │ │ └── m4 │ │ │ │ │ │ │ ├── bitcoin_secp.m4 │ │ │ │ │ │ │ └── ax_prog_cc_for_build.m4 │ │ │ │ │ ├── README.md │ │ │ │ │ └── contrib │ │ │ │ │ │ ├── lax_der_privatekey_parsing.h │ │ │ │ │ │ ├── lax_der_parsing.h │ │ │ │ │ │ └── lax_der_parsing.c │ │ │ │ ├── panic_cb.go │ │ │ │ └── ext.h │ │ │ ├── sha3 │ │ │ │ ├── keccakf_amd64.go │ │ │ │ ├── xor.go │ │ │ │ ├── register.go │ │ │ │ ├── xor_generic.go │ │ │ │ ├── xor_unaligned.go │ │ │ │ ├── PATENTS │ │ │ │ ├── LICENSE │ │ │ │ ├── shake.go │ │ │ │ ├── hashes.go │ │ │ │ └── doc.go │ │ │ ├── signature_cgo.go │ │ │ └── signature_nocgo.go │ │ │ ├── log │ │ │ ├── CONTRIBUTORS │ │ │ ├── README_ETHEREUM.md │ │ │ ├── handler_go14.go │ │ │ ├── LICENSE │ │ │ ├── handler_go13.go │ │ │ ├── root.go │ │ │ ├── syslog.go │ │ │ └── README.md │ │ │ └── rlp │ │ │ ├── doc.go │ │ │ └── typecache.go │ ├── go-stack │ │ └── stack │ │ │ ├── LICENSE.md │ │ │ └── README.md │ └── btcsuite │ │ └── btcd │ │ ├── LICENSE │ │ └── btcec │ │ ├── doc.go │ │ ├── genprecomps.go │ │ ├── precompute.go │ │ ├── privkey.go │ │ └── README.md └── vendor.json ├── .gitignore ├── Makefile ├── Vagrantfile ├── CMakeLists.txt ├── cryptopp └── CMakeLists.txt ├── src ├── libethash │ ├── sha3_cryptopp.h │ ├── sha3.h │ ├── CMakeLists.txt │ ├── compiler.h │ ├── sha3_cryptopp.cpp │ ├── util_win32.c │ ├── util.h │ ├── fnv.h │ ├── mmap.h │ ├── mmap_win32.c │ ├── endian.h │ ├── io_win32.c │ ├── io_posix.c │ ├── io.c │ └── sha3.c └── benchmark │ └── CMakeLists.txt ├── MANIFEST.in ├── .travis.yml ├── README.md ├── appveyor.yml ├── compat.go ├── js ├── LICENSE ├── util.js └── test.js ├── setup.py ├── ethashc.go └── cmake └── modules ├── FindPackageMessage.cmake └── FindCryptoPP.cmake /test/python/.gitignore: -------------------------------------------------------------------------------- 1 | python-virtual-env/ 2 | -------------------------------------------------------------------------------- /test/python/requirements.txt: -------------------------------------------------------------------------------- 1 | pyethereum==0.7.522 2 | nose==1.3.4 3 | pysha3==0.3 -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | autoreconf -if --warnings=all 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | .DS_Store 3 | */**/*un~ 4 | .vagrant/ 5 | *.pyc 6 | build/ 7 | pyethash.egg-info/ 8 | *.so 9 | *~ 10 | *.swp 11 | MANIFEST 12 | dist/ 13 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: clean test 2 | test: 3 | ./test/test.sh 4 | 5 | clean: 6 | rm -rf *.so pyethash.egg-info/ build/ test/python/python-virtual-env/ test/c/build/ pyethash.so test/python/*.pyc dist/ MANIFEST 7 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/TODO: -------------------------------------------------------------------------------- 1 | * Unit tests for fieldelem/groupelem, including ones intended to 2 | trigger fieldelem's boundary cases. 3 | * Complete constant-time operations for signing/keygen 4 | -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | Vagrant.configure(2) do |config| 5 | config.vm.box = "Ubuntu 12.04" 6 | config.vm.box_url = "https://cloud-images.ubuntu.com/vagrant/precise/current/precise-server-cloudimg-amd64-vagrant-disk1.box" 7 | end 8 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/log/CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | Contributors to log15: 2 | 3 | - Aaron L 4 | - Alan Shreve 5 | - Chris Hines 6 | - Ciaran Downey 7 | - Dmitry Chestnykh 8 | - Evan Shaw 9 | - Péter Szilágyi 10 | - Trevor Gattis 11 | - Vincent Vanackere 12 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/log/README_ETHEREUM.md: -------------------------------------------------------------------------------- 1 | This package is a fork of https://github.com/inconshreveable/log15, with some 2 | minor modifications required by the go-ethereum codebase: 3 | 4 | * Support for log level `trace` 5 | * Modified behavior to exit on `critical` failure 6 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.7) 2 | project(ethash) 3 | 4 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/") 5 | set(ETHHASH_LIBS ethash) 6 | 7 | if (WIN32 AND WANT_CRYPTOPP) 8 | add_subdirectory(cryptopp) 9 | endif() 10 | 11 | add_subdirectory(src/libethash) 12 | 13 | add_subdirectory(src/benchmark EXCLUDE_FROM_ALL) 14 | add_subdirectory(test/c) 15 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/src/modules/ecdh/Makefile.am.include: -------------------------------------------------------------------------------- 1 | include_HEADERS += include/secp256k1_ecdh.h 2 | noinst_HEADERS += src/modules/ecdh/main_impl.h 3 | noinst_HEADERS += src/modules/ecdh/tests_impl.h 4 | if USE_BENCHMARK 5 | noinst_PROGRAMS += bench_ecdh 6 | bench_ecdh_SOURCES = src/bench_ecdh.c 7 | bench_ecdh_LDADD = libsecp256k1.la $(SECP_LIBS) $(COMMON_LIB) 8 | endif 9 | -------------------------------------------------------------------------------- /cryptopp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LIBRARY cryptopp) 2 | 3 | include_directories(../../cryptopp) 4 | 5 | # todo, subset 6 | file(GLOB HEADERS "../../cryptopp/*.h") 7 | file(GLOB SOURCE "../../cryptopp/*.cpp") 8 | 9 | add_library(${LIBRARY} ${HEADERS} ${SOURCE}) 10 | 11 | set(CRYPTOPP_INCLUDE_DIRS "../.." "../../../" PARENT_SCOPE) 12 | set(CRYPTOPP_LIBRARIES ${LIBRARY} PARENT_SCOPE) 13 | set(CRYPTOPP_FOUND TRUE PARENT_SCOPE) 14 | -------------------------------------------------------------------------------- /src/libethash/sha3_cryptopp.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "compiler.h" 4 | #include 5 | #include 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | struct ethash_h256; 12 | 13 | void SHA3_256(struct ethash_h256 const* ret, uint8_t const* data, size_t size); 14 | void SHA3_512(uint8_t* const ret, uint8_t const* data, size_t size); 15 | 16 | #ifdef __cplusplus 17 | } 18 | #endif 19 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/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 | // +build amd64,!appengine,!gccgo 6 | 7 | package sha3 8 | 9 | // This function is implemented in keccakf_amd64.s. 10 | 11 | //go:noescape 12 | 13 | func keccakF1600(state *[25]uint64) 14 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/src/modules/recovery/Makefile.am.include: -------------------------------------------------------------------------------- 1 | include_HEADERS += include/secp256k1_recovery.h 2 | noinst_HEADERS += src/modules/recovery/main_impl.h 3 | noinst_HEADERS += src/modules/recovery/tests_impl.h 4 | if USE_BENCHMARK 5 | noinst_PROGRAMS += bench_recover 6 | bench_recover_SOURCES = src/bench_recover.c 7 | bench_recover_LDADD = libsecp256k1.la $(SECP_LIBS) $(COMMON_LIB) 8 | endif 9 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/libsecp256k1.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: libsecp256k1 7 | Description: Optimized C library for EC operations on curve secp256k1 8 | URL: https://github.com/bitcoin-core/secp256k1 9 | Version: @PACKAGE_VERSION@ 10 | Cflags: -I${includedir} 11 | Libs.private: @SECP_LIBS@ 12 | Libs: -L${libdir} -lsecp256k1 13 | 14 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include setup.py 2 | 3 | # C sources 4 | include src/libethash/internal.c 5 | include src/libethash/sha3.c 6 | include src/libethash/util.c 7 | include src/python/core.c 8 | 9 | # Headers 10 | include src/libethash/compiler.h 11 | include src/libethash/data_sizes.h 12 | include src/libethash/endian.h 13 | include src/libethash/ethash.h 14 | include src/libethash/fnv.h 15 | include src/libethash/internal.h 16 | include src/libethash/sha3.h 17 | include src/libethash/util.h 18 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/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 | // +build !amd64,!386,!ppc64le appengine 6 | 7 | package sha3 8 | 9 | var ( 10 | xorIn = xorInGeneric 11 | copyOut = copyOutGeneric 12 | xorInUnaligned = xorInGeneric 13 | copyOutUnaligned = copyOutGeneric 14 | ) 15 | 16 | const xorImplementationUnaligned = "generic" 17 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/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 | // +build go1.4 6 | 7 | package sha3 8 | 9 | import ( 10 | "crypto" 11 | ) 12 | 13 | func init() { 14 | crypto.RegisterHash(crypto.SHA3_224, New224) 15 | crypto.RegisterHash(crypto.SHA3_256, New256) 16 | crypto.RegisterHash(crypto.SHA3_384, New384) 17 | crypto.RegisterHash(crypto.SHA3_512, New512) 18 | } 19 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/src/java/org_bitcoin_Secp256k1Context.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "org_bitcoin_Secp256k1Context.h" 4 | #include "include/secp256k1.h" 5 | 6 | SECP256K1_API jlong JNICALL Java_org_bitcoin_Secp256k1Context_secp256k1_1init_1context 7 | (JNIEnv* env, jclass classObject) 8 | { 9 | secp256k1_context *ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY); 10 | 11 | (void)classObject;(void)env; 12 | 13 | return (uintptr_t)ctx; 14 | } 15 | 16 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/log/handler_go14.go: -------------------------------------------------------------------------------- 1 | // +build go1.4 2 | 3 | package log 4 | 5 | import "sync/atomic" 6 | 7 | // swapHandler wraps another handler that may be swapped out 8 | // dynamically at runtime in a thread-safe fashion. 9 | type swapHandler struct { 10 | handler atomic.Value 11 | } 12 | 13 | func (h *swapHandler) Log(r *Record) error { 14 | return (*h.handler.Load().(*Handler)).Log(r) 15 | } 16 | 17 | func (h *swapHandler) Swap(newHandler Handler) { 18 | h.handler.Store(&newHandler) 19 | } 20 | 21 | func (h *swapHandler) Get() Handler { 22 | return *h.handler.Load().(*Handler) 23 | } 24 | -------------------------------------------------------------------------------- /vendor/github.com/go-stack/stack/LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright 2014 Chris Hines 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/log/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2014 Alan Shreve 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/log/handler_go13.go: -------------------------------------------------------------------------------- 1 | // +build !go1.4 2 | 3 | package log 4 | 5 | import ( 6 | "sync/atomic" 7 | "unsafe" 8 | ) 9 | 10 | // swapHandler wraps another handler that may be swapped out 11 | // dynamically at runtime in a thread-safe fashion. 12 | type swapHandler struct { 13 | handler unsafe.Pointer 14 | } 15 | 16 | func (h *swapHandler) Log(r *Record) error { 17 | return h.Get().Log(r) 18 | } 19 | 20 | func (h *swapHandler) Get() Handler { 21 | return *(*Handler)(atomic.LoadPointer(&h.handler)) 22 | } 23 | 24 | func (h *swapHandler) Swap(newHandler Handler) { 25 | atomic.StorePointer(&h.handler, unsafe.Pointer(&newHandler)) 26 | } 27 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/src/scalar_low.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2015 Andrew Poelstra * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_SCALAR_REPR_ 8 | #define _SECP256K1_SCALAR_REPR_ 9 | 10 | #include 11 | 12 | /** A scalar modulo the group order of the secp256k1 curve. */ 13 | typedef uint32_t secp256k1_scalar; 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /src/libethash/sha3.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef __cplusplus 4 | extern "C" { 5 | #endif 6 | 7 | #include "compiler.h" 8 | #include 9 | #include 10 | 11 | struct ethash_h256; 12 | 13 | #define decsha3(bits) \ 14 | int sha3_##bits(uint8_t*, size_t, uint8_t const*, size_t); 15 | 16 | decsha3(256) 17 | decsha3(512) 18 | 19 | static inline void SHA3_256(struct ethash_h256 const* ret, uint8_t const* data, size_t const size) 20 | { 21 | sha3_256((uint8_t*)ret, 32, data, size); 22 | } 23 | 24 | static inline void SHA3_512(uint8_t* ret, uint8_t const* data, size_t const size) 25 | { 26 | sha3_512(ret, 64, data, size); 27 | } 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif 32 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/src/ecmult_const.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2015 Andrew Poelstra * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_ECMULT_CONST_ 8 | #define _SECP256K1_ECMULT_CONST_ 9 | 10 | #include "scalar.h" 11 | #include "group.h" 12 | 13 | static void secp256k1_ecmult_const(secp256k1_gej *r, const secp256k1_ge *a, const secp256k1_scalar *q); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/src/java/org_bitcoin_Secp256k1Context.h: -------------------------------------------------------------------------------- 1 | /* DO NOT EDIT THIS FILE - it is machine generated */ 2 | #include 3 | #include "include/secp256k1.h" 4 | /* Header for class org_bitcoin_Secp256k1Context */ 5 | 6 | #ifndef _Included_org_bitcoin_Secp256k1Context 7 | #define _Included_org_bitcoin_Secp256k1Context 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | /* 12 | * Class: org_bitcoin_Secp256k1Context 13 | * Method: secp256k1_init_context 14 | * Signature: ()J 15 | */ 16 | SECP256K1_API jlong JNICALL Java_org_bitcoin_Secp256k1Context_secp256k1_1init_1context 17 | (JNIEnv *, jclass); 18 | 19 | #ifdef __cplusplus 20 | } 21 | #endif 22 | #endif 23 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/src/num_gmp.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2013, 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_NUM_REPR_ 8 | #define _SECP256K1_NUM_REPR_ 9 | 10 | #include 11 | 12 | #define NUM_LIMBS ((256+GMP_NUMB_BITS-1)/GMP_NUMB_BITS) 13 | 14 | typedef struct { 15 | mp_limb_t data[2*NUM_LIMBS]; 16 | int neg; 17 | int limbs; 18 | } secp256k1_num; 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/src/num_impl.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2013, 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_NUM_IMPL_H_ 8 | #define _SECP256K1_NUM_IMPL_H_ 9 | 10 | #if defined HAVE_CONFIG_H 11 | #include "libsecp256k1-config.h" 12 | #endif 13 | 14 | #include "num.h" 15 | 16 | #if defined(USE_NUM_GMP) 17 | #include "num_gmp_impl.h" 18 | #elif defined(USE_NUM_NONE) 19 | /* Nothing. */ 20 | #else 21 | #error "Please select num implementation" 22 | #endif 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/src/scalar_8x32.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_SCALAR_REPR_ 8 | #define _SECP256K1_SCALAR_REPR_ 9 | 10 | #include 11 | 12 | /** A scalar modulo the group order of the secp256k1 curve. */ 13 | typedef struct { 14 | uint32_t d[8]; 15 | } secp256k1_scalar; 16 | 17 | #define SECP256K1_SCALAR_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {{(d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7)}} 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/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 | -------------------------------------------------------------------------------- /vendor/github.com/btcsuite/btcd/LICENSE: -------------------------------------------------------------------------------- 1 | ISC License 2 | 3 | Copyright (c) 2013-2017 The btcsuite developers 4 | Copyright (c) 2015-2016 The Decred developers 5 | 6 | Permission to use, copy, modify, and distribute this software for any 7 | purpose with or without fee is hereby granted, provided that the above 8 | copyright notice and this permission notice appear in all copies. 9 | 10 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/src/scalar_4x64.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_SCALAR_REPR_ 8 | #define _SECP256K1_SCALAR_REPR_ 9 | 10 | #include 11 | 12 | /** A scalar modulo the group order of the secp256k1 curve. */ 13 | typedef struct { 14 | uint64_t d[4]; 15 | } secp256k1_scalar; 16 | 17 | #define SECP256K1_SCALAR_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {{((uint64_t)(d1)) << 32 | (d0), ((uint64_t)(d3)) << 32 | (d2), ((uint64_t)(d5)) << 32 | (d4), ((uint64_t)(d7)) << 32 | (d6)}} 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /test/c/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Strict mode 4 | set -e 5 | 6 | VALGRIND_ARGS="--tool=memcheck" 7 | VALGRIND_ARGS+=" --leak-check=yes" 8 | VALGRIND_ARGS+=" --track-origins=yes" 9 | VALGRIND_ARGS+=" --show-reachable=yes" 10 | VALGRIND_ARGS+=" --num-callers=20" 11 | VALGRIND_ARGS+=" --track-fds=yes" 12 | 13 | SOURCE="${BASH_SOURCE[0]}" 14 | while [ -h "$SOURCE" ]; do 15 | DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" 16 | SOURCE="$(readlink "$SOURCE")" 17 | [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" 18 | done 19 | TEST_DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" 20 | 21 | rm -rf $TEST_DIR/build 22 | mkdir -p $TEST_DIR/build 23 | cd $TEST_DIR/build ; 24 | cmake ../../.. > /dev/null 25 | make Test 26 | ./test/c/Test 27 | 28 | # If we have valgrind also run memory check tests 29 | if hash valgrind 2>/dev/null; then 30 | echo "======== Running tests under valgrind ========"; 31 | cd $TEST_DIR/build/ && valgrind $VALGRIND_ARGS ./test/c/Test 32 | fi 33 | -------------------------------------------------------------------------------- /test/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Strict mode 4 | set -e 5 | 6 | SOURCE="${BASH_SOURCE[0]}" 7 | while [ -h "$SOURCE" ]; do 8 | DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" 9 | SOURCE="$(readlink "$SOURCE")" 10 | [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" 11 | done 12 | TEST_DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" 13 | 14 | echo -e "\n################# Testing JS ##################" 15 | # TODO: Use mocha and real testing tools instead of rolling our own 16 | cd $TEST_DIR/../js 17 | if [ -x "$(which nodejs)" ] ; then 18 | nodejs test.js 19 | fi 20 | if [ -x "$(which node)" ] ; then 21 | node test.js 22 | fi 23 | 24 | echo -e "\n################# Testing C ##################" 25 | $TEST_DIR/c/test.sh 26 | 27 | # Temporarily commenting out python tests until they conform to the API 28 | #echo -e "\n################# Testing Python ##################" 29 | #$TEST_DIR/python/test.sh 30 | 31 | echo "################# Testing Go ##################" 32 | cd $TEST_DIR/.. && go test -timeout 9999s 33 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | go: 3 | - 1.4.2 4 | 5 | before_install: 6 | # for g++4.8 and C++11 7 | - sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test 8 | 9 | # Set up go-ethereum 10 | - sudo apt-get update -y -qq 11 | - sudo apt-get install -yqq libgmp3-dev 12 | - git clone --depth=10 https://github.com/ethereum/go-ethereum ${GOPATH}/src/github.com/ethereum/go-ethereum 13 | # use canned dependencies from the go-ethereum repository 14 | - export GOPATH=$GOPATH:$GOPATH/src/github.com/ethereum/go-ethereum/Godeps/_workspace/ 15 | - echo $GOPATH 16 | 17 | install: 18 | # need to explicitly request version 1.48 since by default we get 1.46 which does not work with C++11 19 | - sudo apt-get install -qq --yes --force-yes g++-4.8 20 | - sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 50 21 | - sudo apt-get install -qq wget cmake bash libboost-test1.48-dev libboost-system1.48-dev libboost-filesystem1.48-dev nodejs python-pip python-dev valgrind 22 | - sudo pip install virtualenv -q 23 | script: "./test/test.sh" 24 | -------------------------------------------------------------------------------- /vendor/github.com/btcsuite/btcd/btcec/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013-2014 The btcsuite developers 2 | // Use of this source code is governed by an ISC 3 | // license that can be found in the LICENSE file. 4 | 5 | /* 6 | Package btcec implements support for the elliptic curves needed for bitcoin. 7 | 8 | Bitcoin uses elliptic curve cryptography using koblitz curves 9 | (specifically secp256k1) for cryptographic functions. See 10 | http://www.secg.org/collateral/sec2_final.pdf for details on the 11 | standard. 12 | 13 | This package provides the data structures and functions implementing the 14 | crypto/elliptic Curve interface in order to permit using these curves 15 | with the standard crypto/ecdsa package provided with go. Helper 16 | functionality is provided to parse signatures and public keys from 17 | standard formats. It was designed for use with btcd, but should be 18 | general enough for other uses of elliptic curve crypto. It was originally based 19 | on some initial work by ThePiachu, but has significantly diverged since then. 20 | */ 21 | package btcec 22 | -------------------------------------------------------------------------------- /test/python/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Strict mode 4 | set -e 5 | 6 | if [ -x "$(which virtualenv2)" ] ; then 7 | VIRTUALENV_EXEC=virtualenv2 8 | elif [ -x "$(which virtualenv)" ] ; then 9 | VIRTUALENV_EXEC=virtualenv 10 | else 11 | echo "Could not find a suitable version of virtualenv" 12 | false 13 | fi 14 | 15 | SOURCE="${BASH_SOURCE[0]}" 16 | while [ -h "$SOURCE" ]; do 17 | DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" 18 | SOURCE="$(readlink "$SOURCE")" 19 | [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" 20 | done 21 | TEST_DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" 22 | 23 | [ -d $TEST_DIR/python-virtual-env ] || $VIRTUALENV_EXEC --system-site-packages $TEST_DIR/python-virtual-env 24 | source $TEST_DIR/python-virtual-env/bin/activate 25 | pip install -r $TEST_DIR/requirements.txt > /dev/null 26 | # force installation of nose in virtualenv even if existing in thereuser's system 27 | pip install nose -I 28 | pip install --upgrade --no-deps --force-reinstall -e $TEST_DIR/../.. 29 | cd $TEST_DIR 30 | nosetests --with-doctest -v --nocapture 31 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://travis-ci.org/ethereum/ethash.svg?branch=master)](https://travis-ci.org/ethereum/ethash) 2 | [![Windows Build Status](https://ci.appveyor.com/api/projects/status/github/debris/ethash?branch=master&svg=true)](https://ci.appveyor.com/project/debris/ethash-nr37r/branch/master) 3 | 4 | # Ethash 5 | 6 | For details on this project, please see the Ethereum wiki: 7 | https://github.com/ethereum/wiki/wiki/Ethash 8 | 9 | ### Coding Style for C++ code: 10 | 11 | Follow the same exact style as in [cpp-ethereum](https://github.com/ethereum/cpp-ethereum/blob/develop/CodingStandards.txt) 12 | 13 | ### Coding Style for C code: 14 | 15 | The main thing above all is code consistency. 16 | 17 | - Tabs for indentation. A tab is 4 spaces 18 | - Try to stick to the [K&R](http://en.wikipedia.org/wiki/Indent_style#K.26R_style), 19 | especially for the C code. 20 | - Keep the line lengths reasonable. No hard limit on 80 characters but don't go further 21 | than 110. Some people work with multiple buffers next to each other. 22 | Make them like you :) 23 | -------------------------------------------------------------------------------- /src/libethash/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LIBRARY ethash) 2 | 3 | if (CPPETHEREUM) 4 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") 5 | endif () 6 | 7 | set(CMAKE_BUILD_TYPE Release) 8 | 9 | if (NOT MSVC) 10 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99") 11 | endif() 12 | 13 | set(FILES util.h 14 | io.c 15 | internal.c 16 | ethash.h 17 | endian.h 18 | compiler.h 19 | fnv.h 20 | data_sizes.h) 21 | 22 | if (MSVC) 23 | list(APPEND FILES util_win32.c io_win32.c mmap_win32.c) 24 | else() 25 | list(APPEND FILES io_posix.c) 26 | endif() 27 | 28 | if (NOT CRYPTOPP_FOUND) 29 | find_package(CryptoPP 5.6.2) 30 | endif() 31 | 32 | if (CRYPTOPP_FOUND) 33 | add_definitions(-DWITH_CRYPTOPP) 34 | include_directories( ${CRYPTOPP_INCLUDE_DIRS} ) 35 | list(APPEND FILES sha3_cryptopp.cpp sha3_cryptopp.h) 36 | else() 37 | list(APPEND FILES sha3.c sha3.h) 38 | endif() 39 | 40 | add_library(${LIBRARY} ${FILES}) 41 | 42 | if (CRYPTOPP_FOUND) 43 | TARGET_LINK_LIBRARIES(${LIBRARY} ${CRYPTOPP_LIBRARIES}) 44 | endif() 45 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | version: 1.0.0.{build} 2 | 3 | environment: 4 | BOOST_ROOT: "c:/projects/ethash/deps/boost" 5 | 6 | branches: 7 | only: 8 | - master 9 | - develop 10 | 11 | os: Windows Server 2012 R2 12 | 13 | clone_folder: c:\projects\ethash 14 | 15 | #platform: Any CPU 16 | #configuration: Debug 17 | 18 | install: 19 | # by default, all script lines are interpreted as batch 20 | 21 | # scripts to run before build 22 | before_build: 23 | - echo "Downloading boost..." 24 | - mkdir c:\projects\ethash\deps 25 | - cd c:\projects\ethash\deps 26 | - curl -O https://build.ethdev.com/builds/windows-precompiled/boost.tar.gz 27 | - echo "Unzipping boost..." 28 | - 7z x boost.tar.gz > nul 29 | - 7z x boost.tar > nul 30 | - ls 31 | - echo "Running cmake..." 32 | - cd c:\projects\ethash 33 | - cmake . 34 | 35 | build: 36 | project: ALL_BUILD.vcxproj # path to Visual Studio solution or project 37 | 38 | after_build: 39 | - echo "Running tests..." 40 | - cd c:\projects\ethash\test\c\Debug 41 | - Test.exe 42 | - echo "Finished!" 43 | 44 | -------------------------------------------------------------------------------- /compat.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 ethash 18 | 19 | import ( 20 | "math/big" 21 | 22 | "github.com/ethereum/go-ethereum/common" 23 | ) 24 | 25 | type Block interface { 26 | Difficulty() *big.Int 27 | HashNoNonce() common.Hash 28 | Nonce() uint64 29 | MixDigest() common.Hash 30 | NumberU64() uint64 31 | } 32 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/src/basic-config.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2013, 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_BASIC_CONFIG_ 8 | #define _SECP256K1_BASIC_CONFIG_ 9 | 10 | #ifdef USE_BASIC_CONFIG 11 | 12 | #undef USE_ASM_X86_64 13 | #undef USE_ENDOMORPHISM 14 | #undef USE_FIELD_10X26 15 | #undef USE_FIELD_5X52 16 | #undef USE_FIELD_INV_BUILTIN 17 | #undef USE_FIELD_INV_NUM 18 | #undef USE_NUM_GMP 19 | #undef USE_NUM_NONE 20 | #undef USE_SCALAR_4X64 21 | #undef USE_SCALAR_8X32 22 | #undef USE_SCALAR_INV_BUILTIN 23 | #undef USE_SCALAR_INV_NUM 24 | 25 | #define USE_NUM_NONE 1 26 | #define USE_FIELD_INV_BUILTIN 1 27 | #define USE_SCALAR_INV_BUILTIN 1 28 | #define USE_FIELD_10X26 1 29 | #define USE_SCALAR_8X32 1 30 | 31 | #endif // USE_BASIC_CONFIG 32 | #endif // _SECP256K1_BASIC_CONFIG_ 33 | -------------------------------------------------------------------------------- /src/libethash/compiler.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU 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 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file compiler.h 18 | * @date 2014 19 | */ 20 | #pragma once 21 | 22 | // Visual Studio doesn't support the inline keyword in C mode 23 | #if defined(_MSC_VER) && !defined(__cplusplus) 24 | #define inline __inline 25 | #endif 26 | 27 | // pretend restrict is a standard keyword 28 | #if defined(_MSC_VER) 29 | #define restrict __restrict 30 | #else 31 | #define restrict __restrict__ 32 | #endif 33 | 34 | -------------------------------------------------------------------------------- /js/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Tim Hughes 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/COPYING: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 Pieter Wuille 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/include/secp256k1_ecdh.h: -------------------------------------------------------------------------------- 1 | #ifndef _SECP256K1_ECDH_ 2 | # define _SECP256K1_ECDH_ 3 | 4 | # include "secp256k1.h" 5 | 6 | # ifdef __cplusplus 7 | extern "C" { 8 | # endif 9 | 10 | /** Compute an EC Diffie-Hellman secret in constant time 11 | * Returns: 1: exponentiation was successful 12 | * 0: scalar was invalid (zero or overflow) 13 | * Args: ctx: pointer to a context object (cannot be NULL) 14 | * Out: result: a 32-byte array which will be populated by an ECDH 15 | * secret computed from the point and scalar 16 | * In: pubkey: a pointer to a secp256k1_pubkey containing an 17 | * initialized public key 18 | * privkey: a 32-byte scalar with which to multiply the point 19 | */ 20 | SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ecdh( 21 | const secp256k1_context* ctx, 22 | unsigned char *result, 23 | const secp256k1_pubkey *pubkey, 24 | const unsigned char *privkey 25 | ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4); 26 | 27 | # ifdef __cplusplus 28 | } 29 | # endif 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /src/libethash/sha3_cryptopp.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of ethash. 3 | 4 | ethash is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU 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 | ethash is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with ethash. If not, see . 16 | */ 17 | 18 | /** @file sha3.cpp 19 | * @author Tim Hughes 20 | * @date 2015 21 | */ 22 | #include 23 | #include 24 | 25 | extern "C" { 26 | struct ethash_h256; 27 | typedef struct ethash_h256 ethash_h256_t; 28 | void SHA3_256(ethash_h256_t const* ret, uint8_t const* data, size_t size) 29 | { 30 | CryptoPP::SHA3_256().CalculateDigest((uint8_t*)ret, data, size); 31 | } 32 | 33 | void SHA3_512(uint8_t* const ret, uint8_t const* data, size_t size) 34 | { 35 | CryptoPP::SHA3_512().CalculateDigest(ret, data, size); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/src/ecdsa.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2013, 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_ECDSA_ 8 | #define _SECP256K1_ECDSA_ 9 | 10 | #include 11 | 12 | #include "scalar.h" 13 | #include "group.h" 14 | #include "ecmult.h" 15 | 16 | static int secp256k1_ecdsa_sig_parse(secp256k1_scalar *r, secp256k1_scalar *s, const unsigned char *sig, size_t size); 17 | static int secp256k1_ecdsa_sig_serialize(unsigned char *sig, size_t *size, const secp256k1_scalar *r, const secp256k1_scalar *s); 18 | static int secp256k1_ecdsa_sig_verify(const secp256k1_ecmult_context *ctx, const secp256k1_scalar* r, const secp256k1_scalar* s, const secp256k1_ge *pubkey, const secp256k1_scalar *message); 19 | static int secp256k1_ecdsa_sig_sign(const secp256k1_ecmult_gen_context *ctx, secp256k1_scalar* r, secp256k1_scalar* s, const secp256k1_scalar *seckey, const secp256k1_scalar *message, const secp256k1_scalar *nonce, int *recid); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /src/libethash/util_win32.c: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU 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 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file util.c 18 | * @author Tim Hughes 19 | * @date 2015 20 | */ 21 | #include 22 | #include 23 | #include "util.h" 24 | 25 | 26 | // foward declare without all of Windows.h 27 | __declspec(dllimport) void __stdcall OutputDebugStringA(char const* lpOutputString); 28 | 29 | void debugf(char const* str, ...) 30 | { 31 | va_list args; 32 | va_start(args, str); 33 | 34 | char buf[1<<16]; 35 | _vsnprintf_s(buf, sizeof(buf), sizeof(buf), str, args); 36 | buf[sizeof(buf)-1] = '\0'; 37 | OutputDebugStringA(buf); 38 | } 39 | -------------------------------------------------------------------------------- /src/libethash/util.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of ethash. 3 | 4 | ethash is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU 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 | ethash is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with ethash. If not, see . 16 | */ 17 | /** @file util.h 18 | * @author Tim Hughes 19 | * @date 2015 20 | */ 21 | #pragma once 22 | #include 23 | #include "compiler.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | #ifdef _MSC_VER 30 | void debugf(char const* str, ...); 31 | #else 32 | #define debugf printf 33 | #endif 34 | 35 | static inline uint32_t min_u32(uint32_t a, uint32_t b) 36 | { 37 | return a < b ? a : b; 38 | } 39 | 40 | static inline uint32_t clamp_u32(uint32_t x, uint32_t min_, uint32_t max_) 41 | { 42 | return x < min_ ? min_ : (x > max_ ? max_ : x); 43 | } 44 | 45 | #ifdef __cplusplus 46 | } 47 | #endif 48 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/src/eckey.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2013, 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_ECKEY_ 8 | #define _SECP256K1_ECKEY_ 9 | 10 | #include 11 | 12 | #include "group.h" 13 | #include "scalar.h" 14 | #include "ecmult.h" 15 | #include "ecmult_gen.h" 16 | 17 | static int secp256k1_eckey_pubkey_parse(secp256k1_ge *elem, const unsigned char *pub, size_t size); 18 | static int secp256k1_eckey_pubkey_serialize(secp256k1_ge *elem, unsigned char *pub, size_t *size, int compressed); 19 | 20 | static int secp256k1_eckey_privkey_tweak_add(secp256k1_scalar *key, const secp256k1_scalar *tweak); 21 | static int secp256k1_eckey_pubkey_tweak_add(const secp256k1_ecmult_context *ctx, secp256k1_ge *key, const secp256k1_scalar *tweak); 22 | static int secp256k1_eckey_privkey_tweak_mul(secp256k1_scalar *key, const secp256k1_scalar *tweak); 23 | static int secp256k1_eckey_pubkey_tweak_mul(const secp256k1_ecmult_context *ctx, secp256k1_ge *key, const secp256k1_scalar *tweak); 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/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 | // +build amd64 386 ppc64le 6 | // +build !appengine 7 | 8 | package sha3 9 | 10 | import "unsafe" 11 | 12 | func xorInUnaligned(d *state, buf []byte) { 13 | bw := (*[maxRate / 8]uint64)(unsafe.Pointer(&buf[0])) 14 | n := len(buf) 15 | if n >= 72 { 16 | d.a[0] ^= bw[0] 17 | d.a[1] ^= bw[1] 18 | d.a[2] ^= bw[2] 19 | d.a[3] ^= bw[3] 20 | d.a[4] ^= bw[4] 21 | d.a[5] ^= bw[5] 22 | d.a[6] ^= bw[6] 23 | d.a[7] ^= bw[7] 24 | d.a[8] ^= bw[8] 25 | } 26 | if n >= 104 { 27 | d.a[9] ^= bw[9] 28 | d.a[10] ^= bw[10] 29 | d.a[11] ^= bw[11] 30 | d.a[12] ^= bw[12] 31 | } 32 | if n >= 136 { 33 | d.a[13] ^= bw[13] 34 | d.a[14] ^= bw[14] 35 | d.a[15] ^= bw[15] 36 | d.a[16] ^= bw[16] 37 | } 38 | if n >= 144 { 39 | d.a[17] ^= bw[17] 40 | } 41 | if n >= 168 { 42 | d.a[18] ^= bw[18] 43 | d.a[19] ^= bw[19] 44 | d.a[20] ^= bw[20] 45 | } 46 | } 47 | 48 | func copyOutUnaligned(d *state, buf []byte) { 49 | ab := (*[maxRate]uint8)(unsafe.Pointer(&d.a[0])) 50 | copy(buf, ab[:]) 51 | } 52 | 53 | var ( 54 | xorIn = xorInUnaligned 55 | copyOut = copyOutUnaligned 56 | ) 57 | 58 | const xorImplementationUnaligned = "unaligned" 59 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/panic_cb.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 secp256k1 18 | 19 | import "C" 20 | import "unsafe" 21 | 22 | // Callbacks for converting libsecp256k1 internal faults into 23 | // recoverable Go panics. 24 | 25 | //export secp256k1GoPanicIllegal 26 | func secp256k1GoPanicIllegal(msg *C.char, data unsafe.Pointer) { 27 | panic("illegal argument: " + C.GoString(msg)) 28 | } 29 | 30 | //export secp256k1GoPanicError 31 | func secp256k1GoPanicError(msg *C.char, data unsafe.Pointer) { 32 | panic("internal error: " + C.GoString(msg)) 33 | } 34 | -------------------------------------------------------------------------------- /src/libethash/fnv.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU 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 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file fnv.h 18 | * @author Matthew Wampler-Doty 19 | * @date 2015 20 | */ 21 | 22 | #pragma once 23 | #include 24 | #include "compiler.h" 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | #define FNV_PRIME 0x01000193 31 | 32 | /* The FNV-1 spec multiplies the prime with the input one byte (octet) in turn. 33 | We instead multiply it with the full 32-bit input. 34 | This gives a different result compared to a canonical FNV-1 implementation. 35 | */ 36 | static inline uint32_t fnv_hash(uint32_t const x, uint32_t const y) 37 | { 38 | return x * FNV_PRIME ^ y; 39 | } 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/crypto/sha3/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 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os 3 | from distutils.core import setup, Extension 4 | sources = [ 5 | 'src/python/core.c', 6 | 'src/libethash/io.c', 7 | 'src/libethash/internal.c', 8 | 'src/libethash/sha3.c'] 9 | if os.name == 'nt': 10 | sources += [ 11 | 'src/libethash/util_win32.c', 12 | 'src/libethash/io_win32.c', 13 | 'src/libethash/mmap_win32.c', 14 | ] 15 | else: 16 | sources += [ 17 | 'src/libethash/io_posix.c' 18 | ] 19 | depends = [ 20 | 'src/libethash/ethash.h', 21 | 'src/libethash/compiler.h', 22 | 'src/libethash/data_sizes.h', 23 | 'src/libethash/endian.h', 24 | 'src/libethash/ethash.h', 25 | 'src/libethash/io.h', 26 | 'src/libethash/fnv.h', 27 | 'src/libethash/internal.h', 28 | 'src/libethash/sha3.h', 29 | 'src/libethash/util.h', 30 | ] 31 | pyethash = Extension('pyethash', 32 | sources=sources, 33 | depends=depends, 34 | extra_compile_args=["-Isrc/", "-std=gnu99", "-Wall"]) 35 | 36 | setup( 37 | name='pyethash', 38 | author="Matthew Wampler-Doty", 39 | author_email="matthew.wampler.doty@gmail.com", 40 | license='GPL', 41 | version='0.1.23', 42 | url='https://github.com/ethereum/ethash', 43 | download_url='https://github.com/ethereum/ethash/tarball/v23', 44 | description=('Python wrappers for ethash, the ethereum proof of work' 45 | 'hashing function'), 46 | ext_modules=[pyethash], 47 | ) 48 | -------------------------------------------------------------------------------- /src/libethash/mmap.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of ethash. 3 | 4 | ethash is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU 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 | ethash is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with ethash. If not, see . 16 | */ 17 | /** @file mmap.h 18 | * @author Lefteris Karapetsas 19 | * @date 2015 20 | */ 21 | #pragma once 22 | #if defined(__MINGW32__) || defined(_WIN32) 23 | #include 24 | 25 | #define PROT_READ 0x1 26 | #define PROT_WRITE 0x2 27 | /* This flag is only available in WinXP+ */ 28 | #ifdef FILE_MAP_EXECUTE 29 | #define PROT_EXEC 0x4 30 | #else 31 | #define PROT_EXEC 0x0 32 | #define FILE_MAP_EXECUTE 0 33 | #endif 34 | 35 | #define MAP_SHARED 0x01 36 | #define MAP_PRIVATE 0x02 37 | #define MAP_ANONYMOUS 0x20 38 | #define MAP_ANON MAP_ANONYMOUS 39 | #define MAP_FAILED ((void *) -1) 40 | 41 | void* mmap(void* start, size_t length, int prot, int flags, int fd, off_t offset); 42 | void munmap(void* addr, size_t length); 43 | #else // posix, yay! ^_^ 44 | #include 45 | #endif 46 | 47 | 48 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/crypto/sha3/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009 The Go Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/src/ecmult.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2013, 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_ECMULT_ 8 | #define _SECP256K1_ECMULT_ 9 | 10 | #include "num.h" 11 | #include "group.h" 12 | 13 | typedef struct { 14 | /* For accelerating the computation of a*P + b*G: */ 15 | secp256k1_ge_storage (*pre_g)[]; /* odd multiples of the generator */ 16 | #ifdef USE_ENDOMORPHISM 17 | secp256k1_ge_storage (*pre_g_128)[]; /* odd multiples of 2^128*generator */ 18 | #endif 19 | } secp256k1_ecmult_context; 20 | 21 | static void secp256k1_ecmult_context_init(secp256k1_ecmult_context *ctx); 22 | static void secp256k1_ecmult_context_build(secp256k1_ecmult_context *ctx, const secp256k1_callback *cb); 23 | static void secp256k1_ecmult_context_clone(secp256k1_ecmult_context *dst, 24 | const secp256k1_ecmult_context *src, const secp256k1_callback *cb); 25 | static void secp256k1_ecmult_context_clear(secp256k1_ecmult_context *ctx); 26 | static int secp256k1_ecmult_context_is_built(const secp256k1_ecmult_context *ctx); 27 | 28 | /** Double multiply: R = na*A + ng*G */ 29 | static void secp256k1_ecmult(const secp256k1_ecmult_context *ctx, secp256k1_gej *r, const secp256k1_gej *a, const secp256k1_scalar *na, const secp256k1_scalar *ng); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/rlp/doc.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 | /* 18 | Package rlp implements the RLP serialization format. 19 | 20 | The purpose of RLP (Recursive Linear Prefix) qis to encode arbitrarily 21 | nested arrays of binary data, and RLP is the main encoding method used 22 | to serialize objects in Ethereum. The only purpose of RLP is to encode 23 | structure; encoding specific atomic data types (eg. strings, ints, 24 | floats) is left up to higher-order protocols; in Ethereum integers 25 | must be represented in big endian binary form with no leading zeroes 26 | (thus making the integer value zero be equivalent to the empty byte 27 | array). 28 | 29 | RLP values are distinguished by a type tag. The type tag precedes the 30 | value in the input stream and defines the size and kind of the bytes 31 | that follow. 32 | */ 33 | package rlp 34 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/src/testrand.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2013, 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_TESTRAND_H_ 8 | #define _SECP256K1_TESTRAND_H_ 9 | 10 | #if defined HAVE_CONFIG_H 11 | #include "libsecp256k1-config.h" 12 | #endif 13 | 14 | /* A non-cryptographic RNG used only for test infrastructure. */ 15 | 16 | /** Seed the pseudorandom number generator for testing. */ 17 | SECP256K1_INLINE static void secp256k1_rand_seed(const unsigned char *seed16); 18 | 19 | /** Generate a pseudorandom number in the range [0..2**32-1]. */ 20 | static uint32_t secp256k1_rand32(void); 21 | 22 | /** Generate a pseudorandom number in the range [0..2**bits-1]. Bits must be 1 or 23 | * more. */ 24 | static uint32_t secp256k1_rand_bits(int bits); 25 | 26 | /** Generate a pseudorandom number in the range [0..range-1]. */ 27 | static uint32_t secp256k1_rand_int(uint32_t range); 28 | 29 | /** Generate a pseudorandom 32-byte array. */ 30 | static void secp256k1_rand256(unsigned char *b32); 31 | 32 | /** Generate a pseudorandom 32-byte array with long sequences of zero and one bits. */ 33 | static void secp256k1_rand256_test(unsigned char *b32); 34 | 35 | /** Generate pseudorandom bytes with long sequences of zero and one bits. */ 36 | static void secp256k1_rand_bytes_test(unsigned char *bytes, size_t len); 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /vendor/github.com/go-stack/stack/README.md: -------------------------------------------------------------------------------- 1 | [![GoDoc](https://godoc.org/github.com/go-stack/stack?status.svg)](https://godoc.org/github.com/go-stack/stack) 2 | [![Go Report Card](https://goreportcard.com/badge/go-stack/stack)](https://goreportcard.com/report/go-stack/stack) 3 | [![TravisCI](https://travis-ci.org/go-stack/stack.svg?branch=master)](https://travis-ci.org/go-stack/stack) 4 | [![Coverage Status](https://coveralls.io/repos/github/go-stack/stack/badge.svg?branch=master)](https://coveralls.io/github/go-stack/stack?branch=master) 5 | 6 | # stack 7 | 8 | Package stack implements utilities to capture, manipulate, and format call 9 | stacks. It provides a simpler API than package runtime. 10 | 11 | The implementation takes care of the minutia and special cases of interpreting 12 | the program counter (pc) values returned by runtime.Callers. 13 | 14 | ## Versioning 15 | 16 | Package stack publishes releases via [semver](http://semver.org/) compatible Git 17 | tags prefixed with a single 'v'. The master branch always contains the latest 18 | release. The develop branch contains unreleased commits. 19 | 20 | ## Formatting 21 | 22 | Package stack's types implement fmt.Formatter, which provides a simple and 23 | flexible way to declaratively configure formatting when used with logging or 24 | error tracking packages. 25 | 26 | ```go 27 | func DoTheThing() { 28 | c := stack.Caller(0) 29 | log.Print(c) // "source.go:10" 30 | log.Printf("%+v", c) // "pkg/path/source.go:10" 31 | log.Printf("%n", c) // "DoTheThing" 32 | 33 | s := stack.Trace().TrimRuntime() 34 | log.Print(s) // "[source.go:15 caller.go:42 main.go:14]" 35 | } 36 | ``` 37 | 38 | See the docs for all of the supported formatting options. 39 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/log/root.go: -------------------------------------------------------------------------------- 1 | package log 2 | 3 | import ( 4 | "os" 5 | ) 6 | 7 | var ( 8 | root = &logger{[]interface{}{}, new(swapHandler)} 9 | StdoutHandler = StreamHandler(os.Stdout, LogfmtFormat()) 10 | StderrHandler = StreamHandler(os.Stderr, LogfmtFormat()) 11 | ) 12 | 13 | func init() { 14 | root.SetHandler(DiscardHandler()) 15 | } 16 | 17 | // New returns a new logger with the given context. 18 | // New is a convenient alias for Root().New 19 | func New(ctx ...interface{}) Logger { 20 | return root.New(ctx...) 21 | } 22 | 23 | // Root returns the root logger 24 | func Root() Logger { 25 | return root 26 | } 27 | 28 | // The following functions bypass the exported logger methods (logger.Debug, 29 | // etc.) to keep the call depth the same for all paths to logger.write so 30 | // runtime.Caller(2) always refers to the call site in client code. 31 | 32 | // Trace is a convenient alias for Root().Trace 33 | func Trace(msg string, ctx ...interface{}) { 34 | root.write(msg, LvlTrace, ctx) 35 | } 36 | 37 | // Debug is a convenient alias for Root().Debug 38 | func Debug(msg string, ctx ...interface{}) { 39 | root.write(msg, LvlDebug, ctx) 40 | } 41 | 42 | // Info is a convenient alias for Root().Info 43 | func Info(msg string, ctx ...interface{}) { 44 | root.write(msg, LvlInfo, ctx) 45 | } 46 | 47 | // Warn is a convenient alias for Root().Warn 48 | func Warn(msg string, ctx ...interface{}) { 49 | root.write(msg, LvlWarn, ctx) 50 | } 51 | 52 | // Error is a convenient alias for Root().Error 53 | func Error(msg string, ctx ...interface{}) { 54 | root.write(msg, LvlError, ctx) 55 | } 56 | 57 | // Crit is a convenient alias for Root().Crit 58 | func Crit(msg string, ctx ...interface{}) { 59 | root.write(msg, LvlCrit, ctx) 60 | os.Exit(1) 61 | } 62 | -------------------------------------------------------------------------------- /vendor/vendor.json: -------------------------------------------------------------------------------- 1 | { 2 | "comment": "", 3 | "ignore": "test", 4 | "package": [ 5 | { 6 | "checksumSHA1": "Eu4iBa1TK3Y5ZQkP4RUi0XTw6tY=", 7 | "path": "github.com/btcsuite/btcd/btcec", 8 | "revision": "4b348c1d33373d672edd83fc576892d0e46686d2", 9 | "revisionTime": "2017-03-22T18:48:02Z" 10 | }, 11 | { 12 | "checksumSHA1": "exEIOkzQrq9M+59RLaXEwhDxGUo=", 13 | "path": "github.com/ethereum/go-ethereum/crypto", 14 | "revision": "cc13d576f07fb6803e09fb42880591a67b8b0ef6", 15 | "revisionTime": "2017-04-07T08:03:11Z" 16 | }, 17 | { 18 | "checksumSHA1": "TMVztwYLcQlIio/kEqbF8TQYWYg=", 19 | "path": "github.com/ethereum/go-ethereum/crypto/secp256k1", 20 | "revision": "cc13d576f07fb6803e09fb42880591a67b8b0ef6", 21 | "revisionTime": "2017-04-07T08:03:11Z", 22 | "tree": true 23 | }, 24 | { 25 | "checksumSHA1": "yunX3AjO6JiMz0NSY/krvG3VWsk=", 26 | "path": "github.com/ethereum/go-ethereum/crypto/sha3", 27 | "revision": "cc13d576f07fb6803e09fb42880591a67b8b0ef6", 28 | "revisionTime": "2017-04-07T08:03:11Z" 29 | }, 30 | { 31 | "checksumSHA1": "NbRntdNRuwam0wGGNJ6HrR83P0M=", 32 | "path": "github.com/ethereum/go-ethereum/log", 33 | "revision": "cc13d576f07fb6803e09fb42880591a67b8b0ef6", 34 | "revisionTime": "2017-04-07T08:03:11Z" 35 | }, 36 | { 37 | "checksumSHA1": "ERaBPyDJCbMQRJsR6Kpqkr7dqfg=", 38 | "path": "github.com/ethereum/go-ethereum/rlp", 39 | "revision": "cc13d576f07fb6803e09fb42880591a67b8b0ef6", 40 | "revisionTime": "2017-04-07T08:03:11Z" 41 | }, 42 | { 43 | "checksumSHA1": "2sj/DbXoXdnPAfjAEyhS0Jj5QL0=", 44 | "path": "github.com/go-stack/stack", 45 | "revision": "100eb0c0a9c5b306ca2fb4f165df21d80ada4b82", 46 | "revisionTime": "2016-05-14T03:44:11Z" 47 | } 48 | ], 49 | "rootPath": "github.com/ethereum/ethash" 50 | } 51 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/src/java/org/bitcoin/NativeSecp256k1Util.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2016 the libsecp256k1 contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.bitcoin; 18 | 19 | public class NativeSecp256k1Util{ 20 | 21 | public static void assertEquals( int val, int val2, String message ) throws AssertFailException{ 22 | if( val != val2 ) 23 | throw new AssertFailException("FAIL: " + message); 24 | } 25 | 26 | public static void assertEquals( boolean val, boolean val2, String message ) throws AssertFailException{ 27 | if( val != val2 ) 28 | throw new AssertFailException("FAIL: " + message); 29 | else 30 | System.out.println("PASS: " + message); 31 | } 32 | 33 | public static void assertEquals( String val, String val2, String message ) throws AssertFailException{ 34 | if( !val.equals(val2) ) 35 | throw new AssertFailException("FAIL: " + message); 36 | else 37 | System.out.println("PASS: " + message); 38 | } 39 | 40 | public static class AssertFailException extends Exception { 41 | public AssertFailException(String message) { 42 | super( message ); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/src/java/org/bitcoin/Secp256k1Context.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2016 the libsecp256k1 contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.bitcoin; 18 | 19 | /** 20 | * This class holds the context reference used in native methods 21 | * to handle ECDSA operations. 22 | */ 23 | public class Secp256k1Context { 24 | private static final boolean enabled; //true if the library is loaded 25 | private static final long context; //ref to pointer to context obj 26 | 27 | static { //static initializer 28 | boolean isEnabled = true; 29 | long contextRef = -1; 30 | try { 31 | System.loadLibrary("secp256k1"); 32 | contextRef = secp256k1_init_context(); 33 | } catch (UnsatisfiedLinkError e) { 34 | System.out.println("UnsatisfiedLinkError: " + e.toString()); 35 | isEnabled = false; 36 | } 37 | enabled = isEnabled; 38 | context = contextRef; 39 | } 40 | 41 | public static boolean isEnabled() { 42 | return enabled; 43 | } 44 | 45 | public static long getContext() { 46 | if(!enabled) return -1; //sanity check 47 | return context; 48 | } 49 | 50 | private static native long secp256k1_init_context(); 51 | } 52 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/src/bench_sign.c: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #include "include/secp256k1.h" 8 | #include "util.h" 9 | #include "bench.h" 10 | 11 | typedef struct { 12 | secp256k1_context* ctx; 13 | unsigned char msg[32]; 14 | unsigned char key[32]; 15 | } bench_sign_t; 16 | 17 | static void bench_sign_setup(void* arg) { 18 | int i; 19 | bench_sign_t *data = (bench_sign_t*)arg; 20 | 21 | for (i = 0; i < 32; i++) { 22 | data->msg[i] = i + 1; 23 | } 24 | for (i = 0; i < 32; i++) { 25 | data->key[i] = i + 65; 26 | } 27 | } 28 | 29 | static void bench_sign(void* arg) { 30 | int i; 31 | bench_sign_t *data = (bench_sign_t*)arg; 32 | 33 | unsigned char sig[74]; 34 | for (i = 0; i < 20000; i++) { 35 | size_t siglen = 74; 36 | int j; 37 | secp256k1_ecdsa_signature signature; 38 | CHECK(secp256k1_ecdsa_sign(data->ctx, &signature, data->msg, data->key, NULL, NULL)); 39 | CHECK(secp256k1_ecdsa_signature_serialize_der(data->ctx, sig, &siglen, &signature)); 40 | for (j = 0; j < 32; j++) { 41 | data->msg[j] = sig[j]; 42 | data->key[j] = sig[j + 32]; 43 | } 44 | } 45 | } 46 | 47 | int main(void) { 48 | bench_sign_t data; 49 | 50 | data.ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN); 51 | 52 | run_benchmark("ecdsa_sign", bench_sign, bench_sign_setup, NULL, &data, 10, 20000); 53 | 54 | secp256k1_context_destroy(data.ctx); 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/log/syslog.go: -------------------------------------------------------------------------------- 1 | // +build !windows,!plan9 2 | 3 | package log 4 | 5 | import ( 6 | "log/syslog" 7 | "strings" 8 | ) 9 | 10 | // SyslogHandler opens a connection to the system syslog daemon by calling 11 | // syslog.New and writes all records to it. 12 | func SyslogHandler(priority syslog.Priority, tag string, fmtr Format) (Handler, error) { 13 | wr, err := syslog.New(priority, tag) 14 | return sharedSyslog(fmtr, wr, err) 15 | } 16 | 17 | // SyslogNetHandler opens a connection to a log daemon over the network and writes 18 | // all log records to it. 19 | func SyslogNetHandler(net, addr string, priority syslog.Priority, tag string, fmtr Format) (Handler, error) { 20 | wr, err := syslog.Dial(net, addr, priority, tag) 21 | return sharedSyslog(fmtr, wr, err) 22 | } 23 | 24 | func sharedSyslog(fmtr Format, sysWr *syslog.Writer, err error) (Handler, error) { 25 | if err != nil { 26 | return nil, err 27 | } 28 | h := FuncHandler(func(r *Record) error { 29 | var syslogFn = sysWr.Info 30 | switch r.Lvl { 31 | case LvlCrit: 32 | syslogFn = sysWr.Crit 33 | case LvlError: 34 | syslogFn = sysWr.Err 35 | case LvlWarn: 36 | syslogFn = sysWr.Warning 37 | case LvlInfo: 38 | syslogFn = sysWr.Info 39 | case LvlDebug: 40 | syslogFn = sysWr.Debug 41 | case LvlTrace: 42 | syslogFn = func(m string) error { return nil } // There's no syslog level for trace 43 | } 44 | 45 | s := strings.TrimSpace(string(fmtr.Format(r))) 46 | return syslogFn(s) 47 | }) 48 | return LazyHandler(&closingHandler{sysWr, h}), nil 49 | } 50 | 51 | func (m muster) SyslogHandler(priority syslog.Priority, tag string, fmtr Format) Handler { 52 | return must(SyslogHandler(priority, tag, fmtr)) 53 | } 54 | 55 | func (m muster) SyslogNetHandler(net, addr string, priority syslog.Priority, tag string, fmtr Format) Handler { 56 | return must(SyslogNetHandler(net, addr, priority, tag, fmtr)) 57 | } 58 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/src/hash.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_HASH_ 8 | #define _SECP256K1_HASH_ 9 | 10 | #include 11 | #include 12 | 13 | typedef struct { 14 | uint32_t s[8]; 15 | uint32_t buf[16]; /* In big endian */ 16 | size_t bytes; 17 | } secp256k1_sha256_t; 18 | 19 | static void secp256k1_sha256_initialize(secp256k1_sha256_t *hash); 20 | static void secp256k1_sha256_write(secp256k1_sha256_t *hash, const unsigned char *data, size_t size); 21 | static void secp256k1_sha256_finalize(secp256k1_sha256_t *hash, unsigned char *out32); 22 | 23 | typedef struct { 24 | secp256k1_sha256_t inner, outer; 25 | } secp256k1_hmac_sha256_t; 26 | 27 | static void secp256k1_hmac_sha256_initialize(secp256k1_hmac_sha256_t *hash, const unsigned char *key, size_t size); 28 | static void secp256k1_hmac_sha256_write(secp256k1_hmac_sha256_t *hash, const unsigned char *data, size_t size); 29 | static void secp256k1_hmac_sha256_finalize(secp256k1_hmac_sha256_t *hash, unsigned char *out32); 30 | 31 | typedef struct { 32 | unsigned char v[32]; 33 | unsigned char k[32]; 34 | int retry; 35 | } secp256k1_rfc6979_hmac_sha256_t; 36 | 37 | static void secp256k1_rfc6979_hmac_sha256_initialize(secp256k1_rfc6979_hmac_sha256_t *rng, const unsigned char *key, size_t keylen); 38 | static void secp256k1_rfc6979_hmac_sha256_generate(secp256k1_rfc6979_hmac_sha256_t *rng, unsigned char *out, size_t outlen); 39 | static void secp256k1_rfc6979_hmac_sha256_finalize(secp256k1_rfc6979_hmac_sha256_t *rng); 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/src/bench_ecdh.c: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2015 Pieter Wuille, Andrew Poelstra * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #include 8 | 9 | #include "include/secp256k1.h" 10 | #include "include/secp256k1_ecdh.h" 11 | #include "util.h" 12 | #include "bench.h" 13 | 14 | typedef struct { 15 | secp256k1_context *ctx; 16 | secp256k1_pubkey point; 17 | unsigned char scalar[32]; 18 | } bench_ecdh_t; 19 | 20 | static void bench_ecdh_setup(void* arg) { 21 | int i; 22 | bench_ecdh_t *data = (bench_ecdh_t*)arg; 23 | const unsigned char point[] = { 24 | 0x03, 25 | 0x54, 0x94, 0xc1, 0x5d, 0x32, 0x09, 0x97, 0x06, 26 | 0xc2, 0x39, 0x5f, 0x94, 0x34, 0x87, 0x45, 0xfd, 27 | 0x75, 0x7c, 0xe3, 0x0e, 0x4e, 0x8c, 0x90, 0xfb, 28 | 0xa2, 0xba, 0xd1, 0x84, 0xf8, 0x83, 0xc6, 0x9f 29 | }; 30 | 31 | /* create a context with no capabilities */ 32 | data->ctx = secp256k1_context_create(SECP256K1_FLAGS_TYPE_CONTEXT); 33 | for (i = 0; i < 32; i++) { 34 | data->scalar[i] = i + 1; 35 | } 36 | CHECK(secp256k1_ec_pubkey_parse(data->ctx, &data->point, point, sizeof(point)) == 1); 37 | } 38 | 39 | static void bench_ecdh(void* arg) { 40 | int i; 41 | unsigned char res[32]; 42 | bench_ecdh_t *data = (bench_ecdh_t*)arg; 43 | 44 | for (i = 0; i < 20000; i++) { 45 | CHECK(secp256k1_ecdh(data->ctx, res, &data->point, data->scalar) == 1); 46 | } 47 | } 48 | 49 | int main(void) { 50 | bench_ecdh_t data; 51 | 52 | run_benchmark("ecdh", bench_ecdh, bench_ecdh_setup, NULL, &data, 10, 20000); 53 | return 0; 54 | } 55 | -------------------------------------------------------------------------------- /ethashc.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 ethash 18 | 19 | /* 20 | -mno-stack-arg-probe disables stack probing which avoids the function 21 | __chkstk_ms being linked. this avoids a clash of this symbol as we also 22 | separately link the secp256k1 lib which ends up defining this symbol 23 | 24 | 1. https://gcc.gnu.org/onlinedocs/gccint/Stack-Checking.html 25 | 2. https://groups.google.com/forum/#!msg/golang-dev/v1bziURSQ4k/88fXuJ24e-gJ 26 | 3. https://groups.google.com/forum/#!topic/golang-nuts/VNP6Mwz_B6o 27 | 28 | */ 29 | 30 | /* 31 | #cgo CFLAGS: -std=gnu99 -Wall 32 | #cgo windows CFLAGS: -mno-stack-arg-probe 33 | #cgo LDFLAGS: -lm 34 | 35 | #include "src/libethash/internal.c" 36 | #include "src/libethash/sha3.c" 37 | #include "src/libethash/io.c" 38 | 39 | #ifdef _WIN32 40 | # include "src/libethash/io_win32.c" 41 | # include "src/libethash/mmap_win32.c" 42 | #else 43 | # include "src/libethash/io_posix.c" 44 | #endif 45 | 46 | // 'gateway function' for calling back into go. 47 | extern int ethashGoCallback(unsigned); 48 | int ethashGoCallback_cgo(unsigned percent) { return ethashGoCallback(percent); } 49 | 50 | */ 51 | import "C" 52 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/src/field_5x52.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2013, 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_FIELD_REPR_ 8 | #define _SECP256K1_FIELD_REPR_ 9 | 10 | #include 11 | 12 | typedef struct { 13 | /* X = sum(i=0..4, elem[i]*2^52) mod n */ 14 | uint64_t n[5]; 15 | #ifdef VERIFY 16 | int magnitude; 17 | int normalized; 18 | #endif 19 | } secp256k1_fe; 20 | 21 | /* Unpacks a constant into a overlapping multi-limbed FE element. */ 22 | #define SECP256K1_FE_CONST_INNER(d7, d6, d5, d4, d3, d2, d1, d0) { \ 23 | (d0) | (((uint64_t)(d1) & 0xFFFFFUL) << 32), \ 24 | ((uint64_t)(d1) >> 20) | (((uint64_t)(d2)) << 12) | (((uint64_t)(d3) & 0xFFUL) << 44), \ 25 | ((uint64_t)(d3) >> 8) | (((uint64_t)(d4) & 0xFFFFFFFUL) << 24), \ 26 | ((uint64_t)(d4) >> 28) | (((uint64_t)(d5)) << 4) | (((uint64_t)(d6) & 0xFFFFUL) << 36), \ 27 | ((uint64_t)(d6) >> 16) | (((uint64_t)(d7)) << 16) \ 28 | } 29 | 30 | #ifdef VERIFY 31 | #define SECP256K1_FE_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {SECP256K1_FE_CONST_INNER((d7), (d6), (d5), (d4), (d3), (d2), (d1), (d0)), 1, 1} 32 | #else 33 | #define SECP256K1_FE_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {SECP256K1_FE_CONST_INNER((d7), (d6), (d5), (d4), (d3), (d2), (d1), (d0))} 34 | #endif 35 | 36 | typedef struct { 37 | uint64_t n[4]; 38 | } secp256k1_fe_storage; 39 | 40 | #define SECP256K1_FE_STORAGE_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {{ \ 41 | (d0) | (((uint64_t)(d1)) << 32), \ 42 | (d2) | (((uint64_t)(d3)) << 32), \ 43 | (d4) | (((uint64_t)(d5)) << 32), \ 44 | (d6) | (((uint64_t)(d7)) << 32) \ 45 | }} 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/src/bench.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_BENCH_H_ 8 | #define _SECP256K1_BENCH_H_ 9 | 10 | #include 11 | #include 12 | #include "sys/time.h" 13 | 14 | static double gettimedouble(void) { 15 | struct timeval tv; 16 | gettimeofday(&tv, NULL); 17 | return tv.tv_usec * 0.000001 + tv.tv_sec; 18 | } 19 | 20 | void print_number(double x) { 21 | double y = x; 22 | int c = 0; 23 | if (y < 0.0) { 24 | y = -y; 25 | } 26 | while (y < 100.0) { 27 | y *= 10.0; 28 | c++; 29 | } 30 | printf("%.*f", c, x); 31 | } 32 | 33 | void run_benchmark(char *name, void (*benchmark)(void*), void (*setup)(void*), void (*teardown)(void*), void* data, int count, int iter) { 34 | int i; 35 | double min = HUGE_VAL; 36 | double sum = 0.0; 37 | double max = 0.0; 38 | for (i = 0; i < count; i++) { 39 | double begin, total; 40 | if (setup != NULL) { 41 | setup(data); 42 | } 43 | begin = gettimedouble(); 44 | benchmark(data); 45 | total = gettimedouble() - begin; 46 | if (teardown != NULL) { 47 | teardown(data); 48 | } 49 | if (total < min) { 50 | min = total; 51 | } 52 | if (total > max) { 53 | max = total; 54 | } 55 | sum += total; 56 | } 57 | printf("%s: min ", name); 58 | print_number(min * 1000000.0 / iter); 59 | printf("us / avg "); 60 | print_number((sum / count) * 1000000.0 / iter); 61 | printf("us / max "); 62 | print_number(max * 1000000.0 / iter); 63 | printf("us\n"); 64 | } 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /vendor/github.com/btcsuite/btcd/btcec/genprecomps.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The btcsuite developers 2 | // Use of this source code is governed by an ISC 3 | // license that can be found in the LICENSE file. 4 | 5 | // This file is ignored during the regular build due to the following build tag. 6 | // It is called by go generate and used to automatically generate pre-computed 7 | // tables used to accelerate operations. 8 | // +build ignore 9 | 10 | package main 11 | 12 | import ( 13 | "bytes" 14 | "compress/zlib" 15 | "encoding/base64" 16 | "fmt" 17 | "log" 18 | "os" 19 | 20 | "github.com/btcsuite/btcd/btcec" 21 | ) 22 | 23 | func main() { 24 | fi, err := os.Create("secp256k1.go") 25 | if err != nil { 26 | log.Fatal(err) 27 | } 28 | defer fi.Close() 29 | 30 | // Compress the serialized byte points. 31 | serialized := btcec.S256().SerializedBytePoints() 32 | var compressed bytes.Buffer 33 | w := zlib.NewWriter(&compressed) 34 | if _, err := w.Write(serialized); err != nil { 35 | fmt.Println(err) 36 | os.Exit(1) 37 | } 38 | w.Close() 39 | 40 | // Encode the compressed byte points with base64. 41 | encoded := make([]byte, base64.StdEncoding.EncodedLen(compressed.Len())) 42 | base64.StdEncoding.Encode(encoded, compressed.Bytes()) 43 | 44 | fmt.Fprintln(fi, "// Copyright (c) 2015 The btcsuite developers") 45 | fmt.Fprintln(fi, "// Use of this source code is governed by an ISC") 46 | fmt.Fprintln(fi, "// license that can be found in the LICENSE file.") 47 | fmt.Fprintln(fi) 48 | fmt.Fprintln(fi, "package btcec") 49 | fmt.Fprintln(fi) 50 | fmt.Fprintln(fi, "// Auto-generated file (see genprecomps.go)") 51 | fmt.Fprintln(fi, "// DO NOT EDIT") 52 | fmt.Fprintln(fi) 53 | fmt.Fprintf(fi, "var secp256k1BytePoints = %q\n", string(encoded)) 54 | 55 | a1, b1, a2, b2 := btcec.S256().EndomorphismVectors() 56 | fmt.Println("The following values are the computed linearly " + 57 | "independent vectors needed to make use of the secp256k1 " + 58 | "endomorphism:") 59 | fmt.Printf("a1: %x\n", a1) 60 | fmt.Printf("b1: %x\n", b1) 61 | fmt.Printf("a2: %x\n", a2) 62 | fmt.Printf("b2: %x\n", b2) 63 | } 64 | -------------------------------------------------------------------------------- /test/c/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if (MSVC) 2 | if (NOT BOOST_ROOT) 3 | set (BOOST_ROOT "$ENV{BOOST_ROOT}") 4 | endif() 5 | set (CMAKE_PREFIX_PATH BOOST_ROOT) 6 | endif() 7 | 8 | IF( NOT Boost_FOUND ) 9 | # use multithreaded boost libraries, with -mt suffix 10 | set(Boost_USE_MULTITHREADED ON) 11 | 12 | if (MSVC) 13 | # TODO handle other msvc versions or it will fail find them 14 | set(Boost_COMPILER -vc120) 15 | # use static boost libraries *.lib 16 | set(Boost_USE_STATIC_LIBS ON) 17 | elseif (APPLE) 18 | 19 | # use static boost libraries *.a 20 | set(Boost_USE_STATIC_LIBS ON) 21 | 22 | elseif (UNIX) 23 | # use dynamic boost libraries .dll 24 | set(Boost_USE_STATIC_LIBS OFF) 25 | 26 | endif() 27 | find_package(Boost 1.48.0 COMPONENTS unit_test_framework system filesystem) 28 | ENDIF() 29 | 30 | IF (Boost_FOUND) 31 | message(STATUS "boost header: ${Boost_INCLUDE_DIRS}") 32 | message(STATUS "boost libs : ${Boost_LIBRARIES}") 33 | 34 | include_directories( ${Boost_INCLUDE_DIR} ) 35 | include_directories(../../src) 36 | 37 | link_directories(${Boost_LIBRARY_DIRS}) 38 | file(GLOB HEADERS "*.h") 39 | if ((NOT MSVC) AND (NOT APPLE)) 40 | ADD_DEFINITIONS(-DBOOST_TEST_DYN_LINK) 41 | endif() 42 | if (NOT CRYPTOPP_FOUND) 43 | find_package (CryptoPP) 44 | endif() 45 | 46 | if (CRYPTOPP_FOUND) 47 | add_definitions(-DWITH_CRYPTOPP) 48 | endif() 49 | 50 | if (NOT MSVC) 51 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 ") 52 | endif() 53 | 54 | add_executable (Test "./test.cpp" ${HEADERS}) 55 | target_link_libraries(Test ${ETHHASH_LIBS}) 56 | target_link_libraries(Test ${Boost_FILESYSTEM_LIBRARIES}) 57 | target_link_libraries(Test ${Boost_SYSTEM_LIBRARIES}) 58 | target_link_libraries(Test ${Boost_UNIT_TEST_FRAMEWORK_LIBRARIES}) 59 | 60 | if (CRYPTOPP_FOUND) 61 | TARGET_LINK_LIBRARIES(Test ${CRYPTOPP_LIBRARIES}) 62 | endif() 63 | 64 | enable_testing () 65 | add_test(NAME ethash COMMAND Test) 66 | ENDIF() 67 | -------------------------------------------------------------------------------- /src/benchmark/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories(..) 2 | 3 | set(CMAKE_BUILD_TYPE Release) 4 | 5 | if (MSVC) 6 | add_definitions("/openmp") 7 | endif() 8 | 9 | # enable C++11, should probably be a bit more specific about compiler 10 | if (NOT MSVC) 11 | SET(CMAKE_CXX_FLAGS "-std=c++11") 12 | endif() 13 | 14 | if (NOT MPI_FOUND) 15 | find_package(MPI) 16 | endif() 17 | 18 | if (NOT CRYPTOPP_FOUND) 19 | find_package(CryptoPP 5.6.2) 20 | endif() 21 | 22 | if (CRYPTOPP_FOUND) 23 | add_definitions(-DWITH_CRYPTOPP) 24 | find_package (Threads REQUIRED) 25 | endif() 26 | 27 | if (NOT OpenCL_FOUND) 28 | find_package(OpenCL) 29 | endif() 30 | if (OpenCL_FOUND) 31 | add_definitions(-DWITH_OPENCL) 32 | include_directories(${OpenCL_INCLUDE_DIRS}) 33 | list(APPEND FILES ethash_cl_miner.cpp ethash_cl_miner.h) 34 | endif() 35 | 36 | if (MPI_FOUND) 37 | include_directories(${MPI_INCLUDE_PATH}) 38 | add_executable (Benchmark_MPI_FULL benchmark.cpp) 39 | target_link_libraries (Benchmark_MPI_FULL ${ETHHASH_LIBS} ${MPI_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}) 40 | SET_TARGET_PROPERTIES(Benchmark_MPI_FULL PROPERTIES COMPILE_FLAGS "${COMPILE_FLAGS} ${MPI_COMPILE_FLAGS} -DFULL -DMPI") 41 | 42 | add_executable (Benchmark_MPI_LIGHT benchmark.cpp) 43 | target_link_libraries (Benchmark_MPI_LIGHT ${ETHHASH_LIBS} ${MPI_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}) 44 | SET_TARGET_PROPERTIES(Benchmark_MPI_LIGHT PROPERTIES COMPILE_FLAGS "${COMPILE_FLAGS} ${MPI_COMPILE_FLAGS} -DMPI") 45 | endif() 46 | 47 | add_executable (Benchmark_FULL benchmark.cpp) 48 | target_link_libraries (Benchmark_FULL ${ETHHASH_LIBS} ${CMAKE_THREAD_LIBS_INIT}) 49 | SET_TARGET_PROPERTIES(Benchmark_FULL PROPERTIES COMPILE_FLAGS "${COMPILE_FLAGS} -DFULL") 50 | 51 | add_executable (Benchmark_LIGHT benchmark.cpp) 52 | target_link_libraries (Benchmark_LIGHT ${ETHHASH_LIBS} ${CMAKE_THREAD_LIBS_INIT}) 53 | 54 | if (OpenCL_FOUND) 55 | add_executable (Benchmark_CL benchmark.cpp) 56 | target_link_libraries (Benchmark_CL ${ETHHASH_LIBS} ethash-cl ${CMAKE_THREAD_LIBS_INIT}) 57 | SET_TARGET_PROPERTIES(Benchmark_CL PROPERTIES COMPILE_FLAGS "${COMPILE_FLAGS} -DOPENCL") 58 | endif() -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/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 instances, as well as utility 9 | // functions for hashing bytes to arbitrary-length output. 10 | 11 | import ( 12 | "io" 13 | ) 14 | 15 | // ShakeHash defines the interface to hash functions that 16 | // support arbitrary-length output. 17 | type ShakeHash interface { 18 | // Write absorbs more data into the hash's state. It panics if input is 19 | // written to it after output has been read from it. 20 | io.Writer 21 | 22 | // Read reads more output from the hash; reading affects the hash's 23 | // state. (ShakeHash.Read is thus very different from Hash.Sum) 24 | // It never returns an error. 25 | io.Reader 26 | 27 | // Clone returns a copy of the ShakeHash in its current state. 28 | Clone() ShakeHash 29 | 30 | // Reset resets the ShakeHash to its initial state. 31 | Reset() 32 | } 33 | 34 | func (d *state) Clone() ShakeHash { 35 | return d.clone() 36 | } 37 | 38 | // NewShake128 creates a new SHAKE128 variable-output-length ShakeHash. 39 | // Its generic security strength is 128 bits against all attacks if at 40 | // least 32 bytes of its output are used. 41 | func NewShake128() ShakeHash { return &state{rate: 168, dsbyte: 0x1f} } 42 | 43 | // NewShake256 creates a new SHAKE128 variable-output-length ShakeHash. 44 | // Its generic security strength is 256 bits against all attacks if 45 | // at least 64 bytes of its output are used. 46 | func NewShake256() ShakeHash { return &state{rate: 136, dsbyte: 0x1f} } 47 | 48 | // ShakeSum128 writes an arbitrary-length digest of data into hash. 49 | func ShakeSum128(hash, data []byte) { 50 | h := NewShake128() 51 | h.Write(data) 52 | h.Read(hash) 53 | } 54 | 55 | // ShakeSum256 writes an arbitrary-length digest of data into hash. 56 | func ShakeSum256(hash, data []byte) { 57 | h := NewShake256() 58 | h.Write(data) 59 | h.Read(hash) 60 | } 61 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/src/field_10x26.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2013, 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_FIELD_REPR_ 8 | #define _SECP256K1_FIELD_REPR_ 9 | 10 | #include 11 | 12 | typedef struct { 13 | /* X = sum(i=0..9, elem[i]*2^26) mod n */ 14 | uint32_t n[10]; 15 | #ifdef VERIFY 16 | int magnitude; 17 | int normalized; 18 | #endif 19 | } secp256k1_fe; 20 | 21 | /* Unpacks a constant into a overlapping multi-limbed FE element. */ 22 | #define SECP256K1_FE_CONST_INNER(d7, d6, d5, d4, d3, d2, d1, d0) { \ 23 | (d0) & 0x3FFFFFFUL, \ 24 | (((uint32_t)d0) >> 26) | (((uint32_t)(d1) & 0xFFFFFUL) << 6), \ 25 | (((uint32_t)d1) >> 20) | (((uint32_t)(d2) & 0x3FFFUL) << 12), \ 26 | (((uint32_t)d2) >> 14) | (((uint32_t)(d3) & 0xFFUL) << 18), \ 27 | (((uint32_t)d3) >> 8) | (((uint32_t)(d4) & 0x3UL) << 24), \ 28 | (((uint32_t)d4) >> 2) & 0x3FFFFFFUL, \ 29 | (((uint32_t)d4) >> 28) | (((uint32_t)(d5) & 0x3FFFFFUL) << 4), \ 30 | (((uint32_t)d5) >> 22) | (((uint32_t)(d6) & 0xFFFFUL) << 10), \ 31 | (((uint32_t)d6) >> 16) | (((uint32_t)(d7) & 0x3FFUL) << 16), \ 32 | (((uint32_t)d7) >> 10) \ 33 | } 34 | 35 | #ifdef VERIFY 36 | #define SECP256K1_FE_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {SECP256K1_FE_CONST_INNER((d7), (d6), (d5), (d4), (d3), (d2), (d1), (d0)), 1, 1} 37 | #else 38 | #define SECP256K1_FE_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {SECP256K1_FE_CONST_INNER((d7), (d6), (d5), (d4), (d3), (d2), (d1), (d0))} 39 | #endif 40 | 41 | typedef struct { 42 | uint32_t n[8]; 43 | } secp256k1_fe_storage; 44 | 45 | #define SECP256K1_FE_STORAGE_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {{ (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) }} 46 | #define SECP256K1_FE_STORAGE_CONST_GET(d) d.n[7], d.n[6], d.n[5], d.n[4],d.n[3], d.n[2], d.n[1], d.n[0] 47 | #endif 48 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/src/modules/ecdh/main_impl.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2015 Andrew Poelstra * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_MODULE_ECDH_MAIN_ 8 | #define _SECP256K1_MODULE_ECDH_MAIN_ 9 | 10 | #include "include/secp256k1_ecdh.h" 11 | #include "ecmult_const_impl.h" 12 | 13 | int secp256k1_ecdh(const secp256k1_context* ctx, unsigned char *result, const secp256k1_pubkey *point, const unsigned char *scalar) { 14 | int ret = 0; 15 | int overflow = 0; 16 | secp256k1_gej res; 17 | secp256k1_ge pt; 18 | secp256k1_scalar s; 19 | VERIFY_CHECK(ctx != NULL); 20 | ARG_CHECK(result != NULL); 21 | ARG_CHECK(point != NULL); 22 | ARG_CHECK(scalar != NULL); 23 | 24 | secp256k1_pubkey_load(ctx, &pt, point); 25 | secp256k1_scalar_set_b32(&s, scalar, &overflow); 26 | if (overflow || secp256k1_scalar_is_zero(&s)) { 27 | ret = 0; 28 | } else { 29 | unsigned char x[32]; 30 | unsigned char y[1]; 31 | secp256k1_sha256_t sha; 32 | 33 | secp256k1_ecmult_const(&res, &pt, &s); 34 | secp256k1_ge_set_gej(&pt, &res); 35 | /* Compute a hash of the point in compressed form 36 | * Note we cannot use secp256k1_eckey_pubkey_serialize here since it does not 37 | * expect its output to be secret and has a timing sidechannel. */ 38 | secp256k1_fe_normalize(&pt.x); 39 | secp256k1_fe_normalize(&pt.y); 40 | secp256k1_fe_get_b32(x, &pt.x); 41 | y[0] = 0x02 | secp256k1_fe_is_odd(&pt.y); 42 | 43 | secp256k1_sha256_initialize(&sha); 44 | secp256k1_sha256_write(&sha, y, sizeof(y)); 45 | secp256k1_sha256_write(&sha, x, sizeof(x)); 46 | secp256k1_sha256_finalize(&sha, result); 47 | ret = 1; 48 | } 49 | 50 | secp256k1_scalar_clear(&s); 51 | return ret; 52 | } 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /cmake/modules/FindPackageMessage.cmake: -------------------------------------------------------------------------------- 1 | #.rst: 2 | # FindPackageMessage 3 | # ------------------ 4 | # 5 | # 6 | # 7 | # FIND_PACKAGE_MESSAGE( "message for user" "find result details") 8 | # 9 | # This macro is intended to be used in FindXXX.cmake modules files. It 10 | # will print a message once for each unique find result. This is useful 11 | # for telling the user where a package was found. The first argument 12 | # specifies the name (XXX) of the package. The second argument 13 | # specifies the message to display. The third argument lists details 14 | # about the find result so that if they change the message will be 15 | # displayed again. The macro also obeys the QUIET argument to the 16 | # find_package command. 17 | # 18 | # Example: 19 | # 20 | # :: 21 | # 22 | # if(X11_FOUND) 23 | # FIND_PACKAGE_MESSAGE(X11 "Found X11: ${X11_X11_LIB}" 24 | # "[${X11_X11_LIB}][${X11_INCLUDE_DIR}]") 25 | # else() 26 | # ... 27 | # endif() 28 | 29 | #============================================================================= 30 | # Copyright 2008-2009 Kitware, Inc. 31 | # 32 | # Distributed under the OSI-approved BSD License (the "License"); 33 | # see accompanying file Copyright.txt for details. 34 | # 35 | # This software is distributed WITHOUT ANY WARRANTY; without even the 36 | # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 37 | # See the License for more information. 38 | #============================================================================= 39 | # (To distribute this file outside of CMake, substitute the full 40 | # License text for the above reference.) 41 | 42 | function(FIND_PACKAGE_MESSAGE pkg msg details) 43 | # Avoid printing a message repeatedly for the same find result. 44 | if(NOT ${pkg}_FIND_QUIETLY) 45 | string(REPLACE "\n" "" details "${details}") 46 | set(DETAILS_VAR FIND_PACKAGE_MESSAGE_DETAILS_${pkg}) 47 | if(NOT "${details}" STREQUAL "${${DETAILS_VAR}}") 48 | # The message has not yet been printed. 49 | message(STATUS "${msg}") 50 | 51 | # Save the find details in the cache to avoid printing the same 52 | # message again. 53 | set("${DETAILS_VAR}" "${details}" 54 | CACHE INTERNAL "Details about finding ${pkg}") 55 | endif() 56 | endif() 57 | endfunction() 58 | -------------------------------------------------------------------------------- /vendor/github.com/btcsuite/btcd/btcec/precompute.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The btcsuite developers 2 | // Use of this source code is governed by an ISC 3 | // license that can be found in the LICENSE file. 4 | 5 | package btcec 6 | 7 | import ( 8 | "compress/zlib" 9 | "encoding/base64" 10 | "encoding/binary" 11 | "io/ioutil" 12 | "strings" 13 | ) 14 | 15 | //go:generate go run -tags gensecp256k1 genprecomps.go 16 | 17 | // loadS256BytePoints decompresses and deserializes the pre-computed byte points 18 | // used to accelerate scalar base multiplication for the secp256k1 curve. This 19 | // approach is used since it allows the compile to use significantly less ram 20 | // and be performed much faster than it is with hard-coding the final in-memory 21 | // data structure. At the same time, it is quite fast to generate the in-memory 22 | // data structure at init time with this approach versus computing the table. 23 | func loadS256BytePoints() error { 24 | // There will be no byte points to load when generating them. 25 | bp := secp256k1BytePoints 26 | if len(bp) == 0 { 27 | return nil 28 | } 29 | 30 | // Decompress the pre-computed table used to accelerate scalar base 31 | // multiplication. 32 | decoder := base64.NewDecoder(base64.StdEncoding, strings.NewReader(bp)) 33 | r, err := zlib.NewReader(decoder) 34 | if err != nil { 35 | return err 36 | } 37 | serialized, err := ioutil.ReadAll(r) 38 | if err != nil { 39 | return err 40 | } 41 | 42 | // Deserialize the precomputed byte points and set the curve to them. 43 | offset := 0 44 | var bytePoints [32][256][3]fieldVal 45 | for byteNum := 0; byteNum < 32; byteNum++ { 46 | // All points in this window. 47 | for i := 0; i < 256; i++ { 48 | px := &bytePoints[byteNum][i][0] 49 | py := &bytePoints[byteNum][i][1] 50 | pz := &bytePoints[byteNum][i][2] 51 | for i := 0; i < 10; i++ { 52 | px.n[i] = binary.LittleEndian.Uint32(serialized[offset:]) 53 | offset += 4 54 | } 55 | for i := 0; i < 10; i++ { 56 | py.n[i] = binary.LittleEndian.Uint32(serialized[offset:]) 57 | offset += 4 58 | } 59 | for i := 0; i < 10; i++ { 60 | pz.n[i] = binary.LittleEndian.Uint32(serialized[offset:]) 61 | offset += 4 62 | } 63 | } 64 | } 65 | secp256k1.bytePoints = &bytePoints 66 | return nil 67 | } 68 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/src/bench_recover.c: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2014-2015 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #include "include/secp256k1.h" 8 | #include "include/secp256k1_recovery.h" 9 | #include "util.h" 10 | #include "bench.h" 11 | 12 | typedef struct { 13 | secp256k1_context *ctx; 14 | unsigned char msg[32]; 15 | unsigned char sig[64]; 16 | } bench_recover_t; 17 | 18 | void bench_recover(void* arg) { 19 | int i; 20 | bench_recover_t *data = (bench_recover_t*)arg; 21 | secp256k1_pubkey pubkey; 22 | unsigned char pubkeyc[33]; 23 | 24 | for (i = 0; i < 20000; i++) { 25 | int j; 26 | size_t pubkeylen = 33; 27 | secp256k1_ecdsa_recoverable_signature sig; 28 | CHECK(secp256k1_ecdsa_recoverable_signature_parse_compact(data->ctx, &sig, data->sig, i % 2)); 29 | CHECK(secp256k1_ecdsa_recover(data->ctx, &pubkey, &sig, data->msg)); 30 | CHECK(secp256k1_ec_pubkey_serialize(data->ctx, pubkeyc, &pubkeylen, &pubkey, SECP256K1_EC_COMPRESSED)); 31 | for (j = 0; j < 32; j++) { 32 | data->sig[j + 32] = data->msg[j]; /* Move former message to S. */ 33 | data->msg[j] = data->sig[j]; /* Move former R to message. */ 34 | data->sig[j] = pubkeyc[j + 1]; /* Move recovered pubkey X coordinate to R (which must be a valid X coordinate). */ 35 | } 36 | } 37 | } 38 | 39 | void bench_recover_setup(void* arg) { 40 | int i; 41 | bench_recover_t *data = (bench_recover_t*)arg; 42 | 43 | for (i = 0; i < 32; i++) { 44 | data->msg[i] = 1 + i; 45 | } 46 | for (i = 0; i < 64; i++) { 47 | data->sig[i] = 65 + i; 48 | } 49 | } 50 | 51 | int main(void) { 52 | bench_recover_t data; 53 | 54 | data.ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY); 55 | 56 | run_benchmark("ecdsa_recover", bench_recover, bench_recover_setup, NULL, &data, 10, 20000); 57 | 58 | secp256k1_context_destroy(data.ctx); 59 | return 0; 60 | } 61 | -------------------------------------------------------------------------------- /js/util.js: -------------------------------------------------------------------------------- 1 | // util.js 2 | // Tim Hughes 3 | 4 | /*jslint node: true, shadow:true */ 5 | "use strict"; 6 | 7 | function nibbleToChar(nibble) 8 | { 9 | return String.fromCharCode((nibble < 10 ? 48 : 87) + nibble); 10 | } 11 | 12 | function charToNibble(chr) 13 | { 14 | if (chr >= 48 && chr <= 57) 15 | { 16 | return chr - 48; 17 | } 18 | if (chr >= 65 && chr <= 70) 19 | { 20 | return chr - 65 + 10; 21 | } 22 | if (chr >= 97 && chr <= 102) 23 | { 24 | return chr - 97 + 10; 25 | } 26 | return 0; 27 | } 28 | 29 | function stringToBytes(str) 30 | { 31 | var bytes = new Uint8Array(str.length); 32 | for (var i = 0; i != str.length; ++i) 33 | { 34 | bytes[i] = str.charCodeAt(i); 35 | } 36 | return bytes; 37 | } 38 | 39 | function hexStringToBytes(str) 40 | { 41 | var bytes = new Uint8Array(str.length>>>1); 42 | for (var i = 0; i != bytes.length; ++i) 43 | { 44 | bytes[i] = charToNibble(str.charCodeAt(i<<1 | 0)) << 4; 45 | bytes[i] |= charToNibble(str.charCodeAt(i<<1 | 1)); 46 | } 47 | return bytes; 48 | } 49 | 50 | function bytesToHexString(bytes) 51 | { 52 | var str = ""; 53 | for (var i = 0; i != bytes.length; ++i) 54 | { 55 | str += nibbleToChar(bytes[i] >>> 4); 56 | str += nibbleToChar(bytes[i] & 0xf); 57 | } 58 | return str; 59 | } 60 | 61 | function wordsToHexString(words) 62 | { 63 | return bytesToHexString(new Uint8Array(words.buffer)); 64 | } 65 | 66 | function uint32ToHexString(num) 67 | { 68 | var buf = new Uint8Array(4); 69 | buf[0] = (num >> 24) & 0xff; 70 | buf[1] = (num >> 16) & 0xff; 71 | buf[2] = (num >> 8) & 0xff; 72 | buf[3] = (num >> 0) & 0xff; 73 | return bytesToHexString(buf); 74 | } 75 | 76 | function toWords(input) 77 | { 78 | if (input instanceof Uint32Array) 79 | { 80 | return input; 81 | } 82 | else if (input instanceof Uint8Array) 83 | { 84 | var tmp = new Uint8Array((input.length + 3) & ~3); 85 | tmp.set(input); 86 | return new Uint32Array(tmp.buffer); 87 | } 88 | else if (typeof input === typeof "") 89 | { 90 | return toWords(stringToBytes(input)); 91 | } 92 | return null; 93 | } 94 | 95 | exports.stringToBytes = stringToBytes; 96 | exports.hexStringToBytes = hexStringToBytes; 97 | exports.bytesToHexString = bytesToHexString; 98 | exports.wordsToHexString = wordsToHexString; 99 | exports.uint32ToHexString = uint32ToHexString; 100 | exports.toWords = toWords; -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/crypto/signature_cgo.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 | // +build !nacl,!js,!nocgo 18 | 19 | package crypto 20 | 21 | import ( 22 | "crypto/ecdsa" 23 | "crypto/elliptic" 24 | "fmt" 25 | 26 | "github.com/ethereum/go-ethereum/common/math" 27 | "github.com/ethereum/go-ethereum/crypto/secp256k1" 28 | ) 29 | 30 | func Ecrecover(hash, sig []byte) ([]byte, error) { 31 | return secp256k1.RecoverPubkey(hash, sig) 32 | } 33 | 34 | func SigToPub(hash, sig []byte) (*ecdsa.PublicKey, error) { 35 | s, err := Ecrecover(hash, sig) 36 | if err != nil { 37 | return nil, err 38 | } 39 | 40 | x, y := elliptic.Unmarshal(S256(), s) 41 | return &ecdsa.PublicKey{Curve: S256(), X: x, Y: y}, nil 42 | } 43 | 44 | // Sign calculates an ECDSA signature. 45 | // 46 | // This function is susceptible to chosen plaintext attacks that can leak 47 | // information about the private key that is used for signing. Callers must 48 | // be aware that the given hash cannot be chosen by an adversery. Common 49 | // solution is to hash any input before calculating the signature. 50 | // 51 | // The produced signature is in the [R || S || V] format where V is 0 or 1. 52 | func Sign(hash []byte, prv *ecdsa.PrivateKey) (sig []byte, err error) { 53 | if len(hash) != 32 { 54 | return nil, fmt.Errorf("hash is required to be exactly 32 bytes (%d)", len(hash)) 55 | } 56 | seckey := math.PaddedBigBytes(prv.D, prv.Params().BitSize/8) 57 | defer zeroBytes(seckey) 58 | return secp256k1.Sign(hash, seckey) 59 | } 60 | 61 | // S256 returns an instance of the secp256k1 curve. 62 | func S256() elliptic.Curve { 63 | return secp256k1.S256() 64 | } 65 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/src/ecmult_gen.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2013, 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_ECMULT_GEN_ 8 | #define _SECP256K1_ECMULT_GEN_ 9 | 10 | #include "scalar.h" 11 | #include "group.h" 12 | 13 | typedef struct { 14 | /* For accelerating the computation of a*G: 15 | * To harden against timing attacks, use the following mechanism: 16 | * * Break up the multiplicand into groups of 4 bits, called n_0, n_1, n_2, ..., n_63. 17 | * * Compute sum(n_i * 16^i * G + U_i, i=0..63), where: 18 | * * U_i = U * 2^i (for i=0..62) 19 | * * U_i = U * (1-2^63) (for i=63) 20 | * where U is a point with no known corresponding scalar. Note that sum(U_i, i=0..63) = 0. 21 | * For each i, and each of the 16 possible values of n_i, (n_i * 16^i * G + U_i) is 22 | * precomputed (call it prec(i, n_i)). The formula now becomes sum(prec(i, n_i), i=0..63). 23 | * None of the resulting prec group elements have a known scalar, and neither do any of 24 | * the intermediate sums while computing a*G. 25 | */ 26 | secp256k1_ge_storage (*prec)[64][16]; /* prec[j][i] = 16^j * i * G + U_i */ 27 | secp256k1_scalar blind; 28 | secp256k1_gej initial; 29 | } secp256k1_ecmult_gen_context; 30 | 31 | static void secp256k1_ecmult_gen_context_init(secp256k1_ecmult_gen_context* ctx); 32 | static void secp256k1_ecmult_gen_context_build(secp256k1_ecmult_gen_context* ctx, const secp256k1_callback* cb); 33 | static void secp256k1_ecmult_gen_context_clone(secp256k1_ecmult_gen_context *dst, 34 | const secp256k1_ecmult_gen_context* src, const secp256k1_callback* cb); 35 | static void secp256k1_ecmult_gen_context_clear(secp256k1_ecmult_gen_context* ctx); 36 | static int secp256k1_ecmult_gen_context_is_built(const secp256k1_ecmult_gen_context* ctx); 37 | 38 | /** Multiply with the generator: R = a*G */ 39 | static void secp256k1_ecmult_gen(const secp256k1_ecmult_gen_context* ctx, secp256k1_gej *r, const secp256k1_scalar *a); 40 | 41 | static void secp256k1_ecmult_gen_blind(secp256k1_ecmult_gen_context *ctx, const unsigned char *seed32); 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/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 | // NewKeccak256 creates a new Keccak-256 hash. 16 | func NewKeccak256() hash.Hash { return &state{rate: 136, outputLen: 32, dsbyte: 0x01} } 17 | 18 | // NewKeccak512 creates a new Keccak-512 hash. 19 | func NewKeccak512() hash.Hash { return &state{rate: 72, outputLen: 64, dsbyte: 0x01} } 20 | 21 | // New224 creates a new SHA3-224 hash. 22 | // Its generic security strength is 224 bits against preimage attacks, 23 | // and 112 bits against collision attacks. 24 | func New224() hash.Hash { return &state{rate: 144, outputLen: 28, dsbyte: 0x06} } 25 | 26 | // New256 creates a new SHA3-256 hash. 27 | // Its generic security strength is 256 bits against preimage attacks, 28 | // and 128 bits against collision attacks. 29 | func New256() hash.Hash { return &state{rate: 136, outputLen: 32, dsbyte: 0x06} } 30 | 31 | // New384 creates a new SHA3-384 hash. 32 | // Its generic security strength is 384 bits against preimage attacks, 33 | // and 192 bits against collision attacks. 34 | func New384() hash.Hash { return &state{rate: 104, outputLen: 48, dsbyte: 0x06} } 35 | 36 | // New512 creates a new SHA3-512 hash. 37 | // Its generic security strength is 512 bits against preimage attacks, 38 | // and 256 bits against collision attacks. 39 | func New512() hash.Hash { return &state{rate: 72, outputLen: 64, dsbyte: 0x06} } 40 | 41 | // Sum224 returns the SHA3-224 digest of the data. 42 | func Sum224(data []byte) (digest [28]byte) { 43 | h := New224() 44 | h.Write(data) 45 | h.Sum(digest[:0]) 46 | return 47 | } 48 | 49 | // Sum256 returns the SHA3-256 digest of the data. 50 | func Sum256(data []byte) (digest [32]byte) { 51 | h := New256() 52 | h.Write(data) 53 | h.Sum(digest[:0]) 54 | return 55 | } 56 | 57 | // Sum384 returns the SHA3-384 digest of the data. 58 | func Sum384(data []byte) (digest [48]byte) { 59 | h := New384() 60 | h.Write(data) 61 | h.Sum(digest[:0]) 62 | return 63 | } 64 | 65 | // Sum512 returns the SHA3-512 digest of the data. 66 | func Sum512(data []byte) (digest [64]byte) { 67 | h := New512() 68 | h.Write(data) 69 | h.Sum(digest[:0]) 70 | return 71 | } 72 | -------------------------------------------------------------------------------- /src/libethash/mmap_win32.c: -------------------------------------------------------------------------------- 1 | /* mmap() replacement for Windows 2 | * 3 | * Author: Mike Frysinger 4 | * Placed into the public domain 5 | */ 6 | 7 | /* References: 8 | * CreateFileMapping: http://msdn.microsoft.com/en-us/library/aa366537(VS.85).aspx 9 | * CloseHandle: http://msdn.microsoft.com/en-us/library/ms724211(VS.85).aspx 10 | * MapViewOfFile: http://msdn.microsoft.com/en-us/library/aa366761(VS.85).aspx 11 | * UnmapViewOfFile: http://msdn.microsoft.com/en-us/library/aa366882(VS.85).aspx 12 | */ 13 | 14 | #include 15 | #include 16 | #include "mmap.h" 17 | 18 | #ifdef __USE_FILE_OFFSET64 19 | # define DWORD_HI(x) (x >> 32) 20 | # define DWORD_LO(x) ((x) & 0xffffffff) 21 | #else 22 | # define DWORD_HI(x) (0) 23 | # define DWORD_LO(x) (x) 24 | #endif 25 | 26 | void* mmap(void* start, size_t length, int prot, int flags, int fd, off_t offset) 27 | { 28 | if (prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC)) 29 | return MAP_FAILED; 30 | if (fd == -1) { 31 | if (!(flags & MAP_ANON) || offset) 32 | return MAP_FAILED; 33 | } else if (flags & MAP_ANON) 34 | return MAP_FAILED; 35 | 36 | DWORD flProtect; 37 | if (prot & PROT_WRITE) { 38 | if (prot & PROT_EXEC) 39 | flProtect = PAGE_EXECUTE_READWRITE; 40 | else 41 | flProtect = PAGE_READWRITE; 42 | } else if (prot & PROT_EXEC) { 43 | if (prot & PROT_READ) 44 | flProtect = PAGE_EXECUTE_READ; 45 | else if (prot & PROT_EXEC) 46 | flProtect = PAGE_EXECUTE; 47 | } else 48 | flProtect = PAGE_READONLY; 49 | 50 | off_t end = length + offset; 51 | HANDLE mmap_fd, h; 52 | if (fd == -1) 53 | mmap_fd = INVALID_HANDLE_VALUE; 54 | else 55 | mmap_fd = (HANDLE)_get_osfhandle(fd); 56 | h = CreateFileMapping(mmap_fd, NULL, flProtect, DWORD_HI(end), DWORD_LO(end), NULL); 57 | if (h == NULL) 58 | return MAP_FAILED; 59 | 60 | DWORD dwDesiredAccess; 61 | if (prot & PROT_WRITE) 62 | dwDesiredAccess = FILE_MAP_WRITE; 63 | else 64 | dwDesiredAccess = FILE_MAP_READ; 65 | if (prot & PROT_EXEC) 66 | dwDesiredAccess |= FILE_MAP_EXECUTE; 67 | if (flags & MAP_PRIVATE) 68 | dwDesiredAccess |= FILE_MAP_COPY; 69 | void *ret = MapViewOfFile(h, dwDesiredAccess, DWORD_HI(offset), DWORD_LO(offset), length); 70 | if (ret == NULL) { 71 | ret = MAP_FAILED; 72 | } 73 | // since we are handling the file ourselves with fd, close the Windows Handle here 74 | CloseHandle(h); 75 | return ret; 76 | } 77 | 78 | void munmap(void* addr, size_t length) 79 | { 80 | UnmapViewOfFile(addr); 81 | } 82 | 83 | #undef DWORD_HI 84 | #undef DWORD_LO 85 | -------------------------------------------------------------------------------- /js/test.js: -------------------------------------------------------------------------------- 1 | // test.js 2 | // Tim Hughes 3 | 4 | /*jslint node: true, shadow:true */ 5 | "use strict"; 6 | 7 | var ethash = require('./ethash'); 8 | var util = require('./util'); 9 | var Keccak = require('./keccak'); 10 | 11 | // sanity check hash functions 12 | var src = util.stringToBytes(""); 13 | if (util.bytesToHexString(new Keccak().digest(32, src)) != "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470") throw Error("Keccak-256 failed"); 14 | if (util.bytesToHexString(new Keccak().digest(64, src)) != "0eab42de4c3ceb9235fc91acffe746b29c29a8c366b7c60e4e67c466f36a4304c00fa9caf9d87976ba469bcbe06713b435f091ef2769fb160cdab33d3670680e") throw Error("Keccak-512 failed"); 15 | 16 | src = new Uint32Array(src.buffer); 17 | var dst = new Uint32Array(8); 18 | new Keccak().digestWords(dst, 0, dst.length, src, 0, src.length); 19 | if (util.wordsToHexString(dst) != "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470") throw Error("Keccak-256 Fast failed"); 20 | 21 | var dst = new Uint32Array(16); 22 | new Keccak().digestWords(dst, 0, dst.length, src, 0, src.length); 23 | if (util.wordsToHexString(dst) != "0eab42de4c3ceb9235fc91acffe746b29c29a8c366b7c60e4e67c466f36a4304c00fa9caf9d87976ba469bcbe06713b435f091ef2769fb160cdab33d3670680e") throw Error("Keccak-512 Fast failed"); 24 | 25 | 26 | // init params 27 | var ethashParams = ethash.defaultParams(); 28 | //ethashParams.cacheRounds = 0; 29 | 30 | // create hasher 31 | var seed = util.hexStringToBytes("9410b944535a83d9adf6bbdcc80e051f30676173c16ca0d32d6f1263fc246466") 32 | var startTime = new Date().getTime(); 33 | var hasher = new ethash.Ethash(ethashParams, seed); 34 | console.log('Ethash startup took: '+(new Date().getTime() - startTime) + "ms"); 35 | console.log('Ethash cache hash: ' + util.bytesToHexString(hasher.cacheDigest())); 36 | 37 | var testHexString = "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"; 38 | if (testHexString != util.bytesToHexString(util.hexStringToBytes(testHexString))) 39 | throw Error("bytesToHexString or hexStringToBytes broken"); 40 | 41 | 42 | var header = util.hexStringToBytes("c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"); 43 | var nonce = util.hexStringToBytes("0000000000000000"); 44 | var hash; 45 | 46 | startTime = new Date().getTime(); 47 | var trials = 10; 48 | for (var i = 0; i < trials; ++i) 49 | { 50 | hash = hasher.hash(header, nonce); 51 | } 52 | console.log("Light client hashes averaged: " + (new Date().getTime() - startTime)/trials + "ms"); 53 | console.log("Hash = " + util.bytesToHexString(hash)); 54 | -------------------------------------------------------------------------------- /vendor/github.com/btcsuite/btcd/btcec/privkey.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013-2016 The btcsuite developers 2 | // Use of this source code is governed by an ISC 3 | // license that can be found in the LICENSE file. 4 | 5 | package btcec 6 | 7 | import ( 8 | "crypto/ecdsa" 9 | "crypto/elliptic" 10 | "crypto/rand" 11 | "math/big" 12 | ) 13 | 14 | // PrivateKey wraps an ecdsa.PrivateKey as a convenience mainly for signing 15 | // things with the the private key without having to directly import the ecdsa 16 | // package. 17 | type PrivateKey ecdsa.PrivateKey 18 | 19 | // PrivKeyFromBytes returns a private and public key for `curve' based on the 20 | // private key passed as an argument as a byte slice. 21 | func PrivKeyFromBytes(curve elliptic.Curve, pk []byte) (*PrivateKey, 22 | *PublicKey) { 23 | x, y := curve.ScalarBaseMult(pk) 24 | 25 | priv := &ecdsa.PrivateKey{ 26 | PublicKey: ecdsa.PublicKey{ 27 | Curve: curve, 28 | X: x, 29 | Y: y, 30 | }, 31 | D: new(big.Int).SetBytes(pk), 32 | } 33 | 34 | return (*PrivateKey)(priv), (*PublicKey)(&priv.PublicKey) 35 | } 36 | 37 | // NewPrivateKey is a wrapper for ecdsa.GenerateKey that returns a PrivateKey 38 | // instead of the normal ecdsa.PrivateKey. 39 | func NewPrivateKey(curve elliptic.Curve) (*PrivateKey, error) { 40 | key, err := ecdsa.GenerateKey(curve, rand.Reader) 41 | if err != nil { 42 | return nil, err 43 | } 44 | return (*PrivateKey)(key), nil 45 | } 46 | 47 | // PubKey returns the PublicKey corresponding to this private key. 48 | func (p *PrivateKey) PubKey() *PublicKey { 49 | return (*PublicKey)(&p.PublicKey) 50 | } 51 | 52 | // ToECDSA returns the private key as a *ecdsa.PrivateKey. 53 | func (p *PrivateKey) ToECDSA() *ecdsa.PrivateKey { 54 | return (*ecdsa.PrivateKey)(p) 55 | } 56 | 57 | // Sign generates an ECDSA signature for the provided hash (which should be the result 58 | // of hashing a larger message) using the private key. Produced signature 59 | // is deterministic (same message and same key yield the same signature) and canonical 60 | // in accordance with RFC6979 and BIP0062. 61 | func (p *PrivateKey) Sign(hash []byte) (*Signature, error) { 62 | return signRFC6979(p, hash) 63 | } 64 | 65 | // PrivKeyBytesLen defines the length in bytes of a serialized private key. 66 | const PrivKeyBytesLen = 32 67 | 68 | // Serialize returns the private key number d as a big-endian binary-encoded 69 | // number, padded to a length of 32 bytes. 70 | func (p *PrivateKey) Serialize() []byte { 71 | b := make([]byte, 0, PrivKeyBytesLen) 72 | return paddedAppend(PrivKeyBytesLen, b, p.ToECDSA().D.Bytes()) 73 | } 74 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/build-aux/m4/bitcoin_secp.m4: -------------------------------------------------------------------------------- 1 | dnl libsecp25k1 helper checks 2 | AC_DEFUN([SECP_INT128_CHECK],[ 3 | has_int128=$ac_cv_type___int128 4 | ]) 5 | 6 | dnl escape "$0x" below using the m4 quadrigaph @S|@, and escape it again with a \ for the shell. 7 | AC_DEFUN([SECP_64BIT_ASM_CHECK],[ 8 | AC_MSG_CHECKING(for x86_64 assembly availability) 9 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ 10 | #include ]],[[ 11 | uint64_t a = 11, tmp; 12 | __asm__ __volatile__("movq \@S|@0x100000000,%1; mulq %%rsi" : "+a"(a) : "S"(tmp) : "cc", "%rdx"); 13 | ]])],[has_64bit_asm=yes],[has_64bit_asm=no]) 14 | AC_MSG_RESULT([$has_64bit_asm]) 15 | ]) 16 | 17 | dnl 18 | AC_DEFUN([SECP_OPENSSL_CHECK],[ 19 | has_libcrypto=no 20 | m4_ifdef([PKG_CHECK_MODULES],[ 21 | PKG_CHECK_MODULES([CRYPTO], [libcrypto], [has_libcrypto=yes],[has_libcrypto=no]) 22 | if test x"$has_libcrypto" = x"yes"; then 23 | TEMP_LIBS="$LIBS" 24 | LIBS="$LIBS $CRYPTO_LIBS" 25 | AC_CHECK_LIB(crypto, main,[AC_DEFINE(HAVE_LIBCRYPTO,1,[Define this symbol if libcrypto is installed])],[has_libcrypto=no]) 26 | LIBS="$TEMP_LIBS" 27 | fi 28 | ]) 29 | if test x$has_libcrypto = xno; then 30 | AC_CHECK_HEADER(openssl/crypto.h,[ 31 | AC_CHECK_LIB(crypto, main,[ 32 | has_libcrypto=yes 33 | CRYPTO_LIBS=-lcrypto 34 | AC_DEFINE(HAVE_LIBCRYPTO,1,[Define this symbol if libcrypto is installed]) 35 | ]) 36 | ]) 37 | LIBS= 38 | fi 39 | if test x"$has_libcrypto" = x"yes" && test x"$has_openssl_ec" = x; then 40 | AC_MSG_CHECKING(for EC functions in libcrypto) 41 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ 42 | #include 43 | #include 44 | #include ]],[[ 45 | EC_KEY *eckey = EC_KEY_new_by_curve_name(NID_secp256k1); 46 | ECDSA_sign(0, NULL, 0, NULL, NULL, eckey); 47 | ECDSA_verify(0, NULL, 0, NULL, 0, eckey); 48 | EC_KEY_free(eckey); 49 | ECDSA_SIG *sig_openssl; 50 | sig_openssl = ECDSA_SIG_new(); 51 | (void)sig_openssl->r; 52 | ECDSA_SIG_free(sig_openssl); 53 | ]])],[has_openssl_ec=yes],[has_openssl_ec=no]) 54 | AC_MSG_RESULT([$has_openssl_ec]) 55 | fi 56 | ]) 57 | 58 | dnl 59 | AC_DEFUN([SECP_GMP_CHECK],[ 60 | if test x"$has_gmp" != x"yes"; then 61 | CPPFLAGS_TEMP="$CPPFLAGS" 62 | CPPFLAGS="$GMP_CPPFLAGS $CPPFLAGS" 63 | LIBS_TEMP="$LIBS" 64 | LIBS="$GMP_LIBS $LIBS" 65 | AC_CHECK_HEADER(gmp.h,[AC_CHECK_LIB(gmp, __gmpz_init,[has_gmp=yes; GMP_LIBS="$GMP_LIBS -lgmp"; AC_DEFINE(HAVE_LIBGMP,1,[Define this symbol if libgmp is installed])])]) 66 | CPPFLAGS="$CPPFLAGS_TEMP" 67 | LIBS="$LIBS_TEMP" 68 | fi 69 | ]) 70 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/src/gen_context.c: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2013, 2014, 2015 Thomas Daede, Cory Fields * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #define USE_BASIC_CONFIG 1 8 | 9 | #include "basic-config.h" 10 | #include "include/secp256k1.h" 11 | #include "field_impl.h" 12 | #include "scalar_impl.h" 13 | #include "group_impl.h" 14 | #include "ecmult_gen_impl.h" 15 | 16 | static void default_error_callback_fn(const char* str, void* data) { 17 | (void)data; 18 | fprintf(stderr, "[libsecp256k1] internal consistency check failed: %s\n", str); 19 | abort(); 20 | } 21 | 22 | static const secp256k1_callback default_error_callback = { 23 | default_error_callback_fn, 24 | NULL 25 | }; 26 | 27 | int main(int argc, char **argv) { 28 | secp256k1_ecmult_gen_context ctx; 29 | int inner; 30 | int outer; 31 | FILE* fp; 32 | 33 | (void)argc; 34 | (void)argv; 35 | 36 | fp = fopen("src/ecmult_static_context.h","w"); 37 | if (fp == NULL) { 38 | fprintf(stderr, "Could not open src/ecmult_static_context.h for writing!\n"); 39 | return -1; 40 | } 41 | 42 | fprintf(fp, "#ifndef _SECP256K1_ECMULT_STATIC_CONTEXT_\n"); 43 | fprintf(fp, "#define _SECP256K1_ECMULT_STATIC_CONTEXT_\n"); 44 | fprintf(fp, "#include \"group.h\"\n"); 45 | fprintf(fp, "#define SC SECP256K1_GE_STORAGE_CONST\n"); 46 | fprintf(fp, "static const secp256k1_ge_storage secp256k1_ecmult_static_context[64][16] = {\n"); 47 | 48 | secp256k1_ecmult_gen_context_init(&ctx); 49 | secp256k1_ecmult_gen_context_build(&ctx, &default_error_callback); 50 | for(outer = 0; outer != 64; outer++) { 51 | fprintf(fp,"{\n"); 52 | for(inner = 0; inner != 16; inner++) { 53 | fprintf(fp," SC(%uu, %uu, %uu, %uu, %uu, %uu, %uu, %uu, %uu, %uu, %uu, %uu, %uu, %uu, %uu, %uu)", SECP256K1_GE_STORAGE_CONST_GET((*ctx.prec)[outer][inner])); 54 | if (inner != 15) { 55 | fprintf(fp,",\n"); 56 | } else { 57 | fprintf(fp,"\n"); 58 | } 59 | } 60 | if (outer != 63) { 61 | fprintf(fp,"},\n"); 62 | } else { 63 | fprintf(fp,"}\n"); 64 | } 65 | } 66 | fprintf(fp,"};\n"); 67 | secp256k1_ecmult_gen_context_clear(&ctx); 68 | 69 | fprintf(fp, "#undef SC\n"); 70 | fprintf(fp, "#endif\n"); 71 | fclose(fp); 72 | 73 | return 0; 74 | } 75 | -------------------------------------------------------------------------------- /src/libethash/endian.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "compiler.h" 5 | 6 | #if defined(__MINGW32__) || defined(_WIN32) 7 | # define LITTLE_ENDIAN 1234 8 | # define BYTE_ORDER LITTLE_ENDIAN 9 | #elif defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__) 10 | # include 11 | #elif defined(__OpenBSD__) || defined(__SVR4) 12 | # include 13 | #elif defined(__APPLE__) 14 | # include 15 | #elif defined( BSD ) && (BSD >= 199103) 16 | # include 17 | #elif defined( __QNXNTO__ ) && defined( __LITTLEENDIAN__ ) 18 | # define LITTLE_ENDIAN 1234 19 | # define BYTE_ORDER LITTLE_ENDIAN 20 | #elif defined( __QNXNTO__ ) && defined( __BIGENDIAN__ ) 21 | # define BIG_ENDIAN 1234 22 | # define BYTE_ORDER BIG_ENDIAN 23 | #else 24 | # include 25 | #endif 26 | 27 | #if defined(_WIN32) 28 | #include 29 | #define ethash_swap_u32(input_) _byteswap_ulong(input_) 30 | #define ethash_swap_u64(input_) _byteswap_uint64(input_) 31 | #elif defined(__APPLE__) 32 | #include 33 | #define ethash_swap_u32(input_) OSSwapInt32(input_) 34 | #define ethash_swap_u64(input_) OSSwapInt64(input_) 35 | #elif defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__) 36 | #define ethash_swap_u32(input_) bswap32(input_) 37 | #define ethash_swap_u64(input_) bswap64(input_) 38 | #elif defined(__OpenBSD__) 39 | #include 40 | #define ethash_swap_u32(input_) swap32(input_) 41 | #define ethash_swap_u64(input_) swap64(input_) 42 | #else // posix 43 | #include 44 | #define ethash_swap_u32(input_) bswap_32(input_) 45 | #define ethash_swap_u64(input_) bswap_64(input_) 46 | #endif 47 | 48 | 49 | #if LITTLE_ENDIAN == BYTE_ORDER 50 | 51 | #define fix_endian32(dst_ ,src_) dst_ = src_ 52 | #define fix_endian32_same(val_) 53 | #define fix_endian64(dst_, src_) dst_ = src_ 54 | #define fix_endian64_same(val_) 55 | #define fix_endian_arr32(arr_, size_) 56 | #define fix_endian_arr64(arr_, size_) 57 | 58 | #elif BIG_ENDIAN == BYTE_ORDER 59 | 60 | #define fix_endian32(dst_, src_) dst_ = ethash_swap_u32(src_) 61 | #define fix_endian32_same(val_) val_ = ethash_swap_u32(val_) 62 | #define fix_endian64(dst_, src_) dst_ = ethash_swap_u64(src_) 63 | #define fix_endian64_same(val_) val_ = ethash_swap_u64(val_) 64 | #define fix_endian_arr32(arr_, size_) \ 65 | do { \ 66 | for (unsigned i_ = 0; i_ < (size_); ++i_) { \ 67 | arr_[i_] = ethash_swap_u32(arr_[i_]); \ 68 | } \ 69 | } while (0) 70 | #define fix_endian_arr64(arr_, size_) \ 71 | do { \ 72 | for (unsigned i_ = 0; i_ < (size_); ++i_) { \ 73 | arr_[i_] = ethash_swap_u64(arr_[i_]); \ 74 | } \ 75 | } while (0) 76 | #else 77 | # error "endian not supported" 78 | #endif // BYTE_ORDER 79 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/src/bench_schnorr_verify.c: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #include 8 | #include 9 | 10 | #include "include/secp256k1.h" 11 | #include "include/secp256k1_schnorr.h" 12 | #include "util.h" 13 | #include "bench.h" 14 | 15 | typedef struct { 16 | unsigned char key[32]; 17 | unsigned char sig[64]; 18 | unsigned char pubkey[33]; 19 | size_t pubkeylen; 20 | } benchmark_schnorr_sig_t; 21 | 22 | typedef struct { 23 | secp256k1_context *ctx; 24 | unsigned char msg[32]; 25 | benchmark_schnorr_sig_t sigs[64]; 26 | int numsigs; 27 | } benchmark_schnorr_verify_t; 28 | 29 | static void benchmark_schnorr_init(void* arg) { 30 | int i, k; 31 | benchmark_schnorr_verify_t* data = (benchmark_schnorr_verify_t*)arg; 32 | 33 | for (i = 0; i < 32; i++) { 34 | data->msg[i] = 1 + i; 35 | } 36 | for (k = 0; k < data->numsigs; k++) { 37 | secp256k1_pubkey pubkey; 38 | for (i = 0; i < 32; i++) { 39 | data->sigs[k].key[i] = 33 + i + k; 40 | } 41 | secp256k1_schnorr_sign(data->ctx, data->sigs[k].sig, data->msg, data->sigs[k].key, NULL, NULL); 42 | data->sigs[k].pubkeylen = 33; 43 | CHECK(secp256k1_ec_pubkey_create(data->ctx, &pubkey, data->sigs[k].key)); 44 | CHECK(secp256k1_ec_pubkey_serialize(data->ctx, data->sigs[k].pubkey, &data->sigs[k].pubkeylen, &pubkey, SECP256K1_EC_COMPRESSED)); 45 | } 46 | } 47 | 48 | static void benchmark_schnorr_verify(void* arg) { 49 | int i; 50 | benchmark_schnorr_verify_t* data = (benchmark_schnorr_verify_t*)arg; 51 | 52 | for (i = 0; i < 20000 / data->numsigs; i++) { 53 | secp256k1_pubkey pubkey; 54 | data->sigs[0].sig[(i >> 8) % 64] ^= (i & 0xFF); 55 | CHECK(secp256k1_ec_pubkey_parse(data->ctx, &pubkey, data->sigs[0].pubkey, data->sigs[0].pubkeylen)); 56 | CHECK(secp256k1_schnorr_verify(data->ctx, data->sigs[0].sig, data->msg, &pubkey) == ((i & 0xFF) == 0)); 57 | data->sigs[0].sig[(i >> 8) % 64] ^= (i & 0xFF); 58 | } 59 | } 60 | 61 | 62 | 63 | int main(void) { 64 | benchmark_schnorr_verify_t data; 65 | 66 | data.ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY); 67 | 68 | data.numsigs = 1; 69 | run_benchmark("schnorr_verify", benchmark_schnorr_verify, benchmark_schnorr_init, NULL, &data, 10, 20000); 70 | 71 | secp256k1_context_destroy(data.ctx); 72 | return 0; 73 | } 74 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/crypto/signature_nocgo.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 | // +build nacl js nocgo 18 | 19 | package crypto 20 | 21 | import ( 22 | "crypto/ecdsa" 23 | "crypto/elliptic" 24 | "fmt" 25 | 26 | "github.com/btcsuite/btcd/btcec" 27 | ) 28 | 29 | func Ecrecover(hash, sig []byte) ([]byte, error) { 30 | pub, err := SigToPub(hash, sig) 31 | if err != nil { 32 | return nil, err 33 | } 34 | bytes := (*btcec.PublicKey)(pub).SerializeUncompressed() 35 | return bytes, err 36 | } 37 | 38 | func SigToPub(hash, sig []byte) (*ecdsa.PublicKey, error) { 39 | // Convert to btcec input format with 'recovery id' v at the beginning. 40 | btcsig := make([]byte, 65) 41 | btcsig[0] = sig[64] + 27 42 | copy(btcsig[1:], sig) 43 | 44 | pub, _, err := btcec.RecoverCompact(btcec.S256(), btcsig, hash) 45 | return (*ecdsa.PublicKey)(pub), err 46 | } 47 | 48 | // Sign calculates an ECDSA signature. 49 | // 50 | // This function is susceptible to chosen plaintext attacks that can leak 51 | // information about the private key that is used for signing. Callers must 52 | // be aware that the given hash cannot be chosen by an adversery. Common 53 | // solution is to hash any input before calculating the signature. 54 | // 55 | // The produced signature is in the [R || S || V] format where V is 0 or 1. 56 | func Sign(hash []byte, prv *ecdsa.PrivateKey) ([]byte, error) { 57 | if len(hash) != 32 { 58 | return nil, fmt.Errorf("hash is required to be exactly 32 bytes (%d)", len(hash)) 59 | } 60 | if prv.Curve != btcec.S256() { 61 | return nil, fmt.Errorf("private key curve is not secp256k1") 62 | } 63 | sig, err := btcec.SignCompact(btcec.S256(), (*btcec.PrivateKey)(prv), hash, false) 64 | if err != nil { 65 | return nil, err 66 | } 67 | // Convert to Ethereum signature format with 'recovery id' v at the end. 68 | v := sig[0] - 27 69 | copy(sig, sig[1:]) 70 | sig[64] = v 71 | return sig, nil 72 | } 73 | 74 | // S256 returns an instance of the secp256k1 curve. 75 | func S256() elliptic.Curve { 76 | return btcec.S256() 77 | } 78 | -------------------------------------------------------------------------------- /src/libethash/io_win32.c: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of ethash. 3 | 4 | ethash is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU 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 | ethash is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with ethash. If not, see . 16 | */ 17 | /** @file io_win32.c 18 | * @author Lefteris Karapetsas 19 | * @date 2015 20 | */ 21 | 22 | #include "io.h" 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | FILE* ethash_fopen(char const* file_name, char const* mode) 31 | { 32 | FILE* f; 33 | return fopen_s(&f, file_name, mode) == 0 ? f : NULL; 34 | } 35 | 36 | char* ethash_strncat(char* dest, size_t dest_size, char const* src, size_t count) 37 | { 38 | return strncat_s(dest, dest_size, src, count) == 0 ? dest : NULL; 39 | } 40 | 41 | bool ethash_mkdir(char const* dirname) 42 | { 43 | int rc = _mkdir(dirname); 44 | return rc != -1 || errno == EEXIST; 45 | } 46 | 47 | int ethash_fileno(FILE* f) 48 | { 49 | return _fileno(f); 50 | } 51 | 52 | char* ethash_io_create_filename( 53 | char const* dirname, 54 | char const* filename, 55 | size_t filename_length 56 | ) 57 | { 58 | size_t dirlen = strlen(dirname); 59 | size_t dest_size = dirlen + filename_length + 1; 60 | if (dirname[dirlen] != '\\' || dirname[dirlen] != '/') { 61 | dest_size += 1; 62 | } 63 | char* name = malloc(dest_size); 64 | if (!name) { 65 | return NULL; 66 | } 67 | 68 | name[0] = '\0'; 69 | ethash_strncat(name, dest_size, dirname, dirlen); 70 | if (dirname[dirlen] != '\\' || dirname[dirlen] != '/') { 71 | ethash_strncat(name, dest_size, "\\", 1); 72 | } 73 | ethash_strncat(name, dest_size, filename, filename_length); 74 | return name; 75 | } 76 | 77 | bool ethash_file_size(FILE* f, size_t* ret_size) 78 | { 79 | struct _stat st; 80 | int fd; 81 | if ((fd = _fileno(f)) == -1 || _fstat(fd, &st) != 0) { 82 | return false; 83 | } 84 | *ret_size = st.st_size; 85 | return true; 86 | } 87 | 88 | bool ethash_get_default_dirname(char* strbuf, size_t buffsize) 89 | { 90 | static const char dir_suffix[] = "Ethash\\"; 91 | strbuf[0] = '\0'; 92 | if (!SUCCEEDED(SHGetFolderPathA(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, (CHAR*)strbuf))) { 93 | return false; 94 | } 95 | if (!ethash_strncat(strbuf, buffsize, "\\", 1)) { 96 | return false; 97 | } 98 | 99 | return ethash_strncat(strbuf, buffsize, dir_suffix, sizeof(dir_suffix)); 100 | } 101 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/src/num.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2013, 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_NUM_ 8 | #define _SECP256K1_NUM_ 9 | 10 | #ifndef USE_NUM_NONE 11 | 12 | #if defined HAVE_CONFIG_H 13 | #include "libsecp256k1-config.h" 14 | #endif 15 | 16 | #if defined(USE_NUM_GMP) 17 | #include "num_gmp.h" 18 | #else 19 | #error "Please select num implementation" 20 | #endif 21 | 22 | /** Copy a number. */ 23 | static void secp256k1_num_copy(secp256k1_num *r, const secp256k1_num *a); 24 | 25 | /** Convert a number's absolute value to a binary big-endian string. 26 | * There must be enough place. */ 27 | static void secp256k1_num_get_bin(unsigned char *r, unsigned int rlen, const secp256k1_num *a); 28 | 29 | /** Set a number to the value of a binary big-endian string. */ 30 | static void secp256k1_num_set_bin(secp256k1_num *r, const unsigned char *a, unsigned int alen); 31 | 32 | /** Compute a modular inverse. The input must be less than the modulus. */ 33 | static void secp256k1_num_mod_inverse(secp256k1_num *r, const secp256k1_num *a, const secp256k1_num *m); 34 | 35 | /** Compute the jacobi symbol (a|b). b must be positive and odd. */ 36 | static int secp256k1_num_jacobi(const secp256k1_num *a, const secp256k1_num *b); 37 | 38 | /** Compare the absolute value of two numbers. */ 39 | static int secp256k1_num_cmp(const secp256k1_num *a, const secp256k1_num *b); 40 | 41 | /** Test whether two number are equal (including sign). */ 42 | static int secp256k1_num_eq(const secp256k1_num *a, const secp256k1_num *b); 43 | 44 | /** Add two (signed) numbers. */ 45 | static void secp256k1_num_add(secp256k1_num *r, const secp256k1_num *a, const secp256k1_num *b); 46 | 47 | /** Subtract two (signed) numbers. */ 48 | static void secp256k1_num_sub(secp256k1_num *r, const secp256k1_num *a, const secp256k1_num *b); 49 | 50 | /** Multiply two (signed) numbers. */ 51 | static void secp256k1_num_mul(secp256k1_num *r, const secp256k1_num *a, const secp256k1_num *b); 52 | 53 | /** Replace a number by its remainder modulo m. M's sign is ignored. The result is a number between 0 and m-1, 54 | even if r was negative. */ 55 | static void secp256k1_num_mod(secp256k1_num *r, const secp256k1_num *m); 56 | 57 | /** Right-shift the passed number by bits bits. */ 58 | static void secp256k1_num_shift(secp256k1_num *r, int bits); 59 | 60 | /** Check whether a number is zero. */ 61 | static int secp256k1_num_is_zero(const secp256k1_num *a); 62 | 63 | /** Check whether a number is one. */ 64 | static int secp256k1_num_is_one(const secp256k1_num *a); 65 | 66 | /** Check whether a number is strictly negative. */ 67 | static int secp256k1_num_is_neg(const secp256k1_num *a); 68 | 69 | /** Change a number's sign. */ 70 | static void secp256k1_num_negate(secp256k1_num *r); 71 | 72 | #endif 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /vendor/github.com/btcsuite/btcd/btcec/README.md: -------------------------------------------------------------------------------- 1 | btcec 2 | ===== 3 | 4 | [![Build Status](https://travis-ci.org/btcsuite/btcd.png?branch=master)] 5 | (https://travis-ci.org/btcsuite/btcec) [![ISC License] 6 | (http://img.shields.io/badge/license-ISC-blue.svg)](http://copyfree.org) 7 | [![GoDoc](https://godoc.org/github.com/btcsuite/btcd/btcec?status.png)] 8 | (http://godoc.org/github.com/btcsuite/btcd/btcec) 9 | 10 | Package btcec implements elliptic curve cryptography needed for working with 11 | Bitcoin (secp256k1 only for now). It is designed so that it may be used with the 12 | standard crypto/ecdsa packages provided with go. A comprehensive suite of test 13 | is provided to ensure proper functionality. Package btcec was originally based 14 | on work from ThePiachu which is licensed under the same terms as Go, but it has 15 | signficantly diverged since then. The btcsuite developers original is licensed 16 | under the liberal ISC license. 17 | 18 | Although this package was primarily written for btcd, it has intentionally been 19 | designed so it can be used as a standalone package for any projects needing to 20 | use secp256k1 elliptic curve cryptography. 21 | 22 | ## Installation and Updating 23 | 24 | ```bash 25 | $ go get -u github.com/btcsuite/btcd/btcec 26 | ``` 27 | 28 | ## Examples 29 | 30 | * [Sign Message] 31 | (http://godoc.org/github.com/btcsuite/btcd/btcec#example-package--SignMessage) 32 | Demonstrates signing a message with a secp256k1 private key that is first 33 | parsed form raw bytes and serializing the generated signature. 34 | 35 | * [Verify Signature] 36 | (http://godoc.org/github.com/btcsuite/btcd/btcec#example-package--VerifySignature) 37 | Demonstrates verifying a secp256k1 signature against a public key that is 38 | first parsed from raw bytes. The signature is also parsed from raw bytes. 39 | 40 | * [Encryption] 41 | (http://godoc.org/github.com/btcsuite/btcd/btcec#example-package--EncryptMessage) 42 | Demonstrates encrypting a message for a public key that is first parsed from 43 | raw bytes, then decrypting it using the corresponding private key. 44 | 45 | * [Decryption] 46 | (http://godoc.org/github.com/btcsuite/btcd/btcec#example-package--DecryptMessage) 47 | Demonstrates decrypting a message using a private key that is first parsed 48 | from raw bytes. 49 | 50 | ## GPG Verification Key 51 | 52 | All official release tags are signed by Conformal so users can ensure the code 53 | has not been tampered with and is coming from the btcsuite developers. To 54 | verify the signature perform the following: 55 | 56 | - Download the public key from the Conformal website at 57 | https://opensource.conformal.com/GIT-GPG-KEY-conformal.txt 58 | 59 | - Import the public key into your GPG keyring: 60 | ```bash 61 | gpg --import GIT-GPG-KEY-conformal.txt 62 | ``` 63 | 64 | - Verify the release tag with the following command where `TAG_NAME` is a 65 | placeholder for the specific tag: 66 | ```bash 67 | git tag -v TAG_NAME 68 | ``` 69 | 70 | ## License 71 | 72 | Package btcec is licensed under the [copyfree](http://copyfree.org) ISC License 73 | except for btcec.go and btcec_test.go which is under the same license as Go. 74 | 75 | -------------------------------------------------------------------------------- /src/libethash/io_posix.c: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of ethash. 3 | 4 | ethash is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU 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 | ethash is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with ethash. If not, see . 16 | */ 17 | /** @file io_posix.c 18 | * @author Lefteris Karapetsas 19 | * @date 2015 20 | */ 21 | 22 | #include "io.h" 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | FILE* ethash_fopen(char const* file_name, char const* mode) 33 | { 34 | return fopen(file_name, mode); 35 | } 36 | 37 | char* ethash_strncat(char* dest, size_t dest_size, char const* src, size_t count) 38 | { 39 | return strlen(dest) + count + 1 <= dest_size ? strncat(dest, src, count) : NULL; 40 | } 41 | 42 | bool ethash_mkdir(char const* dirname) 43 | { 44 | int rc = mkdir(dirname, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); 45 | return rc != -1 || errno == EEXIST; 46 | } 47 | 48 | int ethash_fileno(FILE *f) 49 | { 50 | return fileno(f); 51 | } 52 | 53 | char* ethash_io_create_filename( 54 | char const* dirname, 55 | char const* filename, 56 | size_t filename_length 57 | ) 58 | { 59 | size_t dirlen = strlen(dirname); 60 | size_t dest_size = dirlen + filename_length + 1; 61 | if (dirname[dirlen] != '/') { 62 | dest_size += 1; 63 | } 64 | char* name = malloc(dest_size); 65 | if (!name) { 66 | return NULL; 67 | } 68 | 69 | name[0] = '\0'; 70 | ethash_strncat(name, dest_size, dirname, dirlen); 71 | if (dirname[dirlen] != '/') { 72 | ethash_strncat(name, dest_size, "/", 1); 73 | } 74 | ethash_strncat(name, dest_size, filename, filename_length); 75 | return name; 76 | } 77 | 78 | bool ethash_file_size(FILE* f, size_t* ret_size) 79 | { 80 | struct stat st; 81 | int fd; 82 | if ((fd = fileno(f)) == -1 || fstat(fd, &st) != 0) { 83 | return false; 84 | } 85 | *ret_size = st.st_size; 86 | return true; 87 | } 88 | 89 | bool ethash_get_default_dirname(char* strbuf, size_t buffsize) 90 | { 91 | static const char dir_suffix[] = ".ethash/"; 92 | strbuf[0] = '\0'; 93 | char* home_dir = getenv("HOME"); 94 | if (!home_dir || strlen(home_dir) == 0) 95 | { 96 | struct passwd* pwd = getpwuid(getuid()); 97 | if (pwd) 98 | home_dir = pwd->pw_dir; 99 | } 100 | 101 | size_t len = strlen(home_dir); 102 | if (!ethash_strncat(strbuf, buffsize, home_dir, len)) { 103 | return false; 104 | } 105 | if (home_dir[len] != '/') { 106 | if (!ethash_strncat(strbuf, buffsize, "/", 1)) { 107 | return false; 108 | } 109 | } 110 | return ethash_strncat(strbuf, buffsize, dir_suffix, sizeof(dir_suffix)); 111 | } 112 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/README.md: -------------------------------------------------------------------------------- 1 | libsecp256k1 2 | ============ 3 | 4 | [![Build Status](https://travis-ci.org/bitcoin-core/secp256k1.svg?branch=master)](https://travis-ci.org/bitcoin-core/secp256k1) 5 | 6 | Optimized C library for EC operations on curve secp256k1. 7 | 8 | This library is a work in progress and is being used to research best practices. Use at your own risk. 9 | 10 | Features: 11 | * secp256k1 ECDSA signing/verification and key generation. 12 | * Adding/multiplying private/public keys. 13 | * Serialization/parsing of private keys, public keys, signatures. 14 | * Constant time, constant memory access signing and pubkey generation. 15 | * Derandomized DSA (via RFC6979 or with a caller provided function.) 16 | * Very efficient implementation. 17 | 18 | Implementation details 19 | ---------------------- 20 | 21 | * General 22 | * No runtime heap allocation. 23 | * Extensive testing infrastructure. 24 | * Structured to facilitate review and analysis. 25 | * Intended to be portable to any system with a C89 compiler and uint64_t support. 26 | * Expose only higher level interfaces to minimize the API surface and improve application security. ("Be difficult to use insecurely.") 27 | * Field operations 28 | * Optimized implementation of arithmetic modulo the curve's field size (2^256 - 0x1000003D1). 29 | * Using 5 52-bit limbs (including hand-optimized assembly for x86_64, by Diederik Huys). 30 | * Using 10 26-bit limbs. 31 | * Field inverses and square roots using a sliding window over blocks of 1s (by Peter Dettman). 32 | * Scalar operations 33 | * Optimized implementation without data-dependent branches of arithmetic modulo the curve's order. 34 | * Using 4 64-bit limbs (relying on __int128 support in the compiler). 35 | * Using 8 32-bit limbs. 36 | * Group operations 37 | * Point addition formula specifically simplified for the curve equation (y^2 = x^3 + 7). 38 | * Use addition between points in Jacobian and affine coordinates where possible. 39 | * Use a unified addition/doubling formula where necessary to avoid data-dependent branches. 40 | * Point/x comparison without a field inversion by comparison in the Jacobian coordinate space. 41 | * Point multiplication for verification (a*P + b*G). 42 | * Use wNAF notation for point multiplicands. 43 | * Use a much larger window for multiples of G, using precomputed multiples. 44 | * Use Shamir's trick to do the multiplication with the public key and the generator simultaneously. 45 | * Optionally (off by default) use secp256k1's efficiently-computable endomorphism to split the P multiplicand into 2 half-sized ones. 46 | * Point multiplication for signing 47 | * Use a precomputed table of multiples of powers of 16 multiplied with the generator, so general multiplication becomes a series of additions. 48 | * Access the table with branch-free conditional moves so memory access is uniform. 49 | * No data-dependent branches 50 | * The precomputed tables add and eventually subtract points for which no known scalar (private key) is known, preventing even an attacker with control over the private key used to control the data internally. 51 | 52 | Build steps 53 | ----------- 54 | 55 | libsecp256k1 is built using autotools: 56 | 57 | $ ./autogen.sh 58 | $ ./configure 59 | $ make 60 | $ ./tests 61 | $ sudo make install # optional 62 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/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 | // output 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 67 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/src/util.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2013, 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_UTIL_H_ 8 | #define _SECP256K1_UTIL_H_ 9 | 10 | #if defined HAVE_CONFIG_H 11 | #include "libsecp256k1-config.h" 12 | #endif 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | typedef struct { 19 | void (*fn)(const char *text, void* data); 20 | const void* data; 21 | } secp256k1_callback; 22 | 23 | static SECP256K1_INLINE void secp256k1_callback_call(const secp256k1_callback * const cb, const char * const text) { 24 | cb->fn(text, (void*)cb->data); 25 | } 26 | 27 | #ifdef DETERMINISTIC 28 | #define TEST_FAILURE(msg) do { \ 29 | fprintf(stderr, "%s\n", msg); \ 30 | abort(); \ 31 | } while(0); 32 | #else 33 | #define TEST_FAILURE(msg) do { \ 34 | fprintf(stderr, "%s:%d: %s\n", __FILE__, __LINE__, msg); \ 35 | abort(); \ 36 | } while(0) 37 | #endif 38 | 39 | #ifdef HAVE_BUILTIN_EXPECT 40 | #define EXPECT(x,c) __builtin_expect((x),(c)) 41 | #else 42 | #define EXPECT(x,c) (x) 43 | #endif 44 | 45 | #ifdef DETERMINISTIC 46 | #define CHECK(cond) do { \ 47 | if (EXPECT(!(cond), 0)) { \ 48 | TEST_FAILURE("test condition failed"); \ 49 | } \ 50 | } while(0) 51 | #else 52 | #define CHECK(cond) do { \ 53 | if (EXPECT(!(cond), 0)) { \ 54 | TEST_FAILURE("test condition failed: " #cond); \ 55 | } \ 56 | } while(0) 57 | #endif 58 | 59 | /* Like assert(), but when VERIFY is defined, and side-effect safe. */ 60 | #if defined(COVERAGE) 61 | #define VERIFY_CHECK(check) 62 | #define VERIFY_SETUP(stmt) 63 | #elif defined(VERIFY) 64 | #define VERIFY_CHECK CHECK 65 | #define VERIFY_SETUP(stmt) do { stmt; } while(0) 66 | #else 67 | #define VERIFY_CHECK(cond) do { (void)(cond); } while(0) 68 | #define VERIFY_SETUP(stmt) 69 | #endif 70 | 71 | static SECP256K1_INLINE void *checked_malloc(const secp256k1_callback* cb, size_t size) { 72 | void *ret = malloc(size); 73 | if (ret == NULL) { 74 | secp256k1_callback_call(cb, "Out of memory"); 75 | } 76 | return ret; 77 | } 78 | 79 | /* Macro for restrict, when available and not in a VERIFY build. */ 80 | #if defined(SECP256K1_BUILD) && defined(VERIFY) 81 | # define SECP256K1_RESTRICT 82 | #else 83 | # if (!defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L) ) 84 | # if SECP256K1_GNUC_PREREQ(3,0) 85 | # define SECP256K1_RESTRICT __restrict__ 86 | # elif (defined(_MSC_VER) && _MSC_VER >= 1400) 87 | # define SECP256K1_RESTRICT __restrict 88 | # else 89 | # define SECP256K1_RESTRICT 90 | # endif 91 | # else 92 | # define SECP256K1_RESTRICT restrict 93 | # endif 94 | #endif 95 | 96 | #if defined(_WIN32) 97 | # define I64FORMAT "I64d" 98 | # define I64uFORMAT "I64u" 99 | #else 100 | # define I64FORMAT "lld" 101 | # define I64uFORMAT "llu" 102 | #endif 103 | 104 | #if defined(HAVE___INT128) 105 | # if defined(__GNUC__) 106 | # define SECP256K1_GNUC_EXT __extension__ 107 | # else 108 | # define SECP256K1_GNUC_EXT 109 | # endif 110 | SECP256K1_GNUC_EXT typedef unsigned __int128 uint128_t; 111 | #endif 112 | 113 | #endif 114 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/log/README.md: -------------------------------------------------------------------------------- 1 | ![obligatory xkcd](http://imgs.xkcd.com/comics/standards.png) 2 | 3 | # log15 [![godoc reference](https://godoc.org/github.com/inconshreveable/log15?status.png)](https://godoc.org/github.com/inconshreveable/log15) [![Build Status](https://travis-ci.org/inconshreveable/log15.svg?branch=master)](https://travis-ci.org/inconshreveable/log15) 4 | 5 | Package log15 provides an opinionated, simple toolkit for best-practice logging in Go (golang) that is both human and machine readable. It is modeled after the Go standard library's [`io`](http://golang.org/pkg/io/) and [`net/http`](http://golang.org/pkg/net/http/) packages and is an alternative to the standard library's [`log`](http://golang.org/pkg/log/) package. 6 | 7 | ## Features 8 | - A simple, easy-to-understand API 9 | - Promotes structured logging by encouraging use of key/value pairs 10 | - Child loggers which inherit and add their own private context 11 | - Lazy evaluation of expensive operations 12 | - Simple Handler interface allowing for construction of flexible, custom logging configurations with a tiny API. 13 | - Color terminal support 14 | - Built-in support for logging to files, streams, syslog, and the network 15 | - Support for forking records to multiple handlers, buffering records for output, failing over from failed handler writes, + more 16 | 17 | ## Versioning 18 | The API of the master branch of log15 should always be considered unstable. If you want to rely on a stable API, 19 | you must vendor the library. 20 | 21 | ## Importing 22 | 23 | ```go 24 | import log "github.com/inconshreveable/log15" 25 | ``` 26 | 27 | ## Examples 28 | 29 | ```go 30 | // all loggers can have key/value context 31 | srvlog := log.New("module", "app/server") 32 | 33 | // all log messages can have key/value context 34 | srvlog.Warn("abnormal conn rate", "rate", curRate, "low", lowRate, "high", highRate) 35 | 36 | // child loggers with inherited context 37 | connlog := srvlog.New("raddr", c.RemoteAddr()) 38 | connlog.Info("connection open") 39 | 40 | // lazy evaluation 41 | connlog.Debug("ping remote", "latency", log.Lazy{pingRemote}) 42 | 43 | // flexible configuration 44 | srvlog.SetHandler(log.MultiHandler( 45 | log.StreamHandler(os.Stderr, log.LogfmtFormat()), 46 | log.LvlFilterHandler( 47 | log.LvlError, 48 | log.Must.FileHandler("errors.json", log.JsonFormat())))) 49 | ``` 50 | 51 | Will result in output that looks like this: 52 | 53 | ``` 54 | WARN[06-17|21:58:10] abnormal conn rate module=app/server rate=0.500 low=0.100 high=0.800 55 | INFO[06-17|21:58:10] connection open module=app/server raddr=10.0.0.1 56 | ``` 57 | 58 | ## Breaking API Changes 59 | The following commits broke API stability. This reference is intended to help you understand the consequences of updating to a newer version 60 | of log15. 61 | 62 | - 57a084d014d4150152b19e4e531399a7145d1540 - Added a `Get()` method to the `Logger` interface to retrieve the current handler 63 | - 93404652ee366648fa622b64d1e2b67d75a3094a - `Record` field `Call` changed to `stack.Call` with switch to `github.com/go-stack/stack` 64 | - a5e7613673c73281f58e15a87d2cf0cf111e8152 - Restored `syslog.Priority` argument to the `SyslogXxx` handler constructors 65 | 66 | ## FAQ 67 | 68 | ### The varargs style is brittle and error prone! Can I have type safety please? 69 | Yes. Use `log.Ctx`: 70 | 71 | ```go 72 | srvlog := log.New(log.Ctx{"module": "app/server"}) 73 | srvlog.Warn("abnormal conn rate", log.Ctx{"rate": curRate, "low": lowRate, "high": highRate}) 74 | ``` 75 | 76 | ## License 77 | Apache 78 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/src/eckey_impl.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2013, 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_ECKEY_IMPL_H_ 8 | #define _SECP256K1_ECKEY_IMPL_H_ 9 | 10 | #include "eckey.h" 11 | 12 | #include "scalar.h" 13 | #include "field.h" 14 | #include "group.h" 15 | #include "ecmult_gen.h" 16 | 17 | static int secp256k1_eckey_pubkey_parse(secp256k1_ge *elem, const unsigned char *pub, size_t size) { 18 | if (size == 33 && (pub[0] == 0x02 || pub[0] == 0x03)) { 19 | secp256k1_fe x; 20 | return secp256k1_fe_set_b32(&x, pub+1) && secp256k1_ge_set_xo_var(elem, &x, pub[0] == 0x03); 21 | } else if (size == 65 && (pub[0] == 0x04 || pub[0] == 0x06 || pub[0] == 0x07)) { 22 | secp256k1_fe x, y; 23 | if (!secp256k1_fe_set_b32(&x, pub+1) || !secp256k1_fe_set_b32(&y, pub+33)) { 24 | return 0; 25 | } 26 | secp256k1_ge_set_xy(elem, &x, &y); 27 | if ((pub[0] == 0x06 || pub[0] == 0x07) && secp256k1_fe_is_odd(&y) != (pub[0] == 0x07)) { 28 | return 0; 29 | } 30 | return secp256k1_ge_is_valid_var(elem); 31 | } else { 32 | return 0; 33 | } 34 | } 35 | 36 | static int secp256k1_eckey_pubkey_serialize(secp256k1_ge *elem, unsigned char *pub, size_t *size, int compressed) { 37 | if (secp256k1_ge_is_infinity(elem)) { 38 | return 0; 39 | } 40 | secp256k1_fe_normalize_var(&elem->x); 41 | secp256k1_fe_normalize_var(&elem->y); 42 | secp256k1_fe_get_b32(&pub[1], &elem->x); 43 | if (compressed) { 44 | *size = 33; 45 | pub[0] = 0x02 | (secp256k1_fe_is_odd(&elem->y) ? 0x01 : 0x00); 46 | } else { 47 | *size = 65; 48 | pub[0] = 0x04; 49 | secp256k1_fe_get_b32(&pub[33], &elem->y); 50 | } 51 | return 1; 52 | } 53 | 54 | static int secp256k1_eckey_privkey_tweak_add(secp256k1_scalar *key, const secp256k1_scalar *tweak) { 55 | secp256k1_scalar_add(key, key, tweak); 56 | if (secp256k1_scalar_is_zero(key)) { 57 | return 0; 58 | } 59 | return 1; 60 | } 61 | 62 | static int secp256k1_eckey_pubkey_tweak_add(const secp256k1_ecmult_context *ctx, secp256k1_ge *key, const secp256k1_scalar *tweak) { 63 | secp256k1_gej pt; 64 | secp256k1_scalar one; 65 | secp256k1_gej_set_ge(&pt, key); 66 | secp256k1_scalar_set_int(&one, 1); 67 | secp256k1_ecmult(ctx, &pt, &pt, &one, tweak); 68 | 69 | if (secp256k1_gej_is_infinity(&pt)) { 70 | return 0; 71 | } 72 | secp256k1_ge_set_gej(key, &pt); 73 | return 1; 74 | } 75 | 76 | static int secp256k1_eckey_privkey_tweak_mul(secp256k1_scalar *key, const secp256k1_scalar *tweak) { 77 | if (secp256k1_scalar_is_zero(tweak)) { 78 | return 0; 79 | } 80 | 81 | secp256k1_scalar_mul(key, key, tweak); 82 | return 1; 83 | } 84 | 85 | static int secp256k1_eckey_pubkey_tweak_mul(const secp256k1_ecmult_context *ctx, secp256k1_ge *key, const secp256k1_scalar *tweak) { 86 | secp256k1_scalar zero; 87 | secp256k1_gej pt; 88 | if (secp256k1_scalar_is_zero(tweak)) { 89 | return 0; 90 | } 91 | 92 | secp256k1_scalar_set_int(&zero, 0); 93 | secp256k1_gej_set_ge(&pt, key); 94 | secp256k1_ecmult(ctx, &pt, &pt, tweak, &zero); 95 | secp256k1_ge_set_gej(key, &pt); 96 | return 1; 97 | } 98 | 99 | #endif 100 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/ext.h: -------------------------------------------------------------------------------- 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 | // secp256k1_context_create_sign_verify creates a context for signing and signature verification. 18 | static secp256k1_context* secp256k1_context_create_sign_verify() { 19 | return secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY); 20 | } 21 | 22 | // secp256k1_ecdsa_recover_pubkey recovers the public key of an encoded compact signature. 23 | // 24 | // Returns: 1: recovery was successful 25 | // 0: recovery was not successful 26 | // Args: ctx: pointer to a context object (cannot be NULL) 27 | // Out: pubkey_out: the serialized 65-byte public key of the signer (cannot be NULL) 28 | // In: sigdata: pointer to a 65-byte signature with the recovery id at the end (cannot be NULL) 29 | // msgdata: pointer to a 32-byte message (cannot be NULL) 30 | static int secp256k1_ecdsa_recover_pubkey( 31 | const secp256k1_context* ctx, 32 | unsigned char *pubkey_out, 33 | const unsigned char *sigdata, 34 | const unsigned char *msgdata 35 | ) { 36 | secp256k1_ecdsa_recoverable_signature sig; 37 | secp256k1_pubkey pubkey; 38 | 39 | if (!secp256k1_ecdsa_recoverable_signature_parse_compact(ctx, &sig, sigdata, (int)sigdata[64])) { 40 | return 0; 41 | } 42 | if (!secp256k1_ecdsa_recover(ctx, &pubkey, &sig, msgdata)) { 43 | return 0; 44 | } 45 | size_t outputlen = 65; 46 | return secp256k1_ec_pubkey_serialize(ctx, pubkey_out, &outputlen, &pubkey, SECP256K1_EC_UNCOMPRESSED); 47 | } 48 | 49 | // secp256k1_pubkey_scalar_mul multiplies a point by a scalar in constant time. 50 | // 51 | // Returns: 1: multiplication was successful 52 | // 0: scalar was invalid (zero or overflow) 53 | // Args: ctx: pointer to a context object (cannot be NULL) 54 | // Out: point: the multiplied point (usually secret) 55 | // In: point: pointer to a 64-byte public point, 56 | // encoded as two 256bit big-endian numbers. 57 | // scalar: a 32-byte scalar with which to multiply the point 58 | int secp256k1_pubkey_scalar_mul(const secp256k1_context* ctx, unsigned char *point, const unsigned char *scalar) { 59 | int ret = 0; 60 | int overflow = 0; 61 | secp256k1_fe feX, feY; 62 | secp256k1_gej res; 63 | secp256k1_ge ge; 64 | secp256k1_scalar s; 65 | ARG_CHECK(point != NULL); 66 | ARG_CHECK(scalar != NULL); 67 | (void)ctx; 68 | 69 | secp256k1_fe_set_b32(&feX, point); 70 | secp256k1_fe_set_b32(&feY, point+32); 71 | secp256k1_ge_set_xy(&ge, &feX, &feY); 72 | secp256k1_scalar_set_b32(&s, scalar, &overflow); 73 | if (overflow || secp256k1_scalar_is_zero(&s)) { 74 | ret = 0; 75 | } else { 76 | secp256k1_ecmult_const(&res, &ge, &s); 77 | secp256k1_ge_set_gej(&ge, &res); 78 | /* Note: can't use secp256k1_pubkey_save here because it is not constant time. */ 79 | secp256k1_fe_normalize(&ge.x); 80 | secp256k1_fe_normalize(&ge.y); 81 | secp256k1_fe_get_b32(point, &ge.x); 82 | secp256k1_fe_get_b32(point+32, &ge.y); 83 | ret = 1; 84 | } 85 | secp256k1_scalar_clear(&s); 86 | return ret; 87 | } 88 | -------------------------------------------------------------------------------- /src/libethash/io.c: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of ethash. 3 | 4 | ethash is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU 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 | ethash is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with ethash. If not, see . 16 | */ 17 | /** @file io.c 18 | * @author Lefteris Karapetsas 19 | * @date 2015 20 | */ 21 | #include "io.h" 22 | #include 23 | #include 24 | #include 25 | 26 | enum ethash_io_rc ethash_io_prepare( 27 | char const* dirname, 28 | ethash_h256_t const seedhash, 29 | FILE** output_file, 30 | uint64_t file_size, 31 | bool force_create 32 | ) 33 | { 34 | char mutable_name[DAG_MUTABLE_NAME_MAX_SIZE]; 35 | enum ethash_io_rc ret = ETHASH_IO_FAIL; 36 | // reset errno before io calls 37 | errno = 0; 38 | 39 | // assert directory exists 40 | if (!ethash_mkdir(dirname)) { 41 | ETHASH_CRITICAL("Could not create the ethash directory"); 42 | goto end; 43 | } 44 | 45 | ethash_io_mutable_name(ETHASH_REVISION, &seedhash, mutable_name); 46 | char* tmpfile = ethash_io_create_filename(dirname, mutable_name, strlen(mutable_name)); 47 | if (!tmpfile) { 48 | ETHASH_CRITICAL("Could not create the full DAG pathname"); 49 | goto end; 50 | } 51 | 52 | FILE *f; 53 | if (!force_create) { 54 | // try to open the file 55 | f = ethash_fopen(tmpfile, "rb+"); 56 | if (f) { 57 | size_t found_size; 58 | if (!ethash_file_size(f, &found_size)) { 59 | fclose(f); 60 | ETHASH_CRITICAL("Could not query size of DAG file: \"%s\"", tmpfile); 61 | goto free_memo; 62 | } 63 | if (file_size != found_size - ETHASH_DAG_MAGIC_NUM_SIZE) { 64 | fclose(f); 65 | ret = ETHASH_IO_MEMO_SIZE_MISMATCH; 66 | goto free_memo; 67 | } 68 | // compare the magic number, no need to care about endianess since it's local 69 | uint64_t magic_num; 70 | if (fread(&magic_num, ETHASH_DAG_MAGIC_NUM_SIZE, 1, f) != 1) { 71 | // I/O error 72 | fclose(f); 73 | ETHASH_CRITICAL("Could not read from DAG file: \"%s\"", tmpfile); 74 | ret = ETHASH_IO_MEMO_SIZE_MISMATCH; 75 | goto free_memo; 76 | } 77 | if (magic_num != ETHASH_DAG_MAGIC_NUM) { 78 | fclose(f); 79 | ret = ETHASH_IO_MEMO_SIZE_MISMATCH; 80 | goto free_memo; 81 | } 82 | ret = ETHASH_IO_MEMO_MATCH; 83 | goto set_file; 84 | } 85 | } 86 | 87 | // file does not exist, will need to be created 88 | f = ethash_fopen(tmpfile, "wb+"); 89 | if (!f) { 90 | ETHASH_CRITICAL("Could not create DAG file: \"%s\"", tmpfile); 91 | goto free_memo; 92 | } 93 | // make sure it's of the proper size 94 | if (fseek(f, (long int)(file_size + ETHASH_DAG_MAGIC_NUM_SIZE - 1), SEEK_SET) != 0) { 95 | fclose(f); 96 | ETHASH_CRITICAL("Could not seek to the end of DAG file: \"%s\". Insufficient space?", tmpfile); 97 | goto free_memo; 98 | } 99 | if (fputc('\n', f) == EOF) { 100 | fclose(f); 101 | ETHASH_CRITICAL("Could not write in the end of DAG file: \"%s\". Insufficient space?", tmpfile); 102 | goto free_memo; 103 | } 104 | if (fflush(f) != 0) { 105 | fclose(f); 106 | ETHASH_CRITICAL("Could not flush at end of DAG file: \"%s\". Insufficient space?", tmpfile); 107 | goto free_memo; 108 | } 109 | ret = ETHASH_IO_MEMO_MISMATCH; 110 | goto set_file; 111 | 112 | ret = ETHASH_IO_MEMO_MATCH; 113 | set_file: 114 | *output_file = f; 115 | free_memo: 116 | free(tmpfile); 117 | end: 118 | return ret; 119 | } 120 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/contrib/lax_der_privatekey_parsing.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2014, 2015 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | /**** 8 | * Please do not link this file directly. It is not part of the libsecp256k1 9 | * project and does not promise any stability in its API, functionality or 10 | * presence. Projects which use this code should instead copy this header 11 | * and its accompanying .c file directly into their codebase. 12 | ****/ 13 | 14 | /* This file contains code snippets that parse DER private keys with 15 | * various errors and violations. This is not a part of the library 16 | * itself, because the allowed violations are chosen arbitrarily and 17 | * do not follow or establish any standard. 18 | * 19 | * It also contains code to serialize private keys in a compatible 20 | * manner. 21 | * 22 | * These functions are meant for compatibility with applications 23 | * that require BER encoded keys. When working with secp256k1-specific 24 | * code, the simple 32-byte private keys normally used by the 25 | * library are sufficient. 26 | */ 27 | 28 | #ifndef _SECP256K1_CONTRIB_BER_PRIVATEKEY_H_ 29 | #define _SECP256K1_CONTRIB_BER_PRIVATEKEY_H_ 30 | 31 | #include 32 | 33 | # ifdef __cplusplus 34 | extern "C" { 35 | # endif 36 | 37 | /** Export a private key in DER format. 38 | * 39 | * Returns: 1 if the private key was valid. 40 | * Args: ctx: pointer to a context object, initialized for signing (cannot 41 | * be NULL) 42 | * Out: privkey: pointer to an array for storing the private key in BER. 43 | * Should have space for 279 bytes, and cannot be NULL. 44 | * privkeylen: Pointer to an int where the length of the private key in 45 | * privkey will be stored. 46 | * In: seckey: pointer to a 32-byte secret key to export. 47 | * compressed: 1 if the key should be exported in 48 | * compressed format, 0 otherwise 49 | * 50 | * This function is purely meant for compatibility with applications that 51 | * require BER encoded keys. When working with secp256k1-specific code, the 52 | * simple 32-byte private keys are sufficient. 53 | * 54 | * Note that this function does not guarantee correct DER output. It is 55 | * guaranteed to be parsable by secp256k1_ec_privkey_import_der 56 | */ 57 | SECP256K1_WARN_UNUSED_RESULT int ec_privkey_export_der( 58 | const secp256k1_context* ctx, 59 | unsigned char *privkey, 60 | size_t *privkeylen, 61 | const unsigned char *seckey, 62 | int compressed 63 | ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4); 64 | 65 | /** Import a private key in DER format. 66 | * Returns: 1 if a private key was extracted. 67 | * Args: ctx: pointer to a context object (cannot be NULL). 68 | * Out: seckey: pointer to a 32-byte array for storing the private key. 69 | * (cannot be NULL). 70 | * In: privkey: pointer to a private key in DER format (cannot be NULL). 71 | * privkeylen: length of the DER private key pointed to be privkey. 72 | * 73 | * This function will accept more than just strict DER, and even allow some BER 74 | * violations. The public key stored inside the DER-encoded private key is not 75 | * verified for correctness, nor are the curve parameters. Use this function 76 | * only if you know in advance it is supposed to contain a secp256k1 private 77 | * key. 78 | */ 79 | SECP256K1_WARN_UNUSED_RESULT int ec_privkey_import_der( 80 | const secp256k1_context* ctx, 81 | unsigned char *seckey, 82 | const unsigned char *privkey, 83 | size_t privkeylen 84 | ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); 85 | 86 | #ifdef __cplusplus 87 | } 88 | #endif 89 | 90 | #endif 91 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/contrib/lax_der_parsing.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2015 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | /**** 8 | * Please do not link this file directly. It is not part of the libsecp256k1 9 | * project and does not promise any stability in its API, functionality or 10 | * presence. Projects which use this code should instead copy this header 11 | * and its accompanying .c file directly into their codebase. 12 | ****/ 13 | 14 | /* This file defines a function that parses DER with various errors and 15 | * violations. This is not a part of the library itself, because the allowed 16 | * violations are chosen arbitrarily and do not follow or establish any 17 | * standard. 18 | * 19 | * In many places it matters that different implementations do not only accept 20 | * the same set of valid signatures, but also reject the same set of signatures. 21 | * The only means to accomplish that is by strictly obeying a standard, and not 22 | * accepting anything else. 23 | * 24 | * Nonetheless, sometimes there is a need for compatibility with systems that 25 | * use signatures which do not strictly obey DER. The snippet below shows how 26 | * certain violations are easily supported. You may need to adapt it. 27 | * 28 | * Do not use this for new systems. Use well-defined DER or compact signatures 29 | * instead if you have the choice (see secp256k1_ecdsa_signature_parse_der and 30 | * secp256k1_ecdsa_signature_parse_compact). 31 | * 32 | * The supported violations are: 33 | * - All numbers are parsed as nonnegative integers, even though X.609-0207 34 | * section 8.3.3 specifies that integers are always encoded as two's 35 | * complement. 36 | * - Integers can have length 0, even though section 8.3.1 says they can't. 37 | * - Integers with overly long padding are accepted, violation section 38 | * 8.3.2. 39 | * - 127-byte long length descriptors are accepted, even though section 40 | * 8.1.3.5.c says that they are not. 41 | * - Trailing garbage data inside or after the signature is ignored. 42 | * - The length descriptor of the sequence is ignored. 43 | * 44 | * Compared to for example OpenSSL, many violations are NOT supported: 45 | * - Using overly long tag descriptors for the sequence or integers inside, 46 | * violating section 8.1.2.2. 47 | * - Encoding primitive integers as constructed values, violating section 48 | * 8.3.1. 49 | */ 50 | 51 | #ifndef _SECP256K1_CONTRIB_LAX_DER_PARSING_H_ 52 | #define _SECP256K1_CONTRIB_LAX_DER_PARSING_H_ 53 | 54 | #include 55 | 56 | # ifdef __cplusplus 57 | extern "C" { 58 | # endif 59 | 60 | /** Parse a signature in "lax DER" format 61 | * 62 | * Returns: 1 when the signature could be parsed, 0 otherwise. 63 | * Args: ctx: a secp256k1 context object 64 | * Out: sig: a pointer to a signature object 65 | * In: input: a pointer to the signature to be parsed 66 | * inputlen: the length of the array pointed to be input 67 | * 68 | * This function will accept any valid DER encoded signature, even if the 69 | * encoded numbers are out of range. In addition, it will accept signatures 70 | * which violate the DER spec in various ways. Its purpose is to allow 71 | * validation of the Bitcoin blockchain, which includes non-DER signatures 72 | * from before the network rules were updated to enforce DER. Note that 73 | * the set of supported violations is a strict subset of what OpenSSL will 74 | * accept. 75 | * 76 | * After the call, sig will always be initialized. If parsing failed or the 77 | * encoded numbers are out of range, signature validation with it is 78 | * guaranteed to fail for every message and public key. 79 | */ 80 | int ecdsa_signature_parse_der_lax( 81 | const secp256k1_context* ctx, 82 | secp256k1_ecdsa_signature* sig, 83 | const unsigned char *input, 84 | size_t inputlen 85 | ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3); 86 | 87 | #ifdef __cplusplus 88 | } 89 | #endif 90 | 91 | #endif 92 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/src/scalar_low_impl.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2015 Andrew Poelstra * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_SCALAR_REPR_IMPL_H_ 8 | #define _SECP256K1_SCALAR_REPR_IMPL_H_ 9 | 10 | #include "scalar.h" 11 | 12 | #include 13 | 14 | SECP256K1_INLINE static int secp256k1_scalar_is_even(const secp256k1_scalar *a) { 15 | return !(*a & 1); 16 | } 17 | 18 | SECP256K1_INLINE static void secp256k1_scalar_clear(secp256k1_scalar *r) { *r = 0; } 19 | SECP256K1_INLINE static void secp256k1_scalar_set_int(secp256k1_scalar *r, unsigned int v) { *r = v; } 20 | 21 | SECP256K1_INLINE static unsigned int secp256k1_scalar_get_bits(const secp256k1_scalar *a, unsigned int offset, unsigned int count) { 22 | if (offset < 32) 23 | return ((*a >> offset) & ((((uint32_t)1) << count) - 1)); 24 | else 25 | return 0; 26 | } 27 | 28 | SECP256K1_INLINE static unsigned int secp256k1_scalar_get_bits_var(const secp256k1_scalar *a, unsigned int offset, unsigned int count) { 29 | return secp256k1_scalar_get_bits(a, offset, count); 30 | } 31 | 32 | SECP256K1_INLINE static int secp256k1_scalar_check_overflow(const secp256k1_scalar *a) { return *a >= EXHAUSTIVE_TEST_ORDER; } 33 | 34 | static int secp256k1_scalar_add(secp256k1_scalar *r, const secp256k1_scalar *a, const secp256k1_scalar *b) { 35 | *r = (*a + *b) % EXHAUSTIVE_TEST_ORDER; 36 | return *r < *b; 37 | } 38 | 39 | static void secp256k1_scalar_cadd_bit(secp256k1_scalar *r, unsigned int bit, int flag) { 40 | if (flag && bit < 32) 41 | *r += (1 << bit); 42 | #ifdef VERIFY 43 | VERIFY_CHECK(secp256k1_scalar_check_overflow(r) == 0); 44 | #endif 45 | } 46 | 47 | static void secp256k1_scalar_set_b32(secp256k1_scalar *r, const unsigned char *b32, int *overflow) { 48 | const int base = 0x100 % EXHAUSTIVE_TEST_ORDER; 49 | int i; 50 | *r = 0; 51 | for (i = 0; i < 32; i++) { 52 | *r = ((*r * base) + b32[i]) % EXHAUSTIVE_TEST_ORDER; 53 | } 54 | /* just deny overflow, it basically always happens */ 55 | if (overflow) *overflow = 0; 56 | } 57 | 58 | static void secp256k1_scalar_get_b32(unsigned char *bin, const secp256k1_scalar* a) { 59 | memset(bin, 0, 32); 60 | bin[28] = *a >> 24; bin[29] = *a >> 16; bin[30] = *a >> 8; bin[31] = *a; 61 | } 62 | 63 | SECP256K1_INLINE static int secp256k1_scalar_is_zero(const secp256k1_scalar *a) { 64 | return *a == 0; 65 | } 66 | 67 | static void secp256k1_scalar_negate(secp256k1_scalar *r, const secp256k1_scalar *a) { 68 | if (*a == 0) { 69 | *r = 0; 70 | } else { 71 | *r = EXHAUSTIVE_TEST_ORDER - *a; 72 | } 73 | } 74 | 75 | SECP256K1_INLINE static int secp256k1_scalar_is_one(const secp256k1_scalar *a) { 76 | return *a == 1; 77 | } 78 | 79 | static int secp256k1_scalar_is_high(const secp256k1_scalar *a) { 80 | return *a > EXHAUSTIVE_TEST_ORDER / 2; 81 | } 82 | 83 | static int secp256k1_scalar_cond_negate(secp256k1_scalar *r, int flag) { 84 | if (flag) secp256k1_scalar_negate(r, r); 85 | return flag ? -1 : 1; 86 | } 87 | 88 | static void secp256k1_scalar_mul(secp256k1_scalar *r, const secp256k1_scalar *a, const secp256k1_scalar *b) { 89 | *r = (*a * *b) % EXHAUSTIVE_TEST_ORDER; 90 | } 91 | 92 | static int secp256k1_scalar_shr_int(secp256k1_scalar *r, int n) { 93 | int ret; 94 | VERIFY_CHECK(n > 0); 95 | VERIFY_CHECK(n < 16); 96 | ret = *r & ((1 << n) - 1); 97 | *r >>= n; 98 | return ret; 99 | } 100 | 101 | static void secp256k1_scalar_sqr(secp256k1_scalar *r, const secp256k1_scalar *a) { 102 | *r = (*a * *a) % EXHAUSTIVE_TEST_ORDER; 103 | } 104 | 105 | static void secp256k1_scalar_split_128(secp256k1_scalar *r1, secp256k1_scalar *r2, const secp256k1_scalar *a) { 106 | *r1 = *a; 107 | *r2 = 0; 108 | } 109 | 110 | SECP256K1_INLINE static int secp256k1_scalar_eq(const secp256k1_scalar *a, const secp256k1_scalar *b) { 111 | return *a == *b; 112 | } 113 | 114 | #endif 115 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/src/java/org_bitcoin_NativeSecp256k1.h: -------------------------------------------------------------------------------- 1 | /* DO NOT EDIT THIS FILE - it is machine generated */ 2 | #include 3 | #include "include/secp256k1.h" 4 | /* Header for class org_bitcoin_NativeSecp256k1 */ 5 | 6 | #ifndef _Included_org_bitcoin_NativeSecp256k1 7 | #define _Included_org_bitcoin_NativeSecp256k1 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | /* 12 | * Class: org_bitcoin_NativeSecp256k1 13 | * Method: secp256k1_ctx_clone 14 | * Signature: (J)J 15 | */ 16 | SECP256K1_API jlong JNICALL Java_org_bitcoin_NativeSecp256k1_secp256k1_1ctx_1clone 17 | (JNIEnv *, jclass, jlong); 18 | 19 | /* 20 | * Class: org_bitcoin_NativeSecp256k1 21 | * Method: secp256k1_context_randomize 22 | * Signature: (Ljava/nio/ByteBuffer;J)I 23 | */ 24 | SECP256K1_API jint JNICALL Java_org_bitcoin_NativeSecp256k1_secp256k1_1context_1randomize 25 | (JNIEnv *, jclass, jobject, jlong); 26 | 27 | /* 28 | * Class: org_bitcoin_NativeSecp256k1 29 | * Method: secp256k1_privkey_tweak_add 30 | * Signature: (Ljava/nio/ByteBuffer;J)[[B 31 | */ 32 | SECP256K1_API jobjectArray JNICALL Java_org_bitcoin_NativeSecp256k1_secp256k1_1privkey_1tweak_1add 33 | (JNIEnv *, jclass, jobject, jlong); 34 | 35 | /* 36 | * Class: org_bitcoin_NativeSecp256k1 37 | * Method: secp256k1_privkey_tweak_mul 38 | * Signature: (Ljava/nio/ByteBuffer;J)[[B 39 | */ 40 | SECP256K1_API jobjectArray JNICALL Java_org_bitcoin_NativeSecp256k1_secp256k1_1privkey_1tweak_1mul 41 | (JNIEnv *, jclass, jobject, jlong); 42 | 43 | /* 44 | * Class: org_bitcoin_NativeSecp256k1 45 | * Method: secp256k1_pubkey_tweak_add 46 | * Signature: (Ljava/nio/ByteBuffer;JI)[[B 47 | */ 48 | SECP256K1_API jobjectArray JNICALL Java_org_bitcoin_NativeSecp256k1_secp256k1_1pubkey_1tweak_1add 49 | (JNIEnv *, jclass, jobject, jlong, jint); 50 | 51 | /* 52 | * Class: org_bitcoin_NativeSecp256k1 53 | * Method: secp256k1_pubkey_tweak_mul 54 | * Signature: (Ljava/nio/ByteBuffer;JI)[[B 55 | */ 56 | SECP256K1_API jobjectArray JNICALL Java_org_bitcoin_NativeSecp256k1_secp256k1_1pubkey_1tweak_1mul 57 | (JNIEnv *, jclass, jobject, jlong, jint); 58 | 59 | /* 60 | * Class: org_bitcoin_NativeSecp256k1 61 | * Method: secp256k1_destroy_context 62 | * Signature: (J)V 63 | */ 64 | SECP256K1_API void JNICALL Java_org_bitcoin_NativeSecp256k1_secp256k1_1destroy_1context 65 | (JNIEnv *, jclass, jlong); 66 | 67 | /* 68 | * Class: org_bitcoin_NativeSecp256k1 69 | * Method: secp256k1_ecdsa_verify 70 | * Signature: (Ljava/nio/ByteBuffer;JII)I 71 | */ 72 | SECP256K1_API jint JNICALL Java_org_bitcoin_NativeSecp256k1_secp256k1_1ecdsa_1verify 73 | (JNIEnv *, jclass, jobject, jlong, jint, jint); 74 | 75 | /* 76 | * Class: org_bitcoin_NativeSecp256k1 77 | * Method: secp256k1_ecdsa_sign 78 | * Signature: (Ljava/nio/ByteBuffer;J)[[B 79 | */ 80 | SECP256K1_API jobjectArray JNICALL Java_org_bitcoin_NativeSecp256k1_secp256k1_1ecdsa_1sign 81 | (JNIEnv *, jclass, jobject, jlong); 82 | 83 | /* 84 | * Class: org_bitcoin_NativeSecp256k1 85 | * Method: secp256k1_ec_seckey_verify 86 | * Signature: (Ljava/nio/ByteBuffer;J)I 87 | */ 88 | SECP256K1_API jint JNICALL Java_org_bitcoin_NativeSecp256k1_secp256k1_1ec_1seckey_1verify 89 | (JNIEnv *, jclass, jobject, jlong); 90 | 91 | /* 92 | * Class: org_bitcoin_NativeSecp256k1 93 | * Method: secp256k1_ec_pubkey_create 94 | * Signature: (Ljava/nio/ByteBuffer;J)[[B 95 | */ 96 | SECP256K1_API jobjectArray JNICALL Java_org_bitcoin_NativeSecp256k1_secp256k1_1ec_1pubkey_1create 97 | (JNIEnv *, jclass, jobject, jlong); 98 | 99 | /* 100 | * Class: org_bitcoin_NativeSecp256k1 101 | * Method: secp256k1_ec_pubkey_parse 102 | * Signature: (Ljava/nio/ByteBuffer;JI)[[B 103 | */ 104 | SECP256K1_API jobjectArray JNICALL Java_org_bitcoin_NativeSecp256k1_secp256k1_1ec_1pubkey_1parse 105 | (JNIEnv *, jclass, jobject, jlong, jint); 106 | 107 | /* 108 | * Class: org_bitcoin_NativeSecp256k1 109 | * Method: secp256k1_ecdh 110 | * Signature: (Ljava/nio/ByteBuffer;JI)[[B 111 | */ 112 | SECP256K1_API jobjectArray JNICALL Java_org_bitcoin_NativeSecp256k1_secp256k1_1ecdh 113 | (JNIEnv* env, jclass classObject, jobject byteBufferObject, jlong ctx_l, jint publen); 114 | 115 | 116 | #ifdef __cplusplus 117 | } 118 | #endif 119 | #endif 120 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/src/modules/ecdh/tests_impl.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2015 Andrew Poelstra * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_MODULE_ECDH_TESTS_ 8 | #define _SECP256K1_MODULE_ECDH_TESTS_ 9 | 10 | void test_ecdh_api(void) { 11 | /* Setup context that just counts errors */ 12 | secp256k1_context *tctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN); 13 | secp256k1_pubkey point; 14 | unsigned char res[32]; 15 | unsigned char s_one[32] = { 0 }; 16 | int32_t ecount = 0; 17 | s_one[31] = 1; 18 | 19 | secp256k1_context_set_error_callback(tctx, counting_illegal_callback_fn, &ecount); 20 | secp256k1_context_set_illegal_callback(tctx, counting_illegal_callback_fn, &ecount); 21 | CHECK(secp256k1_ec_pubkey_create(tctx, &point, s_one) == 1); 22 | 23 | /* Check all NULLs are detected */ 24 | CHECK(secp256k1_ecdh(tctx, res, &point, s_one) == 1); 25 | CHECK(ecount == 0); 26 | CHECK(secp256k1_ecdh(tctx, NULL, &point, s_one) == 0); 27 | CHECK(ecount == 1); 28 | CHECK(secp256k1_ecdh(tctx, res, NULL, s_one) == 0); 29 | CHECK(ecount == 2); 30 | CHECK(secp256k1_ecdh(tctx, res, &point, NULL) == 0); 31 | CHECK(ecount == 3); 32 | CHECK(secp256k1_ecdh(tctx, res, &point, s_one) == 1); 33 | CHECK(ecount == 3); 34 | 35 | /* Cleanup */ 36 | secp256k1_context_destroy(tctx); 37 | } 38 | 39 | void test_ecdh_generator_basepoint(void) { 40 | unsigned char s_one[32] = { 0 }; 41 | secp256k1_pubkey point[2]; 42 | int i; 43 | 44 | s_one[31] = 1; 45 | /* Check against pubkey creation when the basepoint is the generator */ 46 | for (i = 0; i < 100; ++i) { 47 | secp256k1_sha256_t sha; 48 | unsigned char s_b32[32]; 49 | unsigned char output_ecdh[32]; 50 | unsigned char output_ser[32]; 51 | unsigned char point_ser[33]; 52 | size_t point_ser_len = sizeof(point_ser); 53 | secp256k1_scalar s; 54 | 55 | random_scalar_order(&s); 56 | secp256k1_scalar_get_b32(s_b32, &s); 57 | 58 | /* compute using ECDH function */ 59 | CHECK(secp256k1_ec_pubkey_create(ctx, &point[0], s_one) == 1); 60 | CHECK(secp256k1_ecdh(ctx, output_ecdh, &point[0], s_b32) == 1); 61 | /* compute "explicitly" */ 62 | CHECK(secp256k1_ec_pubkey_create(ctx, &point[1], s_b32) == 1); 63 | CHECK(secp256k1_ec_pubkey_serialize(ctx, point_ser, &point_ser_len, &point[1], SECP256K1_EC_COMPRESSED) == 1); 64 | CHECK(point_ser_len == sizeof(point_ser)); 65 | secp256k1_sha256_initialize(&sha); 66 | secp256k1_sha256_write(&sha, point_ser, point_ser_len); 67 | secp256k1_sha256_finalize(&sha, output_ser); 68 | /* compare */ 69 | CHECK(memcmp(output_ecdh, output_ser, sizeof(output_ser)) == 0); 70 | } 71 | } 72 | 73 | void test_bad_scalar(void) { 74 | unsigned char s_zero[32] = { 0 }; 75 | unsigned char s_overflow[32] = { 76 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 77 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 78 | 0xba, 0xae, 0xdc, 0xe6, 0xaf, 0x48, 0xa0, 0x3b, 79 | 0xbf, 0xd2, 0x5e, 0x8c, 0xd0, 0x36, 0x41, 0x41 80 | }; 81 | unsigned char s_rand[32] = { 0 }; 82 | unsigned char output[32]; 83 | secp256k1_scalar rand; 84 | secp256k1_pubkey point; 85 | 86 | /* Create random point */ 87 | random_scalar_order(&rand); 88 | secp256k1_scalar_get_b32(s_rand, &rand); 89 | CHECK(secp256k1_ec_pubkey_create(ctx, &point, s_rand) == 1); 90 | 91 | /* Try to multiply it by bad values */ 92 | CHECK(secp256k1_ecdh(ctx, output, &point, s_zero) == 0); 93 | CHECK(secp256k1_ecdh(ctx, output, &point, s_overflow) == 0); 94 | /* ...and a good one */ 95 | s_overflow[31] -= 1; 96 | CHECK(secp256k1_ecdh(ctx, output, &point, s_overflow) == 1); 97 | } 98 | 99 | void run_ecdh_tests(void) { 100 | test_ecdh_api(); 101 | test_ecdh_generator_basepoint(); 102 | test_bad_scalar(); 103 | } 104 | 105 | #endif 106 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/contrib/lax_der_parsing.c: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2015 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #include 8 | #include 9 | 10 | #include "lax_der_parsing.h" 11 | 12 | int ecdsa_signature_parse_der_lax(const secp256k1_context* ctx, secp256k1_ecdsa_signature* sig, const unsigned char *input, size_t inputlen) { 13 | size_t rpos, rlen, spos, slen; 14 | size_t pos = 0; 15 | size_t lenbyte; 16 | unsigned char tmpsig[64] = {0}; 17 | int overflow = 0; 18 | 19 | /* Hack to initialize sig with a correctly-parsed but invalid signature. */ 20 | secp256k1_ecdsa_signature_parse_compact(ctx, sig, tmpsig); 21 | 22 | /* Sequence tag byte */ 23 | if (pos == inputlen || input[pos] != 0x30) { 24 | return 0; 25 | } 26 | pos++; 27 | 28 | /* Sequence length bytes */ 29 | if (pos == inputlen) { 30 | return 0; 31 | } 32 | lenbyte = input[pos++]; 33 | if (lenbyte & 0x80) { 34 | lenbyte -= 0x80; 35 | if (pos + lenbyte > inputlen) { 36 | return 0; 37 | } 38 | pos += lenbyte; 39 | } 40 | 41 | /* Integer tag byte for R */ 42 | if (pos == inputlen || input[pos] != 0x02) { 43 | return 0; 44 | } 45 | pos++; 46 | 47 | /* Integer length for R */ 48 | if (pos == inputlen) { 49 | return 0; 50 | } 51 | lenbyte = input[pos++]; 52 | if (lenbyte & 0x80) { 53 | lenbyte -= 0x80; 54 | if (pos + lenbyte > inputlen) { 55 | return 0; 56 | } 57 | while (lenbyte > 0 && input[pos] == 0) { 58 | pos++; 59 | lenbyte--; 60 | } 61 | if (lenbyte >= sizeof(size_t)) { 62 | return 0; 63 | } 64 | rlen = 0; 65 | while (lenbyte > 0) { 66 | rlen = (rlen << 8) + input[pos]; 67 | pos++; 68 | lenbyte--; 69 | } 70 | } else { 71 | rlen = lenbyte; 72 | } 73 | if (rlen > inputlen - pos) { 74 | return 0; 75 | } 76 | rpos = pos; 77 | pos += rlen; 78 | 79 | /* Integer tag byte for S */ 80 | if (pos == inputlen || input[pos] != 0x02) { 81 | return 0; 82 | } 83 | pos++; 84 | 85 | /* Integer length for S */ 86 | if (pos == inputlen) { 87 | return 0; 88 | } 89 | lenbyte = input[pos++]; 90 | if (lenbyte & 0x80) { 91 | lenbyte -= 0x80; 92 | if (pos + lenbyte > inputlen) { 93 | return 0; 94 | } 95 | while (lenbyte > 0 && input[pos] == 0) { 96 | pos++; 97 | lenbyte--; 98 | } 99 | if (lenbyte >= sizeof(size_t)) { 100 | return 0; 101 | } 102 | slen = 0; 103 | while (lenbyte > 0) { 104 | slen = (slen << 8) + input[pos]; 105 | pos++; 106 | lenbyte--; 107 | } 108 | } else { 109 | slen = lenbyte; 110 | } 111 | if (slen > inputlen - pos) { 112 | return 0; 113 | } 114 | spos = pos; 115 | pos += slen; 116 | 117 | /* Ignore leading zeroes in R */ 118 | while (rlen > 0 && input[rpos] == 0) { 119 | rlen--; 120 | rpos++; 121 | } 122 | /* Copy R value */ 123 | if (rlen > 32) { 124 | overflow = 1; 125 | } else { 126 | memcpy(tmpsig + 32 - rlen, input + rpos, rlen); 127 | } 128 | 129 | /* Ignore leading zeroes in S */ 130 | while (slen > 0 && input[spos] == 0) { 131 | slen--; 132 | spos++; 133 | } 134 | /* Copy S value */ 135 | if (slen > 32) { 136 | overflow = 1; 137 | } else { 138 | memcpy(tmpsig + 64 - slen, input + spos, slen); 139 | } 140 | 141 | if (!overflow) { 142 | overflow = !secp256k1_ecdsa_signature_parse_compact(ctx, sig, tmpsig); 143 | } 144 | if (overflow) { 145 | memset(tmpsig, 0, 64); 146 | secp256k1_ecdsa_signature_parse_compact(ctx, sig, tmpsig); 147 | } 148 | return 1; 149 | } 150 | 151 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/src/bench_verify.c: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #include 8 | #include 9 | 10 | #include "include/secp256k1.h" 11 | #include "util.h" 12 | #include "bench.h" 13 | 14 | #ifdef ENABLE_OPENSSL_TESTS 15 | #include 16 | #include 17 | #include 18 | #endif 19 | 20 | typedef struct { 21 | secp256k1_context *ctx; 22 | unsigned char msg[32]; 23 | unsigned char key[32]; 24 | unsigned char sig[72]; 25 | size_t siglen; 26 | unsigned char pubkey[33]; 27 | size_t pubkeylen; 28 | #ifdef ENABLE_OPENSSL_TESTS 29 | EC_GROUP* ec_group; 30 | #endif 31 | } benchmark_verify_t; 32 | 33 | static void benchmark_verify(void* arg) { 34 | int i; 35 | benchmark_verify_t* data = (benchmark_verify_t*)arg; 36 | 37 | for (i = 0; i < 20000; i++) { 38 | secp256k1_pubkey pubkey; 39 | secp256k1_ecdsa_signature sig; 40 | data->sig[data->siglen - 1] ^= (i & 0xFF); 41 | data->sig[data->siglen - 2] ^= ((i >> 8) & 0xFF); 42 | data->sig[data->siglen - 3] ^= ((i >> 16) & 0xFF); 43 | CHECK(secp256k1_ec_pubkey_parse(data->ctx, &pubkey, data->pubkey, data->pubkeylen) == 1); 44 | CHECK(secp256k1_ecdsa_signature_parse_der(data->ctx, &sig, data->sig, data->siglen) == 1); 45 | CHECK(secp256k1_ecdsa_verify(data->ctx, &sig, data->msg, &pubkey) == (i == 0)); 46 | data->sig[data->siglen - 1] ^= (i & 0xFF); 47 | data->sig[data->siglen - 2] ^= ((i >> 8) & 0xFF); 48 | data->sig[data->siglen - 3] ^= ((i >> 16) & 0xFF); 49 | } 50 | } 51 | 52 | #ifdef ENABLE_OPENSSL_TESTS 53 | static void benchmark_verify_openssl(void* arg) { 54 | int i; 55 | benchmark_verify_t* data = (benchmark_verify_t*)arg; 56 | 57 | for (i = 0; i < 20000; i++) { 58 | data->sig[data->siglen - 1] ^= (i & 0xFF); 59 | data->sig[data->siglen - 2] ^= ((i >> 8) & 0xFF); 60 | data->sig[data->siglen - 3] ^= ((i >> 16) & 0xFF); 61 | { 62 | EC_KEY *pkey = EC_KEY_new(); 63 | const unsigned char *pubkey = &data->pubkey[0]; 64 | int result; 65 | 66 | CHECK(pkey != NULL); 67 | result = EC_KEY_set_group(pkey, data->ec_group); 68 | CHECK(result); 69 | result = (o2i_ECPublicKey(&pkey, &pubkey, data->pubkeylen)) != NULL; 70 | CHECK(result); 71 | result = ECDSA_verify(0, &data->msg[0], sizeof(data->msg), &data->sig[0], data->siglen, pkey) == (i == 0); 72 | CHECK(result); 73 | EC_KEY_free(pkey); 74 | } 75 | data->sig[data->siglen - 1] ^= (i & 0xFF); 76 | data->sig[data->siglen - 2] ^= ((i >> 8) & 0xFF); 77 | data->sig[data->siglen - 3] ^= ((i >> 16) & 0xFF); 78 | } 79 | } 80 | #endif 81 | 82 | int main(void) { 83 | int i; 84 | secp256k1_pubkey pubkey; 85 | secp256k1_ecdsa_signature sig; 86 | benchmark_verify_t data; 87 | 88 | data.ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY); 89 | 90 | for (i = 0; i < 32; i++) { 91 | data.msg[i] = 1 + i; 92 | } 93 | for (i = 0; i < 32; i++) { 94 | data.key[i] = 33 + i; 95 | } 96 | data.siglen = 72; 97 | CHECK(secp256k1_ecdsa_sign(data.ctx, &sig, data.msg, data.key, NULL, NULL)); 98 | CHECK(secp256k1_ecdsa_signature_serialize_der(data.ctx, data.sig, &data.siglen, &sig)); 99 | CHECK(secp256k1_ec_pubkey_create(data.ctx, &pubkey, data.key)); 100 | data.pubkeylen = 33; 101 | CHECK(secp256k1_ec_pubkey_serialize(data.ctx, data.pubkey, &data.pubkeylen, &pubkey, SECP256K1_EC_COMPRESSED) == 1); 102 | 103 | run_benchmark("ecdsa_verify", benchmark_verify, NULL, NULL, &data, 10, 20000); 104 | #ifdef ENABLE_OPENSSL_TESTS 105 | data.ec_group = EC_GROUP_new_by_curve_name(NID_secp256k1); 106 | run_benchmark("ecdsa_verify_openssl", benchmark_verify_openssl, NULL, NULL, &data, 10, 20000); 107 | EC_GROUP_free(data.ec_group); 108 | #endif 109 | 110 | secp256k1_context_destroy(data.ctx); 111 | return 0; 112 | } 113 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/src/testrand_impl.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2013-2015 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_TESTRAND_IMPL_H_ 8 | #define _SECP256K1_TESTRAND_IMPL_H_ 9 | 10 | #include 11 | #include 12 | 13 | #include "testrand.h" 14 | #include "hash.h" 15 | 16 | static secp256k1_rfc6979_hmac_sha256_t secp256k1_test_rng; 17 | static uint32_t secp256k1_test_rng_precomputed[8]; 18 | static int secp256k1_test_rng_precomputed_used = 8; 19 | static uint64_t secp256k1_test_rng_integer; 20 | static int secp256k1_test_rng_integer_bits_left = 0; 21 | 22 | SECP256K1_INLINE static void secp256k1_rand_seed(const unsigned char *seed16) { 23 | secp256k1_rfc6979_hmac_sha256_initialize(&secp256k1_test_rng, seed16, 16); 24 | } 25 | 26 | SECP256K1_INLINE static uint32_t secp256k1_rand32(void) { 27 | if (secp256k1_test_rng_precomputed_used == 8) { 28 | secp256k1_rfc6979_hmac_sha256_generate(&secp256k1_test_rng, (unsigned char*)(&secp256k1_test_rng_precomputed[0]), sizeof(secp256k1_test_rng_precomputed)); 29 | secp256k1_test_rng_precomputed_used = 0; 30 | } 31 | return secp256k1_test_rng_precomputed[secp256k1_test_rng_precomputed_used++]; 32 | } 33 | 34 | static uint32_t secp256k1_rand_bits(int bits) { 35 | uint32_t ret; 36 | if (secp256k1_test_rng_integer_bits_left < bits) { 37 | secp256k1_test_rng_integer |= (((uint64_t)secp256k1_rand32()) << secp256k1_test_rng_integer_bits_left); 38 | secp256k1_test_rng_integer_bits_left += 32; 39 | } 40 | ret = secp256k1_test_rng_integer; 41 | secp256k1_test_rng_integer >>= bits; 42 | secp256k1_test_rng_integer_bits_left -= bits; 43 | ret &= ((~((uint32_t)0)) >> (32 - bits)); 44 | return ret; 45 | } 46 | 47 | static uint32_t secp256k1_rand_int(uint32_t range) { 48 | /* We want a uniform integer between 0 and range-1, inclusive. 49 | * B is the smallest number such that range <= 2**B. 50 | * two mechanisms implemented here: 51 | * - generate B bits numbers until one below range is found, and return it 52 | * - find the largest multiple M of range that is <= 2**(B+A), generate B+A 53 | * bits numbers until one below M is found, and return it modulo range 54 | * The second mechanism consumes A more bits of entropy in every iteration, 55 | * but may need fewer iterations due to M being closer to 2**(B+A) then 56 | * range is to 2**B. The array below (indexed by B) contains a 0 when the 57 | * first mechanism is to be used, and the number A otherwise. 58 | */ 59 | static const int addbits[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 1, 0}; 60 | uint32_t trange, mult; 61 | int bits = 0; 62 | if (range <= 1) { 63 | return 0; 64 | } 65 | trange = range - 1; 66 | while (trange > 0) { 67 | trange >>= 1; 68 | bits++; 69 | } 70 | if (addbits[bits]) { 71 | bits = bits + addbits[bits]; 72 | mult = ((~((uint32_t)0)) >> (32 - bits)) / range; 73 | trange = range * mult; 74 | } else { 75 | trange = range; 76 | mult = 1; 77 | } 78 | while(1) { 79 | uint32_t x = secp256k1_rand_bits(bits); 80 | if (x < trange) { 81 | return (mult == 1) ? x : (x % range); 82 | } 83 | } 84 | } 85 | 86 | static void secp256k1_rand256(unsigned char *b32) { 87 | secp256k1_rfc6979_hmac_sha256_generate(&secp256k1_test_rng, b32, 32); 88 | } 89 | 90 | static void secp256k1_rand_bytes_test(unsigned char *bytes, size_t len) { 91 | size_t bits = 0; 92 | memset(bytes, 0, len); 93 | while (bits < len * 8) { 94 | int now; 95 | uint32_t val; 96 | now = 1 + (secp256k1_rand_bits(6) * secp256k1_rand_bits(5) + 16) / 31; 97 | val = secp256k1_rand_bits(1); 98 | while (now > 0 && bits < len * 8) { 99 | bytes[bits / 8] |= val << (bits % 8); 100 | now--; 101 | bits++; 102 | } 103 | } 104 | } 105 | 106 | static void secp256k1_rand256_test(unsigned char *b32) { 107 | secp256k1_rand_bytes_test(b32, 32); 108 | } 109 | 110 | #endif 111 | -------------------------------------------------------------------------------- /cmake/modules/FindCryptoPP.cmake: -------------------------------------------------------------------------------- 1 | # Module for locating the Crypto++ encryption library. 2 | # 3 | # Customizable variables: 4 | # CRYPTOPP_ROOT_DIR 5 | # This variable points to the CryptoPP root directory. On Windows the 6 | # library location typically will have to be provided explicitly using the 7 | # -D command-line option. The directory should include the include/cryptopp, 8 | # lib and/or bin sub-directories. 9 | # 10 | # Read-only variables: 11 | # CRYPTOPP_FOUND 12 | # Indicates whether the library has been found. 13 | # 14 | # CRYPTOPP_INCLUDE_DIRS 15 | # Points to the CryptoPP include directory. 16 | # 17 | # CRYPTOPP_LIBRARIES 18 | # Points to the CryptoPP libraries that should be passed to 19 | # target_link_libararies. 20 | # 21 | # 22 | # Copyright (c) 2012 Sergiu Dotenco 23 | # 24 | # Permission is hereby granted, free of charge, to any person obtaining a copy 25 | # of this software and associated documentation files (the "Software"), to deal 26 | # in the Software without restriction, including without limitation the rights 27 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 28 | # copies of the Software, and to permit persons to whom the Software is 29 | # furnished to do so, subject to the following conditions: 30 | # 31 | # The above copyright notice and this permission notice shall be included in all 32 | # copies or substantial portions of the Software. 33 | # 34 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 35 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 36 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 37 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 38 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 39 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 40 | # SOFTWARE. 41 | 42 | INCLUDE (FindPackageHandleStandardArgs) 43 | 44 | FIND_PATH (CRYPTOPP_ROOT_DIR 45 | NAMES cryptopp/cryptlib.h include/cryptopp/cryptlib.h 46 | PATHS ENV CRYPTOPPROOT 47 | DOC "CryptoPP root directory") 48 | 49 | # Re-use the previous path: 50 | FIND_PATH (CRYPTOPP_INCLUDE_DIR 51 | NAMES cryptopp/cryptlib.h 52 | HINTS ${CRYPTOPP_ROOT_DIR} 53 | PATH_SUFFIXES include 54 | DOC "CryptoPP include directory") 55 | 56 | FIND_LIBRARY (CRYPTOPP_LIBRARY_DEBUG 57 | NAMES cryptlibd cryptoppd 58 | HINTS ${CRYPTOPP_ROOT_DIR} 59 | PATH_SUFFIXES lib 60 | DOC "CryptoPP debug library") 61 | 62 | FIND_LIBRARY (CRYPTOPP_LIBRARY_RELEASE 63 | NAMES cryptlib cryptopp 64 | HINTS ${CRYPTOPP_ROOT_DIR} 65 | PATH_SUFFIXES lib 66 | DOC "CryptoPP release library") 67 | 68 | IF (CRYPTOPP_LIBRARY_DEBUG AND CRYPTOPP_LIBRARY_RELEASE) 69 | SET (CRYPTOPP_LIBRARY 70 | optimized ${CRYPTOPP_LIBRARY_RELEASE} 71 | debug ${CRYPTOPP_LIBRARY_DEBUG} CACHE DOC "CryptoPP library") 72 | ELSEIF (CRYPTOPP_LIBRARY_RELEASE) 73 | SET (CRYPTOPP_LIBRARY ${CRYPTOPP_LIBRARY_RELEASE} CACHE DOC 74 | "CryptoPP library") 75 | ENDIF (CRYPTOPP_LIBRARY_DEBUG AND CRYPTOPP_LIBRARY_RELEASE) 76 | 77 | IF (CRYPTOPP_INCLUDE_DIR) 78 | SET (_CRYPTOPP_VERSION_HEADER ${CRYPTOPP_INCLUDE_DIR}/cryptopp/config.h) 79 | 80 | IF (EXISTS ${_CRYPTOPP_VERSION_HEADER}) 81 | FILE (STRINGS ${_CRYPTOPP_VERSION_HEADER} _CRYPTOPP_VERSION_TMP REGEX 82 | "^#define CRYPTOPP_VERSION[ \t]+[0-9]+$") 83 | 84 | STRING (REGEX REPLACE 85 | "^#define CRYPTOPP_VERSION[ \t]+([0-9]+)" "\\1" _CRYPTOPP_VERSION_TMP 86 | ${_CRYPTOPP_VERSION_TMP}) 87 | 88 | STRING (REGEX REPLACE "([0-9]+)[0-9][0-9]" "\\1" CRYPTOPP_VERSION_MAJOR 89 | ${_CRYPTOPP_VERSION_TMP}) 90 | STRING (REGEX REPLACE "[0-9]([0-9])[0-9]" "\\1" CRYPTOPP_VERSION_MINOR 91 | ${_CRYPTOPP_VERSION_TMP}) 92 | STRING (REGEX REPLACE "[0-9][0-9]([0-9])" "\\1" CRYPTOPP_VERSION_PATCH 93 | ${_CRYPTOPP_VERSION_TMP}) 94 | 95 | SET (CRYPTOPP_VERSION_COUNT 3) 96 | SET (CRYPTOPP_VERSION 97 | ${CRYPTOPP_VERSION_MAJOR}.${CRYPTOPP_VERSION_MINOR}.${CRYPTOPP_VERSION_PATCH}) 98 | ENDIF (EXISTS ${_CRYPTOPP_VERSION_HEADER}) 99 | ENDIF (CRYPTOPP_INCLUDE_DIR) 100 | 101 | SET (CRYPTOPP_INCLUDE_DIRS ${CRYPTOPP_INCLUDE_DIR}) 102 | SET (CRYPTOPP_LIBRARIES ${CRYPTOPP_LIBRARY}) 103 | 104 | MARK_AS_ADVANCED (CRYPTOPP_INCLUDE_DIR CRYPTOPP_LIBRARY CRYPTOPP_LIBRARY_DEBUG 105 | CRYPTOPP_LIBRARY_RELEASE) 106 | 107 | FIND_PACKAGE_HANDLE_STANDARD_ARGS (CryptoPP REQUIRED_VARS CRYPTOPP_ROOT_DIR 108 | CRYPTOPP_INCLUDE_DIR CRYPTOPP_LIBRARY VERSION_VAR CRYPTOPP_VERSION) -------------------------------------------------------------------------------- /src/libethash/sha3.c: -------------------------------------------------------------------------------- 1 | /** libkeccak-tiny 2 | * 3 | * A single-file implementation of SHA-3 and SHAKE. 4 | * 5 | * Implementor: David Leon Gil 6 | * License: CC0, attribution kindly requested. Blame taken too, 7 | * but not liability. 8 | */ 9 | #include "sha3.h" 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | /******** The Keccak-f[1600] permutation ********/ 17 | 18 | /*** Constants. ***/ 19 | static const uint8_t rho[24] = \ 20 | { 1, 3, 6, 10, 15, 21, 21 | 28, 36, 45, 55, 2, 14, 22 | 27, 41, 56, 8, 25, 43, 23 | 62, 18, 39, 61, 20, 44}; 24 | static const uint8_t pi[24] = \ 25 | {10, 7, 11, 17, 18, 3, 26 | 5, 16, 8, 21, 24, 4, 27 | 15, 23, 19, 13, 12, 2, 28 | 20, 14, 22, 9, 6, 1}; 29 | static const uint64_t RC[24] = \ 30 | {1ULL, 0x8082ULL, 0x800000000000808aULL, 0x8000000080008000ULL, 31 | 0x808bULL, 0x80000001ULL, 0x8000000080008081ULL, 0x8000000000008009ULL, 32 | 0x8aULL, 0x88ULL, 0x80008009ULL, 0x8000000aULL, 33 | 0x8000808bULL, 0x800000000000008bULL, 0x8000000000008089ULL, 0x8000000000008003ULL, 34 | 0x8000000000008002ULL, 0x8000000000000080ULL, 0x800aULL, 0x800000008000000aULL, 35 | 0x8000000080008081ULL, 0x8000000000008080ULL, 0x80000001ULL, 0x8000000080008008ULL}; 36 | 37 | /*** Helper macros to unroll the permutation. ***/ 38 | #define rol(x, s) (((x) << s) | ((x) >> (64 - s))) 39 | #define REPEAT6(e) e e e e e e 40 | #define REPEAT24(e) REPEAT6(e e e e) 41 | #define REPEAT5(e) e e e e e 42 | #define FOR5(v, s, e) \ 43 | v = 0; \ 44 | REPEAT5(e; v += s;) 45 | 46 | /*** Keccak-f[1600] ***/ 47 | static inline void keccakf(void* state) { 48 | uint64_t* a = (uint64_t*)state; 49 | uint64_t b[5] = {0}; 50 | uint64_t t = 0; 51 | uint8_t x, y; 52 | 53 | for (int i = 0; i < 24; i++) { 54 | // Theta 55 | FOR5(x, 1, 56 | b[x] = 0; 57 | FOR5(y, 5, 58 | b[x] ^= a[x + y]; )) 59 | FOR5(x, 1, 60 | FOR5(y, 5, 61 | a[y + x] ^= b[(x + 4) % 5] ^ rol(b[(x + 1) % 5], 1); )) 62 | // Rho and pi 63 | t = a[1]; 64 | x = 0; 65 | REPEAT24(b[0] = a[pi[x]]; 66 | a[pi[x]] = rol(t, rho[x]); 67 | t = b[0]; 68 | x++; ) 69 | // Chi 70 | FOR5(y, 71 | 5, 72 | FOR5(x, 1, 73 | b[x] = a[y + x];) 74 | FOR5(x, 1, 75 | a[y + x] = b[x] ^ ((~b[(x + 1) % 5]) & b[(x + 2) % 5]); )) 76 | // Iota 77 | a[0] ^= RC[i]; 78 | } 79 | } 80 | 81 | /******** The FIPS202-defined functions. ********/ 82 | 83 | /*** Some helper macros. ***/ 84 | 85 | #define _(S) do { S } while (0) 86 | #define FOR(i, ST, L, S) \ 87 | _(for (size_t i = 0; i < L; i += ST) { S; }) 88 | #define mkapply_ds(NAME, S) \ 89 | static inline void NAME(uint8_t* dst, \ 90 | const uint8_t* src, \ 91 | size_t len) { \ 92 | FOR(i, 1, len, S); \ 93 | } 94 | #define mkapply_sd(NAME, S) \ 95 | static inline void NAME(const uint8_t* src, \ 96 | uint8_t* dst, \ 97 | size_t len) { \ 98 | FOR(i, 1, len, S); \ 99 | } 100 | 101 | mkapply_ds(xorin, dst[i] ^= src[i]) // xorin 102 | mkapply_sd(setout, dst[i] = src[i]) // setout 103 | 104 | #define P keccakf 105 | #define Plen 200 106 | 107 | // Fold P*F over the full blocks of an input. 108 | #define foldP(I, L, F) \ 109 | while (L >= rate) { \ 110 | F(a, I, rate); \ 111 | P(a); \ 112 | I += rate; \ 113 | L -= rate; \ 114 | } 115 | 116 | /** The sponge-based hash construction. **/ 117 | static inline int hash(uint8_t* out, size_t outlen, 118 | const uint8_t* in, size_t inlen, 119 | size_t rate, uint8_t delim) { 120 | if ((out == NULL) || ((in == NULL) && inlen != 0) || (rate >= Plen)) { 121 | return -1; 122 | } 123 | uint8_t a[Plen] = {0}; 124 | // Absorb input. 125 | foldP(in, inlen, xorin); 126 | // Xor in the DS and pad frame. 127 | a[inlen] ^= delim; 128 | a[rate - 1] ^= 0x80; 129 | // Xor in the last block. 130 | xorin(a, in, inlen); 131 | // Apply P 132 | P(a); 133 | // Squeeze output. 134 | foldP(out, outlen, setout); 135 | setout(a, out, outlen); 136 | memset(a, 0, 200); 137 | return 0; 138 | } 139 | 140 | #define defsha3(bits) \ 141 | int sha3_##bits(uint8_t* out, size_t outlen, \ 142 | const uint8_t* in, size_t inlen) { \ 143 | if (outlen > (bits/8)) { \ 144 | return -1; \ 145 | } \ 146 | return hash(out, outlen, in, inlen, 200 - (bits / 4), 0x01); \ 147 | } 148 | 149 | /*** FIPS202 SHA3 FOFs ***/ 150 | defsha3(256) 151 | defsha3(512) 152 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/build-aux/m4/ax_prog_cc_for_build.m4: -------------------------------------------------------------------------------- 1 | # =========================================================================== 2 | # http://www.gnu.org/software/autoconf-archive/ax_prog_cc_for_build.html 3 | # =========================================================================== 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_PROG_CC_FOR_BUILD 8 | # 9 | # DESCRIPTION 10 | # 11 | # This macro searches for a C compiler that generates native executables, 12 | # that is a C compiler that surely is not a cross-compiler. This can be 13 | # useful if you have to generate source code at compile-time like for 14 | # example GCC does. 15 | # 16 | # The macro sets the CC_FOR_BUILD and CPP_FOR_BUILD macros to anything 17 | # needed to compile or link (CC_FOR_BUILD) and preprocess (CPP_FOR_BUILD). 18 | # The value of these variables can be overridden by the user by specifying 19 | # a compiler with an environment variable (like you do for standard CC). 20 | # 21 | # It also sets BUILD_EXEEXT and BUILD_OBJEXT to the executable and object 22 | # file extensions for the build platform, and GCC_FOR_BUILD to `yes' if 23 | # the compiler we found is GCC. All these variables but GCC_FOR_BUILD are 24 | # substituted in the Makefile. 25 | # 26 | # LICENSE 27 | # 28 | # Copyright (c) 2008 Paolo Bonzini 29 | # 30 | # Copying and distribution of this file, with or without modification, are 31 | # permitted in any medium without royalty provided the copyright notice 32 | # and this notice are preserved. This file is offered as-is, without any 33 | # warranty. 34 | 35 | #serial 8 36 | 37 | AU_ALIAS([AC_PROG_CC_FOR_BUILD], [AX_PROG_CC_FOR_BUILD]) 38 | AC_DEFUN([AX_PROG_CC_FOR_BUILD], [dnl 39 | AC_REQUIRE([AC_PROG_CC])dnl 40 | AC_REQUIRE([AC_PROG_CPP])dnl 41 | AC_REQUIRE([AC_EXEEXT])dnl 42 | AC_REQUIRE([AC_CANONICAL_HOST])dnl 43 | 44 | dnl Use the standard macros, but make them use other variable names 45 | dnl 46 | pushdef([ac_cv_prog_CPP], ac_cv_build_prog_CPP)dnl 47 | pushdef([ac_cv_prog_gcc], ac_cv_build_prog_gcc)dnl 48 | pushdef([ac_cv_prog_cc_works], ac_cv_build_prog_cc_works)dnl 49 | pushdef([ac_cv_prog_cc_cross], ac_cv_build_prog_cc_cross)dnl 50 | pushdef([ac_cv_prog_cc_g], ac_cv_build_prog_cc_g)dnl 51 | pushdef([ac_cv_exeext], ac_cv_build_exeext)dnl 52 | pushdef([ac_cv_objext], ac_cv_build_objext)dnl 53 | pushdef([ac_exeext], ac_build_exeext)dnl 54 | pushdef([ac_objext], ac_build_objext)dnl 55 | pushdef([CC], CC_FOR_BUILD)dnl 56 | pushdef([CPP], CPP_FOR_BUILD)dnl 57 | pushdef([CFLAGS], CFLAGS_FOR_BUILD)dnl 58 | pushdef([CPPFLAGS], CPPFLAGS_FOR_BUILD)dnl 59 | pushdef([LDFLAGS], LDFLAGS_FOR_BUILD)dnl 60 | pushdef([host], build)dnl 61 | pushdef([host_alias], build_alias)dnl 62 | pushdef([host_cpu], build_cpu)dnl 63 | pushdef([host_vendor], build_vendor)dnl 64 | pushdef([host_os], build_os)dnl 65 | pushdef([ac_cv_host], ac_cv_build)dnl 66 | pushdef([ac_cv_host_alias], ac_cv_build_alias)dnl 67 | pushdef([ac_cv_host_cpu], ac_cv_build_cpu)dnl 68 | pushdef([ac_cv_host_vendor], ac_cv_build_vendor)dnl 69 | pushdef([ac_cv_host_os], ac_cv_build_os)dnl 70 | pushdef([ac_cpp], ac_build_cpp)dnl 71 | pushdef([ac_compile], ac_build_compile)dnl 72 | pushdef([ac_link], ac_build_link)dnl 73 | 74 | save_cross_compiling=$cross_compiling 75 | save_ac_tool_prefix=$ac_tool_prefix 76 | cross_compiling=no 77 | ac_tool_prefix= 78 | 79 | AC_PROG_CC 80 | AC_PROG_CPP 81 | AC_EXEEXT 82 | 83 | ac_tool_prefix=$save_ac_tool_prefix 84 | cross_compiling=$save_cross_compiling 85 | 86 | dnl Restore the old definitions 87 | dnl 88 | popdef([ac_link])dnl 89 | popdef([ac_compile])dnl 90 | popdef([ac_cpp])dnl 91 | popdef([ac_cv_host_os])dnl 92 | popdef([ac_cv_host_vendor])dnl 93 | popdef([ac_cv_host_cpu])dnl 94 | popdef([ac_cv_host_alias])dnl 95 | popdef([ac_cv_host])dnl 96 | popdef([host_os])dnl 97 | popdef([host_vendor])dnl 98 | popdef([host_cpu])dnl 99 | popdef([host_alias])dnl 100 | popdef([host])dnl 101 | popdef([LDFLAGS])dnl 102 | popdef([CPPFLAGS])dnl 103 | popdef([CFLAGS])dnl 104 | popdef([CPP])dnl 105 | popdef([CC])dnl 106 | popdef([ac_objext])dnl 107 | popdef([ac_exeext])dnl 108 | popdef([ac_cv_objext])dnl 109 | popdef([ac_cv_exeext])dnl 110 | popdef([ac_cv_prog_cc_g])dnl 111 | popdef([ac_cv_prog_cc_cross])dnl 112 | popdef([ac_cv_prog_cc_works])dnl 113 | popdef([ac_cv_prog_gcc])dnl 114 | popdef([ac_cv_prog_CPP])dnl 115 | 116 | dnl Finally, set Makefile variables 117 | dnl 118 | BUILD_EXEEXT=$ac_build_exeext 119 | BUILD_OBJEXT=$ac_build_objext 120 | AC_SUBST(BUILD_EXEEXT)dnl 121 | AC_SUBST(BUILD_OBJEXT)dnl 122 | AC_SUBST([CFLAGS_FOR_BUILD])dnl 123 | AC_SUBST([CPPFLAGS_FOR_BUILD])dnl 124 | AC_SUBST([LDFLAGS_FOR_BUILD])dnl 125 | ]) 126 | -------------------------------------------------------------------------------- /vendor/github.com/ethereum/go-ethereum/rlp/typecache.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 rlp 18 | 19 | import ( 20 | "fmt" 21 | "reflect" 22 | "strings" 23 | "sync" 24 | ) 25 | 26 | var ( 27 | typeCacheMutex sync.RWMutex 28 | typeCache = make(map[typekey]*typeinfo) 29 | ) 30 | 31 | type typeinfo struct { 32 | decoder 33 | writer 34 | } 35 | 36 | // represents struct tags 37 | type tags struct { 38 | // rlp:"nil" controls whether empty input results in a nil pointer. 39 | nilOK bool 40 | // rlp:"tail" controls whether this field swallows additional list 41 | // elements. It can only be set for the last field, which must be 42 | // of slice type. 43 | tail bool 44 | // rlp:"-" ignores fields. 45 | ignored bool 46 | } 47 | 48 | type typekey struct { 49 | reflect.Type 50 | // the key must include the struct tags because they 51 | // might generate a different decoder. 52 | tags 53 | } 54 | 55 | type decoder func(*Stream, reflect.Value) error 56 | 57 | type writer func(reflect.Value, *encbuf) error 58 | 59 | func cachedTypeInfo(typ reflect.Type, tags tags) (*typeinfo, error) { 60 | typeCacheMutex.RLock() 61 | info := typeCache[typekey{typ, tags}] 62 | typeCacheMutex.RUnlock() 63 | if info != nil { 64 | return info, nil 65 | } 66 | // not in the cache, need to generate info for this type. 67 | typeCacheMutex.Lock() 68 | defer typeCacheMutex.Unlock() 69 | return cachedTypeInfo1(typ, tags) 70 | } 71 | 72 | func cachedTypeInfo1(typ reflect.Type, tags tags) (*typeinfo, error) { 73 | key := typekey{typ, tags} 74 | info := typeCache[key] 75 | if info != nil { 76 | // another goroutine got the write lock first 77 | return info, nil 78 | } 79 | // put a dummmy value into the cache before generating. 80 | // if the generator tries to lookup itself, it will get 81 | // the dummy value and won't call itself recursively. 82 | typeCache[key] = new(typeinfo) 83 | info, err := genTypeInfo(typ, tags) 84 | if err != nil { 85 | // remove the dummy value if the generator fails 86 | delete(typeCache, key) 87 | return nil, err 88 | } 89 | *typeCache[key] = *info 90 | return typeCache[key], err 91 | } 92 | 93 | type field struct { 94 | index int 95 | info *typeinfo 96 | } 97 | 98 | func structFields(typ reflect.Type) (fields []field, err error) { 99 | for i := 0; i < typ.NumField(); i++ { 100 | if f := typ.Field(i); f.PkgPath == "" { // exported 101 | tags, err := parseStructTag(typ, i) 102 | if err != nil { 103 | return nil, err 104 | } 105 | if tags.ignored { 106 | continue 107 | } 108 | info, err := cachedTypeInfo1(f.Type, tags) 109 | if err != nil { 110 | return nil, err 111 | } 112 | fields = append(fields, field{i, info}) 113 | } 114 | } 115 | return fields, nil 116 | } 117 | 118 | func parseStructTag(typ reflect.Type, fi int) (tags, error) { 119 | f := typ.Field(fi) 120 | var ts tags 121 | for _, t := range strings.Split(f.Tag.Get("rlp"), ",") { 122 | switch t = strings.TrimSpace(t); t { 123 | case "": 124 | case "-": 125 | ts.ignored = true 126 | case "nil": 127 | ts.nilOK = true 128 | case "tail": 129 | ts.tail = true 130 | if fi != typ.NumField()-1 { 131 | return ts, fmt.Errorf(`rlp: invalid struct tag "tail" for %v.%s (must be on last field)`, typ, f.Name) 132 | } 133 | if f.Type.Kind() != reflect.Slice { 134 | return ts, fmt.Errorf(`rlp: invalid struct tag "tail" for %v.%s (field type is not slice)`, typ, f.Name) 135 | } 136 | default: 137 | return ts, fmt.Errorf("rlp: unknown struct tag %q on %v.%s", t, typ, f.Name) 138 | } 139 | } 140 | return ts, nil 141 | } 142 | 143 | func genTypeInfo(typ reflect.Type, tags tags) (info *typeinfo, err error) { 144 | info = new(typeinfo) 145 | if info.decoder, err = makeDecoder(typ, tags); err != nil { 146 | return nil, err 147 | } 148 | if info.writer, err = makeWriter(typ, tags); err != nil { 149 | return nil, err 150 | } 151 | return info, nil 152 | } 153 | 154 | func isUint(k reflect.Kind) bool { 155 | return k >= reflect.Uint && k <= reflect.Uintptr 156 | } 157 | --------------------------------------------------------------------------------