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

bebb4185

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bebb4185 - npm Package Compare versions

Comparing version 1.1.0 to 1.1.1

62

js/hash.js

@@ -53,4 +53,4 @@ export const BEBB4185 = discohash;

function round( m64, m8 ) {
const len = m8.length;
function round( m64, m8, len ) {
//console.log(`rds0 = 0x${ds[0].toString(16).padStart(16,'0')} 0x${ds[1].toString(16).padStart(16,'0')} 0x${ds[2].toString(16).padStart(16,'0')} 0x${ds[3].toString(16).padStart(16,'0')}`);
let index = 0;

@@ -63,4 +63,7 @@ let sindex = 0;

T64[0] = m64[index] + BigInt(index) + C[0] + 1n;
ds[sindex] += rot(T64[0], R);
C[0] += ~m64[index] + 1n;
T64[0] = rot(T64[0], R);
//console.log(`rds1 = 0x${ds[0].toString(16).padStart(16,'0')} 0x${ds[1].toString(16).padStart(16,'0')} 0x${ds[2].toString(16).padStart(16,'0')} 0x${ds[3].toString(16).padStart(16,'0')}`);
ds[sindex] += T64[0];
T64[0] = ~m64[index] + 1n;
C[0] += T64[0];
if ( sindex == HSTATE64M ) {

@@ -73,2 +76,3 @@ mix(0);

sindex++;
//console.log(`rds2 = 0x${ds[0].toString(16).padStart(16,'0')} 0x${ds[1].toString(16).padStart(16,'0')} 0x${ds[2].toString(16).padStart(16,'0')} 0x${ds[3].toString(16).padStart(16,'0')}`);
}

@@ -80,11 +84,16 @@

sindex = index&(BSTATEM);
//console.log(`rds3 = 0x${ds[0].toString(16).padStart(16,'0')} 0x${ds[1].toString(16).padStart(16,'0')} 0x${ds[2].toString(16).padStart(16,'0')} 0x${ds[3].toString(16).padStart(16,'0')}`);
//console.log(index,len);
for( ; index < len; index++) {
T8[0] = m8[index] + index + C8[0] + 1;
ds8[sindex] = rot8(T8[0], 23);
C8[0] += ~m8[sindex] + 1;
ds8[sindex] += rot8(T8[0], 23);
T8[0] = ~m8[sindex] + 1;
C8[0] += T8[0];
//console.log(`rds4 = 0x${ds[0].toString(16).padStart(16,'0')} 0x${ds[1].toString(16).padStart(16,'0')} 0x${ds[2].toString(16).padStart(16,'0')} 0x${ds[3].toString(16).padStart(16,'0')}`);
mix(index%STATE64M);
if ( sindex >= STATEM ) {
if ( sindex >= BSTATEM ) {
sindex = -1;
}
sindex++;
//console.log(`rds5 = 0x${ds[0].toString(16).padStart(16,'0')} 0x${ds[1].toString(16).padStart(16,'0')} 0x${ds[2].toString(16).padStart(16,'0')} 0x${ds[3].toString(16).padStart(16,'0')}`);
}

@@ -95,2 +104,3 @@

mix(2);
//console.log(`rds6 = 0x${ds[0].toString(16).padStart(16,'0')} 0x${ds[1].toString(16).padStart(16,'0')} 0x${ds[2].toString(16).padStart(16,'0')} 0x${ds[3].toString(16).padStart(16,'0')}`);
}

@@ -101,2 +111,5 @@

// ref: "I say we take take-off, nuke the site from orbit, only way to be sure"
let wasString = false;
let len = key.length;
if ( typeof key == "string" ) {

@@ -108,10 +121,12 @@ const Key = [];

key = Key;
len = key.length*4;
if( len % 8 != 0 ) {
len += 4;
}
wasString = true;
}
let len = key.length*4;
if( len % 8 != 0 ) {
len += 4;
}
const key_buf = new ArrayBuffer(len);
const blen = len + (8-(len%8))%8;
//console.log(JSON.stringify(Array.from(key)), seed, len, blen);
const key_buf = new ArrayBuffer(blen);
const key8Arr = new Uint8Array(key_buf);

@@ -121,3 +136,7 @@ const key32Arr = new Uint32Array(key_buf);

key32Arr.set(key);
if ( wasString ) {
key32Arr.set(key);
} else {
key8Arr.set(key);
}

@@ -131,6 +150,7 @@ const seed_buf = new ArrayBuffer(16);

seed32Arr[0] -= seed;
// if seed mod doesn't work let's try reverse order of seed/key round calls
seed32Arr[1] = 1 + seed;
seed32Arr[2] = ~(1 - seed);
seed32Arr[3] = (1+seed) * 0xf00dacca;
seed32Arr[2] = 1 - seed;
seed32Arr[2] = ~seed32Arr[2];
seed32Arr[3] = 1 + seed;
seed32Arr[3] *= 0xf00dacca;

@@ -143,6 +163,8 @@ // nothing up my sleeve

round( key64Arr, key8Arr );
round( seed64Arr, seed8Arr );
round( ds, ds8 );
//console.log(`ds = 0x${ds[0].toString(16).padStart(16,'0')} 0x${ds[1].toString(16).padStart(16,'0')} 0x${ds[2].toString(16).padStart(16,'0')} 0x${ds[3].toString(16).padStart(16,'0')}`);
round( key64Arr, key8Arr, len );
round( seed64Arr, seed8Arr, 16 );
round( ds, ds8, STATE );
/**

@@ -149,0 +171,0 @@ console.log(`ds = ${ds[0]} ${ds[1]} ${ds[2]} ${ds[3]}\n`);

@@ -10,2 +10,7 @@ import {discohash} from './index.js';

smhasher_verification_value();
big_key_value();
big_key_value();
big_key_value();
big_key_value();
big_key_value();

@@ -18,2 +23,12 @@ function test() {

function swap(a,i,b,j) {
a[i] ^= b[j];
b[j] ^= a[i];
a[i] ^= b[j];
}
function swapb(a,i) {
a[i] = (a[i] << 4) | (a[i] >> 4);
}
function smhasher_verification_value() {

@@ -39,3 +54,4 @@ // Copied from <smhasher_repo>/src/KeysetTests.cpp

hout[0] = discohash(key.slice(0,i+1), seed );
hout[0] = discohash(key.slice(0,i), seed );
hashes.set( hash, i*hashbytes );

@@ -49,7 +65,32 @@ }

// verif[0] = hash[0] | (hash[1] << 8) | (hash[2] << 16) | (hash[3] << 24);
/**
swap(hash,0,hash,2);
swap(hash,1,hash,3);
swap(hash,2,hash,3);
swapb(hash,0);
**/
verif[0] = h32[0];
console.log(`JS verif val: 0x${verif[0].toString(16).padStart(8, '0')}`);
console.log(`JS verif val: 0x${verif[0].toString(2).padStart(32, '0')}`);
return verif[0];
}
function big_key_value() {
const A = new Array(51000).join('.').split('.');
const B = A.map((_,i) => {
return String.fromCodePoint(i);
});
const C = B.join('');
const start = Date.now();
const hash = discohash(C, 9999);
console.log("Hash", hash);
const end = Date.now();
const duration = (end-start);
const rate = (C.length*4*1000.0/duration)/1000000;
console.log("JS Rate MB/s", rate.toFixed(2));
}
{
"name": "bebb4185",
"version": "1.1.0",
"version": "1.1.1",
"description": "A super-fast SMHasher-passing non-cryptographic hash function.",

@@ -5,0 +5,0 @@ "main": "js/index.js",

@@ -9,13 +9,13 @@ # :city_sunrise: [Discohash](https://github.com/cris691/discohash)

A super-fast 64-bit non-cryptographic hash.
# Quick Facts
Tested at ~ 5GB/s @ 3Gz.
- A super-fast 64-bit non-cryptographic hash.
- Tested at ~ 5GB/s @ 3Gz.
- Passes all SMHasher tests.
- *Also known as*: **BEBB4185**
- Implemented in C++, and also a port to JS
Passes all SMHasher tests.
*Also known as*: **BEBB4185**
## Using
Use the c-code from this repository, or, for a JS implementation:
Use the C code from this repository, or, for a JS implementation:

@@ -35,5 +35,16 @@ ```console

```js
import {discohash} from './webmodules/bebb4185.js';
import {discohash} from './web_modules/bebb4185.js';
```
**Note:** JS implementation is currently WIP.
## JS Implementation
- The JS Implementation produces the same value hashes as the C++ implementation.
- The JS implementation is ~ 1000x slower than the C++ implementation.
- This is probably because of the use of BigInts to stand in for `uint64_t`
- It's possible to implement a 64-bit mult using 32-bit view which would remove the need for BigInt. I have no plan to do this.
## SMHasher verification value
The value is: `BEBB4185`

Sorry, the diff of this file is not supported yet

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