Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
resourceloader: Replace SHA1 with 32-bit FNV-1 as hash function
SHA-1 is not secure enough to be used as a cryptographic hash function, and its implementation in JavaScript is too long and too slow for it to be a good general-purpose hash function. And we currently throw away most of the work: SHA-1 produces 160-bit hash values, of which we keep 48. Although the JavaScript implementation is not exported, SHA-1 is a well-known hash function, and I'm willing to bet that sooner or later someone will move to make it accessible to other modules, at which point usage will start to spread. For ResourceLoader, the qualities we're looking for in a hash function are: * Already implemented in PHP * Easy to implement in JavaScript * Fast * Collision-resistant The requirement that hashes be cheap to compute in JavaScript narrows the field to 32-bit hash functions, because in JavaScript bitwise operators treat their operands as 32 bits, and arithmetic uses double-precision floats, which have a total precision of 53 bits. It's possible to work around these limitations, but it's a lot of extra work. The best match I found is the 32-bit variant of FNV-1, which is available in PHP as of version 5.4 (as 'fnv1a32'). The fnv132 JavaScript function is around ten times faster and eight times shorter than sha1. Change-Id: I1e4fb08d17948538d96f241b2464d594fdc14578
- Loading branch information
Showing
6 changed files
with
35 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters