Skip to content

Commit 228f05a

Browse files
author
liyongfei
committed
fix
Adjusted the array copy offset calculation in the SM4, SM4CTR, SM4GCM, and ZucCipher classes to return data within the correct range. Commented out the SM2 certificate test code in JceTest to temporarily disable the test and avoid hard-coded path issues.
1 parent e3567cc commit 228f05a

File tree

5 files changed

+6
-6
lines changed

5 files changed

+6
-6
lines changed

src/main/java/org/gmssl/crypto/symmetric/SM4CBC.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ protected byte[] processUpdate(byte[] input, int inputOffset, int inputLen) {
7878
}
7979

8080
int outLen = processUpdate(input, inputOffset, inputLen, outputByteArray, offset);
81-
return Arrays.copyOfRange(outputByteArray,offset,offset + outLen);
81+
return Arrays.copyOfRange(outputByteArray,offset-outLen,offset);
8282
}
8383

8484
@Override

src/main/java/org/gmssl/crypto/symmetric/SM4CTR.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ protected byte[] processUpdate(byte[] input, int inputOffset, int inputLen) {
7676
}
7777

7878
int outLen = processUpdate(input, inputOffset, inputLen, outputByteArray, offset);
79-
return Arrays.copyOfRange(outputByteArray,offset,offset + outLen);
79+
return Arrays.copyOfRange(outputByteArray,offset-outLen,offset);
8080
}
8181

8282
@Override

src/main/java/org/gmssl/crypto/symmetric/SM4GCM.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ protected byte[] processUpdate(byte[] input, int inputOffset, int inputLen) {
9292
}
9393

9494
int outLen = processUpdate(input, inputOffset, inputLen, outputByteArray, offset);
95-
return Arrays.copyOfRange(outputByteArray,offset,offset + outLen);
95+
return Arrays.copyOfRange(outputByteArray,offset-outLen,offset);
9696
}
9797

9898
@Override

src/main/java/org/gmssl/crypto/symmetric/ZucCipher.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ protected byte[] engineUpdate(byte[] input, int inputOffset, int inputLen) {
116116
}
117117

118118
int outLen = engineUpdate(input, inputOffset, inputLen, outputByteArray, offset);
119-
return Arrays.copyOfRange(outputByteArray,offset,offset + outLen);
119+
return Arrays.copyOfRange(outputByteArray,offset-outLen,offset);
120120
}
121121

122122
@Override

src/test/java/org/gmssl/JceTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ public void SM2_test() throws Exception{
9393
@Test
9494
public void sm2_certificate_test() throws Exception{
9595
SM2Certificate sm2Cert = new SM2Certificate();
96-
sm2Cert.importPem("D:\\cert.pem");
97-
System.out.println("NotAfter:"+sm2Cert.getNotAfter());
96+
//sm2Cert.importPem("D:\\cert.pem");
97+
//System.out.println("NotAfter:"+sm2Cert.getNotAfter());
9898
}
9999

100100
@Test

0 commit comments

Comments
 (0)