mirror of
https://github.com/balena-io/etcher.git
synced 2025-07-19 09:16:38 +00:00
feat(writer): Use xxHash instead of SHA512 for verification
This switches from SHA512 to xxHash for verification hashing, as xxHash provides more throughput. Change-Type: patch
This commit is contained in:
parent
cbd531e161
commit
d3a4753b79
@ -99,7 +99,7 @@ permissions.isElevated().then((elevated) => {
|
|||||||
const writer = new ImageWriter({
|
const writer = new ImageWriter({
|
||||||
verify: options.check,
|
verify: options.check,
|
||||||
unmountOnSuccess: options.unmount,
|
unmountOnSuccess: options.unmount,
|
||||||
checksumAlgorithms: options.check ? [ 'sha512' ] : []
|
checksumAlgorithms: options.check ? [ 'xxhash' ] : []
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -133,7 +133,7 @@ permissions.isElevated().then((elevated) => {
|
|||||||
exitCode = EXIT_CODES.GENERAL_ERROR
|
exitCode = EXIT_CODES.GENERAL_ERROR
|
||||||
console.log(` - ${result.device.device}: ${result.error.message}`)
|
console.log(` - ${result.device.device}: ${result.error.message}`)
|
||||||
} else {
|
} else {
|
||||||
console.log(` - ${result.device.device}: ${result.checksum.sha512}`)
|
console.log(` - ${result.device.device}: ${result.checksum.xxhash}`)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -147,7 +147,7 @@ exports.performWrite = (image, drives, onProgress) => {
|
|||||||
destinations: drives,
|
destinations: drives,
|
||||||
validateWriteOnSuccess: settings.get('validateWriteOnSuccess'),
|
validateWriteOnSuccess: settings.get('validateWriteOnSuccess'),
|
||||||
unmountOnSuccess: settings.get('unmountOnSuccess'),
|
unmountOnSuccess: settings.get('unmountOnSuccess'),
|
||||||
checksumAlgorithms: [ 'sha512' ]
|
checksumAlgorithms: [ 'xxhash' ]
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
const stream = require('readable-stream')
|
const stream = require('readable-stream')
|
||||||
const crypto = require('crypto')
|
const crypto = require('crypto')
|
||||||
|
const xxhash = require('xxhash')
|
||||||
const _ = require('lodash')
|
const _ = require('lodash')
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -66,7 +67,16 @@ class ChecksumStream extends stream.Transform {
|
|||||||
* const hash = this._createHash(algorithm)
|
* const hash = this._createHash(algorithm)
|
||||||
*/
|
*/
|
||||||
_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)) {
|
if (_.isError(hash)) {
|
||||||
hash.message += ` "${algorithm}"`
|
hash.message += ` "${algorithm}"`
|
||||||
|
4
npm-shrinkwrap.json
generated
4
npm-shrinkwrap.json
generated
@ -9081,6 +9081,10 @@
|
|||||||
"resolved": "https://registry.npmjs.org/xtend/-/xtend-2.1.2.tgz",
|
"resolved": "https://registry.npmjs.org/xtend/-/xtend-2.1.2.tgz",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"xxhash": {
|
||||||
|
"version": "0.2.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/xxhash/-/xxhash-0.2.4.tgz"
|
||||||
|
},
|
||||||
"y18n": {
|
"y18n": {
|
||||||
"version": "3.2.1",
|
"version": "3.2.1",
|
||||||
"resolved": "https://registry.npmjs.org/y18n/-/y18n-3.2.1.tgz"
|
"resolved": "https://registry.npmjs.org/y18n/-/y18n-3.2.1.tgz"
|
||||||
|
@ -89,6 +89,7 @@
|
|||||||
"uuid": "3.0.1",
|
"uuid": "3.0.1",
|
||||||
"winusb-driver-generator": "1.1.7",
|
"winusb-driver-generator": "1.1.7",
|
||||||
"xml2js": "0.4.17",
|
"xml2js": "0.4.17",
|
||||||
|
"xxhash": "0.2.4",
|
||||||
"yargs": "11.0.0",
|
"yargs": "11.0.0",
|
||||||
"yauzl": "2.6.0"
|
"yauzl": "2.6.0"
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user