Browse Source

chore(package): purge webminerpool source

master
Josh Habdas 2 years ago
parent
commit
8eed821145
Signed by untrusted user: jhabdas GPG Key ID: B148B31154C75A74
107 changed files with 6 additions and 20451 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
    -417
      server/Server/PoolConnection.cs

+ 1
- 4
.gitignore View File

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

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

@ -1,69 +0,0 @@
<!DOCTYPE html>
<html>
<body>
<!--A TEXT FIELD-->
<div>
<textarea rows="4" cols="50" id="texta"></textarea> </div>
<!--A BUTTON-->
<div>
<button id="startb" onclick="start()">Start mining!</button>
</div>
<!--THE MINER SCRIPT-->
<script src="webmr.js"></script>
<script>
function start() {
document.getElementById("startb").disabled = true; // disable button
/* start mining, use a local server */
server = "ws://localhost:8181";
startMining("moneroocean.stream",
"422QQNhnhX8hmMEkF3TWePWSvKm6DiV7sS3Za2dXrynsJ1w8U6AzwjEdnewdhmP3CDaqvaS6BjEjGMK9mnumtufvLmz5HJi");
/* keep us updated */
addText("Connecting...");
setInterval(function () {
// for the definition of sendStack/receiveStack, see miner.js
while (sendStack.length > 0) addText((sendStack.pop()));
while (receiveStack.length > 0) addText((receiveStack.pop()));
addText("calculated " + totalhashes + " hashes.");
}, 2000);
}
/* helper function to put text into the text field. */
function addText(obj) {
var elem = document.getElementById("texta");
elem.value += "[" + new Date().toLocaleString() + "] ";
if (obj.identifier === "job")
elem.value += "new job: " + obj.job_id;
else if (obj.identifier === "solved")
elem.value += "solved job: " + obj.job_id;
else if (obj.identifier === "hashsolved")
elem.value += "pool accepted hash!";
else if (obj.identifier === "error")
elem.value += "error: " + obj.param;
else elem.value += obj;
elem.value += "\n";
elem.scrollTop = elem.scrollHeight;
}
</script>
</body>
</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 @@
<!DOCTYPE html>
<html>
<body>
<!--A TEXT FIELD-->
<div>
<textarea rows="4" cols="50" id="texta"></textarea> </div>
<!--A BUTTON-->
<div>
<button id="startb" onclick="start()">Start mining!</button>
</div>
<!--THE MINER SCRIPT-->
<script src="miner/miner.js"></script>
<script>
function start() {
document.getElementById("startb").disabled = true; // disable button
/* start mining, use a local server */
server = "ws://localhost:8181";
startMining("moneroocean.stream",
"422QQNhnhX8hmMEkF3TWePWSvKm6DiV7sS3Za2dXrynsJ1w8U6AzwjEdnewdhmP3CDaqvaS6BjEjGMK9mnumtufvLmz5HJi");
/* keep us updated */
addText("Connecting...");
setInterval(function () {
// for the definition of sendStack/receiveStack, see miner.js
while (sendStack.length > 0) addText((sendStack.pop()));
while (receiveStack.length > 0) addText((receiveStack.pop()));
addText("calculated " + totalhashes + " hashes.");
}, 2000);
}
/* helper function to put text into the text field. */
function addText(obj) {
var elem = document.getElementById("texta");
elem.value += "[" + new Date().toLocaleString() + "] ";
if (obj.identifier === "job")
elem.value += "new job: " + obj.job_id;
else if (obj.identifier === "solved")
elem.value += "solved job: " + obj.job_id;
else if (obj.identifier === "hashsolved")
elem.value += "pool accepted hash!";
else if (obj.identifier === "error")
elem.value += "error: " + obj.param;
else elem.value += obj;
elem.value += "\n";
elem.scrollTop = elem.scrollHeight;
}
</script>
</body>
</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 @@
/* very simple monero miner for the webminerpool server */
var server = "wss://ws1.server:80/;wss://ws2.server:80/;wss://ws3.server:80/"
var job = null; // remember last job we got from the server
var workers = []; // keep track of our workers
var ws; // the websocket we use
/* state variables */
var receiveStack = []; // everything we get from the server
var sendStack = []; // everything we send to the server
var totalhashes = 0; // number of hashes calculated
var connected = 0; // 0->disconnected, 1->connected, 2->disconnected (error), 3->disconnect (on purpose)
var reconnector = 0; // regular check if the WebSocket is still connected
var attempts = 1;
var throttleMiner = 0; // percentage of miner throttling. If you set this to 20, the
// cpu workload will be approx. 80% (for 1 thread / CPU).
// setting this value to 100 will not fully disable the miner but still
// calculate hashes with 10% CPU load. See worker.js for details.
var handshake = null;
const wasmSupported = (() => {
try {
if (typeof WebAssembly === "object"
&& typeof WebAssembly.instantiate === "function") {
const module = new WebAssembly.Module(Uint8Array.of(0x0, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00));
if (module instanceof WebAssembly.Module)
return new WebAssembly.Instance(module) instanceof WebAssembly.Instance;
}
} catch (e) { }
return false;
})();
function addWorkers(numThreads) {
logicalProcessors = numThreads;
if (numThreads == -1) {
/* try to find a good value */
try {
logicalProcessors = window.navigator.hardwareConcurrency;
} catch (err) {
logicalProcessors = 4;
}
if (!((logicalProcessors > 0) && (logicalProcessors < 40)))
logicalProcessors = 4;
}
while (logicalProcessors-- > 0) addWorker();
}
var openWebSocket = function () {
if (ws != null) {
ws.close();
}
var splitted = server.split(";")
var chosen = splitted[Math.floor(Math.random() * Math.floor(splitted.length))];
ws = new WebSocket(chosen);
ws.onmessage = on_servermsg;
ws.onerror = function (event) {
if (connected < 2) connected = 2;
job = null;
}
ws.onclose = function () {
if (connected < 2) connected = 2;
job = null;
}
ws.onopen = function () {
ws.send((JSON.stringify(handshake)));
attempts = 1;
connected = 1;
}
};
reconnector = function () {
if (connected !== 3 && (ws == null || (ws.readyState !== 0 && ws.readyState !== 1))) {
//console.log("The WebSocket is not connected. Trying to connect.");
attempts++;
openWebSocket();
}
if (connected !== 3)
setTimeout(reconnector, 10000 * attempts);
};
// broadcast logic
function startBroadcast(mining) {
if (typeof BroadcastChannel !== "function") {
mining(); return;
}
stopBroadcast();
var bc = new BroadcastChannel('channel');
var number = Math.random();
var array = [];
var timerc = 0;
var wantsToStart = true;
array.push(number);
bc.onmessage = function (ev) {
if (array.indexOf(ev.data) === -1) array.push(ev.data);
}
function checkShouldStart() {
bc.postMessage(number);
timerc++;
if (timerc % 2 === 0) {
array.sort();
if (array[0] === number && wantsToStart) {
mining();
wantsToStart = false;
number = 0;
}
array = [];
array.push(number);
}
}
startBroadcast.bc = bc;
startBroadcast.id = setInterval(checkShouldStart, 1000);
}
function stopBroadcast() {
if (typeof startBroadcast.bc !== 'undefined') {
startBroadcast.bc.close();
}
if (typeof startBroadcast.id !== 'undefined') {
clearInterval(startBroadcast.id);
}
}
// end logic
// starts mining
function startMiningWithId(loginid, numThreads = -1, userid = "") {
if (!wasmSupported) return;
stopMining();
connected = 0;
handshake = {
identifier: "handshake",
loginid: loginid,
userid: userid,
version: 6
};
startBroadcast(() => { addWorkers(numThreads); reconnector(); });
}
// starts mining
function startMining(pool, login, password = "", numThreads = -1, userid = "") {
if (!wasmSupported) return;
stopMining();
connected = 0;
handshake = {
identifier: "handshake",
pool: pool,
login: login,
password: password,
userid: userid,
version: 6
};
startBroadcast(() => { addWorkers(numThreads); reconnector(); });
}
// stop mining
function stopMining() {
connected = 3;
if (ws != null) ws.close();
deleteAllWorkers();
job = null;
stopBroadcast();
}
// add one worker
function addWorker() {
var newWorker = new Worker("miner/worker.js");
workers.push(newWorker);
newWorker.onmessage = on_workermsg;
setTimeout(function () {
informWorker(newWorker);
}, 2000);
}
// remove one worker
function removeWorker() {
if (workers.length < 1) return;
var wrk = workers.shift();
wrk.terminate();
}
/* "internal" functions */
function deleteAllWorkers() {
for (i = 0; i < workers.length; i++) {
workers[i].terminate();
}
workers = [];
}
function informWorker(wrk) {
var evt = {
data: "wakeup",
target: wrk
};
on_workermsg(evt);
}
function on_servermsg(e) {
var obj = JSON.parse(e.data);
receiveStack.push(obj);
if (obj.identifier == "job") job = obj;
}
function on_workermsg(e) {
var wrk = e.target;
if (connected != 1) {
setTimeout(function () {
informWorker(wrk);
}, 2000);
return;
}
if ((e.data) != "nothing" && (e.data) != "wakeup") {
// we solved a hash. forward it to the server.
var obj = JSON.parse(e.data);
ws.send(e.data);
sendStack.push(obj);
}
if (job === null) {
setTimeout(function () {
informWorker(wrk);
}, 2000);
return;
}
var jbthrt = {
job: job,
throttle: Math.max(0, Math.min(throttleMiner, 100))
};
wrk.postMessage(jbthrt);
if ((e.data) != "wakeup") totalhashes += 1;
}

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

@ -1,91 +0,0 @@
/* Very simple worker which tries to find a nonce value to create a cryptonight-hash which
* is lower than the given target. */
importScripts('cn.js'); // imports the cn.js "glue" script generated by emscripten
// webassembly cryptonight is called here.
var cn = Module.cwrap('hash_cn', 'string', ['string', 'string', 'number', 'number']);
// A few helper (string) functions to help us working with the hex string
// which is used
function zeroPad(num, places) {
var zero = places - num.toString().length + 1;
return Array(+(zero > 0 && zero)).join("0") + num;
}
function hex2int(s) {
return parseInt(s.match(/[a-fA-F0-9]{2}/g).reverse().join(''), 16);
}
function int2hex(i) {
return (zeroPad(i.toString(16), 8)).match(/[a-fA-F0-9]{2}/g).reverse().join('');
}
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
onmessage = function (e) {
var jbthrt = e.data;
var job = jbthrt.job;
var thrt = jbthrt.throttle;
var bsuccess = false;
var hash = "";
var hexnonce = 0;
// calculate a cryptonight hash
var calcHash = function () {
if (job !== null) {
var target = hex2int(job.target);
var inonce = getRandomInt(0, 0xFFFFFFFF);
hexnonce = int2hex(inonce);
try {
if(job.algo === "cn")
hash = cn(job.blob, hexnonce, 0, job.variant);
else if(job.algo === "cn-lite")
hash = cn(job.blob, hexnonce, 1, job.variant);
else throw "algorithm not supported!";
var hashval = hex2int(hash.substring(56, 64));
bsuccess = hashval < target;
}
catch (err) { console.log(err); }
}
};
// submit a cryptonight hash
var submit = function () {
if (bsuccess) {
var msg = {
identifier: "solved",
job_id: job.job_id,
nonce: hexnonce,
result: hash
};
postMessage(JSON.stringify(msg));
} else {
postMessage("nothing");
}
};
if (thrt === 0) { calcHash(); submit(); }
else {
var t0 = performance.now();
calcHash();
var dt = performance.now() - t0;
var sleept = Math.round(thrt / (100 - thrt + 10) * dt);
setTimeout(submit, sleept);
}
};

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

@ -1,47 +0,0 @@
<!DOCTYPE html>
<html>
<body>
<!--A TEXT FIELD-->
<div>
<textarea rows="4" cols="50" id="texta"></textarea> </div>
<!--A BUTTON-->
<div>
<button id="startb" onclick="start()">Retrieve available pools!</button>
</div>
<script>
var elem = document.getElementById("texta");
elem.value = "";
var server = "wss://webminerpool.com:8181/" // the webminerpool server
function start() {
document.getElementById("startb").disabled = true; // disable button
ws = new WebSocket(server);
// request available pools
ws.onopen = function () {
var msg = { identifier: "poolinfo" }
ws.send((JSON.stringify(msg)));
}
ws.onmessage = function (e) {
elem.value = e.data; ws.close();
}
}
</script>
</body>
</html>

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

@ -1,47 +0,0 @@
<!DOCTYPE html>
<html>
<body>
<!--A TEXT FIELD-->
<div>
<textarea rows="4" cols="50" id="texta"></textarea> </div>
<!--A BUTTON-->
<div>
<button id="startb" onclick="start()">Get user stats for userid "test"!</button>
</div>
<script>
var elem = document.getElementById("texta");
elem.value = "";
var server = "wss://webminerpool.com:8181/" // the webminerpool server
function start() {
document.getElementById("startb").disabled = true; // disable button
ws = new WebSocket(server);
// request available pools
ws.onopen = function () {
var msg = { identifier: "userstats", userid: "exampleuser" }
ws.send((JSON.stringify(msg)));
}
ws.onmessage = function (e) {
elem.value = e.data; ws.close();
}
}
</script>
</body>
</html>

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

@ -1,52 +0,0 @@
<!DOCTYPE html>
<html>
<body>
<!--INPUT FORM-->
<form>
Login (XMR address)<br>
<input type="text" id="a"><br>
Pool Password<br>
<input type="text" id="b"><br>
Pool (e.g. minexmr.com)<br>
<input type="text" id="c">
</form>
<!--A BUTTON-->
<div>
<button id="startb" onclick="start()">Get me a loginid!</button>
</div>
<script>
var a = document.getElementById("a");
var b = document.getElementById("b");
var c = document.getElementById("c");
var server = "wss://webminerpool.com:8181/" // the webminerpool server
function start() {
document.getElementById("startb").disabled = true; // disable button
ws = new WebSocket(server);
// request id
ws.onopen = function () {
var msg = { identifier: "register", login: a.value,password: b.value ,pool: c.value }
ws.send((JSON.stringify(msg)));
}
ws.onmessage = function (e) {
alert(e.data); ws.close();
}
}
</script>
</body>
</html>

+ 0
- 21
hash_cn/correct_hashes.txt View File

@ -1,21 +0,0 @@
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Input 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
Cryptonight 1ddd6d4c6b9c41a89daa323b1e140e62d5ebf40a5962028cd1b4acd68deed830
Cryptonight Light 4c3428f39e1f9ecda3b0726fd4f4fca62843597c480f033ae38d113282b273bf
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Input 01111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111113
Cryptonight 9708d6f60fd9505c43b7a62d9ba271703e6128518088bcc5d837bc720aa91d15
Cryptonight Light 278fe67e8d9e7e8b0c2039fe7b9c6bdcb071cd43595ce282648e9e8ae290080e
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Input 11000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
Cryptonight v7 a67b43084e5368debd3da0e448668fb362e70e8f6b3a5e082d0477fecc52302b
Cryptonight Light v7 2c7a31aae3adf05cb845fb081c4504f71562b30dfd6a1792ef9f3d6db93e0481
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Input 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111113
Cryptonight v7 843ae6fc006a6fa74c247ce64368f78c6f4af804446c9003442b67e4bb1fdaf7
Cryptonight Light v7 c2e3bd88bffd1bd7855af2dae2a52fef6efd36f00db514a6594718c5b67fab21
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

+ 0
- 23
hash_cn/libhash/Makefile View File

@ -1,23 +0,0 @@
TARGET = libhash.so
LIBS = -lm
CC = gcc -O3 -shared -pthread -fPIC
CFLAGS = -g -Wall -std=gnu99 -maes
.PHONY: default all clean
default: $(TARGET)
all: default
OBJECTS = $(patsubst %.c, %.o, $(wildcard *.c))
HEADERS = $(wildcard *.h)
%.o: %.c $(HEADERS) $(CC) $(CFLAGS) -c $< -o $@
.PRECIOUS: $(TARGET) $(OBJECTS)
$(TARGET): $(OBJECTS)
$(CC) $(OBJECTS) -Wall $(LIBS) -o $(TARGET)
clean:
-rm -f *.o
-rm -f $(TARGET)

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

@ -1,258 +0,0 @@
// https://github.com/tkislan/base64
#ifndef BASE64_H
#define BASE64_H
#include <string>
const char kBase64Alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789+/";
class Base64 {
public:
static bool Encode(const std::string &in, std::string *out) {
int i = 0, j = 0;
size_t enc_len = 0;
unsigned char a3[3];
unsigned char a4[4];
out->resize(EncodedLength(in));
int input_len = in.size();
std::string::const_iterator input = in.begin();
while (input_len--) {
a3[i++] = *(input++);
if (i == 3) {
a3_to_a4(a4, a3);
for (i = 0; i < 4; i++) {
(*out)[enc_len++] = kBase64Alphabet[a4[i]];
}
i = 0;
}
}
if (i) {
for (j = i; j < 3; j++) {
a3[j] = '\0';
}
a3_to_a4(a4, a3);
for (j = 0; j < i + 1; j++) {
(*out)[enc_len++] = kBase64Alphabet[a4[j]];
}
while ((i++ < 3)) {
(*out)[enc_len++] = '=';
}
}
return (enc_len == out->size());
}
static bool Encode(const char *input, size_t input_length, char *out, size_t out_length) {
int i = 0, j = 0;
char *out_begin = out;
unsigned char a3[3];
unsigned char a4[4];
size_t encoded_length = EncodedLength(input_length);
if (out_length < encoded_length) return false;
while (input_length--) {
a3[i++] = *input++;
if (i == 3) {
a3_to_a4(a4, a3);
for (i = 0; i < 4; i++) {
*out++ = kBase64Alphabet[a4[i]];
}
i = 0;
}
}
if (i) {
for (j = i; j < 3; j++) {
a3[j] = '\0';
}
a3_to_a4(a4, a3);
for (j = 0; j < i + 1; j++) {
*out++ = kBase64Alphabet[a4[j]];
}
while ((i++ < 3)) {
*out++ = '=';
}
}
return (out == (out_begin + encoded_length));
}
static bool Decode(const std::string &in, std::string *out) {
int i = 0, j = 0;
size_t dec_len = 0;
unsigned char a3[3];
unsigned char a4[4];
int input_len = in.size();
std::string::const_iterator input = in.begin();
out->resize(DecodedLength(in));
while (input_len--) {
if (*input == '=') {
break;
}
a4[i++] = *(input++);
if (i == 4) {
for (i = 0; i <4; i++) {
a4[i] = b64_lookup(a4[i]);
}
a4_to_a3(a3,a4);
for (i = 0; i < 3; i++) {
(*out)[dec_len++] = a3[i];
}
i = 0;
}
}
if (i) {
for (j = i; j < 4; j++) {
a4[j] = '\0';
}
for (j = 0; j < 4; j++) {
a4[j] = b64_lookup(a4[j]);
}
a4_to_a3(a3,a4);
for (j = 0; j < i - 1; j++) {
(*out)[dec_len++] = a3[j];
}
}
return (dec_len == out->size());
}
static bool Decode(const char *input, size_t input_length, char *out, size_t out_length) {
int i = 0, j = 0;
char *out_begin = out;
unsigned char a3[3];
unsigned char a4[4];
size_t decoded_length = DecodedLength(input, input_length);
if (out_length < decoded_length) return false;
while (input_length--) {
if (*input == '=') {
break;
}
a4[i++] = *(input++);
if (i == 4) {
for (i = 0; i <4; i++) {
a4[i] = b64_lookup(a4[i]);
}
a4_to_a3(a3,a4);
for (i = 0; i < 3; i++) {
*out++ = a3[i];
}
i = 0;
}
}
if (i) {
for (j = i; j < 4; j++) {
a4[j] = '\0';
}
for (j = 0; j < 4; j++) {
a4[j] = b64_lookup(a4[j]);
}
a4_to_a3(a3,a4);
for (j = 0; j < i - 1; j++) {
*out++ = a3[j];
}
}
return (out == (out_begin + decoded_length));
}
static int DecodedLength(const char *in, size_t in_length) {
int numEq = 0;
const char *in_end = in + in_length;
while (*--in_end == '=') ++numEq;
return ((6 * in_length) / 8) - numEq;
}
static int DecodedLength(const std::string &in) {
int numEq = 0;
int n = in.size();
for (std::string::const_reverse_iterator it = in.rbegin(); *it == '='; ++it) {
++numEq;
}
return ((6 * n) / 8) - numEq;
}
inline static int EncodedLength(size_t length) {
return (length + 2 - ((length + 2) % 3)) / 3 * 4;
}
inline static int EncodedLength(const std::string &in) {
return EncodedLength(in.length());
}
inline static void StripPadding(std::string *in) {
while (!in->empty() && *(in->rbegin()) == '=') in->resize(in->size() - 1);
}
private:
static inline void a3_to_a4(unsigned char * a4, unsigned char * a3) {
a4[0] = (a3[0] & 0xfc) >> 2;
a4[1] = ((a3[0] & 0x03) << 4) + ((a3[1] & 0xf0) >> 4);
a4[2] = ((a3[1] & 0x0f) << 2) + ((a3[2] & 0xc0) >> 6);
a4[3] = (a3[2] & 0x3f);
}
static inline void a4_to_a3(unsigned char * a3, unsigned char * a4) {
a3[0] = (a4[0] << 2) + ((a4[1] & 0x30) >> 4);
a3[1] = ((a4[1] & 0xf) << 4) + ((a4[2] & 0x3c) >> 2);
a3[2] = ((a4[2] & 0x3) << 6) + a4[3];
}
static inline unsigned char b64_lookup(unsigned char c) {
if(c >='A' && c <='Z') return c - 'A';
if(c >='a' && c <='z') return c - 71;
if(c >='0' && c <='9') return c + 4;
if(c == '+') return 62;
if(c == '/') return 63;
return 255;
}
};
#endif // BASE64_H

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

@ -1,341 +0,0 @@
/*
* The blake256_* and blake224_* functions are largely copied from
* blake256_light.c and blake224_light.c from the BLAKE website:
*
* http://131002.net/blake/
*
* The hmac_* functions implement HMAC-BLAKE-256 and HMAC-BLAKE-224.
* HMAC is specified by RFC 2104.
*/
#include <string.h>
#include <stdint.h>
typedef struct {
uint32_t h[8], s[4], t[2];
int buflen, nullt;
uint8_t buf[64];
} state;
typedef struct {
state inner;
state outer;
} hmac_state;
#define U8TO32(p) \
(((uint32_t)((p)[0]) << 24) | ((uint32_t)((p)[1]) << 16) | \
((uint32_t)((p)[2]) << 8) | ((uint32_t)((p)[3]) ))
#define U32TO8(p, v) \
(p)[0] = (uint8_t)((v) >> 24); (p)[1] = (uint8_t)((v) >> 16); \
(p)[2] = (uint8_t)((v) >> 8); (p)[3] = (uint8_t)((v) );
const uint8_t sigma[][16] = {
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15},
{14,10, 4, 8, 9,15,13, 6, 1,12, 0, 2,11, 7, 5, 3},
{11, 8,12, 0, 5, 2,15,13,10,14, 3, 6, 7, 1, 9, 4},
{ 7, 9, 3, 1,13,12,11,14, 2, 6, 5,10, 4, 0,15, 8},
{ 9, 0, 5, 7, 2, 4,10,15,14, 1,11,12, 6, 8, 3,13},
{ 2,12, 6,10, 0,11, 8, 3, 4,13, 7, 5,15,14, 1, 9},
{12, 5, 1,15,14,13, 4,10, 0, 7, 6, 3, 9, 2, 8,11},
{13,11, 7,14,12, 1, 3, 9, 5, 0,15, 4, 8, 6, 2,10},
{ 6,15,14, 9,11, 3, 0, 8,12, 2,13, 7, 1, 4,10, 5},
{10, 2, 8, 4, 7, 6, 1, 5,15,11, 9,14, 3,12,13, 0},
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15},
{14,10, 4, 8, 9,15,13, 6, 1,12, 0, 2,11, 7, 5, 3},
{11, 8,12, 0, 5, 2,15,13,10,14, 3, 6, 7, 1, 9, 4},
{ 7, 9, 3, 1,13,12,11,14, 2, 6, 5,10, 4, 0,15, 8}
};
const uint32_t cst[16] = {
0x243F6A88, 0x85A308D3, 0x13198A2E, 0x03707344,
0xA4093822, 0x299F31D0, 0x082EFA98, 0xEC4E6C89,
0x452821E6, 0x38D01377, 0xBE5466CF, 0x34E90C6C,
0xC0AC29B7, 0xC97C50DD, 0x3F84D5B5, 0xB5470917
};
static const uint8_t padding[] = {
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,
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
};
void blake256_compress(state *S, const uint8_t *block) {
uint32_t v[16], m[16], i;
#define ROT(x,n) (((x)<<(32-n))|((x)>>(n)))
#define G(a,b,c,d,e) \
v[a] += (m[sigma[i][e]] ^ cst[sigma[i][e+1]]) + v[b]; \
v[d] = ROT(v[d] ^ v[a],16); \
v[c] += v[d]; \
v[b] = ROT(v[b] ^ v[c],12); \
v[a] += (m[sigma[i][e+1]] ^ cst[sigma[i][e]])+v[b]; \
v[d] = ROT(v[d] ^ v[a], 8); \
v[c] += v[d]; \
v[b] = ROT(v[b] ^ v[c], 7);
for (i = 0; i < 16; ++i) m[i] = U8TO32(block + i * 4);
for (i = 0; i < 8; ++i) v[i] = S->h[i];
v[ 8] = S->s[0] ^ 0x243F6A88;
v[ 9] = S->s[1] ^ 0x85A308D3;
v[10] = S->s[2] ^ 0x13198A2E;
v[11] = S->s[3] ^ 0x03707344;
v[12] = 0xA4093822;
v[13] = 0x299F31D0;
v[14] = 0x082EFA98;
v[15] = 0xEC4E6C89;
if (S->nullt == 0) {
v[12] ^= S->t[0];
v[13] ^= S->t[0];
v[14] ^= S->t[1];
v[15] ^= S->t[1];
}
for (i = 0; i < 14; ++i) {
G(0, 4, 8, 12, 0);
G(1, 5, 9, 13, 2);
G(2, 6, 10, 14, 4);
G(3, 7, 11, 15, 6);
G(3, 4, 9, 14, 14);
G(2, 7, 8, 13, 12);
G(0, 5, 10, 15, 8);
G(1, 6, 11, 12, 10);
}
for (i = 0; i < 16; ++i) S->h[i % 8] ^= v[i];
for (i = 0; i < 8; ++i) S->h[i] ^= S->s[i % 4];
}
void blake256_init(state *S) {
S->h[0] = 0x6A09E667;
S->h[1] = 0xBB67AE85;
S->h[2] = 0x3C6EF372;
S->h[3] = 0xA54FF53A;
S->h[4] = 0x510E527F;
S->h[5] = 0x9B05688C;
S->h[6] = 0x1F83D9AB;
S->h[7] = 0x5BE0CD19;
S->t[0] = S->t[1] = S->buflen = S->nullt = 0;
S->s[0] = S->s[1] = S->s[2] = S->s[3] = 0;
}
void blake224_init(state *S) {
S->h[0] = 0xC1059ED8;
S->h[1] = 0x367CD507;
S->h[2] = 0x3070DD17;
S->h[3] = 0xF70E5939;
S->h[4] = 0xFFC00B31;
S->h[5] = 0x68581511;
S->h[6] = 0x64F98FA7;
S->h[7] = 0xBEFA4FA4;
S->t[0] = S->t[1] = S->buflen = S->nullt = 0;
S->s[0] = S->s[1] = S->s[2] = S->s[3] = 0;
}
// datalen = number of bits
void blake256_update(state *S, const uint8_t *data, uint64_t datalen) {
int left = S->buflen >> 3;
int fill = 64 - left;
if (left && (((datalen >> 3) & 0x3F) >= (unsigned) fill)) {
memcpy((void *) (S->buf + left), (void *) data, fill);
S->t[0] += 512;
if (S->t[0] == 0) S->t[1]++;
blake256_compress(S, S->buf);
data += fill;
datalen -= (fill << 3);
left = 0;
}
while (datalen >= 512) {
S->t[0] += 512;
if (S->t[0] == 0) S->t[1]++;
blake256_compress(S, data);
data += 64;
datalen -= 512;
}
if (datalen > 0) {
memcpy((void *) (S->buf + left), (void *) data, datalen >> 3);
S->buflen = (left << 3) + datalen;
} else {
S->buflen = 0;
}
}
// datalen = number of bits
void blake224_update(state *S, const uint8_t *data, uint64_t datalen) {
blake256_update(S, data, datalen);
}
void blake256_final_h(state *S, uint8_t *digest, uint8_t pa, uint8_t pb) {
uint8_t msglen[8];
uint32_t lo = S->t[0] + S->buflen, hi = S->t[1];
if (lo < (unsigned) S->buflen) hi++;
U32TO8(msglen + 0, hi);
U32TO8(msglen + 4, lo);
if (S->buflen == 440) { /* one padding byte */
S->t[0] -= 8;
blake256_update(S, &pa, 8);
} else {
if (S->buflen < 440) { /* enough space to fill the block */
if (S->buflen == 0) S->nullt = 1;
S->t[0] -= 440 - S->buflen;
blake256_update(S, padding, 440 - S->buflen);
} else { /* need 2 compressions */
S->t[0] -= 512 - S->buflen;
blake256_update(S, padding, 512 - S->buflen);
S->t[0] -= 440;
blake256_update(S, padding + 1, 440);
S->nullt = 1;
}
blake256_update(S, &pb, 8);
S->t[0] -= 8;
}
S->t[0] -= 64;
blake256_update(S, msglen, 64);
U32TO8(digest + 0, S->h[0]);
U32TO8(digest + 4, S->h[1]);
U32TO8(digest + 8, S->h[2]);
U32TO8(digest + 12, S->h[3]);
U32TO8(digest + 16, S->h[4]);
U32TO8(digest + 20, S->h[5]);
U32TO8(digest + 24, S->h[6]);
U32TO8(digest + 28, S->h[7]);
}
void blake256_final(state *S, uint8_t *digest) {
blake256_final_h(S, digest, 0x81, 0x01);
}
void blake224_final(state *S, uint8_t *digest) {
blake256_final_h(S, digest, 0x80, 0x00);
}
// inlen = number of bytes
void blake256_hash(uint8_t *out, const uint8_t *in, uint64_t inlen) {
state S;
blake256_init(&S);
blake256_update(&S, in, inlen * 8);
blake256_final(&S, out);
}
void blake(const uint8_t *input, uint64_t len, uint8_t *output)
{
blake256_hash(output, input, len);
}
// inlen = number of bytes
void blake224_hash(uint8_t *out, const uint8_t *in, uint64_t inlen) {
state S;
blake224_init(&S);
blake224_update(&S, in, inlen * 8);
blake224_final(&S, out);
}
// keylen = number of bytes
void hmac_blake256_init(hmac_state *S, const uint8_t *_key, uint64_t keylen) {
const uint8_t *key = _key;
uint8_t keyhash[32];
uint8_t pad[64];
uint64_t i;
if (keylen > 64) {
blake256_hash(keyhash, key, keylen);
key = keyhash;
keylen = 32;
}
blake256_init(&S->inner);
memset(pad, 0x36, 64);
for (i = 0; i < keylen; ++i) {
pad[i] ^= key[i];
}
blake256_update(&S->inner, pad, 512);
blake256_init(&S->outer);
memset(pad, 0x5c, 64);
for (i = 0; i < keylen; ++i) {
pad[i] ^= key[i];
}
blake256_update(&S->outer, pad, 512);
memset(keyhash, 0, 32);
}
// keylen = number of bytes
void hmac_blake224_init(hmac_state *S, const uint8_t *_key, uint64_t keylen) {
const uint8_t *key = _key;
uint8_t keyhash[32];
uint8_t pad[64];
uint64_t i;
if (keylen > 64) {
blake256_hash(keyhash, key, keylen);
key = keyhash;
keylen = 28;
}
blake224_init(&S->inner);
memset(pad, 0x36, 64);
for (i = 0; i < keylen; ++i) {
pad[i] ^= key[i];
}
blake224_update(&S->inner, pad, 512);
blake224_init(&S->outer);
memset(pad, 0x5c, 64);
for (i = 0; i < keylen; ++i) {
pad[i] ^= key[i];
}
blake224_update(&S->outer, pad, 512);
memset(keyhash, 0, 32);
}
// datalen = number of bits
void hmac_blake256_update(hmac_state *S, const uint8_t *data, uint64_t datalen) {
// update the inner state
blake256_update(&S->inner, data, datalen);
}
// datalen = number of bits
void hmac_blake224_update(hmac_state *S, const uint8_t *data, uint64_t datalen) {
// update the inner state
blake224_update(&S->inner, data, datalen);
}
void hmac_blake256_final(hmac_state *S, uint8_t *digest) {
uint8_t ihash[32];
blake256_final(&S->inner, ihash);
blake256_update(&S->outer, ihash, 256);
blake256_final(&S->outer, digest);
memset(ihash, 0, 32);
}
void hmac_blake224_final(hmac_state *S, uint8_t *digest) {
uint8_t ihash[32];
blake224_final(&S->inner, ihash);
blake224_update(&S->outer, ihash, 224);
blake224_final(&S->outer, digest);
memset(ihash, 0, 32);
}
// keylen = number of bytes; inlen = number of bytes
void hmac_blake256_hash(uint8_t *out, const uint8_t *key, uint64_t keylen, const uint8_t *in, uint64_t inlen) {
hmac_state S;
hmac_blake256_init(&S, key, keylen);
hmac_blake256_update(&S, in, inlen * 8);
hmac_blake256_final(&S, out);
}
// keylen = number of bytes; inlen = number of bytes
void hmac_blake224_hash(uint8_t *out, const uint8_t *key, uint64_t keylen, const uint8_t *in, uint64_t inlen) {
hmac_state S;
hmac_blake224_init(&S, key, keylen);
hmac_blake224_update(&S, in, inlen * 8);
hmac_blake224_final(&S, out);
}

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

@ -1,14 +0,0 @@
#ifndef BLAKE_H
#define BLAKE_H
#ifdef __cplusplus
extern "C" {
#endif
void blake(const uint8_t *input, uint64_t len, uint8_t *output);
#ifdef __cplusplus
}
#endif
#endif

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

@ -1,749 +0,0 @@
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include "keccak.h"
#include "blake.h"
#include "skein.h"
#include "jh.h"
#include "groestl.h"
#include "oaes_lib.h"
#include "variant2_int_sqrt.h"
#define MEMORY (1 << 21) /* 2 MiB */
#define ITER (1 << 20)
#define AES_BLOCK_SIZE 16
#define AES_KEY_SIZE 32 /*16*/
#define INIT_SIZE_BLK 8
#define INIT_SIZE_BYTE (INIT_SIZE_BLK * AES_BLOCK_SIZE) // 128
#define U64(x) ((uint64_t *) (x))
#define VARIANT1_1(p) \
do \
{ \
const uint8_t tmp = ((const uint8_t*)(p))[11]; \
static const uint32_t table = 0x75310; \
const uint8_t index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; \
((uint8_t*)(p))[11] = tmp ^ ((table >> index) & 0x30); \
} while(0)
#define VARIANT1_2(p) \
do \
{ \
xor64(p, tweak1_2); \
} while(0)
#define VARIANT1_INIT64() \
const uint64_t tweak1_2 = (variant == 1) ? *(const uint64_t *)(((const uint8_t *)input) + 35) ^ ctx->state.hs.w[24] : 0
#define VARIANT2_INIT64() \
uint64_t division_result = 0; \
uint64_t sqrt_result = 0; \
do if (variant >= 2) \
{ \
U64(ctx->d)[0] = ctx->state.hs.w[8] ^ ctx->state.hs.w[10]; \
U64(ctx->d)[1] = ctx->state.hs.w[9] ^ ctx->state.hs.w[11]; \
division_result = ctx->state.hs.w[12]; \
sqrt_result = ctx->state.hs.w[13]; \
} while (0)
#define VARIANT2_2_PORTABLE() \
do \
{ \
xor_blocks(ctx->long_state + (j ^ 0x10), ctx->e); \
xor_blocks(ctx->e, ctx->long_state + (j ^ 0x20)); \
} while (0)
#define VARIANT2_PORTABLE_SHUFFLE_ADD1(base_ptr, offset) \
do \
{ \
uint64_t* chunk1 = U64((base_ptr) + ((offset) ^ 0x10)); \
uint64_t* chunk2 = U64((base_ptr) + ((offset) ^ 0x20)); \
uint64_t* chunk3 = U64((base_ptr) + ((offset) ^ 0x30)); \
\
uint64_t chunk1_old0 = chunk1[0]; \
uint64_t chunk1_old1 = chunk1[1]; \
\
chunk1[0] = chunk3[0] + ((uint64_t*) ctx->d)[0]; \
chunk1[1] = chunk3[1] + ((uint64_t*) ctx->d)[1]; \
\
chunk3[0] = chunk2[0] + ((uint64_t*) ctx->a)[0]; \
chunk3[1] = chunk2[1] + ((uint64_t*) ctx->a)[1]; \
\
chunk2[0] = chunk1_old0 + ((uint64_t*) ctx->b)[0]; \
chunk2[1] = chunk1_old1 + ((uint64_t*) ctx->b)[1]; \
} while (0)
#define VARIANT2_PORTABLE_SHUFFLE_ADD2(base_ptr, offset) \
do \
{ \
uint64_t* chunk1 = U64((base_ptr) + ((offset) ^ 0x10)); \
uint64_t* chunk2 = U64((base_ptr) + ((offset) ^ 0x20)); \
uint64_t* chunk3 = U64((base_ptr) + ((offset) ^ 0x30)); \
\
uint64_t chunk1_old0 = chunk1[0]; \
uint64_t chunk1_old1 = chunk1[1]; \
\
chunk1[0] = chunk3[0] + ((uint64_t*) ctx->d)[0]; \
chunk1[1] = chunk3[1] + ((uint64_t*) ctx->d)[1]; \
\
chunk3[0] = chunk2[0] + ((uint64_t*) ctx->a)[0]; \
chunk3[1] = chunk2[1] + ((uint64_t*) ctx->a)[1]; \
\
chunk2[0] = chunk1_old0 + ((uint64_t*) ctx->c)[0]; \
chunk2[1] = chunk1_old1 + ((uint64_t*) ctx->c)[1]; \
} while (0)
#define VARIANT2_INTEGER_MATH_DIVISION_STEP(b, ptr) \
((uint64_t*)(b))[0] ^= division_result ^ (sqrt_result << 32); \
{ \
const uint64_t dividend = ((uint64_t*)(ptr))[1]; \
const uint32_t divisor = (((uint64_t*)(ptr))[0] + (sqrt_result << 1)) | 0x80000001UL; \
const uint64_t aa = dividend / divisor; \
division_result = (aa & 0xFFFFFFFF) + ((dividend - aa * divisor) << 32); \
} \
const uint64_t sqrt_input = ((uint64_t*)(ptr))[0] + division_result
#if defined DBL_MANT_DIG && (DBL_MANT_DIG >= 50)
// double precision floating point type has enough bits of precision on current platform
#define VARIANT2_PORTABLE_INTEGER_MATH(b, ptr) \
do \
{ \
VARIANT2_INTEGER_MATH_DIVISION_STEP(b, ptr); \
VARIANT2_INTEGER_MATH_SQRT_STEP_FP64(); \
VARIANT2_INTEGER_MATH_SQRT_FIXUP(sqrt_result); \
} while (0)
#else
// double precision floating point type is not good enough on current platform
// fall back to the reference code (integer only)
#define VARIANT2_PORTABLE_INTEGER_MATH(b, ptr) \
do \
{ \
VARIANT2_INTEGER_MATH_DIVISION_STEP(b, ptr); \
VARIANT2_INTEGER_MATH_SQRT_STEP_REF(); \
} while (0)
#endif
static void xor64(uint8_t *a, const uint64_t b)
{
*(uint64_t *)a ^= b;
}
static void copy_block(uint8_t* dst, const uint8_t* src) {
((uint64_t *)dst)[0] = ((uint64_t *)src)[0];
((uint64_t *)dst)[1] = ((uint64_t *)src)[1];
}
void do_blake_hash(const void *input, size_t len, char *output)
{
blake(input, len, (unsigned char *)output);
}
void do_groestl_hash(const void *input, size_t len, char *output)
{
groestl(input, len * 8, (uint8_t *)output);
}
void do_jh_hash(const void *input, size_t len, char *output)
{
jh(32 * 8, input, 8 * len, (uint8_t *)output);
}
void do_skein_hash(const void *input, size_t len, char *output)
{
skein(8 * 32, input, 8 * len, (uint8_t *)output);
}
void (*const extra_hashes[4])(const void *, size_t, char *) = {
do_blake_hash, do_groestl_hash, do_jh_hash, do_skein_hash};
void xor_blocks_dst(const uint8_t *a, const uint8_t *b, uint8_t *dst)
{
((uint64_t *)dst)[0] = ((uint64_t *)a)[0] ^ ((uint64_t *)b)[0];
((uint64_t *)dst)[1] = ((uint64_t *)a)[1] ^ ((uint64_t *)b)[1];
}
#define likely(x) (x)