@bounded-sh/client 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/hooks/useQuery.d.ts +58 -0
- package/dist/{index-2UpSvA7V.js → index-BBLnBZjY.js} +353 -2627
- package/dist/index-BBLnBZjY.js.map +1 -0
- package/dist/{index-C2JpxGAC.js → index-BMrN-6oK.js} +2 -2
- package/dist/{index-C2JpxGAC.js.map → index-BMrN-6oK.js.map} +1 -1
- package/dist/{index-DJg-Dduo.esm.js → index-D5Ut2JU7.esm.js} +2 -2
- package/dist/{index-DJg-Dduo.esm.js.map → index-D5Ut2JU7.esm.js.map} +1 -1
- package/dist/{index-C2yvle9S.esm.js → index-DkWfblRJ.esm.js} +2 -2
- package/dist/{index-C2yvle9S.esm.js.map → index-DkWfblRJ.esm.js.map} +1 -1
- package/dist/{index-CYVVTWs4.js → index-FYyc3l_y.js} +2 -2
- package/dist/{index-CYVVTWs4.js.map → index-FYyc3l_y.js.map} +1 -1
- package/dist/{index-DyfiK3_X.esm.js → index-n4fG6EZJ.esm.js} +350 -2628
- package/dist/index-n4fG6EZJ.esm.js.map +1 -0
- package/dist/{index.browser-pymH6o1X.esm.js → index.browser-CCWEiCH-.esm.js} +2 -2
- package/dist/{index.browser-pymH6o1X.esm.js.map → index.browser-CCWEiCH-.esm.js.map} +1 -1
- package/dist/{index.browser-BTJZmhY1.js → index.browser-D5evrolK.js} +2 -2
- package/dist/{index.browser-BTJZmhY1.js.map → index.browser-D5evrolK.js.map} +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.esm.js +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/{index.native-BTjBgNiE.esm.js → index.native-D5q2RUeV.esm.js} +82 -2420
- package/dist/index.native-D5q2RUeV.esm.js.map +1 -0
- package/dist/{index.native-BvsmNFXn.js → index.native-D82ofFXB.js} +84 -2419
- package/dist/index.native-D82ofFXB.js.map +1 -0
- package/dist/index.native.esm.js +1 -1
- package/dist/index.native.js +4 -1
- package/dist/index.native.js.map +1 -1
- package/dist/{phantom-wallet-provider-CTossIFB.esm.js → phantom-wallet-provider-C8DNu92D.esm.js} +3 -3
- package/dist/{phantom-wallet-provider-CTossIFB.esm.js.map → phantom-wallet-provider-C8DNu92D.esm.js.map} +1 -1
- package/dist/{phantom-wallet-provider-BXMvoOrI.js → phantom-wallet-provider-CoL7g8Sr.js} +3 -3
- package/dist/{phantom-wallet-provider-BXMvoOrI.js.map → phantom-wallet-provider-CoL7g8Sr.js.map} +1 -1
- package/dist/{privy-wallet-provider-D64DJ3u4.js → privy-wallet-provider-CV1mU4KR.js} +3 -3
- package/dist/{privy-wallet-provider-D64DJ3u4.js.map → privy-wallet-provider-CV1mU4KR.js.map} +1 -1
- package/dist/{privy-wallet-provider-1qE_f-DF.esm.js → privy-wallet-provider-De3mfJYo.esm.js} +3 -3
- package/dist/{privy-wallet-provider-1qE_f-DF.esm.js.map → privy-wallet-provider-De3mfJYo.esm.js.map} +1 -1
- package/dist/{solana-mobile-wallet-provider-9M8U6AA7.esm.js → solana-mobile-wallet-provider-CLCvi-08.esm.js} +2 -2
- package/dist/{solana-mobile-wallet-provider-9M8U6AA7.esm.js.map → solana-mobile-wallet-provider-CLCvi-08.esm.js.map} +1 -1
- package/dist/{solana-mobile-wallet-provider-C1wQ1DRK.js → solana-mobile-wallet-provider-D9dPbk__.js} +2 -2
- package/dist/{solana-mobile-wallet-provider-C1wQ1DRK.js.map → solana-mobile-wallet-provider-D9dPbk__.js.map} +1 -1
- package/package.json +2 -2
- package/dist/index-2UpSvA7V.js.map +0 -1
- package/dist/index-DyfiK3_X.esm.js.map +0 -1
- package/dist/index.native-BTjBgNiE.esm.js.map +0 -1
- package/dist/index.native-BvsmNFXn.js.map +0 -1
|
@@ -40,7 +40,7 @@ function commonjsRequire(path) {
|
|
|
40
40
|
throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
var naclFast
|
|
43
|
+
var naclFast = {exports: {}};
|
|
44
44
|
|
|
45
45
|
var _nodeResolve_empty = {};
|
|
46
46
|
|
|
@@ -51,11 +51,11 @@ var _nodeResolve_empty$1 = /*#__PURE__*/Object.freeze({
|
|
|
51
51
|
|
|
52
52
|
var require$$0 = /*@__PURE__*/getDefaultExportFromNamespaceIfNotNamed(_nodeResolve_empty$1);
|
|
53
53
|
|
|
54
|
-
var hasRequiredNaclFast
|
|
54
|
+
var hasRequiredNaclFast;
|
|
55
55
|
|
|
56
|
-
function requireNaclFast
|
|
57
|
-
if (hasRequiredNaclFast
|
|
58
|
-
hasRequiredNaclFast
|
|
56
|
+
function requireNaclFast () {
|
|
57
|
+
if (hasRequiredNaclFast) return naclFast.exports;
|
|
58
|
+
hasRequiredNaclFast = 1;
|
|
59
59
|
(function (module) {
|
|
60
60
|
(function(nacl) {
|
|
61
61
|
|
|
@@ -2447,12 +2447,12 @@ function requireNaclFast$1 () {
|
|
|
2447
2447
|
})();
|
|
2448
2448
|
|
|
2449
2449
|
})(module.exports ? module.exports : (self.nacl = self.nacl || {}));
|
|
2450
|
-
} (naclFast
|
|
2451
|
-
return naclFast
|
|
2450
|
+
} (naclFast));
|
|
2451
|
+
return naclFast.exports;
|
|
2452
2452
|
}
|
|
2453
2453
|
|
|
2454
|
-
var naclFastExports
|
|
2455
|
-
var nacl
|
|
2454
|
+
var naclFastExports = requireNaclFast();
|
|
2455
|
+
var nacl = /*@__PURE__*/getDefaultExportFromCjs$1(naclFastExports);
|
|
2456
2456
|
|
|
2457
2457
|
var bn$1 = {exports: {}};
|
|
2458
2458
|
|
|
@@ -10235,7 +10235,7 @@ class ServerSessionManager {
|
|
|
10235
10235
|
const nonce = await genAuthNonce();
|
|
10236
10236
|
const message = await genSolanaMessage(address, nonce);
|
|
10237
10237
|
/* sign the message */
|
|
10238
|
-
const sigBytes = nacl
|
|
10238
|
+
const sigBytes = nacl.sign.detached(new TextEncoder().encode(message), kp.secretKey);
|
|
10239
10239
|
const signature = bufferExports$1.Buffer.from(sigBytes).toString("base64");
|
|
10240
10240
|
/* call auth API */
|
|
10241
10241
|
const { accessToken, idToken, refreshToken, } = await createSessionWithSignature(address, message, signature);
|
|
@@ -12991,6 +12991,73 @@ function serverTimestamp() {
|
|
|
12991
12991
|
return { operation: 'time', value: 'now' };
|
|
12992
12992
|
}
|
|
12993
12993
|
|
|
12994
|
+
/**
|
|
12995
|
+
* Time units in Bounded — read this once and never get a 1000× timestamp bug.
|
|
12996
|
+
*
|
|
12997
|
+
* **Bounded's policy/proof layer is Unix SECONDS.** `@time.now` in a rule,
|
|
12998
|
+
* `rollingSum` `windowSeconds`, `scheduledAt`, and any timestamp *field your
|
|
12999
|
+
* policy compares against `@time.now`* are all **seconds**. (This is also what
|
|
13000
|
+
* the chain uses — Solana's on-chain clock is `unix_timestamp` in seconds — so a
|
|
13001
|
+
* single seconds unit works for both onchain and offchain rules.)
|
|
13002
|
+
*
|
|
13003
|
+
* **JavaScript is MILLISECONDS.** `Date.now()`, `new Date().getTime()`, and the
|
|
13004
|
+
* auto-stamped system fields `_createdAt` / `_updatedAt` are all **ms**.
|
|
13005
|
+
*
|
|
13006
|
+
* Comparing across the two (e.g. `@time.now - myField` where `myField` was set
|
|
13007
|
+
* from `Date.now()`) is 1000× off, so a freshness / TTL check silently treats
|
|
13008
|
+
* every row as ancient (or far-future) and drops it — which reads as "realtime
|
|
13009
|
+
* isn't delivering" when the data is actually fine.
|
|
13010
|
+
*
|
|
13011
|
+
* **The rules:**
|
|
13012
|
+
* - To **write** a timestamp a policy will read, prefer **`serverTimestamp()`**
|
|
13013
|
+
* (from this package) — the *server* stamps it in seconds, so it matches
|
|
13014
|
+
* `@time.now` AND can't be forged by the client (use it for TTLs, rate windows,
|
|
13015
|
+
* anti-cheat). Use `now()` only when you need the value in client code before
|
|
13016
|
+
* the write.
|
|
13017
|
+
* - To **compare** timestamps in client/render code, use `now()` (seconds), not
|
|
13018
|
+
* `Date.now()` (ms), and `toSeconds()` to convert the ms system fields
|
|
13019
|
+
* (`_createdAt`/`_updatedAt`) or any `Date.now()` value first.
|
|
13020
|
+
*/
|
|
13021
|
+
/**
|
|
13022
|
+
* Current time as a **Unix timestamp in seconds** — the unit Bounded policy rules
|
|
13023
|
+
* use (`@time.now`). Use this (not `Date.now()`) when you need a timestamp in
|
|
13024
|
+
* client code (e.g. a freshness check). For a value you *store* and a policy
|
|
13025
|
+
* reads, prefer the server-authoritative {@link serverTimestamp} instead.
|
|
13026
|
+
*
|
|
13027
|
+
* ```ts
|
|
13028
|
+
* // stale if >15s old — seconds vs seconds ✓
|
|
13029
|
+
* if (now() - doc.lastSeenSeconds > 15) renderStale();
|
|
13030
|
+
* ```
|
|
13031
|
+
*/
|
|
13032
|
+
function now() {
|
|
13033
|
+
return Math.floor(Date.now() / 1000);
|
|
13034
|
+
}
|
|
13035
|
+
/**
|
|
13036
|
+
* Convert a JavaScript millisecond timestamp to Bounded's **seconds**. Accepts a
|
|
13037
|
+
* `Date`, or an ms number such as `Date.now()` or a doc's `_createdAt` /
|
|
13038
|
+
* `_updatedAt` system field.
|
|
13039
|
+
*
|
|
13040
|
+
* ```ts
|
|
13041
|
+
* // doc is >15s old (compare the ms system field in seconds):
|
|
13042
|
+
* if (now() - toSeconds(doc._updatedAt) > 15) renderStale();
|
|
13043
|
+
* ```
|
|
13044
|
+
*/
|
|
13045
|
+
function toSeconds(msOrDate) {
|
|
13046
|
+
const ms = msOrDate instanceof Date ? msOrDate.getTime() : msOrDate;
|
|
13047
|
+
return Math.floor(ms / 1000);
|
|
13048
|
+
}
|
|
13049
|
+
/**
|
|
13050
|
+
* Convert a Bounded **seconds** timestamp back to JavaScript **milliseconds** —
|
|
13051
|
+
* e.g. to build a `Date` or do client-side date math/formatting.
|
|
13052
|
+
*
|
|
13053
|
+
* ```ts
|
|
13054
|
+
* new Date(toMillis(doc.createdAtSeconds)).toLocaleString();
|
|
13055
|
+
* ```
|
|
13056
|
+
*/
|
|
13057
|
+
function toMillis(seconds) {
|
|
13058
|
+
return seconds * 1000;
|
|
13059
|
+
}
|
|
13060
|
+
|
|
12994
13061
|
// ---------------------------------------------------------------------------
|
|
12995
13062
|
// realtime-store.ts — Client-side state manager for realtime apps.
|
|
12996
13063
|
//
|
|
@@ -17773,2616 +17840,211 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
17773
17840
|
default: bs582
|
|
17774
17841
|
});
|
|
17775
17842
|
|
|
17776
|
-
|
|
17777
|
-
|
|
17778
|
-
|
|
17779
|
-
|
|
17780
|
-
|
|
17781
|
-
|
|
17782
|
-
|
|
17783
|
-
|
|
17784
|
-
|
|
17843
|
+
// guest-keystore.ts — durable per-device keypair for anonymous ("guest") auth.
|
|
17844
|
+
//
|
|
17845
|
+
// A guest is an ed25519 keypair generated on the device. Its public key is the
|
|
17846
|
+
// Bounded account address; it signs the auth challenge exactly like a wallet.
|
|
17847
|
+
//
|
|
17848
|
+
// Two backends, chosen automatically:
|
|
17849
|
+
// 1. WebCrypto Ed25519 + IndexedDB (browsers that support it) — the key is
|
|
17850
|
+
// NON-EXTRACTABLE: an XSS can ask it to *sign* but can never read the
|
|
17851
|
+
// private bytes. This is the secure default.
|
|
17852
|
+
// 2. tweetnacl keypair in platform storage (React Native / older browsers) —
|
|
17853
|
+
// the secret is stored as bytes. Simpler, but exfiltratable by XSS, so
|
|
17854
|
+
// treat it as a low-stakes guest identity and tell users to upgrade
|
|
17855
|
+
// (link an email) before they care about not losing it.
|
|
17856
|
+
//
|
|
17857
|
+
// Either way the public output is identical: a base58 address + a base64
|
|
17858
|
+
// detached signature, which is the format the session endpoint already accepts.
|
|
17859
|
+
const FALLBACK_STORE_KEY = 'bounded_guest_key_v1';
|
|
17860
|
+
const IDB_NAME = 'bounded-guest';
|
|
17861
|
+
const IDB_STORE = 'keys';
|
|
17862
|
+
const IDB_KEY = 'ed25519';
|
|
17863
|
+
function toBase64(bytes) {
|
|
17864
|
+
let bin = '';
|
|
17865
|
+
for (let i = 0; i < bytes.length; i++)
|
|
17866
|
+
bin += String.fromCharCode(bytes[i]);
|
|
17867
|
+
// btoa exists in browsers + RN (Hermes) ; Buffer is the Node/SSR fallback.
|
|
17868
|
+
return typeof btoa !== 'undefined' ? btoa(bin) : Buffer.from(bytes).toString('base64');
|
|
17869
|
+
}
|
|
17870
|
+
// ----- WebCrypto (non-extractable) backend -----------------------------------
|
|
17871
|
+
function subtle() {
|
|
17872
|
+
const c = globalThis === null || globalThis === void 0 ? void 0 : globalThis.crypto;
|
|
17873
|
+
return c && c.subtle ? c.subtle : null;
|
|
17874
|
+
}
|
|
17875
|
+
function idb() {
|
|
17876
|
+
return new Promise((resolve, reject) => {
|
|
17877
|
+
const req = globalThis.indexedDB.open(IDB_NAME, 1);
|
|
17878
|
+
req.onupgradeneeded = () => req.result.createObjectStore(IDB_STORE);
|
|
17879
|
+
req.onsuccess = () => resolve(req.result);
|
|
17880
|
+
req.onerror = () => reject(req.error);
|
|
17881
|
+
});
|
|
17882
|
+
}
|
|
17883
|
+
function idbGet(db, key) {
|
|
17884
|
+
return new Promise((resolve, reject) => {
|
|
17885
|
+
const r = db.transaction(IDB_STORE, 'readonly').objectStore(IDB_STORE).get(key);
|
|
17886
|
+
r.onsuccess = () => resolve(r.result);
|
|
17887
|
+
r.onerror = () => reject(r.error);
|
|
17888
|
+
});
|
|
17889
|
+
}
|
|
17890
|
+
function idbPut(db, key, val) {
|
|
17891
|
+
return new Promise((resolve, reject) => {
|
|
17892
|
+
const r = db.transaction(IDB_STORE, 'readwrite').objectStore(IDB_STORE).put(val, key);
|
|
17893
|
+
r.onsuccess = () => resolve();
|
|
17894
|
+
r.onerror = () => reject(r.error);
|
|
17895
|
+
});
|
|
17896
|
+
}
|
|
17897
|
+
async function tryWebCrypto() {
|
|
17898
|
+
const s = subtle();
|
|
17899
|
+
if (!s || typeof globalThis.indexedDB === 'undefined')
|
|
17900
|
+
return null;
|
|
17901
|
+
try {
|
|
17902
|
+
const db = await idb();
|
|
17903
|
+
let pair = (await idbGet(db, IDB_KEY));
|
|
17904
|
+
if (!pair) {
|
|
17905
|
+
// Probe Ed25519 support by generating (throws on unsupported engines).
|
|
17906
|
+
pair = (await s.generateKey({ name: 'Ed25519' }, /* extractable */ false, [
|
|
17907
|
+
'sign',
|
|
17908
|
+
'verify',
|
|
17909
|
+
]));
|
|
17910
|
+
await idbPut(db, IDB_KEY, pair); // CryptoKey is structured-cloneable; bytes never exposed
|
|
17911
|
+
}
|
|
17912
|
+
const raw = new Uint8Array(await s.exportKey('raw', pair.publicKey)); // public is exportable
|
|
17913
|
+
const address = bs582.encode(raw);
|
|
17914
|
+
return {
|
|
17915
|
+
address,
|
|
17916
|
+
nonExtractable: true,
|
|
17917
|
+
async sign(message) {
|
|
17918
|
+
const data = new TextEncoder().encode(message);
|
|
17919
|
+
const sig = new Uint8Array(await s.sign({ name: 'Ed25519' }, pair.privateKey, data));
|
|
17920
|
+
return toBase64(sig);
|
|
17921
|
+
},
|
|
17922
|
+
};
|
|
17923
|
+
}
|
|
17924
|
+
catch (_a) {
|
|
17925
|
+
return null; // engine lacks Ed25519 / IndexedDB blocked → fall back
|
|
17926
|
+
}
|
|
17927
|
+
}
|
|
17928
|
+
// ----- tweetnacl (stored-secret) fallback ------------------------------------
|
|
17929
|
+
function fallbackKey() {
|
|
17930
|
+
const store = getPlatform().storage;
|
|
17931
|
+
let secret;
|
|
17932
|
+
const saved = store.getItem(FALLBACK_STORE_KEY);
|
|
17933
|
+
if (saved) {
|
|
17934
|
+
secret = bs582.decode(saved);
|
|
17935
|
+
}
|
|
17936
|
+
else {
|
|
17937
|
+
const kp = web3_js.Keypair.generate();
|
|
17938
|
+
secret = kp.secretKey; // 64 bytes
|
|
17939
|
+
store.setItem(FALLBACK_STORE_KEY, bs582.encode(secret));
|
|
17940
|
+
}
|
|
17941
|
+
const kp = web3_js.Keypair.fromSecretKey(secret);
|
|
17942
|
+
const address = kp.publicKey.toBase58();
|
|
17943
|
+
return {
|
|
17944
|
+
address,
|
|
17945
|
+
nonExtractable: false,
|
|
17946
|
+
async sign(message) {
|
|
17947
|
+
const data = new TextEncoder().encode(message);
|
|
17948
|
+
const sig = nacl.sign.detached(data, secret);
|
|
17949
|
+
return toBase64(sig);
|
|
17950
|
+
},
|
|
17951
|
+
};
|
|
17952
|
+
}
|
|
17953
|
+
let cached = null;
|
|
17954
|
+
/** Get (or create) this device's durable guest key. */
|
|
17955
|
+
async function getGuestKey() {
|
|
17956
|
+
var _a;
|
|
17957
|
+
if (cached)
|
|
17958
|
+
return cached;
|
|
17959
|
+
cached = (_a = (await tryWebCrypto())) !== null && _a !== void 0 ? _a : fallbackKey();
|
|
17960
|
+
return cached;
|
|
17961
|
+
}
|
|
17962
|
+
/** Forget the guest key on this device (a fresh signInAnonymously mints a new one). */
|
|
17963
|
+
async function clearGuestKey() {
|
|
17964
|
+
cached = null;
|
|
17965
|
+
try {
|
|
17966
|
+
getPlatform().storage.removeItem(FALLBACK_STORE_KEY);
|
|
17967
|
+
}
|
|
17968
|
+
catch (_a) { }
|
|
17969
|
+
try {
|
|
17970
|
+
if (typeof globalThis.indexedDB !== 'undefined') {
|
|
17971
|
+
const db = await idb();
|
|
17972
|
+
await new Promise((res) => {
|
|
17973
|
+
const r = db.transaction(IDB_STORE, 'readwrite').objectStore(IDB_STORE).delete(IDB_KEY);
|
|
17974
|
+
r.onsuccess = () => res();
|
|
17975
|
+
r.onerror = () => res();
|
|
17976
|
+
});
|
|
17977
|
+
}
|
|
17978
|
+
}
|
|
17979
|
+
catch (_b) { }
|
|
17980
|
+
}
|
|
17785
17981
|
|
|
17786
|
-
|
|
17787
|
-
|
|
17788
|
-
|
|
17789
|
-
|
|
17790
|
-
|
|
17791
|
-
|
|
17792
|
-
|
|
17793
|
-
|
|
17794
|
-
|
|
17795
|
-
|
|
17796
|
-
|
|
17797
|
-
|
|
17798
|
-
|
|
17799
|
-
|
|
17800
|
-
|
|
17801
|
-
|
|
17802
|
-
|
|
17803
|
-
|
|
17804
|
-
|
|
17805
|
-
|
|
17806
|
-
|
|
17807
|
-
|
|
17808
|
-
|
|
17809
|
-
|
|
17810
|
-
|
|
17811
|
-
|
|
17812
|
-
|
|
17813
|
-
|
|
17814
|
-
|
|
17815
|
-
|
|
17816
|
-
|
|
17817
|
-
|
|
17818
|
-
|
|
17819
|
-
|
|
17820
|
-
|
|
17821
|
-
|
|
17822
|
-
|
|
17823
|
-
|
|
17824
|
-
|
|
17825
|
-
|
|
17826
|
-
|
|
17827
|
-
|
|
17828
|
-
|
|
17829
|
-
|
|
17830
|
-
|
|
17831
|
-
|
|
17832
|
-
|
|
17833
|
-
|
|
17834
|
-
|
|
17835
|
-
|
|
17836
|
-
|
|
17837
|
-
|
|
17838
|
-
|
|
17839
|
-
|
|
17840
|
-
|
|
17841
|
-
|
|
17842
|
-
|
|
17843
|
-
|
|
17844
|
-
|
|
17845
|
-
|
|
17846
|
-
|
|
17847
|
-
|
|
17848
|
-
|
|
17849
|
-
|
|
17850
|
-
|
|
17851
|
-
|
|
17852
|
-
j13 = k[24] & 0xff | (k[25] & 0xff)<<8 | (k[26] & 0xff)<<16 | (k[27] & 0xff)<<24,
|
|
17853
|
-
j14 = k[28] & 0xff | (k[29] & 0xff)<<8 | (k[30] & 0xff)<<16 | (k[31] & 0xff)<<24,
|
|
17854
|
-
j15 = c[12] & 0xff | (c[13] & 0xff)<<8 | (c[14] & 0xff)<<16 | (c[15] & 0xff)<<24;
|
|
17855
|
-
|
|
17856
|
-
var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7,
|
|
17857
|
-
x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14,
|
|
17858
|
-
x15 = j15, u;
|
|
17859
|
-
|
|
17860
|
-
for (var i = 0; i < 20; i += 2) {
|
|
17861
|
-
u = x0 + x12 | 0;
|
|
17862
|
-
x4 ^= u<<7 | u>>>(32-7);
|
|
17863
|
-
u = x4 + x0 | 0;
|
|
17864
|
-
x8 ^= u<<9 | u>>>(32-9);
|
|
17865
|
-
u = x8 + x4 | 0;
|
|
17866
|
-
x12 ^= u<<13 | u>>>(32-13);
|
|
17867
|
-
u = x12 + x8 | 0;
|
|
17868
|
-
x0 ^= u<<18 | u>>>(32-18);
|
|
17869
|
-
|
|
17870
|
-
u = x5 + x1 | 0;
|
|
17871
|
-
x9 ^= u<<7 | u>>>(32-7);
|
|
17872
|
-
u = x9 + x5 | 0;
|
|
17873
|
-
x13 ^= u<<9 | u>>>(32-9);
|
|
17874
|
-
u = x13 + x9 | 0;
|
|
17875
|
-
x1 ^= u<<13 | u>>>(32-13);
|
|
17876
|
-
u = x1 + x13 | 0;
|
|
17877
|
-
x5 ^= u<<18 | u>>>(32-18);
|
|
17878
|
-
|
|
17879
|
-
u = x10 + x6 | 0;
|
|
17880
|
-
x14 ^= u<<7 | u>>>(32-7);
|
|
17881
|
-
u = x14 + x10 | 0;
|
|
17882
|
-
x2 ^= u<<9 | u>>>(32-9);
|
|
17883
|
-
u = x2 + x14 | 0;
|
|
17884
|
-
x6 ^= u<<13 | u>>>(32-13);
|
|
17885
|
-
u = x6 + x2 | 0;
|
|
17886
|
-
x10 ^= u<<18 | u>>>(32-18);
|
|
17887
|
-
|
|
17888
|
-
u = x15 + x11 | 0;
|
|
17889
|
-
x3 ^= u<<7 | u>>>(32-7);
|
|
17890
|
-
u = x3 + x15 | 0;
|
|
17891
|
-
x7 ^= u<<9 | u>>>(32-9);
|
|
17892
|
-
u = x7 + x3 | 0;
|
|
17893
|
-
x11 ^= u<<13 | u>>>(32-13);
|
|
17894
|
-
u = x11 + x7 | 0;
|
|
17895
|
-
x15 ^= u<<18 | u>>>(32-18);
|
|
17896
|
-
|
|
17897
|
-
u = x0 + x3 | 0;
|
|
17898
|
-
x1 ^= u<<7 | u>>>(32-7);
|
|
17899
|
-
u = x1 + x0 | 0;
|
|
17900
|
-
x2 ^= u<<9 | u>>>(32-9);
|
|
17901
|
-
u = x2 + x1 | 0;
|
|
17902
|
-
x3 ^= u<<13 | u>>>(32-13);
|
|
17903
|
-
u = x3 + x2 | 0;
|
|
17904
|
-
x0 ^= u<<18 | u>>>(32-18);
|
|
17905
|
-
|
|
17906
|
-
u = x5 + x4 | 0;
|
|
17907
|
-
x6 ^= u<<7 | u>>>(32-7);
|
|
17908
|
-
u = x6 + x5 | 0;
|
|
17909
|
-
x7 ^= u<<9 | u>>>(32-9);
|
|
17910
|
-
u = x7 + x6 | 0;
|
|
17911
|
-
x4 ^= u<<13 | u>>>(32-13);
|
|
17912
|
-
u = x4 + x7 | 0;
|
|
17913
|
-
x5 ^= u<<18 | u>>>(32-18);
|
|
17914
|
-
|
|
17915
|
-
u = x10 + x9 | 0;
|
|
17916
|
-
x11 ^= u<<7 | u>>>(32-7);
|
|
17917
|
-
u = x11 + x10 | 0;
|
|
17918
|
-
x8 ^= u<<9 | u>>>(32-9);
|
|
17919
|
-
u = x8 + x11 | 0;
|
|
17920
|
-
x9 ^= u<<13 | u>>>(32-13);
|
|
17921
|
-
u = x9 + x8 | 0;
|
|
17922
|
-
x10 ^= u<<18 | u>>>(32-18);
|
|
17923
|
-
|
|
17924
|
-
u = x15 + x14 | 0;
|
|
17925
|
-
x12 ^= u<<7 | u>>>(32-7);
|
|
17926
|
-
u = x12 + x15 | 0;
|
|
17927
|
-
x13 ^= u<<9 | u>>>(32-9);
|
|
17928
|
-
u = x13 + x12 | 0;
|
|
17929
|
-
x14 ^= u<<13 | u>>>(32-13);
|
|
17930
|
-
u = x14 + x13 | 0;
|
|
17931
|
-
x15 ^= u<<18 | u>>>(32-18);
|
|
17932
|
-
}
|
|
17933
|
-
x0 = x0 + j0 | 0;
|
|
17934
|
-
x1 = x1 + j1 | 0;
|
|
17935
|
-
x2 = x2 + j2 | 0;
|
|
17936
|
-
x3 = x3 + j3 | 0;
|
|
17937
|
-
x4 = x4 + j4 | 0;
|
|
17938
|
-
x5 = x5 + j5 | 0;
|
|
17939
|
-
x6 = x6 + j6 | 0;
|
|
17940
|
-
x7 = x7 + j7 | 0;
|
|
17941
|
-
x8 = x8 + j8 | 0;
|
|
17942
|
-
x9 = x9 + j9 | 0;
|
|
17943
|
-
x10 = x10 + j10 | 0;
|
|
17944
|
-
x11 = x11 + j11 | 0;
|
|
17945
|
-
x12 = x12 + j12 | 0;
|
|
17946
|
-
x13 = x13 + j13 | 0;
|
|
17947
|
-
x14 = x14 + j14 | 0;
|
|
17948
|
-
x15 = x15 + j15 | 0;
|
|
17949
|
-
|
|
17950
|
-
o[ 0] = x0 >>> 0 & 0xff;
|
|
17951
|
-
o[ 1] = x0 >>> 8 & 0xff;
|
|
17952
|
-
o[ 2] = x0 >>> 16 & 0xff;
|
|
17953
|
-
o[ 3] = x0 >>> 24 & 0xff;
|
|
17954
|
-
|
|
17955
|
-
o[ 4] = x1 >>> 0 & 0xff;
|
|
17956
|
-
o[ 5] = x1 >>> 8 & 0xff;
|
|
17957
|
-
o[ 6] = x1 >>> 16 & 0xff;
|
|
17958
|
-
o[ 7] = x1 >>> 24 & 0xff;
|
|
17959
|
-
|
|
17960
|
-
o[ 8] = x2 >>> 0 & 0xff;
|
|
17961
|
-
o[ 9] = x2 >>> 8 & 0xff;
|
|
17962
|
-
o[10] = x2 >>> 16 & 0xff;
|
|
17963
|
-
o[11] = x2 >>> 24 & 0xff;
|
|
17964
|
-
|
|
17965
|
-
o[12] = x3 >>> 0 & 0xff;
|
|
17966
|
-
o[13] = x3 >>> 8 & 0xff;
|
|
17967
|
-
o[14] = x3 >>> 16 & 0xff;
|
|
17968
|
-
o[15] = x3 >>> 24 & 0xff;
|
|
17969
|
-
|
|
17970
|
-
o[16] = x4 >>> 0 & 0xff;
|
|
17971
|
-
o[17] = x4 >>> 8 & 0xff;
|
|
17972
|
-
o[18] = x4 >>> 16 & 0xff;
|
|
17973
|
-
o[19] = x4 >>> 24 & 0xff;
|
|
17974
|
-
|
|
17975
|
-
o[20] = x5 >>> 0 & 0xff;
|
|
17976
|
-
o[21] = x5 >>> 8 & 0xff;
|
|
17977
|
-
o[22] = x5 >>> 16 & 0xff;
|
|
17978
|
-
o[23] = x5 >>> 24 & 0xff;
|
|
17979
|
-
|
|
17980
|
-
o[24] = x6 >>> 0 & 0xff;
|
|
17981
|
-
o[25] = x6 >>> 8 & 0xff;
|
|
17982
|
-
o[26] = x6 >>> 16 & 0xff;
|
|
17983
|
-
o[27] = x6 >>> 24 & 0xff;
|
|
17984
|
-
|
|
17985
|
-
o[28] = x7 >>> 0 & 0xff;
|
|
17986
|
-
o[29] = x7 >>> 8 & 0xff;
|
|
17987
|
-
o[30] = x7 >>> 16 & 0xff;
|
|
17988
|
-
o[31] = x7 >>> 24 & 0xff;
|
|
17989
|
-
|
|
17990
|
-
o[32] = x8 >>> 0 & 0xff;
|
|
17991
|
-
o[33] = x8 >>> 8 & 0xff;
|
|
17992
|
-
o[34] = x8 >>> 16 & 0xff;
|
|
17993
|
-
o[35] = x8 >>> 24 & 0xff;
|
|
17994
|
-
|
|
17995
|
-
o[36] = x9 >>> 0 & 0xff;
|
|
17996
|
-
o[37] = x9 >>> 8 & 0xff;
|
|
17997
|
-
o[38] = x9 >>> 16 & 0xff;
|
|
17998
|
-
o[39] = x9 >>> 24 & 0xff;
|
|
17999
|
-
|
|
18000
|
-
o[40] = x10 >>> 0 & 0xff;
|
|
18001
|
-
o[41] = x10 >>> 8 & 0xff;
|
|
18002
|
-
o[42] = x10 >>> 16 & 0xff;
|
|
18003
|
-
o[43] = x10 >>> 24 & 0xff;
|
|
18004
|
-
|
|
18005
|
-
o[44] = x11 >>> 0 & 0xff;
|
|
18006
|
-
o[45] = x11 >>> 8 & 0xff;
|
|
18007
|
-
o[46] = x11 >>> 16 & 0xff;
|
|
18008
|
-
o[47] = x11 >>> 24 & 0xff;
|
|
18009
|
-
|
|
18010
|
-
o[48] = x12 >>> 0 & 0xff;
|
|
18011
|
-
o[49] = x12 >>> 8 & 0xff;
|
|
18012
|
-
o[50] = x12 >>> 16 & 0xff;
|
|
18013
|
-
o[51] = x12 >>> 24 & 0xff;
|
|
18014
|
-
|
|
18015
|
-
o[52] = x13 >>> 0 & 0xff;
|
|
18016
|
-
o[53] = x13 >>> 8 & 0xff;
|
|
18017
|
-
o[54] = x13 >>> 16 & 0xff;
|
|
18018
|
-
o[55] = x13 >>> 24 & 0xff;
|
|
18019
|
-
|
|
18020
|
-
o[56] = x14 >>> 0 & 0xff;
|
|
18021
|
-
o[57] = x14 >>> 8 & 0xff;
|
|
18022
|
-
o[58] = x14 >>> 16 & 0xff;
|
|
18023
|
-
o[59] = x14 >>> 24 & 0xff;
|
|
18024
|
-
|
|
18025
|
-
o[60] = x15 >>> 0 & 0xff;
|
|
18026
|
-
o[61] = x15 >>> 8 & 0xff;
|
|
18027
|
-
o[62] = x15 >>> 16 & 0xff;
|
|
18028
|
-
o[63] = x15 >>> 24 & 0xff;
|
|
18029
|
-
}
|
|
18030
|
-
|
|
18031
|
-
function core_hsalsa20(o,p,k,c) {
|
|
18032
|
-
var j0 = c[ 0] & 0xff | (c[ 1] & 0xff)<<8 | (c[ 2] & 0xff)<<16 | (c[ 3] & 0xff)<<24,
|
|
18033
|
-
j1 = k[ 0] & 0xff | (k[ 1] & 0xff)<<8 | (k[ 2] & 0xff)<<16 | (k[ 3] & 0xff)<<24,
|
|
18034
|
-
j2 = k[ 4] & 0xff | (k[ 5] & 0xff)<<8 | (k[ 6] & 0xff)<<16 | (k[ 7] & 0xff)<<24,
|
|
18035
|
-
j3 = k[ 8] & 0xff | (k[ 9] & 0xff)<<8 | (k[10] & 0xff)<<16 | (k[11] & 0xff)<<24,
|
|
18036
|
-
j4 = k[12] & 0xff | (k[13] & 0xff)<<8 | (k[14] & 0xff)<<16 | (k[15] & 0xff)<<24,
|
|
18037
|
-
j5 = c[ 4] & 0xff | (c[ 5] & 0xff)<<8 | (c[ 6] & 0xff)<<16 | (c[ 7] & 0xff)<<24,
|
|
18038
|
-
j6 = p[ 0] & 0xff | (p[ 1] & 0xff)<<8 | (p[ 2] & 0xff)<<16 | (p[ 3] & 0xff)<<24,
|
|
18039
|
-
j7 = p[ 4] & 0xff | (p[ 5] & 0xff)<<8 | (p[ 6] & 0xff)<<16 | (p[ 7] & 0xff)<<24,
|
|
18040
|
-
j8 = p[ 8] & 0xff | (p[ 9] & 0xff)<<8 | (p[10] & 0xff)<<16 | (p[11] & 0xff)<<24,
|
|
18041
|
-
j9 = p[12] & 0xff | (p[13] & 0xff)<<8 | (p[14] & 0xff)<<16 | (p[15] & 0xff)<<24,
|
|
18042
|
-
j10 = c[ 8] & 0xff | (c[ 9] & 0xff)<<8 | (c[10] & 0xff)<<16 | (c[11] & 0xff)<<24,
|
|
18043
|
-
j11 = k[16] & 0xff | (k[17] & 0xff)<<8 | (k[18] & 0xff)<<16 | (k[19] & 0xff)<<24,
|
|
18044
|
-
j12 = k[20] & 0xff | (k[21] & 0xff)<<8 | (k[22] & 0xff)<<16 | (k[23] & 0xff)<<24,
|
|
18045
|
-
j13 = k[24] & 0xff | (k[25] & 0xff)<<8 | (k[26] & 0xff)<<16 | (k[27] & 0xff)<<24,
|
|
18046
|
-
j14 = k[28] & 0xff | (k[29] & 0xff)<<8 | (k[30] & 0xff)<<16 | (k[31] & 0xff)<<24,
|
|
18047
|
-
j15 = c[12] & 0xff | (c[13] & 0xff)<<8 | (c[14] & 0xff)<<16 | (c[15] & 0xff)<<24;
|
|
18048
|
-
|
|
18049
|
-
var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7,
|
|
18050
|
-
x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14,
|
|
18051
|
-
x15 = j15, u;
|
|
18052
|
-
|
|
18053
|
-
for (var i = 0; i < 20; i += 2) {
|
|
18054
|
-
u = x0 + x12 | 0;
|
|
18055
|
-
x4 ^= u<<7 | u>>>(32-7);
|
|
18056
|
-
u = x4 + x0 | 0;
|
|
18057
|
-
x8 ^= u<<9 | u>>>(32-9);
|
|
18058
|
-
u = x8 + x4 | 0;
|
|
18059
|
-
x12 ^= u<<13 | u>>>(32-13);
|
|
18060
|
-
u = x12 + x8 | 0;
|
|
18061
|
-
x0 ^= u<<18 | u>>>(32-18);
|
|
18062
|
-
|
|
18063
|
-
u = x5 + x1 | 0;
|
|
18064
|
-
x9 ^= u<<7 | u>>>(32-7);
|
|
18065
|
-
u = x9 + x5 | 0;
|
|
18066
|
-
x13 ^= u<<9 | u>>>(32-9);
|
|
18067
|
-
u = x13 + x9 | 0;
|
|
18068
|
-
x1 ^= u<<13 | u>>>(32-13);
|
|
18069
|
-
u = x1 + x13 | 0;
|
|
18070
|
-
x5 ^= u<<18 | u>>>(32-18);
|
|
18071
|
-
|
|
18072
|
-
u = x10 + x6 | 0;
|
|
18073
|
-
x14 ^= u<<7 | u>>>(32-7);
|
|
18074
|
-
u = x14 + x10 | 0;
|
|
18075
|
-
x2 ^= u<<9 | u>>>(32-9);
|
|
18076
|
-
u = x2 + x14 | 0;
|
|
18077
|
-
x6 ^= u<<13 | u>>>(32-13);
|
|
18078
|
-
u = x6 + x2 | 0;
|
|
18079
|
-
x10 ^= u<<18 | u>>>(32-18);
|
|
18080
|
-
|
|
18081
|
-
u = x15 + x11 | 0;
|
|
18082
|
-
x3 ^= u<<7 | u>>>(32-7);
|
|
18083
|
-
u = x3 + x15 | 0;
|
|
18084
|
-
x7 ^= u<<9 | u>>>(32-9);
|
|
18085
|
-
u = x7 + x3 | 0;
|
|
18086
|
-
x11 ^= u<<13 | u>>>(32-13);
|
|
18087
|
-
u = x11 + x7 | 0;
|
|
18088
|
-
x15 ^= u<<18 | u>>>(32-18);
|
|
18089
|
-
|
|
18090
|
-
u = x0 + x3 | 0;
|
|
18091
|
-
x1 ^= u<<7 | u>>>(32-7);
|
|
18092
|
-
u = x1 + x0 | 0;
|
|
18093
|
-
x2 ^= u<<9 | u>>>(32-9);
|
|
18094
|
-
u = x2 + x1 | 0;
|
|
18095
|
-
x3 ^= u<<13 | u>>>(32-13);
|
|
18096
|
-
u = x3 + x2 | 0;
|
|
18097
|
-
x0 ^= u<<18 | u>>>(32-18);
|
|
18098
|
-
|
|
18099
|
-
u = x5 + x4 | 0;
|
|
18100
|
-
x6 ^= u<<7 | u>>>(32-7);
|
|
18101
|
-
u = x6 + x5 | 0;
|
|
18102
|
-
x7 ^= u<<9 | u>>>(32-9);
|
|
18103
|
-
u = x7 + x6 | 0;
|
|
18104
|
-
x4 ^= u<<13 | u>>>(32-13);
|
|
18105
|
-
u = x4 + x7 | 0;
|
|
18106
|
-
x5 ^= u<<18 | u>>>(32-18);
|
|
18107
|
-
|
|
18108
|
-
u = x10 + x9 | 0;
|
|
18109
|
-
x11 ^= u<<7 | u>>>(32-7);
|
|
18110
|
-
u = x11 + x10 | 0;
|
|
18111
|
-
x8 ^= u<<9 | u>>>(32-9);
|
|
18112
|
-
u = x8 + x11 | 0;
|
|
18113
|
-
x9 ^= u<<13 | u>>>(32-13);
|
|
18114
|
-
u = x9 + x8 | 0;
|
|
18115
|
-
x10 ^= u<<18 | u>>>(32-18);
|
|
18116
|
-
|
|
18117
|
-
u = x15 + x14 | 0;
|
|
18118
|
-
x12 ^= u<<7 | u>>>(32-7);
|
|
18119
|
-
u = x12 + x15 | 0;
|
|
18120
|
-
x13 ^= u<<9 | u>>>(32-9);
|
|
18121
|
-
u = x13 + x12 | 0;
|
|
18122
|
-
x14 ^= u<<13 | u>>>(32-13);
|
|
18123
|
-
u = x14 + x13 | 0;
|
|
18124
|
-
x15 ^= u<<18 | u>>>(32-18);
|
|
18125
|
-
}
|
|
18126
|
-
|
|
18127
|
-
o[ 0] = x0 >>> 0 & 0xff;
|
|
18128
|
-
o[ 1] = x0 >>> 8 & 0xff;
|
|
18129
|
-
o[ 2] = x0 >>> 16 & 0xff;
|
|
18130
|
-
o[ 3] = x0 >>> 24 & 0xff;
|
|
18131
|
-
|
|
18132
|
-
o[ 4] = x5 >>> 0 & 0xff;
|
|
18133
|
-
o[ 5] = x5 >>> 8 & 0xff;
|
|
18134
|
-
o[ 6] = x5 >>> 16 & 0xff;
|
|
18135
|
-
o[ 7] = x5 >>> 24 & 0xff;
|
|
18136
|
-
|
|
18137
|
-
o[ 8] = x10 >>> 0 & 0xff;
|
|
18138
|
-
o[ 9] = x10 >>> 8 & 0xff;
|
|
18139
|
-
o[10] = x10 >>> 16 & 0xff;
|
|
18140
|
-
o[11] = x10 >>> 24 & 0xff;
|
|
18141
|
-
|
|
18142
|
-
o[12] = x15 >>> 0 & 0xff;
|
|
18143
|
-
o[13] = x15 >>> 8 & 0xff;
|
|
18144
|
-
o[14] = x15 >>> 16 & 0xff;
|
|
18145
|
-
o[15] = x15 >>> 24 & 0xff;
|
|
18146
|
-
|
|
18147
|
-
o[16] = x6 >>> 0 & 0xff;
|
|
18148
|
-
o[17] = x6 >>> 8 & 0xff;
|
|
18149
|
-
o[18] = x6 >>> 16 & 0xff;
|
|
18150
|
-
o[19] = x6 >>> 24 & 0xff;
|
|
18151
|
-
|
|
18152
|
-
o[20] = x7 >>> 0 & 0xff;
|
|
18153
|
-
o[21] = x7 >>> 8 & 0xff;
|
|
18154
|
-
o[22] = x7 >>> 16 & 0xff;
|
|
18155
|
-
o[23] = x7 >>> 24 & 0xff;
|
|
18156
|
-
|
|
18157
|
-
o[24] = x8 >>> 0 & 0xff;
|
|
18158
|
-
o[25] = x8 >>> 8 & 0xff;
|
|
18159
|
-
o[26] = x8 >>> 16 & 0xff;
|
|
18160
|
-
o[27] = x8 >>> 24 & 0xff;
|
|
18161
|
-
|
|
18162
|
-
o[28] = x9 >>> 0 & 0xff;
|
|
18163
|
-
o[29] = x9 >>> 8 & 0xff;
|
|
18164
|
-
o[30] = x9 >>> 16 & 0xff;
|
|
18165
|
-
o[31] = x9 >>> 24 & 0xff;
|
|
18166
|
-
}
|
|
18167
|
-
|
|
18168
|
-
function crypto_core_salsa20(out,inp,k,c) {
|
|
18169
|
-
core_salsa20(out,inp,k,c);
|
|
18170
|
-
}
|
|
18171
|
-
|
|
18172
|
-
function crypto_core_hsalsa20(out,inp,k,c) {
|
|
18173
|
-
core_hsalsa20(out,inp,k,c);
|
|
18174
|
-
}
|
|
18175
|
-
|
|
18176
|
-
var sigma = new Uint8Array([101, 120, 112, 97, 110, 100, 32, 51, 50, 45, 98, 121, 116, 101, 32, 107]);
|
|
18177
|
-
// "expand 32-byte k"
|
|
18178
|
-
|
|
18179
|
-
function crypto_stream_salsa20_xor(c,cpos,m,mpos,b,n,k) {
|
|
18180
|
-
var z = new Uint8Array(16), x = new Uint8Array(64);
|
|
18181
|
-
var u, i;
|
|
18182
|
-
for (i = 0; i < 16; i++) z[i] = 0;
|
|
18183
|
-
for (i = 0; i < 8; i++) z[i] = n[i];
|
|
18184
|
-
while (b >= 64) {
|
|
18185
|
-
crypto_core_salsa20(x,z,k,sigma);
|
|
18186
|
-
for (i = 0; i < 64; i++) c[cpos+i] = m[mpos+i] ^ x[i];
|
|
18187
|
-
u = 1;
|
|
18188
|
-
for (i = 8; i < 16; i++) {
|
|
18189
|
-
u = u + (z[i] & 0xff) | 0;
|
|
18190
|
-
z[i] = u & 0xff;
|
|
18191
|
-
u >>>= 8;
|
|
18192
|
-
}
|
|
18193
|
-
b -= 64;
|
|
18194
|
-
cpos += 64;
|
|
18195
|
-
mpos += 64;
|
|
18196
|
-
}
|
|
18197
|
-
if (b > 0) {
|
|
18198
|
-
crypto_core_salsa20(x,z,k,sigma);
|
|
18199
|
-
for (i = 0; i < b; i++) c[cpos+i] = m[mpos+i] ^ x[i];
|
|
18200
|
-
}
|
|
18201
|
-
return 0;
|
|
18202
|
-
}
|
|
18203
|
-
|
|
18204
|
-
function crypto_stream_salsa20(c,cpos,b,n,k) {
|
|
18205
|
-
var z = new Uint8Array(16), x = new Uint8Array(64);
|
|
18206
|
-
var u, i;
|
|
18207
|
-
for (i = 0; i < 16; i++) z[i] = 0;
|
|
18208
|
-
for (i = 0; i < 8; i++) z[i] = n[i];
|
|
18209
|
-
while (b >= 64) {
|
|
18210
|
-
crypto_core_salsa20(x,z,k,sigma);
|
|
18211
|
-
for (i = 0; i < 64; i++) c[cpos+i] = x[i];
|
|
18212
|
-
u = 1;
|
|
18213
|
-
for (i = 8; i < 16; i++) {
|
|
18214
|
-
u = u + (z[i] & 0xff) | 0;
|
|
18215
|
-
z[i] = u & 0xff;
|
|
18216
|
-
u >>>= 8;
|
|
18217
|
-
}
|
|
18218
|
-
b -= 64;
|
|
18219
|
-
cpos += 64;
|
|
18220
|
-
}
|
|
18221
|
-
if (b > 0) {
|
|
18222
|
-
crypto_core_salsa20(x,z,k,sigma);
|
|
18223
|
-
for (i = 0; i < b; i++) c[cpos+i] = x[i];
|
|
18224
|
-
}
|
|
18225
|
-
return 0;
|
|
18226
|
-
}
|
|
18227
|
-
|
|
18228
|
-
function crypto_stream(c,cpos,d,n,k) {
|
|
18229
|
-
var s = new Uint8Array(32);
|
|
18230
|
-
crypto_core_hsalsa20(s,n,k,sigma);
|
|
18231
|
-
var sn = new Uint8Array(8);
|
|
18232
|
-
for (var i = 0; i < 8; i++) sn[i] = n[i+16];
|
|
18233
|
-
return crypto_stream_salsa20(c,cpos,d,sn,s);
|
|
18234
|
-
}
|
|
18235
|
-
|
|
18236
|
-
function crypto_stream_xor(c,cpos,m,mpos,d,n,k) {
|
|
18237
|
-
var s = new Uint8Array(32);
|
|
18238
|
-
crypto_core_hsalsa20(s,n,k,sigma);
|
|
18239
|
-
var sn = new Uint8Array(8);
|
|
18240
|
-
for (var i = 0; i < 8; i++) sn[i] = n[i+16];
|
|
18241
|
-
return crypto_stream_salsa20_xor(c,cpos,m,mpos,d,sn,s);
|
|
18242
|
-
}
|
|
18243
|
-
|
|
18244
|
-
/*
|
|
18245
|
-
* Port of Andrew Moon's Poly1305-donna-16. Public domain.
|
|
18246
|
-
* https://github.com/floodyberry/poly1305-donna
|
|
18247
|
-
*/
|
|
18248
|
-
|
|
18249
|
-
var poly1305 = function(key) {
|
|
18250
|
-
this.buffer = new Uint8Array(16);
|
|
18251
|
-
this.r = new Uint16Array(10);
|
|
18252
|
-
this.h = new Uint16Array(10);
|
|
18253
|
-
this.pad = new Uint16Array(8);
|
|
18254
|
-
this.leftover = 0;
|
|
18255
|
-
this.fin = 0;
|
|
18256
|
-
|
|
18257
|
-
var t0, t1, t2, t3, t4, t5, t6, t7;
|
|
18258
|
-
|
|
18259
|
-
t0 = key[ 0] & 0xff | (key[ 1] & 0xff) << 8; this.r[0] = ( t0 ) & 0x1fff;
|
|
18260
|
-
t1 = key[ 2] & 0xff | (key[ 3] & 0xff) << 8; this.r[1] = ((t0 >>> 13) | (t1 << 3)) & 0x1fff;
|
|
18261
|
-
t2 = key[ 4] & 0xff | (key[ 5] & 0xff) << 8; this.r[2] = ((t1 >>> 10) | (t2 << 6)) & 0x1f03;
|
|
18262
|
-
t3 = key[ 6] & 0xff | (key[ 7] & 0xff) << 8; this.r[3] = ((t2 >>> 7) | (t3 << 9)) & 0x1fff;
|
|
18263
|
-
t4 = key[ 8] & 0xff | (key[ 9] & 0xff) << 8; this.r[4] = ((t3 >>> 4) | (t4 << 12)) & 0x00ff;
|
|
18264
|
-
this.r[5] = ((t4 >>> 1)) & 0x1ffe;
|
|
18265
|
-
t5 = key[10] & 0xff | (key[11] & 0xff) << 8; this.r[6] = ((t4 >>> 14) | (t5 << 2)) & 0x1fff;
|
|
18266
|
-
t6 = key[12] & 0xff | (key[13] & 0xff) << 8; this.r[7] = ((t5 >>> 11) | (t6 << 5)) & 0x1f81;
|
|
18267
|
-
t7 = key[14] & 0xff | (key[15] & 0xff) << 8; this.r[8] = ((t6 >>> 8) | (t7 << 8)) & 0x1fff;
|
|
18268
|
-
this.r[9] = ((t7 >>> 5)) & 0x007f;
|
|
18269
|
-
|
|
18270
|
-
this.pad[0] = key[16] & 0xff | (key[17] & 0xff) << 8;
|
|
18271
|
-
this.pad[1] = key[18] & 0xff | (key[19] & 0xff) << 8;
|
|
18272
|
-
this.pad[2] = key[20] & 0xff | (key[21] & 0xff) << 8;
|
|
18273
|
-
this.pad[3] = key[22] & 0xff | (key[23] & 0xff) << 8;
|
|
18274
|
-
this.pad[4] = key[24] & 0xff | (key[25] & 0xff) << 8;
|
|
18275
|
-
this.pad[5] = key[26] & 0xff | (key[27] & 0xff) << 8;
|
|
18276
|
-
this.pad[6] = key[28] & 0xff | (key[29] & 0xff) << 8;
|
|
18277
|
-
this.pad[7] = key[30] & 0xff | (key[31] & 0xff) << 8;
|
|
18278
|
-
};
|
|
18279
|
-
|
|
18280
|
-
poly1305.prototype.blocks = function(m, mpos, bytes) {
|
|
18281
|
-
var hibit = this.fin ? 0 : (1 << 11);
|
|
18282
|
-
var t0, t1, t2, t3, t4, t5, t6, t7, c;
|
|
18283
|
-
var d0, d1, d2, d3, d4, d5, d6, d7, d8, d9;
|
|
18284
|
-
|
|
18285
|
-
var h0 = this.h[0],
|
|
18286
|
-
h1 = this.h[1],
|
|
18287
|
-
h2 = this.h[2],
|
|
18288
|
-
h3 = this.h[3],
|
|
18289
|
-
h4 = this.h[4],
|
|
18290
|
-
h5 = this.h[5],
|
|
18291
|
-
h6 = this.h[6],
|
|
18292
|
-
h7 = this.h[7],
|
|
18293
|
-
h8 = this.h[8],
|
|
18294
|
-
h9 = this.h[9];
|
|
18295
|
-
|
|
18296
|
-
var r0 = this.r[0],
|
|
18297
|
-
r1 = this.r[1],
|
|
18298
|
-
r2 = this.r[2],
|
|
18299
|
-
r3 = this.r[3],
|
|
18300
|
-
r4 = this.r[4],
|
|
18301
|
-
r5 = this.r[5],
|
|
18302
|
-
r6 = this.r[6],
|
|
18303
|
-
r7 = this.r[7],
|
|
18304
|
-
r8 = this.r[8],
|
|
18305
|
-
r9 = this.r[9];
|
|
18306
|
-
|
|
18307
|
-
while (bytes >= 16) {
|
|
18308
|
-
t0 = m[mpos+ 0] & 0xff | (m[mpos+ 1] & 0xff) << 8; h0 += ( t0 ) & 0x1fff;
|
|
18309
|
-
t1 = m[mpos+ 2] & 0xff | (m[mpos+ 3] & 0xff) << 8; h1 += ((t0 >>> 13) | (t1 << 3)) & 0x1fff;
|
|
18310
|
-
t2 = m[mpos+ 4] & 0xff | (m[mpos+ 5] & 0xff) << 8; h2 += ((t1 >>> 10) | (t2 << 6)) & 0x1fff;
|
|
18311
|
-
t3 = m[mpos+ 6] & 0xff | (m[mpos+ 7] & 0xff) << 8; h3 += ((t2 >>> 7) | (t3 << 9)) & 0x1fff;
|
|
18312
|
-
t4 = m[mpos+ 8] & 0xff | (m[mpos+ 9] & 0xff) << 8; h4 += ((t3 >>> 4) | (t4 << 12)) & 0x1fff;
|
|
18313
|
-
h5 += ((t4 >>> 1)) & 0x1fff;
|
|
18314
|
-
t5 = m[mpos+10] & 0xff | (m[mpos+11] & 0xff) << 8; h6 += ((t4 >>> 14) | (t5 << 2)) & 0x1fff;
|
|
18315
|
-
t6 = m[mpos+12] & 0xff | (m[mpos+13] & 0xff) << 8; h7 += ((t5 >>> 11) | (t6 << 5)) & 0x1fff;
|
|
18316
|
-
t7 = m[mpos+14] & 0xff | (m[mpos+15] & 0xff) << 8; h8 += ((t6 >>> 8) | (t7 << 8)) & 0x1fff;
|
|
18317
|
-
h9 += ((t7 >>> 5)) | hibit;
|
|
18318
|
-
|
|
18319
|
-
c = 0;
|
|
18320
|
-
|
|
18321
|
-
d0 = c;
|
|
18322
|
-
d0 += h0 * r0;
|
|
18323
|
-
d0 += h1 * (5 * r9);
|
|
18324
|
-
d0 += h2 * (5 * r8);
|
|
18325
|
-
d0 += h3 * (5 * r7);
|
|
18326
|
-
d0 += h4 * (5 * r6);
|
|
18327
|
-
c = (d0 >>> 13); d0 &= 0x1fff;
|
|
18328
|
-
d0 += h5 * (5 * r5);
|
|
18329
|
-
d0 += h6 * (5 * r4);
|
|
18330
|
-
d0 += h7 * (5 * r3);
|
|
18331
|
-
d0 += h8 * (5 * r2);
|
|
18332
|
-
d0 += h9 * (5 * r1);
|
|
18333
|
-
c += (d0 >>> 13); d0 &= 0x1fff;
|
|
18334
|
-
|
|
18335
|
-
d1 = c;
|
|
18336
|
-
d1 += h0 * r1;
|
|
18337
|
-
d1 += h1 * r0;
|
|
18338
|
-
d1 += h2 * (5 * r9);
|
|
18339
|
-
d1 += h3 * (5 * r8);
|
|
18340
|
-
d1 += h4 * (5 * r7);
|
|
18341
|
-
c = (d1 >>> 13); d1 &= 0x1fff;
|
|
18342
|
-
d1 += h5 * (5 * r6);
|
|
18343
|
-
d1 += h6 * (5 * r5);
|
|
18344
|
-
d1 += h7 * (5 * r4);
|
|
18345
|
-
d1 += h8 * (5 * r3);
|
|
18346
|
-
d1 += h9 * (5 * r2);
|
|
18347
|
-
c += (d1 >>> 13); d1 &= 0x1fff;
|
|
18348
|
-
|
|
18349
|
-
d2 = c;
|
|
18350
|
-
d2 += h0 * r2;
|
|
18351
|
-
d2 += h1 * r1;
|
|
18352
|
-
d2 += h2 * r0;
|
|
18353
|
-
d2 += h3 * (5 * r9);
|
|
18354
|
-
d2 += h4 * (5 * r8);
|
|
18355
|
-
c = (d2 >>> 13); d2 &= 0x1fff;
|
|
18356
|
-
d2 += h5 * (5 * r7);
|
|
18357
|
-
d2 += h6 * (5 * r6);
|
|
18358
|
-
d2 += h7 * (5 * r5);
|
|
18359
|
-
d2 += h8 * (5 * r4);
|
|
18360
|
-
d2 += h9 * (5 * r3);
|
|
18361
|
-
c += (d2 >>> 13); d2 &= 0x1fff;
|
|
18362
|
-
|
|
18363
|
-
d3 = c;
|
|
18364
|
-
d3 += h0 * r3;
|
|
18365
|
-
d3 += h1 * r2;
|
|
18366
|
-
d3 += h2 * r1;
|
|
18367
|
-
d3 += h3 * r0;
|
|
18368
|
-
d3 += h4 * (5 * r9);
|
|
18369
|
-
c = (d3 >>> 13); d3 &= 0x1fff;
|
|
18370
|
-
d3 += h5 * (5 * r8);
|
|
18371
|
-
d3 += h6 * (5 * r7);
|
|
18372
|
-
d3 += h7 * (5 * r6);
|
|
18373
|
-
d3 += h8 * (5 * r5);
|
|
18374
|
-
d3 += h9 * (5 * r4);
|
|
18375
|
-
c += (d3 >>> 13); d3 &= 0x1fff;
|
|
18376
|
-
|
|
18377
|
-
d4 = c;
|
|
18378
|
-
d4 += h0 * r4;
|
|
18379
|
-
d4 += h1 * r3;
|
|
18380
|
-
d4 += h2 * r2;
|
|
18381
|
-
d4 += h3 * r1;
|
|
18382
|
-
d4 += h4 * r0;
|
|
18383
|
-
c = (d4 >>> 13); d4 &= 0x1fff;
|
|
18384
|
-
d4 += h5 * (5 * r9);
|
|
18385
|
-
d4 += h6 * (5 * r8);
|
|
18386
|
-
d4 += h7 * (5 * r7);
|
|
18387
|
-
d4 += h8 * (5 * r6);
|
|
18388
|
-
d4 += h9 * (5 * r5);
|
|
18389
|
-
c += (d4 >>> 13); d4 &= 0x1fff;
|
|
18390
|
-
|
|
18391
|
-
d5 = c;
|
|
18392
|
-
d5 += h0 * r5;
|
|
18393
|
-
d5 += h1 * r4;
|
|
18394
|
-
d5 += h2 * r3;
|
|
18395
|
-
d5 += h3 * r2;
|
|
18396
|
-
d5 += h4 * r1;
|
|
18397
|
-
c = (d5 >>> 13); d5 &= 0x1fff;
|
|
18398
|
-
d5 += h5 * r0;
|
|
18399
|
-
d5 += h6 * (5 * r9);
|
|
18400
|
-
d5 += h7 * (5 * r8);
|
|
18401
|
-
d5 += h8 * (5 * r7);
|
|
18402
|
-
d5 += h9 * (5 * r6);
|
|
18403
|
-
c += (d5 >>> 13); d5 &= 0x1fff;
|
|
18404
|
-
|
|
18405
|
-
d6 = c;
|
|
18406
|
-
d6 += h0 * r6;
|
|
18407
|
-
d6 += h1 * r5;
|
|
18408
|
-
d6 += h2 * r4;
|
|
18409
|
-
d6 += h3 * r3;
|
|
18410
|
-
d6 += h4 * r2;
|
|
18411
|
-
c = (d6 >>> 13); d6 &= 0x1fff;
|
|
18412
|
-
d6 += h5 * r1;
|
|
18413
|
-
d6 += h6 * r0;
|
|
18414
|
-
d6 += h7 * (5 * r9);
|
|
18415
|
-
d6 += h8 * (5 * r8);
|
|
18416
|
-
d6 += h9 * (5 * r7);
|
|
18417
|
-
c += (d6 >>> 13); d6 &= 0x1fff;
|
|
18418
|
-
|
|
18419
|
-
d7 = c;
|
|
18420
|
-
d7 += h0 * r7;
|
|
18421
|
-
d7 += h1 * r6;
|
|
18422
|
-
d7 += h2 * r5;
|
|
18423
|
-
d7 += h3 * r4;
|
|
18424
|
-
d7 += h4 * r3;
|
|
18425
|
-
c = (d7 >>> 13); d7 &= 0x1fff;
|
|
18426
|
-
d7 += h5 * r2;
|
|
18427
|
-
d7 += h6 * r1;
|
|
18428
|
-
d7 += h7 * r0;
|
|
18429
|
-
d7 += h8 * (5 * r9);
|
|
18430
|
-
d7 += h9 * (5 * r8);
|
|
18431
|
-
c += (d7 >>> 13); d7 &= 0x1fff;
|
|
18432
|
-
|
|
18433
|
-
d8 = c;
|
|
18434
|
-
d8 += h0 * r8;
|
|
18435
|
-
d8 += h1 * r7;
|
|
18436
|
-
d8 += h2 * r6;
|
|
18437
|
-
d8 += h3 * r5;
|
|
18438
|
-
d8 += h4 * r4;
|
|
18439
|
-
c = (d8 >>> 13); d8 &= 0x1fff;
|
|
18440
|
-
d8 += h5 * r3;
|
|
18441
|
-
d8 += h6 * r2;
|
|
18442
|
-
d8 += h7 * r1;
|
|
18443
|
-
d8 += h8 * r0;
|
|
18444
|
-
d8 += h9 * (5 * r9);
|
|
18445
|
-
c += (d8 >>> 13); d8 &= 0x1fff;
|
|
18446
|
-
|
|
18447
|
-
d9 = c;
|
|
18448
|
-
d9 += h0 * r9;
|
|
18449
|
-
d9 += h1 * r8;
|
|
18450
|
-
d9 += h2 * r7;
|
|
18451
|
-
d9 += h3 * r6;
|
|
18452
|
-
d9 += h4 * r5;
|
|
18453
|
-
c = (d9 >>> 13); d9 &= 0x1fff;
|
|
18454
|
-
d9 += h5 * r4;
|
|
18455
|
-
d9 += h6 * r3;
|
|
18456
|
-
d9 += h7 * r2;
|
|
18457
|
-
d9 += h8 * r1;
|
|
18458
|
-
d9 += h9 * r0;
|
|
18459
|
-
c += (d9 >>> 13); d9 &= 0x1fff;
|
|
18460
|
-
|
|
18461
|
-
c = (((c << 2) + c)) | 0;
|
|
18462
|
-
c = (c + d0) | 0;
|
|
18463
|
-
d0 = c & 0x1fff;
|
|
18464
|
-
c = (c >>> 13);
|
|
18465
|
-
d1 += c;
|
|
18466
|
-
|
|
18467
|
-
h0 = d0;
|
|
18468
|
-
h1 = d1;
|
|
18469
|
-
h2 = d2;
|
|
18470
|
-
h3 = d3;
|
|
18471
|
-
h4 = d4;
|
|
18472
|
-
h5 = d5;
|
|
18473
|
-
h6 = d6;
|
|
18474
|
-
h7 = d7;
|
|
18475
|
-
h8 = d8;
|
|
18476
|
-
h9 = d9;
|
|
18477
|
-
|
|
18478
|
-
mpos += 16;
|
|
18479
|
-
bytes -= 16;
|
|
18480
|
-
}
|
|
18481
|
-
this.h[0] = h0;
|
|
18482
|
-
this.h[1] = h1;
|
|
18483
|
-
this.h[2] = h2;
|
|
18484
|
-
this.h[3] = h3;
|
|
18485
|
-
this.h[4] = h4;
|
|
18486
|
-
this.h[5] = h5;
|
|
18487
|
-
this.h[6] = h6;
|
|
18488
|
-
this.h[7] = h7;
|
|
18489
|
-
this.h[8] = h8;
|
|
18490
|
-
this.h[9] = h9;
|
|
18491
|
-
};
|
|
18492
|
-
|
|
18493
|
-
poly1305.prototype.finish = function(mac, macpos) {
|
|
18494
|
-
var g = new Uint16Array(10);
|
|
18495
|
-
var c, mask, f, i;
|
|
18496
|
-
|
|
18497
|
-
if (this.leftover) {
|
|
18498
|
-
i = this.leftover;
|
|
18499
|
-
this.buffer[i++] = 1;
|
|
18500
|
-
for (; i < 16; i++) this.buffer[i] = 0;
|
|
18501
|
-
this.fin = 1;
|
|
18502
|
-
this.blocks(this.buffer, 0, 16);
|
|
18503
|
-
}
|
|
18504
|
-
|
|
18505
|
-
c = this.h[1] >>> 13;
|
|
18506
|
-
this.h[1] &= 0x1fff;
|
|
18507
|
-
for (i = 2; i < 10; i++) {
|
|
18508
|
-
this.h[i] += c;
|
|
18509
|
-
c = this.h[i] >>> 13;
|
|
18510
|
-
this.h[i] &= 0x1fff;
|
|
18511
|
-
}
|
|
18512
|
-
this.h[0] += (c * 5);
|
|
18513
|
-
c = this.h[0] >>> 13;
|
|
18514
|
-
this.h[0] &= 0x1fff;
|
|
18515
|
-
this.h[1] += c;
|
|
18516
|
-
c = this.h[1] >>> 13;
|
|
18517
|
-
this.h[1] &= 0x1fff;
|
|
18518
|
-
this.h[2] += c;
|
|
18519
|
-
|
|
18520
|
-
g[0] = this.h[0] + 5;
|
|
18521
|
-
c = g[0] >>> 13;
|
|
18522
|
-
g[0] &= 0x1fff;
|
|
18523
|
-
for (i = 1; i < 10; i++) {
|
|
18524
|
-
g[i] = this.h[i] + c;
|
|
18525
|
-
c = g[i] >>> 13;
|
|
18526
|
-
g[i] &= 0x1fff;
|
|
18527
|
-
}
|
|
18528
|
-
g[9] -= (1 << 13);
|
|
18529
|
-
|
|
18530
|
-
mask = (c ^ 1) - 1;
|
|
18531
|
-
for (i = 0; i < 10; i++) g[i] &= mask;
|
|
18532
|
-
mask = ~mask;
|
|
18533
|
-
for (i = 0; i < 10; i++) this.h[i] = (this.h[i] & mask) | g[i];
|
|
18534
|
-
|
|
18535
|
-
this.h[0] = ((this.h[0] ) | (this.h[1] << 13) ) & 0xffff;
|
|
18536
|
-
this.h[1] = ((this.h[1] >>> 3) | (this.h[2] << 10) ) & 0xffff;
|
|
18537
|
-
this.h[2] = ((this.h[2] >>> 6) | (this.h[3] << 7) ) & 0xffff;
|
|
18538
|
-
this.h[3] = ((this.h[3] >>> 9) | (this.h[4] << 4) ) & 0xffff;
|
|
18539
|
-
this.h[4] = ((this.h[4] >>> 12) | (this.h[5] << 1) | (this.h[6] << 14)) & 0xffff;
|
|
18540
|
-
this.h[5] = ((this.h[6] >>> 2) | (this.h[7] << 11) ) & 0xffff;
|
|
18541
|
-
this.h[6] = ((this.h[7] >>> 5) | (this.h[8] << 8) ) & 0xffff;
|
|
18542
|
-
this.h[7] = ((this.h[8] >>> 8) | (this.h[9] << 5) ) & 0xffff;
|
|
18543
|
-
|
|
18544
|
-
f = this.h[0] + this.pad[0];
|
|
18545
|
-
this.h[0] = f & 0xffff;
|
|
18546
|
-
for (i = 1; i < 8; i++) {
|
|
18547
|
-
f = (((this.h[i] + this.pad[i]) | 0) + (f >>> 16)) | 0;
|
|
18548
|
-
this.h[i] = f & 0xffff;
|
|
18549
|
-
}
|
|
18550
|
-
|
|
18551
|
-
mac[macpos+ 0] = (this.h[0] >>> 0) & 0xff;
|
|
18552
|
-
mac[macpos+ 1] = (this.h[0] >>> 8) & 0xff;
|
|
18553
|
-
mac[macpos+ 2] = (this.h[1] >>> 0) & 0xff;
|
|
18554
|
-
mac[macpos+ 3] = (this.h[1] >>> 8) & 0xff;
|
|
18555
|
-
mac[macpos+ 4] = (this.h[2] >>> 0) & 0xff;
|
|
18556
|
-
mac[macpos+ 5] = (this.h[2] >>> 8) & 0xff;
|
|
18557
|
-
mac[macpos+ 6] = (this.h[3] >>> 0) & 0xff;
|
|
18558
|
-
mac[macpos+ 7] = (this.h[3] >>> 8) & 0xff;
|
|
18559
|
-
mac[macpos+ 8] = (this.h[4] >>> 0) & 0xff;
|
|
18560
|
-
mac[macpos+ 9] = (this.h[4] >>> 8) & 0xff;
|
|
18561
|
-
mac[macpos+10] = (this.h[5] >>> 0) & 0xff;
|
|
18562
|
-
mac[macpos+11] = (this.h[5] >>> 8) & 0xff;
|
|
18563
|
-
mac[macpos+12] = (this.h[6] >>> 0) & 0xff;
|
|
18564
|
-
mac[macpos+13] = (this.h[6] >>> 8) & 0xff;
|
|
18565
|
-
mac[macpos+14] = (this.h[7] >>> 0) & 0xff;
|
|
18566
|
-
mac[macpos+15] = (this.h[7] >>> 8) & 0xff;
|
|
18567
|
-
};
|
|
18568
|
-
|
|
18569
|
-
poly1305.prototype.update = function(m, mpos, bytes) {
|
|
18570
|
-
var i, want;
|
|
18571
|
-
|
|
18572
|
-
if (this.leftover) {
|
|
18573
|
-
want = (16 - this.leftover);
|
|
18574
|
-
if (want > bytes)
|
|
18575
|
-
want = bytes;
|
|
18576
|
-
for (i = 0; i < want; i++)
|
|
18577
|
-
this.buffer[this.leftover + i] = m[mpos+i];
|
|
18578
|
-
bytes -= want;
|
|
18579
|
-
mpos += want;
|
|
18580
|
-
this.leftover += want;
|
|
18581
|
-
if (this.leftover < 16)
|
|
18582
|
-
return;
|
|
18583
|
-
this.blocks(this.buffer, 0, 16);
|
|
18584
|
-
this.leftover = 0;
|
|
18585
|
-
}
|
|
18586
|
-
|
|
18587
|
-
if (bytes >= 16) {
|
|
18588
|
-
want = bytes - (bytes % 16);
|
|
18589
|
-
this.blocks(m, mpos, want);
|
|
18590
|
-
mpos += want;
|
|
18591
|
-
bytes -= want;
|
|
18592
|
-
}
|
|
18593
|
-
|
|
18594
|
-
if (bytes) {
|
|
18595
|
-
for (i = 0; i < bytes; i++)
|
|
18596
|
-
this.buffer[this.leftover + i] = m[mpos+i];
|
|
18597
|
-
this.leftover += bytes;
|
|
18598
|
-
}
|
|
18599
|
-
};
|
|
18600
|
-
|
|
18601
|
-
function crypto_onetimeauth(out, outpos, m, mpos, n, k) {
|
|
18602
|
-
var s = new poly1305(k);
|
|
18603
|
-
s.update(m, mpos, n);
|
|
18604
|
-
s.finish(out, outpos);
|
|
18605
|
-
return 0;
|
|
18606
|
-
}
|
|
18607
|
-
|
|
18608
|
-
function crypto_onetimeauth_verify(h, hpos, m, mpos, n, k) {
|
|
18609
|
-
var x = new Uint8Array(16);
|
|
18610
|
-
crypto_onetimeauth(x,0,m,mpos,n,k);
|
|
18611
|
-
return crypto_verify_16(h,hpos,x,0);
|
|
18612
|
-
}
|
|
18613
|
-
|
|
18614
|
-
function crypto_secretbox(c,m,d,n,k) {
|
|
18615
|
-
var i;
|
|
18616
|
-
if (d < 32) return -1;
|
|
18617
|
-
crypto_stream_xor(c,0,m,0,d,n,k);
|
|
18618
|
-
crypto_onetimeauth(c, 16, c, 32, d - 32, c);
|
|
18619
|
-
for (i = 0; i < 16; i++) c[i] = 0;
|
|
18620
|
-
return 0;
|
|
18621
|
-
}
|
|
18622
|
-
|
|
18623
|
-
function crypto_secretbox_open(m,c,d,n,k) {
|
|
18624
|
-
var i;
|
|
18625
|
-
var x = new Uint8Array(32);
|
|
18626
|
-
if (d < 32) return -1;
|
|
18627
|
-
crypto_stream(x,0,32,n,k);
|
|
18628
|
-
if (crypto_onetimeauth_verify(c, 16,c, 32,d - 32,x) !== 0) return -1;
|
|
18629
|
-
crypto_stream_xor(m,0,c,0,d,n,k);
|
|
18630
|
-
for (i = 0; i < 32; i++) m[i] = 0;
|
|
18631
|
-
return 0;
|
|
18632
|
-
}
|
|
18633
|
-
|
|
18634
|
-
function set25519(r, a) {
|
|
18635
|
-
var i;
|
|
18636
|
-
for (i = 0; i < 16; i++) r[i] = a[i]|0;
|
|
18637
|
-
}
|
|
18638
|
-
|
|
18639
|
-
function car25519(o) {
|
|
18640
|
-
var i, v, c = 1;
|
|
18641
|
-
for (i = 0; i < 16; i++) {
|
|
18642
|
-
v = o[i] + c + 65535;
|
|
18643
|
-
c = Math.floor(v / 65536);
|
|
18644
|
-
o[i] = v - c * 65536;
|
|
18645
|
-
}
|
|
18646
|
-
o[0] += c-1 + 37 * (c-1);
|
|
18647
|
-
}
|
|
18648
|
-
|
|
18649
|
-
function sel25519(p, q, b) {
|
|
18650
|
-
var t, c = ~(b-1);
|
|
18651
|
-
for (var i = 0; i < 16; i++) {
|
|
18652
|
-
t = c & (p[i] ^ q[i]);
|
|
18653
|
-
p[i] ^= t;
|
|
18654
|
-
q[i] ^= t;
|
|
18655
|
-
}
|
|
18656
|
-
}
|
|
18657
|
-
|
|
18658
|
-
function pack25519(o, n) {
|
|
18659
|
-
var i, j, b;
|
|
18660
|
-
var m = gf(), t = gf();
|
|
18661
|
-
for (i = 0; i < 16; i++) t[i] = n[i];
|
|
18662
|
-
car25519(t);
|
|
18663
|
-
car25519(t);
|
|
18664
|
-
car25519(t);
|
|
18665
|
-
for (j = 0; j < 2; j++) {
|
|
18666
|
-
m[0] = t[0] - 0xffed;
|
|
18667
|
-
for (i = 1; i < 15; i++) {
|
|
18668
|
-
m[i] = t[i] - 0xffff - ((m[i-1]>>16) & 1);
|
|
18669
|
-
m[i-1] &= 0xffff;
|
|
18670
|
-
}
|
|
18671
|
-
m[15] = t[15] - 0x7fff - ((m[14]>>16) & 1);
|
|
18672
|
-
b = (m[15]>>16) & 1;
|
|
18673
|
-
m[14] &= 0xffff;
|
|
18674
|
-
sel25519(t, m, 1-b);
|
|
18675
|
-
}
|
|
18676
|
-
for (i = 0; i < 16; i++) {
|
|
18677
|
-
o[2*i] = t[i] & 0xff;
|
|
18678
|
-
o[2*i+1] = t[i]>>8;
|
|
18679
|
-
}
|
|
18680
|
-
}
|
|
18681
|
-
|
|
18682
|
-
function neq25519(a, b) {
|
|
18683
|
-
var c = new Uint8Array(32), d = new Uint8Array(32);
|
|
18684
|
-
pack25519(c, a);
|
|
18685
|
-
pack25519(d, b);
|
|
18686
|
-
return crypto_verify_32(c, 0, d, 0);
|
|
18687
|
-
}
|
|
18688
|
-
|
|
18689
|
-
function par25519(a) {
|
|
18690
|
-
var d = new Uint8Array(32);
|
|
18691
|
-
pack25519(d, a);
|
|
18692
|
-
return d[0] & 1;
|
|
18693
|
-
}
|
|
18694
|
-
|
|
18695
|
-
function unpack25519(o, n) {
|
|
18696
|
-
var i;
|
|
18697
|
-
for (i = 0; i < 16; i++) o[i] = n[2*i] + (n[2*i+1] << 8);
|
|
18698
|
-
o[15] &= 0x7fff;
|
|
18699
|
-
}
|
|
18700
|
-
|
|
18701
|
-
function A(o, a, b) {
|
|
18702
|
-
for (var i = 0; i < 16; i++) o[i] = a[i] + b[i];
|
|
18703
|
-
}
|
|
18704
|
-
|
|
18705
|
-
function Z(o, a, b) {
|
|
18706
|
-
for (var i = 0; i < 16; i++) o[i] = a[i] - b[i];
|
|
18707
|
-
}
|
|
18708
|
-
|
|
18709
|
-
function M(o, a, b) {
|
|
18710
|
-
var v, c,
|
|
18711
|
-
t0 = 0, t1 = 0, t2 = 0, t3 = 0, t4 = 0, t5 = 0, t6 = 0, t7 = 0,
|
|
18712
|
-
t8 = 0, t9 = 0, t10 = 0, t11 = 0, t12 = 0, t13 = 0, t14 = 0, t15 = 0,
|
|
18713
|
-
t16 = 0, t17 = 0, t18 = 0, t19 = 0, t20 = 0, t21 = 0, t22 = 0, t23 = 0,
|
|
18714
|
-
t24 = 0, t25 = 0, t26 = 0, t27 = 0, t28 = 0, t29 = 0, t30 = 0,
|
|
18715
|
-
b0 = b[0],
|
|
18716
|
-
b1 = b[1],
|
|
18717
|
-
b2 = b[2],
|
|
18718
|
-
b3 = b[3],
|
|
18719
|
-
b4 = b[4],
|
|
18720
|
-
b5 = b[5],
|
|
18721
|
-
b6 = b[6],
|
|
18722
|
-
b7 = b[7],
|
|
18723
|
-
b8 = b[8],
|
|
18724
|
-
b9 = b[9],
|
|
18725
|
-
b10 = b[10],
|
|
18726
|
-
b11 = b[11],
|
|
18727
|
-
b12 = b[12],
|
|
18728
|
-
b13 = b[13],
|
|
18729
|
-
b14 = b[14],
|
|
18730
|
-
b15 = b[15];
|
|
18731
|
-
|
|
18732
|
-
v = a[0];
|
|
18733
|
-
t0 += v * b0;
|
|
18734
|
-
t1 += v * b1;
|
|
18735
|
-
t2 += v * b2;
|
|
18736
|
-
t3 += v * b3;
|
|
18737
|
-
t4 += v * b4;
|
|
18738
|
-
t5 += v * b5;
|
|
18739
|
-
t6 += v * b6;
|
|
18740
|
-
t7 += v * b7;
|
|
18741
|
-
t8 += v * b8;
|
|
18742
|
-
t9 += v * b9;
|
|
18743
|
-
t10 += v * b10;
|
|
18744
|
-
t11 += v * b11;
|
|
18745
|
-
t12 += v * b12;
|
|
18746
|
-
t13 += v * b13;
|
|
18747
|
-
t14 += v * b14;
|
|
18748
|
-
t15 += v * b15;
|
|
18749
|
-
v = a[1];
|
|
18750
|
-
t1 += v * b0;
|
|
18751
|
-
t2 += v * b1;
|
|
18752
|
-
t3 += v * b2;
|
|
18753
|
-
t4 += v * b3;
|
|
18754
|
-
t5 += v * b4;
|
|
18755
|
-
t6 += v * b5;
|
|
18756
|
-
t7 += v * b6;
|
|
18757
|
-
t8 += v * b7;
|
|
18758
|
-
t9 += v * b8;
|
|
18759
|
-
t10 += v * b9;
|
|
18760
|
-
t11 += v * b10;
|
|
18761
|
-
t12 += v * b11;
|
|
18762
|
-
t13 += v * b12;
|
|
18763
|
-
t14 += v * b13;
|
|
18764
|
-
t15 += v * b14;
|
|
18765
|
-
t16 += v * b15;
|
|
18766
|
-
v = a[2];
|
|
18767
|
-
t2 += v * b0;
|
|
18768
|
-
t3 += v * b1;
|
|
18769
|
-
t4 += v * b2;
|
|
18770
|
-
t5 += v * b3;
|
|
18771
|
-
t6 += v * b4;
|
|
18772
|
-
t7 += v * b5;
|
|
18773
|
-
t8 += v * b6;
|
|
18774
|
-
t9 += v * b7;
|
|
18775
|
-
t10 += v * b8;
|
|
18776
|
-
t11 += v * b9;
|
|
18777
|
-
t12 += v * b10;
|
|
18778
|
-
t13 += v * b11;
|
|
18779
|
-
t14 += v * b12;
|
|
18780
|
-
t15 += v * b13;
|
|
18781
|
-
t16 += v * b14;
|
|
18782
|
-
t17 += v * b15;
|
|
18783
|
-
v = a[3];
|
|
18784
|
-
t3 += v * b0;
|
|
18785
|
-
t4 += v * b1;
|
|
18786
|
-
t5 += v * b2;
|
|
18787
|
-
t6 += v * b3;
|
|
18788
|
-
t7 += v * b4;
|
|
18789
|
-
t8 += v * b5;
|
|
18790
|
-
t9 += v * b6;
|
|
18791
|
-
t10 += v * b7;
|
|
18792
|
-
t11 += v * b8;
|
|
18793
|
-
t12 += v * b9;
|
|
18794
|
-
t13 += v * b10;
|
|
18795
|
-
t14 += v * b11;
|
|
18796
|
-
t15 += v * b12;
|
|
18797
|
-
t16 += v * b13;
|
|
18798
|
-
t17 += v * b14;
|
|
18799
|
-
t18 += v * b15;
|
|
18800
|
-
v = a[4];
|
|
18801
|
-
t4 += v * b0;
|
|
18802
|
-
t5 += v * b1;
|
|
18803
|
-
t6 += v * b2;
|
|
18804
|
-
t7 += v * b3;
|
|
18805
|
-
t8 += v * b4;
|
|
18806
|
-
t9 += v * b5;
|
|
18807
|
-
t10 += v * b6;
|
|
18808
|
-
t11 += v * b7;
|
|
18809
|
-
t12 += v * b8;
|
|
18810
|
-
t13 += v * b9;
|
|
18811
|
-
t14 += v * b10;
|
|
18812
|
-
t15 += v * b11;
|
|
18813
|
-
t16 += v * b12;
|
|
18814
|
-
t17 += v * b13;
|
|
18815
|
-
t18 += v * b14;
|
|
18816
|
-
t19 += v * b15;
|
|
18817
|
-
v = a[5];
|
|
18818
|
-
t5 += v * b0;
|
|
18819
|
-
t6 += v * b1;
|
|
18820
|
-
t7 += v * b2;
|
|
18821
|
-
t8 += v * b3;
|
|
18822
|
-
t9 += v * b4;
|
|
18823
|
-
t10 += v * b5;
|
|
18824
|
-
t11 += v * b6;
|
|
18825
|
-
t12 += v * b7;
|
|
18826
|
-
t13 += v * b8;
|
|
18827
|
-
t14 += v * b9;
|
|
18828
|
-
t15 += v * b10;
|
|
18829
|
-
t16 += v * b11;
|
|
18830
|
-
t17 += v * b12;
|
|
18831
|
-
t18 += v * b13;
|
|
18832
|
-
t19 += v * b14;
|
|
18833
|
-
t20 += v * b15;
|
|
18834
|
-
v = a[6];
|
|
18835
|
-
t6 += v * b0;
|
|
18836
|
-
t7 += v * b1;
|
|
18837
|
-
t8 += v * b2;
|
|
18838
|
-
t9 += v * b3;
|
|
18839
|
-
t10 += v * b4;
|
|
18840
|
-
t11 += v * b5;
|
|
18841
|
-
t12 += v * b6;
|
|
18842
|
-
t13 += v * b7;
|
|
18843
|
-
t14 += v * b8;
|
|
18844
|
-
t15 += v * b9;
|
|
18845
|
-
t16 += v * b10;
|
|
18846
|
-
t17 += v * b11;
|
|
18847
|
-
t18 += v * b12;
|
|
18848
|
-
t19 += v * b13;
|
|
18849
|
-
t20 += v * b14;
|
|
18850
|
-
t21 += v * b15;
|
|
18851
|
-
v = a[7];
|
|
18852
|
-
t7 += v * b0;
|
|
18853
|
-
t8 += v * b1;
|
|
18854
|
-
t9 += v * b2;
|
|
18855
|
-
t10 += v * b3;
|
|
18856
|
-
t11 += v * b4;
|
|
18857
|
-
t12 += v * b5;
|
|
18858
|
-
t13 += v * b6;
|
|
18859
|
-
t14 += v * b7;
|
|
18860
|
-
t15 += v * b8;
|
|
18861
|
-
t16 += v * b9;
|
|
18862
|
-
t17 += v * b10;
|
|
18863
|
-
t18 += v * b11;
|
|
18864
|
-
t19 += v * b12;
|
|
18865
|
-
t20 += v * b13;
|
|
18866
|
-
t21 += v * b14;
|
|
18867
|
-
t22 += v * b15;
|
|
18868
|
-
v = a[8];
|
|
18869
|
-
t8 += v * b0;
|
|
18870
|
-
t9 += v * b1;
|
|
18871
|
-
t10 += v * b2;
|
|
18872
|
-
t11 += v * b3;
|
|
18873
|
-
t12 += v * b4;
|
|
18874
|
-
t13 += v * b5;
|
|
18875
|
-
t14 += v * b6;
|
|
18876
|
-
t15 += v * b7;
|
|
18877
|
-
t16 += v * b8;
|
|
18878
|
-
t17 += v * b9;
|
|
18879
|
-
t18 += v * b10;
|
|
18880
|
-
t19 += v * b11;
|
|
18881
|
-
t20 += v * b12;
|
|
18882
|
-
t21 += v * b13;
|
|
18883
|
-
t22 += v * b14;
|
|
18884
|
-
t23 += v * b15;
|
|
18885
|
-
v = a[9];
|
|
18886
|
-
t9 += v * b0;
|
|
18887
|
-
t10 += v * b1;
|
|
18888
|
-
t11 += v * b2;
|
|
18889
|
-
t12 += v * b3;
|
|
18890
|
-
t13 += v * b4;
|
|
18891
|
-
t14 += v * b5;
|
|
18892
|
-
t15 += v * b6;
|
|
18893
|
-
t16 += v * b7;
|
|
18894
|
-
t17 += v * b8;
|
|
18895
|
-
t18 += v * b9;
|
|
18896
|
-
t19 += v * b10;
|
|
18897
|
-
t20 += v * b11;
|
|
18898
|
-
t21 += v * b12;
|
|
18899
|
-
t22 += v * b13;
|
|
18900
|
-
t23 += v * b14;
|
|
18901
|
-
t24 += v * b15;
|
|
18902
|
-
v = a[10];
|
|
18903
|
-
t10 += v * b0;
|
|
18904
|
-
t11 += v * b1;
|
|
18905
|
-
t12 += v * b2;
|
|
18906
|
-
t13 += v * b3;
|
|
18907
|
-
t14 += v * b4;
|
|
18908
|
-
t15 += v * b5;
|
|
18909
|
-
t16 += v * b6;
|
|
18910
|
-
t17 += v * b7;
|
|
18911
|
-
t18 += v * b8;
|
|
18912
|
-
t19 += v * b9;
|
|
18913
|
-
t20 += v * b10;
|
|
18914
|
-
t21 += v * b11;
|
|
18915
|
-
t22 += v * b12;
|
|
18916
|
-
t23 += v * b13;
|
|
18917
|
-
t24 += v * b14;
|
|
18918
|
-
t25 += v * b15;
|
|
18919
|
-
v = a[11];
|
|
18920
|
-
t11 += v * b0;
|
|
18921
|
-
t12 += v * b1;
|
|
18922
|
-
t13 += v * b2;
|
|
18923
|
-
t14 += v * b3;
|
|
18924
|
-
t15 += v * b4;
|
|
18925
|
-
t16 += v * b5;
|
|
18926
|
-
t17 += v * b6;
|
|
18927
|
-
t18 += v * b7;
|
|
18928
|
-
t19 += v * b8;
|
|
18929
|
-
t20 += v * b9;
|
|
18930
|
-
t21 += v * b10;
|
|
18931
|
-
t22 += v * b11;
|
|
18932
|
-
t23 += v * b12;
|
|
18933
|
-
t24 += v * b13;
|
|
18934
|
-
t25 += v * b14;
|
|
18935
|
-
t26 += v * b15;
|
|
18936
|
-
v = a[12];
|
|
18937
|
-
t12 += v * b0;
|
|
18938
|
-
t13 += v * b1;
|
|
18939
|
-
t14 += v * b2;
|
|
18940
|
-
t15 += v * b3;
|
|
18941
|
-
t16 += v * b4;
|
|
18942
|
-
t17 += v * b5;
|
|
18943
|
-
t18 += v * b6;
|
|
18944
|
-
t19 += v * b7;
|
|
18945
|
-
t20 += v * b8;
|
|
18946
|
-
t21 += v * b9;
|
|
18947
|
-
t22 += v * b10;
|
|
18948
|
-
t23 += v * b11;
|
|
18949
|
-
t24 += v * b12;
|
|
18950
|
-
t25 += v * b13;
|
|
18951
|
-
t26 += v * b14;
|
|
18952
|
-
t27 += v * b15;
|
|
18953
|
-
v = a[13];
|
|
18954
|
-
t13 += v * b0;
|
|
18955
|
-
t14 += v * b1;
|
|
18956
|
-
t15 += v * b2;
|
|
18957
|
-
t16 += v * b3;
|
|
18958
|
-
t17 += v * b4;
|
|
18959
|
-
t18 += v * b5;
|
|
18960
|
-
t19 += v * b6;
|
|
18961
|
-
t20 += v * b7;
|
|
18962
|
-
t21 += v * b8;
|
|
18963
|
-
t22 += v * b9;
|
|
18964
|
-
t23 += v * b10;
|
|
18965
|
-
t24 += v * b11;
|
|
18966
|
-
t25 += v * b12;
|
|
18967
|
-
t26 += v * b13;
|
|
18968
|
-
t27 += v * b14;
|
|
18969
|
-
t28 += v * b15;
|
|
18970
|
-
v = a[14];
|
|
18971
|
-
t14 += v * b0;
|
|
18972
|
-
t15 += v * b1;
|
|
18973
|
-
t16 += v * b2;
|
|
18974
|
-
t17 += v * b3;
|
|
18975
|
-
t18 += v * b4;
|
|
18976
|
-
t19 += v * b5;
|
|
18977
|
-
t20 += v * b6;
|
|
18978
|
-
t21 += v * b7;
|
|
18979
|
-
t22 += v * b8;
|
|
18980
|
-
t23 += v * b9;
|
|
18981
|
-
t24 += v * b10;
|
|
18982
|
-
t25 += v * b11;
|
|
18983
|
-
t26 += v * b12;
|
|
18984
|
-
t27 += v * b13;
|
|
18985
|
-
t28 += v * b14;
|
|
18986
|
-
t29 += v * b15;
|
|
18987
|
-
v = a[15];
|
|
18988
|
-
t15 += v * b0;
|
|
18989
|
-
t16 += v * b1;
|
|
18990
|
-
t17 += v * b2;
|
|
18991
|
-
t18 += v * b3;
|
|
18992
|
-
t19 += v * b4;
|
|
18993
|
-
t20 += v * b5;
|
|
18994
|
-
t21 += v * b6;
|
|
18995
|
-
t22 += v * b7;
|
|
18996
|
-
t23 += v * b8;
|
|
18997
|
-
t24 += v * b9;
|
|
18998
|
-
t25 += v * b10;
|
|
18999
|
-
t26 += v * b11;
|
|
19000
|
-
t27 += v * b12;
|
|
19001
|
-
t28 += v * b13;
|
|
19002
|
-
t29 += v * b14;
|
|
19003
|
-
t30 += v * b15;
|
|
19004
|
-
|
|
19005
|
-
t0 += 38 * t16;
|
|
19006
|
-
t1 += 38 * t17;
|
|
19007
|
-
t2 += 38 * t18;
|
|
19008
|
-
t3 += 38 * t19;
|
|
19009
|
-
t4 += 38 * t20;
|
|
19010
|
-
t5 += 38 * t21;
|
|
19011
|
-
t6 += 38 * t22;
|
|
19012
|
-
t7 += 38 * t23;
|
|
19013
|
-
t8 += 38 * t24;
|
|
19014
|
-
t9 += 38 * t25;
|
|
19015
|
-
t10 += 38 * t26;
|
|
19016
|
-
t11 += 38 * t27;
|
|
19017
|
-
t12 += 38 * t28;
|
|
19018
|
-
t13 += 38 * t29;
|
|
19019
|
-
t14 += 38 * t30;
|
|
19020
|
-
// t15 left as is
|
|
19021
|
-
|
|
19022
|
-
// first car
|
|
19023
|
-
c = 1;
|
|
19024
|
-
v = t0 + c + 65535; c = Math.floor(v / 65536); t0 = v - c * 65536;
|
|
19025
|
-
v = t1 + c + 65535; c = Math.floor(v / 65536); t1 = v - c * 65536;
|
|
19026
|
-
v = t2 + c + 65535; c = Math.floor(v / 65536); t2 = v - c * 65536;
|
|
19027
|
-
v = t3 + c + 65535; c = Math.floor(v / 65536); t3 = v - c * 65536;
|
|
19028
|
-
v = t4 + c + 65535; c = Math.floor(v / 65536); t4 = v - c * 65536;
|
|
19029
|
-
v = t5 + c + 65535; c = Math.floor(v / 65536); t5 = v - c * 65536;
|
|
19030
|
-
v = t6 + c + 65535; c = Math.floor(v / 65536); t6 = v - c * 65536;
|
|
19031
|
-
v = t7 + c + 65535; c = Math.floor(v / 65536); t7 = v - c * 65536;
|
|
19032
|
-
v = t8 + c + 65535; c = Math.floor(v / 65536); t8 = v - c * 65536;
|
|
19033
|
-
v = t9 + c + 65535; c = Math.floor(v / 65536); t9 = v - c * 65536;
|
|
19034
|
-
v = t10 + c + 65535; c = Math.floor(v / 65536); t10 = v - c * 65536;
|
|
19035
|
-
v = t11 + c + 65535; c = Math.floor(v / 65536); t11 = v - c * 65536;
|
|
19036
|
-
v = t12 + c + 65535; c = Math.floor(v / 65536); t12 = v - c * 65536;
|
|
19037
|
-
v = t13 + c + 65535; c = Math.floor(v / 65536); t13 = v - c * 65536;
|
|
19038
|
-
v = t14 + c + 65535; c = Math.floor(v / 65536); t14 = v - c * 65536;
|
|
19039
|
-
v = t15 + c + 65535; c = Math.floor(v / 65536); t15 = v - c * 65536;
|
|
19040
|
-
t0 += c-1 + 37 * (c-1);
|
|
19041
|
-
|
|
19042
|
-
// second car
|
|
19043
|
-
c = 1;
|
|
19044
|
-
v = t0 + c + 65535; c = Math.floor(v / 65536); t0 = v - c * 65536;
|
|
19045
|
-
v = t1 + c + 65535; c = Math.floor(v / 65536); t1 = v - c * 65536;
|
|
19046
|
-
v = t2 + c + 65535; c = Math.floor(v / 65536); t2 = v - c * 65536;
|
|
19047
|
-
v = t3 + c + 65535; c = Math.floor(v / 65536); t3 = v - c * 65536;
|
|
19048
|
-
v = t4 + c + 65535; c = Math.floor(v / 65536); t4 = v - c * 65536;
|
|
19049
|
-
v = t5 + c + 65535; c = Math.floor(v / 65536); t5 = v - c * 65536;
|
|
19050
|
-
v = t6 + c + 65535; c = Math.floor(v / 65536); t6 = v - c * 65536;
|
|
19051
|
-
v = t7 + c + 65535; c = Math.floor(v / 65536); t7 = v - c * 65536;
|
|
19052
|
-
v = t8 + c + 65535; c = Math.floor(v / 65536); t8 = v - c * 65536;
|
|
19053
|
-
v = t9 + c + 65535; c = Math.floor(v / 65536); t9 = v - c * 65536;
|
|
19054
|
-
v = t10 + c + 65535; c = Math.floor(v / 65536); t10 = v - c * 65536;
|
|
19055
|
-
v = t11 + c + 65535; c = Math.floor(v / 65536); t11 = v - c * 65536;
|
|
19056
|
-
v = t12 + c + 65535; c = Math.floor(v / 65536); t12 = v - c * 65536;
|
|
19057
|
-
v = t13 + c + 65535; c = Math.floor(v / 65536); t13 = v - c * 65536;
|
|
19058
|
-
v = t14 + c + 65535; c = Math.floor(v / 65536); t14 = v - c * 65536;
|
|
19059
|
-
v = t15 + c + 65535; c = Math.floor(v / 65536); t15 = v - c * 65536;
|
|
19060
|
-
t0 += c-1 + 37 * (c-1);
|
|
19061
|
-
|
|
19062
|
-
o[ 0] = t0;
|
|
19063
|
-
o[ 1] = t1;
|
|
19064
|
-
o[ 2] = t2;
|
|
19065
|
-
o[ 3] = t3;
|
|
19066
|
-
o[ 4] = t4;
|
|
19067
|
-
o[ 5] = t5;
|
|
19068
|
-
o[ 6] = t6;
|
|
19069
|
-
o[ 7] = t7;
|
|
19070
|
-
o[ 8] = t8;
|
|
19071
|
-
o[ 9] = t9;
|
|
19072
|
-
o[10] = t10;
|
|
19073
|
-
o[11] = t11;
|
|
19074
|
-
o[12] = t12;
|
|
19075
|
-
o[13] = t13;
|
|
19076
|
-
o[14] = t14;
|
|
19077
|
-
o[15] = t15;
|
|
19078
|
-
}
|
|
19079
|
-
|
|
19080
|
-
function S(o, a) {
|
|
19081
|
-
M(o, a, a);
|
|
19082
|
-
}
|
|
19083
|
-
|
|
19084
|
-
function inv25519(o, i) {
|
|
19085
|
-
var c = gf();
|
|
19086
|
-
var a;
|
|
19087
|
-
for (a = 0; a < 16; a++) c[a] = i[a];
|
|
19088
|
-
for (a = 253; a >= 0; a--) {
|
|
19089
|
-
S(c, c);
|
|
19090
|
-
if(a !== 2 && a !== 4) M(c, c, i);
|
|
19091
|
-
}
|
|
19092
|
-
for (a = 0; a < 16; a++) o[a] = c[a];
|
|
19093
|
-
}
|
|
19094
|
-
|
|
19095
|
-
function pow2523(o, i) {
|
|
19096
|
-
var c = gf();
|
|
19097
|
-
var a;
|
|
19098
|
-
for (a = 0; a < 16; a++) c[a] = i[a];
|
|
19099
|
-
for (a = 250; a >= 0; a--) {
|
|
19100
|
-
S(c, c);
|
|
19101
|
-
if(a !== 1) M(c, c, i);
|
|
19102
|
-
}
|
|
19103
|
-
for (a = 0; a < 16; a++) o[a] = c[a];
|
|
19104
|
-
}
|
|
19105
|
-
|
|
19106
|
-
function crypto_scalarmult(q, n, p) {
|
|
19107
|
-
var z = new Uint8Array(32);
|
|
19108
|
-
var x = new Float64Array(80), r, i;
|
|
19109
|
-
var a = gf(), b = gf(), c = gf(),
|
|
19110
|
-
d = gf(), e = gf(), f = gf();
|
|
19111
|
-
for (i = 0; i < 31; i++) z[i] = n[i];
|
|
19112
|
-
z[31]=(n[31]&127)|64;
|
|
19113
|
-
z[0]&=248;
|
|
19114
|
-
unpack25519(x,p);
|
|
19115
|
-
for (i = 0; i < 16; i++) {
|
|
19116
|
-
b[i]=x[i];
|
|
19117
|
-
d[i]=a[i]=c[i]=0;
|
|
19118
|
-
}
|
|
19119
|
-
a[0]=d[0]=1;
|
|
19120
|
-
for (i=254; i>=0; --i) {
|
|
19121
|
-
r=(z[i>>>3]>>>(i&7))&1;
|
|
19122
|
-
sel25519(a,b,r);
|
|
19123
|
-
sel25519(c,d,r);
|
|
19124
|
-
A(e,a,c);
|
|
19125
|
-
Z(a,a,c);
|
|
19126
|
-
A(c,b,d);
|
|
19127
|
-
Z(b,b,d);
|
|
19128
|
-
S(d,e);
|
|
19129
|
-
S(f,a);
|
|
19130
|
-
M(a,c,a);
|
|
19131
|
-
M(c,b,e);
|
|
19132
|
-
A(e,a,c);
|
|
19133
|
-
Z(a,a,c);
|
|
19134
|
-
S(b,a);
|
|
19135
|
-
Z(c,d,f);
|
|
19136
|
-
M(a,c,_121665);
|
|
19137
|
-
A(a,a,d);
|
|
19138
|
-
M(c,c,a);
|
|
19139
|
-
M(a,d,f);
|
|
19140
|
-
M(d,b,x);
|
|
19141
|
-
S(b,e);
|
|
19142
|
-
sel25519(a,b,r);
|
|
19143
|
-
sel25519(c,d,r);
|
|
19144
|
-
}
|
|
19145
|
-
for (i = 0; i < 16; i++) {
|
|
19146
|
-
x[i+16]=a[i];
|
|
19147
|
-
x[i+32]=c[i];
|
|
19148
|
-
x[i+48]=b[i];
|
|
19149
|
-
x[i+64]=d[i];
|
|
19150
|
-
}
|
|
19151
|
-
var x32 = x.subarray(32);
|
|
19152
|
-
var x16 = x.subarray(16);
|
|
19153
|
-
inv25519(x32,x32);
|
|
19154
|
-
M(x16,x16,x32);
|
|
19155
|
-
pack25519(q,x16);
|
|
19156
|
-
return 0;
|
|
19157
|
-
}
|
|
19158
|
-
|
|
19159
|
-
function crypto_scalarmult_base(q, n) {
|
|
19160
|
-
return crypto_scalarmult(q, n, _9);
|
|
19161
|
-
}
|
|
19162
|
-
|
|
19163
|
-
function crypto_box_keypair(y, x) {
|
|
19164
|
-
randombytes(x, 32);
|
|
19165
|
-
return crypto_scalarmult_base(y, x);
|
|
19166
|
-
}
|
|
19167
|
-
|
|
19168
|
-
function crypto_box_beforenm(k, y, x) {
|
|
19169
|
-
var s = new Uint8Array(32);
|
|
19170
|
-
crypto_scalarmult(s, x, y);
|
|
19171
|
-
return crypto_core_hsalsa20(k, _0, s, sigma);
|
|
19172
|
-
}
|
|
19173
|
-
|
|
19174
|
-
var crypto_box_afternm = crypto_secretbox;
|
|
19175
|
-
var crypto_box_open_afternm = crypto_secretbox_open;
|
|
19176
|
-
|
|
19177
|
-
function crypto_box(c, m, d, n, y, x) {
|
|
19178
|
-
var k = new Uint8Array(32);
|
|
19179
|
-
crypto_box_beforenm(k, y, x);
|
|
19180
|
-
return crypto_box_afternm(c, m, d, n, k);
|
|
19181
|
-
}
|
|
19182
|
-
|
|
19183
|
-
function crypto_box_open(m, c, d, n, y, x) {
|
|
19184
|
-
var k = new Uint8Array(32);
|
|
19185
|
-
crypto_box_beforenm(k, y, x);
|
|
19186
|
-
return crypto_box_open_afternm(m, c, d, n, k);
|
|
19187
|
-
}
|
|
19188
|
-
|
|
19189
|
-
var K = [
|
|
19190
|
-
0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd,
|
|
19191
|
-
0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc,
|
|
19192
|
-
0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019,
|
|
19193
|
-
0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118,
|
|
19194
|
-
0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe,
|
|
19195
|
-
0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2,
|
|
19196
|
-
0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1,
|
|
19197
|
-
0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694,
|
|
19198
|
-
0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3,
|
|
19199
|
-
0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65,
|
|
19200
|
-
0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483,
|
|
19201
|
-
0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5,
|
|
19202
|
-
0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210,
|
|
19203
|
-
0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4,
|
|
19204
|
-
0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725,
|
|
19205
|
-
0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70,
|
|
19206
|
-
0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926,
|
|
19207
|
-
0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df,
|
|
19208
|
-
0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8,
|
|
19209
|
-
0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b,
|
|
19210
|
-
0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001,
|
|
19211
|
-
0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30,
|
|
19212
|
-
0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910,
|
|
19213
|
-
0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8,
|
|
19214
|
-
0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53,
|
|
19215
|
-
0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8,
|
|
19216
|
-
0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb,
|
|
19217
|
-
0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3,
|
|
19218
|
-
0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60,
|
|
19219
|
-
0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec,
|
|
19220
|
-
0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9,
|
|
19221
|
-
0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b,
|
|
19222
|
-
0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207,
|
|
19223
|
-
0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178,
|
|
19224
|
-
0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6,
|
|
19225
|
-
0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b,
|
|
19226
|
-
0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493,
|
|
19227
|
-
0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c,
|
|
19228
|
-
0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a,
|
|
19229
|
-
0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817
|
|
19230
|
-
];
|
|
19231
|
-
|
|
19232
|
-
function crypto_hashblocks_hl(hh, hl, m, n) {
|
|
19233
|
-
var wh = new Int32Array(16), wl = new Int32Array(16),
|
|
19234
|
-
bh0, bh1, bh2, bh3, bh4, bh5, bh6, bh7,
|
|
19235
|
-
bl0, bl1, bl2, bl3, bl4, bl5, bl6, bl7,
|
|
19236
|
-
th, tl, i, j, h, l, a, b, c, d;
|
|
19237
|
-
|
|
19238
|
-
var ah0 = hh[0],
|
|
19239
|
-
ah1 = hh[1],
|
|
19240
|
-
ah2 = hh[2],
|
|
19241
|
-
ah3 = hh[3],
|
|
19242
|
-
ah4 = hh[4],
|
|
19243
|
-
ah5 = hh[5],
|
|
19244
|
-
ah6 = hh[6],
|
|
19245
|
-
ah7 = hh[7],
|
|
19246
|
-
|
|
19247
|
-
al0 = hl[0],
|
|
19248
|
-
al1 = hl[1],
|
|
19249
|
-
al2 = hl[2],
|
|
19250
|
-
al3 = hl[3],
|
|
19251
|
-
al4 = hl[4],
|
|
19252
|
-
al5 = hl[5],
|
|
19253
|
-
al6 = hl[6],
|
|
19254
|
-
al7 = hl[7];
|
|
19255
|
-
|
|
19256
|
-
var pos = 0;
|
|
19257
|
-
while (n >= 128) {
|
|
19258
|
-
for (i = 0; i < 16; i++) {
|
|
19259
|
-
j = 8 * i + pos;
|
|
19260
|
-
wh[i] = (m[j+0] << 24) | (m[j+1] << 16) | (m[j+2] << 8) | m[j+3];
|
|
19261
|
-
wl[i] = (m[j+4] << 24) | (m[j+5] << 16) | (m[j+6] << 8) | m[j+7];
|
|
19262
|
-
}
|
|
19263
|
-
for (i = 0; i < 80; i++) {
|
|
19264
|
-
bh0 = ah0;
|
|
19265
|
-
bh1 = ah1;
|
|
19266
|
-
bh2 = ah2;
|
|
19267
|
-
bh3 = ah3;
|
|
19268
|
-
bh4 = ah4;
|
|
19269
|
-
bh5 = ah5;
|
|
19270
|
-
bh6 = ah6;
|
|
19271
|
-
bh7 = ah7;
|
|
19272
|
-
|
|
19273
|
-
bl0 = al0;
|
|
19274
|
-
bl1 = al1;
|
|
19275
|
-
bl2 = al2;
|
|
19276
|
-
bl3 = al3;
|
|
19277
|
-
bl4 = al4;
|
|
19278
|
-
bl5 = al5;
|
|
19279
|
-
bl6 = al6;
|
|
19280
|
-
bl7 = al7;
|
|
19281
|
-
|
|
19282
|
-
// add
|
|
19283
|
-
h = ah7;
|
|
19284
|
-
l = al7;
|
|
19285
|
-
|
|
19286
|
-
a = l & 0xffff; b = l >>> 16;
|
|
19287
|
-
c = h & 0xffff; d = h >>> 16;
|
|
19288
|
-
|
|
19289
|
-
// Sigma1
|
|
19290
|
-
h = ((ah4 >>> 14) | (al4 << (32-14))) ^ ((ah4 >>> 18) | (al4 << (32-18))) ^ ((al4 >>> (41-32)) | (ah4 << (32-(41-32))));
|
|
19291
|
-
l = ((al4 >>> 14) | (ah4 << (32-14))) ^ ((al4 >>> 18) | (ah4 << (32-18))) ^ ((ah4 >>> (41-32)) | (al4 << (32-(41-32))));
|
|
19292
|
-
|
|
19293
|
-
a += l & 0xffff; b += l >>> 16;
|
|
19294
|
-
c += h & 0xffff; d += h >>> 16;
|
|
19295
|
-
|
|
19296
|
-
// Ch
|
|
19297
|
-
h = (ah4 & ah5) ^ (~ah4 & ah6);
|
|
19298
|
-
l = (al4 & al5) ^ (~al4 & al6);
|
|
19299
|
-
|
|
19300
|
-
a += l & 0xffff; b += l >>> 16;
|
|
19301
|
-
c += h & 0xffff; d += h >>> 16;
|
|
19302
|
-
|
|
19303
|
-
// K
|
|
19304
|
-
h = K[i*2];
|
|
19305
|
-
l = K[i*2+1];
|
|
19306
|
-
|
|
19307
|
-
a += l & 0xffff; b += l >>> 16;
|
|
19308
|
-
c += h & 0xffff; d += h >>> 16;
|
|
19309
|
-
|
|
19310
|
-
// w
|
|
19311
|
-
h = wh[i%16];
|
|
19312
|
-
l = wl[i%16];
|
|
19313
|
-
|
|
19314
|
-
a += l & 0xffff; b += l >>> 16;
|
|
19315
|
-
c += h & 0xffff; d += h >>> 16;
|
|
19316
|
-
|
|
19317
|
-
b += a >>> 16;
|
|
19318
|
-
c += b >>> 16;
|
|
19319
|
-
d += c >>> 16;
|
|
19320
|
-
|
|
19321
|
-
th = c & 0xffff | d << 16;
|
|
19322
|
-
tl = a & 0xffff | b << 16;
|
|
19323
|
-
|
|
19324
|
-
// add
|
|
19325
|
-
h = th;
|
|
19326
|
-
l = tl;
|
|
19327
|
-
|
|
19328
|
-
a = l & 0xffff; b = l >>> 16;
|
|
19329
|
-
c = h & 0xffff; d = h >>> 16;
|
|
19330
|
-
|
|
19331
|
-
// Sigma0
|
|
19332
|
-
h = ((ah0 >>> 28) | (al0 << (32-28))) ^ ((al0 >>> (34-32)) | (ah0 << (32-(34-32)))) ^ ((al0 >>> (39-32)) | (ah0 << (32-(39-32))));
|
|
19333
|
-
l = ((al0 >>> 28) | (ah0 << (32-28))) ^ ((ah0 >>> (34-32)) | (al0 << (32-(34-32)))) ^ ((ah0 >>> (39-32)) | (al0 << (32-(39-32))));
|
|
19334
|
-
|
|
19335
|
-
a += l & 0xffff; b += l >>> 16;
|
|
19336
|
-
c += h & 0xffff; d += h >>> 16;
|
|
19337
|
-
|
|
19338
|
-
// Maj
|
|
19339
|
-
h = (ah0 & ah1) ^ (ah0 & ah2) ^ (ah1 & ah2);
|
|
19340
|
-
l = (al0 & al1) ^ (al0 & al2) ^ (al1 & al2);
|
|
19341
|
-
|
|
19342
|
-
a += l & 0xffff; b += l >>> 16;
|
|
19343
|
-
c += h & 0xffff; d += h >>> 16;
|
|
19344
|
-
|
|
19345
|
-
b += a >>> 16;
|
|
19346
|
-
c += b >>> 16;
|
|
19347
|
-
d += c >>> 16;
|
|
19348
|
-
|
|
19349
|
-
bh7 = (c & 0xffff) | (d << 16);
|
|
19350
|
-
bl7 = (a & 0xffff) | (b << 16);
|
|
19351
|
-
|
|
19352
|
-
// add
|
|
19353
|
-
h = bh3;
|
|
19354
|
-
l = bl3;
|
|
19355
|
-
|
|
19356
|
-
a = l & 0xffff; b = l >>> 16;
|
|
19357
|
-
c = h & 0xffff; d = h >>> 16;
|
|
19358
|
-
|
|
19359
|
-
h = th;
|
|
19360
|
-
l = tl;
|
|
19361
|
-
|
|
19362
|
-
a += l & 0xffff; b += l >>> 16;
|
|
19363
|
-
c += h & 0xffff; d += h >>> 16;
|
|
19364
|
-
|
|
19365
|
-
b += a >>> 16;
|
|
19366
|
-
c += b >>> 16;
|
|
19367
|
-
d += c >>> 16;
|
|
19368
|
-
|
|
19369
|
-
bh3 = (c & 0xffff) | (d << 16);
|
|
19370
|
-
bl3 = (a & 0xffff) | (b << 16);
|
|
19371
|
-
|
|
19372
|
-
ah1 = bh0;
|
|
19373
|
-
ah2 = bh1;
|
|
19374
|
-
ah3 = bh2;
|
|
19375
|
-
ah4 = bh3;
|
|
19376
|
-
ah5 = bh4;
|
|
19377
|
-
ah6 = bh5;
|
|
19378
|
-
ah7 = bh6;
|
|
19379
|
-
ah0 = bh7;
|
|
19380
|
-
|
|
19381
|
-
al1 = bl0;
|
|
19382
|
-
al2 = bl1;
|
|
19383
|
-
al3 = bl2;
|
|
19384
|
-
al4 = bl3;
|
|
19385
|
-
al5 = bl4;
|
|
19386
|
-
al6 = bl5;
|
|
19387
|
-
al7 = bl6;
|
|
19388
|
-
al0 = bl7;
|
|
19389
|
-
|
|
19390
|
-
if (i%16 === 15) {
|
|
19391
|
-
for (j = 0; j < 16; j++) {
|
|
19392
|
-
// add
|
|
19393
|
-
h = wh[j];
|
|
19394
|
-
l = wl[j];
|
|
19395
|
-
|
|
19396
|
-
a = l & 0xffff; b = l >>> 16;
|
|
19397
|
-
c = h & 0xffff; d = h >>> 16;
|
|
19398
|
-
|
|
19399
|
-
h = wh[(j+9)%16];
|
|
19400
|
-
l = wl[(j+9)%16];
|
|
19401
|
-
|
|
19402
|
-
a += l & 0xffff; b += l >>> 16;
|
|
19403
|
-
c += h & 0xffff; d += h >>> 16;
|
|
19404
|
-
|
|
19405
|
-
// sigma0
|
|
19406
|
-
th = wh[(j+1)%16];
|
|
19407
|
-
tl = wl[(j+1)%16];
|
|
19408
|
-
h = ((th >>> 1) | (tl << (32-1))) ^ ((th >>> 8) | (tl << (32-8))) ^ (th >>> 7);
|
|
19409
|
-
l = ((tl >>> 1) | (th << (32-1))) ^ ((tl >>> 8) | (th << (32-8))) ^ ((tl >>> 7) | (th << (32-7)));
|
|
19410
|
-
|
|
19411
|
-
a += l & 0xffff; b += l >>> 16;
|
|
19412
|
-
c += h & 0xffff; d += h >>> 16;
|
|
19413
|
-
|
|
19414
|
-
// sigma1
|
|
19415
|
-
th = wh[(j+14)%16];
|
|
19416
|
-
tl = wl[(j+14)%16];
|
|
19417
|
-
h = ((th >>> 19) | (tl << (32-19))) ^ ((tl >>> (61-32)) | (th << (32-(61-32)))) ^ (th >>> 6);
|
|
19418
|
-
l = ((tl >>> 19) | (th << (32-19))) ^ ((th >>> (61-32)) | (tl << (32-(61-32)))) ^ ((tl >>> 6) | (th << (32-6)));
|
|
19419
|
-
|
|
19420
|
-
a += l & 0xffff; b += l >>> 16;
|
|
19421
|
-
c += h & 0xffff; d += h >>> 16;
|
|
19422
|
-
|
|
19423
|
-
b += a >>> 16;
|
|
19424
|
-
c += b >>> 16;
|
|
19425
|
-
d += c >>> 16;
|
|
19426
|
-
|
|
19427
|
-
wh[j] = (c & 0xffff) | (d << 16);
|
|
19428
|
-
wl[j] = (a & 0xffff) | (b << 16);
|
|
19429
|
-
}
|
|
19430
|
-
}
|
|
19431
|
-
}
|
|
19432
|
-
|
|
19433
|
-
// add
|
|
19434
|
-
h = ah0;
|
|
19435
|
-
l = al0;
|
|
19436
|
-
|
|
19437
|
-
a = l & 0xffff; b = l >>> 16;
|
|
19438
|
-
c = h & 0xffff; d = h >>> 16;
|
|
19439
|
-
|
|
19440
|
-
h = hh[0];
|
|
19441
|
-
l = hl[0];
|
|
19442
|
-
|
|
19443
|
-
a += l & 0xffff; b += l >>> 16;
|
|
19444
|
-
c += h & 0xffff; d += h >>> 16;
|
|
19445
|
-
|
|
19446
|
-
b += a >>> 16;
|
|
19447
|
-
c += b >>> 16;
|
|
19448
|
-
d += c >>> 16;
|
|
19449
|
-
|
|
19450
|
-
hh[0] = ah0 = (c & 0xffff) | (d << 16);
|
|
19451
|
-
hl[0] = al0 = (a & 0xffff) | (b << 16);
|
|
19452
|
-
|
|
19453
|
-
h = ah1;
|
|
19454
|
-
l = al1;
|
|
19455
|
-
|
|
19456
|
-
a = l & 0xffff; b = l >>> 16;
|
|
19457
|
-
c = h & 0xffff; d = h >>> 16;
|
|
19458
|
-
|
|
19459
|
-
h = hh[1];
|
|
19460
|
-
l = hl[1];
|
|
19461
|
-
|
|
19462
|
-
a += l & 0xffff; b += l >>> 16;
|
|
19463
|
-
c += h & 0xffff; d += h >>> 16;
|
|
19464
|
-
|
|
19465
|
-
b += a >>> 16;
|
|
19466
|
-
c += b >>> 16;
|
|
19467
|
-
d += c >>> 16;
|
|
19468
|
-
|
|
19469
|
-
hh[1] = ah1 = (c & 0xffff) | (d << 16);
|
|
19470
|
-
hl[1] = al1 = (a & 0xffff) | (b << 16);
|
|
19471
|
-
|
|
19472
|
-
h = ah2;
|
|
19473
|
-
l = al2;
|
|
19474
|
-
|
|
19475
|
-
a = l & 0xffff; b = l >>> 16;
|
|
19476
|
-
c = h & 0xffff; d = h >>> 16;
|
|
19477
|
-
|
|
19478
|
-
h = hh[2];
|
|
19479
|
-
l = hl[2];
|
|
19480
|
-
|
|
19481
|
-
a += l & 0xffff; b += l >>> 16;
|
|
19482
|
-
c += h & 0xffff; d += h >>> 16;
|
|
19483
|
-
|
|
19484
|
-
b += a >>> 16;
|
|
19485
|
-
c += b >>> 16;
|
|
19486
|
-
d += c >>> 16;
|
|
19487
|
-
|
|
19488
|
-
hh[2] = ah2 = (c & 0xffff) | (d << 16);
|
|
19489
|
-
hl[2] = al2 = (a & 0xffff) | (b << 16);
|
|
19490
|
-
|
|
19491
|
-
h = ah3;
|
|
19492
|
-
l = al3;
|
|
19493
|
-
|
|
19494
|
-
a = l & 0xffff; b = l >>> 16;
|
|
19495
|
-
c = h & 0xffff; d = h >>> 16;
|
|
19496
|
-
|
|
19497
|
-
h = hh[3];
|
|
19498
|
-
l = hl[3];
|
|
19499
|
-
|
|
19500
|
-
a += l & 0xffff; b += l >>> 16;
|
|
19501
|
-
c += h & 0xffff; d += h >>> 16;
|
|
19502
|
-
|
|
19503
|
-
b += a >>> 16;
|
|
19504
|
-
c += b >>> 16;
|
|
19505
|
-
d += c >>> 16;
|
|
19506
|
-
|
|
19507
|
-
hh[3] = ah3 = (c & 0xffff) | (d << 16);
|
|
19508
|
-
hl[3] = al3 = (a & 0xffff) | (b << 16);
|
|
19509
|
-
|
|
19510
|
-
h = ah4;
|
|
19511
|
-
l = al4;
|
|
19512
|
-
|
|
19513
|
-
a = l & 0xffff; b = l >>> 16;
|
|
19514
|
-
c = h & 0xffff; d = h >>> 16;
|
|
19515
|
-
|
|
19516
|
-
h = hh[4];
|
|
19517
|
-
l = hl[4];
|
|
19518
|
-
|
|
19519
|
-
a += l & 0xffff; b += l >>> 16;
|
|
19520
|
-
c += h & 0xffff; d += h >>> 16;
|
|
19521
|
-
|
|
19522
|
-
b += a >>> 16;
|
|
19523
|
-
c += b >>> 16;
|
|
19524
|
-
d += c >>> 16;
|
|
19525
|
-
|
|
19526
|
-
hh[4] = ah4 = (c & 0xffff) | (d << 16);
|
|
19527
|
-
hl[4] = al4 = (a & 0xffff) | (b << 16);
|
|
19528
|
-
|
|
19529
|
-
h = ah5;
|
|
19530
|
-
l = al5;
|
|
19531
|
-
|
|
19532
|
-
a = l & 0xffff; b = l >>> 16;
|
|
19533
|
-
c = h & 0xffff; d = h >>> 16;
|
|
19534
|
-
|
|
19535
|
-
h = hh[5];
|
|
19536
|
-
l = hl[5];
|
|
19537
|
-
|
|
19538
|
-
a += l & 0xffff; b += l >>> 16;
|
|
19539
|
-
c += h & 0xffff; d += h >>> 16;
|
|
19540
|
-
|
|
19541
|
-
b += a >>> 16;
|
|
19542
|
-
c += b >>> 16;
|
|
19543
|
-
d += c >>> 16;
|
|
19544
|
-
|
|
19545
|
-
hh[5] = ah5 = (c & 0xffff) | (d << 16);
|
|
19546
|
-
hl[5] = al5 = (a & 0xffff) | (b << 16);
|
|
19547
|
-
|
|
19548
|
-
h = ah6;
|
|
19549
|
-
l = al6;
|
|
19550
|
-
|
|
19551
|
-
a = l & 0xffff; b = l >>> 16;
|
|
19552
|
-
c = h & 0xffff; d = h >>> 16;
|
|
19553
|
-
|
|
19554
|
-
h = hh[6];
|
|
19555
|
-
l = hl[6];
|
|
19556
|
-
|
|
19557
|
-
a += l & 0xffff; b += l >>> 16;
|
|
19558
|
-
c += h & 0xffff; d += h >>> 16;
|
|
19559
|
-
|
|
19560
|
-
b += a >>> 16;
|
|
19561
|
-
c += b >>> 16;
|
|
19562
|
-
d += c >>> 16;
|
|
19563
|
-
|
|
19564
|
-
hh[6] = ah6 = (c & 0xffff) | (d << 16);
|
|
19565
|
-
hl[6] = al6 = (a & 0xffff) | (b << 16);
|
|
19566
|
-
|
|
19567
|
-
h = ah7;
|
|
19568
|
-
l = al7;
|
|
19569
|
-
|
|
19570
|
-
a = l & 0xffff; b = l >>> 16;
|
|
19571
|
-
c = h & 0xffff; d = h >>> 16;
|
|
19572
|
-
|
|
19573
|
-
h = hh[7];
|
|
19574
|
-
l = hl[7];
|
|
19575
|
-
|
|
19576
|
-
a += l & 0xffff; b += l >>> 16;
|
|
19577
|
-
c += h & 0xffff; d += h >>> 16;
|
|
19578
|
-
|
|
19579
|
-
b += a >>> 16;
|
|
19580
|
-
c += b >>> 16;
|
|
19581
|
-
d += c >>> 16;
|
|
19582
|
-
|
|
19583
|
-
hh[7] = ah7 = (c & 0xffff) | (d << 16);
|
|
19584
|
-
hl[7] = al7 = (a & 0xffff) | (b << 16);
|
|
19585
|
-
|
|
19586
|
-
pos += 128;
|
|
19587
|
-
n -= 128;
|
|
19588
|
-
}
|
|
19589
|
-
|
|
19590
|
-
return n;
|
|
19591
|
-
}
|
|
19592
|
-
|
|
19593
|
-
function crypto_hash(out, m, n) {
|
|
19594
|
-
var hh = new Int32Array(8),
|
|
19595
|
-
hl = new Int32Array(8),
|
|
19596
|
-
x = new Uint8Array(256),
|
|
19597
|
-
i, b = n;
|
|
19598
|
-
|
|
19599
|
-
hh[0] = 0x6a09e667;
|
|
19600
|
-
hh[1] = 0xbb67ae85;
|
|
19601
|
-
hh[2] = 0x3c6ef372;
|
|
19602
|
-
hh[3] = 0xa54ff53a;
|
|
19603
|
-
hh[4] = 0x510e527f;
|
|
19604
|
-
hh[5] = 0x9b05688c;
|
|
19605
|
-
hh[6] = 0x1f83d9ab;
|
|
19606
|
-
hh[7] = 0x5be0cd19;
|
|
19607
|
-
|
|
19608
|
-
hl[0] = 0xf3bcc908;
|
|
19609
|
-
hl[1] = 0x84caa73b;
|
|
19610
|
-
hl[2] = 0xfe94f82b;
|
|
19611
|
-
hl[3] = 0x5f1d36f1;
|
|
19612
|
-
hl[4] = 0xade682d1;
|
|
19613
|
-
hl[5] = 0x2b3e6c1f;
|
|
19614
|
-
hl[6] = 0xfb41bd6b;
|
|
19615
|
-
hl[7] = 0x137e2179;
|
|
19616
|
-
|
|
19617
|
-
crypto_hashblocks_hl(hh, hl, m, n);
|
|
19618
|
-
n %= 128;
|
|
19619
|
-
|
|
19620
|
-
for (i = 0; i < n; i++) x[i] = m[b-n+i];
|
|
19621
|
-
x[n] = 128;
|
|
19622
|
-
|
|
19623
|
-
n = 256-128*(n<112?1:0);
|
|
19624
|
-
x[n-9] = 0;
|
|
19625
|
-
ts64(x, n-8, (b / 0x20000000) | 0, b << 3);
|
|
19626
|
-
crypto_hashblocks_hl(hh, hl, x, n);
|
|
19627
|
-
|
|
19628
|
-
for (i = 0; i < 8; i++) ts64(out, 8*i, hh[i], hl[i]);
|
|
19629
|
-
|
|
19630
|
-
return 0;
|
|
19631
|
-
}
|
|
19632
|
-
|
|
19633
|
-
function add(p, q) {
|
|
19634
|
-
var a = gf(), b = gf(), c = gf(),
|
|
19635
|
-
d = gf(), e = gf(), f = gf(),
|
|
19636
|
-
g = gf(), h = gf(), t = gf();
|
|
19637
|
-
|
|
19638
|
-
Z(a, p[1], p[0]);
|
|
19639
|
-
Z(t, q[1], q[0]);
|
|
19640
|
-
M(a, a, t);
|
|
19641
|
-
A(b, p[0], p[1]);
|
|
19642
|
-
A(t, q[0], q[1]);
|
|
19643
|
-
M(b, b, t);
|
|
19644
|
-
M(c, p[3], q[3]);
|
|
19645
|
-
M(c, c, D2);
|
|
19646
|
-
M(d, p[2], q[2]);
|
|
19647
|
-
A(d, d, d);
|
|
19648
|
-
Z(e, b, a);
|
|
19649
|
-
Z(f, d, c);
|
|
19650
|
-
A(g, d, c);
|
|
19651
|
-
A(h, b, a);
|
|
19652
|
-
|
|
19653
|
-
M(p[0], e, f);
|
|
19654
|
-
M(p[1], h, g);
|
|
19655
|
-
M(p[2], g, f);
|
|
19656
|
-
M(p[3], e, h);
|
|
19657
|
-
}
|
|
19658
|
-
|
|
19659
|
-
function cswap(p, q, b) {
|
|
19660
|
-
var i;
|
|
19661
|
-
for (i = 0; i < 4; i++) {
|
|
19662
|
-
sel25519(p[i], q[i], b);
|
|
19663
|
-
}
|
|
19664
|
-
}
|
|
19665
|
-
|
|
19666
|
-
function pack(r, p) {
|
|
19667
|
-
var tx = gf(), ty = gf(), zi = gf();
|
|
19668
|
-
inv25519(zi, p[2]);
|
|
19669
|
-
M(tx, p[0], zi);
|
|
19670
|
-
M(ty, p[1], zi);
|
|
19671
|
-
pack25519(r, ty);
|
|
19672
|
-
r[31] ^= par25519(tx) << 7;
|
|
19673
|
-
}
|
|
19674
|
-
|
|
19675
|
-
function scalarmult(p, q, s) {
|
|
19676
|
-
var b, i;
|
|
19677
|
-
set25519(p[0], gf0);
|
|
19678
|
-
set25519(p[1], gf1);
|
|
19679
|
-
set25519(p[2], gf1);
|
|
19680
|
-
set25519(p[3], gf0);
|
|
19681
|
-
for (i = 255; i >= 0; --i) {
|
|
19682
|
-
b = (s[(i/8)|0] >> (i&7)) & 1;
|
|
19683
|
-
cswap(p, q, b);
|
|
19684
|
-
add(q, p);
|
|
19685
|
-
add(p, p);
|
|
19686
|
-
cswap(p, q, b);
|
|
19687
|
-
}
|
|
19688
|
-
}
|
|
19689
|
-
|
|
19690
|
-
function scalarbase(p, s) {
|
|
19691
|
-
var q = [gf(), gf(), gf(), gf()];
|
|
19692
|
-
set25519(q[0], X);
|
|
19693
|
-
set25519(q[1], Y);
|
|
19694
|
-
set25519(q[2], gf1);
|
|
19695
|
-
M(q[3], X, Y);
|
|
19696
|
-
scalarmult(p, q, s);
|
|
19697
|
-
}
|
|
19698
|
-
|
|
19699
|
-
function crypto_sign_keypair(pk, sk, seeded) {
|
|
19700
|
-
var d = new Uint8Array(64);
|
|
19701
|
-
var p = [gf(), gf(), gf(), gf()];
|
|
19702
|
-
var i;
|
|
19703
|
-
|
|
19704
|
-
if (!seeded) randombytes(sk, 32);
|
|
19705
|
-
crypto_hash(d, sk, 32);
|
|
19706
|
-
d[0] &= 248;
|
|
19707
|
-
d[31] &= 127;
|
|
19708
|
-
d[31] |= 64;
|
|
19709
|
-
|
|
19710
|
-
scalarbase(p, d);
|
|
19711
|
-
pack(pk, p);
|
|
19712
|
-
|
|
19713
|
-
for (i = 0; i < 32; i++) sk[i+32] = pk[i];
|
|
19714
|
-
return 0;
|
|
19715
|
-
}
|
|
19716
|
-
|
|
19717
|
-
var L = new Float64Array([0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58, 0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x10]);
|
|
19718
|
-
|
|
19719
|
-
function modL(r, x) {
|
|
19720
|
-
var carry, i, j, k;
|
|
19721
|
-
for (i = 63; i >= 32; --i) {
|
|
19722
|
-
carry = 0;
|
|
19723
|
-
for (j = i - 32, k = i - 12; j < k; ++j) {
|
|
19724
|
-
x[j] += carry - 16 * x[i] * L[j - (i - 32)];
|
|
19725
|
-
carry = Math.floor((x[j] + 128) / 256);
|
|
19726
|
-
x[j] -= carry * 256;
|
|
19727
|
-
}
|
|
19728
|
-
x[j] += carry;
|
|
19729
|
-
x[i] = 0;
|
|
19730
|
-
}
|
|
19731
|
-
carry = 0;
|
|
19732
|
-
for (j = 0; j < 32; j++) {
|
|
19733
|
-
x[j] += carry - (x[31] >> 4) * L[j];
|
|
19734
|
-
carry = x[j] >> 8;
|
|
19735
|
-
x[j] &= 255;
|
|
19736
|
-
}
|
|
19737
|
-
for (j = 0; j < 32; j++) x[j] -= carry * L[j];
|
|
19738
|
-
for (i = 0; i < 32; i++) {
|
|
19739
|
-
x[i+1] += x[i] >> 8;
|
|
19740
|
-
r[i] = x[i] & 255;
|
|
19741
|
-
}
|
|
19742
|
-
}
|
|
19743
|
-
|
|
19744
|
-
function reduce(r) {
|
|
19745
|
-
var x = new Float64Array(64), i;
|
|
19746
|
-
for (i = 0; i < 64; i++) x[i] = r[i];
|
|
19747
|
-
for (i = 0; i < 64; i++) r[i] = 0;
|
|
19748
|
-
modL(r, x);
|
|
19749
|
-
}
|
|
19750
|
-
|
|
19751
|
-
// Note: difference from C - smlen returned, not passed as argument.
|
|
19752
|
-
function crypto_sign(sm, m, n, sk) {
|
|
19753
|
-
var d = new Uint8Array(64), h = new Uint8Array(64), r = new Uint8Array(64);
|
|
19754
|
-
var i, j, x = new Float64Array(64);
|
|
19755
|
-
var p = [gf(), gf(), gf(), gf()];
|
|
19756
|
-
|
|
19757
|
-
crypto_hash(d, sk, 32);
|
|
19758
|
-
d[0] &= 248;
|
|
19759
|
-
d[31] &= 127;
|
|
19760
|
-
d[31] |= 64;
|
|
19761
|
-
|
|
19762
|
-
var smlen = n + 64;
|
|
19763
|
-
for (i = 0; i < n; i++) sm[64 + i] = m[i];
|
|
19764
|
-
for (i = 0; i < 32; i++) sm[32 + i] = d[32 + i];
|
|
19765
|
-
|
|
19766
|
-
crypto_hash(r, sm.subarray(32), n+32);
|
|
19767
|
-
reduce(r);
|
|
19768
|
-
scalarbase(p, r);
|
|
19769
|
-
pack(sm, p);
|
|
19770
|
-
|
|
19771
|
-
for (i = 32; i < 64; i++) sm[i] = sk[i];
|
|
19772
|
-
crypto_hash(h, sm, n + 64);
|
|
19773
|
-
reduce(h);
|
|
19774
|
-
|
|
19775
|
-
for (i = 0; i < 64; i++) x[i] = 0;
|
|
19776
|
-
for (i = 0; i < 32; i++) x[i] = r[i];
|
|
19777
|
-
for (i = 0; i < 32; i++) {
|
|
19778
|
-
for (j = 0; j < 32; j++) {
|
|
19779
|
-
x[i+j] += h[i] * d[j];
|
|
19780
|
-
}
|
|
19781
|
-
}
|
|
19782
|
-
|
|
19783
|
-
modL(sm.subarray(32), x);
|
|
19784
|
-
return smlen;
|
|
19785
|
-
}
|
|
19786
|
-
|
|
19787
|
-
function unpackneg(r, p) {
|
|
19788
|
-
var t = gf(), chk = gf(), num = gf(),
|
|
19789
|
-
den = gf(), den2 = gf(), den4 = gf(),
|
|
19790
|
-
den6 = gf();
|
|
19791
|
-
|
|
19792
|
-
set25519(r[2], gf1);
|
|
19793
|
-
unpack25519(r[1], p);
|
|
19794
|
-
S(num, r[1]);
|
|
19795
|
-
M(den, num, D);
|
|
19796
|
-
Z(num, num, r[2]);
|
|
19797
|
-
A(den, r[2], den);
|
|
19798
|
-
|
|
19799
|
-
S(den2, den);
|
|
19800
|
-
S(den4, den2);
|
|
19801
|
-
M(den6, den4, den2);
|
|
19802
|
-
M(t, den6, num);
|
|
19803
|
-
M(t, t, den);
|
|
19804
|
-
|
|
19805
|
-
pow2523(t, t);
|
|
19806
|
-
M(t, t, num);
|
|
19807
|
-
M(t, t, den);
|
|
19808
|
-
M(t, t, den);
|
|
19809
|
-
M(r[0], t, den);
|
|
19810
|
-
|
|
19811
|
-
S(chk, r[0]);
|
|
19812
|
-
M(chk, chk, den);
|
|
19813
|
-
if (neq25519(chk, num)) M(r[0], r[0], I);
|
|
19814
|
-
|
|
19815
|
-
S(chk, r[0]);
|
|
19816
|
-
M(chk, chk, den);
|
|
19817
|
-
if (neq25519(chk, num)) return -1;
|
|
19818
|
-
|
|
19819
|
-
if (par25519(r[0]) === (p[31]>>7)) Z(r[0], gf0, r[0]);
|
|
19820
|
-
|
|
19821
|
-
M(r[3], r[0], r[1]);
|
|
19822
|
-
return 0;
|
|
19823
|
-
}
|
|
19824
|
-
|
|
19825
|
-
function crypto_sign_open(m, sm, n, pk) {
|
|
19826
|
-
var i;
|
|
19827
|
-
var t = new Uint8Array(32), h = new Uint8Array(64);
|
|
19828
|
-
var p = [gf(), gf(), gf(), gf()],
|
|
19829
|
-
q = [gf(), gf(), gf(), gf()];
|
|
19830
|
-
|
|
19831
|
-
if (n < 64) return -1;
|
|
19832
|
-
|
|
19833
|
-
if (unpackneg(q, pk)) return -1;
|
|
19834
|
-
|
|
19835
|
-
for (i = 0; i < n; i++) m[i] = sm[i];
|
|
19836
|
-
for (i = 0; i < 32; i++) m[i+32] = pk[i];
|
|
19837
|
-
crypto_hash(h, m, n);
|
|
19838
|
-
reduce(h);
|
|
19839
|
-
scalarmult(p, q, h);
|
|
19840
|
-
|
|
19841
|
-
scalarbase(q, sm.subarray(32));
|
|
19842
|
-
add(p, q);
|
|
19843
|
-
pack(t, p);
|
|
19844
|
-
|
|
19845
|
-
n -= 64;
|
|
19846
|
-
if (crypto_verify_32(sm, 0, t, 0)) {
|
|
19847
|
-
for (i = 0; i < n; i++) m[i] = 0;
|
|
19848
|
-
return -1;
|
|
19849
|
-
}
|
|
19850
|
-
|
|
19851
|
-
for (i = 0; i < n; i++) m[i] = sm[i + 64];
|
|
19852
|
-
return n;
|
|
19853
|
-
}
|
|
19854
|
-
|
|
19855
|
-
var crypto_secretbox_KEYBYTES = 32,
|
|
19856
|
-
crypto_secretbox_NONCEBYTES = 24,
|
|
19857
|
-
crypto_secretbox_ZEROBYTES = 32,
|
|
19858
|
-
crypto_secretbox_BOXZEROBYTES = 16,
|
|
19859
|
-
crypto_scalarmult_BYTES = 32,
|
|
19860
|
-
crypto_scalarmult_SCALARBYTES = 32,
|
|
19861
|
-
crypto_box_PUBLICKEYBYTES = 32,
|
|
19862
|
-
crypto_box_SECRETKEYBYTES = 32,
|
|
19863
|
-
crypto_box_BEFORENMBYTES = 32,
|
|
19864
|
-
crypto_box_NONCEBYTES = crypto_secretbox_NONCEBYTES,
|
|
19865
|
-
crypto_box_ZEROBYTES = crypto_secretbox_ZEROBYTES,
|
|
19866
|
-
crypto_box_BOXZEROBYTES = crypto_secretbox_BOXZEROBYTES,
|
|
19867
|
-
crypto_sign_BYTES = 64,
|
|
19868
|
-
crypto_sign_PUBLICKEYBYTES = 32,
|
|
19869
|
-
crypto_sign_SECRETKEYBYTES = 64,
|
|
19870
|
-
crypto_sign_SEEDBYTES = 32,
|
|
19871
|
-
crypto_hash_BYTES = 64;
|
|
19872
|
-
|
|
19873
|
-
nacl.lowlevel = {
|
|
19874
|
-
crypto_core_hsalsa20: crypto_core_hsalsa20,
|
|
19875
|
-
crypto_stream_xor: crypto_stream_xor,
|
|
19876
|
-
crypto_stream: crypto_stream,
|
|
19877
|
-
crypto_stream_salsa20_xor: crypto_stream_salsa20_xor,
|
|
19878
|
-
crypto_stream_salsa20: crypto_stream_salsa20,
|
|
19879
|
-
crypto_onetimeauth: crypto_onetimeauth,
|
|
19880
|
-
crypto_onetimeauth_verify: crypto_onetimeauth_verify,
|
|
19881
|
-
crypto_verify_16: crypto_verify_16,
|
|
19882
|
-
crypto_verify_32: crypto_verify_32,
|
|
19883
|
-
crypto_secretbox: crypto_secretbox,
|
|
19884
|
-
crypto_secretbox_open: crypto_secretbox_open,
|
|
19885
|
-
crypto_scalarmult: crypto_scalarmult,
|
|
19886
|
-
crypto_scalarmult_base: crypto_scalarmult_base,
|
|
19887
|
-
crypto_box_beforenm: crypto_box_beforenm,
|
|
19888
|
-
crypto_box_afternm: crypto_box_afternm,
|
|
19889
|
-
crypto_box: crypto_box,
|
|
19890
|
-
crypto_box_open: crypto_box_open,
|
|
19891
|
-
crypto_box_keypair: crypto_box_keypair,
|
|
19892
|
-
crypto_hash: crypto_hash,
|
|
19893
|
-
crypto_sign: crypto_sign,
|
|
19894
|
-
crypto_sign_keypair: crypto_sign_keypair,
|
|
19895
|
-
crypto_sign_open: crypto_sign_open,
|
|
19896
|
-
|
|
19897
|
-
crypto_secretbox_KEYBYTES: crypto_secretbox_KEYBYTES,
|
|
19898
|
-
crypto_secretbox_NONCEBYTES: crypto_secretbox_NONCEBYTES,
|
|
19899
|
-
crypto_secretbox_ZEROBYTES: crypto_secretbox_ZEROBYTES,
|
|
19900
|
-
crypto_secretbox_BOXZEROBYTES: crypto_secretbox_BOXZEROBYTES,
|
|
19901
|
-
crypto_scalarmult_BYTES: crypto_scalarmult_BYTES,
|
|
19902
|
-
crypto_scalarmult_SCALARBYTES: crypto_scalarmult_SCALARBYTES,
|
|
19903
|
-
crypto_box_PUBLICKEYBYTES: crypto_box_PUBLICKEYBYTES,
|
|
19904
|
-
crypto_box_SECRETKEYBYTES: crypto_box_SECRETKEYBYTES,
|
|
19905
|
-
crypto_box_BEFORENMBYTES: crypto_box_BEFORENMBYTES,
|
|
19906
|
-
crypto_box_NONCEBYTES: crypto_box_NONCEBYTES,
|
|
19907
|
-
crypto_box_ZEROBYTES: crypto_box_ZEROBYTES,
|
|
19908
|
-
crypto_box_BOXZEROBYTES: crypto_box_BOXZEROBYTES,
|
|
19909
|
-
crypto_sign_BYTES: crypto_sign_BYTES,
|
|
19910
|
-
crypto_sign_PUBLICKEYBYTES: crypto_sign_PUBLICKEYBYTES,
|
|
19911
|
-
crypto_sign_SECRETKEYBYTES: crypto_sign_SECRETKEYBYTES,
|
|
19912
|
-
crypto_sign_SEEDBYTES: crypto_sign_SEEDBYTES,
|
|
19913
|
-
crypto_hash_BYTES: crypto_hash_BYTES,
|
|
19914
|
-
|
|
19915
|
-
gf: gf,
|
|
19916
|
-
D: D,
|
|
19917
|
-
L: L,
|
|
19918
|
-
pack25519: pack25519,
|
|
19919
|
-
unpack25519: unpack25519,
|
|
19920
|
-
M: M,
|
|
19921
|
-
A: A,
|
|
19922
|
-
S: S,
|
|
19923
|
-
Z: Z,
|
|
19924
|
-
pow2523: pow2523,
|
|
19925
|
-
add: add,
|
|
19926
|
-
set25519: set25519,
|
|
19927
|
-
modL: modL,
|
|
19928
|
-
scalarmult: scalarmult,
|
|
19929
|
-
scalarbase: scalarbase,
|
|
19930
|
-
};
|
|
19931
|
-
|
|
19932
|
-
/* High-level API */
|
|
19933
|
-
|
|
19934
|
-
function checkLengths(k, n) {
|
|
19935
|
-
if (k.length !== crypto_secretbox_KEYBYTES) throw new Error('bad key size');
|
|
19936
|
-
if (n.length !== crypto_secretbox_NONCEBYTES) throw new Error('bad nonce size');
|
|
19937
|
-
}
|
|
19938
|
-
|
|
19939
|
-
function checkBoxLengths(pk, sk) {
|
|
19940
|
-
if (pk.length !== crypto_box_PUBLICKEYBYTES) throw new Error('bad public key size');
|
|
19941
|
-
if (sk.length !== crypto_box_SECRETKEYBYTES) throw new Error('bad secret key size');
|
|
19942
|
-
}
|
|
19943
|
-
|
|
19944
|
-
function checkArrayTypes() {
|
|
19945
|
-
for (var i = 0; i < arguments.length; i++) {
|
|
19946
|
-
if (!(arguments[i] instanceof Uint8Array))
|
|
19947
|
-
throw new TypeError('unexpected type, use Uint8Array');
|
|
19948
|
-
}
|
|
19949
|
-
}
|
|
19950
|
-
|
|
19951
|
-
function cleanup(arr) {
|
|
19952
|
-
for (var i = 0; i < arr.length; i++) arr[i] = 0;
|
|
19953
|
-
}
|
|
19954
|
-
|
|
19955
|
-
nacl.randomBytes = function(n) {
|
|
19956
|
-
var b = new Uint8Array(n);
|
|
19957
|
-
randombytes(b, n);
|
|
19958
|
-
return b;
|
|
19959
|
-
};
|
|
19960
|
-
|
|
19961
|
-
nacl.secretbox = function(msg, nonce, key) {
|
|
19962
|
-
checkArrayTypes(msg, nonce, key);
|
|
19963
|
-
checkLengths(key, nonce);
|
|
19964
|
-
var m = new Uint8Array(crypto_secretbox_ZEROBYTES + msg.length);
|
|
19965
|
-
var c = new Uint8Array(m.length);
|
|
19966
|
-
for (var i = 0; i < msg.length; i++) m[i+crypto_secretbox_ZEROBYTES] = msg[i];
|
|
19967
|
-
crypto_secretbox(c, m, m.length, nonce, key);
|
|
19968
|
-
return c.subarray(crypto_secretbox_BOXZEROBYTES);
|
|
19969
|
-
};
|
|
19970
|
-
|
|
19971
|
-
nacl.secretbox.open = function(box, nonce, key) {
|
|
19972
|
-
checkArrayTypes(box, nonce, key);
|
|
19973
|
-
checkLengths(key, nonce);
|
|
19974
|
-
var c = new Uint8Array(crypto_secretbox_BOXZEROBYTES + box.length);
|
|
19975
|
-
var m = new Uint8Array(c.length);
|
|
19976
|
-
for (var i = 0; i < box.length; i++) c[i+crypto_secretbox_BOXZEROBYTES] = box[i];
|
|
19977
|
-
if (c.length < 32) return null;
|
|
19978
|
-
if (crypto_secretbox_open(m, c, c.length, nonce, key) !== 0) return null;
|
|
19979
|
-
return m.subarray(crypto_secretbox_ZEROBYTES);
|
|
19980
|
-
};
|
|
19981
|
-
|
|
19982
|
-
nacl.secretbox.keyLength = crypto_secretbox_KEYBYTES;
|
|
19983
|
-
nacl.secretbox.nonceLength = crypto_secretbox_NONCEBYTES;
|
|
19984
|
-
nacl.secretbox.overheadLength = crypto_secretbox_BOXZEROBYTES;
|
|
19985
|
-
|
|
19986
|
-
nacl.scalarMult = function(n, p) {
|
|
19987
|
-
checkArrayTypes(n, p);
|
|
19988
|
-
if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error('bad n size');
|
|
19989
|
-
if (p.length !== crypto_scalarmult_BYTES) throw new Error('bad p size');
|
|
19990
|
-
var q = new Uint8Array(crypto_scalarmult_BYTES);
|
|
19991
|
-
crypto_scalarmult(q, n, p);
|
|
19992
|
-
return q;
|
|
19993
|
-
};
|
|
19994
|
-
|
|
19995
|
-
nacl.scalarMult.base = function(n) {
|
|
19996
|
-
checkArrayTypes(n);
|
|
19997
|
-
if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error('bad n size');
|
|
19998
|
-
var q = new Uint8Array(crypto_scalarmult_BYTES);
|
|
19999
|
-
crypto_scalarmult_base(q, n);
|
|
20000
|
-
return q;
|
|
20001
|
-
};
|
|
20002
|
-
|
|
20003
|
-
nacl.scalarMult.scalarLength = crypto_scalarmult_SCALARBYTES;
|
|
20004
|
-
nacl.scalarMult.groupElementLength = crypto_scalarmult_BYTES;
|
|
20005
|
-
|
|
20006
|
-
nacl.box = function(msg, nonce, publicKey, secretKey) {
|
|
20007
|
-
var k = nacl.box.before(publicKey, secretKey);
|
|
20008
|
-
return nacl.secretbox(msg, nonce, k);
|
|
20009
|
-
};
|
|
20010
|
-
|
|
20011
|
-
nacl.box.before = function(publicKey, secretKey) {
|
|
20012
|
-
checkArrayTypes(publicKey, secretKey);
|
|
20013
|
-
checkBoxLengths(publicKey, secretKey);
|
|
20014
|
-
var k = new Uint8Array(crypto_box_BEFORENMBYTES);
|
|
20015
|
-
crypto_box_beforenm(k, publicKey, secretKey);
|
|
20016
|
-
return k;
|
|
20017
|
-
};
|
|
20018
|
-
|
|
20019
|
-
nacl.box.after = nacl.secretbox;
|
|
20020
|
-
|
|
20021
|
-
nacl.box.open = function(msg, nonce, publicKey, secretKey) {
|
|
20022
|
-
var k = nacl.box.before(publicKey, secretKey);
|
|
20023
|
-
return nacl.secretbox.open(msg, nonce, k);
|
|
20024
|
-
};
|
|
20025
|
-
|
|
20026
|
-
nacl.box.open.after = nacl.secretbox.open;
|
|
20027
|
-
|
|
20028
|
-
nacl.box.keyPair = function() {
|
|
20029
|
-
var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES);
|
|
20030
|
-
var sk = new Uint8Array(crypto_box_SECRETKEYBYTES);
|
|
20031
|
-
crypto_box_keypair(pk, sk);
|
|
20032
|
-
return {publicKey: pk, secretKey: sk};
|
|
20033
|
-
};
|
|
20034
|
-
|
|
20035
|
-
nacl.box.keyPair.fromSecretKey = function(secretKey) {
|
|
20036
|
-
checkArrayTypes(secretKey);
|
|
20037
|
-
if (secretKey.length !== crypto_box_SECRETKEYBYTES)
|
|
20038
|
-
throw new Error('bad secret key size');
|
|
20039
|
-
var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES);
|
|
20040
|
-
crypto_scalarmult_base(pk, secretKey);
|
|
20041
|
-
return {publicKey: pk, secretKey: new Uint8Array(secretKey)};
|
|
20042
|
-
};
|
|
20043
|
-
|
|
20044
|
-
nacl.box.publicKeyLength = crypto_box_PUBLICKEYBYTES;
|
|
20045
|
-
nacl.box.secretKeyLength = crypto_box_SECRETKEYBYTES;
|
|
20046
|
-
nacl.box.sharedKeyLength = crypto_box_BEFORENMBYTES;
|
|
20047
|
-
nacl.box.nonceLength = crypto_box_NONCEBYTES;
|
|
20048
|
-
nacl.box.overheadLength = nacl.secretbox.overheadLength;
|
|
20049
|
-
|
|
20050
|
-
nacl.sign = function(msg, secretKey) {
|
|
20051
|
-
checkArrayTypes(msg, secretKey);
|
|
20052
|
-
if (secretKey.length !== crypto_sign_SECRETKEYBYTES)
|
|
20053
|
-
throw new Error('bad secret key size');
|
|
20054
|
-
var signedMsg = new Uint8Array(crypto_sign_BYTES+msg.length);
|
|
20055
|
-
crypto_sign(signedMsg, msg, msg.length, secretKey);
|
|
20056
|
-
return signedMsg;
|
|
20057
|
-
};
|
|
20058
|
-
|
|
20059
|
-
nacl.sign.open = function(signedMsg, publicKey) {
|
|
20060
|
-
checkArrayTypes(signedMsg, publicKey);
|
|
20061
|
-
if (publicKey.length !== crypto_sign_PUBLICKEYBYTES)
|
|
20062
|
-
throw new Error('bad public key size');
|
|
20063
|
-
var tmp = new Uint8Array(signedMsg.length);
|
|
20064
|
-
var mlen = crypto_sign_open(tmp, signedMsg, signedMsg.length, publicKey);
|
|
20065
|
-
if (mlen < 0) return null;
|
|
20066
|
-
var m = new Uint8Array(mlen);
|
|
20067
|
-
for (var i = 0; i < m.length; i++) m[i] = tmp[i];
|
|
20068
|
-
return m;
|
|
20069
|
-
};
|
|
20070
|
-
|
|
20071
|
-
nacl.sign.detached = function(msg, secretKey) {
|
|
20072
|
-
var signedMsg = nacl.sign(msg, secretKey);
|
|
20073
|
-
var sig = new Uint8Array(crypto_sign_BYTES);
|
|
20074
|
-
for (var i = 0; i < sig.length; i++) sig[i] = signedMsg[i];
|
|
20075
|
-
return sig;
|
|
20076
|
-
};
|
|
20077
|
-
|
|
20078
|
-
nacl.sign.detached.verify = function(msg, sig, publicKey) {
|
|
20079
|
-
checkArrayTypes(msg, sig, publicKey);
|
|
20080
|
-
if (sig.length !== crypto_sign_BYTES)
|
|
20081
|
-
throw new Error('bad signature size');
|
|
20082
|
-
if (publicKey.length !== crypto_sign_PUBLICKEYBYTES)
|
|
20083
|
-
throw new Error('bad public key size');
|
|
20084
|
-
var sm = new Uint8Array(crypto_sign_BYTES + msg.length);
|
|
20085
|
-
var m = new Uint8Array(crypto_sign_BYTES + msg.length);
|
|
20086
|
-
var i;
|
|
20087
|
-
for (i = 0; i < crypto_sign_BYTES; i++) sm[i] = sig[i];
|
|
20088
|
-
for (i = 0; i < msg.length; i++) sm[i+crypto_sign_BYTES] = msg[i];
|
|
20089
|
-
return (crypto_sign_open(m, sm, sm.length, publicKey) >= 0);
|
|
20090
|
-
};
|
|
20091
|
-
|
|
20092
|
-
nacl.sign.keyPair = function() {
|
|
20093
|
-
var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
|
|
20094
|
-
var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES);
|
|
20095
|
-
crypto_sign_keypair(pk, sk);
|
|
20096
|
-
return {publicKey: pk, secretKey: sk};
|
|
20097
|
-
};
|
|
20098
|
-
|
|
20099
|
-
nacl.sign.keyPair.fromSecretKey = function(secretKey) {
|
|
20100
|
-
checkArrayTypes(secretKey);
|
|
20101
|
-
if (secretKey.length !== crypto_sign_SECRETKEYBYTES)
|
|
20102
|
-
throw new Error('bad secret key size');
|
|
20103
|
-
var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
|
|
20104
|
-
for (var i = 0; i < pk.length; i++) pk[i] = secretKey[32+i];
|
|
20105
|
-
return {publicKey: pk, secretKey: new Uint8Array(secretKey)};
|
|
20106
|
-
};
|
|
20107
|
-
|
|
20108
|
-
nacl.sign.keyPair.fromSeed = function(seed) {
|
|
20109
|
-
checkArrayTypes(seed);
|
|
20110
|
-
if (seed.length !== crypto_sign_SEEDBYTES)
|
|
20111
|
-
throw new Error('bad seed size');
|
|
20112
|
-
var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
|
|
20113
|
-
var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES);
|
|
20114
|
-
for (var i = 0; i < 32; i++) sk[i] = seed[i];
|
|
20115
|
-
crypto_sign_keypair(pk, sk, true);
|
|
20116
|
-
return {publicKey: pk, secretKey: sk};
|
|
20117
|
-
};
|
|
20118
|
-
|
|
20119
|
-
nacl.sign.publicKeyLength = crypto_sign_PUBLICKEYBYTES;
|
|
20120
|
-
nacl.sign.secretKeyLength = crypto_sign_SECRETKEYBYTES;
|
|
20121
|
-
nacl.sign.seedLength = crypto_sign_SEEDBYTES;
|
|
20122
|
-
nacl.sign.signatureLength = crypto_sign_BYTES;
|
|
20123
|
-
|
|
20124
|
-
nacl.hash = function(msg) {
|
|
20125
|
-
checkArrayTypes(msg);
|
|
20126
|
-
var h = new Uint8Array(crypto_hash_BYTES);
|
|
20127
|
-
crypto_hash(h, msg, msg.length);
|
|
20128
|
-
return h;
|
|
20129
|
-
};
|
|
20130
|
-
|
|
20131
|
-
nacl.hash.hashLength = crypto_hash_BYTES;
|
|
20132
|
-
|
|
20133
|
-
nacl.verify = function(x, y) {
|
|
20134
|
-
checkArrayTypes(x, y);
|
|
20135
|
-
// Zero length arguments are considered not equal.
|
|
20136
|
-
if (x.length === 0 || y.length === 0) return false;
|
|
20137
|
-
if (x.length !== y.length) return false;
|
|
20138
|
-
return (vn(x, 0, y, 0, x.length) === 0) ? true : false;
|
|
20139
|
-
};
|
|
20140
|
-
|
|
20141
|
-
nacl.setPRNG = function(fn) {
|
|
20142
|
-
randombytes = fn;
|
|
20143
|
-
};
|
|
20144
|
-
|
|
20145
|
-
(function() {
|
|
20146
|
-
// Initialize PRNG if environment provides CSPRNG.
|
|
20147
|
-
// If not, methods calling randombytes will throw.
|
|
20148
|
-
var crypto = typeof self !== 'undefined' ? (self.crypto || self.msCrypto) : null;
|
|
20149
|
-
if (crypto && crypto.getRandomValues) {
|
|
20150
|
-
// Browsers.
|
|
20151
|
-
var QUOTA = 65536;
|
|
20152
|
-
nacl.setPRNG(function(x, n) {
|
|
20153
|
-
var i, v = new Uint8Array(n);
|
|
20154
|
-
for (i = 0; i < n; i += QUOTA) {
|
|
20155
|
-
crypto.getRandomValues(v.subarray(i, i + Math.min(n - i, QUOTA)));
|
|
20156
|
-
}
|
|
20157
|
-
for (i = 0; i < n; i++) x[i] = v[i];
|
|
20158
|
-
cleanup(v);
|
|
20159
|
-
});
|
|
20160
|
-
} else if (typeof commonjsRequire !== 'undefined') {
|
|
20161
|
-
// Node.js.
|
|
20162
|
-
crypto = require$$0;
|
|
20163
|
-
if (crypto && crypto.randomBytes) {
|
|
20164
|
-
nacl.setPRNG(function(x, n) {
|
|
20165
|
-
var i, v = crypto.randomBytes(n);
|
|
20166
|
-
for (i = 0; i < n; i++) x[i] = v[i];
|
|
20167
|
-
cleanup(v);
|
|
20168
|
-
});
|
|
20169
|
-
}
|
|
20170
|
-
}
|
|
20171
|
-
})();
|
|
20172
|
-
|
|
20173
|
-
})(module.exports ? module.exports : (self.nacl = self.nacl || {}));
|
|
20174
|
-
} (naclFast));
|
|
20175
|
-
return naclFast.exports;
|
|
20176
|
-
}
|
|
20177
|
-
|
|
20178
|
-
var naclFastExports = requireNaclFast();
|
|
20179
|
-
var nacl = /*@__PURE__*/getDefaultExportFromCjs$1(naclFastExports);
|
|
20180
|
-
|
|
20181
|
-
// guest-keystore.ts — durable per-device keypair for anonymous ("guest") auth.
|
|
20182
|
-
//
|
|
20183
|
-
// A guest is an ed25519 keypair generated on the device. Its public key is the
|
|
20184
|
-
// Bounded account address; it signs the auth challenge exactly like a wallet.
|
|
20185
|
-
//
|
|
20186
|
-
// Two backends, chosen automatically:
|
|
20187
|
-
// 1. WebCrypto Ed25519 + IndexedDB (browsers that support it) — the key is
|
|
20188
|
-
// NON-EXTRACTABLE: an XSS can ask it to *sign* but can never read the
|
|
20189
|
-
// private bytes. This is the secure default.
|
|
20190
|
-
// 2. tweetnacl keypair in platform storage (React Native / older browsers) —
|
|
20191
|
-
// the secret is stored as bytes. Simpler, but exfiltratable by XSS, so
|
|
20192
|
-
// treat it as a low-stakes guest identity and tell users to upgrade
|
|
20193
|
-
// (link an email) before they care about not losing it.
|
|
20194
|
-
//
|
|
20195
|
-
// Either way the public output is identical: a base58 address + a base64
|
|
20196
|
-
// detached signature, which is the format the session endpoint already accepts.
|
|
20197
|
-
const FALLBACK_STORE_KEY = 'bounded_guest_key_v1';
|
|
20198
|
-
const IDB_NAME = 'bounded-guest';
|
|
20199
|
-
const IDB_STORE = 'keys';
|
|
20200
|
-
const IDB_KEY = 'ed25519';
|
|
20201
|
-
function toBase64(bytes) {
|
|
20202
|
-
let bin = '';
|
|
20203
|
-
for (let i = 0; i < bytes.length; i++)
|
|
20204
|
-
bin += String.fromCharCode(bytes[i]);
|
|
20205
|
-
// btoa exists in browsers + RN (Hermes) ; Buffer is the Node/SSR fallback.
|
|
20206
|
-
return typeof btoa !== 'undefined' ? btoa(bin) : Buffer.from(bytes).toString('base64');
|
|
20207
|
-
}
|
|
20208
|
-
// ----- WebCrypto (non-extractable) backend -----------------------------------
|
|
20209
|
-
function subtle() {
|
|
20210
|
-
const c = globalThis === null || globalThis === void 0 ? void 0 : globalThis.crypto;
|
|
20211
|
-
return c && c.subtle ? c.subtle : null;
|
|
20212
|
-
}
|
|
20213
|
-
function idb() {
|
|
20214
|
-
return new Promise((resolve, reject) => {
|
|
20215
|
-
const req = globalThis.indexedDB.open(IDB_NAME, 1);
|
|
20216
|
-
req.onupgradeneeded = () => req.result.createObjectStore(IDB_STORE);
|
|
20217
|
-
req.onsuccess = () => resolve(req.result);
|
|
20218
|
-
req.onerror = () => reject(req.error);
|
|
20219
|
-
});
|
|
20220
|
-
}
|
|
20221
|
-
function idbGet(db, key) {
|
|
20222
|
-
return new Promise((resolve, reject) => {
|
|
20223
|
-
const r = db.transaction(IDB_STORE, 'readonly').objectStore(IDB_STORE).get(key);
|
|
20224
|
-
r.onsuccess = () => resolve(r.result);
|
|
20225
|
-
r.onerror = () => reject(r.error);
|
|
20226
|
-
});
|
|
20227
|
-
}
|
|
20228
|
-
function idbPut(db, key, val) {
|
|
20229
|
-
return new Promise((resolve, reject) => {
|
|
20230
|
-
const r = db.transaction(IDB_STORE, 'readwrite').objectStore(IDB_STORE).put(val, key);
|
|
20231
|
-
r.onsuccess = () => resolve();
|
|
20232
|
-
r.onerror = () => reject(r.error);
|
|
20233
|
-
});
|
|
20234
|
-
}
|
|
20235
|
-
async function tryWebCrypto() {
|
|
20236
|
-
const s = subtle();
|
|
20237
|
-
if (!s || typeof globalThis.indexedDB === 'undefined')
|
|
20238
|
-
return null;
|
|
20239
|
-
try {
|
|
20240
|
-
const db = await idb();
|
|
20241
|
-
let pair = (await idbGet(db, IDB_KEY));
|
|
20242
|
-
if (!pair) {
|
|
20243
|
-
// Probe Ed25519 support by generating (throws on unsupported engines).
|
|
20244
|
-
pair = (await s.generateKey({ name: 'Ed25519' }, /* extractable */ false, [
|
|
20245
|
-
'sign',
|
|
20246
|
-
'verify',
|
|
20247
|
-
]));
|
|
20248
|
-
await idbPut(db, IDB_KEY, pair); // CryptoKey is structured-cloneable; bytes never exposed
|
|
20249
|
-
}
|
|
20250
|
-
const raw = new Uint8Array(await s.exportKey('raw', pair.publicKey)); // public is exportable
|
|
20251
|
-
const address = bs582.encode(raw);
|
|
20252
|
-
return {
|
|
20253
|
-
address,
|
|
20254
|
-
nonExtractable: true,
|
|
20255
|
-
async sign(message) {
|
|
20256
|
-
const data = new TextEncoder().encode(message);
|
|
20257
|
-
const sig = new Uint8Array(await s.sign({ name: 'Ed25519' }, pair.privateKey, data));
|
|
20258
|
-
return toBase64(sig);
|
|
20259
|
-
},
|
|
20260
|
-
};
|
|
20261
|
-
}
|
|
20262
|
-
catch (_a) {
|
|
20263
|
-
return null; // engine lacks Ed25519 / IndexedDB blocked → fall back
|
|
20264
|
-
}
|
|
20265
|
-
}
|
|
20266
|
-
// ----- tweetnacl (stored-secret) fallback ------------------------------------
|
|
20267
|
-
function fallbackKey() {
|
|
20268
|
-
const store = getPlatform().storage;
|
|
20269
|
-
let secret;
|
|
20270
|
-
const saved = store.getItem(FALLBACK_STORE_KEY);
|
|
20271
|
-
if (saved) {
|
|
20272
|
-
secret = bs582.decode(saved);
|
|
20273
|
-
}
|
|
20274
|
-
else {
|
|
20275
|
-
const kp = web3_js.Keypair.generate();
|
|
20276
|
-
secret = kp.secretKey; // 64 bytes
|
|
20277
|
-
store.setItem(FALLBACK_STORE_KEY, bs582.encode(secret));
|
|
20278
|
-
}
|
|
20279
|
-
const kp = web3_js.Keypair.fromSecretKey(secret);
|
|
20280
|
-
const address = kp.publicKey.toBase58();
|
|
20281
|
-
return {
|
|
20282
|
-
address,
|
|
20283
|
-
nonExtractable: false,
|
|
20284
|
-
async sign(message) {
|
|
20285
|
-
const data = new TextEncoder().encode(message);
|
|
20286
|
-
const sig = nacl.sign.detached(data, secret);
|
|
20287
|
-
return toBase64(sig);
|
|
20288
|
-
},
|
|
20289
|
-
};
|
|
20290
|
-
}
|
|
20291
|
-
let cached = null;
|
|
20292
|
-
/** Get (or create) this device's durable guest key. */
|
|
20293
|
-
async function getGuestKey() {
|
|
20294
|
-
var _a;
|
|
20295
|
-
if (cached)
|
|
20296
|
-
return cached;
|
|
20297
|
-
cached = (_a = (await tryWebCrypto())) !== null && _a !== void 0 ? _a : fallbackKey();
|
|
20298
|
-
return cached;
|
|
20299
|
-
}
|
|
20300
|
-
/** Forget the guest key on this device (a fresh signInAnonymously mints a new one). */
|
|
20301
|
-
async function clearGuestKey() {
|
|
20302
|
-
cached = null;
|
|
20303
|
-
try {
|
|
20304
|
-
getPlatform().storage.removeItem(FALLBACK_STORE_KEY);
|
|
20305
|
-
}
|
|
20306
|
-
catch (_a) { }
|
|
20307
|
-
try {
|
|
20308
|
-
if (typeof globalThis.indexedDB !== 'undefined') {
|
|
20309
|
-
const db = await idb();
|
|
20310
|
-
await new Promise((res) => {
|
|
20311
|
-
const r = db.transaction(IDB_STORE, 'readwrite').objectStore(IDB_STORE).delete(IDB_KEY);
|
|
20312
|
-
r.onsuccess = () => res();
|
|
20313
|
-
r.onerror = () => res();
|
|
20314
|
-
});
|
|
20315
|
-
}
|
|
20316
|
-
}
|
|
20317
|
-
catch (_b) { }
|
|
20318
|
-
}
|
|
20319
|
-
|
|
20320
|
-
const GUEST_TX_UNSUPPORTED = 'Guest (anonymous) auth is offchain-only — it cannot sign or submit Solana transactions. ' +
|
|
20321
|
-
'Use a wallet provider for onchain actions.';
|
|
20322
|
-
class GuestAuthProvider {
|
|
20323
|
-
async login() {
|
|
20324
|
-
setAuthLoading(true);
|
|
20325
|
-
try {
|
|
20326
|
-
const key = await getGuestKey();
|
|
20327
|
-
// Reuse a still-valid session for this exact guest.
|
|
20328
|
-
const existing = await getActiveSessionManager().getSession();
|
|
20329
|
-
if (existing && existing.address === key.address) {
|
|
20330
|
-
const user = { address: key.address, isAnonymous: true, provider: this };
|
|
20331
|
-
setCurrentUser(user);
|
|
20332
|
-
return user;
|
|
20333
|
-
}
|
|
20334
|
-
// Mint a fresh session: nonce -> canonical message -> local signature.
|
|
20335
|
-
const nonce = await genAuthNonce();
|
|
20336
|
-
const message = await genSolanaMessage(key.address, nonce);
|
|
20337
|
-
const signature = await key.sign(message); // base64 detached ed25519
|
|
20338
|
-
const result = await createSessionWithSignature(key.address, message, signature);
|
|
20339
|
-
await getActiveSessionManager().storeSession(key.address, result.accessToken, result.idToken, result.refreshToken);
|
|
20340
|
-
const user = { address: key.address, isAnonymous: true, provider: this };
|
|
20341
|
-
setCurrentUser(user);
|
|
20342
|
-
return user;
|
|
20343
|
-
}
|
|
20344
|
-
finally {
|
|
20345
|
-
setAuthLoading(false);
|
|
20346
|
-
}
|
|
20347
|
-
}
|
|
20348
|
-
async restoreSession() {
|
|
20349
|
-
const session = await getActiveSessionManager().getSession();
|
|
20350
|
-
if (!session)
|
|
20351
|
-
return null;
|
|
20352
|
-
const user = { address: session.address, isAnonymous: true, provider: this };
|
|
20353
|
-
setCurrentUser(user);
|
|
20354
|
-
return user;
|
|
20355
|
-
}
|
|
20356
|
-
async logout() {
|
|
20357
|
-
// Clears the SESSION but keeps the device key, so logging back in returns the
|
|
20358
|
-
// SAME guest identity (and its data). Use forgetGuest() to wipe the key too.
|
|
20359
|
-
getActiveSessionManager().clearSession();
|
|
20360
|
-
setCurrentUser(null);
|
|
20361
|
-
}
|
|
20362
|
-
/** Wipe the device key — the next login() is a brand-new guest identity. */
|
|
20363
|
-
async forgetGuest() {
|
|
20364
|
-
getActiveSessionManager().clearSession();
|
|
20365
|
-
await clearGuestKey();
|
|
20366
|
-
setCurrentUser(null);
|
|
20367
|
-
}
|
|
20368
|
-
async signMessage(message) {
|
|
20369
|
-
const key = await getGuestKey();
|
|
20370
|
-
return key.sign(message);
|
|
20371
|
-
}
|
|
20372
|
-
// --- offchain guest: no Solana transaction surface -------------------------
|
|
20373
|
-
async runTransaction(_evm, _sol, _options) {
|
|
20374
|
-
throw new Error(GUEST_TX_UNSUPPORTED);
|
|
20375
|
-
}
|
|
20376
|
-
async signTransaction(_t) {
|
|
20377
|
-
throw new Error(GUEST_TX_UNSUPPORTED);
|
|
20378
|
-
}
|
|
20379
|
-
async signAndSubmitTransaction() {
|
|
20380
|
-
throw new Error(GUEST_TX_UNSUPPORTED);
|
|
20381
|
-
}
|
|
20382
|
-
async getNativeMethods() {
|
|
20383
|
-
return {};
|
|
20384
|
-
}
|
|
20385
|
-
}
|
|
17982
|
+
const GUEST_TX_UNSUPPORTED = 'Guest (anonymous) auth is offchain-only — it cannot sign or submit Solana transactions. ' +
|
|
17983
|
+
'Use a wallet provider for onchain actions.';
|
|
17984
|
+
class GuestAuthProvider {
|
|
17985
|
+
async login() {
|
|
17986
|
+
setAuthLoading(true);
|
|
17987
|
+
try {
|
|
17988
|
+
const key = await getGuestKey();
|
|
17989
|
+
// Reuse a still-valid session for this exact guest.
|
|
17990
|
+
const existing = await getActiveSessionManager().getSession();
|
|
17991
|
+
if (existing && existing.address === key.address) {
|
|
17992
|
+
const user = { address: key.address, isAnonymous: true, provider: this };
|
|
17993
|
+
setCurrentUser(user);
|
|
17994
|
+
return user;
|
|
17995
|
+
}
|
|
17996
|
+
// Mint a fresh session: nonce -> canonical message -> local signature.
|
|
17997
|
+
const nonce = await genAuthNonce();
|
|
17998
|
+
const message = await genSolanaMessage(key.address, nonce);
|
|
17999
|
+
const signature = await key.sign(message); // base64 detached ed25519
|
|
18000
|
+
const result = await createSessionWithSignature(key.address, message, signature);
|
|
18001
|
+
await getActiveSessionManager().storeSession(key.address, result.accessToken, result.idToken, result.refreshToken);
|
|
18002
|
+
const user = { address: key.address, isAnonymous: true, provider: this };
|
|
18003
|
+
setCurrentUser(user);
|
|
18004
|
+
return user;
|
|
18005
|
+
}
|
|
18006
|
+
finally {
|
|
18007
|
+
setAuthLoading(false);
|
|
18008
|
+
}
|
|
18009
|
+
}
|
|
18010
|
+
async restoreSession() {
|
|
18011
|
+
const session = await getActiveSessionManager().getSession();
|
|
18012
|
+
if (!session)
|
|
18013
|
+
return null;
|
|
18014
|
+
const user = { address: session.address, isAnonymous: true, provider: this };
|
|
18015
|
+
setCurrentUser(user);
|
|
18016
|
+
return user;
|
|
18017
|
+
}
|
|
18018
|
+
async logout() {
|
|
18019
|
+
// Clears the SESSION but keeps the device key, so logging back in returns the
|
|
18020
|
+
// SAME guest identity (and its data). Use forgetGuest() to wipe the key too.
|
|
18021
|
+
getActiveSessionManager().clearSession();
|
|
18022
|
+
setCurrentUser(null);
|
|
18023
|
+
}
|
|
18024
|
+
/** Wipe the device key — the next login() is a brand-new guest identity. */
|
|
18025
|
+
async forgetGuest() {
|
|
18026
|
+
getActiveSessionManager().clearSession();
|
|
18027
|
+
await clearGuestKey();
|
|
18028
|
+
setCurrentUser(null);
|
|
18029
|
+
}
|
|
18030
|
+
async signMessage(message) {
|
|
18031
|
+
const key = await getGuestKey();
|
|
18032
|
+
return key.sign(message);
|
|
18033
|
+
}
|
|
18034
|
+
// --- offchain guest: no Solana transaction surface -------------------------
|
|
18035
|
+
async runTransaction(_evm, _sol, _options) {
|
|
18036
|
+
throw new Error(GUEST_TX_UNSUPPORTED);
|
|
18037
|
+
}
|
|
18038
|
+
async signTransaction(_t) {
|
|
18039
|
+
throw new Error(GUEST_TX_UNSUPPORTED);
|
|
18040
|
+
}
|
|
18041
|
+
async signAndSubmitTransaction() {
|
|
18042
|
+
throw new Error(GUEST_TX_UNSUPPORTED);
|
|
18043
|
+
}
|
|
18044
|
+
async getNativeMethods() {
|
|
18045
|
+
return {};
|
|
18046
|
+
}
|
|
18047
|
+
}
|
|
20386
18048
|
|
|
20387
18049
|
// Web uses localStorage (WebSessionManager); React Native uses the configured
|
|
20388
18050
|
// ReactNativeSessionManager. getActiveSessionManager() picks the right one by
|
|
@@ -21559,17 +19221,17 @@ function setAuthProviderInstance(provider) {
|
|
|
21559
19221
|
authProviderInstance = provider;
|
|
21560
19222
|
}
|
|
21561
19223
|
|
|
21562
|
-
var _a;
|
|
19224
|
+
var _a$1;
|
|
21563
19225
|
// Whether we're in a server-side rendering context (no hooks allowed).
|
|
21564
19226
|
// React Native has no `window` but DOES support hooks.
|
|
21565
19227
|
// We detect Node SSR specifically via process.versions.node to avoid
|
|
21566
19228
|
// false positives from Node 21+ which defines `navigator` globally.
|
|
21567
|
-
const isSSR = typeof window === 'undefined'
|
|
19229
|
+
const isSSR$1 = typeof window === 'undefined'
|
|
21568
19230
|
&& typeof process !== 'undefined'
|
|
21569
|
-
&& !!((_a = process.versions) === null || _a === void 0 ? void 0 : _a.node);
|
|
19231
|
+
&& !!((_a$1 = process.versions) === null || _a$1 === void 0 ? void 0 : _a$1.node);
|
|
21570
19232
|
function useAuth() {
|
|
21571
19233
|
// Provide a fallback so server render doesn't break
|
|
21572
|
-
if (isSSR) {
|
|
19234
|
+
if (isSSR$1) {
|
|
21573
19235
|
return {
|
|
21574
19236
|
login: async () => undefined,
|
|
21575
19237
|
logout: async () => undefined,
|
|
@@ -21629,6 +19291,66 @@ function useAuth() {
|
|
|
21629
19291
|
};
|
|
21630
19292
|
}
|
|
21631
19293
|
|
|
19294
|
+
var _a;
|
|
19295
|
+
// SSR guard (mirrors useAuth): no hooks/subscriptions during Node server render.
|
|
19296
|
+
// React Native has no `window` but DOES support hooks, so detect Node SSR
|
|
19297
|
+
// specifically via process.versions.node.
|
|
19298
|
+
const isSSR = typeof window === 'undefined'
|
|
19299
|
+
&& typeof process !== 'undefined'
|
|
19300
|
+
&& !!((_a = process.versions) === null || _a === void 0 ? void 0 : _a.node);
|
|
19301
|
+
function useQuery(path, options) {
|
|
19302
|
+
if (isSSR) {
|
|
19303
|
+
return { data: undefined, loading: true, error: null };
|
|
19304
|
+
}
|
|
19305
|
+
const [data, setData] = React__namespace.useState(undefined);
|
|
19306
|
+
const [loading, setLoading] = React__namespace.useState(true);
|
|
19307
|
+
const [error, setError] = React__namespace.useState(null);
|
|
19308
|
+
// Re-subscribe only when the query actually changes (not on every render).
|
|
19309
|
+
const optionsKey = options ? JSON.stringify(options) : '';
|
|
19310
|
+
React__namespace.useEffect(() => {
|
|
19311
|
+
if (!path) {
|
|
19312
|
+
setData(undefined);
|
|
19313
|
+
setLoading(false);
|
|
19314
|
+
setError(null);
|
|
19315
|
+
return;
|
|
19316
|
+
}
|
|
19317
|
+
let active = true;
|
|
19318
|
+
let unsubscribe;
|
|
19319
|
+
setLoading(true);
|
|
19320
|
+
setError(null);
|
|
19321
|
+
subscribe(path, Object.assign(Object.assign({}, options), { onData: (d) => {
|
|
19322
|
+
if (!active)
|
|
19323
|
+
return;
|
|
19324
|
+
setData(d);
|
|
19325
|
+
setLoading(false);
|
|
19326
|
+
}, onError: (e) => {
|
|
19327
|
+
if (!active)
|
|
19328
|
+
return;
|
|
19329
|
+
setError(e instanceof Error ? e : new Error(String(e)));
|
|
19330
|
+
setLoading(false);
|
|
19331
|
+
} }))
|
|
19332
|
+
.then((unsub) => {
|
|
19333
|
+
if (active)
|
|
19334
|
+
unsubscribe = unsub;
|
|
19335
|
+
else
|
|
19336
|
+
void unsub(); // unmounted before subscribe resolved
|
|
19337
|
+
})
|
|
19338
|
+
.catch((e) => {
|
|
19339
|
+
if (!active)
|
|
19340
|
+
return;
|
|
19341
|
+
setError(e instanceof Error ? e : new Error(String(e)));
|
|
19342
|
+
setLoading(false);
|
|
19343
|
+
});
|
|
19344
|
+
return () => {
|
|
19345
|
+
active = false;
|
|
19346
|
+
void (unsubscribe === null || unsubscribe === void 0 ? void 0 : unsubscribe());
|
|
19347
|
+
};
|
|
19348
|
+
// optionsKey captures the option object's contents; path is the other input.
|
|
19349
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
19350
|
+
}, [path, optionsKey]);
|
|
19351
|
+
return { data, loading, error };
|
|
19352
|
+
}
|
|
19353
|
+
|
|
21632
19354
|
async function deserializeTransaction(tx) {
|
|
21633
19355
|
const buf = Buffer.isBuffer(tx) ? tx : Buffer.from(tx, 'base64');
|
|
21634
19356
|
if ((buf[0] & 0x80) !== 0) {
|
|
@@ -21762,7 +19484,7 @@ async function loadDependencies() {
|
|
|
21762
19484
|
const [reactModule, reactDomModule, phantomModule] = await Promise.all([
|
|
21763
19485
|
import('react'),
|
|
21764
19486
|
import('react-dom/client'),
|
|
21765
|
-
Promise.resolve().then(function () { return require('./index-
|
|
19487
|
+
Promise.resolve().then(function () { return require('./index-FYyc3l_y.js'); })
|
|
21766
19488
|
]);
|
|
21767
19489
|
// Extract default export from ESM module namespace
|
|
21768
19490
|
// Dynamic import() returns { default: Module, ...exports }, not the module directly
|
|
@@ -23663,7 +21385,7 @@ async function registerMobileWalletAdapter(config) {
|
|
|
23663
21385
|
if (typeof window === 'undefined')
|
|
23664
21386
|
return;
|
|
23665
21387
|
try {
|
|
23666
|
-
const walletStandardMobile = await Promise.resolve().then(function () { return require('./index.browser-
|
|
21388
|
+
const walletStandardMobile = await Promise.resolve().then(function () { return require('./index.browser-D5evrolK.js'); });
|
|
23667
21389
|
const registerMwa = walletStandardMobile.registerMwa || ((_a = walletStandardMobile.default) === null || _a === void 0 ? void 0 : _a.registerMwa);
|
|
23668
21390
|
if (!registerMwa) {
|
|
23669
21391
|
console.warn('[SolanaMobileWallet] registerMwa not found in @solana-mobile/wallet-standard-mobile');
|
|
@@ -23802,7 +21524,7 @@ class SolanaMobileWalletProvider {
|
|
|
23802
21524
|
async ensureWallet() {
|
|
23803
21525
|
if (this.wallet)
|
|
23804
21526
|
return this.wallet;
|
|
23805
|
-
const mod = await Promise.resolve().then(function () { return require('./index.browser-
|
|
21527
|
+
const mod = await Promise.resolve().then(function () { return require('./index.browser-D5evrolK.js'); });
|
|
23806
21528
|
const chain = mapChainToWalletStandard(this.cluster);
|
|
23807
21529
|
this.wallet = new mod.LocalSolanaMobileWalletAdapterWallet({
|
|
23808
21530
|
appIdentity: this.appIdentity,
|
|
@@ -25996,6 +23718,7 @@ exports.loginWithPopup = loginWithPopup;
|
|
|
25996
23718
|
exports.loginWithPrivy = loginWithPrivy;
|
|
25997
23719
|
exports.loginWithRedirect = loginWithRedirect;
|
|
25998
23720
|
exports.logout = logout;
|
|
23721
|
+
exports.now = now;
|
|
25999
23722
|
exports.onAuthLoadingChanged = onAuthLoadingChanged;
|
|
26000
23723
|
exports.onAuthStateChanged = onAuthStateChanged;
|
|
26001
23724
|
exports.queryAggregate = queryAggregate;
|
|
@@ -26023,7 +23746,10 @@ exports.signTransaction = signTransaction;
|
|
|
26023
23746
|
exports.status = status;
|
|
26024
23747
|
exports.subscribe = subscribe;
|
|
26025
23748
|
exports.subscribeView = subscribeView;
|
|
23749
|
+
exports.toMillis = toMillis;
|
|
23750
|
+
exports.toSeconds = toSeconds;
|
|
26026
23751
|
exports.useAuth = useAuth;
|
|
23752
|
+
exports.useQuery = useQuery;
|
|
26027
23753
|
exports.verifyEmailOtp = verifyEmailOtp;
|
|
26028
23754
|
exports.withEffects = withEffects;
|
|
26029
23755
|
exports.wsDelete = wsDelete;
|
|
@@ -26031,4 +23757,4 @@ exports.wsGet = wsGet;
|
|
|
26031
23757
|
exports.wsGetMany = wsGetMany;
|
|
26032
23758
|
exports.wsQuery = wsQuery;
|
|
26033
23759
|
exports.wsSet = wsSet;
|
|
26034
|
-
//# sourceMappingURL=index-
|
|
23760
|
+
//# sourceMappingURL=index-BBLnBZjY.js.map
|