# siphash

> SipHash-2-4 fast short-input pseudo-random function

Latest version **1.2.0** (published 2024-12-10) · BSD-2-Clause license · 0 weekly downloads

## Install

```sh
npm install siphash
pnpm add siphash
yarn add siphash
bun add siphash
```

## Health

**Score 25/100 (F)** — status: maintenance-mode.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2024-12-10 |
| First published | 2012-06-23 |
| Weekly downloads | 0 |
| License | BSD-2-Clause |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 71 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 129 |
| Author | Frank Denis |
| Maintainers | jedisct1 |
| Keywords | prf, hash, crypto |

## Links

- npm: https://www.npmjs.com/package/siphash
- Repository: https://github.com/jedisct1/siphash-js
- Issues: https://github.com/jedisct1/siphash-js/issues
- npm.io page: https://npm.io/package/siphash

## Alternatives

- [@gemini-wallet/core](https://npm.io/package/@gemini-wallet/core.md) — 515.6K weekly downloads
- [utility](https://npm.io/package/utility.md) — 416.6K weekly downloads
- [@primno/dpapi](https://npm.io/package/@primno/dpapi.md) — 7.2K weekly downloads
- [pi-readseek](https://npm.io/package/pi-readseek.md) — 3.7K weekly downloads
- [@emilia-protocol/verify](https://npm.io/package/@emilia-protocol/verify.md) — 1.1K weekly downloads

## Recent versions

- 1.2.0 (latest) — 2024-12-10
- 1.1.0 — 2019-04-25
- 1.0.3 — 2016-12-12
- 1.0.1 — 2013-04-04
- 1.0.0 — 2012-06-23

## README

siphash.js
==========

A pure Javascript implementation of
[SipHash](https://www.aumasson.jp/siphash/siphash.pdf)

> SipHash is a family of pseudorandom functions optimized for short
> inputs. Target applications include network traffic authentication and
> hash-table lookups protected against hash-flooding denial-of-service
> attacks. SipHash has well-defined security goals and competitive
> performance.

This package also includes implementations of SipHash-1-3, SipHash128, and SipHash128-1-3.

Installation
------------

Server-side installation (io.js/nodejs):

    $ npm install siphash

Browser-side/single-line minified version: use
[lib/siphash.js.min](https://raw.githubusercontent.com/jedisct1/siphash-js/master/lib/siphash.js.min).

Usage
-----

```javascript
var siphash = require("siphash"),
    key = siphash.string16_to_key("This is the key!"),
    message = "Short test message",
    hash_hex = siphash.hash_hex(key, message);
```

A key is an array of 4 integers, and each of them will be clamped to
32 bits in order to build a 128-bit key.
For a random key, just generate 4 random integers instead of calling
`string16_to_key()`.

```javascript
var siphash = require("siphash"),
    key = [ 0xdeadbeef, 0xcafebabe, 0x8badf00d, 0x1badb002 ],
    message = "Short test message",
    hash_hex = siphash.hash_hex(key, message);
```

The 64-bit hash can also be obtained as two 32-bit values with
`hash(key, message)`:

```javascript
var siphash = require("siphash"),
    key = [ 0xdeadbeef, 0xcafebabe, 0x8badf00d, 0x1badb002 ],
    message = "Short test message",
    hash = siphash.hash(key, message),
    hash_msb = hash.h,
    hash_lsb = hash.l;
```

A 53-bit unsigned integer can be obtained with `hash_uint(key, message)`:

```javascript
var siphash = require("siphash"),
    key = siphash.string16_to_key("0123456789ABCDEF"),
    message = "Short test message",
    index = siphash.hash_uint(key, message);
```

SipHash-1-3
-----------
SipHash-1-3 is a faster variant of SipHash-2-4 with fewer rounds, which is still believed to be secure
enough for typical uses. This variant is available here:
[siphash13.js](https://raw.githubusercontent.com/jedisct1/siphash-js/master/lib/siphash13.js.min)


SipHash-double
--------------

Although not part of the module, an implementation of SipHash with
128-bit output is also available:
[siphash-double.js](https://raw.githubusercontent.com/jedisct1/siphash-js/master/lib/siphash-double.js.min)

SipHash-1-3 with a 128-bit output is also part of the package:
[siphash13-double.js](https://raw.githubusercontent.com/jedisct1/siphash-js/master/lib/siphash13-double.js.min)

---
_Source: https://npm.io/package/siphash · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
