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