misc changes
authors_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b>
Sun, 15 Aug 2010 21:05:16 +0000 (21:05 +0000)
committers_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b>
Sun, 15 Aug 2010 21:05:16 +0000 (21:05 +0000)
git-svn-id: https://bitcoin.svn.sourceforge.net/svnroot/bitcoin/trunk@131 1a98c847-1fd6-4fd8-948a-caf3550aa51b

init.cpp
main.cpp
main.h
script.cpp
serialize.h
setup.nsi
sha256.cpp [new file with mode: 0644]
util.cpp

index b99237e..a2df01b 100644 (file)
--- a/init.cpp
+++ b/init.cpp
@@ -373,6 +373,8 @@ bool AppInit2(int argc, char* argv[])
             wxMessageBox(_("Invalid amount for -paytxfee=<amount>"), "Bitcoin");\r
             return false;\r
         }\r
+        if (nTransactionFee > 1 * COIN)\r
+            wxMessageBox(_("Warning: -paytxfee is set very high.  This is the transaction fee you will pay if you send a transaction."), "Bitcoin");\r
     }\r
 \r
     //\r
index 4b71465..3e7d2b9 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -538,7 +538,7 @@ bool CTransaction::AcceptTransaction(CTxDB& txdb, bool fCheckInputs, bool* pfMis
     // Check against previous transactions\r
     map<uint256, CTxIndex> mapUnused;\r
     int64 nFees = 0;\r
-    if (fCheckInputs && !ConnectInputs(txdb, mapUnused, CDiskTxPos(1,1,1), 0, nFees, false, false))\r
+    if (fCheckInputs && !ConnectInputs(txdb, mapUnused, CDiskTxPos(1,1,1), pindexBest, nFees, false, false))\r
     {\r
         if (pfMissingInputs)\r
             *pfMissingInputs = true;\r
@@ -744,7 +744,7 @@ void ResendWalletTransactions()
     if (GetTime() < nNextTime)\r
         return;\r
     bool fFirst = (nNextTime == 0);\r
-    nNextTime = GetTime() + GetRand(120 * 60);\r
+    nNextTime = GetTime() + GetRand(30 * 60);\r
     if (fFirst)\r
         return;\r
 \r
@@ -760,7 +760,7 @@ void ResendWalletTransactions()
             CWalletTx& wtx = item.second;\r
             // Don't rebroadcast until it's had plenty of time that\r
             // it should have gotten in already by now.\r
-            if (nTimeBestReceived - wtx.nTimeReceived > 60 * 60)\r
+            if (nTimeBestReceived - (int64)wtx.nTimeReceived > 5 * 60)\r
                 mapSorted.insert(make_pair(wtx.nTimeReceived, &wtx));\r
         }\r
         foreach(PAIRTYPE(const unsigned int, CWalletTx*)& item, mapSorted)\r
@@ -931,7 +931,8 @@ bool CTransaction::DisconnectInputs(CTxDB& txdb)
 }\r
 \r
 \r
-bool CTransaction::ConnectInputs(CTxDB& txdb, map<uint256, CTxIndex>& mapTestPool, CDiskTxPos posThisTx, int nHeight, int64& nFees, bool fBlock, bool fMiner, int64 nMinFee)\r
+bool CTransaction::ConnectInputs(CTxDB& txdb, map<uint256, CTxIndex>& mapTestPool, CDiskTxPos posThisTx,\r
+                                 CBlockIndex* pindexBlock, int64& nFees, bool fBlock, bool fMiner, int64 nMinFee)\r
 {\r
     // Take over previous transactions' spent pointers\r
     if (!IsCoinBase())\r
@@ -983,9 +984,9 @@ bool CTransaction::ConnectInputs(CTxDB& txdb, map<uint256, CTxIndex>& mapTestPoo
 \r
             // If prev is coinbase, check that it's matured\r
             if (txPrev.IsCoinBase())\r
-                for (CBlockIndex* pindex = pindexBest; pindex && nBestHeight - pindex->nHeight < COINBASE_MATURITY-1; pindex = pindex->pprev)\r
+                for (CBlockIndex* pindex = pindexBlock; pindex && pindexBlock->nHeight - pindex->nHeight < COINBASE_MATURITY; pindex = pindex->pprev)\r
                     if (pindex->nBlockPos == txindex.pos.nBlockPos && pindex->nFile == txindex.pos.nFile)\r
-                        return error("ConnectInputs() : tried to spend coinbase at depth %d", nBestHeight - pindex->nHeight);\r
+                        return error("ConnectInputs() : tried to spend coinbase at depth %d", pindexBlock->nHeight - pindex->nHeight);\r
 \r
             // Verify signature\r
             if (!VerifySignature(txPrev, *this, i))\r
@@ -1019,7 +1020,7 @@ bool CTransaction::ConnectInputs(CTxDB& txdb, map<uint256, CTxIndex>& mapTestPoo
     if (fBlock)\r
     {\r
         // Add transaction to disk index\r
-        if (!txdb.AddTxIndex(*this, posThisTx, nHeight))\r
+        if (!txdb.AddTxIndex(*this, posThisTx, pindexBlock->nHeight))\r
             return error("ConnectInputs() : AddTxPos failed");\r
     }\r
     else if (fMiner)\r
@@ -1108,7 +1109,7 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex)
         CDiskTxPos posThisTx(pindex->nFile, pindex->nBlockPos, nTxPos);\r
         nTxPos += ::GetSerializeSize(tx, SER_DISK);\r
 \r
-        if (!tx.ConnectInputs(txdb, mapUnused, posThisTx, pindex->nHeight, nFees, true, false))\r
+        if (!tx.ConnectInputs(txdb, mapUnused, posThisTx, pindex, nFees, true, false))\r
             return false;\r
     }\r
 \r
@@ -1379,14 +1380,12 @@ bool CBlock::AcceptBlock()
         return error("AcceptBlock() : incorrect proof of work");\r
 \r
     // Check that the block chain matches the known block chain up to a checkpoint\r
-    if (pindexPrev->nHeight+1 == 11111 && hash != uint256("0x0000000069e244f73d78e8fd29ba2fd2ed618bd6fa2ee92559f542fdb26e7c1d"))\r
-        return error("AcceptBlock() : rejected by checkpoint lockin at 11111");\r
-    if (pindexPrev->nHeight+1 == 33333 && hash != uint256("0x000000002dd5588a74784eaa7ab0507a18ad16a236e7b1ce69f00d7ddfb5d0a6"))\r
-        return error("AcceptBlock() : rejected by checkpoint lockin at 33333");\r
-    if (pindexPrev->nHeight+1 == 68555 && hash != uint256("0x00000000001e1b4903550a0b96e9a9405c8a95f387162e4944e8d9fbe501cd6a"))\r
-        return error("AcceptBlock() : rejected by checkpoint lockin at 68555");\r
-    if (pindexPrev->nHeight+1 == 70567 && hash != uint256("0x00000000006a49b14bcf27462068f1264c961f11fa2e0eddd2be0791e1d4124a"))\r
-        return error("AcceptBlock() : rejected by checkpoint lockin at 70567");\r
+    if ((pindexPrev->nHeight+1 == 11111 && hash != uint256("0x0000000069e244f73d78e8fd29ba2fd2ed618bd6fa2ee92559f542fdb26e7c1d")) ||\r
+        (pindexPrev->nHeight+1 == 33333 && hash != uint256("0x000000002dd5588a74784eaa7ab0507a18ad16a236e7b1ce69f00d7ddfb5d0a6")) ||\r
+        (pindexPrev->nHeight+1 == 68555 && hash != uint256("0x00000000001e1b4903550a0b96e9a9405c8a95f387162e4944e8d9fbe501cd6a")) ||\r
+        (pindexPrev->nHeight+1 == 70567 && hash != uint256("0x00000000006a49b14bcf27462068f1264c961f11fa2e0eddd2be0791e1d4124a")) ||\r
+        (pindexPrev->nHeight+1 == 74000 && hash != uint256("0x0000000000573993a3c9e41ce34471c079dcf5f52a0e824a81e7f953b8661a20")))\r
+        return error("AcceptBlock() : rejected by checkpoint lockin");\r
 \r
     // Write block to history file\r
     if (!CheckDiskSpace(::GetSerializeSize(*this, SER_DISK)))\r
@@ -2577,6 +2576,8 @@ inline void SHA256Transform(void* pstate, void* pinput, const void* pinit)
     CryptoPP::SHA256::Transform((CryptoPP::word32*)pstate, (CryptoPP::word32*)pinput);\r
 }\r
 \r
+static const int NPAR = 32;\r
+extern void Double_BlockSHA256(const void* pin, void* pout, const void* pinit, unsigned int hash[8][NPAR], const void* init2);\r
 \r
 \r
 \r
@@ -2658,7 +2659,7 @@ void BitcoinMiner()
                     int64 nMinFee = tx.GetMinFee(nBlockSize);\r
 \r
                     map<uint256, CTxIndex> mapTestPoolTmp(mapTestPool);\r
-                    if (!tx.ConnectInputs(txdb, mapTestPoolTmp, CDiskTxPos(1,1,1), 0, nFees, false, true, nMinFee))\r
+                    if (!tx.ConnectInputs(txdb, mapTestPoolTmp, CDiskTxPos(1,1,1), pindexPrev, nFees, false, true, nMinFee))\r
                         continue;\r
                     swap(mapTestPool, mapTestPoolTmp);\r
 \r
@@ -2719,14 +2720,40 @@ void BitcoinMiner()
         //\r
         // Search\r
         //\r
+        bool f4WaySSE2 = mapArgs.count("-4way");\r
         int64 nStart = GetTime();\r
         uint256 hashTarget = CBigNum().SetCompact(pblock->nBits).getuint256();\r
         uint256 hashbuf[2];\r
         uint256& hash = *alignup<16>(hashbuf);\r
         loop\r
         {\r
-            SHA256Transform(&tmp.hash1, (char*)&tmp.block + 64, &midstate);\r
-            SHA256Transform(&hash, &tmp.hash1, pSHA256InitState);\r
+#ifdef FOURWAYSSE2\r
+            if (f4WaySSE2)\r
+            {\r
+                // tcatm's 4-way SSE2 SHA-256\r
+                tmp.block.nNonce += NPAR;\r
+                unsigned int thashbuf[9][NPAR];\r
+                unsigned int (&thash)[9][NPAR] = *alignup<16>(&thashbuf);\r
+                Double_BlockSHA256((char*)&tmp.block + 64, &tmp.hash1, &midstate, thash, pSHA256InitState);\r
+                ((unsigned short*)&hash)[14] = 0xffff;\r
+                for (int j = 0; j < NPAR; j++)\r
+                {\r
+                    if (thash[7][j] == 0)\r
+                    {\r
+                        for (int i = 0; i < sizeof(hash)/4; i++)\r
+                            ((unsigned int*)&hash)[i] = thash[i][j];\r
+                        pblock->nNonce = ByteReverse(tmp.block.nNonce + j);\r
+                    }\r
+                }\r
+            }\r
+            else\r
+#endif\r
+            {\r
+                // Crypto++ SHA-256\r
+                tmp.block.nNonce++;\r
+                SHA256Transform(&tmp.hash1, (char*)&tmp.block + 64, &midstate);\r
+                SHA256Transform(&hash, &tmp.hash1, pSHA256InitState);\r
+            }\r
 \r
             if (((unsigned short*)&hash)[14] == 0)\r
             {\r
@@ -2736,7 +2763,10 @@ void BitcoinMiner()
 \r
                 if (hash <= hashTarget)\r
                 {\r
-                    pblock->nNonce = ByteReverse(tmp.block.nNonce);\r
+#ifdef FOURWAYSSE2\r
+                    if (!f4WaySSE2)\r
+#endif\r
+                        pblock->nNonce = ByteReverse(tmp.block.nNonce);\r
                     assert(hash == pblock->GetHash());\r
 \r
                         //// debug print\r
@@ -2775,7 +2805,7 @@ void BitcoinMiner()
             // Update nTime every few seconds\r
             const unsigned int nMask = 0xffff;\r
             const int nHashesPerCycle = (nMask+1);\r
-            if ((++tmp.block.nNonce & nMask) == 0)\r
+            if ((tmp.block.nNonce & nMask) == 0)\r
             {\r
                 // Meter hashes/sec\r
                 static int nCycleCounter;\r
diff --git a/main.h b/main.h
index 2ddac59..8ed3ef2 100644 (file)
--- a/main.h
+++ b/main.h
@@ -613,7 +613,8 @@ public:
 \r
 \r
     bool DisconnectInputs(CTxDB& txdb);\r
-    bool ConnectInputs(CTxDB& txdb, map<uint256, CTxIndex>& mapTestPool, CDiskTxPos posThisTx, int nHeight, int64& nFees, bool fBlock, bool fMiner, int64 nMinFee=0);\r
+    bool ConnectInputs(CTxDB& txdb, map<uint256, CTxIndex>& mapTestPool, CDiskTxPos posThisTx,\r
+                       CBlockIndex* pindexBlock, int64& nFees, bool fBlock, bool fMiner, int64 nMinFee=0);\r
     bool ClientConnectInputs();\r
 \r
     bool AcceptTransaction(CTxDB& txdb, bool fCheckInputs=true, bool* pfMissingInputs=NULL);\r
index a88f915..b33becc 100644 (file)
@@ -16,12 +16,30 @@ static const CBigNum bnZero(0);
 static const CBigNum bnOne(1);\r
 static const CBigNum bnFalse(0);\r
 static const CBigNum bnTrue(1);\r
-static const size_t nMaxNumSize = 258;\r
+static const size_t nMaxNumSize = 4;\r
 \r
 \r
+CBigNum CastToBigNum(const valtype& vch)\r
+{\r
+    if (vch.size() > nMaxNumSize)\r
+        throw runtime_error("CastToBigNum() : overflow");\r
+    // Get rid of extra leading zeros\r
+    return CBigNum(CBigNum(vch).getvch());\r
+}\r
+\r
 bool CastToBool(const valtype& vch)\r
 {\r
-    return (CBigNum(vch) != bnZero);\r
+    for (int i = 0; i < vch.size(); i++)\r
+    {\r
+        if (vch[i] != 0)\r
+        {\r
+            // Can be negative zero\r
+            if (i == vch.size()-1 && vch[i] == 0x80)\r
+                return false;\r
+            return true;\r
+        }\r
+    }\r
+    return false;\r
 }\r
 \r
 void MakeSameSize(valtype& vch1, valtype& vch2)\r
@@ -68,11 +86,28 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, co
             valtype vchPushValue;\r
             if (!script.GetOp(pc, opcode, vchPushValue))\r
                 return false;\r
-            if (vchPushValue.size() > 5000)\r
+            if (vchPushValue.size() > 520)\r
                 return false;\r
             if (opcode > OP_16 && nOpCount++ > 200)\r
                 return false;\r
 \r
+            if (opcode == OP_CAT ||\r
+                opcode == OP_SUBSTR ||\r
+                opcode == OP_LEFT ||\r
+                opcode == OP_RIGHT ||\r
+                opcode == OP_INVERT ||\r
+                opcode == OP_AND ||\r
+                opcode == OP_OR ||\r
+                opcode == OP_XOR ||\r
+                opcode == OP_2MUL ||\r
+                opcode == OP_2DIV ||\r
+                opcode == OP_MUL ||\r
+                opcode == OP_DIV ||\r
+                opcode == OP_MOD ||\r
+                opcode == OP_LSHIFT ||\r
+                opcode == OP_RSHIFT)\r
+                return false;\r
+\r
             if (fExec && opcode <= OP_PUSHDATA4)\r
                 stack.push_back(vchPushValue);\r
             else if (fExec || (OP_IF <= opcode && opcode <= OP_ENDIF))\r
@@ -332,7 +367,7 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, co
                     // (xn ... x2 x1 x0 n - ... x2 x1 x0 xn)\r
                     if (stack.size() < 2)\r
                         return false;\r
-                    int n = CBigNum(stacktop(-1)).getint();\r
+                    int n = CastToBigNum(stacktop(-1)).getint();\r
                     stack.pop_back();\r
                     if (n < 0 || n >= stack.size())\r
                         return false;\r
@@ -387,7 +422,7 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, co
                     valtype& vch2 = stacktop(-1);\r
                     vch1.insert(vch1.end(), vch2.begin(), vch2.end());\r
                     stack.pop_back();\r
-                    if (stacktop(-1).size() > 5000)\r
+                    if (stacktop(-1).size() > 520)\r
                         return false;\r
                 }\r
                 break;\r
@@ -398,8 +433,8 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, co
                     if (stack.size() < 3)\r
                         return false;\r
                     valtype& vch = stacktop(-3);\r
-                    int nBegin = CBigNum(stacktop(-2)).getint();\r
-                    int nEnd = nBegin + CBigNum(stacktop(-1)).getint();\r
+                    int nBegin = CastToBigNum(stacktop(-2)).getint();\r
+                    int nEnd = nBegin + CastToBigNum(stacktop(-1)).getint();\r
                     if (nBegin < 0 || nEnd < nBegin)\r
                         return false;\r
                     if (nBegin > vch.size())\r
@@ -420,7 +455,7 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, co
                     if (stack.size() < 2)\r
                         return false;\r
                     valtype& vch = stacktop(-2);\r
-                    int nSize = CBigNum(stacktop(-1)).getint();\r
+                    int nSize = CastToBigNum(stacktop(-1)).getint();\r
                     if (nSize < 0)\r
                         return false;\r
                     if (nSize > vch.size())\r
@@ -531,9 +566,7 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, co
                     // (in -- out)\r
                     if (stack.size() < 1)\r
                         return false;\r
-                    if (stacktop(-1).size() > nMaxNumSize)\r
-                        return false;\r
-                    CBigNum bn(stacktop(-1));\r
+                    CBigNum bn = CastToBigNum(stacktop(-1));\r
                     switch (opcode)\r
                     {\r
                     case OP_1ADD:       bn += bnOne; break;\r
@@ -572,11 +605,8 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, co
                     // (x1 x2 -- out)\r
                     if (stack.size() < 2)\r
                         return false;\r
-                    if (stacktop(-2).size() > nMaxNumSize ||\r
-                        stacktop(-1).size() > nMaxNumSize)\r
-                        return false;\r
-                    CBigNum bn1(stacktop(-2));\r
-                    CBigNum bn2(stacktop(-1));\r
+                    CBigNum bn1 = CastToBigNum(stacktop(-2));\r
+                    CBigNum bn2 = CastToBigNum(stacktop(-1));\r
                     CBigNum bn;\r
                     switch (opcode)\r
                     {\r
@@ -646,13 +676,9 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, co
                     // (x min max -- out)\r
                     if (stack.size() < 3)\r
                         return false;\r
-                    if (stacktop(-3).size() > nMaxNumSize ||\r
-                        stacktop(-2).size() > nMaxNumSize ||\r
-                        stacktop(-1).size() > nMaxNumSize)\r
-                        return false;\r
-                    CBigNum bn1(stacktop(-3));\r
-                    CBigNum bn2(stacktop(-2));\r
-                    CBigNum bn3(stacktop(-1));\r
+                    CBigNum bn1 = CastToBigNum(stacktop(-3));\r
+                    CBigNum bn2 = CastToBigNum(stacktop(-2));\r
+                    CBigNum bn3 = CastToBigNum(stacktop(-1));\r
                     bool fValue = (bn2 <= bn1 && bn1 < bn3);\r
                     stack.pop_back();\r
                     stack.pop_back();\r
@@ -748,7 +774,7 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, co
                     if (stack.size() < i)\r
                         return false;\r
 \r
-                    int nKeysCount = CBigNum(stacktop(-i)).getint();\r
+                    int nKeysCount = CastToBigNum(stacktop(-i)).getint();\r
                     if (nKeysCount < 0)\r
                         return false;\r
                     int ikey = ++i;\r
@@ -756,7 +782,7 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, co
                     if (stack.size() < i)\r
                         return false;\r
 \r
-                    int nSigsCount = CBigNum(stacktop(-i)).getint();\r
+                    int nSigsCount = CastToBigNum(stacktop(-i)).getint();\r
                     if (nSigsCount < 0 || nSigsCount > nKeysCount)\r
                         return false;\r
                     int isig = ++i;\r
index 0c60bb9..591aaa4 100644 (file)
@@ -19,8 +19,8 @@ class CScript;
 class CDataStream;\r
 class CAutoFile;\r
 \r
-static const int VERSION = 308;\r
-static const char* pszSubVer = ".4";\r
+static const int VERSION = 309;\r
+static const char* pszSubVer = ".0";\r
 \r
 \r
 \r
index ae871fd..da03820 100644 (file)
--- a/setup.nsi
+++ b/setup.nsi
@@ -7,7 +7,7 @@ RequestExecutionLevel highest
 \r
 # General Symbol Definitions\r
 !define REGKEY "SOFTWARE\$(^Name)"\r
-!define VERSION 0.3.8\r
+!define VERSION 0.3.9\r
 !define COMPANY "Bitcoin project"\r
 !define URL http://www.bitcoin.org/\r
 \r
@@ -42,12 +42,12 @@ Var StartMenuGroup
 !insertmacro MUI_LANGUAGE English\r
 \r
 # Installer attributes\r
-OutFile bitcoin-0.3.8-win32-setup.exe\r
+OutFile bitcoin-0.3.9-win32-setup.exe\r
 InstallDir $PROGRAMFILES\Bitcoin\r
 CRCCheck on\r
 XPStyle on\r
 ShowInstDetails show\r
-VIProductVersion 0.3.8.0\r
+VIProductVersion 0.3.9.0\r
 VIAddVersionKey ProductName Bitcoin\r
 VIAddVersionKey ProductVersion "${VERSION}"\r
 VIAddVersionKey CompanyName "${COMPANY}"\r
diff --git a/sha256.cpp b/sha256.cpp
new file mode 100644 (file)
index 0000000..bcab2b9
--- /dev/null
@@ -0,0 +1,419 @@
+// Copyright (c) 2010 Satoshi Nakamoto\r
+// Distributed under the MIT/X11 software license, see the accompanying\r
+// file license.txt or http://www.opensource.org/licenses/mit-license.php.\r
+\r
+#include <string.h>\r
+#include <assert.h>\r
+\r
+#include <xmmintrin.h>\r
+#include <stdint.h>\r
+#include <stdio.h>\r
+\r
+#define NPAR 32\r
+\r
+static const unsigned int sha256_consts[] = {\r
+    0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, /*  0 */\r
+    0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,\r
+    0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, /*  8 */\r
+    0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,\r
+    0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, /* 16 */\r
+    0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,\r
+    0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, /* 24 */\r
+    0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,\r
+    0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, /* 32 */\r
+    0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,\r
+    0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, /* 40 */\r
+    0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,\r
+    0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, /* 48 */\r
+    0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,\r
+    0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, /* 56 */\r
+    0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2\r
+};\r
+\r
+\r
+static inline __m128i Ch(const __m128i b, const __m128i c, const __m128i d) {\r
+    return (b & c) ^ (~b & d);\r
+}\r
+\r
+static inline __m128i Maj(const __m128i b, const __m128i c, const __m128i d) {\r
+    return (b & c) ^ (b & d) ^ (c & d);\r
+}\r
+\r
+static inline __m128i ROTR(__m128i x, const int n) {\r
+    return _mm_srli_epi32(x, n) | _mm_slli_epi32(x, 32 - n);\r
+}\r
+\r
+static inline __m128i SHR(__m128i x, const int n) {\r
+    return _mm_srli_epi32(x, n);\r
+}\r
+\r
+/* SHA256 Functions */\r
+#define BIGSIGMA0_256(x)    (ROTR((x), 2) ^ ROTR((x), 13) ^ ROTR((x), 22))\r
+#define BIGSIGMA1_256(x)    (ROTR((x), 6) ^ ROTR((x), 11) ^ ROTR((x), 25))\r
+#define SIGMA0_256(x)       (ROTR((x), 7) ^ ROTR((x), 18) ^ SHR((x), 3))\r
+#define SIGMA1_256(x)       (ROTR((x), 17) ^ ROTR((x), 19) ^ SHR((x), 10))\r
+\r
+static inline unsigned int store32(const __m128i x, int i) {\r
+    union { unsigned int ret[4]; __m128i x; } box;\r
+    box.x = x;\r
+    return box.ret[i];\r
+}\r
+\r
+static inline void store_epi32(const __m128i x, unsigned int *x0, unsigned int *x1, unsigned int *x2, unsigned int *x3) {\r
+    union { unsigned int ret[4]; __m128i x; } box;\r
+    box.x = x;\r
+    *x0 = box.ret[3]; *x1 = box.ret[2]; *x2 = box.ret[1]; *x3 = box.ret[0];\r
+}\r
+\r
+#define add4(x0, x1, x2, x3) _mm_add_epi32(_mm_add_epi32(_mm_add_epi32(x0, x1), x2), x3)\r
+#define add5(x0, x1, x2, x3, x4) _mm_add_epi32(add4(x0, x1, x2, x3), x4)\r
+\r
+#define SHA256ROUND(a, b, c, d, e, f, g, h, i, w)                       \\r
+    T1 = add5(h, BIGSIGMA1_256(e), Ch(e, f, g), _mm_set1_epi32(sha256_consts[i]), w);   \\r
+d = _mm_add_epi32(d, T1);                                           \\r
+h = _mm_add_epi32(T1, _mm_add_epi32(BIGSIGMA0_256(a), Maj(a, b, c)));\r
+\r
+static inline void dumpreg(__m128i x, char *msg) {\r
+    union { unsigned int ret[4]; __m128i x; } box;\r
+    box.x = x ;\r
+    printf("%s %08x %08x %08x %08x\n", msg, box.ret[0], box.ret[1], box.ret[2], box.ret[3]);\r
+}\r
+\r
+#if 1\r
+#define dumpstate(i) printf("%s: %08x %08x %08x %08x %08x %08x %08x %08x %08x\n", \\r
+        __func__, store32(w0, i), store32(a, i), store32(b, i), store32(c, i), store32(d, i), store32(e, i), store32(f, i), store32(g, i), store32(h, i));\r
+#else\r
+#define dumpstate()\r
+#endif\r
+void Double_BlockSHA256(const void* pin, void* pad, const void *pre, unsigned int thash[9][NPAR], const void *init)\r
+{\r
+    unsigned int* In = (unsigned int*)pin;\r
+    unsigned int* Pad = (unsigned int*)pad;\r
+    unsigned int* hPre = (unsigned int*)pre;\r
+    unsigned int* hInit = (unsigned int*)init;\r
+    unsigned int i, j, k;\r
+\r
+    /* vectors used in calculation */\r
+    __m128i w0, w1, w2, w3, w4, w5, w6, w7;\r
+    __m128i w8, w9, w10, w11, w12, w13, w14, w15;\r
+    __m128i T1;\r
+    __m128i a, b, c, d, e, f, g, h;\r
+    __m128i nonce;\r
+\r
+    /* nonce offset for vector */\r
+    __m128i offset = _mm_set_epi32(0x00000003, 0x00000002, 0x00000001, 0x00000000);\r
+\r
+\r
+    for(k = 0; k<NPAR; k+=4) {\r
+        w0 = _mm_set1_epi32(In[0]);\r
+        w1 = _mm_set1_epi32(In[1]);\r
+        w2 = _mm_set1_epi32(In[2]);\r
+        //w3 = _mm_set1_epi32(In[3]); nonce will be later hacked into the hash\r
+        w4 = _mm_set1_epi32(In[4]);\r
+        w5 = _mm_set1_epi32(In[5]);\r
+        w6 = _mm_set1_epi32(In[6]);\r
+        w7 = _mm_set1_epi32(In[7]);\r
+        w8 = _mm_set1_epi32(In[8]);\r
+        w9 = _mm_set1_epi32(In[9]);\r
+        w10 = _mm_set1_epi32(In[10]);\r
+        w11 = _mm_set1_epi32(In[11]);\r
+        w12 = _mm_set1_epi32(In[12]);\r
+        w13 = _mm_set1_epi32(In[13]);\r
+        w14 = _mm_set1_epi32(In[14]);\r
+        w15 = _mm_set1_epi32(In[15]);\r
+\r
+        /* hack nonce into lowest byte of w3 */\r
+        nonce = _mm_set1_epi32(In[3]);\r
+        nonce = _mm_add_epi32(nonce, offset);\r
+        nonce = _mm_add_epi32(nonce, _mm_set1_epi32(k));\r
+        w3 = nonce;\r
+\r
+        a = _mm_set1_epi32(hPre[0]);\r
+        b = _mm_set1_epi32(hPre[1]);\r
+        c = _mm_set1_epi32(hPre[2]);\r
+        d = _mm_set1_epi32(hPre[3]);\r
+        e = _mm_set1_epi32(hPre[4]);\r
+        f = _mm_set1_epi32(hPre[5]);\r
+        g = _mm_set1_epi32(hPre[6]);\r
+        h = _mm_set1_epi32(hPre[7]);\r
+\r
+        SHA256ROUND(a, b, c, d, e, f, g, h, 0, w0);\r
+        SHA256ROUND(h, a, b, c, d, e, f, g, 1, w1);\r
+        SHA256ROUND(g, h, a, b, c, d, e, f, 2, w2);\r
+        SHA256ROUND(f, g, h, a, b, c, d, e, 3, w3);\r
+        SHA256ROUND(e, f, g, h, a, b, c, d, 4, w4);\r
+        SHA256ROUND(d, e, f, g, h, a, b, c, 5, w5);\r
+        SHA256ROUND(c, d, e, f, g, h, a, b, 6, w6);\r
+        SHA256ROUND(b, c, d, e, f, g, h, a, 7, w7);\r
+        SHA256ROUND(a, b, c, d, e, f, g, h, 8, w8);\r
+        SHA256ROUND(h, a, b, c, d, e, f, g, 9, w9);\r
+        SHA256ROUND(g, h, a, b, c, d, e, f, 10, w10);\r
+        SHA256ROUND(f, g, h, a, b, c, d, e, 11, w11);\r
+        SHA256ROUND(e, f, g, h, a, b, c, d, 12, w12);\r
+        SHA256ROUND(d, e, f, g, h, a, b, c, 13, w13);\r
+        SHA256ROUND(c, d, e, f, g, h, a, b, 14, w14);\r
+        SHA256ROUND(b, c, d, e, f, g, h, a, 15, w15);\r
+\r
+        w0 = add4(SIGMA1_256(w14), w9, SIGMA0_256(w1), w0);\r
+        SHA256ROUND(a, b, c, d, e, f, g, h, 16, w0);\r
+        w1 = add4(SIGMA1_256(w15), w10, SIGMA0_256(w2), w1);\r
+        SHA256ROUND(h, a, b, c, d, e, f, g, 17, w1);\r
+        w2 = add4(SIGMA1_256(w0), w11, SIGMA0_256(w3), w2);\r
+        SHA256ROUND(g, h, a, b, c, d, e, f, 18, w2);\r
+        w3 = add4(SIGMA1_256(w1), w12, SIGMA0_256(w4), w3);\r
+        SHA256ROUND(f, g, h, a, b, c, d, e, 19, w3);\r
+        w4 = add4(SIGMA1_256(w2), w13, SIGMA0_256(w5), w4);\r
+        SHA256ROUND(e, f, g, h, a, b, c, d, 20, w4);\r
+        w5 = add4(SIGMA1_256(w3), w14, SIGMA0_256(w6), w5);\r
+        SHA256ROUND(d, e, f, g, h, a, b, c, 21, w5);\r
+        w6 = add4(SIGMA1_256(w4), w15, SIGMA0_256(w7), w6);\r
+        SHA256ROUND(c, d, e, f, g, h, a, b, 22, w6);\r
+        w7 = add4(SIGMA1_256(w5), w0, SIGMA0_256(w8), w7);\r
+        SHA256ROUND(b, c, d, e, f, g, h, a, 23, w7);\r
+        w8 = add4(SIGMA1_256(w6), w1, SIGMA0_256(w9), w8);\r
+        SHA256ROUND(a, b, c, d, e, f, g, h, 24, w8);\r
+        w9 = add4(SIGMA1_256(w7), w2, SIGMA0_256(w10), w9);\r
+        SHA256ROUND(h, a, b, c, d, e, f, g, 25, w9);\r
+        w10 = add4(SIGMA1_256(w8), w3, SIGMA0_256(w11), w10);\r
+        SHA256ROUND(g, h, a, b, c, d, e, f, 26, w10);\r
+        w11 = add4(SIGMA1_256(w9), w4, SIGMA0_256(w12), w11);\r
+        SHA256ROUND(f, g, h, a, b, c, d, e, 27, w11);\r
+        w12 = add4(SIGMA1_256(w10), w5, SIGMA0_256(w13), w12);\r
+        SHA256ROUND(e, f, g, h, a, b, c, d, 28, w12);\r
+        w13 = add4(SIGMA1_256(w11), w6, SIGMA0_256(w14), w13);\r
+        SHA256ROUND(d, e, f, g, h, a, b, c, 29, w13);\r
+        w14 = add4(SIGMA1_256(w12), w7, SIGMA0_256(w15), w14);\r
+        SHA256ROUND(c, d, e, f, g, h, a, b, 30, w14);\r
+        w15 = add4(SIGMA1_256(w13), w8, SIGMA0_256(w0), w15);\r
+        SHA256ROUND(b, c, d, e, f, g, h, a, 31, w15);\r
+\r
+        w0 = add4(SIGMA1_256(w14), w9, SIGMA0_256(w1), w0);\r
+        SHA256ROUND(a, b, c, d, e, f, g, h, 32, w0);\r
+        w1 = add4(SIGMA1_256(w15), w10, SIGMA0_256(w2), w1);\r
+        SHA256ROUND(h, a, b, c, d, e, f, g, 33, w1);\r
+        w2 = add4(SIGMA1_256(w0), w11, SIGMA0_256(w3), w2);\r
+        SHA256ROUND(g, h, a, b, c, d, e, f, 34, w2);\r
+        w3 = add4(SIGMA1_256(w1), w12, SIGMA0_256(w4), w3);\r
+        SHA256ROUND(f, g, h, a, b, c, d, e, 35, w3);\r
+        w4 = add4(SIGMA1_256(w2), w13, SIGMA0_256(w5), w4);\r
+        SHA256ROUND(e, f, g, h, a, b, c, d, 36, w4);\r
+        w5 = add4(SIGMA1_256(w3), w14, SIGMA0_256(w6), w5);\r
+        SHA256ROUND(d, e, f, g, h, a, b, c, 37, w5);\r
+        w6 = add4(SIGMA1_256(w4), w15, SIGMA0_256(w7), w6);\r
+        SHA256ROUND(c, d, e, f, g, h, a, b, 38, w6);\r
+        w7 = add4(SIGMA1_256(w5), w0, SIGMA0_256(w8), w7);\r
+        SHA256ROUND(b, c, d, e, f, g, h, a, 39, w7);\r
+        w8 = add4(SIGMA1_256(w6), w1, SIGMA0_256(w9), w8);\r
+        SHA256ROUND(a, b, c, d, e, f, g, h, 40, w8);\r
+        w9 = add4(SIGMA1_256(w7), w2, SIGMA0_256(w10), w9);\r
+        SHA256ROUND(h, a, b, c, d, e, f, g, 41, w9);\r
+        w10 = add4(SIGMA1_256(w8), w3, SIGMA0_256(w11), w10);\r
+        SHA256ROUND(g, h, a, b, c, d, e, f, 42, w10);\r
+        w11 = add4(SIGMA1_256(w9), w4, SIGMA0_256(w12), w11);\r
+        SHA256ROUND(f, g, h, a, b, c, d, e, 43, w11);\r
+        w12 = add4(SIGMA1_256(w10), w5, SIGMA0_256(w13), w12);\r
+        SHA256ROUND(e, f, g, h, a, b, c, d, 44, w12);\r
+        w13 = add4(SIGMA1_256(w11), w6, SIGMA0_256(w14), w13);\r
+        SHA256ROUND(d, e, f, g, h, a, b, c, 45, w13);\r
+        w14 = add4(SIGMA1_256(w12), w7, SIGMA0_256(w15), w14);\r
+        SHA256ROUND(c, d, e, f, g, h, a, b, 46, w14);\r
+        w15 = add4(SIGMA1_256(w13), w8, SIGMA0_256(w0), w15);\r
+        SHA256ROUND(b, c, d, e, f, g, h, a, 47, w15);\r
+\r
+        w0 = add4(SIGMA1_256(w14), w9, SIGMA0_256(w1), w0);\r
+        SHA256ROUND(a, b, c, d, e, f, g, h, 48, w0);\r
+        w1 = add4(SIGMA1_256(w15), w10, SIGMA0_256(w2), w1);\r
+        SHA256ROUND(h, a, b, c, d, e, f, g, 49, w1);\r
+        w2 = add4(SIGMA1_256(w0), w11, SIGMA0_256(w3), w2);\r
+        SHA256ROUND(g, h, a, b, c, d, e, f, 50, w2);\r
+        w3 = add4(SIGMA1_256(w1), w12, SIGMA0_256(w4), w3);\r
+        SHA256ROUND(f, g, h, a, b, c, d, e, 51, w3);\r
+        w4 = add4(SIGMA1_256(w2), w13, SIGMA0_256(w5), w4);\r
+        SHA256ROUND(e, f, g, h, a, b, c, d, 52, w4);\r
+        w5 = add4(SIGMA1_256(w3), w14, SIGMA0_256(w6), w5);\r
+        SHA256ROUND(d, e, f, g, h, a, b, c, 53, w5);\r
+        w6 = add4(SIGMA1_256(w4), w15, SIGMA0_256(w7), w6);\r
+        SHA256ROUND(c, d, e, f, g, h, a, b, 54, w6);\r
+        w7 = add4(SIGMA1_256(w5), w0, SIGMA0_256(w8), w7);\r
+        SHA256ROUND(b, c, d, e, f, g, h, a, 55, w7);\r
+        w8 = add4(SIGMA1_256(w6), w1, SIGMA0_256(w9), w8);\r
+        SHA256ROUND(a, b, c, d, e, f, g, h, 56, w8);\r
+        w9 = add4(SIGMA1_256(w7), w2, SIGMA0_256(w10), w9);\r
+        SHA256ROUND(h, a, b, c, d, e, f, g, 57, w9);\r
+        w10 = add4(SIGMA1_256(w8), w3, SIGMA0_256(w11), w10);\r
+        SHA256ROUND(g, h, a, b, c, d, e, f, 58, w10);\r
+        w11 = add4(SIGMA1_256(w9), w4, SIGMA0_256(w12), w11);\r
+        SHA256ROUND(f, g, h, a, b, c, d, e, 59, w11);\r
+        w12 = add4(SIGMA1_256(w10), w5, SIGMA0_256(w13), w12);\r
+        SHA256ROUND(e, f, g, h, a, b, c, d, 60, w12);\r
+        w13 = add4(SIGMA1_256(w11), w6, SIGMA0_256(w14), w13);\r
+        SHA256ROUND(d, e, f, g, h, a, b, c, 61, w13);\r
+        w14 = add4(SIGMA1_256(w12), w7, SIGMA0_256(w15), w14);\r
+        SHA256ROUND(c, d, e, f, g, h, a, b, 62, w14);\r
+        w15 = add4(SIGMA1_256(w13), w8, SIGMA0_256(w0), w15);\r
+        SHA256ROUND(b, c, d, e, f, g, h, a, 63, w15);\r
+\r
+#define store_load(x, i, dest) \\r
+        T1 = _mm_set1_epi32((hPre)[i]); \\r
+        dest = _mm_add_epi32(T1, x);\r
+\r
+        store_load(a, 0, w0);\r
+        store_load(b, 1, w1);\r
+        store_load(c, 2, w2);\r
+        store_load(d, 3, w3);\r
+        store_load(e, 4, w4);\r
+        store_load(f, 5, w5);\r
+        store_load(g, 6, w6);\r
+        store_load(h, 7, w7);\r
+\r
+        w8 = _mm_set1_epi32(Pad[8]);\r
+        w9 = _mm_set1_epi32(Pad[9]);\r
+        w10 = _mm_set1_epi32(Pad[10]);\r
+        w11 = _mm_set1_epi32(Pad[11]);\r
+        w12 = _mm_set1_epi32(Pad[12]);\r
+        w13 = _mm_set1_epi32(Pad[13]);\r
+        w14 = _mm_set1_epi32(Pad[14]);\r
+        w15 = _mm_set1_epi32(Pad[15]);\r
+\r
+        a = _mm_set1_epi32(hInit[0]);\r
+        b = _mm_set1_epi32(hInit[1]);\r
+        c = _mm_set1_epi32(hInit[2]);\r
+        d = _mm_set1_epi32(hInit[3]);\r
+        e = _mm_set1_epi32(hInit[4]);\r
+        f = _mm_set1_epi32(hInit[5]);\r
+        g = _mm_set1_epi32(hInit[6]);\r
+        h = _mm_set1_epi32(hInit[7]);\r
+\r
+        SHA256ROUND(a, b, c, d, e, f, g, h, 0, w0);\r
+        SHA256ROUND(h, a, b, c, d, e, f, g, 1, w1);\r
+        SHA256ROUND(g, h, a, b, c, d, e, f, 2, w2);\r
+        SHA256ROUND(f, g, h, a, b, c, d, e, 3, w3);\r
+        SHA256ROUND(e, f, g, h, a, b, c, d, 4, w4);\r
+        SHA256ROUND(d, e, f, g, h, a, b, c, 5, w5);\r
+        SHA256ROUND(c, d, e, f, g, h, a, b, 6, w6);\r
+        SHA256ROUND(b, c, d, e, f, g, h, a, 7, w7);\r
+        SHA256ROUND(a, b, c, d, e, f, g, h, 8, w8);\r
+        SHA256ROUND(h, a, b, c, d, e, f, g, 9, w9);\r
+        SHA256ROUND(g, h, a, b, c, d, e, f, 10, w10);\r
+        SHA256ROUND(f, g, h, a, b, c, d, e, 11, w11);\r
+        SHA256ROUND(e, f, g, h, a, b, c, d, 12, w12);\r
+        SHA256ROUND(d, e, f, g, h, a, b, c, 13, w13);\r
+        SHA256ROUND(c, d, e, f, g, h, a, b, 14, w14);\r
+        SHA256ROUND(b, c, d, e, f, g, h, a, 15, w15);\r
+\r
+        w0 = add4(SIGMA1_256(w14), w9, SIGMA0_256(w1), w0);\r
+        SHA256ROUND(a, b, c, d, e, f, g, h, 16, w0);\r
+        w1 = add4(SIGMA1_256(w15), w10, SIGMA0_256(w2), w1);\r
+        SHA256ROUND(h, a, b, c, d, e, f, g, 17, w1);\r
+        w2 = add4(SIGMA1_256(w0), w11, SIGMA0_256(w3), w2);\r
+        SHA256ROUND(g, h, a, b, c, d, e, f, 18, w2);\r
+        w3 = add4(SIGMA1_256(w1), w12, SIGMA0_256(w4), w3);\r
+        SHA256ROUND(f, g, h, a, b, c, d, e, 19, w3);\r
+        w4 = add4(SIGMA1_256(w2), w13, SIGMA0_256(w5), w4);\r
+        SHA256ROUND(e, f, g, h, a, b, c, d, 20, w4);\r
+        w5 = add4(SIGMA1_256(w3), w14, SIGMA0_256(w6), w5);\r
+        SHA256ROUND(d, e, f, g, h, a, b, c, 21, w5);\r
+        w6 = add4(SIGMA1_256(w4), w15, SIGMA0_256(w7), w6);\r
+        SHA256ROUND(c, d, e, f, g, h, a, b, 22, w6);\r
+        w7 = add4(SIGMA1_256(w5), w0, SIGMA0_256(w8), w7);\r
+        SHA256ROUND(b, c, d, e, f, g, h, a, 23, w7);\r
+        w8 = add4(SIGMA1_256(w6), w1, SIGMA0_256(w9), w8);\r
+        SHA256ROUND(a, b, c, d, e, f, g, h, 24, w8);\r
+        w9 = add4(SIGMA1_256(w7), w2, SIGMA0_256(w10), w9);\r
+        SHA256ROUND(h, a, b, c, d, e, f, g, 25, w9);\r
+        w10 = add4(SIGMA1_256(w8), w3, SIGMA0_256(w11), w10);\r
+        SHA256ROUND(g, h, a, b, c, d, e, f, 26, w10);\r
+        w11 = add4(SIGMA1_256(w9), w4, SIGMA0_256(w12), w11);\r
+        SHA256ROUND(f, g, h, a, b, c, d, e, 27, w11);\r
+        w12 = add4(SIGMA1_256(w10), w5, SIGMA0_256(w13), w12);\r
+        SHA256ROUND(e, f, g, h, a, b, c, d, 28, w12);\r
+        w13 = add4(SIGMA1_256(w11), w6, SIGMA0_256(w14), w13);\r
+        SHA256ROUND(d, e, f, g, h, a, b, c, 29, w13);\r
+        w14 = add4(SIGMA1_256(w12), w7, SIGMA0_256(w15), w14);\r
+        SHA256ROUND(c, d, e, f, g, h, a, b, 30, w14);\r
+        w15 = add4(SIGMA1_256(w13), w8, SIGMA0_256(w0), w15);\r
+        SHA256ROUND(b, c, d, e, f, g, h, a, 31, w15);\r
+\r
+        w0 = add4(SIGMA1_256(w14), w9, SIGMA0_256(w1), w0);\r
+        SHA256ROUND(a, b, c, d, e, f, g, h, 32, w0);\r
+        w1 = add4(SIGMA1_256(w15), w10, SIGMA0_256(w2), w1);\r
+        SHA256ROUND(h, a, b, c, d, e, f, g, 33, w1);\r
+        w2 = add4(SIGMA1_256(w0), w11, SIGMA0_256(w3), w2);\r
+        SHA256ROUND(g, h, a, b, c, d, e, f, 34, w2);\r
+        w3 = add4(SIGMA1_256(w1), w12, SIGMA0_256(w4), w3);\r
+        SHA256ROUND(f, g, h, a, b, c, d, e, 35, w3);\r
+        w4 = add4(SIGMA1_256(w2), w13, SIGMA0_256(w5), w4);\r
+        SHA256ROUND(e, f, g, h, a, b, c, d, 36, w4);\r
+        w5 = add4(SIGMA1_256(w3), w14, SIGMA0_256(w6), w5);\r
+        SHA256ROUND(d, e, f, g, h, a, b, c, 37, w5);\r
+        w6 = add4(SIGMA1_256(w4), w15, SIGMA0_256(w7), w6);\r
+        SHA256ROUND(c, d, e, f, g, h, a, b, 38, w6);\r
+        w7 = add4(SIGMA1_256(w5), w0, SIGMA0_256(w8), w7);\r
+        SHA256ROUND(b, c, d, e, f, g, h, a, 39, w7);\r
+        w8 = add4(SIGMA1_256(w6), w1, SIGMA0_256(w9), w8);\r
+        SHA256ROUND(a, b, c, d, e, f, g, h, 40, w8);\r
+        w9 = add4(SIGMA1_256(w7), w2, SIGMA0_256(w10), w9);\r
+        SHA256ROUND(h, a, b, c, d, e, f, g, 41, w9);\r
+        w10 = add4(SIGMA1_256(w8), w3, SIGMA0_256(w11), w10);\r
+        SHA256ROUND(g, h, a, b, c, d, e, f, 42, w10);\r
+        w11 = add4(SIGMA1_256(w9), w4, SIGMA0_256(w12), w11);\r
+        SHA256ROUND(f, g, h, a, b, c, d, e, 43, w11);\r
+        w12 = add4(SIGMA1_256(w10), w5, SIGMA0_256(w13), w12);\r
+        SHA256ROUND(e, f, g, h, a, b, c, d, 44, w12);\r
+        w13 = add4(SIGMA1_256(w11), w6, SIGMA0_256(w14), w13);\r
+        SHA256ROUND(d, e, f, g, h, a, b, c, 45, w13);\r
+        w14 = add4(SIGMA1_256(w12), w7, SIGMA0_256(w15), w14);\r
+        SHA256ROUND(c, d, e, f, g, h, a, b, 46, w14);\r
+        w15 = add4(SIGMA1_256(w13), w8, SIGMA0_256(w0), w15);\r
+        SHA256ROUND(b, c, d, e, f, g, h, a, 47, w15);\r
+\r
+        w0 = add4(SIGMA1_256(w14), w9, SIGMA0_256(w1), w0);\r
+        SHA256ROUND(a, b, c, d, e, f, g, h, 48, w0);\r
+        w1 = add4(SIGMA1_256(w15), w10, SIGMA0_256(w2), w1);\r
+        SHA256ROUND(h, a, b, c, d, e, f, g, 49, w1);\r
+        w2 = add4(SIGMA1_256(w0), w11, SIGMA0_256(w3), w2);\r
+        SHA256ROUND(g, h, a, b, c, d, e, f, 50, w2);\r
+        w3 = add4(SIGMA1_256(w1), w12, SIGMA0_256(w4), w3);\r
+        SHA256ROUND(f, g, h, a, b, c, d, e, 51, w3);\r
+        w4 = add4(SIGMA1_256(w2), w13, SIGMA0_256(w5), w4);\r
+        SHA256ROUND(e, f, g, h, a, b, c, d, 52, w4);\r
+        w5 = add4(SIGMA1_256(w3), w14, SIGMA0_256(w6), w5);\r
+        SHA256ROUND(d, e, f, g, h, a, b, c, 53, w5);\r
+        w6 = add4(SIGMA1_256(w4), w15, SIGMA0_256(w7), w6);\r
+        SHA256ROUND(c, d, e, f, g, h, a, b, 54, w6);\r
+        w7 = add4(SIGMA1_256(w5), w0, SIGMA0_256(w8), w7);\r
+        SHA256ROUND(b, c, d, e, f, g, h, a, 55, w7);\r
+        w8 = add4(SIGMA1_256(w6), w1, SIGMA0_256(w9), w8);\r
+        SHA256ROUND(a, b, c, d, e, f, g, h, 56, w8);\r
+        w9 = add4(SIGMA1_256(w7), w2, SIGMA0_256(w10), w9);\r
+        SHA256ROUND(h, a, b, c, d, e, f, g, 57, w9);\r
+        w10 = add4(SIGMA1_256(w8), w3, SIGMA0_256(w11), w10);\r
+        SHA256ROUND(g, h, a, b, c, d, e, f, 58, w10);\r
+        w11 = add4(SIGMA1_256(w9), w4, SIGMA0_256(w12), w11);\r
+        SHA256ROUND(f, g, h, a, b, c, d, e, 59, w11);\r
+        w12 = add4(SIGMA1_256(w10), w5, SIGMA0_256(w13), w12);\r
+        SHA256ROUND(e, f, g, h, a, b, c, d, 60, w12);\r
+        w13 = add4(SIGMA1_256(w11), w6, SIGMA0_256(w14), w13);\r
+        SHA256ROUND(d, e, f, g, h, a, b, c, 61, w13);\r
+        w14 = add4(SIGMA1_256(w12), w7, SIGMA0_256(w15), w14);\r
+        SHA256ROUND(c, d, e, f, g, h, a, b, 62, w14);\r
+        w15 = add4(SIGMA1_256(w13), w8, SIGMA0_256(w0), w15);\r
+        SHA256ROUND(b, c, d, e, f, g, h, a, 63, w15);\r
+\r
+        /* store resulsts directly in thash */\r
+#define store_2(x,i)  \\r
+        w0 = _mm_set1_epi32(hInit[i]); \\r
+        *(__m128i *)&(thash)[i][0+k] = _mm_add_epi32(w0, x);\r
+\r
+        store_2(a, 0);\r
+        store_2(b, 1);\r
+        store_2(c, 2);\r
+        store_2(d, 3);\r
+        store_2(e, 4);\r
+        store_2(f, 5);\r
+        store_2(g, 6);\r
+        store_2(h, 7);\r
+        *(__m128i *)&(thash)[8][0+k] = nonce;\r
+    }\r
+\r
+}\r
index 7cb6600..8f06e30 100644 (file)
--- a/util.cpp
+++ b/util.cpp
@@ -19,6 +19,14 @@ bool fCommandLine = false;
 \r
 \r
 \r
+// Workaround for "multiple definition of `_tls_used'"\r
+// http://svn.boost.org/trac/boost/ticket/4258\r
+extern "C" void tss_cleanup_implemented() { }\r
+\r
+\r
+\r
+\r
+\r
 // Init openssl library multithreading support\r
 static boost::interprocess::interprocess_mutex** ppmutexOpenSSL;\r
 void locking_callback(int mode, int i, const char* file, int line)\r