fixed adding file problem
[c11concurrency-benchmarks.git] / gdax-orderbook-hpp / demo / dependencies / websocketpp-0.7.0 / websocketpp / sha1 / sha1.hpp
diff --git a/gdax-orderbook-hpp/demo/dependencies/websocketpp-0.7.0/websocketpp/sha1/sha1.hpp b/gdax-orderbook-hpp/demo/dependencies/websocketpp-0.7.0/websocketpp/sha1/sha1.hpp
new file mode 100644 (file)
index 0000000..43a8433
--- /dev/null
@@ -0,0 +1,189 @@
+/*\r
+*****\r
+sha1.hpp is a repackaging of the sha1.cpp and sha1.h files from the smallsha1\r
+library (http://code.google.com/p/smallsha1/) into a single header suitable for\r
+use as a header only library. This conversion was done by Peter Thorson\r
+(webmaster@zaphoyd.com) in 2013. All modifications to the code are redistributed\r
+under the same license as the original, which is listed below.\r
+*****\r
+\r
+ Copyright (c) 2011, Micael Hildenborg\r
+ All rights reserved.\r
+\r
+ Redistribution and use in source and binary forms, with or without\r
+ modification, are permitted provided that the following conditions are met:\r
+    * Redistributions of source code must retain the above copyright\r
+      notice, this list of conditions and the following disclaimer.\r
+    * Redistributions in binary form must reproduce the above copyright\r
+      notice, this list of conditions and the following disclaimer in the\r
+      documentation and/or other materials provided with the distribution.\r
+    * Neither the name of Micael Hildenborg nor the\r
+      names of its contributors may be used to endorse or promote products\r
+      derived from this software without specific prior written permission.\r
+\r
+ THIS SOFTWARE IS PROVIDED BY Micael Hildenborg ''AS IS'' AND ANY\r
+ EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\r
+ DISCLAIMED. IN NO EVENT SHALL Micael Hildenborg BE LIABLE FOR ANY\r
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND\r
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+\r
+#ifndef SHA1_DEFINED\r
+#define SHA1_DEFINED\r
+\r
+namespace websocketpp {\r
+namespace sha1 {\r
+\r
+namespace { // local\r
+\r
+// Rotate an integer value to left.\r
+inline unsigned int rol(unsigned int value, unsigned int steps) {\r
+    return ((value << steps) | (value >> (32 - steps)));\r
+}\r
+\r
+// Sets the first 16 integers in the buffert to zero.\r
+// Used for clearing the W buffert.\r
+inline void clearWBuffert(unsigned int * buffert)\r
+{\r
+    for (int pos = 16; --pos >= 0;)\r
+    {\r
+        buffert[pos] = 0;\r
+    }\r
+}\r
+\r
+inline void innerHash(unsigned int * result, unsigned int * w)\r
+{\r
+    unsigned int a = result[0];\r
+    unsigned int b = result[1];\r
+    unsigned int c = result[2];\r
+    unsigned int d = result[3];\r
+    unsigned int e = result[4];\r
+\r
+    int round = 0;\r
+\r
+    #define sha1macro(func,val) \\r
+    { \\r
+        const unsigned int t = rol(a, 5) + (func) + e + val + w[round]; \\r
+        e = d; \\r
+        d = c; \\r
+        c = rol(b, 30); \\r
+        b = a; \\r
+        a = t; \\r
+    }\r
+\r
+    while (round < 16)\r
+    {\r
+        sha1macro((b & c) | (~b & d), 0x5a827999)\r
+        ++round;\r
+    }\r
+    while (round < 20)\r
+    {\r
+        w[round] = rol((w[round - 3] ^ w[round - 8] ^ w[round - 14] ^ w[round - 16]), 1);\r
+        sha1macro((b & c) | (~b & d), 0x5a827999)\r
+        ++round;\r
+    }\r
+    while (round < 40)\r
+    {\r
+        w[round] = rol((w[round - 3] ^ w[round - 8] ^ w[round - 14] ^ w[round - 16]), 1);\r
+        sha1macro(b ^ c ^ d, 0x6ed9eba1)\r
+        ++round;\r
+    }\r
+    while (round < 60)\r
+    {\r
+        w[round] = rol((w[round - 3] ^ w[round - 8] ^ w[round - 14] ^ w[round - 16]), 1);\r
+        sha1macro((b & c) | (b & d) | (c & d), 0x8f1bbcdc)\r
+        ++round;\r
+    }\r
+    while (round < 80)\r
+    {\r
+        w[round] = rol((w[round - 3] ^ w[round - 8] ^ w[round - 14] ^ w[round - 16]), 1);\r
+        sha1macro(b ^ c ^ d, 0xca62c1d6)\r
+        ++round;\r
+    }\r
+\r
+    #undef sha1macro\r
+\r
+    result[0] += a;\r
+    result[1] += b;\r
+    result[2] += c;\r
+    result[3] += d;\r
+    result[4] += e;\r
+}\r
+\r
+} // namespace\r
+\r
+/// Calculate a SHA1 hash\r
+/**\r
+ * @param src points to any kind of data to be hashed.\r
+ * @param bytelength the number of bytes to hash from the src pointer.\r
+ * @param hash should point to a buffer of at least 20 bytes of size for storing\r
+ * the sha1 result in.\r
+ */\r
+inline void calc(void const * src, size_t bytelength, unsigned char * hash) {\r
+    // Init the result array.\r
+    unsigned int result[5] = { 0x67452301, 0xefcdab89, 0x98badcfe,\r
+                               0x10325476, 0xc3d2e1f0 };\r
+\r
+    // Cast the void src pointer to be the byte array we can work with.\r
+    unsigned char const * sarray = (unsigned char const *) src;\r
+\r
+    // The reusable round buffer\r
+    unsigned int w[80];\r
+\r
+    // Loop through all complete 64byte blocks.\r
+\r
+    size_t endCurrentBlock;\r
+    size_t currentBlock = 0;\r
+\r
+    if (bytelength >= 64) {\r
+        size_t const endOfFullBlocks = bytelength - 64;\r
+\r
+        while (currentBlock <= endOfFullBlocks) {\r
+            endCurrentBlock = currentBlock + 64;\r
+\r
+            // Init the round buffer with the 64 byte block data.\r
+            for (int roundPos = 0; currentBlock < endCurrentBlock; currentBlock += 4)\r
+            {\r
+                // This line will swap endian on big endian and keep endian on\r
+                // little endian.\r
+                w[roundPos++] = (unsigned int) sarray[currentBlock + 3]\r
+                        | (((unsigned int) sarray[currentBlock + 2]) << 8)\r
+                        | (((unsigned int) sarray[currentBlock + 1]) << 16)\r
+                        | (((unsigned int) sarray[currentBlock]) << 24);\r
+            }\r
+            innerHash(result, w);\r
+        }\r
+    }\r
+\r
+    // Handle the last and not full 64 byte block if existing.\r
+    endCurrentBlock = bytelength - currentBlock;\r
+    clearWBuffert(w);\r
+    size_t lastBlockBytes = 0;\r
+    for (;lastBlockBytes < endCurrentBlock; ++lastBlockBytes) {\r
+        w[lastBlockBytes >> 2] |= (unsigned int) sarray[lastBlockBytes + currentBlock] << ((3 - (lastBlockBytes & 3)) << 3);\r
+    }\r
+\r
+    w[lastBlockBytes >> 2] |= 0x80 << ((3 - (lastBlockBytes & 3)) << 3);\r
+    if (endCurrentBlock >= 56) {\r
+        innerHash(result, w);\r
+        clearWBuffert(w);\r
+    }\r
+    w[15] = bytelength << 3;\r
+    innerHash(result, w);\r
+\r
+    // Store hash in result pointer, and make sure we get in in the correct\r
+    // order on both endian models.\r
+    for (int hashByte = 20; --hashByte >= 0;) {\r
+        hash[hashByte] = (result[hashByte >> 2] >> (((3 - hashByte) & 0x3) << 3)) & 0xff;\r
+    }\r
+}\r
+\r
+} // namespace sha1\r
+} // namespace websocketpp\r
+\r
+#endif // SHA1_DEFINED\r