|
|
|
@ -11,7 +11,7 @@ import cokr.xit.foundation.AbstractComponent;
|
|
|
|
|
/**
|
|
|
|
|
* @author leebj
|
|
|
|
|
*/
|
|
|
|
|
public class XitBridge extends AbstractComponent {
|
|
|
|
|
public class XitBridge extends AbstractComponent implements Delphi {
|
|
|
|
|
private int[] masterKey = new int[32];
|
|
|
|
|
private int keySize;
|
|
|
|
|
private String
|
|
|
|
@ -323,7 +323,7 @@ public class XitBridge extends AbstractComponent {
|
|
|
|
|
hash = inMD5(key = value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Delphi.move(hash, 0, masterKey, hash.length);
|
|
|
|
|
move(hash, 0, masterKey, hash.length);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
throw runtimeException(e);
|
|
|
|
|
}
|
|
|
|
@ -384,13 +384,13 @@ public class XitBridge extends AbstractComponent {
|
|
|
|
|
encryptSize = value_byte.length;
|
|
|
|
|
|
|
|
|
|
if(version == 1) {
|
|
|
|
|
encryptData = Delphi.setLength(encryptSize);
|
|
|
|
|
Delphi.move(value_byte,0,encryptData,0,encryptSize);
|
|
|
|
|
encryptData = setLength(encryptSize);
|
|
|
|
|
move(value_byte,0,encryptData,0,encryptSize);
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
encryptData = Delphi.setLength(encryptSize + 4);
|
|
|
|
|
Delphi.move(encryptSize, encryptData, 0);
|
|
|
|
|
Delphi.move(value_byte,0,encryptData,4,encryptSize);
|
|
|
|
|
encryptData = setLength(encryptSize + 4);
|
|
|
|
|
move(encryptSize, encryptData, 0);
|
|
|
|
|
move(value_byte,0,encryptData,4,encryptSize);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -401,20 +401,20 @@ public class XitBridge extends AbstractComponent {
|
|
|
|
|
start = 1;
|
|
|
|
|
|
|
|
|
|
if(version == 1) {
|
|
|
|
|
cryptData = Delphi.setLength(dataSize);
|
|
|
|
|
cryptData = setLength(dataSize);
|
|
|
|
|
} else {
|
|
|
|
|
cryptData = Delphi.setLength(dataSize + 16 - (dataSize % 16));
|
|
|
|
|
cryptData = setLength(dataSize + 16 - (dataSize % 16));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for(i = 1; i <= Math.floorDiv(dataSize,16); i++) {
|
|
|
|
|
Arrays.fill(inBlock, 0);
|
|
|
|
|
Arrays.fill(outBlock, 0);
|
|
|
|
|
|
|
|
|
|
Delphi.move(encryptData, start-1, inBlock, 16);
|
|
|
|
|
move(encryptData, start-1, inBlock, 16);
|
|
|
|
|
doEncrypt(inBlock, roundNum, roundKey, outBlock);
|
|
|
|
|
Delphi.move(outBlock,cryptData,start-1,16);
|
|
|
|
|
move(outBlock,cryptData,start-1,16);
|
|
|
|
|
|
|
|
|
|
start = Delphi.inc(start,16);
|
|
|
|
|
start = inc(start,16);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//나머지크기
|
|
|
|
@ -422,9 +422,9 @@ public class XitBridge extends AbstractComponent {
|
|
|
|
|
Arrays.fill(inBlock, 0);
|
|
|
|
|
Arrays.fill(outBlock, 0);
|
|
|
|
|
|
|
|
|
|
Delphi.move(encryptData,start-1,inBlock,modSize);
|
|
|
|
|
move(encryptData,start-1,inBlock,modSize);
|
|
|
|
|
doEncrypt(inBlock, roundNum, roundKey, outBlock);
|
|
|
|
|
Delphi.move(outBlock,cryptData,start-1,16);
|
|
|
|
|
move(outBlock,cryptData,start-1,16);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(encode) {
|
|
|
|
@ -464,16 +464,16 @@ public class XitBridge extends AbstractComponent {
|
|
|
|
|
roundNum = decKeySetup(masterKey, roundKey);
|
|
|
|
|
|
|
|
|
|
start = 1;
|
|
|
|
|
encryptData = Delphi.setLength(dataSize);
|
|
|
|
|
encryptData = setLength(dataSize);
|
|
|
|
|
for (i = 1; i <= Math.floorDiv(dataSize, 16); i++) {
|
|
|
|
|
Arrays.fill(inBlock, 0);
|
|
|
|
|
Arrays.fill(outBlock, 0);
|
|
|
|
|
|
|
|
|
|
Delphi.move(cryptData,(start-1),inBlock,16);
|
|
|
|
|
move(cryptData,(start-1),inBlock,16);
|
|
|
|
|
doEncrypt(inBlock, roundNum, roundKey, outBlock);
|
|
|
|
|
Delphi.move(outBlock,encryptData,start-1,16);
|
|
|
|
|
move(outBlock,encryptData,start-1,16);
|
|
|
|
|
|
|
|
|
|
start = Delphi.inc(start,16);
|
|
|
|
|
start = inc(start,16);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -481,9 +481,9 @@ public class XitBridge extends AbstractComponent {
|
|
|
|
|
Arrays.fill(inBlock, 0);
|
|
|
|
|
Arrays.fill(outBlock, 0);
|
|
|
|
|
|
|
|
|
|
Delphi.move(cryptData,(start-1),inBlock,16);
|
|
|
|
|
move(cryptData,(start-1),inBlock,16);
|
|
|
|
|
doEncrypt(inBlock, roundNum, roundKey, outBlock);
|
|
|
|
|
Delphi.move(outBlock,encryptData,start-1,16);
|
|
|
|
|
move(outBlock,encryptData,start-1,16);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -498,9 +498,9 @@ public class XitBridge extends AbstractComponent {
|
|
|
|
|
|
|
|
|
|
return new String(encryptData, charset);
|
|
|
|
|
} else {
|
|
|
|
|
encryptSize = Delphi.move(encryptData,0);
|
|
|
|
|
encryptSize = move(encryptData,0);
|
|
|
|
|
byte[] copy = new byte[encryptSize];
|
|
|
|
|
Delphi.move(encryptData,4,copy,0,encryptSize);
|
|
|
|
|
move(encryptData,4,copy,0,encryptSize);
|
|
|
|
|
return new String(copy, charset);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -509,15 +509,6 @@ public class XitBridge extends AbstractComponent {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void _convertIntArray(int[] n){
|
|
|
|
|
for(int j = 0; j < n.length; j++ ) {
|
|
|
|
|
if(n[j] < 0)
|
|
|
|
|
n[j] = n[j] + 256;
|
|
|
|
|
else
|
|
|
|
|
n[j] = n[j];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static int[][] SBox = {
|
|
|
|
|
// S-box type 1
|
|
|
|
|
{
|
|
|
|
|