Switch RPC server to use fastsha256 package.

This commit is contained in:
Dave Collins 2014-03-23 00:49:20 -05:00
parent e98db34ef2
commit 049a545427

View file

@ -7,7 +7,6 @@ package main
import ( import (
"bytes" "bytes"
"code.google.com/p/go.net/websocket" "code.google.com/p/go.net/websocket"
"crypto/sha256"
"crypto/subtle" "crypto/subtle"
"crypto/tls" "crypto/tls"
"encoding/base64" "encoding/base64"
@ -20,6 +19,7 @@ import (
"github.com/conformal/btcscript" "github.com/conformal/btcscript"
"github.com/conformal/btcutil" "github.com/conformal/btcutil"
"github.com/conformal/btcwire" "github.com/conformal/btcwire"
"github.com/conformal/fastsha256"
"io/ioutil" "io/ioutil"
"math/big" "math/big"
"net" "net"
@ -144,7 +144,7 @@ type rpcServer struct {
started int32 started int32
shutdown int32 shutdown int32
server *server server *server
authsha [sha256.Size]byte authsha [fastsha256.Size]byte
ntfnMgr *wsNotificationManager ntfnMgr *wsNotificationManager
numClients int numClients int
numClientsMutex sync.Mutex numClientsMutex sync.Mutex
@ -276,7 +276,7 @@ func (s *rpcServer) checkAuth(r *http.Request, require bool) (bool, error) {
return false, nil return false, nil
} }
authsha := sha256.Sum256([]byte(authhdr[0])) authsha := fastsha256.Sum256([]byte(authhdr[0]))
cmp := subtle.ConstantTimeCompare(authsha[:], s.authsha[:]) cmp := subtle.ConstantTimeCompare(authsha[:], s.authsha[:])
if cmp != 1 { if cmp != 1 {
rpcsLog.Warnf("RPC authentication failure from %s", r.RemoteAddr) rpcsLog.Warnf("RPC authentication failure from %s", r.RemoteAddr)
@ -336,7 +336,7 @@ func newRPCServer(listenAddrs []string, s *server) (*rpcServer, error) {
login := cfg.RPCUser + ":" + cfg.RPCPass login := cfg.RPCUser + ":" + cfg.RPCPass
auth := "Basic " + base64.StdEncoding.EncodeToString([]byte(login)) auth := "Basic " + base64.StdEncoding.EncodeToString([]byte(login))
rpc := rpcServer{ rpc := rpcServer{
authsha: sha256.Sum256([]byte(auth)), authsha: fastsha256.Sum256([]byte(auth)),
server: s, server: s,
quit: make(chan int), quit: make(chan int),
} }