{"id":13527390,"url":"https://github.com/lovell/highwayhash","last_synced_at":"2025-04-06T09:09:09.310Z","repository":{"id":57264202,"uuid":"53694952","full_name":"lovell/highwayhash","owner":"lovell","description":"Node.js implementation of HighwayHash, Google's fast and strong hash function","archived":false,"fork":false,"pushed_at":"2021-10-08T07:53:23.000Z","size":118,"stargazers_count":219,"open_issues_count":2,"forks_count":16,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-30T08:11:09.497Z","etag":null,"topics":["avx2","checksum","fingerprint","hash","highwayhash","javascript","nodejs","sse41"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lovell.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-03-11T20:29:24.000Z","updated_at":"2025-01-28T10:47:17.000Z","dependencies_parsed_at":"2022-08-25T02:51:59.736Z","dependency_job_id":null,"html_url":"https://github.com/lovell/highwayhash","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lovell%2Fhighwayhash","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lovell%2Fhighwayhash/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lovell%2Fhighwayhash/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lovell%2Fhighwayhash/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lovell","download_url":"https://codeload.github.com/lovell/highwayhash/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247457803,"owners_count":20941906,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["avx2","checksum","fingerprint","hash","highwayhash","javascript","nodejs","sse41"],"created_at":"2024-08-01T06:01:47.000Z","updated_at":"2025-04-06T09:09:09.294Z","avatar_url":"https://github.com/lovell.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# highwayhash\n\nNode.js implementation of Google's [HighwayHash](https://github.com/google/highwayhash).\n\nBased on [SipHash](https://en.wikipedia.org/wiki/SipHash),\nit is believed to be robust against hash flooding and timing attacks\nbecause memory accesses are sequential and the algorithm is branch-free.\n\nThis makes it suitable for random number generators and hash tables storing untrusted data.\n\n64-bit hash values are platform independent and will not change for a given input.\nThis is important for applications that write hashes to persistent storage.\n\nSIMD intrinsics (AVX2, SSE4.1) will be used when available at runtime.\n\nExpect up to 8 million operations/second,\ndepending on the length of the input and the output type required.\n\nAs JavaScript lacks native support for 64-bit integers,\nhash values are made available as hex, string, Buffer and\nlow/high 32-bit unsigned integer types.\n\nIf the input to be hashed is trusted,\na cryptographically-insecure alternative is\n[FarmHash](https://github.com/lovell/farmhash).\n\nPre-compiled binaries are provided for the most common platforms.\n\n## Requirements\n\n* x64 CPU\n* Node.js v10+\n\n## Installation\n\n```sh\nnpm install highwayhash\n```\n\n```sh\nyarn add highwayhash\n```\n\n## Usage\n\n```javascript\nconst highwayhash = require('highwayhash');\n```\n\n```javascript\nconst key = require('crypto').randomBytes(32);\n\nconst input = Buffer.from('The quick brown fox jumped over the lazy sleeping dog');\n\nconst hashAsString = highwayhash.asString(key, input);\n// Example: '15456351453344120596'\n\nconst hashAsHexString = highwayhash.asHexString(key, input);\n// Example: '143f2b6cc1fd7fd6'\n\nconst hashAsUInt32Low = highwayhash.asUInt32Low(key, input);\n// Example: 1814773524\n\nconst hashAsUInt32High = highwayhash.asUInt32High(key, input);\n// Example: 3598712257\n\nconst hashAsBuffer = highwayhash.asBuffer(key, input);\n// Example: \u003cBuffer 14 3f 2b 6c c1 fd 7f d6\u003e\n\n```\n\n## API\n\n* `key` is a Buffer containing 32 bytes (256-bit)\n* `input` is a Buffer to calculate a hash value of\n\n### asString(key, input)\n\nReturns a String representing the 64-bit unsigned integer hash value of `input`.\n\n### asHexString(key, input)\n\nReturns a hexadecimal String representing the 64-bit unsigned integer hash value of `input`.\nThis is equivalent to but much faster than `asBuffer().toString('hex')`.\n\n### asBuffer(key, input)\n\nReturns a Buffer representing the 64-bit unsigned integer hash value of `input`.\n\nThis method is much slower then `asString` so only use this method when the hash value needs to be in a Buffer.\n\n### asUInt32Low(key, input)\n\nReturns a Number representing the low 32-bits of the 64-bit unsigned integer hash value of `input`.\n\n### asUInt32High(key, input)\n\nReturns a Number representing the high 32-bits of the 64-bit unsigned integer hash value of `input`.\n\n## Benchmarks\n\n* [Intel i3-4170](http://ark.intel.com/products/77490/Intel-Core-i3-4170-Processor-3M-Cache-3_70-GHz)\n* Ubuntu 16.04.1 LTS\n* Node.js v6.9.4\n* Cryptographically strong pseudo-random input via OpenSSL's RAND_bytes\n\n| Input size / bytes | Hash function  | Hash size / bits | Output data type  | Ops/sec   |\n| -----------------: | :------------- | ---------------: | :---------------- | --------: |\n|                100 | md5            |              128 | Buffer            |   577,384 |\n|                100 | sha256         |              256 | Buffer            |   516,888 |\n|                100 | FarmHash       |               32 | 32-bit int        | 3,870,645 |\n|                100 | FarmHash       |               64 | string            | 1,332,578 |\n|                100 | HighwayHash    |               32 | 32-bit int (low)  | 5,534,449 |\n|                100 | HighwayHash    |               32 | 32-bit int (high) | 5,626,820 |\n|                100 | HighwayHash    |               64 | string            | 2,583,533 |\n|                100 | HighwayHash    |               64 | hex string        | 3,477,324 |\n|               1000 | md5            |              128 | Buffer            |   343,203 |\n|               1000 | sha256         |              256 | Buffer            |   259,395 |\n|               1000 | FarmHash       |               32 | 32-bit int        | 3,836,197 |\n|               1000 | FarmHash       |               64 | string            | 1,219,728 |\n|               1000 | HighwayHash    |               32 | 32-bit int (low)  | 5,531,220 |\n|               1000 | HighwayHash    |               32 | 32-bit int (high) | 5,609,610 |\n|               1000 | HighwayHash    |               64 | string            | 2,616,148 |\n|               1000 | HighwayHash    |               64 | hex string        | 3,520,123 |\n|              10000 | md5            |              128 | Buffer            |    67,178 |\n|              10000 | sha256         |              256 | Buffer            |    44,260 |\n|              10000 | FarmHash       |               32 | 32-bit int        | 1,462,781 |\n|              10000 | FarmHash       |               64 | string            |   832,073 |\n|              10000 | HighwayHash    |               32 | 32-bit int (low)  | 3,949,544 |\n|              10000 | HighwayHash    |               32 | 32-bit int (high) | 3,974,480 |\n|              10000 | HighwayHash    |               64 | string            | 2,613,013 |\n|              10000 | HighwayHash    |               64 | hex string        | 3,537,567 |\n\n```sh\ngit clone https://github.com/lovell/highwayhash\ncd highwayhash\nnpm install \u0026\u0026 npm test\ncd bench\nnpm install \u0026\u0026 npm test\n```\n\n## Licence\n\nCopyright 2016, 2017, 2018, 2019, 2020 Lovell Fuller.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n     http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n\nCopyright 2015, 2016, 2017 Google Inc. All Rights Reserved.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n     http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flovell%2Fhighwayhash","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flovell%2Fhighwayhash","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flovell%2Fhighwayhash/lists"}