diff --git a/lib/cli/etcher.js b/lib/cli/etcher.js index c9df30aa..5ce0d432 100644 --- a/lib/cli/etcher.js +++ b/lib/cli/etcher.js @@ -99,7 +99,7 @@ permissions.isElevated().then((elevated) => { const writer = new ImageWriter({ verify: options.check, unmountOnSuccess: options.unmount, - checksumAlgorithms: options.check ? [ 'sha512' ] : [] + checksumAlgorithms: options.check ? [ 'xxhash' ] : [] }) /** @@ -133,7 +133,7 @@ permissions.isElevated().then((elevated) => { exitCode = EXIT_CODES.GENERAL_ERROR console.log(` - ${result.device.device}: ${result.error.message}`) } else { - console.log(` - ${result.device.device}: ${result.checksum.sha512}`) + console.log(` - ${result.device.device}: ${result.checksum.xxhash}`) } }) } diff --git a/lib/gui/app/modules/image-writer.js b/lib/gui/app/modules/image-writer.js index ea59187c..71ab2dd0 100644 --- a/lib/gui/app/modules/image-writer.js +++ b/lib/gui/app/modules/image-writer.js @@ -192,7 +192,7 @@ exports.performWrite = (image, drives, onProgress) => { destinations: drives, validateWriteOnSuccess: settings.get('validateWriteOnSuccess'), unmountOnSuccess: settings.get('unmountOnSuccess'), - checksumAlgorithms: [ 'sha512' ] + checksumAlgorithms: [ 'xxhash' ] }) }) diff --git a/lib/sdk/writer/checksum-stream.js b/lib/sdk/writer/checksum-stream.js index 68e33cee..634ada7c 100644 --- a/lib/sdk/writer/checksum-stream.js +++ b/lib/sdk/writer/checksum-stream.js @@ -18,6 +18,7 @@ const stream = require('readable-stream') const crypto = require('crypto') +const xxhash = require('xxhash') const _ = require('lodash') /** @@ -66,7 +67,16 @@ class ChecksumStream extends stream.Transform { * const hash = this._createHash(algorithm) */ _createHash (algorithm) { - const hash = _.attempt(crypto.createHash, algorithm) + let hash = null + + if (algorithm === 'xxhash') { + // Seed value 0x45544348 = ASCII "ETCH" + const seed = 0x45544348 + const is64Bit = process.arch === 'x64' || process.arch === 'aarch64' + hash = new xxhash.Stream(seed, is64Bit ? 64 : 32) + } else { + hash = _.attempt(crypto.createHash, algorithm) + } if (_.isError(hash)) { hash.message += ` "${algorithm}"` diff --git a/lib/sdk/writer/index.js b/lib/sdk/writer/index.js index 8346339f..391f9ea1 100644 --- a/lib/sdk/writer/index.js +++ b/lib/sdk/writer/index.js @@ -810,7 +810,8 @@ class ImageWriter extends EventEmitter { fd: destination.fd, autoClose: false, start: 0, - end: size + end: size, + highWaterMark: 1048576 }) pipeline.bind(source, 'error') diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index e58d5784..9ae47ff1 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -9093,6 +9093,10 @@ "resolved": "https://registry.npmjs.org/xtend/-/xtend-2.1.2.tgz", "dev": true }, + "xxhash": { + "version": "0.2.4", + "resolved": "https://registry.npmjs.org/xxhash/-/xxhash-0.2.4.tgz" + }, "y18n": { "version": "3.2.1", "resolved": "https://registry.npmjs.org/y18n/-/y18n-3.2.1.tgz" diff --git a/package.json b/package.json index 60294fed..ee452ab9 100644 --- a/package.json +++ b/package.json @@ -91,6 +91,7 @@ "uuid": "3.0.1", "winusb-driver-generator": "1.1.7", "xml2js": "0.4.17", + "xxhash": "0.2.4", "yargs": "11.0.0", "yauzl": "2.6.0" },