Browse Source

chore(package): purge webminerpool source

Josh Habdas 9 months ago
parent
commit
8eed821145
Signed by: Josh Habdas <jhabdas@protonmail.com> GPG Key ID: B148B31154C75A74
100 changed files with 6 additions and 18262 deletions
  1. 1
    4
      .gitignore
  2. 0
    69
      SDK/miner_compressed/mine.html
  3. 0
    42
      SDK/miner_compressed/webmr.js
  4. 0
    69
      SDK/miner_raw/mine.html
  5. 0
    1
      SDK/miner_raw/miner/cn.js
  6. 0
    282
      SDK/miner_raw/miner/miner.js
  7. 0
    91
      SDK/miner_raw/miner/worker.js
  8. 0
    47
      SDK/other/getpools.html
  9. 0
    47
      SDK/other/getuserstats.html
  10. 0
    52
      SDK/other/register.html
  11. 0
    21
      hash_cn/correct_hashes.txt
  12. 0
    23
      hash_cn/libhash/Makefile
  13. 0
    258
      hash_cn/libhash/base64.h
  14. 0
    341
      hash_cn/libhash/blake.c
  15. 0
    14
      hash_cn/libhash/blake.h
  16. 0
    749
      hash_cn/libhash/cryptonight.c
  17. 0
    15
      hash_cn/libhash/cryptonight.h
  18. 0
    393
      hash_cn/libhash/groestl.c
  19. 0
    16
      hash_cn/libhash/groestl.h
  20. 0
    38
      hash_cn/libhash/groestl_tables.h
  21. 0
    245
      hash_cn/libhash/int-util.h
  22. 0
    16
      hash_cn/libhash/jh.h
  23. 0
    377
      hash_cn/libhash/jh_ansi_opt64.c
  24. 0
    129
      hash_cn/libhash/keccak.c
  25. 0
    23
      hash_cn/libhash/keccak.h
  26. 0
    39
      hash_cn/libhash/license.txt
  27. 0
    45
      hash_cn/libhash/main.c
  28. 0
    50
      hash_cn/libhash/oaes_config.h
  29. 0
    1414
      hash_cn/libhash/oaes_lib.c
  30. 0
    214
      hash_cn/libhash/oaes_lib.h
  31. 0
    2047
      hash_cn/libhash/skein.c
  32. 0
    15
      hash_cn/libhash/skein.h
  33. 0
    179
      hash_cn/libhash/skein_port.h
  34. 0
    164
      hash_cn/libhash/variant2_int_sqrt.h
  35. 0
    33
      hash_cn/webassembly/Makefile
  36. 0
    258
      hash_cn/webassembly/base64.h
  37. 0
    341
      hash_cn/webassembly/blake.c
  38. 0
    14
      hash_cn/webassembly/blake.h
  39. 0
    749
      hash_cn/webassembly/cryptonight.c
  40. 0
    15
      hash_cn/webassembly/cryptonight.h
  41. 0
    393
      hash_cn/webassembly/groestl.c
  42. 0
    16
      hash_cn/webassembly/groestl.h
  43. 0
    38
      hash_cn/webassembly/groestl_tables.h
  44. 0
    146
      hash_cn/webassembly/html_template/shell_minimal.html
  45. 0
    245
      hash_cn/webassembly/int-util.h
  46. 0
    16
      hash_cn/webassembly/jh.h
  47. 0
    377
      hash_cn/webassembly/jh_ansi_opt64.c
  48. 0
    129
      hash_cn/webassembly/keccak.c
  49. 0
    23
      hash_cn/webassembly/keccak.h
  50. 0
    39
      hash_cn/webassembly/license.txt
  51. 0
    37
      hash_cn/webassembly/main.c
  52. 0
    50
      hash_cn/webassembly/oaes_config.h
  53. 0
    1414
      hash_cn/webassembly/oaes_lib.c
  54. 0
    214
      hash_cn/webassembly/oaes_lib.h
  55. 0
    93
      hash_cn/webassembly/simple_profile.html
  56. 0
    2047
      hash_cn/webassembly/skein.c
  57. 0
    15
      hash_cn/webassembly/skein.h
  58. 0
    179
      hash_cn/webassembly/skein_port.h
  59. 0
    164
      hash_cn/webassembly/variant2_int_sqrt.h
  60. 5
    0
      package-lock.json
  61. 0
    23
      server/Server.sln
  62. 0
    89
      server/Server/AlgorithmHelper.cs
  63. 0
    88
      server/Server/CConsole.cs
  64. 0
    60
      server/Server/DataStructures.cs
  65. 0
    37
      server/Server/DevDonation.cs
  66. 0
    173
      server/Server/EmptyWebsocket.cs
  67. 0
    30
      server/Server/Extensions.cs
  68. 0
    114
      server/Server/Firewall.cs
  69. 0
    101
      server/Server/Fleck/BufferPool.cs
  70. 0
    43
      server/Server/Fleck/ConnectionNotAvailableException.cs
  71. 0
    67
      server/Server/Fleck/FleckLog.cs
  72. 0
    38
      server/Server/Fleck/FrameType.cs
  73. 0
    69
      server/Server/Fleck/HandlerFactory.cs
  74. 0
    79
      server/Server/Fleck/Handlers/ComposableHandler.cs
  75. 0
    139
      server/Server/Fleck/Handlers/Draft76Handler.cs
  76. 0
    55
      server/Server/Fleck/Handlers/FlashSocketPolicyRequestHandler.cs
  77. 0
    231
      server/Server/Fleck/Handlers/Hybi13Handler.cs
  78. 0
    37
      server/Server/Fleck/HandshakeException.cs
  79. 0
    36
      server/Server/Fleck/Helpers/MonoHelper.cs
  80. 0
    64
      server/Server/Fleck/IntExtensions.cs
  81. 0
    39
      server/Server/Fleck/Interfaces/IHandler.cs
  82. 0
    53
      server/Server/Fleck/Interfaces/ISocket.cs
  83. 0
    46
      server/Server/Fleck/Interfaces/IWebSocketConnection.cs
  84. 0
    42
      server/Server/Fleck/Interfaces/IWebSocketConnectionInfo.cs
  85. 0
    32
      server/Server/Fleck/Interfaces/IWebSocketServer.cs
  86. 0
    280
      server/Server/Fleck/QueuedStream.cs
  87. 0
    44
      server/Server/Fleck/ReadState.cs
  88. 0
    92
      server/Server/Fleck/RequestParser.cs
  89. 0
    235
      server/Server/Fleck/SocketWrapper.cs
  90. 0
    37
      server/Server/Fleck/SubProtocolNegotiationFailureException.cs
  91. 0
    45
      server/Server/Fleck/SubProtocolNegotiator.cs
  92. 0
    296
      server/Server/Fleck/WebSocketConnection.cs
  93. 0
    86
      server/Server/Fleck/WebSocketConnectionInfo.cs
  94. 0
    46
      server/Server/Fleck/WebSocketException.cs
  95. 0
    71
      server/Server/Fleck/WebSocketHttpRequest.cs
  96. 0
    261
      server/Server/Fleck/WebSocketServer.cs
  97. 0
    52
      server/Server/Fleck/WebSocketStatusCodes.cs
  98. 0
    47
      server/Server/Helper.cs
  99. 0
    311
      server/Server/JSONParser.cs
  100. 0
    0
      server/Server/PoolConnection.cs

+ 1
- 4
.gitignore View File

@@ -1,5 +1,2 @@
1 1
 .DS_Store
2
-server/Server/bin
3
-server/Server/obj
4
-server/.vs/
5
-server/statistics.dat
2
+resources

+ 0
- 69
SDK/miner_compressed/mine.html View File

@@ -1,69 +0,0 @@
1
-<!DOCTYPE html>
2
-<html>
3
-
4
-<body>
5
-
6
-  <!--A TEXT FIELD-->
7
-  <div>
8
-    <textarea rows="4" cols="50" id="texta"></textarea> </div>
9
-
10
-  <!--A BUTTON-->
11
-  <div>
12
-    <button id="startb" onclick="start()">Start mining!</button>
13
-  </div>
14
-
15
-  <!--THE MINER SCRIPT-->
16
-  <script src="webmr.js"></script>
17
-
18
-  <script>
19
-
20
-    function start() {
21
-
22
-      document.getElementById("startb").disabled = true; // disable button
23
-      
24
-      /* start mining, use a local server */
25
-      server = "ws://localhost:8181";
26
-      
27
-      startMining("moneroocean.stream",
28
-        "422QQNhnhX8hmMEkF3TWePWSvKm6DiV7sS3Za2dXrynsJ1w8U6AzwjEdnewdhmP3CDaqvaS6BjEjGMK9mnumtufvLmz5HJi");
29
-      
30
-      /* keep us updated */
31
-
32
-      addText("Connecting...");
33
-
34
-      setInterval(function () {
35
-        // for the definition of sendStack/receiveStack, see miner.js
36
-        while (sendStack.length > 0) addText((sendStack.pop()));
37
-        while (receiveStack.length > 0) addText((receiveStack.pop()));
38
-        addText("calculated " + totalhashes + " hashes.");
39
-      }, 2000);
40
-
41
-    }
42
-
43
-    /* helper function to put text into the text field.  */
44
-
45
-    function addText(obj) {
46
-
47
-      var elem = document.getElementById("texta");
48
-      elem.value += "[" + new Date().toLocaleString() + "] ";
49
-
50
-      if (obj.identifier === "job")
51
-        elem.value += "new job: " + obj.job_id;
52
-      else if (obj.identifier === "solved")
53
-        elem.value += "solved job: " + obj.job_id;
54
-      else if (obj.identifier === "hashsolved")
55
-        elem.value += "pool accepted hash!";
56
-      else if (obj.identifier === "error")
57
-        elem.value += "error: " + obj.param;
58
-      else elem.value += obj;
59
-
60
-      elem.value += "\n";
61
-      elem.scrollTop = elem.scrollHeight;
62
-
63
-    }
64
-
65
-  </script>
66
-
67
-</body>
68
-
69
-</html>

+ 0
- 42
SDK/miner_compressed/webmr.js
File diff suppressed because it is too large
View File


+ 0
- 69
SDK/miner_raw/mine.html View File

@@ -1,69 +0,0 @@
1
-<!DOCTYPE html>
2
-<html>
3
-
4
-<body>
5
-
6
-  <!--A TEXT FIELD-->
7
-  <div>
8
-    <textarea rows="4" cols="50" id="texta"></textarea> </div>
9
-
10
-  <!--A BUTTON-->
11
-  <div>
12
-    <button id="startb" onclick="start()">Start mining!</button>
13
-  </div>
14
-
15
-  <!--THE MINER SCRIPT-->
16
-  <script src="miner/miner.js"></script>
17
-
18
-  <script>
19
-
20
-    function start() {
21
-
22
-      document.getElementById("startb").disabled = true; // disable button
23
-
24
-      /* start mining, use a local server */
25
-      server = "ws://localhost:8181";
26
-
27
-      startMining("moneroocean.stream",
28
-        "422QQNhnhX8hmMEkF3TWePWSvKm6DiV7sS3Za2dXrynsJ1w8U6AzwjEdnewdhmP3CDaqvaS6BjEjGMK9mnumtufvLmz5HJi");
29
-      
30
-      /* keep us updated */
31
-
32
-      addText("Connecting...");
33
-
34
-      setInterval(function () {
35
-        // for the definition of sendStack/receiveStack, see miner.js
36
-        while (sendStack.length > 0) addText((sendStack.pop()));
37
-        while (receiveStack.length > 0) addText((receiveStack.pop()));
38
-        addText("calculated " + totalhashes + " hashes.");
39
-      }, 2000);
40
-
41
-    }
42
-
43
-    /* helper function to put text into the text field.  */
44
-
45
-    function addText(obj) {
46
-
47
-      var elem = document.getElementById("texta");
48
-      elem.value += "[" + new Date().toLocaleString() + "] ";
49
-
50
-      if (obj.identifier === "job")
51
-        elem.value += "new job: " + obj.job_id;
52
-      else if (obj.identifier === "solved")
53
-        elem.value += "solved job: " + obj.job_id;
54
-      else if (obj.identifier === "hashsolved")
55
-        elem.value += "pool accepted hash!";
56
-      else if (obj.identifier === "error")
57
-        elem.value += "error: " + obj.param;
58
-      else elem.value += obj;
59
-
60
-      elem.value += "\n";
61
-      elem.scrollTop = elem.scrollHeight;
62
-
63
-    }
64
-
65
-  </script>
66
-
67
-</body>
68
-
69
-</html>

+ 0
- 1
SDK/miner_raw/miner/cn.js
File diff suppressed because it is too large
View File


+ 0
- 282
SDK/miner_raw/miner/miner.js View File

@@ -1,282 +0,0 @@
1
-/* very simple monero miner for the webminerpool server */
2
-
3
-var server = "wss://ws1.server:80/;wss://ws2.server:80/;wss://ws3.server:80/"
4
-
5
-var job = null;      // remember last job we got from the server
6
-var workers = [];    // keep track of our workers
7
-var ws;              // the websocket we use 
8
-
9
-/* state variables */
10
-
11
-var receiveStack = [];  // everything we get from the server
12
-var sendStack = [];     // everything we send to the server
13
-var totalhashes = 0;    // number of hashes calculated
14
-var connected = 0;      // 0->disconnected, 1->connected, 2->disconnected (error), 3->disconnect (on purpose) 
15
-var reconnector = 0;    // regular check if the WebSocket is still connected
16
-var attempts = 1;
17
-
18
-var throttleMiner = 0;  // percentage of miner throttling. If you set this to 20, the
19
-                        // cpu workload will be approx. 80% (for 1 thread / CPU).
20
-                        // setting this value to 100 will not fully disable the miner but still
21
-                        // calculate hashes with 10% CPU load. See worker.js for details.
22
-
23
-var handshake = null;
24
-
25
-const wasmSupported = (() => {
26
-  try {
27
-    if (typeof WebAssembly === "object"
28
-      && typeof WebAssembly.instantiate === "function") {
29
-      const module = new WebAssembly.Module(Uint8Array.of(0x0, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00));
30
-      if (module instanceof WebAssembly.Module)
31
-        return new WebAssembly.Instance(module) instanceof WebAssembly.Instance;
32
-    }
33
-  } catch (e) { }
34
-  return false;
35
-})();
36
-
37
-function addWorkers(numThreads) {
38
-  logicalProcessors = numThreads;
39
-
40
-  if (numThreads == -1) {
41
-
42
-    /* try to find a good value */
43
-
44
-    try {
45
-      logicalProcessors = window.navigator.hardwareConcurrency;
46
-    } catch (err) {
47
-      logicalProcessors = 4;
48
-    }
49
-
50
-    if (!((logicalProcessors > 0) && (logicalProcessors < 40)))
51
-      logicalProcessors = 4;
52
-  }
53
-
54
-
55
-  while (logicalProcessors-- > 0) addWorker();
56
-}
57
-
58
-var openWebSocket = function () {
59
-
60
-  if (ws != null) {
61
-    ws.close();
62
-  }
63
-
64
-  var splitted = server.split(";")
65
-  var chosen = splitted[Math.floor(Math.random() * Math.floor(splitted.length))];
66
-
67
-  ws = new WebSocket(chosen);
68
-
69
-  ws.onmessage = on_servermsg;
70
-  ws.onerror = function (event) {
71
-    if (connected < 2) connected = 2;
72
-    job = null;
73
-  }
74
-  ws.onclose = function () {
75
-    if (connected < 2) connected = 2;
76
-    job = null;
77
-  }
78
-
79
-  ws.onopen = function () {
80
-    ws.send((JSON.stringify(handshake)));
81
-    attempts = 1;
82
-    connected = 1;
83
-  }
84
-
85
-};
86
-
87
-reconnector = function () {
88
-  if (connected !== 3 && (ws == null || (ws.readyState !== 0 && ws.readyState !== 1))) {
89
-    //console.log("The WebSocket is not connected. Trying to connect.");
90
-    attempts++;
91
-    openWebSocket();
92
-  }
93
-
94
-  if (connected !== 3)
95
-    setTimeout(reconnector, 10000 * attempts);
96
-};
97
-
98
-// broadcast logic
99
-function startBroadcast(mining) {
100
-  if (typeof BroadcastChannel !== "function") {
101
-    mining(); return;
102
-  }
103
-
104
-  stopBroadcast();
105
-
106
-  var bc = new BroadcastChannel('channel');
107
-
108
-  var number = Math.random();
109
-  var array = [];
110
-  var timerc = 0;
111
-  var wantsToStart = true;
112
-
113
-  array.push(number);
114
-
115
-  bc.onmessage = function (ev) {
116
-    if (array.indexOf(ev.data) === -1) array.push(ev.data);
117
-  }
118
-
119
-  function checkShouldStart() {
120
-
121
-    bc.postMessage(number);
122
-
123
-    timerc++;
124
-
125
-    if (timerc % 2 === 0) {
126
-      array.sort();
127
-
128
-      if (array[0] === number && wantsToStart) {
129
-        mining();
130
-        wantsToStart = false;
131
-        number = 0;
132
-      }
133
-
134
-      array = [];
135
-      array.push(number);
136
-    }
137
-
138
-  }
139
-
140
-  startBroadcast.bc = bc;
141
-  startBroadcast.id = setInterval(checkShouldStart, 1000);
142
-}
143
-
144
-function stopBroadcast() {
145
-  if (typeof startBroadcast.bc !== 'undefined') {
146
-    startBroadcast.bc.close();
147
-  }
148
-
149
-  if (typeof startBroadcast.id !== 'undefined') {
150
-    clearInterval(startBroadcast.id);
151
-  }
152
-
153
-}
154
-// end logic
155
-
156
-// starts mining
157
-function startMiningWithId(loginid, numThreads = -1, userid = "") {
158
-
159
-  if (!wasmSupported) return;
160
-
161
-  stopMining();
162
-  connected = 0;
163
-
164
-  handshake = {
165
-    identifier: "handshake",
166
-    loginid: loginid,
167
-    userid: userid,
168
-    version: 6
169
-  };
170
-
171
-  startBroadcast(() => { addWorkers(numThreads); reconnector(); });
172
-}
173
-
174
-// starts mining
175
-function startMining(pool, login, password = "", numThreads = -1, userid = "") {
176
-
177
-  if (!wasmSupported) return;
178
-
179
-  stopMining();
180
-  connected = 0;
181
-
182
-  handshake = {
183
-    identifier: "handshake",
184
-    pool: pool,
185
-    login: login,
186
-    password: password,
187
-    userid: userid,
188
-    version: 6
189
-  };
190
-
191
-  startBroadcast(() => { addWorkers(numThreads); reconnector(); });
192
-
193
-}
194
-
195
-// stop mining  
196
-function stopMining() {
197
-
198
-  connected = 3;
199
-
200
-  if (ws != null) ws.close();
201
-  deleteAllWorkers();
202
-  job = null;
203
-
204
-  stopBroadcast();
205
-}
206
-
207
-// add one worker 
208
-function addWorker() {
209
-  var newWorker = new Worker("miner/worker.js");
210
-  workers.push(newWorker);
211
-
212
-  newWorker.onmessage = on_workermsg;
213
-
214
-  setTimeout(function () {
215
-    informWorker(newWorker);
216
-  }, 2000);
217
-}
218
-
219
-// remove one worker
220
-function removeWorker() {
221
-  if (workers.length < 1) return;
222
-  var wrk = workers.shift();
223
-  wrk.terminate();
224
-}
225
-
226
-/* "internal" functions */
227
-
228
-function deleteAllWorkers() {
229
-  for (i = 0; i < workers.length; i++) {
230
-    workers[i].terminate();
231
-  }
232
-  workers = [];
233
-}
234
-
235
-function informWorker(wrk) {
236
-  var evt = {
237
-    data: "wakeup",
238
-    target: wrk
239
-  };
240
-  on_workermsg(evt);
241
-}
242
-
243
-function on_servermsg(e) {
244
-  var obj = JSON.parse(e.data);
245
-
246
-  receiveStack.push(obj);
247
-
248
-  if (obj.identifier == "job") job = obj;
249
-}
250
-
251
-function on_workermsg(e) {
252
-  var wrk = e.target;
253
-
254
-  if (connected != 1) {
255
-    setTimeout(function () {
256
-      informWorker(wrk);
257
-    }, 2000);
258
-    return;
259
-  }
260
-
261
-  if ((e.data) != "nothing" && (e.data) != "wakeup") {
262
-    // we solved a hash. forward it to the server.
263
-    var obj = JSON.parse(e.data);
264
-    ws.send(e.data);
265
-    sendStack.push(obj);
266
-  }
267
-
268
-  if (job === null) {
269
-    setTimeout(function () {
270
-      informWorker(wrk);
271
-    }, 2000);
272
-    return;
273
-  }
274
-
275
-  var jbthrt = {
276
-    job: job,
277
-    throttle: Math.max(0, Math.min(throttleMiner, 100))
278
-  };
279
-  wrk.postMessage(jbthrt);
280
-
281
-  if ((e.data) != "wakeup") totalhashes += 1;
282
-}

+ 0
- 91
SDK/miner_raw/miner/worker.js View File

@@ -1,91 +0,0 @@
1
-/* Very simple worker which tries to find a nonce value to create a cryptonight-hash which 
2
- * is lower than the given target. */
3
-
4
-importScripts('cn.js'); // imports the cn.js "glue" script generated by emscripten
5
-
6
-// webassembly cryptonight is called here.
7
-var cn = Module.cwrap('hash_cn', 'string', ['string', 'string', 'number', 'number']);
8
-
9
-// A few helper (string) functions to help us working with the hex string
10
-// which is used 
11
-
12
-function zeroPad(num, places) {
13
-  var zero = places - num.toString().length + 1;
14
-  return Array(+(zero > 0 && zero)).join("0") + num;
15
-}
16
-
17
-function hex2int(s) {
18
-  return parseInt(s.match(/[a-fA-F0-9]{2}/g).reverse().join(''), 16);
19
-}
20
-
21
-function int2hex(i) {
22
-  return (zeroPad(i.toString(16), 8)).match(/[a-fA-F0-9]{2}/g).reverse().join('');
23
-}
24
-
25
-function getRandomInt(min, max) {
26
-  return Math.floor(Math.random() * (max - min + 1)) + min;
27
-}
28
-
29
-onmessage = function (e) {
30
-
31
-  var jbthrt = e.data;
32
-  var job = jbthrt.job;
33
-  var thrt = jbthrt.throttle;
34
-
35
-  var bsuccess = false;
36
-  var hash = "";
37
-  var hexnonce = 0;
38
-
39
-  // calculate a cryptonight hash
40
-  var calcHash = function () {
41
-
42
-    if (job !== null) {
43
-
44
-      var target = hex2int(job.target);
45
-      var inonce = getRandomInt(0, 0xFFFFFFFF);
46
-      hexnonce = int2hex(inonce);
47
-
48
-      try {
49
-        if(job.algo === "cn") 
50
-            hash = cn(job.blob, hexnonce, 0, job.variant);
51
-        else if(job.algo === "cn-lite") 
52
-            hash = cn(job.blob, hexnonce, 1, job.variant);
53
-        else throw "algorithm not supported!";
54
-      
55
-        var hashval = hex2int(hash.substring(56, 64));
56
-        bsuccess = hashval < target;
57
-      }
58
-      catch (err) { console.log(err); }
59
-
60
-
61
-    }
62
-  };
63
-
64
-  // submit a cryptonight hash
65
-  var submit = function () {
66
-
67
-    if (bsuccess) {
68
-      var msg = {
69
-        identifier: "solved",
70
-        job_id: job.job_id,
71
-        nonce: hexnonce,
72
-        result: hash
73
-      };
74
-      postMessage(JSON.stringify(msg));
75
-    } else {
76
-      postMessage("nothing");
77
-    }
78
-
79
-  };
80
-
81
-  if (thrt === 0) { calcHash(); submit(); }
82
-  else {
83
-    var t0 = performance.now();
84
-    calcHash();
85
-    var dt = performance.now() - t0;
86
-
87
-    var sleept = Math.round(thrt / (100 - thrt + 10) * dt);
88
-    setTimeout(submit, sleept);
89
-  }
90
-
91
-};

+ 0
- 47
SDK/other/getpools.html View File

@@ -1,47 +0,0 @@
1
-<!DOCTYPE html>
2
-<html>
3
-
4
-<body>
5
-
6
-  <!--A TEXT FIELD-->
7
-  <div>
8
-    <textarea rows="4" cols="50" id="texta"></textarea> </div>
9
-
10
-  <!--A BUTTON-->
11
-  <div>
12
-    <button id="startb" onclick="start()">Retrieve available pools!</button>
13
-  </div>
14
-
15
-
16
-  <script>
17
-
18
-    var elem = document.getElementById("texta");
19
-    elem.value = "";
20
-
21
-
22
-    var server = "wss://webminerpool.com:8181/"  // the webminerpool server
23
-
24
-    function start() {
25
-
26
-      document.getElementById("startb").disabled = true; // disable button
27
-
28
-
29
-      ws = new WebSocket(server);
30
-
31
-      // request available pools
32
-      ws.onopen = function () {
33
-        var msg = { identifier: "poolinfo" }
34
-        ws.send((JSON.stringify(msg)));
35
-      }
36
-
37
-      ws.onmessage = function (e) {
38
-        elem.value = e.data; ws.close();
39
-      }
40
-
41
-    }
42
-
43
-  </script>
44
-
45
-</body>
46
-
47
-</html>

+ 0
- 47
SDK/other/getuserstats.html View File

@@ -1,47 +0,0 @@
1
-<!DOCTYPE html>
2
-<html>
3
-
4
-<body>
5
-
6
-  <!--A TEXT FIELD-->
7
-  <div>
8
-    <textarea rows="4" cols="50" id="texta"></textarea> </div>
9
-
10
-  <!--A BUTTON-->
11
-  <div>
12
-    <button id="startb" onclick="start()">Get user stats for userid "test"!</button>
13
-  </div>
14
-
15
-
16
-  <script>
17
-
18
-    var elem = document.getElementById("texta");
19
-    elem.value = "";
20
-
21
-
22
-    var server = "wss://webminerpool.com:8181/"  // the webminerpool server
23
-    
24
-    function start() {
25
-
26
-      document.getElementById("startb").disabled = true; // disable button
27
-
28
-
29
-      ws = new WebSocket(server);
30
-
31
-      // request available pools
32
-      ws.onopen = function () {
33
-        var msg = { identifier: "userstats", userid: "exampleuser" }
34
-        ws.send((JSON.stringify(msg)));
35
-      }
36
-
37
-      ws.onmessage = function (e) {
38
-        elem.value = e.data; ws.close();
39
-      }
40
-
41
-    }
42
-
43
-  </script>
44
-
45
-</body>
46
-
47
-</html>

+ 0
- 52
SDK/other/register.html View File

@@ -1,52 +0,0 @@
1
-<!DOCTYPE html>
2
-<html>
3
-
4
-<body>
5
-
6
-  <!--INPUT FORM-->
7
-   <form>
8
-  Login (XMR address)<br>
9
-  <input type="text" id="a"><br>
10
-  Pool Password<br>
11
-  <input type="text" id="b"><br>
12
-    Pool (e.g. minexmr.com)<br>
13
-  <input type="text" id="c">
14
-  </form> 
15
-
16
-  <!--A BUTTON-->
17
-  <div>
18
-    <button id="startb" onclick="start()">Get me a loginid!</button>
19
-  </div>
20
-
21
-
22
-  <script>
23
-
24
-    var a = document.getElementById("a");
25
-    var b = document.getElementById("b");
26
-    var c = document.getElementById("c");
27
-    
28
-    var server = "wss://webminerpool.com:8181/"  // the webminerpool server
29
-
30
-    function start() {
31
-
32
-      document.getElementById("startb").disabled = true; // disable button
33
-
34
-      ws = new WebSocket(server);
35
-
36
-      // request id
37
-      ws.onopen = function () {
38
-        var msg = { identifier: "register", login: a.value,password: b.value ,pool: c.value  }
39
-        ws.send((JSON.stringify(msg)));
40
-      }
41
-
42
-      ws.onmessage = function (e) {
43
-        alert(e.data); ws.close();
44
-      }
45
-
46
-    }
47
-
48
-  </script>
49
-
50
-</body>
51
-
52
-</html>

+ 0
- 21
hash_cn/correct_hashes.txt View File

@@ -1,21 +0,0 @@
1
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2
-Input			00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
3
-
4
-Cryptonight 		1ddd6d4c6b9c41a89daa323b1e140e62d5ebf40a5962028cd1b4acd68deed830
5
-Cryptonight Light 	4c3428f39e1f9ecda3b0726fd4f4fca62843597c480f033ae38d113282b273bf
6
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
7
-Input 			01111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111113
8
-
9
-Cryptonight		9708d6f60fd9505c43b7a62d9ba271703e6128518088bcc5d837bc720aa91d15
10
-Cryptonight Light	278fe67e8d9e7e8b0c2039fe7b9c6bdcb071cd43595ce282648e9e8ae290080e
11
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
12
-Input			11000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
13
-
14
-Cryptonight v7 		a67b43084e5368debd3da0e448668fb362e70e8f6b3a5e082d0477fecc52302b
15
-Cryptonight Light v7 	2c7a31aae3adf05cb845fb081c4504f71562b30dfd6a1792ef9f3d6db93e0481
16
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
17
-Input			11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111113
18
-
19
-Cryptonight v7 		843ae6fc006a6fa74c247ce64368f78c6f4af804446c9003442b67e4bb1fdaf7
20
-Cryptonight Light v7 	c2e3bd88bffd1bd7855af2dae2a52fef6efd36f00db514a6594718c5b67fab21
21
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

+ 0
- 23
hash_cn/libhash/Makefile View File

@@ -1,23 +0,0 @@
1
-TARGET = libhash.so
2
-LIBS = -lm
3
-CC = gcc -O3 -shared -pthread -fPIC
4
-CFLAGS = -g -Wall -std=gnu99 -maes
5
-
6
-.PHONY: default all clean
7
-
8
-default: $(TARGET)
9
-all: default
10
-
11
-OBJECTS = $(patsubst %.c, %.o, $(wildcard *.c))
12
-HEADERS = $(wildcard *.h)
13
-
14
-%.o: %.c $(HEADERS) $(CC) $(CFLAGS) -c $< -o $@
15
-
16
-.PRECIOUS: $(TARGET) $(OBJECTS)
17
-
18
-$(TARGET): $(OBJECTS)
19
-	$(CC) $(OBJECTS) -Wall $(LIBS) -o $(TARGET)
20
-
21
-clean:
22
-	-rm -f *.o
23
-	-rm -f $(TARGET)

+ 0
- 258
hash_cn/libhash/base64.h View File

@@ -1,258 +0,0 @@
1
-// https://github.com/tkislan/base64
2
-
3
-#ifndef BASE64_H
4
-#define BASE64_H
5
-
6
-#include <string>
7
-
8
-const char kBase64Alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
9
-    "abcdefghijklmnopqrstuvwxyz"
10
-    "0123456789+/";
11
-
12
-class Base64 {
13
- public:
14
-  static bool Encode(const std::string &in, std::string *out) {
15
-    int i = 0, j = 0;
16
-    size_t enc_len = 0;
17
-    unsigned char a3[3];
18
-    unsigned char a4[4];
19
-
20
-    out->resize(EncodedLength(in));
21
-
22
-    int input_len = in.size();
23
-    std::string::const_iterator input = in.begin();
24
-
25
-    while (input_len--) {
26
-      a3[i++] = *(input++);
27
-      if (i == 3) {
28
-        a3_to_a4(a4, a3);
29
-
30
-        for (i = 0; i < 4; i++) {
31
-          (*out)[enc_len++] = kBase64Alphabet[a4[i]];
32
-        }
33
-
34
-        i = 0;
35
-      }
36
-    }
37
-
38
-    if (i) {
39
-      for (j = i; j < 3; j++) {
40
-        a3[j] = '\0';
41
-      }
42
-
43
-      a3_to_a4(a4, a3);
44
-
45
-      for (j = 0; j < i + 1; j++) {
46
-        (*out)[enc_len++] = kBase64Alphabet[a4[j]];
47
-      }
48
-
49
-      while ((i++ < 3)) {
50
-        (*out)[enc_len++] = '=';
51
-      }
52
-    }
53
-
54
-    return (enc_len == out->size());
55
-  }
56
-
57
-  static bool Encode(const char *input, size_t input_length, char *out, size_t out_length) {
58
-    int i = 0, j = 0;
59
-    char *out_begin = out;
60
-    unsigned char a3[3];
61
-    unsigned char a4[4];
62
-
63
-    size_t encoded_length = EncodedLength(input_length);
64
-
65
-    if (out_length < encoded_length) return false;
66
-
67
-    while (input_length--) {
68
-      a3[i++] = *input++;
69
-      if (i == 3) {
70
-        a3_to_a4(a4, a3);
71
-
72
-        for (i = 0; i < 4; i++) {
73
-          *out++ = kBase64Alphabet[a4[i]];
74
-        }
75
-
76
-        i = 0;
77
-      }
78
-    }
79
-
80
-    if (i) {
81
-      for (j = i; j < 3; j++) {
82
-        a3[j] = '\0';
83
-      }
84
-
85
-      a3_to_a4(a4, a3);
86
-
87
-      for (j = 0; j < i + 1; j++) {
88
-        *out++ = kBase64Alphabet[a4[j]];
89
-      }
90
-
91
-      while ((i++ < 3)) {
92
-        *out++ = '=';
93
-      }
94
-    }
95
-
96
-    return (out == (out_begin + encoded_length));
97
-  }
98
-
99
-  static bool Decode(const std::string &in, std::string *out) {
100
-    int i = 0, j = 0;
101
-    size_t dec_len = 0;
102
-    unsigned char a3[3];
103
-    unsigned char a4[4];
104
-
105
-    int input_len = in.size();
106
-    std::string::const_iterator input = in.begin();
107
-
108
-    out->resize(DecodedLength(in));
109
-
110
-    while (input_len--) {
111
-      if (*input == '=') {
112
-        break;
113
-      }
114
-
115
-      a4[i++] = *(input++);
116
-      if (i == 4) {
117
-        for (i = 0; i <4; i++) {
118
-          a4[i] = b64_lookup(a4[i]);
119
-        }
120
-
121
-        a4_to_a3(a3,a4);
122
-
123
-        for (i = 0; i < 3; i++) {
124
-          (*out)[dec_len++] = a3[i];
125
-        }
126
-
127
-        i = 0;
128
-      }
129
-    }
130
-
131
-    if (i) {
132
-      for (j = i; j < 4; j++) {
133
-        a4[j] = '\0';
134
-      }
135
-
136
-      for (j = 0; j < 4; j++) {
137
-        a4[j] = b64_lookup(a4[j]);
138
-      }
139
-
140
-      a4_to_a3(a3,a4);
141
-
142
-      for (j = 0; j < i - 1; j++) {
143
-        (*out)[dec_len++] = a3[j];
144
-      }
145
-    }
146
-
147
-    return (dec_len == out->size());
148
-  }
149
-
150
-  static bool Decode(const char *input, size_t input_length, char *out, size_t out_length) {
151
-    int i = 0, j = 0;
152
-    char *out_begin = out;
153
-    unsigned char a3[3];
154
-    unsigned char a4[4];
155
-
156
-    size_t decoded_length = DecodedLength(input, input_length);
157
-
158
-    if (out_length < decoded_length) return false;
159
-
160
-    while (input_length--) {
161
-      if (*input == '=') {
162
-        break;
163
-      }
164
-
165
-      a4[i++] = *(input++);
166
-      if (i == 4) {
167
-        for (i = 0; i <4; i++) {
168
-          a4[i] = b64_lookup(a4[i]);
169
-        }
170
-
171
-        a4_to_a3(a3,a4);
172
-
173
-        for (i = 0; i < 3; i++) {
174
-          *out++ = a3[i];
175
-        }
176
-
177
-        i = 0;
178
-      }
179
-    }
180
-
181
-    if (i) {
182
-      for (j = i; j < 4; j++) {
183
-        a4[j] = '\0';
184
-      }
185
-
186
-      for (j = 0; j < 4; j++) {
187
-        a4[j] = b64_lookup(a4[j]);
188
-      }
189
-
190
-      a4_to_a3(a3,a4);
191
-
192
-      for (j = 0; j < i - 1; j++) {
193
-        *out++ = a3[j];
194
-      }
195
-    }
196
-
197
-    return (out == (out_begin + decoded_length));
198
-  }
199
-
200
-  static int DecodedLength(const char *in, size_t in_length) {
201
-    int numEq = 0;
202
-
203
-    const char *in_end = in + in_length;
204
-    while (*--in_end == '=') ++numEq;
205
-
206
-    return ((6 * in_length) / 8) - numEq;
207
-  }
208
-
209
-  static int DecodedLength(const std::string &in) {
210
-    int numEq = 0;
211
-    int n = in.size();
212
-
213
-    for (std::string::const_reverse_iterator it = in.rbegin(); *it == '='; ++it) {
214
-      ++numEq;
215
-    }
216
-
217
-    return ((6 * n) / 8) - numEq;
218
-  }
219
-
220
-  inline static int EncodedLength(size_t length) {
221
-    return (length + 2 - ((length + 2) % 3)) / 3 * 4;
222
-  }
223
-
224
-  inline static int EncodedLength(const std::string &in) {
225
-    return EncodedLength(in.length());
226
-  }
227
-
228
-  inline static void StripPadding(std::string *in) {
229
-    while (!in->empty() && *(in->rbegin()) == '=') in->resize(in->size() - 1);
230
-  }
231
-
232
- private:
233
-  static inline void a3_to_a4(unsigned char * a4, unsigned char * a3) {
234
-    a4[0] = (a3[0] & 0xfc) >> 2;
235
-    a4[1] = ((a3[0] & 0x03) << 4) + ((a3[1] & 0xf0) >> 4);
236
-    a4[2] = ((a3[1] & 0x0f) << 2) + ((a3[2] & 0xc0) >> 6);
237
-    a4[3] = (a3[2] & 0x3f);
238
-  }
239
-
240
-  static inline void a4_to_a3(unsigned char * a3, unsigned char * a4) {
241
-    a3[0] = (a4[0] << 2) + ((a4[1] & 0x30) >> 4);
242
-    a3[1] = ((a4[1] & 0xf) << 4) + ((a4[2] & 0x3c) >> 2);
243
-    a3[2] = ((a4[2] & 0x3) << 6) + a4[3];
244
-  }
245
-
246
-  static inline unsigned char b64_lookup(unsigned char c) {
247
-    if(c >='A' && c <='Z') return c - 'A';
248
-    if(c >='a' && c <='z') return c - 71;
249
-    if(c >='0' && c <='9') return c + 4;
250
-    if(c == '+') return 62;
251
-    if(c == '/') return 63;
252
-    return 255;
253
-  }
254
-};
255
-
256
-
257
-
258
-#endif // BASE64_H

+ 0
- 341
hash_cn/libhash/blake.c View File

@@ -1,341 +0,0 @@
1
-/*
2
- * The blake256_* and blake224_* functions are largely copied from
3
- * blake256_light.c and blake224_light.c from the BLAKE website:
4
- *
5
- *     http://131002.net/blake/
6
- *
7
- * The hmac_* functions implement HMAC-BLAKE-256 and HMAC-BLAKE-224.
8
- * HMAC is specified by RFC 2104.
9
- */
10
-
11
-#include <string.h>
12
-#include <stdint.h>
13
-
14
-typedef struct {
15
-  uint32_t h[8], s[4], t[2];
16
-  int buflen, nullt;
17
-  uint8_t buf[64];
18
-} state;
19
-
20
-typedef struct {
21
-  state inner;
22
-  state outer;
23
-} hmac_state;
24
-
25
-
26
-#define U8TO32(p) \
27
-	(((uint32_t)((p)[0]) << 24) | ((uint32_t)((p)[1]) << 16) |    \
28
-	 ((uint32_t)((p)[2]) <<  8) | ((uint32_t)((p)[3])      ))
29
-#define U32TO8(p, v) \
30
-	(p)[0] = (uint8_t)((v) >> 24); (p)[1] = (uint8_t)((v) >> 16); \
31
-	(p)[2] = (uint8_t)((v) >>  8); (p)[3] = (uint8_t)((v)      );
32
-
33
-const uint8_t sigma[][16] = {
34
-	{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15},
35
-	{14,10, 4, 8, 9,15,13, 6, 1,12, 0, 2,11, 7, 5, 3},
36
-	{11, 8,12, 0, 5, 2,15,13,10,14, 3, 6, 7, 1, 9, 4},
37
-	{ 7, 9, 3, 1,13,12,11,14, 2, 6, 5,10, 4, 0,15, 8},
38
-	{ 9, 0, 5, 7, 2, 4,10,15,14, 1,11,12, 6, 8, 3,13},
39
-	{ 2,12, 6,10, 0,11, 8, 3, 4,13, 7, 5,15,14, 1, 9},
40
-	{12, 5, 1,15,14,13, 4,10, 0, 7, 6, 3, 9, 2, 8,11},
41
-	{13,11, 7,14,12, 1, 3, 9, 5, 0,15, 4, 8, 6, 2,10},
42
-	{ 6,15,14, 9,11, 3, 0, 8,12, 2,13, 7, 1, 4,10, 5},
43
-	{10, 2, 8, 4, 7, 6, 1, 5,15,11, 9,14, 3,12,13, 0},
44
-	{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15},
45
-	{14,10, 4, 8, 9,15,13, 6, 1,12, 0, 2,11, 7, 5, 3},
46
-	{11, 8,12, 0, 5, 2,15,13,10,14, 3, 6, 7, 1, 9, 4},
47
-	{ 7, 9, 3, 1,13,12,11,14, 2, 6, 5,10, 4, 0,15, 8}
48
-};
49
-
50
-const uint32_t cst[16] = {
51
-	0x243F6A88, 0x85A308D3, 0x13198A2E, 0x03707344,
52
-	0xA4093822, 0x299F31D0, 0x082EFA98, 0xEC4E6C89,
53
-	0x452821E6, 0x38D01377, 0xBE5466CF, 0x34E90C6C,
54
-	0xC0AC29B7, 0xC97C50DD, 0x3F84D5B5, 0xB5470917
55
-};
56
-
57
-static const uint8_t padding[] = {
58
-	0x80,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
59
-	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
60
-};
61
-
62
-
63
-void blake256_compress(state *S, const uint8_t *block) {
64
-	uint32_t v[16], m[16], i;
65
-
66
-#define ROT(x,n) (((x)<<(32-n))|((x)>>(n)))
67
-#define G(a,b,c,d,e)                                      \
68
-	v[a] += (m[sigma[i][e]] ^ cst[sigma[i][e+1]]) + v[b]; \
69
-	v[d] = ROT(v[d] ^ v[a],16);                           \
70
-	v[c] += v[d];                                         \
71
-	v[b] = ROT(v[b] ^ v[c],12);                           \
72
-	v[a] += (m[sigma[i][e+1]] ^ cst[sigma[i][e]])+v[b];   \
73
-	v[d] = ROT(v[d] ^ v[a], 8);                           \
74
-	v[c] += v[d];                                         \
75
-	v[b] = ROT(v[b] ^ v[c], 7);
76
-
77
-	for (i = 0; i < 16; ++i) m[i] = U8TO32(block + i * 4);
78
-	for (i = 0; i < 8;  ++i) v[i] = S->h[i];
79
-	v[ 8] = S->s[0] ^ 0x243F6A88;
80
-	v[ 9] = S->s[1] ^ 0x85A308D3;
81
-	v[10] = S->s[2] ^ 0x13198A2E;
82
-	v[11] = S->s[3] ^ 0x03707344;
83
-	v[12] = 0xA4093822;
84
-	v[13] = 0x299F31D0;
85
-	v[14] = 0x082EFA98;
86
-	v[15] = 0xEC4E6C89;
87
-
88
-	if (S->nullt == 0) {
89
-		v[12] ^= S->t[0];
90
-		v[13] ^= S->t[0];
91
-		v[14] ^= S->t[1];
92
-		v[15] ^= S->t[1];
93
-	}
94
-
95
-	for (i = 0; i < 14; ++i) {
96
-		G(0, 4,  8, 12,  0);
97
-		G(1, 5,  9, 13,  2);
98
-		G(2, 6, 10, 14,  4);
99
-		G(3, 7, 11, 15,  6);
100
-		G(3, 4,  9, 14, 14);
101
-		G(2, 7,  8, 13, 12);
102
-		G(0, 5, 10, 15,  8);
103
-		G(1, 6, 11, 12, 10);
104
-	}
105
-
106
-	for (i = 0; i < 16; ++i) S->h[i % 8] ^= v[i];
107
-	for (i = 0; i < 8;  ++i) S->h[i] ^= S->s[i % 4];
108
-}
109
-
110
-void blake256_init(state *S) {
111
-	S->h[0] = 0x6A09E667;
112
-	S->h[1] = 0xBB67AE85;
113
-	S->h[2] = 0x3C6EF372;
114
-	S->h[3] = 0xA54FF53A;
115
-	S->h[4] = 0x510E527F;
116
-	S->h[5] = 0x9B05688C;
117
-	S->h[6] = 0x1F83D9AB;
118
-	S->h[7] = 0x5BE0CD19;
119
-	S->t[0] = S->t[1] = S->buflen = S->nullt = 0;
120
-	S->s[0] = S->s[1] = S->s[2] = S->s[3] = 0;
121
-}
122
-
123
-void blake224_init(state *S) {
124
-	S->h[0] = 0xC1059ED8;
125
-	S->h[1] = 0x367CD507;
126
-	S->h[2] = 0x3070DD17;
127
-	S->h[3] = 0xF70E5939;
128
-	S->h[4] = 0xFFC00B31;
129
-	S->h[5] = 0x68581511;
130
-	S->h[6] = 0x64F98FA7;
131
-	S->h[7] = 0xBEFA4FA4;
132
-	S->t[0] = S->t[1] = S->buflen = S->nullt = 0;
133
-	S->s[0] = S->s[1] = S->s[2] = S->s[3] = 0;
134
-}
135
-
136
-// datalen = number of bits
137
-void blake256_update(state *S, const uint8_t *data, uint64_t datalen) {
138
-	int left = S->buflen >> 3;
139
-	int fill = 64 - left;
140
-
141
-	if (left && (((datalen >> 3) & 0x3F) >= (unsigned) fill)) {
142
-		memcpy((void *) (S->buf + left), (void *) data, fill);
143
-		S->t[0] += 512;
144
-		if (S->t[0] == 0) S->t[1]++;
145
-		blake256_compress(S, S->buf);
146
-		data += fill;
147
-		datalen -= (fill << 3);
148
-		left = 0;
149
-	}
150
-
151
-	while (datalen >= 512) {
152
-		S->t[0] += 512;
153
-		if (S->t[0] == 0) S->t[1]++;
154
-		blake256_compress(S, data);
155
-		data += 64;
156
-		datalen -= 512;
157
-	}
158
-
159
-	if (datalen > 0) {
160
-		memcpy((void *) (S->buf + left), (void *) data, datalen >> 3);
161
-		S->buflen = (left << 3) + datalen;
162
-	} else {
163
-		S->buflen = 0;
164
-	}
165
-}
166
-
167
-// datalen = number of bits
168
-void blake224_update(state *S, const uint8_t *data, uint64_t datalen) {
169
-	blake256_update(S, data, datalen);
170
-}
171
-
172
-void blake256_final_h(state *S, uint8_t *digest, uint8_t pa, uint8_t pb) {
173
-	uint8_t msglen[8];
174
-	uint32_t lo = S->t[0] + S->buflen, hi = S->t[1];
175
-	if (lo < (unsigned) S->buflen) hi++;
176
-	U32TO8(msglen + 0, hi);
177
-	U32TO8(msglen + 4, lo);
178
-
179
-	if (S->buflen == 440) { /* one padding byte */
180
-		S->t[0] -= 8;
181
-		blake256_update(S, &pa, 8);
182
-	} else {
183
-		if (S->buflen < 440) { /* enough space to fill the block  */
184
-			if (S->buflen == 0) S->nullt = 1;
185
-			S->t[0] -= 440 - S->buflen;
186
-			blake256_update(S, padding, 440 - S->buflen);
187
-		} else { /* need 2 compressions */
188
-			S->t[0] -= 512 - S->buflen;
189
-			blake256_update(S, padding, 512 - S->buflen);
190
-			S->t[0] -= 440;
191
-			blake256_update(S, padding + 1, 440);
192
-			S->nullt = 1;
193
-		}
194
-		blake256_update(S, &pb, 8);
195
-		S->t[0] -= 8;
196
-	}
197
-	S->t[0] -= 64;
198
-	blake256_update(S, msglen, 64);
199
-
200
-	U32TO8(digest +  0, S->h[0]);
201
-	U32TO8(digest +  4, S->h[1]);
202
-	U32TO8(digest +  8, S->h[2]);
203
-	U32TO8(digest + 12, S->h[3]);
204
-	U32TO8(digest + 16, S->h[4]);
205
-	U32TO8(digest + 20, S->h[5]);
206
-	U32TO8(digest + 24, S->h[6]);
207
-	U32TO8(digest + 28, S->h[7]);
208
-}
209
-
210
-void blake256_final(state *S, uint8_t *digest) {
211
-	blake256_final_h(S, digest, 0x81, 0x01);
212
-}
213
-
214
-void blake224_final(state *S, uint8_t *digest) {
215
-	blake256_final_h(S, digest, 0x80, 0x00);
216
-}
217
-
218
-// inlen = number of bytes
219
-void blake256_hash(uint8_t *out, const uint8_t *in, uint64_t inlen) {
220
-	state S;
221
-	blake256_init(&S);
222
-	blake256_update(&S, in, inlen * 8);
223
-	blake256_final(&S, out);
224
-}
225
-
226
-void blake(const uint8_t *input, uint64_t len, uint8_t *output)
227
-{
228
-	blake256_hash(output, input, len);
229
-}
230
-
231
-// inlen = number of bytes
232
-void blake224_hash(uint8_t *out, const uint8_t *in, uint64_t inlen) {
233
-	state S;
234
-	blake224_init(&S);
235
-	blake224_update(&S, in, inlen * 8);
236
-	blake224_final(&S, out);
237
-}
238
-
239
-// keylen = number of bytes
240
-void hmac_blake256_init(hmac_state *S, const uint8_t *_key, uint64_t keylen) {
241
-	const uint8_t *key = _key;
242
-	uint8_t keyhash[32];
243
-	uint8_t pad[64];
244
-	uint64_t i;
245
-
246
-	if (keylen > 64) {
247
-		blake256_hash(keyhash, key, keylen);
248
-		key = keyhash;
249
-		keylen = 32;
250
-	}
251
-
252
-	blake256_init(&S->inner);
253
-	memset(pad, 0x36, 64);
254
-	for (i = 0; i < keylen; ++i) {
255
-		pad[i] ^= key[i];
256
-	}
257
-	blake256_update(&S->inner, pad, 512);
258
-
259
-	blake256_init(&S->outer);
260
-	memset(pad, 0x5c, 64);
261
-	for (i = 0; i < keylen; ++i) {
262
-		pad[i] ^= key[i];
263
-	}
264
-	blake256_update(&S->outer, pad, 512);
265
-
266
-	memset(keyhash, 0, 32);
267
-}
268
-
269
-// keylen = number of bytes
270
-void hmac_blake224_init(hmac_state *S, const uint8_t *_key, uint64_t keylen) {
271
-	const uint8_t *key = _key;
272
-	uint8_t keyhash[32];
273
-	uint8_t pad[64];
274
-	uint64_t i;
275
-
276
-	if (keylen > 64) {
277
-		blake256_hash(keyhash, key, keylen);
278
-		key = keyhash;
279
-		keylen = 28;
280
-	}
281
-
282
-	blake224_init(&S->inner);
283
-	memset(pad, 0x36, 64);
284
-	for (i = 0; i < keylen; ++i) {
285
-		pad[i] ^= key[i];
286
-	}
287
-	blake224_update(&S->inner, pad, 512);
288
-
289
-	blake224_init(&S->outer);
290
-	memset(pad, 0x5c, 64);
291
-	for (i = 0; i < keylen; ++i) {
292
-		pad[i] ^= key[i];
293
-	}
294
-	blake224_update(&S->outer, pad, 512);
295
-
296
-	memset(keyhash, 0, 32);
297
-}
298
-
299
-// datalen = number of bits
300
-void hmac_blake256_update(hmac_state *S, const uint8_t *data, uint64_t datalen) {
301
-  // update the inner state
302
-  blake256_update(&S->inner, data, datalen);
303
-}
304
-
305
-// datalen = number of bits
306
-void hmac_blake224_update(hmac_state *S, const uint8_t *data, uint64_t datalen) {
307
-  // update the inner state
308
-  blake224_update(&S->inner, data, datalen);
309
-}
310
-
311
-void hmac_blake256_final(hmac_state *S, uint8_t *digest) {
312
-	uint8_t ihash[32];
313
-	blake256_final(&S->inner, ihash);
314
-	blake256_update(&S->outer, ihash, 256);
315
-	blake256_final(&S->outer, digest);
316
-	memset(ihash, 0, 32);
317
-}
318
-
319
-void hmac_blake224_final(hmac_state *S, uint8_t *digest) {
320
-	uint8_t ihash[32];
321
-	blake224_final(&S->inner, ihash);
322
-	blake224_update(&S->outer, ihash, 224);
323
-	blake224_final(&S->outer, digest);
324
-	memset(ihash, 0, 32);
325
-}
326
-
327
-// keylen = number of bytes; inlen = number of bytes
328
-void hmac_blake256_hash(uint8_t *out, const uint8_t *key, uint64_t keylen, const uint8_t *in, uint64_t inlen) {
329
-	hmac_state S;
330
-	hmac_blake256_init(&S, key, keylen);
331
-	hmac_blake256_update(&S, in, inlen * 8);
332
-	hmac_blake256_final(&S, out);
333
-}
334
-
335
-// keylen = number of bytes; inlen = number of bytes
336
-void hmac_blake224_hash(uint8_t *out, const uint8_t *key, uint64_t keylen, const uint8_t *in, uint64_t inlen) {
337
-	hmac_state S;
338
-	hmac_blake224_init(&S, key, keylen);
339
-	hmac_blake224_update(&S, in, inlen * 8);
340
-	hmac_blake224_final(&S, out);
341
-}

+ 0
- 14
hash_cn/libhash/blake.h View File

@@ -1,14 +0,0 @@
1
-#ifndef BLAKE_H
2
-#define BLAKE_H
3
-
4
-#ifdef __cplusplus
5
-extern "C" {
6
-#endif
7
-
8
-void blake(const uint8_t *input, uint64_t len, uint8_t *output);
9
-
10
-#ifdef __cplusplus
11
-}
12
-#endif
13
-
14
-#endif

+ 0
- 749
hash_cn/libhash/cryptonight.c View File

@@ -1,749 +0,0 @@
1
-#include <stdlib.h>
2
-#include <stdint.h>
3
-#include <string.h>
4
-#include "keccak.h"
5
-#include "blake.h"
6
-#include "skein.h"
7
-#include "jh.h"
8
-#include "groestl.h"
9
-#include "oaes_lib.h"
10
-#include "variant2_int_sqrt.h"
11
-
12
-#define MEMORY (1 << 21) /* 2 MiB */
13
-#define ITER (1 << 20)
14
-#define AES_BLOCK_SIZE 16
15
-#define AES_KEY_SIZE 32 /*16*/
16
-#define INIT_SIZE_BLK 8
17
-#define INIT_SIZE_BYTE (INIT_SIZE_BLK * AES_BLOCK_SIZE) // 128
18
-
19
-#define U64(x) ((uint64_t *) (x))
20
-
21
-#define VARIANT1_1(p) \
22
-  do \
23
-  { \
24
-    const uint8_t tmp = ((const uint8_t*)(p))[11]; \
25
-    static const uint32_t table = 0x75310; \
26
-    const uint8_t index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; \
27
-    ((uint8_t*)(p))[11] = tmp ^ ((table >> index) & 0x30); \
28
-  } while(0)
29
-
30
-#define VARIANT1_2(p) \
31
-  do \
32
-  { \
33
-    xor64(p, tweak1_2); \
34
-  } while(0)
35
-  
36
- 
37
-#define VARIANT1_INIT64() \
38
- const uint64_t tweak1_2 = (variant == 1) ? *(const uint64_t *)(((const uint8_t *)input) + 35) ^ ctx->state.hs.w[24] : 0
39
-
40
-#define VARIANT2_INIT64() \
41
-  uint64_t division_result = 0; \
42
-  uint64_t sqrt_result = 0; \
43
-  do if (variant >= 2) \
44
-  { \
45
-    U64(ctx->d)[0] = ctx->state.hs.w[8] ^ ctx->state.hs.w[10]; \
46
-    U64(ctx->d)[1] = ctx->state.hs.w[9] ^ ctx->state.hs.w[11]; \
47
-    division_result = ctx->state.hs.w[12]; \
48
-    sqrt_result = ctx->state.hs.w[13]; \
49
-  } while (0)
50
-
51
-  
52
-#define VARIANT2_2_PORTABLE() \
53
-  do \
54
-  { \
55
-      xor_blocks(ctx->long_state + (j ^ 0x10), ctx->e); \
56
-      xor_blocks(ctx->e, ctx->long_state + (j ^ 0x20)); \
57
-  } while (0)
58
-  
59
-#define VARIANT2_PORTABLE_SHUFFLE_ADD1(base_ptr, offset) \
60
-  do \
61
-  { \
62
-    uint64_t* chunk1 = U64((base_ptr) + ((offset) ^ 0x10)); \
63
-    uint64_t* chunk2 = U64((base_ptr) + ((offset) ^ 0x20)); \
64
-    uint64_t* chunk3 = U64((base_ptr) + ((offset) ^ 0x30)); \
65
-    \
66
-    uint64_t chunk1_old0 = chunk1[0]; \
67
-    uint64_t chunk1_old1 = chunk1[1]; \
68
-    \
69
-    chunk1[0] = chunk3[0] + ((uint64_t*) ctx->d)[0]; \
70
-    chunk1[1] = chunk3[1] + ((uint64_t*) ctx->d)[1]; \
71
-    \
72
-    chunk3[0] = chunk2[0] + ((uint64_t*) ctx->a)[0]; \
73
-    chunk3[1] = chunk2[1] + ((uint64_t*) ctx->a)[1]; \
74
-    \
75
-    chunk2[0] = chunk1_old0 + ((uint64_t*) ctx->b)[0]; \
76
-    chunk2[1] = chunk1_old1 + ((uint64_t*) ctx->b)[1]; \
77
-  } while (0)
78
-
79
-  
80
-#define VARIANT2_PORTABLE_SHUFFLE_ADD2(base_ptr, offset) \
81
-  do \
82
-  { \
83
-    uint64_t* chunk1 = U64((base_ptr) + ((offset) ^ 0x10)); \
84
-    uint64_t* chunk2 = U64((base_ptr) + ((offset) ^ 0x20)); \
85
-    uint64_t* chunk3 = U64((base_ptr) + ((offset) ^ 0x30)); \
86
-    \
87
-    uint64_t chunk1_old0 = chunk1[0]; \
88
-    uint64_t chunk1_old1 = chunk1[1]; \
89
-    \
90
-    chunk1[0] = chunk3[0] + ((uint64_t*) ctx->d)[0]; \
91
-    chunk1[1] = chunk3[1] + ((uint64_t*) ctx->d)[1]; \
92
-    \
93
-    chunk3[0] = chunk2[0] + ((uint64_t*) ctx->a)[0]; \
94
-    chunk3[1] = chunk2[1] + ((uint64_t*) ctx->a)[1]; \
95
-    \
96
-    chunk2[0] = chunk1_old0 + ((uint64_t*) ctx->c)[0]; \
97
-    chunk2[1] = chunk1_old1 + ((uint64_t*) ctx->c)[1]; \
98
-  } while (0)
99
-
100
-
101
-#define VARIANT2_INTEGER_MATH_DIVISION_STEP(b, ptr) \
102
-  ((uint64_t*)(b))[0] ^= division_result ^ (sqrt_result << 32); \
103
-  { \
104
-    const uint64_t dividend = ((uint64_t*)(ptr))[1]; \
105
-    const uint32_t divisor = (((uint64_t*)(ptr))[0] + (sqrt_result << 1)) | 0x80000001UL; \
106
-    const uint64_t aa = dividend / divisor; \
107
-    division_result = (aa & 0xFFFFFFFF) + ((dividend - aa * divisor) << 32); \
108
-  } \
109
-  const uint64_t sqrt_input = ((uint64_t*)(ptr))[0] + division_result
110
-
111
-#if defined DBL_MANT_DIG && (DBL_MANT_DIG >= 50)
112
-  // double precision floating point type has enough bits of precision on current platform
113
-  #define VARIANT2_PORTABLE_INTEGER_MATH(b, ptr) \
114
-  do \
115
-    { \
116
-      VARIANT2_INTEGER_MATH_DIVISION_STEP(b, ptr); \
117
-      VARIANT2_INTEGER_MATH_SQRT_STEP_FP64(); \
118
-      VARIANT2_INTEGER_MATH_SQRT_FIXUP(sqrt_result); \
119
-    } while (0)
120
-#else
121
-  // double precision floating point type is not good enough on current platform
122
-  // fall back to the reference code (integer only)
123
-  #define VARIANT2_PORTABLE_INTEGER_MATH(b, ptr) \
124
-  do \
125
-    { \
126
-      VARIANT2_INTEGER_MATH_DIVISION_STEP(b, ptr); \
127
-      VARIANT2_INTEGER_MATH_SQRT_STEP_REF(); \
128
-    } while (0)
129
-#endif
130
-
131
-static void xor64(uint8_t *a, const uint64_t b)
132
-{
133
-    *(uint64_t *)a ^= b;
134
-}
135
-
136
-static void copy_block(uint8_t* dst, const uint8_t* src) {
137
-   ((uint64_t *)dst)[0] = ((uint64_t *)src)[0];
138
-   ((uint64_t *)dst)[1] = ((uint64_t *)src)[1];
139
-}
140
-
141
-void do_blake_hash(const void *input, size_t len, char *output)
142
-{
143
-    blake(input, len, (unsigned char *)output);
144
-}
145
-
146
-void do_groestl_hash(const void *input, size_t len, char *output)
147
-{
148
-    groestl(input, len * 8, (uint8_t *)output);
149
-}
150
-
151
-void do_jh_hash(const void *input, size_t len, char *output)
152
-{
153
-    jh(32 * 8, input, 8 * len, (uint8_t *)output);
154
-}
155
-
156
-void do_skein_hash(const void *input, size_t len, char *output)
157
-{
158
-    skein(8 * 32, input, 8 * len, (uint8_t *)output);
159
-}
160
-
161
-void (*const extra_hashes[4])(const void *, size_t, char *) = {
162
-    do_blake_hash, do_groestl_hash, do_jh_hash, do_skein_hash};
163
-
164
-void xor_blocks_dst(const uint8_t *a, const uint8_t *b, uint8_t *dst)
165
-{
166
-    ((uint64_t *)dst)[0] = ((uint64_t *)a)[0] ^ ((uint64_t *)b)[0];
167
-    ((uint64_t *)dst)[1] = ((uint64_t *)a)[1] ^ ((uint64_t *)b)[1];
168
-}
169
-
170
-#define likely(x) (x)
171
-
172
-#pragma pack(push, 1)
173
-union hash_state {
174
-    uint8_t b[200];
175
-    uint64_t w[25];
176
-};
177
-#pragma pack(pop)
178
-
179
-#pragma pack(push, 1)
180
-union cn_slow_hash_state {
181
-    union hash_state hs;
182
-    struct
183
-    {
184
-        uint8_t k[64];
185
-        uint8_t init[INIT_SIZE_BYTE];
186
-    };
187
-};
188
-#pragma pack(pop)
189
-
190
-struct cryptonight_ctx
191
-{
192
-    uint8_t long_state[MEMORY] __attribute((aligned(16)));
193
-    union cn_slow_hash_state state;
194
-    uint8_t text[INIT_SIZE_BYTE] __attribute((aligned(16)));
195
-    uint8_t a[AES_BLOCK_SIZE] __attribute__((aligned(16)));
196
-    uint8_t b[AES_BLOCK_SIZE] __attribute__((aligned(16)));
197
-    uint8_t c[AES_BLOCK_SIZE] __attribute__((aligned(16)));
198
-    uint8_t d[AES_BLOCK_SIZE] __attribute__((aligned(16)));
199
-    uint8_t e[AES_BLOCK_SIZE] __attribute__((aligned(16)));
200
-    oaes_ctx *aes_ctx;
201
-};
202
-
203
-struct cryptonight_ctx_lite
204
-{
205
-    uint8_t long_state[MEMORY/2] __attribute((aligned(16)));
206
-    union cn_slow_hash_state state;
207
-    uint8_t text[INIT_SIZE_BYTE] __attribute((aligned(16)));
208
-    uint8_t a[AES_BLOCK_SIZE] __attribute__((aligned(16)));
209
-    uint8_t b[AES_BLOCK_SIZE] __attribute__((aligned(16)));
210
-    uint8_t c[AES_BLOCK_SIZE] __attribute__((aligned(16)));
211
-    uint8_t d[AES_BLOCK_SIZE] __attribute__((aligned(16)));
212
-    uint8_t e[AES_BLOCK_SIZE] __attribute__((aligned(16)));
213
-    oaes_ctx *aes_ctx;
214
-};
215
-
216
-const uint32_t TestTable1[256] __attribute((aligned(16))) = {
217
-    0xA56363C6, 0x847C7CF8, 0x997777EE, 0x8D7B7BF6, 0x0DF2F2FF, 0xBD6B6BD6, 0xB16F6FDE, 0x54C5C591,
218
-    0x50303060, 0x03010102, 0xA96767CE, 0x7D2B2B56, 0x19FEFEE7, 0x62D7D7B5, 0xE6ABAB4D, 0x9A7676EC,
219
-    0x45CACA8F, 0x9D82821F, 0x40C9C989, 0x877D7DFA, 0x15FAFAEF, 0xEB5959B2, 0xC947478E, 0x0BF0F0FB,
220
-    0xECADAD41, 0x67D4D4B3, 0xFDA2A25F, 0xEAAFAF45, 0xBF9C9C23, 0xF7A4A453, 0x967272E4, 0x5BC0C09B,
221
-    0xC2B7B775, 0x1CFDFDE1, 0xAE93933D, 0x6A26264C, 0x5A36366C, 0x413F3F7E, 0x02F7F7F5, 0x4FCCCC83,
222
-    0x5C343468, 0xF4A5A551, 0x34E5E5D1, 0x08F1F1F9, 0x937171E2, 0x73D8D8AB, 0x53313162, 0x3F15152A,
223
-    0x0C040408, 0x52C7C795, 0x65232346, 0x5EC3C39D, 0x28181830, 0xA1969637, 0x0F05050A, 0xB59A9A2F,
224
-    0x0907070E, 0x36121224, 0x9B80801B, 0x3DE2E2DF, 0x26EBEBCD, 0x6927274E, 0xCDB2B27F, 0x9F7575EA,
225
-    0x1B090912, 0x9E83831D, 0x742C2C58, 0x2E1A1A34, 0x2D1B1B36, 0xB26E6EDC, 0xEE5A5AB4, 0xFBA0A05B,
226
-    0xF65252A4, 0x4D3B3B76, 0x61D6D6B7, 0xCEB3B37D, 0x7B292952, 0x3EE3E3DD, 0x712F2F5E, 0x97848413,
227
-    0xF55353A6, 0x68D1D1B9, 0x00000000, 0x2CEDEDC1, 0x60202040, 0x1FFCFCE3, 0xC8B1B179, 0xED5B5BB6,
228
-    0xBE6A6AD4, 0x46CBCB8D, 0xD9BEBE67, 0x4B393972, 0xDE4A4A94, 0xD44C4C98, 0xE85858B0, 0x4ACFCF85,
229
-    0x6BD0D0BB, 0x2AEFEFC5, 0xE5AAAA4F, 0x16FBFBED, 0xC5434386, 0xD74D4D9A, 0x55333366, 0x94858511,
230
-    0xCF45458A, 0x10F9F9E9, 0x06020204, 0x817F7FFE, 0xF05050A0, 0x443C3C78, 0xBA9F9F25, 0xE3A8A84B,
231
-    0xF35151A2, 0xFEA3A35D, 0xC0404080, 0x8A8F8F05, 0xAD92923F, 0xBC9D9D21, 0x48383870, 0x04F5F5F1,
232
-    0xDFBCBC63, 0xC1B6B677, 0x75DADAAF, 0x63212142, 0x30101020, 0x1AFFFFE5, 0x0EF3F3FD, 0x6DD2D2BF,
233
-    0x4CCDCD81, 0x140C0C18, 0x35131326, 0x2FECECC3, 0xE15F5FBE, 0xA2979735, 0xCC444488, 0x3917172E,
234
-    0x57C4C493, 0xF2A7A755, 0x827E7EFC, 0x473D3D7A, 0xAC6464C8, 0xE75D5DBA, 0x2B191932, 0x957373E6,
235
-    0xA06060C0, 0x98818119, 0xD14F4F9E, 0x7FDCDCA3, 0x66222244, 0x7E2A2A54, 0xAB90903B, 0x8388880B,
236
-    0xCA46468C, 0x29EEEEC7, 0xD3B8B86B, 0x3C141428, 0x79DEDEA7, 0xE25E5EBC, 0x1D0B0B16, 0x76DBDBAD,
237
-    0x3BE0E0DB, 0x56323264, 0x4E3A3A74, 0x1E0A0A14, 0xDB494992, 0x0A06060C, 0x6C242448, 0xE45C5CB8,
238
-    0x5DC2C29F, 0x6ED3D3BD, 0xEFACAC43, 0xA66262C4, 0xA8919139, 0xA4959531, 0x37E4E4D3, 0x8B7979F2,
239
-    0x32E7E7D5, 0x43C8C88B, 0x5937376E, 0xB76D6DDA, 0x8C8D8D01, 0x64D5D5B1, 0xD24E4E9C, 0xE0A9A949,
240
-    0xB46C6CD8, 0xFA5656AC, 0x07F4F4F3, 0x25EAEACF, 0xAF6565CA, 0x8E7A7AF4, 0xE9AEAE47, 0x18080810,
241
-    0xD5BABA6F, 0x887878F0, 0x6F25254A, 0x722E2E5C, 0x241C1C38, 0xF1A6A657, 0xC7B4B473, 0x51C6C697,
242
-    0x23E8E8CB, 0x7CDDDDA1, 0x9C7474E8, 0x211F1F3E, 0xDD4B4B96, 0xDCBDBD61, 0x868B8B0D, 0x858A8A0F,
243
-    0x907070E0, 0x423E3E7C, 0xC4B5B571, 0xAA6666CC, 0xD8484890, 0x05030306, 0x01F6F6F7, 0x120E0E1C,
244
-    0xA36161C2, 0x5F35356A, 0xF95757AE, 0xD0B9B969, 0x91868617, 0x58C1C199, 0x271D1D3A, 0xB99E9E27,
245
-    0x38E1E1D9, 0x13F8F8EB, 0xB398982B, 0x33111122, 0xBB6969D2, 0x70D9D9A9, 0x898E8E07, 0xA7949433,
246
-    0xB69B9B2D, 0x221E1E3C, 0x92878715, 0x20E9E9C9, 0x49CECE87, 0xFF5555AA, 0x78282850, 0x7ADFDFA5,
247
-    0x8F8C8C03, 0xF8A1A159, 0x80898909, 0x170D0D1A, 0xDABFBF65, 0x31E6E6D7, 0xC6424284, 0xB86868D0,
248
-    0xC3414182, 0xB0999929, 0x772D2D5A, 0x110F0F1E, 0xCBB0B07B, 0xFC5454A8, 0xD6BBBB6D, 0x3A16162C};
249
-
250
-const uint32_t TestTable2[256] __attribute((aligned(16))) = {
251
-    0x6363C6A5, 0x7C7CF884, 0x7777EE99, 0x7B7BF68D, 0xF2F2FF0D, 0x6B6BD6BD, 0x6F6FDEB1, 0xC5C59154,
252
-    0x30306050, 0x01010203, 0x6767CEA9, 0x2B2B567D, 0xFEFEE719, 0xD7D7B562, 0xABAB4DE6, 0x7676EC9A,
253
-    0xCACA8F45, 0x82821F9D, 0xC9C98940, 0x7D7DFA87, 0xFAFAEF15, 0x5959B2EB, 0x47478EC9, 0xF0F0FB0B,
254
-    0xADAD41EC, 0xD4D4B367, 0xA2A25FFD, 0xAFAF45EA, 0x9C9C23BF, 0xA4A453F7, 0x7272E496, 0xC0C09B5B,
255
-    0xB7B775C2, 0xFDFDE11C, 0x93933DAE, 0x26264C6A, 0x36366C5A, 0x3F3F7E41, 0xF7F7F502, 0xCCCC834F,
256
-    0x3434685C, 0xA5A551F4, 0xE5E5D134, 0xF1F1F908, 0x7171E293, 0xD8D8AB73, 0x31316253, 0x15152A3F,
257
-    0x0404080C, 0xC7C79552, 0x23234665, 0xC3C39D5E, 0x18183028, 0x969637A1, 0x05050A0F, 0x9A9A2FB5,
258
-    0x07070E09, 0x12122436, 0x80801B9B, 0xE2E2DF3D, 0xEBEBCD26, 0x27274E69, 0xB2B27FCD, 0x7575EA9F,
259
-    0x0909121B, 0x83831D9E, 0x2C2C5874, 0x1A1A342E, 0x1B1B362D, 0x6E6EDCB2, 0x5A5AB4EE, 0xA0A05BFB,
260
-    0x5252A4F6, 0x3B3B764D, 0xD6D6B761, 0xB3B37DCE, 0x2929527B, 0xE3E3DD3E, 0x2F2F5E71, 0x84841397,
261
-    0x5353A6F5, 0xD1D1B968, 0x00000000, 0xEDEDC12C, 0x20204060, 0xFCFCE31F, 0xB1B179C8, 0x5B5BB6ED,
262
-    0x6A6AD4BE, 0xCBCB8D46, 0xBEBE67D9, 0x3939724B, 0x4A4A94DE, 0x4C4C98D4, 0x5858B0E8, 0xCFCF854A,
263
-    0xD0D0BB6B, 0xEFEFC52A, 0xAAAA4FE5, 0xFBFBED16, 0x434386C5, 0x4D4D9AD7, 0x33336655, 0x85851194,
264
-    0x45458ACF, 0xF9F9E910, 0x02020406, 0x7F7FFE81, 0x5050A0F0, 0x3C3C7844, 0x9F9F25BA, 0xA8A84BE3,
265
-    0x5151A2F3, 0xA3A35DFE, 0x404080C0, 0x8F8F058A, 0x92923FAD, 0x9D9D21BC, 0x38387048, 0xF5F5F104,
266
-    0xBCBC63DF, 0xB6B677C1, 0xDADAAF75, 0x21214263, 0x10102030, 0xFFFFE51A, 0xF3F3FD0E, 0xD2D2BF6D,
267
-    0xCDCD814C, 0x0C0C1814, 0x13132635, 0xECECC32F, 0x5F5FBEE1, 0x979735A2, 0x444488CC, 0x17172E39,
268
-    0xC4C49357, 0xA7A755F2, 0x7E7EFC82, 0x3D3D7A47, 0x6464C8AC, 0x5D5DBAE7, 0x1919322B, 0x7373E695,
269
-    0x6060C0A0, 0x81811998, 0x4F4F9ED1, 0xDCDCA37F, 0x22224466, 0x2A2A547E, 0x90903BAB, 0x88880B83,
270
-    0x46468CCA, 0xEEEEC729, 0xB8B86BD3, 0x1414283C, 0xDEDEA779, 0x5E5EBCE2, 0x0B0B161D, 0xDBDBAD76,
271
-    0xE0E0DB3B, 0x32326456, 0x3A3A744E, 0x0A0A141E, 0x494992DB, 0x06060C0A, 0x2424486C, 0x5C5CB8E4,
272
-    0xC2C29F5D, 0xD3D3BD6E, 0xACAC43EF, 0x6262C4A6, 0x919139A8, 0x959531A4, 0xE4E4D337, 0x7979F28B,
273
-    0xE7E7D532, 0xC8C88B43, 0x37376E59, 0x6D6DDAB7, 0x8D8D018C, 0xD5D5B164, 0x4E4E9CD2, 0xA9A949E0,
274
-    0x6C6CD8B4, 0x5656ACFA, 0xF4F4F307, 0xEAEACF25, 0x6565CAAF, 0x7A7AF48E, 0xAEAE47E9, 0x08081018,
275
-    0xBABA6FD5, 0x7878F088, 0x25254A6F, 0x2E2E5C72, 0x1C1C3824, 0xA6A657F1, 0xB4B473C7, 0xC6C69751,
276
-    0xE8E8CB23, 0xDDDDA17C, 0x7474E89C, 0x1F1F3E21, 0x4B4B96DD, 0xBDBD61DC, 0x8B8B0D86, 0x8A8A0F85,
277
-    0x7070E090, 0x3E3E7C42, 0xB5B571C4, 0x6666CCAA, 0x484890D8, 0x03030605, 0xF6F6F701, 0x0E0E1C12,
278
-    0x6161C2A3, 0x35356A5F, 0x5757AEF9, 0xB9B969D0, 0x86861791, 0xC1C19958, 0x1D1D3A27, 0x9E9E27B9,
279
-    0xE1E1D938, 0xF8F8EB13, 0x98982BB3, 0x11112233, 0x6969D2BB, 0xD9D9A970, 0x8E8E0789, 0x949433A7,
280
-    0x9B9B2DB6, 0x1E1E3C22, 0x87871592, 0xE9E9C920, 0xCECE8749, 0x5555AAFF, 0x28285078, 0xDFDFA57A,
281
-    0x8C8C038F, 0xA1A159F8, 0x89890980, 0x0D0D1A17, 0xBFBF65DA, 0xE6E6D731, 0x424284C6, 0x6868D0B8,
282
-    0x414182C3, 0x999929B0, 0x2D2D5A77, 0x0F0F1E11, 0xB0B07BCB, 0x5454A8FC, 0xBBBB6DD6, 0x16162C3A};
283
-
284
-const uint32_t TestTable3[256] __attribute((aligned(16))) = {
285
-    0x63C6A563, 0x7CF8847C, 0x77EE9977, 0x7BF68D7B, 0xF2FF0DF2, 0x6BD6BD6B, 0x6FDEB16F, 0xC59154C5,
286
-    0x30605030, 0x01020301, 0x67CEA967, 0x2B567D2B, 0xFEE719FE, 0xD7B562D7, 0xAB4DE6AB, 0x76EC9A76,
287
-    0xCA8F45CA, 0x821F9D82, 0xC98940C9, 0x7DFA877D, 0xFAEF15FA, 0x59B2EB59, 0x478EC947, 0xF0FB0BF0,
288
-    0xAD41ECAD, 0xD4B367D4, 0xA25FFDA2, 0xAF45EAAF, 0x9C23BF9C, 0xA453F7A4, 0x72E49672, 0xC09B5BC0,
289
-    0xB775C2B7, 0xFDE11CFD, 0x933DAE93, 0x264C6A26, 0x366C5A36, 0x3F7E413F, 0xF7F502F7, 0xCC834FCC,
290
-    0x34685C34, 0xA551F4A5, 0xE5D134E5, 0xF1F908F1, 0x71E29371, 0xD8AB73D8, 0x31625331, 0x152A3F15,
291
-    0x04080C04, 0xC79552C7, 0x23466523, 0xC39D5EC3, 0x18302818, 0x9637A196, 0x050A0F05, 0x9A2FB59A,
292
-    0x070E0907, 0x12243612, 0x801B9B80, 0xE2DF3DE2, 0xEBCD26EB, 0x274E6927, 0xB27FCDB2, 0x75EA9F75,
293
-    0x09121B09, 0x831D9E83, 0x2C58742C, 0x1A342E1A, 0x1B362D1B, 0x6EDCB26E, 0x5AB4EE5A, 0xA05BFBA0,
294
-    0x52A4F652, 0x3B764D3B, 0xD6B761D6, 0xB37DCEB3, 0x29527B29, 0xE3DD3EE3, 0x2F5E712F, 0x84139784,
295
-    0x53A6F553, 0xD1B968D1, 0x00000000, 0xEDC12CED, 0x20406020, 0xFCE31FFC, 0xB179C8B1, 0x5BB6ED5B,
296
-    0x6AD4BE6A, 0xCB8D46CB, 0xBE67D9BE, 0x39724B39, 0x4A94DE4A, 0x4C98D44C, 0x58B0E858, 0xCF854ACF,
297
-    0xD0BB6BD0, 0xEFC52AEF, 0xAA4FE5AA, 0xFBED16FB, 0x4386C543, 0x4D9AD74D, 0x33665533, 0x85119485,
298
-    0x458ACF45, 0xF9E910F9, 0x02040602, 0x7FFE817F, 0x50A0F050, 0x3C78443C, 0x9F25BA9F, 0xA84BE3A8,
299
-    0x51A2F351, 0xA35DFEA3, 0x4080C040, 0x8F058A8F, 0x923FAD92, 0x9D21BC9D, 0x38704838, 0xF5F104F5,
300
-    0xBC63DFBC, 0xB677C1B6, 0xDAAF75DA, 0x21426321, 0x10203010, 0xFFE51AFF, 0xF3FD0EF3, 0xD2BF6DD2,
301
-    0xCD814CCD, 0x0C18140C, 0x13263513, 0xECC32FEC, 0x5FBEE15F, 0x9735A297, 0x4488CC44, 0x172E3917,
302
-    0xC49357C4, 0xA755F2A7, 0x7EFC827E, 0x3D7A473D, 0x64C8AC64, 0x5DBAE75D, 0x19322B19, 0x73E69573,
303
-    0x60C0A060, 0x81199881, 0x4F9ED14F, 0xDCA37FDC, 0x22446622, 0x2A547E2A, 0x903BAB90, 0x880B8388,
304
-    0x468CCA46, 0xEEC729EE, 0xB86BD3B8, 0x14283C14, 0xDEA779DE, 0x5EBCE25E, 0x0B161D0B, 0xDBAD76DB,
305
-    0xE0DB3BE0, 0x32645632, 0x3A744E3A, 0x0A141E0A, 0x4992DB49, 0x060C0A06, 0x24486C24, 0x5CB8E45C,
306
-    0xC29F5DC2, 0xD3BD6ED3, 0xAC43EFAC, 0x62C4A662, 0x9139A891, 0x9531A495, 0xE4D337E4, 0x79F28B79,
307
-    0xE7D532E7, 0xC88B43C8, 0x376E5937, 0x6DDAB76D, 0x8D018C8D, 0xD5B164D5, 0x4E9CD24E, 0xA949E0A9,
308
-    0x6CD8B46C, 0x56ACFA56, 0xF4F307F4, 0xEACF25EA, 0x65CAAF65, 0x7AF48E7A, 0xAE47E9AE, 0x08101808,
309
-    0xBA6FD5BA, 0x78F08878, 0x254A6F25, 0x2E5C722E, 0x1C38241C, 0xA657F1A6, 0xB473C7B4, 0xC69751C6,
310
-    0xE8CB23E8, 0xDDA17CDD, 0x74E89C74, 0x1F3E211F, 0x4B96DD4B, 0xBD61DCBD, 0x8B0D868B, 0x8A0F858A,
311
-    0x70E09070, 0x3E7C423E, 0xB571C4B5, 0x66CCAA66, 0x4890D848, 0x03060503, 0xF6F701F6, 0x0E1C120E,
312
-    0x61C2A361, 0x356A5F35, 0x57AEF957, 0xB969D0B9, 0x86179186, 0xC19958C1, 0x1D3A271D, 0x9E27B99E,
313
-    0xE1D938E1, 0xF8EB13F8, 0x982BB398, 0x11223311, 0x69D2BB69, 0xD9A970D9, 0x8E07898E, 0x9433A794,
314
-    0x9B2DB69B, 0x1E3C221E, 0x87159287, 0xE9C920E9, 0xCE8749CE, 0x55AAFF55, 0x28507828, 0xDFA57ADF,
315
-    0x8C038F8C, 0xA159F8A1, 0x89098089, 0x0D1A170D, 0xBF65DABF, 0xE6D731E6, 0x4284C642, 0x68D0B868,
316
-    0x4182C341, 0x9929B099, 0x2D5A772D, 0x0F1E110F, 0xB07BCBB0, 0x54A8FC54, 0xBB6DD6BB, 0x162C3A16};
317
-
318
-const uint32_t TestTable4[256] __attribute((aligned(16))) = {
319
-    0xC6A56363, 0xF8847C7C, 0xEE997777, 0xF68D7B7B, 0xFF0DF2F2, 0xD6BD6B6B, 0xDEB16F6F, 0x9154C5C5,
320
-    0x60503030, 0x02030101, 0xCEA96767, 0x567D2B2B, 0xE719FEFE, 0xB562D7D7, 0x4DE6ABAB, 0xEC9A7676,
321
-    0x8F45CACA, 0x1F9D8282, 0x8940C9C9, 0xFA877D7D, 0xEF15FAFA, 0xB2EB5959, 0x8EC94747, 0xFB0BF0F0,
322
-    0x41ECADAD, 0xB367D4D4, 0x5FFDA2A2, 0x45EAAFAF, 0x23BF9C9C, 0x53F7A4A4, 0xE4967272, 0x9B5BC0C0,
323
-    0x75C2B7B7, 0xE11CFDFD, 0x3DAE9393, 0x4C6A2626, 0x6C5A3636, 0x7E413F3F, 0xF502F7F7, 0x834FCCCC,
324
-    0x685C3434, 0x51F4A5A5, 0xD134E5E5, 0xF908F1F1, 0xE2937171, 0xAB73D8D8, 0x62533131, 0x2A3F1515,
325
-    0x080C0404, 0x9552C7C7, 0x46652323, 0x9D5EC3C3, 0x30281818, 0x37A19696, 0x0A0F0505, 0x2FB59A9A,
326
-    0x0E090707, 0x24361212, 0x1B9B8080, 0xDF3DE2E2, 0xCD26EBEB, 0x4E692727, 0x7FCDB2B2, 0xEA9F7575,
327
-    0x121B0909, 0x1D9E8383, 0x58742C2C, 0x342E1A1A, 0x362D1B1B, 0xDCB26E6E, 0xB4EE5A5A, 0x5BFBA0A0,
328
-    0xA4F65252, 0x764D3B3B, 0xB761D6D6, 0x7DCEB3B3, 0x527B2929, 0xDD3EE3E3, 0x5E712F2F, 0x13978484,
329
-    0xA6F55353, 0xB968D1D1, 0x00000000, 0xC12CEDED, 0x40602020, 0xE31FFCFC, 0x79C8B1B1, 0xB6ED5B5B,
330
-    0xD4BE6A6A, 0x8D46CBCB, 0x67D9BEBE, 0x724B3939, 0x94DE4A4A, 0x98D44C4C, 0xB0E85858, 0x854ACFCF,
331
-    0xBB6BD0D0, 0xC52AEFEF, 0x4FE5AAAA, 0xED16FBFB, 0x86C54343, 0x9AD74D4D, 0x66553333, 0x11948585,
332
-    0x8ACF4545, 0xE910F9F9, 0x04060202, 0xFE817F7F, 0xA0F05050, 0x78443C3C, 0x25BA9F9F, 0x4BE3A8A8,
333
-    0xA2F35151, 0x5DFEA3A3, 0x80C04040, 0x058A8F8F, 0x3FAD9292, 0x21BC9D9D, 0x70483838, 0xF104F5F5,
334
-    0x63DFBCBC, 0x77C1B6B6, 0xAF75DADA, 0x42632121, 0x20301010, 0xE51AFFFF, 0xFD0EF3F3, 0xBF6DD2D2,
335
-    0x814CCDCD, 0x18140C0C, 0x26351313, 0xC32FECEC, 0xBEE15F5F, 0x35A29797, 0x88CC4444, 0x2E391717,
336
-    0x9357C4C4, 0x55F2A7A7, 0xFC827E7E, 0x7A473D3D, 0xC8AC6464, 0xBAE75D5D, 0x322B1919, 0xE6957373,
337
-    0xC0A06060, 0x19988181, 0x9ED14F4F, 0xA37FDCDC, 0x44662222, 0x547E2A2A, 0x3BAB9090, 0x0B838888,
338
-    0x8CCA4646, 0xC729EEEE, 0x6BD3B8B8, 0x283C1414, 0xA779DEDE, 0xBCE25E5E, 0x161D0B0B, 0xAD76DBDB,
339
-    0xDB3BE0E0, 0x64563232, 0x744E3A3A, 0x141E0A0A, 0x92DB4949, 0x0C0A0606, 0x486C2424, 0xB8E45C5C,
340
-    0x9F5DC2C2, 0xBD6ED3D3, 0x43EFACAC, 0xC4A66262, 0x39A89191, 0x31A49595, 0xD337E4E4, 0xF28B7979,
341
-    0xD532E7E7, 0x8B43C8C8, 0x6E593737, 0xDAB76D6D, 0x018C8D8D, 0xB164D5D5, 0x9CD24E4E, 0x49E0A9A9,
342
-    0xD8B46C6C, 0xACFA5656, 0xF307F4F4, 0xCF25EAEA, 0xCAAF6565, 0xF48E7A7A, 0x47E9AEAE, 0x10180808,
343
-    0x6FD5BABA, 0xF0887878, 0x4A6F2525, 0x5C722E2E, 0x38241C1C, 0x57F1A6A6, 0x73C7B4B4, 0x9751C6C6,
344
-    0xCB23E8E8, 0xA17CDDDD, 0xE89C7474, 0x3E211F1F, 0x96DD4B4B, 0x61DCBDBD, 0x0D868B8B, 0x0F858A8A,
345
-    0xE0907070, 0x7C423E3E, 0x71C4B5B5, 0xCCAA6666, 0x90D84848, 0x06050303, 0xF701F6F6, 0x1C120E0E,
346
-    0xC2A36161, 0x6A5F3535, 0xAEF95757, 0x69D0B9B9, 0x17918686, 0x9958C1C1, 0x3A271D1D, 0x27B99E9E,
347
-    0xD938E1E1, 0xEB13F8F8, 0x2BB39898, 0x22331111, 0xD2BB6969, 0xA970D9D9, 0x07898E8E, 0x33A79494,
348
-    0x2DB69B9B, 0x3C221E1E, 0x15928787, 0xC920E9E9, 0x8749CECE, 0xAAFF5555, 0x50782828, 0xA57ADFDF,
349
-    0x038F8C8C, 0x59F8A1A1, 0x09808989, 0x1A170D0D, 0x65DABFBF, 0xD731E6E6, 0x84C64242, 0xD0B86868,
350
-    0x82C34141, 0x29B09999, 0x5A772D2D, 0x1E110F0F, 0x7BCBB0B0, 0xA8FC5454, 0x6DD6BBBB, 0x2C3A1616};
351
-
352
-    
353
-void mul64to128(uint8_t *op1, uint8_t *op2, uint8_t *dst)
354
-{
355
-    uint64_t hi = ((uint64_t *)op1)[0];
356
-    uint64_t lo = ((uint64_t *)op2)[0];
357
-
358
-    uint64_t u1 = (hi & 0xffffffff);
359
-    uint64_t v1 = (lo & 0xffffffff);
360
-    uint64_t t = (u1 * v1);
361
-    uint64_t w3 = (t & 0xffffffff);
362
-    uint64_t k = (t >> 32);
363
-
364
-    hi >>= 32;
365
-    t = (hi * v1) + k;
366
-    k = (t & 0xffffffff);
367
-    v1 = (t >> 32);
368
-
369
-    lo >>= 32;
370
-    t = (u1 * lo) + k;
371
-    k = (t >> 32);
372
-
373
-    hi = (hi * lo) + v1 + k;
374
-    lo = (t << 32) + w3;
375
-    
376
-    ((uint64_t *)dst)[0] = hi;
377
-    ((uint64_t *)dst)[1] = lo;
378
-}
379
-
380
-void sum_xor_dst(const uint8_t *a, uint8_t *c, uint8_t *dst)
381
-{
382
-    uint64_t hi = ((uint64_t *)a)[0];
383
-    uint64_t lo = ((uint64_t *)a)[1];
384
-    
385
-    lo += ((uint64_t *)c)[1];
386
-    hi += ((uint64_t *)c)[0];
387
-    
388
-    ((uint64_t *)c)[0] = ((uint64_t *)dst)[0] ^ hi;
389
-    ((uint64_t *)c)[1] = ((uint64_t *)dst)[1] ^ lo;
390
-    ((uint64_t *)dst)[0] = hi;
391
-    ((uint64_t *)dst)[1] = lo;
392
-}
393
-
394
-void xor_blocks(uint8_t *a, const uint8_t *b)
395
-{
396
-    ((uint64_t *)a)[0] ^= ((uint64_t *)b)[0];
397
-    ((uint64_t *)a)[1] ^= ((uint64_t *)b)[1];
398
-}
399
-
400
-void SubAndShiftAndMixAddRound(uint32_t *out, uint8_t *temp, uint32_t *AesEncKey)
401
-{
402
-    out[0] = TestTable1[temp[0]] ^ TestTable2[temp[5]] ^ TestTable3[temp[10]] ^ TestTable4[temp[15]] ^ AesEncKey[0];
403
-    out[1] = TestTable4[temp[3]] ^ TestTable1[temp[4]] ^ TestTable2[temp[9]] ^ TestTable3[temp[14]] ^ AesEncKey[1];
404
-    out[2] = TestTable3[temp[2]] ^ TestTable4[temp[7]] ^ TestTable1[temp[8]] ^ TestTable2[temp[13]] ^ AesEncKey[2];
405
-    out[3] = TestTable2[temp[1]] ^ TestTable3[temp[6]] ^ TestTable4[temp[11]] ^ TestTable1[temp[12]] ^ AesEncKey[3];
406
-}
407
-
408
-void SubAndShiftAndMixAddRoundInPlace(uint32_t *temp, uint32_t *AesEncKey)
409
-{
410
-    uint8_t *state = (uint8_t *)&temp[0];
411
-    uint8_t saved[6];
412
-
413
-    saved[0] = state[3];
414
-    saved[1] = state[2];
415
-    saved[2] = state[7];
416
-    saved[3] = state[1];
417
-    saved[4] = state[6];
418
-    saved[5] = state[11];
419
-
420
-    temp[0] = TestTable1[state[0]] ^ TestTable2[state[5]] ^ TestTable3[state[10]] ^ TestTable4[state[15]] ^ AesEncKey[0];
421
-    temp[1] = TestTable4[saved[0]] ^ TestTable1[state[4]] ^ TestTable2[state[9]] ^ TestTable3[state[14]] ^ AesEncKey[1];
422
-    temp[2] = TestTable3[saved[1]] ^ TestTable4[saved[2]] ^ TestTable1[state[8]] ^ TestTable2[state[13]] ^ AesEncKey[2];
423
-    temp[3] = TestTable2[saved[3]] ^ TestTable3[saved[4]] ^ TestTable4[saved[5]] ^ TestTable1[state[12]] ^ AesEncKey[3];
424
-}
425
-
426
-void cryptonight_hash_ctx(void *output, const void *input, size_t len, struct cryptonight_ctx *ctx, int variant)
427
-{
428
-    ctx->aes_ctx = (oaes_ctx *)oaes_alloc();
429
-    size_t i, j;
430
-
431
-    keccak((const uint8_t *)input, len, ctx->state.hs.b, 200);
432
-    memcpy(ctx->text, ctx->state.init, INIT_SIZE_BYTE);
433
-    
434
-    VARIANT1_INIT64();
435
-    VARIANT2_INIT64();
436
-    
437
-    oaes_key_import_data(ctx->aes_ctx, ctx->state.hs.b, AES_KEY_SIZE);
438
-    
439
-    for (i = 0; likely(i < MEMORY); i += INIT_SIZE_BYTE)
440
-    {
441
-        for (j = 0; j < 10; j++)
442
-        {
443
-            uint32_t *ptr = (uint32_t *)&ctx->aes_ctx->key->exp_data[j << 4];
444
-
445
-            SubAndShiftAndMixAddRoundInPlace((uint32_t *)&ctx->text[0], ptr);
446
-            SubAndShiftAndMixAddRoundInPlace((uint32_t *)&ctx->text[0x10], ptr);
447
-            SubAndShiftAndMixAddRoundInPlace((uint32_t *)&ctx->text[0x20], ptr);
448
-            SubAndShiftAndMixAddRoundInPlace((uint32_t *)&ctx->text[0x30], ptr);
449
-            SubAndShiftAndMixAddRoundInPlace((uint32_t *)&ctx->text[0x40], ptr);
450
-            SubAndShiftAndMixAddRoundInPlace((uint32_t *)&ctx->text[0x50], ptr);
451
-            SubAndShiftAndMixAddRoundInPlace((uint32_t *)&ctx->text[0x60], ptr);
452
-            SubAndShiftAndMixAddRoundInPlace((uint32_t *)&ctx->text[0x70], ptr);
453
-        }
454
-        memcpy(&ctx->long_state[i], ctx->text, INIT_SIZE_BYTE);
455
-    }
456
-
457
-    for (i = 0; i < 2; i++)
458
-    {
459
-        ((uint64_t *)(ctx->a))[i] = ((uint64_t *)ctx->state.k)[i] ^ ((uint64_t *)ctx->state.k)[i + 4];
460
-        ((uint64_t *)(ctx->b))[i] = ((uint64_t *)ctx->state.k)[i + 2] ^ ((uint64_t *)ctx->state.k)[i + 6];
461
-    }
462
-
463
-    if (variant == 0) 
464
-    {
465
-        for (i = 0; likely(i < ITER / 4); ++i)
466
-        { 
467
-            j = ((uint32_t *)(ctx->a))[0] & 0x1FFFF0;
468
-            SubAndShiftAndMixAddRound((uint32_t *)ctx->c, &ctx->long_state[j], (uint32_t *)ctx->a);
469
-            xor_blocks_dst(ctx->c, ctx->b, &ctx->long_state[j]);
470
-               
471
-            j = ((uint32_t *)ctx->c)[0] & 0x1FFFF0;
472
-            mul64to128(ctx->c, &ctx->long_state[j], ctx->e);
473
-            sum_xor_dst(ctx->e, ctx->a, &ctx->long_state[j]);
474
-            
475
-            j = ((uint32_t *)(ctx->a))[0] & 0x1FFFF0;
476
-            SubAndShiftAndMixAddRound((uint32_t *)ctx->b, &ctx->long_state[j], (uint32_t *)ctx->a);
477
-            xor_blocks_dst(ctx->b, ctx->c, &ctx->long_state[j]); 
478
-            
479
-            j = ((uint32_t *)ctx->b)[0] & 0x1FFFF0;
480
-            mul64to128(ctx->b, &ctx->long_state[j], ctx->e);
481
-            sum_xor_dst(ctx->e, ctx->a, &ctx->long_state[j]);
482
-        }
483
-    }
484
-    else if(variant == 1)
485
-    {
486
-        for (i = 0; likely(i < ITER / 4); ++i)
487
-        { 
488
-            j = ((uint32_t *)(ctx->a))[0] & 0x1FFFF0;
489
-            SubAndShiftAndMixAddRound((uint32_t *)ctx->c, &ctx->long_state[j], (uint32_t *)ctx->a);
490
-            xor_blocks_dst(ctx->c, ctx->b, &ctx->long_state[j]);
491
-            VARIANT1_1(&ctx->long_state[j]);
492
-              
493
-            j = ((uint32_t *)ctx->c)[0] & 0x1FFFF0; 
494
-            mul64to128(ctx->c, &ctx->long_state[j], ctx->e);
495
-            sum_xor_dst(ctx->e, ctx->a, &ctx->long_state[j]);
496
-            VARIANT1_2(&ctx->long_state[j] + 8);
497
-            
498
-            j = ((uint32_t *)(ctx->a))[0] & 0x1FFFF0;
499
-            SubAndShiftAndMixAddRound((uint32_t *)ctx->b, &ctx->long_state[j], (uint32_t *)ctx->a);
500
-            xor_blocks_dst(ctx->b, ctx->c, &ctx->long_state[j]); 
501
-            VARIANT1_1(&ctx->long_state[j]);
502
-            
503
-            j = ((uint32_t *)ctx->b)[0] & 0x1FFFF0;
504
-            mul64to128(ctx->b, &ctx->long_state[j], ctx->e);
505
-            sum_xor_dst(ctx->e, ctx->a, &ctx->long_state[j]);
506
-            VARIANT1_2(&ctx->long_state[j] + 8);
507
-        }
508
-    }
509
-    else
510
-    {
511
-        for (i = 0; likely(i < ITER / 4); ++i)
512
-        {
513
-            j = ((uint32_t *)(ctx->a))[0] & 0x1FFFF0;
514
-            VARIANT2_PORTABLE_SHUFFLE_ADD1(ctx->long_state, j);
515
-            SubAndShiftAndMixAddRound((uint32_t *)ctx->c, &ctx->long_state[j], (uint32_t *)ctx->a);
516
-            xor_blocks_dst(ctx->c, ctx->b, &ctx->long_state[j]);
517
-               
518
-            j = ((uint32_t *)ctx->c)[0] & 0x1FFFF0;
519
-            VARIANT2_PORTABLE_INTEGER_MATH(&ctx->long_state[j], ctx->c);  
520
-            mul64to128(ctx->c, &ctx->long_state[j], ctx->e);
521
-	    VARIANT2_2_PORTABLE();
522
-            VARIANT2_PORTABLE_SHUFFLE_ADD1(ctx->long_state, j);
523
-            sum_xor_dst(ctx->e, ctx->a, &ctx->long_state[j]);
524
-            copy_block(ctx->d, ctx->b); 
525
-            
526
-            j = ((uint32_t *)(ctx->a))[0] & 0x1FFFF0;
527
-            VARIANT2_PORTABLE_SHUFFLE_ADD2(ctx->long_state, j);
528
-            SubAndShiftAndMixAddRound((uint32_t *)ctx->b, &ctx->long_state[j], (uint32_t *)ctx->a);
529
-            xor_blocks_dst(ctx->b, ctx->c, &ctx->long_state[j]); 
530
-            
531
-            j = ((uint32_t *)ctx->b)[0] & 0x1FFFF0;
532
-            VARIANT2_PORTABLE_INTEGER_MATH(&ctx->long_state[j], ctx->b);
533
-            mul64to128(ctx->b, &ctx->long_state[j], ctx->e);
534
-	    VARIANT2_2_PORTABLE();
535
-            VARIANT2_PORTABLE_SHUFFLE_ADD2(ctx->long_state, j);
536
-            sum_xor_dst(ctx->e, ctx->a, &ctx->long_state[j]);
537
-            copy_block(ctx->d, ctx->c); 
538
-        }
539
-    }
540
-
541
-    memcpy(ctx->text, ctx->state.init, INIT_SIZE_BYTE);
542
-
543
-    oaes_free((OAES_CTX **)&ctx->aes_ctx);
544
-    ctx->aes_ctx = (oaes_ctx *)oaes_alloc();
545
-
546
-    oaes_key_import_data(ctx->aes_ctx, &ctx->state.hs.b[32], AES_KEY_SIZE);
547
-
548
-    for (i = 0; likely(i < MEMORY); i += INIT_SIZE_BYTE)
549
-    {
550
-        xor_blocks(&ctx->text[0x00], &ctx->long_state[i + 0x00]);
551
-        xor_blocks(&ctx->text[0x10], &ctx->long_state[i + 0x10]);
552
-        xor_blocks(&ctx->text[0x20], &ctx->long_state[i + 0x20]);
553
-        xor_blocks(&ctx->text[0x30], &ctx->long_state[i + 0x30]);
554
-        xor_blocks(&ctx->text[0x40], &ctx->long_state[i + 0x40]);
555
-        xor_blocks(&ctx->text[0x50], &ctx->long_state[i + 0x50]);
556
-        xor_blocks(&ctx->text[0x60], &ctx->long_state[i + 0x60]);
557
-        xor_blocks(&ctx->text[0x70], &ctx->long_state[i + 0x70]);
558
-
559
-        for (j = 0; j < 10; j++)
560
-        {
561
-            uint32_t *ptr = (uint32_t *)&ctx->aes_ctx->key->exp_data[j << 4];
562
-
563
-            SubAndShiftAndMixAddRoundInPlace((uint32_t *)&ctx->text[0], ptr);
564
-            SubAndShiftAndMixAddRoundInPlace((uint32_t *)&ctx->text[0x10], ptr);
565
-            SubAndShiftAndMixAddRoundInPlace((uint32_t *)&ctx->text[0x20], ptr);
566
-            SubAndShiftAndMixAddRoundInPlace((uint32_t *)&ctx->text[0x30], ptr);
567
-            SubAndShiftAndMixAddRoundInPlace((uint32_t *)&ctx->text[0x40], ptr);
568
-            SubAndShiftAndMixAddRoundInPlace((uint32_t *)&ctx->text[0x50], ptr);
569
-            SubAndShiftAndMixAddRoundInPlace((uint32_t *)&ctx->text[0x60], ptr);
570
-            SubAndShiftAndMixAddRoundInPlace((uint32_t *)&ctx->text[0x70], ptr);
571
-        }
572
-    }
573
-
574
-    memcpy(ctx->state.init, ctx->text, INIT_SIZE_BYTE);
575
-    keccakf((uint64_t *)ctx->state.hs.b, 24);
576
-    extra_hashes[ctx->state.hs.b[0] & 3](&ctx->state, 200, output);
577
-    oaes_free((OAES_CTX **)&ctx->aes_ctx);
578
-}
579
-
580
-void cryptonight_hash_ctx_lite(void *output, const void *input, size_t len, struct cryptonight_ctx_lite *ctx, int variant)
581
-{
582
-    ctx->aes_ctx = (oaes_ctx *)oaes_alloc();
583
-    size_t i, j;
584
-
585
-    keccak((const uint8_t *)input, len, ctx->state.hs.b, 200);
586
-    memcpy(ctx->text, ctx->state.init, INIT_SIZE_BYTE);
587
-    
588
-    VARIANT1_INIT64();
589
-    VARIANT2_INIT64();
590
-    
591
-    oaes_key_import_data(ctx->aes_ctx, ctx->state.hs.b, AES_KEY_SIZE);
592
-    
593
-    for (i = 0; likely(i < MEMORY/2); i += INIT_SIZE_BYTE)
594
-    {
595
-        for (j = 0; j < 10; j++)
596
-        {
597
-            uint32_t *ptr = (uint32_t *)&ctx->aes_ctx->key->exp_data[j << 4];
598
-
599
-            SubAndShiftAndMixAddRoundInPlace((uint32_t *)&ctx->text[0], ptr);
600
-            SubAndShiftAndMixAddRoundInPlace((uint32_t *)&ctx->text[0x10], ptr);
601
-            SubAndShiftAndMixAddRoundInPlace((uint32_t *)&ctx->text[0x20], ptr);
602
-            SubAndShiftAndMixAddRoundInPlace((uint32_t *)&ctx->text[0x30], ptr);
603
-            SubAndShiftAndMixAddRoundInPlace((uint32_t *)&ctx->text[0x40], ptr);
604
-            SubAndShiftAndMixAddRoundInPlace((uint32_t *)&ctx->text[0x50], ptr);
605
-            SubAndShiftAndMixAddRoundInPlace((uint32_t *)&ctx->text[0x60], ptr);
606
-            SubAndShiftAndMixAddRoundInPlace((uint32_t *)&ctx->text[0x70], ptr);
607
-        }
608
-        memcpy(&ctx->long_state[i], ctx->text, INIT_SIZE_BYTE);
609
-    }
610
-
611
-    for (i = 0; i < 2; i++)
612
-    {
613
-        ((uint64_t *)(ctx->a))[i] = ((uint64_t *)ctx->state.k)[i] ^ ((uint64_t *)ctx->state.k)[i + 4];
614
-        ((uint64_t *)(ctx->b))[i] = ((uint64_t *)ctx->state.k)[i + 2] ^ ((uint64_t *)ctx->state.k)[i + 6];
615
-    }
616
-
617
-    if (variant == 0) 
618
-    {
619
-        for (i = 0; likely(i < ITER / 8); ++i)
620
-        { 
621
-            j = ((uint32_t *)(ctx->a))[0] & 0x0FFFF0;
622
-            SubAndShiftAndMixAddRound((uint32_t *)ctx->c, &ctx->long_state[j], (uint32_t *)ctx->a);
623
-            xor_blocks_dst(ctx->c, ctx->b, &ctx->long_state[j]);
624
-               
625
-            j = ((uint32_t *)ctx->c)[0] & 0x0FFFF0;
626
-            mul64to128(ctx->c, &ctx->long_state[j], ctx->e);
627
-            sum_xor_dst(ctx->e, ctx->a, &ctx->long_state[j]);
628
-            
629
-            j = ((uint32_t *)(ctx->a))[0] & 0x0FFFF0;
630
-            SubAndShiftAndMixAddRound((uint32_t *)ctx->b, &ctx->long_state[j], (uint32_t *)ctx->a);
631
-            xor_blocks_dst(ctx->b, ctx->c, &ctx->long_state[j]); 
632
-            
633
-            j = ((uint32_t *)ctx->b)[0] & 0x0FFFF0;
634
-            mul64to128(ctx->b, &ctx->long_state[j], ctx->e);
635
-            sum_xor_dst(ctx->e, ctx->a, &ctx->long_state[j]);
636
-        }
637
-    }
638
-    else if(variant == 1)
639
-    {
640
-        for (i = 0; likely(i < ITER / 8); ++i)
641
-        { 
642
-            j = ((uint32_t *)(ctx->a))[0] & 0x0FFFF0;
643
-            SubAndShiftAndMixAddRound((uint32_t *)ctx->c, &ctx->long_state[j], (uint32_t *)ctx->a);
644
-            xor_blocks_dst(ctx->c, ctx->b, &ctx->long_state[j]);
645
-            VARIANT1_1(&ctx->long_state[j]);
646
-              
647
-            j = ((uint32_t *)ctx->c)[0] & 0x0FFFF0; 
648
-            mul64to128(ctx->c, &ctx->long_state[j], ctx->e);
649
-            sum_xor_dst(ctx->e, ctx->a, &ctx->long_state[j]);
650
-            VARIANT1_2(&ctx->long_state[j] + 8);
651
-            
652
-            j = ((uint32_t *)(ctx->a))[0] & 0x0FFFF0;
653
-            SubAndShiftAndMixAddRound((uint32_t *)ctx->b, &ctx->long_state[j], (uint32_t *)ctx->a);
654
-            xor_blocks_dst(ctx->b, ctx->c, &ctx->long_state[j]); 
655
-            VARIANT1_1(&ctx->long_state[j]);
656
-            
657
-            j = ((uint32_t *)ctx->b)[0] & 0x0FFFF0;
658
-            mul64to128(ctx->b, &ctx->long_state[j], ctx->e);
659
-            sum_xor_dst(ctx->e, ctx->a, &ctx->long_state[j]);
660
-            VARIANT1_2(&ctx->long_state[j] + 8);
661
-        }
662
-    }
663
-    else
664
-    {
665
-        for (i = 0; likely(i < ITER / 8); ++i)
666
-        {
667
-            j = ((uint32_t *)(ctx->a))[0] & 0x0FFFF0;
668
-            VARIANT2_PORTABLE_SHUFFLE_ADD1(ctx->long_state, j);
669
-            SubAndShiftAndMixAddRound((uint32_t *)ctx->c, &ctx->long_state[j], (uint32_t *)ctx->a);
670
-            xor_blocks_dst(ctx->c, ctx->b, &ctx->long_state[j]);
671
-               
672
-            j = ((uint32_t *)ctx->c)[0] & 0x0FFFF0;
673
-            VARIANT2_PORTABLE_INTEGER_MATH(&ctx->long_state[j], ctx->c);  
674
-            mul64to128(ctx->c, &ctx->long_state[j], ctx->e);
675
-	    VARIANT2_2_PORTABLE();
676
-            VARIANT2_PORTABLE_SHUFFLE_ADD1(ctx->long_state, j);
677
-            sum_xor_dst(ctx->e, ctx->a, &ctx->long_state[j]);
678
-            copy_block(ctx->d, ctx->b); 
679
-            
680
-            j = ((uint32_t *)(ctx->a))[0] & 0x0FFFF0;
681
-            VARIANT2_PORTABLE_SHUFFLE_ADD2(ctx->long_state, j);
682
-            SubAndShiftAndMixAddRound((uint32_t *)ctx->b, &ctx->long_state[j], (uint32_t *)ctx->a);
683
-            xor_blocks_dst(ctx->b, ctx->c, &ctx->long_state[j]); 
684
-            
685
-            j = ((uint32_t *)ctx->b)[0] & 0x0FFFF0;
686
-            VARIANT2_PORTABLE_INTEGER_MATH(&ctx->long_state[j], ctx->b);
687
-            mul64to128(ctx->b, &ctx->long_state[j], ctx->e);
688
-	    VARIANT2_2_PORTABLE();
689
-            VARIANT2_PORTABLE_SHUFFLE_ADD2(ctx->long_state, j);
690
-            sum_xor_dst(ctx->e, ctx->a, &ctx->long_state[j]);
691
-            copy_block(ctx->d, ctx->c); 
692
-        }
693
-    }
694
-
695
-    memcpy(ctx->text, ctx->state.init, INIT_SIZE_BYTE);
696
-
697
-    oaes_free((OAES_CTX **)&ctx->aes_ctx);
698
-    ctx->aes_ctx = (oaes_ctx *)oaes_alloc();
699
-
700
-    oaes_key_import_data(ctx->aes_ctx, &ctx->state.hs.b[32], AES_KEY_SIZE);
701
-
702
-    for (i = 0; likely(i < MEMORY/2); i += INIT_SIZE_BYTE)
703
-    {
704
-        xor_blocks(&ctx->text[0x00], &ctx->long_state[i + 0x00]);
705
-        xor_blocks(&ctx->text[0x10], &ctx->long_state[i + 0x10]);
706
-        xor_blocks(&ctx->text[0x20], &ctx->long_state[i + 0x20]);
707
-        xor_blocks(&ctx->text[0x30], &ctx->long_state[i + 0x30]);
708
-        xor_blocks(&ctx->text[0x40], &ctx->long_state[i + 0x40]);
709
-        xor_blocks(&ctx->text[0x50], &ctx->long_state[i + 0x50]);
710
-        xor_blocks(&ctx->text[0x60], &ctx->long_state[i + 0x60]);
711
-        xor_blocks(&ctx->text[0x70], &ctx->long_state[i + 0x70]);
712
-
713
-        for (j = 0; j < 10; j++)
714
-        {
715
-            uint32_t *ptr = (uint32_t *)&ctx->aes_ctx->key->exp_data[j << 4];
716
-
717
-            SubAndShiftAndMixAddRoundInPlace((uint32_t *)&ctx->text[0], ptr);
718
-            SubAndShiftAndMixAddRoundInPlace((uint32_t *)&ctx->text[0x10], ptr);
719
-            SubAndShiftAndMixAddRoundInPlace((uint32_t *)&ctx->text[0x20], ptr);
720
-            SubAndShiftAndMixAddRoundInPlace((uint32_t *)&ctx->text[0x30], ptr);
721
-            SubAndShiftAndMixAddRoundInPlace((uint32_t *)&ctx->text[0x40], ptr);
722
-            SubAndShiftAndMixAddRoundInPlace((uint32_t *)&ctx->text[0x50], ptr);
723
-            SubAndShiftAndMixAddRoundInPlace((uint32_t *)&ctx->text[0x60], ptr);
724
-            SubAndShiftAndMixAddRoundInPlace((uint32_t *)&ctx->text[0x70], ptr);
725
-        }
726
-    }
727
-
728
-    memcpy(ctx->state.init, ctx->text, INIT_SIZE_BYTE);
729
-    keccakf((uint64_t *)ctx->state.hs.b, 24);
730
-    extra_hashes[ctx->state.hs.b[0] & 3](&ctx->state, 200, output);
731
-    oaes_free((OAES_CTX **)&ctx->aes_ctx);
732
-}
733
-
734
-void cryptonight(void *output, const void *input, size_t len, int lite, int variant)
735
-{
736
-    if(lite)
737
-    {
738
-        struct cryptonight_ctx_lite *ctx = (struct cryptonight_ctx_lite *)malloc(sizeof(struct cryptonight_ctx_lite));
739
-        cryptonight_hash_ctx_lite(output, input, len, ctx, variant);
740
-        free(ctx);
741
-    }
742
-    else
743
-    {
744
-        struct cryptonight_ctx *ctx = (struct cryptonight_ctx *)malloc(sizeof(struct cryptonight_ctx));
745
-        cryptonight_hash_ctx(output, input, len, ctx, variant);
746
-        free(ctx);
747
-    }
748
-
749
-}

+ 0
- 15
hash_cn/libhash/cryptonight.h View File

@@ -1,15 +0,0 @@
1
-#ifndef CRYPTONIGHT_H
2
-#define CRYPTONIGHT_H
3
-
4
-#ifdef __cplusplus
5
-extern "C" {
6
-#endif
7
-
8
-void cryptonight(void *output, const void *input, size_t len, int lite, int variant);
9
-struct cryptonight_ctx;
10
-
11
-#ifdef __cplusplus
12
-}
13
-#endif
14
-
15
-#endif

+ 0
- 393
hash_cn/libhash/groestl.c View File

@@ -1,393 +0,0 @@
1
-/* hash.c     April 2012
2
- * Groestl ANSI C code optimised for 32-bit machines
3
- * Author: Thomas Krinninger
4
- *
5
- *  This work is based on the implementation of
6
- *          Soeren S. Thomsen and Krystian Matusiewicz
7
- *          
8
- *
9
- */
10
-
11
-#include <stdint.h>
12
-#include "groestl_tables.h"
13
-
14
-typedef unsigned char BitSequence;
15
-typedef unsigned long long DataLength;
16
-typedef enum {SUCCESS = 0, FAIL = 1, BAD_HASHLEN = 2} HashReturn;
17
-
18
-/* some sizes (number of bytes) */
19
-#define ROWS 8
20
-#define LENGTHFIELDLEN ROWS
21
-#define COLS512 8
22
-
23
-#define SIZE512 (ROWS*COLS512)
24
-
25
-#define ROUNDS512 10
26
-#define HASH_BIT_LEN 256
27
-
28
-#define ROTL32(v, n) ((((v)<<(n))|((v)>>(32-(n))))&li_32(ffffffff))
29
-
30
-#define li_32(h) 0x##h##u
31
-#define EXT_BYTE(var,n) ((uint8_t)((uint32_t)(var) >> (8*n)))
32
-#define u32BIG(a)				\
33
-  ((ROTL32(a,8) & li_32(00FF00FF)) |		\
34
-   (ROTL32(a,24) & li_32(FF00FF00)))
35
-
36
-/* NIST API begin */
37
-typedef struct {
38
-  uint32_t chaining[SIZE512/sizeof(uint32_t)];            /* actual state */
39
-  uint32_t block_counter1,
40
-  block_counter2;         /* message block counter(s) */
41
-  BitSequence buffer[SIZE512];      /* data buffer */
42
-  int buf_ptr;              /* data buffer pointer */
43
-  int bits_in_last_byte;    /* no. of message bits in last byte of
44
-			       data buffer */
45
-} groestlHashState;
46
-
47
-#define P_TYPE 0
48
-#define Q_TYPE 1
49
-
50
-const uint8_t shift_Values[2][8] = {{0,1,2,3,4,5,6,7},{1,3,5,7,0,2,4,6}};
51
-
52
-const uint8_t indices_cyclic[15] = {0,1,2,3,4,5,6,7,0,1,2,3,4,5,6};
53
-
54
-
55
-#define ROTATE_COLUMN_DOWN(v1, v2, amount_bytes, temp_var) {temp_var = (v1<<(8*amount_bytes))|(v2>>(8*(4-amount_bytes))); \
56
-															v2 = (v2<<(8*amount_bytes))|(v1>>(8*(4-amount_bytes))); \
57
-															v1 = temp_var;}
58
-  
59
-
60
-#define COLUMN(x,y,i,c0,c1,c2,c3,c4,c5,c6,c7,tv1,tv2,tu,tl,t)				\
61
-   tu = T[2*(uint32_t)x[4*c0+0]];			    \
62
-   tl = T[2*(uint32_t)x[4*c0+0]+1];		    \
63
-   tv1 = T[2*(uint32_t)x[4*c1+1]];			\
64
-   tv2 = T[2*(uint32_t)x[4*c1+1]+1];			\
65
-   ROTATE_COLUMN_DOWN(tv1,tv2,1,t)	\
66
-   tu ^= tv1;						\
67
-   tl ^= tv2;						\
68
-   tv1 = T[2*(uint32_t)x[4*c2+2]];			\
69
-   tv2 = T[2*(uint32_t)x[4*c2+2]+1];			\
70
-   ROTATE_COLUMN_DOWN(tv1,tv2,2,t)	\
71
-   tu ^= tv1;						\
72
-   tl ^= tv2;   					\
73
-   tv1 = T[2*(uint32_t)x[4*c3+3]];			\
74
-   tv2 = T[2*(uint32_t)x[4*c3+3]+1];			\
75
-   ROTATE_COLUMN_DOWN(tv1,tv2,3,t)	\
76
-   tu ^= tv1;						\
77
-   tl ^= tv2;						\
78
-   tl ^= T[2*(uint32_t)x[4*c4+0]];			\
79
-   tu ^= T[2*(uint32_t)x[4*c4+0]+1];			\
80
-   tv1 = T[2*(uint32_t)x[4*c5+1]];			\
81
-   tv2 = T[2*(uint32_t)x[4*c5+1]+1];			\
82
-   ROTATE_COLUMN_DOWN(tv1,tv2,1,t)	\
83
-   tl ^= tv1;						\
84
-   tu ^= tv2;						\
85
-   tv1 = T[2*(uint32_t)x[4*c6+2]];			\
86
-   tv2 = T[2*(uint32_t)x[4*c6+2]+1];			\
87
-   ROTATE_COLUMN_DOWN(tv1,tv2,2,t)	\
88
-   tl ^= tv1;						\
89
-   tu ^= tv2;   					\
90
-   tv1 = T[2*(uint32_t)x[4*c7+3]];			\
91
-   tv2 = T[2*(uint32_t)x[4*c7+3]+1];			\
92
-   ROTATE_COLUMN_DOWN(tv1,tv2,3,t)	\
93
-   tl ^= tv1;						\
94
-   tu ^= tv2;						\
95
-   y[i] = tu;						\
96
-   y[i+1] = tl;
97
-
98
-
99
-/* compute one round of P (short variants) */
100
-static void RND512P(uint8_t *x, uint32_t *y, uint32_t r) {
101
-  uint32_t temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp;
102
-  uint32_t* x32 = (uint32_t*)x;
103
-  x32[ 0] ^= 0x00000000^r;
104
-  x32[ 2] ^= 0x00000010^r;
105
-  x32[ 4] ^= 0x00000020^r;
106
-  x32[ 6] ^= 0x00000030^r;
107
-  x32[ 8] ^= 0x00000040^r;
108
-  x32[10] ^= 0x00000050^r;
109
-  x32[12] ^= 0x00000060^r;
110
-  x32[14] ^= 0x00000070^r;
111
-  COLUMN(x,y, 0,  0,  2,  4,  6,  9, 11, 13, 15, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp);
112
-  COLUMN(x,y, 2,  2,  4,  6,  8, 11, 13, 15,  1, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp);
113
-  COLUMN(x,y, 4,  4,  6,  8, 10, 13, 15,  1,  3, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp);
114
-  COLUMN(x,y, 6,  6,  8, 10, 12, 15,  1,  3,  5, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp);
115
-  COLUMN(x,y, 8,  8, 10, 12, 14,  1,  3,  5,  7, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp);
116
-  COLUMN(x,y,10, 10, 12, 14,  0,  3,  5,  7,  9, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp);
117
-  COLUMN(x,y,12, 12, 14,  0,  2,  5,  7,  9, 11, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp);
118
-  COLUMN(x,y,14, 14,  0,  2,  4,  7,  9, 11, 13, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp);
119
-}
120
-
121
-/* compute one round of Q (short variants) */
122
-static void RND512Q(uint8_t *x, uint32_t *y, uint32_t r) {
123
-  uint32_t temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp;
124
-  uint32_t* x32 = (uint32_t*)x;
125
-  x32[ 0] = ~x32[ 0];
126
-  x32[ 1] ^= 0xffffffff^r;
127
-  x32[ 2] = ~x32[ 2];
128
-  x32[ 3] ^= 0xefffffff^r;
129
-  x32[ 4] = ~x32[ 4];
130
-  x32[ 5] ^= 0xdfffffff^r;
131
-  x32[ 6] = ~x32[ 6];
132
-  x32[ 7] ^= 0xcfffffff^r;
133
-  x32[ 8] = ~x32[ 8];
134
-  x32[ 9] ^= 0xbfffffff^r;
135
-  x32[10] = ~x32[10];
136
-  x32[11] ^= 0xafffffff^r;
137
-  x32[12] = ~x32[12];
138
-  x32[13] ^= 0x9fffffff^r;
139
-  x32[14] = ~x32[14];
140
-  x32[15] ^= 0x8fffffff^r;
141
-  COLUMN(x,y, 0,  2,  6, 10, 14,  1,  5,  9, 13, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp);
142
-  COLUMN(x,y, 2,  4,  8, 12,  0,  3,  7, 11, 15, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp);
143
-  COLUMN(x,y, 4,  6, 10, 14,  2,  5,  9, 13,  1, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp);
144
-  COLUMN(x,y, 6,  8, 12,  0,  4,  7, 11, 15,  3, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp);
145
-  COLUMN(x,y, 8, 10, 14,  2,  6,  9, 13,  1,  5, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp);
146
-  COLUMN(x,y,10, 12,  0,  4,  8, 11, 15,  3,  7, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp);
147
-  COLUMN(x,y,12, 14,  2,  6, 10, 13,  1,  5,  9, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp);
148
-  COLUMN(x,y,14,  0,  4,  8, 12, 15,  3,  7, 11, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp);
149
-}
150
-
151
-/* compute compression function (short variants) */
152
-static void F512(uint32_t *h, const uint32_t *m) {
153
-  int i;
154
-  uint32_t Ptmp[2*COLS512];
155
-  uint32_t Qtmp[2*COLS512];
156
-  uint32_t y[2*COLS512];
157
-  uint32_t z[2*COLS512];
158
-
159
-  for (i = 0; i < 2*COLS512; i++) {
160
-	z[i] = m[i];
161
-	Ptmp[i] = h[i]^m[i];
162
-  }
163
-
164
-  /* compute Q(m) */
165
-  RND512Q((uint8_t*)z, y, 0x00000000);
166
-  RND512Q((uint8_t*)y, z, 0x01000000);
167
-  RND512Q((uint8_t*)z, y, 0x02000000);
168
-  RND512Q((uint8_t*)y, z, 0x03000000);
169
-  RND512Q((uint8_t*)z, y, 0x04000000);
170
-  RND512Q((uint8_t*)y, z, 0x05000000);
171
-  RND512Q((uint8_t*)z, y, 0x06000000);
172
-  RND512Q((uint8_t*)y, z, 0x07000000);
173
-  RND512Q((uint8_t*)z, y, 0x08000000);
174
-  RND512Q((uint8_t*)y, Qtmp, 0x09000000);
175
-
176
-  /* compute P(h+m) */
177
-  RND512P((uint8_t*)Ptmp, y, 0x00000000);
178
-  RND512P((uint8_t*)y, z, 0x00000001);
179
-  RND512P((uint8_t*)z, y, 0x00000002);
180
-  RND512P((uint8_t*)y, z, 0x00000003);
181
-  RND512P((uint8_t*)z, y, 0x00000004);
182
-  RND512P((uint8_t*)y, z, 0x00000005);
183
-  RND512P((uint8_t*)z, y, 0x00000006);
184
-  RND512P((uint8_t*)y, z, 0x00000007);
185
-  RND512P((uint8_t*)z, y, 0x00000008);
186
-  RND512P((uint8_t*)y, Ptmp, 0x00000009);
187
-
188
-  /* compute P(h+m) + Q(m) + h */
189
-  for (i = 0; i < 2*COLS512; i++) {
190
-	h[i] ^= Ptmp[i]^Qtmp[i];
191
-  }
192
-}
193
-
194
-
195
-/* digest up to msglen bytes of input (full blocks only) */
196
-static void Transform(groestlHashState *ctx,
197
-	       const uint8_t *input, 
198
-	       int msglen) {
199
-
200
-  /* digest message, one block at a time */
201
-  for (; msglen >= SIZE512; 
202
-	   msglen -= SIZE512, input += SIZE512) {
203
-	F512(ctx->chaining,(uint32_t*)input);
204
-
205
-	/* increment block counter */
206
-	ctx->block_counter1++;
207
-	if (ctx->block_counter1 == 0) ctx->block_counter2++;
208
-  }
209
-}
210
-
211
-/* given state h, do h <- P(h)+h */
212
-static void OutputTransformation(groestlHashState *ctx) {
213
-  int j;
214
-  uint32_t temp[2*COLS512];
215
-  uint32_t y[2*COLS512];
216
-  uint32_t z[2*COLS512];
217
-
218
-
219
-
220
-	for (j = 0; j < 2*COLS512; j++) {
221
-	  temp[j] = ctx->chaining[j];
222
-	}
223
-	RND512P((uint8_t*)temp, y, 0x00000000);
224
-	RND512P((uint8_t*)y, z, 0x00000001);
225
-	RND512P((uint8_t*)z, y, 0x00000002);
226
-	RND512P((uint8_t*)y, z, 0x00000003);
227
-	RND512P((uint8_t*)z, y, 0x00000004);
228
-	RND512P((uint8_t*)y, z, 0x00000005);
229
-	RND512P((uint8_t*)z, y, 0x00000006);
230
-	RND512P((uint8_t*)y, z, 0x00000007);
231
-	RND512P((uint8_t*)z, y, 0x00000008);
232
-	RND512P((uint8_t*)y, temp, 0x00000009);
233
-	for (j = 0; j < 2*COLS512; j++) {
234
-	  ctx->chaining[j] ^= temp[j];
235
-	}									  
236
-}
237
-
238
-/* initialise context */
239
-static void Init(groestlHashState* ctx) {
240
-  int i = 0;
241
-  /* allocate memory for state and data buffer */
242
-
243
-  for(;i<(SIZE512/sizeof(uint32_t));i++)
244
-  {
245
-	ctx->chaining[i] = 0;
246
-  }
247
-
248
-  /* set initial value */
249
-  ctx->chaining[2*COLS512-1] = u32BIG((uint32_t)HASH_BIT_LEN);
250
-
251
-  /* set other variables */
252
-  ctx->buf_ptr = 0;
253
-  ctx->block_counter1 = 0;
254
-  ctx->block_counter2 = 0;
255
-  ctx->bits_in_last_byte = 0;
256
-}
257
-
258
-/* update state with databitlen bits of input */
259
-static void Update(groestlHashState* ctx,
260
-		  const BitSequence* input,
261
-		  DataLength databitlen) {
262
-  int index = 0;
263
-  int msglen = (int)(databitlen/8);
264
-  int rem = (int)(databitlen%8);
265
-
266
-  /* if the buffer contains data that has not yet been digested, first
267
-	 add data to buffer until full */
268
-  if (ctx->buf_ptr) {
269
-	while (ctx->buf_ptr < SIZE512 && index < msglen) {
270
-	  ctx->buffer[(int)ctx->buf_ptr++] = input[index++];
271
-	}
272
-	if (ctx->buf_ptr < SIZE512) {
273
-	  /* buffer still not full, return */
274
-	  if (rem) {
275
-	ctx->bits_in_last_byte = rem;
276
-	ctx->buffer[(int)ctx->buf_ptr++] = input[index];
277
-	  }
278
-	  return;
279
-	}
280
-
281
-	/* digest buffer */
282
-	ctx->buf_ptr = 0;
283
-	Transform(ctx, ctx->buffer, SIZE512);
284
-  }
285
-
286
-  /* digest bulk of message */
287
-  Transform(ctx, input+index, msglen-index);
288
-  index += ((msglen-index)/SIZE512)*SIZE512;
289
-
290
-  /* store remaining data in buffer */
291
-  while (index < msglen) {
292
-	ctx->buffer[(int)ctx->buf_ptr++] = input[index++];
293
-  }
294
-
295
-  /* if non-integral number of bytes have been supplied, store
296
-	 remaining bits in last byte, together with information about
297
-	 number of bits */
298
-  if (rem) {
299
-	ctx->bits_in_last_byte = rem;
300
-	ctx->buffer[(int)ctx->buf_ptr++] = input[index];
301
-  }
302
-}
303
-
304
-#define BILB ctx->bits_in_last_byte
305
-
306
-/* finalise: process remaining data (including padding), perform
307
-   output transformation, and write hash result to 'output' */
308
-static void Final(groestlHashState* ctx,
309
-		 BitSequence* output) {
310
-  int i, j = 0, hashbytelen = HASH_BIT_LEN/8;
311
-  uint8_t *s = (BitSequence*)ctx->chaining;
312
-
313
-  /* pad with '1'-bit and first few '0'-bits */
314