Drop fastsha256 in favor of crypto/sha256 (#468)

This commit is contained in:
David Hill 2017-01-12 09:47:46 -05:00 committed by Josh Rickmar
parent 3e598f0f7b
commit 15635025c4
13 changed files with 90 additions and 80 deletions

View file

@ -1,7 +1,7 @@
language: go language: go
go: go:
- 1.6.3 - 1.6.x
- 1.7.3 - 1.7.x
sudo: false sudo: false
before_install: before_install:
- GLIDE_TAG=v0.12.3 - GLIDE_TAG=v0.12.3

View file

@ -1,4 +1,4 @@
// Copyright (c) 2013-2016 The btcsuite developers // Copyright (c) 2013-2017 The btcsuite developers
// Use of this source code is governed by an ISC // Use of this source code is governed by an ISC
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
@ -500,9 +500,9 @@ func loadConfig() (*config, []string, error) {
} }
localhostListeners := map[string]struct{}{ localhostListeners := map[string]struct{}{
"localhost": struct{}{}, "localhost": {},
"127.0.0.1": struct{}{}, "127.0.0.1": {},
"::1": struct{}{}, "::1": {},
} }
RPCHost, _, err := net.SplitHostPort(cfg.RPCConnect) RPCHost, _, err := net.SplitHostPort(cfg.RPCConnect)
if err != nil { if err != nil {

29
glide.lock generated
View file

@ -1,10 +1,10 @@
hash: 5efa5cef5495a0b5256f45ecb2456ea21101934ed56e780a46b1c16e30177ebc hash: d945622a1e24954b5ffe2855e922e687132ccc13fb1a1bc5d57c15c72603948a
updated: 2016-10-27T11:54:19.492811-05:00 updated: 2017-01-11T20:24:15.024651319-05:00
imports: imports:
- name: github.com/boltdb/bolt - name: github.com/boltdb/bolt
version: 583e8937c61f1af6513608ccc75c97b6abdf4ff9 version: 583e8937c61f1af6513608ccc75c97b6abdf4ff9
- name: github.com/btcsuite/btcd - name: github.com/btcsuite/btcd
version: f6ad7eb2c963151c71de2bd37d04d9af644a891d version: 7c0fd83c87b2d2be405489cff522e0110328cd1e
subpackages: subpackages:
- blockchain - blockchain
- btcec - btcec
@ -17,16 +17,14 @@ imports:
- name: github.com/btcsuite/btclog - name: github.com/btcsuite/btclog
version: 73889fb79bd687870312b6e40effcecffbd57d30 version: 73889fb79bd687870312b6e40effcecffbd57d30
- name: github.com/btcsuite/btcrpcclient - name: github.com/btcsuite/btcrpcclient
version: 2b780d16b042054d07aa322146194118fd7f7b81 version: 5ce0ed600997eafaed25ad4936c1d84ec6ad2b5a
- name: github.com/btcsuite/btcutil - name: github.com/btcsuite/btcutil
version: 9b9ce80a2edafc6198569550fcc01df11d214425 version: 86346b5a958c0cf94186b87855469ae991be501c
subpackages: subpackages:
- base58 - base58
- hdkeychain - hdkeychain
- name: github.com/btcsuite/fastsha256
version: 637e656429416087660c84436a2a035d69d54e2e
- name: github.com/btcsuite/go-socks - name: github.com/btcsuite/go-socks
version: cfe8b59e565c1a5bd4e2005d77cd9aa8b2e14524 version: 4720035b7bfd2a9bb130b1c184f8bbe41b6f0d0f
subpackages: subpackages:
- socks - socks
- name: github.com/btcsuite/golangcrypto - name: github.com/btcsuite/golangcrypto
@ -44,13 +42,13 @@ imports:
- name: github.com/btcsuite/websocket - name: github.com/btcsuite/websocket
version: 31079b6807923eb23992c421b114992b95131b55 version: 31079b6807923eb23992c421b114992b95131b55
- name: github.com/golang/protobuf - name: github.com/golang/protobuf
version: 98fa357170587e470c5f27d3c3ea0947b71eb455 version: 8ee79997227bf9b34611aee7946ae64735e6fd93
subpackages: subpackages:
- proto - proto
- name: github.com/jessevdk/go-flags - name: github.com/jessevdk/go-flags
version: 1679536dcc895411a9f5848d9a0250be7856448c version: 1679536dcc895411a9f5848d9a0250be7856448c
- name: golang.org/x/net - name: golang.org/x/net
version: c46f265c325130a7a6c7b27db8c6fe14b64f1a68 version: 60c41d1de8da134c05b7b40154a9a82bf5b7edb9
subpackages: subpackages:
- context - context
- http2 - http2
@ -60,9 +58,16 @@ imports:
- lex/httplex - lex/httplex
- trace - trace
- name: golang.org/x/sys - name: golang.org/x/sys
version: c200b10b5d5e122be351b67af224adc6128af5bf version: d75a52659825e75fff6158388dddc6a5b04f9ba5
subpackages: subpackages:
- unix - unix
- name: golang.org/x/text
version: 44f4f658a783b0cee41fe0a23b8fc91d9c120558
subpackages:
- secure/bidirule
- transform
- unicode/bidi
- unicode/norm
- name: google.golang.org/grpc - name: google.golang.org/grpc
version: b7f1379d3cbbbeb2ca3405852012e237aa05459e version: b7f1379d3cbbbeb2ca3405852012e237aa05459e
subpackages: subpackages:
@ -76,6 +81,6 @@ imports:
- transport - transport
testImports: testImports:
- name: github.com/davecgh/go-spew - name: github.com/davecgh/go-spew
version: 6d212800a42e8ab5c146b8ace3490ee17e5225f9 version: 346938d642f2ec3594ed81d874461961cd0faa76
subpackages: subpackages:
- spew - spew

View file

@ -1,11 +1,14 @@
package: github.com/btcsuite/btcwallet package: github.com/btcsuite/btcwallet
import: import:
- package: github.com/boltdb/bolt
version: ^1.3.0
- package: github.com/btcsuite/btcd - package: github.com/btcsuite/btcd
subpackages: subpackages:
- blockchain - blockchain
- btcec - btcec
- btcjson - btcjson
- chaincfg - chaincfg
- chaincfg/chainhash
- txscript - txscript
- wire - wire
- package: github.com/btcsuite/btclog - package: github.com/btcsuite/btclog
@ -13,7 +16,6 @@ import:
- package: github.com/btcsuite/btcutil - package: github.com/btcsuite/btcutil
subpackages: subpackages:
- hdkeychain - hdkeychain
- package: github.com/btcsuite/fastsha256
- package: github.com/btcsuite/golangcrypto - package: github.com/btcsuite/golangcrypto
subpackages: subpackages:
- nacl/secretbox - nacl/secretbox
@ -25,16 +27,19 @@ import:
- package: github.com/golang/protobuf - package: github.com/golang/protobuf
subpackages: subpackages:
- proto - proto
- package: github.com/jessevdk/go-flags
version: 1679536dcc895411a9f5848d9a0250be7856448c
- package: golang.org/x/net - package: golang.org/x/net
subpackages: subpackages:
- context - context
- package: google.golang.org/grpc - package: google.golang.org/grpc
version: ^1.0.0 version: 1.0.3
subpackages: subpackages:
- codes - codes
- credentials - credentials
- grpclog - grpclog
- package: github.com/jessevdk/go-flags testImport:
version: 1679536dcc895411a9f5848d9a0250be7856448c - package: github.com/davecgh/go-spew
- package: github.com/boltdb/bolt version: ^1.1.0
version: ^1.3.0 subpackages:
- spew

View file

@ -1,10 +1,11 @@
// Copyright (c) 2013-2015 The btcsuite developers // Copyright (c) 2013-2017 The btcsuite developers
// Use of this source code is governed by an ISC // Use of this source code is governed by an ISC
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package legacyrpc package legacyrpc
import ( import (
"crypto/sha256"
"crypto/subtle" "crypto/subtle"
"encoding/base64" "encoding/base64"
"encoding/json" "encoding/json"
@ -21,7 +22,6 @@ import (
"github.com/btcsuite/btcd/btcjson" "github.com/btcsuite/btcd/btcjson"
"github.com/btcsuite/btcwallet/chain" "github.com/btcsuite/btcwallet/chain"
"github.com/btcsuite/btcwallet/wallet" "github.com/btcsuite/btcwallet/wallet"
"github.com/btcsuite/fastsha256"
"github.com/btcsuite/websocket" "github.com/btcsuite/websocket"
) )
@ -66,7 +66,7 @@ type Server struct {
handlerMu sync.Mutex handlerMu sync.Mutex
listeners []net.Listener listeners []net.Listener
authsha [fastsha256.Size]byte authsha [sha256.Size]byte
upgrader websocket.Upgrader upgrader websocket.Upgrader
maxPostClients int64 // Max concurrent HTTP POST clients. maxPostClients int64 // Max concurrent HTTP POST clients.
@ -105,7 +105,7 @@ func NewServer(opts *Options, walletLoader *wallet.Loader, listeners []net.Liste
listeners: listeners, listeners: listeners,
// A hash of the HTTP basic auth string is used for a constant // A hash of the HTTP basic auth string is used for a constant
// time comparison. // time comparison.
authsha: fastsha256.Sum256(httpBasicAuth(opts.Username, opts.Password)), authsha: sha256.Sum256(httpBasicAuth(opts.Username, opts.Password)),
upgrader: websocket.Upgrader{ upgrader: websocket.Upgrader{
// Allow all origins. // Allow all origins.
CheckOrigin: func(r *http.Request) bool { return true }, CheckOrigin: func(r *http.Request) bool { return true },
@ -301,7 +301,7 @@ func (s *Server) checkAuthHeader(r *http.Request) error {
return ErrNoAuth return ErrNoAuth
} }
authsha := fastsha256.Sum256([]byte(authhdr[0])) authsha := sha256.Sum256([]byte(authhdr[0]))
cmp := subtle.ConstantTimeCompare(authsha[:], s.authsha[:]) cmp := subtle.ConstantTimeCompare(authsha[:], s.authsha[:])
if cmp != 1 { if cmp != 1 {
return errors.New("bad auth") return errors.New("bad auth")
@ -378,7 +378,7 @@ func (s *Server) invalidAuth(req *btcjson.Request) bool {
// Check credentials. // Check credentials.
login := authCmd.Username + ":" + authCmd.Passphrase login := authCmd.Username + ":" + authCmd.Passphrase
auth := "Basic " + base64.StdEncoding.EncodeToString([]byte(login)) auth := "Basic " + base64.StdEncoding.EncodeToString([]byte(login))
authSha := fastsha256.Sum256([]byte(auth)) authSha := sha256.Sum256([]byte(auth))
return subtle.ConstantTimeCompare(authSha[:], s.authsha[:]) != 1 return subtle.ConstantTimeCompare(authSha[:], s.authsha[:]) != 1
} }

View file

@ -1,4 +1,4 @@
// Copyright (c) 2014-2015 The btcsuite developers // Copyright (c) 2014-2017 The btcsuite developers
// Use of this source code is governed by an ISC // Use of this source code is governed by an ISC
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
@ -6,6 +6,7 @@ package snacl
import ( import (
"crypto/rand" "crypto/rand"
"crypto/sha256"
"crypto/subtle" "crypto/subtle"
"encoding/binary" "encoding/binary"
"errors" "errors"
@ -13,7 +14,6 @@ import (
"runtime/debug" "runtime/debug"
"github.com/btcsuite/btcwallet/internal/zero" "github.com/btcsuite/btcwallet/internal/zero"
"github.com/btcsuite/fastsha256"
"github.com/btcsuite/golangcrypto/nacl/secretbox" "github.com/btcsuite/golangcrypto/nacl/secretbox"
"github.com/btcsuite/golangcrypto/scrypt" "github.com/btcsuite/golangcrypto/scrypt"
) )
@ -96,7 +96,7 @@ func GenerateCryptoKey() (*CryptoKey, error) {
// Parameters are not secret and can be stored in plain text. // Parameters are not secret and can be stored in plain text.
type Parameters struct { type Parameters struct {
Salt [KeySize]byte Salt [KeySize]byte
Digest [fastsha256.Size]byte Digest [sha256.Size]byte
N int N int
R int R int
P int P int
@ -141,14 +141,14 @@ func (sk *SecretKey) Marshal() []byte {
// The marshalled format for the the params is as follows: // The marshalled format for the the params is as follows:
// <salt><digest><N><R><P> // <salt><digest><N><R><P>
// //
// KeySize + fastsha256.Size + N (8 bytes) + R (8 bytes) + P (8 bytes) // KeySize + sha256.Size + N (8 bytes) + R (8 bytes) + P (8 bytes)
marshalled := make([]byte, KeySize+fastsha256.Size+24) marshalled := make([]byte, KeySize+sha256.Size+24)
b := marshalled b := marshalled
copy(b[:KeySize], params.Salt[:]) copy(b[:KeySize], params.Salt[:])
b = b[KeySize:] b = b[KeySize:]
copy(b[:fastsha256.Size], params.Digest[:]) copy(b[:sha256.Size], params.Digest[:])
b = b[fastsha256.Size:] b = b[sha256.Size:]
binary.LittleEndian.PutUint64(b[:8], uint64(params.N)) binary.LittleEndian.PutUint64(b[:8], uint64(params.N))
b = b[8:] b = b[8:]
binary.LittleEndian.PutUint64(b[:8], uint64(params.R)) binary.LittleEndian.PutUint64(b[:8], uint64(params.R))
@ -168,16 +168,16 @@ func (sk *SecretKey) Unmarshal(marshalled []byte) error {
// The marshalled format for the the params is as follows: // The marshalled format for the the params is as follows:
// <salt><digest><N><R><P> // <salt><digest><N><R><P>
// //
// KeySize + fastsha256.Size + N (8 bytes) + R (8 bytes) + P (8 bytes) // KeySize + sha256.Size + N (8 bytes) + R (8 bytes) + P (8 bytes)
if len(marshalled) != KeySize+fastsha256.Size+24 { if len(marshalled) != KeySize+sha256.Size+24 {
return ErrMalformed return ErrMalformed
} }
params := &sk.Parameters params := &sk.Parameters
copy(params.Salt[:], marshalled[:KeySize]) copy(params.Salt[:], marshalled[:KeySize])
marshalled = marshalled[KeySize:] marshalled = marshalled[KeySize:]
copy(params.Digest[:], marshalled[:fastsha256.Size]) copy(params.Digest[:], marshalled[:sha256.Size])
marshalled = marshalled[fastsha256.Size:] marshalled = marshalled[sha256.Size:]
params.N = int(binary.LittleEndian.Uint64(marshalled[:8])) params.N = int(binary.LittleEndian.Uint64(marshalled[:8]))
marshalled = marshalled[8:] marshalled = marshalled[8:]
params.R = int(binary.LittleEndian.Uint64(marshalled[:8])) params.R = int(binary.LittleEndian.Uint64(marshalled[:8]))
@ -203,7 +203,7 @@ func (sk *SecretKey) DeriveKey(password *[]byte) error {
} }
// verify password // verify password
digest := fastsha256.Sum256(sk.Key[:]) digest := sha256.Sum256(sk.Key[:])
if subtle.ConstantTimeCompare(digest[:], sk.Parameters.Digest[:]) != 1 { if subtle.ConstantTimeCompare(digest[:], sk.Parameters.Digest[:]) != 1 {
return ErrInvalidPassword return ErrInvalidPassword
} }
@ -242,7 +242,7 @@ func NewSecretKey(password *[]byte, N, r, p int) (*SecretKey, error) {
} }
// store digest // store digest
sk.Parameters.Digest = fastsha256.Sum256(sk.Key[:]) sk.Parameters.Digest = sha256.Sum256(sk.Key[:])
return &sk, nil return &sk, nil
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2014 The btcsuite developers * Copyright (c) 2014-2017 The btcsuite developers
* *
* Permission to use, copy, modify, and distribute this software for any * Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * purpose with or without fee is hereby granted, provided that the above
@ -203,7 +203,7 @@ func Example_startWithdrawal() {
addr, _ := btcutil.DecodeAddress("1MirQ9bwyQcGVJPwKUgapu5ouK2E2Ey4gX", mgr.ChainParams()) addr, _ := btcutil.DecodeAddress("1MirQ9bwyQcGVJPwKUgapu5ouK2E2Ey4gX", mgr.ChainParams())
pkScript, _ := txscript.PayToAddrScript(addr) pkScript, _ := txscript.PayToAddrScript(addr)
requests := []votingpool.OutputRequest{ requests := []votingpool.OutputRequest{
votingpool.OutputRequest{ {
PkScript: pkScript, PkScript: pkScript,
Address: addr, Address: addr,
Amount: 1e6, Amount: 1e6,

View file

@ -1,4 +1,4 @@
// Copyright (c) 2015-2016 The btcsuite developers // Copyright (c) 2015-2017 The btcsuite developers
// Use of this source code is governed by an ISC // Use of this source code is governed by an ISC
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
@ -264,9 +264,9 @@ func TestCreditSortingByAddress(t *testing.T) {
c6 := newDummyCredit(t, pool, 2, 0, 0, shaHash0, 0) c6 := newDummyCredit(t, pool, 2, 0, 0, shaHash0, 0)
randomCredits := [][]credit{ randomCredits := [][]credit{
[]credit{c6, c5, c4, c3, c2, c1, c0}, {c6, c5, c4, c3, c2, c1, c0},
[]credit{c2, c1, c0, c6, c5, c4, c3}, {c2, c1, c0, c6, c5, c4, c3},
[]credit{c6, c4, c5, c2, c3, c0, c1}, {c6, c4, c5, c2, c3, c0, c1},
} }
want := []credit{c0, c1, c2, c3, c4, c5, c6} want := []credit{c0, c1, c2, c3, c4, c5, c6}

View file

@ -1,4 +1,4 @@
// Copyright (c) 2015-2016 The btcsuite developers // Copyright (c) 2015-2017 The btcsuite developers
// Use of this source code is governed by an ISC // Use of this source code is governed by an ISC
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
@ -6,6 +6,7 @@ package votingpool
import ( import (
"bytes" "bytes"
"crypto/sha256"
"fmt" "fmt"
"math" "math"
"reflect" "reflect"
@ -19,7 +20,6 @@ import (
"github.com/btcsuite/btcwallet/waddrmgr" "github.com/btcsuite/btcwallet/waddrmgr"
"github.com/btcsuite/btcwallet/walletdb" "github.com/btcsuite/btcwallet/walletdb"
"github.com/btcsuite/btcwallet/wtxmgr" "github.com/btcsuite/btcwallet/wtxmgr"
"github.com/btcsuite/fastsha256"
) )
// Maximum tx size (in bytes). This should be the same as bitcoind's // Maximum tx size (in bytes). This should be the same as bitcoind's
@ -212,7 +212,7 @@ func (r OutputRequest) outBailmentIDHash() []byte {
return r.cachedHash return r.cachedHash
} }
str := r.Server + strconv.Itoa(int(r.Transaction)) str := r.Server + strconv.Itoa(int(r.Transaction))
hasher := fastsha256.New() hasher := sha256.New()
// hasher.Write() always returns nil as the error, so it's safe to ignore it here. // hasher.Write() always returns nil as the error, so it's safe to ignore it here.
_, _ = hasher.Write([]byte(str)) _, _ = hasher.Write([]byte(str))
id := hasher.Sum(nil) id := hasher.Sum(nil)

View file

@ -1,4 +1,4 @@
// Copyright (c) 2015 The btcsuite developers // Copyright (c) 2015-2017 The btcsuite developers
// Use of this source code is governed by an ISC // Use of this source code is governed by an ISC
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
@ -413,14 +413,14 @@ func TestRollbackLastOutputWhenNewOutputAdded(t *testing.T) {
firstTx := w.transactions[0] firstTx := w.transactions[0]
req1 := requests[0] req1 := requests[0]
checkTxOutputs(t, firstTx, checkTxOutputs(t, firstTx,
[]*withdrawalTxOut{&withdrawalTxOut{request: req1, amount: req1.Amount}}) []*withdrawalTxOut{{request: req1, amount: req1.Amount}})
checkTxChangeAmount(t, firstTx, btcutil.Amount(4)) checkTxChangeAmount(t, firstTx, btcutil.Amount(4))
// Second tx should have one output with 2 and one changeoutput with 3 satoshis. // Second tx should have one output with 2 and one changeoutput with 3 satoshis.
secondTx := w.transactions[1] secondTx := w.transactions[1]
req2 := requests[1] req2 := requests[1]
checkTxOutputs(t, secondTx, checkTxOutputs(t, secondTx,
[]*withdrawalTxOut{&withdrawalTxOut{request: req2, amount: req2.Amount}}) []*withdrawalTxOut{{request: req2, amount: req2.Amount}})
checkTxChangeAmount(t, secondTx, btcutil.Amount(3)) checkTxChangeAmount(t, secondTx, btcutil.Amount(3))
} }
@ -469,7 +469,7 @@ func TestRollbackLastOutputWhenNewInputAdded(t *testing.T) {
firstTx := w.transactions[0] firstTx := w.transactions[0]
req1 := requests[0] req1 := requests[0]
checkTxOutputs(t, firstTx, checkTxOutputs(t, firstTx,
[]*withdrawalTxOut{&withdrawalTxOut{request: req1, amount: req1.Amount}}) []*withdrawalTxOut{{request: req1, amount: req1.Amount}})
checkTxInputs(t, firstTx, eligible[5:6]) checkTxInputs(t, firstTx, eligible[5:6])
// Second tx should have outputs for the two last requests (in the same // Second tx should have outputs for the two last requests (in the same
@ -478,8 +478,8 @@ func TestRollbackLastOutputWhenNewInputAdded(t *testing.T) {
// that's how fulfillRequests() consumes them) and no change output. // that's how fulfillRequests() consumes them) and no change output.
secondTx := w.transactions[1] secondTx := w.transactions[1]
wantOutputs := []*withdrawalTxOut{ wantOutputs := []*withdrawalTxOut{
&withdrawalTxOut{request: requests[1], amount: requests[1].Amount}, {request: requests[1], amount: requests[1].Amount},
&withdrawalTxOut{request: requests[2], amount: requests[2].Amount}} {request: requests[2], amount: requests[2].Amount}}
checkTxOutputs(t, secondTx, wantOutputs) checkTxOutputs(t, secondTx, wantOutputs)
wantInputs := []credit{eligible[4], eligible[3], eligible[2]} wantInputs := []credit{eligible[4], eligible[3], eligible[2]}
checkTxInputs(t, secondTx, wantInputs) checkTxInputs(t, secondTx, wantInputs)
@ -804,7 +804,7 @@ func TestSignMultiSigUTXOUnparseablePkScript(t *testing.T) {
msgtx := tx.toMsgTx() msgtx := tx.toMsgTx()
unparseablePkScript := []byte{0x01} unparseablePkScript := []byte{0x01}
err := signMultiSigUTXO(mgr, msgtx, 0, unparseablePkScript, []RawSig{RawSig{}}) err := signMultiSigUTXO(mgr, msgtx, 0, unparseablePkScript, []RawSig{{}})
TstCheckError(t, "", err, ErrTxSigning) TstCheckError(t, "", err, ErrTxSigning)
} }
@ -819,7 +819,7 @@ func TestSignMultiSigUTXOPkScriptNotP2SH(t *testing.T) {
pubKeyHashPkScript, _ := txscript.PayToAddrScript(addr.(*btcutil.AddressPubKeyHash)) pubKeyHashPkScript, _ := txscript.PayToAddrScript(addr.(*btcutil.AddressPubKeyHash))
msgtx := tx.toMsgTx() msgtx := tx.toMsgTx()
err := signMultiSigUTXO(mgr, msgtx, 0, pubKeyHashPkScript, []RawSig{RawSig{}}) err := signMultiSigUTXO(mgr, msgtx, 0, pubKeyHashPkScript, []RawSig{{}})
TstCheckError(t, "", err, ErrTxSigning) TstCheckError(t, "", err, ErrTxSigning)
} }
@ -839,7 +839,7 @@ func TestSignMultiSigUTXORedeemScriptNotFound(t *testing.T) {
msgtx := tx.toMsgTx() msgtx := tx.toMsgTx()
pkScript, _ := txscript.PayToAddrScript(addr.(*btcutil.AddressScriptHash)) pkScript, _ := txscript.PayToAddrScript(addr.(*btcutil.AddressScriptHash))
err := signMultiSigUTXO(mgr, msgtx, 0, pkScript, []RawSig{RawSig{}}) err := signMultiSigUTXO(mgr, msgtx, 0, pkScript, []RawSig{{}})
TstCheckError(t, "", err, ErrTxSigning) TstCheckError(t, "", err, ErrTxSigning)
} }
@ -875,7 +875,7 @@ func TestSignMultiSigUTXOWrongRawSigs(t *testing.T) {
mgr := pool.Manager() mgr := pool.Manager()
tx := createWithdrawalTx(t, pool, []int64{4e6}, []int64{}) tx := createWithdrawalTx(t, pool, []int64{4e6}, []int64{})
sigs := []RawSig{RawSig{0x00}, RawSig{0x01}} sigs := []RawSig{{0x00}, {0x01}}
idx := 0 // The index of the tx input we're going to sign. idx := 0 // The index of the tx input we're going to sign.
pkScript := tx.inputs[idx].PkScript pkScript := tx.inputs[idx].PkScript

View file

@ -1,4 +1,4 @@
// Copyright (c) 2014-2016 The btcsuite developers // Copyright (c) 2014-2017 The btcsuite developers
// Use of this source code is governed by an ISC // Use of this source code is governed by an ISC
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
@ -6,6 +6,7 @@ package waddrmgr
import ( import (
"bytes" "bytes"
"crypto/sha256"
"encoding/binary" "encoding/binary"
"fmt" "fmt"
"time" "time"
@ -14,7 +15,6 @@ import (
"github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcutil/hdkeychain" "github.com/btcsuite/btcutil/hdkeychain"
"github.com/btcsuite/btcwallet/walletdb" "github.com/btcsuite/btcwallet/walletdb"
"github.com/btcsuite/fastsha256"
) )
const ( const (
@ -1006,7 +1006,7 @@ func fetchAddressByHash(tx walletdb.Tx, addrHash []byte) (interface{}, error) {
func fetchAddressUsed(tx walletdb.Tx, addressID []byte) bool { func fetchAddressUsed(tx walletdb.Tx, addressID []byte) bool {
bucket := tx.RootBucket().Bucket(usedAddrBucketName) bucket := tx.RootBucket().Bucket(usedAddrBucketName)
addrHash := fastsha256.Sum256(addressID) addrHash := sha256.Sum256(addressID)
return bucket.Get(addrHash[:]) != nil return bucket.Get(addrHash[:]) != nil
} }
@ -1014,7 +1014,7 @@ func fetchAddressUsed(tx walletdb.Tx, addressID []byte) bool {
func markAddressUsed(tx walletdb.Tx, addressID []byte) error { func markAddressUsed(tx walletdb.Tx, addressID []byte) error {
bucket := tx.RootBucket().Bucket(usedAddrBucketName) bucket := tx.RootBucket().Bucket(usedAddrBucketName)
addrHash := fastsha256.Sum256(addressID) addrHash := sha256.Sum256(addressID)
val := bucket.Get(addrHash[:]) val := bucket.Get(addrHash[:])
if val != nil { if val != nil {
return nil return nil
@ -1033,7 +1033,7 @@ func markAddressUsed(tx walletdb.Tx, addressID []byte) error {
// The caller should prefix the error message with the address which caused the // The caller should prefix the error message with the address which caused the
// failure. // failure.
func fetchAddress(tx walletdb.Tx, addressID []byte) (interface{}, error) { func fetchAddress(tx walletdb.Tx, addressID []byte) (interface{}, error) {
addrHash := fastsha256.Sum256(addressID) addrHash := sha256.Sum256(addressID)
return fetchAddressByHash(tx, addrHash[:]) return fetchAddressByHash(tx, addrHash[:])
} }
@ -1045,7 +1045,7 @@ func putAddress(tx walletdb.Tx, addressID []byte, row *dbAddressRow) error {
// Write the serialized value keyed by the hash of the address. The // Write the serialized value keyed by the hash of the address. The
// additional hash is used to conceal the actual address while still // additional hash is used to conceal the actual address while still
// allowed keyed lookups. // allowed keyed lookups.
addrHash := fastsha256.Sum256(addressID) addrHash := sha256.Sum256(addressID)
err := bucket.Put(addrHash[:], serializeAddressRow(row)) err := bucket.Put(addrHash[:], serializeAddressRow(row))
if err != nil { if err != nil {
str := fmt.Sprintf("failed to store address %x", addressID) str := fmt.Sprintf("failed to store address %x", addressID)
@ -1151,7 +1151,7 @@ func putScriptAddress(tx walletdb.Tx, addressID []byte, account uint32,
func existsAddress(tx walletdb.Tx, addressID []byte) bool { func existsAddress(tx walletdb.Tx, addressID []byte) bool {
bucket := tx.RootBucket().Bucket(addrBucketName) bucket := tx.RootBucket().Bucket(addrBucketName)
addrHash := fastsha256.Sum256(addressID) addrHash := sha256.Sum256(addressID)
return bucket.Get(addrHash[:]) != nil return bucket.Get(addrHash[:]) != nil
} }
@ -1161,7 +1161,7 @@ func existsAddress(tx walletdb.Tx, addressID []byte) bool {
func fetchAddrAccount(tx walletdb.Tx, addressID []byte) (uint32, error) { func fetchAddrAccount(tx walletdb.Tx, addressID []byte) (uint32, error) {
bucket := tx.RootBucket().Bucket(addrAcctIdxBucketName) bucket := tx.RootBucket().Bucket(addrAcctIdxBucketName)
addrHash := fastsha256.Sum256(addressID) addrHash := sha256.Sum256(addressID)
val := bucket.Get(addrHash[:]) val := bucket.Get(addrHash[:])
if val == nil { if val == nil {
str := "address not found" str := "address not found"

View file

@ -1,4 +1,4 @@
// Copyright (c) 2015-2016 The btcsuite developers // Copyright (c) 2015-2017 The btcsuite developers
// Use of this source code is governed by an ISC // Use of this source code is governed by an ISC
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
@ -516,8 +516,8 @@ func TestStoreQueries(t *testing.T) {
newState = lastState.deepCopy() newState = lastState.deepCopy()
newState.blocks = [][]TxDetails{ newState.blocks = [][]TxDetails{
newState.blocks[0], newState.blocks[0],
[]TxDetails{newState.blocks[1][0]}, {newState.blocks[1][0]},
[]TxDetails{newState.blocks[1][1]}, {newState.blocks[1][1]},
} }
newState.blocks[1][0].Block = b101 newState.blocks[1][0].Block = b101
newState.txDetails[recA.Hash][1].Block = b101 newState.txDetails[recA.Hash][1].Block = b101
@ -558,17 +558,17 @@ func TestPreviousPkScripts(t *testing.T) {
buildTx := func(prevHash *chainhash.Hash, script0, script1 []byte) *wire.MsgTx { buildTx := func(prevHash *chainhash.Hash, script0, script1 []byte) *wire.MsgTx {
return &wire.MsgTx{ return &wire.MsgTx{
TxIn: []*wire.TxIn{ TxIn: []*wire.TxIn{
&wire.TxIn{PreviousOutPoint: wire.OutPoint{ {PreviousOutPoint: wire.OutPoint{
Hash: *prevHash, Hash: *prevHash,
Index: 0, Index: 0,
}}, }},
&wire.TxIn{PreviousOutPoint: wire.OutPoint{ {PreviousOutPoint: wire.OutPoint{
Hash: *prevHash, Index: 1, Hash: *prevHash, Index: 1,
}}, }},
}, },
TxOut: []*wire.TxOut{ TxOut: []*wire.TxOut{
&wire.TxOut{Value: 1e8, PkScript: script0}, {Value: 1e8, PkScript: script0},
&wire.TxOut{Value: 1e8, PkScript: script1}, {Value: 1e8, PkScript: script1},
}, },
} }
} }

View file

@ -1,4 +1,4 @@
// Copyright (c) 2013-2016 The btcsuite developers // Copyright (c) 2013-2017 The btcsuite developers
// Use of this source code is governed by an ISC // Use of this source code is governed by an ISC
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
@ -606,7 +606,7 @@ func TestFindingSpentCredits(t *testing.T) {
func newCoinBase(outputValues ...int64) *wire.MsgTx { func newCoinBase(outputValues ...int64) *wire.MsgTx {
tx := wire.MsgTx{ tx := wire.MsgTx{
TxIn: []*wire.TxIn{ TxIn: []*wire.TxIn{
&wire.TxIn{ {
PreviousOutPoint: wire.OutPoint{Index: ^uint32(0)}, PreviousOutPoint: wire.OutPoint{Index: ^uint32(0)},
}, },
}, },
@ -620,7 +620,7 @@ func newCoinBase(outputValues ...int64) *wire.MsgTx {
func spendOutput(txHash *chainhash.Hash, index uint32, outputValues ...int64) *wire.MsgTx { func spendOutput(txHash *chainhash.Hash, index uint32, outputValues ...int64) *wire.MsgTx {
tx := wire.MsgTx{ tx := wire.MsgTx{
TxIn: []*wire.TxIn{ TxIn: []*wire.TxIn{
&wire.TxIn{ {
PreviousOutPoint: wire.OutPoint{Hash: *txHash, Index: index}, PreviousOutPoint: wire.OutPoint{Hash: *txHash, Index: index},
}, },
}, },