Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

highwayhash

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

highwayhash

Node.js implementation of HighwayHash, Google's fast and strong AVX2+ hash function

  • 0.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
29
decreased by-14.71%
Maintainers
1
Weekly downloads
 
Created
Source

highwayhash

Node.js implementation of Google's AVX2+ HighwayHash.

Based on SipHash, it is believed to be robust against hash flooding and timing attacks because memory accesses are sequential and the algorithm is branch-free.

This makes it suitable for random number generators and hash tables storing untrusted data.

Expect data throughput of up to 11 GB/s, which translates to about 3 million operations/second when used with Node.js.

As JavaScript lacks native support for 64-bit integers, hash values are made available as string, Buffer and low/high 32-bit unsigned integer types.

If the input to be hashed is trusted, a cryptographically-insecure alternative is FarmHash. It can be almost an order of magnitude faster, especially for smaller inputs when only 32-bit hash values are required.

Requirements

Installation

npm install highwayhash

Usage

const highwayhash = require('highwayhash');
const key = new Buffer([
  0x55, 0xce, 0x85, 0x31, 0x06, 0x5e, 0xdc, 0x68,
  0x0b, 0x46, 0x14, 0xb6, 0x0c, 0xfe, 0x80, 0xcc,
  0x7d, 0xcf, 0x89, 0xe5, 0x83, 0xfe, 0x9a, 0xae,
  0x1c, 0x8b, 0xee, 0xeb, 0x3e, 0xe3, 0x1d, 0x1d
]);

const input = 'The quick brown fox jumped over the lazy sleeping dog';

const hashAsString = highwayhash.asString(key, input);
// '13898145506225518925'

const hashAsUInt32Low = highwayhash.asUInt32Low(key, input);
// 3477305677

const hashAsUInt32High = highwayhash.asUInt32High(key, input);
// 3235914163

const hashAsBuffer = highwayhash.asBuffer(key, input);
// <Buffer 4d 79 43 cf b3 21 e0 c0>

API

  • key is a Buffer containing 32 bytes (256-bit)
  • input is a Buffer to calculate a hash value of

asString(key, input)

Returns a String representing the 64-bit unsigned integer hash value of input.

asBuffer(key, input)

Returns a Buffer representing the 64-bit unsigned integer hash value of input.

This method is much slower then asString so only use this method when the hash value needs to be in a Buffer.

asUInt32Low(key, input)

Returns a Number representing the low 32-bits of the 64-bit unsigned integer hash value of input.

asUInt32High(key, input)

Returns a Number representing the high 32-bits of the 64-bit unsigned integer hash value of input.

Benchmarks

Intel i3-4170

Input size / bytesHash functionHash size / bitsOutput data typeOps/sec
100FarmHash32string9,007,638
100FarmHash64string1,702,653
100HighwayHash3232-bit int (low)4,338,413
100HighwayHash3232-bit int (high)4,372,574
100HighwayHash64string3,278,853
1000FarmHash32string3,352,427
1000FarmHash64string1,506,128
1000HighwayHash3232-bit int (low)3,090,887
1000HighwayHash3232-bit int (high)3,082,453
1000HighwayHash64string2,580,694
10000FarmHash32string1,535,208
10000FarmHash64string978,921
10000HighwayHash3232-bit int (low)1,082,865
10000HighwayHash3232-bit int (high)1,081,761
10000HighwayHash64string901,997
git clone https://github.com/lovell/highwayhash
cd highwayhash
npm install && npm test
cd bench
npm install && npm test

Licence

Copyright 2016 Lovell Fuller.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2015 Google Inc. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Keywords

FAQs

Package last updated on 11 Mar 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc