@bounded-sh/client 0.0.4 → 0.0.6
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 +1 -1
- package/dist/{index-DkWfblRJ.esm.js → index-BzOrZU4R.esm.js} +2 -2
- package/dist/{index-DkWfblRJ.esm.js.map → index-BzOrZU4R.esm.js.map} +1 -1
- package/dist/{index-FYyc3l_y.js → index-CSUmsmHJ.js} +2 -2
- package/dist/{index-FYyc3l_y.js.map → index-CSUmsmHJ.js.map} +1 -1
- package/dist/{index-BMrN-6oK.js → index-CtMYXtmh.js} +2 -2
- package/dist/{index-BMrN-6oK.js.map → index-CtMYXtmh.js.map} +1 -1
- package/dist/{index-D5Ut2JU7.esm.js → index-DAI10qql.esm.js} +2 -2
- package/dist/{index-D5Ut2JU7.esm.js.map → index-DAI10qql.esm.js.map} +1 -1
- package/dist/{index-BBLnBZjY.js → index-Dj2C_uV6.js} +2556 -23
- package/dist/index-Dj2C_uV6.js.map +1 -0
- package/dist/{index-n4fG6EZJ.esm.js → index-Oc5pQUDo.esm.js} +2556 -24
- package/dist/index-Oc5pQUDo.esm.js.map +1 -0
- package/dist/{index.browser-CCWEiCH-.esm.js → index.browser-BxwM4axz.esm.js} +2 -2
- package/dist/{index.browser-CCWEiCH-.esm.js.map → index.browser-BxwM4axz.esm.js.map} +1 -1
- package/dist/{index.browser-D5evrolK.js → index.browser-Cp6PqsEM.js} +2 -2
- package/dist/{index.browser-D5evrolK.js.map → index.browser-Cp6PqsEM.js.map} +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/{index.native-D82ofFXB.js → index.native-Lrhg8G-G.js} +2556 -23
- package/dist/index.native-Lrhg8G-G.js.map +1 -0
- package/dist/{index.native-D5q2RUeV.esm.js → index.native-Y7aFGpZp.esm.js} +2556 -24
- package/dist/index.native-Y7aFGpZp.esm.js.map +1 -0
- package/dist/index.native.d.ts +1 -1
- package/dist/index.native.esm.js +1 -1
- package/dist/index.native.js +2 -1
- package/dist/index.native.js.map +1 -1
- package/dist/{phantom-wallet-provider-CoL7g8Sr.js → phantom-wallet-provider-DQDZjZkl.js} +3 -3
- package/dist/{phantom-wallet-provider-CoL7g8Sr.js.map → phantom-wallet-provider-DQDZjZkl.js.map} +1 -1
- package/dist/{phantom-wallet-provider-C8DNu92D.esm.js → phantom-wallet-provider-K10GQBxk.esm.js} +3 -3
- package/dist/{phantom-wallet-provider-C8DNu92D.esm.js.map → phantom-wallet-provider-K10GQBxk.esm.js.map} +1 -1
- package/dist/{privy-wallet-provider-CV1mU4KR.js → privy-wallet-provider-Dh_jHrsq.js} +3 -3
- package/dist/{privy-wallet-provider-CV1mU4KR.js.map → privy-wallet-provider-Dh_jHrsq.js.map} +1 -1
- package/dist/{privy-wallet-provider-De3mfJYo.esm.js → privy-wallet-provider-scXNSzjF.esm.js} +3 -3
- package/dist/{privy-wallet-provider-De3mfJYo.esm.js.map → privy-wallet-provider-scXNSzjF.esm.js.map} +1 -1
- package/dist/{solana-mobile-wallet-provider-CLCvi-08.esm.js → solana-mobile-wallet-provider-BlwQuB4D.esm.js} +2 -2
- package/dist/{solana-mobile-wallet-provider-CLCvi-08.esm.js.map → solana-mobile-wallet-provider-BlwQuB4D.esm.js.map} +1 -1
- package/dist/{solana-mobile-wallet-provider-D9dPbk__.js → solana-mobile-wallet-provider-DMXR_nmz.js} +2 -2
- package/dist/{solana-mobile-wallet-provider-D9dPbk__.js.map → solana-mobile-wallet-provider-DMXR_nmz.js.map} +1 -1
- package/package.json +2 -2
- package/dist/index-BBLnBZjY.js.map +0 -1
- package/dist/index-n4fG6EZJ.esm.js.map +0 -1
- package/dist/index.native-D5q2RUeV.esm.js.map +0 -1
- package/dist/index.native-D82ofFXB.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 = {exports: {}};
|
|
21
|
+
var naclFast$1 = {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$1;
|
|
33
33
|
|
|
34
|
-
function requireNaclFast () {
|
|
35
|
-
if (hasRequiredNaclFast) return naclFast.exports;
|
|
36
|
-
hasRequiredNaclFast = 1;
|
|
34
|
+
function requireNaclFast$1 () {
|
|
35
|
+
if (hasRequiredNaclFast$1) return naclFast$1.exports;
|
|
36
|
+
hasRequiredNaclFast$1 = 1;
|
|
37
37
|
(function (module) {
|
|
38
38
|
(function(nacl) {
|
|
39
39
|
|
|
@@ -2425,12 +2425,12 @@ function requireNaclFast () {
|
|
|
2425
2425
|
})();
|
|
2426
2426
|
|
|
2427
2427
|
})(module.exports ? module.exports : (self.nacl = self.nacl || {}));
|
|
2428
|
-
} (naclFast));
|
|
2429
|
-
return naclFast.exports;
|
|
2428
|
+
} (naclFast$1));
|
|
2429
|
+
return naclFast$1.exports;
|
|
2430
2430
|
}
|
|
2431
2431
|
|
|
2432
|
-
var naclFastExports = requireNaclFast();
|
|
2433
|
-
var nacl = /*@__PURE__*/getDefaultExportFromCjs$1(naclFastExports);
|
|
2432
|
+
var naclFastExports$1 = requireNaclFast$1();
|
|
2433
|
+
var nacl$1 = /*@__PURE__*/getDefaultExportFromCjs$1(naclFastExports$1);
|
|
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.sign.detached(new TextEncoder().encode(message), kp.secretKey);
|
|
10216
|
+
const sigBytes = nacl$1.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);
|
|
@@ -10632,6 +10632,91 @@ const pendingRequests = {};
|
|
|
10632
10632
|
const GET_CACHE_TTL = 500; // Adjust this value as needed (in milliseconds)
|
|
10633
10633
|
// Last time we cleaned up the cache
|
|
10634
10634
|
let lastCacheCleanup = Date.now();
|
|
10635
|
+
/**
|
|
10636
|
+
* Return the leaf document key (last path segment) for a document path.
|
|
10637
|
+
*
|
|
10638
|
+
* Bounded rows carry `_id` (and `pathId`) set to the FULL document path
|
|
10639
|
+
* (e.g. `"rooms/r1/prompts/8rd49se3sg"`). Apps that build a child path from a
|
|
10640
|
+
* row naturally want the bare doc key, not the whole path — using the full path
|
|
10641
|
+
* doubles it (`rooms/r1/prompts/rooms/r1/prompts/8rd.../votes/...`) → 403/404.
|
|
10642
|
+
* `docId` extracts that leaf key. Tolerates leading slashes and a trailing `*`.
|
|
10643
|
+
*
|
|
10644
|
+
* @example docId("rooms/r1/prompts/8rd49se3sg") // "8rd49se3sg"
|
|
10645
|
+
*/
|
|
10646
|
+
function docId(path) {
|
|
10647
|
+
if (typeof path !== 'string')
|
|
10648
|
+
return '';
|
|
10649
|
+
let p = path.startsWith('/') ? path.slice(1) : path;
|
|
10650
|
+
if (p.endsWith('*') && p.length > 1)
|
|
10651
|
+
p = p.slice(0, -1);
|
|
10652
|
+
if (p.endsWith('/'))
|
|
10653
|
+
p = p.slice(0, -1);
|
|
10654
|
+
const segments = p.split('/').filter(Boolean);
|
|
10655
|
+
return segments.length ? segments[segments.length - 1] : '';
|
|
10656
|
+
}
|
|
10657
|
+
/**
|
|
10658
|
+
* Additively attach a convenience bare `id` (the leaf doc key) to a returned row.
|
|
10659
|
+
*
|
|
10660
|
+
* Rows already carry `_id`/`pathId` = the full document path; this leaves those
|
|
10661
|
+
* untouched and adds `id` = the last path segment so `row.id` is the doc key apps
|
|
10662
|
+
* expect. No-ops for non-objects, arrays, and rows that already define `id`
|
|
10663
|
+
* (never clobber a user field named `id`). Source for the leaf is `_id` (falling
|
|
10664
|
+
* back to `pathId`/`relativePath`/`absolutePath`).
|
|
10665
|
+
*/
|
|
10666
|
+
function withBareId(row) {
|
|
10667
|
+
var _a, _b, _c;
|
|
10668
|
+
if (!row || typeof row !== 'object' || Array.isArray(row))
|
|
10669
|
+
return row;
|
|
10670
|
+
const r = row;
|
|
10671
|
+
if ('id' in r)
|
|
10672
|
+
return row; // don't clobber an explicit user field
|
|
10673
|
+
const source = (_c = (_b = (_a = r._id) !== null && _a !== void 0 ? _a : r.pathId) !== null && _b !== void 0 ? _b : r.relativePath) !== null && _c !== void 0 ? _c : r.absolutePath;
|
|
10674
|
+
if (typeof source !== 'string' || source.length === 0)
|
|
10675
|
+
return row;
|
|
10676
|
+
const leaf = docId(source);
|
|
10677
|
+
if (!leaf)
|
|
10678
|
+
return row;
|
|
10679
|
+
return Object.assign(Object.assign({}, r), { id: leaf });
|
|
10680
|
+
}
|
|
10681
|
+
/**
|
|
10682
|
+
* Normalize a raw read response from the worker into the SDK's stable shape and
|
|
10683
|
+
* attach the bare `id` to every returned row (Bug 1 + Bug 2).
|
|
10684
|
+
*
|
|
10685
|
+
* - Single-document path: returns EXACTLY ONE shape — the resolved document, or
|
|
10686
|
+
* `null` if missing (Firebase/Mongo convention). Unwraps the ambiguous
|
|
10687
|
+
* `{ data, status }` envelope the worker sometimes emits for a single doc so a
|
|
10688
|
+
* single-doc `get` never sometimes-returns the doc and sometimes the envelope.
|
|
10689
|
+
* - Collection path: preserves the `{ data, nextCursor, ... }` envelope and maps
|
|
10690
|
+
* the bare `id` onto each row in `data`.
|
|
10691
|
+
*/
|
|
10692
|
+
function normalizeReadResult(responseData, pathIsDocument) {
|
|
10693
|
+
if (pathIsDocument) {
|
|
10694
|
+
let doc = responseData;
|
|
10695
|
+
// Unwrap the single-doc envelope `{ data, status }` (Bug 2). A real document
|
|
10696
|
+
// never has the exact shape `{ data, status }` with nothing else meaningful,
|
|
10697
|
+
// so detect the envelope by `data` + numeric `status` AND the absence of a
|
|
10698
|
+
// top-level `_id` (a real stored doc always carries `_id`/`pathId` from the
|
|
10699
|
+
// worker; the envelope wrapper does not). This avoids unwrapping a genuine
|
|
10700
|
+
// document that merely happens to own `data`/`status` fields.
|
|
10701
|
+
if (doc && typeof doc === 'object' && !Array.isArray(doc) &&
|
|
10702
|
+
'data' in doc && 'status' in doc && typeof doc.status === 'number' &&
|
|
10703
|
+
!('_id' in doc) && !('pathId' in doc)) {
|
|
10704
|
+
doc = doc.data;
|
|
10705
|
+
}
|
|
10706
|
+
if (doc === undefined || doc === null)
|
|
10707
|
+
return null;
|
|
10708
|
+
return withBareId(doc);
|
|
10709
|
+
}
|
|
10710
|
+
// Collection read. The worker body is `{ data: rows[], nextCursor?, status? }`.
|
|
10711
|
+
if (responseData && typeof responseData === 'object' && !Array.isArray(responseData) && Array.isArray(responseData.data)) {
|
|
10712
|
+
return Object.assign(Object.assign({}, responseData), { data: responseData.data.map((row) => withBareId(row)) });
|
|
10713
|
+
}
|
|
10714
|
+
// Some paths return a bare array of rows — map id onto each.
|
|
10715
|
+
if (Array.isArray(responseData)) {
|
|
10716
|
+
return responseData.map((row) => withBareId(row));
|
|
10717
|
+
}
|
|
10718
|
+
return responseData;
|
|
10719
|
+
}
|
|
10635
10720
|
function hashForKey$1(value) {
|
|
10636
10721
|
let h = 5381;
|
|
10637
10722
|
for (let i = 0; i < value.length; i++) {
|
|
@@ -11056,7 +11141,7 @@ async function get(path, opts = {}) {
|
|
|
11056
11141
|
if (hasActiveConnection()) {
|
|
11057
11142
|
if (pathIsDocument) {
|
|
11058
11143
|
const wsResult = await wsGet(normalizedPath);
|
|
11059
|
-
const responseData = wsResult;
|
|
11144
|
+
const responseData = normalizeReadResult(wsResult, true);
|
|
11060
11145
|
if (!opts.bypassCache) {
|
|
11061
11146
|
getCache[cacheKey] = { data: responseData, expiresAt: now + GET_CACHE_TTL };
|
|
11062
11147
|
}
|
|
@@ -11068,7 +11153,7 @@ async function get(path, opts = {}) {
|
|
|
11068
11153
|
sort: undefined,
|
|
11069
11154
|
includeSubPaths: opts.includeSubPaths,
|
|
11070
11155
|
});
|
|
11071
|
-
const responseData = wsResult;
|
|
11156
|
+
const responseData = normalizeReadResult(wsResult, false);
|
|
11072
11157
|
if (!opts.bypassCache) {
|
|
11073
11158
|
getCache[cacheKey] = { data: responseData, expiresAt: now + GET_CACHE_TTL };
|
|
11074
11159
|
}
|
|
@@ -11099,7 +11184,11 @@ async function get(path, opts = {}) {
|
|
|
11099
11184
|
const apiPath = `items?path=${path}${promptQueryParam}${filterParam}${sortParam}${includeSubPathsParam}${shapeParam}${limitParam}${cursorParam}`;
|
|
11100
11185
|
response = await makeApiRequest('GET', apiPath, null, opts._overrides);
|
|
11101
11186
|
}
|
|
11102
|
-
|
|
11187
|
+
// Normalize the worker's raw body into the SDK's stable shape:
|
|
11188
|
+
// - single-doc path → the resolved document or null (Bug 2), and
|
|
11189
|
+
// - collection path → `{ data, nextCursor }` preserved,
|
|
11190
|
+
// with the bare `id` (leaf doc key) attached to every returned row (Bug 1).
|
|
11191
|
+
const responseData = normalizeReadResult(response.data, pathIsDocument);
|
|
11103
11192
|
// Cache the response (unless bypassing cache)
|
|
11104
11193
|
if (!opts.bypassCache) {
|
|
11105
11194
|
getCache[cacheKey] = {
|
|
@@ -11197,11 +11286,16 @@ async function getMany(paths, opts = {}) {
|
|
|
11197
11286
|
const normalizedPath = uncachedPaths[i];
|
|
11198
11287
|
const serverResult = serverResultsMap.get(normalizedPath);
|
|
11199
11288
|
if (serverResult) {
|
|
11200
|
-
|
|
11201
|
-
|
|
11289
|
+
// getMany batches single-doc paths — attach the bare `id` (leaf doc
|
|
11290
|
+
// key) to each returned doc, additive (Bug 1), matching get().
|
|
11291
|
+
const normalizedResult = serverResult.error
|
|
11292
|
+
? serverResult
|
|
11293
|
+
: Object.assign(Object.assign({}, serverResult), { data: withBareId(serverResult.data) });
|
|
11294
|
+
results[originalIndex] = normalizedResult;
|
|
11295
|
+
if (!normalizedResult.error && !opts.bypassCache) {
|
|
11202
11296
|
const cacheKey = `${principalKey}|${normalizedPath}:`;
|
|
11203
11297
|
getCache[cacheKey] = {
|
|
11204
|
-
data:
|
|
11298
|
+
data: normalizedResult.data,
|
|
11205
11299
|
expiresAt: now + GET_CACHE_TTL
|
|
11206
11300
|
};
|
|
11207
11301
|
}
|
|
@@ -11746,6 +11840,7 @@ var operations = /*#__PURE__*/Object.freeze({
|
|
|
11746
11840
|
aggregate: aggregate,
|
|
11747
11841
|
clearReadCacheForAuthChange: clearReadCacheForAuthChange,
|
|
11748
11842
|
count: count,
|
|
11843
|
+
docId: docId,
|
|
11749
11844
|
get: get,
|
|
11750
11845
|
getFiles: getFiles,
|
|
11751
11846
|
getMany: getMany,
|
|
@@ -12333,14 +12428,46 @@ function handleServerMessage(connection, message) {
|
|
|
12333
12428
|
}
|
|
12334
12429
|
}
|
|
12335
12430
|
}
|
|
12431
|
+
/**
|
|
12432
|
+
* Additively attach the bare `id` (leaf doc key) to a subscription row (Bug 1).
|
|
12433
|
+
* Rows carry `_id`/`pathId` = the full document path; this leaves those as-is and
|
|
12434
|
+
* adds `id` = the last path segment so `row.id` is the doc key apps expect. No-ops
|
|
12435
|
+
* for non-objects and rows that already define `id`.
|
|
12436
|
+
*/
|
|
12437
|
+
function withSubscriptionId(row) {
|
|
12438
|
+
var _a, _b, _c;
|
|
12439
|
+
if (!row || typeof row !== 'object' || Array.isArray(row))
|
|
12440
|
+
return row;
|
|
12441
|
+
if ('id' in row)
|
|
12442
|
+
return row;
|
|
12443
|
+
const source = (_c = (_b = (_a = row._id) !== null && _a !== void 0 ? _a : row.pathId) !== null && _b !== void 0 ? _b : row.relativePath) !== null && _c !== void 0 ? _c : row.absolutePath;
|
|
12444
|
+
if (typeof source !== 'string' || source.length === 0)
|
|
12445
|
+
return row;
|
|
12446
|
+
const leaf = docId(source);
|
|
12447
|
+
if (!leaf)
|
|
12448
|
+
return row;
|
|
12449
|
+
return Object.assign(Object.assign({}, row), { id: leaf });
|
|
12450
|
+
}
|
|
12451
|
+
/**
|
|
12452
|
+
* The `onData` payload follows the path: a collection delivers a bare array of
|
|
12453
|
+
* rows, a single-doc path delivers the document (or null). Attach the bare `id`
|
|
12454
|
+
* to each returned row in either case, additive (Bug 1).
|
|
12455
|
+
*/
|
|
12456
|
+
function addIdsToSubscriptionData(data) {
|
|
12457
|
+
if (Array.isArray(data))
|
|
12458
|
+
return data.map(withSubscriptionId);
|
|
12459
|
+
return withSubscriptionId(data);
|
|
12460
|
+
}
|
|
12336
12461
|
function notifyCallbacks(subscription, data) {
|
|
12337
12462
|
var _a;
|
|
12463
|
+
// Attach the bare `id` (leaf doc key) to every delivered row (Bug 1).
|
|
12464
|
+
const decorated = addIdsToSubscriptionData(data);
|
|
12338
12465
|
// Snapshot the callbacks array so that unsubscriptions during
|
|
12339
12466
|
// notification don't cause callbacks to be skipped.
|
|
12340
12467
|
const callbacks = subscription.callbacks.slice();
|
|
12341
12468
|
for (const callback of callbacks) {
|
|
12342
12469
|
try {
|
|
12343
|
-
(_a = callback.onData) === null || _a === void 0 ? void 0 : _a.call(callback,
|
|
12470
|
+
(_a = callback.onData) === null || _a === void 0 ? void 0 : _a.call(callback, decorated);
|
|
12344
12471
|
}
|
|
12345
12472
|
catch (error) {
|
|
12346
12473
|
console.error('[WS v2] Error in subscription callback:', error);
|
|
@@ -12431,7 +12558,7 @@ async function subscribeV2(path, subscriptionOptions, roomRoutePath) {
|
|
|
12431
12558
|
if (cachedEntry && Date.now() - cachedEntry.timestamp < CACHE_TTL && subscriptionOptions.onData) {
|
|
12432
12559
|
setTimeout(() => {
|
|
12433
12560
|
var _a;
|
|
12434
|
-
(_a = subscriptionOptions.onData) === null || _a === void 0 ? void 0 : _a.call(subscriptionOptions, cachedEntry.data);
|
|
12561
|
+
(_a = subscriptionOptions.onData) === null || _a === void 0 ? void 0 : _a.call(subscriptionOptions, addIdsToSubscriptionData(cachedEntry.data));
|
|
12435
12562
|
}, 0);
|
|
12436
12563
|
}
|
|
12437
12564
|
// Get or create connection for this routing target (room-scoped when a
|
|
@@ -12461,7 +12588,7 @@ async function subscribeV2(path, subscriptionOptions, roomRoutePath) {
|
|
|
12461
12588
|
if (existingSubscription.lastData !== undefined && subscriptionOptions.onData) {
|
|
12462
12589
|
setTimeout(() => {
|
|
12463
12590
|
var _a;
|
|
12464
|
-
(_a = subscriptionOptions.onData) === null || _a === void 0 ? void 0 : _a.call(subscriptionOptions, existingSubscription.lastData);
|
|
12591
|
+
(_a = subscriptionOptions.onData) === null || _a === void 0 ? void 0 : _a.call(subscriptionOptions, addIdsToSubscriptionData(existingSubscription.lastData));
|
|
12465
12592
|
}, 0);
|
|
12466
12593
|
}
|
|
12467
12594
|
return async () => {
|
|
@@ -17818,6 +17945,2411 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
17818
17945
|
default: bs582
|
|
17819
17946
|
});
|
|
17820
17947
|
|
|
17948
|
+
var naclFast = {exports: {}};
|
|
17949
|
+
|
|
17950
|
+
var hasRequiredNaclFast;
|
|
17951
|
+
|
|
17952
|
+
function requireNaclFast () {
|
|
17953
|
+
if (hasRequiredNaclFast) return naclFast.exports;
|
|
17954
|
+
hasRequiredNaclFast = 1;
|
|
17955
|
+
(function (module) {
|
|
17956
|
+
(function(nacl) {
|
|
17957
|
+
|
|
17958
|
+
// Ported in 2014 by Dmitry Chestnykh and Devi Mandiri.
|
|
17959
|
+
// Public domain.
|
|
17960
|
+
//
|
|
17961
|
+
// Implementation derived from TweetNaCl version 20140427.
|
|
17962
|
+
// See for details: http://tweetnacl.cr.yp.to/
|
|
17963
|
+
|
|
17964
|
+
var gf = function(init) {
|
|
17965
|
+
var i, r = new Float64Array(16);
|
|
17966
|
+
if (init) for (i = 0; i < init.length; i++) r[i] = init[i];
|
|
17967
|
+
return r;
|
|
17968
|
+
};
|
|
17969
|
+
|
|
17970
|
+
// Pluggable, initialized in high-level API below.
|
|
17971
|
+
var randombytes = function(/* x, n */) { throw new Error('no PRNG'); };
|
|
17972
|
+
|
|
17973
|
+
var _0 = new Uint8Array(16);
|
|
17974
|
+
var _9 = new Uint8Array(32); _9[0] = 9;
|
|
17975
|
+
|
|
17976
|
+
var gf0 = gf(),
|
|
17977
|
+
gf1 = gf([1]),
|
|
17978
|
+
_121665 = gf([0xdb41, 1]),
|
|
17979
|
+
D = gf([0x78a3, 0x1359, 0x4dca, 0x75eb, 0xd8ab, 0x4141, 0x0a4d, 0x0070, 0xe898, 0x7779, 0x4079, 0x8cc7, 0xfe73, 0x2b6f, 0x6cee, 0x5203]),
|
|
17980
|
+
D2 = gf([0xf159, 0x26b2, 0x9b94, 0xebd6, 0xb156, 0x8283, 0x149a, 0x00e0, 0xd130, 0xeef3, 0x80f2, 0x198e, 0xfce7, 0x56df, 0xd9dc, 0x2406]),
|
|
17981
|
+
X = gf([0xd51a, 0x8f25, 0x2d60, 0xc956, 0xa7b2, 0x9525, 0xc760, 0x692c, 0xdc5c, 0xfdd6, 0xe231, 0xc0a4, 0x53fe, 0xcd6e, 0x36d3, 0x2169]),
|
|
17982
|
+
Y = gf([0x6658, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666]),
|
|
17983
|
+
I = gf([0xa0b0, 0x4a0e, 0x1b27, 0xc4ee, 0xe478, 0xad2f, 0x1806, 0x2f43, 0xd7a7, 0x3dfb, 0x0099, 0x2b4d, 0xdf0b, 0x4fc1, 0x2480, 0x2b83]);
|
|
17984
|
+
|
|
17985
|
+
function ts64(x, i, h, l) {
|
|
17986
|
+
x[i] = (h >> 24) & 0xff;
|
|
17987
|
+
x[i+1] = (h >> 16) & 0xff;
|
|
17988
|
+
x[i+2] = (h >> 8) & 0xff;
|
|
17989
|
+
x[i+3] = h & 0xff;
|
|
17990
|
+
x[i+4] = (l >> 24) & 0xff;
|
|
17991
|
+
x[i+5] = (l >> 16) & 0xff;
|
|
17992
|
+
x[i+6] = (l >> 8) & 0xff;
|
|
17993
|
+
x[i+7] = l & 0xff;
|
|
17994
|
+
}
|
|
17995
|
+
|
|
17996
|
+
function vn(x, xi, y, yi, n) {
|
|
17997
|
+
var i,d = 0;
|
|
17998
|
+
for (i = 0; i < n; i++) d |= x[xi+i]^y[yi+i];
|
|
17999
|
+
return (1 & ((d - 1) >>> 8)) - 1;
|
|
18000
|
+
}
|
|
18001
|
+
|
|
18002
|
+
function crypto_verify_16(x, xi, y, yi) {
|
|
18003
|
+
return vn(x,xi,y,yi,16);
|
|
18004
|
+
}
|
|
18005
|
+
|
|
18006
|
+
function crypto_verify_32(x, xi, y, yi) {
|
|
18007
|
+
return vn(x,xi,y,yi,32);
|
|
18008
|
+
}
|
|
18009
|
+
|
|
18010
|
+
function core_salsa20(o, p, k, c) {
|
|
18011
|
+
var j0 = c[ 0] & 0xff | (c[ 1] & 0xff)<<8 | (c[ 2] & 0xff)<<16 | (c[ 3] & 0xff)<<24,
|
|
18012
|
+
j1 = k[ 0] & 0xff | (k[ 1] & 0xff)<<8 | (k[ 2] & 0xff)<<16 | (k[ 3] & 0xff)<<24,
|
|
18013
|
+
j2 = k[ 4] & 0xff | (k[ 5] & 0xff)<<8 | (k[ 6] & 0xff)<<16 | (k[ 7] & 0xff)<<24,
|
|
18014
|
+
j3 = k[ 8] & 0xff | (k[ 9] & 0xff)<<8 | (k[10] & 0xff)<<16 | (k[11] & 0xff)<<24,
|
|
18015
|
+
j4 = k[12] & 0xff | (k[13] & 0xff)<<8 | (k[14] & 0xff)<<16 | (k[15] & 0xff)<<24,
|
|
18016
|
+
j5 = c[ 4] & 0xff | (c[ 5] & 0xff)<<8 | (c[ 6] & 0xff)<<16 | (c[ 7] & 0xff)<<24,
|
|
18017
|
+
j6 = p[ 0] & 0xff | (p[ 1] & 0xff)<<8 | (p[ 2] & 0xff)<<16 | (p[ 3] & 0xff)<<24,
|
|
18018
|
+
j7 = p[ 4] & 0xff | (p[ 5] & 0xff)<<8 | (p[ 6] & 0xff)<<16 | (p[ 7] & 0xff)<<24,
|
|
18019
|
+
j8 = p[ 8] & 0xff | (p[ 9] & 0xff)<<8 | (p[10] & 0xff)<<16 | (p[11] & 0xff)<<24,
|
|
18020
|
+
j9 = p[12] & 0xff | (p[13] & 0xff)<<8 | (p[14] & 0xff)<<16 | (p[15] & 0xff)<<24,
|
|
18021
|
+
j10 = c[ 8] & 0xff | (c[ 9] & 0xff)<<8 | (c[10] & 0xff)<<16 | (c[11] & 0xff)<<24,
|
|
18022
|
+
j11 = k[16] & 0xff | (k[17] & 0xff)<<8 | (k[18] & 0xff)<<16 | (k[19] & 0xff)<<24,
|
|
18023
|
+
j12 = k[20] & 0xff | (k[21] & 0xff)<<8 | (k[22] & 0xff)<<16 | (k[23] & 0xff)<<24,
|
|
18024
|
+
j13 = k[24] & 0xff | (k[25] & 0xff)<<8 | (k[26] & 0xff)<<16 | (k[27] & 0xff)<<24,
|
|
18025
|
+
j14 = k[28] & 0xff | (k[29] & 0xff)<<8 | (k[30] & 0xff)<<16 | (k[31] & 0xff)<<24,
|
|
18026
|
+
j15 = c[12] & 0xff | (c[13] & 0xff)<<8 | (c[14] & 0xff)<<16 | (c[15] & 0xff)<<24;
|
|
18027
|
+
|
|
18028
|
+
var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7,
|
|
18029
|
+
x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14,
|
|
18030
|
+
x15 = j15, u;
|
|
18031
|
+
|
|
18032
|
+
for (var i = 0; i < 20; i += 2) {
|
|
18033
|
+
u = x0 + x12 | 0;
|
|
18034
|
+
x4 ^= u<<7 | u>>>(32-7);
|
|
18035
|
+
u = x4 + x0 | 0;
|
|
18036
|
+
x8 ^= u<<9 | u>>>(32-9);
|
|
18037
|
+
u = x8 + x4 | 0;
|
|
18038
|
+
x12 ^= u<<13 | u>>>(32-13);
|
|
18039
|
+
u = x12 + x8 | 0;
|
|
18040
|
+
x0 ^= u<<18 | u>>>(32-18);
|
|
18041
|
+
|
|
18042
|
+
u = x5 + x1 | 0;
|
|
18043
|
+
x9 ^= u<<7 | u>>>(32-7);
|
|
18044
|
+
u = x9 + x5 | 0;
|
|
18045
|
+
x13 ^= u<<9 | u>>>(32-9);
|
|
18046
|
+
u = x13 + x9 | 0;
|
|
18047
|
+
x1 ^= u<<13 | u>>>(32-13);
|
|
18048
|
+
u = x1 + x13 | 0;
|
|
18049
|
+
x5 ^= u<<18 | u>>>(32-18);
|
|
18050
|
+
|
|
18051
|
+
u = x10 + x6 | 0;
|
|
18052
|
+
x14 ^= u<<7 | u>>>(32-7);
|
|
18053
|
+
u = x14 + x10 | 0;
|
|
18054
|
+
x2 ^= u<<9 | u>>>(32-9);
|
|
18055
|
+
u = x2 + x14 | 0;
|
|
18056
|
+
x6 ^= u<<13 | u>>>(32-13);
|
|
18057
|
+
u = x6 + x2 | 0;
|
|
18058
|
+
x10 ^= u<<18 | u>>>(32-18);
|
|
18059
|
+
|
|
18060
|
+
u = x15 + x11 | 0;
|
|
18061
|
+
x3 ^= u<<7 | u>>>(32-7);
|
|
18062
|
+
u = x3 + x15 | 0;
|
|
18063
|
+
x7 ^= u<<9 | u>>>(32-9);
|
|
18064
|
+
u = x7 + x3 | 0;
|
|
18065
|
+
x11 ^= u<<13 | u>>>(32-13);
|
|
18066
|
+
u = x11 + x7 | 0;
|
|
18067
|
+
x15 ^= u<<18 | u>>>(32-18);
|
|
18068
|
+
|
|
18069
|
+
u = x0 + x3 | 0;
|
|
18070
|
+
x1 ^= u<<7 | u>>>(32-7);
|
|
18071
|
+
u = x1 + x0 | 0;
|
|
18072
|
+
x2 ^= u<<9 | u>>>(32-9);
|
|
18073
|
+
u = x2 + x1 | 0;
|
|
18074
|
+
x3 ^= u<<13 | u>>>(32-13);
|
|
18075
|
+
u = x3 + x2 | 0;
|
|
18076
|
+
x0 ^= u<<18 | u>>>(32-18);
|
|
18077
|
+
|
|
18078
|
+
u = x5 + x4 | 0;
|
|
18079
|
+
x6 ^= u<<7 | u>>>(32-7);
|
|
18080
|
+
u = x6 + x5 | 0;
|
|
18081
|
+
x7 ^= u<<9 | u>>>(32-9);
|
|
18082
|
+
u = x7 + x6 | 0;
|
|
18083
|
+
x4 ^= u<<13 | u>>>(32-13);
|
|
18084
|
+
u = x4 + x7 | 0;
|
|
18085
|
+
x5 ^= u<<18 | u>>>(32-18);
|
|
18086
|
+
|
|
18087
|
+
u = x10 + x9 | 0;
|
|
18088
|
+
x11 ^= u<<7 | u>>>(32-7);
|
|
18089
|
+
u = x11 + x10 | 0;
|
|
18090
|
+
x8 ^= u<<9 | u>>>(32-9);
|
|
18091
|
+
u = x8 + x11 | 0;
|
|
18092
|
+
x9 ^= u<<13 | u>>>(32-13);
|
|
18093
|
+
u = x9 + x8 | 0;
|
|
18094
|
+
x10 ^= u<<18 | u>>>(32-18);
|
|
18095
|
+
|
|
18096
|
+
u = x15 + x14 | 0;
|
|
18097
|
+
x12 ^= u<<7 | u>>>(32-7);
|
|
18098
|
+
u = x12 + x15 | 0;
|
|
18099
|
+
x13 ^= u<<9 | u>>>(32-9);
|
|
18100
|
+
u = x13 + x12 | 0;
|
|
18101
|
+
x14 ^= u<<13 | u>>>(32-13);
|
|
18102
|
+
u = x14 + x13 | 0;
|
|
18103
|
+
x15 ^= u<<18 | u>>>(32-18);
|
|
18104
|
+
}
|
|
18105
|
+
x0 = x0 + j0 | 0;
|
|
18106
|
+
x1 = x1 + j1 | 0;
|
|
18107
|
+
x2 = x2 + j2 | 0;
|
|
18108
|
+
x3 = x3 + j3 | 0;
|
|
18109
|
+
x4 = x4 + j4 | 0;
|
|
18110
|
+
x5 = x5 + j5 | 0;
|
|
18111
|
+
x6 = x6 + j6 | 0;
|
|
18112
|
+
x7 = x7 + j7 | 0;
|
|
18113
|
+
x8 = x8 + j8 | 0;
|
|
18114
|
+
x9 = x9 + j9 | 0;
|
|
18115
|
+
x10 = x10 + j10 | 0;
|
|
18116
|
+
x11 = x11 + j11 | 0;
|
|
18117
|
+
x12 = x12 + j12 | 0;
|
|
18118
|
+
x13 = x13 + j13 | 0;
|
|
18119
|
+
x14 = x14 + j14 | 0;
|
|
18120
|
+
x15 = x15 + j15 | 0;
|
|
18121
|
+
|
|
18122
|
+
o[ 0] = x0 >>> 0 & 0xff;
|
|
18123
|
+
o[ 1] = x0 >>> 8 & 0xff;
|
|
18124
|
+
o[ 2] = x0 >>> 16 & 0xff;
|
|
18125
|
+
o[ 3] = x0 >>> 24 & 0xff;
|
|
18126
|
+
|
|
18127
|
+
o[ 4] = x1 >>> 0 & 0xff;
|
|
18128
|
+
o[ 5] = x1 >>> 8 & 0xff;
|
|
18129
|
+
o[ 6] = x1 >>> 16 & 0xff;
|
|
18130
|
+
o[ 7] = x1 >>> 24 & 0xff;
|
|
18131
|
+
|
|
18132
|
+
o[ 8] = x2 >>> 0 & 0xff;
|
|
18133
|
+
o[ 9] = x2 >>> 8 & 0xff;
|
|
18134
|
+
o[10] = x2 >>> 16 & 0xff;
|
|
18135
|
+
o[11] = x2 >>> 24 & 0xff;
|
|
18136
|
+
|
|
18137
|
+
o[12] = x3 >>> 0 & 0xff;
|
|
18138
|
+
o[13] = x3 >>> 8 & 0xff;
|
|
18139
|
+
o[14] = x3 >>> 16 & 0xff;
|
|
18140
|
+
o[15] = x3 >>> 24 & 0xff;
|
|
18141
|
+
|
|
18142
|
+
o[16] = x4 >>> 0 & 0xff;
|
|
18143
|
+
o[17] = x4 >>> 8 & 0xff;
|
|
18144
|
+
o[18] = x4 >>> 16 & 0xff;
|
|
18145
|
+
o[19] = x4 >>> 24 & 0xff;
|
|
18146
|
+
|
|
18147
|
+
o[20] = x5 >>> 0 & 0xff;
|
|
18148
|
+
o[21] = x5 >>> 8 & 0xff;
|
|
18149
|
+
o[22] = x5 >>> 16 & 0xff;
|
|
18150
|
+
o[23] = x5 >>> 24 & 0xff;
|
|
18151
|
+
|
|
18152
|
+
o[24] = x6 >>> 0 & 0xff;
|
|
18153
|
+
o[25] = x6 >>> 8 & 0xff;
|
|
18154
|
+
o[26] = x6 >>> 16 & 0xff;
|
|
18155
|
+
o[27] = x6 >>> 24 & 0xff;
|
|
18156
|
+
|
|
18157
|
+
o[28] = x7 >>> 0 & 0xff;
|
|
18158
|
+
o[29] = x7 >>> 8 & 0xff;
|
|
18159
|
+
o[30] = x7 >>> 16 & 0xff;
|
|
18160
|
+
o[31] = x7 >>> 24 & 0xff;
|
|
18161
|
+
|
|
18162
|
+
o[32] = x8 >>> 0 & 0xff;
|
|
18163
|
+
o[33] = x8 >>> 8 & 0xff;
|
|
18164
|
+
o[34] = x8 >>> 16 & 0xff;
|
|
18165
|
+
o[35] = x8 >>> 24 & 0xff;
|
|
18166
|
+
|
|
18167
|
+
o[36] = x9 >>> 0 & 0xff;
|
|
18168
|
+
o[37] = x9 >>> 8 & 0xff;
|
|
18169
|
+
o[38] = x9 >>> 16 & 0xff;
|
|
18170
|
+
o[39] = x9 >>> 24 & 0xff;
|
|
18171
|
+
|
|
18172
|
+
o[40] = x10 >>> 0 & 0xff;
|
|
18173
|
+
o[41] = x10 >>> 8 & 0xff;
|
|
18174
|
+
o[42] = x10 >>> 16 & 0xff;
|
|
18175
|
+
o[43] = x10 >>> 24 & 0xff;
|
|
18176
|
+
|
|
18177
|
+
o[44] = x11 >>> 0 & 0xff;
|
|
18178
|
+
o[45] = x11 >>> 8 & 0xff;
|
|
18179
|
+
o[46] = x11 >>> 16 & 0xff;
|
|
18180
|
+
o[47] = x11 >>> 24 & 0xff;
|
|
18181
|
+
|
|
18182
|
+
o[48] = x12 >>> 0 & 0xff;
|
|
18183
|
+
o[49] = x12 >>> 8 & 0xff;
|
|
18184
|
+
o[50] = x12 >>> 16 & 0xff;
|
|
18185
|
+
o[51] = x12 >>> 24 & 0xff;
|
|
18186
|
+
|
|
18187
|
+
o[52] = x13 >>> 0 & 0xff;
|
|
18188
|
+
o[53] = x13 >>> 8 & 0xff;
|
|
18189
|
+
o[54] = x13 >>> 16 & 0xff;
|
|
18190
|
+
o[55] = x13 >>> 24 & 0xff;
|
|
18191
|
+
|
|
18192
|
+
o[56] = x14 >>> 0 & 0xff;
|
|
18193
|
+
o[57] = x14 >>> 8 & 0xff;
|
|
18194
|
+
o[58] = x14 >>> 16 & 0xff;
|
|
18195
|
+
o[59] = x14 >>> 24 & 0xff;
|
|
18196
|
+
|
|
18197
|
+
o[60] = x15 >>> 0 & 0xff;
|
|
18198
|
+
o[61] = x15 >>> 8 & 0xff;
|
|
18199
|
+
o[62] = x15 >>> 16 & 0xff;
|
|
18200
|
+
o[63] = x15 >>> 24 & 0xff;
|
|
18201
|
+
}
|
|
18202
|
+
|
|
18203
|
+
function core_hsalsa20(o,p,k,c) {
|
|
18204
|
+
var j0 = c[ 0] & 0xff | (c[ 1] & 0xff)<<8 | (c[ 2] & 0xff)<<16 | (c[ 3] & 0xff)<<24,
|
|
18205
|
+
j1 = k[ 0] & 0xff | (k[ 1] & 0xff)<<8 | (k[ 2] & 0xff)<<16 | (k[ 3] & 0xff)<<24,
|
|
18206
|
+
j2 = k[ 4] & 0xff | (k[ 5] & 0xff)<<8 | (k[ 6] & 0xff)<<16 | (k[ 7] & 0xff)<<24,
|
|
18207
|
+
j3 = k[ 8] & 0xff | (k[ 9] & 0xff)<<8 | (k[10] & 0xff)<<16 | (k[11] & 0xff)<<24,
|
|
18208
|
+
j4 = k[12] & 0xff | (k[13] & 0xff)<<8 | (k[14] & 0xff)<<16 | (k[15] & 0xff)<<24,
|
|
18209
|
+
j5 = c[ 4] & 0xff | (c[ 5] & 0xff)<<8 | (c[ 6] & 0xff)<<16 | (c[ 7] & 0xff)<<24,
|
|
18210
|
+
j6 = p[ 0] & 0xff | (p[ 1] & 0xff)<<8 | (p[ 2] & 0xff)<<16 | (p[ 3] & 0xff)<<24,
|
|
18211
|
+
j7 = p[ 4] & 0xff | (p[ 5] & 0xff)<<8 | (p[ 6] & 0xff)<<16 | (p[ 7] & 0xff)<<24,
|
|
18212
|
+
j8 = p[ 8] & 0xff | (p[ 9] & 0xff)<<8 | (p[10] & 0xff)<<16 | (p[11] & 0xff)<<24,
|
|
18213
|
+
j9 = p[12] & 0xff | (p[13] & 0xff)<<8 | (p[14] & 0xff)<<16 | (p[15] & 0xff)<<24,
|
|
18214
|
+
j10 = c[ 8] & 0xff | (c[ 9] & 0xff)<<8 | (c[10] & 0xff)<<16 | (c[11] & 0xff)<<24,
|
|
18215
|
+
j11 = k[16] & 0xff | (k[17] & 0xff)<<8 | (k[18] & 0xff)<<16 | (k[19] & 0xff)<<24,
|
|
18216
|
+
j12 = k[20] & 0xff | (k[21] & 0xff)<<8 | (k[22] & 0xff)<<16 | (k[23] & 0xff)<<24,
|
|
18217
|
+
j13 = k[24] & 0xff | (k[25] & 0xff)<<8 | (k[26] & 0xff)<<16 | (k[27] & 0xff)<<24,
|
|
18218
|
+
j14 = k[28] & 0xff | (k[29] & 0xff)<<8 | (k[30] & 0xff)<<16 | (k[31] & 0xff)<<24,
|
|
18219
|
+
j15 = c[12] & 0xff | (c[13] & 0xff)<<8 | (c[14] & 0xff)<<16 | (c[15] & 0xff)<<24;
|
|
18220
|
+
|
|
18221
|
+
var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7,
|
|
18222
|
+
x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14,
|
|
18223
|
+
x15 = j15, u;
|
|
18224
|
+
|
|
18225
|
+
for (var i = 0; i < 20; i += 2) {
|
|
18226
|
+
u = x0 + x12 | 0;
|
|
18227
|
+
x4 ^= u<<7 | u>>>(32-7);
|
|
18228
|
+
u = x4 + x0 | 0;
|
|
18229
|
+
x8 ^= u<<9 | u>>>(32-9);
|
|
18230
|
+
u = x8 + x4 | 0;
|
|
18231
|
+
x12 ^= u<<13 | u>>>(32-13);
|
|
18232
|
+
u = x12 + x8 | 0;
|
|
18233
|
+
x0 ^= u<<18 | u>>>(32-18);
|
|
18234
|
+
|
|
18235
|
+
u = x5 + x1 | 0;
|
|
18236
|
+
x9 ^= u<<7 | u>>>(32-7);
|
|
18237
|
+
u = x9 + x5 | 0;
|
|
18238
|
+
x13 ^= u<<9 | u>>>(32-9);
|
|
18239
|
+
u = x13 + x9 | 0;
|
|
18240
|
+
x1 ^= u<<13 | u>>>(32-13);
|
|
18241
|
+
u = x1 + x13 | 0;
|
|
18242
|
+
x5 ^= u<<18 | u>>>(32-18);
|
|
18243
|
+
|
|
18244
|
+
u = x10 + x6 | 0;
|
|
18245
|
+
x14 ^= u<<7 | u>>>(32-7);
|
|
18246
|
+
u = x14 + x10 | 0;
|
|
18247
|
+
x2 ^= u<<9 | u>>>(32-9);
|
|
18248
|
+
u = x2 + x14 | 0;
|
|
18249
|
+
x6 ^= u<<13 | u>>>(32-13);
|
|
18250
|
+
u = x6 + x2 | 0;
|
|
18251
|
+
x10 ^= u<<18 | u>>>(32-18);
|
|
18252
|
+
|
|
18253
|
+
u = x15 + x11 | 0;
|
|
18254
|
+
x3 ^= u<<7 | u>>>(32-7);
|
|
18255
|
+
u = x3 + x15 | 0;
|
|
18256
|
+
x7 ^= u<<9 | u>>>(32-9);
|
|
18257
|
+
u = x7 + x3 | 0;
|
|
18258
|
+
x11 ^= u<<13 | u>>>(32-13);
|
|
18259
|
+
u = x11 + x7 | 0;
|
|
18260
|
+
x15 ^= u<<18 | u>>>(32-18);
|
|
18261
|
+
|
|
18262
|
+
u = x0 + x3 | 0;
|
|
18263
|
+
x1 ^= u<<7 | u>>>(32-7);
|
|
18264
|
+
u = x1 + x0 | 0;
|
|
18265
|
+
x2 ^= u<<9 | u>>>(32-9);
|
|
18266
|
+
u = x2 + x1 | 0;
|
|
18267
|
+
x3 ^= u<<13 | u>>>(32-13);
|
|
18268
|
+
u = x3 + x2 | 0;
|
|
18269
|
+
x0 ^= u<<18 | u>>>(32-18);
|
|
18270
|
+
|
|
18271
|
+
u = x5 + x4 | 0;
|
|
18272
|
+
x6 ^= u<<7 | u>>>(32-7);
|
|
18273
|
+
u = x6 + x5 | 0;
|
|
18274
|
+
x7 ^= u<<9 | u>>>(32-9);
|
|
18275
|
+
u = x7 + x6 | 0;
|
|
18276
|
+
x4 ^= u<<13 | u>>>(32-13);
|
|
18277
|
+
u = x4 + x7 | 0;
|
|
18278
|
+
x5 ^= u<<18 | u>>>(32-18);
|
|
18279
|
+
|
|
18280
|
+
u = x10 + x9 | 0;
|
|
18281
|
+
x11 ^= u<<7 | u>>>(32-7);
|
|
18282
|
+
u = x11 + x10 | 0;
|
|
18283
|
+
x8 ^= u<<9 | u>>>(32-9);
|
|
18284
|
+
u = x8 + x11 | 0;
|
|
18285
|
+
x9 ^= u<<13 | u>>>(32-13);
|
|
18286
|
+
u = x9 + x8 | 0;
|
|
18287
|
+
x10 ^= u<<18 | u>>>(32-18);
|
|
18288
|
+
|
|
18289
|
+
u = x15 + x14 | 0;
|
|
18290
|
+
x12 ^= u<<7 | u>>>(32-7);
|
|
18291
|
+
u = x12 + x15 | 0;
|
|
18292
|
+
x13 ^= u<<9 | u>>>(32-9);
|
|
18293
|
+
u = x13 + x12 | 0;
|
|
18294
|
+
x14 ^= u<<13 | u>>>(32-13);
|
|
18295
|
+
u = x14 + x13 | 0;
|
|
18296
|
+
x15 ^= u<<18 | u>>>(32-18);
|
|
18297
|
+
}
|
|
18298
|
+
|
|
18299
|
+
o[ 0] = x0 >>> 0 & 0xff;
|
|
18300
|
+
o[ 1] = x0 >>> 8 & 0xff;
|
|
18301
|
+
o[ 2] = x0 >>> 16 & 0xff;
|
|
18302
|
+
o[ 3] = x0 >>> 24 & 0xff;
|
|
18303
|
+
|
|
18304
|
+
o[ 4] = x5 >>> 0 & 0xff;
|
|
18305
|
+
o[ 5] = x5 >>> 8 & 0xff;
|
|
18306
|
+
o[ 6] = x5 >>> 16 & 0xff;
|
|
18307
|
+
o[ 7] = x5 >>> 24 & 0xff;
|
|
18308
|
+
|
|
18309
|
+
o[ 8] = x10 >>> 0 & 0xff;
|
|
18310
|
+
o[ 9] = x10 >>> 8 & 0xff;
|
|
18311
|
+
o[10] = x10 >>> 16 & 0xff;
|
|
18312
|
+
o[11] = x10 >>> 24 & 0xff;
|
|
18313
|
+
|
|
18314
|
+
o[12] = x15 >>> 0 & 0xff;
|
|
18315
|
+
o[13] = x15 >>> 8 & 0xff;
|
|
18316
|
+
o[14] = x15 >>> 16 & 0xff;
|
|
18317
|
+
o[15] = x15 >>> 24 & 0xff;
|
|
18318
|
+
|
|
18319
|
+
o[16] = x6 >>> 0 & 0xff;
|
|
18320
|
+
o[17] = x6 >>> 8 & 0xff;
|
|
18321
|
+
o[18] = x6 >>> 16 & 0xff;
|
|
18322
|
+
o[19] = x6 >>> 24 & 0xff;
|
|
18323
|
+
|
|
18324
|
+
o[20] = x7 >>> 0 & 0xff;
|
|
18325
|
+
o[21] = x7 >>> 8 & 0xff;
|
|
18326
|
+
o[22] = x7 >>> 16 & 0xff;
|
|
18327
|
+
o[23] = x7 >>> 24 & 0xff;
|
|
18328
|
+
|
|
18329
|
+
o[24] = x8 >>> 0 & 0xff;
|
|
18330
|
+
o[25] = x8 >>> 8 & 0xff;
|
|
18331
|
+
o[26] = x8 >>> 16 & 0xff;
|
|
18332
|
+
o[27] = x8 >>> 24 & 0xff;
|
|
18333
|
+
|
|
18334
|
+
o[28] = x9 >>> 0 & 0xff;
|
|
18335
|
+
o[29] = x9 >>> 8 & 0xff;
|
|
18336
|
+
o[30] = x9 >>> 16 & 0xff;
|
|
18337
|
+
o[31] = x9 >>> 24 & 0xff;
|
|
18338
|
+
}
|
|
18339
|
+
|
|
18340
|
+
function crypto_core_salsa20(out,inp,k,c) {
|
|
18341
|
+
core_salsa20(out,inp,k,c);
|
|
18342
|
+
}
|
|
18343
|
+
|
|
18344
|
+
function crypto_core_hsalsa20(out,inp,k,c) {
|
|
18345
|
+
core_hsalsa20(out,inp,k,c);
|
|
18346
|
+
}
|
|
18347
|
+
|
|
18348
|
+
var sigma = new Uint8Array([101, 120, 112, 97, 110, 100, 32, 51, 50, 45, 98, 121, 116, 101, 32, 107]);
|
|
18349
|
+
// "expand 32-byte k"
|
|
18350
|
+
|
|
18351
|
+
function crypto_stream_salsa20_xor(c,cpos,m,mpos,b,n,k) {
|
|
18352
|
+
var z = new Uint8Array(16), x = new Uint8Array(64);
|
|
18353
|
+
var u, i;
|
|
18354
|
+
for (i = 0; i < 16; i++) z[i] = 0;
|
|
18355
|
+
for (i = 0; i < 8; i++) z[i] = n[i];
|
|
18356
|
+
while (b >= 64) {
|
|
18357
|
+
crypto_core_salsa20(x,z,k,sigma);
|
|
18358
|
+
for (i = 0; i < 64; i++) c[cpos+i] = m[mpos+i] ^ x[i];
|
|
18359
|
+
u = 1;
|
|
18360
|
+
for (i = 8; i < 16; i++) {
|
|
18361
|
+
u = u + (z[i] & 0xff) | 0;
|
|
18362
|
+
z[i] = u & 0xff;
|
|
18363
|
+
u >>>= 8;
|
|
18364
|
+
}
|
|
18365
|
+
b -= 64;
|
|
18366
|
+
cpos += 64;
|
|
18367
|
+
mpos += 64;
|
|
18368
|
+
}
|
|
18369
|
+
if (b > 0) {
|
|
18370
|
+
crypto_core_salsa20(x,z,k,sigma);
|
|
18371
|
+
for (i = 0; i < b; i++) c[cpos+i] = m[mpos+i] ^ x[i];
|
|
18372
|
+
}
|
|
18373
|
+
return 0;
|
|
18374
|
+
}
|
|
18375
|
+
|
|
18376
|
+
function crypto_stream_salsa20(c,cpos,b,n,k) {
|
|
18377
|
+
var z = new Uint8Array(16), x = new Uint8Array(64);
|
|
18378
|
+
var u, i;
|
|
18379
|
+
for (i = 0; i < 16; i++) z[i] = 0;
|
|
18380
|
+
for (i = 0; i < 8; i++) z[i] = n[i];
|
|
18381
|
+
while (b >= 64) {
|
|
18382
|
+
crypto_core_salsa20(x,z,k,sigma);
|
|
18383
|
+
for (i = 0; i < 64; i++) c[cpos+i] = x[i];
|
|
18384
|
+
u = 1;
|
|
18385
|
+
for (i = 8; i < 16; i++) {
|
|
18386
|
+
u = u + (z[i] & 0xff) | 0;
|
|
18387
|
+
z[i] = u & 0xff;
|
|
18388
|
+
u >>>= 8;
|
|
18389
|
+
}
|
|
18390
|
+
b -= 64;
|
|
18391
|
+
cpos += 64;
|
|
18392
|
+
}
|
|
18393
|
+
if (b > 0) {
|
|
18394
|
+
crypto_core_salsa20(x,z,k,sigma);
|
|
18395
|
+
for (i = 0; i < b; i++) c[cpos+i] = x[i];
|
|
18396
|
+
}
|
|
18397
|
+
return 0;
|
|
18398
|
+
}
|
|
18399
|
+
|
|
18400
|
+
function crypto_stream(c,cpos,d,n,k) {
|
|
18401
|
+
var s = new Uint8Array(32);
|
|
18402
|
+
crypto_core_hsalsa20(s,n,k,sigma);
|
|
18403
|
+
var sn = new Uint8Array(8);
|
|
18404
|
+
for (var i = 0; i < 8; i++) sn[i] = n[i+16];
|
|
18405
|
+
return crypto_stream_salsa20(c,cpos,d,sn,s);
|
|
18406
|
+
}
|
|
18407
|
+
|
|
18408
|
+
function crypto_stream_xor(c,cpos,m,mpos,d,n,k) {
|
|
18409
|
+
var s = new Uint8Array(32);
|
|
18410
|
+
crypto_core_hsalsa20(s,n,k,sigma);
|
|
18411
|
+
var sn = new Uint8Array(8);
|
|
18412
|
+
for (var i = 0; i < 8; i++) sn[i] = n[i+16];
|
|
18413
|
+
return crypto_stream_salsa20_xor(c,cpos,m,mpos,d,sn,s);
|
|
18414
|
+
}
|
|
18415
|
+
|
|
18416
|
+
/*
|
|
18417
|
+
* Port of Andrew Moon's Poly1305-donna-16. Public domain.
|
|
18418
|
+
* https://github.com/floodyberry/poly1305-donna
|
|
18419
|
+
*/
|
|
18420
|
+
|
|
18421
|
+
var poly1305 = function(key) {
|
|
18422
|
+
this.buffer = new Uint8Array(16);
|
|
18423
|
+
this.r = new Uint16Array(10);
|
|
18424
|
+
this.h = new Uint16Array(10);
|
|
18425
|
+
this.pad = new Uint16Array(8);
|
|
18426
|
+
this.leftover = 0;
|
|
18427
|
+
this.fin = 0;
|
|
18428
|
+
|
|
18429
|
+
var t0, t1, t2, t3, t4, t5, t6, t7;
|
|
18430
|
+
|
|
18431
|
+
t0 = key[ 0] & 0xff | (key[ 1] & 0xff) << 8; this.r[0] = ( t0 ) & 0x1fff;
|
|
18432
|
+
t1 = key[ 2] & 0xff | (key[ 3] & 0xff) << 8; this.r[1] = ((t0 >>> 13) | (t1 << 3)) & 0x1fff;
|
|
18433
|
+
t2 = key[ 4] & 0xff | (key[ 5] & 0xff) << 8; this.r[2] = ((t1 >>> 10) | (t2 << 6)) & 0x1f03;
|
|
18434
|
+
t3 = key[ 6] & 0xff | (key[ 7] & 0xff) << 8; this.r[3] = ((t2 >>> 7) | (t3 << 9)) & 0x1fff;
|
|
18435
|
+
t4 = key[ 8] & 0xff | (key[ 9] & 0xff) << 8; this.r[4] = ((t3 >>> 4) | (t4 << 12)) & 0x00ff;
|
|
18436
|
+
this.r[5] = ((t4 >>> 1)) & 0x1ffe;
|
|
18437
|
+
t5 = key[10] & 0xff | (key[11] & 0xff) << 8; this.r[6] = ((t4 >>> 14) | (t5 << 2)) & 0x1fff;
|
|
18438
|
+
t6 = key[12] & 0xff | (key[13] & 0xff) << 8; this.r[7] = ((t5 >>> 11) | (t6 << 5)) & 0x1f81;
|
|
18439
|
+
t7 = key[14] & 0xff | (key[15] & 0xff) << 8; this.r[8] = ((t6 >>> 8) | (t7 << 8)) & 0x1fff;
|
|
18440
|
+
this.r[9] = ((t7 >>> 5)) & 0x007f;
|
|
18441
|
+
|
|
18442
|
+
this.pad[0] = key[16] & 0xff | (key[17] & 0xff) << 8;
|
|
18443
|
+
this.pad[1] = key[18] & 0xff | (key[19] & 0xff) << 8;
|
|
18444
|
+
this.pad[2] = key[20] & 0xff | (key[21] & 0xff) << 8;
|
|
18445
|
+
this.pad[3] = key[22] & 0xff | (key[23] & 0xff) << 8;
|
|
18446
|
+
this.pad[4] = key[24] & 0xff | (key[25] & 0xff) << 8;
|
|
18447
|
+
this.pad[5] = key[26] & 0xff | (key[27] & 0xff) << 8;
|
|
18448
|
+
this.pad[6] = key[28] & 0xff | (key[29] & 0xff) << 8;
|
|
18449
|
+
this.pad[7] = key[30] & 0xff | (key[31] & 0xff) << 8;
|
|
18450
|
+
};
|
|
18451
|
+
|
|
18452
|
+
poly1305.prototype.blocks = function(m, mpos, bytes) {
|
|
18453
|
+
var hibit = this.fin ? 0 : (1 << 11);
|
|
18454
|
+
var t0, t1, t2, t3, t4, t5, t6, t7, c;
|
|
18455
|
+
var d0, d1, d2, d3, d4, d5, d6, d7, d8, d9;
|
|
18456
|
+
|
|
18457
|
+
var h0 = this.h[0],
|
|
18458
|
+
h1 = this.h[1],
|
|
18459
|
+
h2 = this.h[2],
|
|
18460
|
+
h3 = this.h[3],
|
|
18461
|
+
h4 = this.h[4],
|
|
18462
|
+
h5 = this.h[5],
|
|
18463
|
+
h6 = this.h[6],
|
|
18464
|
+
h7 = this.h[7],
|
|
18465
|
+
h8 = this.h[8],
|
|
18466
|
+
h9 = this.h[9];
|
|
18467
|
+
|
|
18468
|
+
var r0 = this.r[0],
|
|
18469
|
+
r1 = this.r[1],
|
|
18470
|
+
r2 = this.r[2],
|
|
18471
|
+
r3 = this.r[3],
|
|
18472
|
+
r4 = this.r[4],
|
|
18473
|
+
r5 = this.r[5],
|
|
18474
|
+
r6 = this.r[6],
|
|
18475
|
+
r7 = this.r[7],
|
|
18476
|
+
r8 = this.r[8],
|
|
18477
|
+
r9 = this.r[9];
|
|
18478
|
+
|
|
18479
|
+
while (bytes >= 16) {
|
|
18480
|
+
t0 = m[mpos+ 0] & 0xff | (m[mpos+ 1] & 0xff) << 8; h0 += ( t0 ) & 0x1fff;
|
|
18481
|
+
t1 = m[mpos+ 2] & 0xff | (m[mpos+ 3] & 0xff) << 8; h1 += ((t0 >>> 13) | (t1 << 3)) & 0x1fff;
|
|
18482
|
+
t2 = m[mpos+ 4] & 0xff | (m[mpos+ 5] & 0xff) << 8; h2 += ((t1 >>> 10) | (t2 << 6)) & 0x1fff;
|
|
18483
|
+
t3 = m[mpos+ 6] & 0xff | (m[mpos+ 7] & 0xff) << 8; h3 += ((t2 >>> 7) | (t3 << 9)) & 0x1fff;
|
|
18484
|
+
t4 = m[mpos+ 8] & 0xff | (m[mpos+ 9] & 0xff) << 8; h4 += ((t3 >>> 4) | (t4 << 12)) & 0x1fff;
|
|
18485
|
+
h5 += ((t4 >>> 1)) & 0x1fff;
|
|
18486
|
+
t5 = m[mpos+10] & 0xff | (m[mpos+11] & 0xff) << 8; h6 += ((t4 >>> 14) | (t5 << 2)) & 0x1fff;
|
|
18487
|
+
t6 = m[mpos+12] & 0xff | (m[mpos+13] & 0xff) << 8; h7 += ((t5 >>> 11) | (t6 << 5)) & 0x1fff;
|
|
18488
|
+
t7 = m[mpos+14] & 0xff | (m[mpos+15] & 0xff) << 8; h8 += ((t6 >>> 8) | (t7 << 8)) & 0x1fff;
|
|
18489
|
+
h9 += ((t7 >>> 5)) | hibit;
|
|
18490
|
+
|
|
18491
|
+
c = 0;
|
|
18492
|
+
|
|
18493
|
+
d0 = c;
|
|
18494
|
+
d0 += h0 * r0;
|
|
18495
|
+
d0 += h1 * (5 * r9);
|
|
18496
|
+
d0 += h2 * (5 * r8);
|
|
18497
|
+
d0 += h3 * (5 * r7);
|
|
18498
|
+
d0 += h4 * (5 * r6);
|
|
18499
|
+
c = (d0 >>> 13); d0 &= 0x1fff;
|
|
18500
|
+
d0 += h5 * (5 * r5);
|
|
18501
|
+
d0 += h6 * (5 * r4);
|
|
18502
|
+
d0 += h7 * (5 * r3);
|
|
18503
|
+
d0 += h8 * (5 * r2);
|
|
18504
|
+
d0 += h9 * (5 * r1);
|
|
18505
|
+
c += (d0 >>> 13); d0 &= 0x1fff;
|
|
18506
|
+
|
|
18507
|
+
d1 = c;
|
|
18508
|
+
d1 += h0 * r1;
|
|
18509
|
+
d1 += h1 * r0;
|
|
18510
|
+
d1 += h2 * (5 * r9);
|
|
18511
|
+
d1 += h3 * (5 * r8);
|
|
18512
|
+
d1 += h4 * (5 * r7);
|
|
18513
|
+
c = (d1 >>> 13); d1 &= 0x1fff;
|
|
18514
|
+
d1 += h5 * (5 * r6);
|
|
18515
|
+
d1 += h6 * (5 * r5);
|
|
18516
|
+
d1 += h7 * (5 * r4);
|
|
18517
|
+
d1 += h8 * (5 * r3);
|
|
18518
|
+
d1 += h9 * (5 * r2);
|
|
18519
|
+
c += (d1 >>> 13); d1 &= 0x1fff;
|
|
18520
|
+
|
|
18521
|
+
d2 = c;
|
|
18522
|
+
d2 += h0 * r2;
|
|
18523
|
+
d2 += h1 * r1;
|
|
18524
|
+
d2 += h2 * r0;
|
|
18525
|
+
d2 += h3 * (5 * r9);
|
|
18526
|
+
d2 += h4 * (5 * r8);
|
|
18527
|
+
c = (d2 >>> 13); d2 &= 0x1fff;
|
|
18528
|
+
d2 += h5 * (5 * r7);
|
|
18529
|
+
d2 += h6 * (5 * r6);
|
|
18530
|
+
d2 += h7 * (5 * r5);
|
|
18531
|
+
d2 += h8 * (5 * r4);
|
|
18532
|
+
d2 += h9 * (5 * r3);
|
|
18533
|
+
c += (d2 >>> 13); d2 &= 0x1fff;
|
|
18534
|
+
|
|
18535
|
+
d3 = c;
|
|
18536
|
+
d3 += h0 * r3;
|
|
18537
|
+
d3 += h1 * r2;
|
|
18538
|
+
d3 += h2 * r1;
|
|
18539
|
+
d3 += h3 * r0;
|
|
18540
|
+
d3 += h4 * (5 * r9);
|
|
18541
|
+
c = (d3 >>> 13); d3 &= 0x1fff;
|
|
18542
|
+
d3 += h5 * (5 * r8);
|
|
18543
|
+
d3 += h6 * (5 * r7);
|
|
18544
|
+
d3 += h7 * (5 * r6);
|
|
18545
|
+
d3 += h8 * (5 * r5);
|
|
18546
|
+
d3 += h9 * (5 * r4);
|
|
18547
|
+
c += (d3 >>> 13); d3 &= 0x1fff;
|
|
18548
|
+
|
|
18549
|
+
d4 = c;
|
|
18550
|
+
d4 += h0 * r4;
|
|
18551
|
+
d4 += h1 * r3;
|
|
18552
|
+
d4 += h2 * r2;
|
|
18553
|
+
d4 += h3 * r1;
|
|
18554
|
+
d4 += h4 * r0;
|
|
18555
|
+
c = (d4 >>> 13); d4 &= 0x1fff;
|
|
18556
|
+
d4 += h5 * (5 * r9);
|
|
18557
|
+
d4 += h6 * (5 * r8);
|
|
18558
|
+
d4 += h7 * (5 * r7);
|
|
18559
|
+
d4 += h8 * (5 * r6);
|
|
18560
|
+
d4 += h9 * (5 * r5);
|
|
18561
|
+
c += (d4 >>> 13); d4 &= 0x1fff;
|
|
18562
|
+
|
|
18563
|
+
d5 = c;
|
|
18564
|
+
d5 += h0 * r5;
|
|
18565
|
+
d5 += h1 * r4;
|
|
18566
|
+
d5 += h2 * r3;
|
|
18567
|
+
d5 += h3 * r2;
|
|
18568
|
+
d5 += h4 * r1;
|
|
18569
|
+
c = (d5 >>> 13); d5 &= 0x1fff;
|
|
18570
|
+
d5 += h5 * r0;
|
|
18571
|
+
d5 += h6 * (5 * r9);
|
|
18572
|
+
d5 += h7 * (5 * r8);
|
|
18573
|
+
d5 += h8 * (5 * r7);
|
|
18574
|
+
d5 += h9 * (5 * r6);
|
|
18575
|
+
c += (d5 >>> 13); d5 &= 0x1fff;
|
|
18576
|
+
|
|
18577
|
+
d6 = c;
|
|
18578
|
+
d6 += h0 * r6;
|
|
18579
|
+
d6 += h1 * r5;
|
|
18580
|
+
d6 += h2 * r4;
|
|
18581
|
+
d6 += h3 * r3;
|
|
18582
|
+
d6 += h4 * r2;
|
|
18583
|
+
c = (d6 >>> 13); d6 &= 0x1fff;
|
|
18584
|
+
d6 += h5 * r1;
|
|
18585
|
+
d6 += h6 * r0;
|
|
18586
|
+
d6 += h7 * (5 * r9);
|
|
18587
|
+
d6 += h8 * (5 * r8);
|
|
18588
|
+
d6 += h9 * (5 * r7);
|
|
18589
|
+
c += (d6 >>> 13); d6 &= 0x1fff;
|
|
18590
|
+
|
|
18591
|
+
d7 = c;
|
|
18592
|
+
d7 += h0 * r7;
|
|
18593
|
+
d7 += h1 * r6;
|
|
18594
|
+
d7 += h2 * r5;
|
|
18595
|
+
d7 += h3 * r4;
|
|
18596
|
+
d7 += h4 * r3;
|
|
18597
|
+
c = (d7 >>> 13); d7 &= 0x1fff;
|
|
18598
|
+
d7 += h5 * r2;
|
|
18599
|
+
d7 += h6 * r1;
|
|
18600
|
+
d7 += h7 * r0;
|
|
18601
|
+
d7 += h8 * (5 * r9);
|
|
18602
|
+
d7 += h9 * (5 * r8);
|
|
18603
|
+
c += (d7 >>> 13); d7 &= 0x1fff;
|
|
18604
|
+
|
|
18605
|
+
d8 = c;
|
|
18606
|
+
d8 += h0 * r8;
|
|
18607
|
+
d8 += h1 * r7;
|
|
18608
|
+
d8 += h2 * r6;
|
|
18609
|
+
d8 += h3 * r5;
|
|
18610
|
+
d8 += h4 * r4;
|
|
18611
|
+
c = (d8 >>> 13); d8 &= 0x1fff;
|
|
18612
|
+
d8 += h5 * r3;
|
|
18613
|
+
d8 += h6 * r2;
|
|
18614
|
+
d8 += h7 * r1;
|
|
18615
|
+
d8 += h8 * r0;
|
|
18616
|
+
d8 += h9 * (5 * r9);
|
|
18617
|
+
c += (d8 >>> 13); d8 &= 0x1fff;
|
|
18618
|
+
|
|
18619
|
+
d9 = c;
|
|
18620
|
+
d9 += h0 * r9;
|
|
18621
|
+
d9 += h1 * r8;
|
|
18622
|
+
d9 += h2 * r7;
|
|
18623
|
+
d9 += h3 * r6;
|
|
18624
|
+
d9 += h4 * r5;
|
|
18625
|
+
c = (d9 >>> 13); d9 &= 0x1fff;
|
|
18626
|
+
d9 += h5 * r4;
|
|
18627
|
+
d9 += h6 * r3;
|
|
18628
|
+
d9 += h7 * r2;
|
|
18629
|
+
d9 += h8 * r1;
|
|
18630
|
+
d9 += h9 * r0;
|
|
18631
|
+
c += (d9 >>> 13); d9 &= 0x1fff;
|
|
18632
|
+
|
|
18633
|
+
c = (((c << 2) + c)) | 0;
|
|
18634
|
+
c = (c + d0) | 0;
|
|
18635
|
+
d0 = c & 0x1fff;
|
|
18636
|
+
c = (c >>> 13);
|
|
18637
|
+
d1 += c;
|
|
18638
|
+
|
|
18639
|
+
h0 = d0;
|
|
18640
|
+
h1 = d1;
|
|
18641
|
+
h2 = d2;
|
|
18642
|
+
h3 = d3;
|
|
18643
|
+
h4 = d4;
|
|
18644
|
+
h5 = d5;
|
|
18645
|
+
h6 = d6;
|
|
18646
|
+
h7 = d7;
|
|
18647
|
+
h8 = d8;
|
|
18648
|
+
h9 = d9;
|
|
18649
|
+
|
|
18650
|
+
mpos += 16;
|
|
18651
|
+
bytes -= 16;
|
|
18652
|
+
}
|
|
18653
|
+
this.h[0] = h0;
|
|
18654
|
+
this.h[1] = h1;
|
|
18655
|
+
this.h[2] = h2;
|
|
18656
|
+
this.h[3] = h3;
|
|
18657
|
+
this.h[4] = h4;
|
|
18658
|
+
this.h[5] = h5;
|
|
18659
|
+
this.h[6] = h6;
|
|
18660
|
+
this.h[7] = h7;
|
|
18661
|
+
this.h[8] = h8;
|
|
18662
|
+
this.h[9] = h9;
|
|
18663
|
+
};
|
|
18664
|
+
|
|
18665
|
+
poly1305.prototype.finish = function(mac, macpos) {
|
|
18666
|
+
var g = new Uint16Array(10);
|
|
18667
|
+
var c, mask, f, i;
|
|
18668
|
+
|
|
18669
|
+
if (this.leftover) {
|
|
18670
|
+
i = this.leftover;
|
|
18671
|
+
this.buffer[i++] = 1;
|
|
18672
|
+
for (; i < 16; i++) this.buffer[i] = 0;
|
|
18673
|
+
this.fin = 1;
|
|
18674
|
+
this.blocks(this.buffer, 0, 16);
|
|
18675
|
+
}
|
|
18676
|
+
|
|
18677
|
+
c = this.h[1] >>> 13;
|
|
18678
|
+
this.h[1] &= 0x1fff;
|
|
18679
|
+
for (i = 2; i < 10; i++) {
|
|
18680
|
+
this.h[i] += c;
|
|
18681
|
+
c = this.h[i] >>> 13;
|
|
18682
|
+
this.h[i] &= 0x1fff;
|
|
18683
|
+
}
|
|
18684
|
+
this.h[0] += (c * 5);
|
|
18685
|
+
c = this.h[0] >>> 13;
|
|
18686
|
+
this.h[0] &= 0x1fff;
|
|
18687
|
+
this.h[1] += c;
|
|
18688
|
+
c = this.h[1] >>> 13;
|
|
18689
|
+
this.h[1] &= 0x1fff;
|
|
18690
|
+
this.h[2] += c;
|
|
18691
|
+
|
|
18692
|
+
g[0] = this.h[0] + 5;
|
|
18693
|
+
c = g[0] >>> 13;
|
|
18694
|
+
g[0] &= 0x1fff;
|
|
18695
|
+
for (i = 1; i < 10; i++) {
|
|
18696
|
+
g[i] = this.h[i] + c;
|
|
18697
|
+
c = g[i] >>> 13;
|
|
18698
|
+
g[i] &= 0x1fff;
|
|
18699
|
+
}
|
|
18700
|
+
g[9] -= (1 << 13);
|
|
18701
|
+
|
|
18702
|
+
mask = (c ^ 1) - 1;
|
|
18703
|
+
for (i = 0; i < 10; i++) g[i] &= mask;
|
|
18704
|
+
mask = ~mask;
|
|
18705
|
+
for (i = 0; i < 10; i++) this.h[i] = (this.h[i] & mask) | g[i];
|
|
18706
|
+
|
|
18707
|
+
this.h[0] = ((this.h[0] ) | (this.h[1] << 13) ) & 0xffff;
|
|
18708
|
+
this.h[1] = ((this.h[1] >>> 3) | (this.h[2] << 10) ) & 0xffff;
|
|
18709
|
+
this.h[2] = ((this.h[2] >>> 6) | (this.h[3] << 7) ) & 0xffff;
|
|
18710
|
+
this.h[3] = ((this.h[3] >>> 9) | (this.h[4] << 4) ) & 0xffff;
|
|
18711
|
+
this.h[4] = ((this.h[4] >>> 12) | (this.h[5] << 1) | (this.h[6] << 14)) & 0xffff;
|
|
18712
|
+
this.h[5] = ((this.h[6] >>> 2) | (this.h[7] << 11) ) & 0xffff;
|
|
18713
|
+
this.h[6] = ((this.h[7] >>> 5) | (this.h[8] << 8) ) & 0xffff;
|
|
18714
|
+
this.h[7] = ((this.h[8] >>> 8) | (this.h[9] << 5) ) & 0xffff;
|
|
18715
|
+
|
|
18716
|
+
f = this.h[0] + this.pad[0];
|
|
18717
|
+
this.h[0] = f & 0xffff;
|
|
18718
|
+
for (i = 1; i < 8; i++) {
|
|
18719
|
+
f = (((this.h[i] + this.pad[i]) | 0) + (f >>> 16)) | 0;
|
|
18720
|
+
this.h[i] = f & 0xffff;
|
|
18721
|
+
}
|
|
18722
|
+
|
|
18723
|
+
mac[macpos+ 0] = (this.h[0] >>> 0) & 0xff;
|
|
18724
|
+
mac[macpos+ 1] = (this.h[0] >>> 8) & 0xff;
|
|
18725
|
+
mac[macpos+ 2] = (this.h[1] >>> 0) & 0xff;
|
|
18726
|
+
mac[macpos+ 3] = (this.h[1] >>> 8) & 0xff;
|
|
18727
|
+
mac[macpos+ 4] = (this.h[2] >>> 0) & 0xff;
|
|
18728
|
+
mac[macpos+ 5] = (this.h[2] >>> 8) & 0xff;
|
|
18729
|
+
mac[macpos+ 6] = (this.h[3] >>> 0) & 0xff;
|
|
18730
|
+
mac[macpos+ 7] = (this.h[3] >>> 8) & 0xff;
|
|
18731
|
+
mac[macpos+ 8] = (this.h[4] >>> 0) & 0xff;
|
|
18732
|
+
mac[macpos+ 9] = (this.h[4] >>> 8) & 0xff;
|
|
18733
|
+
mac[macpos+10] = (this.h[5] >>> 0) & 0xff;
|
|
18734
|
+
mac[macpos+11] = (this.h[5] >>> 8) & 0xff;
|
|
18735
|
+
mac[macpos+12] = (this.h[6] >>> 0) & 0xff;
|
|
18736
|
+
mac[macpos+13] = (this.h[6] >>> 8) & 0xff;
|
|
18737
|
+
mac[macpos+14] = (this.h[7] >>> 0) & 0xff;
|
|
18738
|
+
mac[macpos+15] = (this.h[7] >>> 8) & 0xff;
|
|
18739
|
+
};
|
|
18740
|
+
|
|
18741
|
+
poly1305.prototype.update = function(m, mpos, bytes) {
|
|
18742
|
+
var i, want;
|
|
18743
|
+
|
|
18744
|
+
if (this.leftover) {
|
|
18745
|
+
want = (16 - this.leftover);
|
|
18746
|
+
if (want > bytes)
|
|
18747
|
+
want = bytes;
|
|
18748
|
+
for (i = 0; i < want; i++)
|
|
18749
|
+
this.buffer[this.leftover + i] = m[mpos+i];
|
|
18750
|
+
bytes -= want;
|
|
18751
|
+
mpos += want;
|
|
18752
|
+
this.leftover += want;
|
|
18753
|
+
if (this.leftover < 16)
|
|
18754
|
+
return;
|
|
18755
|
+
this.blocks(this.buffer, 0, 16);
|
|
18756
|
+
this.leftover = 0;
|
|
18757
|
+
}
|
|
18758
|
+
|
|
18759
|
+
if (bytes >= 16) {
|
|
18760
|
+
want = bytes - (bytes % 16);
|
|
18761
|
+
this.blocks(m, mpos, want);
|
|
18762
|
+
mpos += want;
|
|
18763
|
+
bytes -= want;
|
|
18764
|
+
}
|
|
18765
|
+
|
|
18766
|
+
if (bytes) {
|
|
18767
|
+
for (i = 0; i < bytes; i++)
|
|
18768
|
+
this.buffer[this.leftover + i] = m[mpos+i];
|
|
18769
|
+
this.leftover += bytes;
|
|
18770
|
+
}
|
|
18771
|
+
};
|
|
18772
|
+
|
|
18773
|
+
function crypto_onetimeauth(out, outpos, m, mpos, n, k) {
|
|
18774
|
+
var s = new poly1305(k);
|
|
18775
|
+
s.update(m, mpos, n);
|
|
18776
|
+
s.finish(out, outpos);
|
|
18777
|
+
return 0;
|
|
18778
|
+
}
|
|
18779
|
+
|
|
18780
|
+
function crypto_onetimeauth_verify(h, hpos, m, mpos, n, k) {
|
|
18781
|
+
var x = new Uint8Array(16);
|
|
18782
|
+
crypto_onetimeauth(x,0,m,mpos,n,k);
|
|
18783
|
+
return crypto_verify_16(h,hpos,x,0);
|
|
18784
|
+
}
|
|
18785
|
+
|
|
18786
|
+
function crypto_secretbox(c,m,d,n,k) {
|
|
18787
|
+
var i;
|
|
18788
|
+
if (d < 32) return -1;
|
|
18789
|
+
crypto_stream_xor(c,0,m,0,d,n,k);
|
|
18790
|
+
crypto_onetimeauth(c, 16, c, 32, d - 32, c);
|
|
18791
|
+
for (i = 0; i < 16; i++) c[i] = 0;
|
|
18792
|
+
return 0;
|
|
18793
|
+
}
|
|
18794
|
+
|
|
18795
|
+
function crypto_secretbox_open(m,c,d,n,k) {
|
|
18796
|
+
var i;
|
|
18797
|
+
var x = new Uint8Array(32);
|
|
18798
|
+
if (d < 32) return -1;
|
|
18799
|
+
crypto_stream(x,0,32,n,k);
|
|
18800
|
+
if (crypto_onetimeauth_verify(c, 16,c, 32,d - 32,x) !== 0) return -1;
|
|
18801
|
+
crypto_stream_xor(m,0,c,0,d,n,k);
|
|
18802
|
+
for (i = 0; i < 32; i++) m[i] = 0;
|
|
18803
|
+
return 0;
|
|
18804
|
+
}
|
|
18805
|
+
|
|
18806
|
+
function set25519(r, a) {
|
|
18807
|
+
var i;
|
|
18808
|
+
for (i = 0; i < 16; i++) r[i] = a[i]|0;
|
|
18809
|
+
}
|
|
18810
|
+
|
|
18811
|
+
function car25519(o) {
|
|
18812
|
+
var i, v, c = 1;
|
|
18813
|
+
for (i = 0; i < 16; i++) {
|
|
18814
|
+
v = o[i] + c + 65535;
|
|
18815
|
+
c = Math.floor(v / 65536);
|
|
18816
|
+
o[i] = v - c * 65536;
|
|
18817
|
+
}
|
|
18818
|
+
o[0] += c-1 + 37 * (c-1);
|
|
18819
|
+
}
|
|
18820
|
+
|
|
18821
|
+
function sel25519(p, q, b) {
|
|
18822
|
+
var t, c = ~(b-1);
|
|
18823
|
+
for (var i = 0; i < 16; i++) {
|
|
18824
|
+
t = c & (p[i] ^ q[i]);
|
|
18825
|
+
p[i] ^= t;
|
|
18826
|
+
q[i] ^= t;
|
|
18827
|
+
}
|
|
18828
|
+
}
|
|
18829
|
+
|
|
18830
|
+
function pack25519(o, n) {
|
|
18831
|
+
var i, j, b;
|
|
18832
|
+
var m = gf(), t = gf();
|
|
18833
|
+
for (i = 0; i < 16; i++) t[i] = n[i];
|
|
18834
|
+
car25519(t);
|
|
18835
|
+
car25519(t);
|
|
18836
|
+
car25519(t);
|
|
18837
|
+
for (j = 0; j < 2; j++) {
|
|
18838
|
+
m[0] = t[0] - 0xffed;
|
|
18839
|
+
for (i = 1; i < 15; i++) {
|
|
18840
|
+
m[i] = t[i] - 0xffff - ((m[i-1]>>16) & 1);
|
|
18841
|
+
m[i-1] &= 0xffff;
|
|
18842
|
+
}
|
|
18843
|
+
m[15] = t[15] - 0x7fff - ((m[14]>>16) & 1);
|
|
18844
|
+
b = (m[15]>>16) & 1;
|
|
18845
|
+
m[14] &= 0xffff;
|
|
18846
|
+
sel25519(t, m, 1-b);
|
|
18847
|
+
}
|
|
18848
|
+
for (i = 0; i < 16; i++) {
|
|
18849
|
+
o[2*i] = t[i] & 0xff;
|
|
18850
|
+
o[2*i+1] = t[i]>>8;
|
|
18851
|
+
}
|
|
18852
|
+
}
|
|
18853
|
+
|
|
18854
|
+
function neq25519(a, b) {
|
|
18855
|
+
var c = new Uint8Array(32), d = new Uint8Array(32);
|
|
18856
|
+
pack25519(c, a);
|
|
18857
|
+
pack25519(d, b);
|
|
18858
|
+
return crypto_verify_32(c, 0, d, 0);
|
|
18859
|
+
}
|
|
18860
|
+
|
|
18861
|
+
function par25519(a) {
|
|
18862
|
+
var d = new Uint8Array(32);
|
|
18863
|
+
pack25519(d, a);
|
|
18864
|
+
return d[0] & 1;
|
|
18865
|
+
}
|
|
18866
|
+
|
|
18867
|
+
function unpack25519(o, n) {
|
|
18868
|
+
var i;
|
|
18869
|
+
for (i = 0; i < 16; i++) o[i] = n[2*i] + (n[2*i+1] << 8);
|
|
18870
|
+
o[15] &= 0x7fff;
|
|
18871
|
+
}
|
|
18872
|
+
|
|
18873
|
+
function A(o, a, b) {
|
|
18874
|
+
for (var i = 0; i < 16; i++) o[i] = a[i] + b[i];
|
|
18875
|
+
}
|
|
18876
|
+
|
|
18877
|
+
function Z(o, a, b) {
|
|
18878
|
+
for (var i = 0; i < 16; i++) o[i] = a[i] - b[i];
|
|
18879
|
+
}
|
|
18880
|
+
|
|
18881
|
+
function M(o, a, b) {
|
|
18882
|
+
var v, c,
|
|
18883
|
+
t0 = 0, t1 = 0, t2 = 0, t3 = 0, t4 = 0, t5 = 0, t6 = 0, t7 = 0,
|
|
18884
|
+
t8 = 0, t9 = 0, t10 = 0, t11 = 0, t12 = 0, t13 = 0, t14 = 0, t15 = 0,
|
|
18885
|
+
t16 = 0, t17 = 0, t18 = 0, t19 = 0, t20 = 0, t21 = 0, t22 = 0, t23 = 0,
|
|
18886
|
+
t24 = 0, t25 = 0, t26 = 0, t27 = 0, t28 = 0, t29 = 0, t30 = 0,
|
|
18887
|
+
b0 = b[0],
|
|
18888
|
+
b1 = b[1],
|
|
18889
|
+
b2 = b[2],
|
|
18890
|
+
b3 = b[3],
|
|
18891
|
+
b4 = b[4],
|
|
18892
|
+
b5 = b[5],
|
|
18893
|
+
b6 = b[6],
|
|
18894
|
+
b7 = b[7],
|
|
18895
|
+
b8 = b[8],
|
|
18896
|
+
b9 = b[9],
|
|
18897
|
+
b10 = b[10],
|
|
18898
|
+
b11 = b[11],
|
|
18899
|
+
b12 = b[12],
|
|
18900
|
+
b13 = b[13],
|
|
18901
|
+
b14 = b[14],
|
|
18902
|
+
b15 = b[15];
|
|
18903
|
+
|
|
18904
|
+
v = a[0];
|
|
18905
|
+
t0 += v * b0;
|
|
18906
|
+
t1 += v * b1;
|
|
18907
|
+
t2 += v * b2;
|
|
18908
|
+
t3 += v * b3;
|
|
18909
|
+
t4 += v * b4;
|
|
18910
|
+
t5 += v * b5;
|
|
18911
|
+
t6 += v * b6;
|
|
18912
|
+
t7 += v * b7;
|
|
18913
|
+
t8 += v * b8;
|
|
18914
|
+
t9 += v * b9;
|
|
18915
|
+
t10 += v * b10;
|
|
18916
|
+
t11 += v * b11;
|
|
18917
|
+
t12 += v * b12;
|
|
18918
|
+
t13 += v * b13;
|
|
18919
|
+
t14 += v * b14;
|
|
18920
|
+
t15 += v * b15;
|
|
18921
|
+
v = a[1];
|
|
18922
|
+
t1 += v * b0;
|
|
18923
|
+
t2 += v * b1;
|
|
18924
|
+
t3 += v * b2;
|
|
18925
|
+
t4 += v * b3;
|
|
18926
|
+
t5 += v * b4;
|
|
18927
|
+
t6 += v * b5;
|
|
18928
|
+
t7 += v * b6;
|
|
18929
|
+
t8 += v * b7;
|
|
18930
|
+
t9 += v * b8;
|
|
18931
|
+
t10 += v * b9;
|
|
18932
|
+
t11 += v * b10;
|
|
18933
|
+
t12 += v * b11;
|
|
18934
|
+
t13 += v * b12;
|
|
18935
|
+
t14 += v * b13;
|
|
18936
|
+
t15 += v * b14;
|
|
18937
|
+
t16 += v * b15;
|
|
18938
|
+
v = a[2];
|
|
18939
|
+
t2 += v * b0;
|
|
18940
|
+
t3 += v * b1;
|
|
18941
|
+
t4 += v * b2;
|
|
18942
|
+
t5 += v * b3;
|
|
18943
|
+
t6 += v * b4;
|
|
18944
|
+
t7 += v * b5;
|
|
18945
|
+
t8 += v * b6;
|
|
18946
|
+
t9 += v * b7;
|
|
18947
|
+
t10 += v * b8;
|
|
18948
|
+
t11 += v * b9;
|
|
18949
|
+
t12 += v * b10;
|
|
18950
|
+
t13 += v * b11;
|
|
18951
|
+
t14 += v * b12;
|
|
18952
|
+
t15 += v * b13;
|
|
18953
|
+
t16 += v * b14;
|
|
18954
|
+
t17 += v * b15;
|
|
18955
|
+
v = a[3];
|
|
18956
|
+
t3 += v * b0;
|
|
18957
|
+
t4 += v * b1;
|
|
18958
|
+
t5 += v * b2;
|
|
18959
|
+
t6 += v * b3;
|
|
18960
|
+
t7 += v * b4;
|
|
18961
|
+
t8 += v * b5;
|
|
18962
|
+
t9 += v * b6;
|
|
18963
|
+
t10 += v * b7;
|
|
18964
|
+
t11 += v * b8;
|
|
18965
|
+
t12 += v * b9;
|
|
18966
|
+
t13 += v * b10;
|
|
18967
|
+
t14 += v * b11;
|
|
18968
|
+
t15 += v * b12;
|
|
18969
|
+
t16 += v * b13;
|
|
18970
|
+
t17 += v * b14;
|
|
18971
|
+
t18 += v * b15;
|
|
18972
|
+
v = a[4];
|
|
18973
|
+
t4 += v * b0;
|
|
18974
|
+
t5 += v * b1;
|
|
18975
|
+
t6 += v * b2;
|
|
18976
|
+
t7 += v * b3;
|
|
18977
|
+
t8 += v * b4;
|
|
18978
|
+
t9 += v * b5;
|
|
18979
|
+
t10 += v * b6;
|
|
18980
|
+
t11 += v * b7;
|
|
18981
|
+
t12 += v * b8;
|
|
18982
|
+
t13 += v * b9;
|
|
18983
|
+
t14 += v * b10;
|
|
18984
|
+
t15 += v * b11;
|
|
18985
|
+
t16 += v * b12;
|
|
18986
|
+
t17 += v * b13;
|
|
18987
|
+
t18 += v * b14;
|
|
18988
|
+
t19 += v * b15;
|
|
18989
|
+
v = a[5];
|
|
18990
|
+
t5 += v * b0;
|
|
18991
|
+
t6 += v * b1;
|
|
18992
|
+
t7 += v * b2;
|
|
18993
|
+
t8 += v * b3;
|
|
18994
|
+
t9 += v * b4;
|
|
18995
|
+
t10 += v * b5;
|
|
18996
|
+
t11 += v * b6;
|
|
18997
|
+
t12 += v * b7;
|
|
18998
|
+
t13 += v * b8;
|
|
18999
|
+
t14 += v * b9;
|
|
19000
|
+
t15 += v * b10;
|
|
19001
|
+
t16 += v * b11;
|
|
19002
|
+
t17 += v * b12;
|
|
19003
|
+
t18 += v * b13;
|
|
19004
|
+
t19 += v * b14;
|
|
19005
|
+
t20 += v * b15;
|
|
19006
|
+
v = a[6];
|
|
19007
|
+
t6 += v * b0;
|
|
19008
|
+
t7 += v * b1;
|
|
19009
|
+
t8 += v * b2;
|
|
19010
|
+
t9 += v * b3;
|
|
19011
|
+
t10 += v * b4;
|
|
19012
|
+
t11 += v * b5;
|
|
19013
|
+
t12 += v * b6;
|
|
19014
|
+
t13 += v * b7;
|
|
19015
|
+
t14 += v * b8;
|
|
19016
|
+
t15 += v * b9;
|
|
19017
|
+
t16 += v * b10;
|
|
19018
|
+
t17 += v * b11;
|
|
19019
|
+
t18 += v * b12;
|
|
19020
|
+
t19 += v * b13;
|
|
19021
|
+
t20 += v * b14;
|
|
19022
|
+
t21 += v * b15;
|
|
19023
|
+
v = a[7];
|
|
19024
|
+
t7 += v * b0;
|
|
19025
|
+
t8 += v * b1;
|
|
19026
|
+
t9 += v * b2;
|
|
19027
|
+
t10 += v * b3;
|
|
19028
|
+
t11 += v * b4;
|
|
19029
|
+
t12 += v * b5;
|
|
19030
|
+
t13 += v * b6;
|
|
19031
|
+
t14 += v * b7;
|
|
19032
|
+
t15 += v * b8;
|
|
19033
|
+
t16 += v * b9;
|
|
19034
|
+
t17 += v * b10;
|
|
19035
|
+
t18 += v * b11;
|
|
19036
|
+
t19 += v * b12;
|
|
19037
|
+
t20 += v * b13;
|
|
19038
|
+
t21 += v * b14;
|
|
19039
|
+
t22 += v * b15;
|
|
19040
|
+
v = a[8];
|
|
19041
|
+
t8 += v * b0;
|
|
19042
|
+
t9 += v * b1;
|
|
19043
|
+
t10 += v * b2;
|
|
19044
|
+
t11 += v * b3;
|
|
19045
|
+
t12 += v * b4;
|
|
19046
|
+
t13 += v * b5;
|
|
19047
|
+
t14 += v * b6;
|
|
19048
|
+
t15 += v * b7;
|
|
19049
|
+
t16 += v * b8;
|
|
19050
|
+
t17 += v * b9;
|
|
19051
|
+
t18 += v * b10;
|
|
19052
|
+
t19 += v * b11;
|
|
19053
|
+
t20 += v * b12;
|
|
19054
|
+
t21 += v * b13;
|
|
19055
|
+
t22 += v * b14;
|
|
19056
|
+
t23 += v * b15;
|
|
19057
|
+
v = a[9];
|
|
19058
|
+
t9 += v * b0;
|
|
19059
|
+
t10 += v * b1;
|
|
19060
|
+
t11 += v * b2;
|
|
19061
|
+
t12 += v * b3;
|
|
19062
|
+
t13 += v * b4;
|
|
19063
|
+
t14 += v * b5;
|
|
19064
|
+
t15 += v * b6;
|
|
19065
|
+
t16 += v * b7;
|
|
19066
|
+
t17 += v * b8;
|
|
19067
|
+
t18 += v * b9;
|
|
19068
|
+
t19 += v * b10;
|
|
19069
|
+
t20 += v * b11;
|
|
19070
|
+
t21 += v * b12;
|
|
19071
|
+
t22 += v * b13;
|
|
19072
|
+
t23 += v * b14;
|
|
19073
|
+
t24 += v * b15;
|
|
19074
|
+
v = a[10];
|
|
19075
|
+
t10 += v * b0;
|
|
19076
|
+
t11 += v * b1;
|
|
19077
|
+
t12 += v * b2;
|
|
19078
|
+
t13 += v * b3;
|
|
19079
|
+
t14 += v * b4;
|
|
19080
|
+
t15 += v * b5;
|
|
19081
|
+
t16 += v * b6;
|
|
19082
|
+
t17 += v * b7;
|
|
19083
|
+
t18 += v * b8;
|
|
19084
|
+
t19 += v * b9;
|
|
19085
|
+
t20 += v * b10;
|
|
19086
|
+
t21 += v * b11;
|
|
19087
|
+
t22 += v * b12;
|
|
19088
|
+
t23 += v * b13;
|
|
19089
|
+
t24 += v * b14;
|
|
19090
|
+
t25 += v * b15;
|
|
19091
|
+
v = a[11];
|
|
19092
|
+
t11 += v * b0;
|
|
19093
|
+
t12 += v * b1;
|
|
19094
|
+
t13 += v * b2;
|
|
19095
|
+
t14 += v * b3;
|
|
19096
|
+
t15 += v * b4;
|
|
19097
|
+
t16 += v * b5;
|
|
19098
|
+
t17 += v * b6;
|
|
19099
|
+
t18 += v * b7;
|
|
19100
|
+
t19 += v * b8;
|
|
19101
|
+
t20 += v * b9;
|
|
19102
|
+
t21 += v * b10;
|
|
19103
|
+
t22 += v * b11;
|
|
19104
|
+
t23 += v * b12;
|
|
19105
|
+
t24 += v * b13;
|
|
19106
|
+
t25 += v * b14;
|
|
19107
|
+
t26 += v * b15;
|
|
19108
|
+
v = a[12];
|
|
19109
|
+
t12 += v * b0;
|
|
19110
|
+
t13 += v * b1;
|
|
19111
|
+
t14 += v * b2;
|
|
19112
|
+
t15 += v * b3;
|
|
19113
|
+
t16 += v * b4;
|
|
19114
|
+
t17 += v * b5;
|
|
19115
|
+
t18 += v * b6;
|
|
19116
|
+
t19 += v * b7;
|
|
19117
|
+
t20 += v * b8;
|
|
19118
|
+
t21 += v * b9;
|
|
19119
|
+
t22 += v * b10;
|
|
19120
|
+
t23 += v * b11;
|
|
19121
|
+
t24 += v * b12;
|
|
19122
|
+
t25 += v * b13;
|
|
19123
|
+
t26 += v * b14;
|
|
19124
|
+
t27 += v * b15;
|
|
19125
|
+
v = a[13];
|
|
19126
|
+
t13 += v * b0;
|
|
19127
|
+
t14 += v * b1;
|
|
19128
|
+
t15 += v * b2;
|
|
19129
|
+
t16 += v * b3;
|
|
19130
|
+
t17 += v * b4;
|
|
19131
|
+
t18 += v * b5;
|
|
19132
|
+
t19 += v * b6;
|
|
19133
|
+
t20 += v * b7;
|
|
19134
|
+
t21 += v * b8;
|
|
19135
|
+
t22 += v * b9;
|
|
19136
|
+
t23 += v * b10;
|
|
19137
|
+
t24 += v * b11;
|
|
19138
|
+
t25 += v * b12;
|
|
19139
|
+
t26 += v * b13;
|
|
19140
|
+
t27 += v * b14;
|
|
19141
|
+
t28 += v * b15;
|
|
19142
|
+
v = a[14];
|
|
19143
|
+
t14 += v * b0;
|
|
19144
|
+
t15 += v * b1;
|
|
19145
|
+
t16 += v * b2;
|
|
19146
|
+
t17 += v * b3;
|
|
19147
|
+
t18 += v * b4;
|
|
19148
|
+
t19 += v * b5;
|
|
19149
|
+
t20 += v * b6;
|
|
19150
|
+
t21 += v * b7;
|
|
19151
|
+
t22 += v * b8;
|
|
19152
|
+
t23 += v * b9;
|
|
19153
|
+
t24 += v * b10;
|
|
19154
|
+
t25 += v * b11;
|
|
19155
|
+
t26 += v * b12;
|
|
19156
|
+
t27 += v * b13;
|
|
19157
|
+
t28 += v * b14;
|
|
19158
|
+
t29 += v * b15;
|
|
19159
|
+
v = a[15];
|
|
19160
|
+
t15 += v * b0;
|
|
19161
|
+
t16 += v * b1;
|
|
19162
|
+
t17 += v * b2;
|
|
19163
|
+
t18 += v * b3;
|
|
19164
|
+
t19 += v * b4;
|
|
19165
|
+
t20 += v * b5;
|
|
19166
|
+
t21 += v * b6;
|
|
19167
|
+
t22 += v * b7;
|
|
19168
|
+
t23 += v * b8;
|
|
19169
|
+
t24 += v * b9;
|
|
19170
|
+
t25 += v * b10;
|
|
19171
|
+
t26 += v * b11;
|
|
19172
|
+
t27 += v * b12;
|
|
19173
|
+
t28 += v * b13;
|
|
19174
|
+
t29 += v * b14;
|
|
19175
|
+
t30 += v * b15;
|
|
19176
|
+
|
|
19177
|
+
t0 += 38 * t16;
|
|
19178
|
+
t1 += 38 * t17;
|
|
19179
|
+
t2 += 38 * t18;
|
|
19180
|
+
t3 += 38 * t19;
|
|
19181
|
+
t4 += 38 * t20;
|
|
19182
|
+
t5 += 38 * t21;
|
|
19183
|
+
t6 += 38 * t22;
|
|
19184
|
+
t7 += 38 * t23;
|
|
19185
|
+
t8 += 38 * t24;
|
|
19186
|
+
t9 += 38 * t25;
|
|
19187
|
+
t10 += 38 * t26;
|
|
19188
|
+
t11 += 38 * t27;
|
|
19189
|
+
t12 += 38 * t28;
|
|
19190
|
+
t13 += 38 * t29;
|
|
19191
|
+
t14 += 38 * t30;
|
|
19192
|
+
// t15 left as is
|
|
19193
|
+
|
|
19194
|
+
// first car
|
|
19195
|
+
c = 1;
|
|
19196
|
+
v = t0 + c + 65535; c = Math.floor(v / 65536); t0 = v - c * 65536;
|
|
19197
|
+
v = t1 + c + 65535; c = Math.floor(v / 65536); t1 = v - c * 65536;
|
|
19198
|
+
v = t2 + c + 65535; c = Math.floor(v / 65536); t2 = v - c * 65536;
|
|
19199
|
+
v = t3 + c + 65535; c = Math.floor(v / 65536); t3 = v - c * 65536;
|
|
19200
|
+
v = t4 + c + 65535; c = Math.floor(v / 65536); t4 = v - c * 65536;
|
|
19201
|
+
v = t5 + c + 65535; c = Math.floor(v / 65536); t5 = v - c * 65536;
|
|
19202
|
+
v = t6 + c + 65535; c = Math.floor(v / 65536); t6 = v - c * 65536;
|
|
19203
|
+
v = t7 + c + 65535; c = Math.floor(v / 65536); t7 = v - c * 65536;
|
|
19204
|
+
v = t8 + c + 65535; c = Math.floor(v / 65536); t8 = v - c * 65536;
|
|
19205
|
+
v = t9 + c + 65535; c = Math.floor(v / 65536); t9 = v - c * 65536;
|
|
19206
|
+
v = t10 + c + 65535; c = Math.floor(v / 65536); t10 = v - c * 65536;
|
|
19207
|
+
v = t11 + c + 65535; c = Math.floor(v / 65536); t11 = v - c * 65536;
|
|
19208
|
+
v = t12 + c + 65535; c = Math.floor(v / 65536); t12 = v - c * 65536;
|
|
19209
|
+
v = t13 + c + 65535; c = Math.floor(v / 65536); t13 = v - c * 65536;
|
|
19210
|
+
v = t14 + c + 65535; c = Math.floor(v / 65536); t14 = v - c * 65536;
|
|
19211
|
+
v = t15 + c + 65535; c = Math.floor(v / 65536); t15 = v - c * 65536;
|
|
19212
|
+
t0 += c-1 + 37 * (c-1);
|
|
19213
|
+
|
|
19214
|
+
// second car
|
|
19215
|
+
c = 1;
|
|
19216
|
+
v = t0 + c + 65535; c = Math.floor(v / 65536); t0 = v - c * 65536;
|
|
19217
|
+
v = t1 + c + 65535; c = Math.floor(v / 65536); t1 = v - c * 65536;
|
|
19218
|
+
v = t2 + c + 65535; c = Math.floor(v / 65536); t2 = v - c * 65536;
|
|
19219
|
+
v = t3 + c + 65535; c = Math.floor(v / 65536); t3 = v - c * 65536;
|
|
19220
|
+
v = t4 + c + 65535; c = Math.floor(v / 65536); t4 = v - c * 65536;
|
|
19221
|
+
v = t5 + c + 65535; c = Math.floor(v / 65536); t5 = v - c * 65536;
|
|
19222
|
+
v = t6 + c + 65535; c = Math.floor(v / 65536); t6 = v - c * 65536;
|
|
19223
|
+
v = t7 + c + 65535; c = Math.floor(v / 65536); t7 = v - c * 65536;
|
|
19224
|
+
v = t8 + c + 65535; c = Math.floor(v / 65536); t8 = v - c * 65536;
|
|
19225
|
+
v = t9 + c + 65535; c = Math.floor(v / 65536); t9 = v - c * 65536;
|
|
19226
|
+
v = t10 + c + 65535; c = Math.floor(v / 65536); t10 = v - c * 65536;
|
|
19227
|
+
v = t11 + c + 65535; c = Math.floor(v / 65536); t11 = v - c * 65536;
|
|
19228
|
+
v = t12 + c + 65535; c = Math.floor(v / 65536); t12 = v - c * 65536;
|
|
19229
|
+
v = t13 + c + 65535; c = Math.floor(v / 65536); t13 = v - c * 65536;
|
|
19230
|
+
v = t14 + c + 65535; c = Math.floor(v / 65536); t14 = v - c * 65536;
|
|
19231
|
+
v = t15 + c + 65535; c = Math.floor(v / 65536); t15 = v - c * 65536;
|
|
19232
|
+
t0 += c-1 + 37 * (c-1);
|
|
19233
|
+
|
|
19234
|
+
o[ 0] = t0;
|
|
19235
|
+
o[ 1] = t1;
|
|
19236
|
+
o[ 2] = t2;
|
|
19237
|
+
o[ 3] = t3;
|
|
19238
|
+
o[ 4] = t4;
|
|
19239
|
+
o[ 5] = t5;
|
|
19240
|
+
o[ 6] = t6;
|
|
19241
|
+
o[ 7] = t7;
|
|
19242
|
+
o[ 8] = t8;
|
|
19243
|
+
o[ 9] = t9;
|
|
19244
|
+
o[10] = t10;
|
|
19245
|
+
o[11] = t11;
|
|
19246
|
+
o[12] = t12;
|
|
19247
|
+
o[13] = t13;
|
|
19248
|
+
o[14] = t14;
|
|
19249
|
+
o[15] = t15;
|
|
19250
|
+
}
|
|
19251
|
+
|
|
19252
|
+
function S(o, a) {
|
|
19253
|
+
M(o, a, a);
|
|
19254
|
+
}
|
|
19255
|
+
|
|
19256
|
+
function inv25519(o, i) {
|
|
19257
|
+
var c = gf();
|
|
19258
|
+
var a;
|
|
19259
|
+
for (a = 0; a < 16; a++) c[a] = i[a];
|
|
19260
|
+
for (a = 253; a >= 0; a--) {
|
|
19261
|
+
S(c, c);
|
|
19262
|
+
if(a !== 2 && a !== 4) M(c, c, i);
|
|
19263
|
+
}
|
|
19264
|
+
for (a = 0; a < 16; a++) o[a] = c[a];
|
|
19265
|
+
}
|
|
19266
|
+
|
|
19267
|
+
function pow2523(o, i) {
|
|
19268
|
+
var c = gf();
|
|
19269
|
+
var a;
|
|
19270
|
+
for (a = 0; a < 16; a++) c[a] = i[a];
|
|
19271
|
+
for (a = 250; a >= 0; a--) {
|
|
19272
|
+
S(c, c);
|
|
19273
|
+
if(a !== 1) M(c, c, i);
|
|
19274
|
+
}
|
|
19275
|
+
for (a = 0; a < 16; a++) o[a] = c[a];
|
|
19276
|
+
}
|
|
19277
|
+
|
|
19278
|
+
function crypto_scalarmult(q, n, p) {
|
|
19279
|
+
var z = new Uint8Array(32);
|
|
19280
|
+
var x = new Float64Array(80), r, i;
|
|
19281
|
+
var a = gf(), b = gf(), c = gf(),
|
|
19282
|
+
d = gf(), e = gf(), f = gf();
|
|
19283
|
+
for (i = 0; i < 31; i++) z[i] = n[i];
|
|
19284
|
+
z[31]=(n[31]&127)|64;
|
|
19285
|
+
z[0]&=248;
|
|
19286
|
+
unpack25519(x,p);
|
|
19287
|
+
for (i = 0; i < 16; i++) {
|
|
19288
|
+
b[i]=x[i];
|
|
19289
|
+
d[i]=a[i]=c[i]=0;
|
|
19290
|
+
}
|
|
19291
|
+
a[0]=d[0]=1;
|
|
19292
|
+
for (i=254; i>=0; --i) {
|
|
19293
|
+
r=(z[i>>>3]>>>(i&7))&1;
|
|
19294
|
+
sel25519(a,b,r);
|
|
19295
|
+
sel25519(c,d,r);
|
|
19296
|
+
A(e,a,c);
|
|
19297
|
+
Z(a,a,c);
|
|
19298
|
+
A(c,b,d);
|
|
19299
|
+
Z(b,b,d);
|
|
19300
|
+
S(d,e);
|
|
19301
|
+
S(f,a);
|
|
19302
|
+
M(a,c,a);
|
|
19303
|
+
M(c,b,e);
|
|
19304
|
+
A(e,a,c);
|
|
19305
|
+
Z(a,a,c);
|
|
19306
|
+
S(b,a);
|
|
19307
|
+
Z(c,d,f);
|
|
19308
|
+
M(a,c,_121665);
|
|
19309
|
+
A(a,a,d);
|
|
19310
|
+
M(c,c,a);
|
|
19311
|
+
M(a,d,f);
|
|
19312
|
+
M(d,b,x);
|
|
19313
|
+
S(b,e);
|
|
19314
|
+
sel25519(a,b,r);
|
|
19315
|
+
sel25519(c,d,r);
|
|
19316
|
+
}
|
|
19317
|
+
for (i = 0; i < 16; i++) {
|
|
19318
|
+
x[i+16]=a[i];
|
|
19319
|
+
x[i+32]=c[i];
|
|
19320
|
+
x[i+48]=b[i];
|
|
19321
|
+
x[i+64]=d[i];
|
|
19322
|
+
}
|
|
19323
|
+
var x32 = x.subarray(32);
|
|
19324
|
+
var x16 = x.subarray(16);
|
|
19325
|
+
inv25519(x32,x32);
|
|
19326
|
+
M(x16,x16,x32);
|
|
19327
|
+
pack25519(q,x16);
|
|
19328
|
+
return 0;
|
|
19329
|
+
}
|
|
19330
|
+
|
|
19331
|
+
function crypto_scalarmult_base(q, n) {
|
|
19332
|
+
return crypto_scalarmult(q, n, _9);
|
|
19333
|
+
}
|
|
19334
|
+
|
|
19335
|
+
function crypto_box_keypair(y, x) {
|
|
19336
|
+
randombytes(x, 32);
|
|
19337
|
+
return crypto_scalarmult_base(y, x);
|
|
19338
|
+
}
|
|
19339
|
+
|
|
19340
|
+
function crypto_box_beforenm(k, y, x) {
|
|
19341
|
+
var s = new Uint8Array(32);
|
|
19342
|
+
crypto_scalarmult(s, x, y);
|
|
19343
|
+
return crypto_core_hsalsa20(k, _0, s, sigma);
|
|
19344
|
+
}
|
|
19345
|
+
|
|
19346
|
+
var crypto_box_afternm = crypto_secretbox;
|
|
19347
|
+
var crypto_box_open_afternm = crypto_secretbox_open;
|
|
19348
|
+
|
|
19349
|
+
function crypto_box(c, m, d, n, y, x) {
|
|
19350
|
+
var k = new Uint8Array(32);
|
|
19351
|
+
crypto_box_beforenm(k, y, x);
|
|
19352
|
+
return crypto_box_afternm(c, m, d, n, k);
|
|
19353
|
+
}
|
|
19354
|
+
|
|
19355
|
+
function crypto_box_open(m, c, d, n, y, x) {
|
|
19356
|
+
var k = new Uint8Array(32);
|
|
19357
|
+
crypto_box_beforenm(k, y, x);
|
|
19358
|
+
return crypto_box_open_afternm(m, c, d, n, k);
|
|
19359
|
+
}
|
|
19360
|
+
|
|
19361
|
+
var K = [
|
|
19362
|
+
0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd,
|
|
19363
|
+
0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc,
|
|
19364
|
+
0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019,
|
|
19365
|
+
0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118,
|
|
19366
|
+
0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe,
|
|
19367
|
+
0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2,
|
|
19368
|
+
0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1,
|
|
19369
|
+
0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694,
|
|
19370
|
+
0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3,
|
|
19371
|
+
0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65,
|
|
19372
|
+
0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483,
|
|
19373
|
+
0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5,
|
|
19374
|
+
0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210,
|
|
19375
|
+
0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4,
|
|
19376
|
+
0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725,
|
|
19377
|
+
0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70,
|
|
19378
|
+
0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926,
|
|
19379
|
+
0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df,
|
|
19380
|
+
0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8,
|
|
19381
|
+
0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b,
|
|
19382
|
+
0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001,
|
|
19383
|
+
0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30,
|
|
19384
|
+
0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910,
|
|
19385
|
+
0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8,
|
|
19386
|
+
0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53,
|
|
19387
|
+
0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8,
|
|
19388
|
+
0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb,
|
|
19389
|
+
0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3,
|
|
19390
|
+
0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60,
|
|
19391
|
+
0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec,
|
|
19392
|
+
0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9,
|
|
19393
|
+
0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b,
|
|
19394
|
+
0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207,
|
|
19395
|
+
0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178,
|
|
19396
|
+
0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6,
|
|
19397
|
+
0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b,
|
|
19398
|
+
0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493,
|
|
19399
|
+
0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c,
|
|
19400
|
+
0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a,
|
|
19401
|
+
0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817
|
|
19402
|
+
];
|
|
19403
|
+
|
|
19404
|
+
function crypto_hashblocks_hl(hh, hl, m, n) {
|
|
19405
|
+
var wh = new Int32Array(16), wl = new Int32Array(16),
|
|
19406
|
+
bh0, bh1, bh2, bh3, bh4, bh5, bh6, bh7,
|
|
19407
|
+
bl0, bl1, bl2, bl3, bl4, bl5, bl6, bl7,
|
|
19408
|
+
th, tl, i, j, h, l, a, b, c, d;
|
|
19409
|
+
|
|
19410
|
+
var ah0 = hh[0],
|
|
19411
|
+
ah1 = hh[1],
|
|
19412
|
+
ah2 = hh[2],
|
|
19413
|
+
ah3 = hh[3],
|
|
19414
|
+
ah4 = hh[4],
|
|
19415
|
+
ah5 = hh[5],
|
|
19416
|
+
ah6 = hh[6],
|
|
19417
|
+
ah7 = hh[7],
|
|
19418
|
+
|
|
19419
|
+
al0 = hl[0],
|
|
19420
|
+
al1 = hl[1],
|
|
19421
|
+
al2 = hl[2],
|
|
19422
|
+
al3 = hl[3],
|
|
19423
|
+
al4 = hl[4],
|
|
19424
|
+
al5 = hl[5],
|
|
19425
|
+
al6 = hl[6],
|
|
19426
|
+
al7 = hl[7];
|
|
19427
|
+
|
|
19428
|
+
var pos = 0;
|
|
19429
|
+
while (n >= 128) {
|
|
19430
|
+
for (i = 0; i < 16; i++) {
|
|
19431
|
+
j = 8 * i + pos;
|
|
19432
|
+
wh[i] = (m[j+0] << 24) | (m[j+1] << 16) | (m[j+2] << 8) | m[j+3];
|
|
19433
|
+
wl[i] = (m[j+4] << 24) | (m[j+5] << 16) | (m[j+6] << 8) | m[j+7];
|
|
19434
|
+
}
|
|
19435
|
+
for (i = 0; i < 80; i++) {
|
|
19436
|
+
bh0 = ah0;
|
|
19437
|
+
bh1 = ah1;
|
|
19438
|
+
bh2 = ah2;
|
|
19439
|
+
bh3 = ah3;
|
|
19440
|
+
bh4 = ah4;
|
|
19441
|
+
bh5 = ah5;
|
|
19442
|
+
bh6 = ah6;
|
|
19443
|
+
bh7 = ah7;
|
|
19444
|
+
|
|
19445
|
+
bl0 = al0;
|
|
19446
|
+
bl1 = al1;
|
|
19447
|
+
bl2 = al2;
|
|
19448
|
+
bl3 = al3;
|
|
19449
|
+
bl4 = al4;
|
|
19450
|
+
bl5 = al5;
|
|
19451
|
+
bl6 = al6;
|
|
19452
|
+
bl7 = al7;
|
|
19453
|
+
|
|
19454
|
+
// add
|
|
19455
|
+
h = ah7;
|
|
19456
|
+
l = al7;
|
|
19457
|
+
|
|
19458
|
+
a = l & 0xffff; b = l >>> 16;
|
|
19459
|
+
c = h & 0xffff; d = h >>> 16;
|
|
19460
|
+
|
|
19461
|
+
// Sigma1
|
|
19462
|
+
h = ((ah4 >>> 14) | (al4 << (32-14))) ^ ((ah4 >>> 18) | (al4 << (32-18))) ^ ((al4 >>> (41-32)) | (ah4 << (32-(41-32))));
|
|
19463
|
+
l = ((al4 >>> 14) | (ah4 << (32-14))) ^ ((al4 >>> 18) | (ah4 << (32-18))) ^ ((ah4 >>> (41-32)) | (al4 << (32-(41-32))));
|
|
19464
|
+
|
|
19465
|
+
a += l & 0xffff; b += l >>> 16;
|
|
19466
|
+
c += h & 0xffff; d += h >>> 16;
|
|
19467
|
+
|
|
19468
|
+
// Ch
|
|
19469
|
+
h = (ah4 & ah5) ^ (~ah4 & ah6);
|
|
19470
|
+
l = (al4 & al5) ^ (~al4 & al6);
|
|
19471
|
+
|
|
19472
|
+
a += l & 0xffff; b += l >>> 16;
|
|
19473
|
+
c += h & 0xffff; d += h >>> 16;
|
|
19474
|
+
|
|
19475
|
+
// K
|
|
19476
|
+
h = K[i*2];
|
|
19477
|
+
l = K[i*2+1];
|
|
19478
|
+
|
|
19479
|
+
a += l & 0xffff; b += l >>> 16;
|
|
19480
|
+
c += h & 0xffff; d += h >>> 16;
|
|
19481
|
+
|
|
19482
|
+
// w
|
|
19483
|
+
h = wh[i%16];
|
|
19484
|
+
l = wl[i%16];
|
|
19485
|
+
|
|
19486
|
+
a += l & 0xffff; b += l >>> 16;
|
|
19487
|
+
c += h & 0xffff; d += h >>> 16;
|
|
19488
|
+
|
|
19489
|
+
b += a >>> 16;
|
|
19490
|
+
c += b >>> 16;
|
|
19491
|
+
d += c >>> 16;
|
|
19492
|
+
|
|
19493
|
+
th = c & 0xffff | d << 16;
|
|
19494
|
+
tl = a & 0xffff | b << 16;
|
|
19495
|
+
|
|
19496
|
+
// add
|
|
19497
|
+
h = th;
|
|
19498
|
+
l = tl;
|
|
19499
|
+
|
|
19500
|
+
a = l & 0xffff; b = l >>> 16;
|
|
19501
|
+
c = h & 0xffff; d = h >>> 16;
|
|
19502
|
+
|
|
19503
|
+
// Sigma0
|
|
19504
|
+
h = ((ah0 >>> 28) | (al0 << (32-28))) ^ ((al0 >>> (34-32)) | (ah0 << (32-(34-32)))) ^ ((al0 >>> (39-32)) | (ah0 << (32-(39-32))));
|
|
19505
|
+
l = ((al0 >>> 28) | (ah0 << (32-28))) ^ ((ah0 >>> (34-32)) | (al0 << (32-(34-32)))) ^ ((ah0 >>> (39-32)) | (al0 << (32-(39-32))));
|
|
19506
|
+
|
|
19507
|
+
a += l & 0xffff; b += l >>> 16;
|
|
19508
|
+
c += h & 0xffff; d += h >>> 16;
|
|
19509
|
+
|
|
19510
|
+
// Maj
|
|
19511
|
+
h = (ah0 & ah1) ^ (ah0 & ah2) ^ (ah1 & ah2);
|
|
19512
|
+
l = (al0 & al1) ^ (al0 & al2) ^ (al1 & al2);
|
|
19513
|
+
|
|
19514
|
+
a += l & 0xffff; b += l >>> 16;
|
|
19515
|
+
c += h & 0xffff; d += h >>> 16;
|
|
19516
|
+
|
|
19517
|
+
b += a >>> 16;
|
|
19518
|
+
c += b >>> 16;
|
|
19519
|
+
d += c >>> 16;
|
|
19520
|
+
|
|
19521
|
+
bh7 = (c & 0xffff) | (d << 16);
|
|
19522
|
+
bl7 = (a & 0xffff) | (b << 16);
|
|
19523
|
+
|
|
19524
|
+
// add
|
|
19525
|
+
h = bh3;
|
|
19526
|
+
l = bl3;
|
|
19527
|
+
|
|
19528
|
+
a = l & 0xffff; b = l >>> 16;
|
|
19529
|
+
c = h & 0xffff; d = h >>> 16;
|
|
19530
|
+
|
|
19531
|
+
h = th;
|
|
19532
|
+
l = tl;
|
|
19533
|
+
|
|
19534
|
+
a += l & 0xffff; b += l >>> 16;
|
|
19535
|
+
c += h & 0xffff; d += h >>> 16;
|
|
19536
|
+
|
|
19537
|
+
b += a >>> 16;
|
|
19538
|
+
c += b >>> 16;
|
|
19539
|
+
d += c >>> 16;
|
|
19540
|
+
|
|
19541
|
+
bh3 = (c & 0xffff) | (d << 16);
|
|
19542
|
+
bl3 = (a & 0xffff) | (b << 16);
|
|
19543
|
+
|
|
19544
|
+
ah1 = bh0;
|
|
19545
|
+
ah2 = bh1;
|
|
19546
|
+
ah3 = bh2;
|
|
19547
|
+
ah4 = bh3;
|
|
19548
|
+
ah5 = bh4;
|
|
19549
|
+
ah6 = bh5;
|
|
19550
|
+
ah7 = bh6;
|
|
19551
|
+
ah0 = bh7;
|
|
19552
|
+
|
|
19553
|
+
al1 = bl0;
|
|
19554
|
+
al2 = bl1;
|
|
19555
|
+
al3 = bl2;
|
|
19556
|
+
al4 = bl3;
|
|
19557
|
+
al5 = bl4;
|
|
19558
|
+
al6 = bl5;
|
|
19559
|
+
al7 = bl6;
|
|
19560
|
+
al0 = bl7;
|
|
19561
|
+
|
|
19562
|
+
if (i%16 === 15) {
|
|
19563
|
+
for (j = 0; j < 16; j++) {
|
|
19564
|
+
// add
|
|
19565
|
+
h = wh[j];
|
|
19566
|
+
l = wl[j];
|
|
19567
|
+
|
|
19568
|
+
a = l & 0xffff; b = l >>> 16;
|
|
19569
|
+
c = h & 0xffff; d = h >>> 16;
|
|
19570
|
+
|
|
19571
|
+
h = wh[(j+9)%16];
|
|
19572
|
+
l = wl[(j+9)%16];
|
|
19573
|
+
|
|
19574
|
+
a += l & 0xffff; b += l >>> 16;
|
|
19575
|
+
c += h & 0xffff; d += h >>> 16;
|
|
19576
|
+
|
|
19577
|
+
// sigma0
|
|
19578
|
+
th = wh[(j+1)%16];
|
|
19579
|
+
tl = wl[(j+1)%16];
|
|
19580
|
+
h = ((th >>> 1) | (tl << (32-1))) ^ ((th >>> 8) | (tl << (32-8))) ^ (th >>> 7);
|
|
19581
|
+
l = ((tl >>> 1) | (th << (32-1))) ^ ((tl >>> 8) | (th << (32-8))) ^ ((tl >>> 7) | (th << (32-7)));
|
|
19582
|
+
|
|
19583
|
+
a += l & 0xffff; b += l >>> 16;
|
|
19584
|
+
c += h & 0xffff; d += h >>> 16;
|
|
19585
|
+
|
|
19586
|
+
// sigma1
|
|
19587
|
+
th = wh[(j+14)%16];
|
|
19588
|
+
tl = wl[(j+14)%16];
|
|
19589
|
+
h = ((th >>> 19) | (tl << (32-19))) ^ ((tl >>> (61-32)) | (th << (32-(61-32)))) ^ (th >>> 6);
|
|
19590
|
+
l = ((tl >>> 19) | (th << (32-19))) ^ ((th >>> (61-32)) | (tl << (32-(61-32)))) ^ ((tl >>> 6) | (th << (32-6)));
|
|
19591
|
+
|
|
19592
|
+
a += l & 0xffff; b += l >>> 16;
|
|
19593
|
+
c += h & 0xffff; d += h >>> 16;
|
|
19594
|
+
|
|
19595
|
+
b += a >>> 16;
|
|
19596
|
+
c += b >>> 16;
|
|
19597
|
+
d += c >>> 16;
|
|
19598
|
+
|
|
19599
|
+
wh[j] = (c & 0xffff) | (d << 16);
|
|
19600
|
+
wl[j] = (a & 0xffff) | (b << 16);
|
|
19601
|
+
}
|
|
19602
|
+
}
|
|
19603
|
+
}
|
|
19604
|
+
|
|
19605
|
+
// add
|
|
19606
|
+
h = ah0;
|
|
19607
|
+
l = al0;
|
|
19608
|
+
|
|
19609
|
+
a = l & 0xffff; b = l >>> 16;
|
|
19610
|
+
c = h & 0xffff; d = h >>> 16;
|
|
19611
|
+
|
|
19612
|
+
h = hh[0];
|
|
19613
|
+
l = hl[0];
|
|
19614
|
+
|
|
19615
|
+
a += l & 0xffff; b += l >>> 16;
|
|
19616
|
+
c += h & 0xffff; d += h >>> 16;
|
|
19617
|
+
|
|
19618
|
+
b += a >>> 16;
|
|
19619
|
+
c += b >>> 16;
|
|
19620
|
+
d += c >>> 16;
|
|
19621
|
+
|
|
19622
|
+
hh[0] = ah0 = (c & 0xffff) | (d << 16);
|
|
19623
|
+
hl[0] = al0 = (a & 0xffff) | (b << 16);
|
|
19624
|
+
|
|
19625
|
+
h = ah1;
|
|
19626
|
+
l = al1;
|
|
19627
|
+
|
|
19628
|
+
a = l & 0xffff; b = l >>> 16;
|
|
19629
|
+
c = h & 0xffff; d = h >>> 16;
|
|
19630
|
+
|
|
19631
|
+
h = hh[1];
|
|
19632
|
+
l = hl[1];
|
|
19633
|
+
|
|
19634
|
+
a += l & 0xffff; b += l >>> 16;
|
|
19635
|
+
c += h & 0xffff; d += h >>> 16;
|
|
19636
|
+
|
|
19637
|
+
b += a >>> 16;
|
|
19638
|
+
c += b >>> 16;
|
|
19639
|
+
d += c >>> 16;
|
|
19640
|
+
|
|
19641
|
+
hh[1] = ah1 = (c & 0xffff) | (d << 16);
|
|
19642
|
+
hl[1] = al1 = (a & 0xffff) | (b << 16);
|
|
19643
|
+
|
|
19644
|
+
h = ah2;
|
|
19645
|
+
l = al2;
|
|
19646
|
+
|
|
19647
|
+
a = l & 0xffff; b = l >>> 16;
|
|
19648
|
+
c = h & 0xffff; d = h >>> 16;
|
|
19649
|
+
|
|
19650
|
+
h = hh[2];
|
|
19651
|
+
l = hl[2];
|
|
19652
|
+
|
|
19653
|
+
a += l & 0xffff; b += l >>> 16;
|
|
19654
|
+
c += h & 0xffff; d += h >>> 16;
|
|
19655
|
+
|
|
19656
|
+
b += a >>> 16;
|
|
19657
|
+
c += b >>> 16;
|
|
19658
|
+
d += c >>> 16;
|
|
19659
|
+
|
|
19660
|
+
hh[2] = ah2 = (c & 0xffff) | (d << 16);
|
|
19661
|
+
hl[2] = al2 = (a & 0xffff) | (b << 16);
|
|
19662
|
+
|
|
19663
|
+
h = ah3;
|
|
19664
|
+
l = al3;
|
|
19665
|
+
|
|
19666
|
+
a = l & 0xffff; b = l >>> 16;
|
|
19667
|
+
c = h & 0xffff; d = h >>> 16;
|
|
19668
|
+
|
|
19669
|
+
h = hh[3];
|
|
19670
|
+
l = hl[3];
|
|
19671
|
+
|
|
19672
|
+
a += l & 0xffff; b += l >>> 16;
|
|
19673
|
+
c += h & 0xffff; d += h >>> 16;
|
|
19674
|
+
|
|
19675
|
+
b += a >>> 16;
|
|
19676
|
+
c += b >>> 16;
|
|
19677
|
+
d += c >>> 16;
|
|
19678
|
+
|
|
19679
|
+
hh[3] = ah3 = (c & 0xffff) | (d << 16);
|
|
19680
|
+
hl[3] = al3 = (a & 0xffff) | (b << 16);
|
|
19681
|
+
|
|
19682
|
+
h = ah4;
|
|
19683
|
+
l = al4;
|
|
19684
|
+
|
|
19685
|
+
a = l & 0xffff; b = l >>> 16;
|
|
19686
|
+
c = h & 0xffff; d = h >>> 16;
|
|
19687
|
+
|
|
19688
|
+
h = hh[4];
|
|
19689
|
+
l = hl[4];
|
|
19690
|
+
|
|
19691
|
+
a += l & 0xffff; b += l >>> 16;
|
|
19692
|
+
c += h & 0xffff; d += h >>> 16;
|
|
19693
|
+
|
|
19694
|
+
b += a >>> 16;
|
|
19695
|
+
c += b >>> 16;
|
|
19696
|
+
d += c >>> 16;
|
|
19697
|
+
|
|
19698
|
+
hh[4] = ah4 = (c & 0xffff) | (d << 16);
|
|
19699
|
+
hl[4] = al4 = (a & 0xffff) | (b << 16);
|
|
19700
|
+
|
|
19701
|
+
h = ah5;
|
|
19702
|
+
l = al5;
|
|
19703
|
+
|
|
19704
|
+
a = l & 0xffff; b = l >>> 16;
|
|
19705
|
+
c = h & 0xffff; d = h >>> 16;
|
|
19706
|
+
|
|
19707
|
+
h = hh[5];
|
|
19708
|
+
l = hl[5];
|
|
19709
|
+
|
|
19710
|
+
a += l & 0xffff; b += l >>> 16;
|
|
19711
|
+
c += h & 0xffff; d += h >>> 16;
|
|
19712
|
+
|
|
19713
|
+
b += a >>> 16;
|
|
19714
|
+
c += b >>> 16;
|
|
19715
|
+
d += c >>> 16;
|
|
19716
|
+
|
|
19717
|
+
hh[5] = ah5 = (c & 0xffff) | (d << 16);
|
|
19718
|
+
hl[5] = al5 = (a & 0xffff) | (b << 16);
|
|
19719
|
+
|
|
19720
|
+
h = ah6;
|
|
19721
|
+
l = al6;
|
|
19722
|
+
|
|
19723
|
+
a = l & 0xffff; b = l >>> 16;
|
|
19724
|
+
c = h & 0xffff; d = h >>> 16;
|
|
19725
|
+
|
|
19726
|
+
h = hh[6];
|
|
19727
|
+
l = hl[6];
|
|
19728
|
+
|
|
19729
|
+
a += l & 0xffff; b += l >>> 16;
|
|
19730
|
+
c += h & 0xffff; d += h >>> 16;
|
|
19731
|
+
|
|
19732
|
+
b += a >>> 16;
|
|
19733
|
+
c += b >>> 16;
|
|
19734
|
+
d += c >>> 16;
|
|
19735
|
+
|
|
19736
|
+
hh[6] = ah6 = (c & 0xffff) | (d << 16);
|
|
19737
|
+
hl[6] = al6 = (a & 0xffff) | (b << 16);
|
|
19738
|
+
|
|
19739
|
+
h = ah7;
|
|
19740
|
+
l = al7;
|
|
19741
|
+
|
|
19742
|
+
a = l & 0xffff; b = l >>> 16;
|
|
19743
|
+
c = h & 0xffff; d = h >>> 16;
|
|
19744
|
+
|
|
19745
|
+
h = hh[7];
|
|
19746
|
+
l = hl[7];
|
|
19747
|
+
|
|
19748
|
+
a += l & 0xffff; b += l >>> 16;
|
|
19749
|
+
c += h & 0xffff; d += h >>> 16;
|
|
19750
|
+
|
|
19751
|
+
b += a >>> 16;
|
|
19752
|
+
c += b >>> 16;
|
|
19753
|
+
d += c >>> 16;
|
|
19754
|
+
|
|
19755
|
+
hh[7] = ah7 = (c & 0xffff) | (d << 16);
|
|
19756
|
+
hl[7] = al7 = (a & 0xffff) | (b << 16);
|
|
19757
|
+
|
|
19758
|
+
pos += 128;
|
|
19759
|
+
n -= 128;
|
|
19760
|
+
}
|
|
19761
|
+
|
|
19762
|
+
return n;
|
|
19763
|
+
}
|
|
19764
|
+
|
|
19765
|
+
function crypto_hash(out, m, n) {
|
|
19766
|
+
var hh = new Int32Array(8),
|
|
19767
|
+
hl = new Int32Array(8),
|
|
19768
|
+
x = new Uint8Array(256),
|
|
19769
|
+
i, b = n;
|
|
19770
|
+
|
|
19771
|
+
hh[0] = 0x6a09e667;
|
|
19772
|
+
hh[1] = 0xbb67ae85;
|
|
19773
|
+
hh[2] = 0x3c6ef372;
|
|
19774
|
+
hh[3] = 0xa54ff53a;
|
|
19775
|
+
hh[4] = 0x510e527f;
|
|
19776
|
+
hh[5] = 0x9b05688c;
|
|
19777
|
+
hh[6] = 0x1f83d9ab;
|
|
19778
|
+
hh[7] = 0x5be0cd19;
|
|
19779
|
+
|
|
19780
|
+
hl[0] = 0xf3bcc908;
|
|
19781
|
+
hl[1] = 0x84caa73b;
|
|
19782
|
+
hl[2] = 0xfe94f82b;
|
|
19783
|
+
hl[3] = 0x5f1d36f1;
|
|
19784
|
+
hl[4] = 0xade682d1;
|
|
19785
|
+
hl[5] = 0x2b3e6c1f;
|
|
19786
|
+
hl[6] = 0xfb41bd6b;
|
|
19787
|
+
hl[7] = 0x137e2179;
|
|
19788
|
+
|
|
19789
|
+
crypto_hashblocks_hl(hh, hl, m, n);
|
|
19790
|
+
n %= 128;
|
|
19791
|
+
|
|
19792
|
+
for (i = 0; i < n; i++) x[i] = m[b-n+i];
|
|
19793
|
+
x[n] = 128;
|
|
19794
|
+
|
|
19795
|
+
n = 256-128*(n<112?1:0);
|
|
19796
|
+
x[n-9] = 0;
|
|
19797
|
+
ts64(x, n-8, (b / 0x20000000) | 0, b << 3);
|
|
19798
|
+
crypto_hashblocks_hl(hh, hl, x, n);
|
|
19799
|
+
|
|
19800
|
+
for (i = 0; i < 8; i++) ts64(out, 8*i, hh[i], hl[i]);
|
|
19801
|
+
|
|
19802
|
+
return 0;
|
|
19803
|
+
}
|
|
19804
|
+
|
|
19805
|
+
function add(p, q) {
|
|
19806
|
+
var a = gf(), b = gf(), c = gf(),
|
|
19807
|
+
d = gf(), e = gf(), f = gf(),
|
|
19808
|
+
g = gf(), h = gf(), t = gf();
|
|
19809
|
+
|
|
19810
|
+
Z(a, p[1], p[0]);
|
|
19811
|
+
Z(t, q[1], q[0]);
|
|
19812
|
+
M(a, a, t);
|
|
19813
|
+
A(b, p[0], p[1]);
|
|
19814
|
+
A(t, q[0], q[1]);
|
|
19815
|
+
M(b, b, t);
|
|
19816
|
+
M(c, p[3], q[3]);
|
|
19817
|
+
M(c, c, D2);
|
|
19818
|
+
M(d, p[2], q[2]);
|
|
19819
|
+
A(d, d, d);
|
|
19820
|
+
Z(e, b, a);
|
|
19821
|
+
Z(f, d, c);
|
|
19822
|
+
A(g, d, c);
|
|
19823
|
+
A(h, b, a);
|
|
19824
|
+
|
|
19825
|
+
M(p[0], e, f);
|
|
19826
|
+
M(p[1], h, g);
|
|
19827
|
+
M(p[2], g, f);
|
|
19828
|
+
M(p[3], e, h);
|
|
19829
|
+
}
|
|
19830
|
+
|
|
19831
|
+
function cswap(p, q, b) {
|
|
19832
|
+
var i;
|
|
19833
|
+
for (i = 0; i < 4; i++) {
|
|
19834
|
+
sel25519(p[i], q[i], b);
|
|
19835
|
+
}
|
|
19836
|
+
}
|
|
19837
|
+
|
|
19838
|
+
function pack(r, p) {
|
|
19839
|
+
var tx = gf(), ty = gf(), zi = gf();
|
|
19840
|
+
inv25519(zi, p[2]);
|
|
19841
|
+
M(tx, p[0], zi);
|
|
19842
|
+
M(ty, p[1], zi);
|
|
19843
|
+
pack25519(r, ty);
|
|
19844
|
+
r[31] ^= par25519(tx) << 7;
|
|
19845
|
+
}
|
|
19846
|
+
|
|
19847
|
+
function scalarmult(p, q, s) {
|
|
19848
|
+
var b, i;
|
|
19849
|
+
set25519(p[0], gf0);
|
|
19850
|
+
set25519(p[1], gf1);
|
|
19851
|
+
set25519(p[2], gf1);
|
|
19852
|
+
set25519(p[3], gf0);
|
|
19853
|
+
for (i = 255; i >= 0; --i) {
|
|
19854
|
+
b = (s[(i/8)|0] >> (i&7)) & 1;
|
|
19855
|
+
cswap(p, q, b);
|
|
19856
|
+
add(q, p);
|
|
19857
|
+
add(p, p);
|
|
19858
|
+
cswap(p, q, b);
|
|
19859
|
+
}
|
|
19860
|
+
}
|
|
19861
|
+
|
|
19862
|
+
function scalarbase(p, s) {
|
|
19863
|
+
var q = [gf(), gf(), gf(), gf()];
|
|
19864
|
+
set25519(q[0], X);
|
|
19865
|
+
set25519(q[1], Y);
|
|
19866
|
+
set25519(q[2], gf1);
|
|
19867
|
+
M(q[3], X, Y);
|
|
19868
|
+
scalarmult(p, q, s);
|
|
19869
|
+
}
|
|
19870
|
+
|
|
19871
|
+
function crypto_sign_keypair(pk, sk, seeded) {
|
|
19872
|
+
var d = new Uint8Array(64);
|
|
19873
|
+
var p = [gf(), gf(), gf(), gf()];
|
|
19874
|
+
var i;
|
|
19875
|
+
|
|
19876
|
+
if (!seeded) randombytes(sk, 32);
|
|
19877
|
+
crypto_hash(d, sk, 32);
|
|
19878
|
+
d[0] &= 248;
|
|
19879
|
+
d[31] &= 127;
|
|
19880
|
+
d[31] |= 64;
|
|
19881
|
+
|
|
19882
|
+
scalarbase(p, d);
|
|
19883
|
+
pack(pk, p);
|
|
19884
|
+
|
|
19885
|
+
for (i = 0; i < 32; i++) sk[i+32] = pk[i];
|
|
19886
|
+
return 0;
|
|
19887
|
+
}
|
|
19888
|
+
|
|
19889
|
+
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]);
|
|
19890
|
+
|
|
19891
|
+
function modL(r, x) {
|
|
19892
|
+
var carry, i, j, k;
|
|
19893
|
+
for (i = 63; i >= 32; --i) {
|
|
19894
|
+
carry = 0;
|
|
19895
|
+
for (j = i - 32, k = i - 12; j < k; ++j) {
|
|
19896
|
+
x[j] += carry - 16 * x[i] * L[j - (i - 32)];
|
|
19897
|
+
carry = Math.floor((x[j] + 128) / 256);
|
|
19898
|
+
x[j] -= carry * 256;
|
|
19899
|
+
}
|
|
19900
|
+
x[j] += carry;
|
|
19901
|
+
x[i] = 0;
|
|
19902
|
+
}
|
|
19903
|
+
carry = 0;
|
|
19904
|
+
for (j = 0; j < 32; j++) {
|
|
19905
|
+
x[j] += carry - (x[31] >> 4) * L[j];
|
|
19906
|
+
carry = x[j] >> 8;
|
|
19907
|
+
x[j] &= 255;
|
|
19908
|
+
}
|
|
19909
|
+
for (j = 0; j < 32; j++) x[j] -= carry * L[j];
|
|
19910
|
+
for (i = 0; i < 32; i++) {
|
|
19911
|
+
x[i+1] += x[i] >> 8;
|
|
19912
|
+
r[i] = x[i] & 255;
|
|
19913
|
+
}
|
|
19914
|
+
}
|
|
19915
|
+
|
|
19916
|
+
function reduce(r) {
|
|
19917
|
+
var x = new Float64Array(64), i;
|
|
19918
|
+
for (i = 0; i < 64; i++) x[i] = r[i];
|
|
19919
|
+
for (i = 0; i < 64; i++) r[i] = 0;
|
|
19920
|
+
modL(r, x);
|
|
19921
|
+
}
|
|
19922
|
+
|
|
19923
|
+
// Note: difference from C - smlen returned, not passed as argument.
|
|
19924
|
+
function crypto_sign(sm, m, n, sk) {
|
|
19925
|
+
var d = new Uint8Array(64), h = new Uint8Array(64), r = new Uint8Array(64);
|
|
19926
|
+
var i, j, x = new Float64Array(64);
|
|
19927
|
+
var p = [gf(), gf(), gf(), gf()];
|
|
19928
|
+
|
|
19929
|
+
crypto_hash(d, sk, 32);
|
|
19930
|
+
d[0] &= 248;
|
|
19931
|
+
d[31] &= 127;
|
|
19932
|
+
d[31] |= 64;
|
|
19933
|
+
|
|
19934
|
+
var smlen = n + 64;
|
|
19935
|
+
for (i = 0; i < n; i++) sm[64 + i] = m[i];
|
|
19936
|
+
for (i = 0; i < 32; i++) sm[32 + i] = d[32 + i];
|
|
19937
|
+
|
|
19938
|
+
crypto_hash(r, sm.subarray(32), n+32);
|
|
19939
|
+
reduce(r);
|
|
19940
|
+
scalarbase(p, r);
|
|
19941
|
+
pack(sm, p);
|
|
19942
|
+
|
|
19943
|
+
for (i = 32; i < 64; i++) sm[i] = sk[i];
|
|
19944
|
+
crypto_hash(h, sm, n + 64);
|
|
19945
|
+
reduce(h);
|
|
19946
|
+
|
|
19947
|
+
for (i = 0; i < 64; i++) x[i] = 0;
|
|
19948
|
+
for (i = 0; i < 32; i++) x[i] = r[i];
|
|
19949
|
+
for (i = 0; i < 32; i++) {
|
|
19950
|
+
for (j = 0; j < 32; j++) {
|
|
19951
|
+
x[i+j] += h[i] * d[j];
|
|
19952
|
+
}
|
|
19953
|
+
}
|
|
19954
|
+
|
|
19955
|
+
modL(sm.subarray(32), x);
|
|
19956
|
+
return smlen;
|
|
19957
|
+
}
|
|
19958
|
+
|
|
19959
|
+
function unpackneg(r, p) {
|
|
19960
|
+
var t = gf(), chk = gf(), num = gf(),
|
|
19961
|
+
den = gf(), den2 = gf(), den4 = gf(),
|
|
19962
|
+
den6 = gf();
|
|
19963
|
+
|
|
19964
|
+
set25519(r[2], gf1);
|
|
19965
|
+
unpack25519(r[1], p);
|
|
19966
|
+
S(num, r[1]);
|
|
19967
|
+
M(den, num, D);
|
|
19968
|
+
Z(num, num, r[2]);
|
|
19969
|
+
A(den, r[2], den);
|
|
19970
|
+
|
|
19971
|
+
S(den2, den);
|
|
19972
|
+
S(den4, den2);
|
|
19973
|
+
M(den6, den4, den2);
|
|
19974
|
+
M(t, den6, num);
|
|
19975
|
+
M(t, t, den);
|
|
19976
|
+
|
|
19977
|
+
pow2523(t, t);
|
|
19978
|
+
M(t, t, num);
|
|
19979
|
+
M(t, t, den);
|
|
19980
|
+
M(t, t, den);
|
|
19981
|
+
M(r[0], t, den);
|
|
19982
|
+
|
|
19983
|
+
S(chk, r[0]);
|
|
19984
|
+
M(chk, chk, den);
|
|
19985
|
+
if (neq25519(chk, num)) M(r[0], r[0], I);
|
|
19986
|
+
|
|
19987
|
+
S(chk, r[0]);
|
|
19988
|
+
M(chk, chk, den);
|
|
19989
|
+
if (neq25519(chk, num)) return -1;
|
|
19990
|
+
|
|
19991
|
+
if (par25519(r[0]) === (p[31]>>7)) Z(r[0], gf0, r[0]);
|
|
19992
|
+
|
|
19993
|
+
M(r[3], r[0], r[1]);
|
|
19994
|
+
return 0;
|
|
19995
|
+
}
|
|
19996
|
+
|
|
19997
|
+
function crypto_sign_open(m, sm, n, pk) {
|
|
19998
|
+
var i;
|
|
19999
|
+
var t = new Uint8Array(32), h = new Uint8Array(64);
|
|
20000
|
+
var p = [gf(), gf(), gf(), gf()],
|
|
20001
|
+
q = [gf(), gf(), gf(), gf()];
|
|
20002
|
+
|
|
20003
|
+
if (n < 64) return -1;
|
|
20004
|
+
|
|
20005
|
+
if (unpackneg(q, pk)) return -1;
|
|
20006
|
+
|
|
20007
|
+
for (i = 0; i < n; i++) m[i] = sm[i];
|
|
20008
|
+
for (i = 0; i < 32; i++) m[i+32] = pk[i];
|
|
20009
|
+
crypto_hash(h, m, n);
|
|
20010
|
+
reduce(h);
|
|
20011
|
+
scalarmult(p, q, h);
|
|
20012
|
+
|
|
20013
|
+
scalarbase(q, sm.subarray(32));
|
|
20014
|
+
add(p, q);
|
|
20015
|
+
pack(t, p);
|
|
20016
|
+
|
|
20017
|
+
n -= 64;
|
|
20018
|
+
if (crypto_verify_32(sm, 0, t, 0)) {
|
|
20019
|
+
for (i = 0; i < n; i++) m[i] = 0;
|
|
20020
|
+
return -1;
|
|
20021
|
+
}
|
|
20022
|
+
|
|
20023
|
+
for (i = 0; i < n; i++) m[i] = sm[i + 64];
|
|
20024
|
+
return n;
|
|
20025
|
+
}
|
|
20026
|
+
|
|
20027
|
+
var crypto_secretbox_KEYBYTES = 32,
|
|
20028
|
+
crypto_secretbox_NONCEBYTES = 24,
|
|
20029
|
+
crypto_secretbox_ZEROBYTES = 32,
|
|
20030
|
+
crypto_secretbox_BOXZEROBYTES = 16,
|
|
20031
|
+
crypto_scalarmult_BYTES = 32,
|
|
20032
|
+
crypto_scalarmult_SCALARBYTES = 32,
|
|
20033
|
+
crypto_box_PUBLICKEYBYTES = 32,
|
|
20034
|
+
crypto_box_SECRETKEYBYTES = 32,
|
|
20035
|
+
crypto_box_BEFORENMBYTES = 32,
|
|
20036
|
+
crypto_box_NONCEBYTES = crypto_secretbox_NONCEBYTES,
|
|
20037
|
+
crypto_box_ZEROBYTES = crypto_secretbox_ZEROBYTES,
|
|
20038
|
+
crypto_box_BOXZEROBYTES = crypto_secretbox_BOXZEROBYTES,
|
|
20039
|
+
crypto_sign_BYTES = 64,
|
|
20040
|
+
crypto_sign_PUBLICKEYBYTES = 32,
|
|
20041
|
+
crypto_sign_SECRETKEYBYTES = 64,
|
|
20042
|
+
crypto_sign_SEEDBYTES = 32,
|
|
20043
|
+
crypto_hash_BYTES = 64;
|
|
20044
|
+
|
|
20045
|
+
nacl.lowlevel = {
|
|
20046
|
+
crypto_core_hsalsa20: crypto_core_hsalsa20,
|
|
20047
|
+
crypto_stream_xor: crypto_stream_xor,
|
|
20048
|
+
crypto_stream: crypto_stream,
|
|
20049
|
+
crypto_stream_salsa20_xor: crypto_stream_salsa20_xor,
|
|
20050
|
+
crypto_stream_salsa20: crypto_stream_salsa20,
|
|
20051
|
+
crypto_onetimeauth: crypto_onetimeauth,
|
|
20052
|
+
crypto_onetimeauth_verify: crypto_onetimeauth_verify,
|
|
20053
|
+
crypto_verify_16: crypto_verify_16,
|
|
20054
|
+
crypto_verify_32: crypto_verify_32,
|
|
20055
|
+
crypto_secretbox: crypto_secretbox,
|
|
20056
|
+
crypto_secretbox_open: crypto_secretbox_open,
|
|
20057
|
+
crypto_scalarmult: crypto_scalarmult,
|
|
20058
|
+
crypto_scalarmult_base: crypto_scalarmult_base,
|
|
20059
|
+
crypto_box_beforenm: crypto_box_beforenm,
|
|
20060
|
+
crypto_box_afternm: crypto_box_afternm,
|
|
20061
|
+
crypto_box: crypto_box,
|
|
20062
|
+
crypto_box_open: crypto_box_open,
|
|
20063
|
+
crypto_box_keypair: crypto_box_keypair,
|
|
20064
|
+
crypto_hash: crypto_hash,
|
|
20065
|
+
crypto_sign: crypto_sign,
|
|
20066
|
+
crypto_sign_keypair: crypto_sign_keypair,
|
|
20067
|
+
crypto_sign_open: crypto_sign_open,
|
|
20068
|
+
|
|
20069
|
+
crypto_secretbox_KEYBYTES: crypto_secretbox_KEYBYTES,
|
|
20070
|
+
crypto_secretbox_NONCEBYTES: crypto_secretbox_NONCEBYTES,
|
|
20071
|
+
crypto_secretbox_ZEROBYTES: crypto_secretbox_ZEROBYTES,
|
|
20072
|
+
crypto_secretbox_BOXZEROBYTES: crypto_secretbox_BOXZEROBYTES,
|
|
20073
|
+
crypto_scalarmult_BYTES: crypto_scalarmult_BYTES,
|
|
20074
|
+
crypto_scalarmult_SCALARBYTES: crypto_scalarmult_SCALARBYTES,
|
|
20075
|
+
crypto_box_PUBLICKEYBYTES: crypto_box_PUBLICKEYBYTES,
|
|
20076
|
+
crypto_box_SECRETKEYBYTES: crypto_box_SECRETKEYBYTES,
|
|
20077
|
+
crypto_box_BEFORENMBYTES: crypto_box_BEFORENMBYTES,
|
|
20078
|
+
crypto_box_NONCEBYTES: crypto_box_NONCEBYTES,
|
|
20079
|
+
crypto_box_ZEROBYTES: crypto_box_ZEROBYTES,
|
|
20080
|
+
crypto_box_BOXZEROBYTES: crypto_box_BOXZEROBYTES,
|
|
20081
|
+
crypto_sign_BYTES: crypto_sign_BYTES,
|
|
20082
|
+
crypto_sign_PUBLICKEYBYTES: crypto_sign_PUBLICKEYBYTES,
|
|
20083
|
+
crypto_sign_SECRETKEYBYTES: crypto_sign_SECRETKEYBYTES,
|
|
20084
|
+
crypto_sign_SEEDBYTES: crypto_sign_SEEDBYTES,
|
|
20085
|
+
crypto_hash_BYTES: crypto_hash_BYTES,
|
|
20086
|
+
|
|
20087
|
+
gf: gf,
|
|
20088
|
+
D: D,
|
|
20089
|
+
L: L,
|
|
20090
|
+
pack25519: pack25519,
|
|
20091
|
+
unpack25519: unpack25519,
|
|
20092
|
+
M: M,
|
|
20093
|
+
A: A,
|
|
20094
|
+
S: S,
|
|
20095
|
+
Z: Z,
|
|
20096
|
+
pow2523: pow2523,
|
|
20097
|
+
add: add,
|
|
20098
|
+
set25519: set25519,
|
|
20099
|
+
modL: modL,
|
|
20100
|
+
scalarmult: scalarmult,
|
|
20101
|
+
scalarbase: scalarbase,
|
|
20102
|
+
};
|
|
20103
|
+
|
|
20104
|
+
/* High-level API */
|
|
20105
|
+
|
|
20106
|
+
function checkLengths(k, n) {
|
|
20107
|
+
if (k.length !== crypto_secretbox_KEYBYTES) throw new Error('bad key size');
|
|
20108
|
+
if (n.length !== crypto_secretbox_NONCEBYTES) throw new Error('bad nonce size');
|
|
20109
|
+
}
|
|
20110
|
+
|
|
20111
|
+
function checkBoxLengths(pk, sk) {
|
|
20112
|
+
if (pk.length !== crypto_box_PUBLICKEYBYTES) throw new Error('bad public key size');
|
|
20113
|
+
if (sk.length !== crypto_box_SECRETKEYBYTES) throw new Error('bad secret key size');
|
|
20114
|
+
}
|
|
20115
|
+
|
|
20116
|
+
function checkArrayTypes() {
|
|
20117
|
+
for (var i = 0; i < arguments.length; i++) {
|
|
20118
|
+
if (!(arguments[i] instanceof Uint8Array))
|
|
20119
|
+
throw new TypeError('unexpected type, use Uint8Array');
|
|
20120
|
+
}
|
|
20121
|
+
}
|
|
20122
|
+
|
|
20123
|
+
function cleanup(arr) {
|
|
20124
|
+
for (var i = 0; i < arr.length; i++) arr[i] = 0;
|
|
20125
|
+
}
|
|
20126
|
+
|
|
20127
|
+
nacl.randomBytes = function(n) {
|
|
20128
|
+
var b = new Uint8Array(n);
|
|
20129
|
+
randombytes(b, n);
|
|
20130
|
+
return b;
|
|
20131
|
+
};
|
|
20132
|
+
|
|
20133
|
+
nacl.secretbox = function(msg, nonce, key) {
|
|
20134
|
+
checkArrayTypes(msg, nonce, key);
|
|
20135
|
+
checkLengths(key, nonce);
|
|
20136
|
+
var m = new Uint8Array(crypto_secretbox_ZEROBYTES + msg.length);
|
|
20137
|
+
var c = new Uint8Array(m.length);
|
|
20138
|
+
for (var i = 0; i < msg.length; i++) m[i+crypto_secretbox_ZEROBYTES] = msg[i];
|
|
20139
|
+
crypto_secretbox(c, m, m.length, nonce, key);
|
|
20140
|
+
return c.subarray(crypto_secretbox_BOXZEROBYTES);
|
|
20141
|
+
};
|
|
20142
|
+
|
|
20143
|
+
nacl.secretbox.open = function(box, nonce, key) {
|
|
20144
|
+
checkArrayTypes(box, nonce, key);
|
|
20145
|
+
checkLengths(key, nonce);
|
|
20146
|
+
var c = new Uint8Array(crypto_secretbox_BOXZEROBYTES + box.length);
|
|
20147
|
+
var m = new Uint8Array(c.length);
|
|
20148
|
+
for (var i = 0; i < box.length; i++) c[i+crypto_secretbox_BOXZEROBYTES] = box[i];
|
|
20149
|
+
if (c.length < 32) return null;
|
|
20150
|
+
if (crypto_secretbox_open(m, c, c.length, nonce, key) !== 0) return null;
|
|
20151
|
+
return m.subarray(crypto_secretbox_ZEROBYTES);
|
|
20152
|
+
};
|
|
20153
|
+
|
|
20154
|
+
nacl.secretbox.keyLength = crypto_secretbox_KEYBYTES;
|
|
20155
|
+
nacl.secretbox.nonceLength = crypto_secretbox_NONCEBYTES;
|
|
20156
|
+
nacl.secretbox.overheadLength = crypto_secretbox_BOXZEROBYTES;
|
|
20157
|
+
|
|
20158
|
+
nacl.scalarMult = function(n, p) {
|
|
20159
|
+
checkArrayTypes(n, p);
|
|
20160
|
+
if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error('bad n size');
|
|
20161
|
+
if (p.length !== crypto_scalarmult_BYTES) throw new Error('bad p size');
|
|
20162
|
+
var q = new Uint8Array(crypto_scalarmult_BYTES);
|
|
20163
|
+
crypto_scalarmult(q, n, p);
|
|
20164
|
+
return q;
|
|
20165
|
+
};
|
|
20166
|
+
|
|
20167
|
+
nacl.scalarMult.base = function(n) {
|
|
20168
|
+
checkArrayTypes(n);
|
|
20169
|
+
if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error('bad n size');
|
|
20170
|
+
var q = new Uint8Array(crypto_scalarmult_BYTES);
|
|
20171
|
+
crypto_scalarmult_base(q, n);
|
|
20172
|
+
return q;
|
|
20173
|
+
};
|
|
20174
|
+
|
|
20175
|
+
nacl.scalarMult.scalarLength = crypto_scalarmult_SCALARBYTES;
|
|
20176
|
+
nacl.scalarMult.groupElementLength = crypto_scalarmult_BYTES;
|
|
20177
|
+
|
|
20178
|
+
nacl.box = function(msg, nonce, publicKey, secretKey) {
|
|
20179
|
+
var k = nacl.box.before(publicKey, secretKey);
|
|
20180
|
+
return nacl.secretbox(msg, nonce, k);
|
|
20181
|
+
};
|
|
20182
|
+
|
|
20183
|
+
nacl.box.before = function(publicKey, secretKey) {
|
|
20184
|
+
checkArrayTypes(publicKey, secretKey);
|
|
20185
|
+
checkBoxLengths(publicKey, secretKey);
|
|
20186
|
+
var k = new Uint8Array(crypto_box_BEFORENMBYTES);
|
|
20187
|
+
crypto_box_beforenm(k, publicKey, secretKey);
|
|
20188
|
+
return k;
|
|
20189
|
+
};
|
|
20190
|
+
|
|
20191
|
+
nacl.box.after = nacl.secretbox;
|
|
20192
|
+
|
|
20193
|
+
nacl.box.open = function(msg, nonce, publicKey, secretKey) {
|
|
20194
|
+
var k = nacl.box.before(publicKey, secretKey);
|
|
20195
|
+
return nacl.secretbox.open(msg, nonce, k);
|
|
20196
|
+
};
|
|
20197
|
+
|
|
20198
|
+
nacl.box.open.after = nacl.secretbox.open;
|
|
20199
|
+
|
|
20200
|
+
nacl.box.keyPair = function() {
|
|
20201
|
+
var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES);
|
|
20202
|
+
var sk = new Uint8Array(crypto_box_SECRETKEYBYTES);
|
|
20203
|
+
crypto_box_keypair(pk, sk);
|
|
20204
|
+
return {publicKey: pk, secretKey: sk};
|
|
20205
|
+
};
|
|
20206
|
+
|
|
20207
|
+
nacl.box.keyPair.fromSecretKey = function(secretKey) {
|
|
20208
|
+
checkArrayTypes(secretKey);
|
|
20209
|
+
if (secretKey.length !== crypto_box_SECRETKEYBYTES)
|
|
20210
|
+
throw new Error('bad secret key size');
|
|
20211
|
+
var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES);
|
|
20212
|
+
crypto_scalarmult_base(pk, secretKey);
|
|
20213
|
+
return {publicKey: pk, secretKey: new Uint8Array(secretKey)};
|
|
20214
|
+
};
|
|
20215
|
+
|
|
20216
|
+
nacl.box.publicKeyLength = crypto_box_PUBLICKEYBYTES;
|
|
20217
|
+
nacl.box.secretKeyLength = crypto_box_SECRETKEYBYTES;
|
|
20218
|
+
nacl.box.sharedKeyLength = crypto_box_BEFORENMBYTES;
|
|
20219
|
+
nacl.box.nonceLength = crypto_box_NONCEBYTES;
|
|
20220
|
+
nacl.box.overheadLength = nacl.secretbox.overheadLength;
|
|
20221
|
+
|
|
20222
|
+
nacl.sign = function(msg, secretKey) {
|
|
20223
|
+
checkArrayTypes(msg, secretKey);
|
|
20224
|
+
if (secretKey.length !== crypto_sign_SECRETKEYBYTES)
|
|
20225
|
+
throw new Error('bad secret key size');
|
|
20226
|
+
var signedMsg = new Uint8Array(crypto_sign_BYTES+msg.length);
|
|
20227
|
+
crypto_sign(signedMsg, msg, msg.length, secretKey);
|
|
20228
|
+
return signedMsg;
|
|
20229
|
+
};
|
|
20230
|
+
|
|
20231
|
+
nacl.sign.open = function(signedMsg, publicKey) {
|
|
20232
|
+
checkArrayTypes(signedMsg, publicKey);
|
|
20233
|
+
if (publicKey.length !== crypto_sign_PUBLICKEYBYTES)
|
|
20234
|
+
throw new Error('bad public key size');
|
|
20235
|
+
var tmp = new Uint8Array(signedMsg.length);
|
|
20236
|
+
var mlen = crypto_sign_open(tmp, signedMsg, signedMsg.length, publicKey);
|
|
20237
|
+
if (mlen < 0) return null;
|
|
20238
|
+
var m = new Uint8Array(mlen);
|
|
20239
|
+
for (var i = 0; i < m.length; i++) m[i] = tmp[i];
|
|
20240
|
+
return m;
|
|
20241
|
+
};
|
|
20242
|
+
|
|
20243
|
+
nacl.sign.detached = function(msg, secretKey) {
|
|
20244
|
+
var signedMsg = nacl.sign(msg, secretKey);
|
|
20245
|
+
var sig = new Uint8Array(crypto_sign_BYTES);
|
|
20246
|
+
for (var i = 0; i < sig.length; i++) sig[i] = signedMsg[i];
|
|
20247
|
+
return sig;
|
|
20248
|
+
};
|
|
20249
|
+
|
|
20250
|
+
nacl.sign.detached.verify = function(msg, sig, publicKey) {
|
|
20251
|
+
checkArrayTypes(msg, sig, publicKey);
|
|
20252
|
+
if (sig.length !== crypto_sign_BYTES)
|
|
20253
|
+
throw new Error('bad signature size');
|
|
20254
|
+
if (publicKey.length !== crypto_sign_PUBLICKEYBYTES)
|
|
20255
|
+
throw new Error('bad public key size');
|
|
20256
|
+
var sm = new Uint8Array(crypto_sign_BYTES + msg.length);
|
|
20257
|
+
var m = new Uint8Array(crypto_sign_BYTES + msg.length);
|
|
20258
|
+
var i;
|
|
20259
|
+
for (i = 0; i < crypto_sign_BYTES; i++) sm[i] = sig[i];
|
|
20260
|
+
for (i = 0; i < msg.length; i++) sm[i+crypto_sign_BYTES] = msg[i];
|
|
20261
|
+
return (crypto_sign_open(m, sm, sm.length, publicKey) >= 0);
|
|
20262
|
+
};
|
|
20263
|
+
|
|
20264
|
+
nacl.sign.keyPair = function() {
|
|
20265
|
+
var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
|
|
20266
|
+
var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES);
|
|
20267
|
+
crypto_sign_keypair(pk, sk);
|
|
20268
|
+
return {publicKey: pk, secretKey: sk};
|
|
20269
|
+
};
|
|
20270
|
+
|
|
20271
|
+
nacl.sign.keyPair.fromSecretKey = function(secretKey) {
|
|
20272
|
+
checkArrayTypes(secretKey);
|
|
20273
|
+
if (secretKey.length !== crypto_sign_SECRETKEYBYTES)
|
|
20274
|
+
throw new Error('bad secret key size');
|
|
20275
|
+
var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
|
|
20276
|
+
for (var i = 0; i < pk.length; i++) pk[i] = secretKey[32+i];
|
|
20277
|
+
return {publicKey: pk, secretKey: new Uint8Array(secretKey)};
|
|
20278
|
+
};
|
|
20279
|
+
|
|
20280
|
+
nacl.sign.keyPair.fromSeed = function(seed) {
|
|
20281
|
+
checkArrayTypes(seed);
|
|
20282
|
+
if (seed.length !== crypto_sign_SEEDBYTES)
|
|
20283
|
+
throw new Error('bad seed size');
|
|
20284
|
+
var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
|
|
20285
|
+
var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES);
|
|
20286
|
+
for (var i = 0; i < 32; i++) sk[i] = seed[i];
|
|
20287
|
+
crypto_sign_keypair(pk, sk, true);
|
|
20288
|
+
return {publicKey: pk, secretKey: sk};
|
|
20289
|
+
};
|
|
20290
|
+
|
|
20291
|
+
nacl.sign.publicKeyLength = crypto_sign_PUBLICKEYBYTES;
|
|
20292
|
+
nacl.sign.secretKeyLength = crypto_sign_SECRETKEYBYTES;
|
|
20293
|
+
nacl.sign.seedLength = crypto_sign_SEEDBYTES;
|
|
20294
|
+
nacl.sign.signatureLength = crypto_sign_BYTES;
|
|
20295
|
+
|
|
20296
|
+
nacl.hash = function(msg) {
|
|
20297
|
+
checkArrayTypes(msg);
|
|
20298
|
+
var h = new Uint8Array(crypto_hash_BYTES);
|
|
20299
|
+
crypto_hash(h, msg, msg.length);
|
|
20300
|
+
return h;
|
|
20301
|
+
};
|
|
20302
|
+
|
|
20303
|
+
nacl.hash.hashLength = crypto_hash_BYTES;
|
|
20304
|
+
|
|
20305
|
+
nacl.verify = function(x, y) {
|
|
20306
|
+
checkArrayTypes(x, y);
|
|
20307
|
+
// Zero length arguments are considered not equal.
|
|
20308
|
+
if (x.length === 0 || y.length === 0) return false;
|
|
20309
|
+
if (x.length !== y.length) return false;
|
|
20310
|
+
return (vn(x, 0, y, 0, x.length) === 0) ? true : false;
|
|
20311
|
+
};
|
|
20312
|
+
|
|
20313
|
+
nacl.setPRNG = function(fn) {
|
|
20314
|
+
randombytes = fn;
|
|
20315
|
+
};
|
|
20316
|
+
|
|
20317
|
+
(function() {
|
|
20318
|
+
// Initialize PRNG if environment provides CSPRNG.
|
|
20319
|
+
// If not, methods calling randombytes will throw.
|
|
20320
|
+
var crypto = typeof self !== 'undefined' ? (self.crypto || self.msCrypto) : null;
|
|
20321
|
+
if (crypto && crypto.getRandomValues) {
|
|
20322
|
+
// Browsers.
|
|
20323
|
+
var QUOTA = 65536;
|
|
20324
|
+
nacl.setPRNG(function(x, n) {
|
|
20325
|
+
var i, v = new Uint8Array(n);
|
|
20326
|
+
for (i = 0; i < n; i += QUOTA) {
|
|
20327
|
+
crypto.getRandomValues(v.subarray(i, i + Math.min(n - i, QUOTA)));
|
|
20328
|
+
}
|
|
20329
|
+
for (i = 0; i < n; i++) x[i] = v[i];
|
|
20330
|
+
cleanup(v);
|
|
20331
|
+
});
|
|
20332
|
+
} else if (typeof commonjsRequire !== 'undefined') {
|
|
20333
|
+
// Node.js.
|
|
20334
|
+
crypto = require$$0;
|
|
20335
|
+
if (crypto && crypto.randomBytes) {
|
|
20336
|
+
nacl.setPRNG(function(x, n) {
|
|
20337
|
+
var i, v = crypto.randomBytes(n);
|
|
20338
|
+
for (i = 0; i < n; i++) x[i] = v[i];
|
|
20339
|
+
cleanup(v);
|
|
20340
|
+
});
|
|
20341
|
+
}
|
|
20342
|
+
}
|
|
20343
|
+
})();
|
|
20344
|
+
|
|
20345
|
+
})(module.exports ? module.exports : (self.nacl = self.nacl || {}));
|
|
20346
|
+
} (naclFast));
|
|
20347
|
+
return naclFast.exports;
|
|
20348
|
+
}
|
|
20349
|
+
|
|
20350
|
+
var naclFastExports = requireNaclFast();
|
|
20351
|
+
var nacl = /*@__PURE__*/getDefaultExportFromCjs$1(naclFastExports);
|
|
20352
|
+
|
|
17821
20353
|
// guest-keystore.ts — durable per-device keypair for anonymous ("guest") auth.
|
|
17822
20354
|
//
|
|
17823
20355
|
// A guest is an ed25519 keypair generated on the device. Its public key is the
|
|
@@ -19462,7 +21994,7 @@ async function loadDependencies() {
|
|
|
19462
21994
|
const [reactModule, reactDomModule, phantomModule] = await Promise.all([
|
|
19463
21995
|
import('react'),
|
|
19464
21996
|
import('react-dom/client'),
|
|
19465
|
-
import('./index-
|
|
21997
|
+
import('./index-DAI10qql.esm.js')
|
|
19466
21998
|
]);
|
|
19467
21999
|
// Extract default export from ESM module namespace
|
|
19468
22000
|
// Dynamic import() returns { default: Module, ...exports }, not the module directly
|
|
@@ -21363,7 +23895,7 @@ async function registerMobileWalletAdapter(config) {
|
|
|
21363
23895
|
if (typeof window === 'undefined')
|
|
21364
23896
|
return;
|
|
21365
23897
|
try {
|
|
21366
|
-
const walletStandardMobile = await import('./index.browser-
|
|
23898
|
+
const walletStandardMobile = await import('./index.browser-BxwM4axz.esm.js');
|
|
21367
23899
|
const registerMwa = walletStandardMobile.registerMwa || ((_a = walletStandardMobile.default) === null || _a === void 0 ? void 0 : _a.registerMwa);
|
|
21368
23900
|
if (!registerMwa) {
|
|
21369
23901
|
console.warn('[SolanaMobileWallet] registerMwa not found in @solana-mobile/wallet-standard-mobile');
|
|
@@ -21502,7 +24034,7 @@ class SolanaMobileWalletProvider {
|
|
|
21502
24034
|
async ensureWallet() {
|
|
21503
24035
|
if (this.wallet)
|
|
21504
24036
|
return this.wallet;
|
|
21505
|
-
const mod = await import('./index.browser-
|
|
24037
|
+
const mod = await import('./index.browser-BxwM4axz.esm.js');
|
|
21506
24038
|
const chain = mapChainToWalletStandard(this.cluster);
|
|
21507
24039
|
this.wallet = new mod.LocalSolanaMobileWalletAdapterWallet({
|
|
21508
24040
|
appIdentity: this.appIdentity,
|
|
@@ -23635,5 +26167,5 @@ class PrivyExpoProvider {
|
|
|
23635
26167
|
}
|
|
23636
26168
|
}
|
|
23637
26169
|
|
|
23638
|
-
export {
|
|
23639
|
-
//# sourceMappingURL=index-
|
|
26170
|
+
export { registerMobileWalletAdapter as $, setMany as A, setFile as B, getFiles as C, search as D, queryAggregate as E, runQuery as F, runQueryMany as G, runExpression as H, runExpressionMany as I, signMessage as J, signTransaction as K, signAndSubmitTransaction as L, count as M, aggregate as N, subscribe as O, useAuth as P, useQuery as Q, deserializeTransaction as R, getIdToken as S, setPlatform as T, getPlatform as U, PhantomWalletProvider as V, MockAuthProvider as W, DEFAULT_TEST_ADDRESS as X, OffchainAuthProvider as Y, SolanaMobileWalletProvider as Z, isMobileWalletAvailable as _, bs582 as a, PrivyWalletProvider as a0, PrivyExpoProvider as a1, EFFECT_INTENT_ADDRESS as a2, FunctionInvokeError as a3, InsufficientBalanceError as a4, LiveIntentError as a5, ReactNativeSessionManager as a6, RealtimeStore as a7, ServerSessionManager as a8, WebSessionManager as a9, serverTimestamp as aA, signSessionCreateMessage as aB, subscribeView as aC, toMillis as aD, toSeconds as aE, withEffects as aF, wsDelete as aG, wsGet as aH, wsGetMany as aI, wsQuery as aJ, wsSet as aK, buildSetDocumentsTransaction as aa, clearCache as ab, closeAllSubscriptions as ac, convertRemainingAccounts as ad, createSessionWithSignature as ae, defineLiveModule as af, deriveUserIdentityFromIdToken as ag, functions as ah, genAuthNonce as ai, genSolanaMessage as aj, getActiveSessionManager as ak, getCachedData as al, getRealtimeStore as am, getWebhookKeysUrl as an, hasActiveConnection as ao, increment as ap, invoke as aq, isEffectResult as ar, live as as, intent as at, status as au, now as av, reconnectWithNewAuth as aw, refreshSession as ax, resetRealtimeStore as ay, revokeSession 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, getMany as x, docId as y, set as z };
|
|
26171
|
+
//# sourceMappingURL=index-Oc5pQUDo.esm.js.map
|