From 03c332e6d1ab92d4ddbe06f233d1c798ed151546 Mon Sep 17 00:00:00 2001 From: leebj Date: Thu, 24 Oct 2024 11:18:34 +0900 Subject: [PATCH] =?UTF-8?q?=EC=95=94=EB=B3=B5=ED=98=B8=ED=99=94=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC=20=EB=B0=A9=EB=B2=95=20=EC=B6=94=EA=B0=80(?= =?UTF-8?q?=EA=B8=B0=EC=A1=B4=EC=97=90=20=EB=8D=B8=ED=8C=8C=EC=9D=B4(?= =?UTF-8?q?=ED=81=B4=EB=A6=B0=ED=8C=8C=ED=82=B9)=EC=97=90=EC=84=9C=20c++?= =?UTF-8?q?=EB=A1=9C=20=EC=9E=91=EC=84=B1=EB=90=9C=20DLL=ED=8C=8C=EC=9D=BC?= =?UTF-8?q?(xAria32.dll)=20=ED=98=B8=EC=B6=9C=ED=95=98=EC=97=AC=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC=ED=95=9C=20=EC=95=94=EB=B3=B5=ED=98=B8?= =?UTF-8?q?=ED=99=94)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cokr/xit/base/crypto/bean/XitAria.java | 4 +- .../cokr/xit/base/crypto/bean/XitBridge.java | 435 ++++++------------ 2 files changed, 155 insertions(+), 284 deletions(-) diff --git a/src/main/java/cokr/xit/base/crypto/bean/XitAria.java b/src/main/java/cokr/xit/base/crypto/bean/XitAria.java index 78e344c..c3aa31d 100644 --- a/src/main/java/cokr/xit/base/crypto/bean/XitAria.java +++ b/src/main/java/cokr/xit/base/crypto/bean/XitAria.java @@ -3,15 +3,17 @@ package cokr.xit.base.crypto.bean; import cokr.xit.base.crypto.Cryptography; public class XitAria extends Cryptography { + private String key; private int keySize; private XitBridge bridge; public XitAria(String name) { super(name); + int version = def.settings().number("version").intValue(); setKey(def.settings().string("key")); setKeySize(def.settings().number("keySize").intValue()); - bridge = XitBridge.create(key, def.settings().string("charset"), keySize); + bridge = XitBridge.create(key, def.settings().string("charset"), keySize, version); } public XitAria setKey(String key) { diff --git a/src/main/java/cokr/xit/base/crypto/bean/XitBridge.java b/src/main/java/cokr/xit/base/crypto/bean/XitBridge.java index cdf25c2..7b41af2 100644 --- a/src/main/java/cokr/xit/base/crypto/bean/XitBridge.java +++ b/src/main/java/cokr/xit/base/crypto/bean/XitBridge.java @@ -24,6 +24,10 @@ public class XitBridge extends AbstractComponent { "KeySize", new KeySize() ); + // version이 1이면 델파이(클린파킹)에서 c++로 작성된 xAria32.dll파일 호출하던 암복호화 방식 + // version이 1이 아닐 경우 델파이(클린파킹)로 작성된 암복호화 방식(cxAria.pas) + int version; + public abstract class Property { public abstract T read(); public abstract void write(T o); @@ -168,8 +172,16 @@ public class XitBridge extends AbstractComponent { // Encryption round key generation rountine // w0 : master key, e : encryption round keys private int encKeySetup(int[] w0, int[] e) { - int R = (keySize + 256) / 32; - int q = (keySize - 128) / 64; + int R, q; + //if(version == 1) { + //R = (128 + 256) / 32; + //q = (128 - 128) / 64; + //} else { + R = (keySize + 256) / 32; + q = (keySize - 128) / 64; + //} + + int i; int[] t = new int[16]; int[] w1 = new int[16]; @@ -220,7 +232,11 @@ public class XitBridge extends AbstractComponent { diffusionLayer(t, w3); for (i = 0; i < 16; i++) { - w3[i] = w3[1] ^ w1[i]; + if(version == 1) { + w3[i] = w3[i] ^ w1[i]; + } else { + w3[i] = w3[1] ^ w1[i]; + } } //e초기화 @@ -297,10 +313,17 @@ public class XitBridge extends AbstractComponent { private void setKey(String value) { if (equals(key, value)) return; - + byte[] hash; try { - byte[] hash = inMD5(key = value); - Delphi.move(hash, 0, masterKey, masterKey.length); + if(version == 1) { + key = value; + hash = key.getBytes(charset); + masterKey = new int[hash.length]; + } else { + hash = inMD5(key = value); + } + + Delphi.move(hash, 0, masterKey, hash.length); } catch (Exception e) { throw runtimeException(e); } @@ -313,11 +336,12 @@ public class XitBridge extends AbstractComponent { throw new IllegalArgumentException("num: " + num); } - public static XitBridge create(String key, String charset, int keySize) { + public static XitBridge create(String key, String charset, int keySize, int version) { XitBridge newAria = new XitBridge(); newAria.encode = true; newAria.key = ""; newAria.charset = charset; + newAria.version = version; newAria.keySize = keySize; newAria.properties.get("Encode").write(true); @@ -344,18 +368,43 @@ public class XitBridge extends AbstractComponent { byte[] value_byte = value.getBytes(charset); + if(version == 1) { + if(value_byte.length % 16 != 0) { + int padCount = 16 - (value_byte.length % 16); + byte[] newByte = new byte[value_byte.length + padCount]; + Arrays.fill(newByte, (byte)0x00); + for(int j=0;j= 0x01 && encryptData[encryptData.length-1] <= 0x0F) { + byte[] newByte = new byte[encryptData.length-encryptData[15]]; + for(int j=0; j