Example #1
0
var decryptBlock = function(self, input, index, out, outOff) {
  var w2 = (input[index + 0] << 8) + (input[index + 1] & 0xff);
  var w1 = (input[index + 2] << 8) + (input[index + 3] & 0xff);
  var w4 = (input[index + 4] << 8) + (input[index + 5] & 0xff);
  var w3 = (input[index + 6] << 8) + (input[index + 7] & 0xff);
  
  var k = 31;
  
  for (var t = 0; t < 2; t++) {
      for(var i = 0; i < 8; i++) {
          var tmp = w4;
          w4 = w3;
          w3 = w2;
          w2 = h(self, k, w1);
          w1 = w2 ^ tmp ^ (k + 1);
          k--;
      }

      for(var i = 0; i < 8; i++) {
          var tmp = w4;
          w4 = w3;
          w3 = w1 ^ w2 ^ (k + 1);
          w2 = h(self, k, w1);
          w1 = tmp;
          k--;
      }
  }

  util.inPlaceEncodeUInt16(w2, out, outOff + 0);
  util.inPlaceEncodeUInt16(w1, out, outOff + 2);
  util.inPlaceEncodeUInt16(w4, out, outOff + 4);
  util.inPlaceEncodeUInt16(w3, out, outOff + 6);
  return BlockSize;
}
Example #2
0
var encryptBlock = function(self, input, index, out, outOff) {
  var w1 = util.decodeUInt16(input, index);
  var w2 = util.decodeUInt16(input, index + 2);
  var w3 = util.decodeUInt16(input, index + 4);
  var w4 = util.decodeUInt16(input, index + 6);
  var k = 0;

  for(var t = 0; t < 2; t++) {
    for(var i = 0; i < 8; i++) {
      var tmp = w4;
      w4 = w3;
      w3 = w2;
      w2 = g(self, k, w1);
      w1 = w2 ^ tmp ^ (k + 1);
      k++;      
    }
    
    for(var i = 0; i < 8; i++) {
        var tmp = w4;
        w4 = w3;
        w3 = w1 ^ w2 ^ (k + 1);
        w2 = g(self, k, w1);
        w1 = tmp;
        k++;
    }        
  }
  
  util.inPlaceEncodeUInt16(w1, out, outOff + 0);
  util.inPlaceEncodeUInt16(w2, out, outOff + 2);
  util.inPlaceEncodeUInt16(w3, out, outOff + 4);
  util.inPlaceEncodeUInt16(w4, out, outOff + 6);
  return BlockSize;
}
Example #3
0
var cryptPair = function(block, key, index, out, outOff) {
  // Prepare the word array
  var word = [util.decodeUInt16(block, index)
    , util.decodeUInt16(block, index + 2)
    , util.decodeUInt16(block, index + 4)
    , util.decodeUInt16(block, index + 6)];
  var k = key.slice(0);
  
  for(var i = 8; i > 0; i--) {
    word[0] = Long.fromNumber(mul(word[0], k.shift())).getLowBitsUnsigned();
    word[1] = Long.fromNumber((word[1] + k.shift()) % USHORT).getLowBitsUnsigned();
    word[2] = Long.fromNumber((word[2] + k.shift()) % USHORT).getLowBitsUnsigned();
    word[3] = Long.fromNumber(mul(word[3], k.shift())).getLowBitsUnsigned();

    var t2 = Long.fromNumber(word[0] ^ word[2]).getLowBitsUnsigned();
    t2 = Long.fromNumber(mul(t2, k.shift())).getLowBitsUnsigned();
    var t1 = Long.fromNumber((t2 + (word[1] ^ word[3])) % USHORT).getLowBitsUnsigned();
    var v = k.shift()
    t1 = Long.fromNumber(mul(t1, v)).getLowBitsUnsigned();
    t2 = Long.fromNumber((t1 + t2) % USHORT).getLowBitsUnsigned();
    
    word[0] = Long.fromNumber(word[0] ^ t1).getLowBitsUnsigned();
    word[3] = Long.fromNumber(word[3] ^ t2).getLowBitsUnsigned();
    t2 = Long.fromNumber(t2 ^ word[1]).getLowBitsUnsigned();
    word[1] = Long.fromNumber(word[2] ^ t1).getLowBitsUnsigned();
    word[2] = t2
  }
  
  var result = [];
  result.push(Long.fromNumber(mul(word[0], k.shift())).getLowBitsUnsigned());
  result.push(word[2] + k.shift() % USHORT);
  result.push(word[1] + k.shift() % USHORT);
  result.push(Long.fromNumber(mul(word[3], k.shift())).getLowBitsUnsigned());

  util.inPlaceEncodeUInt16(result[0], out, outOff);
  util.inPlaceEncodeUInt16(result[1], out, outOff + 2);
  util.inPlaceEncodeUInt16(result[2], out, outOff + 4);
  util.inPlaceEncodeUInt16(result[3], out, outOff + 6);
  return BlockSize;
}