src/crypto/siphash.js
function siphash24(data, key, shift) {
  const blocks = Math.floor(data.length / 8);
  const c0 = U64(0x736f6d65, 0x70736575);
  const c1 = U64(0x646f7261, 0x6e646f6d);
  const c2 = U64(0x6c796765, 0x6e657261);
  const c3 = U64(0x74656462, 0x79746573);
  const f0 = U64(blocks << (shift - 32), 0);
  const f1 = U64(0, 0xff);
  const k0 = U64.fromRaw(key, 0);
  const k1 = U64.fromRaw(key, 8);

  // Init
  const v0 = c0.ixor(k0);
  const v1 = c1.ixor(k1);
  const v2 = c2.ixor(k0);
  const v3 = c3.ixor(k1);

  // Blocks
  let p = 0;
  for (let i = 0; i < blocks; i++) {
    const d = U64.fromRaw(data, p);
    p += 8;
    v3.ixor(d);
    sipround(v0, v1, v2, v3);
    sipround(v0, v1, v2, v3);
    v0.ixor(d);
  }

  switch (data.length & 7) {
    case 7:
      f0.hi |= data[p + 6] << 16;
    case 6:
      f0.hi |= data[p + 5] << 8;
    case 5:
      f0.hi |= data[p + 4];
    case 4:
      f0.lo |= data[p + 3] << 24;
    case 3:
      f0.lo |= data[p + 2] << 16;
    case 2:
      f0.lo |= data[p + 1] << 8;
    case 1:
      f0.lo |= data[p];
  }

  // Finalization
  v3.ixor(f0);
  sipround(v0, v1, v2, v3);
  sipround(v0, v1, v2, v3);
  v0.ixor(f0);
  v2.ixor(f1);
  sipround(v0, v1, v2, v3);
  sipround(v0, v1, v2, v3);
  sipround(v0, v1, v2, v3);
  sipround(v0, v1, v2, v3);
  v0.ixor(v1);
  v0.ixor(v2);
  v0.ixor(v3);

  return [v0.hi, v0.lo];
}
function siphash24(data, key, shift) {
  const blocks = Math.floor(data.length / 8);
  const c0 = U64(0x736f6d65, 0x70736575);
  const c1 = U64(0x646f7261, 0x6e646f6d);
  const c2 = U64(0x6c796765, 0x6e657261);
  const c3 = U64(0x74656462, 0x79746573);
  const f0 = U64(blocks << (shift - 32), 0);
  const f1 = U64(0, 0xff);
  const k0 = U64.fromRaw(key, 0);
  const k1 = U64.fromRaw(key, 8);

  // Init
  const v0 = c0.ixor(k0);
  const v1 = c1.ixor(k1);
  const v2 = c2.ixor(k0);
  const v3 = c3.ixor(k1);

  // Blocks
  let p = 0;
  for (let i = 0; i < blocks; i++) {
    const d = U64.fromRaw(data, p);
    p += 8;
    v3.ixor(d);
    sipround(v0, v1, v2, v3);
    sipround(v0, v1, v2, v3);
    v0.ixor(d);
  }

  switch (data.length & 7) {
    case 7:
      f0.hi |= data[p + 6] << 16;
    case 6:
      f0.hi |= data[p + 5] << 8;
    case 5:
      f0.hi |= data[p + 4];
    case 4:
      f0.lo |= data[p + 3] << 24;
    case 3:
      f0.lo |= data[p + 2] << 16;
    case 2:
      f0.lo |= data[p + 1] << 8;
    case 1:
      f0.lo |= data[p];
  }

  // Finalization
  v3.ixor(f0);
  sipround(v0, v1, v2, v3);
  sipround(v0, v1, v2, v3);
  v0.ixor(f0);
  v2.ixor(f1);
  sipround(v0, v1, v2, v3);
  sipround(v0, v1, v2, v3);
  sipround(v0, v1, v2, v3);
  sipround(v0, v1, v2, v3);
  v0.ixor(v1);
  v0.ixor(v2);
  v0.ixor(v3);

  return [v0.hi, v0.lo];
}
function siphash24 ( data , key , shift ) { const blocks = Math . floor ( data . length / 8 ) ; const c0 = U64 ( 0x736f6d65 , 0x70736575 ) ; const c1 = U64 ( 0x646f7261 , 0x6e646f6d ) ; const c2 = U64 ( 0x6c796765 , 0x6e657261 ) ; const c3 = U64 ( 0x74656462 , 0x79746573 ) ; const f0 = U64 ( blocks << ( shift - 32 ) , 0 ) ; const f1 = U64 ( 0 , 0xff ) ; const k0 = U64 . fromRaw ( key , 0 ) ; const k1 = U64 . fromRaw ( key , 8 ) ; // Init const v0 = c0 . ixor ( k0 ) ; const v1 = c1 . ixor ( k1 ) ; const v2 = c2 . ixor ( k0 ) ; const v3 = c3 . ixor ( k1 ) ; // Blocks let p = 0 ; for ( let i = 0 ; i < blocks ; i ++ ) { const d = U64 . fromRaw ( data , p ) ; p += 8 ; v3 . ixor ( d ) ; sipround ( v0 , v1 , v2 , v3 ) ; sipround ( v0 , v1 , v2 , v3 ) ; v0 . ixor ( d ) ; } switch ( data . length & 7 ) { case 7 : f0 . hi |= data [ p + 6 ] << 16 ; case 6 : f0 . hi |= data [ p + 5 ] << 8 ; case 5 : f0 . hi |= data [ p + 4 ] ; case 4 : f0 . lo |= data [ p + 3 ] << 24 ; case 3 : f0 . lo |= data [ p + 2 ] << 16 ; case 2 : f0 . lo |= data [ p + 1 ] << 8 ; case 1 : f0 . lo |= data [ p ] ; } // Finalization v3 . ixor ( f0 ) ; sipround ( v0 , v1 , v2 , v3 ) ; sipround ( v0 , v1 , v2 , v3 ) ; v0 . ixor ( f0 ) ; v2 . ixor ( f1 ) ; sipround ( v0 , v1 , v2 , v3 ) ; sipround ( v0 , v1 , v2 , v3 ) ; sipround ( v0 , v1 , v2 , v3 ) ; sipround ( v0 , v1 , v2 , v3 ) ; v0 . ixor ( v1 ) ; v0 . ixor ( v2 ) ; v0 . ixor ( v3 ) ; return [ v0 . hi , v0 . lo ] ; }
Javascript siphash implementation. Used for compact block relay.
@alias module:crypto/siphash.siphash24
@param {Buffer} data
@param {Buffer} key - 128 bit key.
@returns {Array} [hi, lo]
Javascript siphash implementation . Used for compact block relay .