REF: remove scryptsy from sources (closes #3421)

This commit is contained in:
Overtorment 2021-07-23 19:56:41 +01:00
parent 2f6858327b
commit 5636e1f918
10 changed files with 3 additions and 567 deletions

View File

@ -1,50 +0,0 @@
3.0.0 / 2019-03-12
------------------
- **breaking** Import gives an object with two functions `scrypt` and `scryptSync`
- `scryptSync` is the old synchronus function.
- `scrypt` will return a promise with the buffer.
2.0.0 / 2016-05-26
------------------
- **breaking** Node v0.10 not supported anymore.
1.2.1 / 2015-03-01
------------------
- now using standard for code formatting
- now using `pbkdf2` module over `pbkdf2-sha256`, huge performance increase in Node
1.2.0 / 2014-12-11
------------------
- upgraded `pbkdf2-sha256` from `1.0.1` to `1.1.0`
- removed `browser` field for `crypto`; not-necessary anymore
1.1.0 / 2014-07-28
------------------
- added `progressCallback` (Nadav Ivgi / #4)[https://github.com/cryptocoinjs/scryptsy/pull/4]
1.0.0 / 2014-06-10
------------------
- moved tests to fixtures
- removed semilcolons per http://cryptocoinjs.com/about/contributing/#semicolons
- changed `module.exports.scrypt = funct..` to `module.exports = funct...`
- removed `terst` from dev deps
- upgraded `"pbkdf2-sha256": "~0.1.1"` to `"pbkdf2-sha256": "^1.0.1"`
- added `crypto-browserify` dev dep for `pbkdf2-sha256` tests
- added TravisCI
- added Coveralls
- added testling
0.2.0 / 2014-03-05
------------------
- made a lot of scrypt functions internal along with variables to make thread safe
0.1.0 / 2014-02-18
------------------
- changed spacing from 4 to 2
- removed unneeded JavaScript implementations. Using `pbkdf2-sha256` dep now.
- add browser test support
- convert from `Array` to typed arrays and `Buffer`
0.0.1 / 2014-02-18
------------------
- initial release. Forked from https://github.com/cheongwy/node-scrypt-js and added tests.

View File

@ -1,21 +0,0 @@
MIT License
Copyright (c) 2018 cryptocoinjs
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -1,157 +0,0 @@
scryptsy
========
[![build status](https://secure.travis-ci.org/cryptocoinjs/scryptsy.svg)](https://travis-ci.org/cryptocoinjs/scryptsy)
[![Coverage Status](https://img.shields.io/coveralls/cryptocoinjs/scryptsy.svg)](https://coveralls.io/r/cryptocoinjs/scryptsy)
[![Version](https://img.shields.io/npm/v/scryptsy.svg)](https://www.npmjs.org/package/scryptsy)
`scryptsy` is a pure Javascript implementation of the [scrypt][wiki] key derivation function that is fully compatible with Node.js and the browser (via Browserify).
Why?
----
`Scrypt` is an integral part of many crypto currencies. It's a part of the [BIP38](https://github.com/bitcoin/bips/blob/master/bip-0038.mediawiki) standard for encrypting private Bitcoin keys. It also serves as the [proof-of-work system](https://en.wikipedia.org/wiki/Proof-of-work_system) for many crypto currencies, most notably: Litecoin and Dogecoin.
Installation
------------
npm install --save scryptsy
Browserify Note
------------
When using a browserified bundle, be sure to add `setImmediate` as a shim.
Example
-------
```js
const scrypt = require('scryptsy')
async function main () {
var key = "pleaseletmein"
var salt = "SodiumChloride"
var data1 = scrypt(key, salt, 16384, 8, 1, 64)
console.log(data1.toString('hex'))
// => 7023bdcb3afd7348461c06cd81fd38ebfda8fbba904f8e3ea9b543f6545da1f2d5432955613f0fcf62d49705242a9af9e61e85dc0d651e40dfcf017b45575887
// async is actually slower, but it will free up the event loop occasionally
// which will allow for front end GUI elements to update and cause it to not
// freeze up.
// See benchmarks below
// Passing 300 below means every 300 iterations internally will call setImmediate once
var data2 = await scrypt.async(key, salt, 16384, 8, 1, 64, undefined, 300)
console.log(data2.toString('hex'))
// => 7023bdcb3afd7348461c06cd81fd38ebfda8fbba904f8e3ea9b543f6545da1f2d5432955613f0fcf62d49705242a9af9e61e85dc0d651e40dfcf017b45575887
}
main().catch(console.error)
```
Benchmarks
-------
Internal iterations are N * p, so changing r doesn't affect the number of calls to setImmediate.
Decreasing pI decreases performance in exchange for more frequently freeing the event loop.
(pI Default is 5000 loops per setImmediate call)
Note: these benchmarks were done on node v10 on a CPU with good single thread performance.
browsers show a much larger difference. Please tinker with the pI setting to balance between
performance and GUI responsiveness.
If `pI >= N`, setImmediate will only be called `p * 2` times total (on the i = 0 of each for loop).
```
---------------------------
time : type : (N,r,p,pI) (pI = promiseInterval)
---------------------------
2266 ms : sync (2^16,16,1)
2548 ms : async (2^16,16,1,5000)
12.44% increase
---------------------------
2616 ms : sync (2^16,1,16)
2995 ms : async (2^16,1,16,5000)
14.49% increase
---------------------------
2685 ms : sync (2^20,1,1)
3090 ms : async (2^20,1,1,5000)
15.08% increase
---------------------------
2235 ms : sync (2^16,16,1)
2627 ms : async (2^16,16,1,10)
17.54% increase
---------------------------
2592 ms : sync (2^16,1,16)
3305 ms : async (2^16,1,16,10)
27.51% increase
---------------------------
2705 ms : sync (2^20,1,1)
3363 ms : async (2^20,1,1,10)
24.33% increase
---------------------------
2278 ms : sync (2^16,16,1)
2773 ms : async (2^16,16,1,1)
21.73% increase
---------------------------
2617 ms : sync (2^16,1,16)
5632 ms : async (2^16,1,16,1)
115.21% increase
---------------------------
2727 ms : sync (2^20,1,1)
5723 ms : async (2^20,1,1,1)
109.86% increase
---------------------------
```
API
---
### scrypt(key, salt, N, r, p, keyLenBytes, [progressCallback])
- **key**: The key. Either `Buffer` or `string`.
- **salt**: The salt. Either `Buffer` or `string`.
- **N**: The number of iterations. `number` (integer)
- **r**: Memory factor. `number` (integer)
- **p**: Parallelization factor. `number` (integer)
- **keyLenBytes**: The number of bytes to return. `number` (integer)
- **progressCallback**: Call callback on every `1000` ops. Passes in `{current, total, percent}` as first parameter to `progressCallback()`.
Returns `Buffer`.
### scrypt.async(key, salt, N, r, p, keyLenBytes, [progressCallback, promiseInterval])
- **key**: The key. Either `Buffer` or `string`.
- **salt**: The salt. Either `Buffer` or `string`.
- **N**: The number of iterations. `number` (integer)
- **r**: Memory factor. `number` (integer)
- **p**: Parallelization factor. `number` (integer)
- **keyLenBytes**: The number of bytes to return. `number` (integer)
- **progressCallback**: Call callback on every `1000` ops. Passes in `{current, total, percent}` as first parameter to `progressCallback()`.
- **promiseInterval**: The number of internal iterations before calling setImmediate once to free the event loop.
Returns `Promise<Buffer>`.
Resources
---------
- [Tarsnap Blurb on Scrypt][tarsnap]
- [Scrypt Whitepaper](http://www.tarsnap.com/scrypt/scrypt.pdf)
- [IETF Scrypt](https://tools.ietf.org/html/draft-josefsson-scrypt-kdf-00) (Test vector params are [incorrect](https://twitter.com/dchest/status/247734446881640448).)
License
-------
MIT
[wiki]: https://en.wikipedia.org/wiki/Scrypt
[tarsnap]: https://www.tarsnap.com/scrypt.html

View File

@ -1,3 +0,0 @@
const scrypt = require('./scryptSync')
scrypt.async = require('./scrypt')
module.exports = scrypt

View File

@ -1,26 +0,0 @@
let pbkdf2 = require('pbkdf2')
const {
checkAndInit,
smix
} = require('./utils')
// N = Cpu cost, r = Memory cost, p = parallelization cost
async function scrypt (key, salt, N, r, p, dkLen, progressCallback, promiseInterval) {
const {
XY,
V,
B32,
x,
_X,
B,
tickCallback
} = checkAndInit(key, salt, N, r, p, dkLen, progressCallback)
for (var i = 0; i < p; i++) {
await smix(B, i * 128 * r, r, N, V, XY, _X, B32, x, tickCallback, promiseInterval)
}
return pbkdf2.pbkdf2Sync(key, B, 1, dkLen, 'sha256')
}
module.exports = scrypt

View File

@ -1,26 +0,0 @@
let pbkdf2 = require('pbkdf2')
const {
checkAndInit,
smixSync
} = require('./utils')
// N = Cpu cost, r = Memory cost, p = parallelization cost
function scrypt (key, salt, N, r, p, dkLen, progressCallback) {
const {
XY,
V,
B32,
x,
_X,
B,
tickCallback
} = checkAndInit(key, salt, N, r, p, dkLen, progressCallback)
for (var i = 0; i < p; i++) {
smixSync(B, i * 128 * r, r, N, V, XY, _X, B32, x, tickCallback)
}
return pbkdf2.pbkdf2Sync(key, B, 1, dkLen, 'sha256')
}
module.exports = scrypt

View File

@ -1,216 +0,0 @@
let pbkdf2 = require('pbkdf2')
const MAX_VALUE = 0x7fffffff
const DEFAULT_PROMISE_INTERVAL = 5000
/* eslint-disable camelcase */
function checkAndInit (key, salt, N, r, p, dkLen, progressCallback) {
if (N === 0 || (N & (N - 1)) !== 0) throw Error('N must be > 0 and a power of 2')
if (N > MAX_VALUE / 128 / r) throw Error('Parameter N is too large')
if (r > MAX_VALUE / 128 / p) throw Error('Parameter r is too large')
let XY = Buffer.alloc(256 * r)
let V = Buffer.alloc(128 * r * N)
// pseudo global
let B32 = new Int32Array(16) // salsa20_8
let x = new Int32Array(16) // salsa20_8
let _X = Buffer.alloc(64) // blockmix_salsa8
// pseudo global
let B = pbkdf2.pbkdf2Sync(key, salt, 1, p * 128 * r, 'sha256')
let tickCallback
if (progressCallback) {
let totalOps = p * N * 2
let currentOp = 0
tickCallback = function () {
++currentOp
// send progress notifications once every 1,000 ops
if (currentOp % 1000 === 0) {
progressCallback({
current: currentOp,
total: totalOps,
percent: (currentOp / totalOps) * 100.0
})
}
}
}
return {
XY,
V,
B32,
x,
_X,
B,
tickCallback
}
}
async function smix (B, Bi, r, N, V, XY, _X, B32, x, tickCallback, promiseInterval) {
promiseInterval = promiseInterval || DEFAULT_PROMISE_INTERVAL
let Xi = 0
let Yi = 128 * r
let i
B.copy(XY, Xi, Bi, Bi + Yi)
for (i = 0; i < N; i++) {
XY.copy(V, i * Yi, Xi, Xi + Yi)
if (i % promiseInterval === 0) {
await new Promise(resolve => setImmediate(resolve))
}
blockmix_salsa8(XY, Xi, Yi, r, _X, B32, x)
if (tickCallback) tickCallback()
}
for (i = 0; i < N; i++) {
let offset = Xi + (2 * r - 1) * 64
let j = XY.readUInt32LE(offset) & (N - 1)
blockxor(V, j * Yi, XY, Xi, Yi)
if (i % promiseInterval === 0) {
await new Promise(resolve => setImmediate(resolve))
}
blockmix_salsa8(XY, Xi, Yi, r, _X, B32, x)
if (tickCallback) tickCallback()
}
XY.copy(B, Bi, Xi, Xi + Yi)
}
function smixSync (B, Bi, r, N, V, XY, _X, B32, x, tickCallback) {
let Xi = 0
let Yi = 128 * r
let i
B.copy(XY, Xi, Bi, Bi + Yi)
for (i = 0; i < N; i++) {
XY.copy(V, i * Yi, Xi, Xi + Yi)
blockmix_salsa8(XY, Xi, Yi, r, _X, B32, x)
if (tickCallback) tickCallback()
}
for (i = 0; i < N; i++) {
let offset = Xi + (2 * r - 1) * 64
let j = XY.readUInt32LE(offset) & (N - 1)
blockxor(V, j * Yi, XY, Xi, Yi)
blockmix_salsa8(XY, Xi, Yi, r, _X, B32, x)
if (tickCallback) tickCallback()
}
XY.copy(B, Bi, Xi, Xi + Yi)
}
function blockmix_salsa8 (BY, Bi, Yi, r, _X, B32, x) {
let i
arraycopy(BY, Bi + (2 * r - 1) * 64, _X, 0, 64)
for (i = 0; i < 2 * r; i++) {
blockxor(BY, i * 64, _X, 0, 64)
salsa20_8(_X, B32, x)
arraycopy(_X, 0, BY, Yi + (i * 64), 64)
}
for (i = 0; i < r; i++) {
arraycopy(BY, Yi + (i * 2) * 64, BY, Bi + (i * 64), 64)
}
for (i = 0; i < r; i++) {
arraycopy(BY, Yi + (i * 2 + 1) * 64, BY, Bi + (i + r) * 64, 64)
}
}
function R (a, b) {
return (a << b) | (a >>> (32 - b))
}
function salsa20_8 (B, B32, x) {
let i
for (i = 0; i < 16; i++) {
B32[i] = (B[i * 4 + 0] & 0xff) << 0
B32[i] |= (B[i * 4 + 1] & 0xff) << 8
B32[i] |= (B[i * 4 + 2] & 0xff) << 16
B32[i] |= (B[i * 4 + 3] & 0xff) << 24
// B32[i] = B.readUInt32LE(i*4) <--- this is signficantly slower even in Node.js
}
arraycopy(B32, 0, x, 0, 16)
for (i = 8; i > 0; i -= 2) {
x[4] ^= R(x[0] + x[12], 7)
x[8] ^= R(x[4] + x[0], 9)
x[12] ^= R(x[8] + x[4], 13)
x[0] ^= R(x[12] + x[8], 18)
x[9] ^= R(x[5] + x[1], 7)
x[13] ^= R(x[9] + x[5], 9)
x[1] ^= R(x[13] + x[9], 13)
x[5] ^= R(x[1] + x[13], 18)
x[14] ^= R(x[10] + x[6], 7)
x[2] ^= R(x[14] + x[10], 9)
x[6] ^= R(x[2] + x[14], 13)
x[10] ^= R(x[6] + x[2], 18)
x[3] ^= R(x[15] + x[11], 7)
x[7] ^= R(x[3] + x[15], 9)
x[11] ^= R(x[7] + x[3], 13)
x[15] ^= R(x[11] + x[7], 18)
x[1] ^= R(x[0] + x[3], 7)
x[2] ^= R(x[1] + x[0], 9)
x[3] ^= R(x[2] + x[1], 13)
x[0] ^= R(x[3] + x[2], 18)
x[6] ^= R(x[5] + x[4], 7)
x[7] ^= R(x[6] + x[5], 9)
x[4] ^= R(x[7] + x[6], 13)
x[5] ^= R(x[4] + x[7], 18)
x[11] ^= R(x[10] + x[9], 7)
x[8] ^= R(x[11] + x[10], 9)
x[9] ^= R(x[8] + x[11], 13)
x[10] ^= R(x[9] + x[8], 18)
x[12] ^= R(x[15] + x[14], 7)
x[13] ^= R(x[12] + x[15], 9)
x[14] ^= R(x[13] + x[12], 13)
x[15] ^= R(x[14] + x[13], 18)
}
for (i = 0; i < 16; ++i) B32[i] = x[i] + B32[i]
for (i = 0; i < 16; i++) {
let bi = i * 4
B[bi + 0] = (B32[i] >> 0 & 0xff)
B[bi + 1] = (B32[i] >> 8 & 0xff)
B[bi + 2] = (B32[i] >> 16 & 0xff)
B[bi + 3] = (B32[i] >> 24 & 0xff)
// B.writeInt32LE(B32[i], i*4) //<--- this is signficantly slower even in Node.js
}
}
// naive approach... going back to loop unrolling may yield additional performance
function blockxor (S, Si, D, Di, len) {
for (let i = 0; i < len; i++) {
D[Di + i] ^= S[Si + i]
}
}
function arraycopy (src, srcPos, dest, destPos, length) {
if (Buffer.isBuffer(src) && Buffer.isBuffer(dest)) {
src.copy(dest, destPos, srcPos, srcPos + length)
} else {
while (length--) {
dest[destPos++] = src[srcPos++]
}
}
}
module.exports = {
checkAndInit,
smix,
smixSync
}

View File

@ -1,65 +0,0 @@
{
"_from": "scryptsy@2.1.0",
"_id": "scryptsy@2.1.0",
"_inBundle": false,
"_integrity": "sha512-1CdSqHQowJBnMAFyPEBRfqag/YP9OF394FV+4YREIJX4ljD7OxvQRDayyoyyCk+senRjSkP6VnUNQmVQqB6g7w==",
"_location": "/scryptsy",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "scryptsy@2.1.0",
"name": "scryptsy",
"escapedName": "scryptsy",
"rawSpec": "2.1.0",
"saveSpec": null,
"fetchSpec": "2.1.0"
},
"_requiredBy": [
"#USER",
"/"
],
"_resolved": "https://registry.npmjs.org/scryptsy/-/scryptsy-2.1.0.tgz",
"_shasum": "8d1e8d0c025b58fdd25b6fa9a0dc905ee8faa790",
"_spec": "scryptsy@2.1.0",
"_where": "/home/overtorment/Documents/BlueWallet",
"author": "",
"bugs": {
"url": "https://github.com/cryptocoinjs/scryptsy/issues"
},
"bundleDependencies": false,
"dependencies": {},
"deprecated": false,
"description": "Pure JavaScript implementation of the scrypt key deriviation function that is fully compatible with Node.js and the browser.",
"devDependencies": {},
"files": [
"lib"
],
"homepage": "https://github.com/cryptocoinjs/scryptsy#readme",
"keywords": [
"crytpo",
"cryptography",
"scrypt",
"kdf",
"litecoin",
"dogecoin",
"bitcoin",
"bip38"
],
"license": "MIT",
"main": "lib/index.js",
"name": "scryptsy",
"repository": {
"url": "git+ssh://git@github.com/cryptocoinjs/scryptsy.git",
"type": "git"
},
"scripts": {
"browser-test": "mochify --wd -R spec",
"coverage": "nyc --check-coverage --statements 80 --branches 60 --functions 90 --lines 90 mocha",
"coveralls": "npm run-script coverage && coveralls < coverage/lcov.info",
"lint": "standard",
"test": "mocha --ui bdd",
"unit": "mocha"
},
"version": "2.1.0"
}

3
package-lock.json generated
View File

@ -19573,7 +19573,8 @@
}
},
"scryptsy": {
"version": "file:blue_modules/scryptsy",
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/scryptsy/-/scryptsy-2.1.0.tgz",
"integrity": "sha512-1CdSqHQowJBnMAFyPEBRfqag/YP9OF394FV+4YREIJX4ljD7OxvQRDayyoyyCk+senRjSkP6VnUNQmVQqB6g7w=="
},
"secp256k1": {

View File

@ -137,7 +137,6 @@
"metro-react-native-babel-preset": "0.66.0",
"path-browserify": "1.0.1",
"payjoin-client": "1.0.0",
"pbkdf2": "3.1.1",
"process": "0.11.10",
"prop-types": "15.7.2",
"react": "17.0.1",
@ -192,7 +191,7 @@
"readable-stream": "3.6.0",
"realm": "10.6.0",
"rn-nodeify": "10.3.0",
"scryptsy": "file:blue_modules/scryptsy",
"scryptsy": "2.1.0",
"secure-random": "1.1.2",
"slip39": "file:blue_modules/slip39",
"stream-browserify": "2.0.2",