Compare commits

...

12 Commits

Author SHA1 Message Date
leehagjoon(이학준) b42ef07d38 [LDRA] 585 S : 연산식 재수정 11 months ago
leehagjoon(이학준) 2deddbf699 [LDRA] 585 S : 동일한 데이터에 비트와 연산 - 연산식 수정 11 months ago
leehagjoon(이학준) 9e3b5df7b4 . 1 year ago
leehagjoon(이학준) eae3ae285a [LDRA] 585 S: 동일한 데이터에 대한 비트와 연산 - 한줄로 작업되는 부분들 변수 추가로 나눠서 처리 1 year ago
leehagjoon(이학준) e24d99cb5f [LDRA] 585 S (부분적 처리): 동일한 데이터에 대한 비트와 연산 - 한줄로 작업되는 부분들 변수 추가로 나눠서 처리 1 year ago
leehagjoon(이학준) 3857d826b4 [LDRA] 585 S (부분적 처리): 동일한 데이터에 대한 비트와 연산 - System.out.print 부분에 비트 연산이 두번 진행 중이여서 나눠서 처리 1 year ago
leehagjoon(이학준) 5ba2648c2c [LDRA] 202 S : 클래스 데이터가 명시적으로 비공개가 아닙니다. - public -> private 부분 수정 확인 필요 1 year ago
leehagjoon(이학준) 7635692998 [LDRA] 9 S : 식에 할당 작업이 있다. - 식에 ‘=’ 연산자가 한번에 처리 되고 있어서 해당 연산자 나눠서 코드 수정 1 year ago
leehagjoon(이학준) 77516f9a10 [LDRA] 28 D : 잠재적으로 무한 루프가 발견되었다. - 기존 26 S에서 수정한 코드 while문이 무한루프에 빠질 수 있다 하여 for-each 문으로 수정 1 year ago
leehagjoon(이학준) 6553c706ea [LDRA] 113 S : 한글 문자 또는 아스키코드 사용하면 안된다. - log 영문으로 변경, 특수문자 변경 1 year ago
leehagjoon(이학준) a6690a982e [LDRA] 30 S : 사용하지 않는 ++ 또는 -- 연산자가 발견 - ++ 연산자 밖으로 꺼내주어 처리 1 year ago
leehagjoon(이학준) fbb4ad0c21 [LDRA] 26 S : 루프 컨트롤 식을 종료하지 않을 수 있다. - for문 수정 1 year ago
  1. 21
      src/main/java/com/palnet/comn/collection/AuthCollection.java
  2. 18
      src/main/java/com/palnet/server/command/SocketCommand.java
  3. 328
      src/main/java/com/palnet/server/encrptn/kisa/KISA_SEED_CBC.java
  4. 71
      src/main/java/com/palnet/server/encrptn/kisa/KISA_SHA256.java

21
src/main/java/com/palnet/comn/collection/AuthCollection.java

@ -9,9 +9,9 @@ import java.util.*;
@Slf4j
public class AuthCollection {
private Logger logger = LoggerFactory.getLogger(getClass());
private final Logger logger = LoggerFactory.getLogger(getClass());
private static Set<String> authkeyList = new HashSet<>();
private static final Set<String> authkeyList = new HashSet<>();
public void reloadAuthkey() {
// 인증키 하드코딩 처리
@ -25,14 +25,21 @@ public class AuthCollection {
public boolean checkAuthkey(String authKey) {
boolean result = false;
for (Iterator<String> iterator = authkeyList.iterator(); iterator.hasNext();) {
String item = iterator.next();
if(authKey.equals(item)) {
for (String item : authkeyList) {
if (authKey.equals(item)) {
result = true;
break;
}
}
// for (Iterator<String> iterator = authkeyList.iterator(); iterator.hasNext();) {
// String item = iterator.next();
//
// if(authKey.equals(item)) {
// result = true;
// }
// }
return result;
}

18
src/main/java/com/palnet/server/command/SocketCommand.java

@ -137,7 +137,7 @@ public class SocketCommand {
ControlCacheUtils.setControl(model.getObjectId(),ccm);
} catch (IOException e) {
logger.error("요청한 URL 정보가 잘못되었습니다.", e.getMessage());
logger.error("Requested URL Information is Invalid.", e.getMessage());
} catch (Exception e) {
e.printStackTrace();
}
@ -162,8 +162,8 @@ public class SocketCommand {
messageProducer.sendControlMessage(model);
} else {
logger.error("좌표 정보가 존재하지 않습니다.");
throw new IllegalArgumentException("좌표 정보가 존재하지 않습니다.");
logger.error("Coordinate Information does not exist.");
throw new IllegalArgumentException("Coordinate Information does not exist.");
}
}
}
@ -253,7 +253,7 @@ public class SocketCommand {
ControlCacheUtils.setControl(model.getObjectId(),ccm);
} catch (IOException e) {
logger.error("요청한 URL 정보가 잘못되었습니다.", e.getMessage());
logger.error("Requested URL Information is Invalid.", e.getMessage());
} catch (Exception e) {
e.printStackTrace();
}
@ -276,8 +276,8 @@ public class SocketCommand {
messageProducer.sendControlMessage(model);
} else {
logger.error("좌표 정보가 존재하지 않습니다.");
throw new IllegalArgumentException("좌표 정보가 존재하지 않습니다.");
logger.error("Coordinate Information does not exist.");
throw new IllegalArgumentException("Coordinate Information does not exist.");
}
}
}
@ -367,7 +367,7 @@ public class SocketCommand {
ControlCacheUtils.setControl(model.getObjectId(),ccm);
} catch (IOException e) {
logger.error("요청한 URL 정보가 잘못되었습니다.", e.getMessage());
logger.error("Requested URL Information is Invalid.", e.getMessage());
} catch (Exception e) {
e.printStackTrace();
}
@ -390,8 +390,8 @@ public class SocketCommand {
messageProducer.sendControlMessage(model);
} else {
logger.error("좌표 정보가 존재하지 않습니다.");
throw new IllegalArgumentException("좌표 정보가 존재하지 않습니다.");
logger.error("Coordinate information does not exist.");
throw new IllegalArgumentException("Coordinate information does not exist.");
}
}
}

328
src/main/java/com/palnet/server/encrptn/kisa/KISA_SEED_CBC.java

@ -164,8 +164,10 @@ public class KISA_SEED_CBC {
// R0, R1 : right input values at each round
// K : round keys at each round
private static final void SeedRound(int[] T, int LR[], int L0, int L1, int R0, int R1, int[] K, int K_offset) {
T[0] = LR[R0] ^ K[K_offset+0];
T[1] = LR[R1] ^ K[K_offset+1];
int offset = K_offset + 0;
int offset1 = K_offset + 1;
T[0] = LR[R0] ^ K[offset];
T[1] = LR[R1] ^ K[offset1];
T[1] ^= T[0];
T[1] = SS0[GetB0(T[1])&0x0ff] ^ SS1[GetB1(T[1])&0x0ff] ^
SS2[GetB2(T[1])&0x0ff] ^ SS3[GetB3(T[1])&0x0ff];
@ -372,12 +374,18 @@ public class KISA_SEED_CBC {
if(ENDIAN != Common.BIG_ENDIAN) {
for(i=0;i<inLen;i++)
{
data[i] = (byte)(in[i/4] >> ((i%4)*8));
int temp = in[i / 4];
int shift = (i % 4) * 8;
data[i] = (byte) (temp >> shift);
// data[i] = (byte)(in[i/4] >> ((i%4)*8));
}
} else {
for(i=0;i<inLen;i++)
{
data[i] = (byte)(in[i/4] >> ((3-(i%4))*8));
int temp = in[i / 4];
int shift = (3 - (i % 4)) * 8;
data[i] = (byte) (temp >> shift);
// data[i] = (byte)(in[i/4] >> ((3-(i%4))*8));
}
}
@ -398,7 +406,8 @@ public class KISA_SEED_CBC {
K = pInfo.seed_key.key_data; // Pointer of round keys
pInfo.encrypt = enc.value; //
Common.memcpy(pInfo.ivec, pbszIV, 16, ENDIAN);
pInfo.last_block_flag = pInfo.buffer_length = 0;
pInfo.buffer_length = 0;
pInfo.last_block_flag = pInfo.buffer_length;
// Set up input values for Key Schedule
ABCD[ABCD_A] = Common.byte_to_int(pbszUserKey, 0*4, ENDIAN);
@ -704,12 +713,20 @@ public class KISA_SEED_CBC {
public static final int _KISA_DECRYPT = 0;
public static final int _KISA_ENCRYPT = 1;
public int value;
private int value;
public KISA_ENC_DEC(int value ) {
this.value = value;
}
public int getValue(){
return value;
}
public void setValue(int value){
this.value = value;
}
public static final KISA_ENC_DEC KISA_ENCRYPT = new KISA_ENC_DEC(_KISA_ENCRYPT);
public static final KISA_ENC_DEC KISA_DECRYPT = new KISA_ENC_DEC(_KISA_DECRYPT);
@ -736,11 +753,23 @@ public class KISA_SEED_CBC {
public KISA_SEED_INFO() {
encrypt = 0;
ivec[0] = ivec[1] = ivec[2] = ivec[3] = 0;
ivec[3] = 0;
ivec[2] = ivec[3];
ivec[1] = ivec[2];
ivec[0] = ivec[1];
// ivec[0] = ivec[1] = ivec[2] = ivec[3] = 0;
seed_key.init();
cbc_buffer[0] = cbc_buffer[1] = cbc_buffer[2] = cbc_buffer[3] = 0;
cbc_buffer[3] = 0;
cbc_buffer[2] = cbc_buffer[3];
cbc_buffer[1] = cbc_buffer[2];
cbc_buffer[0] = cbc_buffer[1];
// cbc_buffer[0] = cbc_buffer[1] = cbc_buffer[2] = cbc_buffer[3] = 0;
buffer_length = 0;
cbc_last_block[0] = cbc_last_block[1] = cbc_last_block[2] = cbc_last_block[3] = 0;
cbc_last_block[3] = 0;
cbc_last_block[2] = cbc_last_block[3];
cbc_last_block[1] = cbc_last_block[2];
cbc_last_block[0] = cbc_last_block[1];
// cbc_last_block[0] = cbc_last_block[1] = cbc_last_block[2] = cbc_last_block[3] = 0;
last_block_flag = 0;
}
@ -800,13 +829,21 @@ public class KISA_SEED_CBC {
int mask_value = 0x0ff << shift_value;
int mask_value2 = ~mask_value;
int value2 = (value&0x0ff) << shift_value;
dst[b_offset/4] = (dst[b_offset/4] & mask_value2) | (value2 & mask_value);
int dstValue = dst[b_offset / 4];
dstValue = (dstValue & mask_value2) | (value2 & mask_value);
dst[b_offset / 4] = dstValue;
// dst[b_offset/4] = (dst[b_offset/4] & mask_value2) | (value2 & mask_value);
} else {
int shift_value = (b_offset%4)*8;
int mask_value = 0x0ff << shift_value;
int mask_value2 = ~mask_value;
int value2 = (value&0x0ff) << shift_value;
dst[b_offset/4] = (dst[b_offset/4] & mask_value2) | (value2 & mask_value);
int dstValue = dst[b_offset / 4];
dstValue = (dstValue & mask_value2) | (value2 & mask_value);
dst[b_offset / 4] = dstValue;
// dst[b_offset/4] = (dst[b_offset/4] & mask_value2) | (value2 & mask_value);
}
}
@ -814,12 +851,18 @@ public class KISA_SEED_CBC {
if(ENDIAN == BIG_ENDIAN) {
int shift_value = (3-b_offset%4)*8;
int mask_value = 0x0ff << shift_value;
int value = (src[b_offset/4] & mask_value) >> shift_value;
int mask_value2 = src[b_offset/4];
int value2 = mask_value2 & mask_value;
int value = value2 >> shift_value;
// int value = (src[b_offset/4] & mask_value) >> shift_value;
return (byte)value;
} else {
int shift_value = (b_offset%4)*8;
int mask_value = 0x0ff << shift_value;
int value = (src[b_offset/4] & mask_value) >> shift_value;
int mask_value2 = src[b_offset/4];
int value2 = mask_value2 & mask_value;
int value = value2 >> shift_value;
// int value = (src[b_offset/4] & mask_value) >> shift_value;
return (byte)value;
}
@ -836,10 +879,13 @@ public class KISA_SEED_CBC {
}
public static void byte_to_int(int[] dst, int dst_offset, byte[] src, int src_offset, int ENDIAN) {
int offset1 = src_offset + 1;
int offset2 = src_offset + 2;
int offset3 = src_offset + 3;
if(ENDIAN == BIG_ENDIAN) {
dst[dst_offset] = ((0x0ff&src[src_offset]) << 24) | ((0x0ff&src[src_offset+1]) << 16) | ((0x0ff&src[src_offset+2]) << 8) | ((0x0ff&src[src_offset+3]));
dst[dst_offset] = ((0x0ff&src[src_offset]) << 24) | ((0x0ff&src[offset1]) << 16) | ((0x0ff&src[offset2]) << 8) | ((0x0ff&src[offset3]));
} else {
dst[dst_offset] = ((0x0ff&src[src_offset])) | ((0x0ff&src[src_offset+1]) << 8) | ((0x0ff&src[src_offset+2]) << 16) | ((0x0ff&src[src_offset+3]) << 24);
dst[dst_offset] = ((0x0ff&src[src_offset])) | ((0x0ff&src[offset1]) << 8) | ((0x0ff&src[offset2]) << 16) | ((0x0ff&src[offset3]) << 24);
}
}
@ -887,7 +933,8 @@ public class KISA_SEED_CBC {
if(n >= 32)
return 0;
int v = x >> n;
int v_mask = ~(0x80000000 >> (n-1));
int shift = n - 1;
int v_mask = ~(0x80000000 >> shift);
return v & v_mask;
}
@ -940,7 +987,8 @@ public class KISA_SEED_CBC {
K = pInfo.seed_key.key_data; // Pointer of round keys
pInfo.encrypt = enc.value; //
Common.memcpy(pInfo.ivec, pbszIV, 16, ENDIAN);
pInfo.last_block_flag = pInfo.buffer_length = 0;
pInfo.buffer_length = 0;
pInfo.last_block_flag = pInfo.buffer_length;
// Set up input values for Key Schedule
ABCD[ABCD_A] = Common.byte_to_int(pbszUserKey, 0*4, ENDIAN);
@ -1028,15 +1076,25 @@ public class KISA_SEED_CBC {
System.out.print("\n");
System.out.print("[ Test SEED reference code CBC]"+"\n");
System.out.print("\n\n");
System.out.print("[ Test Encrypt mode : <EFBFBD><EFBFBD><EFBFBD> 1 ]"+"\n");
System.out.print("[ Test Encrypt mode : \uFFFD\uFFFD\uFFFD 1 ]" +"\n");
System.out.print("Key\t\t\t\t: ");
for (int i=0; i<16; i++) System.out.print(Integer.toHexString(0xff&pbUserKey[i])+" ");
for (int i=0; i<16; i++) {
int intValue = 0xff & pbUserKey[i];
String hexString = Integer.toHexString(intValue);
// System.out.print(Integer.toHexString(0xff & pbUserKey[i]) + " ");
System.out.print(hexString + " ");
}
System.out.print("\n");
System.out.print("Plaintext\t\t\t: ");
for (int i=0; i<PLAINTEXT_LENGTH; i++) System.out.print(Integer.toHexString(0xff&pbData[i])+" ");
for (int i=0; i<PLAINTEXT_LENGTH; i++){
int intValue = 0xff & pbData[i];
String hexString = Integer.toHexString(intValue);
System.out.print(hexString + " ");
// System.out.print(Integer.toHexString(0xff&pbData[i])+" ");
}
System.out.print("\n");
@ -1049,18 +1107,30 @@ public class KISA_SEED_CBC {
System.out.print("\nIV\t\t\t\t: ");
for (int i=0; i<16; i++)
System.out.print(Integer.toHexString(0xff&bszIV[i])+" ");
for (int i=0; i<16; i++){
int intValue = 0xff & bszIV[i];
String hexString = Integer.toHexString(intValue);
System.out.print(hexString + " ");
// System.out.print(Integer.toHexString(0xff&bszIV[i])+" ");
}
System.out.print("\n");
System.out.print("Ciphertext(SEED_CBC_Encrypt)\t: ");
for (int i=0; i<CIPHERTEXT_LENGTH; i++)
System.out.print(Integer.toHexString(0xff&defaultCipherText[i])+" ");
for (int i=0; i<CIPHERTEXT_LENGTH; i++){
int intValue = 0xff & defaultCipherText[i];
String hexString = Integer.toHexString(intValue);
System.out.print(hexString + " ");
// System.out.print(Integer.toHexString(0xff&defaultCipherText[i])+" ");
}
System.out.print("\n");
System.out.print("Plaintext(SEED_CBC_Decrypt)\t: ");
for (int i=0; i<PLAINTEXT_LENGTH; i++)
System.out.print(Integer.toHexString(0xff&PPPPP[i])+" ");
for (int i=0; i<PLAINTEXT_LENGTH; i++){
int intValue = 0xff & PPPPP[i];
String hexString = Integer.toHexString(intValue);
System.out.print(hexString + " ");
// System.out.print(Integer.toHexString(0xff&PPPPP[i])+" ");
}
System.out.print("\n\n");
@ -1069,18 +1139,30 @@ public class KISA_SEED_CBC {
byte[] Plain1 = SEED_CBC_Decrypt(pbUserKey, bszIV, Cipher1, 0, 16);
System.out.print("IV\t\t\t\t: ");
for (int i=0; i<16; i++)
System.out.print(Integer.toHexString(0xff&bszIV[i])+" ");
for (int i=0; i<16; i++){
int intValue = 0xff & bszIV[i];
String hexString = Integer.toHexString(intValue);
System.out.print(hexString + " ");
// System.out.print(Integer.toHexString(0xff&bszIV[i])+" ");
}
System.out.print("\n");
System.out.print("Ciphertext(SEED_CBC_Encrypt1)\t: ");
for (int i=0; i<16; i++)
System.out.print(Integer.toHexString(0xff&Cipher1[i])+" ");
for (int i=0; i<16; i++){
int intValue = 0xff & Cipher1[i];
String hexString = Integer.toHexString(intValue);
System.out.print(hexString + " ");
// System.out.print(Integer.toHexString(0xff&Cipher1[i])+" ");
}
System.out.print("\n");
System.out.print("Plaintext(SEED_CBC_Decrypt1)\t: ");
for (int i=0; i<2; i++)
System.out.print(Integer.toHexString(0xff&Plain1[i])+" ");
for (int i=0; i<2; i++){
int intValue = 0xff & Plain1[i];
String hexString = Integer.toHexString(intValue);
System.out.print(hexString + " ");
// System.out.print(Integer.toHexString(0xff&Plain1[i])+" ");
}
System.out.print("\n\n");
@ -1089,18 +1171,30 @@ public class KISA_SEED_CBC {
byte[] Plain2 = SEED_CBC_Decrypt(pbUserKey, bszIV, Cipher2, 0, 32);
System.out.print("IV\t\t\t\t: ");
for (int i=0; i<16; i++)
System.out.print(Integer.toHexString(0xff&bszIV[i])+" ");
for (int i=0; i<16; i++){
int intValue = 0xff & bszIV[i];
String hexString = Integer.toHexString(intValue);
System.out.print(hexString + " ");
// System.out.print(Integer.toHexString(0xff&bszIV[i])+" ");
}
System.out.print("\n\n");
System.out.print("Ciphertext(SEED_CBC_Encrypt)\t: ");
for (int i=0; i<32; i++)
System.out.print(Integer.toHexString(0xff&Cipher2[i])+" ");
for (int i=0; i<32; i++){
int intValue = 0xff & Cipher2[i];
String hexString = Integer.toHexString(intValue);
System.out.print(hexString + " ");
// System.out.print(Integer.toHexString(0xff&Cipher2[i])+" ");
}
System.out.print("\n");
System.out.print("Plaintext(SEED_CBC_Decrypt)\t: ");
for (int i=0; i<16; i++)
System.out.print(Integer.toHexString(0xff&Plain2[i])+" ");
for (int i=0; i<16; i++){
int intValue = 0xff & Plain2[i];
String hexString = Integer.toHexString(intValue);
System.out.print(hexString + " ");
// System.out.print(Integer.toHexString(0xff&Plain2[i])+" ");
}
System.out.print("\n\n\n");
@ -1111,18 +1205,30 @@ public class KISA_SEED_CBC {
byte[] Plain3 = SEED_CBC_Decrypt(pbUserKey, bszIV, Cipher3, 0, 32);
System.out.print("IV\t\t\t\t: ");
for (int i=0; i<16; i++)
System.out.print(Integer.toHexString(0xff&bszIV[i])+" ");
for (int i=0; i<16; i++){
int intValue = 0xff & bszIV[i];
String hexString = Integer.toHexString(intValue);
System.out.print(hexString + " ");
// System.out.print(Integer.toHexString(0xff&bszIV[i])+" ");
}
System.out.print("\n");
System.out.print("Ciphertext(SEED_CBC_Encrypt3)\t: ");
for (int i=0; i<32; i++)
System.out.print(Integer.toHexString(0xff&Cipher3[i])+" ");
for (int i=0; i<32; i++){
int intValue = 0xff & Cipher3[i];
String hexString = Integer.toHexString(intValue);
System.out.print(hexString + " ");
// System.out.print(Integer.toHexString(0xff&Cipher3[i])+" ");
}
System.out.print("\n");
System.out.print("Plaintext(SEED_CBC_Decrypt3)\t: ");
for (int i=0; i<18; i++)
System.out.print(Integer.toHexString(0xff&Plain3[i])+" ");
for (int i=0; i<18; i++){
int intValue = 0xff & Plain3[i];
String hexString = Integer.toHexString(intValue);
System.out.print(hexString + " ");
// System.out.print(Integer.toHexString(0xff&Plain3[i])+" ");
}
System.out.print("\n");
@ -1149,12 +1255,22 @@ public class KISA_SEED_CBC {
PLAINTEXT_LENGTH = 14;
System.out.print("\n\n[ Test Encrypt mode : <EFBFBD><EFBFBD><EFBFBD> 2 ]"+"\n");
System.out.print("\n\n[ Test Encrypt mode : \uFFFD\uFFFD\uFFFD 2 ]" +"\n");
System.out.print("Key\t\t\t\t: ");
for (int i=0; i<16; i++) System.out.print(Integer.toHexString(0xff&pbUserKey[i])+", ");
for (int i=0; i<16; i++) {
int intValue = 0xff & pbUserKey[i];
String hexString = Integer.toHexString(intValue);
System.out.print(hexString + " ");
// System.out.print(Integer.toHexString(0xff&pbUserKey[i])+", ");
}
System.out.print("\n");
System.out.print("Plaintext\t\t\t: ");
for (int i=0; i<PLAINTEXT_LENGTH; i++) System.out.print(Integer.toHexString(0xff&pbData[i])+", ");
for (int i=0; i<PLAINTEXT_LENGTH; i++){
int intValue = 0xff & pbData[i];
String hexString = Integer.toHexString(intValue);
System.out.print(hexString + " ");
// System.out.print(Integer.toHexString(0xff&pbData[i])+", ");
}
System.out.print("\n");
@ -1190,7 +1306,7 @@ public class KISA_SEED_CBC {
int[] outbuf = new int[process_blockLeng/4];
for(j=0; j<PLAINTEXT_LENGTH-process_blockLeng; )
for(j=0; j<PLAINTEXT_LENGTH-process_blockLeng; j+= process_blockLeng)
{
System.arraycopy(pbData, j, newpbszPlainText, 0, process_blockLeng);
data = chartoint32_for_SEED_CBC(newpbszPlainText, process_blockLeng);
@ -1223,13 +1339,21 @@ public class KISA_SEED_CBC {
System.out.print("IV\t\t\t\t: ");
for (int i=0; i<16; i++)
System.out.print(Integer.toHexString(0xff&bszIV[i])+", ");
for (int i=0; i<16; i++){
int intValue = 0xff & bszIV[i];
String hexString = Integer.toHexString(intValue);
System.out.print(hexString + " ");
// System.out.print(Integer.toHexString(0xff&bszIV[i])+", ");
}
System.out.print("\n");
System.out.print("Ciphertext(SEED_CBC_Encrypt 1)\t: ");
for (int i=0; i<CIPHERTEXT_LENGTH; i++)
System.out.print(Integer.toHexString(0xff&pbszCipherText[i])+", ");
for (int i=0; i<CIPHERTEXT_LENGTH; i++){
int intValue = 0xff & pbszCipherText[i];
String hexString = Integer.toHexString(intValue);
System.out.print(hexString + " ");
// System.out.print(Integer.toHexString(0xff&pbszCipherText[i])+", ");
}
System.out.print("\n");
@ -1275,7 +1399,7 @@ public class KISA_SEED_CBC {
byte []pbszPlainText = new byte[nCipherTextLen];
for(j=0; j<nCipherTextLen - process_blockLeng; )
for(j=0; j<nCipherTextLen - process_blockLeng; j+= process_blockLeng)
{
System.arraycopy(message, j, newpbszCipherText, 0, process_blockLeng);
data = chartoint32_for_SEED_CBC(newpbszCipherText, process_blockLeng);
@ -1326,8 +1450,12 @@ public class KISA_SEED_CBC {
System.out.print("Plaintext(SEED_CBC_Decrypt 1)\t: ");
for (int i=0; i<PLAINTEXT_LENGTH; i++)
System.out.print(Integer.toHexString(0xff&result[i])+", ");
for (int i=0; i<PLAINTEXT_LENGTH; i++){
int intValue = 0xff & result[i];
String hexString = Integer.toHexString(intValue);
System.out.print(hexString + " ");
// System.out.print(Integer.toHexString(0xff&result[i])+", ");
}
System.out.print("\n\n");
data = null;
@ -1377,7 +1505,7 @@ public class KISA_SEED_CBC {
outbuf = new int[process_blockLeng/4];
pbszPlainText = new byte[process_blockLeng];
for(j=0; j<PLAINTEXT_LENGTH-process_blockLeng; )
for(j=0; j<PLAINTEXT_LENGTH-process_blockLeng; j+= process_blockLeng)
{
System.arraycopy(pbData1, j, newpbszPlainText, 0, process_blockLeng);
data = chartoint32_for_SEED_CBC(newpbszPlainText, process_blockLeng);
@ -1412,13 +1540,21 @@ public class KISA_SEED_CBC {
System.out.print("\n\nIV\t\t\t\t: ");
for (int i=0; i<16; i++)
System.out.print(Integer.toHexString(0xff&bszIV[i])+" ");
for (int i=0; i<16; i++){
int intValue = 0xff & bszIV[i];
String hexString = Integer.toHexString(intValue);
System.out.print(hexString + " ");
// System.out.print(Integer.toHexString(0xff&bszIV[i])+" ");
}
System.out.print("\n");
System.out.print("Ciphertext(SEED_CBC_Encrypt)\t: ");
for (int i=0; i<16; i++)
System.out.print(Integer.toHexString(0xff&pbszCipherText[i])+" ");
for (int i=0; i<16; i++){
int intValue = 0xff & pbszCipherText[i];
String hexString = Integer.toHexString(intValue);
System.out.print(hexString + " ");
// System.out.print(Integer.toHexString(0xff&pbszCipherText[i])+" ");
}
System.out.print("\n");
@ -1466,7 +1602,7 @@ public class KISA_SEED_CBC {
pbszPlainText = new byte[nCipherTextLen];
for(j=0; j<nCipherTextLen - process_blockLeng; )
for(j=0; j<nCipherTextLen - process_blockLeng; j+= process_blockLeng)
{
System.arraycopy(message, j, newpbszCipherText, 0, process_blockLeng);
data = chartoint32_for_SEED_CBC(newpbszCipherText, process_blockLeng);
@ -1517,8 +1653,12 @@ public class KISA_SEED_CBC {
System.out.print("Plaintext(SEED_CBC_Decrypt 1)\t: ");
for (int i=0; i<PLAINTEXT_LENGTH; i++)
System.out.print(Integer.toHexString(0xff&result[i])+" ");
for (int i=0; i<PLAINTEXT_LENGTH; i++){
int intValue = 0xff & result[i];
String hexString = Integer.toHexString(intValue);
System.out.print(hexString + " ");
// System.out.print(Integer.toHexString(0xff&result[i])+" ");
}
System.out.print("\n\n");
data = null;
@ -1553,7 +1693,7 @@ public class KISA_SEED_CBC {
outbuf = new int[process_blockLeng/4];
pbszPlainText = new byte[process_blockLeng];
for(j=0; j<PLAINTEXT_LENGTH-process_blockLeng; )
for(j=0; j<PLAINTEXT_LENGTH-process_blockLeng; j+= process_blockLeng)
{
System.arraycopy(pbData2, j, newpbszPlainText, 0, process_blockLeng);
data = chartoint32_for_SEED_CBC(newpbszPlainText, process_blockLeng);
@ -1588,13 +1728,21 @@ public class KISA_SEED_CBC {
System.out.print("\n\nIV\t\t\t\t: ");
for (int i=0; i<16; i++)
System.out.print(Integer.toHexString(0xff&bszIV[i])+" ");
for (int i=0; i<16; i++){
int intValue = 0xff & bszIV[i];
String hexString = Integer.toHexString(intValue);
System.out.print(hexString + " ");
// System.out.print(Integer.toHexString(0xff&bszIV[i])+" ");
}
System.out.print("\n");
System.out.print("Ciphertext(SEED_CBC_Encrypt)\t: ");
for (int i=0; i<32; i++)
System.out.print(Integer.toHexString(0xff&pbszCipherText[i])+" ");
for (int i=0; i<32; i++){
int intValue = 0xff & pbszCipherText[i];
String hexString = Integer.toHexString(intValue);
System.out.print(hexString + " ");
// System.out.print(Integer.toHexString(0xff&pbszCipherText[i])+" ");
}
System.out.print("\n");
@ -1641,7 +1789,7 @@ public class KISA_SEED_CBC {
pbszPlainText = new byte[nCipherTextLen];
for(j=0; j<nCipherTextLen - process_blockLeng; )
for(j=0; j<nCipherTextLen - process_blockLeng; j+= process_blockLeng)
{
System.arraycopy(message, j, newpbszCipherText, 0, process_blockLeng);
data = chartoint32_for_SEED_CBC(newpbszCipherText, process_blockLeng);
@ -1692,8 +1840,12 @@ public class KISA_SEED_CBC {
System.out.print("Plaintext(SEED_CBC_Decrypt 1)\t: ");
for (int i=0; i<PLAINTEXT_LENGTH; i++)
System.out.print(Integer.toHexString(0xff&result[i])+" ");
for (int i=0; i<PLAINTEXT_LENGTH; i++){
int intValue = 0xff & result[i];
String hexString = Integer.toHexString(intValue);
System.out.print(hexString + " ");
// System.out.print(Integer.toHexString(0xff&result[i])+" ");
}
System.out.print("\n\n");
data = null;
@ -1730,7 +1882,7 @@ public class KISA_SEED_CBC {
outbuf = new int[process_blockLeng/4];
pbszPlainText = new byte[process_blockLeng];
for(j=0; j<PLAINTEXT_LENGTH-process_blockLeng; )
for(j=0; j<PLAINTEXT_LENGTH-process_blockLeng; j+= process_blockLeng)
{
System.arraycopy(pbData3, j, newpbszPlainText, 0, process_blockLeng);
data = chartoint32_for_SEED_CBC(newpbszPlainText, process_blockLeng);
@ -1765,13 +1917,21 @@ public class KISA_SEED_CBC {
System.out.print("\n\nIV\t\t\t\t: ");
for (int i=0; i<16; i++)
System.out.print(Integer.toHexString(0xff&bszIV[i])+" ");
for (int i=0; i<16; i++){
int intValue = 0xff & bszIV[i];
String hexString = Integer.toHexString(intValue);
System.out.print(hexString + " ");
// System.out.print(Integer.toHexString(0xff&bszIV[i])+" ");
}
System.out.print("\n");
System.out.print("Ciphertext(SEED_CBC_Encrypt)\t: ");
for (int i=0; i<32; i++)
System.out.print(Integer.toHexString(0xff&pbszCipherText[i])+" ");
for (int i=0; i<32; i++){
int intValue = 0xff & pbszCipherText[i];
String hexString = Integer.toHexString(intValue);
System.out.print(hexString + " ");
// System.out.print(Integer.toHexString(0xff&pbszCipherText[i])+" ");
}
System.out.print("\n");
@ -1819,7 +1979,7 @@ public class KISA_SEED_CBC {
pbszPlainText = new byte[nCipherTextLen];
for(j=0; j<nCipherTextLen - process_blockLeng; )
for(j=0; j<nCipherTextLen - process_blockLeng; j+= process_blockLeng)
{
System.arraycopy(message, j, newpbszCipherText, 0, process_blockLeng);
data = chartoint32_for_SEED_CBC(newpbszCipherText, process_blockLeng);
@ -1870,8 +2030,12 @@ public class KISA_SEED_CBC {
System.out.print("Plaintext(SEED_CBC_Decrypt 1)\t: ");
for (int i=0; i<PLAINTEXT_LENGTH; i++)
System.out.print(Integer.toHexString(0xff&result[i])+" ");
for (int i=0; i<PLAINTEXT_LENGTH; i++){
int intValue = 0xff & result[i];
String hexString = Integer.toHexString(intValue);
System.out.print(hexString + " ");
// System.out.print(Integer.toHexString(0xff&result[i])+" ");
}
System.out.print("\n\n");
data = null;

71
src/main/java/com/palnet/server/encrptn/kisa/KISA_SHA256.java

@ -135,8 +135,9 @@ public class KISA_SHA256 {
Info.uChainVar[5] = 0x9b05688c;
Info.uChainVar[6] = 0x1f83d9ab;
Info.uChainVar[7] = 0x5be0cd19;
Info.uHighLength = Info.uLowLength = 0;
Info.uLowLength = 0;
Info.uHighLength = Info.uLowLength;
// Info.uHighLength = Info.uLowLength = 0;
}
/**
@ -148,7 +149,8 @@ public class KISA_SHA256 {
public static void SHA256_Process( SHA256_INFO Info, byte[] pszMessage, int uDataLen ) {
int pszMessage_offset;
if((Info.uLowLength += (uDataLen << 3)) < 0) {
Info.uLowLength += (uDataLen <<3);
if(Info.uLowLength < 0) {
Info.uHighLength++;
}
@ -174,7 +176,8 @@ public class KISA_SHA256 {
int i, Index;
Index = Common.URShift(Info.uLowLength, 3) % SHA256_DIGEST_BLOCKLEN;
Info.szBuffer[Index++] = (byte)0x80;
Index = Index + 1;
Info.szBuffer[Index] = (byte)0x80;
if (Index > SHA256_DIGEST_BLOCKLEN - 8) {
Common.arrayinit_offset(Info.szBuffer, Index, (byte)0, SHA256_DIGEST_BLOCKLEN - Index);
@ -269,13 +272,21 @@ public class KISA_SHA256 {
int mask_value = 0x0ff << shift_value;
int mask_value2 = ~mask_value;
int value2 = (value&0x0ff) << shift_value;
dst[b_offset/4] = (dst[b_offset/4] & mask_value2) | (value2 & mask_value);
int dstValue = dst[b_offset / 4];
dstValue = (dstValue & mask_value2) | (value2 & mask_value);
dst[b_offset / 4] = dstValue;
// dst[b_offset/4] = (dst[b_offset/4] & mask_value2) | (value2 & mask_value);
} else {
int shift_value = (b_offset%4)*8;
int mask_value = 0x0ff << shift_value;
int mask_value2 = ~mask_value;
int value2 = (value&0x0ff) << shift_value;
dst[b_offset/4] = (dst[b_offset/4] & mask_value2) | (value2 & mask_value);
int dstValue = dst[b_offset / 4];
dstValue = (dstValue & mask_value2) | (value2 & mask_value);
dst[b_offset / 4] = dstValue;
// dst[b_offset/4] = (dst[b_offset/4] & mask_value2) | (value2 & mask_value);
}
}
@ -283,12 +294,18 @@ public class KISA_SHA256 {
if(ENDIAN == BIG_ENDIAN) {
int shift_value = (3-b_offset%4)*8;
int mask_value = 0x0ff << shift_value;
int value = (src[b_offset/4] & mask_value) >> shift_value;
int mask_value2 = src[b_offset/4];
int value2 = mask_value2 & mask_value;
int value = value2 >> shift_value;
// int value = (src[b_offset/4] & mask_value) >> shift_value;
return (byte)value;
} else {
int shift_value = (b_offset%4)*8;
int mask_value = 0x0ff << shift_value;
int value = (src[b_offset/4] & mask_value) >> shift_value;
int mask_value2 = src[b_offset/4];
int value2 = mask_value2 & mask_value;
int value = value2 >> shift_value;
// int value = (src[b_offset/4] & mask_value) >> shift_value;
return (byte)value;
}
@ -305,10 +322,13 @@ public class KISA_SHA256 {
}
public static void byte_to_int(int[] dst, int dst_offset, byte[] src, int src_offset, int ENDIAN) {
int offset1 = src_offset + 1;
int offset2 = src_offset + 2;
int offset3 = src_offset + 3;
if(ENDIAN == BIG_ENDIAN) {
dst[dst_offset] = ((0x0ff&src[src_offset]) << 24) | ((0x0ff&src[src_offset+1]) << 16) | ((0x0ff&src[src_offset+2]) << 8) | ((0x0ff&src[src_offset+3]));
dst[dst_offset] = ((0x0ff&src[src_offset]) << 24) | ((0x0ff&src[offset1]) << 16) | ((0x0ff&src[offset2]) << 8) | ((0x0ff&src[offset3]));
} else {
dst[dst_offset] = ((0x0ff&src[src_offset])) | ((0x0ff&src[src_offset+1]) << 8) | ((0x0ff&src[src_offset+2]) << 16) | ((0x0ff&src[src_offset+3]) << 24);
dst[dst_offset] = ((0x0ff&src[src_offset])) | ((0x0ff&src[offset1]) << 8) | ((0x0ff&src[offset2]) << 16) | ((0x0ff&src[offset3]) << 24);
}
}
@ -356,7 +376,8 @@ public class KISA_SHA256 {
if(n >= 32)
return 0;
int v = x >> n;
int v_mask = ~(0x80000000 >> (n-1));
int shift = n - 1;
int v_mask = ~(0x80000000 >> shift);
return v & v_mask;
}
@ -393,14 +414,24 @@ public class KISA_SHA256 {
{
System.out.print("Plaintext\t: ");
for (int i=0; i<Plaintext_length; i++) System.out.print(Integer.toHexString(0xff&pbData[i])+" ");
for (int i=0; i<Plaintext_length; i++) {
int intValue = 0xff & pbData[i];
String hexString = Integer.toHexString(intValue);
System.out.print(hexString + " ");
// System.out.print(Integer.toHexString(0xff&pbData[i])+" ");
}
System.out.print("\n");
// Encryption
SHA256_Encrpyt( pbData, Plaintext_length, pbCipher );
System.out.print("Ciphertext\t: ");
for (int i=0; i<32; i++) System.out.print(Integer.toHexString(0xff&pbCipher[i])+" ");
for (int i=0; i<32; i++){
int intValue = 0xff & pbCipher[i];
String hexString = Integer.toHexString(intValue);
System.out.print(hexString + " ");
// System.out.print(Integer.toHexString(0xff&pbCipher[i])+" ");
}
System.out.print("\n\n");
Plaintext_length++;
@ -409,12 +440,22 @@ public class KISA_SHA256 {
System.out.print("Plaintext\t: ");
for (int i=0; i<1; i++) System.out.print(Integer.toHexString(0xff&pbData1[i])+" ");
for (int i=0; i<1; i++){
int intValue = 0xff & pbData1[i];
String hexString = Integer.toHexString(intValue);
System.out.print(hexString + " ");
// System.out.print(Integer.toHexString(0xff&pbData1[i])+" ");
}
System.out.print("\n");
// Encryption
SHA256_Encrpyt( pbData1, 1, pbCipher );
System.out.print("Ciphertext\t: ");
for (int i=0; i<32; i++) System.out.print(Integer.toHexString(0xff&pbCipher[i])+" ");
for (int i=0; i<32; i++){
int intValue = 0xff & pbCipher[i];
String hexString = Integer.toHexString(intValue);
System.out.println(hexString + " ");
// System.out.print(Integer.toHexString(0xff&pbCipher[i])+" ");
}
System.out.print("\n\n");

Loading…
Cancel
Save