• Stars
    star
    210
  • Rank 181,570 (Top 4 %)
  • Language
    JavaScript
  • License
    Apache License 2.0
  • Created about 8 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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 / bytes Hash function Hash size / bits Output data type Ops/sec
100 md5 128 Buffer 577,384
100 sha256 256 Buffer 516,888
100 FarmHash 32 32-bit int 3,870,645
100 FarmHash 64 string 1,332,578
100 HighwayHash 32 32-bit int (low) 5,534,449
100 HighwayHash 32 32-bit int (high) 5,626,820
100 HighwayHash 64 string 2,583,533
100 HighwayHash 64 hex string 3,477,324
1000 md5 128 Buffer 343,203
1000 sha256 256 Buffer 259,395
1000 FarmHash 32 32-bit int 3,836,197
1000 FarmHash 64 string 1,219,728
1000 HighwayHash 32 32-bit int (low) 5,531,220
1000 HighwayHash 32 32-bit int (high) 5,609,610
1000 HighwayHash 64 string 2,616,148
1000 HighwayHash 64 hex string 3,520,123
10000 md5 128 Buffer 67,178
10000 sha256 256 Buffer 44,260
10000 FarmHash 32 32-bit int 1,462,781
10000 FarmHash 64 string 832,073
10000 HighwayHash 32 32-bit int (low) 3,949,544
10000 HighwayHash 32 32-bit int (high) 3,974,480
10000 HighwayHash 64 string 2,613,013
10000 HighwayHash 64 hex string 3,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.

More Repositories

1

sharp

High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP, AVIF and TIFF images. Uses the libvips library.
JavaScript
27,645
star
2

limax

Node.js module to generate URL slugs. Another one? This one cares about i18n and transliterates non-Latin scripts to conform to the RFC3986 standard. Mostly API-compatible with similar modules.
JavaScript
572
star
3

farmhash

Node.js implementation of FarmHash, Google's family of high performance hash functions
JavaScript
378
star
4

sharp-libvips

Packaging scripts to prebuild libvips and its dependencies - you're probably looking for https://github.com/lovell/sharp
Shell
161
star
5

avif-cli

Command line utility to convert images to AVIF
JavaScript
139
star
6

hepburn

Node.js module for converting Japanese Hiragana and Katakana script to, and from, Romaji using Hepburn romanisation
JavaScript
124
star
7

64

High performance Base64 encoding and decoding for Node.js using SIMD (AVX2, AVX, SSE4.2, SSE4.1, SSSE3) acceleration
JavaScript
108
star
8

attention

No longer maintained - Node.js module to detect the dominant palette and salient region of an image
C++
56
star
9

detect-libc

Node.js module to detect details of the C standard library (libc) implementation provided by a given Linux system
JavaScript
55
star
10

icc

JavaScript module to parse International Color Consortium (ICC) profiles
JavaScript
54
star
11

shorter

Node.js module to very quickly (de)compress short strings. Uses the SIMD-powered entropy encoding features of shoco.
JavaScript
32
star
12

nginx-cache

Node.js module to find files in an Nginx cache based on partial URL keys
JavaScript
25
star
13

media-type

JavaScript module to parse and validate RFC6838 media types, anything from 'text/plain' to 'application/vnd.company.app.entity-v2+xml;charset=utf8'
JavaScript
15
star
14

libimagequant

libimagequant v2.4.1 fork (BSD-2-Clause) with support for building and cross-compiling via meson
C
11
star
15

uk-postcode

Node.js module for parsing and validating UK postcodes
JavaScript
11
star
16

cc

Code style linter for C++ source files used in Node.js native addons
JavaScript
10
star
17

cgif-packaging

Packaging scripts for cgif
Shell
8
star
18

package-libvips-darwin

Superseded by https://github.com/lovell/sharp-libvips
Ruby
5
star
19

deephouse.uk

Nunjucks
5
star
20

petra

Embed a caching, reverse HTTP proxy into an existing distributed ES6 web application
JavaScript
5
star
21

libvips-cpp-dll

DEPRECATED
JavaScript
2
star
22

aarch64-linux-musl-crosstools

Cross-compiler toolchain to produce linuxmusl-arm64v8 binaries on linuxmusl-x64
C++
2
star
23

rampart

Reverse HTTP proxy backed by distributed memory cache. Designed to protect APIs from intense GET request traffic spikes.
JavaScript
1
star
24

wi-scrapbook

Stoke Ferry WI Scrapbook 1965. Images are licensed under a Creative Commons BY-NC-SA 4.0 International License.
JavaScript
1
star
25

broad-norfolk

English to Broad Norfolk Translator
JavaScript
1
star
26

lovell.info

JavaScript
1
star
27

sharp-osx-ci

DEPRECATED
1
star
28

counted

Capture, store and track download_count values for assets distributed via Github Releases
JavaScript
1
star