3.1.1 • Published 3 years ago

highwayhash v3.1.1

Weekly downloads
428
License
Apache-2.0
Repository
github
Last release
3 years ago

highwayhash

Node.js implementation of Google's 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.

64-bit hash values are platform independent and will not change for a given input. This is important for applications that write hashes to persistent storage.

SIMD intrinsics (AVX2, SSE4.1) will be used when available at runtime.

Expect up to 8 million operations/second, depending on the length of the input and the output type required.

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

If the input to be hashed is trusted, a cryptographically-insecure alternative is FarmHash.

Pre-compiled binaries are provided for the most common platforms.

Requirements

  • x64 CPU
  • Node.js v10+

Installation

npm install highwayhash
yarn add highwayhash

Usage

const highwayhash = require('highwayhash');
const key = require('crypto').randomBytes(32);

const input = Buffer.from('The quick brown fox jumped over the lazy sleeping dog');

const hashAsString = highwayhash.asString(key, input);
// Example: '15456351453344120596'

const hashAsHexString = highwayhash.asHexString(key, input);
// Example: '143f2b6cc1fd7fd6'

const hashAsUInt32Low = highwayhash.asUInt32Low(key, input);
// Example: 1814773524

const hashAsUInt32High = highwayhash.asUInt32High(key, input);
// Example: 3598712257

const hashAsBuffer = highwayhash.asBuffer(key, input);
// Example: <Buffer 14 3f 2b 6c c1 fd 7f d6>

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.

asHexString(key, input)

Returns a hexadecimal String representing the 64-bit unsigned integer hash value of input. This is equivalent to but much faster than asBuffer().toString('hex').

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
  • Ubuntu 16.04.1 LTS
  • Node.js v6.9.4
  • Cryptographically strong pseudo-random input via OpenSSL's RAND_bytes
Input size / bytesHash functionHash size / bitsOutput data typeOps/sec
100md5128Buffer577,384
100sha256256Buffer516,888
100FarmHash3232-bit int3,870,645
100FarmHash64string1,332,578
100HighwayHash3232-bit int (low)5,534,449
100HighwayHash3232-bit int (high)5,626,820
100HighwayHash64string2,583,533
100HighwayHash64hex string3,477,324
1000md5128Buffer343,203
1000sha256256Buffer259,395
1000FarmHash3232-bit int3,836,197
1000FarmHash64string1,219,728
1000HighwayHash3232-bit int (low)5,531,220
1000HighwayHash3232-bit int (high)5,609,610
1000HighwayHash64string2,616,148
1000HighwayHash64hex string3,520,123
10000md5128Buffer67,178
10000sha256256Buffer44,260
10000FarmHash3232-bit int1,462,781
10000FarmHash64string832,073
10000HighwayHash3232-bit int (low)3,949,544
10000HighwayHash3232-bit int (high)3,974,480
10000HighwayHash64string2,613,013
10000HighwayHash64hex string3,537,567
git clone https://github.com/lovell/highwayhash
cd highwayhash
npm install && npm test
cd bench
npm install && npm test

Licence

Copyright 2016, 2017, 2018, 2019, 2020 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, 2016, 2017 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.

3.1.1

3 years ago

3.1.0

3 years ago

3.0.0

4 years ago

2.5.0

5 years ago

2.4.0

6 years ago

2.3.0

6 years ago

2.2.0

7 years ago

2.1.1

7 years ago

2.1.0

7 years ago

2.0.0

7 years ago

1.0.0

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago