From 2544842bcb778c7ccee76444b461625a0fbe8e33 Mon Sep 17 00:00:00 2001
From: miha-q <>
Date: Mon, 20 Jan 2025 13:27:02 -0500
Subject: [PATCH] Mon Jan 20 01:27:02 PM EST 2025
---
src/www/imports/code.html | 14 +--
.../imports/{estouls-api.js => rosado-api.js} | 101 +++++++++---------
src/www/index.html | 10 +-
3 files changed, 62 insertions(+), 63 deletions(-)
rename src/www/imports/{estouls-api.js => rosado-api.js} (74%)
diff --git a/src/www/imports/code.html b/src/www/imports/code.html
index 4d2ba5e..0ee9e62 100644
--- a/src/www/imports/code.html
+++ b/src/www/imports/code.html
@@ -1,10 +1,10 @@
- EstoulsAPI
+ RosadoAPI
-
+
@@ -107,7 +107,7 @@ else
{
var a = document.createElement("a");
a.href = "/apk";
- a.download = "EstoulsAPI.apk";
+ a.download = "RosadoAPI.apk";
a.style.display = "none";
document.body.appendChild(a);
a.click();
@@ -212,10 +212,10 @@ else
return;
}
- EstoulsAPI.username = dat[0];
- EstoulsAPI.apikey = dat[1];
- EstoulsAPI.endpoint = "https://" + dat[2];
- EstoulsAPI.request(IstinaEditor.getText()).then(x =>
+ RosadoAPI.username = dat[0];
+ RosadoAPI.apikey = dat[1];
+ RosadoAPI.endpoint = "https://" + dat[2];
+ RosadoAPI.request(IstinaEditor.getText()).then(x =>
{
if (x.success && x.response.trim().length > 0)
{
diff --git a/src/www/imports/estouls-api.js b/src/www/imports/rosado-api.js
similarity index 74%
rename from src/www/imports/estouls-api.js
rename to src/www/imports/rosado-api.js
index 73760d7..bb8d769 100644
--- a/src/www/imports/estouls-api.js
+++ b/src/www/imports/rosado-api.js
@@ -1,4 +1,4 @@
-var EstoulsAPI =
+var RosadoAPI =
{
username: undefined,
apikey: undefined,
@@ -12,14 +12,14 @@ var EstoulsAPI =
a += a < 0 ? 0x100000000 : -0x100000000;
return a;
},
- shl: (a, b) => EstoulsAPI.Math32.clamp(a << b),
- shr: (a, b) => EstoulsAPI.Math32.clamp(a >>> b),
- rtl: (a, b) => EstoulsAPI.Math32.clamp((a << b) | (a >>> (32 - b))),
- rtr: (a, b) => EstoulsAPI.Math32.clamp((a >>> b) | (a << (32 - b))),
- add: (a, b) => EstoulsAPI.Math32.clamp(a + b),
- sub: (a, b) => EstoulsAPI.Math32.clamp(a + b),
- or: (a, b) => EstoulsAPI.Math32.clamp(a | b),
- xor: (a, b) => EstoulsAPI.Math32.clamp(a ^ b)
+ shl: (a, b) => RosadoAPI.Math32.clamp(a << b),
+ shr: (a, b) => RosadoAPI.Math32.clamp(a >>> b),
+ rtl: (a, b) => RosadoAPI.Math32.clamp((a << b) | (a >>> (32 - b))),
+ rtr: (a, b) => RosadoAPI.Math32.clamp((a >>> b) | (a << (32 - b))),
+ add: (a, b) => RosadoAPI.Math32.clamp(a + b),
+ sub: (a, b) => RosadoAPI.Math32.clamp(a + b),
+ or: (a, b) => RosadoAPI.Math32.clamp(a | b),
+ xor: (a, b) => RosadoAPI.Math32.clamp(a ^ b)
},
HMACSHA256:
{
@@ -42,32 +42,32 @@ var EstoulsAPI =
{
QR: (cc, a, b, c, d) =>
{
- cc[a] = EstoulsAPI.Math32.add(cc[a], cc[b]);
- cc[d] = EstoulsAPI.Math32.xor(cc[d], cc[a]);
- cc[d] = EstoulsAPI.Math32.rtl(cc[d], 16);
+ cc[a] = RosadoAPI.Math32.add(cc[a], cc[b]);
+ cc[d] = RosadoAPI.Math32.xor(cc[d], cc[a]);
+ cc[d] = RosadoAPI.Math32.rtl(cc[d], 16);
- cc[c] = EstoulsAPI.Math32.add(cc[c], cc[d]);
- cc[b] = EstoulsAPI.Math32.xor(cc[b], cc[c]);
- cc[b] = EstoulsAPI.Math32.rtl(cc[b], 12);
+ cc[c] = RosadoAPI.Math32.add(cc[c], cc[d]);
+ cc[b] = RosadoAPI.Math32.xor(cc[b], cc[c]);
+ cc[b] = RosadoAPI.Math32.rtl(cc[b], 12);
- cc[a] = EstoulsAPI.Math32.add(cc[a], cc[b]);
- cc[d] = EstoulsAPI.Math32.xor(cc[d], cc[a]);
- cc[d] = EstoulsAPI.Math32.rtl(cc[d], 8);
+ cc[a] = RosadoAPI.Math32.add(cc[a], cc[b]);
+ cc[d] = RosadoAPI.Math32.xor(cc[d], cc[a]);
+ cc[d] = RosadoAPI.Math32.rtl(cc[d], 8);
- cc[c] = EstoulsAPI.Math32.add(cc[c], cc[d]);
- cc[b] = EstoulsAPI.Math32.xor(cc[b], cc[c]);
- cc[b] = EstoulsAPI.Math32.rtl(cc[b], 7);
+ cc[c] = RosadoAPI.Math32.add(cc[c], cc[d]);
+ cc[b] = RosadoAPI.Math32.xor(cc[b], cc[c]);
+ cc[b] = RosadoAPI.Math32.rtl(cc[b], 7);
},
DR: (cc) =>
{
- EstoulsAPI.ChaCha20.QR(cc, 0, 4, 8, 12);
- EstoulsAPI.ChaCha20.QR(cc, 1, 5, 9, 13);
- EstoulsAPI.ChaCha20.QR(cc, 2, 6, 10, 14);
- EstoulsAPI.ChaCha20.QR(cc, 3, 7, 11, 15);
- EstoulsAPI.ChaCha20.QR(cc, 0, 5, 10, 15);
- EstoulsAPI.ChaCha20.QR(cc, 1, 6, 11, 12);
- EstoulsAPI.ChaCha20.QR(cc, 2, 7, 8, 13);
- EstoulsAPI.ChaCha20.QR(cc, 3, 4, 9, 14);
+ RosadoAPI.ChaCha20.QR(cc, 0, 4, 8, 12);
+ RosadoAPI.ChaCha20.QR(cc, 1, 5, 9, 13);
+ RosadoAPI.ChaCha20.QR(cc, 2, 6, 10, 14);
+ RosadoAPI.ChaCha20.QR(cc, 3, 7, 11, 15);
+ RosadoAPI.ChaCha20.QR(cc, 0, 5, 10, 15);
+ RosadoAPI.ChaCha20.QR(cc, 1, 6, 11, 12);
+ RosadoAPI.ChaCha20.QR(cc, 2, 7, 8, 13);
+ RosadoAPI.ChaCha20.QR(cc, 3, 4, 9, 14);
},
CB: (cc) =>
{
@@ -79,11 +79,11 @@ var EstoulsAPI =
}
for (i = 0; i < 10; i++)
{
- EstoulsAPI.ChaCha20.DR(cc);
+ RosadoAPI.ChaCha20.DR(cc);
}
for (i = 0; i < 16; i++)
{
- cc[i] = EstoulsAPI.Math32.add(cc[i], x[i]);
+ cc[i] = RosadoAPI.Math32.add(cc[i], x[i]);
}
},
S: (cc, cs) =>
@@ -119,8 +119,8 @@ var EstoulsAPI =
nonce[8] | (nonce[9] << 8) | (nonce[10] << 16) | (nonce[11] << 24)
];
- EstoulsAPI.ChaCha20.CB(cc);
- EstoulsAPI.ChaCha20.S(cc, out);
+ RosadoAPI.ChaCha20.CB(cc);
+ RosadoAPI.ChaCha20.S(cc, out);
},
encrypt: async (key, nonce, block, data) =>
{
@@ -132,7 +132,7 @@ var EstoulsAPI =
while (count > 64)
{
ret.length = size + 64;
- EstoulsAPI.ChaCha20.B(key, nonce, block++, ccblock);
+ RosadoAPI.ChaCha20.B(key, nonce, block++, ccblock);
for (var i = 0; i < 64; i++) ret[size + i] = ccblock[i];
size += 64;
count -= 64;
@@ -140,7 +140,7 @@ var EstoulsAPI =
if (count > 0)
{
ret.length = size + count;
- EstoulsAPI.ChaCha20.B(key, nonce, block, ccblock);
+ RosadoAPI.ChaCha20.B(key, nonce, block, ccblock);
for (var i = 0; i < count; i++) ret[size + i] = ccblock[i];
}
for (var i = 0; i < data.length; i++) ret[i] ^= data[i];
@@ -285,15 +285,15 @@ var EstoulsAPI =
generateRequest: async (msg) =>
{
msg = new TextEncoder().encode(msg);
- var key = EstoulsAPI.Hex.decode(EstoulsAPI.apikey);
+ var key = RosadoAPI.Hex.decode(RosadoAPI.apikey);
//var sess = crypto.getRandomValues(new Uint8Array(12));
var r = () => { return Math.floor(Math.random() * 10000) % 256 };;
var sess = new Uint8Array([r(), r(), r(), r(), r(), r(), r(), r(), r(), r(), r(), r()]);
- var rawdata = await EstoulsAPI.ChaCha20.encrypt(key, sess, 0, msg);
- var dgst = await EstoulsAPI.Hex.encode(await EstoulsAPI.HMACSHA256.sign(key, rawdata));
- var data = await EstoulsAPI.Base64.encode(rawdata);
- var resp = "user=" + EstoulsAPI.username;
- resp += "&sess=" + EstoulsAPI.Hex.encode(sess);
+ var rawdata = await RosadoAPI.ChaCha20.encrypt(key, sess, 0, msg);
+ var dgst = await RosadoAPI.Hex.encode(await RosadoAPI.HMACSHA256.sign(key, rawdata));
+ var data = await RosadoAPI.Base64.encode(rawdata);
+ var resp = "user=" + RosadoAPI.username;
+ resp += "&sess=" + RosadoAPI.Hex.encode(sess);
resp += "&dgst=" + dgst;
resp += "&data=" + data;
return resp;
@@ -310,30 +310,30 @@ var EstoulsAPI =
var dgst = msg.split("&dgst=")[1].split("&")[0].trim();
var data = msg.split("&data=")[1].split("&")[0].trim();
- if (user != EstoulsAPI.username)
+ if (user != RosadoAPI.username)
{
return { success: false, response: "invalid user in response" };
}
- data = EstoulsAPI.Base64.decode(data);
- sess = EstoulsAPI.Hex.decode(sess);
- var key = EstoulsAPI.Hex.decode(EstoulsAPI.apikey);
- var sig = await EstoulsAPI.Hex.encode(await EstoulsAPI.HMACSHA256.sign(key, data));
+ data = RosadoAPI.Base64.decode(data);
+ sess = RosadoAPI.Hex.decode(sess);
+ var key = RosadoAPI.Hex.decode(RosadoAPI.apikey);
+ var sig = await RosadoAPI.Hex.encode(await RosadoAPI.HMACSHA256.sign(key, data));
if (sig != dgst)
{
return { success: false, response: "invalid signature" };
}
- var resp = await EstoulsAPI.ChaCha20.encrypt(key, sess, 0, data);
+ var resp = await RosadoAPI.ChaCha20.encrypt(key, sess, 0, data);
return { success: true, response: new TextDecoder().decode(resp) };
},
request: async (msg) =>
{
if (msg.trim().length == 0) return { success: true, response: "" };
- var req = await EstoulsAPI.generateRequest(msg);
+ var req = await RosadoAPI.generateRequest(msg);
return await new Promise(r =>
{
const xhr = new XMLHttpRequest();
- xhr.open("POST", EstoulsAPI.endpoint, true);
+ xhr.open("POST", RosadoAPI.endpoint, true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.onreadystatechange = (x) =>
{
@@ -341,7 +341,7 @@ var EstoulsAPI =
{
if (xhr.status === 200)
{
- EstoulsAPI.parseResponse(xhr.responseText).then(pr => { r(pr); }).catch(x => alert("ERR(3)"));
+ RosadoAPI.parseResponse(xhr.responseText).then(pr => { r(pr); }).catch(x => alert("ERR(3)"));
}
else
{
@@ -352,6 +352,5 @@ var EstoulsAPI =
xhr.send(req);
}).catch(x => alert("ERR(1): " + x));
}
-
};
diff --git a/src/www/index.html b/src/www/index.html
index deace9b..638bc79 100644
--- a/src/www/index.html
+++ b/src/www/index.html
@@ -3,7 +3,7 @@
QAnsel - Quantum Computer Simulator
-
+
@@ -934,10 +934,10 @@
errorModal("Please click the gear icon and input your API key.");
return;
}
- EstoulsAPI.username = key.split(":")[0];
- EstoulsAPI.apikey = key.split(":")[1];
- EstoulsAPI.endpoint = "https://" + key.split(":")[2];
- EstoulsAPI.request(IstinaEditor.getText()).then(x =>
+ RosadoAPI.username = key.split(":")[0];
+ RosadoAPI.apikey = key.split(":")[1];
+ RosadoAPI.endpoint = "https://" + key.split(":")[2];
+ RosadoAPI.request(IstinaEditor.getText()).then(x =>
{
$("#blocker-div")[0].remove();
$("#blocker-img")[0].remove();
--
2.39.5